]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGeometry.cxx
comment some print output
[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 "Riostream.h"
35
36 #include <TMath.h>
37 #include <TVector3.h>
38               //#include <TArrayD.h>
39 #include <TObjArray.h>
40 #include <TGeoManager.h>
41 #include <TGeoNode.h>
42 #include <TGeoMatrix.h>
43 #include <TMatrixD.h>
44 #include <TObjString.h>
45 #include <TClonesArray.h>
46
47 // -- ALICE Headers.
48 //#include "AliConst.h"
49 #include "AliLog.h"
50
51 // --- EMCAL headers
52 #include "AliEMCALGeometry.h"
53 #include "AliEMCALShishKebabTrd1Module.h"
54 #include "AliEMCALRecPoint.h"
55 #include "AliEMCALDigit.h"
56 #include "AliEMCALHistoUtilities.h"
57 #include "AliEMCALAlignData.h"
58
59 ClassImp(AliEMCALGeometry)
60
61 // these initialisations are needed for a singleton
62 AliEMCALGeometry  *AliEMCALGeometry::fgGeom      = 0;
63 Bool_t             AliEMCALGeometry::fgInit      = kFALSE;
64 AliEMCALAlignData *AliEMCALGeometry::fgAlignData = 0;
65
66
67
68 AliEMCALGeometry::AliEMCALGeometry() : AliGeometry() 
69
70   // default ctor only for internal usage (singleton)
71   // must be kept public for root persistency purposes, but should never be called by the outside world    
72   //  CreateListOfTrd1Modules();
73   AliDebug(2, "AliEMCALGeometry : default ctor ");
74 }
75 //______________________________________________________________________
76 AliEMCALGeometry::AliEMCALGeometry(const Text_t* name, const Text_t* title) :
77 AliGeometry(name, title) {// ctor only for internal usage (singleton)
78   AliDebug(2, Form("AliEMCALGeometry(%s,%s) ", name,title));
79   Init();
80   CreateListOfTrd1Modules();
81 }
82 //______________________________________________________________________
83 AliEMCALGeometry::~AliEMCALGeometry(void){
84     // dtor
85 }
86 //______________________________________________________________________
87 void AliEMCALGeometry::Init(void){
88   // Initializes the EMCAL parameters
89   // naming convention : GUV_WX_N_ gives the composition of a tower
90   // WX inform about the composition of the EM calorimeter section: 
91   //   thickness in mm of Pb radiator (W) and of scintillator (X), and number of scintillator layers (N)
92   // New geometry: EMCAL_55_25
93   // 24-aug-04 for shish-kebab
94   // SHISH_25 or SHISH_62
95   // 11-oct-05   - correction for pre final design
96   // Feb 06,2006 - decrease the weight of EMCAL
97
98   fAdditionalOpts[0] = "nl=";    // number of sampling layers (fNECLayers)
99   fAdditionalOpts[1] = "pbTh=";  // cm, Thickness of the Pb   (fECPbRadThick)
100   fAdditionalOpts[2] = "scTh=";  // cm, Thickness of the Sc    (fECScintThick)
101   fAdditionalOpts[3] = "latSS=";  // cm, Thickness of lateral steel strip (fLateralSteelStrip)
102
103   fNAdditionalOpts = sizeof(fAdditionalOpts) / sizeof(char*);
104
105   fgInit = kFALSE; // Assume failed until proven otherwise.
106   fGeoName   = GetName();
107   fGeoName.ToUpper();
108   fKey110DEG = 0;
109   if(fGeoName.Contains("110DEG")) fKey110DEG = 1; // for GetAbsCellId
110   fShishKebabTrd1Modules = 0;
111   fTrd2AngleY = f2Trd2Dy2 = fEmptySpace = fTubsR = fTubsTurnAngle = 0;
112
113   fNZ             = 114;        // granularity along Z (eta) 
114   fNPhi           = 168;        // granularity in phi (azimuth)
115   fArm1PhiMin     = 60.0;       // degrees, Starting EMCAL Phi position
116   fArm1PhiMax     = 180.0;      // degrees, Ending EMCAL Phi position
117   fArm1EtaMin     = -0.7;       // pseudorapidity, Starting EMCAL Eta position
118   fArm1EtaMax     = +0.7;       // pseudorapidity, Ending EMCAL Eta position
119   fIPDistance     = 454.0;      // cm, Radial distance to inner surface of EMCAL
120   fPhiGapForSM    = 0.;         // cm, only for final TRD1 geometry
121   for(int i=0; i<12; i++) fMatrixOfSM[i] = 0;
122
123   // geometry
124   if(fGeoName.Contains("SHISH")){ // Only shahslyk now
125     // 7-sep-05; integration issue
126     fArm1PhiMin     = 80.0;     // 60  -> 80
127     fArm1PhiMax     = 180.0;    // 180 -> 190
128
129     fNumberOfSuperModules = 10; // 12 = 6 * 2 (6 in phi, 2 in Z);
130     fSteelFrontThick = 2.54;    //  9-sep-04
131     fIPDistance      = 460.0;
132     fFrontSteelStrip = fPassiveScintThick = 0.0; // 13-may-05
133     fLateralSteelStrip = 0.025; // before MAY 2005 
134     fPhiModuleSize   = fEtaModuleSize   = 11.4;
135     fPhiTileSize = fEtaTileSize      = 5.52; // (11.4-5.52*2)/2. = 0.18 cm (wall thickness)
136     fNPhi            = 14;
137     fNZ              = 30;
138     fAlFrontThick    = fGap2Active = 0;
139     fNPHIdiv = fNETAdiv = 2;
140
141     fNECLayers       = 62;
142     fECScintThick    = fECPbRadThickness = 0.2;
143     fSampling        = 1.;  // 30-aug-04 - should be calculated
144     if(fGeoName.Contains("TWIST")) { // all about EMCAL module
145       fNZ             = 27;  // 16-sep-04
146     } else if(fGeoName.Contains("TRD")) {
147       fIPDistance      = 428.0;  //  11-may-05
148       fSteelFrontThick = 0.0;    // 3.17 -> 0.0; 28-mar-05 : no stell plate
149       fNPhi            = 12;
150       fSampling       = 12.327;
151       fPhiModuleSize = fEtaModuleSize = 12.26;
152       fNZ            = 26;     // 11-oct-04
153       fTrd1Angle     = 1.3;    // in degree
154 // 18-nov-04; 1./0.08112=12.327
155 // http://pdsfweb01.nersc.gov/~pavlinov/ALICE/SHISHKEBAB/RES/linearityAndResolutionForTRD1.html
156       if(fGeoName.Contains("TRD1")) {       // 30-jan-05
157         // for final design
158         fPhiGapForSM    = 2.;         // cm, only for final TRD1 geometry
159         if(fGeoName.Contains("MAY05") || fGeoName.Contains("WSUC") || fGeoName.Contains("FINAL")){
160           fNumberOfSuperModules = 12; // 20-may-05
161           if(fGeoName.Contains("WSUC")) fNumberOfSuperModules = 1; // 27-may-05
162           fNECLayers     = 77;       // (13-may-05 from V.Petrov)
163           fPhiModuleSize = 12.5;     // 20-may-05 - rectangular shape
164           fEtaModuleSize = 11.9;
165           fECScintThick  = fECPbRadThickness = 0.16;// (13-may-05 from V.Petrov)
166           fFrontSteelStrip   = 0.025;// 0.025cm = 0.25mm  (13-may-05 from V.Petrov)
167           fLateralSteelStrip = 0.01; // 0.01cm  = 0.1mm   (13-may-05 from V.Petrov) - was 0.025
168           fPassiveScintThick = 0.8;  // 0.8cm   = 8mm     (13-may-05 from V.Petrov)
169           fNZ                = 24;
170           fTrd1Angle         = 1.5;  // 1.3 or 1.5
171
172           if(fGeoName.Contains("FINAL")) { // 9-sep-05
173             fNumberOfSuperModules = 10;
174             if(fGeoName.Contains("110DEG")) {
175               fNumberOfSuperModules = 12;// last two modules have size 10 degree in phi (180<phi<190)
176               fArm1PhiMax = 200.0; // for XEN1 and turn angle of super modules
177             }
178             fPhiModuleSize = 12.26 - fPhiGapForSM / Float_t(fNPhi); // first assumption
179             fEtaModuleSize = fPhiModuleSize;
180             if(fGeoName.Contains("HUGE")) fNECLayers *= 3; // 28-oct-05 for analysing leakage    
181           }
182         }
183       } else if(fGeoName.Contains("TRD2")) {       // 30-jan-05
184         fSteelFrontThick = 0.0;         // 11-mar-05
185         fIPDistance+= fSteelFrontThick; // 1-feb-05 - compensate absence of steel plate
186         fTrd1Angle  = 1.64;             // 1.3->1.64
187         fTrd2AngleY = fTrd1Angle;       //  symmetric case now
188         fEmptySpace    = 0.2; // 2 mm
189         fTubsR         = fIPDistance; // 31-jan-05 - as for Fred case
190
191         fPhiModuleSize  = fTubsR*2.*TMath::Tan(fTrd2AngleY*TMath::DegToRad()/2.);
192         fPhiModuleSize -= fEmptySpace/2.; // 11-mar-05  
193         fEtaModuleSize  = fPhiModuleSize; // 20-may-05 
194         fTubsTurnAngle  = 3.;
195       }
196       fNPHIdiv = fNETAdiv  = 2;   // 13-oct-04 - division again
197       if(fGeoName.Contains("3X3")) {   // 23-nov-04
198         fNPHIdiv = fNETAdiv  = 3;
199       } else if(fGeoName.Contains("4X4")) {
200         fNPHIdiv = fNETAdiv  = 4;
201       }
202     }
203     if(fGeoName.Contains("25")){
204       fNECLayers     = 25;
205       fECScintThick  = fECPbRadThickness = 0.5;
206     }
207     if(fGeoName.Contains("WSUC")){ // 18-may-05 - about common structure
208       fShellThickness = 30.; // should be change 
209       fNPhi = fNZ = 4; 
210     }
211
212     CheckAdditionalOptions();
213     DefineSamplingFraction();
214
215     fPhiTileSize = fPhiModuleSize/2. - fLateralSteelStrip; // 13-may-05 
216     fEtaTileSize = fEtaModuleSize/2. - fLateralSteelStrip; // 13-may-05 
217
218     // constant for transition absid <--> indexes
219     fNCellsInTower  = fNPHIdiv*fNETAdiv;
220     fNCellsInSupMod = fNCellsInTower*fNPhi*fNZ;
221     fNCells         = fNCellsInSupMod*fNumberOfSuperModules;
222     if(fGeoName.Contains("110DEG")) fNCells -= fNCellsInSupMod;
223
224     fLongModuleSize = fNECLayers*(fECScintThick + fECPbRadThickness);
225     if(fGeoName.Contains("MAY05")) fLongModuleSize += (fFrontSteelStrip + fPassiveScintThick);
226
227     // 30-sep-04
228     if(fGeoName.Contains("TRD")) {
229       f2Trd1Dx2 = fEtaModuleSize + 2.*fLongModuleSize*TMath::Tan(fTrd1Angle*TMath::DegToRad()/2.);
230       if(fGeoName.Contains("TRD2")) {  // 27-jan-05
231         f2Trd2Dy2 = fPhiModuleSize + 2.*fLongModuleSize*TMath::Tan(fTrd2AngleY*TMath::DegToRad()/2.);
232       }
233     }
234   } else Fatal("Init", "%s is an undefined geometry!", fGeoName.Data()) ; 
235
236   fNPhiSuperModule = fNumberOfSuperModules/2;
237   if(fNPhiSuperModule<1) fNPhiSuperModule = 1;
238   //There is always one more scintillator than radiator layer because of the first block of aluminium
239   fShellThickness = fAlFrontThick + fGap2Active + fNECLayers*GetECScintThick()+(fNECLayers-1)*GetECPbRadThick();
240   if(fGeoName.Contains("SHISH")) {
241     fShellThickness = fSteelFrontThick + fLongModuleSize;
242     if(fGeoName.Contains("TWIST")) { // 13-sep-04
243       fShellThickness  = TMath::Sqrt(fLongModuleSize*fLongModuleSize + fPhiModuleSize*fEtaModuleSize);
244       fShellThickness += fSteelFrontThick;
245     } else if(fGeoName.Contains("TRD")) { // 1-oct-04
246       fShellThickness  = TMath::Sqrt(fLongModuleSize*fLongModuleSize + f2Trd1Dx2*f2Trd1Dx2);
247       fShellThickness += fSteelFrontThick;
248       // Local coordinates
249       fParSM[0] = GetShellThickness()/2.;        
250       fParSM[1] = GetPhiModuleSize() * GetNPhi()/2.;
251       fParSM[2] = 350./2.;
252     }
253   }
254
255   fZLength        = 2.*ZFromEtaR(fIPDistance+fShellThickness,fArm1EtaMax); // Z coverage
256   fEnvelop[0]     = fIPDistance; // mother volume inner radius
257   fEnvelop[1]     = fIPDistance + fShellThickness; // mother volume outer r.
258   fEnvelop[2]     = 1.00001*fZLength; // add some padding for mother volume. 
259   
260   if(fgAlignData != NULL) {
261     // Number of modules is read from Alignment DB if exists
262     fNumberOfSuperModules = fgAlignData->GetNSuperModules();
263   }
264  
265   fgInit = kTRUE; 
266   
267   if (AliDebugLevel()>=2) {
268     printf("Init: geometry of EMCAL named %s is as follows:\n", fGeoName.Data());
269     printf( "               ECAL      : %d x (%f cm Pb, %f cm Sc) \n", 
270     GetNECLayers(), GetECPbRadThick(), GetECScintThick() ) ; 
271     printf("                fSampling %5.2f \n",  fSampling );
272     if(fGeoName.Contains("SHISH")){
273       printf(" fIPDistance       %6.3f cm \n", fIPDistance);
274       if(fSteelFrontThick>0.) 
275       printf(" fSteelFrontThick  %6.3f cm \n", fSteelFrontThick);
276       printf(" fNPhi %i   |  fNZ %i \n", fNPhi, fNZ);
277       printf(" fNCellsInTower %i : fNCellsInSupMod %i : fNCells %i\n",fNCellsInTower, fNCellsInSupMod, fNCells);
278       if(fGeoName.Contains("MAY05")){
279         printf(" fFrontSteelStrip         %6.4f cm (thickness of front steel strip)\n", 
280         fFrontSteelStrip);
281         printf(" fLateralSteelStrip       %6.4f cm (thickness of lateral steel strip)\n", 
282         fLateralSteelStrip);
283         printf(" fPassiveScintThick  %6.4f cm (thickness of front passive Sc tile)\n",
284         fPassiveScintThick);
285       }
286       printf(" X:Y module size     %6.3f , %6.3f cm \n", fPhiModuleSize, fEtaModuleSize);
287       printf(" X:Y   tile size     %6.3f , %6.3f cm \n", fPhiTileSize, fEtaTileSize);
288       printf(" #of sampling layers %i(fNECLayers) \n", fNECLayers);
289       printf(" fLongModuleSize     %6.3f cm \n", fLongModuleSize);
290       printf(" #supermodule in phi direction %i \n", fNPhiSuperModule );
291     }
292     if(fGeoName.Contains("TRD")) {
293       printf(" fTrd1Angle %7.4f\n", fTrd1Angle);
294       printf(" f2Trd1Dx2  %7.4f\n",  f2Trd1Dx2);
295       if(fGeoName.Contains("TRD2")) {
296         printf(" fTrd2AngleY     %7.4f\n", fTrd2AngleY);
297         printf(" f2Trd2Dy2       %7.4f\n", f2Trd2Dy2);
298         printf(" fTubsR          %7.2f cm\n", fTubsR);
299         printf(" fTubsTurnAngle  %7.4f\n", fTubsTurnAngle);
300         printf(" fEmptySpace     %7.4f cm\n", fEmptySpace);
301       } else if(fGeoName.Contains("TRD1") && fGeoName.Contains("FINAL")){
302         printf("SM dimensions(TRD1) : dx %7.2f dy %7.2f dz %7.2f (SMOD, BOX)\n", 
303         fParSM[0],fParSM[1],fParSM[2]);
304         printf(" fPhiGapForSM  %7.4f cm \n",  fPhiGapForSM);
305         if(fGeoName.Contains("110DEG"))printf(" Last two modules have size 10 degree in  phi (180<phi<190)\n");
306       }
307     }
308     printf("Granularity: %d in eta and %d in phi\n", GetNZ(), GetNPhi()) ;
309     printf("Layout: phi = (%7.1f, %7.1f), eta = (%5.2f, %5.2f), IP = %7.2f\n",  
310            GetArm1PhiMin(), GetArm1PhiMax(),GetArm1EtaMin(), GetArm1EtaMax(), GetIPDistance() );
311   }
312   //TRU parameters. These parameters values are not the final ones.
313   fNTRU    = 3 ;
314   fNTRUEta = 3 ;
315   fNTRUPhi = 1 ;
316 }
317
318 //______________________________________________________________________
319
320 void AliEMCALGeometry::CheckAdditionalOptions()
321 {
322   // Feb 06,2006
323   //Additional options that
324   //can be used to select
325   //the specific geometry of 
326   //EMCAL to run
327
328   fArrayOpts = new TObjArray;
329   Int_t nopt = AliEMCALHistoUtilities::ParseString(fGeoName, *fArrayOpts);
330   if(nopt==1) { // no aditional option(s)
331     fArrayOpts->Delete();
332     delete fArrayOpts;
333     fArrayOpts = 0; 
334     return;
335   }              
336   for(Int_t i=1; i<nopt; i++){
337     TObjString *o = (TObjString*)fArrayOpts->At(i); 
338
339     TString addOpt = o->String();
340     Int_t indj=-1;
341     for(Int_t j=0; j<fNAdditionalOpts; j++) {
342       TString opt = fAdditionalOpts[j];
343       if(addOpt.Contains(opt,TString::kIgnoreCase)) {
344           indj = j;
345         break;
346       }
347     }
348     if(indj<0) {
349       AliDebug(2,Form("<E> option |%s| unavailable : ** look to the file AliEMCALGeometry.h **\n", 
350                       addOpt.Data()));
351       assert(0);
352     } else {
353       AliDebug(2,Form("<I> option |%s| is valid : number %i : |%s|\n", 
354                       addOpt.Data(), indj, fAdditionalOpts[indj]));
355       if       (addOpt.Contains("NL=",TString::kIgnoreCase))   {// number of sampling layers
356         sscanf(addOpt.Data(),"NL=%i", &fNECLayers);
357         AliDebug(2,Form(" fNECLayers %i (new) \n", fNECLayers));
358       } else if(addOpt.Contains("PBTH=",TString::kIgnoreCase)) {//Thickness of the Pb(fECPbRadThicknes)
359         sscanf(addOpt.Data(),"PBTH=%f", &fECPbRadThickness);
360       } else if(addOpt.Contains("SCTH=",TString::kIgnoreCase)) {//Thickness of the Sc(fECScintThick)
361         sscanf(addOpt.Data(),"SCTH=%f", &fECScintThick);
362       } else if(addOpt.Contains("LATSS=",TString::kIgnoreCase)) {// Thickness of lateral steel strip (fLateralSteelStrip)
363         sscanf(addOpt.Data(),"LATSS=%f", &fLateralSteelStrip);
364         AliDebug(2,Form(" fLateralSteelStrip %f (new) \n", fLateralSteelStrip));
365       }
366     }
367   }
368 }
369
370 void AliEMCALGeometry::DefineSamplingFraction()
371 {
372   // Jun 05,2006
373   // Look http://rhic.physics.wayne.edu/~pavlinov/ALICE/SHISHKEBAB/RES/linearityAndResolutionForTRD1.html
374   // Keep for compatibilty
375   //
376   if(fNECLayers == 69) {        // 10% layer reduction
377     fSampling = 12.55;
378   } else if(fNECLayers == 61) { // 20% layer reduction
379     fSampling = 12.80;
380   } else if(fNECLayers == 77) {
381     if       (fECScintThick>0.175 && fECScintThick<0.177) { // 10% Pb thicknes reduction
382       fSampling = 10.5; // fECScintThick = 0.176, fECPbRadThickness=0.144;
383     } else if(fECScintThick>0.191 && fECScintThick<0.193) { // 20% Pb thicknes reduction
384       fSampling = 8.93; // fECScintThick = 0.192, fECPbRadThickness=0.128;
385     }
386   }
387 }
388
389 //____________________________________________________________________________
390 void AliEMCALGeometry::FillTRU(const TClonesArray * digits, TClonesArray * ampmatrix, TClonesArray * timeRmatrix) {
391
392
393 //  Orders digits ampitudes list in fNTRU TRUs (384 cells) per supermodule. 
394 //  Each TRU is a TMatrixD, and they are kept in TClonesArrays. The number of 
395 //  TRU in phi is fNTRUPhi, and the number of TRU in eta is fNTRUEta.
396 //  Last 2 modules are half size in Phi, I considered that the number of TRU
397 //  is maintained for the last modules but decision not taken. If different, 
398 //  then this must be changed. 
399  
400
401   //Check data members
402
403   if(fNTRUEta*fNTRUPhi != fNTRU)
404     Error("FillTRU"," Wrong number of TRUS per Eta or Phi");
405
406   //Initilize and declare variables
407   //List of TRU matrices initialized to 0.
408   Int_t nCellsPhi  = fNPhi*2/fNTRUPhi;
409   Int_t nCellsPhi2 = fNPhi/fNTRUPhi; //HalfSize modules
410   Int_t nCellsEta  = fNZ*2/fNTRUEta;
411   Int_t id      = -1; 
412   Float_t amp   = -1;
413   Float_t timeR = -1;
414   Int_t iSupMod = -1;
415   Int_t nTower  = -1;
416   Int_t nIphi   = -1;
417   Int_t nIeta   = -1;
418   Int_t iphi    = -1;
419   Int_t ieta    = -1;
420
421   //List of TRU matrices initialized to 0.
422   for(Int_t k = 0; k < fNTRU*fNumberOfSuperModules; k++){
423     TMatrixD  * amptrus   = new TMatrixD(nCellsPhi,nCellsEta) ;
424     TMatrixD  * timeRtrus = new TMatrixD(nCellsPhi,nCellsEta) ;
425     for(Int_t i = 0; i < nCellsPhi; i++){
426       for(Int_t j = 0; j < nCellsEta; j++){
427         (*amptrus)(i,j) = 0.0;
428         (*timeRtrus)(i,j) = 0.0;
429       }
430     }
431     new((*ampmatrix)[k])   TMatrixD(*amptrus) ;
432     new((*timeRmatrix)[k]) TMatrixD(*timeRtrus) ; 
433   }
434   
435   AliEMCALDigit * dig ;
436   
437   //Digits loop to fill TRU matrices with amplitudes.
438   for(Int_t idig = 0 ; idig < digits->GetEntriesFast() ; idig++){
439     
440     dig = dynamic_cast<AliEMCALDigit *>(digits->At(idig)) ;
441     amp    = dig->GetAmp() ;   // Energy of the digit (arbitrary units)
442     id     = dig->GetId() ;    // Id label of the cell
443     timeR  = dig->GetTimeR() ; // Earliest time of the digit
444    
445     //Get eta and phi cell position in supermodule
446     Bool_t bCell = GetCellIndex(id, iSupMod, nTower, nIphi, nIeta) ;
447     if(!bCell)
448       Error("FillTRU","Wrong cell id number") ;
449     
450     GetCellPhiEtaIndexInSModule(iSupMod,nTower,nIphi, nIeta,iphi,ieta);
451
452     //Check to which TRU in the supermodule belongs the cell. 
453     //Supermodules are divided in a TRU matrix of dimension 
454     //(fNTRUPhi,fNTRUEta).
455     //Each TRU is a cell matrix of dimension (nCellsPhi,nCellsEta)
456
457     //First calculate the row and column in the supermodule 
458     //of the TRU to which the cell belongs.
459     Int_t col   = ieta/nCellsEta; 
460     Int_t row   = iphi/nCellsPhi; 
461     if(iSupMod > 9)
462       row   = iphi/nCellsPhi2; 
463     //Calculate label number of the TRU
464     Int_t itru  = row + col*fNTRUPhi + iSupMod*fNTRU ;  
465  
466     //Fill TRU matrix with cell values
467     TMatrixD * amptrus   = dynamic_cast<TMatrixD *>(ampmatrix->At(itru)) ;
468     TMatrixD * timeRtrus = dynamic_cast<TMatrixD *>(timeRmatrix->At(itru)) ;
469
470     //Calculate row and column of the cell inside the TRU with number itru
471     Int_t irow = iphi - row *  nCellsPhi;
472     if(iSupMod > 9)
473       irow = iphi - row *  nCellsPhi2;
474     Int_t icol = ieta - col *  nCellsEta;
475     
476     (*amptrus)(irow,icol) = amp ;
477     (*timeRtrus)(irow,icol) = timeR ;
478
479   }
480 }
481
482 //______________________________________________________________________
483 void AliEMCALGeometry::GetCellPhiEtaIndexInSModuleFromTRUIndex(const Int_t itru, const Int_t iphitru, const Int_t ietatru, Int_t &iphiSM, Int_t &ietaSM) const 
484 {
485   
486   // This method transforms the (eta,phi) index of cells in a 
487   // TRU matrix into Super Module (eta,phi) index.
488   
489   // Calculate in which row and column where the TRU are 
490   // ordered in the SM
491
492   Int_t col = itru/ fNTRUPhi ;
493   Int_t row = itru - col*fNTRUPhi ;
494    
495   //Calculate the (eta,phi) index in SM
496   Int_t nCellsPhi = fNPhi*2/fNTRUPhi;
497   Int_t nCellsEta = fNZ*2/fNTRUEta;
498   
499   iphiSM = nCellsPhi*row + iphitru  ;
500   ietaSM = nCellsEta*col + ietatru  ; 
501 }
502
503 //______________________________________________________________________
504 AliEMCALGeometry *  AliEMCALGeometry::GetInstance(){ 
505   // Returns the pointer of the unique instance
506   
507   AliEMCALGeometry * rv = static_cast<AliEMCALGeometry *>( fgGeom );
508   return rv; 
509 }
510
511 //______________________________________________________________________
512 AliEMCALGeometry* AliEMCALGeometry::GetInstance(const Text_t* name,
513                                                 const Text_t* title){
514     // Returns the pointer of the unique instance
515
516     AliEMCALGeometry * rv = 0; 
517     if ( fgGeom == 0 ) {
518         if ( strcmp(name,"") == 0 ) rv = 0;
519         else {
520             fgGeom = new AliEMCALGeometry(name, title);
521             if ( fgInit ) rv = (AliEMCALGeometry * ) fgGeom;
522             else {
523                 rv = 0; 
524                 delete fgGeom; 
525                 fgGeom = 0; 
526             } // end if fgInit
527         } // end if strcmp(name,"")
528     }else{
529         if ( strcmp(fgGeom->GetName(), name) != 0) {
530           printf("\ncurrent geometry is %s : ", fgGeom->GetName());
531           printf(" you cannot call %s ", name);  
532         }else{
533           rv = (AliEMCALGeometry *) fgGeom; 
534         } // end 
535     }  // end if fgGeom
536     return rv; 
537 }
538
539 Bool_t AliEMCALGeometry::IsInEMCAL(Double_t x, Double_t y, Double_t z) const {
540   // Checks whether point is inside the EMCal volume, used in AliEMCALv*.cxx
541   //
542   // Code uses cylindrical approximation made of inner radius (for speed)
543   //
544   // Points behind EMCAl, i.e. R > outer radius, but eta, phi in acceptance 
545   // are considered to inside
546
547   Double_t r=sqrt(x*x+y*y);
548
549   if ( r > fEnvelop[0] ) {
550      Double_t theta;
551      theta  =    TMath::ATan2(r,z);
552      Double_t eta;
553      if(theta == 0) 
554        eta = 9999;
555      else 
556        eta    =   -TMath::Log(TMath::Tan(theta/2.));
557      if (eta < fArm1EtaMin || eta > fArm1EtaMax)
558        return 0;
559  
560      Double_t phi = TMath::ATan2(y,x) * 180./TMath::Pi();
561      if (phi > fArm1PhiMin && phi < fArm1PhiMax)
562        return 1;
563   }
564   return 0;
565 }
566 // ==
567
568 //
569 // == Shish-kebab cases ==
570 //
571 Int_t AliEMCALGeometry::GetAbsCellId(Int_t nSupMod, Int_t nTower, Int_t nIphi, Int_t nIeta) const
572
573   // 27-aug-04; 
574   // corr. 21-sep-04; 
575   //       13-oct-05; 110 degree case
576   // May 31, 2006; ALICE numbering scheme:
577   // 0 <= nSupMod < fNumberOfSuperModules
578   // 0 <= nTower  < fNPHI * fNZ ( fNPHI * fNZ/2 for fKey110DEG=1)
579   // 0 <= nIphi   < fNPHIdiv
580   // 0 <= nIeta   < fNETAdiv
581   // 0 <= absid   < fNCells
582   static Int_t id=0; // have to change from 0 to fNCells-1
583   if(fKey110DEG == 1 && nSupMod >= 10) { // 110 degree case; last two supermodules
584     id  = fNCellsInSupMod*10 + (fNCellsInSupMod/2)*(nSupMod-10);
585   } else {
586     id  = fNCellsInSupMod*nSupMod;
587   }
588   id += fNCellsInTower *nTower;
589   id += fNPHIdiv *nIphi;
590   id += nIeta;
591   if(id<0 || id >= fNCells) {
592 //     printf(" wrong numerations !!\n");
593 //     printf("    id      %6i(will be force to -1)\n", id);
594 //     printf("    fNCells %6i\n", fNCells);
595 //     printf("    nSupMod %6i\n", nSupMod);
596 //     printf("    nTower  %6i\n", nTower);
597 //     printf("    nIphi   %6i\n", nIphi);
598 //     printf("    nIeta   %6i\n", nIeta);
599     id = -TMath::Abs(id); // if negative something wrong
600   }
601   return id;
602 }
603
604 Bool_t  AliEMCALGeometry::CheckAbsCellId(Int_t absId) const
605
606   // May 31, 2006; only trd1 now
607   if(absId<0 || absId >= fNCells) return kFALSE;
608   else                            return kTRUE;
609 }
610
611 Bool_t AliEMCALGeometry::GetCellIndex(Int_t absId,Int_t &nSupMod,Int_t &nTower,Int_t &nIphi,Int_t &nIeta) const
612
613   // 21-sep-04; 19-oct-05;
614   // May 31, 2006; ALICE numbering scheme:
615   static Int_t tmp=0, sm10=0;
616   if(!CheckAbsCellId(absId)) return kFALSE;
617
618   sm10 = fNCellsInSupMod*10;
619   if(fKey110DEG == 1 && absId >= sm10) { // 110 degree case; last two supermodules  
620     nSupMod = (absId-sm10) / (fNCellsInSupMod/2) + 10;
621     tmp     = (absId-sm10) % (fNCellsInSupMod/2);
622   } else {
623     nSupMod = absId / fNCellsInSupMod;
624     tmp     = absId % fNCellsInSupMod;
625   }
626
627   nTower  = tmp / fNCellsInTower;
628   tmp     = tmp % fNCellsInTower;
629   nIphi   = tmp / fNPHIdiv;
630   nIeta   = tmp % fNPHIdiv;
631
632   return kTRUE;
633 }
634
635 void AliEMCALGeometry::GetModulePhiEtaIndexInSModule(Int_t nSupMod, Int_t nTower,  int &iphim, int &ietam) const
636
637   // added nSupMod; have to check  - 19-oct-05 !
638   // Alice numbering scheme        - Jun 01,2006 
639   static Int_t nphi;
640
641   if(fKey110DEG == 1 && nSupMod>=10) nphi = fNPhi/2;
642   else                               nphi = fNPhi;
643
644   ietam = nTower/nphi; // have to change from 0 to fNZ-1
645   iphim = nTower%nphi; // have to change from 0 to fNPhi-1
646 }
647
648 void AliEMCALGeometry::GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nTower, Int_t nIphi, Int_t nIeta, 
649 int &iphi, int &ieta) const
650
651   // added nSupMod; Nov 25, 05
652   // Alice numbering scheme        - Jun 01,2006 
653   static Int_t iphim, ietam;
654
655   GetModulePhiEtaIndexInSModule(nSupMod,nTower, iphim, ietam); 
656   // have to change from 0 to (fNZ*fNETAdiv-1)
657   ieta  = ietam*fNETAdiv + (1-nIeta); // x(module) = -z(SM) 
658   // iphi - have to change from 0 to (fNPhi*fNPHIdiv-1)
659   iphi  = iphim*fNPHIdiv + nIphi;     // y(module) =  y(SM) 
660 }
661
662 Int_t  AliEMCALGeometry::GetSuperModuleNumber(Int_t absId)  const
663 {
664   //return the number of the 
665   //supermodule given the absolute
666   //ALICE numbering
667
668   static Int_t nSupMod, nTower, nIphi, nIeta;
669   GetCellIndex(absId, nSupMod, nTower, nIphi, nIeta);
670   return nSupMod;
671
672
673 // Methods for AliEMCALRecPoint - Feb 19, 2006
674 Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, Double_t &xr, Double_t &yr, Double_t &zr) const
675 {
676   // Look to see what the relative
677   // position inside a given cell is
678   // for a recpoint.
679   // Alice numbering scheme - Jun 08, 2006
680
681   static Int_t nSupMod, nTower, nIphi, nIeta, iphi, ieta;
682   static Int_t phiIndexShift=6;
683   if(!CheckAbsCellId(absId)) return kFALSE;
684
685   GetCellIndex(absId, nSupMod, nTower, nIphi, nIeta);
686   GetCellPhiEtaIndexInSModule(nSupMod,nTower,nIphi,nIeta, iphi, ieta); 
687  
688   xr = fXCentersOfCells.At(ieta);
689   zr = fEtaCentersOfCells.At(ieta);
690
691   if(nSupMod<10) {
692     yr = fPhiCentersOfCells.At(iphi);
693   } else {
694     yr = fPhiCentersOfCells.At(iphi + phiIndexShift);
695     //    cout<<" absId "<<absId<<" nSupMod "<<nSupMod << " iphi "<<iphi<<" ieta "<<ieta;
696     //    cout<< " xr " << xr << " yr " << yr << " zr " << zr <<endl;
697   }
698
699   return kTRUE;
700 }
701
702 Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, Double_t loc[3]) const
703 {
704   // Alice numbering scheme - Jun 03, 2006
705   loc[0] = loc[1] = loc[2]=0.0;
706   if(RelPosCellInSModule(absId, loc[0],loc[1],loc[2])) {
707     return kTRUE;
708   }
709   return kFALSE;
710 }
711
712 Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, TVector3 &vloc) const
713 {
714   static Double_t loc[3];
715   if(RelPosCellInSModule(absId,loc)) {
716     vloc.SetXYZ(loc[0], loc[1], loc[2]);
717     return kTRUE;
718   } else {
719     vloc.SetXYZ(0,0,0);
720     return kFALSE;
721   }
722   // Alice numbering scheme - Jun 03, 2006
723 }
724
725 void AliEMCALGeometry::CreateListOfTrd1Modules()
726 {
727   //Generate the list of Trd1 modules
728   //which will make up the EMCAL
729   //geometry
730
731   AliDebug(2,Form(" AliEMCALGeometry::CreateListOfTrd1Modules() started "));
732
733   AliEMCALShishKebabTrd1Module *mod=0, *mTmp=0; // current module
734   if(fShishKebabTrd1Modules == 0) {
735     fShishKebabTrd1Modules = new TList;
736     for(int iz=0; iz< GetNZ(); iz++) { 
737       if(iz==0) { 
738         mod  = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,this);
739       } else {
740         mTmp  = new AliEMCALShishKebabTrd1Module(*mod);
741         mod   = mTmp;
742       }
743       fShishKebabTrd1Modules->Add(mod);
744     }
745   } else {
746     AliDebug(2,Form(" Already exits : "));
747   }
748   AliDebug(2,Form(" fShishKebabTrd1Modules has %i modules \n", 
749                   fShishKebabTrd1Modules->GetSize()));
750   // Feb 20,2006;
751   // Jun 01, 2006 - ALICE numbering scheme
752   // define grid for cells in eta(z) and x directions in local coordinates system of SM
753   //  fEtaCentersOfCells = new TArrayD(fNZ *fNETAdiv);
754   //  fXCentersOfCells = new TArrayD(fNZ *fNETAdiv);
755   fEtaCentersOfCells.Set(fNZ *fNETAdiv);
756   fXCentersOfCells.Set(fNZ *fNETAdiv);
757   AliDebug(2,Form(" Cells grid in eta directions : size %i\n", fEtaCentersOfCells.GetSize()));
758   Int_t iphi=0, ieta=0, nTower=0;
759   Double_t xr, zr;
760   for(Int_t it=0; it<fNZ; it++) { // array index
761     AliEMCALShishKebabTrd1Module *trd1 = GetShishKebabModule(it);
762     nTower = fNPhi*it;
763     for(Int_t ic=0; ic<fNETAdiv; ic++) { // array index
764       trd1->GetCenterOfCellInLocalCoordinateofSM(ic, xr, zr);
765       GetCellPhiEtaIndexInSModule(0, nTower, 0, ic, iphi, ieta); // don't depend from phi - ieta in action
766       fXCentersOfCells.AddAt(float(xr) - fParSM[0],ieta);
767       fEtaCentersOfCells.AddAt(float(zr) - fParSM[2],ieta);
768     }
769   }
770   for(Int_t i=0; i<fEtaCentersOfCells.GetSize(); i++) {
771     AliDebug(2,Form(" ind %2.2i : z %8.3f : x %8.3f", i+1, 
772                     fEtaCentersOfCells.At(i),fXCentersOfCells.At(i)));
773   }
774
775  // define grid for cells in phi(y) direction in local coordinates system of SM
776   //  fPhiCentersOfCells = new TArrayD(fNPhi*fNPHIdiv);
777   fPhiCentersOfCells.Set(fNPhi*fNPHIdiv);
778   AliDebug(2,Form(" Cells grid in phi directions : size %i\n", fPhiCentersOfCells.GetSize()));
779   Int_t ind=0;
780   for(Int_t it=0; it<fNPhi; it++) { // array index
781     Float_t ytLeftCenterModule = -fParSM[1] + fPhiModuleSize*(2*it+1)/2;         // module
782     for(Int_t ic=0; ic<fNPHIdiv; ic++) { // array index
783       Float_t ytLeftCenterCell = ytLeftCenterModule + fPhiTileSize *(2*ic-1)/2.; // tower(cell) 
784       fPhiCentersOfCells.AddAt(ytLeftCenterCell,ind);
785       AliDebug(2,Form(" ind %2.2i : y %8.3f ", ind, fPhiCentersOfCells.At(ind))); 
786       ind++;
787     }
788   }
789 }
790
791 void  AliEMCALGeometry::GetTransformationForSM()
792 {
793   //Uses the geometry manager to
794   //load the transformation matrix
795   //for the supermodules
796
797   static Bool_t transInit=kFALSE;
798   if(transInit) return;
799
800   int i=0;
801   if(gGeoManager == 0) {
802     Info("CreateTransformationForSM() "," Load geometry : TGeoManager::Import()");
803     assert(0);
804   }
805   TGeoNode *tn = gGeoManager->GetTopNode();
806   TGeoNode *node=0, *xen1 = 0;
807   for(i=0; i<tn->GetNdaughters(); i++) {
808     node = tn->GetDaughter(i);
809     TString ns(node->GetName());
810     if(ns.Contains(GetNameOfEMCALEnvelope())) {
811       xen1 = node;
812       break;
813     }
814   }
815   if(!xen1) {
816     Info("CreateTransformationForSM() "," geometry has not EMCAL envelope with name %s", 
817     GetNameOfEMCALEnvelope());
818     assert(0);
819   }
820   printf(" i %i : EMCAL Envelope is %s : #SM %i \n", i, xen1->GetName(), xen1->GetNdaughters());
821   for(i=0; i<xen1->GetNdaughters(); i++) {
822     TGeoNodeMatrix *sm = (TGeoNodeMatrix*)xen1->GetDaughter(i);
823     fMatrixOfSM[i] = sm->GetMatrix();
824     //Compiler doesn't like this syntax...
825     //    printf(" %i : matrix %x \n", i, fMatrixOfSM[i]);
826   }
827   transInit = kTRUE;
828 }
829
830 void AliEMCALGeometry::GetGlobal(const Double_t *loc, Double_t *glob, int ind) const
831 {
832   // Figure out the global numbering
833   // of a given supermodule from the
834   // local numbering
835   // Alice numbering - Jun 03,2006
836   //  if(fMatrixOfSM[0] == 0) GetTransformationForSM();
837
838   if(ind>=0 && ind < GetNumberOfSuperModules()) {
839     fMatrixOfSM[ind]->LocalToMaster(loc, glob);
840   }
841 }
842
843 void AliEMCALGeometry::GetGlobal(const TVector3 &vloc, TVector3 &vglob, int ind) const
844 {
845   //Figure out the global numbering
846   //of a given supermodule from the
847   //local numbering given a 3-vector location
848
849   static Double_t tglob[3], tloc[3];
850   vloc.GetXYZ(tloc);
851   GetGlobal(tloc, tglob, ind);
852   vglob.SetXYZ(tglob[0], tglob[1], tglob[2]);
853 }
854
855 void AliEMCALGeometry::GetGlobal(Int_t absId , double glob[3]) const
856
857   // Alice numbering scheme - Jun 03, 2006
858   static Int_t nSupMod, nModule, nIphi, nIeta;
859   static double loc[3];
860
861   glob[0]=glob[1]=glob[2]=0.0; // bad case
862   if(RelPosCellInSModule(absId, loc)) {
863     GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
864     fMatrixOfSM[nSupMod]->LocalToMaster(loc, glob);
865   }
866 }
867
868 void AliEMCALGeometry::GetGlobal(Int_t absId , TVector3 &vglob) const
869
870   // Alice numbering scheme - Jun 03, 2006
871   static Double_t glob[3];
872
873   GetGlobal(absId, glob);
874   vglob.SetXYZ(glob[0], glob[1], glob[2]);
875
876 }
877
878 void AliEMCALGeometry::GetGlobal(const AliRecPoint *rp, TVector3 &vglob) const
879 {
880   // Figure out the global numbering
881   // of a given supermodule from the
882   // local numbering for RecPoints
883
884   static TVector3 vloc;
885   static Int_t nSupMod, nModule, nIphi, nIeta;
886
887   AliRecPoint *rpTmp = (AliRecPoint*)rp; // const_cast ??
888   if(!rpTmp) return;
889   AliEMCALRecPoint *rpEmc = (AliEMCALRecPoint*)rpTmp;
890
891   GetCellIndex(rpEmc->GetAbsId(0), nSupMod, nModule, nIphi, nIeta);
892   rpTmp->GetLocalPosition(vloc);
893   GetGlobal(vloc, vglob, nSupMod);
894 }
895
896 void AliEMCALGeometry::EtaPhiFromIndex(Int_t absId,Float_t &eta,Float_t &phi) const
897 {
898   // Jun 03, 2006 - version for TRD1
899   static TVector3 vglob;
900   GetGlobal(absId, vglob);
901   eta = vglob.Eta();
902   phi = vglob.Phi();
903 }
904
905 AliEMCALShishKebabTrd1Module* AliEMCALGeometry::GetShishKebabModule(Int_t neta=0)
906 {
907   //This method was too long to be
908   //included in the header file - the
909   //rule checker complained about it's
910   //length, so we move it here.  It returns the
911   //shishkebabmodule at a given eta index point.
912
913   static AliEMCALShishKebabTrd1Module* trd1=0;
914   if(fShishKebabTrd1Modules && neta>=0 && neta<fShishKebabTrd1Modules->GetSize()) {
915     trd1 = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(neta);
916   } else trd1 = 0;
917   return trd1;
918 }