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