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