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