]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryModule.cxx
Adding MUON HLT code to the repository.
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryModule.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 AliMUONGeometryModule
19 // -----------------------------
20 // Class for definition of the detector module parameters
21 // (the transformations of detection elements, mapping between
22 //  sensitive volumes and detection elements).
23 //
24 // Author: Ivana Hrivnacova, IPN Orsay
25
26 #include <TVirtualMC.h>
27 #include <TGeoMatrix.h>
28 #include <TObjArray.h>
29 #include <TArrayI.h>
30 #include <Riostream.h>
31
32 #include "AliLog.h"     
33
34 #include "AliMUONGeometryModule.h"
35 #include "AliMUONGeometryEnvelope.h"
36 #include "AliMUONGeometryEnvelopeStore.h"
37 #include "AliMUONGeometryDetElement.h"  
38 #include "AliMUONGeometryStore.h"       
39 #include "AliMUONGeometrySVMap.h"       
40 #include "AliMUONGeometryDEIndexing.h"
41
42 ClassImp(AliMUONGeometryModule)
43
44 //______________________________________________________________________________
45 AliMUONGeometryModule::AliMUONGeometryModule(Int_t moduleId)
46  : TObject(),
47    fIsVirtual(true),
48    fModuleId(moduleId),
49    fMotherVolume("ALIC"),
50    fVolume("NONE"),
51    fNofSVs(0),
52    fSVVolumeIds(0),
53    fTransformation(0),
54    fEnvelopes(0),
55    fDEIndexing(0),
56    fDetElements(0),
57    fSVMap(0)
58 {
59 // Standard constructor
60
61   // Chamber transformation
62   fTransformation = new TGeoCombiTrans("");
63
64   // Arrays of volumes Ids
65   fSVVolumeIds = new TArrayI(20);
66
67   // Sensitive volumes map
68   fSVMap = new AliMUONGeometrySVMap(100);
69
70   // Get indexing
71   fDEIndexing = new AliMUONGeometryDEIndexing(fModuleId, 0);
72
73   // Det elements transformation stores
74   fDetElements = new AliMUONGeometryStore(fDEIndexing);
75     
76   // Envelope store
77   fEnvelopes = new AliMUONGeometryEnvelopeStore(fDetElements);  
78 }
79
80
81 //______________________________________________________________________________
82 AliMUONGeometryModule::AliMUONGeometryModule()
83  : TObject(),
84    fIsVirtual(true),
85    fModuleId(0),
86    fMotherVolume(),
87    fVolume(),
88    fNofSVs(0),
89    fSVVolumeIds(0),
90    fTransformation(0),
91    fEnvelopes(0),
92    fDEIndexing(0),
93    fDetElements(0),
94    fSVMap(0)
95 {
96 // Default constructor
97 }
98
99
100 //______________________________________________________________________________
101 AliMUONGeometryModule::AliMUONGeometryModule(const AliMUONGeometryModule& rhs)
102   : TObject(rhs)
103 {
104   AliFatal("Copy constructor is not implemented.");
105 }
106
107 //______________________________________________________________________________
108 AliMUONGeometryModule::~AliMUONGeometryModule() {
109 //
110
111   delete fTransformation;
112   delete fSVVolumeIds;
113   delete fEnvelopes;
114   delete fDEIndexing;
115   delete fDetElements;
116   delete fSVMap;
117 }
118
119 //______________________________________________________________________________
120 AliMUONGeometryModule& 
121 AliMUONGeometryModule::operator = (const AliMUONGeometryModule& rhs) 
122 {
123   // check assignement to self
124   if (this == &rhs) return *this;
125
126   AliFatal("Assignment operator is not implemented.");
127     
128   return *this;  
129 }
130
131 //
132 // private methods
133 //
134
135 //______________________________________________________________________________
136 Int_t AliMUONGeometryModule::GetSVIndex(Int_t svVolId) const
137 {
138 // Returns the index of the volume specified by volId
139 // if it is present in the list of sensitive volumes 
140 // (or -1 if not present).
141  
142   for (Int_t i=0; i<fNofSVs; i++) {
143       if (fSVVolumeIds->At(i) == svVolId) return i;
144   }
145   return -1;
146 }
147
148 //
149 // public methods
150 //
151
152 //______________________________________________________________________________
153 void  AliMUONGeometryModule::Global2Local(Int_t detElemId,
154                                   Float_t xg, Float_t yg, Float_t zg, 
155                                   Float_t& xl, Float_t& yl, Float_t& zl) const
156 {
157 // Transforms point from the global reference frame (ALIC)
158 // to the local reference frame of the detection element specified
159 // by detElemId.
160 // ---
161
162   // Get detection element
163   AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
164   if (!detElement) return;
165    
166   // Transform point
167   detElement->Global2Local(xg, yg, zg, xl, yl, zl);
168 }
169                                   
170 //______________________________________________________________________________
171 void  AliMUONGeometryModule::Global2Local(Int_t detElemId,
172                                   Double_t xg, Double_t yg, Double_t zg, 
173                                   Double_t& xl, Double_t& yl, Double_t& zl) const
174 {
175 // Transforms point from the global reference frame (ALIC)
176 // to the local reference frame of the detection element specified
177 // by detElemId.
178 // ---
179
180    // Get detection element
181    AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
182    if (!detElement) return;
183    
184    // Transform point
185    detElement->Global2Local(xg, yg, zg, xl, yl, zl);
186 }
187                                   
188 //______________________________________________________________________________
189 void  AliMUONGeometryModule::Local2Global(Int_t detElemId,
190                  Float_t xl, Float_t yl, Float_t zl, 
191                  Float_t& xg, Float_t& yg, Float_t& zg) const
192 {
193 // Transforms point from the local reference frame of the detection element 
194 // specified by detElemId to the global reference frame (ALIC).
195 // ---
196
197   // Get detection element
198   AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
199   if (!detElement) return;
200    
201    // Transform point
202   detElement->Local2Global(xl, yl, zl, xg, yg, zg);  
203 }
204
205 //______________________________________________________________________________
206 void  AliMUONGeometryModule::Local2Global(Int_t detElemId,
207                  Double_t xl, Double_t yl, Double_t zl, 
208                  Double_t& xg, Double_t& yg, Double_t& zg) const
209 {
210 // Transforms point from the local reference frame of the detection element 
211 // specified by detElemId to the global reference frame (ALIC).
212 // ---
213
214    // Get detection element
215    AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
216    if (!detElement) return;
217    
218    // Transform point
219    detElement->Local2Global(xl, yl, zl, xg, yg, zg); 
220 }
221
222 //______________________________________________________________________________
223 void AliMUONGeometryModule::SetVolume(const TString& volumeName)
224
225 // Sets the concrete volume associated with this module.
226 // The module in not virtual in this case
227
228   fVolume = volumeName;
229   fIsVirtual = false;
230 }
231
232 //______________________________________________________________________________
233 void  AliMUONGeometryModule::SetTranslation(const TGeoTranslation& translation)
234 {
235 // Sets the module position wrt world.
236 // ---
237
238   fTransformation
239     ->SetTranslation(const_cast<Double_t*>(translation.GetTranslation()));
240 }  
241
242 //______________________________________________________________________________
243 void  AliMUONGeometryModule::SetRotation(const TGeoRotation& rotation)
244 {
245 // Sets the module rotation wrt ALIC.
246 // ---
247
248   TGeoRotation* rot = new TGeoRotation();
249   rot->SetMatrix(const_cast<Double_t*>(rotation.GetRotationMatrix()));
250
251   fTransformation->SetRotation(rot);
252 }  
253
254 //______________________________________________________________________________
255 void  AliMUONGeometryModule::SetSensitiveVolume(Int_t svVolId)
256 {
257 // Adds the volume specified by volId to the list of sensitive
258 // volumes
259 // ---
260   
261   // Resize TArrayI if needed
262   if (fSVVolumeIds->GetSize() == fNofSVs) fSVVolumeIds->Set(2*fNofSVs);
263
264   fSVVolumeIds->AddAt(svVolId, fNofSVs++);
265 }      
266
267 //______________________________________________________________________________
268 void  AliMUONGeometryModule::SetSensitiveVolume(const TString& volName)
269 {
270 // Adds the volume specified by volName to the list of sensitive
271 // volumes
272 // ---
273
274   SetSensitiveVolume(gMC->VolId(volName));
275 }      
276
277 //______________________________________________________________________________
278 void  AliMUONGeometryModule::SetAlign(Bool_t align)
279 {
280 // Sets alignement option to enevelope store.
281 // ---
282   
283   fEnvelopes->SetAlign(align);
284 }  
285
286 //______________________________________________________________________________
287 AliMUONGeometryDetElement* 
288 AliMUONGeometryModule::FindBySensitiveVolume(const TString& sensVolume) const
289 {
290 // Finds TGeoCombiTrans for the detector element Id specified by aligned volume 
291 // ---
292
293   Int_t detElemId = fSVMap->GetDetElemId(sensVolume);
294
295   if (!detElemId) return 0; 
296         // The specified sensitive volume is not in the map   
297   
298   return (AliMUONGeometryDetElement*)fDetElements->Get(detElemId);
299 }  
300
301 //______________________________________________________________________________
302 Bool_t AliMUONGeometryModule::IsSensitiveVolume(Int_t volId) const
303 {
304 // Checks if the volume specified by volId is present in the list
305 // of sensitive volumes.
306 // ---
307
308   for (Int_t i=0; i<fNofSVs; i++) {
309       if (fSVVolumeIds->At(i) == volId) return kTRUE;
310   }
311   return kFALSE;
312 }
313
314 //______________________________________________________________________________
315 Bool_t AliMUONGeometryModule::IsSensitiveVolume(const TString& volName) const
316 {
317 // Checks if the volume specified by volName  is present in the list
318 // of sensitive volumes.
319 // ---
320
321   return IsSensitiveVolume(gMC->VolId(volName));
322 }
323
324 //______________________________________________________________________________
325 AliMUONGeometryDetElement*
326 AliMUONGeometryModule::GetDetElement(Int_t detElemId) const
327 {
328 // Returns thethe detection element specified by detElemId.
329 // Gives error if detection element is not defined.
330 // ---
331
332    // Get detection element
333    AliMUONGeometryDetElement* detElement
334      = (AliMUONGeometryDetElement*) fDetElements->Get(detElemId);
335
336    if (!detElement) {
337      AliErrorStream() 
338        << "Detection element " << detElemId
339        << " not found in module " << fModuleId << endl;
340      return 0;
341    }  
342
343    return detElement;
344 }
345
346 /*                                
347 //______________________________________________________________________________
348 Int_t  AliMUONGeometryModule::GetNofDetElements() const
349 {
350 // Returns the number of detection elements
351 // ---
352
353   return fDEIndexing->GetNofDetElements();
354 }   
355
356 //______________________________________________________________________________
357 Int_t  AliMUONGeometryModule::GetDetElemId(Int_t i) const
358 {
359 // Returns the i-th detection element id
360 // ---
361
362   return fDEIndexing->GetDetElementId(i);
363 }   
364 */