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 // Class AliMUONVGeometryBuilder
19 // -----------------------------
20 // Abstract base class for geometry construction per geometry module(s).
21 // Author: Ivana Hrivnacova, IPN Orsay
24 #include <Riostream.h>
25 #include <TObjArray.h>
27 #include <TGeoMatrix.h>
28 #include <TVirtualMC.h>
30 #include "AliMUONVGeometryBuilder.h"
31 #include "AliMUONGeometryModule.h"
32 #include "AliMUONGeometryDetElement.h"
33 #include "AliMUONGeometryStore.h"
34 #include "AliMUONGeometryEnvelopeStore.h"
35 #include "AliMUONGeometryEnvelope.h"
36 #include "AliMUONGeometryConstituent.h"
37 #include "AliMUONGeometryBuilder.h"
38 #include "AliMUONStringIntMap.h"
41 ClassImp(AliMUONVGeometryBuilder)
43 //______________________________________________________________________________
44 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(
45 Int_t moduleId1, Int_t moduleId2,
46 Int_t moduleId3, Int_t moduleId4,
47 Int_t moduleId5, Int_t moduleId6)
52 // Standard constructor
54 // Create the module geometries array
55 fGeometryModules = new TObjArray();
58 fGeometryModules->Add(new AliMUONGeometryModule(moduleId1));
61 fGeometryModules->Add(new AliMUONGeometryModule(moduleId2));
64 fGeometryModules->Add(new AliMUONGeometryModule(moduleId3));
67 fGeometryModules->Add(new AliMUONGeometryModule(moduleId4));
70 fGeometryModules->Add(new AliMUONGeometryModule(moduleId5));
73 fGeometryModules->Add(new AliMUONGeometryModule(moduleId6));
76 //______________________________________________________________________________
77 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
82 // Default constructor
86 //______________________________________________________________________________
87 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
90 // Protected copy constructor
92 AliFatal("Copy constructor is not implemented.");
95 //______________________________________________________________________________
96 AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() {
98 if (fGeometryModules) {
99 fGeometryModules->Clear(); // Sets pointers to 0 since it is not the owner
100 delete fGeometryModules;
104 //______________________________________________________________________________
105 AliMUONVGeometryBuilder&
106 AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs)
108 // Protected assignement operator
110 // check assignement to self
111 if (this == &rhs) return *this;
113 AliFatal("Assignment operator is not implemented.");
122 //______________________________________________________________________________
124 AliMUONVGeometryBuilder::ConvertTransform(const TGeoHMatrix& transform) const
126 // Convert transformation into the reference frame
128 if ( fReferenceFrame.IsIdentity() )
131 return AliMUONGeometryBuilder::Multiply( fReferenceFrame,
133 fReferenceFrame.Inverse() );
137 //______________________________________________________________________________
139 AliMUONVGeometryBuilder::ConvertDETransform(const TGeoHMatrix& transform) const
141 // Convert transformation into the reference frame
143 if ( fReferenceFrame.IsIdentity() )
146 return AliMUONGeometryBuilder::Multiply( fReferenceFrame,
151 //______________________________________________________________________________
152 TString AliMUONVGeometryBuilder::ComposePath(const TString& volName,
155 // Compose path from given volName and copyNo
166 //______________________________________________________________________________
167 void AliMUONVGeometryBuilder::MapSV(const TString& path0,
168 const TString& volName, Int_t detElemId) const
170 // Update the path with all daughters volumes recursively
171 // and map it to the detection element Id if it is a sensitive volume
174 // Get module sensitive volumes map
175 Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
176 AliMUONStringIntMap* svMap = GetSVMap(moduleId);
178 Int_t nofDaughters = gMC->NofVolDaughters(volName);
179 if (nofDaughters == 0) {
181 // Get the name of the last volume in the path
182 Ssiz_t npos1 = path0.Last('/')+1;
183 Ssiz_t npos2 = path0.Last('_');
184 TString volName(path0(npos1, npos2-npos1));
186 // Check if it is sensitive volume
187 Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
188 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
189 if ( geometry->IsSensitiveVolume(volName) &&
190 ! svMap->Get(path0) ) {
191 //cout << ".. adding to the map "
192 // << path0 << " " << detElemId << endl;
194 // Map the sensitive volume to detection element
195 svMap->Add(path0, detElemId);
200 for (Int_t i=0; i<nofDaughters; i++) {
201 Int_t copyNo = gMC->VolDaughterCopyNo(volName, i);
202 TString newName = gMC->VolDaughterName(volName, i);
204 TString path = path0;
205 path += ComposePath(newName, copyNo);
207 MapSV(path, newName, detElemId);
215 //______________________________________________________________________________
216 AliMUONGeometryModule*
217 AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
219 // Returns the module geometry specified by moduleId
222 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
224 AliMUONGeometryModule* geometry
225 = (AliMUONGeometryModule*)fGeometryModules->At(i);
227 if ( geometry->GetModuleId() == moduleId) return geometry;
233 //______________________________________________________________________________
234 AliMUONGeometryEnvelopeStore*
235 AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
237 // Returns the envelope store of the module geometry specified by moduleId
240 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
243 AliFatal(Form("Module geometry %d is not defined", moduleId));
247 return geometry->GetEnvelopeStore();
250 //______________________________________________________________________________
252 AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
254 // Returns the transformation store of the module geometry specified by moduleId
257 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
260 AliFatal(Form("Geometry %d is not defined", moduleId));
264 return geometry->GetSVMap();
267 //______________________________________________________________________________
268 void AliMUONVGeometryBuilder::SetTranslation(Int_t moduleId,
269 const TGeoTranslation& translation)
271 // Sets the translation to the geometry module given by moduleId,
272 // applies reference frame transformation
275 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
278 AliFatal(Form("Geometry %d is not defined", moduleId));
282 // Apply frame transform
283 TGeoHMatrix newTransform = ConvertTransform(translation);
285 // Set new transformation
286 geometry->SetTransformation(newTransform);
290 //______________________________________________________________________________
291 void AliMUONVGeometryBuilder::SetTransformation(Int_t moduleId,
292 const TGeoTranslation& translation,
293 const TGeoRotation& rotation)
295 // Sets the translation to the geometry module given by moduleId,
296 // applies reference frame transformation
299 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
302 AliFatal(Form("Geometry %d is not defined", moduleId));
306 TGeoCombiTrans transformation
307 = TGeoCombiTrans(translation, rotation);
309 // Apply frame transform
310 TGeoHMatrix newTransform = ConvertTransform(transformation);
312 // Set new transformation
313 geometry->SetTransformation(newTransform);
316 //______________________________________________________________________________
317 void AliMUONVGeometryBuilder::SetVolume(Int_t moduleId,
318 const TString& volumeName,
321 /// Set volume name, virtuality
323 TString path = GetGeometry(moduleId)->GetVolumePath();
324 // cout << "in AliMUONVGeometryBuilder::SetVolume " << path.Data() << endl;
326 if ( path == "" ) path = "/ALIC_1";
327 path += ComposePath(volumeName, 1);
329 GetGeometry(moduleId)->SetVolumePath(path);
330 GetGeometry(moduleId)->SetIsVirtual(isVirtual);
331 // cout << "... set " << path.Data() << endl;
334 //______________________________________________________________________________
335 void AliMUONVGeometryBuilder::SetMotherVolume(Int_t moduleId,
336 const TString& volumeName)
338 /// Set mother volume name
340 TString motherVolumeName = ComposePath(volumeName, 1);
342 TString path = GetGeometry(moduleId)->GetVolumePath();
343 if ( path == "" ) path = "/ALIC_1";
344 path.Insert(7, motherVolumeName);
346 GetGeometry(moduleId)->SetVolumePath(path);
353 //______________________________________________________________________________
354 void AliMUONVGeometryBuilder::SetReferenceFrame(
355 const TGeoCombiTrans& referenceFrame)
357 /// Set reference frame to builder and to all associated geometry
360 fReferenceFrame = referenceFrame;
362 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
363 AliMUONGeometryModule* geometry
364 = (AliMUONGeometryModule*)fGeometryModules->At(i);
365 AliMUONGeometryEnvelopeStore* envelopeStore
366 = geometry->GetEnvelopeStore();
368 envelopeStore->SetReferenceFrame(referenceFrame);
373 //______________________________________________________________________________
374 void AliMUONVGeometryBuilder::CreateDetElements() const
376 /// Create detection element and fill their global and
377 /// local transformations from geometry.
379 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
380 AliMUONGeometryModule* geometry
381 = (AliMUONGeometryModule*)fGeometryModules->At(i);
383 const TObjArray* envelopes
384 = geometry->GetEnvelopeStore()->GetEnvelopes();
386 AliMUONGeometryStore* detElements
387 = geometry->GetTransformer()->GetDetElementStore();
389 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
390 AliMUONGeometryEnvelope* envelope
391 = (AliMUONGeometryEnvelope*)envelopes->At(j);
393 // skip envelope not corresponding to detection element
394 if ( envelope->GetUniqueID() == 0) continue;
397 Int_t detElemId = envelope->GetUniqueID();
399 // Compose full volume path
400 TString volPath = geometry->GetVolumePath();
401 volPath += ComposePath(envelope->GetName(), envelope->GetCopyNo());
403 // Create detection element
404 AliMUONGeometryDetElement* detElement
405 = new AliMUONGeometryDetElement(detElemId, volPath);
406 detElements->Add(detElemId, detElement);
408 // Compose local transformation
409 const TGeoCombiTrans* transform = envelope->GetTransformation();
410 // Apply frame transform
411 TGeoHMatrix localTransform = ConvertDETransform(*transform);
412 detElement->SetLocalTransformation(localTransform);
414 // Compose global transformation
415 TGeoHMatrix globalTransform
416 = AliMUONGeometryBuilder::Multiply(
417 (*geometry->GetTransformer()->GetTransformation()),
420 // Set the global transformation to detection element
421 detElement->SetGlobalTransformation(globalTransform);
426 //_____ _________________________________________________________________________
427 void AliMUONVGeometryBuilder::RebuildSVMaps(Bool_t withEnvelopes) const
429 // Clear the SV maps in memory and fill them from defined geometry.
432 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
433 AliMUONGeometryModule* geometry
434 = (AliMUONGeometryModule*)fGeometryModules->At(i);
437 geometry->GetSVMap()->Clear();
439 // Fill the map from geometry
440 const TObjArray* envelopes
441 = geometry->GetEnvelopeStore()->GetEnvelopes();
443 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
444 AliMUONGeometryEnvelope* envelope
445 = (AliMUONGeometryEnvelope*)envelopes->At(j);
447 // skip envelope not corresponding to detection element
448 if ( envelope->GetUniqueID() == 0 ) continue;
450 // Get volume path of detection element
451 AliMUONGeometryDetElement* detElement
452 = geometry->GetTransformer()->GetDetElement(envelope->GetUniqueID());
453 std::string path0 = detElement->GetVolumePath().Data();
455 if ( ! withEnvelopes && geometry->IsVirtual() ) {
456 std::string vName = geometry->GetTransformer()->GetVolumeName().Data();
457 std::string vPath = ComposePath(vName, 1).Data();
458 path0.erase(path0.find(vPath), vPath.size());
461 if ( ! withEnvelopes && envelope->IsVirtual()) {
462 std::string eName = envelope->GetName();
463 std::string ePath = ComposePath(eName, envelope->GetCopyNo()).Data();
464 path0.erase(path0.find(ePath), ePath.size());
467 if ( ! envelope->IsVirtual() )
468 MapSV(path0, envelope->GetName(), envelope->GetUniqueID());
470 for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
471 AliMUONGeometryConstituent* constituent
472 = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
473 TString path = path0;
474 path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
475 MapSV(path, constituent->GetName(), envelope->GetUniqueID());