1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //_________________________________________________________________________
17 // Reconstructed Points for the EMCAL
18 // A RecPoint is a cluster of digits
19 //*-- Author: Yves Schutz (SUBATECH)
20 //*-- Author: Dmitri Peressounko (RRC KI & SUBATECH)
21 //*-- Author: Heather Gray (LBL) merged AliEMCALRecPoint and AliEMCALTowerRecPoint 02/04
23 // --- ROOT system ---
26 #include "TPaveText.h"
27 #include "TClonesArray.h"
29 #include "TGeoMatrix.h"
30 #include "TGeoManager.h"
31 #include "TGeoPhysicalNode.h"
33 // --- Standard library ---
34 #include <Riostream.h>
36 // --- AliRoot header files ---
37 //#include "AliGenerator.h"
41 #include "AliGeomManager.h"
42 #include "AliEMCALGeometry.h"
43 #include "AliEMCALHit.h"
44 #include "AliEMCALDigit.h"
45 #include "AliEMCALRecPoint.h"
47 ClassImp(AliEMCALRecPoint)
49 //____________________________________________________________________________
50 AliEMCALRecPoint::AliEMCALRecPoint()
51 : AliCluster(), fGeomPtr(0),
52 fAmp(0), fIndexInList(-1), //to be set when the point is already stored
53 fLocPos(0,0,0), fLocPosM(0),
54 fMaxDigit(100), fMulDigit(0), fMaxTrack(200),
55 fMulTrack(0), fDigitsList(0), fTracksList(0),
56 fClusterType(-1), fCoreEnergy(0), fDispersion(0),
57 fEnergyList(0), fTimeList(0), fAbsIdList(0),
58 fTime(0.), fNExMax(0), fCoreRadius(10), //HG check this
59 fDETracksList(0), fMulParent(0), fMaxParent(0),
60 fParentsList(0), fDEParentsList(0), fSuperModuleNumber(0),
64 fGeomPtr = AliEMCALGeometry::GetInstance();
71 //____________________________________________________________________________
72 AliEMCALRecPoint::AliEMCALRecPoint(const char *)
73 : AliCluster(), fGeomPtr(0),
74 fAmp(0), fIndexInList(-1), //to be set when the point is already stored
75 fLocPos(0,0,0), fLocPosM(new TMatrixF(3,3)),
76 fMaxDigit(100), fMulDigit(0), fMaxTrack(1000), fMulTrack(0),
77 fDigitsList(new Int_t[fMaxDigit]), fTracksList(new Int_t[fMaxTrack]),
78 fClusterType(-1), fCoreEnergy(0), fDispersion(0),
79 fEnergyList(new Float_t[fMaxDigit]), fTimeList(new Float_t[fMaxDigit]),
80 fAbsIdList(new Int_t[fMaxDigit]), fTime(-1.), fNExMax(0), fCoreRadius(10),
81 fDETracksList(new Float_t[fMaxTrack]), fMulParent(0), fMaxParent(1000),
82 fParentsList(new Int_t[fMaxParent]), fDEParentsList(new Float_t[fMaxParent]),
83 fSuperModuleNumber(0), fDigitIndMax(-1)
86 for (Int_t i = 0; i < fMaxTrack; i++)
88 for (Int_t i = 0; i < fMaxParent; i++) {
90 fDEParentsList[i] = 0;
93 fGeomPtr = AliEMCALGeometry::GetInstance();
98 //____________________________________________________________________________
99 AliEMCALRecPoint::AliEMCALRecPoint(const AliEMCALRecPoint & rp)
100 : AliCluster(rp), fGeomPtr(rp.fGeomPtr),
101 fAmp(rp.fAmp), fIndexInList(rp.fIndexInList),
102 fLocPos(rp.fLocPos), fLocPosM(rp.fLocPosM),
103 fMaxDigit(rp.fMaxDigit), fMulDigit(rp.fMulDigit),
104 fMaxTrack(rp.fMaxTrack), fMulTrack(rp.fMaxTrack),
105 fDigitsList(new Int_t[rp.fMaxDigit]), fTracksList(new Int_t[rp.fMaxTrack]),
106 fClusterType(rp.fClusterType), fCoreEnergy(rp.fCoreEnergy),
107 fDispersion(rp.fDispersion),
108 fEnergyList(new Float_t[rp.fMaxDigit]), fTimeList(new Float_t[rp.fMaxDigit]),
109 fAbsIdList(new Int_t[rp.fMaxDigit]), fTime(rp.fTime), fNExMax(rp.fNExMax),fCoreRadius(rp.fCoreRadius),
110 fDETracksList(new Float_t[rp.fMaxTrack]), fMulParent(rp.fMulParent),
111 fMaxParent(rp.fMaxParent), fParentsList(new Int_t[rp.fMaxParent]),
112 fDEParentsList(new Float_t[rp.fMaxParent]),
113 fSuperModuleNumber(rp.fSuperModuleNumber), fDigitIndMax(rp.fDigitIndMax)
116 fLambda[0] = rp.fLambda[0];
117 fLambda[1] = rp.fLambda[1];
119 for(Int_t i = 0; i < rp.fMulDigit; i++) {
120 fEnergyList[i] = rp.fEnergyList[i];
121 fTimeList[i] = rp.fTimeList[i];
122 fAbsIdList[i] = rp.fAbsIdList[i];
125 for(Int_t i = 0; i < rp.fMulTrack; i++) fDETracksList[i] = rp.fDETracksList[i];
127 for(Int_t i = 0; i < rp.fMulParent; i++) {
128 fParentsList[i] = rp.fParentsList[i];
129 fDEParentsList[i] = rp.fDEParentsList[i];
133 //____________________________________________________________________________
134 AliEMCALRecPoint::~AliEMCALRecPoint()
138 delete[] fEnergyList ;
142 delete[] fAbsIdList ;
144 delete[] fDETracksList;
146 delete[] fParentsList;
148 delete[] fDEParentsList;
151 delete [] fDigitsList ;
152 delete [] fTracksList ;
155 //____________________________________________________________________________
156 AliEMCALRecPoint& AliEMCALRecPoint::operator= (const AliEMCALRecPoint &rp)
158 // assignment operator
160 if(&rp == this) return *this;
162 fGeomPtr = rp.fGeomPtr;
164 fIndexInList = rp.fIndexInList;
165 fLocPos = rp.fLocPos;
166 fLocPosM = rp.fLocPosM;
167 fMaxDigit = rp.fMaxDigit;
168 fMulDigit = rp.fMulDigit;
169 fMaxTrack = rp.fMaxTrack;
170 fMulTrack = rp.fMaxTrack;
171 for(Int_t i = 0; i<fMaxDigit; i++) fDigitsList[i] = rp.fDigitsList[i];
172 for(Int_t i = 0; i<fMaxTrack; i++) fTracksList[i] = rp.fTracksList[i];
173 fClusterType = rp.fClusterType;
174 fCoreEnergy = rp.fCoreEnergy;
175 fDispersion = rp.fDispersion;
176 for(Int_t i = 0; i<fMaxDigit; i++) {
177 fEnergyList[i] = rp.fEnergyList[i];
178 fTimeList[i] = rp.fTimeList[i];
179 fAbsIdList[i] = rp.fAbsIdList[i];
182 fNExMax = rp.fNExMax;
183 fCoreRadius = rp.fCoreRadius;
184 for(Int_t i = 0; i < fMaxTrack; i++) fDETracksList[i] = rp.fDETracksList[i];
185 fMulParent = rp.fMulParent;
186 fMaxParent = rp.fMaxParent;
187 for(Int_t i = 0; i < fMaxParent; i++) {
188 fParentsList[i] = rp.fParentsList[i];
189 fDEParentsList[i] = rp.fDEParentsList[i];
191 fSuperModuleNumber = rp.fSuperModuleNumber;
192 fDigitIndMax = rp.fDigitIndMax;
194 fLambda[0] = rp.fLambda[0];
195 fLambda[1] = rp.fLambda[1];
201 //____________________________________________________________________________
202 void AliEMCALRecPoint::AddDigit(AliEMCALDigit & digit, Float_t Energy)
204 // Adds a digit to the RecPoint
205 // and accumulates the total amplitude and the multiplicity
208 fEnergyList = new Float_t[fMaxDigit];
210 fTimeList = new Float_t[fMaxDigit];
211 if(fAbsIdList == 0) {
212 fAbsIdList = new Int_t[fMaxDigit];
215 if ( fMulDigit >= fMaxDigit ) { // increase the size of the lists
217 Int_t * tempo = new Int_t[fMaxDigit];
218 Float_t * tempoE = new Float_t[fMaxDigit];
219 Float_t * tempoT = new Float_t[fMaxDigit];
220 Int_t * tempoId = new Int_t[fMaxDigit];
223 for ( index = 0 ; index < fMulDigit ; index++ ){
224 tempo[index] = fDigitsList[index] ;
225 tempoE[index] = fEnergyList[index] ;
226 tempoT[index] = fTimeList[index] ;
227 tempoId[index] = fAbsIdList[index] ;
230 delete [] fDigitsList ;
231 delete [] fEnergyList ;
232 delete [] fTimeList ;
233 delete [] fAbsIdList ;
236 fEnergyList = tempoE;
238 fAbsIdList = tempoId;
241 fDigitsList[fMulDigit] = digit.GetIndexInList() ;
242 fEnergyList[fMulDigit] = Energy ;
243 fTimeList[fMulDigit] = digit.GetTimeR() ;
244 fAbsIdList[fMulDigit] = digit.GetId();
248 //JLK 10-Oct-2007 this hasn't been filled before because it was in
249 //the wrong place in previous versions.
250 //Now we evaluate it only if the supermodulenumber for this recpoint
251 //has not yet been set (or is the 0th one)
252 if(fSuperModuleNumber == 0)
253 fSuperModuleNumber = fGeomPtr->GetSuperModuleNumber(digit.GetId());
256 //____________________________________________________________________________
257 Bool_t AliEMCALRecPoint::AreNeighbours(AliEMCALDigit * digit1, AliEMCALDigit * digit2 ) const
259 // Tells if (true) or not (false) two digits are neighbours
260 // A neighbour is defined as being two digits which share a corner
262 static Bool_t areNeighbours = kFALSE ;
263 static Int_t nSupMod=0, nModule=0, nIphi=0, nIeta=0;
264 static int nSupMod1=0, nModule1=0, nIphi1=0, nIeta1=0;
265 static Int_t relid1[2] , relid2[2] ; // ieta, iphi
266 static Int_t rowdiff=0, coldiff=0;
268 areNeighbours = kFALSE ;
270 fGeomPtr->GetCellIndex(digit1->GetId(), nSupMod,nModule,nIphi,nIeta);
271 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, relid1[0],relid1[1]);
273 fGeomPtr->GetCellIndex(digit2->GetId(), nSupMod1,nModule1,nIphi1,nIeta1);
274 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod1,nModule1,nIphi1,nIeta1, relid2[0],relid2[1]);
276 rowdiff = TMath::Abs( relid1[0] - relid2[0] ) ;
277 coldiff = TMath::Abs( relid1[1] - relid2[1] ) ;
279 if (( coldiff <= 1 ) && ( rowdiff <= 1 ) && (coldiff + rowdiff > 0))
280 areNeighbours = kTRUE ;
282 return areNeighbours;
285 //____________________________________________________________________________
286 Int_t AliEMCALRecPoint::Compare(const TObject * obj) const
288 // Compares two RecPoints according to their position in the EMCAL modules
290 Float_t delta = 1 ; //Width of "Sorting row". If you change this
291 //value (what is senseless) change as well delta in
292 //AliEMCALTrackSegmentMakerv* and other RecPoints...
295 AliEMCALRecPoint * clu = (AliEMCALRecPoint *)obj ;
298 GetLocalPosition(locpos1);
300 clu->GetLocalPosition(locpos2);
302 Int_t rowdif = (Int_t)(TMath::Ceil(locpos1.X()/delta)-TMath::Ceil(locpos2.X()/delta)) ;
307 else if(locpos1.Y()>locpos2.Y())
315 //____________________________________________________________________________
316 Int_t AliEMCALRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
318 // Compute distance from point px,py to a AliEMCALRecPoint considered as a Tmarker
319 // Compute the closest distance of approach from point px,py to this marker.
320 // The distance is computed in pixels units.
321 // HG Still need to update -> Not sure what this should achieve
323 TVector3 pos(0.,0.,0.) ;
324 GetLocalPosition(pos) ;
325 Float_t x = pos.X() ;
326 Float_t y = pos.Y() ;
327 const Int_t kMaxDiff = 10;
328 Int_t pxm = gPad->XtoAbsPixel(x);
329 Int_t pym = gPad->YtoAbsPixel(y);
330 Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
332 if (dist > kMaxDiff) return 9999;
336 //___________________________________________________________________________
337 void AliEMCALRecPoint::Draw(Option_t *option)
339 // Draw this AliEMCALRecPoint with its current attributes
344 //______________________________________________________________________________
345 void AliEMCALRecPoint::ExecuteEvent(Int_t /*event*/, Int_t, Int_t)
347 // Execute action corresponding to one event
348 // This member function is called when a AliEMCALRecPoint is clicked with the locator
350 // If Left button is clicked on AliEMCALRecPoint, the digits are switched on
351 // and switched off when the mouse button is released.
353 // static Int_t pxold, pyold;
355 /* static TGraph * digitgraph = 0 ;
356 static TPaveText* clustertext = 0 ;
358 if (!gPad->IsEditable()) return;
364 AliEMCALDigit * digit ;
369 const Int_t kMulDigit=AliEMCALRecPoint::GetDigitsMultiplicity() ;
370 Float_t * xi = new Float_t [kMulDigit] ;
371 Float_t * zi = new Float_t [kMulDigit] ;
373 for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
374 Fatal("AliEMCALRecPoint::ExecuteEvent", " -> Something wrong with the code");
375 digit = 0 ; //dynamic_cast<AliEMCALDigit *>((fDigitsList)[iDigit]);
376 fGeomPtr->AbsToRelNumbering(digit->GetId(), relid) ;
377 fGeomPtr->PosInAlice(relid, xi[iDigit], zi[iDigit]) ;
381 digitgraph = new TGraph(fMulDigit,xi,zi);
382 digitgraph-> SetMarkerStyle(5) ;
383 digitgraph-> SetMarkerSize(1.) ;
384 digitgraph-> SetMarkerColor(1) ;
385 digitgraph-> Draw("P") ;
389 TVector3 pos(0.,0.,0.) ;
390 GetLocalPosition(pos) ;
391 clustertext = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+50,pos.Z()+35,"") ;
394 sprintf(line1,"Energy=%1.2f GeV",GetEnergy()) ;
395 sprintf(line2,"%d Digits",GetDigitsMultiplicity()) ;
396 clustertext ->AddText(line1) ;
397 clustertext ->AddText(line2) ;
398 clustertext ->Draw("");
422 //____________________________________________________________________________
423 void AliEMCALRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits)
425 // Evaluates all shower parameters
426 EvalLocalPosition(logWeight, digits) ;
427 EvalElipsAxis(logWeight, digits) ;
428 EvalDispersion(logWeight, digits) ;
429 //EvalCoreEnergy(logWeight, digits);
431 EvalPrimaries(digits) ;
434 //Called last because it sets the global position of the cluster?
435 EvalLocal2TrackingCSTransform();
439 //____________________________________________________________________________
440 void AliEMCALRecPoint::EvalDispersion(Float_t logWeight, TClonesArray * digits)
442 // Calculates the dispersion of the shower at the origin of the RecPoint
443 // in cell units - Nov 16,2006
445 Double_t d = 0., wtot = 0., w = 0.;
446 Int_t iDigit=0, nstat=0;
447 AliEMCALDigit * digit ;
449 // Calculates the dispersion in cell units
450 Double_t etai, phii, etaMean=0.0, phiMean=0.0;
451 int nSupMod=0, nModule=0, nIphi=0, nIeta=0;
453 // Calculate mean values
454 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
455 digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
457 if (fAmp>0 && fEnergyList[iDigit]>0) {
458 fGeomPtr->GetCellIndex(digit->GetId(), nSupMod,nModule,nIphi,nIeta);
459 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
462 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
474 } else AliError(Form("Wrong weight %f\n", wtot));
476 // Calculate dispersion
477 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
478 digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
480 if (fAmp>0 && fEnergyList[iDigit]>0) {
481 fGeomPtr->GetCellIndex(digit->GetId(), nSupMod,nModule,nIphi,nIeta);
482 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
485 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
489 d += w*((etai-etaMean)*(etai-etaMean)+(phii-phiMean)*(phii-phiMean));
494 if ( wtot > 0 && nstat>1) d /= wtot ;
497 fDispersion = TMath::Sqrt(d) ;
500 //____________________________________________________________________________
501 void AliEMCALRecPoint::EvalLocalPosition(Float_t logWeight, TClonesArray * digits)
503 // Calculates the center of gravity in the local EMCAL-module coordinates
504 // Info("Print", " logWeight %f : cluster energy %f ", logWeight, fAmp); // for testing
506 static Double_t dist;
508 AliEMCALDigit * digit;
509 Int_t i=0, nstat=0, idMax=-1;
510 Double_t clXYZ[3]={0.,0.,0.}, clRmsXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.;
512 //printf(" dist : %f e : %f \n", dist, fAmp);
513 for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
514 digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
516 idMax = digit->GetId(); // is it correct
517 dist = TmaxInCm(Double_t(fAmp));
519 fGeomPtr->RelPosCellInSModule(digit->GetId(), idMax, dist, xyzi[0], xyzi[1], xyzi[2]);
520 //printf(" Id %i : dist %f Local x,y,z %f %f %f \n", digit->GetId(), dist, xyzi[0], xyzi[1], xyzi[2]);
522 //fGeomPtr->RelPosCellInSModule(digit->GetId(), xyzi[0], xyzi[1], xyzi[2]);
523 //printf(" Id %i : dist %f Local x,y,z %f %f %f \n", digit->GetId(), 0.0, xyzi[0], xyzi[1], xyzi[2]);
524 // if(fAmp>102.) assert(0);
526 if(logWeight > 0.0) w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ));
527 else w = fEnergyList[iDigit]; // just energy
532 for(i=0; i<3; i++ ) {
533 clXYZ[i] += (w*xyzi[i]);
534 clRmsXYZ[i] += (w*xyzi[i]*xyzi[i]);
538 // cout << " wtot " << wtot << endl;
540 // xRMS = TMath::Sqrt(x2m - xMean*xMean);
541 for(i=0; i<3; i++ ) {
544 clRmsXYZ[i] /= (wtot*wtot);
545 clRmsXYZ[i] = clRmsXYZ[i] - clXYZ[i]*clXYZ[i];
546 if(clRmsXYZ[i] > 0.0) {
547 clRmsXYZ[i] = TMath::Sqrt(clRmsXYZ[i]);
548 } else clRmsXYZ[i] = 0;
549 } else clRmsXYZ[i] = 0;
552 for(i=0; i<3; i++ ) {
553 clXYZ[i] = clRmsXYZ[i] = -1.;
557 fLocPos.SetX(clXYZ[0]);
558 fLocPos.SetY(clXYZ[1]);
559 fLocPos.SetZ(clXYZ[2]);
562 // printf("EvalLocalPosition: eta,phi,r = %f,%f,%f", fLocPos.X(), fLocPos.Y(), fLocPos.Z()) ;
563 fLocPosM = 0 ; // covariance matrix
566 //____________________________________________________________________________
567 void AliEMCALRecPoint::EvalLocalPositionFit(Double_t deff, Double_t logWeight,
568 Double_t phiSlope, TClonesArray * digits)
570 // Aug 14-16, 2007 - for fit
571 // Aug 31 - should be static ??
572 static Double_t dist, ycorr;
573 static AliEMCALDigit *digit;
575 Int_t i=0, nstat=0, idMax=-1;
576 Double_t clXYZ[3]={0.,0.,0.}, clRmsXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.;
578 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
579 digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
581 idMax = digit->GetId(); // is it correct
582 dist = TmaxInCm(Double_t(fAmp));
586 fGeomPtr->RelPosCellInSModule(digit->GetId(), idMax, dist, xyzi[0], xyzi[1], xyzi[2]);
588 if(logWeight > 0.0) w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ));
589 else w = fEnergyList[iDigit]; // just energy
594 for(i=0; i<3; i++ ) {
595 clXYZ[i] += (w*xyzi[i]);
596 clRmsXYZ[i] += (w*xyzi[i]*xyzi[i]);
600 // cout << " wtot " << wtot << endl;
602 // xRMS = TMath::Sqrt(x2m - xMean*xMean);
603 for(i=0; i<3; i++ ) {
606 clRmsXYZ[i] /= (wtot*wtot);
607 clRmsXYZ[i] = clRmsXYZ[i] - clXYZ[i]*clXYZ[i];
608 if(clRmsXYZ[i] > 0.0) {
609 clRmsXYZ[i] = TMath::Sqrt(clRmsXYZ[i]);
610 } else clRmsXYZ[i] = 0;
611 } else clRmsXYZ[i] = 0;
614 for(i=0; i<3; i++ ) {
615 clXYZ[i] = clRmsXYZ[i] = -1.;
619 if(phiSlope != 0.0 && logWeight > 0.0 && wtot) {
620 // Correction in phi direction (y - coords here); Aug 16;
621 // May be put to global level or seperate method
622 ycorr = clXYZ[1] * (1. + phiSlope);
623 //printf(" y %f : ycorr %f : slope %f \n", clXYZ[1], ycorr, phiSlope);
626 fLocPos.SetX(clXYZ[0]);
627 fLocPos.SetY(clXYZ[1]);
628 fLocPos.SetZ(clXYZ[2]);
631 // printf("EvalLocalPosition: eta,phi,r = %f,%f,%f", fLocPos.X(), fLocPos.Y(), fLocPos.Z()) ;
632 fLocPosM = 0 ; // covariance matrix
635 //_____________________________________________________________________________
636 Bool_t AliEMCALRecPoint::EvalLocalPosition2(TClonesArray * digits, TArrayD &ed)
638 // Evaluated local position of rec.point using digits
639 // and parametrisation of w0 and deff
640 //printf(" <I> AliEMCALRecPoint::EvalLocalPosition2() \n");
641 return AliEMCALRecPoint::EvalLocalPositionFromDigits(digits, ed, fLocPos);
644 //_____________________________________________________________________________
645 Bool_t AliEMCALRecPoint::EvalLocalPositionFromDigits(TClonesArray *digits, TArrayD &ed, TVector3 &locPos)
647 // Used when digits should be recalibrated
648 static Double_t deff, w0, esum;
650 // static AliEMCALDigit *digit;
652 if(ed.GetSize() && (digits->GetEntries()!=ed.GetSize())) return kFALSE;
654 // Calculate sum energy of digits
656 for(iDigit=0; iDigit<ed.GetSize(); iDigit++) esum += ed[iDigit];
658 GetDeffW0(esum, deff, w0);
660 return EvalLocalPositionFromDigits(esum, deff, w0, digits, ed, locPos);
663 //_____________________________________________________________________________
664 Bool_t AliEMCALRecPoint::EvalLocalPositionFromDigits(const Double_t esum, const Double_t deff, const Double_t w0, TClonesArray *digits, TArrayD &ed, TVector3 &locPos)
666 static AliEMCALDigit *digit;
668 Int_t i=0, nstat=0, idMax=-1;
669 Double_t clXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.;
671 // Get pointer to EMCAL geometry
672 // (can't use fGeomPtr in static method)
673 AliEMCALGeometry* geo = AliEMCALGeometry::GetInstance();
675 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
676 digit = dynamic_cast<AliEMCALDigit *>(digits->At(iDigit));
678 geo->RelPosCellInSModule(digit->GetId(), idMax, deff, xyzi[0], xyzi[1], xyzi[2]);
680 if(w0 > 0.0) w = TMath::Max( 0., w0 + TMath::Log(ed[iDigit] / esum));
681 else w = ed[iDigit]; // just energy
686 for(i=0; i<3; i++ ) {
687 clXYZ[i] += (w*xyzi[i]);
691 // cout << " wtot " << wtot << endl;
693 for(i=0; i<3; i++ ) {
696 locPos.SetX(clXYZ[0]);
697 locPos.SetY(clXYZ[1]);
698 locPos.SetZ(clXYZ[2]);
706 //_____________________________________________________________________________
707 void AliEMCALRecPoint::GetDeffW0(const Double_t esum , Double_t &deff, Double_t &w0)
711 // Applied for simulation data with threshold 3 adc
712 // Calculate efective distance (deff) and weigh parameter (w0)
713 // for coordinate calculation; 0.5 GeV < esum <100 GeV.
714 // Look to: http://rhic.physics.wayne.edu/~pavlinov/ALICE/SHISHKEBAB/RES/CALIB/GEOMCORR/deffandW0VaEgamma_2.gif
716 static Double_t e=0.0;
717 const Double_t kdp0=9.25147, kdp1=1.16700; // Hard coded now
718 const Double_t kwp0=4.83713, kwp1=-2.77970e-01, kwp2 = 4.41116;
720 // No extrapolation here
721 e = esum<0.5?0.5:esum;
724 deff = kdp0 + kdp1*TMath::Log(e);
725 w0 = kwp0 / (1. + TMath::Exp(kwp1*(e+kwp2)));
726 //printf("<I> AliEMCALRecPoint::GetDeffW0 esum %5.2f : deff %5.2f : w0 %5.2f \n", esum, deff, w0);
729 //______________________________________________________________________________
730 void AliEMCALRecPoint::EvalCoreEnergy(Float_t logWeight, TClonesArray * digits)
732 // This function calculates energy in the core,
733 // i.e. within a radius rad = fCoreEnergy around the center. Beyond this radius
734 // in accordance with shower profile the energy deposition
735 // should be less than 2%
736 // Unfinished - Nov 15,2006
737 // Distance is calculate in (phi,eta) units
739 AliEMCALDigit * digit ;
743 if (!fLocPos.Mag()) {
744 EvalLocalPosition(logWeight, digits);
747 Double_t phiPoint = fLocPos.Phi(), etaPoint = fLocPos.Eta();
748 Double_t eta, phi, distance;
749 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
750 digit = (AliEMCALDigit *) ( digits->At(fDigitsList[iDigit]) ) ;
753 fGeomPtr->EtaPhiFromIndex(digit->GetId(),eta, phi) ;
754 phi = phi * TMath::DegToRad();
756 distance = TMath::Sqrt((eta-etaPoint)*(eta-etaPoint)+(phi-phiPoint)*(phi-phiPoint));
757 if(distance < fCoreRadius)
758 fCoreEnergy += fEnergyList[iDigit] ;
762 //____________________________________________________________________________
763 void AliEMCALRecPoint::EvalElipsAxis(Float_t logWeight,TClonesArray * digits)
765 // Calculates the axis of the shower ellipsoid in eta and phi
768 static TString gn(fGeomPtr->GetName());
777 AliEMCALDigit * digit = 0;
779 Double_t etai , phii, w;
780 int nSupMod=0, nModule=0, nIphi=0, nIeta=0;
782 for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
783 digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
785 // Nov 15,2006 - use cell numbers as coordinates
786 // Copied for shish-kebab geometry, ieta,iphi is cast as double as eta,phi
787 // We can use the eta,phi(or coordinates) of cell
788 nSupMod = nModule = nIphi = nIeta = iphi = ieta = 0;
790 fGeomPtr->GetCellIndex(digit->GetId(), nSupMod,nModule,nIphi,nIeta);
791 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
795 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
796 // fAmp summed amplitude of digits, i.e. energy of recpoint
797 // Gives smaller value of lambda than log weight
798 // w = fEnergyList[iDigit] / fAmp; // Nov 16, 2006 - try just energy
800 dxx += w * etai * etai ;
802 dzz += w * phii * phii ;
805 dxz += w * etai * phii ;
820 fLambda[0] = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
822 fLambda[0] = TMath::Sqrt(fLambda[0]) ;
826 fLambda[1] = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
828 if(fLambda[1] > 0) //To avoid exception if numerical errors lead to negative lambda.
829 fLambda[1] = TMath::Sqrt(fLambda[1]) ;
837 // printf("Evalaxis: lambdas = %f,%f", fLambda[0],fLambda[1]) ;
841 //______________________________________________________________________________
842 void AliEMCALRecPoint::EvalPrimaries(TClonesArray * digits)
844 // Constructs the list of primary particles (tracks) which
845 // have contributed to this RecPoint and calculate deposited energy
848 AliEMCALDigit * digit ;
849 Int_t * primArray = new Int_t[fMaxTrack] ;
850 Float_t * dEPrimArray = new Float_t[fMaxTrack] ;
853 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
854 digit = dynamic_cast<AliEMCALDigit *>(digits->At( fDigitsList[index] )) ;
855 Int_t nprimaries = digit->GetNprimary() ;
856 if ( nprimaries == 0 ) continue ;
858 for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
859 if ( fMulTrack > fMaxTrack ) {
860 fMulTrack = fMaxTrack ;
861 Error("EvalPrimaries", "increase fMaxTrack ") ;
864 Int_t newPrimary = digit->GetPrimary(jndex+1);
865 Float_t dEPrimary = digit->GetDEPrimary(jndex+1);
867 Bool_t already = kFALSE ;
868 for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
869 if ( newPrimary == primArray[kndex] ){
871 dEPrimArray[kndex] += dEPrimary;
875 if ( !already && (fMulTrack < fMaxTrack)) { // store it
876 primArray[fMulTrack] = newPrimary ;
877 dEPrimArray[fMulTrack] = dEPrimary ;
880 } // all primaries in digit
883 Int_t *sortIdx = new Int_t[fMulTrack];
884 TMath::Sort(fMulTrack,dEPrimArray,sortIdx);
885 for(index = 0; index < fMulTrack; index++) {
886 fTracksList[index] = primArray[sortIdx[index]] ;
887 fDETracksList[index] = dEPrimArray[sortIdx[index]] ;
890 delete [] primArray ;
891 delete [] dEPrimArray ;
895 //______________________________________________________________________________
896 void AliEMCALRecPoint::EvalParents(TClonesArray * digits)
898 // Constructs the list of parent particles (tracks) which have contributed to this RecPoint
900 AliEMCALDigit * digit ;
901 Int_t * parentArray = new Int_t[fMaxTrack] ;
902 Float_t * dEParentArray = new Float_t[fMaxTrack] ;
905 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
906 if (fDigitsList[index] >= digits->GetEntries() || fDigitsList[index] < 0)
907 AliError(Form("Trying to get invalid digit %d (idx in WriteRecPoint %d)",fDigitsList[index],index));
908 digit = dynamic_cast<AliEMCALDigit *>(digits->At( fDigitsList[index] )) ;
909 Int_t nparents = digit->GetNiparent() ;
910 if ( nparents == 0 ) continue ;
913 for ( jndex = 0 ; jndex < nparents ; jndex++ ) { // all primaries in digit
914 if ( fMulParent > fMaxParent ) {
916 Error("EvalParents", "increase fMaxParent") ;
919 Int_t newParent = digit->GetIparent(jndex+1) ;
920 Float_t newdEParent = digit->GetDEParent(jndex+1) ;
922 Bool_t already = kFALSE ;
923 for ( kndex = 0 ; kndex < fMulParent ; kndex++ ) { //check if not already stored
924 if ( newParent == parentArray[kndex] ){
925 dEParentArray[kndex] += newdEParent;
930 if ( !already && (fMulParent < fMaxParent)) { // store it
931 parentArray[fMulParent] = newParent ;
932 dEParentArray[fMulParent] = newdEParent ;
935 } // all parents in digit
939 Int_t *sortIdx = new Int_t[fMulParent];
940 TMath::Sort(fMulParent,dEParentArray,sortIdx);
941 for(index = 0; index < fMulParent; index++) {
942 fParentsList[index] = parentArray[sortIdx[index]] ;
943 fDEParentsList[index] = dEParentArray[sortIdx[index]] ;
948 delete [] parentArray;
949 delete [] dEParentArray;
952 //____________________________________________________________________________
953 void AliEMCALRecPoint::GetLocalPosition(TVector3 & lpos) const
955 // returns the position of the cluster in the local reference system
956 // of the sub-detector
961 //____________________________________________________________________________
962 void AliEMCALRecPoint::GetGlobalPosition(TVector3 & gpos) const
964 // returns the position of the cluster in the global reference system of ALICE
965 // These are now the Cartesian X, Y and Z
966 // cout<<" geom "<<geom<<endl;
967 fGeomPtr->GetGlobal(fLocPos, gpos, fSuperModuleNumber);
971 //____________________________________________________________________________
972 void AliEMCALRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrixF & gmat) const
974 // returns the position of the cluster in the global reference system of ALICE
975 // These are now the Cartesian X, Y and Z
976 // cout<<" geom "<<geom<<endl;
979 fGeomPtr->GetGlobalEMCAL(this, gpos, gmat);
983 //_____________________________________________________________________________
984 void AliEMCALRecPoint::EvalLocal2TrackingCSTransform()
986 //Evaluates local to "tracking" c.s. transformation (B.P.).
987 //All evaluations should be completed before calling for this
989 //See ALICE PPR Chapter 5 p.18 for "tracking" c.s. definition,
990 //or just ask Jouri Belikov. :)
992 SetVolumeId(AliGeomManager::LayerToVolUID(AliGeomManager::kEMCAL,GetSuperModuleNumber()));
994 const TGeoHMatrix* tr2loc = GetTracking2LocalMatrix();
995 if(!tr2loc) AliFatal(Form("No Tracking2LocalMatrix found."));
997 Double_t lxyz[3] = {fLocPos.X(),fLocPos.Y(),fLocPos.Z()};
998 Double_t txyz[3] = {0,0,0};
1000 tr2loc->MasterToLocal(lxyz,txyz);
1001 SetX(txyz[0]); SetY(txyz[1]); SetZ(txyz[2]);
1003 if(AliLog::GetGlobalDebugLevel()>0) {
1004 TVector3 gpos; TMatrixF gmat;
1005 GetGlobalPosition(gpos,gmat);
1008 AliInfo(Form("lCS-->(%.3f,%.3f,%.3f), tCS-->(%.3f,%.3f,%.3f), gCS-->(%.3f,%.3f,%.3f), gCScalc-\
1009 ->(%.3f,%.3f,%.3f), supermodule %d",
1010 fLocPos.X(),fLocPos.Y(),fLocPos.Z(),
1011 GetX(),GetY(),GetZ(),
1012 gpos.X(),gpos.Y(),gpos.Z(),
1013 gxyz[0],gxyz[1],gxyz[2],GetSuperModuleNumber()));
1018 //____________________________________________________________________________
1019 Float_t AliEMCALRecPoint::GetMaximalEnergy(void) const
1021 // Finds the maximum energy in the cluster
1023 Float_t menergy = 0. ;
1027 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
1029 if(fEnergyList[iDigit] > menergy)
1030 menergy = fEnergyList[iDigit] ;
1035 //____________________________________________________________________________
1036 Int_t AliEMCALRecPoint::GetMultiplicityAtLevel(Float_t H) const
1038 // Calculates the multiplicity of digits with energy larger than H*energy
1042 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
1044 if(fEnergyList[iDigit] > H * fAmp)
1050 //____________________________________________________________________________
1051 Int_t AliEMCALRecPoint::GetNumberOfLocalMax(AliEMCALDigit ** maxAt, Float_t * maxAtEnergy,
1052 Float_t locMaxCut,TClonesArray * digits) const
1054 // Calculates the number of local maxima in the cluster using fLocalMaxCut as the minimum
1055 // energy difference between two local maxima
1057 AliEMCALDigit * digit ;
1058 AliEMCALDigit * digitN ;
1063 for(iDigit = 0; iDigit < fMulDigit; iDigit++)
1064 maxAt[iDigit] = (AliEMCALDigit*) digits->At(fDigitsList[iDigit]) ;
1066 for(iDigit = 0 ; iDigit < fMulDigit; iDigit++) {
1068 digit = maxAt[iDigit] ;
1070 for(iDigitN = 0; iDigitN < fMulDigit; iDigitN++) {
1071 digitN = (AliEMCALDigit *) digits->At(fDigitsList[iDigitN]) ;
1073 if ( AreNeighbours(digit, digitN) ) {
1074 if (fEnergyList[iDigit] > fEnergyList[iDigitN] ) {
1075 maxAt[iDigitN] = 0 ;
1076 // but may be digit too is not local max ?
1077 if(fEnergyList[iDigit] < fEnergyList[iDigitN] + locMaxCut)
1082 // but may be digitN too is not local max ?
1083 if(fEnergyList[iDigit] > fEnergyList[iDigitN] - locMaxCut)
1084 maxAt[iDigitN] = 0 ;
1086 } // if Areneighbours
1092 for(iDigit = 0; iDigit < fMulDigit; iDigit++) {
1094 maxAt[iDigitN] = maxAt[iDigit] ;
1095 maxAtEnergy[iDigitN] = fEnergyList[iDigit] ;
1102 //____________________________________________________________________________
1103 Int_t AliEMCALRecPoint::GetPrimaryIndex() const
1105 // Get the primary track index in TreeK which deposits the most energy
1106 // in Digits which forms RecPoint.
1109 return fTracksList[0];
1113 //____________________________________________________________________________
1114 void AliEMCALRecPoint::EvalTime(TClonesArray * digits){
1115 // time is set to the time of the digit with the maximum energy
1119 for(Int_t idig=0; idig < fMulDigit; idig++){
1120 if(fEnergyList[idig] > maxE){
1121 maxE = fEnergyList[idig] ;
1125 fTime = ((AliEMCALDigit*) digits->At(fDigitsList[maxAt]))->GetTime() ;
1129 //______________________________________________________________________________
1130 void AliEMCALRecPoint::Paint(Option_t *)
1132 // Paint this ALiRecPoint as a TMarker with its current attributes
1134 TVector3 pos(0.,0.,0.) ;
1135 GetLocalPosition(pos) ;
1136 Coord_t x = pos.X() ;
1137 Coord_t y = pos.Z() ;
1138 Color_t markercolor = 1 ;
1139 Size_t markersize = 1. ;
1140 Style_t markerstyle = 5 ;
1142 if (!gPad->IsBatch()) {
1143 gVirtualX->SetMarkerColor(markercolor) ;
1144 gVirtualX->SetMarkerSize (markersize) ;
1145 gVirtualX->SetMarkerStyle(markerstyle) ;
1147 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
1148 gPad->PaintPolyMarker(1,&x,&y,"") ;
1151 //_____________________________________________________________________
1152 Double_t AliEMCALRecPoint::TmaxInCm(const Double_t e , const Int_t key)
1155 // key = 0(gamma, default)
1157 static Double_t ca = 4.82; // shower max parameter - first guess; ca=TMath::Log(1000./8.07)
1158 static Double_t x0 = 1.23; // radiation lenght (cm)
1159 static Double_t tmax = 0.; // position of electromagnetic shower max in cm
1163 tmax = TMath::Log(e) + ca;
1164 if (key==0) tmax += 0.5;
1166 tmax *= x0; // convert to cm
1171 //______________________________________________________________________________
1172 Float_t AliEMCALRecPoint::EtaToTheta(Float_t arg) const
1174 //Converts Theta (Radians) to Eta(Radians)
1175 return (2.*TMath::ATan(TMath::Exp(-arg)));
1178 //______________________________________________________________________________
1179 Float_t AliEMCALRecPoint::ThetaToEta(Float_t arg) const
1181 //Converts Eta (Radians) to Theta(Radians)
1182 return (-1 * TMath::Log(TMath::Tan(0.5 * arg)));
1185 //____________________________________________________________________________
1186 void AliEMCALRecPoint::Print(Option_t *opt) const
1188 // Print the list of digits belonging to the cluster
1189 if(strlen(opt)==0) return;
1191 message = "AliEMCALRecPoint:\n" ;
1192 message += " digits # = " ;
1193 Info("Print", message.Data()) ;
1196 for(iDigit=0; iDigit<fMulDigit; iDigit++)
1197 printf(" %d ", fDigitsList[iDigit] ) ;
1200 Info("Print", " Energies = ") ;
1201 for(iDigit=0; iDigit<fMulDigit; iDigit++)
1202 printf(" %f ", fEnergyList[iDigit] ) ;
1205 Info("Print", "\n Abs Ids = ") ;
1206 for(iDigit=0; iDigit<fMulDigit; iDigit++)
1207 printf(" %i ", fAbsIdList[iDigit] ) ;
1210 Info("Print", " Primaries ") ;
1211 for(iDigit = 0;iDigit < fMulTrack; iDigit++)
1212 printf(" %d ", fTracksList[iDigit]) ;
1214 printf("\n Local x %6.2f y %7.2f z %7.1f \n", fLocPos[0], fLocPos[1], fLocPos[2]);
1216 message = " ClusterType = %d" ;
1217 message += " Multiplicity = %d" ;
1218 message += " Cluster Energy = %f" ;
1219 message += " Core energy = %f" ;
1220 message += " Core radius = %f" ;
1221 message += " Number of primaries %d" ;
1222 message += " Stored at position %d" ;
1223 Info("Print", message.Data(), fClusterType, fMulDigit, fAmp, fCoreEnergy, fCoreRadius, fMulTrack, GetIndexInList() ) ;
1226 //___________________________________________________________
1227 Double_t AliEMCALRecPoint::GetPointEnergy() const
1229 //Returns energy ....
1232 for(int ic=0; ic<GetMultiplicity(); ic++) e += double(fEnergyList[ic]);