]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSGeometry.cxx
More exact rounding function, but also much slower.
[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 <iostream.h>
39 #include <stdlib.h>
40
41 // --- AliRoot header files ---
42
43 #include "AliPHOSGeometry.h"
44 #include "AliPHOSEMCAGeometry.h" 
45 #include "AliPHOSRecPoint.h"
46 #include "AliConst.h"
47
48 ClassImp(AliPHOSGeometry) ;
49
50 // these initialisations are needed for a singleton
51 AliPHOSGeometry * AliPHOSGeometry::fgGeom = 0 ;
52 Bool_t            AliPHOSGeometry::fgInit = kFALSE ;
53
54 //____________________________________________________________________________
55 AliPHOSGeometry::~AliPHOSGeometry(void)
56 {
57   // dtor
58
59   if (fRotMatrixArray) fRotMatrixArray->Delete() ; 
60   if (fRotMatrixArray) delete fRotMatrixArray ; 
61   if (fPHOSAngle     ) delete[] fPHOSAngle ; 
62 }
63 //____________________________________________________________________________
64
65 void AliPHOSGeometry::Init(void)
66 {
67   // Initializes the PHOS parameters :
68   //  IHEP is the Protvino CPV (cathode pad chambers)
69   //  GPS2 is the Subatech Pre-Shower (two micromegas sandwiching a passive lead converter)
70   //  MIXT 4 PHOS modules withe the IHEP CPV qnd one PHOS module with the Subatche Pre-Shower
71   
72   fgInit     = kTRUE ; 
73   
74   fNModules     = 5;
75   fAngle        = 20;
76   
77   fGeometryEMCA = new AliPHOSEMCAGeometry();
78   
79   fGeometryCPV  = new AliPHOSCPVGeometry ();
80   
81   fGeometrySUPP = new AliPHOSSupportGeometry();
82   
83   fPHOSAngle = new Float_t[fNModules] ;
84   
85   Float_t * emcParams = fGeometryEMCA->GetEMCParams() ;
86   
87   fPHOSParams[0] =  TMath::Max((Double_t)fGeometryCPV->GetCPVBoxSize(0)/2., 
88                                (Double_t)(emcParams[0]*(fGeometryCPV->GetCPVBoxSize(1)+emcParams[3]) - 
89                                 emcParams[1]* fGeometryCPV->GetCPVBoxSize(1))/emcParams[3] ) ;
90   fPHOSParams[1] = emcParams[1] ;
91   fPHOSParams[2] = TMath::Max((Double_t)emcParams[2], (Double_t)fGeometryCPV->GetCPVBoxSize(2)/2.);
92   fPHOSParams[3] = emcParams[3] + fGeometryCPV->GetCPVBoxSize(1)/2. ;
93   
94   fIPtoUpperCPVsurface = fGeometryEMCA->GetIPtoOuterCoverDistance() - fGeometryCPV->GetCPVBoxSize(1) ;
95   
96   Int_t index ;
97   for ( index = 0; index < fNModules; index++ )
98     fPHOSAngle[index] = 0.0 ; // Module position angles are set in CreateGeometry()
99   
100   this->SetPHOSAngles() ; 
101   fRotMatrixArray = new TObjArray(fNModules) ; 
102   
103 }
104
105
106 //____________________________________________________________________________
107 AliPHOSGeometry *  AliPHOSGeometry::GetInstance() 
108
109   // Returns the pointer of the unique instance; singleton specific
110   
111   return (AliPHOSGeometry *) fgGeom ; 
112 }
113
114 //____________________________________________________________________________
115 AliPHOSGeometry *  AliPHOSGeometry::GetInstance(const Text_t* name, const Text_t* title) 
116 {
117   // Returns the pointer of the unique instance
118   // Creates it with the specified options (name, title) if it does not exist yet
119
120   AliPHOSGeometry * rv = 0  ; 
121   if ( fgGeom == 0 ) {
122     if ( strcmp(name,"") == 0 ) 
123       rv = 0 ;
124     else {    
125       fgGeom = new AliPHOSGeometry(name, title) ;
126       if ( fgInit )
127         rv = (AliPHOSGeometry * ) fgGeom ;
128       else {
129         rv = 0 ; 
130         delete fgGeom ; 
131         fgGeom = 0 ; 
132       }
133     }
134   }
135   else {
136     if ( strcmp(fgGeom->GetName(), name) != 0 ) {
137       cout << "AliPHOSGeometry <E> : current geometry is " << fgGeom->GetName() << endl
138            << "                      you cannot call     " << name << endl ; 
139     }
140     else
141       rv = (AliPHOSGeometry *) fgGeom ; 
142   } 
143   return rv ; 
144 }
145
146 //____________________________________________________________________________
147 void AliPHOSGeometry::SetPHOSAngles() 
148
149   // Calculates the position of the PHOS modules in ALICE global coordinate system
150   
151   Double_t const kRADDEG = 180.0 / kPI ;
152   Float_t pphi =  2 * TMath::ATan( GetOuterBoxSize(0)  / ( 2.0 * GetIPtoUpperCPVsurface() ) ) ;
153   pphi *= kRADDEG ;
154   if (pphi > fAngle){ 
155     cout << "AliPHOSGeometry: PHOS modules overlap!\n";
156     cout <<  "pphi = " << pphi << " fAngle  " << fAngle << endl ;
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     cout << "<I>  AliPHOSGeometry::EmcXtalCoverage : " << opt << " unknown option; result in radian " << endl ; 
215     conv = 1. ;
216       }
217
218   Float_t phi = GetPHOSAngle(mod) *  (TMath::Pi() / 180.)  ;  
219   Float_t y0  = GetIPtoCrystalSurface() ; 
220   Float_t * strip = fGeometryEMCA->GetStripHalfSize() ;
221   Float_t x0  = fGeometryEMCA->GetNStripX()*strip[0] ;
222   Float_t z0  = fGeometryEMCA->GetNStripZ()*strip[2] ;
223   Double_t angle = TMath::ATan( x0 / y0 ) ;
224   phi = phi + 1.5 * TMath::Pi() ; // to follow the convention of the particle generator(PHOS is between 220 and 320 deg.)
225   Double_t max  = phi - angle ;
226   Double_t min   = phi + angle ;
227   pM = TMath::Max(max, min) * conv ;
228   pm = TMath::Min(max, min) * conv ; 
229   
230   angle =  TMath::ATan( z0 /  y0 ) ;
231   max  = TMath::Pi() / 2.  + angle ; // to follow the convention of the particle generator(PHOS is at 90 deg.)
232   min  = TMath::Pi() / 2.  - angle ;
233   tM = TMath::Max(max, min) * conv ;
234   tm = TMath::Min(max, min) * conv ; 
235  
236 }
237
238 //____________________________________________________________________________  
239 void AliPHOSGeometry::EmcXtalCoverage(Double_t & theta, Double_t & phi, Option_t * opt) const
240 {
241   // calculates the angular coverage in theta and phi of a single crystal in a EMC(=PHOS) module
242
243   Double_t conv ; 
244   if ( opt == Radian() ) 
245     conv = 1. ; 
246   else if ( opt == Degre() )
247     conv = 180. / TMath::Pi() ; 
248   else {
249     cout << "<I>  AliPHOSGeometry::EmcXtalCoverage : " << opt << " unknown option; result in radian " << endl ; 
250     conv = 1. ;
251       }
252
253   Float_t y0  = GetIPtoCrystalSurface() ; 
254   theta = 2 * TMath::ATan( GetCrystalSize(2) / (2 * y0) ) * conv ;
255   phi   = 2 * TMath::ATan( GetCrystalSize(0) / (2 * y0) ) * conv ;
256 }
257  
258
259 //____________________________________________________________________________
260 void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos, TMatrix & gmat) const
261 {
262   // Calculates the coordinates of a RecPoint and the error matrix in the ALICE global coordinate system
263  
264   AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;  
265   TVector3 localposition ;
266
267   tmpPHOS->GetLocalPosition(gpos) ;
268
269
270   if ( tmpPHOS->IsEmc() ) // it is a EMC crystal 
271     {  gpos.SetY( - GetIPtoCrystalSurface()) ;  
272
273     }
274   else
275     { // it is a CPV
276       gpos.SetY(- GetIPtoUpperCPVsurface()  ) ; 
277     }  
278
279   Float_t phi           = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ; 
280   Double_t const kRADDEG = 180.0 / kPI ;
281   Float_t rphi          = phi / kRADDEG ; 
282   
283   TRotation rot ;
284   rot.RotateZ(-rphi) ; // a rotation around Z by angle  
285   
286   TRotation dummy = rot.Invert() ;  // to transform from original frame to rotate frame
287   gpos.Transform(rot) ; // rotate the baby 
288
289 }
290
291 //____________________________________________________________________________
292 void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos) const 
293 {
294   // Calculates the coordinates of a RecPoint in the ALICE global coordinate system 
295
296   AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;  
297   TVector3 localposition ;
298   tmpPHOS->GetLocalPosition(gpos) ;
299
300
301   if ( tmpPHOS->IsEmc() ) // it is a EMC crystal 
302     {  gpos.SetY( - GetIPtoCrystalSurface()  ) ;  
303     }
304   else
305     { // it is a CPV
306           gpos.SetY(- GetIPtoUpperCPVsurface()  ) ; 
307     }  
308
309   Float_t phi           = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ; 
310   Double_t const kRADDEG = 180.0 / kPI ;
311   Float_t rphi          = phi / kRADDEG ; 
312   
313   TRotation rot ;
314   rot.RotateZ(-rphi) ; // a rotation around Z by angle  
315   
316   TRotation dummy = rot.Invert() ;  // to transform from original frame to rotate frame
317   gpos.Transform(rot) ; // rotate the baby 
318 }
319
320 //____________________________________________________________________________
321 void AliPHOSGeometry::ImpactOnEmc(const Double_t theta, const Double_t phi, Int_t & ModuleNumber, Double_t & z, Double_t & x) const
322 {
323   // calculates the impact coordinates on PHOS of a neutral particle  
324   // emitted in the direction theta and phi in the ALICE global coordinate system
325
326   // searches for the PHOS EMC module
327   ModuleNumber = 0 ; 
328   Double_t tm, tM, pm, pM ; 
329   Int_t index = 1 ; 
330   while ( ModuleNumber == 0 && index <= GetNModules() ) { 
331     EmcModuleCoverage(index, tm, tM, pm, pM) ; 
332     if ( (theta >= tm && theta <= tM) && (phi >= pm && phi <= pM ) ) 
333       ModuleNumber = index ; 
334     index++ ;    
335   }
336   if ( ModuleNumber != 0 ) {
337     Float_t phi0 =  GetPHOSAngle(ModuleNumber) *  (TMath::Pi() / 180.) + 1.5 * TMath::Pi()  ;  
338     Float_t y0  =  GetIPtoCrystalSurface()  ;   
339     Double_t angle = phi - phi0; 
340     x = y0 * TMath::Tan(angle) ; 
341     angle = theta - TMath::Pi() / 2 ; 
342     z = y0 * TMath::Tan(angle) ; 
343   }
344 }
345
346 Bool_t  AliPHOSGeometry::Impact(const TParticle * particle) const 
347 {
348   Bool_t In=kFALSE;
349   Int_t ModuleNumber=0;
350   Double_t z,x;
351   ImpactOnEmc(particle->Theta(),particle->Phi(),ModuleNumber,z,x);
352   if(ModuleNumber) In=kTRUE;
353   else In=kFALSE;
354   return In;
355 }
356
357 //____________________________________________________________________________
358 Bool_t AliPHOSGeometry::RelToAbsNumbering(const Int_t * relid, Int_t &  AbsId) const
359 {
360   // Converts the relative numbering into the absolute numbering
361   // EMCA crystals:
362   //  AbsId = from 1 to fNModules * fNPhi * fNZ
363   // CPV pad:
364   //  AbsId = from N(total PHOS crystals) + 1
365   //          to NCPVModules * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ
366
367   Bool_t rv = kTRUE ; 
368   
369   if ( relid[1] ==  0 ) {                            // it is a Phos crystal
370     AbsId =
371       ( relid[0] - 1 ) * GetNPhi() * GetNZ()         // the offset of PHOS modules
372       + ( relid[2] - 1 ) * GetNZ()                   // the offset along phi
373       +   relid[3] ;                                 // the offset along z
374   }
375   else { // it is a CPV pad
376     AbsId =    GetNPhi() * GetNZ() *  GetNModules()         // the offset to separate EMCA crystals from CPV pads
377       + ( relid[0] - 1 ) * GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ()   // the pads offset of PHOS modules 
378       + ( relid[2] - 1 ) * GetNumberOfCPVPadsZ()                             // the pads offset of a CPV row
379       +   relid[3] ;                                                         // the column number
380   }
381   
382   return rv ; 
383 }
384
385 //____________________________________________________________________________
386
387 void AliPHOSGeometry::RelPosInAlice(const Int_t id, TVector3 & pos ) const
388 {
389   // Converts the absolute numbering into the global ALICE coordinate system
390   
391     
392     Int_t relid[4] ;
393     
394     AbsToRelNumbering(id , relid) ;
395     
396     Int_t phosmodule = relid[0] ; 
397     
398     Float_t y0 = 0 ; 
399     
400     if ( relid[1] == 0 )  // it is a PbW04 crystal 
401       y0 =  - GetIPtoCrystalSurface() ;  
402     else
403       y0 =  - GetIPtoUpperCPVsurface() ; 
404
405     Float_t x, z ; 
406     RelPosInModule(relid, x, z) ; 
407     
408     pos.SetX(x) ;
409     pos.SetZ(z) ;
410     pos.SetY(y0) ;
411     
412     Float_t phi           = GetPHOSAngle( phosmodule) ; 
413     Double_t const kRADDEG = 180.0 / kPI ;
414     Float_t rphi          = phi / kRADDEG ; 
415     
416     TRotation rot ;
417     rot.RotateZ(-rphi) ; // a rotation around Z by angle  
418     
419     TRotation dummy = rot.Invert() ;  // to transform from original frame to rotate frame
420     
421     pos.Transform(rot) ; // rotate the baby 
422
423
424 //____________________________________________________________________________
425 void AliPHOSGeometry::RelPosInModule(const Int_t * relid, Float_t & x, Float_t & z) const 
426 {
427   // Converts the relative numbering into the local PHOS-module (x, z) coordinates
428   // Note: sign of z differs from that in the previous version (Yu.Kharlov, 12 Oct 2000)
429   
430   Int_t row        = relid[2] ; //offset along x axis
431   Int_t column     = relid[3] ; //offset along z axis
432
433   
434   if ( relid[1] == 0 ) { // its a PbW04 crystal 
435     x = - ( GetNPhi()/2. - row    + 0.5 ) *  GetCrystalSize(0) ; // position of Xtal with respect
436     z =   ( GetNZ()  /2. - column + 0.5 ) *  GetCrystalSize(2) ; // of center of PHOS module  
437   }  
438   else  {    
439     x = - ( GetNumberOfCPVPadsPhi()/2. - row    - 0.5 ) * GetPadSizePhi()  ; // position of pad  with respect
440     z =   ( GetNumberOfCPVPadsZ()  /2. - column - 0.5 ) * GetPadSizeZ()  ; // of center of PHOS module  
441   }
442 }