AliPHOSGeometry is removed from AliPHOSGetter and AliPHOSLoader
[u/mrichter/AliRoot.git] / PHOS / AliPHOSEmcRecPoint.cxx
CommitLineData
d15a28e7 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
b2a60966 16/* $Id$ */
17
702ab87e 18/* History of cvs commits:
19 *
20 * $Log$
25779c68 21 * Revision 1.59 2007/10/18 15:12:22 kharlov
22 * Moved MakePrimary to EMCRecPoint to rpduce correct order of primaries
23 *
c307c629 24 * Revision 1.58 2007/04/16 09:03:37 kharlov
25 * Incedent angle correction fixed
26 *
753b19cd 27 * Revision 1.57 2007/04/05 10:18:58 policheh
28 * Introduced distance to nearest bad crystal.
29 *
dce76bbb 30 * Revision 1.56 2007/03/06 06:47:28 kharlov
31 * DP:Possibility to use actual vertex position added
32 *
91daaf24 33 * Revision 1.55 2007/01/19 20:31:19 kharlov
34 * Improved formatting for Print()
702ab87e 35 */
36
d15a28e7 37//_________________________________________________________________________
b2a60966 38// RecPoint implementation for PHOS-EMC
39// An EmcRecPoint is a cluster of digits
6c8cd883 40//--
41//-- Author: Dmitri Peressounko (RRC KI & SUBATECH)
b2a60966 42
d15a28e7 43
44// --- ROOT system ---
9f616d61 45#include "TH2.h"
d15a28e7 46#include "TMath.h"
9f616d61 47#include "TCanvas.h"
55fe9d13 48#include "TGraph.h"
d15a28e7 49
50// --- Standard library ---
51
d15a28e7 52// --- AliRoot header files ---
351dd634 53#include "AliLog.h"
e957fea8 54#include "AliPHOSLoader.h"
88cb7938 55#include "AliGenerator.h"
d15a28e7 56#include "AliPHOSGeometry.h"
e957fea8 57#include "AliPHOSDigit.h"
d15a28e7 58#include "AliPHOSEmcRecPoint.h"
e957fea8 59
d15a28e7 60ClassImp(AliPHOSEmcRecPoint)
61
62//____________________________________________________________________________
3663622c 63AliPHOSEmcRecPoint::AliPHOSEmcRecPoint() :
64 AliPHOSRecPoint(),
65 fCoreEnergy(0.), fDispersion(0.),
66 fEnergyList(0), fTime(-1.), fNExMax(0),
67 fM2x(0.), fM2z(0.), fM3x(0.), fM4z(0.),
dce76bbb 68 fPhixe(0.), fDistToBadCrystal(-1),fDebug(0)
d15a28e7 69{
70 // ctor
d15a28e7 71 fMulDigit = 0 ;
72 fAmp = 0. ;
a6eedfad 73 fLocPos.SetX(1000000.) ; //Local position should be evaluated
83974468 74}
75
76//____________________________________________________________________________
3663622c 77AliPHOSEmcRecPoint::AliPHOSEmcRecPoint(const char * opt) :
78 AliPHOSRecPoint(opt),
79 fCoreEnergy(0.), fDispersion(0.),
80 fEnergyList(0), fTime(-1.), fNExMax(0),
81 fM2x(0.), fM2z(0.), fM3x(0.), fM4z(0.),
dce76bbb 82 fPhixe(0.), fDistToBadCrystal(-1), fDebug(0)
73a68ccb 83{
84 // ctor
73a68ccb 85 fMulDigit = 0 ;
86 fAmp = 0. ;
73a68ccb 87 fLocPos.SetX(1000000.) ; //Local position should be evaluated
73a68ccb 88}
89
90//____________________________________________________________________________
3663622c 91AliPHOSEmcRecPoint::AliPHOSEmcRecPoint(const AliPHOSEmcRecPoint & rp) :
92 AliPHOSRecPoint(rp),
93 fCoreEnergy(rp.fCoreEnergy), fDispersion(rp.fDispersion),
94 fEnergyList(0), fTime(rp.fTime), fNExMax(rp.fNExMax),
95 fM2x(rp.fM2x), fM2z(rp.fM2z), fM3x(rp.fM3x), fM4z(rp.fM4z),
dce76bbb 96 fPhixe(rp.fPhixe), fDistToBadCrystal(rp.fDistToBadCrystal), fDebug(rp.fDebug)
55fe9d13 97{
98 // cpy ctor
55fe9d13 99 fMulDigit = rp.fMulDigit ;
100 fAmp = rp.fAmp ;
25779c68 101 if (rp.fMulDigit>0) fEnergyList = new Float_t[rp.fMulDigit] ;
102 for(Int_t index = 0 ; index < fMulDigit ; index++)
55fe9d13 103 fEnergyList[index] = rp.fEnergyList[index] ;
55fe9d13 104}
105
106//____________________________________________________________________________
83974468 107AliPHOSEmcRecPoint::~AliPHOSEmcRecPoint()
108{
88714635 109 // dtor
83974468 110 if ( fEnergyList )
111 delete[] fEnergyList ;
d15a28e7 112}
113
9f616d61 114//____________________________________________________________________________
83974468 115void AliPHOSEmcRecPoint::AddDigit(AliPHOSDigit & digit, Float_t Energy)
d15a28e7 116{
b2a60966 117 // Adds a digit to the RecPoint
a4e98857 118 // and accumulates the total amplitude and the multiplicity
d15a28e7 119
7932f811 120 if(fEnergyList == 0)
121 fEnergyList = new Float_t[fMaxDigit];
122
d15a28e7 123 if ( fMulDigit >= fMaxDigit ) { // increase the size of the lists
9f616d61 124 fMaxDigit*=2 ;
0fbb8738 125 Int_t * tempo = new Int_t[fMaxDigit];
126 Float_t * tempoE = new Float_t[fMaxDigit];
9f616d61 127
128 Int_t index ;
d15a28e7 129 for ( index = 0 ; index < fMulDigit ; index++ ){
83974468 130 tempo[index] = fDigitsList[index] ;
d15a28e7 131 tempoE[index] = fEnergyList[index] ;
132 }
133
9f616d61 134 delete [] fDigitsList ;
0fbb8738 135 fDigitsList = new Int_t[fMaxDigit];
9f616d61 136
137 delete [] fEnergyList ;
0fbb8738 138 fEnergyList = new Float_t[fMaxDigit];
9f616d61 139
140 for ( index = 0 ; index < fMulDigit ; index++ ){
141 fDigitsList[index] = tempo[index] ;
142 fEnergyList[index] = tempoE[index] ;
143 }
144
145 delete [] tempo ;
146 delete [] tempoE ;
147 } // if
d15a28e7 148
83974468 149 fDigitsList[fMulDigit] = digit.GetIndexInList() ;
150 fEnergyList[fMulDigit] = Energy ;
151 fMulDigit++ ;
d15a28e7 152 fAmp += Energy ;
7932f811 153
154 EvalPHOSMod(&digit) ;
d15a28e7 155}
156
157//____________________________________________________________________________
ad8cfaf4 158Bool_t AliPHOSEmcRecPoint::AreNeighbours(AliPHOSDigit * digit1, AliPHOSDigit * digit2 ) const
d15a28e7 159{
a4e98857 160 // Tells if (true) or not (false) two digits are neighbors
d15a28e7 161
162 Bool_t aren = kFALSE ;
163
686b771f 164 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
7b7c1533 165
d15a28e7 166 Int_t relid1[4] ;
92862013 167 phosgeom->AbsToRelNumbering(digit1->GetId(), relid1) ;
d15a28e7 168
169 Int_t relid2[4] ;
92862013 170 phosgeom->AbsToRelNumbering(digit2->GetId(), relid2) ;
d15a28e7 171
92862013 172 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
173 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
d15a28e7 174
92862013 175 if (( coldiff <= 1 ) && ( rowdiff <= 1 ) && (coldiff + rowdiff > 0))
d15a28e7 176 aren = kTRUE ;
177
178 return aren ;
179}
180
181//____________________________________________________________________________
2a941f4e 182Int_t AliPHOSEmcRecPoint::Compare(const TObject * obj) const
d15a28e7 183{
b2a60966 184 // Compares two RecPoints according to their position in the PHOS modules
686b771f 185
186 const Float_t delta = 1 ; //Width of "Sorting row". If you changibg this
7932f811 187 //value (what is senseless) change as vell delta in
188 //AliPHOSTrackSegmentMakerv* and other RecPoints...
d15a28e7 189 Int_t rv ;
190
191 AliPHOSEmcRecPoint * clu = (AliPHOSEmcRecPoint *)obj ;
192
193
ad8cfaf4 194 Int_t phosmod1 = GetPHOSMod() ;
92862013 195 Int_t phosmod2 = clu->GetPHOSMod() ;
d15a28e7 196
92862013 197 TVector3 locpos1;
7932f811 198 GetLocalPosition(locpos1) ;
92862013 199 TVector3 locpos2;
200 clu->GetLocalPosition(locpos2) ;
d15a28e7 201
92862013 202 if(phosmod1 == phosmod2 ) {
7932f811 203 Int_t rowdif = (Int_t)TMath::Ceil(locpos1.X()/delta)-(Int_t)TMath::Ceil(locpos2.X()/delta) ;
d15a28e7 204 if (rowdif> 0)
7932f811 205 rv = 1 ;
d15a28e7 206 else if(rowdif < 0)
7932f811 207 rv = -1 ;
92862013 208 else if(locpos1.Z()>locpos2.Z())
d15a28e7 209 rv = -1 ;
210 else
211 rv = 1 ;
212 }
213
214 else {
92862013 215 if(phosmod1 < phosmod2 )
d15a28e7 216 rv = -1 ;
217 else
218 rv = 1 ;
219 }
220
221 return rv ;
222}
9f616d61 223//______________________________________________________________________________
702ab87e 224void AliPHOSEmcRecPoint::ExecuteEvent(Int_t event, Int_t, Int_t) /*const*/
9f616d61 225{
9f616d61 226
9688c1dd 227 // Execute action corresponding to one event
228 // This member function is called when a AliPHOSRecPoint is clicked with the locator
229 //
230 // If Left button is clicked on AliPHOSRecPoint, the digits are switched on
231 // and switched off when the mouse button is released.
232
88cb7938 233
686b771f 234 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
83974468 235
9688c1dd 236 static TGraph * digitgraph = 0 ;
83974468 237
9688c1dd 238 if (!gPad->IsEditable()) return;
83974468 239
9688c1dd 240 TH2F * histo = 0 ;
241 TCanvas * histocanvas ;
242
88cb7938 243
244 //try to get run loader from default event folder
e191bb57 245 AliRunLoader* rn = AliRunLoader::GetRunLoader(AliConfig::GetDefaultEventFolderName());
88cb7938 246 if (rn == 0x0)
247 {
351dd634 248 AliError(Form("Cannot find Run Loader in Default Event Folder"));
88cb7938 249 return;
250 }
251 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(rn->GetLoader("PHOSLoader"));
252 if (gime == 0x0)
253 {
351dd634 254 AliError(Form("Cannot find PHOS Loader from Run Loader"));
88cb7938 255 return;
256 }
257
258
afa51c4e 259 const TClonesArray * digits = gime->Digits() ;
9688c1dd 260
261 switch (event) {
83974468 262
9688c1dd 263 case kButton1Down: {
264 AliPHOSDigit * digit ;
265 Int_t iDigit;
266 Int_t relid[4] ;
83974468 267
9688c1dd 268 const Int_t kMulDigit = AliPHOSEmcRecPoint::GetDigitsMultiplicity() ;
269 Float_t * xi = new Float_t[kMulDigit] ;
270 Float_t * zi = new Float_t[kMulDigit] ;
83974468 271
9688c1dd 272 // create the histogram for the single cluster
273 // 1. gets histogram boundaries
274 Float_t ximax = -999. ;
275 Float_t zimax = -999. ;
276 Float_t ximin = 999. ;
277 Float_t zimin = 999. ;
83974468 278
9688c1dd 279 for(iDigit=0; iDigit<kMulDigit; iDigit++) {
280 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
281 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
282 phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]);
283 if ( xi[iDigit] > ximax )
284 ximax = xi[iDigit] ;
285 if ( xi[iDigit] < ximin )
286 ximin = xi[iDigit] ;
287 if ( zi[iDigit] > zimax )
288 zimax = zi[iDigit] ;
289 if ( zi[iDigit] < zimin )
290 zimin = zi[iDigit] ;
291 }
292 ximax += phosgeom->GetCrystalSize(0) / 2. ;
293 zimax += phosgeom->GetCrystalSize(2) / 2. ;
294 ximin -= phosgeom->GetCrystalSize(0) / 2. ;
295 zimin -= phosgeom->GetCrystalSize(2) / 2. ;
296 Int_t xdim = (int)( (ximax - ximin ) / phosgeom->GetCrystalSize(0) + 0.5 ) ;
297 Int_t zdim = (int)( (zimax - zimin ) / phosgeom->GetCrystalSize(2) + 0.5 ) ;
83974468 298
9688c1dd 299 // 2. gets the histogram title
83974468 300
9688c1dd 301 Text_t title[100] ;
302 sprintf(title,"Energy=%1.2f GeV ; Digits ; %d ", GetEnergy(), GetDigitsMultiplicity()) ;
83974468 303
9688c1dd 304 if (!histo) {
305 delete histo ;
306 histo = 0 ;
307 }
308 histo = new TH2F("cluster3D", title, xdim, ximin, ximax, zdim, zimin, zimax) ;
83974468 309
9688c1dd 310 Float_t x, z ;
311 for(iDigit=0; iDigit<kMulDigit; iDigit++) {
312 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
313 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
314 phosgeom->RelPosInModule(relid, x, z);
315 histo->Fill(x, z, fEnergyList[iDigit] ) ;
316 }
83974468 317
9688c1dd 318 if (!digitgraph) {
319 digitgraph = new TGraph(kMulDigit,xi,zi);
320 digitgraph-> SetMarkerStyle(5) ;
321 digitgraph-> SetMarkerSize(1.) ;
322 digitgraph-> SetMarkerColor(1) ;
323 digitgraph-> Paint("P") ;
324 }
83974468 325
9688c1dd 326 // Print() ;
327 histocanvas = new TCanvas("cluster", "a single cluster", 600, 500) ;
328 histocanvas->Draw() ;
329 histo->Draw("lego1") ;
83974468 330
9688c1dd 331 delete[] xi ;
332 delete[] zi ;
83974468 333
9688c1dd 334 break;
335 }
83974468 336
9688c1dd 337 case kButton1Up:
338 if (digitgraph) {
339 delete digitgraph ;
340 digitgraph = 0 ;
341 }
342 break;
9f616d61 343
9688c1dd 344 }
9f616d61 345}
346
d15a28e7 347//____________________________________________________________________________
308fb942 348void AliPHOSEmcRecPoint::EvalDispersion(Float_t logWeight,TClonesArray * digits, TVector3 & /* vInc */)
d15a28e7 349{
b2a60966 350 // Calculates the dispersion of the shower at the origine of the RecPoint
91daaf24 351 //DP: should we correct dispersion for non-perpendicular hit????????
352
e5b16749 353 Float_t d = 0. ;
354 Float_t wtot = 0. ;
d15a28e7 355
d084d50d 356 Float_t x = 0.;
357 Float_t z = 0.;
d15a28e7 358
359 AliPHOSDigit * digit ;
7b7c1533 360
686b771f 361 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
e5b16749 362
363 // Calculates the center of gravity in the local PHOS-module coordinates
364
d15a28e7 365 Int_t iDigit;
e5b16749 366
367 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
368 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
369 Int_t relid[4] ;
370 Float_t xi ;
371 Float_t zi ;
372 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
373 phosgeom->RelPosInModule(relid, xi, zi);
f33a3764 374 if (fAmp>0 && fEnergyList[iDigit]>0) {
375 Float_t w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
376 x += xi * w ;
377 z += zi * w ;
378 wtot += w ;
379 }
380 else
381 AliError(Form("Wrong energy %f and/or amplitude %f\n", fEnergyList[iDigit], fAmp));
e5b16749 382 }
f33a3764 383 if (wtot>0) {
384 x /= wtot ;
385 z /= wtot ;
386 }
387 else
388 AliError(Form("Wrong weight %f\n", wtot));
e5b16749 389
390
391// Calculates the dispersion in coordinates
392 wtot = 0.;
88714635 393 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
7932f811 394 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
d15a28e7 395 Int_t relid[4] ;
396 Float_t xi ;
397 Float_t zi ;
92862013 398 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
399 phosgeom->RelPosInModule(relid, xi, zi);
f33a3764 400 if (fAmp>0 && fEnergyList[iDigit]>0) {
401 Float_t w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
402 d += w*((xi-x)*(xi-x) + (zi-z)*(zi-z) ) ;
403 wtot+=w ;
404 }
405 else
406 AliError(Form("Wrong energy %f and/or amplitude %f\n", fEnergyList[iDigit], fAmp));
d15a28e7 407 }
e5b16749 408
7932f811 409
f33a3764 410 if (wtot>0) {
411 d /= wtot ;
412 }
413 else
414 AliError(Form("Wrong weight %f\n", wtot));
d15a28e7 415
f33a3764 416 fDispersion = 0;
417 if (d>=0)
418 fDispersion = TMath::Sqrt(d) ;
91daaf24 419
c63c49e9 420
d15a28e7 421}
fad3e5b9 422//______________________________________________________________________________
e5b16749 423void AliPHOSEmcRecPoint::EvalCoreEnergy(Float_t logWeight, TClonesArray * digits)
fad3e5b9 424{
a4e98857 425 // This function calculates energy in the core,
426 // i.e. within a radius rad = 3cm around the center. Beyond this radius
427 // in accordance with shower profile the energy deposition
fad3e5b9 428 // should be less than 2%
91daaf24 429//DP: non-perpendicular incidence??????????????
fad3e5b9 430
fad3e5b9 431 Float_t coreRadius = 3 ;
432
e5b16749 433 Float_t x = 0 ;
434 Float_t z = 0 ;
fad3e5b9 435
436 AliPHOSDigit * digit ;
7b7c1533 437
686b771f 438 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
88cb7938 439
fad3e5b9 440 Int_t iDigit;
e5b16749 441
442// Calculates the center of gravity in the local PHOS-module coordinates
443 Float_t wtot = 0;
444 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
445 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
446 Int_t relid[4] ;
447 Float_t xi ;
448 Float_t zi ;
449 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
450 phosgeom->RelPosInModule(relid, xi, zi);
f33a3764 451 if (fAmp>0 && fEnergyList[iDigit]>0) {
452 Float_t w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
453 x += xi * w ;
454 z += zi * w ;
455 wtot += w ;
456 }
457 else
458 AliError(Form("Wrong energy %f and/or amplitude %f\n", fEnergyList[iDigit], fAmp));
e5b16749 459 }
f33a3764 460 if (wtot>0) {
461 x /= wtot ;
462 z /= wtot ;
463 }
464 else
465 AliError(Form("Wrong weight %f\n", wtot));
e5b16749 466
467
fad3e5b9 468 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
7932f811 469 digit = (AliPHOSDigit *) ( digits->At(fDigitsList[iDigit]) ) ;
fad3e5b9 470 Int_t relid[4] ;
471 Float_t xi ;
472 Float_t zi ;
473 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
474 phosgeom->RelPosInModule(relid, xi, zi);
475 Float_t distance = TMath::Sqrt((xi-x)*(xi-x)+(zi-z)*(zi-z)) ;
476 if(distance < coreRadius)
7932f811 477 fCoreEnergy += fEnergyList[iDigit] ;
fad3e5b9 478 }
479
91daaf24 480
fad3e5b9 481}
d15a28e7 482
483//____________________________________________________________________________
308fb942 484void AliPHOSEmcRecPoint::EvalElipsAxis(Float_t logWeight,TClonesArray * digits, TVector3 & /* vInc */)
d15a28e7 485{
b2a60966 486 // Calculates the axis of the shower ellipsoid
83974468 487
e8dbb96e 488 Double_t wtot = 0. ;
489 Double_t x = 0.;
490 Double_t z = 0.;
491 Double_t dxx = 0.;
492 Double_t dzz = 0.;
493 Double_t dxz = 0.;
d15a28e7 494
495 AliPHOSDigit * digit ;
7b7c1533 496
686b771f 497 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
7b7c1533 498
d15a28e7 499 Int_t iDigit;
500
e5b16749 501
d15a28e7 502 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
7932f811 503 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
d15a28e7 504 Int_t relid[4] ;
505 Float_t xi ;
506 Float_t zi ;
92862013 507 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
508 phosgeom->RelPosInModule(relid, xi, zi);
f33a3764 509 if (fAmp>0 && fEnergyList[iDigit]>0) {
510 Double_t w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
511 dxx += w * xi * xi ;
512 x += w * xi ;
513 dzz += w * zi * zi ;
514 z += w * zi ;
515 dxz += w * xi * zi ;
516 wtot += w ;
517 }
518 else
519 AliError(Form("Wrong energy %f and/or amplitude %f\n", fEnergyList[iDigit], fAmp));
d15a28e7 520 }
f33a3764 521 if (wtot>0) {
522 dxx /= wtot ;
523 x /= wtot ;
524 dxx -= x * x ;
525 dzz /= wtot ;
526 z /= wtot ;
527 dzz -= z * z ;
528 dxz /= wtot ;
529 dxz -= x * z ;
d15a28e7 530
69183710 531// //Apply correction due to non-perpendicular incidence
532// Double_t CosX ;
533// Double_t CosZ ;
88cb7938 534// AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
7b7c1533 535// AliPHOSGeometry * phosgeom = (AliPHOSGeometry*)gime->PHOSGeometry();
91daaf24 536// Double_t DistanceToIP= (Double_t ) phosgeom->GetIPtoCrystalSurface() ;
69183710 537
538// CosX = DistanceToIP/TMath::Sqrt(DistanceToIP*DistanceToIP+x*x) ;
539// CosZ = DistanceToIP/TMath::Sqrt(DistanceToIP*DistanceToIP+z*z) ;
540
541// dxx = dxx/(CosX*CosX) ;
542// dzz = dzz/(CosZ*CosZ) ;
543// dxz = dxz/(CosX*CosZ) ;
544
545
f33a3764 546 fLambda[0] = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
547 if(fLambda[0] > 0)
548 fLambda[0] = TMath::Sqrt(fLambda[0]) ;
e8dbb96e 549
f33a3764 550 fLambda[1] = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
551 if(fLambda[1] > 0) //To avoid exception if numerical errors lead to negative lambda.
552 fLambda[1] = TMath::Sqrt(fLambda[1]) ;
553 else
554 fLambda[1]= 0. ;
555 }
556 else {
557 AliError(Form("Wrong weight %f\n", wtot));
558 fLambda[0]=fLambda[1]=0.;
559 }
d15a28e7 560}
561
562//____________________________________________________________________________
308fb942 563void AliPHOSEmcRecPoint::EvalMoments(Float_t logWeight,TClonesArray * digits, TVector3 & /* vInc */)
ce2a9a95 564{
565 // Calculate the shower moments in the eigen reference system
566 // M2x, M2z, M3x, M4z
567 // Calculate the angle between the shower position vector and the eigen vector
568
569 Double_t wtot = 0. ;
570 Double_t x = 0.;
571 Double_t z = 0.;
572 Double_t dxx = 0.;
573 Double_t dzz = 0.;
574 Double_t dxz = 0.;
575 Double_t lambda0=0, lambda1=0;
576
577 AliPHOSDigit * digit ;
578
686b771f 579 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
ce2a9a95 580
581 Int_t iDigit;
582
583 // 1) Find covariance matrix elements:
584 // || dxx dxz ||
585 // || dxz dzz ||
586
587 Float_t xi ;
588 Float_t zi ;
589 Int_t relid[4] ;
590 Double_t w;
591 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
592 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
593 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
594 phosgeom->RelPosInModule(relid, xi, zi);
f33a3764 595 if (fAmp>0 && fEnergyList[iDigit]>0) {
596 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
597 x += w * xi ;
598 z += w * zi ;
599 dxx += w * xi * xi ;
600 dzz += w * zi * zi ;
601 dxz += w * xi * zi ;
602 wtot += w ;
603 }
604 else
605 AliError(Form("Wrong energy %f and/or amplitude %f\n", fEnergyList[iDigit], fAmp));
606
ce2a9a95 607 }
f33a3764 608 if (wtot>0) {
609 x /= wtot ;
610 z /= wtot ;
611 dxx /= wtot ;
612 dzz /= wtot ;
613 dxz /= wtot ;
614 dxx -= x * x ;
615 dzz -= z * z ;
616 dxz -= x * z ;
ce2a9a95 617
618 // 2) Find covariance matrix eigen values lambda0 and lambda1
619
f33a3764 620 lambda0 = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
621 lambda1 = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
622 }
623 else {
624 AliError(Form("Wrong weight %f\n", wtot));
625 lambda0=lambda1=0.;
626 }
ce2a9a95 627
628 // 3) Find covariance matrix eigen vectors e0 and e1
629
630 TVector2 e0,e1;
631 if (dxz != 0)
632 e0.Set(1.,(lambda0-dxx)/dxz);
633 else
634 e0.Set(0.,1.);
635
636 e0 = e0.Unit();
637 e1.Set(-e0.Y(),e0.X());
638
639 // 4) Rotate cluster tensor from (x,z) to (e0,e1) system
640 // and calculate moments M3x and M4z
641
642 Float_t cosPhi = e0.X();
643 Float_t sinPhi = e0.Y();
644
645 Float_t xiPHOS ;
646 Float_t ziPHOS ;
647 Double_t dx3, dz3, dz4;
648 wtot = 0.;
649 x = 0.;
650 z = 0.;
651 dxx = 0.;
652 dzz = 0.;
653 dxz = 0.;
654 dx3 = 0.;
655 dz3 = 0.;
656 dz4 = 0.;
657 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
658 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
659 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
660 phosgeom->RelPosInModule(relid, xiPHOS, ziPHOS);
661 xi = xiPHOS*cosPhi + ziPHOS*sinPhi;
662 zi = ziPHOS*cosPhi - xiPHOS*sinPhi;
f33a3764 663 if (fAmp>0 && fEnergyList[iDigit]>0) {
664 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
665 x += w * xi ;
666 z += w * zi ;
667 dxx += w * xi * xi ;
668 dzz += w * zi * zi ;
669 dxz += w * xi * zi ;
670 dx3 += w * xi * xi * xi;
671 dz3 += w * zi * zi * zi ;
672 dz4 += w * zi * zi * zi * zi ;
673 wtot += w ;
674 }
675 else
676 AliError(Form("Wrong energy %f and/or amplitude %f\n", fEnergyList[iDigit], fAmp));
ce2a9a95 677 }
f33a3764 678 if (wtot>0) {
679 x /= wtot ;
680 z /= wtot ;
681 dxx /= wtot ;
682 dzz /= wtot ;
683 dxz /= wtot ;
684 dx3 /= wtot ;
685 dz3 /= wtot ;
686 dz4 /= wtot ;
687 dx3 += -3*dxx*x + 2*x*x*x;
688 dz4 += -4*dz3*z + 6*dzz*z*z -3*z*z*z*z;
689 dxx -= x * x ;
690 dzz -= z * z ;
691 dxz -= x * z ;
692 }
693 else
694 AliError(Form("Wrong weight %f\n", wtot));
ce2a9a95 695
696 // 5) Find an angle between cluster center vector and eigen vector e0
697
f33a3764 698 Float_t phi = 0;
699 if ( (x*x+z*z) > 0 )
700 phi = TMath::ACos ((x*e0.X() + z*e0.Y()) / sqrt(x*x + z*z));
ce2a9a95 701
702 fM2x = lambda0;
703 fM2z = lambda1;
704 fM3x = dx3;
705 fM4z = dz4;
706 fPhixe = phi;
707
708}
c307c629 709//______________________________________________________________________________
710void AliPHOSEmcRecPoint::EvalPrimaries(TClonesArray * digits)
711{
712 // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
713
714 AliPHOSDigit * digit ;
715 Int_t * tempo = new Int_t[fMaxTrack] ;
716
717 //First find digit with maximal energy deposition and copy its primaries
718 Float_t emax=0.;
719 Int_t imaxDigit=0;
720 for(Int_t id=0; id<GetDigitsMultiplicity(); id++){
721 if(emax<fEnergyList[id])
722 imaxDigit=id ;
723 }
724 digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[imaxDigit] )) ;
725 Int_t nprimaries = digit->GetNprimary() ;
726 if ( nprimaries > fMaxTrack ) {
727 fMulTrack = - 1 ;
728 Error("EvalPrimaries", "GetNprimaries ERROR > increase fMaxTrack" ) ;
729 nprimaries = fMaxTrack; //skip the rest
730 }
7fb719de 731 for(fMulTrack=0; fMulTrack<nprimaries ; fMulTrack++){
732 tempo[fMulTrack] = digit->GetPrimary(fMulTrack+1) ;
c307c629 733 }
734
735 //Now add other digits contributions
736 for (Int_t index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
737 if(index==imaxDigit) //already in
738 continue ;
739 digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ;
740 nprimaries = digit->GetNprimary() ;
741 for(Int_t ipr=0; ipr<nprimaries; ipr++){
742 Int_t iprimary = digit->GetPrimary(ipr+1) ;
743 Bool_t notIn=1 ;
744 for(Int_t kndex = 0 ; (kndex < fMulTrack)&& notIn ; kndex++ ) { //check if not already stored
745 if(iprimary == tempo[kndex]){
746 notIn = kFALSE ;
747 }
748 }
749 if(notIn){
750 if(fMulTrack<fMaxTrack){
751 tempo[fMulTrack]=iprimary ;
752 fMulTrack++ ;
753 }
754 else{
755 Error("EvalPrimaries", "GetNprimaries ERROR > increase fMaxTrack!!!" ) ;
756 break ;
757 }
758 }
759 }
760 } // all digits
c307c629 761 if(fMulTrack > 0){
762 if(fTracksList)delete [] fTracksList;
763 fTracksList = new Int_t[fMulTrack] ;
764 }
765 for(Int_t index = 0; index < fMulTrack; index++)
766 fTracksList[index] = tempo[index] ;
767
768 delete [] tempo ;
769
770}
771
ce2a9a95 772//____________________________________________________________________________
7932f811 773void AliPHOSEmcRecPoint::EvalAll(Float_t logWeight, TClonesArray * digits )
ad8cfaf4 774{
e5b16749 775 EvalCoreEnergy(logWeight, digits);
a6eedfad 776 EvalTime(digits) ;
c307c629 777 EvalPrimaries(digits) ;
e957fea8 778 AliPHOSRecPoint::EvalAll(digits) ;
ad8cfaf4 779}
780//____________________________________________________________________________
91daaf24 781void AliPHOSEmcRecPoint::EvalAll(Float_t logWeight, TVector3 &vtx, TClonesArray * digits )
782{
783 // Evaluates all shower parameters
784 TVector3 vInc ;
785 EvalLocalPosition(logWeight, vtx, digits,vInc) ;
786 EvalElipsAxis(logWeight, digits, vInc) ; //they are evaluated with momenta
787 EvalMoments(logWeight, digits, vInc) ;
788 EvalDispersion(logWeight, digits, vInc) ;
789}
790//____________________________________________________________________________
791void AliPHOSEmcRecPoint::EvalLocalPosition(Float_t logWeight, TVector3 &vtx, TClonesArray * digits, TVector3 &vInc)
b2a60966 792{
793 // Calculates the center of gravity in the local PHOS-module coordinates
b2a60966 794 Float_t wtot = 0. ;
795
796 Int_t relid[4] ;
797
798 Float_t x = 0. ;
799 Float_t z = 0. ;
800
801 AliPHOSDigit * digit ;
802
686b771f 803 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
b2a60966 804
805 Int_t iDigit;
806
b2a60966 807 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
7932f811 808 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
b2a60966 809
810 Float_t xi ;
811 Float_t zi ;
812 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
813 phosgeom->RelPosInModule(relid, xi, zi);
f33a3764 814 if (fAmp>0 && fEnergyList[iDigit]>0) {
815 Float_t w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
816 x += xi * w ;
817 z += zi * w ;
818 wtot += w ;
819 }
820 else
821 AliError(Form("Wrong energy %f and/or amplitude %f\n", fEnergyList[iDigit], fAmp));
9ce1a8d9 822 }
f33a3764 823 if (wtot>0) {
824 x /= wtot ;
825 z /= wtot ;
826 }
827 else
828 AliError(Form("Wrong weight %f\n", wtot));
ad8cfaf4 829
830 // Correction for the depth of the shower starting point (TDR p 127)
831 Float_t para = 0.925 ;
832 Float_t parb = 6.52 ;
833
91daaf24 834 phosgeom->GetIncidentVector(vtx,GetPHOSMod(),x,z,vInc) ;
1b799736 835
f33a3764 836 Float_t depthx = 0.;
837 Float_t depthz = 0.;
91daaf24 838 if (fAmp>0&&vInc.Y()!=0.) {
753b19cd 839 depthx = ( para * TMath::Log(fAmp) + parb ) * vInc.X()/TMath::Abs(vInc.Y()) ;
840 depthz = ( para * TMath::Log(fAmp) + parb ) * vInc.Z()/TMath::Abs(vInc.Y()) ;
f33a3764 841 }
842 else
843 AliError(Form("Wrong amplitude %f\n", fAmp));
ad8cfaf4 844
845 fLocPos.SetX(x - depthx) ;
b2a60966 846 fLocPos.SetY(0.) ;
ad8cfaf4 847 fLocPos.SetZ(z - depthz) ;
b2a60966 848
a6eedfad 849 fLocPosM = 0 ;
b2a60966 850}
851
852//____________________________________________________________________________
ad8cfaf4 853Float_t AliPHOSEmcRecPoint::GetMaximalEnergy(void) const
d15a28e7 854{
b2a60966 855 // Finds the maximum energy in the cluster
856
d15a28e7 857 Float_t menergy = 0. ;
858
859 Int_t iDigit;
860
861 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
862
863 if(fEnergyList[iDigit] > menergy)
864 menergy = fEnergyList[iDigit] ;
865 }
866 return menergy ;
867}
868
869//____________________________________________________________________________
fc7e2f43 870Int_t AliPHOSEmcRecPoint::GetMultiplicityAtLevel(Float_t H) const
d15a28e7 871{
b2a60966 872 // Calculates the multiplicity of digits with energy larger than H*energy
873
d15a28e7 874 Int_t multipl = 0 ;
875 Int_t iDigit ;
876 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
877
878 if(fEnergyList[iDigit] > H * fAmp)
879 multipl++ ;
880 }
881 return multipl ;
882}
883
884//____________________________________________________________________________
a0636361 885Int_t AliPHOSEmcRecPoint::GetNumberOfLocalMax( AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
7932f811 886 Float_t locMaxCut,TClonesArray * digits) const
d15a28e7 887{
b2a60966 888 // Calculates the number of local maxima in the cluster using fLocalMaxCut as the minimum
a4e98857 889 // energy difference between two local maxima
b2a60966 890
d15a28e7 891 AliPHOSDigit * digit ;
892 AliPHOSDigit * digitN ;
893
894
895 Int_t iDigitN ;
896 Int_t iDigit ;
897
7932f811 898 for(iDigit = 0; iDigit < fMulDigit; iDigit++)
a0636361 899 maxAt[iDigit] = (AliPHOSDigit*) digits->At(fDigitsList[iDigit]) ;
7932f811 900
d15a28e7 901
6ad0bfa0 902 for(iDigit = 0 ; iDigit < fMulDigit; iDigit++) {
a0636361 903 if(maxAt[iDigit]) {
904 digit = maxAt[iDigit] ;
83974468 905
6ad0bfa0 906 for(iDigitN = 0; iDigitN < fMulDigit; iDigitN++) {
686b771f 907 if(iDigit == iDigitN)
908 continue ;
909
7932f811 910 digitN = (AliPHOSDigit *) digits->At(fDigitsList[iDigitN]) ;
d15a28e7 911
9f616d61 912 if ( AreNeighbours(digit, digitN) ) {
d15a28e7 913 if (fEnergyList[iDigit] > fEnergyList[iDigitN] ) {
a0636361 914 maxAt[iDigitN] = 0 ;
6ad0bfa0 915 // but may be digit too is not local max ?
7932f811 916 if(fEnergyList[iDigit] < fEnergyList[iDigitN] + locMaxCut)
a0636361 917 maxAt[iDigit] = 0 ;
d15a28e7 918 }
919 else {
a0636361 920 maxAt[iDigit] = 0 ;
6ad0bfa0 921 // but may be digitN too is not local max ?
7932f811 922 if(fEnergyList[iDigit] > fEnergyList[iDigitN] - locMaxCut)
a0636361 923 maxAt[iDigitN] = 0 ;
d15a28e7 924 }
925 } // if Areneighbours
926 } // while digitN
927 } // slot not empty
928 } // while digit
929
930 iDigitN = 0 ;
6ad0bfa0 931 for(iDigit = 0; iDigit < fMulDigit; iDigit++) {
a0636361 932 if(maxAt[iDigit]){
d15a28e7 933 maxAt[iDigitN] = maxAt[iDigit] ;
9f616d61 934 maxAtEnergy[iDigitN] = fEnergyList[iDigit] ;
935 iDigitN++ ;
d15a28e7 936 }
937 }
938 return iDigitN ;
939}
9688c1dd 940//____________________________________________________________________________
0bc3b8ed 941void AliPHOSEmcRecPoint::EvalTime(TClonesArray * digits)
942{
943 // Define a rec.point time as a time in the cell with the maximum energy
944
9688c1dd 945 Float_t maxE = 0;
946 Int_t maxAt = 0;
947 for(Int_t idig=0; idig < fMulDigit; idig++){
948 if(fEnergyList[idig] > maxE){
949 maxE = fEnergyList[idig] ;
950 maxAt = idig;
951 }
952 }
953 fTime = ((AliPHOSDigit*) digits->At(fDigitsList[maxAt]))->GetTime() ;
954
955}
d15a28e7 956//____________________________________________________________________________
092b50ba 957void AliPHOSEmcRecPoint::Purify(Float_t threshold){
958 //Removes digits below threshold
959
0fbb8738 960 Int_t * tempo = new Int_t[fMaxDigit];
961 Float_t * tempoE = new Float_t[fMaxDigit];
092b50ba 962
963 Int_t mult = 0 ;
964 for(Int_t iDigit=0;iDigit< fMulDigit ;iDigit++){
965 if(fEnergyList[iDigit] > threshold){
966 tempo[mult] = fDigitsList[iDigit] ;
967 tempoE[mult] = fEnergyList[iDigit] ;
968 mult++ ;
969 }
970 }
971
972 fMulDigit = mult ;
973 delete [] fDigitsList ;
974 delete [] fEnergyList ;
0fbb8738 975 fDigitsList = new Int_t[fMulDigit];
976 fEnergyList = new Float_t[fMulDigit];
092b50ba 977
0458aa58 978 fAmp = 0.; //Recalculate total energy
092b50ba 979 for(Int_t iDigit=0;iDigit< fMulDigit ;iDigit++){
0458aa58 980 fDigitsList[iDigit] = tempo[iDigit];
981 fEnergyList[iDigit] = tempoE[iDigit] ;
982 fAmp+=tempoE[iDigit];
092b50ba 983 }
984
985 delete [] tempo ;
986 delete [] tempoE ;
987
988}
989//____________________________________________________________________________
a8c47ab6 990void AliPHOSEmcRecPoint::Print(Option_t *) const
d15a28e7 991{
b2a60966 992 // Print the list of digits belonging to the cluster
993
21cd0c07 994 TString message ;
995 message = "AliPHOSEmcRecPoint:\n" ;
6f766ada 996 message += "Digit multiplicity = %d" ;
997 message += ", cluster Energy = %f" ;
998 message += ", number of primaries = %d" ;
999 message += ", rec.point index = %d \n" ;
1000 printf(message.Data(), fMulDigit, fAmp, fMulTrack,GetIndexInList() ) ;
d15a28e7 1001
d15a28e7 1002 Int_t iDigit;
6f766ada 1003 printf(" digits ids = ") ;
7932f811 1004 for(iDigit=0; iDigit<fMulDigit; iDigit++)
53ad38d8 1005 printf(" %d ", fDigitsList[iDigit] ) ;
7932f811 1006
6f766ada 1007 printf("\n digit energies = ") ;
7932f811 1008 for(iDigit=0; iDigit<fMulDigit; iDigit++)
53ad38d8 1009 printf(" %f ", fEnergyList[iDigit] ) ;
6f766ada 1010
1011 printf("\n digit primaries ") ;
1012 if (fMulTrack<1) printf("... no primaries");
bc68d12c 1013 for(iDigit = 0;iDigit < fMulTrack; iDigit++)
53ad38d8 1014 printf(" %d ", fTracksList[iDigit]) ;
1015 printf("\n") ;
6f766ada 1016
d15a28e7 1017}
88714635 1018
7932f811 1019