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