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 PHOS-EMC
20 // An EmcRecPoint is a cluster of digits
22 //*-- Author: Dmitri Peressounko (RRC KI & SUBATECH)
25 // --- ROOT system ---
31 // --- Standard library ---
35 // --- AliRoot header files ---
37 #include "AliGenerator.h"
38 #include "AliPHOSGeometry.h"
39 #include "AliPHOSEmcRecPoint.h"
41 #include "AliPHOSIndexToObject.h"
43 ClassImp(AliPHOSEmcRecPoint)
45 //____________________________________________________________________________
46 AliPHOSEmcRecPoint::AliPHOSEmcRecPoint(Float_t W0, Float_t LocMaxCut)
53 fEnergyList = new Float_t[fMaxDigit];
54 fGeom = AliPHOSGeometry::GetInstance() ;
55 fDelta = ((AliPHOSGeometry *) fGeom)->GetCrystalSize(0) ;
57 fLocMaxCut = LocMaxCut ;
58 fLocPos.SetX(1000000.) ; //Local position should be evaluated
62 //____________________________________________________________________________
63 AliPHOSEmcRecPoint::~AliPHOSEmcRecPoint()
67 delete[] fEnergyList ;
70 //____________________________________________________________________________
71 void AliPHOSEmcRecPoint::AddDigit(AliPHOSDigit & digit, Float_t Energy)
73 // Adds a digit to the RecPoint
74 // and accumulates the total amplitude and the multiplicity
76 if ( fMulDigit >= fMaxDigit ) { // increase the size of the lists
78 Int_t * tempo = new ( Int_t[fMaxDigit] ) ;
79 Float_t * tempoE = new ( Float_t[fMaxDigit] ) ;
82 for ( index = 0 ; index < fMulDigit ; index++ ){
83 tempo[index] = fDigitsList[index] ;
84 tempoE[index] = fEnergyList[index] ;
87 delete [] fDigitsList ;
88 fDigitsList = new ( Int_t[fMaxDigit] ) ;
90 delete [] fEnergyList ;
91 fEnergyList = new ( Float_t[fMaxDigit] ) ;
93 for ( index = 0 ; index < fMulDigit ; index++ ){
94 fDigitsList[index] = tempo[index] ;
95 fEnergyList[index] = tempoE[index] ;
102 fDigitsList[fMulDigit] = digit.GetIndexInList() ;
103 fEnergyList[fMulDigit] = Energy ;
108 //____________________________________________________________________________
109 Bool_t AliPHOSEmcRecPoint::AreNeighbours(AliPHOSDigit * digit1, AliPHOSDigit * digit2 ) const
111 // Tells if (true) or not (false) two digits are neighbors)
113 Bool_t aren = kFALSE ;
115 AliPHOSGeometry * phosgeom = (AliPHOSGeometry *) fGeom ;
117 phosgeom->AbsToRelNumbering(digit1->GetId(), relid1) ;
120 phosgeom->AbsToRelNumbering(digit2->GetId(), relid2) ;
122 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
123 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
125 if (( coldiff <= 1 ) && ( rowdiff <= 1 ) && (coldiff + rowdiff > 0))
131 //____________________________________________________________________________
132 Int_t AliPHOSEmcRecPoint::Compare(const TObject * obj) const
134 // Compares two RecPoints according to their position in the PHOS modules
138 AliPHOSEmcRecPoint * clu = (AliPHOSEmcRecPoint *)obj ;
141 Int_t phosmod1 = GetPHOSMod() ;
142 Int_t phosmod2 = clu->GetPHOSMod() ;
145 this->GetLocalPosition(locpos1) ;
147 clu->GetLocalPosition(locpos2) ;
149 if(phosmod1 == phosmod2 ) {
150 Int_t rowdif = (Int_t)TMath::Ceil(locpos1.X()/fDelta)-(Int_t)TMath::Ceil(locpos2.X()/fDelta) ;
155 else if(locpos1.Z()>locpos2.Z())
162 if(phosmod1 < phosmod2 )
171 //______________________________________________________________________________
172 void AliPHOSEmcRecPoint::ExecuteEvent(Int_t event, Int_t px, Int_t py)
174 // Execute action corresponding to one event
175 // This member function is called when a AliPHOSRecPoint is clicked with the locator
177 // If Left button is clicked on AliPHOSRecPoint, the digits are switched on
178 // and switched off when the mouse button is released.
181 // static Int_t pxold, pyold;
183 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
185 static TGraph * digitgraph = 0 ;
187 if (!gPad->IsEditable()) return;
190 TCanvas * histocanvas ;
195 AliPHOSDigit * digit ;
196 AliPHOSGeometry * phosgeom = (AliPHOSGeometry *) fGeom ;
200 const Int_t kMulDigit = AliPHOSEmcRecPoint::GetDigitsMultiplicity() ;
201 Float_t * xi = new Float_t[kMulDigit] ;
202 Float_t * zi = new Float_t[kMulDigit] ;
204 // create the histogram for the single cluster
205 // 1. gets histogram boundaries
206 Float_t ximax = -999. ;
207 Float_t zimax = -999. ;
208 Float_t ximin = 999. ;
209 Float_t zimin = 999. ;
211 for(iDigit=0; iDigit<kMulDigit; iDigit++) {
212 digit = (AliPHOSDigit *) ( please->GimeDigit(fDigitsList[iDigit]) ) ;
213 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
214 phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]);
215 if ( xi[iDigit] > ximax )
217 if ( xi[iDigit] < ximin )
219 if ( zi[iDigit] > zimax )
221 if ( zi[iDigit] < zimin )
224 ximax += phosgeom->GetCrystalSize(0) / 2. ;
225 zimax += phosgeom->GetCrystalSize(2) / 2. ;
226 ximin -= phosgeom->GetCrystalSize(0) / 2. ;
227 zimin -= phosgeom->GetCrystalSize(2) / 2. ;
228 Int_t xdim = (int)( (ximax - ximin ) / phosgeom->GetCrystalSize(0) + 0.5 ) ;
229 Int_t zdim = (int)( (zimax - zimin ) / phosgeom->GetCrystalSize(2) + 0.5 ) ;
231 // 2. gets the histogram title
234 sprintf(title,"Energy=%1.2f GeV ; Digits ; %d ", GetEnergy(), GetDigitsMultiplicity()) ;
240 histo = new TH2F("cluster3D", title, xdim, ximin, ximax, zdim, zimin, zimax) ;
243 for(iDigit=0; iDigit<kMulDigit; iDigit++) {
244 digit = (AliPHOSDigit *) ( please->GimeDigit(fDigitsList[iDigit]) ) ;
245 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
246 phosgeom->RelPosInModule(relid, x, z);
247 histo->Fill(x, z, fEnergyList[iDigit] ) ;
251 digitgraph = new TGraph(kMulDigit,xi,zi);
252 digitgraph-> SetMarkerStyle(5) ;
253 digitgraph-> SetMarkerSize(1.) ;
254 digitgraph-> SetMarkerColor(1) ;
255 digitgraph-> Paint("P") ;
259 histocanvas = new TCanvas("cluser", "a single cluster", 600, 500) ;
260 histocanvas->Draw() ;
261 histo->Draw("lego1") ;
279 //____________________________________________________________________________
280 Float_t AliPHOSEmcRecPoint::GetDispersion() const
282 // Calculates the dispersion of the shower at the origine of the RecPoint
284 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
290 GetLocalPosition(locpos);
291 Float_t x = locpos.X() ;
292 Float_t z = locpos.Z() ;
294 AliPHOSDigit * digit ;
295 AliPHOSGeometry * phosgeom = (AliPHOSGeometry *) fGeom ;
298 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
299 digit = (AliPHOSDigit *) ( please->GimeDigit(fDigitsList[iDigit]) ) ;
303 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
304 phosgeom->RelPosInModule(relid, xi, zi);
305 Float_t w = TMath::Max(0.,fW0+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
306 d += w*((xi-x)*(xi-x) + (zi-z)*(zi-z) ) ;
312 return TMath::Sqrt(d) ;
314 //______________________________________________________________________________
315 Float_t AliPHOSEmcRecPoint::CoreEnergy()
317 //This function calculates energy in the core,
318 //i.e. within radius rad = 3cm. Beyond this radius
319 //in accoradnce with shower profile energy deposition
320 // should be less than 2%
322 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
325 Float_t coreRadius = 3 ;
328 GetLocalPosition(locpos);
329 Float_t x = locpos.X() ;
330 Float_t z = locpos.Z() ;
332 AliPHOSDigit * digit ;
333 AliPHOSGeometry * phosgeom = (AliPHOSGeometry *) fGeom ;
336 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
337 digit = (AliPHOSDigit *) ( please->GimeDigit(fDigitsList[iDigit]) ) ;
341 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
342 phosgeom->RelPosInModule(relid, xi, zi);
343 Float_t distance = TMath::Sqrt((xi-x)*(xi-x)+(zi-z)*(zi-z)) ;
344 if(distance < coreRadius)
345 eCore += fEnergyList[iDigit] ;
351 //____________________________________________________________________________
352 void AliPHOSEmcRecPoint::GetElipsAxis(Float_t * lambda)
354 // Calculates the axis of the shower ellipsoid
356 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
365 AliPHOSDigit * digit ;
366 AliPHOSGeometry * phosgeom = (AliPHOSGeometry *) fGeom ;
369 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
370 digit = (AliPHOSDigit *) ( please->GimeDigit(fDigitsList[iDigit]) ) ;
374 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
375 phosgeom->RelPosInModule(relid, xi, zi);
376 Double_t w = TMath::Max(0.,fW0+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
393 // //Apply correction due to non-perpendicular incidence
396 // Double_t DistanceToIP= (Double_t ) ((AliPHOSGeometry *) fGeom)->GetIPtoCrystalSurface() ;
398 // CosX = DistanceToIP/TMath::Sqrt(DistanceToIP*DistanceToIP+x*x) ;
399 // CosZ = DistanceToIP/TMath::Sqrt(DistanceToIP*DistanceToIP+z*z) ;
401 // dxx = dxx/(CosX*CosX) ;
402 // dzz = dzz/(CosZ*CosZ) ;
403 // dxz = dxz/(CosX*CosZ) ;
406 lambda[0] = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
408 lambda[0] = TMath::Sqrt(lambda[0]) ;
410 lambda[1] = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
411 if(lambda[1] > 0) //To avoid exception if numerical errors lead to negative lambda.
412 lambda[1] = TMath::Sqrt(lambda[1]) ;
417 //____________________________________________________________________________
418 void AliPHOSEmcRecPoint::EvalAll(void )
420 AliPHOSRecPoint::EvalAll() ;
421 EvalLocalPosition() ;
423 //____________________________________________________________________________
424 void AliPHOSEmcRecPoint::EvalLocalPosition(void )
426 // Calculates the center of gravity in the local PHOS-module coordinates
428 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
437 AliPHOSDigit * digit ;
439 AliPHOSGeometry * phosgeom = (AliPHOSGeometry *) fGeom ;
443 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
444 digit = (AliPHOSDigit *) ( please->GimeDigit(fDigitsList[iDigit]) );
448 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
449 phosgeom->RelPosInModule(relid, xi, zi);
450 Float_t w = TMath::Max( 0., fW0 + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
460 // Correction for the depth of the shower starting point (TDR p 127)
461 Float_t para = 0.925 ;
462 Float_t parb = 6.52 ;
464 Float_t xo,yo,zo ; //Coordinates of the origin
465 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
467 Float_t phi = phosgeom->GetPHOSAngle(relid[0]) ;
469 //Transform to the local ref.frame
471 xoL = xo*TMath::Cos(phi)-yo*TMath::Sin(phi) ;
472 yoL = xo*TMath::Sin(phi)+yo*TMath::Cos(phi) ;
474 Float_t radius = TMath::Sqrt((xoL-x)*(xoL-x)+
475 (phosgeom->GetIPtoCrystalSurface()-yoL)*(phosgeom->GetIPtoCrystalSurface()-yoL)+
478 Float_t incidencephi = TMath::ATan((x-xoL ) / radius) ;
479 Float_t incidencetheta = TMath::ATan((z-zo) / radius) ;
481 Float_t depthx = ( para * TMath::Log(fAmp) + parb ) * TMath::Sin(incidencephi) ;
482 Float_t depthz = ( para * TMath::Log(fAmp) + parb ) * TMath::Sin(incidencetheta) ;
485 fLocPos.SetX(x - depthx) ;
487 fLocPos.SetZ(z - depthz) ;
491 //____________________________________________________________________________
492 Float_t AliPHOSEmcRecPoint::GetMaximalEnergy(void) const
494 // Finds the maximum energy in the cluster
496 Float_t menergy = 0. ;
500 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
502 if(fEnergyList[iDigit] > menergy)
503 menergy = fEnergyList[iDigit] ;
508 //____________________________________________________________________________
509 Int_t AliPHOSEmcRecPoint::GetMultiplicityAtLevel(const Float_t H) const
511 // Calculates the multiplicity of digits with energy larger than H*energy
515 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
517 if(fEnergyList[iDigit] > H * fAmp)
523 //____________________________________________________________________________
524 Int_t AliPHOSEmcRecPoint::GetNumberOfLocalMax(Int_t * maxAt, Float_t * maxAtEnergy) const
526 // Calculates the number of local maxima in the cluster using fLocalMaxCut as the minimum
527 // energy difference between two local maxima
529 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
531 AliPHOSDigit * digit ;
532 AliPHOSDigit * digitN ;
538 for(iDigit = 0; iDigit < fMulDigit; iDigit++){
539 maxAt[iDigit] = (Int_t) ( please->GimeDigit(fDigitsList[iDigit]) ) ;
542 for(iDigit = 0 ; iDigit < fMulDigit; iDigit++) {
543 if(maxAt[iDigit] != -1) {
544 digit = (AliPHOSDigit *) maxAt[iDigit] ;
546 for(iDigitN = 0; iDigitN < fMulDigit; iDigitN++) {
547 digitN = (AliPHOSDigit *) ( please->GimeDigit(fDigitsList[iDigitN]) ) ;
549 if ( AreNeighbours(digit, digitN) ) {
550 if (fEnergyList[iDigit] > fEnergyList[iDigitN] ) {
551 maxAt[iDigitN] = -1 ;
552 // but may be digit too is not local max ?
553 if(fEnergyList[iDigit] < fEnergyList[iDigitN] + fLocMaxCut)
558 // but may be digitN too is not local max ?
559 if(fEnergyList[iDigit] > fEnergyList[iDigitN] - fLocMaxCut)
560 maxAt[iDigitN] = -1 ;
562 } // if Areneighbours
568 for(iDigit = 0; iDigit < fMulDigit; iDigit++) {
569 if(maxAt[iDigit] != -1){
570 maxAt[iDigitN] = maxAt[iDigit] ;
571 maxAtEnergy[iDigitN] = fEnergyList[iDigit] ;
579 // //____________________________________________________________________________
580 // AliPHOSEmcRecPoint& AliPHOSEmcRecPoint::operator = (AliPHOSEmcRecPoint Clu)
582 // int * dl = Clu.GetDigitsList() ;
585 // delete fDigitsList ;
587 // AliPHOSDigit * digit ;
591 // for(iDigit=0; iDigit<fMulDigit; iDigit++) {
592 // digit = (AliPHOSDigit *) dl[iDigit];
593 // AddDigit(*digit) ;
596 // fAmp = Clu.GetEnergy() ;
597 // fGeom = Clu.GetGeom() ;
599 // Clu.GetLocalPosition(locpos) ;
601 // fMulDigit = Clu.GetMultiplicity() ;
602 // fMaxDigit = Clu.GetMaximumMultiplicity() ;
603 // fPHOSMod = Clu.GetPHOSMod() ;
604 // fW0 = Clu.GetLogWeightCut() ;
605 // fDelta = Clu.GetDelta() ;
606 // fLocMaxCut = Clu.GetLocMaxCut() ;
613 //____________________________________________________________________________
614 void AliPHOSEmcRecPoint::Print(Option_t * option)
616 // Print the list of digits belonging to the cluster
618 cout << "AliPHOSEmcRecPoint: " << endl ;
620 AliPHOSDigit * digit ;
622 AliPHOSGeometry * phosgeom = (AliPHOSGeometry *) fGeom ;
628 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
630 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
631 digit = please->GimeDigit( fDigitsList[iDigit] ) ;
632 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
633 phosgeom->RelPosInModule(relid, xi, zi);
634 cout << " Id = " << digit->GetId() ;
635 cout << " module = " << relid[0] ;
636 cout << " x = " << xi ;
637 cout << " z = " << zi ;
638 cout << " Energy = " << fEnergyList[iDigit] << endl ;
640 cout << " Multiplicity = " << fMulDigit << endl ;
641 cout << " Cluster Energy = " << fAmp << endl ;
642 cout << " Stored at position " << GetIndexInList() << endl ;
645 //______________________________________________________________________________
646 // void AliPHOSEmcRecPoint::Streamer(TBuffer &R__b)
648 // // Stream an object of class AliPHOSEmcRecPoint.
650 // if (R__b.IsReading()) {
651 // Version_t R__v = R__b.ReadVersion(); if (R__v) { }
652 // AliPHOSRecPoint::Streamer(R__b);
654 // fEnergyList = new Float_t[fMulDigit] ;
655 // R__b.ReadFastArray(fEnergyList, fMulDigit);
656 // R__b >> fLocMaxCut;
659 // R__b.WriteVersion(AliPHOSEmcRecPoint::IsA());
660 // AliPHOSRecPoint::Streamer(R__b);
662 // R__b.WriteFastArray(fEnergyList, fMulDigit);
663 // R__b << fLocMaxCut;