]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryBuilder.cxx
Geometry construction functions separated from AliMUON, AliMUONv1into a new AliMUONGe...
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryBuilder.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *      SigmaEffect_thetadegrees                                                                  *
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 purpeateose. It is      *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 // $Id$
17 //
18 // Class AliMUONGeometryBuilder
19 // ----------------------------
20 // MUON manager class for geometry construction,
21 // separated form AliMUONv1
22 //
23 // Author: Ivana Hrivnacova, IPN Orsay
24
25 #include <TClonesArray.h>
26 #include <TGeoMatrix.h>
27 #include <TVirtualMC.h>
28
29 #include "AliMUONGeometryBuilder.h"
30 #include "AliMUON.h"
31 #include "AliMUONChamber.h"
32 #include "AliMUONConstants.h"
33 #include "AliMUONVGeometryBuilder.h"    
34 #include "AliMUONChamberGeometry.h"     
35 #include "AliMUONGeometryEnvelope.h"    
36 #include "AliMUONGeometryConstituent.h" 
37 #include "AliMagF.h"
38 #include "AliRun.h"
39
40 ClassImp(AliMUONGeometryBuilder)
41  
42 //______________________________________________________________________________//___________________________________________
43 AliMUONGeometryBuilder::AliMUONGeometryBuilder() 
44   : TObject(),
45     fMUON(0),
46     fGlobalTransformation(0),
47     fGeometryBuilders(0)
48 {
49 // Default constructor
50
51
52 //______________________________________________________________________________//___________________________________________
53 AliMUONGeometryBuilder::AliMUONGeometryBuilder(AliMUON* muon)
54   : TObject(),
55     fMUON(muon),
56     fGlobalTransformation(0), 
57     fGeometryBuilders(0)
58 {
59 // Standars constructor
60
61   // Define the global transformation:
62   // Transformation from the old ALICE coordinate system to a new one:
63   // x->-x, z->-z 
64   TGeoRotation* rotGlobal 
65     = new TGeoRotation("rotGlobal", 90., 180., 90., 90., 180., 0.);
66   fGlobalTransformation = new TGeoCombiTrans(0., 0., 0., rotGlobal);
67
68   fGeometryBuilders = new TObjArray(AliMUONConstants::NCh());
69 }
70
71 //______________________________________________________________________________
72 AliMUONGeometryBuilder::AliMUONGeometryBuilder(const AliMUONGeometryBuilder& right) 
73   : TObject(right) 
74 {  
75   // copy constructor (not implemented)
76
77   Fatal("AliMUONGeometryBuilder", "Copy constructor not provided.");
78 }
79
80 //______________________________________________________________________________
81 AliMUONGeometryBuilder::~AliMUONGeometryBuilder()
82 {
83 // Destructor
84
85   delete fGlobalTransformation;
86
87   if (fGeometryBuilders){
88     fGeometryBuilders->Delete();
89     delete fGeometryBuilders;
90   }
91 }
92
93 //______________________________________________________________________________
94 AliMUONGeometryBuilder& 
95 AliMUONGeometryBuilder::operator=(const AliMUONGeometryBuilder& right)
96 {
97   // assignement operator (not implemented)
98
99   // check assignement to self
100   if (this == &right) return *this;
101
102   Fatal("operator =", "Assignement operator not provided.");
103     
104   return *this;  
105 }    
106
107 //
108 // private functions
109 //
110
111 //______________________________________________________________________________
112 void AliMUONGeometryBuilder::PlaceVolume(const TString& name, const TString& mName, 
113                             Int_t copyNo, const TGeoHMatrix& matrix, 
114                             Int_t npar, Double_t* param, const char* only) const
115 {
116 // Place the volume specified by name with the given transformation matrix
117 // ---
118
119   // Do not apply global transformation 
120   // if mother volume == DDIP
121   // (as it is applied on this volume)
122   TGeoHMatrix transform(matrix);
123   if (mName == TString("DDIP")) {
124     transform = (*fGlobalTransformation) * transform;
125                // To be changed to (*fGlobalTransformation).inverse()
126                // when available in TGeo
127                // To make this correct also for a general case when
128                // (*fGlobalTransformation) * *fGlobalTransformation) != 1
129   }            
130      
131   // Decompose transformation
132   const Double_t* xyz = transform.GetTranslation();
133   const Double_t* rm = transform.GetRotationMatrix();
134         
135   //cout << "Got translation: "
136   //     << xyz[0] << " " << xyz[1] << " " << xyz[2] << endl;
137         
138   //cout << "Got rotation: "
139   //     << rm[0] << " " << rm[1] << " " << rm[2] << endl
140   //     << rm[3] << " " << rm[4] << " " << rm[5] << endl
141   //     << rm[6] << " " << rm[7] << " " << rm[8] << endl;
142
143   // Check for presence of rotation
144   // (will be nice to be available in TGeo)
145   const Double_t kTolerance = 1e-04;
146   Bool_t isRotation = true; 
147   if (TMath::Abs(rm[0] - 1.) < kTolerance &&
148       TMath::Abs(rm[1] - 0.) < kTolerance &&
149       TMath::Abs(rm[2] - 0.) < kTolerance &&
150       TMath::Abs(rm[3] - 0.) < kTolerance &&
151       TMath::Abs(rm[4] - 1.) < kTolerance &&
152       TMath::Abs(rm[5] - 0.) < kTolerance &&
153       TMath::Abs(rm[6] - 0.) < kTolerance &&
154       TMath::Abs(rm[7] - 0.) < kTolerance &&
155       TMath::Abs(rm[8] - 1.) < kTolerance) isRotation = false; 
156
157   Int_t krot = 0;
158   if (isRotation) {
159     TGeoRotation rot;
160     rot.SetMatrix(const_cast<Double_t*>(transform.GetRotationMatrix()));
161     Double_t theta1, phi1, theta2, phi2, theta3, phi3;
162     rot.GetAngles(theta1, phi1, theta2, phi2, theta3, phi3);
163         
164     //cout << "angles: " 
165     //     << theta1 << " " << phi1 << " "
166     //     << theta2 << " " << phi2 << " "
167     //     << theta3 << " " << phi3 << endl;
168         
169     fMUON->AliMatrix(krot, theta1, phi1, theta2, phi2, theta3, phi3);
170   }     
171         
172   // Place the volume in ALIC
173   if (npar == 0)
174     gMC->Gspos(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only);
175   else 
176     gMC->Gsposp(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only,
177                 param, npar);
178
179
180
181 //
182 // public functions
183 //
184
185 //______________________________________________________________________________
186 void AliMUONGeometryBuilder::CreateGeometry()
187 {
188 //
189 // Construct geometry using geometry builders.
190 //
191
192   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
193
194     // Get the builder
195     AliMUONVGeometryBuilder* builder
196       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
197
198     // Create geometry with each builder
199     if (builder) {
200       builder->CreateGeometry();
201       builder->SetTransformations();
202     }
203   }
204
205   for (Int_t j=0; j<AliMUONConstants::NCh(); j++) {
206
207     AliMUONChamberGeometry* geometry = fMUON->Chamber(j).GetGeometry();
208
209     if (!geometry) continue;
210           // Skip chambers with not defined geometry  
211           
212     // Loop over envelopes
213     const TObjArray* kEnvelopes = geometry->GetEnvelopes();
214     for (Int_t k=0; k<kEnvelopes->GetEntriesFast(); k++) {
215
216       // Get envelope
217       AliMUONGeometryEnvelope* env = (AliMUONGeometryEnvelope*)kEnvelopes->At(k);
218       const TGeoCombiTrans* kEnvTrans = env->GetTransformation();
219       const char* only = "ONLY";
220       if (env->IsMANY()) only = "MANY";
221
222       if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
223         // virtual envelope + nof constituents = 0 
224         //         => not allowed;
225         //            empty virtual envelope has no sense 
226         Fatal("CreateGeometry", "Virtual envelope must have constituents.");
227         return;
228       }
229
230       if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
231         // non virtual envelope + nof constituents > 0 
232         //        => not allowed;
233         //           use VMC to place constituents
234         Fatal("CreateGeometry", "Non virtual envelope cannot have constituents.");
235         return;
236       }
237
238       if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
239         // non virtual envelope + nof constituents = 0 
240         //        => place envelope in ALICE by composed transformation:
241         //           Tglobal * Tch * Tenv
242
243         // Compound chamber transformation with the envelope one
244         TGeoHMatrix total 
245           = (*fGlobalTransformation) * 
246             (*geometry->GetTransformation()) * 
247             (*kEnvTrans);
248         PlaceVolume(env->GetName(), geometry->GetMotherVolume(),
249                     env->GetCopyNo(), total, 0, 0, only);
250       }
251
252       if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
253         // virtual envelope + nof constituents > 0 
254         //         => do not place envelope and place constituents
255         //            in ALICE by composed transformation:
256         //            Tglobal * Tch * Tenv * Tconst   
257
258         for  (Int_t l=0; l<env->GetConstituents()->GetEntriesFast(); l++) {
259           AliMUONGeometryConstituent* constituent
260             = (AliMUONGeometryConstituent*)env->GetConstituents()->At(l);
261
262           // Compound chamber transformation with the envelope one + the constituent one
263           TGeoHMatrix total 
264             = (*fGlobalTransformation) *
265               (*geometry->GetTransformation()) * 
266               (*kEnvTrans) * 
267               (*constituent->GetTransformation());
268
269           PlaceVolume(constituent->GetName(), geometry->GetMotherVolume(),
270                       constituent->GetCopyNo(), total,
271                       constituent->GetNpar(), constituent->GetParam(), only);
272         }
273       }
274     } 
275   }
276 }
277
278 //_____________________________________________________________________________
279 void AliMUONGeometryBuilder::CreateMaterials()
280 {
281 // Definition of common materials
282 // --
283
284   //
285   //     Ar-CO2 gas (80%+20%)
286     Float_t ag1[3]   = { 39.95,12.01,16. };
287     Float_t zg1[3]   = { 18.,6.,8. };
288     Float_t wg1[3]   = { .8,.0667,.13333 };
289     Float_t dg1      = .001821;
290     //
291     //     Ar-buthane-freon gas -- trigger chambers 
292     Float_t atr1[4]  = { 39.95,12.01,1.01,19. };
293     Float_t ztr1[4]  = { 18.,6.,1.,9. };
294     Float_t wtr1[4]  = { .56,.1262857,.2857143,.028 };
295     Float_t dtr1     = .002599;
296     //
297     //     Ar-CO2 gas 
298     Float_t agas[3]  = { 39.95,12.01,16. };
299     Float_t zgas[3]  = { 18.,6.,8. };
300     Float_t wgas[3]  = { .74,.086684,.173316 };
301     Float_t dgas     = .0018327;
302     //
303     //     Ar-Isobutane gas (80%+20%) -- tracking 
304     Float_t ag[3]    = { 39.95,12.01,1.01 };
305     Float_t zg[3]    = { 18.,6.,1. };
306     Float_t wg[3]    = { .8,.057,.143 };
307     Float_t dg       = .0019596;
308     //
309     //     Ar-Isobutane-Forane-SF6 gas (49%+7%+40%+4%) -- trigger 
310     Float_t atrig[5] = { 39.95,12.01,1.01,19.,32.066 };
311     Float_t ztrig[5] = { 18.,6.,1.,9.,16. };
312     Float_t wtrig[5] = { .49,1.08,1.5,1.84,0.04 };
313     Float_t dtrig    = .0031463;
314     //
315     //     bakelite 
316
317     Float_t abak[3] = {12.01 , 1.01 , 16.};
318     Float_t zbak[3] = {6.     , 1.   , 8.};
319     Float_t wbak[3] = {6.     , 6.   , 1.}; 
320     Float_t dbak = 1.4;
321
322     Int_t iSXFLD   = gAlice->Field()->Integ();
323     Float_t sXMGMX = gAlice->Field()->Max();
324     //
325     // --- Define the various materials for GEANT --- 
326     fMUON->AliMaterial(9, "ALUMINIUM$", 26.98, 13., 2.7, 8.9, 37.2);
327     fMUON->AliMaterial(10, "ALUMINIUM$", 26.98, 13., 2.7, 8.9, 37.2);
328     // Air
329     Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
330     Float_t zAir[4]={6.,7.,8.,18.};
331     Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
332     Float_t dAir = 1.20479E-3;
333     fMUON->AliMixture(15, "AIR$      ", aAir,  zAir, dAir,4, wAir);
334     //    fMUON->AliMaterial(15, "AIR$      ", 14.61, 7.3, .001205, 30423.24, 67500);
335     fMUON->AliMixture(19, "Bakelite$", abak, zbak, dbak, -3, wbak);
336     fMUON->AliMixture(20, "ArC4H10 GAS$", ag, zg, dg, 3, wg);
337     fMUON->AliMixture(21, "TRIG GAS$", atrig, ztrig, dtrig, -5, wtrig);
338     fMUON->AliMixture(22, "ArCO2 80%$", ag1, zg1, dg1, 3, wg1);
339     fMUON->AliMixture(23, "Ar-freon $", atr1, ztr1, dtr1, 4, wtr1);
340     fMUON->AliMixture(24, "ArCO2 GAS$", agas, zgas, dgas, 3, wgas);
341     // materials for slat: 
342     //     Sensitive area: gas (already defined) 
343     //     PCB: copper 
344     //     insulating material and frame: vetronite
345     //     walls: carbon, rohacell, carbon 
346   Float_t aglass[5]={12.01, 28.09, 16.,   10.8,  23.};
347   Float_t zglass[5]={ 6.,   14.,    8.,    5.,   11.};
348   Float_t wglass[5]={ 0.5,  0.105, 0.355, 0.03,  0.01};
349   Float_t dglass=1.74;
350
351   // rohacell: C9 H13 N1 O2
352   Float_t arohac[4] = {12.01,  1.01, 14.010, 16.};
353   Float_t zrohac[4] = { 6.,    1.,    7.,     8.};
354   Float_t wrohac[4] = { 9.,   13.,    1.,     2.};
355   Float_t drohac    = 0.03;
356
357   fMUON->AliMaterial(31, "COPPER$",   63.54,    29.,   8.96,  1.4, 0.);
358   fMUON->AliMixture(32, "Vetronite$",aglass, zglass, dglass,    5, wglass);
359   fMUON->AliMaterial(33, "Carbon$",   12.01,     6.,  2.265, 18.8, 49.9);
360   fMUON->AliMixture(34, "Rohacell$", arohac, zrohac, drohac,   -4, wrohac); 
361
362    Float_t  epsil  = .001; // Tracking precision, 
363    Float_t  stemax = -1.;  // Maximum displacement for multiple scat 
364    Float_t  tmaxfd = -20.; // Maximum angle due to field deflection 
365    Float_t  deemax = -.3;  // Maximum fractional energy loss, DLS 
366    Float_t  stmin  = -.8;
367    Float_t  maxDestepAlu = fMUON->GetMaxDestepAlu();
368    Float_t  maxDestepGas = fMUON->GetMaxDestepGas();
369    Float_t  maxStepAlu = fMUON->GetMaxStepAlu();
370    Float_t  maxStepGas = fMUON->GetMaxStepGas();
371
372     //
373     //    Air 
374     fMUON->AliMedium(1, "AIR_CH_US         ", 15, 1, iSXFLD, sXMGMX, tmaxfd, stemax, deemax, epsil, stmin);
375     //
376     //    Aluminum 
377
378     fMUON->AliMedium(4, "ALU_CH_US          ", 9, 0, iSXFLD, sXMGMX, tmaxfd, maxStepAlu, 
379             maxDestepAlu, epsil, stmin);
380     fMUON->AliMedium(5, "ALU_CH_US          ", 10, 0, iSXFLD, sXMGMX, tmaxfd, maxStepAlu, 
381             maxDestepAlu, epsil, stmin);
382     //
383     //    Ar-isoC4H10 gas 
384
385     fMUON->AliMedium(6, "AR_CH_US          ", 20, 1, iSXFLD, sXMGMX, tmaxfd, maxStepGas, 
386             maxDestepGas, epsil, stmin);
387 //
388     //    Ar-Isobuthane-Forane-SF6 gas 
389
390     fMUON->AliMedium(7, "GAS_CH_TRIGGER    ", 21, 1, iSXFLD, sXMGMX, tmaxfd, stemax, deemax, epsil, stmin);
391
392     fMUON->AliMedium(8, "BAKE_CH_TRIGGER   ", 19, 0, iSXFLD, sXMGMX, tmaxfd, maxStepAlu, 
393             maxDestepAlu, epsil, stmin);
394
395     fMUON->AliMedium(9, "ARG_CO2   ", 22, 1, iSXFLD, sXMGMX, tmaxfd, maxStepGas, 
396             maxDestepAlu, epsil, stmin);
397     // tracking media for slats: check the parameters!! 
398     fMUON->AliMedium(11, "PCB_COPPER        ", 31, 0, iSXFLD, sXMGMX, tmaxfd, 
399               maxStepAlu, maxDestepAlu, epsil, stmin);
400     fMUON->AliMedium(12, "VETRONITE         ", 32, 0, iSXFLD, sXMGMX, tmaxfd, 
401               maxStepAlu, maxDestepAlu, epsil, stmin);
402     fMUON->AliMedium(13, "CARBON            ", 33, 0, iSXFLD, sXMGMX, tmaxfd, 
403               maxStepAlu, maxDestepAlu, epsil, stmin);
404     fMUON->AliMedium(14, "Rohacell          ", 34, 0, iSXFLD, sXMGMX, tmaxfd, 
405               maxStepAlu, maxDestepAlu, epsil, stmin);
406
407
408
409   //.Materials specific to stations
410   // created via builders
411   
412   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
413
414     // Get the builder
415     AliMUONVGeometryBuilder* builder
416       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
417
418     // Create materials with each builder
419     if (builder) builder->CreateMaterials();
420   }
421 }
422
423 //______________________________________________________________________________
424 void AliMUONGeometryBuilder::InitGeometry()
425 {
426  // Initialize geometry
427  // ---
428
429   //
430   // Set the chamber (sensitive region) GEANT identifier
431   //
432   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
433
434     // Get the builder
435     AliMUONVGeometryBuilder* builder
436       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
437
438     // Set sesitive volumes with each builder
439     if (builder) builder->SetSensitiveVolumes();
440   }
441 }
442
443 //_____________________________________________________________________________
444 void AliMUONGeometryBuilder::AddBuilder(AliMUONVGeometryBuilder* geomBuilder)
445 {
446 // Adds the geometry builder to the list
447 // ---
448
449   fGeometryBuilders->Add(geomBuilder);
450 }
451