]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGeometry.cxx
Fixing problems in the generation of HTML documentation
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGeometry.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 EMCAL : singleton  
20 // EMCAL consists of layers of scintillator and lead
21 // Places the the Barrel Geometry of The EMCAL at Midrapidity
22 // between 0 and 120 degrees of Phi and
23 // -0.7 to 0.7 in eta 
24 // Number of Modules and Layers may be controlled by 
25 // the name of the instance defined               
26 // EMCALArch2x has more modules along both phi and eta
27 // EMCALArchxa has less Layers in the Radial Direction
28 //*-- Author: Sahal Yacoob (LBL / UCT)
29 //     and  : Yves Schutz (SUBATECH)
30 //     and  : Jennifer Klay (LBL)
31
32 // --- AliRoot header files ---
33 #include <TMath.h>
34 #include <TVector3.h>
35
36 // -- ALICE Headers.
37 //#include "AliConst.h"
38
39 // --- EMCAL headers
40 #include "AliEMCALGeometry.h"
41
42 ClassImp(AliEMCALGeometry);
43
44 AliEMCALGeometry *AliEMCALGeometry::fgGeom = 0;
45 Bool_t            AliEMCALGeometry::fgInit = kFALSE;
46
47 //______________________________________________________________________
48 AliEMCALGeometry::~AliEMCALGeometry(void){
49     // dtor
50 }
51
52 //______________________________________________________________________
53 const Bool_t AliEMCALGeometry::AreInSameTower(Int_t id1, Int_t id2) const {
54   // Find out whether two hits are in the same tower
55   Int_t idmax = TMath::Max(id1, id2) ; 
56   Int_t idmin = TMath::Min(id1, id2) ;
57   if ( ((idmax - GetNZ() * GetNPhi()) == idmin ) || 
58        ((idmax - 2 * GetNZ() * GetNPhi()) == idmin ) )
59     return kTRUE ; 
60   else 
61     return kFALSE ; 
62 }
63
64 //______________________________________________________________________
65 void AliEMCALGeometry::Init(void){
66   // Initializes the EMCAL parameters
67   // naming convention : GUV_WX_N_ gives the composition of a tower
68   // WX inform about the composition of the EM calorimeter section: 
69   //   thickness in mm of Pb radiator (W) and of scintillator (X), and number of scintillator layers (N)
70   // New geometry: EMCAL_55_25
71
72   fgInit = kFALSE; // Assume failed until proven otherwise.
73   TString name(GetName()) ; 
74   if (name == "EMCAL_55_25") {
75     fECPbRadThickness  = 0.5;  // cm, Thickness of the Pb radiators
76     fECScintThick      = 0.5;  // cm, Thickness of the scintillator
77     fNECLayers         = 25;   // number of scintillator layers
78     
79     fSampling          = 11.8; 
80  
81     fAlFrontThick      = 3.5;  // cm, Thickness of front Al layer
82     fGap2Active        = 1.0;  // cm, Gap between Al and 1st Scintillator
83   }
84   else if( name == "G56_2_55_19" || name == "EMCAL_5655_21" || name == "G56_2_55_19_104_14"|| name == "G65_2_64_19" || name == "EMCAL_6564_21"){
85     Fatal("Init", "%s is an old geometry! Please update your Config file", name.Data()) ;
86   }
87   else
88     Fatal("Init", "%s is an undefined geometry!", name.Data()) ; 
89                  
90   // geometry
91   fNZ             = 114;        // granularity along Z (eta) 
92   fNPhi           = 168;        // granularity in phi (azimuth)
93   fArm1PhiMin     = 60.0;       // degrees, Starting EMCAL Phi position
94   fArm1PhiMax     = 180.0;      // degrees, Ending EMCAL Phi position
95   fArm1EtaMin     = -0.7;       // pseudorapidity, Starting EMCAL Eta position
96   fArm1EtaMax     = +0.7;       // pseudorapidity, Ending EMCAL Eta position
97   
98   fIPDistance     = 454.0; // cm, Radial distance to inner surface of EMCAL
99
100   //There is always one more scintillator than radiator layer because of the first block of aluminium
101   fShellThickness = fAlFrontThick + fGap2Active + fNECLayers*GetECScintThick()+(fNECLayers-1)*GetECPbRadThick();
102
103   fZLength        = 2.*ZFromEtaR(fIPDistance+fShellThickness,fArm1EtaMax); // Z coverage
104   fEnvelop[0]     = fIPDistance; // mother volume inner radius
105   fEnvelop[1]     = fIPDistance + fShellThickness; // mother volume outer r.
106   fEnvelop[2]     = 1.00001*fZLength; // add some padding for mother volume. 
107   
108   fgInit = kTRUE; 
109   
110   if (gDebug) {
111     printf("Init: geometry of EMCAL named %s is as follows:", name.Data());
112     printf( "               ECAL      : %d x (%f mm Pb, %f mm Sc) \n", GetNECLayers(), GetECPbRadThick(), GetECScintThick() ) ; 
113     printf("Granularity: %d in eta and %d in phi\n", GetNZ(), GetNPhi()) ;
114     printf("Layout: phi = (%f, %f), eta = (%f, %f), y = %f\n",  
115            GetArm1PhiMin(), GetArm1PhiMax(),GetArm1EtaMin(), GetArm1EtaMax(), GetIPDistance() ) ;    
116   }
117 }
118
119 //______________________________________________________________________
120 AliEMCALGeometry *  AliEMCALGeometry::GetInstance(){ 
121   // Returns the pointer of the unique instance
122   
123   return static_cast<AliEMCALGeometry *>( fgGeom ) ; 
124 }
125
126 //______________________________________________________________________
127 AliEMCALGeometry* AliEMCALGeometry::GetInstance(const Text_t* name,
128                                                 const Text_t* title){
129     // Returns the pointer of the unique instance
130
131     AliEMCALGeometry * rv = 0; 
132     if ( fgGeom == 0 ) {
133         if ( strcmp(name,"") == 0 ) rv = 0;
134         else {    
135             fgGeom = new AliEMCALGeometry(name, title);
136             if ( fgInit ) rv = (AliEMCALGeometry * ) fgGeom;
137             else {
138                 rv = 0; 
139                 delete fgGeom; 
140                 fgGeom = 0; 
141             } // end if fgInit
142         } // end if strcmp(name,"")
143     }else{
144         if ( strcmp(fgGeom->GetName(), name) != 0 ) {
145           printf("\ncurrent geometry is ") ;  
146           printf(fgGeom->GetName());
147           printf("\n                      you cannot call     "); 
148           printf(name);  
149         }else{
150           rv = (AliEMCALGeometry *) fgGeom; 
151         } // end if
152     }  // end if fgGeom
153     return rv; 
154 }
155
156 //______________________________________________________________________
157 Int_t AliEMCALGeometry::TowerIndex(Int_t ieta,Int_t iphi) const {
158   // Returns the tower index number from the based on the Z and Phi
159   // index numbers.
160   // Inputs:
161   //   Int_t ieta    // index along z axis [1-fNZ]
162   //   Int_t iphi  // index along phi axis [1-fNPhi]
163   // Outputs:
164   //   none.
165   // Returned
166   //   Int_t index // Tower index number 
167   
168   if ( (ieta <= 0 || ieta>GetNEta()) || 
169        (iphi <= 0 || iphi>GetNPhi())) 
170     Fatal("TowerIndex", "Unexpected parameters eta = %d phi = %d!", ieta, iphi) ; 
171   
172   return ( (iphi - 1)*GetNEta() + ieta ); 
173 }
174
175 //______________________________________________________________________
176 void AliEMCALGeometry::TowerIndexes(Int_t index,Int_t &ieta,Int_t &iphi) const {
177   // Inputs:
178   //   Int_t index // Tower index number [1-fNZ*fNPhi]
179   // Outputs:
180   //   Int_t ieta    // index allong z axis [1-fNZ]
181   //   Int_t iphi  // index allong phi axis [1-fNPhi]
182   // Returned
183   //   none.
184
185   Int_t nindex = 0;
186
187   if ( IsInECA(index) ) { // ECAL index
188     nindex = index ;
189   }
190   else 
191     Fatal("TowerIndexes", "Unexpected Id number!") ;
192    
193   if (nindex%GetNZ()) 
194     iphi = nindex / GetNZ() + 1 ; 
195   else 
196     iphi = nindex / GetNZ() ; 
197   ieta = nindex - (iphi - 1) * GetNZ() ; 
198
199   if (gDebug==2)
200     printf("TowerIndexes: index=%d,%d, ieta=%d, iphi = %d", index, nindex,ieta, iphi) ; 
201   return;
202   
203 }
204
205 //______________________________________________________________________
206 void AliEMCALGeometry::EtaPhiFromIndex(Int_t index,Float_t &eta,Float_t &phi) const {
207     // given the tower index number it returns the based on the eta and phi
208     // of the tower.
209     // Inputs:
210     //   Int_t index // Tower index number [1-fNZ*fNPhi]
211     // Outputs:
212     //   Float_t eta  // eta of center of tower in pseudorapidity
213     //   Float_t phi  // phi of center of tower in degrees
214     // Returned
215     //   none.
216     Int_t ieta, iphi;
217     Float_t deta, dphi ;
218
219     TowerIndexes(index,ieta,iphi);
220     
221     if (gDebug == 2) 
222       printf("EtaPhiFromIndex: index = %d, ieta = %d, iphi = %d", index, ieta, iphi) ;
223
224     deta = (GetArm1EtaMax()-GetArm1EtaMin())/(static_cast<Float_t>(GetNEta()));
225     eta  = GetArm1EtaMin() + ((static_cast<Float_t>(ieta) - 0.5 ))*deta;
226
227     dphi = (GetArm1PhiMax() - GetArm1PhiMin())/(static_cast<Float_t>(GetNPhi()));  // in degrees.
228     phi  = GetArm1PhiMin() + dphi*(static_cast<Float_t>(iphi) - 0.5);//iphi range [1-fNphi].
229 }
230
231 //______________________________________________________________________
232 Int_t AliEMCALGeometry::TowerIndexFromEtaPhi(Float_t eta,Float_t phi) const {
233     // returns the tower index number based on the eta and phi of the tower.
234     // Inputs:
235     //   Float_t eta  // eta of center of tower in pseudorapidity
236     //   Float_t phi  // phi of center of tower in degrees
237     // Outputs:
238     //   none.
239     // Returned
240     //   Int_t index // Tower index number [1-fNZ*fNPhi]
241
242     Int_t ieta,iphi;
243
244     ieta = static_cast<Int_t> ( 1 + (static_cast<Float_t>(GetNEta()) * (eta - GetArm1EtaMin()) / (GetArm1EtaMax() - GetArm1EtaMin())) ) ;
245
246     if( ieta <= 0 || ieta > GetNEta() ) { 
247       Error("TowerIndexFromEtaPhi", "Unexpected (eta, phi) = (%f, %f) value, outside of EMCAL!", eta, phi) ; 
248       return -1 ; 
249     }
250
251     iphi = static_cast<Int_t> ( 1 + (static_cast<Float_t>(GetNPhi()) * (phi - GetArm1PhiMin()) / (GetArm1PhiMax() - GetArm1PhiMin())) ) ;
252
253     if( iphi <= 0 || iphi > GetNPhi() ) { 
254       Error("TowerIndexFromEtaPhi", "Unexpected (eta, phi) = (%f, %f) value, outside of EMCAL!", eta, phi) ; 
255       return -1 ; 
256     }
257
258     return TowerIndex(ieta,iphi);
259 }
260
261 //______________________________________________________________________
262 Int_t AliEMCALGeometry::PreTowerIndexFromEtaPhi(Float_t eta,Float_t phi) const {
263     // returns the pretower index number based on the eta and phi of the tower.
264     // Inputs:
265     //   Float_t eta  // eta of center of tower in pseudorapidity
266     //   Float_t phi  // phi of center of tower in degrees
267     // Outputs:
268     //   none.
269     // Returned
270     //   Int_t index // PreTower index number [fNZ*fNPhi-2*fNZ*fNPhi]
271
272     return GetNEta()*GetNPhi()+TowerIndexFromEtaPhi(eta,phi);
273 }
274
275 //______________________________________________________________________
276 Bool_t AliEMCALGeometry::AbsToRelNumbering(Int_t AbsId, Int_t *relid) const {
277     // Converts the absolute numbering into the following array/
278     //  relid[0] = EMCAL Arm number 1:1 
279     //  relid[1] = Row number inside EMCAL
280     //  relid[2] = Column number inside EMCAL
281     // Input:
282     //   Int_t AbsId // Tower index number [1-2*fNZ*fNPhi]
283     // Outputs:
284     //   Int_t *relid // array of 3. Discribed above.
285     Bool_t rv  = kTRUE ;
286     Int_t ieta=0,iphi=0,index=AbsId;
287
288     TowerIndexes(index,ieta,iphi);
289     relid[0] = 1;
290     relid[1] = ieta;
291     relid[2] = iphi;
292
293     return rv;
294 }
295
296 //______________________________________________________________________
297 void AliEMCALGeometry::PosInAlice(const Int_t *relid, Float_t &theta, Float_t &phi) const 
298 {
299   // Converts the relative numbering into the local EMCAL-module (x, z)
300   // coordinates
301   Int_t ieta = relid[1]; // offset along x axis
302   Int_t iphi = relid[2]; // offset along z axis
303   Int_t index;
304   Float_t eta;
305   
306   index = TowerIndex(ieta,iphi);
307   EtaPhiFromIndex(index,eta,phi);
308   //theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
309   theta = 2.0*TMath::ATan(TMath::Exp(-eta));
310
311   // correct for distance to IP
312   Float_t d = GetIP2ECASection() - GetIPDistance() ;  
313
314   Float_t correction = 1 + d/GetIPDistance() ; 
315   Float_t tantheta = TMath::Tan(theta) * correction ; 
316   theta = TMath::ATan(tantheta) * TMath::RadToDeg() ; 
317   if (theta < 0 ) 
318     theta += 180. ; 
319   
320   return;
321 }
322
323 //______________________________________________________________________
324 void AliEMCALGeometry::PosInAlice(const Int_t absid, Float_t &theta, Float_t &phi) const 
325 {
326   // Converts the relative numbering into the local EMCAL-module (x, z)
327   // coordinates
328   
329   Int_t relid[3] ; 
330   AbsToRelNumbering(absid, relid) ;
331   Int_t ieta = relid[1]; // offset along x axis
332   Int_t iphi = relid[2]; // offset along z axis
333   Int_t index;
334   Float_t eta;
335   
336   index = TowerIndex(ieta,iphi);
337   EtaPhiFromIndex(index,eta,phi);
338   theta = 2.0*TMath::ATan(TMath::Exp(-eta)) ;
339   
340   // correct for distance to IP
341   Float_t d = 0. ; 
342   if (IsInECA(absid))
343     d = GetIP2ECASection() - GetIPDistance() ; 
344   else 
345     Fatal("PosInAlice", "Unexpected id # %d!", absid) ; 
346
347   Float_t correction = 1 + d/GetIPDistance() ; 
348   Float_t tantheta = TMath::Tan(theta) * correction ; 
349   theta = TMath::ATan(tantheta) * TMath::RadToDeg() ; 
350   if (theta < 0 ) 
351     theta += 180. ; 
352   
353   return;
354 }
355
356 //______________________________________________________________________
357 void AliEMCALGeometry::XYZFromIndex(const Int_t *relid,Float_t &x,Float_t &y, Float_t &z) const {
358     // given the tower relative number it returns the X, Y and Z
359     // of the tower.
360     
361     // Outputs:
362     //   Float_t x  // x of center of tower in cm
363     //   Float_t y  // y of center of tower in cm
364     //   Float_t z  // z of centre of tower in cm
365     // Returned
366     //   none.
367     
368     Float_t eta,theta, phi,cylradius=0. ;
369     
370     Int_t ieta   = relid[1]; // offset along x axis
371     Int_t iphi = relid[2]; // offset along z axis.
372     Int_t index;
373     
374     index = TowerIndex(ieta,iphi);
375     EtaPhiFromIndex(index,eta,phi);
376     theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
377     
378     cylradius = GetIP2ECASection() ;  
379
380     Double_t  kDeg2Rad = TMath::DegToRad() ; 
381     x =  cylradius * TMath::Cos(phi * kDeg2Rad ) ;
382     y =  cylradius * TMath::Sin(phi * kDeg2Rad ) ; 
383     z =  cylradius / TMath::Tan(theta * kDeg2Rad ) ; 
384  
385  return;
386
387
388 //______________________________________________________________________
389 void AliEMCALGeometry::XYZFromIndex(const Int_t absid,  TVector3 &v) const {
390     // given the tower relative number it returns the X, Y and Z
391     // of the tower.
392     
393     // Outputs:
394     //   Float_t x  // x of center of tower in cm
395     //   Float_t y  // y of center of tower in cm
396     //   Float_t z  // z of centre of tower in cm
397     // Returned
398     //   none.
399     
400     Float_t theta, phi,cylradius=0. ;
401         
402     PosInAlice(absid, theta, phi) ; 
403     
404     if ( IsInECA(absid) ) 
405       cylradius = GetIP2ECASection() ;
406     else 
407       Fatal("XYZFromIndex", "Unexpected Tower section") ;  
408
409     Double_t  kDeg2Rad = TMath::DegToRad() ; 
410     v.SetX(cylradius * TMath::Cos(phi * kDeg2Rad ) );
411     v.SetY(cylradius * TMath::Sin(phi * kDeg2Rad ) ); 
412     v.SetZ(cylradius / TMath::Tan(theta * kDeg2Rad ) ) ; 
413  
414  return;
415
416
417 //______________________________________________________________________
418 /*
419 Boot_t AliEMCALGeometry::AreNeighbours(Int_t index1,Int_t index2) const {
420     // Returns kTRUE if the two towers are neighbours or not, including
421     // diagonals. Both indexes are required to be either towers or preshower.
422     // Inputs:
423     //   Int_t index1  // index of tower 1
424     //   Int_t index2  // index of tower 2
425     // Outputs:
426     //   none.
427     // Returned
428     //   Boot_t kTRUE if the towers are neighbours otherwise false.
429     Boot_t anb = kFALSE;
430     Int_t ieta1 = 0, ieta2 = 0, iphi1 = 0, iphi2 = 0;
431
432     TowerIndexes(index1,ieta1,iphi1);
433     TowerIndexes(index2,ieta2,iphi2);
434     if((ieta1>=ieta2-1 && ieta1<=ieta2+1) && (iphi1>=iphi2-1 &&iphi1<=iphi2+1))
435                                                                  anb = kTRUE;
436     return anb;
437 }
438  */