]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGeometry.cxx
revised geometry, fully parametrized and including HCAL possibility
[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 // --- ROOT system ---
33
34 // --- Standard library ---
35 #include <stdlib.h> 
36
37 // --- AliRoot header files ---
38 #include <TMath.h>
39
40 // -- ALICE Headers.
41 #include "AliConst.h"
42
43 // --- EMCAL headers
44 #include "AliEMCALGeometry.h"
45
46 ClassImp(AliEMCALGeometry);
47
48 AliEMCALGeometry *AliEMCALGeometry::fgGeom = 0;
49 Bool_t            AliEMCALGeometry::fgInit = kFALSE;
50
51 //______________________________________________________________________
52 AliEMCALGeometry::~AliEMCALGeometry(void){
53     // dtor
54 }
55 //______________________________________________________________________
56 void AliEMCALGeometry::Init(void){
57     // Initializes the EMCAL parameters
58
59     fgInit = kFALSE; // Assume failer untill proven otherwise.
60
61     TString name(GetName()) ; 
62                  
63     if( name != "EMCALArch1a" &&
64         name != "EMCALArch1b" && 
65         name != "EMCALArch2a" && 
66         name != "EMCALArch2b" && 
67         name != "EMCALArch1aN" ){
68       Fatal("Init", "%s is not a known geometry (choose among EMCALArch1a, EMCALArch1b, EMCALArch2a and EMCALArch2b, EMCALArch1aN)",  name.Data()) ;  
69     } // end if
70     //
71     if ( name == "EMCALArch1a"  ||
72          name == "EMCALArch1b"  || 
73          name == "EMCALArch1aN") {
74       fNZ         = 96;
75       fNPhi       = 144;
76     } // end if
77     if ( name == "EMCALArch2a"  ||
78          name == "EMCALArch2b" ) {
79         fNZ         = 112;
80         fNPhi       = 168;
81     } // end if
82     if ( name == "EMCALArch1a"  ||
83          name == "EMCALArch2a" ) {
84       fNPRLayers  = 2;
85       fNECLayers  = 19;
86       fNHCLayers  = 0;
87     } // end if
88     if ( name == "EMCALArch1b"  ||
89          name == "EMCALArch2b" ) {
90         fNPRLayers  = 2;
91         fNECLayers  = 23;
92         fNHCLayers  = 0;
93     } // end if
94     if ( name == "EMCALArch1aN") { 
95       fNPRLayers   = 2;
96       fNECLayers  = 19;
97       fNHCLayers  = 14;
98     }
99
100     // geometry
101     fArm1PhiMin     =  60.0; // degrees, Starting EMCAL Phi position
102     fArm1PhiMax     = 180.0; // degrees, Ending EMCAL Phi position
103     fArm1EtaMin     = -0.7; // pseudorapidity, Starting EMCAL Eta position
104     fArm1EtaMax     = +0.7; // pseudorapidity, Ending EMCAL Eta position
105
106     fAlFrontThick        = 3.18; // cm, Thickness of front Al layer
107     fGap2Active          = 1.0;  // cm, Gap between Al and 1st Scintillator
108     fPbRadThickness      = 0.5;  // cm, Thickness of the Pb radiators.
109     fPreShowerSintThick  = 0.6;  // cm, Thickness of the sintilator for the preshower part of the calorimeter
110     fFullShowerSintThick = 0.5;  // cm, Thickness of the sintilator for the dull shower part of the calorimeter
111     fCuRadThickness      = 0.0;  // cm, Thickness of the Cu radiators.
112
113     if (name ==  "EMCALArch1aN") {
114       fAlFrontThick        = 3.0;  // cm, Thickness of front Al layer
115       fGap2Active          = 1.0;  // cm, Gap between Al and 1st Scintillator
116       fPbRadThickness      = 0.6;  // cm, Thickness of the Pb radiators.
117       fPreShowerSintThick  = 0.5;  // cm, Thickness of the sintilator for the preshower part of the calorimeter
118       fFullShowerSintThick = 0.4;  // cm, Thickness of the sintilator for the full shower part of the calorimeter
119       fCuRadThickness      = 1.0;  // cm, Thickness of the Cu radiators.
120    }
121
122     fIPDistance     = 454.0; // cm, Radial distance to inner surface of EMCAL
123     fShellThickness = fAlFrontThick + fGap2Active + 2.*(GetPreSintThick() + GetPbRadThick()) + // pre shower 
124       (fNECLayers-1)*(GetFullSintThick()+ GetPbRadThick()) + // E cal -1 because the last element is a scintillator
125       fNHCLayers*(GetFullSintThick()+ GetCuRadThick()) + // H cal
126       GetFullSintThick() ; // last scintillator
127     fZLength        = 2.*ZFromEtaR(fIPDistance+fShellThickness,fArm1EtaMax); // Z coverage
128     fEnvelop[0]     = fIPDistance; // mother volume inner radius
129     fEnvelop[1]     = fIPDistance + fShellThickness; // mother volume outer r.
130     fEnvelop[2]     = 1.00001*fZLength; // add some padding for mother volume. 
131     fgInit = kTRUE; 
132 }
133
134 //______________________________________________________________________
135 AliEMCALGeometry *  AliEMCALGeometry::GetInstance(){ 
136   // Returns the pointer of the unique instance
137   
138   return static_cast<AliEMCALGeometry *>( fgGeom ) ; 
139 }
140
141 //______________________________________________________________________
142 AliEMCALGeometry* AliEMCALGeometry::GetInstance(const Text_t* name,
143                                                 const Text_t* title){
144     // Returns the pointer of the unique instance
145
146     AliEMCALGeometry * rv = 0; 
147     if ( fgGeom == 0 ) {
148         if ( strcmp(name,"") == 0 ) rv = 0;
149         else {    
150             fgGeom = new AliEMCALGeometry(name, title);
151             if ( fgInit ) rv = (AliEMCALGeometry * ) fgGeom;
152             else {
153                 rv = 0; 
154                 delete fgGeom; 
155                 fgGeom = 0; 
156             } // end if fgInit
157         } // end if strcmp(name,"")
158     }else{
159         if ( strcmp(fgGeom->GetName(), name) != 0 ) {
160           TString message("\n") ; 
161           message += "current geometry is " ;  
162           message += fgGeom->GetName() ;
163           message += "\n                      you cannot call     " ; 
164           message += name ;  
165           ::Info("GetGeometry", message.Data() ) ; 
166         }else{
167           rv = (AliEMCALGeometry *) fgGeom; 
168         } // end if
169     }  // end if fgGeom
170     return rv; 
171 }
172
173 //______________________________________________________________________
174 Int_t AliEMCALGeometry::TowerIndex(Int_t ieta,Int_t iphi,Int_t ipre) const {
175     // Returns the tower index number from the based on the Z and Phi
176     // index numbers. There are 2 times the number of towers to separate
177     // out the full towers from the pre-showers.
178     // Inputs:
179     //   Int_t ieta    // index allong z axis [1-fNZ]
180     //   Int_t iphi  // index allong phi axis [1-fNPhi]
181     //   Int_t ipre  // 0 = Full tower, 1 = Pre-shower tower only. [0,1]
182     // Outputs:
183     //   none.
184     // Returned
185     // Int_t the absoulute tower index. [1-2*fNZ*fNPhi]
186     Int_t index;
187
188     if((ieta<=0 || ieta>GetNEta()) || (iphi<=0 || iphi>GetNPhi()) ||
189        (ipre<0 || ipre>1) ){
190       TString message ("\n") ; 
191       message += "inputs out of range ieta= " ; 
192       message += ieta ; 
193       message += " [1-" ; 
194       message += GetNEta() ;
195       message += "] iphi= " ; 
196       message += iphi ; 
197       message += " [1-" ; 
198       message += GetNPhi() ; 
199       message += "] ipre= " ;
200       message += ipre ; 
201       message += "[0,1]. returning -1" ; 
202       Warning("TowerIndex", message.Data() ) ; 
203       return -1;
204     } // end if
205     index = iphi + GetNPhi()*(ieta-1) + ipre*(GetNPhi()*GetNEta());
206     return index;
207 }
208
209 //______________________________________________________________________
210 void AliEMCALGeometry::TowerIndexes(Int_t index,Int_t &ieta,Int_t &iphi,
211                                     Int_t &ipre) const {
212     // given the tower index number it returns the based on the Z and Phi
213     // index numbers and if it is for the full tower or the pre-tower number.
214     // There are 2 times the number of towers to separate
215     // out the full towsers from the pre-towsers.
216     // Inputs:
217     //   Int_t index // Tower index number [1-2*fNZ*fNPhi]
218     // Outputs:
219     //   Int_t ieta    // index allong z axis [1-fNZ]
220     //   Int_t iphi  // index allong phi axis [1-fNPhi]
221     //   Int_t ipre  // 0 = Full tower, 1 = Pre-shower tower only. [0,1]
222     // Returned
223     //   none.
224     Int_t itowers;
225
226     itowers = GetNEta()*GetNPhi();
227     if(index<1 || index>2*itowers){
228       TString message("\n") ; 
229       message += "index= " ; 
230       message += index ; 
231       message += " is out of range [1-" ;
232       message += 2*itowers ; 
233       message += "], returning -1 for all." ;
234       Warning("TowerIndex", message.Data() ) ; 
235       ieta = -1; iphi = -1; ipre = -1;
236       return ;
237     } // end if
238     ipre = 0;
239     if(index>itowers){ // pre shower indexs
240         ipre = 1;
241         index = index - itowers;
242     } // end if
243     ieta = 1+ (Int_t)((index-1)/GetNPhi());
244     iphi = index - GetNPhi()*(ieta-1);
245     return;
246 }
247
248 //______________________________________________________________________
249 void AliEMCALGeometry::EtaPhiFromIndex(Int_t index,Float_t &eta,Float_t &phi) const {
250     // given the tower index number it returns the based on the eta and phi
251     // of the tower.
252     // Inputs:
253     //   Int_t index // Tower index number [1-2*fNZ*fNPhi]
254     // Outputs:
255     //   Float_t eta  // eta of center of tower in pseudorapidity
256     //   Float_t phi  // phi of center of tower in degrees
257     // Returned
258     //   none.
259     Int_t ieta,iphi,ipre;
260     Double_t deta,dphi,phid;
261
262     TowerIndexes(index,ieta,iphi,ipre);
263     deta = (GetArm1EtaMax()-GetArm1EtaMin())/((Float_t)GetNEta());
264     eta  = GetArm1EtaMin() + (((Float_t)ieta)-0.5)*deta;
265     dphi = (GetArm1PhiMax() - GetArm1PhiMin())/((Float_t)GetNPhi());  // in degrees.
266     phid = GetArm1PhiMin() + dphi*((Float_t)iphi -0.5);//iphi range [1-fNphi].
267     phi  = phid;
268 }
269
270 //______________________________________________________________________
271 Int_t AliEMCALGeometry::TowerIndexFromEtaPhi(Float_t eta,Float_t phi) const {
272     // returns the tower index number based on the eta and phi of the tower.
273     // Inputs:
274     //   Float_t eta  // eta of center of tower in pseudorapidity
275     //   Float_t phi  // phi of center of tower in degrees
276     // Outputs:
277     //   none.
278     // Returned
279     //   Int_t index // Tower index number [1-fNZ*fNPhi]
280     Int_t ieta,iphi;
281
282     ieta = 1 + (Int_t)(((Float_t)GetNEta())*(eta-GetArm1EtaMin())/
283                   (GetArm1EtaMax() - GetArm1EtaMin()));
284     if(ieta<=0 || ieta>GetNEta()){
285       TString message("\n") ; 
286       message += "ieta = " ; 
287       message += ieta ; 
288       message += " eta=" ; 
289       message += eta ; 
290       message += " is outside of EMCAL. etamin=" ;
291       message += GetArm1EtaMin() ;
292       message += " to etamax=" ; 
293       message += GetArm1EtaMax();
294       message += " returning -1";
295       Warning("TowerIndexFromEtaPhi", message.Data() ) ; 
296       return -1;
297     } // end if
298     iphi = 1 + (Int_t)(((Float_t)GetNPhi())*(phi-GetArm1PhiMin())/
299                   ((Float_t)(GetArm1PhiMax() - GetArm1PhiMin())));
300     if(iphi<=0 || iphi>GetNPhi()){
301       TString message("\n") ; 
302       message += "iphi=" ; 
303       message += iphi ;  
304       message += "phi= " ; 
305       message += phi ; 
306       message += " is outside of EMCAL." ;
307       message += " Phimin=" ; 
308       message += GetArm1PhiMin() ; 
309       message += " PhiMax=" ; 
310       message += GetArm1PhiMax() ;
311       message += " returning -1" ;
312       Warning("TowerIndexFromEtaPhi", message.Data() ) ; 
313       return -1;
314     } // end if
315     return TowerIndex(ieta,iphi,0);
316 }
317
318 //______________________________________________________________________
319 Int_t AliEMCALGeometry::PreTowerIndexFromEtaPhi(Float_t eta,Float_t phi) const {
320     // returns the pretower index number based on the eta and phi of the tower.
321     // Inputs:
322     //   Float_t eta  // eta of center of tower in pseudorapidity
323     //   Float_t phi  // phi of center of tower in degrees
324     // Outputs:
325     //   none.
326     // Returned
327     //   Int_t index // PreTower index number [fNZ*fNPhi-2*fNZ*fNPhi]
328
329     return GetNEta()*GetNPhi()+TowerIndexFromEtaPhi(eta,phi);
330 }
331
332 //______________________________________________________________________
333 Bool_t AliEMCALGeometry::AbsToRelNumbering(Int_t AbsId, Int_t *relid) const {
334     // Converts the absolute numbering into the following array/
335     //  relid[0] = EMCAL Arm number 1:1 
336     //  relid[1] = 0  Not in Pre Shower layers
337     //           = -1 In Pre Shower
338     //  relid[2] = Row number inside EMCAL
339     //  relid[3] = Column number inside EMCAL
340     // Input:
341     //   Int_t AbsId // Tower index number [1-2*fNZ*fNPhi]
342     // Outputs:
343     //   Int_t *relid // array of 5. Discribed above.
344     Bool_t rv  = kTRUE ;
345     Int_t ieta=0,iphi=0,ipre=0,index=AbsId;
346
347     TowerIndexes(index,ieta,iphi,ipre);
348     relid[0] = 1;
349     relid[1] = 0;
350     if(ipre==1) 
351       relid[1] = -1;
352     relid[2] = ieta;
353     relid[3] = iphi;
354
355     return rv;
356 }
357
358 //______________________________________________________________________
359 void AliEMCALGeometry::PosInAlice(const Int_t *relid,Float_t &theta,
360                                      Float_t &phi) const {
361     // Converts the relative numbering into the local EMCAL-module (x, z)
362     // coordinates
363     Int_t ieta   = relid[2]; // offset along x axis
364     Int_t iphi = relid[3]; // offset along z axis
365     Int_t ipre = relid[1]; // indicates -1 preshower, or 0 full tower.
366     Int_t index;
367     Float_t eta;
368
369     if(ipre==-1) ipre = 1;
370     index = TowerIndex(ieta,iphi,ipre);
371     EtaPhiFromIndex(index,eta,phi);
372     theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
373
374     return;
375 }
376
377 //______________________________________________________________________
378 void AliEMCALGeometry::XYZFromIndex(const Int_t *relid,Float_t &x,Float_t &y, Float_t &z) const {
379     // given the tower relative number it returns the X, Y and Z
380     // of the tower.
381     
382     // Outputs:
383     //   Float_t x  // x of center of tower in cm
384     //   Float_t y  // y of center of tower in cm
385     //   Float_t z  // z of centre of tower in cm
386     // Returned
387     //   none.
388     
389     Float_t eta,theta, phi,cyl_radius,kDeg2Rad;
390     
391     Int_t ieta   = relid[2]; // offset along x axis
392     Int_t iphi = relid[3]; // offset along z axis
393     Int_t ipre = relid[1]; // indicates -1 preshower, or 0 full tower.
394     Int_t index;
395     
396
397     if(ipre==-1) ipre = 1;
398     index = TowerIndex(ieta,iphi,ipre);
399     EtaPhiFromIndex(index,eta,phi);
400     theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
401     
402     kDeg2Rad = TMath::Pi() / static_cast<Double_t>(180) ; 
403     if ( ipre == -1 ) 
404       cyl_radius = GetIP2PreShower() ;
405     else 
406       cyl_radius = GetIP2Tower() ;
407
408     x =  cyl_radius * TMath::Cos(phi * kDeg2Rad ) ;
409     y =  cyl_radius * TMath::Sin(phi * kDeg2Rad ) ; 
410     z =  cyl_radius / TMath::Tan(theta * kDeg2Rad ) ; 
411  
412  return;
413
414
415 //______________________________________________________________________
416 /*
417 Boot_t AliEMCALGeometry::AreNeighbours(Int_t index1,Int_t index2) const {
418     // Returns kTRUE if the two towers are neighbours or not, including
419     // diagonals. Both indexes are required to be either towers or preshower.
420     // Inputs:
421     //   Int_t index1  // index of tower 1
422     //   Int_t index2  // index of tower 2
423     // Outputs:
424     //   none.
425     // Returned
426     //   Boot_t kTRUE if the towers are neighbours otherwise false.
427     Boot_t anb = kFALSE;
428     Int_t ieta1 = 0, ieta2 = 0, iphi1 = 0, iphi2 = 0, ipre1 = 0, ipre2 = 0;
429
430     TowerIndexes(index1,ieta1,iphi1,ipre1);
431     TowerIndexes(index2,ieta2,iphi2,ipre2);
432     if(ipre1!=ipre2) return anb;
433     if((ieta1>=ieta2-1 && ieta1<=ieta2+1) && (iphi1>=iphi2-1 &&iphi1<=iphi2+1))
434                                                                  anb = kTRUE;
435     return anb;
436 }
437  */