]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGeometry.cxx
stdlib.h needeed to define abort()
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGeometry.cxx
1 /**************************************************************************
2
3  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4
5  *                                                                        *
6
7  * Author: The ALICE Off-line Project.                                    *
8
9  * Contributors are mentioned in the code where appropriate.              *
10
11  *                                                                        *
12
13  * Permission to use, copy, modify and distribute this software and its   *
14
15  * documentation strictly for non-commercial purposes is hereby granted   *
16
17  * without fee, provided that the above copyright notice appears in all   *
18
19  * copies and that both the copyright notice and this permission notice   *
20
21  * appear in the supporting documentation. The authors make no claims     *
22
23  * about the suitability of this software for any purpose. It is          *
24
25  * provided "as is" without express or implied warranty.                  *
26
27  **************************************************************************/
28
29
30
31 /* $Id$*/
32
33
34
35 //_________________________________________________________________________
36
37 // Geometry class  for EMCAL : singleton  
38
39 // EMCAL consists of layers of scintillator and lead
40
41 // Places the the Barrel Geometry of The EMCAL at Midrapidity
42
43 // between 0 and 120 degrees of Phi and
44
45 // -0.7 to 0.7 in eta 
46
47 // Number of Modules and Layers may be controlled by 
48
49 // the name of the instance defined               
50
51 // EMCALArch2x has more modules along both phi and eta
52
53 // EMCALArchxa has less Layers in the Radial Direction
54
55 //*-- Author: Sahal Yacoob (LBL / UCT)
56
57 //     and  : Yves Schutz (SUBATECH)
58
59 //     and  : Jennifer Klay (LBL)
60
61
62
63 // --- ROOT system ---
64
65
66
67 // --- Standard library ---
68
69
70
71 #include <iostream.h>
72 #include <stdlib.h> 
73
74
75
76 // --- AliRoot header files ---
77
78 #include <TMath.h>
79
80 // -- ALICE Headers.
81
82 #include "AliConst.h"
83
84 // --- EMCAL headers
85
86 #include "AliEMCALGeometry.h"
87
88
89
90 ClassImp(AliEMCALGeometry);
91
92
93
94 AliEMCALGeometry *AliEMCALGeometry::fgGeom = 0;
95
96 Bool_t            AliEMCALGeometry::fgInit = kFALSE;
97
98
99
100 //______________________________________________________________________
101
102 AliEMCALGeometry::~AliEMCALGeometry(void){
103
104     // dtor
105
106 }
107
108 //______________________________________________________________________
109
110 void AliEMCALGeometry::Init(void){
111
112     // Initializes the EMCAL parameters
113
114
115
116     fgInit = kFALSE; // Assume failer untill proven otherwise.
117
118
119
120     TString name(GetName()) ; 
121
122                  
123
124     if( name != "EMCALArch1a" &&
125
126         name != "EMCALArch1b" && 
127
128         name != "EMCALArch2a" && 
129
130         name != "EMCALArch2b"  ){
131
132       cerr << "ERROR: " << ClassName() << "::Init -> " << name.Data() 
133
134            << " is not a known geometry (choose among EMCALArch1a, EMCALArch1b, EMCALArch2a and EMCALArch2b)" 
135
136            << endl ; 
137
138       abort() ;
139
140     } // end if
141
142     //
143
144     if ( name == "EMCALArch1a"  ||
145
146          name == "EMCALArch1b" ) {
147
148         fNZ         = 96;
149
150         fNPhi       = 144;
151
152     } // end if
153
154     if ( name == "EMCALArch2a"  ||
155
156          name, "EMCALArch2b" ) {
157
158         fNZ         = 112;
159
160         fNPhi       = 168;
161
162     } // end if
163
164     if ( name == "EMCALArch1a"  ||
165
166          name == "EMCALArch2a" ) {
167
168         fNLayers    = 21;
169
170     } // end if
171
172     if ( name == "EMCALArch1b"  ||
173
174          name == "EMCALArch2b" ) {
175
176         fNLayers    = 25;
177
178     } // end if
179
180
181
182     // geometry
183
184     fAirGap         = 5.0; // cm, air gap between EMCAL mother volume and 
185
186                            // active material.
187
188     fAlFrontThick   = 3.18; // cm, Thickness of front Al layer
189
190     fPbRadThickness = 0.5; // cm, Thickness of theh Pb radiators.
191
192     fPreShowerSintThick = 0.6; // cm, Thickness of the sintilator for the
193
194                                // preshower part of the calorimeter
195
196     fFullShowerSintThick = 0.5; // cm, Thickness of the sintilator for the
197
198                                 // full shower part of the calorimeter
199
200     fArm1PhiMin     =  60.0; // degrees, Starting EMCAL Phi position
201
202     fArm1PhiMax     = 180.0; // degrees, Ending EMCAL Phi position
203
204     fArm1EtaMin     = -0.7; // pseudorapidity, Starting EMCAL Eta position
205
206     fArm1EtaMax     = +0.7; // pseudorapidity, Ending EMCAL Eta position
207
208     fIPDistance     = 454.0; // cm, Radial distance to inner surface of EMCAL
209
210     fShellThickness = GetAlFrontThickness() + 2.*GetPreSintThick() +
211
212         (fNLayers-2)*GetFullSintThick()+(fNLayers-1)*GetPbRadThick();
213
214     //below; cm, Z lenght of the EMCAL.
215
216     fZLength        = 2.*ZFromEtaR(fIPDistance+fShellThickness,fArm1EtaMax);
217
218     fEnvelop[0]     = fIPDistance; // mother volume inner radius
219
220     fEnvelop[1]     = fIPDistance + fShellThickness; // mother volume outer r.
221
222     fEnvelop[2]     = 1.00001*fZLength; // add some padding for mother volume. 
223
224     fGap2Active     = 1.0;  // cm, Gap between 
225
226     fgInit = kTRUE; 
227
228 }
229
230 //______________________________________________________________________
231
232 AliEMCALGeometry *  AliEMCALGeometry::GetInstance(){ 
233
234   // Returns the pointer of the unique instance
235
236   
237
238   return static_cast<AliEMCALGeometry *>( fgGeom ) ; 
239
240 }
241
242 //______________________________________________________________________
243
244 AliEMCALGeometry* AliEMCALGeometry::GetInstance(const Text_t* name,
245
246                                                 const Text_t* title){
247
248     // Returns the pointer of the unique instance
249
250
251
252     AliEMCALGeometry * rv = 0; 
253
254     if ( fgGeom == 0 ) {
255
256         if ( strcmp(name,"") == 0 ) rv = 0;
257
258         else {    
259
260             fgGeom = new AliEMCALGeometry(name, title);
261
262             if ( fgInit ) rv = (AliEMCALGeometry * ) fgGeom;
263
264             else {
265
266                 rv = 0; 
267
268                 delete fgGeom; 
269
270                 fgGeom = 0; 
271
272             } // end if fgInit
273
274         } // end if strcmp(name,"")
275
276     }else{
277
278         if ( strcmp(fgGeom->GetName(), name) != 0 ) {
279
280             cout << "AliEMCALGeometry <E> : current geometry is " 
281
282                  << fgGeom->GetName() << endl
283
284                  << "                      you cannot call     " << name 
285
286                  << endl; 
287
288         }else{
289
290             rv = (AliEMCALGeometry *) fgGeom; 
291
292         } // end if
293
294     }  // end if fgGeom
295
296     return rv; 
297
298 }
299
300 //______________________________________________________________________
301
302 Int_t AliEMCALGeometry::TowerIndex(Int_t ieta,Int_t iphi,Int_t ipre) const {
303
304     // Returns the tower index number from the based on the Z and Phi
305
306     // index numbers. There are 2 times the number of towers to separate
307
308     // out the full towsers from the pre-towsers.
309
310     // Inputs:
311
312     //   Int_t ieta    // index allong z axis [1-fNZ]
313
314     //   Int_t iphi  // index allong phi axis [1-fNPhi]
315
316     //   Int_t ipre  // 0 = Full tower, 1 = Pre-shower tower only. [0,1]
317
318     // Outputs:
319
320     //   none.
321
322     // Returned
323
324     // Int_t the absoulute tower index. [1-2*fNZ*fNPhi]
325
326     Int_t index;
327
328
329
330     if((ieta<=0 || ieta>GetNEta()) || (iphi<=0 || iphi>GetNPhi()) ||
331
332        (ipre<0 || ipre>1) ){
333
334         cout << "inputs out of range ieta=" << ieta << " [1-" << GetNEta();
335
336         cout << "] iphi=" << iphi << " [1-" << GetNPhi() << "] ipre=";
337
338         cout << ipre << "[0,1]. returning -1" << endl;
339
340         return -1;
341
342     } // end if
343
344     index = iphi + GetNPhi()*(ieta-1) + ipre*(GetNPhi()*GetNEta());
345
346     return index;
347
348 }
349
350 //______________________________________________________________________
351
352 void AliEMCALGeometry::TowerIndexes(Int_t index,Int_t &ieta,Int_t &iphi,
353
354                                     Int_t &ipre) const {
355
356     // given the tower index number it returns the based on the Z and Phi
357
358     // index numbers and if it is for the full tower or the pre-tower number.
359
360     // There are 2 times the number of towers to separate
361
362     // out the full towsers from the pre-towsers.
363
364     // Inputs:
365
366     //   Int_t index // Tower index number [1-2*fNZ*fNPhi]
367
368     // Outputs:
369
370     //   Int_t ieta    // index allong z axis [1-fNZ]
371
372     //   Int_t iphi  // index allong phi axis [1-fNPhi]
373
374     //   Int_t ipre  // 0 = Full tower, 1 = Pre-shower tower only. [0,1]
375
376     // Returned
377
378     //   none.
379
380     Int_t itowers;
381
382
383
384     itowers = GetNEta()*GetNPhi();
385
386     if(index<1 || index>2*itowers){
387
388         cout << "index=" << index <<" is out of range [1-";
389
390         cout << 2*itowers << "], returning -1 for all." << endl;
391
392         ieta = -1; iphi = -1; ipre = -1;
393
394         return ;
395
396     } // end if
397
398     ipre = 0;
399
400     if(index>itowers){ // pre shower indexs
401
402         ipre = 1;
403
404         index = index - itowers;
405
406     } // end if
407
408     ieta = 1+ (Int_t)((index-1)/GetNPhi());
409
410     iphi = index - GetNPhi()*(ieta-1);
411
412     return;
413
414 }
415
416 //______________________________________________________________________
417
418 void AliEMCALGeometry::EtaPhiFromIndex(Int_t index,Float_t &eta,Float_t &phi) const {
419
420     // given the tower index number it returns the based on the eta and phi
421
422     // of the tower.
423
424     // Inputs:
425
426     //   Int_t index // Tower index number [1-2*fNZ*fNPhi]
427
428     // Outputs:
429
430     //   Float_t eta  // eta of center of tower in pseudorapidity
431
432     //   Float_t phi  // phi of center of tower in degrees
433
434     // Returned
435
436     //   none.
437
438     Int_t ieta,iphi,ipre;
439
440     Double_t deta,dphi,phid;
441
442
443
444     TowerIndexes(index,ieta,iphi,ipre);
445
446     deta = (GetArm1EtaMax()-GetArm1EtaMin())/((Float_t)GetNEta());
447
448     eta  = GetArm1EtaMin() + (((Float_t)ieta)-0.5)*deta;
449
450     dphi = (GetArm1PhiMax() - GetArm1PhiMin())/((Float_t)GetNPhi());  // in degrees.
451
452     phid = GetArm1PhiMin() + dphi*((Float_t)iphi -0.5);//iphi range [1-fNphi].
453
454     phi  = phid;
455
456 }
457
458 //______________________________________________________________________
459
460 Int_t AliEMCALGeometry::TowerIndexFromEtaPhi(Float_t eta,Float_t phi) const {
461
462     // returns the tower index number based on the eta and phi of the tower.
463
464     // Inputs:
465
466     //   Float_t eta  // eta of center of tower in pseudorapidity
467
468     //   Float_t phi  // phi of center of tower in degrees
469
470     // Outputs:
471
472     //   none.
473
474     // Returned
475
476     //   Int_t index // Tower index number [1-fNZ*fNPhi]
477
478     Int_t ieta,iphi;
479
480
481
482     ieta = 1 + (Int_t)(((Float_t)GetNEta())*(eta-GetArm1EtaMin())/
483
484                   (GetArm1EtaMax() - GetArm1EtaMin()));
485
486     if(ieta<=0 || ieta>GetNEta()){
487
488         cout << "TowerIndexFromEtaPhi:";
489
490         cout << "ieta = "<< ieta << " eta=" << eta << " is outside of EMCAL. etamin=";
491
492         cout << GetArm1EtaMin() << " to etamax=" << GetArm1EtaMax();
493
494         cout << " returning -1" << endl;
495
496         return -1;
497
498     } // end if
499
500     iphi = 1 + (Int_t)(((Float_t)GetNPhi())*(phi-GetArm1PhiMin())/
501
502                   ((Float_t)(GetArm1PhiMax() - GetArm1PhiMin())));
503
504     if(iphi<=0 || iphi>GetNPhi()){
505
506         cout << "TowerIndexFromEtaPhi:";
507
508         cout << "iphi=" << iphi << " phi=" << phi << " is outside of EMCAL.";
509
510         cout << " Phimin=" << GetArm1PhiMin() << " PhiMax=" << GetArm1PhiMax();
511
512         cout << " returning -1" << endl;
513
514         return -1;
515
516     } // end if
517
518     return TowerIndex(ieta,iphi,0);
519
520 }
521
522 //______________________________________________________________________
523
524 Int_t AliEMCALGeometry::PreTowerIndexFromEtaPhi(Float_t eta,Float_t phi) const {
525
526     // returns the pretower index number based on the eta and phi of the tower.
527
528     // Inputs:
529
530     //   Float_t eta  // eta of center of tower in pseudorapidity
531
532     //   Float_t phi  // phi of center of tower in degrees
533
534     // Outputs:
535
536     //   none.
537
538     // Returned
539
540     //   Int_t index // PreTower index number [fNZ*fNPhi-2*fNZ*fNPhi]
541
542
543
544     return GetNEta()*GetNPhi()+TowerIndexFromEtaPhi(eta,phi);
545
546 }
547
548 //______________________________________________________________________
549
550 Bool_t AliEMCALGeometry::AbsToRelNumbering(Int_t AbsId, Int_t *relid) const {
551
552     // Converts the absolute numbering into the following array/
553
554     //  relid[0] = EMCAL Arm number 1:1 
555
556     //  relid[1] = 0  Not in Pre Shower layers
557
558     //           = -1 In Pre Shower
559
560     //  relid[2] = Row number inside EMCAL
561
562     //  relid[3] = Column number inside EMCAL
563
564     // Input:
565
566     //   Int_t AbsId // Tower index number [1-2*fNZ*fNPhi]
567
568     // Outputs:
569
570     //   Int_t *relid // array of 5. Discribed above.
571
572     Bool_t rv  = kTRUE ;
573
574     Int_t ieta=0,iphi=0,ipre=0,index=AbsId;
575
576
577
578     TowerIndexes(index,ieta,iphi,ipre);
579
580     relid[0] = 1;
581
582     relid[1] = 0;
583
584     if(ipre==1) 
585
586       relid[1] = -1;
587
588     relid[2] = ieta;
589
590     relid[3] = iphi;
591
592
593
594     return rv;
595
596 }
597
598 //______________________________________________________________________
599
600 void AliEMCALGeometry::PosInAlice(const Int_t *relid,Float_t &theta,
601
602                                      Float_t &phi) const {
603
604     // Converts the relative numbering into the local EMCAL-module (x, z)
605
606     // coordinates
607
608     Int_t ieta   = relid[2]; // offset along x axis
609
610     Int_t iphi = relid[3]; // offset along z axis
611
612     Int_t ipre = relid[1]; // indicates -1 preshower, or 0 full tower.
613
614     Int_t index;
615
616     Float_t eta;
617
618
619
620     if(ipre==-1) ipre = 1;
621
622     index = TowerIndex(ieta,iphi,ipre);
623
624     EtaPhiFromIndex(index,eta,phi);
625
626     theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
627
628
629
630     return;
631
632 }
633
634
635
636 //______________________________________________________________________
637
638 void AliEMCALGeometry::XYZFromIndex(const Int_t *relid,Float_t &x,Float_t &y, Float_t &z) const {
639
640     // given the tower relative number it returns the X, Y and Z
641
642     // of the tower.
643
644     
645
646     // Outputs:
647
648     //   Float_t x  // x of center of tower in cm
649
650     //   Float_t y  // y of center of tower in cm
651
652     //   Float_t z  // z of centre of tower in cm
653
654     // Returned
655
656     //   none.
657
658     
659
660     Float_t eta,theta, phi,cyl_radius,kDeg2Rad;
661
662     
663
664     Int_t ieta   = relid[2]; // offset along x axis
665
666     Int_t iphi = relid[3]; // offset along z axis
667
668     Int_t ipre = relid[1]; // indicates -1 preshower, or 0 full tower.
669
670     Int_t index;
671
672     
673
674
675
676     if(ipre==-1) ipre = 1;
677
678     index = TowerIndex(ieta,iphi,ipre);
679
680     EtaPhiFromIndex(index,eta,phi);
681
682     theta = 180.*(2.0*TMath::ATan(TMath::Exp(-eta)))/TMath::Pi();
683
684
685
686  
687
688     
689
690     kDeg2Rad = TMath::Pi() / static_cast<Double_t>(180) ; 
691
692     cyl_radius = GetIPDistance()+ GetAirGap() ;
693
694     x =  cyl_radius * TMath::Cos(phi * kDeg2Rad ) ;
695
696     y =  cyl_radius * TMath::Cos(phi * kDeg2Rad ) ; 
697
698     z =  cyl_radius / TMath::Tan(theta * kDeg2Rad ) ; 
699
700  
701
702  return;
703
704
705
706
707
708 //______________________________________________________________________
709
710 /*
711
712 Boot_t AliEMCALGeometry::AreNeighbours(Int_t index1,Int_t index2) const {
713
714     // Returns kTRUE if the two towers are neighbours or not, including
715
716     // diagonals. Both indexes are required to be either towers or preshower.
717
718     // Inputs:
719
720     //   Int_t index1  // index of tower 1
721
722     //   Int_t index2  // index of tower 2
723
724     // Outputs:
725
726     //   none.
727
728     // Returned
729
730     //   Boot_t kTRUE if the towers are neighbours otherwise false.
731
732     Boot_t anb = kFALSE;
733
734     Int_t ieta1 = 0, ieta2 = 0, iphi1 = 0, iphi2 = 0, ipre1 = 0, ipre2 = 0;
735
736
737
738     TowerIndexes(index1,ieta1,iphi1,ipre1);
739
740     TowerIndexes(index2,ieta2,iphi2,ipre2);
741
742     if(ipre1!=ipre2) return anb;
743
744     if((ieta1>=ieta2-1 && ieta1<=ieta2+1) && (iphi1>=iphi2-1 &&iphi1<=iphi2+1))
745
746                                                                  anb = kTRUE;
747
748     return anb;
749
750 }
751
752  */
753