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>
48 // --- Standard library ---
49 //#include <Riostream.h>
51 // --- AliRoot header files ---
52 #include "AliEMCALGeoUtils.h"
53 #include "AliEMCALShishKebabTrd1Module.h"
55 ClassImp(AliEMCALGeoUtils)
57 //____________________________________________________________________________
58 AliEMCALGeoUtils::AliEMCALGeoUtils():
59 fEMCGeometry(0x0),fGeoName(0),
60 fKey110DEG(0),fNCellsInSupMod(0),fNETAdiv(0),fNPHIdiv(0),
61 fNCellsInModule(0),fPhiBoundariesOfSM(0x0),fPhiCentersOfSM(0x0),
62 fPhiCentersOfCells(0x0),fCentersOfCellsEtaDir(0x0),
63 fCentersOfCellsPhiDir(0x0),fEtaCentersOfCells(0x0),
64 fNCells(0),fNPhi(0),fCentersOfCellsXDir(0x0),fArm1EtaMin(0),
65 fArm1EtaMax(0),fArm1PhiMin(0),fArm1PhiMax(0),fEtaMaxOfTRD1(0),
66 fShishKebabTrd1Modules(0),fParSM(0x0),fPhiModuleSize(0.),
67 fEtaModuleSize(0.),fPhiTileSize(0.),fEtaTileSize(0.),fNZ(0),
68 fIPDistance(0.),fLongModuleSize(0.),fShellThickness(0.),
69 fZLength(0.),fSampling(0.)
72 // must be kept public for root persistency purposes, but should never be called by the outside world
79 //____________________________________________________________________________
80 AliEMCALGeoUtils::AliEMCALGeoUtils(const AliEMCALGeoUtils & geo)
82 fEMCGeometry(geo.fEMCGeometry),fGeoName(geo.fGeoName),
83 fKey110DEG(geo.fKey110DEG),fNCellsInSupMod(geo.fNCellsInSupMod),fNETAdiv(geo.fNETAdiv),fNPHIdiv(geo.fNPHIdiv),
84 fNCellsInModule(geo.fNCellsInModule),fPhiBoundariesOfSM(geo.fPhiBoundariesOfSM),fPhiCentersOfSM(geo.fPhiCentersOfSM),
85 fPhiCentersOfCells(geo.fPhiCentersOfCells),fCentersOfCellsEtaDir(geo.fCentersOfCellsEtaDir),
86 fCentersOfCellsPhiDir(geo.fCentersOfCellsPhiDir),fEtaCentersOfCells(geo.fEtaCentersOfCells),
87 fNCells(geo.fNCells),fNPhi(geo.fNPhi),fCentersOfCellsXDir(geo.fCentersOfCellsXDir),fArm1EtaMin(geo.fArm1EtaMin),
88 fArm1EtaMax(geo.fArm1EtaMax),fArm1PhiMin(geo.fArm1PhiMin),fArm1PhiMax(geo.fArm1PhiMax),fEtaMaxOfTRD1(geo.fEtaMaxOfTRD1),
89 fShishKebabTrd1Modules(geo.fShishKebabTrd1Modules),fParSM(geo.fParSM),fPhiModuleSize(geo.fPhiModuleSize),
90 fEtaModuleSize(geo.fEtaModuleSize),fPhiTileSize(geo.fPhiTileSize),fEtaTileSize(geo.fEtaTileSize),fNZ(geo.fNZ),
91 fIPDistance(geo.fIPDistance),fLongModuleSize(geo.fLongModuleSize),fShellThickness(geo.fShellThickness),
92 fZLength(geo.fZLength),fSampling(geo.fSampling)
94 fEnvelop[0] = geo.fEnvelop[0];
95 fEnvelop[1] = geo.fEnvelop[1];
96 fEnvelop[2] = geo.fEnvelop[2];
99 //____________________________________________________________________________
100 AliEMCALGeoUtils::AliEMCALGeoUtils(const Text_t* name, const Text_t* title)
101 : TNamed(name, title),
102 fEMCGeometry(0x0),fGeoName(0),
103 fKey110DEG(0),fNCellsInSupMod(0),fNETAdiv(0),fNPHIdiv(0),
104 fNCellsInModule(0),fPhiBoundariesOfSM(0x0),fPhiCentersOfSM(0x0),
105 fPhiCentersOfCells(0x0),fCentersOfCellsEtaDir(0x0),
106 fCentersOfCellsPhiDir(0x0),fEtaCentersOfCells(0x0),
107 fNCells(0),fNPhi(0),fCentersOfCellsXDir(0x0),fArm1EtaMin(0),
108 fArm1EtaMax(0),fArm1PhiMin(0),fArm1PhiMax(0),fEtaMaxOfTRD1(0),
109 fShishKebabTrd1Modules(0),fParSM(0x0),fPhiModuleSize(0.),
110 fEtaModuleSize(0.),fPhiTileSize(0.),fEtaTileSize(0.),fNZ(0),
111 fIPDistance(0.),fLongModuleSize(0.),fShellThickness(0.),
112 fZLength(0.),fSampling(0.)
115 // ctor only for normal usage
117 fEMCGeometry = new AliEMCALEMCGeometry(name,title);
119 fGeoName = fEMCGeometry->GetGeoName();
120 fKey110DEG = fEMCGeometry->GetKey110DEG();
121 fNCellsInSupMod = fEMCGeometry->GetNCellsInSupMod();
122 fNETAdiv = fEMCGeometry->GetNETAdiv();
123 fNPHIdiv = fEMCGeometry->GetNPHIdiv();
124 fNCellsInModule = fNPHIdiv*fNETAdiv;
126 Int_t nSMod = fEMCGeometry->GetNumberOfSuperModules();
127 fPhiBoundariesOfSM.Set(nSMod);
128 fPhiCentersOfSM.Set(nSMod/2);
129 for(Int_t sm=0; sm<nSMod; sm++) {
131 fEMCGeometry->GetPhiBoundariesOfSM(sm,fPhiBoundariesOfSM[2*i],fPhiBoundariesOfSM[2*i+1]);
134 Double_t phiMin = 0.;
135 Double_t phiMax = 0.;
136 for(Int_t sm=0; sm<nSMod; sm++) {
137 fEMCGeometry->GetPhiBoundariesOfSM(sm,phiMin,phiMax);
139 fPhiCentersOfSM[i] = fEMCGeometry->GetPhiCenterOfSM(sm);
141 fNCells = fEMCGeometry->GetNCells();
142 fNPhi = fEMCGeometry->GetNPhi();
143 fEnvelop[0] = fEMCGeometry->GetEnvelop(0);
144 fEnvelop[1] = fEMCGeometry->GetEnvelop(1);
145 fEnvelop[2] = fEMCGeometry->GetEnvelop(2);
146 fArm1EtaMin = fEMCGeometry->GetArm1EtaMin();
147 fArm1EtaMax = fEMCGeometry->GetArm1EtaMax();
148 fArm1PhiMin = fEMCGeometry->GetArm1PhiMin();
149 fArm1PhiMax = fEMCGeometry->GetArm1PhiMax();
150 fShellThickness = fEMCGeometry->GetShellThickness();
151 fZLength = fEMCGeometry->GetZLength();
152 fSampling = fEMCGeometry->GetSampling();
153 fParSM = fEMCGeometry->GetSuperModulesPars();
154 fEtaModuleSize = fEMCGeometry->GetEtaModuleSize();
155 fPhiModuleSize = fEMCGeometry->GetPhiModuleSize();
156 fEtaTileSize = fEMCGeometry->GetEtaTileSize();
157 fPhiTileSize = fEMCGeometry->GetPhiTileSize();
158 fNZ = fEMCGeometry->GetNZ();
159 fIPDistance = fEMCGeometry->GetIPDistance();
160 fLongModuleSize = fEMCGeometry->GetLongModuleSize();
162 CreateListOfTrd1Modules();
164 for(Int_t smod=0; smod < fEMCGeometry->GetNumberOfSuperModules(); smod++)
165 fkSModuleMatrix[smod]=0 ;
167 if (AliDebugLevel()>=2) {
168 fEMCGeometry->Print();
174 //____________________________________________________________________________
175 AliEMCALGeoUtils & AliEMCALGeoUtils::operator = (const AliEMCALGeoUtils & /*rvalue*/) {
177 Fatal("assignment operator", "not implemented") ;
181 //____________________________________________________________________________
182 AliEMCALGeoUtils::~AliEMCALGeoUtils(void)
186 delete fEMCGeometry; fEMCGeometry = 0 ;
191 //________________________________________________________________________________________________
192 void AliEMCALGeoUtils::Browse(TBrowser* b)
195 if(fShishKebabTrd1Modules) b->Add(fShishKebabTrd1Modules);
198 //________________________________________________________________________________________________
199 Bool_t AliEMCALGeoUtils::IsFolder() const
201 //Check if fShishKebabTrd1Modules is in folder
202 if(fShishKebabTrd1Modules) return kTRUE;
206 //________________________________________________________________________________________________
207 void AliEMCALGeoUtils::GetGlobal(const Double_t *loc, Double_t *glob, int ind) const
209 // Figure out the global numbering
210 // of a given supermodule from the
211 // local numbering and the transformation
212 // matrix stored by the geometry manager (allows for misaligned
215 const TGeoHMatrix* m = GetMatrixForSuperModule(ind);
217 m->LocalToMaster(loc, glob);
219 AliFatal("Geo matrixes are not loaded \n") ;
223 //________________________________________________________________________________________________
224 void AliEMCALGeoUtils::GetGlobal(const TVector3 &vloc, TVector3 &vglob, int ind) const
226 //Figure out the global numbering
227 //of a given supermodule from the
228 //local numbering given a 3-vector location
230 static Double_t tglob[3], tloc[3];
232 GetGlobal(tloc, tglob, ind);
233 vglob.SetXYZ(tglob[0], tglob[1], tglob[2]);
236 //________________________________________________________________________________________________
237 void AliEMCALGeoUtils::GetGlobal(Int_t absId , double glob[3]) const
239 // Alice numbering scheme - Jun 03, 2006
240 static Int_t nSupMod, nModule, nIphi, nIeta;
241 static double loc[3];
243 glob[0]=glob[1]=glob[2]=0.0; // bad case
244 if(RelPosCellInSModule(absId, loc)) {
245 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
247 const TGeoHMatrix* m = GetMatrixForSuperModule(nSupMod);
249 m->LocalToMaster(loc, glob);
251 AliFatal("Geo matrixes are not loaded \n") ;
256 //___________________________________________________________________
257 void AliEMCALGeoUtils::GetGlobal(Int_t absId , TVector3 &vglob) const
259 // Alice numbering scheme - Jun 03, 2006
260 static Double_t glob[3];
262 GetGlobal(absId, glob);
263 vglob.SetXYZ(glob[0], glob[1], glob[2]);
268 //______________________________________________________________________
269 void AliEMCALGeoUtils::PrintCellIndexes(Int_t absId, int pri, const char *tit) const
272 Int_t nSupMod, nModule, nIphi, nIeta;
276 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
277 printf(" %s | absId : %i -> nSupMod %i nModule %i nIphi %i nIeta %i \n", tit, absId, nSupMod, nModule, nIphi, nIeta);
279 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
280 printf(" local SM index : iphi %i : ieta %i \n", iphi,ieta);
281 GetGlobal(absId, vg);
282 printf(" vglob : mag %7.2f : perp %7.2f : z %7.2f : eta %6.4f : phi %6.4f(%6.2f) \n",
283 vg.Mag(), vg.Perp(), vg.Z(), vg.Eta(), vg.Phi(), vg.Phi()*TMath::RadToDeg());
287 //________________________________________________________________________________________________
288 void AliEMCALGeoUtils::EtaPhiFromIndex(Int_t absId,Double_t &eta,Double_t &phi) const
290 // Nov 16, 2006- float to double
291 // version for TRD1 only
292 static TVector3 vglob;
293 GetGlobal(absId, vglob);
298 //________________________________________________________________________________________________
299 void AliEMCALGeoUtils::EtaPhiFromIndex(Int_t absId,Float_t &eta,Float_t &phi) const
301 // Nov 16,2006 - should be discard in future
302 static TVector3 vglob;
303 GetGlobal(absId, vglob);
304 eta = float(vglob.Eta());
305 phi = float(vglob.Phi());
309 // == Shish-kebab cases ==
311 //________________________________________________________________________________________________
312 Int_t AliEMCALGeoUtils::GetAbsCellId(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta) const
316 // 13-oct-05; 110 degree case
317 // May 31, 2006; ALICE numbering scheme:
318 // 0 <= nSupMod < fNumberOfSuperModules
319 // 0 <= nModule < fNPHI * fNZ ( fNPHI * fNZ/2 for fKey110DEG=1)
320 // 0 <= nIphi < fNPHIdiv
321 // 0 <= nIeta < fNETAdiv
322 // 0 <= absid < fNCells
323 static Int_t id=0; // have to change from 0 to fNCells-1
324 if(fKey110DEG == 1 && nSupMod >= 10) { // 110 degree case; last two supermodules
325 id = fNCellsInSupMod*10 + (fNCellsInSupMod/2)*(nSupMod-10);
327 id = fNCellsInSupMod*nSupMod;
329 id += fNCellsInModule *nModule;
330 id += fNPHIdiv *nIphi;
332 if(id<0 || id >= fNCells) {
333 // printf(" wrong numerations !!\n");
334 // printf(" id %6i(will be force to -1)\n", id);
335 // printf(" fNCells %6i\n", fNCells);
336 // printf(" nSupMod %6i\n", nSupMod);
337 // printf(" nModule %6i\n", nModule);
338 // printf(" nIphi %6i\n", nIphi);
339 // printf(" nIeta %6i\n", nIeta);
340 id = -TMath::Abs(id); // if negative something wrong
345 //________________________________________________________________________________________________
346 void AliEMCALGeoUtils::GetModuleIndexesFromCellIndexesInSModule(Int_t nSupMod, Int_t iphi, Int_t ieta,
347 Int_t &iphim, Int_t &ietam, Int_t &nModule) const
349 // Transition from cell indexes (ieta,iphi) to module indexes (ietam,iphim, nModule)
351 nphi = GetNumberOfModuleInPhiDirection(nSupMod);
353 ietam = ieta/fNETAdiv;
354 iphim = iphi/fNPHIdiv;
355 nModule = ietam * nphi + iphim;
358 //________________________________________________________________________________________________
359 Int_t AliEMCALGeoUtils::GetAbsCellIdFromCellIndexes(Int_t nSupMod, Int_t iphi, Int_t ieta) const
361 // Transition from super module number(nSupMod) and cell indexes (ieta,iphi) to absId
362 static Int_t ietam, iphim, nModule;
363 static Int_t nIeta, nIphi; // cell indexes in module
365 GetModuleIndexesFromCellIndexesInSModule(nSupMod, iphi, ieta, ietam, iphim, nModule);
367 nIeta = ieta%fNETAdiv;
368 nIeta = fNETAdiv - 1 - nIeta;
369 nIphi = iphi%fNPHIdiv;
371 return GetAbsCellId(nSupMod, nModule, nIphi, nIeta);
374 //________________________________________________________________________________________________
375 Bool_t AliEMCALGeoUtils::SuperModuleNumberFromEtaPhi(Double_t eta, Double_t phi, Int_t &nSupMod) const
377 // Return false if phi belongs a phi cracks between SM
381 if(TMath::Abs(eta) > fEtaMaxOfTRD1) return kFALSE;
383 phi = TVector2::Phi_0_2pi(phi); // move phi to (0,2pi) boundaries
386 //Check if it is not the complete geometry
387 if (i >= fEMCGeometry->GetNumberOfSuperModules()/2) return kFALSE;
389 if(phi>=fPhiBoundariesOfSM[2*i] && phi<=fPhiBoundariesOfSM[2*i+1]) {
391 if(eta < 0.0) nSupMod++;
392 AliDebug(1,Form("eta %f phi %f(%5.2f) : nSupMod %i : #bound %i", eta,phi,phi*TMath::RadToDeg(), nSupMod,i));
400 //________________________________________________________________________________________________
401 Bool_t AliEMCALGeoUtils::GetAbsCellIdFromEtaPhi(Double_t eta, Double_t phi, Int_t &absId) const
404 // stay here - phi problem as usual
405 static Int_t nSupMod, i, ieta, iphi, etaShift, nphi;
406 static Double_t absEta=0.0, d=0.0, dmin=0.0, phiLoc;
407 absId = nSupMod = - 1;
408 if(SuperModuleNumberFromEtaPhi(eta, phi, nSupMod)) {
410 phi = TVector2::Phi_0_2pi(phi);
411 phiLoc = phi - fPhiCentersOfSM[nSupMod/2];
412 nphi = fPhiCentersOfCells.GetSize();
414 phiLoc = phi - 190.*TMath::DegToRad();
418 dmin = TMath::Abs(fPhiCentersOfCells[0]-phiLoc);
420 for(i=1; i<nphi; i++) {
421 d = TMath::Abs(fPhiCentersOfCells[i] - phiLoc);
426 // printf(" i %i : d %f : dmin %f : fPhiCentersOfCells[i] %f \n", i, d, dmin, fPhiCentersOfCells[i]);
428 // odd SM are turned with respect of even SM - reverse indexes
429 AliDebug(2,Form(" iphi %i : dmin %f (phi %f, phiLoc %f ) ", iphi, dmin, phi, phiLoc));
431 absEta = TMath::Abs(eta);
432 etaShift = iphi*fCentersOfCellsEtaDir.GetSize();
433 dmin = TMath::Abs(fEtaCentersOfCells[etaShift]-absEta);
435 for(i=1; i<fCentersOfCellsEtaDir.GetSize(); i++) {
436 d = TMath::Abs(fEtaCentersOfCells[i+etaShift] - absEta);
442 AliDebug(2,Form(" ieta %i : dmin %f (eta=%f) : nSupMod %i ", ieta, dmin, eta, nSupMod));
444 if(eta<0) iphi = (nphi-1) - iphi;
446 //patch for mapping following alice convention
448 ieta = (fCentersOfCellsEtaDir.GetSize()-1)-ieta;// 47-ieta, revert the ordering on A side in order to keep convention.
451 iphi = (fCentersOfCellsPhiDir.GetSize()-1) -iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
453 iphi = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
456 absId = GetAbsCellIdFromCellIndexes(nSupMod, iphi, ieta);
463 //________________________________________________________________________________________________
464 Bool_t AliEMCALGeoUtils::CheckAbsCellId(Int_t absId) const
466 // May 31, 2006; only trd1 now
467 if(absId<0 || absId >= fNCells) return kFALSE;
471 //________________________________________________________________________________________________
472 Bool_t AliEMCALGeoUtils::GetCellIndex(Int_t absId,Int_t &nSupMod,Int_t &nModule,Int_t &nIphi,Int_t &nIeta) const
474 // 21-sep-04; 19-oct-05;
475 // May 31, 2006; ALICE numbering scheme:
478 // absId - cell is as in Geant, 0<= absId < fNCells;
480 // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
481 // nModule - module number in SM, 0<= nModule < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
482 // nIphi - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv;
483 // nIeta - cell number in eta driection inside module; 0<= nIeta < fNETAdiv;
485 static Int_t tmp=0, sm10=0;
486 if(!CheckAbsCellId(absId)) return kFALSE;
488 sm10 = fNCellsInSupMod*10;
489 if(fKey110DEG == 1 && absId >= sm10) { // 110 degree case; last two supermodules
490 nSupMod = (absId-sm10) / (fNCellsInSupMod/2) + 10;
491 tmp = (absId-sm10) % (fNCellsInSupMod/2);
493 nSupMod = absId / fNCellsInSupMod;
494 tmp = absId % fNCellsInSupMod;
497 nModule = tmp / fNCellsInModule;
498 tmp = tmp % fNCellsInModule;
499 nIphi = tmp / fNPHIdiv;
500 nIeta = tmp % fNPHIdiv;
505 //________________________________________________________________________________________________
506 Int_t AliEMCALGeoUtils::GetSuperModuleNumber(Int_t absId) const
508 // Return the number of the supermodule given the absolute
509 // ALICE numbering id
511 static Int_t nSupMod, nModule, nIphi, nIeta;
512 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
516 //________________________________________________________________________________________________
517 void AliEMCALGeoUtils::GetModulePhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, int &iphim, int &ietam) const
519 // added nSupMod; - 19-oct-05 !
520 // Alice numbering scheme - Jun 01,2006
521 // ietam, iphi - indexes of module in two dimensional grid of SM
522 // ietam - have to change from 0 to fNZ-1
523 // iphim - have to change from 0 to nphi-1 (fNPhi-1 or fNPhi/2-1)
526 if(fKey110DEG == 1 && nSupMod>=10) nphi = fNPhi/2;
529 ietam = nModule/nphi;
530 iphim = nModule%nphi;
533 //________________________________________________________________________________________________
534 void AliEMCALGeoUtils::GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta,
535 int &iphi, int &ieta) const
538 // Added nSupMod; Nov 25, 05
539 // Alice numbering scheme - Jun 01,2006
541 // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
542 // nModule - module number in SM, 0<= nModule < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
543 // nIphi - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv;
544 // nIeta - cell number in eta driection inside module; 0<= nIeta < fNETAdiv;
547 // ieta, iphi - indexes of cell(tower) in two dimensional grid of SM
548 // ieta - have to change from 0 to (fNZ*fNETAdiv-1)
549 // iphi - have to change from 0 to (fNPhi*fNPHIdiv-1 or fNPhi*fNPHIdiv/2-1)
551 static Int_t iphim, ietam;
553 GetModulePhiEtaIndexInSModule(nSupMod,nModule, iphim, ietam);
554 // ieta = ietam*fNETAdiv + (1-nIeta); // x(module) = -z(SM)
555 ieta = ietam*fNETAdiv + (fNETAdiv - 1 - nIeta); // x(module) = -z(SM)
556 iphi = iphim*fNPHIdiv + nIphi; // y(module) = y(SM)
559 AliDebug(1,Form(" nSupMod %i nModule %i nIphi %i nIeta %i => ieta %i iphi %i\n",
560 nSupMod, nModule, nIphi, nIeta, ieta, iphi));
564 // Methods for AliEMCALRecPoint - Feb 19, 2006
565 //________________________________________________________________________________________________
566 Bool_t AliEMCALGeoUtils::RelPosCellInSModule(Int_t absId, Double_t &xr, Double_t &yr, Double_t &zr) const
568 // Look to see what the relative
569 // position inside a given cell is
571 // Alice numbering scheme - Jun 08, 2006
573 // absId - cell is as in Geant, 0<= absId < fNCells;
575 // xr,yr,zr - x,y,z coordinates of cell with absId inside SM
577 // Shift index taking into account the difference between standard SM
578 // and SM of half size in phi direction
579 const Int_t kphiIndexShift = fCentersOfCellsPhiDir.GetSize()/4; // Nov 22, 2006; was 6 for cas 2X2
580 static Int_t nSupMod, nModule, nIphi, nIeta, iphi, ieta;
581 if(!CheckAbsCellId(absId)) return kFALSE;
583 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
584 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi, ieta);
586 //Get eta position. Careful with ALICE conventions (increase index decrease eta)
589 ieta2 = (fCentersOfCellsEtaDir.GetSize()-1)-ieta;// 47-ieta, revert the ordering on A side in order to keep convention.
590 zr = fCentersOfCellsEtaDir.At(ieta2);
591 xr = fCentersOfCellsXDir.At(ieta2);
593 //Get phi position. Careful with ALICE conventions (increase index increase phi)
597 iphi2 = (fCentersOfCellsPhiDir.GetSize()-1)-iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
598 yr = fCentersOfCellsPhiDir.At(iphi2);
602 iphi2 = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
603 yr = fCentersOfCellsPhiDir.At(iphi2 + kphiIndexShift);
605 AliDebug(1,Form("absId %i nSupMod %i iphi %i ieta %i xr %f yr %f zr %f ",absId,nSupMod,iphi,ieta,xr,yr,zr));
610 //________________________________________________________________________________________________
611 Bool_t AliEMCALGeoUtils::RelPosCellInSModule(Int_t absId, Double_t loc[3]) const
613 // Look to see what the relative
614 // position inside a given cell is
615 // for a recpoint. // Alice numbering scheme - Jun 03, 2006
616 loc[0] = loc[1] = loc[2]=0.0;
617 if(RelPosCellInSModule(absId, loc[0],loc[1],loc[2])) {
623 //________________________________________________________________________________________________
624 Bool_t AliEMCALGeoUtils::RelPosCellInSModule(Int_t absId, TVector3 &vloc) const
626 // Look to see what the relative
627 // position inside a given cell is
629 // Alice numbering scheme - Jun 03, 2006
630 static Double_t loc[3];
631 if(RelPosCellInSModule(absId,loc)) {
632 vloc.SetXYZ(loc[0], loc[1], loc[2]);
640 //________________________________________________________________________________________________
641 void AliEMCALGeoUtils::CreateListOfTrd1Modules()
643 // Generate the list of Trd1 modules
644 // which will make up the EMCAL
647 AliDebug(2,Form(" AliEMCALGeometry::CreateListOfTrd1Modules() started "));
649 AliEMCALShishKebabTrd1Module *mod=0, *mTmp=0; // current module
650 if(fShishKebabTrd1Modules == 0) {
651 fShishKebabTrd1Modules = new TList;
652 fShishKebabTrd1Modules->SetName("ListOfTRD1");
653 for(int iz=0; iz< fEMCGeometry->GetNZ(); iz++) {
655 // mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,this);
656 mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,fEMCGeometry);
658 mTmp = new AliEMCALShishKebabTrd1Module(*mod);
661 fShishKebabTrd1Modules->Add(mod);
664 AliDebug(2,Form(" Already exits : "));
666 mod = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(fShishKebabTrd1Modules->GetSize()-1);
667 fEtaMaxOfTRD1 = mod->GetMaxEtaOfModule(0);
669 AliDebug(2,Form(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
670 fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1));
672 // Jun 01, 2006 - ALICE numbering scheme
673 // define grid for cells in eta(z) and x directions in local coordinates system of SM
674 // Works just for 2x2 case only -- ?? start here
677 // Define grid for cells in phi(y) direction in local coordinates system of SM
678 // as for 2X2 as for 3X3 - Nov 8,2006
680 AliDebug(2,Form(" Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize()));
681 Int_t ind=0; // this is phi index
682 Int_t ieta=0, nModule=0, iphiTemp;
683 Double_t xr=0., zr=0., theta=0., phi=0., eta=0., r=0., x=0.,y=0.;
685 Double_t ytCenterModule=0.0, ytCenterCell=0.0;
687 fCentersOfCellsPhiDir.Set(fNPhi*fNPHIdiv);
688 fPhiCentersOfCells.Set(fNPhi*fNPHIdiv);
690 Double_t r0 = fIPDistance + fLongModuleSize/2.;
691 for(Int_t it=0; it<fNPhi; it++) { // cycle on modules
692 ytCenterModule = -fParSM[1] + fPhiModuleSize*(2*it+1)/2; // center of module
693 for(Int_t ic=0; ic<fNPHIdiv; ic++) { // cycle on cells in module
695 ytCenterCell = ytCenterModule + fPhiTileSize *(2*ic-1)/2.;
696 } else if(fNPHIdiv==3){
697 ytCenterCell = ytCenterModule + fPhiTileSize *(ic-1);
698 } else if(fNPHIdiv==1){
699 ytCenterCell = ytCenterModule;
701 fCentersOfCellsPhiDir.AddAt(ytCenterCell,ind);
702 // Define grid on phi direction
703 // Grid is not the same for different eta bin;
704 // Effect is small but is still here
705 phi = TMath::ATan2(ytCenterCell, r0);
706 fPhiCentersOfCells.AddAt(phi, ind);
708 AliDebug(2,Form(" ind %2.2i : y %8.3f ", ind, fCentersOfCellsPhiDir.At(ind)));
713 fCentersOfCellsEtaDir.Set(fNZ *fNETAdiv);
714 fCentersOfCellsXDir.Set(fNZ *fNETAdiv);
715 fEtaCentersOfCells.Set(fNZ *fNETAdiv * fNPhi*fNPHIdiv);
716 AliDebug(2,Form(" Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize()));
717 for(Int_t it=0; it<fNZ; it++) {
718 AliEMCALShishKebabTrd1Module *trd1 = GetShishKebabModule(it);
720 for(Int_t ic=0; ic<fNETAdiv; ic++) {
722 trd1->GetCenterOfCellInLocalCoordinateofSM(ic, xr, zr); // case of 2X2
723 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
725 trd1->GetCenterOfCellInLocalCoordinateofSM3X3(ic, xr, zr); // case of 3X3
726 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
728 trd1->GetCenterOfCellInLocalCoordinateofSM1X1(xr, zr); // case of 1X1
729 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
731 fCentersOfCellsXDir.AddAt(float(xr) - fParSM[0],ieta);
732 fCentersOfCellsEtaDir.AddAt(float(zr) - fParSM[2],ieta);
733 // Define grid on eta direction for each bin in phi
734 for(int iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
735 x = xr + trd1->GetRadius();
736 y = fCentersOfCellsPhiDir[iphi];
737 r = TMath::Sqrt(x*x + y*y + zr*zr);
738 theta = TMath::ACos(zr/r);
739 eta = AliEMCALShishKebabTrd1Module::ThetaToEta(theta);
740 // ind = ieta*fCentersOfCellsPhiDir.GetSize() + iphi;
741 ind = iphi*fCentersOfCellsEtaDir.GetSize() + ieta;
742 fEtaCentersOfCells.AddAt(eta, ind);
744 //printf(" ieta %i : xr + trd1->GetRadius() %f : zr %f : eta %f \n", ieta, xr + trd1->GetRadius(), zr, eta);
747 for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
748 AliDebug(2,Form(" ind %2.2i : z %8.3f : x %8.3f", i+1,
749 fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i)));
755 //________________________________________________________________________________________________
756 AliEMCALShishKebabTrd1Module* AliEMCALGeoUtils::GetShishKebabModule(Int_t neta) const
758 //This method was too long to be
759 //included in the header file - the
760 //rule checker complained about it's
761 //length, so we move it here. It returns the
762 //shishkebabmodule at a given eta index point.
764 static AliEMCALShishKebabTrd1Module* trd1=0;
765 if(fShishKebabTrd1Modules && neta>=0 && neta<fShishKebabTrd1Modules->GetSize()) {
766 trd1 = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(neta);
771 //___________________________________________________________________
772 void AliEMCALGeoUtils::PrintGeometry()
774 //Print information from geometry
775 fEMCGeometry->PrintGeometry();
777 printf(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
778 fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1);
780 printf("\n Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize());
781 for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
782 printf(" ind %2.2i : z %8.3f : x %8.3f \n", i,
783 fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i));
784 int ind=0; // Nov 21,2006
785 for(Int_t iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
786 ind = iphi*fCentersOfCellsEtaDir.GetSize() + i;
787 printf("%6.4f ", fEtaCentersOfCells[ind]);
788 if((iphi+1)%12 == 0) printf("\n");
794 printf("\n Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize());
795 for(Int_t i=0; i<fCentersOfCellsPhiDir.GetSize(); i++) {
796 double phi=fPhiCentersOfCells.At(i);
797 printf(" ind %2.2i : y %8.3f : phi %7.5f(%6.2f) \n", i, fCentersOfCellsPhiDir.At(i),
798 phi, phi*TMath::RadToDeg());
803 //____________________________________________________________________________
804 Bool_t AliEMCALGeoUtils::Impact(const TParticle * particle) const
806 // Tells if a particle enters EMCAL
809 TVector3 vtx(particle->Vx(),particle->Vy(),particle->Vz());
810 TVector3 vimpact(0,0,0);
811 ImpactOnEmcal(vtx,particle->Theta(),particle->Phi(),absID,vimpact);
816 //____________________________________________________________________________
817 void AliEMCALGeoUtils::ImpactOnEmcal(TVector3 vtx, Double_t theta, Double_t phi,
818 Int_t & absId, TVector3 & vimpact) const
820 // calculates the impact coordinates on EMCAL (centre of a tower/not on EMCAL surface)
821 // of a neutral particle
822 // emitted in the vertex vtx[3] with direction theta and phi in the ALICE global coordinate system
824 TVector3 p(TMath::Sin(theta)*TMath::Cos(phi),TMath::Sin(theta)*TMath::Sin(phi),TMath::Cos(theta)) ;
826 vimpact.SetXYZ(0,0,0);
828 if(phi==0 || theta==0) return;
831 Double_t factor = (fIPDistance-vtx[1])/p[1];
832 direction = vtx + factor*p;
834 //from particle direction -> tower hitted
835 GetAbsCellIdFromEtaPhi(direction.Eta(),direction.Phi(),absId);
837 //tower absID hitted -> tower/module plane (evaluated at the center of the tower)
838 Int_t nSupMod, nModule, nIphi, nIeta;
839 Double_t loc[3],loc2[3],loc3[3];
840 Double_t glob[3]={},glob2[3]={},glob3[3]={};
842 if(!RelPosCellInSModule(absId,loc)) return;
844 //loc is cell center of tower
845 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
847 //look at 2 neighbours-s cell using nIphi={0,1} and nIeta={0,1}
848 Int_t nIphi2,nIeta2,absId2,absId3;
849 if(nIeta==0) nIeta2=1;
851 absId2=GetAbsCellId(nSupMod,nModule,nIphi,nIeta2);
852 if(nIphi==0) nIphi2=1;
854 absId3=GetAbsCellId(nSupMod,nModule,nIphi2,nIeta);
856 //2nd point on emcal cell plane
857 if(!RelPosCellInSModule(absId2,loc2)) return;
859 //3rd point on emcal cell plane
860 if(!RelPosCellInSModule(absId3,loc3)) return;
863 const TGeoHMatrix* m = GetMatrixForSuperModule(nSupMod);
865 m->LocalToMaster(loc, glob);
866 m->LocalToMaster(loc2, glob2);
867 m->LocalToMaster(loc3, glob3);
869 AliFatal("Geo matrixes are not loaded \n") ;
872 //Equation of Plane from glob,glob2,glob3 (Ax+By+Cz+D=0)
873 Double_t a = glob[1]*(glob2[2]-glob3[2]) + glob2[1]*(glob3[2]-glob[2]) + glob3[1]*(glob[2]-glob2[2]);
874 Double_t b = glob[2]*(glob2[0]-glob3[0]) + glob2[2]*(glob3[0]-glob[0]) + glob3[2]*(glob[0]-glob2[0]);
875 Double_t c = glob[0]*(glob2[1]-glob3[1]) + glob2[0]*(glob3[1]-glob[1]) + glob3[0]*(glob[1]-glob2[1]);
876 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]);
879 //shift equation of plane from tower/module center to surface along vector (A,B,C) normal to tower/module plane
880 Double_t dist = fLongModuleSize/2.;
881 Double_t norm = TMath::Sqrt(a*a+b*b+c*c);
882 Double_t glob4[3]={};
884 TVector3 point(glob[0],glob[1],glob[2]);
885 if(point.Dot(dir)<0) dist*=-1;
886 glob4[0]=glob[0]-dist*a/norm;
887 glob4[1]=glob[1]-dist*b/norm;
888 glob4[2]=glob[2]-dist*c/norm;
889 d = glob4[0]*a + glob4[1]*b + glob4[2]*c ;
892 //Line determination (2 points for equation of line : vtx and direction)
893 //impact between line (particle) and plane (module/tower plane)
894 Double_t den = a*(vtx(0)-direction(0)) + b*(vtx(1)-direction(1)) + c*(vtx(2)-direction(2));
896 printf("ImpactOnEmcal() No solution :\n");
900 Double_t length = a*vtx(0)+b*vtx(1)+c*vtx(2)+d;
903 vimpact.SetXYZ(vtx(0)+length*(direction(0)-vtx(0)),vtx(1)+length*(direction(1)-vtx(1)),vtx(2)+length*(direction(2)-vtx(2)));
905 //shift vimpact from tower/module surface to center along vector (A,B,C) normal to tower/module plane
906 vimpact.SetXYZ(vimpact(0)+dist*a/norm,vimpact(1)+dist*b/norm,vimpact(2)+dist*c/norm);
911 //_____________________________________________________________________________
912 Bool_t AliEMCALGeoUtils::IsInEMCAL(Double_t x, Double_t y, Double_t z) const {
913 // Checks whether point is inside the EMCal volume, used in AliEMCALv*.cxx
915 // Code uses cylindrical approximation made of inner radius (for speed)
917 // Points behind EMCAl, i.e. R > outer radius, but eta, phi in acceptance
918 // are considered to inside
920 Double_t r=sqrt(x*x+y*y);
922 if ( r > fEnvelop[0] ) {
924 theta = TMath::ATan2(r,z);
929 eta = -TMath::Log(TMath::Tan(theta/2.));
930 if (eta < fArm1EtaMin || eta > fArm1EtaMax)
933 Double_t phi = TMath::ATan2(y,x) * 180./TMath::Pi();
934 if (phi < 0) phi += 360; // phi should go from 0 to 360 in this case
935 if (phi > fArm1PhiMin && phi < fArm1PhiMax)
941 //________________________________________________________________________________________________
942 Int_t AliEMCALGeoUtils::GetAbsTRUNumberFromNumberInSm(const Int_t row, const Int_t col, const Int_t sm) const
944 // Get TRU absolute number from column, row and Super Module number
945 Int_t itru = row + col*fEMCGeometry->GetNModulesInTRUPhi() + sm*fEMCGeometry->GetNTRU();
946 // printf(" GetAbsTRUNumberFromNumberInSm : row %2i col %2i sm %2i -> itru %2i\n", row, col, sm, itru);
950 //________________________________________________________________________________________________
951 Bool_t AliEMCALGeoUtils::GetAbsFastORIndexFromTRU(const Int_t iTRU, const Int_t iADC, Int_t& id) const
953 //Trigger mapping method, get FastOr Index from TRU
955 if (iTRU > 31 || iTRU < 0 || iADC > 95 || iADC < 0)
957 AliError("TRU out of range!");
961 id = iADC + iTRU * 96;
966 //________________________________________________________________________________________________
967 Bool_t AliEMCALGeoUtils::GetTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iADC) const
970 //Trigger mapping method, get TRU number from FastOr Index
972 if (id > 3071 || id < 0)
974 AliError("Id out of range!");
984 //________________________________________________________________________________________________
985 Bool_t AliEMCALGeoUtils::GetPositionInTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iEta, Int_t& iPhi) const
987 //Trigger mapping method, get position in TRU from FasOr Index
991 Bool_t isOK = GetTRUFromAbsFastORIndex(id, iTRU, iADC);
993 if (!isOK) return kFALSE;
998 if ( int( iTRU / 3 ) % 2 ) // C side
1012 //________________________________________________________________________________________________
1013 Bool_t AliEMCALGeoUtils::GetPositionInSMFromAbsFastORIndex(const Int_t id, Int_t& iSM, Int_t& iEta, Int_t& iPhi) const
1015 //Trigger mapping method, get position in Super Module from FasOr Index
1018 Bool_t isOK = GetPositionInTRUFromAbsFastORIndex(id, iTRU, iEta, iPhi);
1020 if (!isOK) return kFALSE;
1024 if ( int( iTRU / 3 ) % 2 ) // C side
1026 iPhi = iPhi + 4 * ( 2 - ( iTRU % 3 ) );
1030 iPhi = iPhi + 4 * ( iTRU % 3 );
1036 //________________________________________________________________________________________________
1037 Bool_t AliEMCALGeoUtils::GetAbsFastORIndexFromPositionInTRU(const Int_t iTRU, const Int_t iEta, const Int_t iPhi, Int_t& id) const
1039 //Trigger mapping method, get Index if FastOr from Position in TRU
1041 if (iTRU < 0 || iTRU > 31 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 3) return kFALSE;
1043 if ( int( iTRU / 3 ) % 2 ) // C side
1045 id = iPhi + 4 * ( 23 - iEta ) + iTRU * 96;
1049 id = (3 - iPhi) + 4 * iEta + iTRU * 96;
1055 //____________________________________________________________________________
1056 const TGeoHMatrix * AliEMCALGeoUtils::GetMatrixForSuperModule(Int_t smod) const {
1058 //Provides shift-rotation matrix for EMCAL
1060 if(smod < 0 || smod > fEMCGeometry->GetNumberOfSuperModules())
1061 AliFatal(Form("Wrong supermodule index -> %d",smod));
1063 //If GeoManager exists, take matrixes from it
1066 // if(fKey110DEG && ind>=10) {
1069 // if(!gGeoManager->cd(volpath.Data()))
1070 // AliFatal(Form("AliEMCALGeometry::GeoManager cannot find path %s!",volpath.Data()));
1072 // TGeoHMatrix* m = gGeoManager->GetCurrentMatrix();
1076 sprintf(path,"/ALIC_1/XEN1_1/SMOD_%d",smod+1) ;
1077 //TString volpath = "ALIC_1/XEN1_1/SMOD_";
1078 //volpath += smod+1;
1080 if(fKey110DEG && smod >= 10){
1081 sprintf(path,"/ALIC_1/XEN1_1/SM10_%d",smod-10+1) ;
1082 //volpath = "ALIC_1/XEN1_1/SM10_";
1083 //volpath += smod-10+1;
1085 if (!gGeoManager->cd(path)){
1086 AliFatal(Form("Geo manager can not find path %s!\n",path));
1088 return gGeoManager->GetCurrentMatrix();
1091 if(fkSModuleMatrix[smod]){
1092 return fkSModuleMatrix[smod] ;
1096 printf("\t Can not find EMCAL misalignment matrixes\n") ;
1097 printf("\t Either import TGeoManager from geometry.root or \n");
1098 printf("\t read stored matrixes from AliESD Header: \n") ;
1099 printf("\t AliEMCALGeoUtils::SetMisalMatrixes(header->GetEMCALMisalMatrix()) \n") ;
1105 //______________________________________________________________________
1106 void AliEMCALGeoUtils::GetModulePhiEtaIndexInSModuleFromTRUIndex(Int_t itru, Int_t iphitru, Int_t ietatru, Int_t &iphiSM, Int_t &ietaSM) const
1109 // This method transforms the (eta,phi) index of module in a
1110 // TRU matrix into Super Module (eta,phi) index.
1112 // Calculate in which row and column where the TRU are
1113 // ordered in the SM
1115 Int_t col = itru/fEMCGeometry->GetNTRUPhi() ; // indexes of TRU in SM
1116 Int_t row = itru - col*fEMCGeometry->GetNTRUPhi();
1118 iphiSM = fEMCGeometry->GetNModulesInTRUPhi()*row + iphitru ;
1119 ietaSM = fEMCGeometry->GetNModulesInTRUEta()*col + ietatru ;
1120 //printf(" GetModulePhiEtaIndexInSModuleFromTRUIndex : itru %2i iphitru %2i ietatru %2i iphiSM %2i ietaSM %2i \n",
1121 // itru, iphitru, ietatru, iphiSM, ietaSM);