]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDgeometry.cxx
Removing old segmentation, obsolete classes and removing old new conditions (Christian)
[u/mrichter/AliRoot.git] / TRD / AliTRDgeometry.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 //                                                                           //
20 //  TRD geometry class                                                       //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24
25 #include <TError.h>
26
27 #include "AliRunLoader.h"
28 #include "AliTRDgeometry.h"
29 #include "AliTRDparameter.h"
30 #include "AliTRDpadPlane.h"
31
32 #include "AliRun.h"
33 #include "AliTRD.h"
34
35 ClassImp(AliTRDgeometry)
36
37 //_____________________________________________________________________________
38
39   //
40   // The geometry constants
41   //
42   const Int_t   AliTRDgeometry::fgkNsect   = kNsect;
43   const Int_t   AliTRDgeometry::fgkNplan   = kNplan;
44   const Int_t   AliTRDgeometry::fgkNcham   = kNcham;
45   const Int_t   AliTRDgeometry::fgkNdet    = kNdet;
46
47   //
48   // Dimensions of the detector
49   //
50
51   // Inner and outer radius of the mother volumes 
52   const Float_t AliTRDgeometry::fgkRmin    = 294.0;
53   const Float_t AliTRDgeometry::fgkRmax    = 368.0;
54
55   // Upper and lower length of the mother volumes 
56   const Float_t AliTRDgeometry::fgkZmax1   = 378.35; 
57   const Float_t AliTRDgeometry::fgkZmax2   = 302.0; 
58
59   // Parameter of the BTR mother volumes 
60   const Float_t AliTRDgeometry::fgkSheight =  74.0; 
61   const Float_t AliTRDgeometry::fgkSwidth1 =  99.613;
62   const Float_t AliTRDgeometry::fgkSwidth2 = 125.707;
63   const Float_t AliTRDgeometry::fgkSlenTR1 = 751.0;
64   const Float_t AliTRDgeometry::fgkSlenTR2 = 313.5; 
65   const Float_t AliTRDgeometry::fgkSlenTR3 = 159.5;  
66
67   // The super module side plates
68   const Float_t AliTRDgeometry::fgkSMpltT  =   0.2;
69   const Float_t AliTRDgeometry::fgkSMgapT  =   0.5;  
70
71   // Height of different chamber parts
72   // Radiator
73   const Float_t AliTRDgeometry::fgkCraH    =   4.8; 
74   // Drift region
75   const Float_t AliTRDgeometry::fgkCdrH    =   3.0;
76   // Amplification region
77   const Float_t AliTRDgeometry::fgkCamH    =   0.7;
78   // Readout
79   const Float_t AliTRDgeometry::fgkCroH    =   2.316;
80   // Total height
81   const Float_t AliTRDgeometry::fgkCH      = AliTRDgeometry::fgkCraH
82                                            + AliTRDgeometry::fgkCdrH
83                                            + AliTRDgeometry::fgkCamH
84                                            + AliTRDgeometry::fgkCroH;  
85
86   // Vertical spacing of the chambers
87   const Float_t AliTRDgeometry::fgkVspace  =   1.784;
88
89   // Horizontal spacing of the chambers
90   const Float_t AliTRDgeometry::fgkHspace  =   2.0;
91
92   // Thicknesses of different parts of the chamber frame
93   // Lower aluminum frame
94   const Float_t AliTRDgeometry::fgkCalT    =   0.3;
95   // Lower G10 frame sides
96   const Float_t AliTRDgeometry::fgkCclsT   =   0.3;
97   // Lower G10 frame front
98   const Float_t AliTRDgeometry::fgkCclfT   =   1.0;
99   // Upper G10 frame
100   const Float_t AliTRDgeometry::fgkCcuT    =   0.9;
101   // Upper Al frame
102   const Float_t AliTRDgeometry::fgkCauT    =   1.5;
103
104   // Additional width of the readout chamber frames
105   const Float_t AliTRDgeometry::fgkCroW    =   0.9;
106
107   // Difference of outer chamber width and pad plane width
108   //const Float_t AliTRDgeometry::fgkCpadW   =   1.0;
109   const Float_t AliTRDgeometry::fgkCpadW   =   0.0;
110   const Float_t AliTRDgeometry::fgkRpadW   =   1.0;
111
112   //
113   // Thickness of the the material layers
114   //
115   const Float_t AliTRDgeometry::fgkRaThick = 0.3646;  
116   const Float_t AliTRDgeometry::fgkMyThick = 0.005;
117   const Float_t AliTRDgeometry::fgkDrThick = AliTRDgeometry::fgkCdrH;    
118   const Float_t AliTRDgeometry::fgkAmThick = AliTRDgeometry::fgkCamH;
119   const Float_t AliTRDgeometry::fgkXeThick = AliTRDgeometry::fgkDrThick
120                                            + AliTRDgeometry::fgkAmThick;
121   const Float_t AliTRDgeometry::fgkCuThick = 0.001; 
122   const Float_t AliTRDgeometry::fgkSuThick = 0.06; 
123   const Float_t AliTRDgeometry::fgkFeThick = 0.0044; 
124   const Float_t AliTRDgeometry::fgkCoThick = 0.02;
125   const Float_t AliTRDgeometry::fgkWaThick = 0.02;
126
127   //
128   // Position of the material layers
129   //
130   const Float_t AliTRDgeometry::fgkRaZpos  = -1.50;
131   const Float_t AliTRDgeometry::fgkMyZpos  =  0.895;
132   const Float_t AliTRDgeometry::fgkDrZpos  =  2.4;
133   const Float_t AliTRDgeometry::fgkAmZpos  =  0.0;
134   const Float_t AliTRDgeometry::fgkCuZpos  = -0.9995;
135   const Float_t AliTRDgeometry::fgkSuZpos  =  0.0000;
136   const Float_t AliTRDgeometry::fgkFeZpos  =  0.0322;
137   const Float_t AliTRDgeometry::fgkCoZpos  =  0.97;
138   const Float_t AliTRDgeometry::fgkWaZpos  =  0.99;
139
140 //_____________________________________________________________________________
141 AliTRDgeometry::AliTRDgeometry():AliGeometry()
142 {
143   //
144   // AliTRDgeometry default constructor
145   //
146
147   Init();
148
149 }
150
151 //_____________________________________________________________________________
152 AliTRDgeometry::~AliTRDgeometry()
153 {
154   //
155   // AliTRDgeometry destructor
156   //
157
158 }
159
160 //_____________________________________________________________________________
161 void AliTRDgeometry::Init()
162 {
163   //
164   // Initializes the geometry parameter
165   //
166   // The maximum number of pads
167   // and the position of pad 0,0,0 
168   // 
169   // chambers seen from the top:
170   //     +----------------------------+
171   //     |                            |
172   //     |                            |      ^
173   //     |                            |  rphi|
174   //     |                            |      |
175   //     |0                           |      | 
176   //     +----------------------------+      +------>
177   //                                             z 
178   // chambers seen from the side:            ^
179   //     +----------------------------+ drift|
180   //     |0                           |      |
181   //     |                            |      |
182   //     +----------------------------+      +------>
183   //                                             z
184   //                                             
185   // IMPORTANT: time bin 0 is now the first one in the drift region 
186   // closest to the readout !!!
187   //
188
189   Int_t icham;
190   Int_t iplan;
191   Int_t isect;
192
193   // The outer width of the chambers
194   //
195   // Changed with the introduction of 
196   // the new layer 0. The old layer 6
197   // is removed.
198   fCwidth[0] =  90.4;
199   fCwidth[1] =  94.8;
200   fCwidth[2] =  99.3;
201   fCwidth[3] = 103.7;
202   fCwidth[4] = 108.1;
203   fCwidth[5] = 112.6;
204   // Old layer 6
205   // fCwidth[5] = 117.0;
206
207   // The outer lengths of the chambers
208   // Includes the spacings between the chambers!
209   // Changed with the introduction of 
210   // the new layer 0. The old layer 6
211   // is removed.
212   Float_t length[kNplan][kNcham]   = { { 124.0, 124.0, 110.0, 124.0, 124.0 }
213                                      , { 124.0, 124.0, 110.0, 124.0, 124.0 }
214                                      , { 131.0, 131.0, 110.0, 131.0, 131.0 }
215                                      , { 138.0, 138.0, 110.0, 138.0, 138.0 }
216                                      , { 145.0, 145.0, 110.0, 145.0, 145.0 }
217                                      , { 147.0, 147.0, 110.0, 147.0, 147.0 } };
218   // Old layer 6
219   //                                 , { 147.0, 147.0, 110.0, 147.0, 147.0 } };
220
221   for (icham = 0; icham < kNcham; icham++) {
222     for (iplan = 0; iplan < kNplan; iplan++) {
223       fClength[iplan][icham]   = length[iplan][icham];
224       fClengthPH[iplan][icham] = 0.0;
225       fClengthRH[iplan][icham] = 0.0;
226     }
227   }
228
229   // The rotation matrix elements
230   Float_t phi = 0;
231   for (isect = 0; isect < fgkNsect; isect++) {
232     phi = -2.0 * TMath::Pi() /  (Float_t) fgkNsect * ((Float_t) isect + 0.5);
233     fRotA11[isect] = TMath::Cos(phi);
234     fRotA12[isect] = TMath::Sin(phi);
235     fRotA21[isect] = TMath::Sin(phi);
236     fRotA22[isect] = TMath::Cos(phi);
237     phi = -1.0 * phi;
238     fRotB11[isect] = TMath::Cos(phi);
239     fRotB12[isect] = TMath::Sin(phi);
240     fRotB21[isect] = TMath::Sin(phi);
241     fRotB22[isect] = TMath::Cos(phi);
242   }
243  
244 }
245
246 //_____________________________________________________________________________
247 void AliTRDgeometry::CreateGeometry(Int_t* )
248 {
249   //
250   // Create TRD geometry
251   //
252
253 }
254
255 //_____________________________________________________________________________
256 Bool_t AliTRDgeometry::Local2Global(Int_t idet, Double_t *local
257                                    , Double_t *global
258                                    , AliTRDparameter *par) const
259 {
260   //
261   // Converts local pad-coordinates (row,col,time) into 
262   // global ALICE reference frame coordinates (x,y,z)
263   //
264
265   Int_t icham = GetChamber(idet);    // Chamber info (0-4)
266   Int_t isect = GetSector(idet);     // Sector info  (0-17)
267   Int_t iplan = GetPlane(idet);      // Plane info   (0-5)
268
269   return Local2Global(iplan,icham,isect,local,global,par);
270
271 }
272  
273 //_____________________________________________________________________________
274 Bool_t AliTRDgeometry::Local2Global(Int_t iplan, Int_t icham, Int_t isect
275                                   , Double_t *local, Double_t *global
276                                   , AliTRDparameter *par) const
277 {
278   //
279   // Converts local pad-coordinates (row,col,time) into 
280   // global ALICE reference frame coordinates (x,y,z)
281   //
282
283   if (!par) {
284     Error("Local2Global","No parameter defined\n");
285     return kFALSE;
286   }
287
288   AliTRDpadPlane *padPlane = par->GetPadPlane(iplan,icham);
289
290   // calculate (x,y,z) position in rotated chamber
291   Int_t    row       = ((Int_t) local[0]);
292   Int_t    col       = ((Int_t) local[1]);
293   Float_t  timeSlice = local[2] + 0.5;
294   Float_t  time0     = par->GetTime0(iplan);
295
296   Double_t  rot[3];
297   rot[0] = time0 - (timeSlice - par->GetTimeBefore()) 
298          * par->GetDriftVelocity()/par->GetSamplingFrequency();
299   rot[1] = padPlane->GetColPos(col) - 0.5 * padPlane->GetColSize(col);
300   rot[2] = padPlane->GetRowPos(row) - 0.5 * padPlane->GetRowSize(row);
301
302   // Rotate back to original position
303   Int_t idet = GetDetector(iplan,icham,isect); 
304   return RotateBack(idet,rot,global);
305
306 }
307
308 //_____________________________________________________________________________
309 Bool_t AliTRDgeometry::Global2Local(Int_t mode, Double_t *local, Double_t *global
310                                    , Int_t* index,  AliTRDparameter *par) const
311 {
312   //
313   // Converts local pad-coordinates (row,col,time) into 
314   // global ALICE reference frame coordinates (x,y,z)
315   //
316   // index[0] = plane number
317   // index[1] = chamber number
318   // index[2] = sector number
319   //
320   // mode=0  - local coordinate in y, z,             x - rotated global   
321   // mode=2  - local coordinate in pad, and pad row, x - rotated global
322   //
323
324   if (!par) {
325     Error("Local2Global","No parameter defined\n");
326     return kFALSE;
327   }
328   
329   //Int_t    idet    = GetDetector(iplan,icham,isect); // Detector number
330   Int_t    idet      = GetDetector(index[0],index[1],index[2]); // Detector number
331   Rotate(idet,global,local);
332   if (mode==0) return kTRUE;
333   //
334   //  Float_t  row0      = par->GetRow0(iplan,icham,isect);
335   //Float_t  col0      = par->GetCol0(iplan);
336   //Float_t  time0     = par->GetTime0(iplan);
337   //
338   // mode 1 to be implemented later
339   // calculate (x,y,z) position in time bin pad row pad
340   //
341   //rot[0] = time0 - (timeSlice - par->GetTimeBefore()) 
342   //       * par->GetDriftVelocity()/par->GetSamplingFrequency();
343   //rot[1] = col0  + padCol                    
344   //       * par->GetColPadSize(iplan);
345   //rot[2] = row0  + padRow                    
346   //       * par->GetRowPadSize(iplan,icham,isect);
347
348   return kTRUE;
349
350 }
351
352 //_____________________________________________________________________________
353 Bool_t AliTRDgeometry::Global2Detector(Double_t global[3], Int_t index[3]
354                                       , AliTRDparameter *par)
355 {
356   //  
357   // input    = global position
358   // output   = index
359   // index[0] = plane number
360   // index[1] = chamber number
361   // index[2] = sector number
362   //
363
364   Float_t fi;
365   //
366   fi = TMath::ATan2(global[1],global[0]);
367   if (fi<0) fi += 2*TMath::Pi();
368   index[2] = Int_t(TMath::Nint((fi - GetAlpha()/2.)/GetAlpha()));
369   //
370   //
371   Float_t locx = global[0] * fRotA11[index[2]] + global[1] * fRotA12[index[2]];  
372   index[0] = 0;
373   Float_t max = locx-par->GetTime0(0);
374   for (Int_t iplane=1; iplane<fgkNplan;iplane++){
375     Float_t dist = TMath::Abs(locx-par->GetTime0(iplane));
376     if (dist < max){
377       index[0] = iplane;
378       max = dist;
379     }
380   }
381   Float_t theta = TMath::ATan2(global[2],locx);
382   index[1] = TMath::Nint(float(fgkNcham)*theta/(0.25*TMath::Pi()));
383   return kTRUE;
384
385 }
386
387
388 //_____________________________________________________________________________
389 Bool_t AliTRDgeometry::Rotate(Int_t d, Double_t *pos, Double_t *rot) const
390 {
391   //
392   // Rotates all chambers in the position of sector 0 and transforms
393   // the coordinates in the ALICE restframe <pos> into the 
394   // corresponding local frame <rot>.
395   //
396
397   Int_t sector = GetSector(d);
398
399   rot[0] =  pos[0] * fRotA11[sector] + pos[1] * fRotA12[sector];
400   rot[1] = -pos[0] * fRotA21[sector] + pos[1] * fRotA22[sector];
401   rot[2] =  pos[2];
402
403   return kTRUE;
404
405 }
406
407 //_____________________________________________________________________________
408 Bool_t AliTRDgeometry::RotateBack(Int_t d, Double_t *rot, Double_t *pos) const
409 {
410   //
411   // Rotates a chambers from the position of sector 0 into its
412   // original position and transforms the corresponding local frame 
413   // coordinates <rot> into the coordinates of the ALICE restframe <pos>.
414   //
415
416   Int_t sector = GetSector(d);
417
418   pos[0] =  rot[0] * fRotB11[sector] + rot[1] * fRotB12[sector];
419   pos[1] = -rot[0] * fRotB21[sector] + rot[1] * fRotB22[sector];
420   pos[2] =  rot[2];
421
422   return kTRUE;
423
424 }
425
426 //_____________________________________________________________________________
427 Int_t AliTRDgeometry::GetDetectorSec(Int_t p, Int_t c) const
428 {
429   //
430   // Convert plane / chamber into detector number for one single sector
431   //
432
433   return (p + c * fgkNplan);
434
435 }
436
437 //_____________________________________________________________________________
438 Int_t AliTRDgeometry::GetDetector(Int_t p, Int_t c, Int_t s) const
439 {
440   //
441   // Convert plane / chamber / sector into detector number
442   //
443
444   return (p + c * fgkNplan + s * fgkNplan * fgkNcham);
445
446 }
447
448 //_____________________________________________________________________________
449 Int_t AliTRDgeometry::GetPlane(Int_t d) const
450 {
451   //
452   // Reconstruct the plane number from the detector number
453   //
454
455   return ((Int_t) (d % fgkNplan));
456
457 }
458
459 //_____________________________________________________________________________
460 Int_t AliTRDgeometry::GetChamber(Int_t d) const
461 {
462   //
463   // Reconstruct the chamber number from the detector number
464   //
465
466   return ((Int_t) (d % (fgkNplan * fgkNcham)) / fgkNplan);
467
468 }
469
470 //_____________________________________________________________________________
471 Int_t AliTRDgeometry::GetSector(Int_t d) const
472 {
473   //
474   // Reconstruct the sector number from the detector number
475   //
476
477   return ((Int_t) (d / (fgkNplan * fgkNcham)));
478
479 }
480
481 //_____________________________________________________________________________
482 AliTRDgeometry* AliTRDgeometry::GetGeometry(AliRunLoader* runLoader)
483 {
484   //
485   // load the geometry from the galice file
486   //
487
488   if (!runLoader) runLoader = AliRunLoader::GetRunLoader();
489   if (!runLoader) {
490     ::Error("AliTRDgeometry::GetGeometry", "No run loader");
491     return NULL;
492   }
493
494   TDirectory* saveDir = gDirectory;
495   runLoader->CdGAFile();
496
497   // Try from the galice.root file
498   AliTRDgeometry* geom = (AliTRDgeometry*) gDirectory->Get("TRDgeometry");
499
500   if (!geom) {
501     // It is not in the file, try to get it from gAlice, 
502     // which corresponds to the run loader 
503     AliTRD * trd = (AliTRD*)runLoader->GetAliRun()->GetDetector("TRD");
504     geom = trd->GetGeometry();
505   }
506   if (!geom) ::Error("AliTRDgeometry::GetGeometry", "Geometry not found");
507
508   saveDir->cd();
509   return geom;
510 }