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 **************************************************************************/
18 //_________________________________________________________________________
19 // RecPoint implementation for EMCAL-EMC
20 // An TowerRecPoint is a cluster of digits
22 //*-- Author: Dmitri Peressounko (RRC KI & SUBATECH)
25 // --- ROOT system ---
31 // --- Standard library ---
33 // --- AliRoot header files ---
35 #include "AliGenerator.h"
36 #include "AliEMCALGeometry.h"
37 #include "AliEMCALTowerRecPoint.h"
39 #include "AliEMCALGetter.h"
41 ClassImp(AliEMCALTowerRecPoint)
43 //____________________________________________________________________________
44 AliEMCALTowerRecPoint::AliEMCALTowerRecPoint() : AliEMCALRecPoint()
53 fLocPos.SetX(0.) ; //Local position should be evaluated
56 //____________________________________________________________________________
57 AliEMCALTowerRecPoint::AliEMCALTowerRecPoint(const char * opt) : AliEMCALRecPoint(opt)
66 fLocPos.SetX(1000000.) ; //Local position should be evaluated
69 //____________________________________________________________________________
70 AliEMCALTowerRecPoint::~AliEMCALTowerRecPoint()
75 delete[] fEnergyList ;
78 //____________________________________________________________________________
79 void AliEMCALTowerRecPoint::AddDigit(AliEMCALDigit & digit, Float_t Energy)
81 // Adds a digit to the RecPoint
82 // and accumulates the total amplitude and the multiplicity
85 fEnergyList = new Float_t[fMaxDigit];
87 if ( fMulDigit >= fMaxDigit ) { // increase the size of the lists
89 Int_t * tempo = new ( Int_t[fMaxDigit] ) ;
90 Float_t * tempoE = new ( Float_t[fMaxDigit] ) ;
93 for ( index = 0 ; index < fMulDigit ; index++ ){
94 tempo[index] = fDigitsList[index] ;
95 tempoE[index] = fEnergyList[index] ;
98 delete [] fDigitsList ;
99 fDigitsList = new ( Int_t[fMaxDigit] ) ;
101 delete [] fEnergyList ;
102 fEnergyList = new ( Float_t[fMaxDigit] ) ;
104 for ( index = 0 ; index < fMulDigit ; index++ ){
105 fDigitsList[index] = tempo[index] ;
106 fEnergyList[index] = tempoE[index] ;
113 fDigitsList[fMulDigit] = digit.GetIndexInList() ;
114 fEnergyList[fMulDigit] = Energy ;
118 // EvalEMCALMod(&digit) ;
121 //____________________________________________________________________________
122 Bool_t AliEMCALTowerRecPoint::AreNeighbours(AliEMCALDigit * digit1, AliEMCALDigit * digit2 ) const
124 // Tells if (true) or not (false) two digits are neighbors
126 Bool_t aren = kFALSE ;
128 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
129 AliEMCALGeometry * phosgeom = (AliEMCALGeometry*)gime->EMCALGeometry();
132 phosgeom->AbsToRelNumbering(digit1->GetId(), relid1) ;
135 phosgeom->AbsToRelNumbering(digit2->GetId(), relid2) ;
137 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
138 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
140 if (( coldiff <= 1 ) && ( rowdiff <= 1 ) && (coldiff + rowdiff > 0))
146 //____________________________________________________________________________
147 Int_t AliEMCALTowerRecPoint::Compare(const TObject * obj) const
149 // Compares two RecPoints according to their position in the EMCAL modules
151 Float_t delta = 1 ; //Width of "Sorting row". If you change this
152 //value (what is senseless) change as vell delta in
153 //AliEMCALTrackSegmentMakerv* and other RecPoints...
156 AliEMCALTowerRecPoint * clu = (AliEMCALTowerRecPoint *)obj ;
159 Int_t phosmod1 = GetEMCALArm() ;
160 Int_t phosmod2 = clu->GetEMCALArm() ;
163 GetLocalPosition(locpos1) ;
165 clu->GetLocalPosition(locpos2) ;
167 if(phosmod1 == phosmod2 ) {
168 Int_t rowdif = (Int_t)TMath::Ceil(locpos1.X()/delta)-(Int_t)TMath::Ceil(locpos2.X()/delta) ;
173 else if(locpos1.Z()>locpos2.Z())
180 if(phosmod1 < phosmod2 )
188 //______________________________________________________________________________
189 void AliEMCALTowerRecPoint::ExecuteEvent(Int_t event, Int_t px, Int_t py) const
192 // Execute action corresponding to one event
193 // This member function is called when a AliEMCALRecPoint is clicked with the locator
195 // If Left button is clicked on AliEMCALRecPoint, the digits are switched on
196 // and switched off when the mouse button is released.
199 // AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
200 // if(!gime) return ;
201 // AliEMCALGeometry * emcalgeom = (AliEMCALGeometry*)gime->EMCALGeometry();
203 // static TGraph * digitgraph = 0 ;
205 // if (!gPad->IsEditable()) return;
207 // TH2F * histo = 0 ;
208 // TCanvas * histocanvas ;
210 // const TClonesArray * digits = gime->Digits() ;
214 // case kButton1Down: {
215 // AliEMCALDigit * digit ;
219 // const Int_t kMulDigit = AliEMCALTowerRecPoint::GetDigitsMultiplicity() ;
220 // Float_t * xi = new Float_t[kMulDigit] ;
221 // Float_t * zi = new Float_t[kMulDigit] ;
223 // // create the histogram for the single cluster
224 // // 1. gets histogram boundaries
225 // Float_t ximax = -999. ;
226 // Float_t zimax = -999. ;
227 // Float_t ximin = 999. ;
228 // Float_t zimin = 999. ;
230 // for(iDigit=0; iDigit<kMulDigit; iDigit++) {
231 // digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
232 // emcalgeom->AbsToRelNumbering(digit->GetId(), relid) ;
233 // emcalgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]);
234 // if ( xi[iDigit] > ximax )
235 // ximax = xi[iDigit] ;
236 // if ( xi[iDigit] < ximin )
237 // ximin = xi[iDigit] ;
238 // if ( zi[iDigit] > zimax )
239 // zimax = zi[iDigit] ;
240 // if ( zi[iDigit] < zimin )
241 // zimin = zi[iDigit] ;
243 // ximax += emcalgeom->GetCrystalSize(0) / 2. ;
244 // zimax += emcalgeom->GetCrystalSize(2) / 2. ;
245 // ximin -= emcalgeom->GetCrystalSize(0) / 2. ;
246 // zimin -= emcalgeom->GetCrystalSize(2) / 2. ;
247 // Int_t xdim = (int)( (ximax - ximin ) / emcalgeom->GetCrystalSize(0) + 0.5 ) ;
248 // Int_t zdim = (int)( (zimax - zimin ) / emcalgeom->GetCrystalSize(2) + 0.5 ) ;
250 // // 2. gets the histogram title
252 // Text_t title[100] ;
253 // sprintf(title,"Energy=%1.2f GeV ; Digits ; %d ", GetEnergy(), GetDigitsMultiplicity()) ;
259 // histo = new TH2F("cluster3D", title, xdim, ximin, ximax, zdim, zimin, zimax) ;
262 // for(iDigit=0; iDigit<kMulDigit; iDigit++) {
263 // digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
264 // emcalgeom->AbsToRelNumbering(digit->GetId(), relid) ;
265 // emcalgeom->RelPosInModule(relid, x, z);
266 // histo->Fill(x, z, fEnergyList[iDigit] ) ;
269 // if (!digitgraph) {
270 // digitgraph = new TGraph(kMulDigit,xi,zi);
271 // digitgraph-> SetMarkerStyle(5) ;
272 // digitgraph-> SetMarkerSize(1.) ;
273 // digitgraph-> SetMarkerColor(1) ;
274 // digitgraph-> Paint("P") ;
278 // histocanvas = new TCanvas("cluster", "a single cluster", 600, 500) ;
279 // histocanvas->Draw() ;
280 // histo->Draw("lego1") ;
290 // delete digitgraph ;
298 //____________________________________________________________________________
299 void AliEMCALTowerRecPoint::EvalDispersion(Float_t logWeight,TClonesArray * digits)
301 // Calculates the dispersion of the shower at the origine of the RecPoint
306 AliEMCALDigit * digit ;
308 AliEMCALGeometry * emcalgeom = AliEMCALGetter::GetInstance()->EMCALGeometry();
311 // Calculates the center of gravity in the local EMCAL-module coordinates
315 if (!fTheta || !fPhi )
316 EvalGlobalPosition(logWeight, digits) ;
318 const Float_t kDeg2Rad = TMath::DegToRad() ;
320 Float_t cyl_radius = 0 ;
323 cyl_radius = emcalgeom->GetIP2PRESection() ;
325 cyl_radius = emcalgeom->GetIP2ECALSection() ;
327 cyl_radius = emcalgeom->GetIP2HCALSection() ;
329 Fatal("EvalDispersion", "Unexpected tower section!") ;
331 Float_t x = fLocPos.X() ;
332 Float_t y = fLocPos.Y() ;
333 Float_t z = fLocPos.Z() ;
336 Info("EvalDispersion", "x,y,z = %f,%f,%f", x, y, z) ;
338 // Calculates the dispersion in coordinates
340 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
341 digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
342 Float_t thetai = 0. ;
344 emcalgeom->PosInAlice(digit->GetId(), thetai, phii);
345 Float_t xi = cyl_radius * TMath::Cos(phii * kDeg2Rad ) ;
346 Float_t yi = cyl_radius * TMath::Sin(phii * kDeg2Rad ) ;
347 Float_t zi = cyl_radius / TMath::Tan(thetai * kDeg2Rad ) ;
350 Info("EvalDispersion", "id = %d, xi,yi,zi = %f,%f,%f", digit->GetId(), xi, yi, zi) ;
352 Float_t w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
353 d += w * ( (xi-x)*(xi-x) + (zi-z)*(zi-z) ) ;
362 fDispersion = TMath::Sqrt(d) ;
365 //______________________________________________________________________________
366 void AliEMCALTowerRecPoint::EvalCoreEnergy(Float_t logWeight, TClonesArray * digits)
368 // This function calculates energy in the core,
369 // i.e. within a radius rad = 3cm around the center. Beyond this radius
370 // in accordance with shower profile the energy deposition
371 // should be less than 2%
373 Float_t coreRadius = 10. ;
375 AliEMCALDigit * digit ;
378 AliEMCALGeometry * emcalgeom = AliEMCALGetter::GetInstance()->EMCALGeometry();
381 if (!fTheta || !fPhi ) {
382 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
383 digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
387 emcalgeom->PosInAlice(digit->GetId(), thetai, phii);
388 Float_t w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
389 fTheta = fTheta + thetai * w ;
403 const Float_t kDeg2Rad = TMath::DegToRad() ;
405 Float_t cyl_radius = emcalgeom->GetIP2ECALSection();
406 Float_t x = cyl_radius * TMath::Cos(fPhi * kDeg2Rad ) ;
407 Float_t y = cyl_radius * TMath::Cos(fPhi * kDeg2Rad ) ;
408 Float_t z = cyl_radius * TMath::Tan(fTheta * kDeg2Rad ) ;
410 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
411 digit = (AliEMCALDigit *) ( digits->At(fDigitsList[iDigit]) ) ;
412 Float_t thetai = 0. ;
414 emcalgeom->PosInAlice(digit->GetId(), thetai, phii);
416 Float_t xi = cyl_radius * TMath::Cos(phii * kDeg2Rad ) ;
417 Float_t yi = cyl_radius * TMath::Sin(phii * kDeg2Rad ) ;
418 Float_t zi = cyl_radius * TMath::Tan(thetai * kDeg2Rad ) ;
420 Float_t distance = TMath::Sqrt((xi-x)*(xi-x)+(yi-y)*(yi-y)+(zi-z)*(zi-z)) ;
421 if(distance < coreRadius)
422 fCoreEnergy += fEnergyList[iDigit] ;
427 //____________________________________________________________________________
428 void AliEMCALTowerRecPoint::EvalElipsAxis(Float_t logWeight,TClonesArray * digits)
430 // Calculates the axis of the shower ellipsoid
439 AliEMCALDigit * digit ;
441 AliEMCALGeometry * emcalgeom = AliEMCALGetter::GetInstance()->EMCALGeometry();
444 const Float_t kDeg2Rad = TMath::DegToRad() ;
446 Float_t cyl_radius = 0 ;
449 cyl_radius = emcalgeom->GetIP2PRESection() ;
451 cyl_radius = emcalgeom->GetIP2ECALSection() ;
453 cyl_radius = emcalgeom->GetIP2HCALSection() ;
455 Fatal("EvalDispersion", "Unexpected tower section!") ;
457 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
458 digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
459 Float_t thetai = 0. ;
461 emcalgeom->PosInAlice(digit->GetId(), thetai, phii);
462 Double_t w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
463 Float_t xi = cyl_radius * TMath::Cos(fPhi * kDeg2Rad ) ;
464 Float_t zi = cyl_radius / TMath::Tan(fTheta * kDeg2Rad ) ;
483 // //Apply correction due to non-perpendicular incidence
486 // AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
487 // AliEMCALGeometry * emcalgeom = (AliEMCALGeometry*)gime->EMCALGeometry();
488 // Double_t DistanceToIP= (Double_t ) emcalgeom->GetIPDistance() ;
490 // CosX = DistanceToIP/TMath::Sqrt(DistanceToIP*DistanceToIP+x*x) ;
491 // CosZ = DistanceToIP/TMath::Sqrt(DistanceToIP*DistanceToIP+z*z) ;
493 // dxx = dxx/(CosX*CosX) ;
494 // dzz = dzz/(CosZ*CosZ) ;
495 // dxz = dxz/(CosX*CosZ) ;
498 fLambda[0] = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
500 fLambda[0] = TMath::Sqrt(fLambda[0]) ;
502 fLambda[1] = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
503 if(fLambda[1] > 0) //To avoid exception if numerical errors lead to negative lambda.
504 fLambda[1] = TMath::Sqrt(fLambda[1]) ;
513 //____________________________________________________________________________
514 void AliEMCALTowerRecPoint::EvalAll(Float_t logWeight, TClonesArray * digits )
516 // Evaluates all shower parameters
518 AliEMCALRecPoint::EvalAll(logWeight,digits) ;
519 EvalGlobalPosition(logWeight, digits) ;
520 EvalElipsAxis(logWeight, digits) ;
521 EvalDispersion(logWeight, digits) ;
522 EvalCoreEnergy(logWeight, digits);
526 //____________________________________________________________________________
527 void AliEMCALTowerRecPoint::EvalGlobalPosition(Float_t logWeight, TClonesArray * digits)
529 // Calculates the center of gravity in the local EMCAL-module coordinates
534 AliEMCALDigit * digit ;
535 AliEMCALGeometry * emcalgeom = AliEMCALGetter::GetInstance()->EMCALGeometry();
538 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
539 digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
543 emcalgeom->PosInAlice(digit->GetId(), thetai, phii);
544 Float_t w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
545 fTheta = fTheta + thetai * w ;
559 const Float_t kDeg2Rad = TMath::DegToRad() ;
561 Float_t cyl_radius = 0 ;
564 cyl_radius = emcalgeom->GetIP2PRESection() ;
566 cyl_radius = emcalgeom->GetIP2ECALSection() ;
568 cyl_radius = emcalgeom->GetIP2HCALSection() ;
570 Fatal("EvalGlobalPosition", "Unexpected tower section!") ;
572 Float_t x = cyl_radius * TMath::Cos(fPhi * kDeg2Rad ) ;
573 Float_t y = cyl_radius * TMath::Sin(fPhi * kDeg2Rad ) ;
574 Float_t z = cyl_radius / TMath::Tan(fTheta * kDeg2Rad ) ;
581 Info("EvalGlobalPosition", "x,y,z = %f,%f,%f", fLocPos.X(), fLocPos.Y(), fLocPos.Z()) ;
587 //____________________________________________________________________________
588 Float_t AliEMCALTowerRecPoint::GetMaximalEnergy(void) const
590 // Finds the maximum energy in the cluster
592 Float_t menergy = 0. ;
596 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
598 if(fEnergyList[iDigit] > menergy)
599 menergy = fEnergyList[iDigit] ;
604 //____________________________________________________________________________
605 Int_t AliEMCALTowerRecPoint::GetMultiplicityAtLevel(const Float_t H) const
607 // Calculates the multiplicity of digits with energy larger than H*energy
611 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
613 if(fEnergyList[iDigit] > H * fAmp)
619 //____________________________________________________________________________
620 Int_t AliEMCALTowerRecPoint::GetNumberOfLocalMax(AliEMCALDigit ** maxAt, Float_t * maxAtEnergy,
621 Float_t locMaxCut,TClonesArray * digits) const
623 // Calculates the number of local maxima in the cluster using fLocalMaxCut as the minimum
624 // energy difference between two local maxima
626 AliEMCALDigit * digit ;
627 AliEMCALDigit * digitN ;
633 for(iDigit = 0; iDigit < fMulDigit; iDigit++)
634 maxAt[iDigit] = (AliEMCALDigit*) digits->At(fDigitsList[iDigit]) ;
637 for(iDigit = 0 ; iDigit < fMulDigit; iDigit++) {
639 digit = maxAt[iDigit] ;
641 for(iDigitN = 0; iDigitN < fMulDigit; iDigitN++) {
642 digitN = (AliEMCALDigit *) digits->At(fDigitsList[iDigitN]) ;
644 if ( AreNeighbours(digit, digitN) ) {
645 if (fEnergyList[iDigit] > fEnergyList[iDigitN] ) {
647 // but may be digit too is not local max ?
648 if(fEnergyList[iDigit] < fEnergyList[iDigitN] + locMaxCut)
653 // but may be digitN too is not local max ?
654 if(fEnergyList[iDigit] > fEnergyList[iDigitN] - locMaxCut)
657 } // if Areneighbours
663 for(iDigit = 0; iDigit < fMulDigit; iDigit++) {
665 maxAt[iDigitN] = maxAt[iDigit] ;
666 maxAtEnergy[iDigitN] = fEnergyList[iDigit] ;
672 //____________________________________________________________________________
673 void AliEMCALTowerRecPoint::EvalTime(TClonesArray * digits){
677 for(Int_t idig=0; idig < fMulDigit; idig++){
678 if(fEnergyList[idig] > maxE){
679 maxE = fEnergyList[idig] ;
683 fTime = ((AliEMCALDigit*) digits->At(fDigitsList[maxAt]))->GetTime() ;
686 //____________________________________________________________________________
687 void AliEMCALTowerRecPoint::Print(Option_t * option)
689 // Print the list of digits belonging to the cluster
691 TString message("\n") ;
694 message += "digits # = " ;
695 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
696 message += fDigitsList[iDigit] ;
700 message += "\nEnergies = " ;
701 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
702 message += fEnergyList[iDigit] ;
706 message += "\nPrimaries " ;
707 for(iDigit = 0;iDigit < fMulTrack; iDigit++) {
708 message += fTracksList[iDigit] ;
711 message += "\n Multiplicity = " ;
712 message += fMulDigit ;
713 message += "\n Cluster Energy = " ;
715 message += "\n Number of primaries " ;
716 message += fMulTrack ;
717 message += "\n Stored at position " ;
718 message += GetIndexInList() ;
720 Info("Print", message.Data() ) ;
723 //____________________________________________________________________________
724 const TVector3 AliEMCALTowerRecPoint::XYZInAlice(Float_t r, Float_t theta, Float_t phi) const
726 // spherical coordinates of recpoint in Alice reference frame
729 Info("XYZInAlice", "this= %d , r = %f, theta = %f, phi = %f", this, r, theta, phi) ;
731 if (theta == 9999. || phi == 9999. || r == 9999.) {
733 GetGlobalPosition(globalpos);
734 phi = globalpos.X() * TMath::DegToRad() ;
736 theta = globalpos.Z() * TMath::DegToRad() ;
739 theta *= TMath::DegToRad() ;
740 phi *= TMath::DegToRad() ;
743 Float_t y = r * TMath::Cos(phi) ;
744 Float_t x = r * TMath::Sin(phi) * TMath::Sin(theta) ;
745 Float_t z = r * TMath::Sin(phi) * TMath::Cos(theta) ;
747 TVector3 vec(z, x, y) ;