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