]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliJetDummyGeo.cxx
Updating macro to check the various methods of the AliMUONMCDataInterface
[u/mrichter/AliRoot.git] / JETAN / AliJetDummyGeo.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 //
17 // Temporarily added to define part of the EMCal geometry
18 // necessary for the jet finder
19 //
20 // M. Estienne
21 //
22
23 #include <Riostream.h>
24 #include <assert.h>
25 #include <TList.h>
26
27 // --- Root header files ---
28 #include <TVector3.h>
29 #include <TGeoManager.h>
30 #include <TGeoMatrix.h>
31 #include <TGeoNode.h>
32
33 // --- AliRoot header files ---
34 #include "AliLog.h"
35 #include "AliJetDummyGeo.h"
36 #include "AliJetDummyShishKebabTrd1Module.h"
37
38 ClassImp(AliJetDummyGeo)
39
40 AliJetDummyGeo::AliJetDummyGeo():
41   fArm1EtaMin(-0.7), 
42   fArm1EtaMax(+0.7), 
43   fArm1PhiMin(80.0), 
44   fArm1PhiMax(200.0),
45   fNumberOfSuperModules(12), 
46   fSteelFrontThick(0.0), 
47   fLateralSteelStrip(0.01),
48   fIPDistance(428.0), 
49   fPhiGapForSM(2.), 
50   fNPhi(12),       
51   fNZ(24),      
52   fPhiModuleSize(12.26 - fPhiGapForSM / Float_t(fNPhi)), 
53   fEtaModuleSize(fPhiModuleSize),
54   fNPHIdiv(2), 
55   fNETAdiv(2), 
56   fPhiTileSize(fPhiModuleSize/Double_t(fNPHIdiv) - fLateralSteelStrip),
57   fEtaTileSize(fEtaModuleSize/Double_t(fNETAdiv) - fLateralSteelStrip),
58   fNECLayers(77), 
59   fECScintThick(0.16), 
60   fECPbRadThickness(0.16), 
61   fSampling(12.327),
62   fTrd1Angle(1.5), 
63   fNCellsInModule(fNPHIdiv*fNETAdiv), 
64   fNCellsInSupMod(fNCellsInModule*fNPhi*fNZ), 
65   fNCells(fNCellsInSupMod*fNumberOfSuperModules-fNCellsInSupMod), 
66   fLongModuleSize(fNECLayers*(fECScintThick + fECPbRadThickness)), 
67   f2Trd1Dx2(fEtaModuleSize + 2.*fLongModuleSize*TMath::Tan(fTrd1Angle*TMath::DegToRad()/2.)), 
68   fShellThickness(TMath::Sqrt(fLongModuleSize*fLongModuleSize + f2Trd1Dx2*f2Trd1Dx2)+fSteelFrontThick),
69   fZLength(2.*ZFromEtaR(fIPDistance+fShellThickness,fArm1EtaMax)),
70   fEtaMaxOfTRD1(0.), 
71   fPhiBoundariesOfSM(0),
72   fPhiCentersOfSM(0),
73   fCentersOfCellsEtaDir(0),
74   fCentersOfCellsXDir(0),
75   fCentersOfCellsPhiDir(0),
76   fEtaCentersOfCells(0),
77   fPhiCentersOfCells(0),
78   fShishKebabTrd1Modules(0),
79   fDebug(0)
80 {
81   // Constructor
82
83   // Local coordinates
84   fParSM[0] = GetShellThickness()/2.;        
85   fParSM[1] = GetPhiModuleSize() * GetNPhi()/2.;
86   fParSM[2] = 350./2.;
87
88   fEnvelop[0] = fIPDistance; // mother volume inner radius
89   fEnvelop[1] = fIPDistance + fShellThickness; // mother volume outer r.
90   fEnvelop[2] = 1.00001*fZLength; // add some padding for mother volume. 
91
92   // SM phi boundaries - (0,1),(2,3) .. (10,11) - has the same boundaries; Nov 7, 2006 
93   fPhiBoundariesOfSM.Set(fNumberOfSuperModules);
94   fPhiCentersOfSM.Set(fNumberOfSuperModules/2);
95   fPhiBoundariesOfSM[0] = TMath::PiOver2() - TMath::ATan2(fParSM[1] , fIPDistance); // 1th and 2th modules)
96   fPhiBoundariesOfSM[1] = TMath::PiOver2() + TMath::ATan2(fParSM[1] , fIPDistance);
97   fPhiCentersOfSM[0]    = TMath::PiOver2();
98   for(Int_t i=1; i<=4; i++) { // from 2th ro 9th
99     fPhiBoundariesOfSM[2*i]   = fPhiBoundariesOfSM[0] + 20.*TMath::DegToRad()*i;
100     fPhiBoundariesOfSM[2*i+1] = fPhiBoundariesOfSM[1] + 20.*TMath::DegToRad()*i;
101     fPhiCentersOfSM[i]        = fPhiCentersOfSM[0]    + 20.*TMath::DegToRad()*i;
102   }
103   fPhiBoundariesOfSM[11] = 190.*TMath::DegToRad();
104   fPhiBoundariesOfSM[10] = fPhiBoundariesOfSM[11] - TMath::ATan2((fParSM[1]) , fIPDistance);
105   fPhiCentersOfSM[5]     = (fPhiBoundariesOfSM[10]+fPhiBoundariesOfSM[11])/2.; 
106
107   Int_t nphism  = GetNumberOfSuperModules()/2;
108   Double_t dphi = (GetArm1PhiMax() - GetArm1PhiMin())/nphism;
109   Double_t rpos = (GetEnvelop(0) + GetEnvelop(1))/2.;
110   Double_t phi, phiRad, xpos, ypos, zpos;
111   for(Int_t i=0; i<nphism; i++){
112     phi    = GetArm1PhiMin() + dphi*(2*i+1)/2.; // phi= 90, 110, 130, 150, 170, 190
113     phiRad = phi*TMath::Pi()/180.;
114     xpos = rpos * TMath::Cos(phiRad);
115     ypos = rpos * TMath::Sin(phiRad);
116     zpos = fParSM[2];
117     if(i==5) {
118       xpos += (fParSM[1]/2. * TMath::Sin(phiRad)); 
119       ypos -= (fParSM[1]/2. * TMath::Cos(phiRad));
120     }
121     // pozitive z
122     Int_t ind = 2*i;
123     TGeoRotation *geoRot0 = new TGeoRotation("geoRot0", 90.0, phi, 90.0, 90.0+phi, 0.0, 0.0);
124     fMatrixOfSM[ind] = new TGeoCombiTrans(Form("EmcalSM%2.2i",ind),
125                                           xpos,ypos, zpos, geoRot0);
126     // negaive z
127     ind++;
128     Double_t phiy = 90. + phi + 180.;
129     if(phiy>=360.) phiy -= 360.;
130     TGeoRotation *geoRot1 = new TGeoRotation("geoRot1", 90.0, phi, 90.0, phiy, 180.0, 0.0);
131     fMatrixOfSM[ind] = new TGeoCombiTrans(Form("EmcalSM%2.2i",ind),
132                                           xpos,ypos,-zpos, geoRot1);
133   } // for
134
135   CreateListOfTrd1Modules();
136
137   if(fDebug > 0){
138     for(Int_t i=0; i<6; i++){
139       cout << "fMatrixOfSM[" << i << "]: " << fMatrixOfSM[i] << endl;
140     }
141     cout << "fArm1EtaMin: " << fArm1EtaMin << endl;
142     cout << "fArm1EtaMax: " << fArm1EtaMax << endl;
143     cout << "fArm1PhiMin: " << fArm1PhiMin << endl;
144     cout << "fArm1PhiMax: " << fArm1PhiMax << endl;
145     cout << "fNumberOfSuperModules: " << fNumberOfSuperModules << endl;
146     cout << "fSteelFrontThick: " << fSteelFrontThick << endl;
147     cout << "fIPDistance: " << fIPDistance  << endl;
148     cout << "fZLength: " << fZLength << endl;
149     cout << "fPhiGapForSM: " << fPhiGapForSM << endl;
150     cout << "fNPhi: " << fNPhi << endl;
151     cout << "fNZ: " << fNZ << endl;
152     cout << "fPhiModuleSize: " << fPhiModuleSize << endl;
153     cout << "fEtaModuleSize: " << fEtaModuleSize << endl;
154     cout << "fNPHIdiv: " << fNPHIdiv << endl;
155     cout << "fNETAdiv: " << fNETAdiv << endl;
156     cout << "fNECLayers: " << fNECLayers << endl;
157     cout << "fECScintThick: " <<  fECScintThick << endl;
158     cout << "fECPbRadThickness: " << fECPbRadThickness << endl;
159     cout << "fSampling: " << fSampling << endl;
160     cout << "fTrd1Angle: " << fTrd1Angle << endl;
161     cout << "fNCellsInModule: " << fNCellsInModule << endl;
162     cout << "fNCellsInSupMod: " << fNCellsInSupMod << endl;
163     cout << "fNCells: " << fNCells << endl;
164     cout << "fLongModuleSize: " <<  fLongModuleSize << endl;
165     cout << "f2Trd1Dx2: " << f2Trd1Dx2 << endl;
166     cout << "fShellThickness: " << fShellThickness << endl;
167     cout << "fEtaMaxOfTRD1: " << fEtaMaxOfTRD1 << endl;
168   }
169 }
170
171 AliJetDummyGeo::AliJetDummyGeo(const AliJetDummyGeo& geom):
172   fArm1EtaMin(geom.fArm1EtaMin), 
173   fArm1EtaMax(geom.fArm1EtaMax), 
174   fArm1PhiMin(geom.fArm1PhiMin), 
175   fArm1PhiMax(geom.fArm1PhiMax),
176   fNumberOfSuperModules(geom.fNumberOfSuperModules), 
177   fSteelFrontThick(geom.fSteelFrontThick), 
178   fLateralSteelStrip(geom.fLateralSteelStrip),
179   fIPDistance(geom.fIPDistance), 
180   fPhiGapForSM(geom.fPhiGapForSM), 
181   fNPhi(geom.fNPhi),       
182   fNZ(geom.fNZ),      
183   fPhiModuleSize(geom.fPhiModuleSize), 
184   fEtaModuleSize(geom.fEtaModuleSize),
185   fNPHIdiv(geom.fNPHIdiv), 
186   fNETAdiv(geom.fNETAdiv), 
187   fPhiTileSize(geom.fPhiTileSize),
188   fEtaTileSize(geom.fEtaTileSize),
189   fNECLayers(geom.fNECLayers), 
190   fECScintThick(geom.fECScintThick), 
191   fECPbRadThickness(geom.fECPbRadThickness), 
192   fSampling(geom.fSampling),
193   fTrd1Angle(geom.fTrd1Angle), 
194   fNCellsInModule(geom.fNCellsInModule), 
195   fNCellsInSupMod(geom.fNCellsInSupMod), 
196   fNCells(geom.fNCells),
197   fLongModuleSize(geom.fLongModuleSize),
198   f2Trd1Dx2(geom.f2Trd1Dx2),
199   fShellThickness(geom.fShellThickness),
200   fZLength(geom.fZLength),
201   fEtaMaxOfTRD1(geom.fEtaMaxOfTRD1),
202   fPhiBoundariesOfSM(geom.fPhiBoundariesOfSM),
203   fPhiCentersOfSM(geom.fPhiCentersOfSM),
204   fCentersOfCellsEtaDir(geom.fCentersOfCellsEtaDir),
205   fCentersOfCellsXDir(geom.fCentersOfCellsXDir),
206   fCentersOfCellsPhiDir(geom.fCentersOfCellsPhiDir),
207   fEtaCentersOfCells(geom.fEtaCentersOfCells),
208   fPhiCentersOfCells(geom.fPhiCentersOfCells),
209   fShishKebabTrd1Modules(geom.fShishKebabTrd1Modules),
210   fDebug(geom.fDebug)
211 {
212   // Constructor
213   // Local coordinates
214   fParSM[0] = GetShellThickness()/2.;        
215   fParSM[1] = GetPhiModuleSize() * GetNPhi()/2.;
216   fParSM[2] = 350./2.;
217
218   fEnvelop[0] = fIPDistance; // mother volume inner radius
219   fEnvelop[1] = fIPDistance + fShellThickness; // mother volume outer r.
220   fEnvelop[2] = 1.00001*fZLength; // add some padding for mother volume. 
221
222   // SM phi boundaries - (0,1),(2,3) .. (10,11) - has the same boundaries; Nov 7, 2006 
223   fPhiBoundariesOfSM.Set(fNumberOfSuperModules);
224   fPhiCentersOfSM.Set(fNumberOfSuperModules/2);
225   fPhiBoundariesOfSM[0] = TMath::PiOver2() - TMath::ATan2(fParSM[1] , fIPDistance); // 1th and 2th modules)
226   fPhiBoundariesOfSM[1] = TMath::PiOver2() + TMath::ATan2(fParSM[1] , fIPDistance);
227   fPhiCentersOfSM[0]    = TMath::PiOver2();
228   for(Int_t i=1; i<=4; i++) { // from 2th ro 9th
229     fPhiBoundariesOfSM[2*i]   = fPhiBoundariesOfSM[0] + 20.*TMath::DegToRad()*i;
230     fPhiBoundariesOfSM[2*i+1] = fPhiBoundariesOfSM[1] + 20.*TMath::DegToRad()*i;
231     fPhiCentersOfSM[i]        = fPhiCentersOfSM[0]    + 20.*TMath::DegToRad()*i;
232   }
233   fPhiBoundariesOfSM[11] = 190.*TMath::DegToRad();
234   fPhiBoundariesOfSM[10] = fPhiBoundariesOfSM[11] - TMath::ATan2((fParSM[1]) , fIPDistance);
235   fPhiCentersOfSM[5]     = (fPhiBoundariesOfSM[10]+fPhiBoundariesOfSM[11])/2.; 
236
237   Int_t nphism  = GetNumberOfSuperModules()/2;
238   Double_t dphi = (GetArm1PhiMax() - GetArm1PhiMin())/nphism;
239   Double_t rpos = (GetEnvelop(0) + GetEnvelop(1))/2.;
240   Double_t phi, phiRad, xpos, ypos, zpos;
241   for(Int_t i=0; i<nphism; i++){
242     phi    = GetArm1PhiMin() + dphi*(2*i+1)/2.; // phi= 90, 110, 130, 150, 170, 190
243     phiRad = phi*TMath::Pi()/180.;
244     xpos = rpos * TMath::Cos(phiRad);
245     ypos = rpos * TMath::Sin(phiRad);
246     zpos = fParSM[2];
247     if(i==5) {
248       xpos += (fParSM[1]/2. * TMath::Sin(phiRad)); 
249       ypos -= (fParSM[1]/2. * TMath::Cos(phiRad));
250     }
251     // pozitive z
252     Int_t ind = 2*i;
253     TGeoRotation *geoRot0 = new TGeoRotation("geoRot0", 90.0, phi, 90.0, 90.0+phi, 0.0, 0.0);
254     fMatrixOfSM[ind] = new TGeoCombiTrans(Form("EmcalSM%2.2i",ind),
255                                           xpos,ypos, zpos, geoRot0);
256     // negaive z
257     ind++;
258     Double_t phiy = 90. + phi + 180.;
259     if(phiy>=360.) phiy -= 360.;
260     TGeoRotation *geoRot1 = new TGeoRotation("geoRot1", 90.0, phi, 90.0, phiy, 180.0, 0.0);
261     fMatrixOfSM[ind] = new TGeoCombiTrans(Form("EmcalSM%2.2i",ind),
262                                           xpos,ypos,-zpos, geoRot1);
263
264     delete geoRot0;
265     delete geoRot1;
266
267   } // for
268
269   CreateListOfTrd1Modules();
270
271 }
272
273 //------------------------------------------------------------------------------------
274 AliJetDummyGeo::~AliJetDummyGeo()
275 {
276   // Destructor
277   delete [] fMatrixOfSM;
278 }
279
280 //------------------------------------------------------------------------------------
281 void AliJetDummyGeo::EtaPhiFromIndex(Int_t absId, Float_t& eta, Float_t& phi)
282 {
283   // Nov 16, 2006- float to double
284   // version for TRD1 only
285   static TVector3 vglob;
286   GetGlobal(absId, vglob);
287   eta = vglob.Eta();
288   phi = vglob.Phi();
289
290 }
291
292 //------------------------------------------------------------------------------------
293 void AliJetDummyGeo::GetGlobal(const Double_t *loc, Double_t *glob, Int_t ind) const
294 {
295   // Figure out the global numbering of a given supermodule from the
296   // local numbering
297   // Alice numbering - Jun 03,2006
298   //  if(fMatrixOfSM[0] == 0) GetTransformationForSM();
299
300   if(ind>=0 && ind < GetNumberOfSuperModules()) {
301     fMatrixOfSM[ind]->LocalToMaster(loc, glob);
302   }
303 }
304
305 //------------------------------------------------------------------------------------
306 void AliJetDummyGeo::GetGlobal(Int_t absId , Double_t glob[3]) const
307
308   // Alice numbering scheme - Jun 03, 2006
309   static Int_t nSupMod, nModule, nIphi, nIeta;
310   static Double_t loc[3];
311
312   glob[0]=glob[1]=glob[2]=0.0; // bad case
313   if(RelPosCellInSModule(absId, loc)) {
314     GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
315     fMatrixOfSM[nSupMod]->LocalToMaster(loc, glob);
316   }
317 }
318
319 //------------------------------------------------------------------------------------
320 void AliJetDummyGeo::GetGlobal(Int_t absId , TVector3 &vglob) const
321
322   // Alice numbering scheme - Jun 03, 2006
323   static Double_t glob[3];
324
325   GetGlobal(absId, glob);
326   vglob.SetXYZ(glob[0], glob[1], glob[2]);
327
328 }
329
330 //------------------------------------------------------------------------------------
331 Bool_t AliJetDummyGeo::RelPosCellInSModule(Int_t absId, Double_t loc[3]) const
332 {
333   // Alice numbering scheme - Jun 03, 2006
334   loc[0] = loc[1] = loc[2]=0.0;
335   if(RelPosCellInSModule(absId, loc[0],loc[1],loc[2])) {
336     return kTRUE;
337   }
338   return kFALSE;
339 }
340
341 //------------------------------------------------------------------------------------
342 Bool_t AliJetDummyGeo::RelPosCellInSModule(Int_t absId, Double_t &xr, Double_t &yr, Double_t &zr) const
343 {
344   // Look to see what the relative position inside a given cell is
345   // for a recpoint.
346   // Alice numbering scheme - Jun 08, 2006
347   // In:
348   // absId   - cell is as in Geant,     0<= absId   < fNCells;
349   // OUT:
350   // xr,yr,zr - x,y,z coordinates of cell with absId inside SM 
351
352   // Shift index taking into account the difference between standard SM 
353   // and SM of half size in phi direction
354   const Int_t phiIndexShift = fCentersOfCellsPhiDir.GetSize()/4; // Nov 22, 2006; was 6 for cas 2X2
355   static Int_t nSupMod, nModule, nIphi, nIeta, iphi, ieta;
356   if(!CheckAbsCellId(absId)) return kFALSE;
357
358   GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
359   GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi, ieta); 
360  
361   xr = fCentersOfCellsXDir.At(ieta);
362   zr = fCentersOfCellsEtaDir.At(ieta);
363
364   if(nSupMod<10) {
365     yr = fCentersOfCellsPhiDir.At(iphi);
366   } else {
367     yr = fCentersOfCellsPhiDir.At(iphi + phiIndexShift);
368   }
369
370   return kTRUE;
371 }
372
373 //------------------------------------------------------------------------------------
374 Bool_t  AliJetDummyGeo::CheckAbsCellId(Int_t absId) const
375
376   // May 31, 2006; only trd1 now
377   if(absId<0 || absId >= fNCells) return kFALSE;
378   else                            return kTRUE;
379 }
380
381 //------------------------------------------------------------------------------------
382 Bool_t AliJetDummyGeo::GetCellIndex(Int_t absId,Int_t &nSupMod,Int_t &nModule,Int_t &nIphi,Int_t &nIeta) const
383
384   // 21-sep-04; 19-oct-05;
385   // May 31, 2006; ALICE numbering scheme:
386   // 
387   // In:
388   // absId   - cell is as in Geant,     0<= absId   < fNCells;
389   // Out:
390   // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
391   // nModule  - module number in SM,    0<= nModule  < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
392   // nIphi   - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv; 
393   // nIeta   - cell number in eta driection inside module; 0<= nIeta < fNETAdiv; 
394   // 
395   static Int_t tmp=0, sm10=0;
396   if(!CheckAbsCellId(absId)) return kFALSE;
397
398   sm10 = fNCellsInSupMod*10;
399   if(absId >= sm10) { // 110 degree case; last two supermodules  
400     nSupMod = (absId-sm10) / (fNCellsInSupMod/2) + 10;
401     tmp     = (absId-sm10) % (fNCellsInSupMod/2);
402   } else {
403     nSupMod = absId / fNCellsInSupMod;
404     tmp     = absId % fNCellsInSupMod;
405   }
406
407   nModule  = tmp / fNCellsInModule;
408   tmp     = tmp % fNCellsInModule;
409   nIphi   = tmp / fNPHIdiv;
410   nIeta   = tmp % fNPHIdiv;
411
412   return kTRUE;
413 }
414
415 //------------------------------------------------------------------------------------
416 void AliJetDummyGeo::GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta, Int_t &iphi, Int_t &ieta) const
417
418   // 
419   // Added nSupMod; Nov 25, 05
420   // Alice numbering scheme  - Jun 01,2006 
421   // IN:
422   // nSupMod - super module(SM) number, 0<= nSupMod < fNumberOfSuperModules;
423   // nModule  - module number in SM,     0<= nModule  < fNCellsInSupMod/fNCellsInSupMod or(/2) for tow last SM (10th and 11th);
424   // nIphi   - cell number in phi driection inside module; 0<= nIphi < fNPHIdiv; 
425   // nIeta   - cell number in eta driection inside module; 0<= nIeta < fNETAdiv; 
426   // 
427  // OUT:
428   // ieta, iphi - indexes of cell(tower) in two dimensional grid of SM
429   // ieta - have to change from 0 to (fNZ*fNETAdiv-1)
430   // iphi - have to change from 0 to (fNPhi*fNPHIdiv-1 or fNPhi*fNPHIdiv/2-1)
431   //
432   static Int_t iphim, ietam;
433
434   GetModulePhiEtaIndexInSModule(nSupMod,nModule, iphim, ietam); 
435   //  ieta  = ietam*fNETAdiv + (1-nIeta); // x(module) = -z(SM) 
436   ieta  = ietam*fNETAdiv + (fNETAdiv - 1 - nIeta); // x(module) = -z(SM) 
437   iphi  = iphim*fNPHIdiv + nIphi;     // y(module) =  y(SM) 
438
439 }
440
441
442 //------------------------------------------------------------------------------------
443 void AliJetDummyGeo::GetModulePhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule,  Int_t &iphim, Int_t &ietam) const
444
445   // added nSupMod; - 19-oct-05 !
446   // Alice numbering scheme        - Jun 01,2006 
447   // ietam, iphi - indexes of module in two dimensional grid of SM
448   // ietam - have to change from 0 to fNZ-1
449   // iphim - have to change from 0 to nphi-1 (fNPhi-1 or fNPhi/2-1)
450   static Int_t nphi;
451
452   if(nSupMod>=10) nphi = fNPhi/2;
453   else            nphi = fNPhi;
454
455   ietam = nModule/nphi;
456   iphim = nModule%nphi;
457 }
458
459 //------------------------------------------------------------------------------------
460 Bool_t AliJetDummyGeo::GetAbsCellIdFromEtaPhi(Double_t eta, Double_t phi, Int_t &absId) const
461 {
462   // Nov 17,2006
463   // stay here - phi problem as usual 
464   static Int_t nSupMod, i, ieta, iphi, etaShift, nphi;
465   static Double_t absEta=0.0, d=0.0, dmin=0.0, phiLoc;
466   absId = nSupMod = - 1;
467   if(SuperModuleNumberFromEtaPhi(eta, phi, nSupMod)) {
468     // phi index first
469     phi    = TVector2::Phi_0_2pi(phi);
470     phiLoc = phi - fPhiCentersOfSM[nSupMod/2];
471     nphi   = fPhiCentersOfCells.GetSize();
472     if(nSupMod>=10) {
473       phiLoc = phi - 190.*TMath::DegToRad();
474       nphi /= 2;
475     }
476
477     dmin   = TMath::Abs(fPhiCentersOfCells[0]-phiLoc);
478     iphi   = 0;
479     for(i=1; i<nphi; i++) {
480       d = TMath::Abs(fPhiCentersOfCells[i] - phiLoc);
481       if(d < dmin) {
482         dmin = d;
483         iphi = i;
484       }
485     }
486     // odd SM are turned with respect of even SM - reverse indexes
487
488     // eta index
489     absEta   = TMath::Abs(eta);
490     etaShift = iphi*fCentersOfCellsEtaDir.GetSize();
491     dmin     = TMath::Abs(fEtaCentersOfCells[etaShift]-absEta);
492     ieta     = 0;
493     for(i=1; i<fCentersOfCellsEtaDir.GetSize(); i++) {
494       d = TMath::Abs(fEtaCentersOfCells[i+etaShift] - absEta);
495       if(d < dmin) {
496         dmin = d;
497         ieta = i;
498       }
499     }
500
501     if(eta<0) iphi = (nphi-1) - iphi;
502     absId = GetAbsCellIdFromCellIndexes(nSupMod, iphi, ieta);
503
504     return kTRUE;
505   }
506   return kFALSE;
507 }
508
509 //------------------------------------------------------------------------------------
510 Bool_t AliJetDummyGeo::SuperModuleNumberFromEtaPhi(Double_t eta, Double_t phi, Int_t &nSupMod) const
511
512   // Return false if phi belongs a phi cracks between SM
513  
514   static Int_t i;
515
516   if(TMath::Abs(eta) > fEtaMaxOfTRD1) return kFALSE;
517
518   phi = TVector2::Phi_0_2pi(phi); // move phi to (0,2pi) boundaries
519   for(i=0; i<6; i++) {
520     if(phi>=fPhiBoundariesOfSM[2*i] && phi<=fPhiBoundariesOfSM[2*i+1]) {
521       nSupMod = 2*i;
522       if(eta < 0.0) nSupMod++;
523       return kTRUE;
524     }
525   }
526   return kFALSE;
527 }
528
529 //------------------------------------------------------------------------------------
530 Int_t  AliJetDummyGeo::GetAbsCellIdFromCellIndexes(Int_t nSupMod, Int_t iphi, Int_t ieta) const
531 {
532   // Transition from super module number(nSupMod) and cell indexes (ieta,iphi) to absId
533   static Int_t ietam, iphim, nModule;
534   static Int_t nIeta, nIphi; // cell indexes in module
535
536   GetModuleIndexesFromCellIndexesInSModule(nSupMod, iphi, ieta, ietam, iphim, nModule);
537
538   nIeta = ieta%fNETAdiv;
539   nIeta = fNETAdiv - 1 - nIeta;
540   nIphi = iphi%fNPHIdiv;
541
542   return GetAbsCellId(nSupMod, nModule, nIphi, nIeta);
543 }
544
545 //------------------------------------------------------------------------------------
546 void  AliJetDummyGeo::GetModuleIndexesFromCellIndexesInSModule(Int_t nSupMod, Int_t iphi, Int_t ieta, 
547                         Int_t &iphim, Int_t &ietam, Int_t &nModule) const
548 {
549   // Transition from cell indexes (ieta,iphi) to module indexes (ietam,iphim, nModule)
550   static Int_t nphi;
551   nphi  = GetNumberOfModuleInPhiDirection(nSupMod);  
552
553   ietam  = ieta/fNETAdiv;
554   iphim  = iphi/fNPHIdiv;
555   nModule = ietam * nphi + iphim; 
556 }
557
558 //------------------------------------------------------------------------------------
559 Int_t AliJetDummyGeo::GetAbsCellId(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta) const
560
561   // 27-aug-04; 
562   // corr. 21-sep-04; 
563   //       13-oct-05; 110 degree case
564   // May 31, 2006; ALICE numbering scheme:
565   // 0 <= nSupMod < fNumberOfSuperModules
566   // 0 <= nModule  < fNPHI * fNZ ( fNPHI * fNZ/2 for fKey110DEG=1)
567   // 0 <= nIphi   < fNPHIdiv
568   // 0 <= nIeta   < fNETAdiv
569   // 0 <= absid   < fNCells
570   static Int_t id=0; // have to change from 0 to fNCells-1
571   if(nSupMod >= 10) { // 110 degree case; last two supermodules
572     id  = fNCellsInSupMod*10 + (fNCellsInSupMod/2)*(nSupMod-10);
573   } else {
574     id  = fNCellsInSupMod*nSupMod;
575   }
576   id += fNCellsInModule *nModule;
577   id += fNPHIdiv *nIphi;
578   id += nIeta;
579   if(id<0 || id >= fNCells) {
580     id = -TMath::Abs(id); // if negative something wrong
581   }
582   return id;
583 }
584
585 //------------------------------------------------------------------------------------
586 Bool_t AliJetDummyGeo::GetPhiBoundariesOfSMGap(Int_t nPhiSec, Double_t &phiMin, Double_t &phiMax) const
587 {
588   // 0<= nPhiSec <=4; phi in rad
589   // 0;  gap boundaries between  0th&2th  | 1th&3th SM
590   // 1;  gap boundaries between  2th&4th  | 3th&5th SM
591   // 2;  gap boundaries between  4th&6th  | 5th&7th SM
592   // 3;  gap boundaries between  6th&8th  | 7th&9th SM
593   // 4;  gap boundaries between  8th&10th | 9th&11th SM
594   if(nPhiSec<0 || nPhiSec >4) return kFALSE; 
595   phiMin = fPhiBoundariesOfSM[2*nPhiSec+1];
596   phiMax = fPhiBoundariesOfSM[2*nPhiSec+2];
597   return kTRUE; 
598 }
599
600 //------------------------------------------------------------------------------------
601 void AliJetDummyGeo::CreateListOfTrd1Modules()
602 {
603   // Generate the list of Trd1 modules
604   // which will make up the EMCAL
605   // geometry
606
607   AliJetDummyShishKebabTrd1Module *mod=0, *mTmp=0; // current module
608   if(fShishKebabTrd1Modules == 0) {
609     fShishKebabTrd1Modules = new TList;
610     fShishKebabTrd1Modules->SetName("ListOfTRD1");
611     for(Int_t iz=0; iz< GetNZ(); iz++) { 
612       if(iz==0) { 
613         mod  = new AliJetDummyShishKebabTrd1Module(TMath::Pi()/2.,this);
614       } else {
615         mTmp  = new AliJetDummyShishKebabTrd1Module(*mod);
616         mod   = mTmp;
617       }
618       fShishKebabTrd1Modules->Add(mod);
619     }
620   } else {
621     printf(" Already exits : ");
622   }
623   mod = (AliJetDummyShishKebabTrd1Module*)fShishKebabTrd1Modules->At(fShishKebabTrd1Modules->GetSize()-1);
624   fEtaMaxOfTRD1 = mod->GetMaxEtaOfModule(0);
625
626   //  printf(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n", 
627   //              fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1);
628
629   // Feb 20,2006;
630   // Jun 01, 2006 - ALICE numbering scheme
631   // define grid for cells in eta(z) and x directions in local coordinates system of SM
632   // Works just for 2x2 case only -- ?? start here
633   // 
634   //
635   // Define grid for cells in phi(y) direction in local coordinates system of SM
636   // as for 2X2 as for 3X3 - Nov 8,2006
637   // 
638
639   //  printf(" Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize());
640
641   Int_t ind=0; // this is phi index
642   Int_t ieta=0, nModule=0, iphiTemp;
643   Double_t xr, zr, theta, phi, eta, r, x,y;
644   TVector3 vglob;
645   Double_t ytCenterModule=0.0, ytCenterCell=0.0;
646
647   fCentersOfCellsPhiDir.Set(fNPhi*fNPHIdiv);
648   fPhiCentersOfCells.Set(fNPhi*fNPHIdiv);
649
650   Double_t R0 = GetIPDistance() + GetLongModuleSize()/2.;
651   for(Int_t it=0; it<fNPhi; it++) { // cycle on modules
652     ytCenterModule = -fParSM[1] + fPhiModuleSize*(2*it+1)/2;  // center of module
653     for(Int_t ic=0; ic<fNPHIdiv; ic++) { // cycle on cells in module
654       if(fNPHIdiv==2) {
655         ytCenterCell = ytCenterModule + fPhiTileSize *(2*ic-1)/2.;
656       } else if(fNPHIdiv==3){
657         ytCenterCell = ytCenterModule + fPhiTileSize *(ic-1);
658       } else if(fNPHIdiv==1){
659         ytCenterCell = ytCenterModule;
660       }
661       fCentersOfCellsPhiDir.AddAt(ytCenterCell,ind);
662       // Define grid on phi direction
663       // Grid is not the same for different eta bin;
664       // Effect is small but is still here
665       phi = TMath::ATan2(ytCenterCell, R0);
666       fPhiCentersOfCells.AddAt(phi, ind);
667
668       //      printf(" ind %2.2i : y %8.3f ", ind, fCentersOfCellsPhiDir.At(ind)); 
669       ind++;
670     }
671   }
672
673   fCentersOfCellsEtaDir.Set(fNZ *fNETAdiv);
674   fCentersOfCellsXDir.Set(fNZ *fNETAdiv);
675   fEtaCentersOfCells.Set(fNZ *fNETAdiv * fNPhi*fNPHIdiv);
676   if(fDebug>1) AliInfo(Form(" Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize()));
677   for(Int_t it=0; it<fNZ; it++) {
678     AliJetDummyShishKebabTrd1Module *trd1 = GetShishKebabModule(it);
679     nModule = fNPhi*it;
680     for(Int_t ic=0; ic<fNETAdiv; ic++) {
681       if(fNPHIdiv==2) {
682         trd1->GetCenterOfCellInLocalCoordinateofSM(ic, xr, zr);      // case of 2X2
683         GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta); 
684       } if(fNPHIdiv==3) {
685         trd1->GetCenterOfCellInLocalCoordinateofSM_3X3(ic, xr, zr);  // case of 3X3
686         GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta); 
687       } if(fNPHIdiv==1) {
688         trd1->GetCenterOfCellInLocalCoordinateofSM_1X1(xr, zr);      // case of 1X1
689         GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta); 
690       }
691       fCentersOfCellsXDir.AddAt(Float_t(xr) - fParSM[0],ieta);
692       fCentersOfCellsEtaDir.AddAt(Float_t(zr) - fParSM[2],ieta);
693       // Define grid on eta direction for each bin in phi
694       for(Int_t iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
695         x = xr + trd1->GetRadius();
696         y = fCentersOfCellsPhiDir[iphi];
697         r = TMath::Sqrt(x*x + y*y + zr*zr);
698         theta = TMath::ACos(zr/r);
699         eta   = AliJetDummyShishKebabTrd1Module::ThetaToEta(theta);
700         //        ind   = ieta*fCentersOfCellsPhiDir.GetSize() + iphi;
701         ind   = iphi*fCentersOfCellsEtaDir.GetSize() + ieta;
702         fEtaCentersOfCells.AddAt(eta, ind);
703       }
704       //printf(" ieta %i : xr + trd1->GetRadius() %f : zr %f : eta %f \n", ieta, xr + trd1->GetRadius(), zr, eta);
705     }
706   }
707
708   if(fDebug>1){
709     for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
710       AliInfo(Form(" ind %2.2i : z %8.3f : x %8.3f", i+1, 
711                    fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i)));
712     }
713   }
714 }
715
716 //------------------------------------------------------------------------------------
717 AliJetDummyShishKebabTrd1Module* AliJetDummyGeo::GetShishKebabModule(Int_t neta)
718 {
719   // This method was too long to be included in the header file - the
720   // rule checker complained about it's length, so we move it here. It
721   // returns the shishkebabmodule at a given eta index point.
722
723   static AliJetDummyShishKebabTrd1Module* trd1=0;
724   if(fShishKebabTrd1Modules && neta>=0 && neta<fShishKebabTrd1Modules->GetSize()) {
725     trd1 = (AliJetDummyShishKebabTrd1Module*)fShishKebabTrd1Modules->At(neta);
726   } else trd1 = 0;
727   return trd1;
728 }
729
730 //------------------------------------------------------------------------------------
731 void  AliJetDummyGeo::GetTransformationForSM()
732 {
733   // Uses the geometry manager to load the transformation matrix
734   // for the supermodules
735   // Unused after 19 Jan, 2007 - keep for compatibility; 
736
737   return;
738   static Bool_t transInit=kFALSE;
739   if(transInit) return;
740
741   Int_t i=0;
742   if(gGeoManager == 0) {
743     Info("CreateTransformationForSM() "," Load geometry : TGeoManager::Import()");
744     assert(0);
745   }
746
747   TGeoNode *tn = gGeoManager->GetTopNode();
748   TGeoNode *node=0, *xen1 = 0;
749   for(i=0; i<tn->GetNdaughters(); i++) {
750     node = tn->GetDaughter(i);
751     TString ns(node->GetName());
752     if(ns.Contains(GetNameOfEMCALEnvelope())) {
753       xen1 = node;
754       break;
755     }
756   }
757
758   if(!xen1) {
759     Info("CreateTransformationForSM() "," geometry has not EMCAL envelope with name %s", 
760     GetNameOfEMCALEnvelope());
761     assert(0);
762   }
763   AliInfo(Form(" i %i : EMCAL Envelope is %s : #SM %i \n", i, xen1->GetName(), xen1->GetNdaughters()));
764   for(i=0; i<xen1->GetNdaughters(); i++) {
765     TGeoNodeMatrix *sm = (TGeoNodeMatrix*)xen1->GetDaughter(i);
766     fMatrixOfSM[i] = sm->GetMatrix();
767   }
768   AliInfo(Form("transInit %d: ", transInit));
769   transInit = kTRUE;
770 }
771