]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALGeometry.cxx
Get stack for each event (Yu.Belikov)
[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
2012850d 32// --- AliRoot header files ---
ca8f5bd0 33#include <TMath.h>
116cbefd 34#include <TVector3.h>
173558f2 35
ca8f5bd0 36// -- ALICE Headers.
d64c959b 37//#include "AliConst.h"
173558f2 38
ca8f5bd0 39// --- EMCAL headers
40#include "AliEMCALGeometry.h"
2012850d 41
b13bbe81 42ClassImp(AliEMCALGeometry);
2012850d 43
b13bbe81 44AliEMCALGeometry *AliEMCALGeometry::fgGeom = 0;
45Bool_t AliEMCALGeometry::fgInit = kFALSE;
2012850d 46
b13bbe81 47//______________________________________________________________________
48AliEMCALGeometry::~AliEMCALGeometry(void){
49 // dtor
2012850d 50}
b13bbe81 51
395c7ba2 52//______________________________________________________________________
53const Bool_t AliEMCALGeometry::AreInSameTower(Int_t id1, Int_t id2) const {
fdebddeb 54 // Find out whether two hits are in the same tower
395c7ba2 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}
05a92d59 63
395c7ba2 64//______________________________________________________________________
65void AliEMCALGeometry::Init(void){
66 // Initializes the EMCAL parameters
fdebddeb 67 // naming convention : GUV_WX_N_ gives the composition of a tower
395c7ba2 68 // WX inform about the composition of the EM calorimeter section:
fdebddeb 69 // thickness in mm of Pb radiator (W) and of scintillator (X), and number of scintillator layers (N)
70 // New geometry: EMCAL_55_25
395c7ba2 71
fdebddeb 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
395c7ba2 78
fdebddeb 79 fSampling = 11.8;
395c7ba2 80
fdebddeb 81 fAlFrontThick = 3.5; // cm, Thickness of front Al layer
395c7ba2 82 fGap2Active = 1.0; // cm, Gap between Al and 1st Scintillator
83 }
fdebddeb 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()) ;
395c7ba2 86 }
87 else
88 Fatal("Init", "%s is an undefined geometry!", name.Data()) ;
05a92d59 89
395c7ba2 90 // geometry
fdebddeb 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
395c7ba2 97
98 fIPDistance = 454.0; // cm, Radial distance to inner surface of EMCAL
fdebddeb 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
395c7ba2 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
88cb7938 110 if (gDebug) {
fdebddeb 111 printf("Init: geometry of EMCAL named %s is as follows:", name.Data());
88cb7938 112 printf( " ECAL : %d x (%f mm Pb, %f mm Sc) \n", GetNECLayers(), GetECPbRadThick(), GetECScintThick() ) ;
88cb7938 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 }
2012850d 117}
173558f2 118
b13bbe81 119//______________________________________________________________________
120AliEMCALGeometry * AliEMCALGeometry::GetInstance(){
05a92d59 121 // Returns the pointer of the unique instance
122
123 return static_cast<AliEMCALGeometry *>( fgGeom ) ;
2012850d 124}
173558f2 125
b13bbe81 126//______________________________________________________________________
127AliEMCALGeometry* 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 ) {
fdebddeb 145 printf("\ncurrent geometry is ") ;
146 printf(fgGeom->GetName());
147 printf("\n you cannot call ");
148 printf(name);
b13bbe81 149 }else{
9859bfc0 150 rv = (AliEMCALGeometry *) fgGeom;
b13bbe81 151 } // end if
152 } // end if fgGeom
153 return rv;
2012850d 154}
173558f2 155
ca8f5bd0 156//______________________________________________________________________
395c7ba2 157Int_t AliEMCALGeometry::TowerIndex(Int_t ieta,Int_t iphi) const {
158 // Returns the tower index number from the based on the Z and Phi
fdebddeb 159 // index numbers.
395c7ba2 160 // Inputs:
fdebddeb 161 // Int_t ieta // index along z axis [1-fNZ]
162 // Int_t iphi // index along phi axis [1-fNPhi]
395c7ba2 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 );
ca8f5bd0 173}
173558f2 174
ca8f5bd0 175//______________________________________________________________________
fdebddeb 176void AliEMCALGeometry::TowerIndexes(Int_t index,Int_t &ieta,Int_t &iphi) const {
395c7ba2 177 // Inputs:
fdebddeb 178 // Int_t index // Tower index number [1-fNZ*fNPhi]
395c7ba2 179 // Outputs:
180 // Int_t ieta // index allong z axis [1-fNZ]
181 // Int_t iphi // index allong phi axis [1-fNPhi]
395c7ba2 182 // Returned
183 // none.
395c7ba2 184
fdebddeb 185 Int_t nindex = 0;
395c7ba2 186
fdebddeb 187 if ( IsInECA(index) ) { // ECAL index
395c7ba2 188 nindex = index ;
395c7ba2 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)
fdebddeb 200 printf("TowerIndexes: index=%d,%d, ieta=%d, iphi = %d", index, nindex,ieta, iphi) ;
395c7ba2 201 return;
202
ca8f5bd0 203}
173558f2 204
ca8f5bd0 205//______________________________________________________________________
a34b7b9f 206void AliEMCALGeometry::EtaPhiFromIndex(Int_t index,Float_t &eta,Float_t &phi) const {
ca8f5bd0 207 // given the tower index number it returns the based on the eta and phi
208 // of the tower.
209 // Inputs:
fdebddeb 210 // Int_t index // Tower index number [1-fNZ*fNPhi]
ca8f5bd0 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.
fdebddeb 216 Int_t ieta, iphi;
395c7ba2 217 Float_t deta, dphi ;
ca8f5bd0 218
fdebddeb 219 TowerIndexes(index,ieta,iphi);
395c7ba2 220
221 if (gDebug == 2)
fdebddeb 222 printf("EtaPhiFromIndex: index = %d, ieta = %d, iphi = %d", index, ieta, iphi) ;
395c7ba2 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].
ca8f5bd0 229}
173558f2 230
ca8f5bd0 231//______________________________________________________________________
a34b7b9f 232Int_t AliEMCALGeometry::TowerIndexFromEtaPhi(Float_t eta,Float_t phi) const {
ca8f5bd0 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]
395c7ba2 241
e908f07f 242 Int_t ieta,iphi;
ca8f5bd0 243
395c7ba2 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);
ca8f5bd0 259}
173558f2 260
ca8f5bd0 261//______________________________________________________________________
a34b7b9f 262Int_t AliEMCALGeometry::PreTowerIndexFromEtaPhi(Float_t eta,Float_t phi) const {
ca8f5bd0 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
e908f07f 272 return GetNEta()*GetNPhi()+TowerIndexFromEtaPhi(eta,phi);
ca8f5bd0 273}
173558f2 274
ca8f5bd0 275//______________________________________________________________________
a34b7b9f 276Bool_t AliEMCALGeometry::AbsToRelNumbering(Int_t AbsId, Int_t *relid) const {
ca8f5bd0 277 // Converts the absolute numbering into the following array/
5a9318ff 278 // relid[0] = EMCAL Arm number 1:1
fdebddeb 279 // relid[1] = Row number inside EMCAL
280 // relid[2] = Column number inside EMCAL
ca8f5bd0 281 // Input:
282 // Int_t AbsId // Tower index number [1-2*fNZ*fNPhi]
283 // Outputs:
fdebddeb 284 // Int_t *relid // array of 3. Discribed above.
ca8f5bd0 285 Bool_t rv = kTRUE ;
fdebddeb 286 Int_t ieta=0,iphi=0,index=AbsId;
ca8f5bd0 287
fdebddeb 288 TowerIndexes(index,ieta,iphi);
ca8f5bd0 289 relid[0] = 1;
fdebddeb 290 relid[1] = ieta;
291 relid[2] = iphi;
ca8f5bd0 292
293 return rv;
294}
173558f2 295
ca8f5bd0 296//______________________________________________________________________
395c7ba2 297void 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
fdebddeb 301 Int_t ieta = relid[1]; // offset along x axis
302 Int_t iphi = relid[2]; // offset along z axis
395c7ba2 303 Int_t index;
304 Float_t eta;
305
306 index = TowerIndex(ieta,iphi);
307 EtaPhiFromIndex(index,eta,phi);
fdebddeb 308 //theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
309 theta = 2.0*TMath::ATan(TMath::Exp(-eta));
395c7ba2 310
fdebddeb 311 // correct for distance to IP
312 Float_t d = GetIP2ECASection() - GetIPDistance() ;
395c7ba2 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}
ca8f5bd0 322
395c7ba2 323//______________________________________________________________________
324void 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
fdebddeb 329 Int_t relid[3] ;
395c7ba2 330 AbsToRelNumbering(absid, relid) ;
fdebddeb 331 Int_t ieta = relid[1]; // offset along x axis
332 Int_t iphi = relid[2]; // offset along z axis
395c7ba2 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
fdebddeb 340 // correct for distance to IP
395c7ba2 341 Float_t d = 0. ;
fdebddeb 342 if (IsInECA(absid))
88cb7938 343 d = GetIP2ECASection() - GetIPDistance() ;
395c7ba2 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;
ca8f5bd0 354}
6119e5db 355
356//______________________________________________________________________
357void 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
fdebddeb 368 Float_t eta,theta, phi,cylradius=0. ;
6119e5db 369
fdebddeb 370 Int_t ieta = relid[1]; // offset along x axis
371 Int_t iphi = relid[2]; // offset along z axis.
6119e5db 372 Int_t index;
373
395c7ba2 374 index = TowerIndex(ieta,iphi);
6119e5db 375 EtaPhiFromIndex(index,eta,phi);
376 theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
6119e5db 377
fdebddeb 378 cylradius = GetIP2ECASection() ;
a97849a9 379
395c7ba2 380 Double_t kDeg2Rad = TMath::DegToRad() ;
fdebddeb 381 x = cylradius * TMath::Cos(phi * kDeg2Rad ) ;
382 y = cylradius * TMath::Sin(phi * kDeg2Rad ) ;
383 z = cylradius / TMath::Tan(theta * kDeg2Rad ) ;
6119e5db 384
385 return;
386}
387
395c7ba2 388//______________________________________________________________________
389void 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
fdebddeb 400 Float_t theta, phi,cylradius=0. ;
395c7ba2 401
402 PosInAlice(absid, theta, phi) ;
403
88cb7938 404 if ( IsInECA(absid) )
fdebddeb 405 cylradius = GetIP2ECASection() ;
395c7ba2 406 else
407 Fatal("XYZFromIndex", "Unexpected Tower section") ;
408
409 Double_t kDeg2Rad = TMath::DegToRad() ;
fdebddeb 410 v.SetX(cylradius * TMath::Cos(phi * kDeg2Rad ) );
411 v.SetY(cylradius * TMath::Sin(phi * kDeg2Rad ) );
412 v.SetZ(cylradius / TMath::Tan(theta * kDeg2Rad ) ) ;
395c7ba2 413
414 return;
415}
416
ca8f5bd0 417//______________________________________________________________________
418/*
a34b7b9f 419Boot_t AliEMCALGeometry::AreNeighbours(Int_t index1,Int_t index2) const {
ca8f5bd0 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;
fdebddeb 430 Int_t ieta1 = 0, ieta2 = 0, iphi1 = 0, iphi2 = 0;
ca8f5bd0 431
fdebddeb 432 TowerIndexes(index1,ieta1,iphi1);
433 TowerIndexes(index2,ieta2,iphi2);
e908f07f 434 if((ieta1>=ieta2-1 && ieta1<=ieta2+1) && (iphi1>=iphi2-1 &&iphi1<=iphi2+1))
ca8f5bd0 435 anb = kTRUE;
436 return anb;
437}
438 */