]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONVGeometryBuilder.cxx
Removed unused (and not implemented) method AddSVPath()
[u/mrichter/AliRoot.git] / MUON / AliMUONVGeometryBuilder.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 AliMUONVGeometryBuilder
19 // -----------------------------
20 // Abstract base class for geometry construction per geometry module(s).
21 // Author: Ivana Hrivnacova, IPN Orsay
22 // 23/01/2004
23
24 #include <Riostream.h>
25 #include <TObjArray.h>
26 #include <TSystem.h>
27 #include <TGeoMatrix.h>
28 #include <TVirtualMC.h>
29
30 #include "AliMUONVGeometryBuilder.h"
31 #include "AliMUONGeometryModule.h"
32 #include "AliMUONGeometryDetElement.h"
33 #include "AliMUONGeometryStore.h"
34 #include "AliMUONGeometrySVMap.h"
35 #include "AliMUONGeometryEnvelopeStore.h"
36 #include "AliMUONGeometryEnvelope.h"
37 #include "AliMUONGeometryConstituent.h"
38 #include "AliMUONGeometryDEIndexing.h"
39 #include "AliMUONGeometryBuilder.h"
40 #include "AliLog.h"
41
42 ClassImp(AliMUONVGeometryBuilder)
43
44 //______________________________________________________________________________
45 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(
46                             Int_t moduleId1, Int_t moduleId2,
47                             Int_t moduleId3, Int_t moduleId4,
48                             Int_t moduleId5, Int_t moduleId6)
49  : TObject(),
50    fGeometryModules(0),
51    fReferenceFrame()
52  {
53 // Standard constructor
54
55   // Create the module geometries array
56   fGeometryModules = new TObjArray();
57   
58   if ( moduleId1 >= 0 ) 
59     fGeometryModules->Add(new AliMUONGeometryModule(moduleId1));
60  
61   if ( moduleId2 >= 0 ) 
62     fGeometryModules->Add(new AliMUONGeometryModule(moduleId2));
63
64   if ( moduleId3 >= 0 ) 
65     fGeometryModules->Add(new AliMUONGeometryModule(moduleId3));
66
67   if ( moduleId4 >= 0 ) 
68     fGeometryModules->Add(new AliMUONGeometryModule(moduleId4));
69
70   if ( moduleId5 >= 0 ) 
71     fGeometryModules->Add(new AliMUONGeometryModule(moduleId5));
72
73   if ( moduleId6 >= 0 ) 
74     fGeometryModules->Add(new AliMUONGeometryModule(moduleId6));
75 }
76
77 //______________________________________________________________________________
78 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
79  : TObject(),
80    fGeometryModules(0),
81    fReferenceFrame()
82 {
83 // Default constructor
84 }
85
86
87 //______________________________________________________________________________
88 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
89   : TObject(rhs)
90 {
91 // Protected copy constructor
92
93   AliFatal("Copy constructor is not implemented.");
94 }
95
96 //______________________________________________________________________________
97 AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() {
98 //
99   if (fGeometryModules) {
100     fGeometryModules->Clear(); // Sets pointers to 0 since it is not the owner
101     delete fGeometryModules;
102   }
103 }
104
105 //______________________________________________________________________________
106 AliMUONVGeometryBuilder& 
107 AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs) 
108 {
109 // Protected assignement operator
110
111   // check assignement to self
112   if (this == &rhs) return *this;
113
114   AliFatal("Assignment operator is not implemented.");
115     
116   return *this;  
117 }
118
119 //
120 // private methods
121 //
122
123 //______________________________________________________________________________
124 TGeoHMatrix 
125 AliMUONVGeometryBuilder::ConvertTransform(const TGeoHMatrix& transform) const
126 {
127 // Convert transformation into the reference frame
128
129   if ( fReferenceFrame.IsIdentity() )
130     return transform;
131   else  {
132     return AliMUONGeometryBuilder::Multiply( fReferenceFrame.Inverse(),
133                                              transform,
134                                              fReferenceFrame );  
135   }                         
136 }
137
138 //______________________________________________________________________________
139 TString  AliMUONVGeometryBuilder::ComposePath(const TString& volName, 
140                                                Int_t copyNo) const
141 {
142 // Compose path from given volName and copyNo
143 // ---
144
145   TString path(volName);
146   path += ".";
147   path += copyNo;
148   
149   return path;
150 }  
151
152 //______________________________________________________________________________
153 void AliMUONVGeometryBuilder::MapSV(const TString& path0, 
154                                     const TString& volName, Int_t detElemId) const
155 {
156 // Update the path with all daughters volumes recursively
157 // and map it to the detection element Id if it is a sensitive volume
158 // ---
159
160   // Get module sensitive volumes map
161   Int_t moduleId = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
162   AliMUONGeometrySVMap* svMap = GetSVMap(moduleId);     
163
164   Int_t nofDaughters = gMC->NofVolDaughters(volName);
165   if (nofDaughters == 0) {
166
167     // Get the name of the last volume in the path
168     Ssiz_t npos1 = path0.Last('/')+1; 
169     Ssiz_t npos2 = path0.Last('.');
170     TString volName(path0(npos1, npos2-npos1));  
171     
172     // Check if it is sensitive volume
173     Int_t moduleId = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
174     AliMUONGeometryModule* geometry = GetGeometry(moduleId);
175     if (geometry->IsSensitiveVolume(volName)) {
176       //cout << ".. adding to the map  " 
177       //     <<  path0 << "  "  << detElemId << endl;
178     
179       // Map the sensitive volume to detection element
180       svMap->Add(path0, detElemId); 
181     }  
182     return; 
183   }  
184
185   for (Int_t i=0; i<nofDaughters; i++) {
186     Int_t copyNo = gMC->VolDaughterCopyNo(volName, i);
187     TString newName =  gMC->VolDaughterName(volName, i);
188             
189     TString path = path0;
190     path += "/";
191     path += ComposePath(newName, copyNo);
192
193     MapSV(path, newName, detElemId);
194   }
195 }     
196
197 //
198 // protected methods
199 //
200
201 //______________________________________________________________________________
202 AliMUONGeometryModule*  
203 AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
204 {
205 // Returns the module geometry specified by moduleId
206 // ---
207
208   for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
209
210     AliMUONGeometryModule* geometry 
211       = (AliMUONGeometryModule*)fGeometryModules->At(i);
212
213     if ( geometry->GetModuleId() == moduleId) return geometry;
214   }   
215   
216   return 0;
217 }  
218
219 //______________________________________________________________________________
220 AliMUONGeometryEnvelopeStore*  
221 AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
222 {
223 // Returns the envelope store of the module geometry specified by moduleId
224 // ---
225
226   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
227   
228   if (!geometry) {
229     AliFatal(Form("Module geometry %d is not defined", moduleId)); 
230     return 0;
231   }
232   
233   return geometry->GetEnvelopeStore();
234 }  
235
236 //______________________________________________________________________________
237 AliMUONGeometrySVMap*  
238 AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
239 {
240 // Returns the transformation store of the module geometry specified by moduleId
241 // ---
242
243   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
244   
245   if (!geometry) {
246     AliFatal(Form("Geometry %d is not defined", moduleId)); 
247     return 0;
248   }
249   
250   return geometry->GetSVMap();
251 }  
252
253 //______________________________________________________________________________
254 void AliMUONVGeometryBuilder::SetTranslation(Int_t moduleId, 
255                                   const TGeoTranslation& translation)
256 {
257 // Sets the translation to the geometry module given by moduleId,
258 // applies reference frame transformation 
259 // ---
260
261   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
262   
263   if (!geometry) {
264     AliFatal(Form("Geometry %d is not defined", moduleId)); 
265     return;
266   }
267   
268   // Apply frame transform
269   TGeoHMatrix newTransform = ConvertTransform(translation);
270
271   // Set new transformation
272   geometry->SetTransformation(newTransform);
273 }  
274
275
276 //______________________________________________________________________________
277 void AliMUONVGeometryBuilder::SetTransformation(Int_t moduleId, 
278                                   const TGeoTranslation& translation,
279                                   const TGeoRotation& rotation)
280 {
281 // Sets the translation to the geometry module given by moduleId,
282 // applies reference frame transformation 
283 // ---
284
285   AliMUONGeometryModule* geometry = GetGeometry(moduleId);
286   
287   if (!geometry) {
288     AliFatal(Form("Geometry %d is not defined", moduleId)); 
289     return;
290   }
291   
292   TGeoCombiTrans transformation 
293     = TGeoCombiTrans(translation, rotation);
294
295   // Apply frame transform
296   TGeoHMatrix newTransform = ConvertTransform(translation);
297
298   // Set new transformation
299   geometry->SetTransformation(newTransform);
300 }  
301
302 //
303 // public functions
304 //
305
306 //______________________________________________________________________________
307 void  AliMUONVGeometryBuilder::SetReferenceFrame(
308                                   const TGeoCombiTrans& referenceFrame)
309
310   fReferenceFrame = referenceFrame; 
311
312   for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
313     AliMUONGeometryModule* geometry 
314       = (AliMUONGeometryModule*)fGeometryModules->At(i);
315     AliMUONGeometryEnvelopeStore* envelopeStore 
316       = geometry->GetEnvelopeStore();
317       
318     envelopeStore->SetReferenceFrame(referenceFrame);
319   }          
320 }
321
322
323 //______________________________________________________________________________
324 void  AliMUONVGeometryBuilder::FillTransformations() const
325 {
326 // Fills transformations store from defined geometry.
327 // ---
328
329   for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
330     AliMUONGeometryModule* geometry 
331       = (AliMUONGeometryModule*)fGeometryModules->At(i);
332     const TObjArray* envelopes 
333       = geometry->GetEnvelopeStore()->GetEnvelopes();    
334     
335     AliMUONGeometryStore* detElements 
336       = geometry->GetTransformer()->GetDetElementStore(); 
337       
338     for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
339       AliMUONGeometryEnvelope* envelope
340         = (AliMUONGeometryEnvelope*)envelopes->At(j);
341
342       // skip envelope not corresponding to detection element
343       if(envelope->GetUniqueID() == 0) continue;
344        
345       // Get envelope data 
346       Int_t detElemId = envelope->GetUniqueID();        
347       TString path = ComposePath(envelope->GetName(), 
348                                  envelope->GetCopyNo());
349       const TGeoCombiTrans* transform = envelope->GetTransformation(); 
350       
351       // Apply frame transform
352       TGeoHMatrix newTransform = ConvertTransform(*transform);
353
354       // Add detection element transformation 
355       detElements->Add(detElemId,
356         new AliMUONGeometryDetElement(detElemId, path, newTransform)); 
357     }  
358   }
359 }
360
361 //_____ _________________________________________________________________________
362 void  AliMUONVGeometryBuilder::RebuildSVMaps() const
363 {
364 // Clear the SV maps in memory and fill them from defined geometry.
365 // ---
366
367   for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
368     AliMUONGeometryModule* geometry 
369       = (AliMUONGeometryModule*)fGeometryModules->At(i);
370     
371     // Clear the map   
372     geometry->GetSVMap()->Clear();
373      
374     // Fill the map from geometry
375     const TObjArray* envelopes 
376       = geometry->GetEnvelopeStore()->GetEnvelopes();    
377
378     for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
379       AliMUONGeometryEnvelope* envelope
380         = (AliMUONGeometryEnvelope*)envelopes->At(j);
381
382       // skip envelope not corresponding to detection element
383       if(envelope->GetUniqueID() == 0) continue;
384        
385       TString path0("/ALIC.1");
386       if (geometry->GetMotherVolume() != "ALIC") {
387         path0 += "/";
388         path0 += ComposePath(geometry->GetMotherVolume(), 1);
389       }  
390       if (! geometry->IsVirtual() ) {
391         path0 += "/";
392         path0 += ComposePath(geometry->GetVolume(), 1);
393       }  
394        
395       if (!envelope->IsVirtual()) {
396          TString path = path0;
397          path += "/";
398          path += ComposePath(envelope->GetName(), envelope->GetCopyNo());
399          MapSV(path, envelope->GetName(), envelope->GetUniqueID());
400       }
401       else {     
402         for  (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
403           AliMUONGeometryConstituent* constituent
404             = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
405          TString path = path0;
406          path += "/";
407          path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
408          MapSV(path, constituent->GetName(), envelope->GetUniqueID());
409         }
410       }
411     }  
412   }                  
413 }
414