1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliEMCALGeoUtils.cxx 25590 2008-05-06 07:09:11Z prsnko $ */
18 //_________________________________________________________________________
19 // Geometry class for EMCAL : singleton
21 // -- Author: Magali Estienne (magali.estienne@subatech.in2p3.fr)
25 // You can create the AliEMCALGeoUtils object independently from anything.
26 // You have to use just the correct name of geometry. If name is empty string the
27 // default name of geometry will be used.
29 // AliEMCALGeoUtils* geom = new AliEMCALGeoUtils("EMCAL_COMPLETE","EMCAL");
30 // TGeoManager::Import("geometry.root");
32 // MC: If you work with MC data you have to get geometry the next way:
33 // == =============================
34 // !!!!!!!!! This part has to be modified
35 // AliRunLoader *rl = AliRunLoader::GetRunLoader();
36 // AliEMCALEMCGeometry *geom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
37 // TGeoManager::Import("geometry.root");
40 // --- ROOT system ---
42 #include <TParticle.h>
43 #include <TGeoManager.h>
44 #include <TGeoMatrix.h>
49 // --- Standard library ---
50 //#include <Riostream.h>
52 // --- AliRoot header files ---
53 #include "AliEMCALGeoUtils.h"
54 #include "AliEMCALShishKebabTrd1Module.h"
56 ClassImp(AliEMCALGeoUtils)
58 //____________________________________________________________________________
59 AliEMCALGeoUtils::AliEMCALGeoUtils():
60 fEMCGeometry(0x0),fGeoName(0),
61 fKey110DEG(0),fNCellsInSupMod(0),fNETAdiv(0),fNPHIdiv(0),
62 fNCellsInModule(0),fPhiBoundariesOfSM(0x0),fPhiCentersOfSM(0x0),
63 fPhiCentersOfCells(0x0),fCentersOfCellsEtaDir(0x0),
64 fCentersOfCellsPhiDir(0x0),fEtaCentersOfCells(0x0),
65 fNCells(0),fNPhi(0),fCentersOfCellsXDir(0x0),fArm1EtaMin(0),
66 fArm1EtaMax(0),fArm1PhiMin(0),fArm1PhiMax(0),fEtaMaxOfTRD1(0),
67 fShishKebabTrd1Modules(0),fParSM(0x0),fPhiModuleSize(0.),
68 fEtaModuleSize(0.),fPhiTileSize(0.),fEtaTileSize(0.),fNZ(0),
69 fIPDistance(0.),fLongModuleSize(0.),fShellThickness(0.),
70 fZLength(0.),fSampling(0.)
73 // must be kept public for root persistency purposes, but should never be called by the outside world
77 for(Int_t i=0;i<12;i++)fkSModuleMatrix[i]=0 ;
79 for (Int_t i = 0; i < 48; i++)
80 for (Int_t j = 0; j < 64; j++) fFastOR2DMap[i][j] = -1;
83 //____________________________________________________________________________
84 AliEMCALGeoUtils::AliEMCALGeoUtils(const AliEMCALGeoUtils & geo)
86 fEMCGeometry(geo.fEMCGeometry),fGeoName(geo.fGeoName),
87 fKey110DEG(geo.fKey110DEG),fNCellsInSupMod(geo.fNCellsInSupMod),fNETAdiv(geo.fNETAdiv),fNPHIdiv(geo.fNPHIdiv),
88 fNCellsInModule(geo.fNCellsInModule),fPhiBoundariesOfSM(geo.fPhiBoundariesOfSM),fPhiCentersOfSM(geo.fPhiCentersOfSM),
89 fPhiCentersOfCells(geo.fPhiCentersOfCells),fCentersOfCellsEtaDir(geo.fCentersOfCellsEtaDir),
90 fCentersOfCellsPhiDir(geo.fCentersOfCellsPhiDir),fEtaCentersOfCells(geo.fEtaCentersOfCells),
91 fNCells(geo.fNCells),fNPhi(geo.fNPhi),fCentersOfCellsXDir(geo.fCentersOfCellsXDir),fArm1EtaMin(geo.fArm1EtaMin),
92 fArm1EtaMax(geo.fArm1EtaMax),fArm1PhiMin(geo.fArm1PhiMin),fArm1PhiMax(geo.fArm1PhiMax),fEtaMaxOfTRD1(geo.fEtaMaxOfTRD1),
93 fShishKebabTrd1Modules(geo.fShishKebabTrd1Modules),fParSM(geo.fParSM),fPhiModuleSize(geo.fPhiModuleSize),
94 fEtaModuleSize(geo.fEtaModuleSize),fPhiTileSize(geo.fPhiTileSize),fEtaTileSize(geo.fEtaTileSize),fNZ(geo.fNZ),
95 fIPDistance(geo.fIPDistance),fLongModuleSize(geo.fLongModuleSize),fShellThickness(geo.fShellThickness),
96 fZLength(geo.fZLength),fSampling(geo.fSampling)
98 fEnvelop[0] = geo.fEnvelop[0];
99 fEnvelop[1] = geo.fEnvelop[1];
100 fEnvelop[2] = geo.fEnvelop[2];
101 for(Int_t i=0;i<12;i++)fkSModuleMatrix[i]=0 ;
103 for (Int_t i = 0; i < 48; i++)
104 for (Int_t j = 0; j < 64; j++) fFastOR2DMap[i][j] = geo.fFastOR2DMap[i][j];
107 //____________________________________________________________________________
108 AliEMCALGeoUtils::AliEMCALGeoUtils(const Text_t* name, const Text_t* title)
109 : TNamed(name, title),
110 fEMCGeometry(0x0),fGeoName(0),
111 fKey110DEG(0),fNCellsInSupMod(0),fNETAdiv(0),fNPHIdiv(0),
112 fNCellsInModule(0),fPhiBoundariesOfSM(0x0),fPhiCentersOfSM(0x0),
113 fPhiCentersOfCells(0x0),fCentersOfCellsEtaDir(0x0),
114 fCentersOfCellsPhiDir(0x0),fEtaCentersOfCells(0x0),
115 fNCells(0),fNPhi(0),fCentersOfCellsXDir(0x0),fArm1EtaMin(0),
116 fArm1EtaMax(0),fArm1PhiMin(0),fArm1PhiMax(0),fEtaMaxOfTRD1(0),
117 fShishKebabTrd1Modules(0),fParSM(0x0),fPhiModuleSize(0.),
118 fEtaModuleSize(0.),fPhiTileSize(0.),fEtaTileSize(0.),fNZ(0),
119 fIPDistance(0.),fLongModuleSize(0.),fShellThickness(0.),
120 fZLength(0.),fSampling(0.)
123 // ctor only for normal usage
125 fEMCGeometry = new AliEMCALEMCGeometry(name,title);
127 fGeoName = fEMCGeometry->GetGeoName();
128 fKey110DEG = fEMCGeometry->GetKey110DEG();
129 fNCellsInSupMod = fEMCGeometry->GetNCellsInSupMod();
130 fNETAdiv = fEMCGeometry->GetNETAdiv();
131 fNPHIdiv = fEMCGeometry->GetNPHIdiv();
132 fNCellsInModule = fNPHIdiv*fNETAdiv;
134 Int_t nSMod = fEMCGeometry->GetNumberOfSuperModules();
135 fPhiBoundariesOfSM.Set(nSMod);
136 fPhiCentersOfSM.Set(nSMod/2);
137 for(Int_t sm=0; sm<nSMod; sm++) {
139 fEMCGeometry->GetPhiBoundariesOfSM(sm,fPhiBoundariesOfSM[2*i],fPhiBoundariesOfSM[2*i+1]);
142 Double_t phiMin = 0.;
143 Double_t phiMax = 0.;
144 for(Int_t sm=0; sm<nSMod; sm++) {
145 fEMCGeometry->GetPhiBoundariesOfSM(sm,phiMin,phiMax);
147 fPhiCentersOfSM[i] = fEMCGeometry->GetPhiCenterOfSM(sm);
149 fNCells = fEMCGeometry->GetNCells();
150 fNPhi = fEMCGeometry->GetNPhi();
151 fEnvelop[0] = fEMCGeometry->GetEnvelop(0);
152 fEnvelop[1] = fEMCGeometry->GetEnvelop(1);
153 fEnvelop[2] = fEMCGeometry->GetEnvelop(2);
154 fArm1EtaMin = fEMCGeometry->GetArm1EtaMin();
155 fArm1EtaMax = fEMCGeometry->GetArm1EtaMax();
156 fArm1PhiMin = fEMCGeometry->GetArm1PhiMin();
157 fArm1PhiMax = fEMCGeometry->GetArm1PhiMax();
158 fShellThickness = fEMCGeometry->GetShellThickness();
159 fZLength = fEMCGeometry->GetZLength();
160 fSampling = fEMCGeometry->GetSampling();
161 fParSM = fEMCGeometry->GetSuperModulesPars();
162 fEtaModuleSize = fEMCGeometry->GetEtaModuleSize();
163 fPhiModuleSize = fEMCGeometry->GetPhiModuleSize();
164 fEtaTileSize = fEMCGeometry->GetEtaTileSize();
165 fPhiTileSize = fEMCGeometry->GetPhiTileSize();
166 fNZ = fEMCGeometry->GetNZ();
167 fIPDistance = fEMCGeometry->GetIPDistance();
168 fLongModuleSize = fEMCGeometry->GetLongModuleSize();
170 CreateListOfTrd1Modules();
172 for(Int_t smod=0; smod < fEMCGeometry->GetNumberOfSuperModules(); smod++)
173 fkSModuleMatrix[smod]=0 ;
175 if (AliDebugLevel()>=2) {
176 fEMCGeometry->Print();
180 for (Int_t ix = 0; ix < 48; ix++)
181 for (Int_t jx = 0; jx < 64; jx++) fFastOR2DMap[ix][jx] = -1;
186 //____________________________________________________________________________
187 AliEMCALGeoUtils & AliEMCALGeoUtils::operator = (const AliEMCALGeoUtils & /*rvalue*/) {
189 Fatal("assignment operator", "not implemented") ;
193 //____________________________________________________________________________
194 AliEMCALGeoUtils::~AliEMCALGeoUtils(void)
198 for(Int_t smod = 0 ; smod < fEMCGeometry->GetNumberOfSuperModules(); smod++){
199 if(fkSModuleMatrix[smod])
200 delete fkSModuleMatrix[smod] ;
201 fkSModuleMatrix[smod]=0 ;
203 delete fEMCGeometry; fEMCGeometry = 0 ;
208 //________________________________________________________________________________________________
209 void AliEMCALGeoUtils::Browse(TBrowser* b)
212 if(fShishKebabTrd1Modules) b->Add(fShishKebabTrd1Modules);
215 //________________________________________________________________________________________________
216 Bool_t AliEMCALGeoUtils::IsFolder() const
218 //Check if fShishKebabTrd1Modules is in folder
219 if(fShishKebabTrd1Modules) return kTRUE;
223 //________________________________________________________________________________________________
224 void AliEMCALGeoUtils::GetGlobal(const Double_t *loc, Double_t *glob, int ind) const
226 // Figure out the global numbering
227 // of a given supermodule from the
228 // local numbering and the transformation
229 // matrix stored by the geometry manager (allows for misaligned
232 const TGeoHMatrix* m = GetMatrixForSuperModule(ind);
234 m->LocalToMaster(loc, glob);
236 AliFatal("Geo matrixes are not loaded \n") ;
240 //________________________________________________________________________________________________
241 void AliEMCALGeoUtils::GetGlobal(const TVector3 &vloc, TVector3 &vglob, int ind) const
243 //Figure out the global numbering
244 //of a given supermodule from the
245 //local numbering given a 3-vector location
247 static Double_t tglob[3], tloc[3];
249 GetGlobal(tloc, tglob, ind);
250 vglob.SetXYZ(tglob[0], tglob[1], tglob[2]);
253 //________________________________________________________________________________________________
254 void AliEMCALGeoUtils::GetGlobal(Int_t absId , double glob[3]) const
256 // Alice numbering scheme - Jun 03, 2006
257 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
258 static double loc[3];
260 glob[0]=glob[1]=glob[2]=0.0; // bad case
261 if(RelPosCellInSModule(absId, loc)) {
262 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
264 const TGeoHMatrix* m = GetMatrixForSuperModule(nSupMod);
266 m->LocalToMaster(loc, glob);
268 AliFatal("Geo matrixes are not loaded \n") ;
273 //___________________________________________________________________
274 void AliEMCALGeoUtils::GetGlobal(Int_t absId , TVector3 &vglob) const
276 // Alice numbering scheme - Jun 03, 2006
277 static Double_t glob[3];
279 GetGlobal(absId, glob);
280 vglob.SetXYZ(glob[0], glob[1], glob[2]);
285 //______________________________________________________________________
286 void AliEMCALGeoUtils::PrintCellIndexes(Int_t absId, int pri, const char *tit) const
289 Int_t nSupMod, nModule, nIphi, nIeta;
293 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
294 printf(" %s | absId : %i -> nSupMod %i nModule %i nIphi %i nIeta %i \n", tit, absId, nSupMod, nModule, nIphi, nIeta);
296 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
297 printf(" local SM index : iphi %i : ieta %i \n", iphi,ieta);
298 GetGlobal(absId, vg);
299 printf(" vglob : mag %7.2f : perp %7.2f : z %7.2f : eta %6.4f : phi %6.4f(%6.2f) \n",
300 vg.Mag(), vg.Perp(), vg.Z(), vg.Eta(), vg.Phi(), vg.Phi()*TMath::RadToDeg());
304 //________________________________________________________________________________________________
305 void AliEMCALGeoUtils::EtaPhiFromIndex(Int_t absId,Double_t &eta,Double_t &phi) const
307 // Nov 16, 2006- float to double
308 // version for TRD1 only
309 static TVector3 vglob;
310 GetGlobal(absId, vglob);
315 //________________________________________________________________________________________________
316 void AliEMCALGeoUtils::EtaPhiFromIndex(Int_t absId,Float_t &eta,Float_t &phi) const
318 // Nov 16,2006 - should be discard in future
319 static TVector3 vglob;
320 GetGlobal(absId, vglob);
321 eta = float(vglob.Eta());
322 phi = float(vglob.Phi());
326 // == Shish-kebab cases ==
328 //________________________________________________________________________________________________
329 Int_t AliEMCALGeoUtils::GetAbsCellId(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta) const
333 // 13-oct-05; 110 degree case
334 // May 31, 2006; ALICE numbering scheme:
335 // 0 <= nSupMod < fNumberOfSuperModules
336 // 0 <= nModule < fNPHI * fNZ ( fNPHI * fNZ/2 for fKey110DEG=1)
337 // 0 <= nIphi < fNPHIdiv
338 // 0 <= nIeta < fNETAdiv
339 // 0 <= absid < fNCells
340 static Int_t id=0; // have to change from 0 to fNCells-1
341 if(fKey110DEG == 1 && nSupMod >= 10) { // 110 degree case; last two supermodules
342 id = fNCellsInSupMod*10 + (fNCellsInSupMod/2)*(nSupMod-10);
344 id = fNCellsInSupMod*nSupMod;
346 id += fNCellsInModule *nModule;
347 id += fNPHIdiv *nIphi;
349 if(id<0 || id >= fNCells) {
350 // printf(" wrong numerations !!\n");
351 // printf(" id %6i(will be force to -1)\n", id);
352 // printf(" fNCells %6i\n", fNCells);
353 // printf(" nSupMod %6i\n", nSupMod);
354 // printf(" nModule %6i\n", nModule);
355 // printf(" nIphi %6i\n", nIphi);
356 // printf(" nIeta %6i\n", nIeta);
357 id = -TMath::Abs(id); // if negative something wrong
362 //________________________________________________________________________________________________
363 void AliEMCALGeoUtils::GetModuleIndexesFromCellIndexesInSModule(Int_t nSupMod, Int_t iphi, Int_t ieta,
364 Int_t &iphim, Int_t &ietam, Int_t &nModule) const
366 // Transition from cell indexes (ieta,iphi) to module indexes (ietam,iphim, nModule)
367 static Int_t nphi=-1;
368 nphi = GetNumberOfModuleInPhiDirection(nSupMod);
370 ietam = ieta/fNETAdiv;
371 iphim = iphi/fNPHIdiv;
372 nModule = ietam * nphi + iphim;
375 //________________________________________________________________________________________________
376 Int_t AliEMCALGeoUtils::GetAbsCellIdFromCellIndexes(Int_t nSupMod, Int_t iphi, Int_t ieta) const
378 // Transition from super module number(nSupMod) and cell indexes (ieta,iphi) to absId
379 static Int_t ietam=-1, iphim=-1, nModule=-1;
380 static Int_t nIeta=-1, nIphi=-1; // cell indexes in module
382 GetModuleIndexesFromCellIndexesInSModule(nSupMod, iphi, ieta, ietam, iphim, nModule);
384 nIeta = ieta%fNETAdiv;
385 nIeta = fNETAdiv - 1 - nIeta;
386 nIphi = iphi%fNPHIdiv;
388 return GetAbsCellId(nSupMod, nModule, nIphi, nIeta);
391 //________________________________________________________________________________________________
392 Bool_t AliEMCALGeoUtils::SuperModuleNumberFromEtaPhi(Double_t eta, Double_t phi, Int_t &nSupMod) const
394 // Return false if phi belongs a phi cracks between SM
398 if(TMath::Abs(eta) > fEtaMaxOfTRD1) return kFALSE;
400 phi = TVector2::Phi_0_2pi(phi); // move phi to (0,2pi) boundaries
403 //Check if it is not the complete geometry
404 if (i >= fEMCGeometry->GetNumberOfSuperModules()/2) return kFALSE;
406 if(phi>=fPhiBoundariesOfSM[2*i] && phi<=fPhiBoundariesOfSM[2*i+1]) {
408 if(eta < 0.0) nSupMod++;
409 AliDebug(1,Form("eta %f phi %f(%5.2f) : nSupMod %i : #bound %i", eta,phi,phi*TMath::RadToDeg(), nSupMod,i));
417 //________________________________________________________________________________________________
418 Bool_t AliEMCALGeoUtils::GetAbsCellIdFromEtaPhi(Double_t eta, Double_t phi, Int_t &absId) const
421 // stay here - phi problem as usual
422 static Int_t nSupMod=-1, i=0, ieta=-1, iphi=-1, etaShift=0, nphi=-1;
423 static Double_t absEta=0.0, d=0.0, dmin=0.0, phiLoc=0;
424 absId = nSupMod = - 1;
425 if(SuperModuleNumberFromEtaPhi(eta, phi, nSupMod)) {
427 phi = TVector2::Phi_0_2pi(phi);
428 phiLoc = phi - fPhiCentersOfSM[nSupMod/2];
429 nphi = fPhiCentersOfCells.GetSize();
431 phiLoc = phi - 190.*TMath::DegToRad();
435 dmin = TMath::Abs(fPhiCentersOfCells[0]-phiLoc);
437 for(i=1; i<nphi; i++) {
438 d = TMath::Abs(fPhiCentersOfCells[i] - phiLoc);
443 // printf(" i %i : d %f : dmin %f : fPhiCentersOfCells[i] %f \n", i, d, dmin, fPhiCentersOfCells[i]);
445 // odd SM are turned with respect of even SM - reverse indexes
446 AliDebug(2,Form(" iphi %i : dmin %f (phi %f, phiLoc %f ) ", iphi, dmin, phi, phiLoc));
448 absEta = TMath::Abs(eta);
449 etaShift = iphi*fCentersOfCellsEtaDir.GetSize();
450 dmin = TMath::Abs(fEtaCentersOfCells[etaShift]-absEta);
452 for(i=1; i<fCentersOfCellsEtaDir.GetSize(); i++) {
453 d = TMath::Abs(fEtaCentersOfCells[i+etaShift] - absEta);
459 AliDebug(2,Form(" ieta %i : dmin %f (eta=%f) : nSupMod %i ", ieta, dmin, eta, nSupMod));
461 if(eta<0) iphi = (nphi-1) - iphi;
463 //patch for mapping following alice convention
465 ieta = (fCentersOfCellsEtaDir.GetSize()-1)-ieta;// 47-ieta, revert the ordering on A side in order to keep convention.
468 iphi = (fCentersOfCellsPhiDir.GetSize()-1) -iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
470 iphi = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
473 absId = GetAbsCellIdFromCellIndexes(nSupMod, iphi, ieta);
480 //________________________________________________________________________________________________
481 Bool_t AliEMCALGeoUtils::CheckAbsCellId(Int_t absId) const
483 // May 31, 2006; only trd1 now
484 if(absId<0 || absId >= fNCells) return kFALSE;
488 //________________________________________________________________________________________________
489 Bool_t AliEMCALGeoUtils::GetCellIndex(Int_t absId,Int_t &nSupMod,Int_t &nModule,Int_t &nIphi,Int_t &nIeta) const
491 // 21-sep-04; 19-oct-05;
492 // May 31, 2006; ALICE numbering scheme:
495 // absId - cell is as in Geant, 0<= absId < fNCells;
497 // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
498 // nModule - module number in SM, 0<= nModule < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
499 // nIphi - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv;
500 // nIeta - cell number in eta driection inside module; 0<= nIeta < fNETAdiv;
502 static Int_t tmp=0, sm10=0;
503 if(!CheckAbsCellId(absId)) return kFALSE;
505 sm10 = fNCellsInSupMod*10;
506 if(fKey110DEG == 1 && absId >= sm10) { // 110 degree case; last two supermodules
507 nSupMod = (absId-sm10) / (fNCellsInSupMod/2) + 10;
508 tmp = (absId-sm10) % (fNCellsInSupMod/2);
510 nSupMod = absId / fNCellsInSupMod;
511 tmp = absId % fNCellsInSupMod;
514 nModule = tmp / fNCellsInModule;
515 tmp = tmp % fNCellsInModule;
516 nIphi = tmp / fNPHIdiv;
517 nIeta = tmp % fNPHIdiv;
522 //________________________________________________________________________________________________
523 Int_t AliEMCALGeoUtils::GetSuperModuleNumber(Int_t absId) const
525 // Return the number of the supermodule given the absolute
526 // ALICE numbering id
528 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
529 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
533 //________________________________________________________________________________________________
534 void AliEMCALGeoUtils::GetModulePhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, int &iphim, int &ietam) const
536 // added nSupMod; - 19-oct-05 !
537 // Alice numbering scheme - Jun 01,2006
538 // ietam, iphi - indexes of module in two dimensional grid of SM
539 // ietam - have to change from 0 to fNZ-1
540 // iphim - have to change from 0 to nphi-1 (fNPhi-1 or fNPhi/2-1)
541 static Int_t nphi=-1;
543 if(fKey110DEG == 1 && nSupMod>=10) nphi = fNPhi/2;
546 ietam = nModule/nphi;
547 iphim = nModule%nphi;
550 //________________________________________________________________________________________________
551 void AliEMCALGeoUtils::GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta,
552 int &iphi, int &ieta) const
555 // Added nSupMod; Nov 25, 05
556 // Alice numbering scheme - Jun 01,2006
558 // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
559 // nModule - module number in SM, 0<= nModule < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
560 // nIphi - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv;
561 // nIeta - cell number in eta driection inside module; 0<= nIeta < fNETAdiv;
564 // ieta, iphi - indexes of cell(tower) in two dimensional grid of SM
565 // ieta - have to change from 0 to (fNZ*fNETAdiv-1)
566 // iphi - have to change from 0 to (fNPhi*fNPHIdiv-1 or fNPhi*fNPHIdiv/2-1)
568 static Int_t iphim=-1, ietam=-1;
570 GetModulePhiEtaIndexInSModule(nSupMod,nModule, iphim, ietam);
571 // ieta = ietam*fNETAdiv + (1-nIeta); // x(module) = -z(SM)
572 ieta = ietam*fNETAdiv + (fNETAdiv - 1 - nIeta); // x(module) = -z(SM)
573 iphi = iphim*fNPHIdiv + nIphi; // y(module) = y(SM)
576 AliDebug(1,Form(" nSupMod %i nModule %i nIphi %i nIeta %i => ieta %i iphi %i\n",
577 nSupMod, nModule, nIphi, nIeta, ieta, iphi));
581 // Methods for AliEMCALRecPoint - Feb 19, 2006
582 //________________________________________________________________________________________________
583 Bool_t AliEMCALGeoUtils::RelPosCellInSModule(Int_t absId, Double_t &xr, Double_t &yr, Double_t &zr) const
585 // Look to see what the relative
586 // position inside a given cell is
588 // Alice numbering scheme - Jun 08, 2006
590 // absId - cell is as in Geant, 0<= absId < fNCells;
592 // xr,yr,zr - x,y,z coordinates of cell with absId inside SM
594 // Shift index taking into account the difference between standard SM
595 // and SM of half size in phi direction
596 const Int_t kphiIndexShift = fCentersOfCellsPhiDir.GetSize()/4; // Nov 22, 2006; was 6 for cas 2X2
597 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
598 if(!CheckAbsCellId(absId)) return kFALSE;
600 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
601 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi, ieta);
603 //Get eta position. Careful with ALICE conventions (increase index decrease eta)
606 ieta2 = (fCentersOfCellsEtaDir.GetSize()-1)-ieta;// 47-ieta, revert the ordering on A side in order to keep convention.
607 zr = fCentersOfCellsEtaDir.At(ieta2);
608 xr = fCentersOfCellsXDir.At(ieta2);
610 //Get phi position. Careful with ALICE conventions (increase index increase phi)
614 iphi2 = (fCentersOfCellsPhiDir.GetSize()-1)-iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
615 yr = fCentersOfCellsPhiDir.At(iphi2);
619 iphi2 = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
620 yr = fCentersOfCellsPhiDir.At(iphi2 + kphiIndexShift);
622 AliDebug(1,Form("absId %i nSupMod %i iphi %i ieta %i xr %f yr %f zr %f ",absId,nSupMod,iphi,ieta,xr,yr,zr));
627 //________________________________________________________________________________________________
628 Bool_t AliEMCALGeoUtils::RelPosCellInSModule(Int_t absId, Double_t loc[3]) const
630 // Look to see what the relative
631 // position inside a given cell is
632 // for a recpoint. // Alice numbering scheme - Jun 03, 2006
633 loc[0] = loc[1] = loc[2]=0.0;
634 if(RelPosCellInSModule(absId, loc[0],loc[1],loc[2])) {
640 //________________________________________________________________________________________________
641 Bool_t AliEMCALGeoUtils::RelPosCellInSModule(Int_t absId, TVector3 &vloc) const
643 // Look to see what the relative
644 // position inside a given cell is
646 // Alice numbering scheme - Jun 03, 2006
647 static Double_t loc[3];
648 if(RelPosCellInSModule(absId,loc)) {
649 vloc.SetXYZ(loc[0], loc[1], loc[2]);
657 //________________________________________________________________________________________________
658 void AliEMCALGeoUtils::CreateListOfTrd1Modules()
660 // Generate the list of Trd1 modules
661 // which will make up the EMCAL
664 AliDebug(2,Form(" AliEMCALGeometry::CreateListOfTrd1Modules() started "));
666 AliEMCALShishKebabTrd1Module *mod=0, *mTmp=0; // current module
667 if(fShishKebabTrd1Modules == 0) {
668 fShishKebabTrd1Modules = new TList;
669 fShishKebabTrd1Modules->SetName("ListOfTRD1");
670 for(int iz=0; iz< fEMCGeometry->GetNZ(); iz++) {
672 // mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,this);
673 mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,fEMCGeometry);
675 mTmp = new AliEMCALShishKebabTrd1Module(*mod);
678 fShishKebabTrd1Modules->Add(mod);
681 AliDebug(2,Form(" Already exits : "));
683 mod = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(fShishKebabTrd1Modules->GetSize()-1);
684 fEtaMaxOfTRD1 = mod->GetMaxEtaOfModule(0);
686 AliDebug(2,Form(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
687 fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1));
689 // Jun 01, 2006 - ALICE numbering scheme
690 // define grid for cells in eta(z) and x directions in local coordinates system of SM
691 // Works just for 2x2 case only -- ?? start here
694 // Define grid for cells in phi(y) direction in local coordinates system of SM
695 // as for 2X2 as for 3X3 - Nov 8,2006
697 AliDebug(2,Form(" Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize()));
698 Int_t ind=0; // this is phi index
699 Int_t ieta=0, nModule=0, iphiTemp;
700 Double_t xr=0., zr=0., theta=0., phi=0., eta=0., r=0., x=0.,y=0.;
702 Double_t ytCenterModule=0.0, ytCenterCell=0.0;
704 fCentersOfCellsPhiDir.Set(fNPhi*fNPHIdiv);
705 fPhiCentersOfCells.Set(fNPhi*fNPHIdiv);
707 Double_t r0 = fIPDistance + fLongModuleSize/2.;
708 for(Int_t it=0; it<fNPhi; it++) { // cycle on modules
709 ytCenterModule = -fParSM[1] + fPhiModuleSize*(2*it+1)/2; // center of module
710 for(Int_t ic=0; ic<fNPHIdiv; ic++) { // cycle on cells in module
712 ytCenterCell = ytCenterModule + fPhiTileSize *(2*ic-1)/2.;
713 } else if(fNPHIdiv==3){
714 ytCenterCell = ytCenterModule + fPhiTileSize *(ic-1);
715 } else if(fNPHIdiv==1){
716 ytCenterCell = ytCenterModule;
718 fCentersOfCellsPhiDir.AddAt(ytCenterCell,ind);
719 // Define grid on phi direction
720 // Grid is not the same for different eta bin;
721 // Effect is small but is still here
722 phi = TMath::ATan2(ytCenterCell, r0);
723 fPhiCentersOfCells.AddAt(phi, ind);
725 AliDebug(2,Form(" ind %2.2i : y %8.3f ", ind, fCentersOfCellsPhiDir.At(ind)));
730 fCentersOfCellsEtaDir.Set(fNZ *fNETAdiv);
731 fCentersOfCellsXDir.Set(fNZ *fNETAdiv);
732 fEtaCentersOfCells.Set(fNZ *fNETAdiv * fNPhi*fNPHIdiv);
733 AliDebug(2,Form(" Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize()));
734 for(Int_t it=0; it<fNZ; it++) {
735 AliEMCALShishKebabTrd1Module *trd1 = GetShishKebabModule(it);
737 for(Int_t ic=0; ic<fNETAdiv; ic++) {
739 trd1->GetCenterOfCellInLocalCoordinateofSM(ic, xr, zr); // case of 2X2
740 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
742 trd1->GetCenterOfCellInLocalCoordinateofSM3X3(ic, xr, zr); // case of 3X3
743 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
745 trd1->GetCenterOfCellInLocalCoordinateofSM1X1(xr, zr); // case of 1X1
746 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
748 fCentersOfCellsXDir.AddAt(float(xr) - fParSM[0],ieta);
749 fCentersOfCellsEtaDir.AddAt(float(zr) - fParSM[2],ieta);
750 // Define grid on eta direction for each bin in phi
751 for(int iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
752 x = xr + trd1->GetRadius();
753 y = fCentersOfCellsPhiDir[iphi];
754 r = TMath::Sqrt(x*x + y*y + zr*zr);
755 theta = TMath::ACos(zr/r);
756 eta = AliEMCALShishKebabTrd1Module::ThetaToEta(theta);
757 // ind = ieta*fCentersOfCellsPhiDir.GetSize() + iphi;
758 ind = iphi*fCentersOfCellsEtaDir.GetSize() + ieta;
759 fEtaCentersOfCells.AddAt(eta, ind);
761 //printf(" ieta %i : xr + trd1->GetRadius() %f : zr %f : eta %f \n", ieta, xr + trd1->GetRadius(), zr, eta);
764 for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
765 AliDebug(2,Form(" ind %2.2i : z %8.3f : x %8.3f", i+1,
766 fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i)));
772 //________________________________________________________________________________________________
773 AliEMCALShishKebabTrd1Module* AliEMCALGeoUtils::GetShishKebabModule(Int_t neta) const
775 //This method was too long to be
776 //included in the header file - the
777 //rule checker complained about it's
778 //length, so we move it here. It returns the
779 //shishkebabmodule at a given eta index point.
781 static AliEMCALShishKebabTrd1Module* trd1=0;
782 if(fShishKebabTrd1Modules && neta>=0 && neta<fShishKebabTrd1Modules->GetSize()) {
783 trd1 = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(neta);
788 //___________________________________________________________________
789 void AliEMCALGeoUtils::PrintGeometry()
791 //Print information from geometry
792 fEMCGeometry->PrintGeometry();
794 printf(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
795 fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1);
797 printf("\n Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize());
798 for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
799 printf(" ind %2.2i : z %8.3f : x %8.3f \n", i,
800 fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i));
801 int ind=0; // Nov 21,2006
802 for(Int_t iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
803 ind = iphi*fCentersOfCellsEtaDir.GetSize() + i;
804 printf("%6.4f ", fEtaCentersOfCells[ind]);
805 if((iphi+1)%12 == 0) printf("\n");
811 printf("\n Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize());
812 for(Int_t i=0; i<fCentersOfCellsPhiDir.GetSize(); i++) {
813 double phi=fPhiCentersOfCells.At(i);
814 printf(" ind %2.2i : y %8.3f : phi %7.5f(%6.2f) \n", i, fCentersOfCellsPhiDir.At(i),
815 phi, phi*TMath::RadToDeg());
820 //____________________________________________________________________________
821 Bool_t AliEMCALGeoUtils::Impact(const TParticle * particle) const
823 // Tells if a particle enters EMCAL
826 TVector3 vtx(particle->Vx(),particle->Vy(),particle->Vz());
827 TVector3 vimpact(0,0,0);
828 ImpactOnEmcal(vtx,particle->Theta(),particle->Phi(),absID,vimpact);
833 //____________________________________________________________________________
834 void AliEMCALGeoUtils::ImpactOnEmcal(TVector3 vtx, Double_t theta, Double_t phi,
835 Int_t & absId, TVector3 & vimpact) const
837 // calculates the impact coordinates on EMCAL (centre of a tower/not on EMCAL surface)
838 // of a neutral particle
839 // emitted in the vertex vtx[3] with direction theta and phi in the ALICE global coordinate system
841 TVector3 p(TMath::Sin(theta)*TMath::Cos(phi),TMath::Sin(theta)*TMath::Sin(phi),TMath::Cos(theta)) ;
843 vimpact.SetXYZ(0,0,0);
845 if(phi==0 || theta==0) return;
848 Double_t factor = (fIPDistance-vtx[1])/p[1];
849 direction = vtx + factor*p;
851 //from particle direction -> tower hitted
852 GetAbsCellIdFromEtaPhi(direction.Eta(),direction.Phi(),absId);
854 //tower absID hitted -> tower/module plane (evaluated at the center of the tower)
855 Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
856 Double_t loc[3],loc2[3],loc3[3];
857 Double_t glob[3]={},glob2[3]={},glob3[3]={};
859 if(!RelPosCellInSModule(absId,loc)) return;
861 //loc is cell center of tower
862 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
864 //look at 2 neighbours-s cell using nIphi={0,1} and nIeta={0,1}
865 Int_t nIphi2=-1,nIeta2=-1,absId2=-1,absId3=-1;
866 if(nIeta==0) nIeta2=1;
868 absId2=GetAbsCellId(nSupMod,nModule,nIphi,nIeta2);
869 if(nIphi==0) nIphi2=1;
871 absId3=GetAbsCellId(nSupMod,nModule,nIphi2,nIeta);
873 //2nd point on emcal cell plane
874 if(!RelPosCellInSModule(absId2,loc2)) return;
876 //3rd point on emcal cell plane
877 if(!RelPosCellInSModule(absId3,loc3)) return;
880 const TGeoHMatrix* m = GetMatrixForSuperModule(nSupMod);
882 m->LocalToMaster(loc, glob);
883 m->LocalToMaster(loc2, glob2);
884 m->LocalToMaster(loc3, glob3);
886 AliFatal("Geo matrixes are not loaded \n") ;
889 //Equation of Plane from glob,glob2,glob3 (Ax+By+Cz+D=0)
890 Double_t a = glob[1]*(glob2[2]-glob3[2]) + glob2[1]*(glob3[2]-glob[2]) + glob3[1]*(glob[2]-glob2[2]);
891 Double_t b = glob[2]*(glob2[0]-glob3[0]) + glob2[2]*(glob3[0]-glob[0]) + glob3[2]*(glob[0]-glob2[0]);
892 Double_t c = glob[0]*(glob2[1]-glob3[1]) + glob2[0]*(glob3[1]-glob[1]) + glob3[0]*(glob[1]-glob2[1]);
893 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]);
896 //shift equation of plane from tower/module center to surface along vector (A,B,C) normal to tower/module plane
897 Double_t dist = fLongModuleSize/2.;
898 Double_t norm = TMath::Sqrt(a*a+b*b+c*c);
899 Double_t glob4[3]={};
901 TVector3 point(glob[0],glob[1],glob[2]);
902 if(point.Dot(dir)<0) dist*=-1;
903 glob4[0]=glob[0]-dist*a/norm;
904 glob4[1]=glob[1]-dist*b/norm;
905 glob4[2]=glob[2]-dist*c/norm;
906 d = glob4[0]*a + glob4[1]*b + glob4[2]*c ;
909 //Line determination (2 points for equation of line : vtx and direction)
910 //impact between line (particle) and plane (module/tower plane)
911 Double_t den = a*(vtx(0)-direction(0)) + b*(vtx(1)-direction(1)) + c*(vtx(2)-direction(2));
913 printf("ImpactOnEmcal() No solution :\n");
917 Double_t length = a*vtx(0)+b*vtx(1)+c*vtx(2)+d;
920 vimpact.SetXYZ(vtx(0)+length*(direction(0)-vtx(0)),vtx(1)+length*(direction(1)-vtx(1)),vtx(2)+length*(direction(2)-vtx(2)));
922 //shift vimpact from tower/module surface to center along vector (A,B,C) normal to tower/module plane
923 vimpact.SetXYZ(vimpact(0)+dist*a/norm,vimpact(1)+dist*b/norm,vimpact(2)+dist*c/norm);
928 //_____________________________________________________________________________
929 Bool_t AliEMCALGeoUtils::IsInEMCAL(Double_t x, Double_t y, Double_t z) const {
930 // Checks whether point is inside the EMCal volume, used in AliEMCALv*.cxx
932 // Code uses cylindrical approximation made of inner radius (for speed)
934 // Points behind EMCAl, i.e. R > outer radius, but eta, phi in acceptance
935 // are considered to inside
937 Double_t r=sqrt(x*x+y*y);
939 if ( r > fEnvelop[0] ) {
941 theta = TMath::ATan2(r,z);
946 eta = -TMath::Log(TMath::Tan(theta/2.));
947 if (eta < fArm1EtaMin || eta > fArm1EtaMax)
950 Double_t phi = TMath::ATan2(y,x) * 180./TMath::Pi();
951 if (phi < 0) phi += 360; // phi should go from 0 to 360 in this case
952 if (phi > fArm1PhiMin && phi < fArm1PhiMax)
958 //________________________________________________________________________________________________
959 Int_t AliEMCALGeoUtils::GetAbsTRUNumberFromNumberInSm(const Int_t row, const Int_t col, const Int_t sm) const
961 // Get TRU absolute number from column, row and Super Module number
962 Int_t itru = row + col*fEMCGeometry->GetNModulesInTRUPhi() + sm*fEMCGeometry->GetNTRU();
963 // printf(" GetAbsTRUNumberFromNumberInSm : row %2i col %2i sm %2i -> itru %2i\n", row, col, sm, itru);
967 //________________________________________________________________________________________________
968 Bool_t AliEMCALGeoUtils::GetAbsFastORIndexFromTRU(const Int_t iTRU, const Int_t iADC, Int_t& id) const
970 //Trigger mapping method, get FastOr Index from TRU
972 if (iTRU > 31 || iTRU < 0 || iADC > 95 || iADC < 0)
974 AliError("TRU out of range!");
978 id = ( iTRU % 2 ) ? iADC%4 + 4 * (23 - int(iADC/4)) : (3 - iADC%4) + 4 * int(iADC/4);
985 //________________________________________________________________________________________________
986 Bool_t AliEMCALGeoUtils::GetTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iADC) const
989 //Trigger mapping method, get TRU number from FastOr Index
991 if (id > 3071 || id < 0)
993 AliError("Id out of range!");
1001 iADC = ( iTRU % 2 ) ? iADC%4 + 4 * (23 - int(iADC/4)) : (3 - iADC%4) + 4 * int(iADC/4);
1006 //________________________________________________________________________________________________
1007 Bool_t AliEMCALGeoUtils::GetPositionInTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iEta, Int_t& iPhi) const
1009 //Trigger mapping method, get position in TRU from FasOr Index
1012 if (!GetTRUFromAbsFastORIndex(id, iTRU, iADC)) return kFALSE;
1017 if ( iTRU % 2 ) // C side
1031 //________________________________________________________________________________________________
1032 Bool_t AliEMCALGeoUtils::GetPositionInSMFromAbsFastORIndex(const Int_t id, Int_t& iSM, Int_t& iEta, Int_t& iPhi) const
1034 //Trigger mapping method, get position in Super Module from FasOr Index
1038 if (!GetPositionInTRUFromAbsFastORIndex(id, iTRU, iEta, iPhi)) return kFALSE;
1040 if (iTRU % 2) // C side
1042 iSM = 2 * ( int( int(iTRU / 2) / 3 ) ) + 1;
1046 iSM = 2 * ( int( int(iTRU / 2) / 3 ) );
1049 iPhi += 4 * int((iTRU % 6) / 2);
1054 //________________________________________________________________________________________________
1055 Bool_t AliEMCALGeoUtils::GetPositionInEMCALFromAbsFastORIndex(const Int_t id, Int_t& iEta, Int_t& iPhi) const
1059 if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi))
1061 if (iSM % 2) iEta += 24;
1063 iPhi += 12 * int(iSM / 2);
1071 //________________________________________________________________________________________________
1072 Bool_t AliEMCALGeoUtils::GetAbsFastORIndexFromPositionInTRU(const Int_t iTRU, const Int_t iEta, const Int_t iPhi, Int_t& id) const
1074 //Trigger mapping method, get Index if FastOr from Position in TRU
1076 if (iTRU < 0 || iTRU > 31 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 3)
1078 AliError("Out of range!");
1082 id = iPhi + 4 * iEta + iTRU * 96;
1087 //________________________________________________________________________________________________
1088 Bool_t AliEMCALGeoUtils::GetAbsFastORIndexFromPositionInSM(const Int_t iSM, const Int_t iEta, const Int_t iPhi, Int_t& id) const
1091 if (iSM < 0 || iSM > 11 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 11)
1093 AliError("Out of range!");
1100 Int_t iOff = (iSM % 2) ? 1 : 0;
1101 Int_t iTRU = 2 * int(iPhi / 4) + 6 * int(iSM / 2) + iOff;
1103 if (GetAbsFastORIndexFromPositionInTRU(iTRU, x, y, id))
1111 //________________________________________________________________________________________________
1112 Bool_t AliEMCALGeoUtils::GetAbsFastORIndexFromPositionInEMCAL(const Int_t iEta, const Int_t iPhi, Int_t& id) const
1115 if (iEta < 0 || iEta > 47 || iPhi < 0 || iPhi > 63 )
1117 AliError("Out of range!");
1121 if (fFastOR2DMap[iEta][iPhi] == -1)
1123 AliError("Invalid index!");
1127 id = fFastOR2DMap[iEta][iPhi];
1132 //________________________________________________________________________________________________
1133 Bool_t AliEMCALGeoUtils::GetFastORIndexFromCellIndex(const Int_t id, Int_t& idx) const
1135 Int_t iSupMod, nModule, nIphi, nIeta, iphim, ietam;
1137 Bool_t isOK = GetCellIndex( id, iSupMod, nModule, nIphi, nIeta );
1139 GetModulePhiEtaIndexInSModule( iSupMod, nModule, iphim, ietam );
1141 if (isOK && GetAbsFastORIndexFromPositionInSM(iSupMod, ietam, iphim, idx))
1149 //________________________________________________________________________________________________
1150 Bool_t AliEMCALGeoUtils::GetCellIndexFromFastORIndex(const Int_t id, Int_t idx[4]) const
1152 Int_t iSM=-1, iEta=-1, iPhi=-1;
1153 if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi))
1155 Int_t ix = 2 * iEta;
1156 Int_t iy = 2 * iPhi;
1158 for (Int_t i=0; i<2; i++)
1160 for (Int_t j=0; j<2; j++)
1162 idx[2*i+j] = GetAbsCellIdFromCellIndexes(iSM, iy + i, ix + j);
1172 //________________________________________________________________________________________________
1173 Bool_t AliEMCALGeoUtils::GetTRUIndexFromSTUIndex(const Int_t id, Int_t& idx) const
1175 if (id > 31 || id < 0)
1177 AliError(Form("TRU index out of range: %d",id));
1181 idx = (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
1186 //________________________________________________________________________________________________
1187 Int_t AliEMCALGeoUtils::GetTRUIndexFromSTUIndex(const Int_t id) const
1189 if (id > 31 || id < 0)
1191 AliError(Form("TRU index out of range: %d",id));
1194 Int_t idx = (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
1199 //________________________________________________________________________________________________
1200 void AliEMCALGeoUtils::BuildFastOR2DMap()
1203 for (Int_t i = 0; i < 32; i++)
1205 for (Int_t j = 0; j < 24; j++)
1207 for (Int_t k = 0; k < 4; k++)
1210 if (GetAbsFastORIndexFromPositionInTRU(i, j, k, id))
1212 Int_t x = j, y = k + 4 * int(i / 2);
1216 fFastOR2DMap[x][y] = id;
1223 //________________________________________________________________________________________________
1224 Bool_t AliEMCALGeoUtils::GetFastORIndexFromL0Index(const Int_t iTRU, const Int_t id, Int_t idx[], const Int_t size) const
1226 if (size <= 0 ||size > 4)
1228 AliError("Size not supported!");
1232 Int_t motif[4] = {0, 1, 4, 5};
1236 case 1: // Cosmic trigger
1237 if (!GetAbsFastORIndexFromTRU(iTRU, id, idx[0])) return kFALSE;
1240 for (Int_t k = 0; k < 4; k++)
1242 Int_t iADC = motif[k] + 4 * int(id / 3) + (id % 3);
1244 if (!GetAbsFastORIndexFromTRU(iTRU, iADC, idx[k])) return kFALSE;
1254 //____________________________________________________________________________
1255 const TGeoHMatrix * AliEMCALGeoUtils::GetMatrixForSuperModule(Int_t smod) const {
1257 //Provides shift-rotation matrix for EMCAL
1259 if(smod < 0 || smod > fEMCGeometry->GetNumberOfSuperModules())
1260 AliFatal(Form("Wrong supermodule index -> %d",smod));
1262 //If GeoManager exists, take matrixes from it
1265 // if(fKey110DEG && ind>=10) {
1268 // if(!gGeoManager->cd(volpath.Data()))
1269 // AliFatal(Form("AliEMCALGeometry::GeoManager cannot find path %s!",volpath.Data()));
1271 // TGeoHMatrix* m = gGeoManager->GetCurrentMatrix();
1274 const Int_t buffersize = 255;
1275 char path[buffersize] ;
1276 snprintf(path,buffersize,"/ALIC_1/XEN1_1/SMOD_%d",smod+1) ;
1277 //TString volpath = "ALIC_1/XEN1_1/SMOD_";
1278 //volpath += smod+1;
1280 if(fKey110DEG && smod >= 10){
1281 snprintf(path,buffersize,"/ALIC_1/XEN1_1/SM10_%d",smod-10+1) ;
1282 //volpath = "ALIC_1/XEN1_1/SM10_";
1283 //volpath += smod-10+1;
1285 if (!gGeoManager->cd(path)){
1286 AliFatal(Form("Geo manager can not find path %s!\n",path));
1288 return gGeoManager->GetCurrentMatrix();
1291 if(fkSModuleMatrix[smod]){
1292 return fkSModuleMatrix[smod] ;
1296 printf("\t Can not find EMCAL misalignment matrixes\n") ;
1297 printf("\t Either import TGeoManager from geometry.root or \n");
1298 printf("\t read stored matrixes from AliESD Header: \n") ;
1299 printf("\t AliEMCALGeoUtils::SetMisalMatrixes(header->GetEMCALMisalMatrix()) \n") ;
1305 //______________________________________________________________________
1306 void AliEMCALGeoUtils::GetModulePhiEtaIndexInSModuleFromTRUIndex(Int_t itru, Int_t iphitru, Int_t ietatru, Int_t &iphiSM, Int_t &ietaSM) const
1309 // This method transforms the (eta,phi) index of module in a
1310 // TRU matrix into Super Module (eta,phi) index.
1312 // Calculate in which row and column where the TRU are
1313 // ordered in the SM
1315 Int_t col = itru/fEMCGeometry->GetNTRUPhi() ; // indexes of TRU in SM
1316 Int_t row = itru - col*fEMCGeometry->GetNTRUPhi();
1318 iphiSM = fEMCGeometry->GetNModulesInTRUPhi()*row + iphitru ;
1319 ietaSM = fEMCGeometry->GetNModulesInTRUEta()*col + ietatru ;
1320 //printf(" GetModulePhiEtaIndexInSModuleFromTRUIndex : itru %2i iphitru %2i ietatru %2i iphiSM %2i ietaSM %2i \n",
1321 // itru, iphitru, ietatru, iphiSM, ietaSM);
1324 //__________________________________________________________________________________________________________________
1325 void AliEMCALGeoUtils::RecalculateTowerPosition(Float_t drow, Float_t dcol, const Int_t sm, Float_t energy,
1326 const Int_t particle, const Float_t misaligTransShifts[15],
1327 const Float_t misaligRotShifts[15], Float_t global[3]) const
1328 { //Transform clusters cell position into global with alternative method, taking into account the depth calculation.
1329 //Input are: the tower indeces,
1331 // particle type (photon 0, electron 1, hadron 2 )
1332 // misalignment shifts to global position in case of need.
1333 // Federico.Ronchetti@cern.ch
1336 //Recover some stuff
1339 TGeoNodeMatrix *geoSM[4];
1340 TGeoVolume *geoSMVol[4];
1341 TGeoShape *geoSMShape[4];
1342 TGeoBBox *geoBox[4];
1343 TGeoMatrix *geoSMMatrix[4];
1345 gGeoManager->cd("ALIC_1/XEN1_1");
1346 geoXEn1 = gGeoManager->GetCurrentNode();
1347 for(int iSM = 0; iSM < 4; iSM++) {
1348 geoSM[iSM] = dynamic_cast<TGeoNodeMatrix *>(geoXEn1->GetDaughter(iSM));
1349 geoSMVol[iSM] = geoSM[iSM]->GetVolume();
1350 geoSMShape[iSM] = geoSMVol[iSM]->GetShape();
1351 geoBox[iSM] = dynamic_cast<TGeoBBox *>(geoSMShape[iSM]);
1352 geoSMMatrix[iSM] = geoSM[iSM]->GetMatrix();
1360 Int_t i = 0; // one always needs "i"
1367 Float_t x,y,z; // return variables in terry's RF
1369 //***********************************************************
1370 //Do not like this: too many hardcoded values, is it no stored somewhere else?
1371 // : need more comments in the code
1372 //***********************************************************
1374 Float_t dz = 6.0; // base cell width in eta
1375 Float_t dx = 6.004; // base cell width in phi
1377 // parameters for shower depth calculation
1382 //Float_t L = 26.04; // active tower length for hadron (lead+scint+paper)
1383 // we use the geant numbers 13.87*2=27.74
1388 if (dcol >= 47.5 || dcol<-0.5) {
1392 if (drow >= 23.5 || drow<-0.5) {
1395 if (sm > 13 || sm <0) {
1401 Float_t l = geoBox[i]->GetDX()*2 ;
1403 energy = energy * 1000; // converting to MEV
1408 cj = + 0.5; // photon
1409 d = x0 * TMath::Log( (energy / ecr) + cj);
1413 cj = - 0.5; // electron
1414 d = x0 * TMath::Log( (energy / ecr) + cj);
1423 cj = + 0.5; // photon
1424 d = x0 * TMath::Log( (energy / ecr) + cj);
1427 istrip = int ((dcol+0.5)/2);
1430 teta1 = TMath::DegToRad() * istrip * 1.5;
1432 // calculation of module corner along z
1433 // as a function of strip
1435 for (int is=0; is<= istrip; is++) {
1437 teta1 = TMath::DegToRad() * (is+1) * 1.5;
1438 z_is = z_is + 2*dz*(TMath::Sin(teta1)*TMath::Tan(teta1) + TMath::Cos(teta1));
1442 z0 = dz*(dcol-2*istrip+0.5);
1443 zb = (2*dz-z0-d*TMath::Tan(teta1));
1445 z = z_is - zb*TMath::Cos(teta1);
1446 y = d/TMath::Cos(teta1) + zb*TMath::Sin(teta1);
1448 x = (drow + 0.5)*dx;
1450 // moving the origin from terry's RF
1453 double xx = y - geoBox[i]->GetDX();
1454 double yy = -x + geoBox[i]->GetDY() - 0.512; //to center the towers in the box
1455 double zz = z - geoBox[i]->GetDZ() + 1; //gap at z = 0
1457 const double localIn[3] = {xx, yy, zz};
1459 geoSMMatrix[i]->LocalToMaster(localIn, dglobal);
1462 //hardcoded global shifts
1463 if(sm == 2 || sm == 3) {//sector 1
1464 global[0] = dglobal[0] + misaligTransShifts[3] + misaligRotShifts[3]*TMath::Sin(TMath::DegToRad()*20) ;
1465 global[1] = dglobal[1] + misaligTransShifts[4] + misaligRotShifts[4]*TMath::Cos(TMath::DegToRad()*20) ;
1466 global[2] = dglobal[2] + misaligTransShifts[5];
1468 else if(sm == 0 || sm == 1){//sector 0
1469 global[0] = dglobal[0] + misaligTransShifts[0];
1470 global[1] = dglobal[1] + misaligTransShifts[1];
1471 global[2] = dglobal[2] + misaligTransShifts[2];
1474 AliInfo("Careful, correction not implemented yet!");
1475 global[0] = dglobal[0] ;
1476 global[1] = dglobal[1] ;
1477 global[2] = dglobal[2] ;
1483 AliFatal("Geometry boxes information, check that geometry.root is loaded\n");