]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALGeometry.cxx
Coding rule violations corrected.
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGeometry.cxx
CommitLineData
e5a93224 1/**************************************************************************
2012850d 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//_________________________________________________________________________
e8c0d6bb 19// Geometry class for EMCAL : singleton
b13bbe81 20// EMCAL consists of layers of scintillator and lead
d297ef6e 21// with scintillator fiber arranged as "shish-kebab" skewers
ffa6d63b 22// Places the the Barrel Geometry of The EMCAL at Midrapidity
d87bd045 23// between 80 and 180(or 190) degrees of Phi and
ffa6d63b 24// -0.7 to 0.7 in eta
d297ef6e 25//
1d46d1f6 26// EMCAL geometry tree:
2bb3725c 27// EMCAL -> superModule -> module -> tower(cell)
1d46d1f6 28// Indexes
2bb3725c 29// absId -> nSupMod -> nModule -> (nIphi,nIeta)
1d46d1f6 30//
d297ef6e 31// Name choices:
32// EMCAL_PDC06 (geometry used for PDC06 simulations, kept for backward compatibility)
33// = equivalent to SHISH_77_TRD1_2X2_FINAL_110DEG in old notation
34// EMCAL_COMPLETE (geometry for expected complete detector)
35// = equivalent to SHISH_77_TRD1_2X2_FINAL_110DEG scTh=0.176 pbTh=0.144
36// in old notation
171d2441 37// EMCAL_FIRSTYEARV1 - geometry for December 2009 to December 2010 run period;
3d841a9f 38// fixed bug for positions of modules inside SM
39// (first module has tilt 0.75 degree);
40// the sizes updated with last information from production
41// drawing (end of October 2010).
171d2441 42//
43// EMCAL_COMPLETEV1: Same fixes as FIRSTYEAR and 10 SM instead of 10+2 half SM
3d841a9f 44//
d297ef6e 45// EMCAL_WSUC (Wayne State test stand)
46// = no definite equivalent in old notation, was only used by
47// Aleksei, but kept for testing purposes
48//
49// etc.
e8c0d6bb 50
d297ef6e 51//
e8c0d6bb 52// Usage:
53// You can create the AliEMCALGeometry object independently from anything.
54// You have to use just the correct name of geometry. If name is empty string the
55// default name of geometry will be used.
56//
57// AliEMCALGeometry* g = AliEMCALGeometry::GetInstance(name,title); // first time
58// ..
59// g = AliEMCALGeometry::GetInstance(); // after first time
d297ef6e 60//
e8c0d6bb 61// MC: If you work with MC data you have to get geometry the next way:
62// == =============================
63// AliRunLoader *rl = AliRunLoader::Instance();
64// AliEMCALGeometry *geom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
65// TGeoManager::Import("geometry.root");
d297ef6e 66//
b13bbe81 67//*-- Author: Sahal Yacoob (LBL / UCT)
68// and : Yves Schutz (SUBATECH)
69// and : Jennifer Klay (LBL)
3d841a9f 70// and : Alexei Pavlinov (WSU)
1d46d1f6 71//
e8c0d6bb 72// Implementation for analysis usage, before AliEMCALGeometry now (06/2011) merged again
73// in AliEMCALGeometry
74//
75// -- Author: Magali Estienne (magali.estienne@subatech.in2p3.fr)
76//
89557f6d 77//
78// Usage:
79// You can create the AliEMCALGeometry object independently from anything.
80// You have to use just the correct name of geometry. If name is empty string the
81// default name of geometry will be used.
82//
e8c0d6bb 83// AliEMCALGeometry* geom = new AliEMCALGeometry("EMCAL_COMPLETEV1","EMCAL");
84// TGeoManager::Import("geometry.root");
89557f6d 85//
76855a3c 86// MC: If you work with MC data you have to get geometry the next way:
87// == =============================
e8c0d6bb 88// !!!!!!!!! This part has to be modified
89// AliRunLoader *rl = AliRunLoader::GetRunLoader();
90// AliEMCALEMCGeometry *geom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
d297ef6e 91// TGeoManager::Import("geometry.root");
dc7da436 92
937d0661 93
e8c0d6bb 94// --- ROOT system ---
95
96#include <TParticle.h>
97#include <TGeoManager.h>
98#include <TGeoMatrix.h>
99#include <TGeoBBox.h>
100#include <TList.h>
101#include <TBrowser.h>
102
103// --- Standard library ---
104//#include <Riostream.h>
105
106// --- AliRoot header files ---
107#include "AliEMCALGeometry.h"
108#include "AliEMCALShishKebabTrd1Module.h"
109
110ClassImp(AliEMCALGeometry)
111
112// these initialisations are needed for a singleton
113AliEMCALGeometry *AliEMCALGeometry::fgGeom = 0;
114const Char_t* AliEMCALGeometry::fgkDefaultGeometryName = "EMCAL_COMPLETEV1";
115
116//____________________________________________________________________________
117AliEMCALGeometry::AliEMCALGeometry():
118 fEMCGeometry(0x0),fGeoName(0),
119 fKey110DEG(0),fNCellsInSupMod(0),fNETAdiv(0),fNPHIdiv(0),
120 fNCellsInModule(0),fPhiBoundariesOfSM(0x0),fPhiCentersOfSM(0x0),
121 fPhiCentersOfCells(0x0),fCentersOfCellsEtaDir(0x0),
122 fCentersOfCellsPhiDir(0x0),fEtaCentersOfCells(0x0),
123 fNCells(0),fNPhi(0),fCentersOfCellsXDir(0x0),fArm1EtaMin(0),
124 fArm1EtaMax(0),fArm1PhiMin(0),fArm1PhiMax(0),fEtaMaxOfTRD1(0),
125 fShishKebabTrd1Modules(0),fPhiModuleSize(0.),
126 fEtaModuleSize(0.),fPhiTileSize(0.),fEtaTileSize(0.),fNZ(0),
127 fIPDistance(0.),fLongModuleSize(0.),fShellThickness(0.),
128 fZLength(0.),fSampling(0.),fUseExternalMatrices(kFALSE)
9cff4509 129{
e8c0d6bb 130 // default ctor
131 // must be kept public for root persistency purposes, but should never be called by the outside world
132 fEnvelop[0] = 0.;
133 fEnvelop[1] = 0.;
134 fEnvelop[2] = 0.;
135 fParSM[0] = 0.;
136 fParSM[1] = 0.;
137 fParSM[2] = 0.;
d7cff4de 138 for (Int_t i=0;i<AliEMCALGeoParams::fgkEMCALModules;i++)
139 fkSModuleMatrix[i]=0 ;
1d46d1f6 140
e8c0d6bb 141 for (Int_t i = 0; i < 48; i++)
142 for (Int_t j = 0; j < 64; j++) fFastOR2DMap[i][j] = -1;
143}
144
145//____________________________________________________________________________
146AliEMCALGeometry::AliEMCALGeometry(const AliEMCALGeometry & geo)
147 : TNamed(geo),
148 fEMCGeometry(geo.fEMCGeometry),fGeoName(geo.fGeoName),
149 fKey110DEG(geo.fKey110DEG),fNCellsInSupMod(geo.fNCellsInSupMod),fNETAdiv(geo.fNETAdiv),fNPHIdiv(geo.fNPHIdiv),
150 fNCellsInModule(geo.fNCellsInModule),fPhiBoundariesOfSM(geo.fPhiBoundariesOfSM),fPhiCentersOfSM(geo.fPhiCentersOfSM),
151 fPhiCentersOfCells(geo.fPhiCentersOfCells),fCentersOfCellsEtaDir(geo.fCentersOfCellsEtaDir),
152 fCentersOfCellsPhiDir(geo.fCentersOfCellsPhiDir),fEtaCentersOfCells(geo.fEtaCentersOfCells),
153 fNCells(geo.fNCells),fNPhi(geo.fNPhi),fCentersOfCellsXDir(geo.fCentersOfCellsXDir),fArm1EtaMin(geo.fArm1EtaMin),
154 fArm1EtaMax(geo.fArm1EtaMax),fArm1PhiMin(geo.fArm1PhiMin),fArm1PhiMax(geo.fArm1PhiMax),fEtaMaxOfTRD1(geo.fEtaMaxOfTRD1),
155 fShishKebabTrd1Modules(geo.fShishKebabTrd1Modules),fPhiModuleSize(geo.fPhiModuleSize),
156 fEtaModuleSize(geo.fEtaModuleSize),fPhiTileSize(geo.fPhiTileSize),fEtaTileSize(geo.fEtaTileSize),fNZ(geo.fNZ),
157 fIPDistance(geo.fIPDistance),fLongModuleSize(geo.fLongModuleSize),fShellThickness(geo.fShellThickness),
158 fZLength(geo.fZLength),fSampling(geo.fSampling),fUseExternalMatrices(geo.fUseExternalMatrices)
9cff4509 159{
bccc4a4f 160 // Copy constarctor
e8c0d6bb 161 fEnvelop[0] = geo.fEnvelop[0];
162 fEnvelop[1] = geo.fEnvelop[1];
163 fEnvelop[2] = geo.fEnvelop[2];
164 fParSM[0] = geo.fParSM[0];
165 fParSM[1] = geo.fParSM[1];
166 fParSM[2] = geo.fParSM[2];
d7cff4de 167 for (Int_t i=0;i<AliEMCALGeoParams::fgkEMCALModules;i++)
168 fkSModuleMatrix[i]=0 ;
e8c0d6bb 169
170 for (Int_t i = 0; i < 48; i++)
171 for (Int_t j = 0; j < 64; j++) fFastOR2DMap[i][j] = geo.fFastOR2DMap[i][j];
0a4cb131 172}
173
e8c0d6bb 174//____________________________________________________________________________
126215a5 175AliEMCALGeometry::AliEMCALGeometry(const Text_t* name, const Text_t* title,
176 const Text_t* mcname, const Text_t* mctitle)
e8c0d6bb 177 : TNamed(name, title),
178 fEMCGeometry(0x0),fGeoName(0),
179 fKey110DEG(0),fNCellsInSupMod(0),fNETAdiv(0),fNPHIdiv(0),
180 fNCellsInModule(0),fPhiBoundariesOfSM(0x0),fPhiCentersOfSM(0x0),
181 fPhiCentersOfCells(0x0),fCentersOfCellsEtaDir(0x0),
182 fCentersOfCellsPhiDir(0x0),fEtaCentersOfCells(0x0),
183 fNCells(0),fNPhi(0),fCentersOfCellsXDir(0x0),fArm1EtaMin(0),
184 fArm1EtaMax(0),fArm1PhiMin(0),fArm1PhiMax(0),fEtaMaxOfTRD1(0),
185 fShishKebabTrd1Modules(0),fPhiModuleSize(0.),
186 fEtaModuleSize(0.),fPhiTileSize(0.),fEtaTileSize(0.),fNZ(0),
187 fIPDistance(0.),fLongModuleSize(0.),fShellThickness(0.),
188 fZLength(0.),fSampling(0.), fUseExternalMatrices(kFALSE)
189{
190
191 // ctor only for normal usage
126215a5 192
193 fEMCGeometry = new AliEMCALEMCGeometry(name,title,mcname,mctitle);
e8c0d6bb 194
195 fGeoName = fEMCGeometry->GetGeoName();
196 fKey110DEG = fEMCGeometry->GetKey110DEG();
197 fNCellsInSupMod = fEMCGeometry->GetNCellsInSupMod();
198 fNETAdiv = fEMCGeometry->GetNETAdiv();
199 fNPHIdiv = fEMCGeometry->GetNPHIdiv();
200 fNCellsInModule = fNPHIdiv*fNETAdiv;
201 static int i=0;
202 Int_t nSMod = fEMCGeometry->GetNumberOfSuperModules();
203 fPhiBoundariesOfSM.Set(nSMod);
204 fPhiCentersOfSM.Set(nSMod/2);
205 for(Int_t sm=0; sm<nSMod; sm++) {
206 i = sm/2;
207 fEMCGeometry->GetPhiBoundariesOfSM(sm,fPhiBoundariesOfSM[2*i],fPhiBoundariesOfSM[2*i+1]);
208 }
209
210 Double_t phiMin = 0.;
211 Double_t phiMax = 0.;
212 for(Int_t sm=0; sm<nSMod; sm++) {
213 fEMCGeometry->GetPhiBoundariesOfSM(sm,phiMin,phiMax);
214 i=sm/2;
215 fPhiCentersOfSM[i] = fEMCGeometry->GetPhiCenterOfSM(sm);
216 }
217 fNCells = fEMCGeometry->GetNCells();
218 fNPhi = fEMCGeometry->GetNPhi();
219 fEnvelop[0] = fEMCGeometry->GetEnvelop(0);
220 fEnvelop[1] = fEMCGeometry->GetEnvelop(1);
221 fEnvelop[2] = fEMCGeometry->GetEnvelop(2);
222 fParSM[0] = fEMCGeometry->GetSuperModulesPar(0);
223 fParSM[1] = fEMCGeometry->GetSuperModulesPar(1);
224 fParSM[2] = fEMCGeometry->GetSuperModulesPar(2);
225 fArm1EtaMin = fEMCGeometry->GetArm1EtaMin();
226 fArm1EtaMax = fEMCGeometry->GetArm1EtaMax();
227 fArm1PhiMin = fEMCGeometry->GetArm1PhiMin();
228 fArm1PhiMax = fEMCGeometry->GetArm1PhiMax();
229 fShellThickness = fEMCGeometry->GetShellThickness();
230 fZLength = fEMCGeometry->GetZLength();
231 fSampling = fEMCGeometry->GetSampling();
232 fEtaModuleSize = fEMCGeometry->GetEtaModuleSize();
233 fPhiModuleSize = fEMCGeometry->GetPhiModuleSize();
234 fEtaTileSize = fEMCGeometry->GetEtaTileSize();
235 fPhiTileSize = fEMCGeometry->GetPhiTileSize();
236 fNZ = fEMCGeometry->GetNZ();
237 fIPDistance = fEMCGeometry->GetIPDistance();
238 fLongModuleSize = fEMCGeometry->GetLongModuleSize();
239
240 CreateListOfTrd1Modules();
241
d7cff4de 242 for(Int_t smod=0; smod < AliEMCALGeoParams::fgkEMCALModules; smod++)
243 fkSModuleMatrix[smod]=0 ;
e8c0d6bb 244
245 if (AliDebugLevel()>=2) {
246 fEMCGeometry->Print();
247 PrintGeometryGeoUtils();
248 }
249
250 for (Int_t ix = 0; ix < 48; ix++)
251 for (Int_t jx = 0; jx < 64; jx++) fFastOR2DMap[ix][jx] = -1;
252
253 BuildFastOR2DMap();
2012850d 254}
d297ef6e 255
e8c0d6bb 256//____________________________________________________________________________
257AliEMCALGeometry & AliEMCALGeometry::operator = (const AliEMCALGeometry & /*rvalue*/) {
258 //assing operator
259 Fatal("assignment operator", "not implemented") ;
260 return *this ;
261}
262
263//____________________________________________________________________________
264AliEMCALGeometry::~AliEMCALGeometry(void)
265{
266 // dtor
d7cff4de 267 if (this==fgGeom) {
268 AliError("Do not call delete on me");
269 return;
270 }
e8c0d6bb 271 if (fEMCGeometry){
272 for(Int_t smod = 0 ; smod < fEMCGeometry->GetNumberOfSuperModules(); smod++){
273 if(fkSModuleMatrix[smod])
274 delete fkSModuleMatrix[smod] ;
275 fkSModuleMatrix[smod]=0 ;
276 }
bccc4a4f 277 delete fEMCGeometry; // fEMCGeometry = 0 ;
e8c0d6bb 278 }
279}
f0377b23 280
b13bbe81 281//______________________________________________________________________
282AliEMCALGeometry * AliEMCALGeometry::GetInstance(){
05a92d59 283 // Returns the pointer of the unique instance
284
e52475ed 285 AliEMCALGeometry * rv = static_cast<AliEMCALGeometry *>( fgGeom );
286 return rv;
2012850d 287}
173558f2 288
b13bbe81 289//______________________________________________________________________
126215a5 290AliEMCALGeometry* AliEMCALGeometry::GetInstance(const Text_t* name, const Text_t* title,
291 const Text_t* mcname, const Text_t* mctitle ){
e8c0d6bb 292 // Returns the pointer of the unique instance
126215a5 293
e8c0d6bb 294 AliEMCALGeometry * rv = 0;
295 if ( fgGeom == 0 ) {
296 if ( strcmp(name,"") == 0 ) { // get default geometry
126215a5 297 fgGeom = new AliEMCALGeometry(fgkDefaultGeometryName, title,mcname,mctitle);
e8c0d6bb 298 } else {
126215a5 299 fgGeom = new AliEMCALGeometry(name, title,mcname,mctitle);
e8c0d6bb 300 } // end if strcmp(name,"")
301 if ( AliEMCALEMCGeometry::fgInit ) rv = (AliEMCALGeometry * ) fgGeom;
302 else {
303 rv = 0;
304 delete fgGeom;
305 fgGeom = 0;
306 } // end if fgInit
307 }else{
308 if ( strcmp(fgGeom->GetName(), name) != 0) {
309 printf("\ncurrent geometry is %s : ", fgGeom->GetName());
310 printf(" you cannot call %s ",name);
b13bbe81 311 }else{
e8c0d6bb 312 rv = (AliEMCALGeometry *) fgGeom;
313 } // end
314 } // end if fgGeom
315 return rv;
316}
317
318//________________________________________________________________________________________________
319void AliEMCALGeometry::Browse(TBrowser* b)
320{
321 //Browse the modules
322 if(fShishKebabTrd1Modules) b->Add(fShishKebabTrd1Modules);
323}
324
325//________________________________________________________________________________________________
326Bool_t AliEMCALGeometry::IsFolder() const
327{
328 //Check if fShishKebabTrd1Modules is in folder
329 if(fShishKebabTrd1Modules) return kTRUE;
330 else return kFALSE;
331}
332
333//________________________________________________________________________________________________
334void AliEMCALGeometry::GetGlobal(const Double_t *loc, Double_t *glob, int ind) const
335{
336 // Figure out the global numbering
337 // of a given supermodule from the
338 // local numbering and the transformation
339 // matrix stored by the geometry manager (allows for misaligned
340 // geometry)
341
342 const TGeoHMatrix* m = GetMatrixForSuperModule(ind);
343 if(m) {
344 m->LocalToMaster(loc, glob);
345 } else {
346 AliFatal("Geo matrixes are not loaded \n") ;
347 }
348}
349
350//________________________________________________________________________________________________
351void AliEMCALGeometry::GetGlobal(const TVector3 &vloc, TVector3 &vglob, int ind) const
352{
353 //Figure out the global numbering
354 //of a given supermodule from the
355 //local numbering given a 3-vector location
356
357 static Double_t tglob[3], tloc[3];
358 vloc.GetXYZ(tloc);
359 GetGlobal(tloc, tglob, ind);
360 vglob.SetXYZ(tglob[0], tglob[1], tglob[2]);
361}
362
363//________________________________________________________________________________________________
364void AliEMCALGeometry::GetGlobal(Int_t absId , double glob[3]) const
365{
366 // Alice numbering scheme - Jun 03, 2006
367 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
368 static double loc[3];
369
370 glob[0]=glob[1]=glob[2]=0.0; // bad case
371 if(RelPosCellInSModule(absId, loc)) {
372 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
373
374 const TGeoHMatrix* m = GetMatrixForSuperModule(nSupMod);
375 if(m) {
376 m->LocalToMaster(loc, glob);
377 } else {
378 AliFatal("Geo matrixes are not loaded \n") ;
379 }
380 }
381}
382
383//___________________________________________________________________
384void AliEMCALGeometry::GetGlobal(Int_t absId , TVector3 &vglob) const
385{
386 // Alice numbering scheme - Jun 03, 2006
387 static Double_t glob[3];
388
389 GetGlobal(absId, glob);
390 vglob.SetXYZ(glob[0], glob[1], glob[2]);
391
392}
393
394
395//______________________________________________________________________
396void AliEMCALGeometry::PrintCellIndexes(Int_t absId, int pri, const char *tit) const
397{
398 // Service methods
399 Int_t nSupMod, nModule, nIphi, nIeta;
400 Int_t iphi, ieta;
401 TVector3 vg;
402
403 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
404 printf(" %s | absId : %i -> nSupMod %i nModule %i nIphi %i nIeta %i \n", tit, absId, nSupMod, nModule, nIphi, nIeta);
405 if(pri>0) {
406 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
407 printf(" local SM index : iphi %i : ieta %i \n", iphi,ieta);
408 GetGlobal(absId, vg);
409 printf(" vglob : mag %7.2f : perp %7.2f : z %7.2f : eta %6.4f : phi %6.4f(%6.2f) \n",
410 vg.Mag(), vg.Perp(), vg.Z(), vg.Eta(), vg.Phi(), vg.Phi()*TMath::RadToDeg());
411 }
412}
413
414void AliEMCALGeometry::PrintLocalTrd1(Int_t pri) const
415{
416 // For comparing with numbers from drawing
417 for(Int_t i=0; i<GetShishKebabTrd1Modules()->GetSize(); i++){
418 printf(" %s | ", GetShishKebabModule(i)->GetName());
419 if(i==0 && pri<1) GetShishKebabModule(i)->PrintShish(1);
420 else GetShishKebabModule(i)->PrintShish(pri);
421 }
422}
423
424//________________________________________________________________________________________________
425void AliEMCALGeometry::EtaPhiFromIndex(Int_t absId,Double_t &eta,Double_t &phi) const
426{
427 // Nov 16, 2006- float to double
428 // version for TRD1 only
429 static TVector3 vglob;
430 GetGlobal(absId, vglob);
431 eta = vglob.Eta();
432 phi = vglob.Phi();
433}
434
435//________________________________________________________________________________________________
436void AliEMCALGeometry::EtaPhiFromIndex(Int_t absId,Float_t &eta,Float_t &phi) const
437{
438 // Nov 16,2006 - should be discard in future
439 static TVector3 vglob;
440 GetGlobal(absId, vglob);
441 eta = float(vglob.Eta());
442 phi = float(vglob.Phi());
443}
444
445//
446// == Shish-kebab cases ==
447//
448//________________________________________________________________________________________________
449Int_t AliEMCALGeometry::GetAbsCellId(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta) const
450{
451 // 27-aug-04;
452 // corr. 21-sep-04;
453 // 13-oct-05; 110 degree case
454 // May 31, 2006; ALICE numbering scheme:
455 // 0 <= nSupMod < fNumberOfSuperModules
456 // 0 <= nModule < fNPHI * fNZ ( fNPHI * fNZ/2 for fKey110DEG=1)
457 // 0 <= nIphi < fNPHIdiv
458 // 0 <= nIeta < fNETAdiv
459 // 0 <= absid < fNCells
460 static Int_t id=0; // have to change from 0 to fNCells-1
461 if(fKey110DEG == 1 && nSupMod >= 10) { // 110 degree case; last two supermodules
462 id = fNCellsInSupMod*10 + (fNCellsInSupMod/2)*(nSupMod-10);
463 } else {
464 id = fNCellsInSupMod*nSupMod;
465 }
466 id += fNCellsInModule *nModule;
467 id += fNPHIdiv *nIphi;
468 id += nIeta;
469 if(id<0 || id >= fNCells) {
470// printf(" wrong numerations !!\n");
471// printf(" id %6i(will be force to -1)\n", id);
472// printf(" fNCells %6i\n", fNCells);
473// printf(" nSupMod %6i\n", nSupMod);
474// printf(" nModule %6i\n", nModule);
475// printf(" nIphi %6i\n", nIphi);
476// printf(" nIeta %6i\n", nIeta);
477 id = -TMath::Abs(id); // if negative something wrong
478 }
479 return id;
480}
481
482//________________________________________________________________________________________________
483void AliEMCALGeometry::GetModuleIndexesFromCellIndexesInSModule(Int_t nSupMod, Int_t iphi, Int_t ieta,
484 Int_t &iphim, Int_t &ietam, Int_t &nModule) const
485{
486 // Transition from cell indexes (ieta,iphi) to module indexes (ietam,iphim, nModule)
487 static Int_t nphi=-1;
488 nphi = GetNumberOfModuleInPhiDirection(nSupMod);
489
490 ietam = ieta/fNETAdiv;
491 iphim = iphi/fNPHIdiv;
492 nModule = ietam * nphi + iphim;
493}
494
495//________________________________________________________________________________________________
496Int_t AliEMCALGeometry::GetAbsCellIdFromCellIndexes(Int_t nSupMod, Int_t iphi, Int_t ieta) const
497{
498 // Transition from super module number(nSupMod) and cell indexes (ieta,iphi) to absId
499 static Int_t ietam=-1, iphim=-1, nModule=-1;
500 static Int_t nIeta=-1, nIphi=-1; // cell indexes in module
501
502 GetModuleIndexesFromCellIndexesInSModule(nSupMod, iphi, ieta, ietam, iphim, nModule);
503
504 nIeta = ieta%fNETAdiv;
505 nIeta = fNETAdiv - 1 - nIeta;
506 nIphi = iphi%fNPHIdiv;
507
508 return GetAbsCellId(nSupMod, nModule, nIphi, nIeta);
509}
510
511//________________________________________________________________________________________________
512Bool_t AliEMCALGeometry::SuperModuleNumberFromEtaPhi(Double_t eta, Double_t phi, Int_t &nSupMod) const
513{
514 // Return false if phi belongs a phi cracks between SM
515
516 static Int_t i=0;
517
518 if(TMath::Abs(eta) > fEtaMaxOfTRD1) return kFALSE;
519
520 phi = TVector2::Phi_0_2pi(phi); // move phi to (0,2pi) boundaries
521 for(i=0; i<6; i++) {
522
523 //Check if it is not the complete geometry
524 if (i >= fEMCGeometry->GetNumberOfSuperModules()/2) return kFALSE;
525
526 if(phi>=fPhiBoundariesOfSM[2*i] && phi<=fPhiBoundariesOfSM[2*i+1]) {
527 nSupMod = 2*i;
528 if(eta < 0.0) nSupMod++;
529 AliDebug(1,Form("eta %f phi %f(%5.2f) : nSupMod %i : #bound %i", eta,phi,phi*TMath::RadToDeg(), nSupMod,i));
530 return kTRUE;
531 }
532 }
533 return kFALSE;
534}
535
536
537//________________________________________________________________________________________________
538Bool_t AliEMCALGeometry::GetAbsCellIdFromEtaPhi(Double_t eta, Double_t phi, Int_t &absId) const
539{
540 // Nov 17,2006
541 // stay here - phi problem as usual
542 static Int_t nSupMod=-1, i=0, ieta=-1, iphi=-1, etaShift=0, nphi=-1;
543 static Double_t absEta=0.0, d=0.0, dmin=0.0, phiLoc=0;
544 absId = nSupMod = - 1;
545 if(SuperModuleNumberFromEtaPhi(eta, phi, nSupMod)) {
546 // phi index first
547 phi = TVector2::Phi_0_2pi(phi);
548 phiLoc = phi - fPhiCentersOfSM[nSupMod/2];
549 nphi = fPhiCentersOfCells.GetSize();
550 if(nSupMod>=10) {
551 phiLoc = phi - 190.*TMath::DegToRad();
552 nphi /= 2;
553 }
554
555 dmin = TMath::Abs(fPhiCentersOfCells[0]-phiLoc);
556 iphi = 0;
557 for(i=1; i<nphi; i++) {
558 d = TMath::Abs(fPhiCentersOfCells[i] - phiLoc);
559 if(d < dmin) {
560 dmin = d;
561 iphi = i;
562 }
563 // printf(" i %i : d %f : dmin %f : fPhiCentersOfCells[i] %f \n", i, d, dmin, fPhiCentersOfCells[i]);
564 }
565 // odd SM are turned with respect of even SM - reverse indexes
566 AliDebug(2,Form(" iphi %i : dmin %f (phi %f, phiLoc %f ) ", iphi, dmin, phi, phiLoc));
567 // eta index
568 absEta = TMath::Abs(eta);
569 etaShift = iphi*fCentersOfCellsEtaDir.GetSize();
570 dmin = TMath::Abs(fEtaCentersOfCells[etaShift]-absEta);
571 ieta = 0;
572 for(i=1; i<fCentersOfCellsEtaDir.GetSize(); i++) {
573 d = TMath::Abs(fEtaCentersOfCells[i+etaShift] - absEta);
574 if(d < dmin) {
575 dmin = d;
576 ieta = i;
577 }
578 }
579 AliDebug(2,Form(" ieta %i : dmin %f (eta=%f) : nSupMod %i ", ieta, dmin, eta, nSupMod));
580
581 if(eta<0) iphi = (nphi-1) - iphi;
582
583 //patch for mapping following alice convention
584 if(nSupMod%2 == 0)
585 ieta = (fCentersOfCellsEtaDir.GetSize()-1)-ieta;// 47-ieta, revert the ordering on A side in order to keep convention.
586 else {
587 if(nSupMod<10)
588 iphi = (fCentersOfCellsPhiDir.GetSize()-1) -iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
589 else
590 iphi = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
591 }
592
593 absId = GetAbsCellIdFromCellIndexes(nSupMod, iphi, ieta);
594
595 return kTRUE;
596 }
597 return kFALSE;
598}
599
600//________________________________________________________________________________________________
601Bool_t AliEMCALGeometry::CheckAbsCellId(Int_t absId) const
602{
603 // May 31, 2006; only trd1 now
604 if(absId<0 || absId >= fNCells) return kFALSE;
605 else return kTRUE;
606}
607
608//________________________________________________________________________________________________
609Bool_t AliEMCALGeometry::GetCellIndex(Int_t absId,Int_t &nSupMod,Int_t &nModule,Int_t &nIphi,Int_t &nIeta) const
610{
611 // 21-sep-04; 19-oct-05;
612 // May 31, 2006; ALICE numbering scheme:
613 //
614 // In:
615 // absId - cell is as in Geant, 0<= absId < fNCells;
616 // Out:
617 // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
618 // nModule - module number in SM, 0<= nModule < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
619 // nIphi - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv;
620 // nIeta - cell number in eta driection inside module; 0<= nIeta < fNETAdiv;
621 //
622 static Int_t tmp=0, sm10=0;
623 if(!CheckAbsCellId(absId)) return kFALSE;
624
625 sm10 = fNCellsInSupMod*10;
626 if(fKey110DEG == 1 && absId >= sm10) { // 110 degree case; last two supermodules
627 nSupMod = (absId-sm10) / (fNCellsInSupMod/2) + 10;
628 tmp = (absId-sm10) % (fNCellsInSupMod/2);
629 } else {
630 nSupMod = absId / fNCellsInSupMod;
631 tmp = absId % fNCellsInSupMod;
632 }
633
634 nModule = tmp / fNCellsInModule;
635 tmp = tmp % fNCellsInModule;
636 nIphi = tmp / fNPHIdiv;
637 nIeta = tmp % fNPHIdiv;
638
639 return kTRUE;
640}
641
642//________________________________________________________________________________________________
643Int_t AliEMCALGeometry::GetSuperModuleNumber(Int_t absId) const
644{
645 // Return the number of the supermodule given the absolute
646 // ALICE numbering id
647
648 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
649 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
650 return nSupMod;
651}
652
653//________________________________________________________________________________________________
654void AliEMCALGeometry::GetModulePhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, int &iphim, int &ietam) const
655{
656 // added nSupMod; - 19-oct-05 !
657 // Alice numbering scheme - Jun 01,2006
658 // ietam, iphi - indexes of module in two dimensional grid of SM
659 // ietam - have to change from 0 to fNZ-1
660 // iphim - have to change from 0 to nphi-1 (fNPhi-1 or fNPhi/2-1)
661 static Int_t nphi=-1;
662
663 if(fKey110DEG == 1 && nSupMod>=10) nphi = fNPhi/2;
664 else nphi = fNPhi;
665
666 ietam = nModule/nphi;
667 iphim = nModule%nphi;
668}
669
670//________________________________________________________________________________________________
671void AliEMCALGeometry::GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta,
672int &iphi, int &ieta) const
673{
674 //
675 // Added nSupMod; Nov 25, 05
676 // Alice numbering scheme - Jun 01,2006
677 // IN:
678 // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
679 // nModule - module number in SM, 0<= nModule < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
680 // nIphi - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv;
681 // nIeta - cell number in eta driection inside module; 0<= nIeta < fNETAdiv;
682 //
683 // OUT:
684 // ieta, iphi - indexes of cell(tower) in two dimensional grid of SM
685 // ieta - have to change from 0 to (fNZ*fNETAdiv-1)
686 // iphi - have to change from 0 to (fNPhi*fNPHIdiv-1 or fNPhi*fNPHIdiv/2-1)
687 //
688 static Int_t iphim=-1, ietam=-1;
689
690 GetModulePhiEtaIndexInSModule(nSupMod,nModule, iphim, ietam);
691 // ieta = ietam*fNETAdiv + (1-nIeta); // x(module) = -z(SM)
692 ieta = ietam*fNETAdiv + (fNETAdiv - 1 - nIeta); // x(module) = -z(SM)
693 iphi = iphim*fNPHIdiv + nIphi; // y(module) = y(SM)
694
695 if(iphi<0 || ieta<0)
696 AliDebug(1,Form(" nSupMod %i nModule %i nIphi %i nIeta %i => ieta %i iphi %i\n",
697 nSupMod, nModule, nIphi, nIeta, ieta, iphi));
698}
699
700
701// Methods for AliEMCALRecPoint - Feb 19, 2006
702//________________________________________________________________________________________________
703Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, Double_t &xr, Double_t &yr, Double_t &zr) const
704{
705 // Look to see what the relative
706 // position inside a given cell is
707 // for a recpoint.
708 // Alice numbering scheme - Jun 08, 2006
709 // In:
710 // absId - cell is as in Geant, 0<= absId < fNCells;
711 // OUT:
712 // xr,yr,zr - x,y,z coordinates of cell with absId inside SM
713
714 // Shift index taking into account the difference between standard SM
715 // and SM of half size in phi direction
716 const Int_t kphiIndexShift = fCentersOfCellsPhiDir.GetSize()/4; // Nov 22, 2006; was 6 for cas 2X2
717 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
718 if(!CheckAbsCellId(absId)) return kFALSE;
719
720 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
721 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi, ieta);
722
723 //Get eta position. Careful with ALICE conventions (increase index decrease eta)
724 Int_t ieta2 = ieta;
725 if(nSupMod%2 == 0)
726 ieta2 = (fCentersOfCellsEtaDir.GetSize()-1)-ieta;// 47-ieta, revert the ordering on A side in order to keep convention.
727 zr = fCentersOfCellsEtaDir.At(ieta2);
728 xr = fCentersOfCellsXDir.At(ieta2);
729
730 //Get phi position. Careful with ALICE conventions (increase index increase phi)
731 Int_t iphi2 = iphi;
732 if(nSupMod<10) {
733 if(nSupMod%2 != 0)
734 iphi2 = (fCentersOfCellsPhiDir.GetSize()-1)-iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
735 yr = fCentersOfCellsPhiDir.At(iphi2);
736
737 } else {
738 if(nSupMod%2 != 0)
739 iphi2 = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
740 yr = fCentersOfCellsPhiDir.At(iphi2 + kphiIndexShift);
741 }
742 AliDebug(1,Form("absId %i nSupMod %i iphi %i ieta %i xr %f yr %f zr %f ",absId,nSupMod,iphi,ieta,xr,yr,zr));
743
744 return kTRUE;
745}
746
747//________________________________________________________________________________________________
748Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, Double_t loc[3]) const
749{
750 // Look to see what the relative
751 // position inside a given cell is
752 // for a recpoint. // Alice numbering scheme - Jun 03, 2006
753 loc[0] = loc[1] = loc[2]=0.0;
754 if(RelPosCellInSModule(absId, loc[0],loc[1],loc[2])) {
755 return kTRUE;
756 }
757 return kFALSE;
758}
759
760//________________________________________________________________________________________________
761Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, TVector3 &vloc) const
762{
763 // Look to see what the relative
764 // position inside a given cell is
765 // for a recpoint.
766 // Alice numbering scheme - Jun 03, 2006
767 static Double_t loc[3];
768 if(RelPosCellInSModule(absId,loc)) {
769 vloc.SetXYZ(loc[0], loc[1], loc[2]);
770 return kTRUE;
771 } else {
772 vloc.SetXYZ(0,0,0);
773 return kFALSE;
774 }
2012850d 775}
173558f2 776
d297ef6e 777//________________________________________________________________________________________________
1ae500a2 778Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, Double_t distEff, Double_t &xr, Double_t &yr, Double_t &zr) const
779{
780 // Jul 30, 2007 - taking into account position of shower max
781 // Look to see what the relative
782 // position inside a given cell is
783 // for a recpoint.
784 // In:
785 // absId - cell is as in Geant, 0<= absId < fNCells;
786 // e - cluster energy
787 // OUT:
788 // xr,yr,zr - x,y,z coordinates of cell with absId inside SM
e8c0d6bb 789
1ae500a2 790 // Shift index taking into account the difference between standard SM
791 // and SM of half size in phi direction
37890aaf 792 const Int_t kphiIndexShift = fCentersOfCellsPhiDir.GetSize()/4; // Nov 22, 2006; was 6 for cas 2X2
53e430a3 793 static Int_t nSupMod=0, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
794 static Int_t iphim=-1, ietam=-1;
1ae500a2 795 static AliEMCALShishKebabTrd1Module *mod = 0;
796 static TVector2 v;
797 if(!CheckAbsCellId(absId)) return kFALSE;
c694fff1 798
1ae500a2 799 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
800 GetModulePhiEtaIndexInSModule(nSupMod, nModule, iphim, ietam);
801 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi, ieta);
c694fff1 802
803 //Get eta position. Careful with ALICE conventions (increase index decrease eta)
804 if(nSupMod%2 == 0) {
805 ietam = (fCentersOfCellsEtaDir.GetSize()/2-1)-ietam;// 47-ietam, revert the ordering on A side in order to keep convention.
806 if(nIeta == 0) nIeta = 1;
807 else nIeta = 0;
808 }
1ae500a2 809 mod = GetShishKebabModule(ietam);
c694fff1 810 mod ->GetPositionAtCenterCellLine(nIeta, distEff, v);
1ae500a2 811 xr = v.Y() - fParSM[0];
812 zr = v.X() - fParSM[2];
c694fff1 813
814 //Get phi position. Careful with ALICE conventions (increase index increase phi)
815 Int_t iphi2 = iphi;
816 if(nSupMod<10) {
817 if(nSupMod%2 != 0)
818 iphi2 = (fCentersOfCellsPhiDir.GetSize()-1)-iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
819 yr = fCentersOfCellsPhiDir.At(iphi2);
820
1ae500a2 821 } else {
c694fff1 822 if(nSupMod%2 != 0)
823 iphi2 = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
824 yr = fCentersOfCellsPhiDir.At(iphi2 + kphiIndexShift);
1ae500a2 825 }
c694fff1 826
1ae500a2 827 AliDebug(1,Form("absId %i nSupMod %i iphi %i ieta %i xr %f yr %f zr %f ",absId,nSupMod,iphi,ieta,xr,yr,zr));
c694fff1 828
1ae500a2 829 return kTRUE;
830}
831
1d46d1f6 832
e8c0d6bb 833//________________________________________________________________________________________________
834void AliEMCALGeometry::CreateListOfTrd1Modules()
835{
836 // Generate the list of Trd1 modules
837 // which will make up the EMCAL
838 // geometry
839 // key: look to the AliEMCALShishKebabTrd1Module::
14e75ea7 840
e8c0d6bb 841 AliDebug(2,Form(" AliEMCALGeometry::CreateListOfTrd1Modules() started "));
e52475ed 842
e8c0d6bb 843 AliEMCALShishKebabTrd1Module *mod=0, *mTmp=0; // current module
844 if(fShishKebabTrd1Modules == 0) {
845 fShishKebabTrd1Modules = new TList;
846 fShishKebabTrd1Modules->SetName("ListOfTRD1");
847 for(int iz=0; iz< fEMCGeometry->GetNZ(); iz++) {
848 if(iz==0) {
849 // mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,this);
850 mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,fEMCGeometry);
851 } else {
852 mTmp = new AliEMCALShishKebabTrd1Module(*mod);
853 mod = mTmp;
854 }
855 fShishKebabTrd1Modules->Add(mod);
856 }
857 } else {
858 AliDebug(2,Form(" Already exits : "));
859 }
860 mod = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(fShishKebabTrd1Modules->GetSize()-1);
861 fEtaMaxOfTRD1 = mod->GetMaxEtaOfModule(0);
862
863 AliDebug(2,Form(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
864 fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1));
865 // Feb 20,2006;
866 // Jun 01, 2006 - ALICE numbering scheme
867 // define grid for cells in eta(z) and x directions in local coordinates system of SM
868 // Works just for 2x2 case only -- ?? start here
869 //
870 //
871 // Define grid for cells in phi(y) direction in local coordinates system of SM
872 // as for 2X2 as for 3X3 - Nov 8,2006
873 //
874 AliDebug(2,Form(" Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize()));
875 Int_t ind=0; // this is phi index
876 Int_t ieta=0, nModule=0, iphiTemp;
877 Double_t xr=0., zr=0., theta=0., phi=0., eta=0., r=0., x=0.,y=0.;
878 TVector3 vglob;
879 Double_t ytCenterModule=0.0, ytCenterCell=0.0;
880
881 fCentersOfCellsPhiDir.Set(fNPhi*fNPHIdiv);
882 fPhiCentersOfCells.Set(fNPhi*fNPHIdiv);
883
884 Double_t r0 = fIPDistance + fLongModuleSize/2.;
885 for(Int_t it=0; it<fNPhi; it++) { // cycle on modules
886 ytCenterModule = -fParSM[1] + fPhiModuleSize*(2*it+1)/2; // center of module
887 for(Int_t ic=0; ic<fNPHIdiv; ic++) { // cycle on cells in module
888 if(fNPHIdiv==2) {
889 ytCenterCell = ytCenterModule + fPhiTileSize *(2*ic-1)/2.;
890 } else if(fNPHIdiv==3){
891 ytCenterCell = ytCenterModule + fPhiTileSize *(ic-1);
892 } else if(fNPHIdiv==1){
893 ytCenterCell = ytCenterModule;
894 }
895 fCentersOfCellsPhiDir.AddAt(ytCenterCell,ind);
896 // Define grid on phi direction
897 // Grid is not the same for different eta bin;
898 // Effect is small but is still here
899 phi = TMath::ATan2(ytCenterCell, r0);
900 fPhiCentersOfCells.AddAt(phi, ind);
901
902 AliDebug(2,Form(" ind %2.2i : y %8.3f ", ind, fCentersOfCellsPhiDir.At(ind)));
903 ind++;
904 }
905 }
906
907 fCentersOfCellsEtaDir.Set(fNZ *fNETAdiv);
908 fCentersOfCellsXDir.Set(fNZ *fNETAdiv);
909 fEtaCentersOfCells.Set(fNZ *fNETAdiv * fNPhi*fNPHIdiv);
910 AliDebug(2,Form(" Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize()));
911 for(Int_t it=0; it<fNZ; it++) {
912 AliEMCALShishKebabTrd1Module *trd1 = GetShishKebabModule(it);
913 nModule = fNPhi*it;
914 for(Int_t ic=0; ic<fNETAdiv; ic++) {
915 if(fNPHIdiv==2) {
916 trd1->GetCenterOfCellInLocalCoordinateofSM(ic, xr, zr); // case of 2X2
917 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
918 } if(fNPHIdiv==3) {
919 trd1->GetCenterOfCellInLocalCoordinateofSM3X3(ic, xr, zr); // case of 3X3
920 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
921 } if(fNPHIdiv==1) {
922 trd1->GetCenterOfCellInLocalCoordinateofSM1X1(xr, zr); // case of 1X1
923 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
924 }
925 fCentersOfCellsXDir.AddAt(float(xr) - fParSM[0],ieta);
926 fCentersOfCellsEtaDir.AddAt(float(zr) - fParSM[2],ieta);
927 // Define grid on eta direction for each bin in phi
928 for(int iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
929 x = xr + trd1->GetRadius();
930 y = fCentersOfCellsPhiDir[iphi];
931 r = TMath::Sqrt(x*x + y*y + zr*zr);
932 theta = TMath::ACos(zr/r);
933 eta = AliEMCALShishKebabTrd1Module::ThetaToEta(theta);
934 // ind = ieta*fCentersOfCellsPhiDir.GetSize() + iphi;
935 ind = iphi*fCentersOfCellsEtaDir.GetSize() + ieta;
936 fEtaCentersOfCells.AddAt(eta, ind);
937 }
938 //printf(" ieta %i : xr + trd1->GetRadius() %f : zr %f : eta %f \n", ieta, xr + trd1->GetRadius(), zr, eta);
939 }
940 }
941 for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
942 AliDebug(2,Form(" ind %2.2i : z %8.3f : x %8.3f", i+1,
943 fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i)));
944 }
945
946}
947
948
949//________________________________________________________________________________________________
950AliEMCALShishKebabTrd1Module* AliEMCALGeometry::GetShishKebabModule(Int_t neta) const
951{
952 //This method was too long to be
953 //included in the header file - the
954 //rule checker complained about it's
955 //length, so we move it here. It returns the
956 //shishkebabmodule at a given eta index point.
957
958 static AliEMCALShishKebabTrd1Module* trd1=0;
959 if(fShishKebabTrd1Modules && neta>=0 && neta<fShishKebabTrd1Modules->GetSize()) {
960 trd1 = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(neta);
961 } else trd1 = 0;
962 return trd1;
963}
964
965//___________________________________________________________________
966void AliEMCALGeometry::PrintGeometryGeoUtils()
967{
968 //Print information from geometry
969 fEMCGeometry->PrintGeometry();
970
971 printf(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
972 fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1);
973
974 printf("\n Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize());
975 for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
976 printf(" ind %2.2i : z %8.3f : x %8.3f \n", i,
977 fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i));
978 int ind=0; // Nov 21,2006
979 for(Int_t iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
980 ind = iphi*fCentersOfCellsEtaDir.GetSize() + i;
981 printf("%6.4f ", fEtaCentersOfCells[ind]);
982 if((iphi+1)%12 == 0) printf("\n");
983 }
984 printf("\n");
985
986 }
987
988 printf("\n Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize());
989 for(Int_t i=0; i<fCentersOfCellsPhiDir.GetSize(); i++) {
990 double phi=fPhiCentersOfCells.At(i);
991 printf(" ind %2.2i : y %8.3f : phi %7.5f(%6.2f) \n", i, fCentersOfCellsPhiDir.At(i),
992 phi, phi*TMath::RadToDeg());
993 }
994
995}
996
997//____________________________________________________________________________
998Bool_t AliEMCALGeometry::Impact(const TParticle * particle) const
999{
1000 // Tells if a particle enters EMCAL
1001 Bool_t in=kFALSE;
1002 Int_t absID=0;
1003 TVector3 vtx(particle->Vx(),particle->Vy(),particle->Vz());
1004 TVector3 vimpact(0,0,0);
1005 ImpactOnEmcal(vtx,particle->Theta(),particle->Phi(),absID,vimpact);
1006 if(absID>=0)
1007 in=kTRUE;
1008 return in;
1009}
1010//____________________________________________________________________________
1011void AliEMCALGeometry::ImpactOnEmcal(TVector3 vtx, Double_t theta, Double_t phi,
1012 Int_t & absId, TVector3 & vimpact) const
1013{
1014 // calculates the impact coordinates on EMCAL (centre of a tower/not on EMCAL surface)
1015 // of a neutral particle
1016 // emitted in the vertex vtx[3] with direction theta and phi in the ALICE global coordinate system
1017
1018 TVector3 p(TMath::Sin(theta)*TMath::Cos(phi),TMath::Sin(theta)*TMath::Sin(phi),TMath::Cos(theta)) ;
1019
1020 vimpact.SetXYZ(0,0,0);
1021 absId=-1;
1022 if(phi==0 || theta==0) return;
1023
1024 TVector3 direction;
1025 Double_t factor = (fIPDistance-vtx[1])/p[1];
1026 direction = vtx + factor*p;
1027
1028 //from particle direction -> tower hitted
1029 GetAbsCellIdFromEtaPhi(direction.Eta(),direction.Phi(),absId);
1030
1031 //tower absID hitted -> tower/module plane (evaluated at the center of the tower)
1032 Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
1033 Double_t loc[3],loc2[3],loc3[3];
1034 Double_t glob[3]={},glob2[3]={},glob3[3]={};
1035
1036 if(!RelPosCellInSModule(absId,loc)) return;
1037
1038 //loc is cell center of tower
1039 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
1040
1041 //look at 2 neighbours-s cell using nIphi={0,1} and nIeta={0,1}
1042 Int_t nIphi2=-1,nIeta2=-1,absId2=-1,absId3=-1;
1043 if(nIeta==0) nIeta2=1;
1044 else nIeta2=0;
1045 absId2=GetAbsCellId(nSupMod,nModule,nIphi,nIeta2);
1046 if(nIphi==0) nIphi2=1;
1047 else nIphi2=0;
1048 absId3=GetAbsCellId(nSupMod,nModule,nIphi2,nIeta);
1049
1050 //2nd point on emcal cell plane
1051 if(!RelPosCellInSModule(absId2,loc2)) return;
1052
1053 //3rd point on emcal cell plane
1054 if(!RelPosCellInSModule(absId3,loc3)) return;
1055
1056 // Get Matrix
1057 const TGeoHMatrix* m = GetMatrixForSuperModule(nSupMod);
1058 if(m) {
1059 m->LocalToMaster(loc, glob);
1060 m->LocalToMaster(loc2, glob2);
1061 m->LocalToMaster(loc3, glob3);
1062 } else {
1063 AliFatal("Geo matrixes are not loaded \n") ;
1064 }
1065
1066 //Equation of Plane from glob,glob2,glob3 (Ax+By+Cz+D=0)
1067 Double_t a = glob[1]*(glob2[2]-glob3[2]) + glob2[1]*(glob3[2]-glob[2]) + glob3[1]*(glob[2]-glob2[2]);
1068 Double_t b = glob[2]*(glob2[0]-glob3[0]) + glob2[2]*(glob3[0]-glob[0]) + glob3[2]*(glob[0]-glob2[0]);
1069 Double_t c = glob[0]*(glob2[1]-glob3[1]) + glob2[0]*(glob3[1]-glob[1]) + glob3[0]*(glob[1]-glob2[1]);
1070 Double_t d = glob[0]*(glob2[1]*glob3[2]-glob3[1]*glob2[2]) + glob2[0]*(glob3[1]*glob[2]-glob[1]*glob3[2]) + glob3[0]*(glob[1]*glob2[2]-glob2[1]*glob[2]);
1071 d=-d;
1072
1073 //shift equation of plane from tower/module center to surface along vector (A,B,C) normal to tower/module plane
1074 Double_t dist = fLongModuleSize/2.;
1075 Double_t norm = TMath::Sqrt(a*a+b*b+c*c);
1076 Double_t glob4[3]={};
1077 TVector3 dir(a,b,c);
1078 TVector3 point(glob[0],glob[1],glob[2]);
1079 if(point.Dot(dir)<0) dist*=-1;
1080 glob4[0]=glob[0]-dist*a/norm;
1081 glob4[1]=glob[1]-dist*b/norm;
1082 glob4[2]=glob[2]-dist*c/norm;
1083 d = glob4[0]*a + glob4[1]*b + glob4[2]*c ;
1084 d = -d;
1085
1086 //Line determination (2 points for equation of line : vtx and direction)
1087 //impact between line (particle) and plane (module/tower plane)
1088 Double_t den = a*(vtx(0)-direction(0)) + b*(vtx(1)-direction(1)) + c*(vtx(2)-direction(2));
1089 if(den==0){
1090 printf("ImpactOnEmcal() No solution :\n");
1091 return;
1092 }
1093
1094 Double_t length = a*vtx(0)+b*vtx(1)+c*vtx(2)+d;
1095 length /=den;
1096
1097 vimpact.SetXYZ(vtx(0)+length*(direction(0)-vtx(0)),vtx(1)+length*(direction(1)-vtx(1)),vtx(2)+length*(direction(2)-vtx(2)));
1098
1099 //shift vimpact from tower/module surface to center along vector (A,B,C) normal to tower/module plane
1100 vimpact.SetXYZ(vimpact(0)+dist*a/norm,vimpact(1)+dist*b/norm,vimpact(2)+dist*c/norm);
1101
1102 return;
1103}
1104
1105//_____________________________________________________________________________
1106Bool_t AliEMCALGeometry::IsInEMCAL(Double_t x, Double_t y, Double_t z) const {
1107 // Checks whether point is inside the EMCal volume, used in AliEMCALv*.cxx
1108 //
1109 // Code uses cylindrical approximation made of inner radius (for speed)
1110 //
1111 // Points behind EMCAl, i.e. R > outer radius, but eta, phi in acceptance
1112 // are considered to inside
1113
1114 Double_t r=sqrt(x*x+y*y);
1115
1116 if ( r > fEnvelop[0] ) {
1117 Double_t theta;
1118 theta = TMath::ATan2(r,z);
1119 Double_t eta;
1120 if(theta == 0)
1121 eta = 9999;
1122 else
1123 eta = -TMath::Log(TMath::Tan(theta/2.));
1124 if (eta < fArm1EtaMin || eta > fArm1EtaMax)
1125 return 0;
1126
1127 Double_t phi = TMath::ATan2(y,x) * 180./TMath::Pi();
1128 if (phi < 0) phi += 360; // phi should go from 0 to 360 in this case
1129 if (phi > fArm1PhiMin && phi < fArm1PhiMax)
1130 return 1;
1131 }
1132 return 0;
1133}
1134
1135//________________________________________________________________________________________________
1136Int_t AliEMCALGeometry::GetAbsTRUNumberFromNumberInSm(const Int_t row, const Int_t col, const Int_t sm) const
1137{ // Nov 6, 2007
1138 // Get TRU absolute number from column, row and Super Module number
1139 Int_t itru = row + col*fEMCGeometry->GetNModulesInTRUPhi() + sm*fEMCGeometry->GetNTRU();
1140 // printf(" GetAbsTRUNumberFromNumberInSm : row %2i col %2i sm %2i -> itru %2i\n", row, col, sm, itru);
1141 return itru;
1142}
1143
1144//________________________________________________________________________________________________
1145Bool_t AliEMCALGeometry::GetAbsFastORIndexFromTRU(const Int_t iTRU, const Int_t iADC, Int_t& id) const
1146{
1147 //Trigger mapping method, get FastOr Index from TRU
1148
1149 if (iTRU > 31 || iTRU < 0 || iADC > 95 || iADC < 0)
1150 {
1151 AliError("TRU out of range!");
1152 return kFALSE;
1153 }
1154
1155 id = ( iTRU % 2 ) ? iADC%4 + 4 * (23 - int(iADC/4)) : (3 - iADC%4) + 4 * int(iADC/4);
1156
1157 id += iTRU * 96;
1158
1159 return kTRUE;
1160}
1161
1162//________________________________________________________________________________________________
1163Bool_t AliEMCALGeometry::GetTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iADC) const
1164{
1165
1166 //Trigger mapping method, get TRU number from FastOr Index
1167
1168 if (id > 3071 || id < 0)
1169 {
1170 AliError("Id out of range!");
1171 return kFALSE;
1172 }
1173
1174 iTRU = id / 96;
1175
1176 iADC = id % 96;
1177
1178 iADC = ( iTRU % 2 ) ? iADC%4 + 4 * (23 - int(iADC/4)) : (3 - iADC%4) + 4 * int(iADC/4);
1179
1180 return kTRUE;
1181}
1182
1183//________________________________________________________________________________________________
1184Bool_t AliEMCALGeometry::GetPositionInTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iEta, Int_t& iPhi) const
1185{
1186 //Trigger mapping method, get position in TRU from FasOr Index
1187
1188 Int_t iADC=-1;
1189 if (!GetTRUFromAbsFastORIndex(id, iTRU, iADC)) return kFALSE;
1190
1191 Int_t x = iADC / 4;
1192 Int_t y = iADC % 4;
1193
1194 if ( iTRU % 2 ) // C side
1195 {
1196 iEta = 23 - x;
1197 iPhi = y;
1198 }
1199 else // A side
1200 {
1201 iEta = x;
1202 iPhi = 3 - y;
1203 }
1204
1205 return kTRUE;
1206}
1207
1208//________________________________________________________________________________________________
1209Bool_t AliEMCALGeometry::GetPositionInSMFromAbsFastORIndex(const Int_t id, Int_t& iSM, Int_t& iEta, Int_t& iPhi) const
1210{
1211 //Trigger mapping method, get position in Super Module from FasOr Index
1212
1213 Int_t iTRU=-1;
1214
1215 if (!GetPositionInTRUFromAbsFastORIndex(id, iTRU, iEta, iPhi)) return kFALSE;
1216
1217 if (iTRU % 2) // C side
1218 {
1219 iSM = 2 * ( int( int(iTRU / 2) / 3 ) ) + 1;
1220 }
1221 else // A side
1222 {
1223 iSM = 2 * ( int( int(iTRU / 2) / 3 ) );
1224 }
1225
1226 iPhi += 4 * int((iTRU % 6) / 2);
1227
1228 return kTRUE;
1229}
1230
1231//________________________________________________________________________________________________
1232Bool_t AliEMCALGeometry::GetPositionInEMCALFromAbsFastORIndex(const Int_t id, Int_t& iEta, Int_t& iPhi) const
1233{
1234 //Trigger mapping method, get position in EMCAL from FastOR index
1235
1236 Int_t iSM=-1;
1237
1238 if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi))
1239 {
1240 if (iSM % 2) iEta += 24;
1241
1242 iPhi += 12 * int(iSM / 2);
1243
1244 return kTRUE;
1245 }
1246
1247 return kFALSE;
1248}
1249
1250//________________________________________________________________________________________________
1251Bool_t AliEMCALGeometry::GetAbsFastORIndexFromPositionInTRU(const Int_t iTRU, const Int_t iEta, const Int_t iPhi, Int_t& id) const
1252{
1253 //Trigger mapping method, get Index if FastOr from Position in TRU
1254
1255 if (iTRU < 0 || iTRU > 31 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 3)
1256 {
1257 AliError("Out of range!");
1258 return kFALSE;
1259 }
1260
1261 id = iPhi + 4 * iEta + iTRU * 96;
1262
1263 return kTRUE;
1264}
1265
1266//________________________________________________________________________________________________
1267Bool_t AliEMCALGeometry::GetAbsFastORIndexFromPositionInSM(const Int_t iSM, const Int_t iEta, const Int_t iPhi, Int_t& id) const
1268{
1269 //Trigger mapping method, from position in SM Index get FastOR index
1270
1271 if (iSM < 0 || iSM > 11 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 11)
1272 {
1273 AliError("Out of range!");
1274 return kFALSE;
1275 }
1276
1277 Int_t x = iEta;
1278 Int_t y = iPhi % 4;
1279
1280 Int_t iOff = (iSM % 2) ? 1 : 0;
1281 Int_t iTRU = 2 * int(iPhi / 4) + 6 * int(iSM / 2) + iOff;
1282
1283 if (GetAbsFastORIndexFromPositionInTRU(iTRU, x, y, id))
1284 {
1285 return kTRUE;
1286 }
1287
1288 return kFALSE;
1289}
1290
1291//________________________________________________________________________________________________
1292Bool_t AliEMCALGeometry::GetAbsFastORIndexFromPositionInEMCAL(const Int_t iEta, const Int_t iPhi, Int_t& id) const
1293{
1294 //Trigger mapping method, from position in EMCAL Index get FastOR index
1295
1296 if (iEta < 0 || iEta > 47 || iPhi < 0 || iPhi > 63 )
1297 {
1298 AliError("Out of range!");
1299 return kFALSE;
1300 }
1301
1302 if (fFastOR2DMap[iEta][iPhi] == -1)
1303 {
1304 AliError("Invalid index!");
1305 return kFALSE;
1306 }
1307
1308 id = fFastOR2DMap[iEta][iPhi];
1309
1310 return kTRUE;
1311}
1312
1313//________________________________________________________________________________________________
1314Bool_t AliEMCALGeometry::GetFastORIndexFromCellIndex(const Int_t id, Int_t& idx) const
1315{
1316 //Trigger mapping method, from cell index get FastOR index
1317
1318 Int_t iSupMod, nModule, nIphi, nIeta, iphim, ietam;
1319
1320 Bool_t isOK = GetCellIndex( id, iSupMod, nModule, nIphi, nIeta );
1321
1322 GetModulePhiEtaIndexInSModule( iSupMod, nModule, iphim, ietam );
1323
1324 if (isOK && GetAbsFastORIndexFromPositionInSM(iSupMod, ietam, iphim, idx))
1325 {
1326 return kTRUE;
1327 }
1328
1329 return kFALSE;
1330}
1331
1332//________________________________________________________________________________________________
1333Bool_t AliEMCALGeometry::GetCellIndexFromFastORIndex(const Int_t id, Int_t idx[4]) const
1334{
1335 //Trigger mapping method, from FASTOR index get cell index
1336
1337 Int_t iSM=-1, iEta=-1, iPhi=-1;
1338 if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi))
1339 {
1340 Int_t ix = 2 * iEta;
1341 Int_t iy = 2 * iPhi;
1342
1343 for (Int_t i=0; i<2; i++)
1344 {
1345 for (Int_t j=0; j<2; j++)
1346 {
1347 idx[2*i+j] = GetAbsCellIdFromCellIndexes(iSM, iy + i, ix + j);
1348 }
1349 }
1350
1351 return kTRUE;
1352 }
1353
1354 return kFALSE;
1355}
1356
1357//________________________________________________________________________________________________
1358Bool_t AliEMCALGeometry::GetTRUIndexFromSTUIndex(const Int_t id, Int_t& idx) const
1359{
1360 //Trigger mapping method, from STU index get TRU index
1361
1362 if (id > 31 || id < 0)
1363 {
1364 AliError(Form("TRU index out of range: %d",id));
1365 return kFALSE;
1366 }
1367
1368 idx = (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
1369
1370 return kTRUE;
1371}
1372
1373//________________________________________________________________________________________________
1374Int_t AliEMCALGeometry::GetTRUIndexFromSTUIndex(const Int_t id) const
1375{
1376 //Trigger mapping method, from STU index get TRU index
1377
1378 if (id > 31 || id < 0)
1379 {
1380 AliError(Form("TRU index out of range: %d",id));
1381 }
1382
1383 Int_t idx = (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
1384
1385 return idx;
1386}
1387
1388//________________________________________________________________________________________________
1389void AliEMCALGeometry::BuildFastOR2DMap()
1390{
1391 // Needed by STU
1392 for (Int_t i = 0; i < 32; i++)
1393 {
1394 for (Int_t j = 0; j < 24; j++)
1395 {
1396 for (Int_t k = 0; k < 4; k++)
1397 {
1398 Int_t id;
1399 if (GetAbsFastORIndexFromPositionInTRU(i, j, k, id))
1400 {
1401 Int_t x = j, y = k + 4 * int(i / 2);
1402
1403 if (i % 2) x += 24;
1404
1405 fFastOR2DMap[x][y] = id;
1406 }
1407 }
1408 }
1409 }
1410}
1411
804b828a 1412//________________________________________________________________________________________________
1413Bool_t AliEMCALGeometry::GetTRUIndexFromOnlineIndex(const Int_t id, Int_t& idx) const
1414{
1415 //Trigger mapping method, from STU index get TRU index
1416
1417 if (id > 31 || id < 0)
1418 {
1419 AliError(Form("TRU index out of range: %d",id));
1420 return kFALSE;
1421 }
1422
1423 idx = ((id % 6) < 3) ? 6 * int(id / 6) + 2 * (id % 3) : 6 * int(id / 6) + 2 * (2 - (id % 3)) + 1;
1424
1425 return kTRUE;
1426}
1427
1428//________________________________________________________________________________________________
1429Int_t AliEMCALGeometry::GetTRUIndexFromOnlineIndex(const Int_t id) const
1430{
1431 //Trigger mapping method, from STU index get TRU index
1432
1433 if (id > 31 || id < 0)
1434 {
1435 AliError(Form("TRU index out of range: %d",id));
1436 }
1437
1438 Int_t idx = (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
1439
1440 return idx;
1441}
1442
1443//________________________________________________________________________________________________
1444Bool_t AliEMCALGeometry::GetOnlineIndexFromTRUIndex(const Int_t id, Int_t& idx) const
1445{
1446 //Trigger mapping method, from STU index get TRU index
1447
1448 if (id > 31 || id < 0)
1449 {
1450 AliError(Form("TRU index out of range: %d",id));
1451 return kFALSE;
1452 }
1453
1454 idx = (id % 2) ? int((6 - (id % 6)) / 2) + 3 * (int(id / 6) + 1) : 3 * int(id / 6) + int(id / 2);
1455
1456 return kTRUE;
1457}
1458
1459//________________________________________________________________________________________________
1460Int_t AliEMCALGeometry::GetOnlineIndexFromTRUIndex(const Int_t id) const
1461{
1462 //Trigger mapping method, from STU index get TRU index
1463
1464 if (id > 31 || id < 0)
1465 {
1466 AliError(Form("TRU index out of range: %d",id));
1467 }
1468
1469 Int_t idx = (id % 2) ? int((6 - (id % 6)) / 2) + 3 * (int(id / 6) + 1) : 3 * int(id / 6) + int(id / 2);
1470
1471 return idx;
1472}
1473
e8c0d6bb 1474//________________________________________________________________________________________________
1475Bool_t AliEMCALGeometry::GetFastORIndexFromL0Index(const Int_t iTRU, const Int_t id, Int_t idx[], const Int_t size) const
1476{
1477 //Trigger mapping method, from L0 index get FastOR index
1478 if (size <= 0 ||size > 4)
1479 {
1480 AliError("Size not supported!");
1481 return kFALSE;
1482 }
1483
1484 Int_t motif[4] = {0, 1, 4, 5};
1485
1486 switch (size)
1487 {
1488 case 1: // Cosmic trigger
1489 if (!GetAbsFastORIndexFromTRU(iTRU, id, idx[1])) return kFALSE;
1490 break;
1491 case 4: // 4 x 4
1492 for (Int_t k = 0; k < 4; k++)
1493 {
1494 Int_t iADC = motif[k] + 4 * int(id / 3) + (id % 3);
1495
1496 if (!GetAbsFastORIndexFromTRU(iTRU, iADC, idx[k])) return kFALSE;
1497 }
1498 break;
1499 default:
1500 break;
1501 }
1502
1503 return kTRUE;
1504}
1505
1506//____________________________________________________________________________
1507const TGeoHMatrix * AliEMCALGeometry::GetMatrixForSuperModule(Int_t smod) const {
1508
1509 //Provides shift-rotation matrix for EMCAL
1510
1511 if(smod < 0 || smod > fEMCGeometry->GetNumberOfSuperModules())
1512 AliFatal(Form("Wrong supermodule index -> %d",smod));
1513
1514 //If GeoManager exists, take matrixes from it
1515
1516 //
1517 // if(fKey110DEG && ind>=10) {
1518 // }
1519 //
1520 // if(!gGeoManager->cd(volpath.Data()))
1521 // AliFatal(Form("AliEMCALGeometry::GeoManager cannot find path %s!",volpath.Data()));
1522 //
1523 // TGeoHMatrix* m = gGeoManager->GetCurrentMatrix();
1524
1525 //Use matrices set externally
1526 if(!gGeoManager || (gGeoManager && fUseExternalMatrices)){
1527 if(fkSModuleMatrix[smod]){
1528 return fkSModuleMatrix[smod] ;
1529 }
1530 else{
1531 AliInfo("Stop:");
1532 printf("\t Can not find EMCAL misalignment matrixes\n") ;
1533 printf("\t Either import TGeoManager from geometry.root or \n");
1534 printf("\t read stored matrixes from AliESD Header: \n") ;
1535 printf("\t AliEMCALGeometry::SetMisalMatrixes(header->GetEMCALMisalMatrix()) \n") ;
1536 abort() ;
1537 }
1538 }//external matrices
1539
1540 if(gGeoManager){
1541 const Int_t buffersize = 255;
1542 char path[buffersize] ;
1543 snprintf(path,buffersize,"/ALIC_1/XEN1_1/SMOD_%d",smod+1) ;
1544 //TString volpath = "ALIC_1/XEN1_1/SMOD_";
1545 //volpath += smod+1;
1546
1547 if(fKey110DEG && smod >= 10){
1548 snprintf(path,buffersize,"/ALIC_1/XEN1_1/SM10_%d",smod-10+1) ;
1549 //volpath = "ALIC_1/XEN1_1/SM10_";
1550 //volpath += smod-10+1;
1551 }
1552 if (!gGeoManager->cd(path)){
1553 AliFatal(Form("Geo manager can not find path %s!\n",path));
1554 }
1555 return gGeoManager->GetCurrentMatrix();
1556 }
1557
1558 return 0 ;
1559}
1560
1561//______________________________________________________________________
1562void AliEMCALGeometry::GetModulePhiEtaIndexInSModuleFromTRUIndex(Int_t itru, Int_t iphitru, Int_t ietatru, Int_t &iphiSM, Int_t &ietaSM) const
1563{
1564
1565 // This method transforms the (eta,phi) index of module in a
1566 // TRU matrix into Super Module (eta,phi) index.
1567
1568 // Calculate in which row and column where the TRU are
1569 // ordered in the SM
1570
1571 Int_t col = itru/fEMCGeometry->GetNTRUPhi() ; // indexes of TRU in SM
1572 Int_t row = itru - col*fEMCGeometry->GetNTRUPhi();
1573
1574 iphiSM = fEMCGeometry->GetNModulesInTRUPhi()*row + iphitru ;
1575 ietaSM = fEMCGeometry->GetNModulesInTRUEta()*col + ietatru ;
e8c0d6bb 1576}
1577
1578//__________________________________________________________________________________________________________________
1579void AliEMCALGeometry::RecalculateTowerPosition(Float_t drow, Float_t dcol, const Int_t sm, const Float_t depth,
1580 const Float_t misaligTransShifts[15], const Float_t misaligRotShifts[15], Float_t global[3]) const
1581{ //Transform clusters cell position into global with alternative method, taking into account the depth calculation.
1582 //Input are: the tower indeces,
1583 // supermodule,
1584 // particle type (photon 0, electron 1, hadron 2 )
1585 // misalignment shifts to global position in case of need.
1586 // Federico.Ronchetti@cern.ch
1587
1588
1589 // To use in a print later
1590 Float_t droworg = drow;
1591 Float_t dcolorg = dcol;
1592
1593 if(gGeoManager){
1594 //Recover some stuff
1595
1596 const Int_t nSMod = fEMCGeometry->GetNumberOfSuperModules();
1597
1598 gGeoManager->cd("ALIC_1/XEN1_1");
1599 TGeoNode *geoXEn1 = gGeoManager->GetCurrentNode();
1600 TGeoNodeMatrix *geoSM[nSMod];
1601 TGeoVolume *geoSMVol[nSMod];
1602 TGeoShape *geoSMShape[nSMod];
1603 TGeoBBox *geoBox[nSMod];
1604 TGeoMatrix *geoSMMatrix[nSMod];
1605
1606 for(int iSM = 0; iSM < nSMod; iSM++) {
1607 geoSM[iSM] = dynamic_cast<TGeoNodeMatrix *>(geoXEn1->GetDaughter(iSM));
1608 geoSMVol[iSM] = geoSM[iSM]->GetVolume();
1609 geoSMShape[iSM] = geoSMVol[iSM]->GetShape();
1610 geoBox[iSM] = dynamic_cast<TGeoBBox *>(geoSMShape[iSM]);
1611 geoSMMatrix[iSM] = geoSM[iSM]->GetMatrix();
1612 }
1613
1614 if(sm % 2 == 0) {
1615 dcol = 47. - dcol;
1616 drow = 23. - drow;
1617 }
1618
1619 Int_t istrip = 0;
1620 Float_t z0 = 0;
1621 Float_t zb = 0;
bccc4a4f 1622 Float_t zIs = 0;
e8c0d6bb 1623
1624 Float_t x,y,z; // return variables in terry's RF
1625
1626 //***********************************************************
1627 //Do not like this: too many hardcoded values, is it not already stored somewhere else?
1628 // : need more comments in the code
1629 //***********************************************************
1630
1631 Float_t dz = 6.0; // base cell width in eta
1632 Float_t dx = 6.004; // base cell width in phi
1633
1634
1635 //Float_t L = 26.04; // active tower length for hadron (lead+scint+paper)
1636 // we use the geant numbers 13.87*2=27.74
1637 Float_t teta1 = 0.;
1638
1639 //Do some basic checks
1640 if (dcol >= 47.5 || dcol<-0.5) {
1641 AliError(Form("Bad tower coordinate dcol=%f, where dcol >= 47.5 || dcol<-0.5; org: %f", dcol, dcolorg));
1642 return;
1643 }
1644 if (drow >= 23.5 || drow<-0.5) {
1645 AliError(Form("Bad tower coordinate drow=%f, where drow >= 23.5 || drow<-0.5; org: %f", drow, droworg));
1646 return;
1647 }
1648 if (sm >= nSMod || sm < 0) {
1649 AliError(Form("Bad SM number sm=%d, where sm >= %d || sm < 0", nSMod, sm));
1650 return;
1651 }
1652
1653 istrip = int ((dcol+0.5)/2);
1654
1655 // tapering angle
1656 teta1 = TMath::DegToRad() * istrip * 1.5;
1657
1658 // calculation of module corner along z
1659 // as a function of strip
1660
1661 for (int is=0; is<= istrip; is++) {
1662
1663 teta1 = TMath::DegToRad() * (is*1.5 + 0.75);
1664 if(is==0)
bccc4a4f 1665 zIs = zIs + 2*dz*TMath::Cos(teta1);
e8c0d6bb 1666 else
bccc4a4f 1667 zIs = zIs + 2*dz*TMath::Cos(teta1) + 2*dz*TMath::Sin(teta1)*TMath::Tan(teta1-0.75*TMath::DegToRad());
e8c0d6bb 1668
1669 }
1670
1671 z0 = dz*(dcol-2*istrip+0.5);
1672 zb = (2*dz-z0-depth*TMath::Tan(teta1));
1673
bccc4a4f 1674 z = zIs - zb*TMath::Cos(teta1);
e8c0d6bb 1675 y = depth/TMath::Cos(teta1) + zb*TMath::Sin(teta1);
1676
1677 x = (drow + 0.5)*dx;
1678
1679 // moving the origin from terry's RF
1680 // to the GEANT one
1681
1682 double xx = y - geoBox[sm]->GetDX();
1683 double yy = -x + geoBox[sm]->GetDY();
1684 double zz = z - geoBox[sm]->GetDZ();
1685 const double localIn[3] = {xx, yy, zz};
1686 double dglobal[3];
1687 //geoSMMatrix[sm]->Print();
1688 //printf("TFF Local (row = %d, col = %d, x = %3.2f, y = %3.2f, z = %3.2f)\n", iroworg, icolorg, localIn[0], localIn[1], localIn[2]);
1689 geoSMMatrix[sm]->LocalToMaster(localIn, dglobal);
1690 //printf("TFF Global (row = %2.0f, col = %2.0f, x = %3.2f, y = %3.2f, z = %3.2f)\n", drow, dcol, dglobal[0], dglobal[1], dglobal[2]);
1691
1692 //apply global shifts
1693 if(sm == 2 || sm == 3) {//sector 1
1694 global[0] = dglobal[0] + misaligTransShifts[3] + misaligRotShifts[3]*TMath::Sin(TMath::DegToRad()*20) ;
1695 global[1] = dglobal[1] + misaligTransShifts[4] + misaligRotShifts[4]*TMath::Cos(TMath::DegToRad()*20) ;
1696 global[2] = dglobal[2] + misaligTransShifts[5];
1697 }
1698 else if(sm == 0 || sm == 1){//sector 0
1699 global[0] = dglobal[0] + misaligTransShifts[0];
1700 global[1] = dglobal[1] + misaligTransShifts[1];
1701 global[2] = dglobal[2] + misaligTransShifts[2];
1702 }
1703 else {
1704 AliInfo("Careful, correction not implemented yet!");
1705 global[0] = dglobal[0] ;
1706 global[1] = dglobal[1] ;
1707 global[2] = dglobal[2] ;
1708 }
1709
1710
1711 }
1712 else{
1713 AliFatal("Geometry boxes information, check that geometry.root is loaded\n");
1714 }
1715
1716}
bccc4a4f 1717
1718void AliEMCALGeometry::SetMisalMatrix(const TGeoHMatrix * m, Int_t smod)
1719{
1720// Method to set shift-rotational matrixes from ESDHeader
1721// Move from header due to coding violations : Dec 2,2011 by PAI
1722 fUseExternalMatrices = kTRUE;
1723
1724 if (smod >= 0 && smod < fEMCGeometry->GetNumberOfSuperModules()){
1725 if(!fkSModuleMatrix[smod]) fkSModuleMatrix[smod] = new TGeoHMatrix(*m) ; //Set only if not set yet
1726 } else AliFatal(Form("Wrong supermodule index -> %d",smod));
1727}