Removing unused enum member to avoid warnings with gcc 3.2.3
[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 "AliMUONGeometryEnvelopeStore.h"
35#include "AliMUONGeometryEnvelope.h"
36#include "AliMUONGeometryConstituent.h"
067866a3 37#include "AliMUONGeometryBuilder.h"
fc01c870 38#include "AliMUONStringIntMap.h"
8c343c7c 39#include "AliLog.h"
d1cd2474 40
41ClassImp(AliMUONVGeometryBuilder)
42
43//______________________________________________________________________________
6cfb12b4 44AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(
45 Int_t moduleId1, Int_t moduleId2,
46 Int_t moduleId3, Int_t moduleId4,
47 Int_t moduleId5, Int_t moduleId6)
d1cd2474 48 : TObject(),
6cfb12b4 49 fGeometryModules(0),
067866a3 50 fReferenceFrame()
d1cd2474 51 {
52// Standard constructor
53
e118b27e 54 // Create the module geometries array
6cfb12b4 55 fGeometryModules = new TObjArray();
d1cd2474 56
6cfb12b4 57 if ( moduleId1 >= 0 )
58 fGeometryModules->Add(new AliMUONGeometryModule(moduleId1));
59
60 if ( moduleId2 >= 0 )
61 fGeometryModules->Add(new AliMUONGeometryModule(moduleId2));
62
63 if ( moduleId3 >= 0 )
64 fGeometryModules->Add(new AliMUONGeometryModule(moduleId3));
65
66 if ( moduleId4 >= 0 )
67 fGeometryModules->Add(new AliMUONGeometryModule(moduleId4));
d1cd2474 68
6cfb12b4 69 if ( moduleId5 >= 0 )
70 fGeometryModules->Add(new AliMUONGeometryModule(moduleId5));
71
72 if ( moduleId6 >= 0 )
73 fGeometryModules->Add(new AliMUONGeometryModule(moduleId6));
74}
d1cd2474 75
76//______________________________________________________________________________
77AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
78 : TObject(),
6cfb12b4 79 fGeometryModules(0),
067866a3 80 fReferenceFrame()
d1cd2474 81{
82// Default constructor
83}
84
85
86//______________________________________________________________________________
87AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
88 : TObject(rhs)
89{
30178c30 90// Protected copy constructor
91
8c343c7c 92 AliFatal("Copy constructor is not implemented.");
d1cd2474 93}
94
95//______________________________________________________________________________
96AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() {
97//
6cfb12b4 98 if (fGeometryModules) {
99 fGeometryModules->Clear(); // Sets pointers to 0 since it is not the owner
100 delete fGeometryModules;
86b48c39 101 }
d1cd2474 102}
103
104//______________________________________________________________________________
105AliMUONVGeometryBuilder&
106AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs)
107{
30178c30 108// Protected assignement operator
109
d1cd2474 110 // check assignement to self
111 if (this == &rhs) return *this;
112
8c343c7c 113 AliFatal("Assignment operator is not implemented.");
d1cd2474 114
115 return *this;
116}
117
118//
2811276d 119// private methods
120//
121
122//______________________________________________________________________________
6cfb12b4 123TGeoHMatrix
124AliMUONVGeometryBuilder::ConvertTransform(const TGeoHMatrix& transform) const
125{
126// Convert transformation into the reference frame
127
128 if ( fReferenceFrame.IsIdentity() )
129 return transform;
130 else {
6ec9cd4e 131 return AliMUONGeometryBuilder::Multiply( fReferenceFrame,
6cfb12b4 132 transform,
6ec9cd4e 133 fReferenceFrame.Inverse() );
134 }
135}
136
137//______________________________________________________________________________
138TGeoHMatrix
139AliMUONVGeometryBuilder::ConvertDETransform(const TGeoHMatrix& transform) const
140{
141// Convert transformation into the reference frame
142
143 if ( fReferenceFrame.IsIdentity() )
144 return transform;
145 else {
146 return AliMUONGeometryBuilder::Multiply( fReferenceFrame,
147 transform );
6cfb12b4 148 }
149}
150
151//______________________________________________________________________________
fc01c870 152TString AliMUONVGeometryBuilder::ComposePath(const TString& volName,
153 Int_t copyNo) const
2811276d 154{
155// Compose path from given volName and copyNo
156// ---
157
fc01c870 158 TString path = "/";
159 path += volName;
160 path += '_';
2811276d 161 path += copyNo;
162
163 return path;
164}
165
2811276d 166//______________________________________________________________________________
167void AliMUONVGeometryBuilder::MapSV(const TString& path0,
168 const TString& volName, Int_t detElemId) const
169{
170// Update the path with all daughters volumes recursively
171// and map it to the detection element Id if it is a sensitive volume
172// ---
173
6cfb12b4 174 // Get module sensitive volumes map
e5df8ea1 175 Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
fc01c870 176 AliMUONStringIntMap* svMap = GetSVMap(moduleId);
6cfb12b4 177
2811276d 178 Int_t nofDaughters = gMC->NofVolDaughters(volName);
179 if (nofDaughters == 0) {
180
181 // Get the name of the last volume in the path
182 Ssiz_t npos1 = path0.Last('/')+1;
fc01c870 183 Ssiz_t npos2 = path0.Last('_');
2811276d 184 TString volName(path0(npos1, npos2-npos1));
185
186 // Check if it is sensitive volume
e5df8ea1 187 Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
e118b27e 188 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
fc01c870 189 if ( geometry->IsSensitiveVolume(volName) &&
190 ! svMap->Get(path0) ) {
2811276d 191 //cout << ".. adding to the map "
192 // << path0 << " " << detElemId << endl;
6cfb12b4 193
194 // Map the sensitive volume to detection element
195 svMap->Add(path0, detElemId);
2811276d 196 }
197 return;
198 }
199
200 for (Int_t i=0; i<nofDaughters; i++) {
201 Int_t copyNo = gMC->VolDaughterCopyNo(volName, i);
202 TString newName = gMC->VolDaughterName(volName, i);
203
204 TString path = path0;
2811276d 205 path += ComposePath(newName, copyNo);
206
207 MapSV(path, newName, detElemId);
208 }
209}
e118b27e 210
2811276d 211//
212// protected methods
d1cd2474 213//
214
215//______________________________________________________________________________
e118b27e 216AliMUONGeometryModule*
217AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
d1cd2474 218{
e118b27e 219// Returns the module geometry specified by moduleId
d1cd2474 220// ---
221
6cfb12b4 222 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
e118b27e 223
224 AliMUONGeometryModule* geometry
6cfb12b4 225 = (AliMUONGeometryModule*)fGeometryModules->At(i);
e118b27e 226
227 if ( geometry->GetModuleId() == moduleId) return geometry;
d1cd2474 228 }
229
230 return 0;
231}
2811276d 232
233//______________________________________________________________________________
234AliMUONGeometryEnvelopeStore*
e118b27e 235AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
2811276d 236{
e118b27e 237// Returns the envelope store of the module geometry specified by moduleId
2811276d 238// ---
239
e118b27e 240 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 241
e118b27e 242 if (!geometry) {
243 AliFatal(Form("Module geometry %d is not defined", moduleId));
2811276d 244 return 0;
245 }
246
e118b27e 247 return geometry->GetEnvelopeStore();
2811276d 248}
249
250//______________________________________________________________________________
fc01c870 251AliMUONStringIntMap*
6cfb12b4 252AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
2811276d 253{
6cfb12b4 254// Returns the transformation store of the module geometry specified by moduleId
2811276d 255// ---
256
e118b27e 257 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 258
e118b27e 259 if (!geometry) {
6cfb12b4 260 AliFatal(Form("Geometry %d is not defined", moduleId));
2811276d 261 return 0;
262 }
263
6cfb12b4 264 return geometry->GetSVMap();
2811276d 265}
266
267//______________________________________________________________________________
6cfb12b4 268void AliMUONVGeometryBuilder::SetTranslation(Int_t moduleId,
269 const TGeoTranslation& translation)
2811276d 270{
6cfb12b4 271// Sets the translation to the geometry module given by moduleId,
272// applies reference frame transformation
2811276d 273// ---
274
e118b27e 275 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
2811276d 276
e118b27e 277 if (!geometry) {
278 AliFatal(Form("Geometry %d is not defined", moduleId));
6cfb12b4 279 return;
2811276d 280 }
281
6cfb12b4 282 // Apply frame transform
283 TGeoHMatrix newTransform = ConvertTransform(translation);
284
285 // Set new transformation
286 geometry->SetTransformation(newTransform);
287}
288
289
290//______________________________________________________________________________
291void AliMUONVGeometryBuilder::SetTransformation(Int_t moduleId,
292 const TGeoTranslation& translation,
293 const TGeoRotation& rotation)
294{
295// Sets the translation to the geometry module given by moduleId,
296// applies reference frame transformation
297// ---
298
299 AliMUONGeometryModule* geometry = GetGeometry(moduleId);
300
301 if (!geometry) {
302 AliFatal(Form("Geometry %d is not defined", moduleId));
303 return;
304 }
305
306 TGeoCombiTrans transformation
307 = TGeoCombiTrans(translation, rotation);
308
309 // Apply frame transform
55afe185 310 TGeoHMatrix newTransform = ConvertTransform(transformation);
6cfb12b4 311
312 // Set new transformation
313 geometry->SetTransformation(newTransform);
2811276d 314}
315
fc01c870 316//______________________________________________________________________________
317void AliMUONVGeometryBuilder::SetVolume(Int_t moduleId,
318 const TString& volumeName,
319 Bool_t isVirtual)
320{
321/// Set volume name, virtuality
322
323 TString path = GetGeometry(moduleId)->GetVolumePath();
324 // cout << "in AliMUONVGeometryBuilder::SetVolume " << path.Data() << endl;
325
326 if ( path == "" ) path = "/ALIC_1";
327 path += ComposePath(volumeName, 1);
328
329 GetGeometry(moduleId)->SetVolumePath(path);
330 GetGeometry(moduleId)->SetIsVirtual(isVirtual);
331 // cout << "... set " << path.Data() << endl;
332}
333
334//______________________________________________________________________________
335void AliMUONVGeometryBuilder::SetMotherVolume(Int_t moduleId,
336 const TString& volumeName)
337{
338/// Set mother volume name
339
340 TString motherVolumeName = ComposePath(volumeName, 1);
341
342 TString path = GetGeometry(moduleId)->GetVolumePath();
343 if ( path == "" ) path = "/ALIC_1";
344 path.Insert(7, motherVolumeName);
345
346 GetGeometry(moduleId)->SetVolumePath(path);
347}
348
2811276d 349//
350// public functions
351//
352
353//______________________________________________________________________________
6cfb12b4 354void AliMUONVGeometryBuilder::SetReferenceFrame(
355 const TGeoCombiTrans& referenceFrame)
356{
490da820 357/// Set reference frame to builder and to all associated geometry
358/// modules
359
6cfb12b4 360 fReferenceFrame = referenceFrame;
361
362 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
363 AliMUONGeometryModule* geometry
364 = (AliMUONGeometryModule*)fGeometryModules->At(i);
365 AliMUONGeometryEnvelopeStore* envelopeStore
366 = geometry->GetEnvelopeStore();
367
368 envelopeStore->SetReferenceFrame(referenceFrame);
369 }
370}
371
372
373//______________________________________________________________________________
fc01c870 374void AliMUONVGeometryBuilder::CreateDetElements() const
2811276d 375{
fc01c870 376/// Create detection element and fill their global and
377/// local transformations from geometry.
2811276d 378
6cfb12b4 379 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
e118b27e 380 AliMUONGeometryModule* geometry
6cfb12b4 381 = (AliMUONGeometryModule*)fGeometryModules->At(i);
fc01c870 382
2811276d 383 const TObjArray* envelopes
e118b27e 384 = geometry->GetEnvelopeStore()->GetEnvelopes();
385
6cfb12b4 386 AliMUONGeometryStore* detElements
387 = geometry->GetTransformer()->GetDetElementStore();
e118b27e 388
2811276d 389 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
390 AliMUONGeometryEnvelope* envelope
391 = (AliMUONGeometryEnvelope*)envelopes->At(j);
392
393 // skip envelope not corresponding to detection element
6ec9cd4e 394 if ( envelope->GetUniqueID() == 0) continue;
2811276d 395
396 // Get envelope data
397 Int_t detElemId = envelope->GetUniqueID();
2811276d 398
fc01c870 399 // Compose full volume path
400 TString volPath = geometry->GetVolumePath();
401 volPath += ComposePath(envelope->GetName(), envelope->GetCopyNo());
402
403 // Create detection element
6ec9cd4e 404 AliMUONGeometryDetElement* detElement
fc01c870 405 = new AliMUONGeometryDetElement(detElemId, volPath);
6ec9cd4e 406 detElements->Add(detElemId, detElement);
407
fc01c870 408 // Compose local transformation
409 const TGeoCombiTrans* transform = envelope->GetTransformation();
410 // Apply frame transform
411 TGeoHMatrix localTransform = ConvertDETransform(*transform);
412 detElement->SetLocalTransformation(localTransform);
413
6ec9cd4e 414 // Compose global transformation
415 TGeoHMatrix globalTransform
416 = AliMUONGeometryBuilder::Multiply(
417 (*geometry->GetTransformer()->GetTransformation()),
418 localTransform );
419 ;
420 // Set the global transformation to detection element
421 detElement->SetGlobalTransformation(globalTransform);
fc01c870 422
2811276d 423 }
424 }
425}
2811276d 426//_____ _________________________________________________________________________
fc01c870 427void AliMUONVGeometryBuilder::RebuildSVMaps(Bool_t withEnvelopes) const
2811276d 428{
429// Clear the SV maps in memory and fill them from defined geometry.
430// ---
431
6cfb12b4 432 for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
e118b27e 433 AliMUONGeometryModule* geometry
6cfb12b4 434 = (AliMUONGeometryModule*)fGeometryModules->At(i);
2811276d 435
436 // Clear the map
e118b27e 437 geometry->GetSVMap()->Clear();
2811276d 438
439 // Fill the map from geometry
440 const TObjArray* envelopes
e118b27e 441 = geometry->GetEnvelopeStore()->GetEnvelopes();
2811276d 442
443 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
444 AliMUONGeometryEnvelope* envelope
445 = (AliMUONGeometryEnvelope*)envelopes->At(j);
446
447 // skip envelope not corresponding to detection element
fc01c870 448 if ( envelope->GetUniqueID() == 0 ) continue;
449
450 // Get volume path of detection element
451 AliMUONGeometryDetElement* detElement
452 = geometry->GetTransformer()->GetDetElement(envelope->GetUniqueID());
453 std::string path0 = detElement->GetVolumePath().Data();
454
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());
d639fb9f 459 }
2811276d 460
fc01c870 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());
2811276d 465 }
fc01c870 466
467 if ( ! envelope->IsVirtual() )
468 MapSV(path0, envelope->GetName(), envelope->GetUniqueID());
469 else {
2811276d 470 for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
471 AliMUONGeometryConstituent* constituent
472 = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
473 TString path = path0;
2811276d 474 path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
475 MapSV(path, constituent->GetName(), envelope->GetUniqueID());
476 }
477 }
478 }
479 }
480}
481