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 "AliMUONGeometrySVMap.h"
35 #include "AliMUONGeometryEnvelopeStore.h"
36 #include "AliMUONGeometryEnvelope.h"
37 #include "AliMUONGeometryConstituent.h"
38 #include "AliMUONGeometryDEIndexing.h"
39 #include "AliMUONGeometryBuilder.h"
42 ClassImp(AliMUONVGeometryBuilder)
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)
53 // Standard constructor
55 // Create the module geometries array
56 fGeometryModules = new TObjArray();
59 fGeometryModules->Add(new AliMUONGeometryModule(moduleId1));
62 fGeometryModules->Add(new AliMUONGeometryModule(moduleId2));
65 fGeometryModules->Add(new AliMUONGeometryModule(moduleId3));
68 fGeometryModules->Add(new AliMUONGeometryModule(moduleId4));
71 fGeometryModules->Add(new AliMUONGeometryModule(moduleId5));
74 fGeometryModules->Add(new AliMUONGeometryModule(moduleId6));
77 //______________________________________________________________________________
78 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
83 // Default constructor
87 //______________________________________________________________________________
88 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
91 // Protected copy constructor
93 AliFatal("Copy constructor is not implemented.");
96 //______________________________________________________________________________
97 AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() {
99 if (fGeometryModules) {
100 fGeometryModules->Clear(); // Sets pointers to 0 since it is not the owner
101 delete fGeometryModules;
105 //______________________________________________________________________________
106 AliMUONVGeometryBuilder&
107 AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs)
109 // Protected assignement operator
111 // check assignement to self
112 if (this == &rhs) return *this;
114 AliFatal("Assignment operator is not implemented.");
123 //______________________________________________________________________________
125 AliMUONVGeometryBuilder::ConvertTransform(const TGeoHMatrix& transform) const
127 // Convert transformation into the reference frame
129 if ( fReferenceFrame.IsIdentity() )
132 return AliMUONGeometryBuilder::Multiply( fReferenceFrame.Inverse(),
138 //______________________________________________________________________________
139 TString AliMUONVGeometryBuilder::ComposePath(const TString& volName,
142 // Compose path from given volName and copyNo
145 TString path(volName);
152 //______________________________________________________________________________
153 void AliMUONVGeometryBuilder::MapSV(const TString& path0,
154 const TString& volName, Int_t detElemId) const
156 // Update the path with all daughters volumes recursively
157 // and map it to the detection element Id if it is a sensitive volume
160 // Get module sensitive volumes map
161 Int_t moduleId = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
162 AliMUONGeometrySVMap* svMap = GetSVMap(moduleId);
164 Int_t nofDaughters = gMC->NofVolDaughters(volName);
165 if (nofDaughters == 0) {
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));
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;
179 // Map the sensitive volume to detection element
180 svMap->Add(path0, detElemId);
185 for (Int_t i=0; i<nofDaughters; i++) {
186 Int_t copyNo = gMC->VolDaughterCopyNo(volName, i);
187 TString newName = gMC->VolDaughterName(volName, i);
189 TString path = path0;
191 path += ComposePath(newName, copyNo);
193 MapSV(path, newName, detElemId);
201 //______________________________________________________________________________
202 AliMUONGeometryModule*
203 AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
205 // Returns the module geometry specified by moduleId
208 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
210 AliMUONGeometryModule* geometry
211 = (AliMUONGeometryModule*)fGeometryModules->At(i);
213 if ( geometry->GetModuleId() == moduleId) return geometry;
219 //______________________________________________________________________________
220 AliMUONGeometryEnvelopeStore*
221 AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
223 // Returns the envelope store of the module geometry specified by moduleId
226 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
229 AliFatal(Form("Module geometry %d is not defined", moduleId));
233 return geometry->GetEnvelopeStore();
236 //______________________________________________________________________________
237 AliMUONGeometrySVMap*
238 AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
240 // Returns the transformation store of the module geometry specified by moduleId
243 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
246 AliFatal(Form("Geometry %d is not defined", moduleId));
250 return geometry->GetSVMap();
253 //______________________________________________________________________________
254 void AliMUONVGeometryBuilder::SetTranslation(Int_t moduleId,
255 const TGeoTranslation& translation)
257 // Sets the translation to the geometry module given by moduleId,
258 // applies reference frame transformation
261 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
264 AliFatal(Form("Geometry %d is not defined", moduleId));
268 // Apply frame transform
269 TGeoHMatrix newTransform = ConvertTransform(translation);
271 // Set new transformation
272 geometry->SetTransformation(newTransform);
276 //______________________________________________________________________________
277 void AliMUONVGeometryBuilder::SetTransformation(Int_t moduleId,
278 const TGeoTranslation& translation,
279 const TGeoRotation& rotation)
281 // Sets the translation to the geometry module given by moduleId,
282 // applies reference frame transformation
285 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
288 AliFatal(Form("Geometry %d is not defined", moduleId));
292 TGeoCombiTrans transformation
293 = TGeoCombiTrans(translation, rotation);
295 // Apply frame transform
296 TGeoHMatrix newTransform = ConvertTransform(translation);
298 // Set new transformation
299 geometry->SetTransformation(newTransform);
306 //______________________________________________________________________________
307 void AliMUONVGeometryBuilder::SetReferenceFrame(
308 const TGeoCombiTrans& referenceFrame)
310 fReferenceFrame = referenceFrame;
312 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
313 AliMUONGeometryModule* geometry
314 = (AliMUONGeometryModule*)fGeometryModules->At(i);
315 AliMUONGeometryEnvelopeStore* envelopeStore
316 = geometry->GetEnvelopeStore();
318 envelopeStore->SetReferenceFrame(referenceFrame);
323 //______________________________________________________________________________
324 void AliMUONVGeometryBuilder::FillTransformations() const
326 // Fills transformations store from defined geometry.
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();
335 AliMUONGeometryStore* detElements
336 = geometry->GetTransformer()->GetDetElementStore();
338 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
339 AliMUONGeometryEnvelope* envelope
340 = (AliMUONGeometryEnvelope*)envelopes->At(j);
342 // skip envelope not corresponding to detection element
343 if(envelope->GetUniqueID() == 0) continue;
346 Int_t detElemId = envelope->GetUniqueID();
347 TString path = ComposePath(envelope->GetName(),
348 envelope->GetCopyNo());
349 const TGeoCombiTrans* transform = envelope->GetTransformation();
351 // Apply frame transform
352 TGeoHMatrix newTransform = ConvertTransform(*transform);
354 // Add detection element transformation
355 detElements->Add(detElemId,
356 new AliMUONGeometryDetElement(detElemId, path, newTransform));
361 //_____ _________________________________________________________________________
362 void AliMUONVGeometryBuilder::RebuildSVMaps() const
364 // Clear the SV maps in memory and fill them from defined geometry.
367 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
368 AliMUONGeometryModule* geometry
369 = (AliMUONGeometryModule*)fGeometryModules->At(i);
372 geometry->GetSVMap()->Clear();
374 // Fill the map from geometry
375 const TObjArray* envelopes
376 = geometry->GetEnvelopeStore()->GetEnvelopes();
378 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
379 AliMUONGeometryEnvelope* envelope
380 = (AliMUONGeometryEnvelope*)envelopes->At(j);
382 // skip envelope not corresponding to detection element
383 if(envelope->GetUniqueID() == 0) continue;
385 TString path0("/ALIC.1");
386 if (geometry->GetMotherVolume() != "ALIC") {
388 path0 += ComposePath(geometry->GetMotherVolume(), 1);
390 if (! geometry->IsVirtual() ) {
392 path0 += ComposePath(geometry->GetVolume(), 1);
395 if (!envelope->IsVirtual()) {
396 TString path = path0;
398 path += ComposePath(envelope->GetName(), envelope->GetCopyNo());
399 MapSV(path, envelope->GetName(), envelope->GetUniqueID());
402 for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
403 AliMUONGeometryConstituent* constituent
404 = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
405 TString path = path0;
407 path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
408 MapSV(path, constituent->GetName(), envelope->GetUniqueID());