]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONVGeometryBuilder.cxx
Removed unused (and not implemented) method AddSVPath()
[u/mrichter/AliRoot.git] / MUON / AliMUONVGeometryBuilder.cxx
CommitLineData
30178c30 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
d1cd2474 16// $Id$
17//
18// Class AliMUONVGeometryBuilder
19// -----------------------------
e118b27e 20// Abstract base class for geometry construction per geometry module(s).
d1cd2474 21// Author: Ivana Hrivnacova, IPN Orsay
5f1df83a 22// 23/01/2004
d1cd2474 23
2811276d 24#include <Riostream.h>
d1cd2474 25#include <TObjArray.h>
2811276d 26#include <TSystem.h>
27#include <TGeoMatrix.h>
28#include <TVirtualMC.h>
d1cd2474 29
30#include "AliMUONVGeometryBuilder.h"
e118b27e 31#include "AliMUONGeometryModule.h"
32#include "AliMUONGeometryDetElement.h"
33#include "AliMUONGeometryStore.h"
2811276d 34#include "AliMUONGeometrySVMap.h"
35#include "AliMUONGeometryEnvelopeStore.h"
36#include "AliMUONGeometryEnvelope.h"
37#include "AliMUONGeometryConstituent.h"
6cfb12b4 38#include "AliMUONGeometryDEIndexing.h"
067866a3 39#include "AliMUONGeometryBuilder.h"
8c343c7c 40#include "AliLog.h"
d1cd2474 41
42ClassImp(AliMUONVGeometryBuilder)
43
44//______________________________________________________________________________
6cfb12b4 45AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(
46 Int_t moduleId1, Int_t moduleId2,
47 Int_t moduleId3, Int_t moduleId4,
48 Int_t moduleId5, Int_t moduleId6)
d1cd2474 49 : TObject(),
6cfb12b4 50 fGeometryModules(0),
067866a3 51 fReferenceFrame()
d1cd2474 52 {
53// Standard constructor
54
e118b27e 55 // Create the module geometries array
6cfb12b4 56 fGeometryModules = new TObjArray();
d1cd2474 57
6cfb12b4 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));
d1cd2474 69
6cfb12b4 70 if ( moduleId5 >= 0 )
71 fGeometryModules->Add(new AliMUONGeometryModule(moduleId5));
72
73 if ( moduleId6 >= 0 )
74 fGeometryModules->Add(new AliMUONGeometryModule(moduleId6));
75}
d1cd2474 76
77//______________________________________________________________________________
78AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
79 : TObject(),
6cfb12b4 80 fGeometryModules(0),
067866a3 81 fReferenceFrame()
d1cd2474 82{
83// Default constructor
84}
85
86
87//______________________________________________________________________________
88AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
89 : TObject(rhs)
90{
30178c30 91// Protected copy constructor
92
8c343c7c 93 AliFatal("Copy constructor is not implemented.");
d1cd2474 94}
95
96//______________________________________________________________________________
97AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() {
98//
6cfb12b4 99 if (fGeometryModules) {
100 fGeometryModules->Clear(); // Sets pointers to 0 since it is not the owner
101 delete fGeometryModules;
86b48c39 102 }
d1cd2474 103}
104
105//______________________________________________________________________________
106AliMUONVGeometryBuilder&
107AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs)
108{
30178c30 109// Protected assignement operator
110
d1cd2474 111 // check assignement to self
112 if (this == &rhs) return *this;
113
8c343c7c 114 AliFatal("Assignment operator is not implemented.");
d1cd2474 115
116 return *this;
117}
118
119//
2811276d 120// private methods
121//
122
123//______________________________________________________________________________
6cfb12b4 124TGeoHMatrix
125AliMUONVGeometryBuilder::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//______________________________________________________________________________
139TString AliMUONVGeometryBuilder::ComposePath(const TString& volName,
2811276d 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
2811276d 152//______________________________________________________________________________
153void 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
6cfb12b4 160 // Get module sensitive volumes map
161 Int_t moduleId = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
162 AliMUONGeometrySVMap* svMap = GetSVMap(moduleId);
163
2811276d 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
6cfb12b4 173 Int_t moduleId = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
e118b27e 174 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 175 if (geometry->IsSensitiveVolume(volName)) {
176 //cout << ".. adding to the map "
177 // << path0 << " " << detElemId << endl;
6cfb12b4 178
179 // Map the sensitive volume to detection element
180 svMap->Add(path0, detElemId);
2811276d 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}
e118b27e 196
2811276d 197//
198// protected methods
d1cd2474 199//
200
201//______________________________________________________________________________
e118b27e 202AliMUONGeometryModule*
203AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
d1cd2474 204{
e118b27e 205// Returns the module geometry specified by moduleId
d1cd2474 206// ---
207
6cfb12b4 208 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
e118b27e 209
210 AliMUONGeometryModule* geometry
6cfb12b4 211 = (AliMUONGeometryModule*)fGeometryModules->At(i);
e118b27e 212
213 if ( geometry->GetModuleId() == moduleId) return geometry;
d1cd2474 214 }
215
216 return 0;
217}
2811276d 218
219//______________________________________________________________________________
220AliMUONGeometryEnvelopeStore*
e118b27e 221AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
2811276d 222{
e118b27e 223// Returns the envelope store of the module geometry specified by moduleId
2811276d 224// ---
225
e118b27e 226 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 227
e118b27e 228 if (!geometry) {
229 AliFatal(Form("Module geometry %d is not defined", moduleId));
2811276d 230 return 0;
231 }
232
e118b27e 233 return geometry->GetEnvelopeStore();
2811276d 234}
235
236//______________________________________________________________________________
6cfb12b4 237AliMUONGeometrySVMap*
238AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
2811276d 239{
6cfb12b4 240// Returns the transformation store of the module geometry specified by moduleId
2811276d 241// ---
242
e118b27e 243 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 244
e118b27e 245 if (!geometry) {
6cfb12b4 246 AliFatal(Form("Geometry %d is not defined", moduleId));
2811276d 247 return 0;
248 }
249
6cfb12b4 250 return geometry->GetSVMap();
2811276d 251}
252
253//______________________________________________________________________________
6cfb12b4 254void AliMUONVGeometryBuilder::SetTranslation(Int_t moduleId,
255 const TGeoTranslation& translation)
2811276d 256{
6cfb12b4 257// Sets the translation to the geometry module given by moduleId,
258// applies reference frame transformation
2811276d 259// ---
260
e118b27e 261 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 262
e118b27e 263 if (!geometry) {
264 AliFatal(Form("Geometry %d is not defined", moduleId));
6cfb12b4 265 return;
2811276d 266 }
267
6cfb12b4 268 // Apply frame transform
269 TGeoHMatrix newTransform = ConvertTransform(translation);
270
271 // Set new transformation
272 geometry->SetTransformation(newTransform);
273}
274
275
276//______________________________________________________________________________
277void 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);
2811276d 300}
301
302//
303// public functions
304//
305
6cfb12b4 306//______________________________________________________________________________
307void 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
2811276d 323//______________________________________________________________________________
e118b27e 324void AliMUONVGeometryBuilder::FillTransformations() const
2811276d 325{
326// Fills transformations store from defined geometry.
327// ---
328
6cfb12b4 329 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
e118b27e 330 AliMUONGeometryModule* geometry
6cfb12b4 331 = (AliMUONGeometryModule*)fGeometryModules->At(i);
2811276d 332 const TObjArray* envelopes
e118b27e 333 = geometry->GetEnvelopeStore()->GetEnvelopes();
334
6cfb12b4 335 AliMUONGeometryStore* detElements
336 = geometry->GetTransformer()->GetDetElementStore();
e118b27e 337
2811276d 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();
6cfb12b4 350
351 // Apply frame transform
352 TGeoHMatrix newTransform = ConvertTransform(*transform);
2811276d 353
354 // Add detection element transformation
e118b27e 355 detElements->Add(detElemId,
6cfb12b4 356 new AliMUONGeometryDetElement(detElemId, path, newTransform));
2811276d 357 }
358 }
359}
360
361//_____ _________________________________________________________________________
362void AliMUONVGeometryBuilder::RebuildSVMaps() const
363{
364// Clear the SV maps in memory and fill them from defined geometry.
365// ---
366
6cfb12b4 367 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
e118b27e 368 AliMUONGeometryModule* geometry
6cfb12b4 369 = (AliMUONGeometryModule*)fGeometryModules->At(i);
2811276d 370
371 // Clear the map
e118b27e 372 geometry->GetSVMap()->Clear();
2811276d 373
374 // Fill the map from geometry
375 const TObjArray* envelopes
e118b27e 376 = geometry->GetEnvelopeStore()->GetEnvelopes();
2811276d 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");
e118b27e 386 if (geometry->GetMotherVolume() != "ALIC") {
2811276d 387 path0 += "/";
e118b27e 388 path0 += ComposePath(geometry->GetMotherVolume(), 1);
2811276d 389 }
d639fb9f 390 if (! geometry->IsVirtual() ) {
391 path0 += "/";
392 path0 += ComposePath(geometry->GetVolume(), 1);
393 }
2811276d 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