]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGeometry.cxx
Minor correction before clean up for MDC
[u/mrichter/AliRoot.git] / EMCAL / 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 // Places the the Barrel Geometry of The EMCAL at Midrapidity
22 // between 80 and 180(or 190) degrees of Phi and
23 // -0.7 to 0.7 in eta 
24 // Number of Modules and Layers may be controlled by 
25 // the name of the instance defined               
26 //*-- Author: Sahal Yacoob (LBL / UCT)
27 //     and  : Yves Schutz (SUBATECH)
28 //     and  : Jennifer Klay (LBL)
29 //     SHASHLYK : Aleksei Pavlinov (WSU)
30
31 // --- AliRoot header files ---
32 #include <TMath.h>
33 #include <TVector3.h>
34
35 // -- ALICE Headers.
36 //#include "AliConst.h"
37
38 // --- EMCAL headers
39 #include "AliEMCALGeometry.h"
40
41 ClassImp(AliEMCALGeometry)
42
43 AliEMCALGeometry *AliEMCALGeometry::fgGeom = 0;
44 Bool_t            AliEMCALGeometry::fgInit = kFALSE;
45 TString name; // contains name of geometry
46
47 //______________________________________________________________________
48 AliEMCALGeometry::~AliEMCALGeometry(void){
49     // dtor
50 }
51
52 //______________________________________________________________________
53 Bool_t AliEMCALGeometry::AreInSameTower(Int_t id1, Int_t id2) const {
54   // Find out whether two hits are in the same tower
55   Int_t idmax = TMath::Max(id1, id2) ; 
56   Int_t idmin = TMath::Min(id1, id2) ;
57   if ( ((idmax - GetNZ() * GetNPhi()) == idmin ) || 
58        ((idmax - 2 * GetNZ() * GetNPhi()) == idmin ) )
59     return kTRUE ; 
60   else 
61     return kFALSE ; 
62 }
63
64 //______________________________________________________________________
65 void AliEMCALGeometry::Init(void){
66   // Initializes the EMCAL parameters
67   // naming convention : GUV_WX_N_ gives the composition of a tower
68   // WX inform about the composition of the EM calorimeter section: 
69   //   thickness in mm of Pb radiator (W) and of scintillator (X), and number of scintillator layers (N)
70   // New geometry: EMCAL_55_25
71   // 24-aug-04 for shish-kebab
72   // SHISH_25 or SHISH_62
73   // 11-oct-05 - correction for final design
74   fgInit = kFALSE; // Assume failed until proven otherwise.
75   name   = GetName();
76   name.ToUpper();
77   fKey110DEG = 0;
78   if(name.Contains("110DEG")) fKey110DEG = 1; // for GetAbsCellId
79
80   fNZ             = 114;        // granularity along Z (eta) 
81   fNPhi           = 168;        // granularity in phi (azimuth)
82   fArm1PhiMin     = 60.0;       // degrees, Starting EMCAL Phi position
83   fArm1PhiMax     = 180.0;      // degrees, Ending EMCAL Phi position
84   fArm1EtaMin     = -0.7;       // pseudorapidity, Starting EMCAL Eta position
85   fArm1EtaMax     = +0.7;       // pseudorapidity, Ending EMCAL Eta position
86   fIPDistance     = 454.0;      // cm, Radial distance to inner surface of EMCAL
87   fPhiGapForSM    = 0.;         // cm, only for final TRD1 geometry
88
89   // geometry
90   if (name == "EMCAL_55_25") {
91     fECPbRadThickness  = 0.5;  // cm, Thickness of the Pb radiators
92     fECScintThick      = 0.5;  // cm, Thickness of the scintillator
93     fNECLayers         = 25;   // number of scintillator layers
94     
95     fSampling          = 13.1;  // calculated with Birk's law implementation
96  
97     fAlFrontThick      = 3.5;  // cm, Thickness of front Al layer
98     fGap2Active        = 1.0;  // cm, Gap between Al and 1st Scintillator
99   }
100   else if( name == "G56_2_55_19" || name == "EMCAL_5655_21" || name == "G56_2_55_19_104_14"|| name == "G65_2_64_19" || name == "EMCAL_6564_21"){
101     Fatal("Init", "%s is an old geometry! Please update your Config file", name.Data()) ;
102   }
103   else if(name.Contains("SHISH")){
104     // 7-sep-05; integration issue
105     fArm1PhiMin     = 80.0;     // 60  -> 80
106     fArm1PhiMax     = 180.0;    // 180 -> 190
107
108     fNumberOfSuperModules = 10; // 12 = 6 * 2 (6 in phi, 2 in Z);
109     fSteelFrontThick = 2.54;    //  9-sep-04
110     fIPDistance      = 460.0;
111     fFrontSteelStrip = fPassiveScintThick = 0.0; // 13-may-05
112     fLateralSteelStrip = 0.025; // before MAY 2005 
113     fPhiModuleSize   = fEtaModuleSize   = 11.4;
114     fPhiTileSize = fEtaTileSize      = 5.52; // (11.4-5.52*2)/2. = 0.18 cm (wall thickness)
115     fNPhi            = 14;
116     fNZ              = 30;
117     fAlFrontThick    = fGap2Active = 0;
118     fNPHIdiv = fNETAdiv = 2;
119
120     fNECLayers       = 62;
121     fECScintThick    = fECPbRadThickness = 0.2;
122     fSampling        = 1.;  // 30-aug-04 - should be calculated
123     if(name.Contains("TWIST")) { // all about EMCAL module
124       fNZ             = 27;  // 16-sep-04
125     } else if(name.Contains("TRD")) {
126       fIPDistance      = 428.0;  //  11-may-05
127       fSteelFrontThick = 0.0;    // 3.17 -> 0.0; 28-mar-05 : no stell plate
128       fNPhi            = 12;
129       fSampling       = 12.327;
130       fPhiModuleSize = fEtaModuleSize = 12.26;
131       fNZ            = 26;     // 11-oct-04
132       fTrd1Angle     = 1.3;    // in degree
133 // 18-nov-04; 1./0.08112=12.327
134 // http://pdsfweb01.nersc.gov/~pavlinov/ALICE/SHISHKEBAB/RES/linearityAndResolutionForTRD1.html
135       if(name.Contains("TRD1")) {       // 30-jan-05
136         // for final design
137         fPhiGapForSM    = 2.;         // cm, only for final TRD1 geometry
138         if(name.Contains("MAY05") || name.Contains("WSUC") || name.Contains("FINAL")){
139           fNumberOfSuperModules = 12; // 20-may-05
140           if(name.Contains("WSUC")) fNumberOfSuperModules = 1; // 27-may-05
141           fNECLayers     = 77;       // (13-may-05 from V.Petrov)
142           fPhiModuleSize = 12.5;     // 20-may-05 - rectangular shape
143           fEtaModuleSize = 11.9;
144           fECScintThick  = fECPbRadThickness = 0.16;// (13-may-05 from V.Petrov)
145           fFrontSteelStrip   = 0.025;// 0.025cm = 0.25mm  (13-may-05 from V.Petrov)
146           fLateralSteelStrip = 0.01; // 0.01cm  = 0.1mm   (13-may-05 from V.Petrov) - was 0.025
147           fPassiveScintThick = 0.8;  // 0.8cm   = 8mm     (13-may-05 from V.Petrov)
148           fNZ                = 24;
149           fTrd1Angle         = 1.5;  // 1.3 or 1.5
150
151           if(name.Contains("FINAL")) { // 9-sep-05
152             fNumberOfSuperModules = 10;
153             if(name.Contains("110DEG")) {
154               fNumberOfSuperModules = 12;// last two modules have size 10 degree in phi (180<phi<190)
155               fArm1PhiMax = 200.0; // for XEN1 and turn angle of super modules
156             }
157             fPhiModuleSize = 12.26 - fPhiGapForSM / Float_t(fNPhi); // first assumption
158             fEtaModuleSize = fPhiModuleSize;
159             if(name.Contains("HUGE")) fNECLayers *= 3; // 28-oct-05 for analysing leakage    
160           }
161         }
162       } else if(name.Contains("TRD2")) {       // 30-jan-05
163         fSteelFrontThick = 0.0;         // 11-mar-05
164         fIPDistance+= fSteelFrontThick; // 1-feb-05 - compensate absence of steel plate
165         fTrd1Angle  = 1.64;             // 1.3->1.64
166         fTrd2AngleY = fTrd1Angle;       //  symmetric case now
167         fEmptySpace    = 0.2; // 2 mm
168         fTubsR         = fIPDistance; // 31-jan-05 - as for Fred case
169
170         fPhiModuleSize  = fTubsR*2.*TMath::Tan(fTrd2AngleY*TMath::DegToRad()/2.);
171         fPhiModuleSize -= fEmptySpace/2.; // 11-mar-05  
172         fEtaModuleSize  = fPhiModuleSize; // 20-may-05 
173         fTubsTurnAngle  = 3.;
174       }
175       fNPHIdiv = fNETAdiv  = 2;   // 13-oct-04 - division again
176       if(name.Contains("3X3")) {   // 23-nov-04
177         fNPHIdiv = fNETAdiv  = 3;
178       } else if(name.Contains("4X4")) {
179         fNPHIdiv = fNETAdiv  = 4;
180       }
181     }
182     fPhiTileSize = fPhiModuleSize/2. - fLateralSteelStrip; // 13-may-05 
183     fEtaTileSize = fEtaModuleSize/2. - fLateralSteelStrip; // 13-may-05 
184
185     if(name.Contains("25")){
186       fNECLayers     = 25;
187       fECScintThick  = fECPbRadThickness = 0.5;
188     }
189     if(name.Contains("WSUC")){ // 18-may-05 - about common structure
190       fShellThickness = 30.; // should be change 
191       fNPhi = fNZ = 4; 
192     }
193     // constant for transition absid <--> indexes
194     fNCellsInTower  = fNPHIdiv*fNETAdiv;
195     fNCellsInSupMod = fNCellsInTower*fNPhi*fNZ;
196     fNCells         = fNCellsInSupMod*fNumberOfSuperModules;
197     if(name.Contains("110DEG")) fNCells -= fNCellsInSupMod;
198
199     fLongModuleSize = fNECLayers*(fECScintThick + fECPbRadThickness);
200     if(name.Contains("MAY05")) fLongModuleSize += (fFrontSteelStrip + fPassiveScintThick);
201
202     // 30-sep-04
203     if(name.Contains("TRD")) {
204       f2Trd1Dx2 = fEtaModuleSize + 2.*fLongModuleSize*TMath::Tan(fTrd1Angle*TMath::DegToRad()/2.);
205       if(name.Contains("TRD2")) {  // 27-jan-05
206         f2Trd2Dy2 = fPhiModuleSize + 2.*fLongModuleSize*TMath::Tan(fTrd2AngleY*TMath::DegToRad()/2.);
207       }
208     }
209   }
210   else
211     Fatal("Init", "%s is an undefined geometry!", name.Data()) ; 
212                  
213
214   fNPhiSuperModule = fNumberOfSuperModules/2;
215   if(fNPhiSuperModule<1) fNPhiSuperModule = 1;
216   //There is always one more scintillator than radiator layer because of the first block of aluminium
217   fShellThickness = fAlFrontThick + fGap2Active + fNECLayers*GetECScintThick()+(fNECLayers-1)*GetECPbRadThick();
218   if(name.Contains("SHISH")) {
219     fShellThickness = fSteelFrontThick + fLongModuleSize;
220     if(name.Contains("TWIST")) { // 13-sep-04
221       fShellThickness  = TMath::Sqrt(fLongModuleSize*fLongModuleSize + fPhiModuleSize*fEtaModuleSize);
222       fShellThickness += fSteelFrontThick;
223     } else if(name.Contains("TRD")) { // 1-oct-04
224       fShellThickness  = TMath::Sqrt(fLongModuleSize*fLongModuleSize + f2Trd1Dx2*f2Trd1Dx2);
225       fShellThickness += fSteelFrontThick;
226     }
227   }
228
229   fZLength        = 2.*ZFromEtaR(fIPDistance+fShellThickness,fArm1EtaMax); // Z coverage
230   fEnvelop[0]     = fIPDistance; // mother volume inner radius
231   fEnvelop[1]     = fIPDistance + fShellThickness; // mother volume outer r.
232   fEnvelop[2]     = 1.00001*fZLength; // add some padding for mother volume. 
233   
234   fgInit = kTRUE; 
235   
236   if (kTRUE) {
237     printf("Init: geometry of EMCAL named %s is as follows:\n", name.Data());
238     printf( "               ECAL      : %d x (%f cm Pb, %f cm Sc) \n", GetNECLayers(), GetECPbRadThick(), GetECScintThick() ) ; 
239     if(name.Contains("SHISH")){
240       printf(" fIPDistance       %6.3f cm \n", fIPDistance);
241       if(fSteelFrontThick>0.) 
242       printf(" fSteelFrontThick  %6.3f cm \n", fSteelFrontThick);
243       printf(" fNPhi %i   |  fNZ %i \n", fNPhi, fNZ);
244       printf(" fNCellsInTower %i : fNCellsInSupMod %i : fNCells %i\n",fNCellsInTower, fNCellsInSupMod, fNCells);
245       if(name.Contains("MAY05")){
246         printf(" fFrontSteelStrip         %6.4f cm (thickness of front steel strip)\n", 
247         fFrontSteelStrip);
248         printf(" fLateralSteelStrip       %6.4f cm (thickness of lateral steel strip)\n", 
249         fLateralSteelStrip);
250         printf(" fPassiveScintThick  %6.4f cm (thickness of front passive Sc tile)\n",
251         fPassiveScintThick);
252       }
253       printf(" X:Y module size   %6.3f , %6.3f cm \n", fPhiModuleSize, fEtaModuleSize);
254       printf(" X:Y   tile size   %6.3f , %6.3f cm \n", fPhiTileSize, fEtaTileSize);
255       printf(" fLongModuleSize   %6.3f cm \n", fLongModuleSize);
256       printf(" #supermodule in phi direction %i \n", fNPhiSuperModule );
257     }
258     if(name.Contains("TRD")) {
259       printf(" fTrd1Angle %7.4f\n", fTrd1Angle);
260       printf(" f2Trd1Dx2  %7.4f\n",  f2Trd1Dx2);
261       if(name.Contains("TRD2")) {
262         printf(" fTrd2AngleY     %7.4f\n", fTrd2AngleY);
263         printf(" f2Trd2Dy2       %7.4f\n", f2Trd2Dy2);
264         printf(" fTubsR          %7.2f cm\n", fTubsR);
265         printf(" fTubsTurnAngle  %7.4f\n", fTubsTurnAngle);
266         printf(" fEmptySpace     %7.4f cm\n", fEmptySpace);
267       } else if(name.Contains("TRD1") && name.Contains("FINAL")){
268         printf(" fPhiGapForSM  %7.4f cm \n",  fPhiGapForSM);
269         if(name.Contains("110DEG"))printf(" Last two modules have size 10 degree in  phi (180<phi<190)\n");
270       }
271     }
272     printf("Granularity: %d in eta and %d in phi\n", GetNZ(), GetNPhi()) ;
273     printf("Layout: phi = (%7.1f, %7.1f), eta = (%5.2f, %5.2f), IP = %7.2f\n",  
274            GetArm1PhiMin(), GetArm1PhiMax(),GetArm1EtaMin(), GetArm1EtaMax(), GetIPDistance() );
275   }
276 }
277
278 //______________________________________________________________________
279 AliEMCALGeometry *  AliEMCALGeometry::GetInstance(){ 
280   // Returns the pointer of the unique instance
281   
282   return static_cast<AliEMCALGeometry *>( fgGeom ) ; 
283 }
284
285 //______________________________________________________________________
286 AliEMCALGeometry* AliEMCALGeometry::GetInstance(const Text_t* name,
287                                                 const Text_t* title){
288     // Returns the pointer of the unique instance
289
290     AliEMCALGeometry * rv = 0; 
291     if ( fgGeom == 0 ) {
292         if ( strcmp(name,"") == 0 ) rv = 0;
293         else {    
294             fgGeom = new AliEMCALGeometry(name, title);
295             if ( fgInit ) rv = (AliEMCALGeometry * ) fgGeom;
296             else {
297                 rv = 0; 
298                 delete fgGeom; 
299                 fgGeom = 0; 
300             } // end if fgInit
301         } // end if strcmp(name,"")
302     }else{
303         if ( strcmp(fgGeom->GetName(), name) != 0 ) {
304           printf("\ncurrent geometry is ") ;  
305           printf(fgGeom->GetName());
306           printf("\n                      you cannot call     "); 
307           printf(name);  
308         }else{
309           rv = (AliEMCALGeometry *) fgGeom; 
310         } // end if
311     }  // end if fgGeom
312     return rv; 
313 }
314
315 //______________________________________________________________________
316 Int_t AliEMCALGeometry::TowerIndex(Int_t ieta,Int_t iphi) const {
317   // Returns the tower index number from the based on the Z and Phi
318   // index numbers.
319   // Inputs:
320   //   Int_t ieta    // index along z axis [1-fNZ]
321   //   Int_t iphi  // index along phi axis [1-fNPhi]
322   // Outputs:
323   //   none.
324   // Returned
325   //   Int_t index // Tower index number 
326   
327   if ( (ieta <= 0 || ieta>GetNEta()) || 
328        (iphi <= 0 || iphi>GetNPhi())) {
329     Error("TowerIndex", "Unexpected parameters eta = %d phi = %d!", ieta, iphi) ; 
330     return -1;
331   }
332   return ( (iphi - 1)*GetNEta() + ieta ); 
333 }
334
335 //______________________________________________________________________
336 void AliEMCALGeometry::TowerIndexes(Int_t index,Int_t &ieta,Int_t &iphi) const {
337   // Inputs:
338   //   Int_t index // Tower index number [1-fNZ*fNPhi]
339   // Outputs:
340   //   Int_t ieta    // index allong z axis [1-fNZ]
341   //   Int_t iphi  // index allong phi axis [1-fNPhi]
342   // Returned
343   //   none.
344
345   Int_t nindex = 0;
346
347   if ( IsInECA(index) ) { // ECAL index
348     nindex = index ;
349   }
350   else {
351     Error("TowerIndexes", "Unexpected Id number!") ;
352     ieta = -1;
353     iphi = -1;
354     return;
355   }   
356
357   if (nindex%GetNZ()) 
358     iphi = nindex / GetNZ() + 1 ; 
359   else 
360     iphi = nindex / GetNZ() ; 
361   ieta = nindex - (iphi - 1) * GetNZ() ; 
362
363   if (gDebug==2)
364     printf("TowerIndexes: index=%d,%d, ieta=%d, iphi = %d", index, nindex,ieta, iphi) ; 
365   return;
366   
367 }
368
369 //______________________________________________________________________
370 void AliEMCALGeometry::EtaPhiFromIndex(Int_t index,Float_t &eta,Float_t &phi) const {
371     // given the tower index number it returns the based on the eta and phi
372     // of the tower.
373     // Inputs:
374     //   Int_t index // Tower index number [1-fNZ*fNPhi]
375     // Outputs:
376     //   Float_t eta  // eta of center of tower in pseudorapidity
377     //   Float_t phi  // phi of center of tower in degrees
378     // Returned
379     //   none.
380     Int_t ieta, iphi;
381     Float_t deta, dphi ;
382
383     TowerIndexes(index,ieta,iphi);
384     
385     if (gDebug == 2) 
386       printf("EtaPhiFromIndex: index = %d, ieta = %d, iphi = %d", index, ieta, iphi) ;
387
388     deta = (GetArm1EtaMax()-GetArm1EtaMin())/(static_cast<Float_t>(GetNEta()));
389     eta  = GetArm1EtaMin() + ((static_cast<Float_t>(ieta) - 0.5 ))*deta;
390
391     dphi = (GetArm1PhiMax() - GetArm1PhiMin())/(static_cast<Float_t>(GetNPhi()));  // in degrees.
392     phi  = GetArm1PhiMin() + dphi*(static_cast<Float_t>(iphi) - 0.5);//iphi range [1-fNphi].
393 }
394
395 //______________________________________________________________________
396 Int_t AliEMCALGeometry::TowerIndexFromEtaPhi(Float_t eta,Float_t phi) const {
397     // returns the tower index number based on the eta and phi of the tower.
398     // Inputs:
399     //   Float_t eta  // eta of center of tower in pseudorapidity
400     //   Float_t phi  // phi of center of tower in degrees
401     // Outputs:
402     //   none.
403     // Returned
404     //   Int_t index // Tower index number [1-fNZ*fNPhi]
405
406     Int_t ieta,iphi;
407
408     ieta = static_cast<Int_t> ( 1 + (static_cast<Float_t>(GetNEta()) * (eta - GetArm1EtaMin()) / (GetArm1EtaMax() - GetArm1EtaMin())) ) ;
409
410     if( ieta <= 0 || ieta > GetNEta() ) { 
411       Error("TowerIndexFromEtaPhi", "Unexpected (eta, phi) = (%f, %f) value, outside of EMCAL!", eta, phi) ; 
412       return -1 ; 
413     }
414
415     iphi = static_cast<Int_t> ( 1 + (static_cast<Float_t>(GetNPhi()) * (phi - GetArm1PhiMin()) / (GetArm1PhiMax() - GetArm1PhiMin())) ) ;
416
417     if( iphi <= 0 || iphi > GetNPhi() ) { 
418       Error("TowerIndexFromEtaPhi", "Unexpected (eta, phi) = (%f, %f) value, outside of EMCAL!", eta, phi) ; 
419       return -1 ; 
420     }
421
422     return TowerIndex(ieta,iphi);
423 }
424
425 //______________________________________________________________________
426 Bool_t AliEMCALGeometry::AbsToRelNumbering(Int_t AbsId, Int_t *relid) const {
427     // Converts the absolute numbering into the following array/
428     //  relid[0] = Row number inside EMCAL
429     //  relid[1] = Column number inside EMCAL
430     // Input:
431     //   Int_t AbsId // Tower index number [1-2*fNZ*fNPhi]
432     // Outputs:
433     //   Int_t *relid // array of 2. Described above.
434     Bool_t rv  = kTRUE ;
435     Int_t ieta=0,iphi=0,index=AbsId;
436
437     TowerIndexes(index,ieta,iphi);
438     relid[0] = ieta;
439     relid[1] = iphi;
440
441     return rv;
442 }
443
444 //______________________________________________________________________
445 void AliEMCALGeometry::PosInAlice(const Int_t *relid, Float_t &theta, Float_t &phi) const 
446 {
447   // Converts the relative numbering into the local EMCAL-module (x, z)
448   // coordinates
449   Int_t ieta = relid[0]; // offset along x axis
450   Int_t iphi = relid[1]; // offset along z axis
451   Int_t index;
452   Float_t eta;
453   
454   index = TowerIndex(ieta,iphi);
455   EtaPhiFromIndex(index,eta,phi);
456   //theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
457   theta = 2.0*TMath::ATan(TMath::Exp(-eta));
458
459   // correct for distance to IP
460   Float_t d = GetIP2ECASection() - GetIPDistance() ;  
461
462   Float_t correction = 1 + d/GetIPDistance() ; 
463   Float_t tantheta = TMath::Tan(theta) * correction ; 
464   theta = TMath::ATan(tantheta) * TMath::RadToDeg() ; 
465   if (theta < 0 ) 
466     theta += 180. ; 
467   
468   return;
469 }
470
471 //______________________________________________________________________
472 void AliEMCALGeometry::PosInAlice(Int_t absid, Float_t &theta, Float_t &phi) const 
473 {
474   // Converts the relative numbering into the local EMCAL-module (x, z)
475   // coordinates
476   Int_t relid[2] ; 
477   AbsToRelNumbering(absid, relid) ;
478   Int_t ieta = relid[0]; // offset along x axis
479   Int_t iphi = relid[1]; // offset along z axis
480   Int_t index;
481   Float_t eta;
482   
483   index = TowerIndex(ieta,iphi);
484   EtaPhiFromIndex(index,eta,phi);
485   theta = 2.0*TMath::ATan(TMath::Exp(-eta)) ;
486   
487   // correct for distance to IP
488   Float_t d = 0. ; 
489   if (IsInECA(absid))
490     d = GetIP2ECASection() - GetIPDistance() ; 
491   else {
492     Error("PosInAlice", "Unexpected id # %d!", absid) ; 
493     return;
494   }
495
496   Float_t correction = 1 + d/GetIPDistance() ; 
497   Float_t tantheta = TMath::Tan(theta) * correction ; 
498   theta = TMath::ATan(tantheta) * TMath::RadToDeg() ; 
499   if (theta < 0 ) 
500     theta += 180. ; 
501   
502   return;
503 }
504
505 //______________________________________________________________________
506 void AliEMCALGeometry::XYZFromIndex(const Int_t *relid,Float_t &x,Float_t &y, Float_t &z) const {
507     // given the tower relative number it returns the X, Y and Z
508     // of the tower.
509     
510     // Outputs:
511     //   Float_t x  // x of center of tower in cm
512     //   Float_t y  // y of center of tower in cm
513     //   Float_t z  // z of centre of tower in cm
514     // Returned
515     //   none.
516     
517     Float_t eta,theta, phi,cylradius=0. ;
518     
519     Int_t ieta = relid[0]; // offset along x axis
520     Int_t iphi = relid[1]; // offset along z axis.
521     Int_t index;
522     
523     index = TowerIndex(ieta,iphi);
524     EtaPhiFromIndex(index,eta,phi);
525     theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
526     
527     cylradius = GetIP2ECASection() ;  
528
529     Double_t  kDeg2Rad = TMath::DegToRad() ; 
530     x =  cylradius * TMath::Cos(phi * kDeg2Rad ) ;
531     y =  cylradius * TMath::Sin(phi * kDeg2Rad ) ; 
532     z =  cylradius / TMath::Tan(theta * kDeg2Rad ) ; 
533  
534  return;
535
536
537 //______________________________________________________________________
538 void AliEMCALGeometry::XYZFromIndex(Int_t absid,  TVector3 &v) const {
539     // given the tower relative number it returns the X, Y and Z
540     // of the tower.
541     
542     // Outputs:
543     //   Float_t x  // x of center of tower in cm
544     //   Float_t y  // y of center of tower in cm
545     //   Float_t z  // z of centre of tower in cm
546     // Returned
547     //   none.
548     
549     Float_t theta, phi,cylradius=0. ;
550         
551     PosInAlice(absid, theta, phi) ; 
552     
553     if ( IsInECA(absid) ) 
554       cylradius = GetIP2ECASection() ;
555     else {
556       Error("XYZFromIndex", "Unexpected Tower section") ;
557       return;
558     }
559
560     Double_t  kDeg2Rad = TMath::DegToRad() ; 
561     v.SetX(cylradius * TMath::Cos(phi * kDeg2Rad ) );
562     v.SetY(cylradius * TMath::Sin(phi * kDeg2Rad ) ); 
563     v.SetZ(cylradius / TMath::Tan(theta * kDeg2Rad ) ) ; 
564  
565  return;
566
567
568 Bool_t AliEMCALGeometry::IsInEMCAL(Double_t x, Double_t y, Double_t z) const {
569   // Checks whether point is inside the EMCal volume
570   //
571   // Code uses cylindrical approximation made of inner radius (for speed)
572   //
573   // Points behind EMCAl, i.e. R > outer radius, but eta, phi in acceptance 
574   // are considered to inside
575
576   Double_t r=sqrt(x*x+y*y);
577
578   if ( r > fEnvelop[0] ) {
579      Double_t theta;
580      theta  =    TMath::ATan2(r,z);
581      Double_t eta;
582      if(theta == 0) 
583        eta = 9999;
584      else 
585        eta    =   -TMath::Log(TMath::Tan(theta/2.));
586      if (eta < fArm1EtaMin || eta > fArm1EtaMax)
587        return 0;
588  
589      Double_t phi = TMath::ATan2(y,x) * 180./TMath::Pi();
590      if (phi > fArm1PhiMin && phi < fArm1PhiMax)
591        return 1;
592   }
593   return 0;
594 }
595
596 //
597 // == Shish-kebab cases ==
598 //
599 Int_t AliEMCALGeometry::GetAbsCellId(Int_t nSupMod, Int_t nTower, Int_t nIphi, Int_t nIeta)
600 { // 27-aug-04; 
601   // corr. 21-sep-04; 
602   //       13-oct-05; 110 degree case
603   // 1 <= nSupMod <= fNumberOfSuperModules
604   // 1 <= nTower  <= fNPHI * fNZ ( fNPHI * fNZ/2 for fKey110DEG=1)
605   // 1 <= nIphi   <= fNPHIdiv
606   // 1 <= nIeta   <= fNETAdiv
607   // 1 <= absid   <= fNCells
608   static Int_t id=0; // have to change from 1 to fNCells
609   if(fKey110DEG == 1 && nSupMod > 10) { // 110 degree case; last two supermodules
610     id  = fNCellsInSupMod*10 + (fNCellsInSupMod/2)*(nSupMod-11);
611   } else {
612     id  = fNCellsInSupMod*(nSupMod-1);
613   }
614   id += fNCellsInTower *(nTower-1);
615   id += fNPHIdiv *(nIphi-1);
616   id += nIeta;
617   if(id<=0 || id > fNCells) {
618 //     printf(" wrong numerations !!\n");
619 //     printf("    id      %6i(will be force to -1)\n", id);
620 //     printf("    fNCells %6i\n", fNCells);
621 //     printf("    nSupMod %6i\n", nSupMod);
622 //     printf("    nTower  %6i\n", nTower);
623 //     printf("    nIphi   %6i\n", nIphi);
624 //     printf("    nIeta   %6i\n", nIeta);
625     id = -TMath::Abs(id);
626   }
627   return id;
628 }
629
630 Bool_t  AliEMCALGeometry::CheckAbsCellId(Int_t ind)
631 { // 17-niv-04 - analog of IsInECA
632    if(name.Contains("TRD")) {
633      if(ind<=0 || ind > fNCells) return kFALSE;
634      else                        return kTRUE;
635    } else return IsInECA(ind);
636 }
637
638 Bool_t AliEMCALGeometry::GetCellIndex(Int_t absId,Int_t &nSupMod,Int_t &nTower,Int_t &nIphi,Int_t &nIeta)
639 { // 21-sep-04
640   // 19-oct-05;
641   static Int_t tmp=0, sm10=0;
642   if(absId<=0 || absId>fNCells) {
643 //     Info("GetCellIndex"," wrong abs Id %i !! \n", absId); 
644     return kFALSE;
645   }
646   sm10 = fNCellsInSupMod*10;
647   if(fKey110DEG == 1 && absId > sm10) { // 110 degree case; last two supermodules  
648     nSupMod = (absId-1-sm10) / (fNCellsInSupMod/2) + 11;
649     tmp     = (absId-1-sm10) % (fNCellsInSupMod/2);
650   } else {
651     nSupMod = (absId-1) / fNCellsInSupMod + 1;
652     tmp     = (absId-1) % fNCellsInSupMod;
653   }
654
655   nTower  = tmp / fNCellsInTower + 1;
656   tmp     = tmp % fNCellsInTower;
657   nIphi   = tmp / fNPHIdiv + 1;
658   nIeta   = tmp % fNPHIdiv + 1;
659
660   return kTRUE;
661 }
662
663 void AliEMCALGeometry::GetTowerPhiEtaIndexInSModule(Int_t nSupMod, Int_t nTower,  int &iphit, int &ietat)
664 { // added nSupMod; have to check  - 19-oct-05 ! 
665   static Int_t nphi;
666
667   if(fKey110DEG == 1 && nSupMod>=11) nphi = fNPhi/2;
668   else                               nphi = fNPhi;
669
670   ietat = (nTower-1)/nphi + 1; // have to change from 1 to fNZ
671   iphit = (nTower-1)%nphi + 1; // have to change from 1 to fNPhi
672 }
673
674 void AliEMCALGeometry::GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nTower, Int_t nIphi, Int_t nIeta, 
675 int &iphi, int &ieta)
676 { // added nSupMod; Nov 25, 05
677   static Int_t iphit, ietat;
678
679   GetTowerPhiEtaIndexInSModule(nSupMod,nTower, iphit, ietat); 
680   // have to change from 1 to fNZ*fNETAdiv
681   ieta  = (ietat-1)*fNETAdiv + (3-nIeta); // x(module) = -z(SM) 
682   // iphi - have to change from 1 to fNPhi*fNPHIdiv
683   iphi  = (iphit-1)*fNPHIdiv + nIphi;     // y(module) =  y(SM) 
684 }