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 **************************************************************************/
18 //_________________________________________________________________________
19 // Geometry class for EMCAL : singleton
20 // EMCAL consists of layers of scintillator and lead
21 // with scintillator fiber arranged as "shish-kebab" skewers
22 // Places the the Barrel Geometry of The EMCAL at Midrapidity
23 // between 80 and 180(or 190) degrees of Phi and
26 // EMCAL geometry tree:
27 // EMCAL -> superModule -> module -> tower(cell)
29 // absId -> nSupMod -> nModule -> (nIphi,nIeta)
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
37 // EMCAL_FIRSTYEARV1 - geometry for December 2009 to December 2010 run period;
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).
43 // EMCAL_COMPLETEV1: Same fixes as FIRSTYEAR and 10 SM instead of 10+2 half SM, for 2011 runs
45 // EMCAL_COMPLETE12SMV1: contains 12 SM for runs from year 2012 and on
47 // EMCAL_WSUC (Wayne State test stand)
48 // = no definite equivalent in old notation, was only used by
49 // Aleksei, but kept for testing purposes
55 // You can create the AliEMCALGeometry object independently from anything.
56 // You have to use just the correct name of geometry. If name is empty string the
57 // default name of geometry will be used.
59 // AliEMCALGeometry* g = AliEMCALGeometry::GetInstance(name,title); // first time
61 // g = AliEMCALGeometry::GetInstance(); // after first time
63 // MC: If you work with MC data you have to get geometry the next way:
64 // == =============================
65 // AliRunLoader *rl = AliRunLoader::Instance();
66 // AliEMCALGeometry *geom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
67 // TGeoManager::Import("geometry.root");
69 //*-- Author: Sahal Yacoob (LBL / UCT)
70 // and : Yves Schutz (SUBATECH)
71 // and : Jennifer Klay (LBL)
72 // and : Alexei Pavlinov (WSU)
74 // Implementation for analysis usage, before AliEMCALGeometry now (06/2011) merged again
75 // in AliEMCALGeometry
77 // -- Author: Magali Estienne (magali.estienne@subatech.in2p3.fr)
81 // You can create the AliEMCALGeometry object independently from anything.
82 // You have to use just the correct name of geometry. If name is empty string the
83 // default name of geometry will be used.
85 // AliEMCALGeometry* geom = new AliEMCALGeometry("EMCAL_COMPLETE12SMV1","EMCAL");
86 // TGeoManager::Import("geometry.root");
88 // MC: If you work with MC data you have to get geometry the next way:
89 // == =============================
90 // !!!!!!!!! This part has to be modified
91 // AliRunLoader *rl = AliRunLoader::GetRunLoader();
92 // AliEMCALEMCGeometry *geom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
93 // TGeoManager::Import("geometry.root");
96 // --- ROOT system ---
98 #include <TParticle.h>
99 #include <TGeoManager.h>
100 #include <TGeoMatrix.h>
101 #include <TGeoBBox.h>
103 #include <TBrowser.h>
105 // --- Standard library ---
106 //#include <Riostream.h>
108 // --- AliRoot header files ---
109 #include "AliEMCALGeometry.h"
110 #include "AliEMCALShishKebabTrd1Module.h"
112 ClassImp(AliEMCALGeometry)
114 // these initialisations are needed for a singleton
115 AliEMCALGeometry *AliEMCALGeometry::fgGeom = 0;
116 const Char_t* AliEMCALGeometry::fgkDefaultGeometryName = "EMCAL_COMPLETE12SMV1";
118 //____________________________________________________________________________
119 AliEMCALGeometry::AliEMCALGeometry():
120 fEMCGeometry(0x0),fGeoName(0),
121 fKey110DEG(0),fNCellsInSupMod(0),fNETAdiv(0),fNPHIdiv(0),
122 fNCellsInModule(0),fPhiBoundariesOfSM(0x0),fPhiCentersOfSM(0x0),
123 fPhiCentersOfCells(0x0),fCentersOfCellsEtaDir(0x0),
124 fCentersOfCellsPhiDir(0x0),fEtaCentersOfCells(0x0),
125 fNCells(0),fNPhi(0),fCentersOfCellsXDir(0x0),fArm1EtaMin(0),
126 fArm1EtaMax(0),fArm1PhiMin(0),fArm1PhiMax(0),fEtaMaxOfTRD1(0),
127 fShishKebabTrd1Modules(0),fPhiModuleSize(0.),
128 fEtaModuleSize(0.),fPhiTileSize(0.),fEtaTileSize(0.),fNZ(0),
129 fIPDistance(0.),fLongModuleSize(0.),fShellThickness(0.),
130 fZLength(0.),fSampling(0.),fUseExternalMatrices(kFALSE)
133 // must be kept public for root persistency purposes, but should never be called by the outside world
140 for (Int_t i=0;i<AliEMCALGeoParams::fgkEMCALModules;i++)
141 fkSModuleMatrix[i]=0 ;
143 for (Int_t i = 0; i < 48; i++)
144 for (Int_t j = 0; j < 64; j++) fFastOR2DMap[i][j] = -1;
147 //____________________________________________________________________________
148 AliEMCALGeometry::AliEMCALGeometry(const AliEMCALGeometry & geo)
150 fEMCGeometry(geo.fEMCGeometry),fGeoName(geo.fGeoName),
151 fKey110DEG(geo.fKey110DEG),fNCellsInSupMod(geo.fNCellsInSupMod),fNETAdiv(geo.fNETAdiv),fNPHIdiv(geo.fNPHIdiv),
152 fNCellsInModule(geo.fNCellsInModule),fPhiBoundariesOfSM(geo.fPhiBoundariesOfSM),fPhiCentersOfSM(geo.fPhiCentersOfSM),
153 fPhiCentersOfCells(geo.fPhiCentersOfCells),fCentersOfCellsEtaDir(geo.fCentersOfCellsEtaDir),
154 fCentersOfCellsPhiDir(geo.fCentersOfCellsPhiDir),fEtaCentersOfCells(geo.fEtaCentersOfCells),
155 fNCells(geo.fNCells),fNPhi(geo.fNPhi),fCentersOfCellsXDir(geo.fCentersOfCellsXDir),fArm1EtaMin(geo.fArm1EtaMin),
156 fArm1EtaMax(geo.fArm1EtaMax),fArm1PhiMin(geo.fArm1PhiMin),fArm1PhiMax(geo.fArm1PhiMax),fEtaMaxOfTRD1(geo.fEtaMaxOfTRD1),
157 fShishKebabTrd1Modules(geo.fShishKebabTrd1Modules),fPhiModuleSize(geo.fPhiModuleSize),
158 fEtaModuleSize(geo.fEtaModuleSize),fPhiTileSize(geo.fPhiTileSize),fEtaTileSize(geo.fEtaTileSize),fNZ(geo.fNZ),
159 fIPDistance(geo.fIPDistance),fLongModuleSize(geo.fLongModuleSize),fShellThickness(geo.fShellThickness),
160 fZLength(geo.fZLength),fSampling(geo.fSampling),fUseExternalMatrices(geo.fUseExternalMatrices)
163 fEnvelop[0] = geo.fEnvelop[0];
164 fEnvelop[1] = geo.fEnvelop[1];
165 fEnvelop[2] = geo.fEnvelop[2];
166 fParSM[0] = geo.fParSM[0];
167 fParSM[1] = geo.fParSM[1];
168 fParSM[2] = geo.fParSM[2];
169 for (Int_t i=0;i<AliEMCALGeoParams::fgkEMCALModules;i++)
170 fkSModuleMatrix[i]=0 ;
172 for (Int_t i = 0; i < 48; i++)
173 for (Int_t j = 0; j < 64; j++) fFastOR2DMap[i][j] = geo.fFastOR2DMap[i][j];
176 //____________________________________________________________________________
177 AliEMCALGeometry::AliEMCALGeometry(const Text_t* name, const Text_t* title,
178 const Text_t* mcname, const Text_t* mctitle)
179 : TNamed(name, title),
180 fEMCGeometry(0x0),fGeoName(0),
181 fKey110DEG(0),fNCellsInSupMod(0),fNETAdiv(0),fNPHIdiv(0),
182 fNCellsInModule(0),fPhiBoundariesOfSM(0x0),fPhiCentersOfSM(0x0),
183 fPhiCentersOfCells(0x0),fCentersOfCellsEtaDir(0x0),
184 fCentersOfCellsPhiDir(0x0),fEtaCentersOfCells(0x0),
185 fNCells(0),fNPhi(0),fCentersOfCellsXDir(0x0),fArm1EtaMin(0),
186 fArm1EtaMax(0),fArm1PhiMin(0),fArm1PhiMax(0),fEtaMaxOfTRD1(0),
187 fShishKebabTrd1Modules(0),fPhiModuleSize(0.),
188 fEtaModuleSize(0.),fPhiTileSize(0.),fEtaTileSize(0.),fNZ(0),
189 fIPDistance(0.),fLongModuleSize(0.),fShellThickness(0.),
190 fZLength(0.),fSampling(0.), fUseExternalMatrices(kFALSE)
193 // ctor only for normal usage
195 fEMCGeometry = new AliEMCALEMCGeometry(name,title,mcname,mctitle);
197 fGeoName = fEMCGeometry->GetGeoName();
198 fKey110DEG = fEMCGeometry->GetKey110DEG();
199 fNCellsInSupMod = fEMCGeometry->GetNCellsInSupMod();
200 fNETAdiv = fEMCGeometry->GetNETAdiv();
201 fNPHIdiv = fEMCGeometry->GetNPHIdiv();
202 fNCellsInModule = fNPHIdiv*fNETAdiv;
204 Int_t nSMod = fEMCGeometry->GetNumberOfSuperModules();
205 fPhiBoundariesOfSM.Set(nSMod);
206 fPhiCentersOfSM.Set(nSMod/2);
207 for(Int_t sm=0; sm<nSMod; sm++) {
209 fEMCGeometry->GetPhiBoundariesOfSM(sm,fPhiBoundariesOfSM[2*i],fPhiBoundariesOfSM[2*i+1]);
212 Double_t phiMin = 0.;
213 Double_t phiMax = 0.;
214 for(Int_t sm=0; sm<nSMod; sm++) {
215 fEMCGeometry->GetPhiBoundariesOfSM(sm,phiMin,phiMax);
217 fPhiCentersOfSM[i] = fEMCGeometry->GetPhiCenterOfSM(sm);
219 fNCells = fEMCGeometry->GetNCells();
220 fNPhi = fEMCGeometry->GetNPhi();
221 fEnvelop[0] = fEMCGeometry->GetEnvelop(0);
222 fEnvelop[1] = fEMCGeometry->GetEnvelop(1);
223 fEnvelop[2] = fEMCGeometry->GetEnvelop(2);
224 fParSM[0] = fEMCGeometry->GetSuperModulesPar(0);
225 fParSM[1] = fEMCGeometry->GetSuperModulesPar(1);
226 fParSM[2] = fEMCGeometry->GetSuperModulesPar(2);
227 fArm1EtaMin = fEMCGeometry->GetArm1EtaMin();
228 fArm1EtaMax = fEMCGeometry->GetArm1EtaMax();
229 fArm1PhiMin = fEMCGeometry->GetArm1PhiMin();
230 fArm1PhiMax = fEMCGeometry->GetArm1PhiMax();
231 fShellThickness = fEMCGeometry->GetShellThickness();
232 fZLength = fEMCGeometry->GetZLength();
233 fSampling = fEMCGeometry->GetSampling();
234 fEtaModuleSize = fEMCGeometry->GetEtaModuleSize();
235 fPhiModuleSize = fEMCGeometry->GetPhiModuleSize();
236 fEtaTileSize = fEMCGeometry->GetEtaTileSize();
237 fPhiTileSize = fEMCGeometry->GetPhiTileSize();
238 fNZ = fEMCGeometry->GetNZ();
239 fIPDistance = fEMCGeometry->GetIPDistance();
240 fLongModuleSize = fEMCGeometry->GetLongModuleSize();
242 CreateListOfTrd1Modules();
244 for(Int_t smod=0; smod < AliEMCALGeoParams::fgkEMCALModules; smod++)
245 fkSModuleMatrix[smod]=0 ;
247 if (AliDebugLevel()>=2) {
248 fEMCGeometry->Print();
249 PrintGeometryGeoUtils();
252 for (Int_t ix = 0; ix < 48; ix++)
253 for (Int_t jx = 0; jx < 64; jx++) fFastOR2DMap[ix][jx] = -1;
258 //____________________________________________________________________________
259 AliEMCALGeometry & AliEMCALGeometry::operator = (const AliEMCALGeometry & /*rvalue*/) {
261 Fatal("assignment operator", "not implemented") ;
265 //____________________________________________________________________________
266 AliEMCALGeometry::~AliEMCALGeometry(void)
270 AliError("Do not call delete on me");
274 for(Int_t smod = 0 ; smod < fEMCGeometry->GetNumberOfSuperModules(); smod++){
275 if(fkSModuleMatrix[smod])
276 delete fkSModuleMatrix[smod] ;
277 fkSModuleMatrix[smod]=0 ;
279 delete fEMCGeometry; // fEMCGeometry = 0 ;
283 //______________________________________________________________________
284 AliEMCALGeometry * AliEMCALGeometry::GetInstance(){
285 // Returns the pointer of the unique instance
287 AliEMCALGeometry * rv = static_cast<AliEMCALGeometry *>( fgGeom );
291 //______________________________________________________________________
292 AliEMCALGeometry* AliEMCALGeometry::GetInstance(const Text_t* name, const Text_t* title,
293 const Text_t* mcname, const Text_t* mctitle ){
294 // Returns the pointer of the unique instance
296 AliEMCALGeometry * rv = 0;
298 if ( strcmp(name,"") == 0 ) { // get default geometry
299 fgGeom = new AliEMCALGeometry(fgkDefaultGeometryName, title,mcname,mctitle);
301 fgGeom = new AliEMCALGeometry(name, title,mcname,mctitle);
302 } // end if strcmp(name,"")
303 if ( AliEMCALEMCGeometry::fgInit ) rv = (AliEMCALGeometry * ) fgGeom;
310 if ( strcmp(fgGeom->GetName(), name) != 0) {
311 printf("\ncurrent geometry is %s : ", fgGeom->GetName());
312 printf(" you cannot call %s ",name);
314 rv = (AliEMCALGeometry *) fgGeom;
320 //________________________________________________________________________________________________
321 void AliEMCALGeometry::Browse(TBrowser* b)
324 if(fShishKebabTrd1Modules) b->Add(fShishKebabTrd1Modules);
327 //________________________________________________________________________________________________
328 Bool_t AliEMCALGeometry::IsFolder() const
330 //Check if fShishKebabTrd1Modules is in folder
331 if(fShishKebabTrd1Modules) return kTRUE;
335 //________________________________________________________________________________________________
336 void AliEMCALGeometry::GetGlobal(const Double_t *loc, Double_t *glob, int ind) const
338 // Figure out the global numbering
339 // of a given supermodule from the
340 // local numbering and the transformation
341 // matrix stored by the geometry manager (allows for misaligned
344 const TGeoHMatrix* m = GetMatrixForSuperModule(ind);
346 m->LocalToMaster(loc, glob);
348 AliFatal("Geo matrixes are not loaded \n") ;
352 //________________________________________________________________________________________________
353 void AliEMCALGeometry::GetGlobal(const TVector3 &vloc, TVector3 &vglob, int ind) const
355 //Figure out the global numbering
356 //of a given supermodule from the
357 //local numbering given a 3-vector location
359 static Double_t tglob[3], tloc[3];
361 GetGlobal(tloc, tglob, ind);
362 vglob.SetXYZ(tglob[0], tglob[1], tglob[2]);
365 //________________________________________________________________________________________________
366 void AliEMCALGeometry::GetGlobal(Int_t absId , double glob[3]) const
368 // Alice numbering scheme - Jun 03, 2006
369 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
370 static double loc[3];
372 glob[0]=glob[1]=glob[2]=0.0; // bad case
373 if(RelPosCellInSModule(absId, loc)) {
374 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
376 const TGeoHMatrix* m = GetMatrixForSuperModule(nSupMod);
378 m->LocalToMaster(loc, glob);
380 AliFatal("Geo matrixes are not loaded \n") ;
385 //___________________________________________________________________
386 void AliEMCALGeometry::GetGlobal(Int_t absId , TVector3 &vglob) const
388 // Alice numbering scheme - Jun 03, 2006
389 static Double_t glob[3];
391 GetGlobal(absId, glob);
392 vglob.SetXYZ(glob[0], glob[1], glob[2]);
397 //______________________________________________________________________
398 void AliEMCALGeometry::PrintCellIndexes(Int_t absId, int pri, const char *tit) const
401 Int_t nSupMod, nModule, nIphi, nIeta;
405 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
406 printf(" %s | absId : %i -> nSupMod %i nModule %i nIphi %i nIeta %i \n", tit, absId, nSupMod, nModule, nIphi, nIeta);
408 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
409 printf(" local SM index : iphi %i : ieta %i \n", iphi,ieta);
410 GetGlobal(absId, vg);
411 printf(" vglob : mag %7.2f : perp %7.2f : z %7.2f : eta %6.4f : phi %6.4f(%6.2f) \n",
412 vg.Mag(), vg.Perp(), vg.Z(), vg.Eta(), vg.Phi(), vg.Phi()*TMath::RadToDeg());
416 void AliEMCALGeometry::PrintLocalTrd1(Int_t pri) const
418 // For comparing with numbers from drawing
419 for(Int_t i=0; i<GetShishKebabTrd1Modules()->GetSize(); i++){
420 printf(" %s | ", GetShishKebabModule(i)->GetName());
421 if(i==0 && pri<1) GetShishKebabModule(i)->PrintShish(1);
422 else GetShishKebabModule(i)->PrintShish(pri);
426 //________________________________________________________________________________________________
427 void AliEMCALGeometry::EtaPhiFromIndex(Int_t absId,Double_t &eta,Double_t &phi) const
429 // Nov 16, 2006- float to double
430 // version for TRD1 only
431 static TVector3 vglob;
432 GetGlobal(absId, vglob);
437 //________________________________________________________________________________________________
438 void AliEMCALGeometry::EtaPhiFromIndex(Int_t absId,Float_t &eta,Float_t &phi) const
440 // Nov 16,2006 - should be discard in future
441 static TVector3 vglob;
442 GetGlobal(absId, vglob);
443 eta = float(vglob.Eta());
444 phi = float(vglob.Phi());
448 // == Shish-kebab cases ==
450 //________________________________________________________________________________________________
451 Int_t AliEMCALGeometry::GetAbsCellId(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta) const
455 // 13-oct-05; 110 degree case
456 // May 31, 2006; ALICE numbering scheme:
457 // 0 <= nSupMod < fNumberOfSuperModules
458 // 0 <= nModule < fNPHI * fNZ ( fNPHI * fNZ/2 for fKey110DEG=1)
459 // 0 <= nIphi < fNPHIdiv
460 // 0 <= nIeta < fNETAdiv
461 // 0 <= absid < fNCells
462 static Int_t id=0; // have to change from 0 to fNCells-1
463 if(fKey110DEG == 1 && nSupMod >= 10) { // 110 degree case; last two supermodules
464 id = fNCellsInSupMod*10 + (fNCellsInSupMod/2)*(nSupMod-10);
466 id = fNCellsInSupMod*nSupMod;
468 id += fNCellsInModule *nModule;
469 id += fNPHIdiv *nIphi;
471 if(id<0 || id >= fNCells) {
472 // printf(" wrong numerations !!\n");
473 // printf(" id %6i(will be force to -1)\n", id);
474 // printf(" fNCells %6i\n", fNCells);
475 // printf(" nSupMod %6i\n", nSupMod);
476 // printf(" nModule %6i\n", nModule);
477 // printf(" nIphi %6i\n", nIphi);
478 // printf(" nIeta %6i\n", nIeta);
479 id = -TMath::Abs(id); // if negative something wrong
484 //________________________________________________________________________________________________
485 void AliEMCALGeometry::GetModuleIndexesFromCellIndexesInSModule(Int_t nSupMod, Int_t iphi, Int_t ieta,
486 Int_t &iphim, Int_t &ietam, Int_t &nModule) const
488 // Transition from cell indexes (ieta,iphi) to module indexes (ietam,iphim, nModule)
489 static Int_t nphi=-1;
490 nphi = GetNumberOfModuleInPhiDirection(nSupMod);
492 ietam = ieta/fNETAdiv;
493 iphim = iphi/fNPHIdiv;
494 nModule = ietam * nphi + iphim;
497 //________________________________________________________________________________________________
498 Int_t AliEMCALGeometry::GetAbsCellIdFromCellIndexes(Int_t nSupMod, Int_t iphi, Int_t ieta) const
500 // Transition from super module number(nSupMod) and cell indexes (ieta,iphi) to absId
501 static Int_t ietam=-1, iphim=-1, nModule=-1;
502 static Int_t nIeta=-1, nIphi=-1; // cell indexes in module
504 GetModuleIndexesFromCellIndexesInSModule(nSupMod, iphi, ieta, ietam, iphim, nModule);
506 nIeta = ieta%fNETAdiv;
507 nIeta = fNETAdiv - 1 - nIeta;
508 nIphi = iphi%fNPHIdiv;
510 return GetAbsCellId(nSupMod, nModule, nIphi, nIeta);
513 //________________________________________________________________________________________________
514 Bool_t AliEMCALGeometry::SuperModuleNumberFromEtaPhi(Double_t eta, Double_t phi, Int_t &nSupMod) const
516 // Return false if phi belongs a phi cracks between SM
520 if(TMath::Abs(eta) > fEtaMaxOfTRD1) return kFALSE;
522 phi = TVector2::Phi_0_2pi(phi); // move phi to (0,2pi) boundaries
525 //Check if it is not the complete geometry
526 if (i >= fEMCGeometry->GetNumberOfSuperModules()/2) return kFALSE;
528 if(phi>=fPhiBoundariesOfSM[2*i] && phi<=fPhiBoundariesOfSM[2*i+1]) {
530 if(eta < 0.0) nSupMod++;
531 AliDebug(1,Form("eta %f phi %f(%5.2f) : nSupMod %i : #bound %i", eta,phi,phi*TMath::RadToDeg(), nSupMod,i));
539 //________________________________________________________________________________________________
540 Bool_t AliEMCALGeometry::GetAbsCellIdFromEtaPhi(Double_t eta, Double_t phi, Int_t &absId) const
543 // stay here - phi problem as usual
544 static Int_t nSupMod=-1, i=0, ieta=-1, iphi=-1, etaShift=0, nphi=-1;
545 static Double_t absEta=0.0, d=0.0, dmin=0.0, phiLoc=0;
546 absId = nSupMod = - 1;
547 if(SuperModuleNumberFromEtaPhi(eta, phi, nSupMod)) {
549 phi = TVector2::Phi_0_2pi(phi);
550 phiLoc = phi - fPhiCentersOfSM[nSupMod/2];
551 nphi = fPhiCentersOfCells.GetSize();
553 phiLoc = phi - 190.*TMath::DegToRad();
557 dmin = TMath::Abs(fPhiCentersOfCells[0]-phiLoc);
559 for(i=1; i<nphi; i++) {
560 d = TMath::Abs(fPhiCentersOfCells[i] - phiLoc);
565 // printf(" i %i : d %f : dmin %f : fPhiCentersOfCells[i] %f \n", i, d, dmin, fPhiCentersOfCells[i]);
567 // odd SM are turned with respect of even SM - reverse indexes
568 AliDebug(2,Form(" iphi %i : dmin %f (phi %f, phiLoc %f ) ", iphi, dmin, phi, phiLoc));
570 absEta = TMath::Abs(eta);
571 etaShift = iphi*fCentersOfCellsEtaDir.GetSize();
572 dmin = TMath::Abs(fEtaCentersOfCells[etaShift]-absEta);
574 for(i=1; i<fCentersOfCellsEtaDir.GetSize(); i++) {
575 d = TMath::Abs(fEtaCentersOfCells[i+etaShift] - absEta);
581 AliDebug(2,Form(" ieta %i : dmin %f (eta=%f) : nSupMod %i ", ieta, dmin, eta, nSupMod));
583 if(eta<0) iphi = (nphi-1) - iphi;
585 //patch for mapping following alice convention
587 ieta = (fCentersOfCellsEtaDir.GetSize()-1)-ieta;// 47-ieta, revert the ordering on A side in order to keep convention.
590 iphi = (fCentersOfCellsPhiDir.GetSize()-1) -iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
592 iphi = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
595 absId = GetAbsCellIdFromCellIndexes(nSupMod, iphi, ieta);
602 //________________________________________________________________________________________________
603 Bool_t AliEMCALGeometry::CheckAbsCellId(Int_t absId) const
605 // May 31, 2006; only trd1 now
606 if(absId<0 || absId >= fNCells) return kFALSE;
610 //________________________________________________________________________________________________
611 Bool_t AliEMCALGeometry::GetCellIndex(Int_t absId,Int_t &nSupMod,Int_t &nModule,Int_t &nIphi,Int_t &nIeta) const
613 // 21-sep-04; 19-oct-05;
614 // May 31, 2006; ALICE numbering scheme:
617 // absId - cell is as in Geant, 0<= absId < fNCells;
619 // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
620 // nModule - module number in SM, 0<= nModule < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
621 // nIphi - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv;
622 // nIeta - cell number in eta driection inside module; 0<= nIeta < fNETAdiv;
624 static Int_t tmp=0, sm10=0;
625 if(!CheckAbsCellId(absId)) return kFALSE;
627 sm10 = fNCellsInSupMod*10;
628 if(fKey110DEG == 1 && absId >= sm10) { // 110 degree case; last two supermodules
629 nSupMod = (absId-sm10) / (fNCellsInSupMod/2) + 10;
630 tmp = (absId-sm10) % (fNCellsInSupMod/2);
632 nSupMod = absId / fNCellsInSupMod;
633 tmp = absId % fNCellsInSupMod;
636 nModule = tmp / fNCellsInModule;
637 tmp = tmp % fNCellsInModule;
638 nIphi = tmp / fNPHIdiv;
639 nIeta = tmp % fNPHIdiv;
644 //________________________________________________________________________________________________
645 Int_t AliEMCALGeometry::GetSuperModuleNumber(Int_t absId) const
647 // Return the number of the supermodule given the absolute
648 // ALICE numbering id
650 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
651 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
655 //________________________________________________________________________________________________
656 void AliEMCALGeometry::GetModulePhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, int &iphim, int &ietam) const
658 // added nSupMod; - 19-oct-05 !
659 // Alice numbering scheme - Jun 01,2006
660 // ietam, iphi - indexes of module in two dimensional grid of SM
661 // ietam - have to change from 0 to fNZ-1
662 // iphim - have to change from 0 to nphi-1 (fNPhi-1 or fNPhi/2-1)
663 static Int_t nphi=-1;
665 if(fKey110DEG == 1 && nSupMod>=10) nphi = fNPhi/2;
668 ietam = nModule/nphi;
669 iphim = nModule%nphi;
672 //________________________________________________________________________________________________
673 void AliEMCALGeometry::GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta,
674 int &iphi, int &ieta) const
677 // Added nSupMod; Nov 25, 05
678 // Alice numbering scheme - Jun 01,2006
680 // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
681 // nModule - module number in SM, 0<= nModule < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
682 // nIphi - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv;
683 // nIeta - cell number in eta driection inside module; 0<= nIeta < fNETAdiv;
686 // ieta, iphi - indexes of cell(tower) in two dimensional grid of SM
687 // ieta - have to change from 0 to (fNZ*fNETAdiv-1)
688 // iphi - have to change from 0 to (fNPhi*fNPHIdiv-1 or fNPhi*fNPHIdiv/2-1)
690 static Int_t iphim=-1, ietam=-1;
692 GetModulePhiEtaIndexInSModule(nSupMod,nModule, iphim, ietam);
693 // ieta = ietam*fNETAdiv + (1-nIeta); // x(module) = -z(SM)
694 ieta = ietam*fNETAdiv + (fNETAdiv - 1 - nIeta); // x(module) = -z(SM)
695 iphi = iphim*fNPHIdiv + nIphi; // y(module) = y(SM)
698 AliDebug(1,Form(" nSupMod %i nModule %i nIphi %i nIeta %i => ieta %i iphi %i\n",
699 nSupMod, nModule, nIphi, nIeta, ieta, iphi));
703 // Methods for AliEMCALRecPoint - Feb 19, 2006
704 //________________________________________________________________________________________________
705 Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, Double_t &xr, Double_t &yr, Double_t &zr) const
707 // Look to see what the relative
708 // position inside a given cell is
710 // Alice numbering scheme - Jun 08, 2006
712 // absId - cell is as in Geant, 0<= absId < fNCells;
714 // xr,yr,zr - x,y,z coordinates of cell with absId inside SM
716 // Shift index taking into account the difference between standard SM
717 // and SM of half size in phi direction
718 const Int_t kphiIndexShift = fCentersOfCellsPhiDir.GetSize()/4; // Nov 22, 2006; was 6 for cas 2X2
719 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
720 if(!CheckAbsCellId(absId)) return kFALSE;
722 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
723 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi, ieta);
725 //Get eta position. Careful with ALICE conventions (increase index decrease eta)
728 ieta2 = (fCentersOfCellsEtaDir.GetSize()-1)-ieta;// 47-ieta, revert the ordering on A side in order to keep convention.
729 zr = fCentersOfCellsEtaDir.At(ieta2);
730 xr = fCentersOfCellsXDir.At(ieta2);
732 //Get phi position. Careful with ALICE conventions (increase index increase phi)
736 iphi2 = (fCentersOfCellsPhiDir.GetSize()-1)-iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
737 yr = fCentersOfCellsPhiDir.At(iphi2);
741 iphi2 = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
742 yr = fCentersOfCellsPhiDir.At(iphi2 + kphiIndexShift);
744 AliDebug(1,Form("absId %i nSupMod %i iphi %i ieta %i xr %f yr %f zr %f ",absId,nSupMod,iphi,ieta,xr,yr,zr));
749 //________________________________________________________________________________________________
750 Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, Double_t loc[3]) const
752 // Look to see what the relative
753 // position inside a given cell is
754 // for a recpoint. // Alice numbering scheme - Jun 03, 2006
755 loc[0] = loc[1] = loc[2]=0.0;
756 if(RelPosCellInSModule(absId, loc[0],loc[1],loc[2])) {
762 //________________________________________________________________________________________________
763 Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, TVector3 &vloc) const
765 // Look to see what the relative
766 // position inside a given cell is
768 // Alice numbering scheme - Jun 03, 2006
769 static Double_t loc[3];
770 if(RelPosCellInSModule(absId,loc)) {
771 vloc.SetXYZ(loc[0], loc[1], loc[2]);
779 //________________________________________________________________________________________________
780 Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, Double_t distEff, Double_t &xr, Double_t &yr, Double_t &zr) const
782 // Jul 30, 2007 - taking into account position of shower max
783 // Look to see what the relative
784 // position inside a given cell is
787 // absId - cell is as in Geant, 0<= absId < fNCells;
788 // e - cluster energy
790 // xr,yr,zr - x,y,z coordinates of cell with absId inside SM
792 // Shift index taking into account the difference between standard SM
793 // and SM of half size in phi direction
794 const Int_t kphiIndexShift = fCentersOfCellsPhiDir.GetSize()/4; // Nov 22, 2006; was 6 for cas 2X2
795 static Int_t nSupMod=0, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
796 static Int_t iphim=-1, ietam=-1;
797 static AliEMCALShishKebabTrd1Module *mod = 0;
799 if(!CheckAbsCellId(absId)) return kFALSE;
801 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
802 GetModulePhiEtaIndexInSModule(nSupMod, nModule, iphim, ietam);
803 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi, ieta);
805 //Get eta position. Careful with ALICE conventions (increase index decrease eta)
807 ietam = (fCentersOfCellsEtaDir.GetSize()/2-1)-ietam;// 47-ietam, revert the ordering on A side in order to keep convention.
808 if(nIeta == 0) nIeta = 1;
811 mod = GetShishKebabModule(ietam);
812 mod ->GetPositionAtCenterCellLine(nIeta, distEff, v);
813 xr = v.Y() - fParSM[0];
814 zr = v.X() - fParSM[2];
816 //Get phi position. Careful with ALICE conventions (increase index increase phi)
820 iphi2 = (fCentersOfCellsPhiDir.GetSize()-1)-iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
821 yr = fCentersOfCellsPhiDir.At(iphi2);
825 iphi2 = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
826 yr = fCentersOfCellsPhiDir.At(iphi2 + kphiIndexShift);
829 AliDebug(1,Form("absId %i nSupMod %i iphi %i ieta %i xr %f yr %f zr %f ",absId,nSupMod,iphi,ieta,xr,yr,zr));
835 //________________________________________________________________________________________________
836 void AliEMCALGeometry::CreateListOfTrd1Modules()
838 // Generate the list of Trd1 modules
839 // which will make up the EMCAL
841 // key: look to the AliEMCALShishKebabTrd1Module::
843 AliDebug(2,Form(" AliEMCALGeometry::CreateListOfTrd1Modules() started "));
845 AliEMCALShishKebabTrd1Module *mod=0, *mTmp=0; // current module
846 if(fShishKebabTrd1Modules == 0) {
847 fShishKebabTrd1Modules = new TList;
848 fShishKebabTrd1Modules->SetName("ListOfTRD1");
849 for(int iz=0; iz< fEMCGeometry->GetNZ(); iz++) {
851 // mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,this);
852 mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,fEMCGeometry);
854 mTmp = new AliEMCALShishKebabTrd1Module(*mod);
857 fShishKebabTrd1Modules->Add(mod);
860 AliDebug(2,Form(" Already exits : "));
862 mod = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(fShishKebabTrd1Modules->GetSize()-1);
863 fEtaMaxOfTRD1 = mod->GetMaxEtaOfModule(0);
865 AliDebug(2,Form(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
866 fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1));
868 // Jun 01, 2006 - ALICE numbering scheme
869 // define grid for cells in eta(z) and x directions in local coordinates system of SM
870 // Works just for 2x2 case only -- ?? start here
873 // Define grid for cells in phi(y) direction in local coordinates system of SM
874 // as for 2X2 as for 3X3 - Nov 8,2006
876 AliDebug(2,Form(" Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize()));
877 Int_t ind=0; // this is phi index
878 Int_t ieta=0, nModule=0, iphiTemp;
879 Double_t xr=0., zr=0., theta=0., phi=0., eta=0., r=0., x=0.,y=0.;
881 Double_t ytCenterModule=0.0, ytCenterCell=0.0;
883 fCentersOfCellsPhiDir.Set(fNPhi*fNPHIdiv);
884 fPhiCentersOfCells.Set(fNPhi*fNPHIdiv);
886 Double_t r0 = fIPDistance + fLongModuleSize/2.;
887 for(Int_t it=0; it<fNPhi; it++) { // cycle on modules
888 ytCenterModule = -fParSM[1] + fPhiModuleSize*(2*it+1)/2; // center of module
889 for(Int_t ic=0; ic<fNPHIdiv; ic++) { // cycle on cells in module
891 ytCenterCell = ytCenterModule + fPhiTileSize *(2*ic-1)/2.;
892 } else if(fNPHIdiv==3){
893 ytCenterCell = ytCenterModule + fPhiTileSize *(ic-1);
894 } else if(fNPHIdiv==1){
895 ytCenterCell = ytCenterModule;
897 fCentersOfCellsPhiDir.AddAt(ytCenterCell,ind);
898 // Define grid on phi direction
899 // Grid is not the same for different eta bin;
900 // Effect is small but is still here
901 phi = TMath::ATan2(ytCenterCell, r0);
902 fPhiCentersOfCells.AddAt(phi, ind);
904 AliDebug(2,Form(" ind %2.2i : y %8.3f ", ind, fCentersOfCellsPhiDir.At(ind)));
909 fCentersOfCellsEtaDir.Set(fNZ *fNETAdiv);
910 fCentersOfCellsXDir.Set(fNZ *fNETAdiv);
911 fEtaCentersOfCells.Set(fNZ *fNETAdiv * fNPhi*fNPHIdiv);
912 AliDebug(2,Form(" Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize()));
913 for(Int_t it=0; it<fNZ; it++) {
914 AliEMCALShishKebabTrd1Module *trd1 = GetShishKebabModule(it);
916 for(Int_t ic=0; ic<fNETAdiv; ic++) {
918 trd1->GetCenterOfCellInLocalCoordinateofSM(ic, xr, zr); // case of 2X2
919 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
921 trd1->GetCenterOfCellInLocalCoordinateofSM3X3(ic, xr, zr); // case of 3X3
922 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
924 trd1->GetCenterOfCellInLocalCoordinateofSM1X1(xr, zr); // case of 1X1
925 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
927 fCentersOfCellsXDir.AddAt(float(xr) - fParSM[0],ieta);
928 fCentersOfCellsEtaDir.AddAt(float(zr) - fParSM[2],ieta);
929 // Define grid on eta direction for each bin in phi
930 for(int iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
931 x = xr + trd1->GetRadius();
932 y = fCentersOfCellsPhiDir[iphi];
933 r = TMath::Sqrt(x*x + y*y + zr*zr);
934 theta = TMath::ACos(zr/r);
935 eta = AliEMCALShishKebabTrd1Module::ThetaToEta(theta);
936 // ind = ieta*fCentersOfCellsPhiDir.GetSize() + iphi;
937 ind = iphi*fCentersOfCellsEtaDir.GetSize() + ieta;
938 fEtaCentersOfCells.AddAt(eta, ind);
940 //printf(" ieta %i : xr + trd1->GetRadius() %f : zr %f : eta %f \n", ieta, xr + trd1->GetRadius(), zr, eta);
943 for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
944 AliDebug(2,Form(" ind %2.2i : z %8.3f : x %8.3f", i+1,
945 fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i)));
951 //________________________________________________________________________________________________
952 AliEMCALShishKebabTrd1Module* AliEMCALGeometry::GetShishKebabModule(Int_t neta) const
954 //This method was too long to be
955 //included in the header file - the
956 //rule checker complained about it's
957 //length, so we move it here. It returns the
958 //shishkebabmodule at a given eta index point.
960 static AliEMCALShishKebabTrd1Module* trd1=0;
961 if(fShishKebabTrd1Modules && neta>=0 && neta<fShishKebabTrd1Modules->GetSize()) {
962 trd1 = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(neta);
967 //___________________________________________________________________
968 void AliEMCALGeometry::PrintGeometryGeoUtils()
970 //Print information from geometry
971 fEMCGeometry->PrintGeometry();
973 printf(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
974 fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1);
976 printf("\n Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize());
977 for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
978 printf(" ind %2.2i : z %8.3f : x %8.3f \n", i,
979 fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i));
980 int ind=0; // Nov 21,2006
981 for(Int_t iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
982 ind = iphi*fCentersOfCellsEtaDir.GetSize() + i;
983 printf("%6.4f ", fEtaCentersOfCells[ind]);
984 if((iphi+1)%12 == 0) printf("\n");
990 printf("\n Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize());
991 for(Int_t i=0; i<fCentersOfCellsPhiDir.GetSize(); i++) {
992 double phi=fPhiCentersOfCells.At(i);
993 printf(" ind %2.2i : y %8.3f : phi %7.5f(%6.2f) \n", i, fCentersOfCellsPhiDir.At(i),
994 phi, phi*TMath::RadToDeg());
999 //____________________________________________________________________________
1000 Bool_t AliEMCALGeometry::Impact(const TParticle * particle) const
1002 // Tells if a particle enters EMCAL
1005 TVector3 vtx(particle->Vx(),particle->Vy(),particle->Vz());
1006 TVector3 vimpact(0,0,0);
1007 ImpactOnEmcal(vtx,particle->Theta(),particle->Phi(),absID,vimpact);
1012 //____________________________________________________________________________
1013 void AliEMCALGeometry::ImpactOnEmcal(TVector3 vtx, Double_t theta, Double_t phi,
1014 Int_t & absId, TVector3 & vimpact) const
1016 // calculates the impact coordinates on EMCAL (centre of a tower/not on EMCAL surface)
1017 // of a neutral particle
1018 // emitted in the vertex vtx[3] with direction theta and phi in the ALICE global coordinate system
1020 TVector3 p(TMath::Sin(theta)*TMath::Cos(phi),TMath::Sin(theta)*TMath::Sin(phi),TMath::Cos(theta)) ;
1022 vimpact.SetXYZ(0,0,0);
1024 if(phi==0 || theta==0) return;
1027 Double_t factor = (fIPDistance-vtx[1])/p[1];
1028 direction = vtx + factor*p;
1030 //from particle direction -> tower hitted
1031 GetAbsCellIdFromEtaPhi(direction.Eta(),direction.Phi(),absId);
1033 //tower absID hitted -> tower/module plane (evaluated at the center of the tower)
1034 Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
1035 Double_t loc[3],loc2[3],loc3[3];
1036 Double_t glob[3]={},glob2[3]={},glob3[3]={};
1038 if(!RelPosCellInSModule(absId,loc)) return;
1040 //loc is cell center of tower
1041 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
1043 //look at 2 neighbours-s cell using nIphi={0,1} and nIeta={0,1}
1044 Int_t nIphi2=-1,nIeta2=-1,absId2=-1,absId3=-1;
1045 if(nIeta==0) nIeta2=1;
1047 absId2=GetAbsCellId(nSupMod,nModule,nIphi,nIeta2);
1048 if(nIphi==0) nIphi2=1;
1050 absId3=GetAbsCellId(nSupMod,nModule,nIphi2,nIeta);
1052 //2nd point on emcal cell plane
1053 if(!RelPosCellInSModule(absId2,loc2)) return;
1055 //3rd point on emcal cell plane
1056 if(!RelPosCellInSModule(absId3,loc3)) return;
1059 const TGeoHMatrix* m = GetMatrixForSuperModule(nSupMod);
1061 m->LocalToMaster(loc, glob);
1062 m->LocalToMaster(loc2, glob2);
1063 m->LocalToMaster(loc3, glob3);
1065 AliFatal("Geo matrixes are not loaded \n") ;
1068 //Equation of Plane from glob,glob2,glob3 (Ax+By+Cz+D=0)
1069 Double_t a = glob[1]*(glob2[2]-glob3[2]) + glob2[1]*(glob3[2]-glob[2]) + glob3[1]*(glob[2]-glob2[2]);
1070 Double_t b = glob[2]*(glob2[0]-glob3[0]) + glob2[2]*(glob3[0]-glob[0]) + glob3[2]*(glob[0]-glob2[0]);
1071 Double_t c = glob[0]*(glob2[1]-glob3[1]) + glob2[0]*(glob3[1]-glob[1]) + glob3[0]*(glob[1]-glob2[1]);
1072 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]);
1075 //shift equation of plane from tower/module center to surface along vector (A,B,C) normal to tower/module plane
1076 Double_t dist = fLongModuleSize/2.;
1077 Double_t norm = TMath::Sqrt(a*a+b*b+c*c);
1078 Double_t glob4[3]={};
1079 TVector3 dir(a,b,c);
1080 TVector3 point(glob[0],glob[1],glob[2]);
1081 if(point.Dot(dir)<0) dist*=-1;
1082 glob4[0]=glob[0]-dist*a/norm;
1083 glob4[1]=glob[1]-dist*b/norm;
1084 glob4[2]=glob[2]-dist*c/norm;
1085 d = glob4[0]*a + glob4[1]*b + glob4[2]*c ;
1088 //Line determination (2 points for equation of line : vtx and direction)
1089 //impact between line (particle) and plane (module/tower plane)
1090 Double_t den = a*(vtx(0)-direction(0)) + b*(vtx(1)-direction(1)) + c*(vtx(2)-direction(2));
1092 printf("ImpactOnEmcal() No solution :\n");
1096 Double_t length = a*vtx(0)+b*vtx(1)+c*vtx(2)+d;
1099 vimpact.SetXYZ(vtx(0)+length*(direction(0)-vtx(0)),vtx(1)+length*(direction(1)-vtx(1)),vtx(2)+length*(direction(2)-vtx(2)));
1101 //shift vimpact from tower/module surface to center along vector (A,B,C) normal to tower/module plane
1102 vimpact.SetXYZ(vimpact(0)+dist*a/norm,vimpact(1)+dist*b/norm,vimpact(2)+dist*c/norm);
1107 //_____________________________________________________________________________
1108 Bool_t AliEMCALGeometry::IsInEMCAL(Double_t x, Double_t y, Double_t z) const {
1109 // Checks whether point is inside the EMCal volume, used in AliEMCALv*.cxx
1111 // Code uses cylindrical approximation made of inner radius (for speed)
1113 // Points behind EMCAl, i.e. R > outer radius, but eta, phi in acceptance
1114 // are considered to inside
1116 Double_t r=sqrt(x*x+y*y);
1118 if ( r > fEnvelop[0] ) {
1120 theta = TMath::ATan2(r,z);
1125 eta = -TMath::Log(TMath::Tan(theta/2.));
1126 if (eta < fArm1EtaMin || eta > fArm1EtaMax)
1129 Double_t phi = TMath::ATan2(y,x) * 180./TMath::Pi();
1130 if (phi < 0) phi += 360; // phi should go from 0 to 360 in this case
1131 if (phi > fArm1PhiMin && phi < fArm1PhiMax)
1137 //________________________________________________________________________________________________
1138 Int_t AliEMCALGeometry::GetAbsTRUNumberFromNumberInSm(const Int_t row, const Int_t col, const Int_t sm) const
1140 // Get TRU absolute number from column, row and Super Module number
1141 Int_t itru = row + col*fEMCGeometry->GetNModulesInTRUPhi() + sm*fEMCGeometry->GetNTRU();
1142 // printf(" GetAbsTRUNumberFromNumberInSm : row %2i col %2i sm %2i -> itru %2i\n", row, col, sm, itru);
1146 //________________________________________________________________________________________________
1147 Bool_t AliEMCALGeometry::GetAbsFastORIndexFromTRU(const Int_t iTRU, const Int_t iADC, Int_t& id) const
1149 //Trigger mapping method, get FastOr Index from TRU
1151 if (iTRU > 31 || iTRU < 0 || iADC > 95 || iADC < 0)
1153 AliError("TRU out of range!");
1157 id = ( iTRU % 2 ) ? iADC%4 + 4 * (23 - int(iADC/4)) : (3 - iADC%4) + 4 * int(iADC/4);
1164 //________________________________________________________________________________________________
1165 Bool_t AliEMCALGeometry::GetTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iADC) const
1168 //Trigger mapping method, get TRU number from FastOr Index
1170 if (id > 3071 || id < 0)
1172 AliError("Id out of range!");
1180 iADC = ( iTRU % 2 ) ? iADC%4 + 4 * (23 - int(iADC/4)) : (3 - iADC%4) + 4 * int(iADC/4);
1185 //________________________________________________________________________________________________
1186 Bool_t AliEMCALGeometry::GetPositionInTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iEta, Int_t& iPhi) const
1188 //Trigger mapping method, get position in TRU from FasOr Index
1191 if (!GetTRUFromAbsFastORIndex(id, iTRU, iADC)) return kFALSE;
1196 if ( iTRU % 2 ) // C side
1210 //________________________________________________________________________________________________
1211 Bool_t AliEMCALGeometry::GetPositionInSMFromAbsFastORIndex(const Int_t id, Int_t& iSM, Int_t& iEta, Int_t& iPhi) const
1213 //Trigger mapping method, get position in Super Module from FasOr Index
1217 if (!GetPositionInTRUFromAbsFastORIndex(id, iTRU, iEta, iPhi)) return kFALSE;
1219 if (iTRU % 2) // C side
1221 iSM = 2 * ( int( int(iTRU / 2) / 3 ) ) + 1;
1225 iSM = 2 * ( int( int(iTRU / 2) / 3 ) );
1228 iPhi += 4 * int((iTRU % 6) / 2);
1233 //________________________________________________________________________________________________
1234 Bool_t AliEMCALGeometry::GetPositionInEMCALFromAbsFastORIndex(const Int_t id, Int_t& iEta, Int_t& iPhi) const
1236 //Trigger mapping method, get position in EMCAL from FastOR index
1240 if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi))
1242 if (iSM % 2) iEta += 24;
1244 iPhi += 12 * int(iSM / 2);
1252 //________________________________________________________________________________________________
1253 Bool_t AliEMCALGeometry::GetAbsFastORIndexFromPositionInTRU(const Int_t iTRU, const Int_t iEta, const Int_t iPhi, Int_t& id) const
1255 //Trigger mapping method, get Index if FastOr from Position in TRU
1257 if (iTRU < 0 || iTRU > 31 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 3)
1259 AliError("Out of range!");
1263 id = iPhi + 4 * iEta + iTRU * 96;
1268 //________________________________________________________________________________________________
1269 Bool_t AliEMCALGeometry::GetAbsFastORIndexFromPositionInSM(const Int_t iSM, const Int_t iEta, const Int_t iPhi, Int_t& id) const
1271 //Trigger mapping method, from position in SM Index get FastOR index
1273 if (iSM < 0 || iSM > 11 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 11)
1275 AliError("Out of range!");
1282 Int_t iOff = (iSM % 2) ? 1 : 0;
1283 Int_t iTRU = 2 * int(iPhi / 4) + 6 * int(iSM / 2) + iOff;
1285 if (GetAbsFastORIndexFromPositionInTRU(iTRU, x, y, id))
1293 //________________________________________________________________________________________________
1294 Bool_t AliEMCALGeometry::GetAbsFastORIndexFromPositionInEMCAL(const Int_t iEta, const Int_t iPhi, Int_t& id) const
1296 //Trigger mapping method, from position in EMCAL Index get FastOR index
1298 if (iEta < 0 || iEta > 47 || iPhi < 0 || iPhi > 63 )
1300 AliError("Out of range!");
1304 if (fFastOR2DMap[iEta][iPhi] == -1)
1306 AliError("Invalid index!");
1310 id = fFastOR2DMap[iEta][iPhi];
1315 //________________________________________________________________________________________________
1316 Bool_t AliEMCALGeometry::GetFastORIndexFromCellIndex(const Int_t id, Int_t& idx) const
1318 //Trigger mapping method, from cell index get FastOR index
1320 Int_t iSupMod, nModule, nIphi, nIeta, iphim, ietam;
1322 Bool_t isOK = GetCellIndex( id, iSupMod, nModule, nIphi, nIeta );
1324 GetModulePhiEtaIndexInSModule( iSupMod, nModule, iphim, ietam );
1326 if (isOK && GetAbsFastORIndexFromPositionInSM(iSupMod, ietam, iphim, idx))
1334 //________________________________________________________________________________________________
1335 Bool_t AliEMCALGeometry::GetCellIndexFromFastORIndex(const Int_t id, Int_t idx[4]) const
1337 //Trigger mapping method, from FASTOR index get cell index
1339 Int_t iSM=-1, iEta=-1, iPhi=-1;
1340 if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi))
1342 Int_t ix = 2 * iEta;
1343 Int_t iy = 2 * iPhi;
1345 for (Int_t i=0; i<2; i++)
1347 for (Int_t j=0; j<2; j++)
1349 idx[2*i+j] = GetAbsCellIdFromCellIndexes(iSM, iy + i, ix + j);
1359 //________________________________________________________________________________________________
1360 Bool_t AliEMCALGeometry::GetTRUIndexFromSTUIndex(const Int_t id, Int_t& idx) const
1362 //Trigger mapping method, from STU index get TRU index
1364 if (id > 31 || id < 0)
1366 AliError(Form("TRU index out of range: %d",id));
1370 idx = (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
1375 //________________________________________________________________________________________________
1376 Int_t AliEMCALGeometry::GetTRUIndexFromSTUIndex(const Int_t id) const
1378 //Trigger mapping method, from STU index get TRU index
1380 if (id > 31 || id < 0)
1382 AliError(Form("TRU index out of range: %d",id));
1385 Int_t idx = (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
1390 //________________________________________________________________________________________________
1391 void AliEMCALGeometry::BuildFastOR2DMap()
1394 for (Int_t i = 0; i < 32; i++)
1396 for (Int_t j = 0; j < 24; j++)
1398 for (Int_t k = 0; k < 4; k++)
1401 if (GetAbsFastORIndexFromPositionInTRU(i, j, k, id))
1403 Int_t x = j, y = k + 4 * int(i / 2);
1407 fFastOR2DMap[x][y] = id;
1414 //________________________________________________________________________________________________
1415 Bool_t AliEMCALGeometry::GetTRUIndexFromOnlineIndex(const Int_t id, Int_t& idx) const
1417 //Trigger mapping method, from STU index get TRU index
1419 if (id > 31 || id < 0)
1421 AliError(Form("TRU index out of range: %d",id));
1425 idx = ((id % 6) < 3) ? 6 * int(id / 6) + 2 * (id % 3) : 6 * int(id / 6) + 2 * (2 - (id % 3)) + 1;
1430 //________________________________________________________________________________________________
1431 Int_t AliEMCALGeometry::GetTRUIndexFromOnlineIndex(const Int_t id) const
1433 //Trigger mapping method, from STU index get TRU index
1435 if (id > 31 || id < 0)
1437 AliError(Form("TRU index out of range: %d",id));
1440 Int_t idx = (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
1445 //________________________________________________________________________________________________
1446 Bool_t AliEMCALGeometry::GetOnlineIndexFromTRUIndex(const Int_t id, Int_t& idx) const
1448 //Trigger mapping method, from STU index get TRU index
1450 if (id > 31 || id < 0)
1452 AliError(Form("TRU index out of range: %d",id));
1456 idx = (id % 2) ? int((6 - (id % 6)) / 2) + 3 * (int(id / 6) + 1) : 3 * int(id / 6) + int(id / 2);
1461 //________________________________________________________________________________________________
1462 Int_t AliEMCALGeometry::GetOnlineIndexFromTRUIndex(const Int_t id) const
1464 //Trigger mapping method, from STU index get TRU index
1466 if (id > 31 || id < 0)
1468 AliError(Form("TRU index out of range: %d",id));
1471 Int_t idx = (id % 2) ? int((6 - (id % 6)) / 2) + 3 * (int(id / 6) + 1) : 3 * int(id / 6) + int(id / 2);
1476 //________________________________________________________________________________________________
1477 Bool_t AliEMCALGeometry::GetFastORIndexFromL0Index(const Int_t iTRU, const Int_t id, Int_t idx[], const Int_t size) const
1479 //Trigger mapping method, from L0 index get FastOR index
1480 if (size <= 0 ||size > 4)
1482 AliError("Size not supported!");
1486 Int_t motif[4] = {0, 1, 4, 5};
1490 case 1: // Cosmic trigger
1491 if (!GetAbsFastORIndexFromTRU(iTRU, id, idx[1])) return kFALSE;
1494 for (Int_t k = 0; k < 4; k++)
1496 Int_t iADC = motif[k] + 4 * int(id / 3) + (id % 3);
1498 if (!GetAbsFastORIndexFromTRU(iTRU, iADC, idx[k])) return kFALSE;
1508 //____________________________________________________________________________
1509 const TGeoHMatrix * AliEMCALGeometry::GetMatrixForSuperModule(Int_t smod) const {
1511 //Provides shift-rotation matrix for EMCAL
1513 if(smod < 0 || smod > fEMCGeometry->GetNumberOfSuperModules())
1514 AliFatal(Form("Wrong supermodule index -> %d",smod));
1516 //If GeoManager exists, take matrixes from it
1519 // if(fKey110DEG && ind>=10) {
1522 // if(!gGeoManager->cd(volpath.Data()))
1523 // AliFatal(Form("AliEMCALGeometry::GeoManager cannot find path %s!",volpath.Data()));
1525 // TGeoHMatrix* m = gGeoManager->GetCurrentMatrix();
1527 //Use matrices set externally
1528 if(!gGeoManager || (gGeoManager && fUseExternalMatrices)){
1529 if(fkSModuleMatrix[smod]){
1530 return fkSModuleMatrix[smod] ;
1534 printf("\t Can not find EMCAL misalignment matrixes\n") ;
1535 printf("\t Either import TGeoManager from geometry.root or \n");
1536 printf("\t read stored matrixes from AliESD Header: \n") ;
1537 printf("\t AliEMCALGeometry::SetMisalMatrixes(header->GetEMCALMisalMatrix()) \n") ;
1540 }//external matrices
1543 const Int_t buffersize = 255;
1544 char path[buffersize] ;
1545 snprintf(path,buffersize,"/ALIC_1/XEN1_1/SMOD_%d",smod+1) ;
1546 //TString volpath = "ALIC_1/XEN1_1/SMOD_";
1547 //volpath += smod+1;
1549 if(fKey110DEG && smod >= 10){
1550 snprintf(path,buffersize,"/ALIC_1/XEN1_1/SM10_%d",smod-10+1) ;
1551 //volpath = "ALIC_1/XEN1_1/SM10_";
1552 //volpath += smod-10+1;
1554 if (!gGeoManager->cd(path)){
1555 AliFatal(Form("Geo manager can not find path %s!\n",path));
1557 return gGeoManager->GetCurrentMatrix();
1563 //______________________________________________________________________
1564 void AliEMCALGeometry::GetModulePhiEtaIndexInSModuleFromTRUIndex(Int_t itru, Int_t iphitru, Int_t ietatru, Int_t &iphiSM, Int_t &ietaSM) const
1567 // This method transforms the (eta,phi) index of module in a
1568 // TRU matrix into Super Module (eta,phi) index.
1570 // Calculate in which row and column where the TRU are
1571 // ordered in the SM
1573 Int_t col = itru/fEMCGeometry->GetNTRUPhi() ; // indexes of TRU in SM
1574 Int_t row = itru - col*fEMCGeometry->GetNTRUPhi();
1576 iphiSM = fEMCGeometry->GetNModulesInTRUPhi()*row + iphitru ;
1577 ietaSM = fEMCGeometry->GetNModulesInTRUEta()*col + ietatru ;
1580 //__________________________________________________________________________________________________________________
1581 void AliEMCALGeometry::RecalculateTowerPosition(Float_t drow, Float_t dcol, const Int_t sm, const Float_t depth,
1582 const Float_t misaligTransShifts[15], const Float_t misaligRotShifts[15], Float_t global[3]) const
1583 { //Transform clusters cell position into global with alternative method, taking into account the depth calculation.
1584 //Input are: the tower indeces,
1586 // particle type (photon 0, electron 1, hadron 2 )
1587 // misalignment shifts to global position in case of need.
1588 // Federico.Ronchetti@cern.ch
1591 // To use in a print later
1592 Float_t droworg = drow;
1593 Float_t dcolorg = dcol;
1596 //Recover some stuff
1598 const Int_t nSMod = fEMCGeometry->GetNumberOfSuperModules();
1600 gGeoManager->cd("ALIC_1/XEN1_1");
1601 TGeoNode *geoXEn1 = gGeoManager->GetCurrentNode();
1602 TGeoNodeMatrix *geoSM[nSMod];
1603 TGeoVolume *geoSMVol[nSMod];
1604 TGeoShape *geoSMShape[nSMod];
1605 TGeoBBox *geoBox[nSMod];
1606 TGeoMatrix *geoSMMatrix[nSMod];
1608 for(int iSM = 0; iSM < nSMod; iSM++) {
1609 geoSM[iSM] = dynamic_cast<TGeoNodeMatrix *>(geoXEn1->GetDaughter(iSM));
1610 geoSMVol[iSM] = geoSM[iSM]->GetVolume();
1611 geoSMShape[iSM] = geoSMVol[iSM]->GetShape();
1612 geoBox[iSM] = dynamic_cast<TGeoBBox *>(geoSMShape[iSM]);
1613 geoSMMatrix[iSM] = geoSM[iSM]->GetMatrix();
1626 Float_t x,y,z; // return variables in terry's RF
1628 //***********************************************************
1629 //Do not like this: too many hardcoded values, is it not already stored somewhere else?
1630 // : need more comments in the code
1631 //***********************************************************
1633 Float_t dz = 6.0; // base cell width in eta
1634 Float_t dx = 6.004; // base cell width in phi
1637 //Float_t L = 26.04; // active tower length for hadron (lead+scint+paper)
1638 // we use the geant numbers 13.87*2=27.74
1641 //Do some basic checks
1642 if (dcol >= 47.5 || dcol<-0.5) {
1643 AliError(Form("Bad tower coordinate dcol=%f, where dcol >= 47.5 || dcol<-0.5; org: %f", dcol, dcolorg));
1646 if (drow >= 23.5 || drow<-0.5) {
1647 AliError(Form("Bad tower coordinate drow=%f, where drow >= 23.5 || drow<-0.5; org: %f", drow, droworg));
1650 if (sm >= nSMod || sm < 0) {
1651 AliError(Form("Bad SM number sm=%d, where sm >= %d || sm < 0", nSMod, sm));
1655 istrip = int ((dcol+0.5)/2);
1658 teta1 = TMath::DegToRad() * istrip * 1.5;
1660 // calculation of module corner along z
1661 // as a function of strip
1663 for (int is=0; is<= istrip; is++) {
1665 teta1 = TMath::DegToRad() * (is*1.5 + 0.75);
1667 zIs = zIs + 2*dz*TMath::Cos(teta1);
1669 zIs = zIs + 2*dz*TMath::Cos(teta1) + 2*dz*TMath::Sin(teta1)*TMath::Tan(teta1-0.75*TMath::DegToRad());
1673 z0 = dz*(dcol-2*istrip+0.5);
1674 zb = (2*dz-z0-depth*TMath::Tan(teta1));
1676 z = zIs - zb*TMath::Cos(teta1);
1677 y = depth/TMath::Cos(teta1) + zb*TMath::Sin(teta1);
1679 x = (drow + 0.5)*dx;
1681 // moving the origin from terry's RF
1684 double xx = y - geoBox[sm]->GetDX();
1685 double yy = -x + geoBox[sm]->GetDY();
1686 double zz = z - geoBox[sm]->GetDZ();
1687 const double localIn[3] = {xx, yy, zz};
1689 //geoSMMatrix[sm]->Print();
1690 //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]);
1691 geoSMMatrix[sm]->LocalToMaster(localIn, dglobal);
1692 //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]);
1694 //apply global shifts
1695 if(sm == 2 || sm == 3) {//sector 1
1696 global[0] = dglobal[0] + misaligTransShifts[3] + misaligRotShifts[3]*TMath::Sin(TMath::DegToRad()*20) ;
1697 global[1] = dglobal[1] + misaligTransShifts[4] + misaligRotShifts[4]*TMath::Cos(TMath::DegToRad()*20) ;
1698 global[2] = dglobal[2] + misaligTransShifts[5];
1700 else if(sm == 0 || sm == 1){//sector 0
1701 global[0] = dglobal[0] + misaligTransShifts[0];
1702 global[1] = dglobal[1] + misaligTransShifts[1];
1703 global[2] = dglobal[2] + misaligTransShifts[2];
1706 AliInfo("Careful, correction not implemented yet!");
1707 global[0] = dglobal[0] ;
1708 global[1] = dglobal[1] ;
1709 global[2] = dglobal[2] ;
1715 AliFatal("Geometry boxes information, check that geometry.root is loaded\n");
1720 void AliEMCALGeometry::SetMisalMatrix(const TGeoHMatrix * m, Int_t smod)
1722 // Method to set shift-rotational matrixes from ESDHeader
1723 // Move from header due to coding violations : Dec 2,2011 by PAI
1724 fUseExternalMatrices = kTRUE;
1726 if (smod >= 0 && smod < fEMCGeometry->GetNumberOfSuperModules()){
1727 if(!fkSModuleMatrix[smod]) fkSModuleMatrix[smod] = new TGeoHMatrix(*m) ; //Set only if not set yet
1728 } else AliFatal(Form("Wrong supermodule index -> %d",smod));