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