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