Bug fix in the constructor (thanks to A.Marin)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGeometry.h
CommitLineData
2012850d 1#ifndef ALIEMCALGEOMETRY_H
2#define ALIEMCALGEOMETRY_H
e8c0d6bb 3/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
2012850d 4 * See cxx source for full Copyright notice */
5
6/* $Id$ */
7
8//_________________________________________________________________________
9// Geometry class for EMCAL : singleton
b13bbe81 10// EMCAL consists of a layers of scintillator, and lead.
2012850d 11//
b13bbe81 12//*-- Author: Sahal Yacoob (LBL / UCT)
13//*-- and : Yves Schutz (Subatech)
3d841a9f 14//*-- and : Alexei Pavlinov (WSU) - shashlyk staff
f0377b23 15//*-- and : Gustavo Conesa: Add TRU mapping. TRU parameters still not fixed.
e8c0d6bb 16//*-- and : Magali Estienne : analysis access adaptations
2012850d 17
18// --- ROOT system ---
e8c0d6bb 19#include <TNamed.h>
37890aaf 20#include <TMath.h>
21#include <TArrayD.h>
e8c0d6bb 22#include <TVector3.h>
23#include <TGeoMatrix.h>
24class TBrowser ;
25class TParticle ;
2012850d 26
2012850d 27// --- AliRoot header files ---
0c5b726e 28#include "AliEMCALEMCGeometry.h"
e8c0d6bb 29#include "AliEMCALGeoParams.h"
30class AliEMCALShishKebabTrd1Module;
31#include "AliLog.h"
090026bf 32
e8c0d6bb 33class AliEMCALGeometry : public TNamed {
2012850d 34
e8c0d6bb 35public:
0c5b726e 36
e8c0d6bb 37 AliEMCALGeometry();
38 AliEMCALGeometry(const Text_t* name, const Text_t* title="");
39 AliEMCALGeometry(const AliEMCALGeometry & geom);
40
d434833b 41 virtual ~AliEMCALGeometry(void);
e8c0d6bb 42 AliEMCALGeometry & operator = (const AliEMCALGeometry & rvalue);
43
a97849a9 44 static AliEMCALGeometry * GetInstance(const Text_t* name,
45 const Text_t* title="") ;
89557f6d 46 static AliEMCALGeometry * GetInstance();
937d0661 47
937d0661 48
49 //////////
50 // General
51 //
0c5b726e 52 Bool_t IsInitialized(void) const { return AliEMCALEMCGeometry::fgInit ; }
53 static const Char_t* GetDefaultGeometryName() {return AliEMCALEMCGeometry::fgkDefaultGeometryName;}
e8c0d6bb 54
55 /////////////
56 // TRD1 stuff
57 void CreateListOfTrd1Modules();
58 TList *GetShishKebabTrd1Modules() const {return fShishKebabTrd1Modules;}
59 AliEMCALShishKebabTrd1Module *GetShishKebabModule(Int_t neta) const;
0c5b726e 60
e8c0d6bb 61 void PrintGeometryGeoUtils(); // *MENU*
62 void PrintCellIndexes(Int_t absId=0, int pri=0, const char *tit="") const ; //*MENU*
63 void PrintLocalTrd1(Int_t pri=0) const; // *MENU*
64 virtual void Browse(TBrowser* b);
65 virtual Bool_t IsFolder() const;
ab37d09c 66
e8c0d6bb 67 virtual Bool_t Impact(const TParticle *) const;
68 void ImpactOnEmcal(TVector3 vtx, Double_t theta, Double_t phi, Int_t & absId, TVector3 & vimpact) const;
69 Bool_t IsInEMCAL(Double_t x, Double_t y, Double_t z) const;
937d0661 70
71 //////////////////////////////////////
c63c3c5d 72 // Return EMCAL geometrical parameters
937d0661 73 //
e8c0d6bb 74
75 AliEMCALEMCGeometry* GetEMCGeometry() const { return fEMCGeometry ; }
76 //
77 const Char_t* GetNameOfEMCALEnvelope(void) const { return fEMCGeometry->GetNameOfEMCALEnvelope() ; }
78 Float_t GetArm1PhiMin(void) const { return fEMCGeometry->GetArm1PhiMin() ; }
79 Float_t GetArm1PhiMax(void) const { return fEMCGeometry->GetArm1PhiMax() ; }
80 Float_t GetArm1EtaMin(void) const { return fEMCGeometry->GetArm1EtaMin() ; }
81 Float_t GetArm1EtaMax(void) const { return fEMCGeometry->GetArm1EtaMax() ; }
82 Float_t GetIPDistance(void) const { return fEMCGeometry->GetIPDistance() ; }
83 Float_t GetEnvelop(Int_t index) const { return fEMCGeometry->GetEnvelop(index) ; }
84 Float_t GetShellThickness(void) const { return fEMCGeometry->GetShellThickness() ; }
85 Float_t GetZLength(void) const { return fEMCGeometry->GetZLength() ; }
86 Int_t GetNECLayers(void) const { return fEMCGeometry->GetNECLayers() ; }
87 Int_t GetNZ(void) const { return fEMCGeometry->GetNZ() ; }
88 Int_t GetNEta(void) const { return fEMCGeometry->GetNEta() ; }
89 Int_t GetNPhi(void) const { return fEMCGeometry->GetNPhi() ; }
90 Float_t GetECPbRadThick(void) const { return fEMCGeometry->GetECPbRadThick() ; }
91 Float_t GetECScintThick(void) const { return fEMCGeometry->GetECScintThick() ; }
92 Float_t GetSampling(void) const { return fEMCGeometry->GetSampling() ; }
93 Int_t GetNumberOfSuperModules(void) const { return fEMCGeometry->GetNumberOfSuperModules() ; }
94 Float_t GetPhiGapForSuperModules(void) const { return fEMCGeometry->GetfPhiGapForSuperModules() ; }
95 Float_t GetPhiModuleSize(void) const { return fEMCGeometry->GetPhiModuleSize() ; }
96 Float_t GetEtaModuleSize(void) const { return fEMCGeometry->GetEtaModuleSize() ; }
97 Float_t GetFrontSteelStrip(void) const { return fEMCGeometry->GetFrontSteelStrip() ; }
98 Float_t GetLateralSteelStrip(void) const { return fEMCGeometry->GetLateralSteelStrip() ; }
99 Float_t GetPassiveScintThick(void) const { return fEMCGeometry->GetPassiveScintThick() ; }
100 Float_t GetPhiTileSize(void) const { return fEMCGeometry->GetPhiTileSize() ; }
101 Float_t GetEtaTileSize(void) const { return fEMCGeometry->GetEtaTileSize() ; }
102 Int_t GetNPhiSuperModule(void) const { return fEMCGeometry->GetNPhiSuperModule() ; }
103 Int_t GetNPHIdiv(void) const { return fEMCGeometry->GetNPHIdiv() ; }
104 Int_t GetNETAdiv(void) const { return fEMCGeometry->GetNETAdiv() ; }
105 Int_t GetNCells(void) const { return fEMCGeometry->GetNCells() ; }
106 Float_t GetLongModuleSize(void) const { return fEMCGeometry->GetLongModuleSize() ; }
107 Float_t GetTrd1Angle(void) const { return fEMCGeometry->GetTrd1Angle() ; }
108 Float_t Get2Trd1Dx2(void) const { return fEMCGeometry->Get2Trd1Dx2() ; }
109 Float_t GetTrd1AlFrontThick() const { return fEMCGeometry->GetTrd1AlFrontThick() ; }
110 Float_t GetTrd1BondPaperThick() const { return fEMCGeometry->GetTrd1BondPaperThick() ; }
111 // --
112 Int_t GetNCellsInSupMod(void) const { return fEMCGeometry->GetNCellsInSupMod() ; }
113 Int_t GetNCellsInModule(void) const { return fEMCGeometry->GetNCellsInModule() ; }
114 Int_t GetKey110DEG(void) const { return fEMCGeometry->GetKey110DEG() ; }
115 Int_t GetILOSS(void) const { return fEMCGeometry->GetILOSS() ; }
116 Int_t GetIHADR(void) const { return fEMCGeometry->GetIHADR() ; }
85c25c2e 117 // --
e8c0d6bb 118 Float_t GetDeltaEta(void) const { return fEMCGeometry->GetDeltaEta() ; }
119 Float_t GetDeltaPhi(void) const { return fEMCGeometry->GetDeltaPhi() ; }
120 Int_t GetNTowers(void) const { return fEMCGeometry->GetNTowers() ; }
937d0661 121 //
e8c0d6bb 122 Double_t GetPhiCenterOfSM(Int_t nsupmod) const { return fEMCGeometry->GetPhiCenterOfSM(nsupmod) ; }
123 Float_t GetSuperModulesPar(Int_t ipar) const { return fEMCGeometry->GetSuperModulesPar(ipar) ; }
937d0661 124 //
e8c0d6bb 125 Bool_t GetPhiBoundariesOfSM(Int_t nSupMod, Double_t &phiMin, Double_t &phiMax) const
126 { return fEMCGeometry->GetPhiBoundariesOfSM(nSupMod, phiMin, phiMax) ; }
127 Bool_t GetPhiBoundariesOfSMGap(Int_t nPhiSec, Double_t &phiMin, Double_t &phiMax) const
128 { return fEMCGeometry->GetPhiBoundariesOfSMGap(nPhiSec, phiMin, phiMax); }
937d0661 129 //
225cd96d 130
e8c0d6bb 131 //////////////////////////////////////////////////
132 // Obsolete methods to be thrown out when feasible
133 Float_t GetGap2Active(void) const { return fEMCGeometry->GetGap2Active() ; }
134 Float_t GetSteelFrontThickness(void) const { return fEMCGeometry->GetSteelFrontThickness() ; }
135 Float_t GetTrd2AngleY(void) const { return fEMCGeometry->GetTrd2AngleY() ; }
136 Float_t Get2Trd2Dy2(void) const { return fEMCGeometry->Get2Trd2Dy2() ; }
137 Float_t GetTubsR(void) const { return fEMCGeometry->GetTubsR() ; }
138 Float_t GetTubsTurnAngle(void) const { return fEMCGeometry->GetTubsTurnAngle() ; }
139 //Float_t GetAlFrontThickness(void) const { return fEMCGeometry->GetAlFrontThickness() ; }
140 //Float_t GetIP2ECASection(void) const { return fEMCGeometry->GetIP2ECASection() ; }
141 //////////////////////////////////////////////////
142
937d0661 143 ///////////////////////////////
144 //Geometry data member setters
145 //
e8c0d6bb 146 void SetNZ(Int_t nz) { fEMCGeometry->SetNZ(nz) ; }
147 void SetNPhi(Int_t nphi) { fEMCGeometry->SetNPhi(nphi) ; }
148 //Trigger
149 void SetNTRUEta(Int_t ntru) { fEMCGeometry->SetNTRUEta(ntru) ; }
150 void SetNTRUPhi(Int_t ntru) { fEMCGeometry->SetNTRUPhi(ntru) ; }
151 //
152 void SetSampling(Float_t samp) { fEMCGeometry->SetSampling(samp) ; }
153 //
154 void PrintGeometry() { fEMCGeometry->PrintGeometry() ; } //*MENU*
155
156 //////////////////////////
157 // Global geometry methods
158 //
159 void GetGlobal(const Double_t *loc, Double_t *glob, int ind) const;
160 void GetGlobal(const TVector3 &vloc, TVector3 &vglob, int ind) const;
161 void GetGlobal(Int_t absId, Double_t glob[3]) const;
162 void GetGlobal(Int_t absId, TVector3 &vglob) const;
163
164 ////////////////////////////////////////
165 // May 31, 2006; ALICE numbering scheme:
166 // see ALICE-INT-2003-038: ALICE Coordinate System and Software Numbering Convention
167 // All indexes are stared from zero now.
168 //
169 // abs id <-> indexes; Shish-kebab case, only TRD1 now.
170 // EMCAL -> Super Module -> module -> tower(or cell) - logic tree of EMCAL
171 //
172 //** Usual name of variable - Dec 18,2006 **
173 // nSupMod - index of super module (SM)
174 // nModule - index of module in SM
175 // nIphi - phi index of tower(cell) in module
176 // nIeta - eta index of tower(cell) in module
177 //
178 // Inside SM
179 // iphim - phi index of module in SM
180 // ietam - eta index of module in SM
181 //
182 // iphi - phi index of tower(cell) in SM
183 // ieta - eta index of tower(cell) in SM
184 //
185 // for a given tower index absId returns eta and phi of gravity center of tower.
186 void EtaPhiFromIndex(Int_t absId, Double_t &eta, Double_t &phi) const;
187 void EtaPhiFromIndex(Int_t absId, Float_t &eta, Float_t &phi) const;
937d0661 188
e8c0d6bb 189 Bool_t GetAbsCellIdFromEtaPhi(Double_t eta,Double_t phi, Int_t &absId) const;
190 Bool_t SuperModuleNumberFromEtaPhi(Double_t eta, Double_t phi, Int_t &nSupMod) const;
191 Int_t GetAbsCellId(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta) const;
192 Bool_t CheckAbsCellId(Int_t absId) const;
193 Bool_t GetCellIndex(Int_t absId, Int_t &nSupMod, Int_t &nModule, Int_t &nIphi,
194 Int_t &nIeta) const;
195 // Local coordinate of Super Module
196 void GetModulePhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, Int_t &iphim,
197 Int_t &ietam) const;
198 void GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta,
199 Int_t &iphi, Int_t &ieta) const ;
200 Int_t GetSuperModuleNumber(Int_t absId) const;
201 Int_t GetNumberOfModuleInPhiDirection(Int_t nSupMod) const
202 {
203 if(fKey110DEG == 1 && nSupMod>=10) return fNPhi/2;
204 else return fNPhi;
205 }
206 // From cell indexes to abs cell id
207 void GetModuleIndexesFromCellIndexesInSModule(Int_t nSupMod, Int_t iphi, Int_t ieta,
208 Int_t &iphim, Int_t &ietam, Int_t &nModule) const;
209 Int_t GetAbsCellIdFromCellIndexes(Int_t nSupMod, Int_t iphi, Int_t ieta) const;
3d841a9f 210
e8c0d6bb 211 // Methods for AliEMCALRecPoint - Feb 19, 2006
212 Bool_t RelPosCellInSModule(Int_t absId,
213 Double_t &xr, Double_t &yr, Double_t &zr) const;
214 Bool_t RelPosCellInSModule(Int_t absId, Double_t distEff,
215 Double_t &xr, Double_t &yr, Double_t &zr) const;
216 Bool_t RelPosCellInSModule(Int_t absId, Double_t loc[3]) const;
217 Bool_t RelPosCellInSModule(Int_t absId, TVector3 &vloc) const;
f0377b23 218
e8c0d6bb 219 // Local Coordinates of SM
220 TArrayD GetCentersOfCellsEtaDir() const { return fCentersOfCellsEtaDir ; } // size fNEta*fNETAdiv (for TRD1 only) (eta or z in SM, in cm)
221 TArrayD GetCentersOfCellsXDir() const { return fCentersOfCellsXDir ; } // size fNEta*fNETAdiv (for TRD1 only) ( x in SM, in cm)
222 TArrayD GetCentersOfCellsPhiDir() const { return fCentersOfCellsPhiDir ; } // size fNPhi*fNPHIdiv (for TRD1 only) (phi or y in SM, in cm)
223 //
224 TArrayD GetEtaCentersOfCells() const { return fEtaCentersOfCells ; } // [fNEta*fNETAdiv*fNPhi*fNPHIdiv], positive direction (eta>0); eta depend from phi position;
225 TArrayD GetPhiCentersOfCells() const { return fPhiCentersOfCells ; } // [fNPhi*fNPHIdiv] from center of SM (-10. < phi < +10.)
d434833b 226
e8c0d6bb 227
228 // For gamma(Jet) trigger simulations *FIXME OLD TO BE REMOVED with AliEMCALTrigger*
229 Int_t GetNTRU() const { return fEMCGeometry->GetNTRU() ; }
230 Int_t GetNTRUEta() const { return fEMCGeometry->GetNTRUEta() ; }
231 Int_t GetNTRUPhi() const { return fEMCGeometry->GetNTRUPhi() ; }
232 Int_t GetNEtaSubOfTRU() const { return fEMCGeometry->GetNEtaSubOfTRU() ; }
233 Int_t GetNModulesInTRU() const { return fEMCGeometry->GetNModulesInTRU() ; }
234 Int_t GetNModulesInTRUEta() const { return fEMCGeometry->GetNModulesInTRUEta() ; }
235 Int_t GetNModulesInTRUPhi() const { return fEMCGeometry->GetNModulesInTRUPhi() ; }
236 // *MEFIX OLD TO BE REMOVED*
237
238 //
239 // Tranforms Eta-Phi Module index in TRU into Eta-Phi index in Super Module
240 void GetModulePhiEtaIndexInSModuleFromTRUIndex(Int_t itru, Int_t iphitru, Int_t ietatru,
241 Int_t &ietaSM, Int_t &iphiSM) const;
242 Int_t GetAbsTRUNumberFromNumberInSm(const Int_t row, const Int_t col, const Int_t sm) const ;
937d0661 243
e8c0d6bb 244
245 void BuildFastOR2DMap();
246 Bool_t GetAbsFastORIndexFromTRU(const Int_t iTRU, const Int_t iADC, Int_t& id) const;
247 Bool_t GetAbsFastORIndexFromPositionInTRU(const Int_t iTRU, const Int_t iEta, const Int_t iPhi, Int_t& id) const;
248 Bool_t GetAbsFastORIndexFromPositionInSM( const Int_t iSM, const Int_t iEta, const Int_t iPhi, Int_t& id) const;
249 Bool_t GetAbsFastORIndexFromPositionInEMCAL( const Int_t iEta, const Int_t iPhi, Int_t& id) const;
250 Bool_t GetTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iADC) const;
251 Bool_t GetPositionInTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iEta, Int_t& iPhi) const;
252 Bool_t GetPositionInSMFromAbsFastORIndex(const Int_t id, Int_t& iSM, Int_t& iEta, Int_t& iPhi) const;
253 Bool_t GetPositionInEMCALFromAbsFastORIndex(const Int_t id, Int_t& iEta, Int_t& iPhi) const;
254 Bool_t GetFastORIndexFromCellIndex(const Int_t id, Int_t& idx) const;
255 Bool_t GetCellIndexFromFastORIndex(const Int_t id, Int_t idx[4]) const;
256 Bool_t GetTRUIndexFromSTUIndex(const Int_t id, Int_t& idx) const;
257 Int_t GetTRUIndexFromSTUIndex(const Int_t id) const;
258 Bool_t GetFastORIndexFromL0Index(const Int_t iTRU, const Int_t id, Int_t idx[], const Int_t size) const;
259
260 ///////////////////
261 // useful utilities
262 //
263 Float_t AngleFromEta(Float_t eta) const { // returns theta in radians for a given pseudorapidity
264 return 2.0*TMath::ATan(TMath::Exp(-eta));
265 }
266 Float_t ZFromEtaR(Float_t r,Float_t eta) const { // returns z in for a given
267 // pseudorapidity and r=sqrt(x*x+y*y).
268 return r/TMath::Tan(AngleFromEta(eta));
269 }
d434833b 270
e8c0d6bb 271 //Method to set shift-rotational matrixes from ESDHeader
272 void SetMisalMatrix(const TGeoHMatrix * m, Int_t smod) {
273 fUseExternalMatrices = kTRUE;
274 if (smod >= 0 && smod < fEMCGeometry->GetNumberOfSuperModules()){
275 if(!fkSModuleMatrix[smod]) fkSModuleMatrix[smod] = new TGeoHMatrix(*m) ; //Set only if not set yet
276 }
277 else AliFatal(Form("Wrong supermodule index -> %d",smod));
278 }
279
280 //Alternate geometry that allows to calculate tower position for different particles and different alignments
281 void RecalculateTowerPosition(Float_t drow, Float_t dcol, const Int_t sm, const Float_t depth,
282 const Float_t misaligTransShifts[15], const Float_t misaligRotShifts[15],Float_t global[3]) const;
a97849a9 283
e8c0d6bb 284 //Returns shift-rotational matrixes for different volumes
285 const TGeoHMatrix * GetMatrixForSuperModule(Int_t smod)const ;
286
287protected:
288
ee8f18d6 289 void Init(void); // initializes the parameters of EMCAL
290
e8c0d6bb 291 AliEMCALEMCGeometry * fEMCGeometry; // Geometry object for Electromagnetic calorimeter
292
293 TString fGeoName; // geometry name
294 Int_t fKey110DEG; // for calculation abs cell id; 19-oct-05
295 Int_t fNCellsInSupMod; // number cell in super module
296 Int_t fNETAdiv; // number eta divizion of module
297 Int_t fNPHIdiv; // number phi divizion of module
298 Int_t fNCellsInModule; // number cell in module
299 TArrayD fPhiBoundariesOfSM; // phi boundaries of SM in rad; size is fNumberOfSuperModules;
300 TArrayD fPhiCentersOfSM; // phi of centers of SMl size is fNumberOfSuperModules/2
301 // Local Coordinates of SM
302 TArrayD fPhiCentersOfCells; // [fNPhi*fNPHIdiv] from center of SM (-10. < phi < +10.)
303 TArrayD fCentersOfCellsEtaDir; // size fNEta*fNETAdiv (for TRD1 only) (eta or z in SM, in cm)
304 TArrayD fCentersOfCellsPhiDir; // size fNPhi*fNPHIdiv (for TRD1 only) (phi or y in SM, in cm)
305 TArrayD fEtaCentersOfCells; // [fNEta*fNETAdiv*fNPhi*fNPHIdiv], positive direction (eta>0); eta depend from phi position;
306 Int_t fNCells; // number of cells in calo
307 Int_t fNPhi; // Number of Towers in the PHI direction
308 TArrayD fCentersOfCellsXDir; // size fNEta*fNETAdiv (for TRD1 only) ( x in SM, in cm)
309 Float_t fEnvelop[3]; // the GEANT TUB for the detector
310 Float_t fArm1EtaMin; // Minimum pseudorapidity position of EMCAL in Eta
311 Float_t fArm1EtaMax; // Maximum pseudorapidity position of EMCAL in Eta
312 Float_t fArm1PhiMin; // Minimum angular position of EMCAL in Phi (degrees)
313 Float_t fArm1PhiMax; // Maximum angular position of EMCAL in Phi (degrees)
314 Float_t fEtaMaxOfTRD1; // Max eta in case of TRD1 geometry (see AliEMCALShishKebabTrd1Module)
315 TList *fShishKebabTrd1Modules; //! list of modules
316 Float_t fParSM[3]; // SM sizes as in GEANT (TRD1)
317 Float_t fPhiModuleSize; // Phi -> X
318 Float_t fEtaModuleSize; // Eta -> Y
319 Float_t fPhiTileSize; // Size of phi tile
320 Float_t fEtaTileSize; // Size of eta tile
321 Int_t fNZ; // Number of Towers in the Z direction
322 Float_t fIPDistance; // Radial Distance of the inner surface of the EMCAL
323 Float_t fLongModuleSize; // Size of long module
324 // Geometry Parameters
325 Float_t fShellThickness; // Total thickness in (x,y) direction
326 Float_t fZLength; // Total length in z direction
327 Float_t fSampling; // Sampling factor
937d0661 328
e8c0d6bb 329 Int_t fFastOR2DMap[48][64]; // FastOR 2D Map over full EMCal
330
331 TGeoHMatrix* fkSModuleMatrix[AliEMCALGeoParams::fgkEMCALModules] ; //Orientations of EMCAL super modules
332 Bool_t fUseExternalMatrices; // Use the matrices set in fkSModuleMatrix and not those in the geoManager
333
334private:
335
336 static AliEMCALGeometry *fgGeom; // Pointer to the unique instance of the singleton
337 static Bool_t fgInit; // Tells if geometry has been succesfully set up.
338 static const Char_t *fgkDefaultGeometryName; // Default name of geometry
339
340
341 ClassDef(AliEMCALGeometry,16) // EMCAL geometry class
937d0661 342
e8c0d6bb 343} ;
937d0661 344
e8c0d6bb 345#endif // AliEMCALGEOUTILS_H
2012850d 346