1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 // Class AliMUONVGeometryBuilder
20 // -----------------------------
21 // Abstract base class for geometry construction per geometry module(s).
22 // Author: Ivana Hrivnacova, IPN Orsay
24 //-----------------------------------------------------------------------------
26 #include "AliMUONVGeometryBuilder.h"
27 #include "AliMUONGeometryModule.h"
28 #include "AliMUONGeometryDetElement.h"
29 #include "AliMUONGeometryEnvelopeStore.h"
30 #include "AliMUONGeometryEnvelope.h"
31 #include "AliMUONGeometryConstituent.h"
32 #include "AliMUONGeometryBuilder.h"
33 #include "AliMUONStringIntMap.h"
35 #include "AliMpDEManager.h"
36 #include "AliMpExMap.h"
40 #include <Riostream.h>
41 #include <TObjArray.h>
43 #include <TGeoMatrix.h>
44 #include <TVirtualMC.h>
47 ClassImp(AliMUONVGeometryBuilder)
50 //______________________________________________________________________________
51 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(
58 /// Standard constructor
60 // Create the module geometries array
61 fGeometryModules = new TObjArray();
62 fGeometryModules->SetOwner(kFALSE);
64 for (Int_t i=0; i<nofModules; i++ )
65 fGeometryModules->Add(new AliMUONGeometryModule(firstModuleId++));
68 //______________________________________________________________________________
69 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
74 /// Default constructor
77 //______________________________________________________________________________
78 AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder()
82 if (fGeometryModules) {
83 fGeometryModules->Clear(); // Sets pointers to 0 since it is not the owner
84 delete fGeometryModules;
92 //______________________________________________________________________________
94 AliMUONVGeometryBuilder::ConvertTransform(const TGeoHMatrix& transform) const
96 /// Convert transformation into the reference frame
98 if ( fReferenceFrame.IsIdentity() )
101 return AliMUONGeometryBuilder::Multiply( fReferenceFrame,
103 fReferenceFrame.Inverse() );
107 //______________________________________________________________________________
109 AliMUONVGeometryBuilder::ConvertDETransform(const TGeoHMatrix& transform) const
111 /// Convert DE transformation into the reference frame
113 if ( fReferenceFrame.IsIdentity() )
116 return AliMUONGeometryBuilder::Multiply( fReferenceFrame,
121 //______________________________________________________________________________
122 TString AliMUONVGeometryBuilder::ComposePath(const TString& volName,
125 /// Compose path from given volName and copyNo
135 //______________________________________________________________________________
136 void AliMUONVGeometryBuilder::MapSV(const TString& path0,
137 const TString& volName, Int_t detElemId) const
139 /// Update the path with all daughters volumes recursively
140 /// and map it to the detection element Id if it is a sensitive volume
142 // Get module sensitive volumes map
143 Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
144 AliMUONStringIntMap* svMap = GetSVMap(moduleId);
146 Int_t nofDaughters = gMC->NofVolDaughters(volName);
147 if (nofDaughters == 0) {
149 // Get the name of the last volume in the path
150 Ssiz_t npos1 = path0.Last('/')+1;
151 Ssiz_t npos2 = path0.Last('_');
152 TString volName0(path0(npos1, npos2-npos1));
154 // Check if it is sensitive volume
155 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
156 if ( geometry->IsSensitiveVolume(volName0) &&
157 ! svMap->Get(path0) ) {
158 //cout << ".. adding to the map "
159 // << path0 << " " << detElemId << endl;
161 // Map the sensitive volume to detection element
162 svMap->Add(path0, detElemId);
167 for (Int_t i=0; i<nofDaughters; i++) {
168 Int_t copyNo = gMC->VolDaughterCopyNo(volName, i);
169 TString newName = gMC->VolDaughterName(volName, i);
171 TString path = path0;
172 path += ComposePath(newName, copyNo);
174 MapSV(path, newName, detElemId);
182 //______________________________________________________________________________
183 AliMUONGeometryModule*
184 AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
186 /// Return the module geometry specified by moduleId
188 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
190 AliMUONGeometryModule* geometry
191 = (AliMUONGeometryModule*)fGeometryModules->At(i);
193 if ( geometry->GetModuleId() == moduleId) return geometry;
199 //______________________________________________________________________________
200 AliMUONGeometryEnvelopeStore*
201 AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
203 /// Return the envelope store of the module geometry specified by moduleId
205 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
208 AliFatal(Form("Module geometry %d is not defined", moduleId));
212 return geometry->GetEnvelopeStore();
215 //______________________________________________________________________________
217 AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
219 /// Return the transformation store of the module geometry specified by moduleId
221 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
224 AliFatal(Form("Geometry %d is not defined", moduleId));
228 return geometry->GetSVMap();
231 //______________________________________________________________________________
233 AliMUONVGeometryBuilder::GetModuleId(const TString& envName) const
235 /// Return module Id which has the envelope with given name
237 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
239 AliMUONGeometryModule* geometry
240 = (AliMUONGeometryModule*)fGeometryModules->At(i);
242 if ( geometry->GetEnvelopeStore()->FindEnvelope(envName) )
243 return geometry->GetModuleId();
250 //______________________________________________________________________________
251 void AliMUONVGeometryBuilder::SetTranslation(Int_t moduleId,
252 const TGeoTranslation& translation)
254 /// Set the translation to the geometry module given by moduleId,
255 /// apply reference frame transformation
257 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
260 AliFatal(Form("Geometry %d is not defined", moduleId));
264 // Apply frame transform
265 TGeoHMatrix newTransform = ConvertTransform(translation);
267 // Set new transformation
268 geometry->SetTransformation(newTransform);
272 //______________________________________________________________________________
273 void AliMUONVGeometryBuilder::SetTransformation(Int_t moduleId,
274 const TGeoTranslation& translation,
275 const TGeoRotation& rotation)
277 /// Set the transformation to the geometry module given by moduleId,
278 /// apply reference frame transformation
280 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
283 AliFatal(Form("Geometry %d is not defined", moduleId));
287 TGeoCombiTrans transformation
288 = TGeoCombiTrans(translation, rotation);
290 // Apply frame transform
291 TGeoHMatrix newTransform = ConvertTransform(transformation);
293 // Set new transformation
294 geometry->SetTransformation(newTransform);
297 //______________________________________________________________________________
298 void AliMUONVGeometryBuilder::SetVolume(Int_t moduleId,
299 const TString& volumeName,
302 /// Set volume name, virtuality
304 TString path = GetGeometry(moduleId)->GetVolumePath();
305 // cout << "in AliMUONVGeometryBuilder::SetVolume " << path.Data() << endl;
307 if ( path == "" ) path = "/ALIC_1";
308 path += ComposePath(volumeName, 1);
310 GetGeometry(moduleId)->SetVolumePath(path);
311 GetGeometry(moduleId)->SetIsVirtual(isVirtual);
312 // cout << "... set " << path.Data() << endl;
315 //______________________________________________________________________________
316 void AliMUONVGeometryBuilder::SetMotherVolume(Int_t moduleId,
317 const TString& volumeName)
319 /// Set mother volume name
321 TString motherVolumeName = ComposePath(volumeName, 1);
323 TString path = GetGeometry(moduleId)->GetVolumePath();
324 if ( path == "" ) path = "/ALIC_1";
325 path.Insert(7, motherVolumeName);
327 GetGeometry(moduleId)->SetVolumePath(path);
334 //______________________________________________________________________________
335 void AliMUONVGeometryBuilder::SetReferenceFrame(
336 const TGeoCombiTrans& referenceFrame)
338 /// Set reference frame to builder and to all associated geometry
341 fReferenceFrame = referenceFrame;
343 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
344 AliMUONGeometryModule* geometry
345 = (AliMUONGeometryModule*)fGeometryModules->At(i);
346 AliMUONGeometryEnvelopeStore* envelopeStore
347 = geometry->GetEnvelopeStore();
349 envelopeStore->SetReferenceFrame(referenceFrame);
354 //______________________________________________________________________________
355 void AliMUONVGeometryBuilder::CreateDetElements() const
357 /// Create detection elements and fill their global and
358 /// local transformations from geometry.
360 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
361 AliMUONGeometryModule* geometry
362 = (AliMUONGeometryModule*)fGeometryModules->At(i);
364 const TObjArray* envelopes
365 = geometry->GetEnvelopeStore()->GetEnvelopes();
367 AliMpExMap* detElements
368 = geometry->GetTransformer()->GetDetElementStore();
370 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
371 AliMUONGeometryEnvelope* envelope
372 = (AliMUONGeometryEnvelope*)envelopes->At(j);
374 // skip envelope not corresponding to detection element
375 if ( envelope->GetUniqueID() == 0) continue;
378 Int_t detElemId = envelope->GetUniqueID();
380 // Compose full volume path
381 TString volPath = geometry->GetVolumePath();
382 volPath += ComposePath(envelope->GetName(), envelope->GetCopyNo());
384 // Create detection element
385 AliMUONGeometryDetElement* detElement
386 = new AliMUONGeometryDetElement(detElemId, volPath);
387 detElements->Add(detElemId, detElement);
389 // Compose local transformation
390 const TGeoCombiTrans* transform = envelope->GetTransformation();
391 // Apply frame transform
392 TGeoHMatrix localTransform = ConvertDETransform(*transform);
393 detElement->SetLocalTransformation(localTransform);
395 // Compose global transformation
396 TGeoHMatrix globalTransform
397 = AliMUONGeometryBuilder::Multiply(
398 (*geometry->GetTransformer()->GetTransformation()),
401 // Set the global transformation to detection element
402 detElement->SetGlobalTransformation(globalTransform);
407 //_____ _________________________________________________________________________
408 void AliMUONVGeometryBuilder::RebuildSVMaps(Bool_t withEnvelopes) const
410 /// Clear the SV maps in memory and fill them from defined geometry.
412 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
413 AliMUONGeometryModule* geometry
414 = (AliMUONGeometryModule*)fGeometryModules->At(i);
417 geometry->GetSVMap()->Clear();
419 // Fill the map from geometry
420 const TObjArray* envelopes
421 = geometry->GetEnvelopeStore()->GetEnvelopes();
423 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
424 AliMUONGeometryEnvelope* envelope
425 = (AliMUONGeometryEnvelope*)envelopes->At(j);
427 // skip envelope not corresponding to detection element
428 if ( envelope->GetUniqueID() == 0 ) continue;
430 // Get volume path of detection element
431 AliMUONGeometryDetElement* detElement
432 = geometry->GetTransformer()->GetDetElement(envelope->GetUniqueID());
433 std::string path0 = detElement->GetVolumePath().Data();
435 if ( ! withEnvelopes && geometry->IsVirtual() ) {
436 std::string vName = geometry->GetTransformer()->GetVolumeName().Data();
437 std::string vPath = ComposePath(vName, 1).Data();
438 path0.erase(path0.find(vPath), vPath.size());
441 if ( ! withEnvelopes && envelope->IsVirtual()) {
442 std::string eName = envelope->GetName();
443 std::string ePath = ComposePath(eName, envelope->GetCopyNo()).Data();
444 path0.erase(path0.find(ePath), ePath.size());
447 if ( ! envelope->IsVirtual() )
448 MapSV(path0, envelope->GetName(), envelope->GetUniqueID());
450 for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
451 AliMUONGeometryConstituent* constituent
452 = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
453 TString path = path0;
454 path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
455 MapSV(path, constituent->GetName(), envelope->GetUniqueID());