]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONGeometryBuilder.cxx
Doxygen configuration files (Initial version)
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryBuilder.cxx
CommitLineData
d4bb94a1 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * SigmaEffect_thetadegrees *
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 purpeateose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
17//
18// Class AliMUONGeometryBuilder
19// ----------------------------
e118b27e 20// Manager class for geometry construction via geometry builders.
d4bb94a1 21//
22// Author: Ivana Hrivnacova, IPN Orsay
23
e118b27e 24#include <TObjArray.h>
d4bb94a1 25#include <TVirtualMC.h>
26
27#include "AliMUONGeometryBuilder.h"
d4bb94a1 28#include "AliMUONVGeometryBuilder.h"
e118b27e 29#include "AliMUONGeometryModule.h"
d4bb94a1 30#include "AliMUONGeometryEnvelope.h"
76497dec 31#include "AliMUONGeometryEnvelopeStore.h"
e118b27e 32#include "AliMUONGeometryDetElement.h"
33#include "AliMUONGeometryStore.h"
d4bb94a1 34#include "AliMUONGeometryConstituent.h"
e118b27e 35#include "AliModule.h"
8c343c7c 36#include "AliLog.h"
4a9de4af 37#include "AliRun.h"
38
d4bb94a1 39
40ClassImp(AliMUONGeometryBuilder)
41
e118b27e 42//______________________________________________________________________________
43AliMUONGeometryBuilder::AliMUONGeometryBuilder(AliModule* module)
d4bb94a1 44 : TObject(),
e118b27e 45 fModule(module),
76497dec 46 fAlign(false),
e118b27e 47 fGlobalTransformation(),
d4bb94a1 48 fGeometryBuilders(0)
49{
e118b27e 50// Standard constructor
51
52 fGeometryBuilders = new TObjArray(100);
53}
d4bb94a1 54
e118b27e 55//______________________________________________________________________________
56AliMUONGeometryBuilder::AliMUONGeometryBuilder()
d4bb94a1 57 : TObject(),
e118b27e 58 fModule(0),
76497dec 59 fAlign(false),
e118b27e 60 fGlobalTransformation(),
d4bb94a1 61 fGeometryBuilders(0)
62{
e118b27e 63// Default constructor
64}
d4bb94a1 65
66//______________________________________________________________________________
67AliMUONGeometryBuilder::AliMUONGeometryBuilder(const AliMUONGeometryBuilder& right)
68 : TObject(right)
69{
70 // copy constructor (not implemented)
71
8c343c7c 72 AliFatal("Copy constructor not provided.");
d4bb94a1 73}
74
75//______________________________________________________________________________
76AliMUONGeometryBuilder::~AliMUONGeometryBuilder()
77{
78// Destructor
d4bb94a1 79 if (fGeometryBuilders){
80 fGeometryBuilders->Delete();
81 delete fGeometryBuilders;
82 }
83}
84
85//______________________________________________________________________________
86AliMUONGeometryBuilder&
87AliMUONGeometryBuilder::operator=(const AliMUONGeometryBuilder& right)
88{
89 // assignement operator (not implemented)
90
91 // check assignement to self
92 if (this == &right) return *this;
93
8c343c7c 94 AliFatal("Assignement operator not provided.");
d4bb94a1 95
96 return *this;
97}
98
99//
100// private functions
101//
102
103//______________________________________________________________________________
104void AliMUONGeometryBuilder::PlaceVolume(const TString& name, const TString& mName,
105 Int_t copyNo, const TGeoHMatrix& matrix,
106 Int_t npar, Double_t* param, const char* only) const
107{
108// Place the volume specified by name with the given transformation matrix
109// ---
110
111 // Do not apply global transformation
cfbf2f7d 112 // if mother volume was already placed in
113 // the new system of coordinates (that is MUON in negative Z)
e118b27e 114 // (as it is applied on the mother volume)
d4bb94a1 115 TGeoHMatrix transform(matrix);
cfbf2f7d 116 if (mName == TString("DDIP"))
e118b27e 117 transform = fGlobalTransformation.Inverse() * transform;
d4bb94a1 118
119 // Decompose transformation
120 const Double_t* xyz = transform.GetTranslation();
121 const Double_t* rm = transform.GetRotationMatrix();
122
123 //cout << "Got translation: "
124 // << xyz[0] << " " << xyz[1] << " " << xyz[2] << endl;
125
126 //cout << "Got rotation: "
127 // << rm[0] << " " << rm[1] << " " << rm[2] << endl
128 // << rm[3] << " " << rm[4] << " " << rm[5] << endl
129 // << rm[6] << " " << rm[7] << " " << rm[8] << endl;
130
131 // Check for presence of rotation
132 // (will be nice to be available in TGeo)
133 const Double_t kTolerance = 1e-04;
134 Bool_t isRotation = true;
135 if (TMath::Abs(rm[0] - 1.) < kTolerance &&
136 TMath::Abs(rm[1] - 0.) < kTolerance &&
137 TMath::Abs(rm[2] - 0.) < kTolerance &&
138 TMath::Abs(rm[3] - 0.) < kTolerance &&
139 TMath::Abs(rm[4] - 1.) < kTolerance &&
140 TMath::Abs(rm[5] - 0.) < kTolerance &&
141 TMath::Abs(rm[6] - 0.) < kTolerance &&
142 TMath::Abs(rm[7] - 0.) < kTolerance &&
143 TMath::Abs(rm[8] - 1.) < kTolerance) isRotation = false;
144
145 Int_t krot = 0;
146 if (isRotation) {
147 TGeoRotation rot;
148 rot.SetMatrix(const_cast<Double_t*>(transform.GetRotationMatrix()));
149 Double_t theta1, phi1, theta2, phi2, theta3, phi3;
150 rot.GetAngles(theta1, phi1, theta2, phi2, theta3, phi3);
151
152 //cout << "angles: "
153 // << theta1 << " " << phi1 << " "
154 // << theta2 << " " << phi2 << " "
155 // << theta3 << " " << phi3 << endl;
156
e118b27e 157 fModule->AliMatrix(krot, theta1, phi1, theta2, phi2, theta3, phi3);
d4bb94a1 158 }
159
160 // Place the volume in ALIC
161 if (npar == 0)
162 gMC->Gspos(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only);
163 else
164 gMC->Gsposp(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only,
165 param, npar);
166
167}
168
e118b27e 169//______________________________________________________________________________
170void AliMUONGeometryBuilder::FillGlobalTransformations(
171 AliMUONVGeometryBuilder* builder)
172{
173// Compute and set global transformations to detection elements
174// for each chamber geometry
175// ---
176
177 for (Int_t j=0; j<builder->NofGeometries(); j++) {
178
179 AliMUONGeometryModule* geometry = builder->Geometry(j);
180 AliMUONGeometryStore* detElements = geometry->GetDetElementStore();
181
182 for (Int_t k=0; k<detElements->GetNofEntries(); k++) {
183
184 AliMUONGeometryDetElement* detElement
185 = (AliMUONGeometryDetElement*)detElements->GetEntry(k);
186
187 if (!detElement) AliFatal("Detection element not found.")
188
189 const TGeoCombiTrans* localTransform
190 = detElement->GetLocalTransformation();
191
192 // Compose global transformation
193 TGeoHMatrix total
194 = fGlobalTransformation *
195 (*geometry->GetTransformation()) *
e118b27e 196 (*localTransform);
e118b27e 197
198 // Convert TGeoHMatrix to TGeoCombiTrans
199 TGeoCombiTrans globalTransform(localTransform->GetName());
200 globalTransform.SetTranslation(total.GetTranslation());
201 TGeoRotation rotation;
202 rotation.SetMatrix(total.GetRotationMatrix());
203 globalTransform.SetRotation(rotation);
204
205 // Set the global transformation to detection element
206 detElement->SetGlobalTransformation(globalTransform);
207 }
208 }
209}
210
d4bb94a1 211//
212// public functions
213//
214
e118b27e 215//_____________________________________________________________________________
216void AliMUONGeometryBuilder::AddBuilder(AliMUONVGeometryBuilder* geomBuilder)
217{
218// Adds the geometry builder to the list
219// ---
220
221 fGeometryBuilders->Add(geomBuilder);
222}
223
d4bb94a1 224//______________________________________________________________________________
225void AliMUONGeometryBuilder::CreateGeometry()
226{
227//
228// Construct geometry using geometry builders.
229//
230
231 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
232
233 // Get the builder
234 AliMUONVGeometryBuilder* builder
235 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
236
e118b27e 237 // Create geometry + envelopes
238 //
239 if (fAlign) {
240 builder->ReadTransformations();
241 builder->CreateGeometry();
d4bb94a1 242 }
e118b27e 243 else {
244 builder->CreateGeometry();
245 builder->SetTransformations();
246 }
d4bb94a1 247
cfbf2f7d 248 // Place module volumes and envelopes
e118b27e 249 //
250 for (Int_t j=0; j<builder->NofGeometries(); j++) {
d4bb94a1 251
e118b27e 252 AliMUONGeometryModule* geometry = builder->Geometry(j);
cfbf2f7d 253
254 // Place the module volume
255 if ( !geometry->IsVirtual() ) {
256 TGeoHMatrix total
257 = fGlobalTransformation *
258 (*geometry->GetTransformation());
259
260 PlaceVolume(geometry->GetVolume(), geometry->GetMotherVolume(),
261 1, total, 0, 0, "ONLY");
262 }
e118b27e 263
264 // Loop over envelopes
265 const TObjArray* kEnvelopes = geometry->GetEnvelopeStore()->GetEnvelopes();
266 for (Int_t k=0; k<kEnvelopes->GetEntriesFast(); k++) {
267
268 // Get envelope
269 AliMUONGeometryEnvelope* env = (AliMUONGeometryEnvelope*)kEnvelopes->At(k);
270 const TGeoCombiTrans* kEnvTrans = env->GetTransformation();
271 const char* only = "ONLY";
272 if (env->IsMANY()) only = "MANY";
273
274 if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
275 // virtual envelope + nof constituents = 0
276 // => not allowed;
277 // empty virtual envelope has no sense
278 AliFatal("Virtual envelope must have constituents.");
279 return;
280 }
d4bb94a1 281
e118b27e 282 if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
283 // non virtual envelope + nof constituents > 0
284 // => not allowed;
285 // use VMC to place constituents
286 AliFatal("Non virtual envelope cannot have constituents.");
287 return;
288 }
289
290 if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
291 // non virtual envelope + nof constituents = 0
292 // => place envelope in ALICE by composed transformation:
293 // Tglobal * Tch * Tenv
294
295 // Compound chamber transformation with the envelope one
cfbf2f7d 296 if (geometry->IsVirtual()) {
297 TGeoHMatrix total
298 = fGlobalTransformation *
299 (*geometry->GetTransformation()) *
300 (*kEnvTrans);
301 PlaceVolume(env->GetName(), geometry->GetMotherVolume(),
302 env->GetCopyNo(), total, 0, 0, only);
303 }
304 else {
305 TGeoHMatrix total
306 = (*kEnvTrans);
307 PlaceVolume(env->GetName(), geometry->GetVolume(),
308 env->GetCopyNo(), total, 0, 0, only);
309 }
e118b27e 310 }
311
312 if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
313 // virtual envelope + nof constituents > 0
314 // => do not place envelope and place constituents
315 // in ALICE by composed transformation:
316 // Tglobal * Tch * Tenv * Tconst
d4bb94a1 317
e118b27e 318 for (Int_t l=0; l<env->GetConstituents()->GetEntriesFast(); l++) {
319 AliMUONGeometryConstituent* constituent
320 = (AliMUONGeometryConstituent*)env->GetConstituents()->At(l);
321
322 // Compound chamber transformation with the envelope one + the constituent one
cfbf2f7d 323 if (geometry->IsVirtual()) {
324 TGeoHMatrix total
325 = fGlobalTransformation *
326 (*geometry->GetTransformation()) *
327 (*kEnvTrans) *
328 (*constituent->GetTransformation());
329
330 PlaceVolume(constituent->GetName(), geometry->GetMotherVolume(),
331 constituent->GetCopyNo(), total,
332 constituent->GetNpar(), constituent->GetParam(), only);
333 }
334 else {
335 TGeoHMatrix total
336 = (*kEnvTrans) *
337 (*constituent->GetTransformation());
338
339 PlaceVolume(constituent->GetName(), geometry->GetVolume(),
340 constituent->GetCopyNo(), total,
341 constituent->GetNpar(), constituent->GetParam(), only);
342 }
e118b27e 343 }
d4bb94a1 344 }
e118b27e 345 } // end of loop over envelopes
346 } // end of loop over builder geometries
347 } // end of loop over builders
d4bb94a1 348}
349
350//_____________________________________________________________________________
351void AliMUONGeometryBuilder::CreateMaterials()
352{
e118b27e 353//
354// Construct materials specific to modules via builders
355//
d4bb94a1 356
357 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
358
359 // Get the builder
360 AliMUONVGeometryBuilder* builder
361 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
362
363 // Create materials with each builder
364 if (builder) builder->CreateMaterials();
365 }
366}
367
368//______________________________________________________________________________
369void AliMUONGeometryBuilder::InitGeometry()
370{
371 // Initialize geometry
372 // ---
373
d4bb94a1 374 // Set the chamber (sensitive region) GEANT identifier
375 //
376 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
377
378 // Get the builder
379 AliMUONVGeometryBuilder* builder
380 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
381
4a9de4af 382 // Read alignement data if geometry is read from Root file
383 if (gAlice->IsRootGeometry()) {
384 fAlign = true;
385 builder->ReadTransformations();
386 }
387
d4bb94a1 388 // Set sesitive volumes with each builder
76497dec 389 builder->SetSensitiveVolumes();
e118b27e 390
4a9de4af 391
76497dec 392 // Read sensitive volume map from a file
393 builder->ReadSVMap();
394 if (!fAlign) builder->FillTransformations();
e118b27e 395
396 // Compute global transformations of detection elements
397 FillGlobalTransformations(builder);
398 }
76497dec 399}
400
401//______________________________________________________________________________
402void AliMUONGeometryBuilder::WriteTransformations()
403{
404 // Writes transformations into files per builder
405 // ---
406
407 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
408
409 // Get the builder
410 AliMUONVGeometryBuilder* builder
411 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
412
413 // Write transformations
414 builder->WriteTransformations();
415 }
416}
417
418//______________________________________________________________________________
419void AliMUONGeometryBuilder::WriteSVMaps(Bool_t rebuild)
420{
421 // Writes sensitive volume maps into files per builder
422 // ---
423
424 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
425
426 // Get the builder
427 AliMUONVGeometryBuilder* builder
428 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
429
430 // Write transformations
431 builder->WriteSVMap(rebuild);
d4bb94a1 432 }
433}
434
435//_____________________________________________________________________________
e118b27e 436void AliMUONGeometryBuilder::SetGlobalTransformation(
437 const TGeoCombiTrans& transform)
d4bb94a1 438{
e118b27e 439// Sets the global transformation
d4bb94a1 440// ---
441
e118b27e 442 fGlobalTransformation = transform;
443}
d4bb94a1 444
76497dec 445//_____________________________________________________________________________
446void AliMUONGeometryBuilder::SetAlign(Bool_t align)
447{
448// Sets the option for alignement
449// ---
450
451 fAlign = align;
452
e118b27e 453 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
454
455 // Get the builder
456 AliMUONVGeometryBuilder* builder
457 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
76497dec 458
e118b27e 459 for (Int_t j=0; j<builder->NofGeometries(); j++) {
76497dec 460
e118b27e 461 AliMUONGeometryModule* geometry = builder->Geometry(j);
462
463 geometry->SetAlign(align);
464 }
76497dec 465 }
466}