]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGeometry.cxx
Test Digit macro
[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 //     SuperModules -> module(or tower) -> cell
31
32 // --- AliRoot header files ---
33 #include <assert.h>
34 #include <TMath.h>
35 #include <TVector3.h>
36 #include <TRegexp.h>
37 #include <TObjArray.h>
38 #include <TObjString.h>
39 #include <assert.h>
40 #include <TMatrixD.h>
41 #include <TClonesArray.h>
42
43 // -- ALICE Headers.
44 //#include "AliConst.h"
45
46 // --- EMCAL headers
47 #include "AliEMCALGeometry.h"
48 #include "AliEMCALDigit.h"
49
50 ClassImp(AliEMCALGeometry)
51
52 AliEMCALGeometry *AliEMCALGeometry::fgGeom = 0;
53 Bool_t            AliEMCALGeometry::fgInit = kFALSE;
54 TString name; // contains name of geometry
55
56 char *additionalOpts[]={"nl=",   // number of sampling layers
57                        "pbTh=", // cm, Thickness of the Pb
58                        "scTh="  // cm, Thickness of the Sc
59 };
60 int  nAdditionalOpts = sizeof(additionalOpts) / sizeof(char*);
61
62 //______________________________________________________________________
63 AliEMCALGeometry::~AliEMCALGeometry(void){
64     // dtor
65 }
66
67 //______________________________________________________________________
68 Bool_t AliEMCALGeometry::AreInSameTower(Int_t id1, Int_t id2) const {
69   // Find out whether two hits are in the same tower - have to be change
70   Int_t idmax = TMath::Max(id1, id2) ; 
71   Int_t idmin = TMath::Min(id1, id2) ;
72   if ( ((idmax - GetNZ() * GetNPhi()) == idmin ) || 
73        ((idmax - 2 * GetNZ() * GetNPhi()) == idmin ) )
74     return kTRUE ; 
75   else 
76     return kFALSE ; 
77 }
78
79 //______________________________________________________________________
80 void AliEMCALGeometry::Init(void){
81   // Initializes the EMCAL parameters
82   // naming convention : GUV_WX_N_ gives the composition of a tower
83   // WX inform about the composition of the EM calorimeter section: 
84   //   thickness in mm of Pb radiator (W) and of scintillator (X), and number of scintillator layers (N)
85   // New geometry: EMCAL_55_25
86   // 24-aug-04 for shish-kebab
87   // SHISH_25 or SHISH_62
88   // 11-oct-05   - correction for pre final design
89   // Feb 06,2006 - decrease the weight of EMCAL
90   fgInit = kFALSE; // Assume failed until proven otherwise.
91   name   = GetName();
92   name.ToUpper();
93   fKey110DEG = 0;
94   if(name.Contains("110DEG")) fKey110DEG = 1; // for GetAbsCellId
95
96   fNZ             = 114;        // granularity along Z (eta) 
97   fNPhi           = 168;        // granularity in phi (azimuth)
98   fArm1PhiMin     = 60.0;       // degrees, Starting EMCAL Phi position
99   fArm1PhiMax     = 180.0;      // degrees, Ending EMCAL Phi position
100   fArm1EtaMin     = -0.7;       // pseudorapidity, Starting EMCAL Eta position
101   fArm1EtaMax     = +0.7;       // pseudorapidity, Ending EMCAL Eta position
102   fIPDistance     = 454.0;      // cm, Radial distance to inner surface of EMCAL
103   fPhiGapForSM    = 0.;         // cm, only for final TRD1 geometry
104
105   // geometry
106   if(name.Contains("SHISH")){ // Only shahslyk now
107     // 7-sep-05; integration issue
108     fArm1PhiMin     = 80.0;     // 60  -> 80
109     fArm1PhiMax     = 180.0;    // 180 -> 190
110
111     fNumberOfSuperModules = 10; // 12 = 6 * 2 (6 in phi, 2 in Z);
112     fSteelFrontThick = 2.54;    //  9-sep-04
113     fIPDistance      = 460.0;
114     fFrontSteelStrip = fPassiveScintThick = 0.0; // 13-may-05
115     fLateralSteelStrip = 0.025; // before MAY 2005 
116     fPhiModuleSize   = fEtaModuleSize   = 11.4;
117     fPhiTileSize = fEtaTileSize      = 5.52; // (11.4-5.52*2)/2. = 0.18 cm (wall thickness)
118     fNPhi            = 14;
119     fNZ              = 30;
120     fAlFrontThick    = fGap2Active = 0;
121     fNPHIdiv = fNETAdiv = 2;
122
123     fNECLayers       = 62;
124     fECScintThick    = fECPbRadThickness = 0.2;
125     fSampling        = 1.;  // 30-aug-04 - should be calculated
126     if(name.Contains("TWIST")) { // all about EMCAL module
127       fNZ             = 27;  // 16-sep-04
128     } else if(name.Contains("TRD")) {
129       fIPDistance      = 428.0;  //  11-may-05
130       fSteelFrontThick = 0.0;    // 3.17 -> 0.0; 28-mar-05 : no stell plate
131       fNPhi            = 12;
132       fSampling       = 12.327;
133       fPhiModuleSize = fEtaModuleSize = 12.26;
134       fNZ            = 26;     // 11-oct-04
135       fTrd1Angle     = 1.3;    // in degree
136 // 18-nov-04; 1./0.08112=12.327
137 // http://pdsfweb01.nersc.gov/~pavlinov/ALICE/SHISHKEBAB/RES/linearityAndResolutionForTRD1.html
138       if(name.Contains("TRD1")) {       // 30-jan-05
139         // for final design
140         fPhiGapForSM    = 2.;         // cm, only for final TRD1 geometry
141         if(name.Contains("MAY05") || name.Contains("WSUC") || name.Contains("FINAL")){
142           fNumberOfSuperModules = 12; // 20-may-05
143           if(name.Contains("WSUC")) fNumberOfSuperModules = 1; // 27-may-05
144           fNECLayers     = 77;       // (13-may-05 from V.Petrov)
145           fPhiModuleSize = 12.5;     // 20-may-05 - rectangular shape
146           fEtaModuleSize = 11.9;
147           fECScintThick  = fECPbRadThickness = 0.16;// (13-may-05 from V.Petrov)
148           fFrontSteelStrip   = 0.025;// 0.025cm = 0.25mm  (13-may-05 from V.Petrov)
149           fLateralSteelStrip = 0.01; // 0.01cm  = 0.1mm   (13-may-05 from V.Petrov) - was 0.025
150           fPassiveScintThick = 0.8;  // 0.8cm   = 8mm     (13-may-05 from V.Petrov)
151           fNZ                = 24;
152           fTrd1Angle         = 1.5;  // 1.3 or 1.5
153
154           if(name.Contains("FINAL")) { // 9-sep-05
155             fNumberOfSuperModules = 10;
156             if(name.Contains("110DEG")) {
157               fNumberOfSuperModules = 12;// last two modules have size 10 degree in phi (180<phi<190)
158               fArm1PhiMax = 200.0; // for XEN1 and turn angle of super modules
159             }
160             fPhiModuleSize = 12.26 - fPhiGapForSM / Float_t(fNPhi); // first assumption
161             fEtaModuleSize = fPhiModuleSize;
162             if(name.Contains("HUGE")) fNECLayers *= 3; // 28-oct-05 for analysing leakage    
163           }
164         }
165       } else if(name.Contains("TRD2")) {       // 30-jan-05
166         fSteelFrontThick = 0.0;         // 11-mar-05
167         fIPDistance+= fSteelFrontThick; // 1-feb-05 - compensate absence of steel plate
168         fTrd1Angle  = 1.64;             // 1.3->1.64
169         fTrd2AngleY = fTrd1Angle;       //  symmetric case now
170         fEmptySpace    = 0.2; // 2 mm
171         fTubsR         = fIPDistance; // 31-jan-05 - as for Fred case
172
173         fPhiModuleSize  = fTubsR*2.*TMath::Tan(fTrd2AngleY*TMath::DegToRad()/2.);
174         fPhiModuleSize -= fEmptySpace/2.; // 11-mar-05  
175         fEtaModuleSize  = fPhiModuleSize; // 20-may-05 
176         fTubsTurnAngle  = 3.;
177       }
178       fNPHIdiv = fNETAdiv  = 2;   // 13-oct-04 - division again
179       if(name.Contains("3X3")) {   // 23-nov-04
180         fNPHIdiv = fNETAdiv  = 3;
181       } else if(name.Contains("4X4")) {
182         fNPHIdiv = fNETAdiv  = 4;
183       }
184     }
185     fPhiTileSize = fPhiModuleSize/2. - fLateralSteelStrip; // 13-may-05 
186     fEtaTileSize = fEtaModuleSize/2. - fLateralSteelStrip; // 13-may-05 
187
188     if(name.Contains("25")){
189       fNECLayers     = 25;
190       fECScintThick  = fECPbRadThickness = 0.5;
191     }
192     if(name.Contains("WSUC")){ // 18-may-05 - about common structure
193       fShellThickness = 30.; // should be change 
194       fNPhi = fNZ = 4; 
195     }
196
197     CheckAditionalOptions();
198
199     // constant for transition absid <--> indexes
200     fNCellsInTower  = fNPHIdiv*fNETAdiv;
201     fNCellsInSupMod = fNCellsInTower*fNPhi*fNZ;
202     fNCells         = fNCellsInSupMod*fNumberOfSuperModules;
203     if(name.Contains("110DEG")) fNCells -= fNCellsInSupMod;
204
205     fLongModuleSize = fNECLayers*(fECScintThick + fECPbRadThickness);
206     if(name.Contains("MAY05")) fLongModuleSize += (fFrontSteelStrip + fPassiveScintThick);
207
208     // 30-sep-04
209     if(name.Contains("TRD")) {
210       f2Trd1Dx2 = fEtaModuleSize + 2.*fLongModuleSize*TMath::Tan(fTrd1Angle*TMath::DegToRad()/2.);
211       if(name.Contains("TRD2")) {  // 27-jan-05
212         f2Trd2Dy2 = fPhiModuleSize + 2.*fLongModuleSize*TMath::Tan(fTrd2AngleY*TMath::DegToRad()/2.);
213       }
214     }
215   } else Fatal("Init", "%s is an undefined geometry!", name.Data()) ; 
216
217   fNPhiSuperModule = fNumberOfSuperModules/2;
218   if(fNPhiSuperModule<1) fNPhiSuperModule = 1;
219   //There is always one more scintillator than radiator layer because of the first block of aluminium
220   fShellThickness = fAlFrontThick + fGap2Active + fNECLayers*GetECScintThick()+(fNECLayers-1)*GetECPbRadThick();
221   if(name.Contains("SHISH")) {
222     fShellThickness = fSteelFrontThick + fLongModuleSize;
223     if(name.Contains("TWIST")) { // 13-sep-04
224       fShellThickness  = TMath::Sqrt(fLongModuleSize*fLongModuleSize + fPhiModuleSize*fEtaModuleSize);
225       fShellThickness += fSteelFrontThick;
226     } else if(name.Contains("TRD")) { // 1-oct-04
227       fShellThickness  = TMath::Sqrt(fLongModuleSize*fLongModuleSize + f2Trd1Dx2*f2Trd1Dx2);
228       fShellThickness += fSteelFrontThick;
229     }
230   }
231
232   fZLength        = 2.*ZFromEtaR(fIPDistance+fShellThickness,fArm1EtaMax); // Z coverage
233   fEnvelop[0]     = fIPDistance; // mother volume inner radius
234   fEnvelop[1]     = fIPDistance + fShellThickness; // mother volume outer r.
235   fEnvelop[2]     = 1.00001*fZLength; // add some padding for mother volume. 
236   
237   fgInit = kTRUE; 
238   
239   if (kTRUE) {
240     printf("Init: geometry of EMCAL named %s is as follows:\n", name.Data());
241     printf( "               ECAL      : %d x (%f cm Pb, %f cm Sc) \n", GetNECLayers(), GetECPbRadThick(), GetECScintThick() ) ; 
242     if(name.Contains("SHISH")){
243       printf(" fIPDistance       %6.3f cm \n", fIPDistance);
244       if(fSteelFrontThick>0.) 
245       printf(" fSteelFrontThick  %6.3f cm \n", fSteelFrontThick);
246       printf(" fNPhi %i   |  fNZ %i \n", fNPhi, fNZ);
247       printf(" fNCellsInTower %i : fNCellsInSupMod %i : fNCells %i\n",fNCellsInTower, fNCellsInSupMod, fNCells);
248       if(name.Contains("MAY05")){
249         printf(" fFrontSteelStrip         %6.4f cm (thickness of front steel strip)\n", 
250         fFrontSteelStrip);
251         printf(" fLateralSteelStrip       %6.4f cm (thickness of lateral steel strip)\n", 
252         fLateralSteelStrip);
253         printf(" fPassiveScintThick  %6.4f cm (thickness of front passive Sc tile)\n",
254         fPassiveScintThick);
255       }
256       printf(" X:Y module size     %6.3f , %6.3f cm \n", fPhiModuleSize, fEtaModuleSize);
257       printf(" X:Y   tile size     %6.3f , %6.3f cm \n", fPhiTileSize, fEtaTileSize);
258       printf(" #of sampling layers %i(fNECLayers) \n", fNECLayers);
259       printf(" fLongModuleSize     %6.3f cm \n", fLongModuleSize);
260       printf(" #supermodule in phi direction %i \n", fNPhiSuperModule );
261     }
262     if(name.Contains("TRD")) {
263       printf(" fTrd1Angle %7.4f\n", fTrd1Angle);
264       printf(" f2Trd1Dx2  %7.4f\n",  f2Trd1Dx2);
265       if(name.Contains("TRD2")) {
266         printf(" fTrd2AngleY     %7.4f\n", fTrd2AngleY);
267         printf(" f2Trd2Dy2       %7.4f\n", f2Trd2Dy2);
268         printf(" fTubsR          %7.2f cm\n", fTubsR);
269         printf(" fTubsTurnAngle  %7.4f\n", fTubsTurnAngle);
270         printf(" fEmptySpace     %7.4f cm\n", fEmptySpace);
271       } else if(name.Contains("TRD1") && name.Contains("FINAL")){
272         printf(" fPhiGapForSM  %7.4f cm \n",  fPhiGapForSM);
273         if(name.Contains("110DEG"))printf(" Last two modules have size 10 degree in  phi (180<phi<190)\n");
274       }
275     }
276     printf("Granularity: %d in eta and %d in phi\n", GetNZ(), GetNPhi()) ;
277     printf("Layout: phi = (%7.1f, %7.1f), eta = (%5.2f, %5.2f), IP = %7.2f\n",  
278            GetArm1PhiMin(), GetArm1PhiMax(),GetArm1EtaMin(), GetArm1EtaMax(), GetIPDistance() );
279   }
280   //TRU parameters. These parameters values are not the final ones.
281   fNTRU    = 3 ;
282   fNTRUEta = 3 ;
283   fNTRUPhi = 1 ;
284 }
285
286 //______________________________________________________________________
287
288 void AliEMCALGeometry::CheckAditionalOptions()
289 { // Feb 06,2006
290   fArrayOpts = new TObjArray;
291   Int_t nopt = ParseString(name, *fArrayOpts);
292   if(nopt==1) { // no aditional option(s)
293     fArrayOpts->Delete();
294     delete fArrayOpts;
295     fArrayOpts = 0; 
296     return;
297   }              
298   for(Int_t i=1; i<nopt; i++){
299     TObjString *o = (TObjString*)fArrayOpts->At(i); 
300
301     TString addOpt = o->String();
302     Int_t indj=-1;
303     for(Int_t j=0; j<nAdditionalOpts; j++) {
304       TString opt = additionalOpts[j];
305       if(addOpt.Contains(opt,TString::kIgnoreCase)) {
306           indj = j;
307         break;
308       }
309     }
310     if(indj<0) {
311       printf("<E> option |%s| unavailable : ** look to the file AliEMCALGeometry.h **\n", 
312       addOpt.Data());
313       assert(0);
314     } else {
315       printf("<I> option |%s| is valid : number %i : |%s|\n", 
316              addOpt.Data(), indj, additionalOpts[indj]);
317       if       (addOpt.Contains("NL=",TString::kIgnoreCase))   {// number of sampling layers
318         sscanf(addOpt.Data(),"NL=%i", &fNECLayers);
319         printf(" fNECLayers %i (new) \n", fNECLayers);
320       } else if(addOpt.Contains("PBTH=",TString::kIgnoreCase)) {//Thickness of the Pb
321         sscanf(addOpt.Data(),"PBTH=%f", &fECPbRadThickness);
322       } else if(addOpt.Contains("SCTH=",TString::kIgnoreCase)) {//Thickness of the Sc
323         sscanf(addOpt.Data(),"SCTH=%f", &fECScintThick);
324       }
325     }
326   }
327 }
328
329 //____________________________________________________________________________
330 TClonesArray *  AliEMCALGeometry::FillTRU(const TClonesArray * digits) {
331
332
333   //Orders digits ampitudes list in fNTRU TRUs (384 cells) per supermodule. 
334   //Each TRU is a TMatrixD, and they are kept in TClonesArrays. The number of 
335   //TRU in phi is fNTRUPhi, and the number of TRU in eta is fNTRUEta. For the 
336   //moment the TRU of the 2 smaller supermodules are considered to be equal 
337   //to the rest.  
338
339   //Check data members
340
341   if(fNTRUEta*fNTRUPhi != fNTRU)
342     Error("FillTRU"," Wrong number of TRUS per Eta or Phi");
343
344   //Initilize variables
345   //List of TRU matrices initialized to 0.
346   Int_t nCellsPhi = fNPhi*2/fNTRUPhi;
347   Int_t nCellsEta = fNZ*2/fNTRUEta;
348   TClonesArray * matrix = new TClonesArray("TMatrixD",1000);
349  
350   for(Int_t k = 0; k < fNTRU*fNumberOfSuperModules; k++){
351     TMatrixD  * trus = new TMatrixD(nCellsPhi,nCellsEta) ;
352     for(Int_t i = 0; i < nCellsPhi; i++)
353       for(Int_t j = 0; j < nCellsEta; j++)
354         (*trus)(i,j) = 0.0;
355
356     new((*matrix)[k]) TMatrixD(*trus) ;
357   }
358
359   AliEMCALDigit * dig ;
360   
361   //Declare variables
362   Int_t id      = -1; 
363   Float_t amp   = -1;
364   Int_t iSupMod = -1;
365   Int_t nTower  = -1;
366   Int_t nIphi   = -1;
367   Int_t nIeta   = -1;
368   Int_t iphi    = -1;
369   Int_t ieta    = -1;
370   
371   //Digits loop to fill TRU matrices with amplitudes.
372
373   for(Int_t idig = 0 ; idig < digits->GetEntriesFast() ; idig++){
374     
375     dig = dynamic_cast<AliEMCALDigit *>(digits->At(idig)) ;
376     amp = dig->GetAmp() ; //Energy of the digit (arbitrary units)
377     id  = dig->GetId() ;  //Id label of the cell
378     //cout<<"idig "<<idig<<" Amp "<<amp<<" Id "<<id<<endl;
379    
380     //Get eta and phi cell position in supermodule
381     Bool_t bCell = GetCellIndex(id, iSupMod, nTower, nIphi, nIeta) ;
382     if(!bCell)
383       Error("FillTRU","Wrong cell id number") ;
384     
385     GetCellPhiEtaIndexInSModule(iSupMod,nTower,nIphi, nIeta,iphi,ieta);
386
387     //Check to which TRU in the supermodule belongs the cell. 
388     //Supermodules are divided in a TRU matrix of dimension 
389     //(fNTRUPhi,fNTRUEta).
390     //Each TRU is a cell matrix of dimension (nCellsPhi,nCellsEta)
391
392     //First calculate the row and column in the supermodule 
393     //of the TRU to which the cell belongs.
394
395     Int_t col   = (ieta-1)/nCellsEta+1; 
396     Int_t row   = (iphi-1)/nCellsPhi+1; 
397     Int_t itru  = col*row + (iSupMod-1)*fNTRU - 1; //Label number of the TRU
398 //     Info("FillTRU","SM %d, cell: phi %d, eta %d",iSupMod,iphi,ieta);
399 //     Info("FillTRU","SM TRU: SMrow %d, SMcol %d, SMtru %d,",row,col,itru); 
400     
401  
402     //Fill TRU matrix with cell values
403     
404     TMatrixD * trus = dynamic_cast<TMatrixD *>(matrix->At(itru)) ;
405     
406     //Calculate row and column of the cell inside the TRU with number itru
407
408     Int_t irow = (iphi-1) - (row-1) *  nCellsPhi;       
409     Int_t icol = (ieta-1) - (col-1) *  nCellsEta;
410     
411     (*trus)(irow,icol) = amp ;
412
413
414     //     Info("FillTRU","TRU: row %d, col %d",irow,icol);
415
416   }
417   return matrix;
418 }
419
420
421 //______________________________________________________________________
422 AliEMCALGeometry *  AliEMCALGeometry::GetInstance(){ 
423   // Returns the pointer of the unique instance
424   
425   return static_cast<AliEMCALGeometry *>( fgGeom ) ; 
426 }
427
428 //______________________________________________________________________
429 AliEMCALGeometry* AliEMCALGeometry::GetInstance(const Text_t* name,
430                                                 const Text_t* title){
431     // Returns the pointer of the unique instance
432
433     AliEMCALGeometry * rv = 0; 
434     if ( fgGeom == 0 ) {
435         if ( strcmp(name,"") == 0 ) rv = 0;
436         else {    
437             fgGeom = new AliEMCALGeometry(name, title);
438             if ( fgInit ) rv = (AliEMCALGeometry * ) fgGeom;
439             else {
440                 rv = 0; 
441                 delete fgGeom; 
442                 fgGeom = 0; 
443             } // end if fgInit
444         } // end if strcmp(name,"")
445     }else{
446         if ( strcmp(fgGeom->GetName(), name) != 0 ) {
447           printf("\ncurrent geometry is ") ;  
448           printf(fgGeom->GetName());
449           printf("\n                      you cannot call     "); 
450           printf(name);  
451         }else{
452           rv = (AliEMCALGeometry *) fgGeom; 
453         } // end if
454     }  // end if fgGeom
455     return rv; 
456 }
457
458 // These methods are obsolete but use in AliEMCALRecPoint - keep it now
459 //______________________________________________________________________
460 Int_t AliEMCALGeometry::TowerIndex(Int_t ieta,Int_t iphi) const {
461   // Returns the tower index number from the based on the Z and Phi
462   // index numbers.
463   // Inputs:
464   //   Int_t ieta    // index along z axis [1-fNZ]
465   //   Int_t iphi  // index along phi axis [1-fNPhi]
466   // Outputs:
467   //   none.
468   // Returned
469   //   Int_t index // Tower index number 
470   
471   if ( (ieta <= 0 || ieta>GetNEta()) || 
472        (iphi <= 0 || iphi>GetNPhi())) {
473     Error("TowerIndex", "Unexpected parameters eta = %d phi = %d!", ieta, iphi) ; 
474     return -1;
475   }
476   return ( (iphi - 1)*GetNEta() + ieta ); 
477 }
478
479 //______________________________________________________________________
480 void AliEMCALGeometry::TowerIndexes(Int_t index,Int_t &ieta,Int_t &iphi) const {
481   // Inputs:
482   //   Int_t index // Tower index number [1-fNZ*fNPhi]
483   // Outputs:
484   //   Int_t ieta    // index allong z axis [1-fNZ]
485   //   Int_t iphi  // index allong phi axis [1-fNPhi]
486   // Returned
487   //   none.
488
489   Int_t nindex = 0;
490
491   if ( IsInECA(index) ) { // ECAL index
492     nindex = index ;
493   }
494   else {
495     Error("TowerIndexes", "Unexpected Id number!") ;
496     ieta = -1;
497     iphi = -1;
498     return;
499   }   
500
501   if (nindex%GetNZ()) 
502     iphi = nindex / GetNZ() + 1 ; 
503   else 
504     iphi = nindex / GetNZ() ; 
505   ieta = nindex - (iphi - 1) * GetNZ() ; 
506
507   if (gDebug==2)
508     printf("TowerIndexes: index=%d,%d, ieta=%d, iphi = %d", index, nindex,ieta, iphi) ; 
509   return;
510   
511 }
512
513 //______________________________________________________________________
514 void AliEMCALGeometry::EtaPhiFromIndex(Int_t index,Float_t &eta,Float_t &phi) const {
515     // given the tower index number it returns the based on the eta and phi
516     // of the tower.
517     // Inputs:
518     //   Int_t index // Tower index number [1-fNZ*fNPhi]
519     // Outputs:
520     //   Float_t eta  // eta of center of tower in pseudorapidity
521     //   Float_t phi  // phi of center of tower in degrees
522     // Returned
523     //   none.
524     Int_t ieta, iphi;
525     Float_t deta, dphi ;
526
527     TowerIndexes(index,ieta,iphi);
528     
529     if (gDebug == 2) 
530       printf("EtaPhiFromIndex: index = %d, ieta = %d, iphi = %d", index, ieta, iphi) ;
531
532     deta = (GetArm1EtaMax()-GetArm1EtaMin())/(static_cast<Float_t>(GetNEta()));
533     eta  = GetArm1EtaMin() + ((static_cast<Float_t>(ieta) - 0.5 ))*deta;
534
535     dphi = (GetArm1PhiMax() - GetArm1PhiMin())/(static_cast<Float_t>(GetNPhi()));  // in degrees.
536     phi  = GetArm1PhiMin() + dphi*(static_cast<Float_t>(iphi) - 0.5);//iphi range [1-fNphi].
537 }
538
539 //______________________________________________________________________
540 Int_t AliEMCALGeometry::TowerIndexFromEtaPhi(Float_t eta,Float_t phi) const {
541     // returns the tower index number based on the eta and phi of the tower.
542     // Inputs:
543     //   Float_t eta  // eta of center of tower in pseudorapidity
544     //   Float_t phi  // phi of center of tower in degrees
545     // Outputs:
546     //   none.
547     // Returned
548     //   Int_t index // Tower index number [1-fNZ*fNPhi]
549
550     Int_t ieta,iphi;
551
552     ieta = static_cast<Int_t> ( 1 + (static_cast<Float_t>(GetNEta()) * (eta - GetArm1EtaMin()) / (GetArm1EtaMax() - GetArm1EtaMin())) ) ;
553
554     if( ieta <= 0 || ieta > GetNEta() ) { 
555       Error("TowerIndexFromEtaPhi", "Unexpected (eta, phi) = (%f, %f) value, outside of EMCAL!", eta, phi) ; 
556       return -1 ; 
557     }
558
559     iphi = static_cast<Int_t> ( 1 + (static_cast<Float_t>(GetNPhi()) * (phi - GetArm1PhiMin()) / (GetArm1PhiMax() - GetArm1PhiMin())) ) ;
560
561     if( iphi <= 0 || iphi > GetNPhi() ) { 
562       Error("TowerIndexFromEtaPhi", "Unexpected (eta, phi) = (%f, %f) value, outside of EMCAL!", eta, phi) ; 
563       return -1 ; 
564     }
565
566     return TowerIndex(ieta,iphi);
567 }
568
569 //______________________________________________________________________
570 Bool_t AliEMCALGeometry::AbsToRelNumbering(Int_t AbsId, Int_t *relid) const {
571     // Converts the absolute numbering into the following array/
572     //  relid[0] = Row number inside EMCAL
573     //  relid[1] = Column number inside EMCAL
574     // Input:
575     //   Int_t AbsId // Tower index number [1-2*fNZ*fNPhi]
576     // Outputs:
577     //   Int_t *relid // array of 2. Described above.
578     Bool_t rv  = kTRUE ;
579     Int_t ieta=0,iphi=0,index=AbsId;
580
581     TowerIndexes(index,ieta,iphi);
582     relid[0] = ieta;
583     relid[1] = iphi;
584
585     return rv;
586 }
587
588 //______________________________________________________________________
589 void AliEMCALGeometry::PosInAlice(const Int_t *relid, Float_t &theta, Float_t &phi) const 
590 {
591   // Converts the relative numbering into the local EMCAL-module (x, z)
592   // coordinates
593   Int_t ieta = relid[0]; // offset along x axis
594   Int_t iphi = relid[1]; // offset along z axis
595   Int_t index;
596   Float_t eta;
597   
598   index = TowerIndex(ieta,iphi);
599   EtaPhiFromIndex(index,eta,phi);
600   //theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
601   theta = 2.0*TMath::ATan(TMath::Exp(-eta));
602
603   // correct for distance to IP
604   Float_t d = GetIP2ECASection() - GetIPDistance() ;  
605
606   Float_t correction = 1 + d/GetIPDistance() ; 
607   Float_t tantheta = TMath::Tan(theta) * correction ; 
608   theta = TMath::ATan(tantheta) * TMath::RadToDeg() ; 
609   if (theta < 0 ) 
610     theta += 180. ; 
611   
612   return;
613 }
614
615 //______________________________________________________________________
616 void AliEMCALGeometry::PosInAlice(Int_t absid, Float_t &theta, Float_t &phi) const 
617 {
618   // Converts the relative numbering into the local EMCAL-module (x, z)
619   // coordinates
620   Int_t relid[2] ; 
621   AbsToRelNumbering(absid, relid) ;
622   Int_t ieta = relid[0]; // offset along x axis
623   Int_t iphi = relid[1]; // offset along z axis
624   Int_t index;
625   Float_t eta;
626   
627   index = TowerIndex(ieta,iphi);
628   EtaPhiFromIndex(index,eta,phi);
629   theta = 2.0*TMath::ATan(TMath::Exp(-eta)) ;
630   
631   // correct for distance to IP
632   Float_t d = 0. ; 
633   if (IsInECA(absid))
634     d = GetIP2ECASection() - GetIPDistance() ; 
635   else {
636     Error("PosInAlice", "Unexpected id # %d!", absid) ; 
637     return;
638   }
639
640   Float_t correction = 1 + d/GetIPDistance() ; 
641   Float_t tantheta = TMath::Tan(theta) * correction ; 
642   theta = TMath::ATan(tantheta) * TMath::RadToDeg() ; 
643   if (theta < 0 ) 
644     theta += 180. ; 
645   
646   return;
647 }
648
649 //______________________________________________________________________
650 void AliEMCALGeometry::XYZFromIndex(const Int_t *relid,Float_t &x,Float_t &y, Float_t &z) const {
651     // given the tower relative number it returns the X, Y and Z
652     // of the tower.
653     
654     // Outputs:
655     //   Float_t x  // x of center of tower in cm
656     //   Float_t y  // y of center of tower in cm
657     //   Float_t z  // z of centre of tower in cm
658     // Returned
659     //   none.
660     
661     Float_t eta,theta, phi,cylradius=0. ;
662     
663     Int_t ieta = relid[0]; // offset along x axis
664     Int_t iphi = relid[1]; // offset along z axis.
665     Int_t index;
666     
667     index = TowerIndex(ieta,iphi);
668     EtaPhiFromIndex(index,eta,phi);
669     theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
670     
671     cylradius = GetIP2ECASection() ;  
672
673     Double_t  kDeg2Rad = TMath::DegToRad() ; 
674     x =  cylradius * TMath::Cos(phi * kDeg2Rad ) ;
675     y =  cylradius * TMath::Sin(phi * kDeg2Rad ) ; 
676     z =  cylradius / TMath::Tan(theta * kDeg2Rad ) ; 
677  
678  return;
679
680
681 //______________________________________________________________________
682 void AliEMCALGeometry::XYZFromIndex(Int_t absid,  TVector3 &v) const {
683     // given the tower relative number it returns the X, Y and Z
684     // of the tower.
685     
686     // Outputs:
687     //   Float_t x  // x of center of tower in cm
688     //   Float_t y  // y of center of tower in cm
689     //   Float_t z  // z of centre of tower in cm
690     // Returned
691     //   none.
692     
693     Float_t theta, phi,cylradius=0. ;
694         
695     PosInAlice(absid, theta, phi) ; 
696     
697     if ( IsInECA(absid) ) 
698       cylradius = GetIP2ECASection() ;
699     else {
700       Error("XYZFromIndex", "Unexpected Tower section") ;
701       return;
702     }
703
704     Double_t  kDeg2Rad = TMath::DegToRad() ; 
705     v.SetX(cylradius * TMath::Cos(phi * kDeg2Rad ) );
706     v.SetY(cylradius * TMath::Sin(phi * kDeg2Rad ) ); 
707     v.SetZ(cylradius / TMath::Tan(theta * kDeg2Rad ) ) ; 
708  
709  return;
710
711
712 Bool_t AliEMCALGeometry::IsInEMCAL(Double_t x, Double_t y, Double_t z) const {
713   // Checks whether point is inside the EMCal volume
714   //
715   // Code uses cylindrical approximation made of inner radius (for speed)
716   //
717   // Points behind EMCAl, i.e. R > outer radius, but eta, phi in acceptance 
718   // are considered to inside
719
720   Double_t r=sqrt(x*x+y*y);
721
722   if ( r > fEnvelop[0] ) {
723      Double_t theta;
724      theta  =    TMath::ATan2(r,z);
725      Double_t eta;
726      if(theta == 0) 
727        eta = 9999;
728      else 
729        eta    =   -TMath::Log(TMath::Tan(theta/2.));
730      if (eta < fArm1EtaMin || eta > fArm1EtaMax)
731        return 0;
732  
733      Double_t phi = TMath::ATan2(y,x) * 180./TMath::Pi();
734      if (phi > fArm1PhiMin && phi < fArm1PhiMax)
735        return 1;
736   }
737   return 0;
738 }
739 // ==
740
741 //
742 // == Shish-kebab cases ==
743 //
744 Int_t AliEMCALGeometry::GetAbsCellId(Int_t nSupMod, Int_t nTower, Int_t nIphi, Int_t nIeta)
745 { // 27-aug-04; 
746   // corr. 21-sep-04; 
747   //       13-oct-05; 110 degree case
748   // 1 <= nSupMod <= fNumberOfSuperModules
749   // 1 <= nTower  <= fNPHI * fNZ ( fNPHI * fNZ/2 for fKey110DEG=1)
750   // 1 <= nIphi   <= fNPHIdiv
751   // 1 <= nIeta   <= fNETAdiv
752   // 1 <= absid   <= fNCells
753   static Int_t id=0; // have to change from 1 to fNCells
754   if(fKey110DEG == 1 && nSupMod > 10) { // 110 degree case; last two supermodules
755     id  = fNCellsInSupMod*10 + (fNCellsInSupMod/2)*(nSupMod-11);
756   } else {
757     id  = fNCellsInSupMod*(nSupMod-1);
758   }
759   id += fNCellsInTower *(nTower-1);
760   id += fNPHIdiv *(nIphi-1);
761   id += nIeta;
762   if(id<=0 || id > fNCells) {
763 //     printf(" wrong numerations !!\n");
764 //     printf("    id      %6i(will be force to -1)\n", id);
765 //     printf("    fNCells %6i\n", fNCells);
766 //     printf("    nSupMod %6i\n", nSupMod);
767 //     printf("    nTower  %6i\n", nTower);
768 //     printf("    nIphi   %6i\n", nIphi);
769 //     printf("    nIeta   %6i\n", nIeta);
770     id = -TMath::Abs(id);
771   }
772   return id;
773 }
774
775 Bool_t  AliEMCALGeometry::CheckAbsCellId(Int_t ind)
776 { // 17-niv-04 - analog of IsInECA
777    if(name.Contains("TRD")) {
778      if(ind<=0 || ind > fNCells) return kFALSE;
779      else                        return kTRUE;
780    } else return IsInECA(ind);
781 }
782
783 Bool_t AliEMCALGeometry::GetCellIndex(Int_t absId,Int_t &nSupMod,Int_t &nTower,Int_t &nIphi,Int_t &nIeta)
784 { // 21-sep-04
785   // 19-oct-05;
786   static Int_t tmp=0, sm10=0;
787   if(absId<=0 || absId>fNCells) {
788 //     Info("GetCellIndex"," wrong abs Id %i !! \n", absId); 
789     return kFALSE;
790   }
791   sm10 = fNCellsInSupMod*10;
792   if(fKey110DEG == 1 && absId > sm10) { // 110 degree case; last two supermodules  
793     nSupMod = (absId-1-sm10) / (fNCellsInSupMod/2) + 11;
794     tmp     = (absId-1-sm10) % (fNCellsInSupMod/2);
795   } else {
796     nSupMod = (absId-1) / fNCellsInSupMod + 1;
797     tmp     = (absId-1) % fNCellsInSupMod;
798   }
799
800   nTower  = tmp / fNCellsInTower + 1;
801   tmp     = tmp % fNCellsInTower;
802   nIphi   = tmp / fNPHIdiv + 1;
803   nIeta   = tmp % fNPHIdiv + 1;
804
805   return kTRUE;
806 }
807
808 void AliEMCALGeometry::GetTowerPhiEtaIndexInSModule(Int_t nSupMod, Int_t nTower,  int &iphit, int &ietat)
809 { // added nSupMod; have to check  - 19-oct-05 ! 
810   static Int_t nphi;
811
812   if(fKey110DEG == 1 && nSupMod>=11) nphi = fNPhi/2;
813   else                               nphi = fNPhi;
814
815   ietat = (nTower-1)/nphi + 1; // have to change from 1 to fNZ
816   iphit = (nTower-1)%nphi + 1; // have to change from 1 to fNPhi
817 }
818
819 void AliEMCALGeometry::GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nTower, Int_t nIphi, Int_t nIeta, 
820 int &iphi, int &ieta)
821 { // added nSupMod; Nov 25, 05
822   static Int_t iphit, ietat;
823
824   GetTowerPhiEtaIndexInSModule(nSupMod,nTower, iphit, ietat); 
825   // have to change from 1 to fNZ*fNETAdiv
826   ieta  = (ietat-1)*fNETAdiv + (3-nIeta); // x(module) = -z(SM) 
827   // iphi - have to change from 1 to fNPhi*fNPHIdiv
828   iphi  = (iphit-1)*fNPHIdiv + nIphi;     // y(module) =  y(SM) 
829 }
830 // Service routine 
831 int  AliEMCALGeometry::ParseString(const TString &topt, TObjArray &Opt)
832 { // Feb 06, 2006
833   Ssiz_t begin, index, end, end2;
834   begin = index = end = end2 = 0;
835   TRegexp separator("[^ ;,\\t\\s/]+");
836   while ( (begin < topt.Length()) && (index != kNPOS) ) {
837     // loop over given options
838     index = topt.Index(separator,&end,begin);
839     if (index >= 0 && end >= 1) {
840       TString substring(topt(index,end));
841       Opt.Add(new TObjString(substring.Data()));
842     }
843     begin += end+1;
844   }
845   return Opt.GetEntries();
846 }