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