]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSGeometry.cxx
Number of maxima in parent cluster added
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGeometry.cxx
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
16 /* $Id$ */
17
18 //_________________________________________________________________________
19 // Geometry class  for PHOS : singleton  
20 // PHOS consists of the electromagnetic calorimeter (EMCA)
21 // and a charged particle veto either in the Subatech's version (PPSD)
22 // or in the IHEP's one (CPV).
23 // The EMCA/PPSD/CPV modules are parametrized so that any configuration
24 // can be easily implemented 
25 // The title is used to identify the version of CPV used.
26 //                  
27 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC "KI" & SUBATECH)
28
29 // --- ROOT system ---
30
31 #include "TVector3.h"
32 #include "TRotation.h" 
33 #include "TFolder.h" 
34 #include "TROOT.h" 
35
36 // --- Standard library ---
37
38 #include <stdlib.h>
39
40 // --- AliRoot header files ---
41
42 #include "AliPHOSGeometry.h"
43 #include "AliPHOSEMCAGeometry.h" 
44 #include "AliPHOSRecPoint.h"
45 #include "AliConst.h"
46
47 ClassImp(AliPHOSGeometry) ;
48
49 // these initialisations are needed for a singleton
50 AliPHOSGeometry * AliPHOSGeometry::fgGeom = 0 ;
51 Bool_t            AliPHOSGeometry::fgInit = kFALSE ;
52
53 //____________________________________________________________________________
54 AliPHOSGeometry::~AliPHOSGeometry(void)
55 {
56   // dtor
57
58   if (fRotMatrixArray) fRotMatrixArray->Delete() ; 
59   if (fRotMatrixArray) delete fRotMatrixArray ; 
60   if (fPHOSAngle     ) delete[] fPHOSAngle ; 
61 }
62 //____________________________________________________________________________
63
64 void AliPHOSGeometry::Init(void)
65 {
66   // Initializes the PHOS parameters :
67   //  IHEP is the Protvino CPV (cathode pad chambers)
68   //  GPS2 is the Subatech Pre-Shower (two micromegas sandwiching a passive lead converter)
69   //  MIXT 4 PHOS modules withe the IHEP CPV and one PHOS module with the Subatech Pre-Shower
70   
71   TString test(GetName()) ; 
72   if (test != "IHEP" && test != "GPS2" && test != "MIXT") {
73     Fatal("Init", "%s is not a known geometry (choose among IHEP, GPS2 and MIXT)", test.Data() ) ; 
74   }
75
76   fgInit     = kTRUE ; 
77   
78   fNModules     = 5;
79   fAngle        = 20;
80   
81   fGeometryEMCA = new AliPHOSEMCAGeometry();
82   
83   fGeometryCPV  = new AliPHOSCPVGeometry ();
84   
85   fGeometrySUPP = new AliPHOSSupportGeometry();
86   
87   fPHOSAngle = new Float_t[fNModules] ;
88   
89   Float_t * emcParams = fGeometryEMCA->GetEMCParams() ;
90   
91   fPHOSParams[0] =  TMath::Max((Double_t)fGeometryCPV->GetCPVBoxSize(0)/2., 
92                                (Double_t)(emcParams[0]*(fGeometryCPV->GetCPVBoxSize(1)+emcParams[3]) - 
93                                 emcParams[1]* fGeometryCPV->GetCPVBoxSize(1))/emcParams[3] ) ;
94   fPHOSParams[1] = emcParams[1] ;
95   fPHOSParams[2] = TMath::Max((Double_t)emcParams[2], (Double_t)fGeometryCPV->GetCPVBoxSize(2)/2.);
96   fPHOSParams[3] = emcParams[3] + fGeometryCPV->GetCPVBoxSize(1)/2. ;
97   
98   fIPtoUpperCPVsurface = fGeometryEMCA->GetIPtoOuterCoverDistance() - fGeometryCPV->GetCPVBoxSize(1) ;
99   
100   Int_t index ;
101   for ( index = 0; index < fNModules; index++ )
102     fPHOSAngle[index] = 0.0 ; // Module position angles are set in CreateGeometry()
103   
104   this->SetPHOSAngles() ; 
105   fRotMatrixArray = new TObjArray(fNModules) ; 
106   
107 }
108
109 //____________________________________________________________________________
110 AliPHOSGeometry *  AliPHOSGeometry::GetInstance() 
111
112   // Returns the pointer of the unique instance; singleton specific
113   
114   return static_cast<AliPHOSGeometry *>( fgGeom ) ; 
115 }
116
117 //____________________________________________________________________________
118 AliPHOSGeometry *  AliPHOSGeometry::GetInstance(const Text_t* name, const Text_t* title) 
119 {
120   // Returns the pointer of the unique instance
121   // Creates it with the specified options (name, title) if it does not exist yet
122
123   AliPHOSGeometry * rv = 0  ; 
124   if ( fgGeom == 0 ) {
125     if ( strcmp(name,"") == 0 ) 
126       rv = 0 ;
127     else {    
128       fgGeom = new AliPHOSGeometry(name, title) ;
129       if ( fgInit )
130         rv = (AliPHOSGeometry * ) fgGeom ;
131       else {
132         rv = 0 ; 
133         delete fgGeom ; 
134         fgGeom = 0 ; 
135       }
136     }
137   }
138   else {
139     if ( strcmp(fgGeom->GetName(), name) != 0 ) 
140       ::Error("GetInstance", "Current geometry is %s. You cannot call %s", fgGeom->GetName(), name) ; 
141     else
142       rv = (AliPHOSGeometry *) fgGeom ; 
143   } 
144   return rv ; 
145 }
146
147 //____________________________________________________________________________
148 void AliPHOSGeometry::SetPHOSAngles() 
149
150   // Calculates the position of the PHOS modules in ALICE global coordinate system
151   
152   Double_t const kRADDEG = 180.0 / kPI ;
153   Float_t pphi =  2 * TMath::ATan( GetOuterBoxSize(0)  / ( 2.0 * GetIPtoUpperCPVsurface() ) ) ;
154   pphi *= kRADDEG ;
155   if (pphi > fAngle){ 
156     Error("SetPHOSAngles", "PHOS modules overlap!\n pphi = %f fAngle = %f", pphi, fAngle);
157
158   }
159   pphi = fAngle;
160   
161   for( Int_t i = 1; i <= fNModules ; i++ ) {
162     Float_t angle = pphi * ( i - fNModules / 2.0 - 0.5 ) ;
163     fPHOSAngle[i-1] = -  angle ;
164   } 
165 }
166
167 //____________________________________________________________________________
168 Bool_t AliPHOSGeometry::AbsToRelNumbering(const Int_t AbsId, Int_t * relid) const
169 {
170   // Converts the absolute numbering into the following array/
171   //  relid[0] = PHOS Module number 1:fNModules 
172   //  relid[1] = 0 if PbW04
173   //           = -1 if CPV
174   //  relid[2] = Row number inside a PHOS module
175   //  relid[3] = Column number inside a PHOS module
176
177   Bool_t rv  = kTRUE ; 
178   Float_t id = AbsId ;
179
180   Int_t phosmodulenumber = (Int_t)TMath:: Ceil( id / GetNCristalsInModule() ) ; 
181   
182   if ( phosmodulenumber >  GetNModules() ) { // it is a CPV pad
183     
184     id -=  GetNPhi() * GetNZ() *  GetNModules() ; 
185     Float_t nCPV  = GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() ;
186     relid[0] = (Int_t) TMath::Ceil( id / nCPV ) ;
187     relid[1] = -1 ;
188     id -= ( relid[0] - 1 ) * nCPV ; 
189     relid[2] = (Int_t) TMath::Ceil( id / GetNumberOfCPVPadsZ() ) ;
190     relid[3] = (Int_t) ( id - ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() ) ; 
191   } 
192   else { // it is a PW04 crystal
193
194     relid[0] = phosmodulenumber ;
195     relid[1] = 0 ;
196     id -= ( phosmodulenumber - 1 ) *  GetNPhi() * GetNZ() ; 
197     relid[2] = (Int_t)TMath::Ceil( id / GetNZ() )  ;
198     relid[3] = (Int_t)( id - ( relid[2] - 1 ) * GetNZ() ) ; 
199   } 
200   return rv ; 
201 }
202
203 //____________________________________________________________________________  
204 void AliPHOSGeometry::EmcModuleCoverage(const Int_t mod, Double_t & tm, Double_t & tM, Double_t & pm, Double_t & pM, Option_t * opt) const 
205 {
206   // calculates the angular coverage in theta and phi of one EMC (=PHOS) module
207
208  Double_t conv ; 
209   if ( opt == Radian() ) 
210     conv = 1. ; 
211   else if ( opt == Degre() )
212     conv = 180. / TMath::Pi() ; 
213   else {
214     Warning("EmcModuleCoverage", "%s unknown option; result in radian", opt) ; 
215     conv = 1. ;
216       }
217
218   Float_t phi = GetPHOSAngle(mod) *  (TMath::Pi() / 180.)  ;  
219   Float_t y0  = GetIPtoCrystalSurface() ; 
220   Float_t x0  = GetCellStep()*GetNPhi() ;
221   Float_t z0  = GetCellStep()*GetNZ();
222   Double_t angle = TMath::ATan( x0 / y0 / 2 ) ;
223   phi = phi + 1.5 * TMath::Pi() ; // to follow the convention of the particle generator(PHOS is between 220 and 320 deg.)
224   Double_t max  = phi - angle ;
225   Double_t min   = phi + angle ;
226   pM = TMath::Max(max, min) * conv ;
227   pm = TMath::Min(max, min) * conv ; 
228   
229   angle =  TMath::ATan( z0 /  y0  / 2 ) ;
230   max  = TMath::Pi() / 2.  + angle ; // to follow the convention of the particle generator(PHOS is at 90 deg.)
231   min  = TMath::Pi() / 2.  - angle ;
232   tM = TMath::Max(max, min) * conv ;
233   tm = TMath::Min(max, min) * conv ; 
234  
235 }
236
237 //____________________________________________________________________________  
238 void AliPHOSGeometry::EmcXtalCoverage(Double_t & theta, Double_t & phi, Option_t * opt) const
239 {
240   // calculates the angular coverage in theta and phi of a single crystal in a EMC(=PHOS) module
241
242   Double_t conv ; 
243   if ( opt == Radian() ) 
244     conv = 1. ; 
245   else if ( opt == Degre() )
246     conv = 180. / TMath::Pi() ; 
247   else {
248     Warning("EmcXtalCoverage", "%s unknown option; result in radian", opt) ;  
249     conv = 1. ;
250       }
251
252   Float_t y0  = GetIPtoCrystalSurface() ; 
253   theta = 2 * TMath::ATan( GetCrystalSize(2) / (2 * y0) ) * conv ;
254   phi   = 2 * TMath::ATan( GetCrystalSize(0) / (2 * y0) ) * conv ;
255 }
256  
257
258 //____________________________________________________________________________
259 void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos, TMatrix & gmat) const
260 {
261   // Calculates the coordinates of a RecPoint and the error matrix in the ALICE global coordinate system
262  
263   AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;  
264   TVector3 localposition ;
265
266   tmpPHOS->GetLocalPosition(gpos) ;
267
268
269   if ( tmpPHOS->IsEmc() ) // it is a EMC crystal 
270     {  gpos.SetY( - GetIPtoCrystalSurface()) ;  
271
272     }
273   else
274     { // it is a CPV
275       gpos.SetY(- GetIPtoUpperCPVsurface()  ) ; 
276     }  
277
278   Float_t phi           = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ; 
279   Double_t const kRADDEG = 180.0 / kPI ;
280   Float_t rphi          = phi / kRADDEG ; 
281   
282   TRotation rot ;
283   rot.RotateZ(-rphi) ; // a rotation around Z by angle  
284   
285   TRotation dummy = rot.Invert() ;  // to transform from original frame to rotate frame
286   gpos.Transform(rot) ; // rotate the baby 
287
288 }
289
290 //____________________________________________________________________________
291 void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos) const 
292 {
293   // Calculates the coordinates of a RecPoint in the ALICE global coordinate system 
294
295   AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;  
296   TVector3 localposition ;
297   tmpPHOS->GetLocalPosition(gpos) ;
298
299
300   if ( tmpPHOS->IsEmc() ) // it is a EMC crystal 
301     {  gpos.SetY( - GetIPtoCrystalSurface()  ) ;  
302     }
303   else
304     { // it is a CPV
305           gpos.SetY(- GetIPtoUpperCPVsurface()  ) ; 
306     }  
307
308   Float_t phi           = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ; 
309   Double_t const kRADDEG = 180.0 / kPI ;
310   Float_t rphi          = phi / kRADDEG ; 
311   
312   TRotation rot ;
313   rot.RotateZ(-rphi) ; // a rotation around Z by angle  
314   
315   TRotation dummy = rot.Invert() ;  // to transform from original frame to rotate frame
316   gpos.Transform(rot) ; // rotate the baby 
317 }
318
319 //____________________________________________________________________________
320 void AliPHOSGeometry::ImpactOnEmc(const Double_t theta, const Double_t phi, Int_t & ModuleNumber, Double_t & z, Double_t & x) const
321 {
322   // calculates the impact coordinates on PHOS of a neutral particle  
323   // emitted in the direction theta and phi in the ALICE global coordinate system
324
325   // searches for the PHOS EMC module
326   ModuleNumber = 0 ; 
327   Double_t tm, tM, pm, pM ; 
328   Int_t index = 1 ; 
329   while ( ModuleNumber == 0 && index <= GetNModules() ) { 
330     EmcModuleCoverage(index, tm, tM, pm, pM) ; 
331     if ( (theta >= tm && theta <= tM) && (phi >= pm && phi <= pM ) ) 
332       ModuleNumber = index ; 
333     index++ ;    
334   }
335   if ( ModuleNumber != 0 ) {
336     Float_t phi0 =  GetPHOSAngle(ModuleNumber) *  (TMath::Pi() / 180.) + 1.5 * TMath::Pi()  ;  
337     Float_t y0  =  GetIPtoCrystalSurface()  ;   
338     Double_t angle = phi - phi0; 
339     x = y0 * TMath::Tan(angle) ; 
340     angle = theta - TMath::Pi() / 2 ; 
341     z = y0 * TMath::Tan(angle) ; 
342   }
343 }
344
345 Bool_t  AliPHOSGeometry::Impact(const TParticle * particle) const 
346 {
347   Bool_t In=kFALSE;
348   Int_t ModuleNumber=0;
349   Double_t z,x;
350   ImpactOnEmc(particle->Theta(),particle->Phi(),ModuleNumber,z,x);
351   if(ModuleNumber) In=kTRUE;
352   else In=kFALSE;
353   return In;
354 }
355
356 //____________________________________________________________________________
357 Bool_t AliPHOSGeometry::RelToAbsNumbering(const Int_t * relid, Int_t &  AbsId) const
358 {
359   // Converts the relative numbering into the absolute numbering
360   // EMCA crystals:
361   //  AbsId = from 1 to fNModules * fNPhi * fNZ
362   // CPV pad:
363   //  AbsId = from N(total PHOS crystals) + 1
364   //          to NCPVModules * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ
365
366   Bool_t rv = kTRUE ; 
367   
368   if ( relid[1] ==  0 ) {                            // it is a Phos crystal
369     AbsId =
370       ( relid[0] - 1 ) * GetNPhi() * GetNZ()         // the offset of PHOS modules
371       + ( relid[2] - 1 ) * GetNZ()                   // the offset along phi
372       +   relid[3] ;                                 // the offset along z
373   }
374   else { // it is a CPV pad
375     AbsId =    GetNPhi() * GetNZ() *  GetNModules()         // the offset to separate EMCA crystals from CPV pads
376       + ( relid[0] - 1 ) * GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ()   // the pads offset of PHOS modules 
377       + ( relid[2] - 1 ) * GetNumberOfCPVPadsZ()                             // the pads offset of a CPV row
378       +   relid[3] ;                                                         // the column number
379   }
380   
381   return rv ; 
382 }
383
384 //____________________________________________________________________________
385 void AliPHOSGeometry::RelPosToAbsId(const Int_t module , const Double_t x, const Double_t z, Int_t & AbsId)const{
386   // Converts local PHOS-module (x, z) coordinates to absId 
387
388   if(!module){
389     AbsId = 0 ;
390     return ;
391   }
392   
393   Int_t relid[4] ;
394   relid[0] = module ;
395   relid[1] = 0 ;
396   relid[2] = static_cast<Int_t>(TMath::Ceil(GetNPhi()/2.+ x/GetCellStep()));
397   relid[3] = static_cast<Int_t>(TMath::Ceil(GetNZ()/2.  - z/GetCellStep())) ;
398
399   RelToAbsNumbering(relid,AbsId) ;
400
401 }
402 //____________________________________________________________________________
403 void AliPHOSGeometry::RelPosInAlice(const Int_t id, TVector3 & pos ) const
404 {
405   // Converts the absolute numbering into the global ALICE coordinate system
406   
407     
408     Int_t relid[4] ;
409     
410     AbsToRelNumbering(id , relid) ;
411     
412     Int_t phosmodule = relid[0] ; 
413     
414     Float_t y0 = 0 ; 
415     
416     if ( relid[1] == 0 )  // it is a PbW04 crystal 
417       y0 =  - GetIPtoCrystalSurface() ;  
418     else
419       y0 =  - GetIPtoUpperCPVsurface() ; 
420
421     Float_t x, z ; 
422     RelPosInModule(relid, x, z) ; 
423     
424     pos.SetX(x) ;
425     pos.SetZ(z) ;
426     pos.SetY(y0) ;
427     
428     Float_t phi           = GetPHOSAngle( phosmodule) ; 
429     Double_t const kRADDEG = 180.0 / kPI ;
430     Float_t rphi          = phi / kRADDEG ; 
431     
432     TRotation rot ;
433     rot.RotateZ(-rphi) ; // a rotation around Z by angle  
434     
435     TRotation dummy = rot.Invert() ;  // to transform from original frame to rotate frame
436     
437     pos.Transform(rot) ; // rotate the baby 
438
439
440 //____________________________________________________________________________
441 void AliPHOSGeometry::RelPosInModule(const Int_t * relid, Float_t & x, Float_t & z) const 
442 {
443   // Converts the relative numbering into the local PHOS-module (x, z) coordinates
444   // Note: sign of z differs from that in the previous version (Yu.Kharlov, 12 Oct 2000)
445   
446   Int_t row        = relid[2] ; //offset along x axis
447   Int_t column     = relid[3] ; //offset along z axis
448
449   
450   if ( relid[1] == 0 ) { // its a PbW04 crystal
451     x = - ( GetNPhi()/2. - row    + 0.5 ) *  GetCellStep() ; // position of Xtal with respect
452     z =   ( GetNZ()  /2. - column + 0.5 ) *  GetCellStep() ; // of center of PHOS module  
453   }  
454   else  {    
455     x = - ( GetNumberOfCPVPadsPhi()/2. - row    - 0.5 ) * GetPadSizePhi()  ; // position of pad  with respect
456     z =   ( GetNumberOfCPVPadsZ()  /2. - column - 0.5 ) * GetPadSizeZ()  ; // of center of PHOS module  
457   }
458 }