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