Update on trigger code (Rachid)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGeoUtils.cxx
CommitLineData
0c5b726e 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id: AliEMCALGeoUtils.cxx 25590 2008-05-06 07:09:11Z prsnko $ */
17
18//_________________________________________________________________________
19// Geometry class for EMCAL : singleton
20//
21// -- Author: Magali Estienne (magali.estienne@subatech.in2p3.fr)
22
23//
24// Usage:
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.
28//
29// AliEMCALGeoUtils* geom = new AliEMCALGeoUtils("EMCAL_COMPLETE","EMCAL");
30// TGeoManager::Import("geometry.root");
31//
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");
38
39
40// --- ROOT system ---
41
42#include <TParticle.h>
43#include <TGeoManager.h>
44#include <TGeoMatrix.h>
45#include <TList.h>
46#include <TBrowser.h>
47
48// --- Standard library ---
49//#include <Riostream.h>
50
51// --- AliRoot header files ---
52#include "AliEMCALGeoUtils.h"
53#include "AliEMCALShishKebabTrd1Module.h"
54
55ClassImp(AliEMCALGeoUtils)
56
57//____________________________________________________________________________
58AliEMCALGeoUtils::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.)
70{
71 // default ctor
72 // must be kept public for root persistency purposes, but should never be called by the outside world
73 fEnvelop[0] = 0.;
74 fEnvelop[1] = 0.;
75 fEnvelop[2] = 0.;
fa911ba9 76 for(Int_t i=0;i<12;i++)fkSModuleMatrix[i]=0 ;
0c5b726e 77
de39a0ff 78 for (Int_t i = 0; i < 48; i++)
79 for (Int_t j = 0; j < 64; j++) fFastOR2DMap[i][j] = -1;
0c5b726e 80}
81
82//____________________________________________________________________________
83AliEMCALGeoUtils::AliEMCALGeoUtils(const AliEMCALGeoUtils & geo)
84 : TNamed(geo),
85 fEMCGeometry(geo.fEMCGeometry),fGeoName(geo.fGeoName),
86 fKey110DEG(geo.fKey110DEG),fNCellsInSupMod(geo.fNCellsInSupMod),fNETAdiv(geo.fNETAdiv),fNPHIdiv(geo.fNPHIdiv),
87 fNCellsInModule(geo.fNCellsInModule),fPhiBoundariesOfSM(geo.fPhiBoundariesOfSM),fPhiCentersOfSM(geo.fPhiCentersOfSM),
88 fPhiCentersOfCells(geo.fPhiCentersOfCells),fCentersOfCellsEtaDir(geo.fCentersOfCellsEtaDir),
89 fCentersOfCellsPhiDir(geo.fCentersOfCellsPhiDir),fEtaCentersOfCells(geo.fEtaCentersOfCells),
90 fNCells(geo.fNCells),fNPhi(geo.fNPhi),fCentersOfCellsXDir(geo.fCentersOfCellsXDir),fArm1EtaMin(geo.fArm1EtaMin),
91 fArm1EtaMax(geo.fArm1EtaMax),fArm1PhiMin(geo.fArm1PhiMin),fArm1PhiMax(geo.fArm1PhiMax),fEtaMaxOfTRD1(geo.fEtaMaxOfTRD1),
92 fShishKebabTrd1Modules(geo.fShishKebabTrd1Modules),fParSM(geo.fParSM),fPhiModuleSize(geo.fPhiModuleSize),
93 fEtaModuleSize(geo.fEtaModuleSize),fPhiTileSize(geo.fPhiTileSize),fEtaTileSize(geo.fEtaTileSize),fNZ(geo.fNZ),
94 fIPDistance(geo.fIPDistance),fLongModuleSize(geo.fLongModuleSize),fShellThickness(geo.fShellThickness),
95 fZLength(geo.fZLength),fSampling(geo.fSampling)
96{
97 fEnvelop[0] = geo.fEnvelop[0];
98 fEnvelop[1] = geo.fEnvelop[1];
99 fEnvelop[2] = geo.fEnvelop[2];
fa911ba9 100 for(Int_t i=0;i<12;i++)fkSModuleMatrix[i]=0 ;
de39a0ff 101
102 for (Int_t i = 0; i < 48; i++)
103 for (Int_t j = 0; j < 64; j++) fFastOR2DMap[i][j] = geo.fFastOR2DMap[i][j];
0c5b726e 104}
105
106//____________________________________________________________________________
107AliEMCALGeoUtils::AliEMCALGeoUtils(const Text_t* name, const Text_t* title)
108 : TNamed(name, title),
109 fEMCGeometry(0x0),fGeoName(0),
110 fKey110DEG(0),fNCellsInSupMod(0),fNETAdiv(0),fNPHIdiv(0),
111 fNCellsInModule(0),fPhiBoundariesOfSM(0x0),fPhiCentersOfSM(0x0),
112 fPhiCentersOfCells(0x0),fCentersOfCellsEtaDir(0x0),
113 fCentersOfCellsPhiDir(0x0),fEtaCentersOfCells(0x0),
114 fNCells(0),fNPhi(0),fCentersOfCellsXDir(0x0),fArm1EtaMin(0),
115 fArm1EtaMax(0),fArm1PhiMin(0),fArm1PhiMax(0),fEtaMaxOfTRD1(0),
116 fShishKebabTrd1Modules(0),fParSM(0x0),fPhiModuleSize(0.),
117 fEtaModuleSize(0.),fPhiTileSize(0.),fEtaTileSize(0.),fNZ(0),
118 fIPDistance(0.),fLongModuleSize(0.),fShellThickness(0.),
119 fZLength(0.),fSampling(0.)
120{
121
122 // ctor only for normal usage
123
124 fEMCGeometry = new AliEMCALEMCGeometry(name,title);
125
126 fGeoName = fEMCGeometry->GetGeoName();
127 fKey110DEG = fEMCGeometry->GetKey110DEG();
128 fNCellsInSupMod = fEMCGeometry->GetNCellsInSupMod();
129 fNETAdiv = fEMCGeometry->GetNETAdiv();
130 fNPHIdiv = fEMCGeometry->GetNPHIdiv();
131 fNCellsInModule = fNPHIdiv*fNETAdiv;
53e430a3 132 static int i=0;
0c5b726e 133 Int_t nSMod = fEMCGeometry->GetNumberOfSuperModules();
134 fPhiBoundariesOfSM.Set(nSMod);
135 fPhiCentersOfSM.Set(nSMod/2);
136 for(Int_t sm=0; sm<nSMod; sm++) {
137 i = sm/2;
138 fEMCGeometry->GetPhiBoundariesOfSM(sm,fPhiBoundariesOfSM[2*i],fPhiBoundariesOfSM[2*i+1]);
139 }
140
141 Double_t phiMin = 0.;
142 Double_t phiMax = 0.;
143 for(Int_t sm=0; sm<nSMod; sm++) {
144 fEMCGeometry->GetPhiBoundariesOfSM(sm,phiMin,phiMax);
53e430a3 145 i=sm/2;
0c5b726e 146 fPhiCentersOfSM[i] = fEMCGeometry->GetPhiCenterOfSM(sm);
147 }
148 fNCells = fEMCGeometry->GetNCells();
149 fNPhi = fEMCGeometry->GetNPhi();
150 fEnvelop[0] = fEMCGeometry->GetEnvelop(0);
151 fEnvelop[1] = fEMCGeometry->GetEnvelop(1);
152 fEnvelop[2] = fEMCGeometry->GetEnvelop(2);
153 fArm1EtaMin = fEMCGeometry->GetArm1EtaMin();
154 fArm1EtaMax = fEMCGeometry->GetArm1EtaMax();
155 fArm1PhiMin = fEMCGeometry->GetArm1PhiMin();
156 fArm1PhiMax = fEMCGeometry->GetArm1PhiMax();
157 fShellThickness = fEMCGeometry->GetShellThickness();
158 fZLength = fEMCGeometry->GetZLength();
159 fSampling = fEMCGeometry->GetSampling();
160 fParSM = fEMCGeometry->GetSuperModulesPars();
161 fEtaModuleSize = fEMCGeometry->GetEtaModuleSize();
162 fPhiModuleSize = fEMCGeometry->GetPhiModuleSize();
163 fEtaTileSize = fEMCGeometry->GetEtaTileSize();
164 fPhiTileSize = fEMCGeometry->GetPhiTileSize();
165 fNZ = fEMCGeometry->GetNZ();
166 fIPDistance = fEMCGeometry->GetIPDistance();
167 fLongModuleSize = fEMCGeometry->GetLongModuleSize();
168
169 CreateListOfTrd1Modules();
170
171 for(Int_t smod=0; smod < fEMCGeometry->GetNumberOfSuperModules(); smod++)
172 fkSModuleMatrix[smod]=0 ;
173
174 if (AliDebugLevel()>=2) {
175 fEMCGeometry->Print();
176 PrintGeometry();
177 }
178
de39a0ff 179 for (Int_t ix = 0; ix < 48; ix++)
180 for (Int_t jx = 0; jx < 64; jx++) fFastOR2DMap[ix][jx] = -1;
181
182 BuildFastOR2DMap();
0c5b726e 183}
184
185//____________________________________________________________________________
186AliEMCALGeoUtils & AliEMCALGeoUtils::operator = (const AliEMCALGeoUtils & /*rvalue*/) {
187
188 Fatal("assignment operator", "not implemented") ;
189 return *this ;
190}
191
192//____________________________________________________________________________
193AliEMCALGeoUtils::~AliEMCALGeoUtils(void)
194{
195 // dtor
fa911ba9 196 for(Int_t smod = 0 ; smod < fEMCGeometry->GetNumberOfSuperModules(); smod++){
197 if(fkSModuleMatrix[smod])
198 delete fkSModuleMatrix[smod] ;
199 fkSModuleMatrix[smod]=0 ;
200 }
0c5b726e 201 if(fEMCGeometry){
202 delete fEMCGeometry; fEMCGeometry = 0 ;
203 }
204}
205
206
207//________________________________________________________________________________________________
208void AliEMCALGeoUtils::Browse(TBrowser* b)
209{
210 //Browse the modules
211 if(fShishKebabTrd1Modules) b->Add(fShishKebabTrd1Modules);
212}
213
214//________________________________________________________________________________________________
215Bool_t AliEMCALGeoUtils::IsFolder() const
216{
217 //Check if fShishKebabTrd1Modules is in folder
218 if(fShishKebabTrd1Modules) return kTRUE;
219 else return kFALSE;
220}
221
222//________________________________________________________________________________________________
223void AliEMCALGeoUtils::GetGlobal(const Double_t *loc, Double_t *glob, int ind) const
224{
225 // Figure out the global numbering
226 // of a given supermodule from the
227 // local numbering and the transformation
228 // matrix stored by the geometry manager (allows for misaligned
229 // geometry)
0c5b726e 230
231 const TGeoHMatrix* m = GetMatrixForSuperModule(ind);
232 if(m) {
233 m->LocalToMaster(loc, glob);
234 } else {
235 AliFatal("Geo matrixes are not loaded \n") ;
236 }
0c5b726e 237}
238
239//________________________________________________________________________________________________
240void AliEMCALGeoUtils::GetGlobal(const TVector3 &vloc, TVector3 &vglob, int ind) const
241{
242 //Figure out the global numbering
243 //of a given supermodule from the
244 //local numbering given a 3-vector location
245
246 static Double_t tglob[3], tloc[3];
247 vloc.GetXYZ(tloc);
248 GetGlobal(tloc, tglob, ind);
249 vglob.SetXYZ(tglob[0], tglob[1], tglob[2]);
250}
251
252//________________________________________________________________________________________________
253void AliEMCALGeoUtils::GetGlobal(Int_t absId , double glob[3]) const
254{
255 // Alice numbering scheme - Jun 03, 2006
de39a0ff 256 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
0c5b726e 257 static double loc[3];
258
0c5b726e 259 glob[0]=glob[1]=glob[2]=0.0; // bad case
260 if(RelPosCellInSModule(absId, loc)) {
261 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
262
0c5b726e 263 const TGeoHMatrix* m = GetMatrixForSuperModule(nSupMod);
264 if(m) {
265 m->LocalToMaster(loc, glob);
266 } else {
267 AliFatal("Geo matrixes are not loaded \n") ;
268 }
269 }
270}
271
272//___________________________________________________________________
273void AliEMCALGeoUtils::GetGlobal(Int_t absId , TVector3 &vglob) const
274{
275 // Alice numbering scheme - Jun 03, 2006
276 static Double_t glob[3];
277
278 GetGlobal(absId, glob);
279 vglob.SetXYZ(glob[0], glob[1], glob[2]);
280
281}
282
283
284//______________________________________________________________________
285void AliEMCALGeoUtils::PrintCellIndexes(Int_t absId, int pri, const char *tit) const
286{
287 // Service methods
de39a0ff 288 Int_t nSupMod, nModule, nIphi, nIeta;
289 Int_t iphi, ieta;
0c5b726e 290 TVector3 vg;
291
292 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
293 printf(" %s | absId : %i -> nSupMod %i nModule %i nIphi %i nIeta %i \n", tit, absId, nSupMod, nModule, nIphi, nIeta);
294 if(pri>0) {
295 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
296 printf(" local SM index : iphi %i : ieta %i \n", iphi,ieta);
297 GetGlobal(absId, vg);
298 printf(" vglob : mag %7.2f : perp %7.2f : z %7.2f : eta %6.4f : phi %6.4f(%6.2f) \n",
299 vg.Mag(), vg.Perp(), vg.Z(), vg.Eta(), vg.Phi(), vg.Phi()*TMath::RadToDeg());
300 }
301}
302
303//________________________________________________________________________________________________
304void AliEMCALGeoUtils::EtaPhiFromIndex(Int_t absId,Double_t &eta,Double_t &phi) const
305{
306 // Nov 16, 2006- float to double
307 // version for TRD1 only
308 static TVector3 vglob;
309 GetGlobal(absId, vglob);
310 eta = vglob.Eta();
311 phi = vglob.Phi();
312}
313
314//________________________________________________________________________________________________
315void AliEMCALGeoUtils::EtaPhiFromIndex(Int_t absId,Float_t &eta,Float_t &phi) const
316{
317 // Nov 16,2006 - should be discard in future
318 static TVector3 vglob;
319 GetGlobal(absId, vglob);
320 eta = float(vglob.Eta());
321 phi = float(vglob.Phi());
322}
323
324//
325// == Shish-kebab cases ==
326//
327//________________________________________________________________________________________________
328Int_t AliEMCALGeoUtils::GetAbsCellId(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta) const
329{
330 // 27-aug-04;
331 // corr. 21-sep-04;
332 // 13-oct-05; 110 degree case
333 // May 31, 2006; ALICE numbering scheme:
334 // 0 <= nSupMod < fNumberOfSuperModules
335 // 0 <= nModule < fNPHI * fNZ ( fNPHI * fNZ/2 for fKey110DEG=1)
336 // 0 <= nIphi < fNPHIdiv
337 // 0 <= nIeta < fNETAdiv
338 // 0 <= absid < fNCells
339 static Int_t id=0; // have to change from 0 to fNCells-1
340 if(fKey110DEG == 1 && nSupMod >= 10) { // 110 degree case; last two supermodules
341 id = fNCellsInSupMod*10 + (fNCellsInSupMod/2)*(nSupMod-10);
342 } else {
343 id = fNCellsInSupMod*nSupMod;
344 }
345 id += fNCellsInModule *nModule;
346 id += fNPHIdiv *nIphi;
347 id += nIeta;
348 if(id<0 || id >= fNCells) {
349// printf(" wrong numerations !!\n");
350// printf(" id %6i(will be force to -1)\n", id);
351// printf(" fNCells %6i\n", fNCells);
352// printf(" nSupMod %6i\n", nSupMod);
353// printf(" nModule %6i\n", nModule);
354// printf(" nIphi %6i\n", nIphi);
355// printf(" nIeta %6i\n", nIeta);
356 id = -TMath::Abs(id); // if negative something wrong
357 }
358 return id;
359}
360
361//________________________________________________________________________________________________
362void AliEMCALGeoUtils::GetModuleIndexesFromCellIndexesInSModule(Int_t nSupMod, Int_t iphi, Int_t ieta,
363 Int_t &iphim, Int_t &ietam, Int_t &nModule) const
364{
365 // Transition from cell indexes (ieta,iphi) to module indexes (ietam,iphim, nModule)
de39a0ff 366 static Int_t nphi=-1;
0c5b726e 367 nphi = GetNumberOfModuleInPhiDirection(nSupMod);
368
369 ietam = ieta/fNETAdiv;
370 iphim = iphi/fNPHIdiv;
371 nModule = ietam * nphi + iphim;
372}
373
374//________________________________________________________________________________________________
375Int_t AliEMCALGeoUtils::GetAbsCellIdFromCellIndexes(Int_t nSupMod, Int_t iphi, Int_t ieta) const
376{
377 // Transition from super module number(nSupMod) and cell indexes (ieta,iphi) to absId
53e430a3 378 static Int_t ietam=-1, iphim=-1, nModule=-1;
379 static Int_t nIeta=-1, nIphi=-1; // cell indexes in module
0c5b726e 380
381 GetModuleIndexesFromCellIndexesInSModule(nSupMod, iphi, ieta, ietam, iphim, nModule);
382
383 nIeta = ieta%fNETAdiv;
384 nIeta = fNETAdiv - 1 - nIeta;
385 nIphi = iphi%fNPHIdiv;
386
387 return GetAbsCellId(nSupMod, nModule, nIphi, nIeta);
388}
389
390//________________________________________________________________________________________________
391Bool_t AliEMCALGeoUtils::SuperModuleNumberFromEtaPhi(Double_t eta, Double_t phi, Int_t &nSupMod) const
392{
393 // Return false if phi belongs a phi cracks between SM
394
53e430a3 395 static Int_t i=0;
0c5b726e 396
397 if(TMath::Abs(eta) > fEtaMaxOfTRD1) return kFALSE;
398
399 phi = TVector2::Phi_0_2pi(phi); // move phi to (0,2pi) boundaries
400 for(i=0; i<6; i++) {
39ea291a 401
402 //Check if it is not the complete geometry
403 if (i >= fEMCGeometry->GetNumberOfSuperModules()/2) return kFALSE;
404
0c5b726e 405 if(phi>=fPhiBoundariesOfSM[2*i] && phi<=fPhiBoundariesOfSM[2*i+1]) {
406 nSupMod = 2*i;
407 if(eta < 0.0) nSupMod++;
408 AliDebug(1,Form("eta %f phi %f(%5.2f) : nSupMod %i : #bound %i", eta,phi,phi*TMath::RadToDeg(), nSupMod,i));
409 return kTRUE;
410 }
411 }
412 return kFALSE;
413}
414
415
416//________________________________________________________________________________________________
417Bool_t AliEMCALGeoUtils::GetAbsCellIdFromEtaPhi(Double_t eta, Double_t phi, Int_t &absId) const
418{
419 // Nov 17,2006
420 // stay here - phi problem as usual
de39a0ff 421 static Int_t nSupMod=-1, i=0, ieta=-1, iphi=-1, etaShift=0, nphi=-1;
422 static Double_t absEta=0.0, d=0.0, dmin=0.0, phiLoc=0;
0c5b726e 423 absId = nSupMod = - 1;
424 if(SuperModuleNumberFromEtaPhi(eta, phi, nSupMod)) {
425 // phi index first
426 phi = TVector2::Phi_0_2pi(phi);
427 phiLoc = phi - fPhiCentersOfSM[nSupMod/2];
428 nphi = fPhiCentersOfCells.GetSize();
429 if(nSupMod>=10) {
430 phiLoc = phi - 190.*TMath::DegToRad();
431 nphi /= 2;
432 }
433
434 dmin = TMath::Abs(fPhiCentersOfCells[0]-phiLoc);
435 iphi = 0;
436 for(i=1; i<nphi; i++) {
437 d = TMath::Abs(fPhiCentersOfCells[i] - phiLoc);
438 if(d < dmin) {
439 dmin = d;
440 iphi = i;
441 }
442 // printf(" i %i : d %f : dmin %f : fPhiCentersOfCells[i] %f \n", i, d, dmin, fPhiCentersOfCells[i]);
443 }
444 // odd SM are turned with respect of even SM - reverse indexes
445 AliDebug(2,Form(" iphi %i : dmin %f (phi %f, phiLoc %f ) ", iphi, dmin, phi, phiLoc));
446 // eta index
447 absEta = TMath::Abs(eta);
448 etaShift = iphi*fCentersOfCellsEtaDir.GetSize();
449 dmin = TMath::Abs(fEtaCentersOfCells[etaShift]-absEta);
450 ieta = 0;
451 for(i=1; i<fCentersOfCellsEtaDir.GetSize(); i++) {
452 d = TMath::Abs(fEtaCentersOfCells[i+etaShift] - absEta);
453 if(d < dmin) {
454 dmin = d;
455 ieta = i;
456 }
457 }
458 AliDebug(2,Form(" ieta %i : dmin %f (eta=%f) : nSupMod %i ", ieta, dmin, eta, nSupMod));
459
460 if(eta<0) iphi = (nphi-1) - iphi;
02194d2d 461
462 //patch for mapping following alice convention
463 if(nSupMod%2 == 0)
464 ieta = (fCentersOfCellsEtaDir.GetSize()-1)-ieta;// 47-ieta, revert the ordering on A side in order to keep convention.
465 else {
466 if(nSupMod<10)
467 iphi = (fCentersOfCellsPhiDir.GetSize()-1) -iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
468 else
469 iphi = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
470 }
471
0c5b726e 472 absId = GetAbsCellIdFromCellIndexes(nSupMod, iphi, ieta);
473
474 return kTRUE;
475 }
476 return kFALSE;
477}
478
479//________________________________________________________________________________________________
480Bool_t AliEMCALGeoUtils::CheckAbsCellId(Int_t absId) const
481{
482 // May 31, 2006; only trd1 now
483 if(absId<0 || absId >= fNCells) return kFALSE;
484 else return kTRUE;
485}
486
487//________________________________________________________________________________________________
488Bool_t AliEMCALGeoUtils::GetCellIndex(Int_t absId,Int_t &nSupMod,Int_t &nModule,Int_t &nIphi,Int_t &nIeta) const
489{
490 // 21-sep-04; 19-oct-05;
491 // May 31, 2006; ALICE numbering scheme:
492 //
493 // In:
494 // absId - cell is as in Geant, 0<= absId < fNCells;
495 // Out:
496 // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
497 // nModule - module number in SM, 0<= nModule < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
498 // nIphi - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv;
499 // nIeta - cell number in eta driection inside module; 0<= nIeta < fNETAdiv;
500 //
501 static Int_t tmp=0, sm10=0;
502 if(!CheckAbsCellId(absId)) return kFALSE;
503
504 sm10 = fNCellsInSupMod*10;
505 if(fKey110DEG == 1 && absId >= sm10) { // 110 degree case; last two supermodules
506 nSupMod = (absId-sm10) / (fNCellsInSupMod/2) + 10;
507 tmp = (absId-sm10) % (fNCellsInSupMod/2);
508 } else {
509 nSupMod = absId / fNCellsInSupMod;
510 tmp = absId % fNCellsInSupMod;
511 }
512
513 nModule = tmp / fNCellsInModule;
514 tmp = tmp % fNCellsInModule;
515 nIphi = tmp / fNPHIdiv;
516 nIeta = tmp % fNPHIdiv;
517
518 return kTRUE;
519}
520
521//________________________________________________________________________________________________
522Int_t AliEMCALGeoUtils::GetSuperModuleNumber(Int_t absId) const
523{
524 // Return the number of the supermodule given the absolute
525 // ALICE numbering id
526
de39a0ff 527 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
0c5b726e 528 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
529 return nSupMod;
530}
531
532//________________________________________________________________________________________________
533void AliEMCALGeoUtils::GetModulePhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, int &iphim, int &ietam) const
534{
535 // added nSupMod; - 19-oct-05 !
536 // Alice numbering scheme - Jun 01,2006
537 // ietam, iphi - indexes of module in two dimensional grid of SM
538 // ietam - have to change from 0 to fNZ-1
539 // iphim - have to change from 0 to nphi-1 (fNPhi-1 or fNPhi/2-1)
de39a0ff 540 static Int_t nphi=-1;
0c5b726e 541
542 if(fKey110DEG == 1 && nSupMod>=10) nphi = fNPhi/2;
543 else nphi = fNPhi;
544
545 ietam = nModule/nphi;
546 iphim = nModule%nphi;
547}
548
549//________________________________________________________________________________________________
550void AliEMCALGeoUtils::GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta,
551int &iphi, int &ieta) const
552{
553 //
554 // Added nSupMod; Nov 25, 05
555 // Alice numbering scheme - Jun 01,2006
556 // IN:
557 // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
558 // nModule - module number in SM, 0<= nModule < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
559 // nIphi - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv;
560 // nIeta - cell number in eta driection inside module; 0<= nIeta < fNETAdiv;
561 //
562 // OUT:
563 // ieta, iphi - indexes of cell(tower) in two dimensional grid of SM
564 // ieta - have to change from 0 to (fNZ*fNETAdiv-1)
565 // iphi - have to change from 0 to (fNPhi*fNPHIdiv-1 or fNPhi*fNPHIdiv/2-1)
566 //
53e430a3 567 static Int_t iphim=-1, ietam=-1;
0c5b726e 568
569 GetModulePhiEtaIndexInSModule(nSupMod,nModule, iphim, ietam);
570 // ieta = ietam*fNETAdiv + (1-nIeta); // x(module) = -z(SM)
571 ieta = ietam*fNETAdiv + (fNETAdiv - 1 - nIeta); // x(module) = -z(SM)
572 iphi = iphim*fNPHIdiv + nIphi; // y(module) = y(SM)
573
574 if(iphi<0 || ieta<0)
575 AliDebug(1,Form(" nSupMod %i nModule %i nIphi %i nIeta %i => ieta %i iphi %i\n",
576 nSupMod, nModule, nIphi, nIeta, ieta, iphi));
577}
578
579
580// Methods for AliEMCALRecPoint - Feb 19, 2006
581//________________________________________________________________________________________________
582Bool_t AliEMCALGeoUtils::RelPosCellInSModule(Int_t absId, Double_t &xr, Double_t &yr, Double_t &zr) const
583{
584 // Look to see what the relative
585 // position inside a given cell is
586 // for a recpoint.
587 // Alice numbering scheme - Jun 08, 2006
588 // In:
589 // absId - cell is as in Geant, 0<= absId < fNCells;
590 // OUT:
591 // xr,yr,zr - x,y,z coordinates of cell with absId inside SM
592
593 // Shift index taking into account the difference between standard SM
594 // and SM of half size in phi direction
595 const Int_t kphiIndexShift = fCentersOfCellsPhiDir.GetSize()/4; // Nov 22, 2006; was 6 for cas 2X2
de39a0ff 596 static Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
0c5b726e 597 if(!CheckAbsCellId(absId)) return kFALSE;
598
599 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
600 GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi, ieta);
dd91d8ac 601
f8a955ba 602 //Get eta position. Careful with ALICE conventions (increase index decrease eta)
603 Int_t ieta2 = ieta;
604 if(nSupMod%2 == 0)
605 ieta2 = (fCentersOfCellsEtaDir.GetSize()-1)-ieta;// 47-ieta, revert the ordering on A side in order to keep convention.
606 zr = fCentersOfCellsEtaDir.At(ieta2);
607 xr = fCentersOfCellsXDir.At(ieta2);
608
609 //Get phi position. Careful with ALICE conventions (increase index increase phi)
dd91d8ac 610 Int_t iphi2 = iphi;
dd91d8ac 611 if(nSupMod<10) {
612 if(nSupMod%2 != 0)
613 iphi2 = (fCentersOfCellsPhiDir.GetSize()-1)-iphi;// 23-iphi, revert the ordering on C side in order to keep convention.
614 yr = fCentersOfCellsPhiDir.At(iphi2);
615
0c5b726e 616 } else {
dd91d8ac 617 if(nSupMod%2 != 0)
618 iphi2 = (fCentersOfCellsPhiDir.GetSize()/2-1)-iphi;// 11-iphi, revert the ordering on C side in order to keep convention.
619 yr = fCentersOfCellsPhiDir.At(iphi2 + kphiIndexShift);
0c5b726e 620 }
621 AliDebug(1,Form("absId %i nSupMod %i iphi %i ieta %i xr %f yr %f zr %f ",absId,nSupMod,iphi,ieta,xr,yr,zr));
622
623 return kTRUE;
624}
625
626//________________________________________________________________________________________________
627Bool_t AliEMCALGeoUtils::RelPosCellInSModule(Int_t absId, Double_t loc[3]) const
628{
629 // Look to see what the relative
630 // position inside a given cell is
631 // for a recpoint. // Alice numbering scheme - Jun 03, 2006
632 loc[0] = loc[1] = loc[2]=0.0;
633 if(RelPosCellInSModule(absId, loc[0],loc[1],loc[2])) {
634 return kTRUE;
635 }
636 return kFALSE;
637}
638
639//________________________________________________________________________________________________
640Bool_t AliEMCALGeoUtils::RelPosCellInSModule(Int_t absId, TVector3 &vloc) const
641{
642 // Look to see what the relative
643 // position inside a given cell is
644 // for a recpoint.
645 // Alice numbering scheme - Jun 03, 2006
646 static Double_t loc[3];
647 if(RelPosCellInSModule(absId,loc)) {
648 vloc.SetXYZ(loc[0], loc[1], loc[2]);
649 return kTRUE;
650 } else {
651 vloc.SetXYZ(0,0,0);
652 return kFALSE;
653 }
654}
655
656//________________________________________________________________________________________________
657void AliEMCALGeoUtils::CreateListOfTrd1Modules()
658{
659 // Generate the list of Trd1 modules
660 // which will make up the EMCAL
661 // geometry
662
663 AliDebug(2,Form(" AliEMCALGeometry::CreateListOfTrd1Modules() started "));
664
665 AliEMCALShishKebabTrd1Module *mod=0, *mTmp=0; // current module
666 if(fShishKebabTrd1Modules == 0) {
667 fShishKebabTrd1Modules = new TList;
668 fShishKebabTrd1Modules->SetName("ListOfTRD1");
669 for(int iz=0; iz< fEMCGeometry->GetNZ(); iz++) {
670 if(iz==0) {
671 // mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,this);
672 mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,fEMCGeometry);
673 } else {
674 mTmp = new AliEMCALShishKebabTrd1Module(*mod);
675 mod = mTmp;
676 }
677 fShishKebabTrd1Modules->Add(mod);
678 }
679 } else {
680 AliDebug(2,Form(" Already exits : "));
681 }
682 mod = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(fShishKebabTrd1Modules->GetSize()-1);
683 fEtaMaxOfTRD1 = mod->GetMaxEtaOfModule(0);
684
685 AliDebug(2,Form(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
686 fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1));
687 // Feb 20,2006;
688 // Jun 01, 2006 - ALICE numbering scheme
689 // define grid for cells in eta(z) and x directions in local coordinates system of SM
690 // Works just for 2x2 case only -- ?? start here
691 //
692 //
693 // Define grid for cells in phi(y) direction in local coordinates system of SM
694 // as for 2X2 as for 3X3 - Nov 8,2006
695 //
696 AliDebug(2,Form(" Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize()));
697 Int_t ind=0; // this is phi index
698 Int_t ieta=0, nModule=0, iphiTemp;
699 Double_t xr=0., zr=0., theta=0., phi=0., eta=0., r=0., x=0.,y=0.;
700 TVector3 vglob;
701 Double_t ytCenterModule=0.0, ytCenterCell=0.0;
702
703 fCentersOfCellsPhiDir.Set(fNPhi*fNPHIdiv);
704 fPhiCentersOfCells.Set(fNPhi*fNPHIdiv);
705
706 Double_t r0 = fIPDistance + fLongModuleSize/2.;
707 for(Int_t it=0; it<fNPhi; it++) { // cycle on modules
708 ytCenterModule = -fParSM[1] + fPhiModuleSize*(2*it+1)/2; // center of module
709 for(Int_t ic=0; ic<fNPHIdiv; ic++) { // cycle on cells in module
710 if(fNPHIdiv==2) {
711 ytCenterCell = ytCenterModule + fPhiTileSize *(2*ic-1)/2.;
712 } else if(fNPHIdiv==3){
713 ytCenterCell = ytCenterModule + fPhiTileSize *(ic-1);
714 } else if(fNPHIdiv==1){
715 ytCenterCell = ytCenterModule;
716 }
717 fCentersOfCellsPhiDir.AddAt(ytCenterCell,ind);
718 // Define grid on phi direction
719 // Grid is not the same for different eta bin;
720 // Effect is small but is still here
721 phi = TMath::ATan2(ytCenterCell, r0);
722 fPhiCentersOfCells.AddAt(phi, ind);
723
724 AliDebug(2,Form(" ind %2.2i : y %8.3f ", ind, fCentersOfCellsPhiDir.At(ind)));
725 ind++;
726 }
727 }
728
729 fCentersOfCellsEtaDir.Set(fNZ *fNETAdiv);
730 fCentersOfCellsXDir.Set(fNZ *fNETAdiv);
731 fEtaCentersOfCells.Set(fNZ *fNETAdiv * fNPhi*fNPHIdiv);
732 AliDebug(2,Form(" Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize()));
733 for(Int_t it=0; it<fNZ; it++) {
734 AliEMCALShishKebabTrd1Module *trd1 = GetShishKebabModule(it);
735 nModule = fNPhi*it;
736 for(Int_t ic=0; ic<fNETAdiv; ic++) {
737 if(fNPHIdiv==2) {
738 trd1->GetCenterOfCellInLocalCoordinateofSM(ic, xr, zr); // case of 2X2
739 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
740 } if(fNPHIdiv==3) {
741 trd1->GetCenterOfCellInLocalCoordinateofSM3X3(ic, xr, zr); // case of 3X3
742 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
743 } if(fNPHIdiv==1) {
744 trd1->GetCenterOfCellInLocalCoordinateofSM1X1(xr, zr); // case of 1X1
745 GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
746 }
747 fCentersOfCellsXDir.AddAt(float(xr) - fParSM[0],ieta);
748 fCentersOfCellsEtaDir.AddAt(float(zr) - fParSM[2],ieta);
749 // Define grid on eta direction for each bin in phi
750 for(int iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
751 x = xr + trd1->GetRadius();
752 y = fCentersOfCellsPhiDir[iphi];
753 r = TMath::Sqrt(x*x + y*y + zr*zr);
754 theta = TMath::ACos(zr/r);
755 eta = AliEMCALShishKebabTrd1Module::ThetaToEta(theta);
756 // ind = ieta*fCentersOfCellsPhiDir.GetSize() + iphi;
757 ind = iphi*fCentersOfCellsEtaDir.GetSize() + ieta;
758 fEtaCentersOfCells.AddAt(eta, ind);
759 }
760 //printf(" ieta %i : xr + trd1->GetRadius() %f : zr %f : eta %f \n", ieta, xr + trd1->GetRadius(), zr, eta);
761 }
762 }
763 for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
764 AliDebug(2,Form(" ind %2.2i : z %8.3f : x %8.3f", i+1,
765 fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i)));
766 }
767
768}
769
770
771//________________________________________________________________________________________________
772AliEMCALShishKebabTrd1Module* AliEMCALGeoUtils::GetShishKebabModule(Int_t neta) const
773{
774 //This method was too long to be
775 //included in the header file - the
776 //rule checker complained about it's
777 //length, so we move it here. It returns the
778 //shishkebabmodule at a given eta index point.
779
780 static AliEMCALShishKebabTrd1Module* trd1=0;
781 if(fShishKebabTrd1Modules && neta>=0 && neta<fShishKebabTrd1Modules->GetSize()) {
782 trd1 = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(neta);
783 } else trd1 = 0;
784 return trd1;
785}
786
787//___________________________________________________________________
788void AliEMCALGeoUtils::PrintGeometry()
789{
790 //Print information from geometry
791 fEMCGeometry->PrintGeometry();
792
793 printf(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
794 fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1);
795
796 printf("\n Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize());
797 for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
798 printf(" ind %2.2i : z %8.3f : x %8.3f \n", i,
799 fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i));
800 int ind=0; // Nov 21,2006
801 for(Int_t iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
802 ind = iphi*fCentersOfCellsEtaDir.GetSize() + i;
803 printf("%6.4f ", fEtaCentersOfCells[ind]);
804 if((iphi+1)%12 == 0) printf("\n");
805 }
806 printf("\n");
807
808 }
809
810 printf("\n Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize());
811 for(Int_t i=0; i<fCentersOfCellsPhiDir.GetSize(); i++) {
812 double phi=fPhiCentersOfCells.At(i);
813 printf(" ind %2.2i : y %8.3f : phi %7.5f(%6.2f) \n", i, fCentersOfCellsPhiDir.At(i),
814 phi, phi*TMath::RadToDeg());
815 }
816
817}
818
819//____________________________________________________________________________
820Bool_t AliEMCALGeoUtils::Impact(const TParticle * particle) const
821{
822 // Tells if a particle enters EMCAL
823 Bool_t in=kFALSE;
824 Int_t absID=0;
825 TVector3 vtx(particle->Vx(),particle->Vy(),particle->Vz());
826 TVector3 vimpact(0,0,0);
827 ImpactOnEmcal(vtx,particle->Theta(),particle->Phi(),absID,vimpact);
fa911ba9 828 if(absID>=0)
0c5b726e 829 in=kTRUE;
830 return in;
831}
832//____________________________________________________________________________
833void AliEMCALGeoUtils::ImpactOnEmcal(TVector3 vtx, Double_t theta, Double_t phi,
834 Int_t & absId, TVector3 & vimpact) const
835{
836 // calculates the impact coordinates on EMCAL (centre of a tower/not on EMCAL surface)
837 // of a neutral particle
838 // emitted in the vertex vtx[3] with direction theta and phi in the ALICE global coordinate system
839
840 TVector3 p(TMath::Sin(theta)*TMath::Cos(phi),TMath::Sin(theta)*TMath::Sin(phi),TMath::Cos(theta)) ;
841
842 vimpact.SetXYZ(0,0,0);
843 absId=-1;
844 if(phi==0 || theta==0) return;
845
fa911ba9 846 TVector3 direction;
847 Double_t factor = (fIPDistance-vtx[1])/p[1];
0c5b726e 848 direction = vtx + factor*p;
849
0c5b726e 850 //from particle direction -> tower hitted
851 GetAbsCellIdFromEtaPhi(direction.Eta(),direction.Phi(),absId);
852
853 //tower absID hitted -> tower/module plane (evaluated at the center of the tower)
de39a0ff 854 Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1;
0c5b726e 855 Double_t loc[3],loc2[3],loc3[3];
856 Double_t glob[3]={},glob2[3]={},glob3[3]={};
857
858 if(!RelPosCellInSModule(absId,loc)) return;
859
860 //loc is cell center of tower
861 GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
862
863 //look at 2 neighbours-s cell using nIphi={0,1} and nIeta={0,1}
53e430a3 864 Int_t nIphi2=-1,nIeta2=-1,absId2=-1,absId3=-1;
0c5b726e 865 if(nIeta==0) nIeta2=1;
866 else nIeta2=0;
867 absId2=GetAbsCellId(nSupMod,nModule,nIphi,nIeta2);
868 if(nIphi==0) nIphi2=1;
869 else nIphi2=0;
870 absId3=GetAbsCellId(nSupMod,nModule,nIphi2,nIeta);
871
872 //2nd point on emcal cell plane
873 if(!RelPosCellInSModule(absId2,loc2)) return;
874
875 //3rd point on emcal cell plane
876 if(!RelPosCellInSModule(absId3,loc3)) return;
877
a7e8255c 878 // Get Matrix
0c5b726e 879 const TGeoHMatrix* m = GetMatrixForSuperModule(nSupMod);
880 if(m) {
881 m->LocalToMaster(loc, glob);
882 m->LocalToMaster(loc2, glob2);
883 m->LocalToMaster(loc3, glob3);
884 } else {
885 AliFatal("Geo matrixes are not loaded \n") ;
886 }
887
888 //Equation of Plane from glob,glob2,glob3 (Ax+By+Cz+D=0)
889 Double_t a = glob[1]*(glob2[2]-glob3[2]) + glob2[1]*(glob3[2]-glob[2]) + glob3[1]*(glob[2]-glob2[2]);
890 Double_t b = glob[2]*(glob2[0]-glob3[0]) + glob2[2]*(glob3[0]-glob[0]) + glob3[2]*(glob[0]-glob2[0]);
891 Double_t c = glob[0]*(glob2[1]-glob3[1]) + glob2[0]*(glob3[1]-glob[1]) + glob3[0]*(glob[1]-glob2[1]);
892 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]);
893 d=-d;
894
895 //shift equation of plane from tower/module center to surface along vector (A,B,C) normal to tower/module plane
896 Double_t dist = fLongModuleSize/2.;
897 Double_t norm = TMath::Sqrt(a*a+b*b+c*c);
898 Double_t glob4[3]={};
899 TVector3 dir(a,b,c);
900 TVector3 point(glob[0],glob[1],glob[2]);
901 if(point.Dot(dir)<0) dist*=-1;
902 glob4[0]=glob[0]-dist*a/norm;
903 glob4[1]=glob[1]-dist*b/norm;
904 glob4[2]=glob[2]-dist*c/norm;
905 d = glob4[0]*a + glob4[1]*b + glob4[2]*c ;
906 d = -d;
907
908 //Line determination (2 points for equation of line : vtx and direction)
909 //impact between line (particle) and plane (module/tower plane)
910 Double_t den = a*(vtx(0)-direction(0)) + b*(vtx(1)-direction(1)) + c*(vtx(2)-direction(2));
911 if(den==0){
912 printf("ImpactOnEmcal() No solution :\n");
913 return;
914 }
915
916 Double_t length = a*vtx(0)+b*vtx(1)+c*vtx(2)+d;
917 length /=den;
918
919 vimpact.SetXYZ(vtx(0)+length*(direction(0)-vtx(0)),vtx(1)+length*(direction(1)-vtx(1)),vtx(2)+length*(direction(2)-vtx(2)));
920
921 //shift vimpact from tower/module surface to center along vector (A,B,C) normal to tower/module plane
922 vimpact.SetXYZ(vimpact(0)+dist*a/norm,vimpact(1)+dist*b/norm,vimpact(2)+dist*c/norm);
923
924 return;
925}
926
927//_____________________________________________________________________________
928Bool_t AliEMCALGeoUtils::IsInEMCAL(Double_t x, Double_t y, Double_t z) const {
929 // Checks whether point is inside the EMCal volume, used in AliEMCALv*.cxx
930 //
931 // Code uses cylindrical approximation made of inner radius (for speed)
932 //
933 // Points behind EMCAl, i.e. R > outer radius, but eta, phi in acceptance
934 // are considered to inside
935
936 Double_t r=sqrt(x*x+y*y);
937
938 if ( r > fEnvelop[0] ) {
de39a0ff 939 Double_t theta;
940 theta = TMath::ATan2(r,z);
941 Double_t eta;
942 if(theta == 0)
0c5b726e 943 eta = 9999;
944 else
945 eta = -TMath::Log(TMath::Tan(theta/2.));
946 if (eta < fArm1EtaMin || eta > fArm1EtaMax)
947 return 0;
948
949 Double_t phi = TMath::ATan2(y,x) * 180./TMath::Pi();
950 if (phi < 0) phi += 360; // phi should go from 0 to 360 in this case
951 if (phi > fArm1PhiMin && phi < fArm1PhiMax)
952 return 1;
953 }
954 return 0;
955}
956
957//________________________________________________________________________________________________
958Int_t AliEMCALGeoUtils::GetAbsTRUNumberFromNumberInSm(const Int_t row, const Int_t col, const Int_t sm) const
959{ // Nov 6, 2007
960 // Get TRU absolute number from column, row and Super Module number
961 Int_t itru = row + col*fEMCGeometry->GetNModulesInTRUPhi() + sm*fEMCGeometry->GetNTRU();
962 // printf(" GetAbsTRUNumberFromNumberInSm : row %2i col %2i sm %2i -> itru %2i\n", row, col, sm, itru);
963 return itru;
964}
965
916f1e76 966//________________________________________________________________________________________________
967Bool_t AliEMCALGeoUtils::GetAbsFastORIndexFromTRU(const Int_t iTRU, const Int_t iADC, Int_t& id) const
968{
a7e8255c 969 //Trigger mapping method, get FastOr Index from TRU
970
916f1e76 971 if (iTRU > 31 || iTRU < 0 || iADC > 95 || iADC < 0)
972 {
973 AliError("TRU out of range!");
974 return kFALSE;
975 }
de39a0ff 976
977 id = ( iTRU % 2 ) ? iADC%4 + 4 * (23 - int(iADC/4)) : (3 - iADC%4) + 4 * int(iADC/4);
978
979 id += iTRU * 96;
916f1e76 980
981 return kTRUE;
982}
983
984//________________________________________________________________________________________________
985Bool_t AliEMCALGeoUtils::GetTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iADC) const
986{
a7e8255c 987
988 //Trigger mapping method, get TRU number from FastOr Index
989
916f1e76 990 if (id > 3071 || id < 0)
991 {
992 AliError("Id out of range!");
993 return kFALSE;
994 }
995
996 iTRU = id / 96;
de39a0ff 997
916f1e76 998 iADC = id % 96;
999
de39a0ff 1000 iADC = ( iTRU % 2 ) ? iADC%4 + 4 * (23 - int(iADC/4)) : (3 - iADC%4) + 4 * int(iADC/4);
1001
916f1e76 1002 return kTRUE;
1003}
1004
1005//________________________________________________________________________________________________
1006Bool_t AliEMCALGeoUtils::GetPositionInTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iEta, Int_t& iPhi) const
1007{
a7e8255c 1008 //Trigger mapping method, get position in TRU from FasOr Index
1009
de39a0ff 1010 Int_t iADC=-1;
1011 if (!GetTRUFromAbsFastORIndex(id, iTRU, iADC)) return kFALSE;
916f1e76 1012
1013 Int_t x = iADC / 4;
1014 Int_t y = iADC % 4;
1015
de39a0ff 1016 if ( iTRU % 2 ) // C side
916f1e76 1017 {
1018 iEta = 23 - x;
1019 iPhi = y;
1020 }
de39a0ff 1021 else // A side
916f1e76 1022 {
1023 iEta = x;
1024 iPhi = 3 - y;
1025 }
1026
1027 return kTRUE;
1028}
1029
1030//________________________________________________________________________________________________
1031Bool_t AliEMCALGeoUtils::GetPositionInSMFromAbsFastORIndex(const Int_t id, Int_t& iSM, Int_t& iEta, Int_t& iPhi) const
1032{
a7e8255c 1033 //Trigger mapping method, get position in Super Module from FasOr Index
1034
de39a0ff 1035 Int_t iTRU=-1;
1036
1037 if (!GetPositionInTRUFromAbsFastORIndex(id, iTRU, iEta, iPhi)) return kFALSE;
916f1e76 1038
de39a0ff 1039 if (iTRU % 2) // C side
916f1e76 1040 {
de39a0ff 1041 iSM = 2 * ( int( int(iTRU / 2) / 3 ) ) + 1;
916f1e76 1042 }
de39a0ff 1043 else // A side
916f1e76 1044 {
de39a0ff 1045 iSM = 2 * ( int( int(iTRU / 2) / 3 ) );
916f1e76 1046 }
de39a0ff 1047
1048 iPhi += 4 * int((iTRU % 6) / 2);
916f1e76 1049
1050 return kTRUE;
1051}
1052
1053//________________________________________________________________________________________________
de39a0ff 1054Bool_t AliEMCALGeoUtils::GetPositionInEMCALFromAbsFastORIndex(const Int_t id, Int_t& iEta, Int_t& iPhi) const
1055{
1056 Int_t iSM=-1;
1057
1058 if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi))
1059 {
1060 if (iSM % 2) iEta += 24;
1061
1062 iPhi += 12 * int(iSM / 2);
1063
1064 return kTRUE;
1065 }
1066
1067 return kFALSE;
1068}
1069
1070//________________________________________________________________________________________________
916f1e76 1071Bool_t AliEMCALGeoUtils::GetAbsFastORIndexFromPositionInTRU(const Int_t iTRU, const Int_t iEta, const Int_t iPhi, Int_t& id) const
1072{
a7e8255c 1073 //Trigger mapping method, get Index if FastOr from Position in TRU
1074
de39a0ff 1075 if (iTRU < 0 || iTRU > 31 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 3)
1076 {
1077 AliError("Out of range!");
1078 return kFALSE;
1079 }
1080
1081 id = iPhi + 4 * iEta + iTRU * 96;
1082
1083 return kTRUE;
1084}
1085
1086//________________________________________________________________________________________________
1087Bool_t AliEMCALGeoUtils::GetAbsFastORIndexFromPositionInSM(const Int_t iSM, const Int_t iEta, const Int_t iPhi, Int_t& id) const
1088{
1089 //
1090 if (iSM < 0 || iSM > 11 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 11)
1091 {
1092 AliError("Out of range!");
1093 return kFALSE;
1094 }
1095
1096 Int_t x = iEta;
1097 Int_t y = iPhi % 4;
1098
1099 Int_t iOff = (iSM % 2) ? 1 : 0;
1100 Int_t iTRU = 2 * int(iPhi / 4) + 6 * int(iSM / 2) + iOff;
1101
1102 if (GetAbsFastORIndexFromPositionInTRU(iTRU, x, y, id))
1103 {
1104 return kTRUE;
1105 }
1106
1107 return kFALSE;
1108}
1109
1110//________________________________________________________________________________________________
1111Bool_t AliEMCALGeoUtils::GetAbsFastORIndexFromPositionInEMCAL(const Int_t iEta, const Int_t iPhi, Int_t& id) const
1112{
1113 //
1114 if (iEta < 0 || iEta > 47 || iPhi < 0 || iPhi > 63 )
1115 {
1116 AliError("Out of range!");
1117 return kFALSE;
1118 }
1119
1120 if (fFastOR2DMap[iEta][iPhi] == -1)
1121 {
1122 AliError("Invalid index!");
1123 return kFALSE;
1124 }
1125
1126 id = fFastOR2DMap[iEta][iPhi];
1127
1128 return kTRUE;
1129}
1130
1131//________________________________________________________________________________________________
1132Bool_t AliEMCALGeoUtils::GetFastORIndexFromCellIndex(const Int_t id, Int_t& idx) const
1133{
1134 Int_t iSupMod, nModule, nIphi, nIeta, iphim, ietam;
916f1e76 1135
de39a0ff 1136 Bool_t isOK = GetCellIndex( id, iSupMod, nModule, nIphi, nIeta );
1137
1138 GetModulePhiEtaIndexInSModule( iSupMod, nModule, iphim, ietam );
1139
1140 if (isOK && GetAbsFastORIndexFromPositionInSM(iSupMod, ietam, iphim, idx))
916f1e76 1141 {
de39a0ff 1142 return kTRUE;
916f1e76 1143 }
de39a0ff 1144
1145 return kFALSE;
1146}
1147
1148//________________________________________________________________________________________________
1149Bool_t AliEMCALGeoUtils::GetCellIndexFromFastORIndex(const Int_t id, Int_t idx[4]) const
1150{
1151 Int_t iSM=-1, iEta=-1, iPhi=-1;
1152 if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi))
1153 {
1154 Int_t ix = 2 * iEta;
1155 Int_t iy = 2 * iPhi;
1156
1157 for (Int_t i=0; i<2; i++)
1158 {
1159 for (Int_t j=0; j<2; j++)
1160 {
1161 idx[2*i+j] = GetAbsCellIdFromCellIndexes(iSM, iy + i, ix + j);
1162 }
1163 }
1164
1165 return kTRUE;
1166 }
1167
1168 return kFALSE;
1169}
1170
1171//________________________________________________________________________________________________
1172Bool_t AliEMCALGeoUtils::GetTRUIndexFromSTUIndex(const Int_t id, Int_t& idx) const
1173{
1174 if (id > 31 || id < 0)
1175 {
1176 AliError(Form("TRU index out of range: %d",id));
1177 return kFALSE;
1178 }
1179
1180 idx = (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
1181
1182 return kTRUE;
1183}
1184
1185//________________________________________________________________________________________________
1186Int_t AliEMCALGeoUtils::GetTRUIndexFromSTUIndex(const Int_t id) const
1187{
1188 if (id > 31 || id < 0)
1189 {
1190 AliError(Form("TRU index out of range: %d",id));
1191 }
1192
1193 Int_t idx = (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
1194
1195 return idx;
1196}
1197
1198//________________________________________________________________________________________________
1199void AliEMCALGeoUtils::BuildFastOR2DMap()
1200{
1201 // Needed by STU
1202 for (Int_t i = 0; i < 32; i++)
1203 {
1204 for (Int_t j = 0; j < 24; j++)
1205 {
1206 for (Int_t k = 0; k < 4; k++)
1207 {
1208 Int_t id;
1209 if (GetAbsFastORIndexFromPositionInTRU(i, j, k, id))
1210 {
1211 Int_t x = j, y = k + 4 * int(i / 2);
1212
1213 if (i % 2) x += 24;
1214
1215 fFastOR2DMap[x][y] = id;
1216 }
1217 }
1218 }
1219 }
1220}
1221
1222//________________________________________________________________________________________________
1223Bool_t AliEMCALGeoUtils::GetFastORIndexFromL0Index(const Int_t iTRU, const Int_t id, Int_t idx[], const Int_t size) const
1224{
1225 if (size <= 0 ||size > 4)
1226 {
1227 AliError("Size not supported!");
1228 return kFALSE;
1229 }
1230
1231 Int_t motif[4] = {0, 1, 4, 5};
1232
1233 switch (size)
916f1e76 1234 {
de39a0ff 1235 case 1: // Cosmic trigger
1236 if (!GetAbsFastORIndexFromTRU(iTRU, id, idx[0])) return kFALSE;
1237 break;
1238 case 4: // 4 x 4
1239 for (Int_t k = 0; k < 4; k++)
1240 {
1241 Int_t iADC = motif[k] + 4 * int(id / 3) + (id % 3);
1242
1243 if (!GetAbsFastORIndexFromTRU(iTRU, iADC, idx[k])) return kFALSE;
1244 }
1245 break;
1246 default:
1247 break;
916f1e76 1248 }
1249
1250 return kTRUE;
1251}
0c5b726e 1252
1253//____________________________________________________________________________
1254const TGeoHMatrix * AliEMCALGeoUtils::GetMatrixForSuperModule(Int_t smod) const {
a7e8255c 1255
0c5b726e 1256 //Provides shift-rotation matrix for EMCAL
1257
1258 if(smod < 0 || smod > fEMCGeometry->GetNumberOfSuperModules())
1259 AliFatal(Form("Wrong supermodule index -> %d",smod));
1260
1261 //If GeoManager exists, take matrixes from it
1262
1263 //
1264 // if(fKey110DEG && ind>=10) {
1265 // }
1266 //
1267 // if(!gGeoManager->cd(volpath.Data()))
1268 // AliFatal(Form("AliEMCALGeometry::GeoManager cannot find path %s!",volpath.Data()));
1269 //
1270 // TGeoHMatrix* m = gGeoManager->GetCurrentMatrix();
1271
1272 if(gGeoManager){
1273 char path[255] ;
1274 sprintf(path,"/ALIC_1/XEN1_1/SMOD_%d",smod+1) ;
1275 //TString volpath = "ALIC_1/XEN1_1/SMOD_";
1276 //volpath += smod+1;
1277
1278 if(fKey110DEG && smod >= 10){
1279 sprintf(path,"/ALIC_1/XEN1_1/SM10_%d",smod-10+1) ;
1280 //volpath = "ALIC_1/XEN1_1/SM10_";
1281 //volpath += smod-10+1;
1282 }
1283 if (!gGeoManager->cd(path)){
1284 AliFatal(Form("Geo manager can not find path %s!\n",path));
1285 }
1286 return gGeoManager->GetCurrentMatrix();
1287 }
a7e8255c 1288
0c5b726e 1289 if(fkSModuleMatrix[smod]){
1290 return fkSModuleMatrix[smod] ;
1291 }
1292 else{
a7e8255c 1293 AliInfo("Stop:");
1294 printf("\t Can not find EMCAL misalignment matrixes\n") ;
1295 printf("\t Either import TGeoManager from geometry.root or \n");
1296 printf("\t read stored matrixes from AliESD Header: \n") ;
1297 printf("\t AliEMCALGeoUtils::SetMisalMatrixes(header->GetEMCALMisalMatrix()) \n") ;
0c5b726e 1298 abort() ;
1299 }
1300 return 0 ;
1301}
1302
1303//______________________________________________________________________
1304void AliEMCALGeoUtils::GetModulePhiEtaIndexInSModuleFromTRUIndex(Int_t itru, Int_t iphitru, Int_t ietatru, Int_t &iphiSM, Int_t &ietaSM) const
1305{
1306
1307 // This method transforms the (eta,phi) index of module in a
1308 // TRU matrix into Super Module (eta,phi) index.
1309
1310 // Calculate in which row and column where the TRU are
1311 // ordered in the SM
1312
1313 Int_t col = itru/fEMCGeometry->GetNTRUPhi() ; // indexes of TRU in SM
1314 Int_t row = itru - col*fEMCGeometry->GetNTRUPhi();
1315
1316 iphiSM = fEMCGeometry->GetNModulesInTRUPhi()*row + iphitru ;
1317 ietaSM = fEMCGeometry->GetNModulesInTRUEta()*col + ietatru ;
1318 //printf(" GetModulePhiEtaIndexInSModuleFromTRUIndex : itru %2i iphitru %2i ietatru %2i iphiSM %2i ietaSM %2i \n",
1319 // itru, iphitru, ietatru, iphiSM, ietaSM);
1320}