Reversing previous commit (Gines)
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerGeometryBuilder.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 // Class AliMUONTriggerGeometryBuilder
19 // -----------------------------------
20 // MUON Trigger stations geometry construction class.
21 //
22 // Author: Philippe Crochette, LPC Clermont-Ferrand
23
24 #include <TVirtualMC.h>
25 #include <TGeoMatrix.h>
26
27 #include "AliMUONTriggerGeometryBuilder.h"
28 #include "AliMUON.h"
29 #include "AliMUONChamber.h"
30 #include "AliMUONChamberGeometry.h"
31 #include "AliMUONGeometryEnvelopeStore.h"
32
33 ClassImp(AliMUONTriggerGeometryBuilder)
34
35 //______________________________________________________________________________
36 AliMUONTriggerGeometryBuilder::AliMUONTriggerGeometryBuilder(AliMUON* muon)
37  : AliMUONVGeometryBuilder("trigger.dat",
38                            &muon->Chamber(10), &muon->Chamber(11),
39                            &muon->Chamber(12),&muon->Chamber(13)),
40    fMUON(muon)
41 {
42 // Standard constructor
43
44 }
45
46 //______________________________________________________________________________
47 AliMUONTriggerGeometryBuilder::AliMUONTriggerGeometryBuilder()
48  : AliMUONVGeometryBuilder(),
49    fMUON(0)
50 {
51 // Default constructor
52 }
53
54
55 //______________________________________________________________________________
56 AliMUONTriggerGeometryBuilder::AliMUONTriggerGeometryBuilder(const AliMUONTriggerGeometryBuilder& rhs)
57   : AliMUONVGeometryBuilder(rhs)
58 {
59 // Protected copy constructor
60
61   Fatal("Copy constructor", 
62         "Copy constructor is not implemented.");
63 }
64
65 //______________________________________________________________________________
66 AliMUONTriggerGeometryBuilder::~AliMUONTriggerGeometryBuilder() {
67 //
68 }
69
70 //______________________________________________________________________________
71 AliMUONTriggerGeometryBuilder& 
72 AliMUONTriggerGeometryBuilder::operator = (const AliMUONTriggerGeometryBuilder& rhs) 
73 {
74 // Protected assignement operator
75
76   // check assignement to self
77   if (this == &rhs) return *this;
78
79   Fatal("operator=", 
80         "Assignment operator is not implemented.");
81     
82   return *this;  
83 }
84
85 //
86 // public methods
87 //
88
89 //______________________________________________________________________________
90 void AliMUONTriggerGeometryBuilder::CreateGeometry()
91 {
92 // From AliMUONv1::CreateGeometry()
93
94     /* 
95        zpos1 and zpos2 are the middle of the first and second
96        planes of station 1 (+1m for second station):
97        zpos1=(zpos1m+zpos1p)/2=(15999+16071)/2=16035 mm, thick/2=40 mm
98        zpos2=(zpos2m+zpos2p)/2=(16169+16241)/2=16205 mm, thick/2=40 mm
99        zposxm and zposxp= middles of gaz gaps within a detection plane
100        rem: the total thickness accounts for 1 mm of al on both
101        side of the RPCs (see zpos1 and zpos2)
102     */
103     
104     Int_t *idtmed = fMUON->GetIdtmed()->GetArray()-1099;
105     Int_t idAir= idtmed[1100]; // medium 1
106     Int_t idAlu1=idtmed[1103]; // medium 4
107     Int_t detElemId=0;          // Detection Element Number    
108     Float_t tpar[3];
109     Double_t dpar[3];    
110     
111 // vertical gap between right and left chambers (kDXZERO*2=4cm)
112     const Float_t kDXZERO=2.; 
113 // main distances for chamber definition in first plane/first station
114     const Float_t kXMIN=34.;       
115     const Float_t kXMED=51.;                                
116     const Float_t kXMAX=255.; 
117 // 090704 kXMAX changed from 272 to 255.
118 // (see fig.2-4 & 2-5 of Local Trigger Board PRR)
119 // segmentation updated accordingly
120     const Float_t kYMIN=34.;                              
121     const Float_t kYMAX=51.;                              
122 // inner/outer radius of flange between beam shield. and chambers (1/station)
123     const Float_t kRMIN[2]={50.,50.};
124     const Float_t kRMAX[2]={64.,68.};
125 // z position of the middle of the gas gap in mother vol 
126     const Float_t kZm=-3.6;
127     const Float_t kZp=+3.6;     
128
129     AliMUONChamber *iChamber, *iChamber1;
130     iChamber1 = GetChamber(10);
131     Float_t zpos1=-iChamber1->Z(); 
132     
133 // ratio of zpos1m/zpos1p and inverse for first plane
134     Float_t zmp=(zpos1-3.6)/(zpos1+3.6);
135     Float_t zpm=1./zmp;
136     
137     Int_t icount=0;  // chamber counter (0 1 2 3)
138     
139     for (Int_t istation=0; istation<2; istation++) { // loop on stations
140         for (Int_t iplane=0; iplane<2; iplane++) { // loop on detection planes
141             
142             Int_t iVolNum=1; // counter Volume Number
143             icount = Int_t(iplane*TMath::Power(2,0))+
144                 Int_t(istation*TMath::Power(2,1));
145             
146             iChamber = GetChamber(10+icount);
147             Float_t zpos = - iChamber->Z();          
148             
149 // Flange between beam shielding and RPC 
150             tpar[0]= kRMIN[istation];
151             tpar[1]= kRMAX[istation];
152             tpar[2]= 4.0;           
153             char volFlange[5];
154             sprintf(volFlange,"SF%dA",icount+1);         
155             gMC->Gsvolu(volFlange,"TUBE",idAlu1,tpar,3);     // Al
156             // changed by ivana
157             //gMC->Gspos(volFlange,1,"ALIC",0.,0.,zpos,0,"MANY");
158             iChamber->GetGeometry()->GetEnvelopeStore()
159               ->AddEnvelope(volFlange, 0, false, "MANY");
160             
161 // scaling factor
162             Float_t zRatio = zpos / zpos1;
163             
164 // envelopes (same size except line 5, all virtual)
165             char volEnv[18][5];
166             tpar[1] = kYMIN * zRatio; 
167             tpar[2] = 0.4;
168             Int_t i=0;    // counter
169             for (Int_t icolumn=0; icolumn<2; icolumn++) {
170                 for (Int_t iline=1; iline<10; iline++){
171                     tpar[0] = (kXMAX/2.) * zRatio;
172                     if (iline==5) tpar[0] = ((kXMAX-kXMED)/2.)*zRatio;
173                     if (icolumn==0) 
174                         sprintf(volEnv[i],"S%dR%d",icount,iline);
175                     else
176                         sprintf(volEnv[i],"S%dL%d",icount,iline);
177                     gMC->Gsvolu(volEnv[i],"BOX",idAir,tpar,0); 
178                     i++;
179                 }
180             }
181
182 // chamber prototype
183             tpar[0]= 0.;
184             tpar[1]= 0.;
185             tpar[2]= 0.;            
186             char volAlu[5];     // Alu 
187             char volBak[5];     // Bakelite
188             char volGaz[5];     // Gas streamer     
189             sprintf(volAlu,"SC%dA",icount+1);
190             sprintf(volBak,"SB%dA",icount+1);
191             sprintf(volGaz,"SG%dA",icount+1);
192             gMC->Gsvolu(volAlu,"BOX",idAlu1,tpar,0);         // Al
193             gMC->Gsvolu(volBak,"BOX",idtmed[1107],tpar,0);   // Bakelite
194             gMC->Gsvolu(volGaz,"BOX",idtmed[1106],tpar,0);   // Gas streamer
195             tpar[0] = -1.;
196             tpar[1] = -1.;
197             tpar[2] = 0.1;    
198             gMC->Gsposp(volGaz,1,volBak,0.,0.,0.,0,"ONLY",tpar,3);
199             tpar[2] = 0.3;
200             gMC->Gsposp(volBak,1,volAlu,0.,0.,0.,0,"ONLY",tpar,3);
201
202 // chamber type A
203             Float_t xEnv = (kDXZERO+kXMED+(kXMAX-kXMED)/2.)*zRatio;
204             Float_t yEnvM = 0.;  // y low position of envelope in chamber
205             Float_t yEnvP = 0.;  // y up position of envelope in chamber
206             Float_t yEnvPsave = 0.; // tmp data
207             Float_t yEnvMsave = 0.; // tmp data
208             Float_t xpos = 0.; // x position of RPC in envelope     
209             Float_t ypos = 0.; // y position of RPC in envelope
210             dpar[2] = 0.4;          
211             dpar[0] = ((kXMAX-kXMED)/2.)*zRatio;
212             dpar[1] = kYMIN * zRatio;
213
214             detElemId = (10+icount+1)*100+4;
215             GetEnvelopes(10+icount)->AddEnvelope(volEnv[4], detElemId, true, TGeoTranslation(xEnv,yEnvM,kZm));
216             detElemId = (10+icount+1)*100+50+4;
217             GetEnvelopes(10+icount)->AddEnvelope(volEnv[13], detElemId, true, TGeoTranslation(-xEnv,yEnvP,kZp));
218
219             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[4],iVolNum++,3, dpar);
220             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[13],iVolNum++,3, dpar);      
221
222 // chamber type B (plus envelope chambers B & C)   
223             xEnv = (kDXZERO+kXMAX/2.)*zRatio;
224             yEnvPsave = yEnvP;
225             yEnvMsave = yEnvM;
226             yEnvP = (yEnvMsave + kYMIN * zRatio ) * zpm + kYMIN * zRatio;
227             yEnvM = (yEnvPsave + kYMIN * zRatio ) * zmp + kYMIN * zRatio;
228             dpar[0] = ((kXMAX-kXMIN)/2.) * zRatio;
229             dpar[1] = ((kYMAX-kYMIN)/2.) * zRatio;
230             xpos = kXMIN/2. * zRatio;
231             ypos = (kYMIN - kYMIN/4.) * zRatio;
232
233             detElemId = (10+icount+1)*100+3;
234             GetEnvelopes(10+icount)->AddEnvelope(volEnv[3], detElemId, true, TGeoTranslation( xEnv,-yEnvP,kZp));
235             detElemId = (10+icount+1)*100+5;
236             GetEnvelopes(10+icount)->AddEnvelope(volEnv[5], detElemId, true, TGeoTranslation( xEnv, yEnvP,kZp));
237             detElemId = (10+icount+1)*100+50+3;
238             GetEnvelopes(10+icount)->AddEnvelope(volEnv[12], detElemId, true, TGeoTranslation(-xEnv,-yEnvM,kZm));
239             detElemId = (10+icount+1)*100+50+5;
240             GetEnvelopes(10+icount)->AddEnvelope(volEnv[14], detElemId, true, TGeoTranslation(-xEnv, yEnvM,kZm));
241
242             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[3],iVolNum++,TGeoTranslation(xpos, ypos,0.),3,dpar);
243             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[5],iVolNum++,TGeoTranslation(xpos,-ypos,0.),3,dpar);
244             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[12],iVolNum++,TGeoTranslation(-xpos, ypos,0.),3,dpar);
245             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[14],iVolNum++,TGeoTranslation(-xpos,-ypos,0.),3,dpar);
246
247 // chamber type C (note: same Z than type B)
248             dpar[0] = (kXMAX/2)*zRatio;
249             dpar[1] = (kYMAX/2)*zRatio;
250             xpos = 0.;      
251             ypos = ((kYMAX - kYMIN)/2.) * zRatio;
252
253             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[3],iVolNum++,TGeoTranslation(xpos,-ypos,0.),3,dpar);
254             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[5],iVolNum++,TGeoTranslation(xpos, ypos,0.),3,dpar);
255             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[12],iVolNum++,TGeoTranslation(-xpos,-ypos,0.),3,dpar);
256             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[14],iVolNum++,TGeoTranslation(-xpos, ypos,0.),3,dpar);
257     
258 // chamber type D, E and F (same size)
259 // D        
260             yEnvPsave = yEnvP;
261             yEnvMsave = yEnvM;
262             yEnvP = (yEnvMsave + kYMIN * zRatio ) * zpm + kYMIN * zRatio;
263             yEnvM = (yEnvPsave + kYMIN * zRatio ) * zmp + kYMIN * zRatio;
264             dpar[0] = (kXMAX/2.)*zRatio;
265             dpar[1] =  kYMIN*zRatio;
266
267             detElemId = (10+icount+1)*100+2;
268             GetEnvelopes(10+icount)->AddEnvelope(volEnv[2], detElemId, true, TGeoTranslation(xEnv,-yEnvM,kZm));
269             detElemId = (10+icount+1)*100+6;
270             GetEnvelopes(10+icount)->AddEnvelope(volEnv[6], detElemId, true, TGeoTranslation(xEnv, yEnvM,kZm));
271             detElemId = (10+icount+1)*100+50+2;
272             GetEnvelopes(10+icount)->AddEnvelope(volEnv[11], detElemId, true, TGeoTranslation(-xEnv,-yEnvP,kZp));
273             detElemId = (10+icount+1)*100+50+6;
274             GetEnvelopes(10+icount)->AddEnvelope(volEnv[15], detElemId, true, TGeoTranslation(-xEnv, yEnvP,kZp));
275
276             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[2],iVolNum++,3, dpar);
277             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[6],iVolNum++,3, dpar);
278             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[11],iVolNum++,3, dpar);
279             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[15],iVolNum++,3, dpar);
280
281 // E
282             yEnvPsave = yEnvP;
283             yEnvMsave = yEnvM;
284             yEnvP = (yEnvMsave + kYMIN * zRatio ) * zpm + kYMIN * zRatio;
285             yEnvM = (yEnvPsave + kYMIN * zRatio ) * zmp + kYMIN * zRatio;
286
287             detElemId = (10+icount+1)*100+1;
288             GetEnvelopes(10+icount)->AddEnvelope(volEnv[1], detElemId, true, TGeoTranslation(xEnv,-yEnvP,kZp));
289             detElemId = (10+icount+1)*100+7;
290             GetEnvelopes(10+icount)->AddEnvelope(volEnv[7], detElemId, true, TGeoTranslation(xEnv, yEnvP,kZp));
291             detElemId = (10+icount+1)*100+50+1;
292             GetEnvelopes(10+icount)->AddEnvelope(volEnv[10], detElemId, true, TGeoTranslation(-xEnv,-yEnvM,kZm));
293             detElemId = (10+icount+1)*100+50+7;
294             GetEnvelopes(10+icount)->AddEnvelope(volEnv[16], detElemId, true, TGeoTranslation(-xEnv, yEnvM,kZm));
295
296             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[1],iVolNum++,3,dpar);
297             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[7],iVolNum++,3,dpar);
298             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[10],iVolNum++,3,dpar);
299             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[16],iVolNum++,3,dpar);
300
301
302 // F
303             yEnvPsave = yEnvP;
304             yEnvMsave = yEnvM;
305             yEnvP = (yEnvMsave + kYMIN * zRatio ) * zpm + kYMIN * zRatio;
306             yEnvM = (yEnvPsave + kYMIN * zRatio ) * zmp + kYMIN * zRatio;
307
308             detElemId = (10+icount+1)*100;
309             GetEnvelopes(10+icount)->AddEnvelope(volEnv[0], detElemId, true, TGeoTranslation(xEnv,-yEnvM,kZm));
310             detElemId = (10+icount+1)*100+8;
311             GetEnvelopes(10+icount)->AddEnvelope(volEnv[8], detElemId, true, TGeoTranslation(xEnv, yEnvM,kZm));
312             detElemId = (10+icount+1)*100+50;
313             GetEnvelopes(10+icount)->AddEnvelope(volEnv[9], detElemId, true, TGeoTranslation(-xEnv,-yEnvP,kZp));
314             detElemId = (10+icount+1)*100+50+8;
315             GetEnvelopes(10+icount)->AddEnvelope(volEnv[17], detElemId, true, TGeoTranslation(-xEnv, yEnvP,kZp));
316             
317             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[0],iVolNum++,3,dpar);
318             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[8],iVolNum++,3,dpar);
319             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[9],iVolNum++,3,dpar);
320             GetEnvelopes(10+icount)->AddEnvelopeConstituentParam(volAlu,volEnv[17],iVolNum++,3,dpar);
321
322         } // end loop on detection planes
323     } // end loop on stations    
324 }
325
326 //______________________________________________________________________________
327 void AliMUONTriggerGeometryBuilder::SetTransformations() 
328 {
329 // Defines the transformations for the trigger chambers.
330 // ---
331     Double_t zpos1, zpos2;    
332     AliMUONChamber *iChamber1, *iChamber2;
333
334     iChamber1 = GetChamber(10);
335     zpos1= - iChamber1->Z(); 
336     iChamber1->GetGeometry()
337         ->SetTranslation(TGeoTranslation(0., 0., zpos1));
338     
339     iChamber2 = GetChamber(11);
340     zpos2 = - iChamber2->Z(); 
341     iChamber2->GetGeometry()
342         ->SetTranslation(TGeoTranslation(0., 0., zpos2));
343
344     iChamber1 = GetChamber(12);
345     zpos1 = - iChamber1->Z(); 
346     iChamber1->GetGeometry()
347         ->SetTranslation(TGeoTranslation(0., 0., zpos1));
348     
349     iChamber2 = GetChamber(13);
350     zpos2 = - iChamber2->Z(); 
351     iChamber2->GetGeometry()
352         ->SetTranslation(TGeoTranslation(0., 0., zpos2));
353 }
354
355 //______________________________________________________________________________
356 void AliMUONTriggerGeometryBuilder::SetSensitiveVolumes()
357 {
358 // Defines the sensitive volumes for trigger station chambers.
359 // ---
360
361   GetChamber(10)->GetGeometry()->SetSensitiveVolume("SG1A");
362   GetChamber(11)->GetGeometry()->SetSensitiveVolume("SG2A");
363   GetChamber(12)->GetGeometry()->SetSensitiveVolume("SG3A");
364   GetChamber(13)->GetGeometry()->SetSensitiveVolume("SG4A");
365 }
366