]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONGeometryBuilder.cxx
Use of appropriate sensor depending response objects in SPD simulation
[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"
6cfb12b4 29#include "AliMUONGeometry.h"
30#include "AliMUONGeometryTransformer.h"
e118b27e 31#include "AliMUONGeometryModule.h"
6cfb12b4 32#include "AliMUONGeometryModuleTransformer.h"
d4bb94a1 33#include "AliMUONGeometryEnvelope.h"
76497dec 34#include "AliMUONGeometryEnvelopeStore.h"
e118b27e 35#include "AliMUONGeometryDetElement.h"
36#include "AliMUONGeometryStore.h"
6cfb12b4 37#include "AliMUONGeometryConstituent.h"
e118b27e 38#include "AliModule.h"
8c343c7c 39#include "AliLog.h"
4a9de4af 40#include "AliRun.h"
41
d4bb94a1 42
43ClassImp(AliMUONGeometryBuilder)
eea63c73 44
45// static data members
d4bb94a1 46
eea63c73 47const TString AliMUONGeometryBuilder::fgkDefaultTransformFileName = "transform.dat";
48const TString AliMUONGeometryBuilder::fgkDefaultSVMapFileName = "svmap.dat";
49const TString AliMUONGeometryBuilder::fgkOutFileNameExtension = ".out";
50
067866a3 51// static functions
52
53//______________________________________________________________________________
54TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1,
55 const TGeoMatrix& m2)
56{
57/// Temporary fix for problem with matrix multiplication in Root 5.02/00
58
59 if (m1.IsIdentity() && m2.IsIdentity()) return TGeoHMatrix();
60
61 if (m1.IsIdentity()) return m2;
62
63 if (m2.IsIdentity()) return m1;
64
65 return m1 * m2;
66}
67
68//______________________________________________________________________________
69TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1,
70 const TGeoMatrix& m2,
71 const TGeoMatrix& m3)
72{
73/// Temporary fix for problem with matrix multiplication in Root 5.02/00
74
75 if (m1.IsIdentity() && m2.IsIdentity() & m3.IsIdentity())
76 return TGeoHMatrix();
77
78 if (m1.IsIdentity()) return Multiply(m2, m3);
79
80 if (m2.IsIdentity()) return Multiply(m1, m3);
81
82 if (m3.IsIdentity()) return Multiply(m1, m2);
83
84 return m1 * m2 * m3;
85}
86
87//______________________________________________________________________________
88TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1,
89 const TGeoMatrix& m2,
90 const TGeoMatrix& m3,
91 const TGeoMatrix& m4)
92{
93/// Temporary fix for problem with matrix multiplication in Root 5.02/00
94
95 if (m1.IsIdentity() && m2.IsIdentity() & m3.IsIdentity() & m4.IsIdentity())
96 return TGeoHMatrix();
97
98 if (m1.IsIdentity()) return Multiply(m2, m3, m4);
99
100 if (m2.IsIdentity()) return Multiply(m1, m3, m4);
101
102 if (m3.IsIdentity()) return Multiply(m1, m2, m4);
103
104 if (m4.IsIdentity()) return Multiply(m1, m2, m3);
105
106 return m1 * m2 * m3 * m4;
107}
108
e118b27e 109//______________________________________________________________________________
110AliMUONGeometryBuilder::AliMUONGeometryBuilder(AliModule* module)
d4bb94a1 111 : TObject(),
e118b27e 112 fModule(module),
76497dec 113 fAlign(false),
eea63c73 114 fTransformFileName(fgkDefaultTransformFileName),
115 fSVMapFileName(fgkDefaultSVMapFileName),
e118b27e 116 fGlobalTransformation(),
6cfb12b4 117 fGeometryBuilders(0),
118 fGeometry(0)
d4bb94a1 119{
692de412 120/// Standard constructor
e118b27e 121
6cfb12b4 122 fGeometryBuilders = new TObjArray();
123 fGeometryBuilders->SetOwner(true);
124
125 fGeometry = new AliMUONGeometry(true);
126
127 // Define the global transformation:
128 // Transformation from the old ALICE coordinate system to a new one:
129 // x->-x, z->-z
130 TGeoRotation* rotGlobal
131 = new TGeoRotation("rotGlobal", 90., 180., 90., 90., 180., 0.);
132 fGlobalTransformation = TGeoCombiTrans(0., 0., 0., rotGlobal);
e118b27e 133}
d4bb94a1 134
e118b27e 135//______________________________________________________________________________
136AliMUONGeometryBuilder::AliMUONGeometryBuilder()
d4bb94a1 137 : TObject(),
e118b27e 138 fModule(0),
76497dec 139 fAlign(false),
eea63c73 140 fTransformFileName(),
141 fSVMapFileName(),
e118b27e 142 fGlobalTransformation(),
6cfb12b4 143 fGeometryBuilders(0),
144 fGeometry(0)
d4bb94a1 145{
692de412 146/// Default constructor
e118b27e 147}
d4bb94a1 148
149//______________________________________________________________________________
150AliMUONGeometryBuilder::AliMUONGeometryBuilder(const AliMUONGeometryBuilder& right)
151 : TObject(right)
152{
692de412 153/// Copy constructor (not implemented)
d4bb94a1 154
8c343c7c 155 AliFatal("Copy constructor not provided.");
d4bb94a1 156}
157
158//______________________________________________________________________________
159AliMUONGeometryBuilder::~AliMUONGeometryBuilder()
160{
692de412 161/// Destructor
6cfb12b4 162
163 delete fGeometryBuilders;
164 delete fGeometry;
d4bb94a1 165}
166
167//______________________________________________________________________________
168AliMUONGeometryBuilder&
169AliMUONGeometryBuilder::operator=(const AliMUONGeometryBuilder& right)
170{
692de412 171/// Assignement operator (not implemented)
d4bb94a1 172
173 // check assignement to self
174 if (this == &right) return *this;
175
8c343c7c 176 AliFatal("Assignement operator not provided.");
d4bb94a1 177
178 return *this;
179}
180
181//
182// private functions
183//
184
185//______________________________________________________________________________
186void AliMUONGeometryBuilder::PlaceVolume(const TString& name, const TString& mName,
187 Int_t copyNo, const TGeoHMatrix& matrix,
188 Int_t npar, Double_t* param, const char* only) const
189{
692de412 190/// Place the volume specified by name with the given transformation matrix
d4bb94a1 191
6cfb12b4 192 TGeoHMatrix transform(matrix);
d4bb94a1 193 // Do not apply global transformation
cfbf2f7d 194 // if mother volume was already placed in
195 // the new system of coordinates (that is MUON in negative Z)
e118b27e 196 // (as it is applied on the mother volume)
cfbf2f7d 197 if (mName == TString("DDIP"))
e118b27e 198 transform = fGlobalTransformation.Inverse() * transform;
d4bb94a1 199
200 // Decompose transformation
201 const Double_t* xyz = transform.GetTranslation();
202 const Double_t* rm = transform.GetRotationMatrix();
203
204 //cout << "Got translation: "
205 // << xyz[0] << " " << xyz[1] << " " << xyz[2] << endl;
206
207 //cout << "Got rotation: "
208 // << rm[0] << " " << rm[1] << " " << rm[2] << endl
209 // << rm[3] << " " << rm[4] << " " << rm[5] << endl
210 // << rm[6] << " " << rm[7] << " " << rm[8] << endl;
211
212 // Check for presence of rotation
213 // (will be nice to be available in TGeo)
214 const Double_t kTolerance = 1e-04;
215 Bool_t isRotation = true;
216 if (TMath::Abs(rm[0] - 1.) < kTolerance &&
217 TMath::Abs(rm[1] - 0.) < kTolerance &&
218 TMath::Abs(rm[2] - 0.) < kTolerance &&
219 TMath::Abs(rm[3] - 0.) < kTolerance &&
220 TMath::Abs(rm[4] - 1.) < kTolerance &&
221 TMath::Abs(rm[5] - 0.) < kTolerance &&
222 TMath::Abs(rm[6] - 0.) < kTolerance &&
223 TMath::Abs(rm[7] - 0.) < kTolerance &&
224 TMath::Abs(rm[8] - 1.) < kTolerance) isRotation = false;
225
226 Int_t krot = 0;
227 if (isRotation) {
228 TGeoRotation rot;
229 rot.SetMatrix(const_cast<Double_t*>(transform.GetRotationMatrix()));
230 Double_t theta1, phi1, theta2, phi2, theta3, phi3;
231 rot.GetAngles(theta1, phi1, theta2, phi2, theta3, phi3);
232
233 //cout << "angles: "
234 // << theta1 << " " << phi1 << " "
235 // << theta2 << " " << phi2 << " "
236 // << theta3 << " " << phi3 << endl;
237
e118b27e 238 fModule->AliMatrix(krot, theta1, phi1, theta2, phi2, theta3, phi3);
d4bb94a1 239 }
240
241 // Place the volume in ALIC
242 if (npar == 0)
243 gMC->Gspos(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only);
244 else
245 gMC->Gsposp(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only,
246 param, npar);
247
248}
249
8618c022 250//_____________________________________________________________________________
251void AliMUONGeometryBuilder::SetAlign(AliMUONVGeometryBuilder* builder)
252{
253/// Set align option to all geometry modules associated with the builder
254
255 for (Int_t j=0; j<builder->NofGeometries(); j++) {
256
257 AliMUONGeometryModule* geometry = builder->Geometry(j);
258
259 geometry->SetAlign(fAlign);
260 }
261}
262
d4bb94a1 263//
264// public functions
265//
266
e118b27e 267//_____________________________________________________________________________
268void AliMUONGeometryBuilder::AddBuilder(AliMUONVGeometryBuilder* geomBuilder)
269{
067866a3 270/// Add the geometry builder to the list
e118b27e 271
272 fGeometryBuilders->Add(geomBuilder);
8618c022 273
6cfb12b4 274 // Pass geometry modules created in the to the geometry parametrisation
275 for (Int_t i=0; i<geomBuilder->NofGeometries(); i++) {
276 fGeometry->AddModule(geomBuilder->Geometry(i));
277 }
278
279 if (geomBuilder->ApplyGlobalTransformation())
280 geomBuilder->SetReferenceFrame(fGlobalTransformation);
281
8618c022 282 SetAlign(geomBuilder);
e118b27e 283}
284
d4bb94a1 285//______________________________________________________________________________
286void AliMUONGeometryBuilder::CreateGeometry()
287{
692de412 288/// Construct geometry using geometry builders.
d4bb94a1 289
6cfb12b4 290 if (fAlign) ReadTransformations();
291
d4bb94a1 292 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
293
294 // Get the builder
295 AliMUONVGeometryBuilder* builder
296 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
297
e118b27e 298 // Create geometry + envelopes
299 //
6cfb12b4 300 builder->CreateGeometry();
301 if (!fAlign) builder->SetTransformations();
302
cfbf2f7d 303 // Place module volumes and envelopes
e118b27e 304 //
305 for (Int_t j=0; j<builder->NofGeometries(); j++) {
d4bb94a1 306
e118b27e 307 AliMUONGeometryModule* geometry = builder->Geometry(j);
6cfb12b4 308 const TGeoCombiTrans* kModuleTransform
309 = geometry->GetTransformer()->GetTransformation();
cfbf2f7d 310
311 // Place the module volume
312 if ( !geometry->IsVirtual() ) {
6cfb12b4 313 PlaceVolume(geometry->GetVolume(), geometry->GetMotherVolume(),
314 1, *kModuleTransform, 0, 0, "ONLY");
cfbf2f7d 315 }
e118b27e 316
6cfb12b4 317 TGeoCombiTrans appliedGlobalTransform;
318 if (builder->ApplyGlobalTransformation())
319 appliedGlobalTransform = fGlobalTransformation;
320
e118b27e 321 // Loop over envelopes
6cfb12b4 322 const TObjArray* kEnvelopes
323 = geometry->GetEnvelopeStore()->GetEnvelopes();
e118b27e 324 for (Int_t k=0; k<kEnvelopes->GetEntriesFast(); k++) {
325
326 // Get envelope
6cfb12b4 327 AliMUONGeometryEnvelope* env
328 = (AliMUONGeometryEnvelope*)kEnvelopes->At(k);
329
e118b27e 330 const TGeoCombiTrans* kEnvTrans = env->GetTransformation();
331 const char* only = "ONLY";
332 if (env->IsMANY()) only = "MANY";
333
334 if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
335 // virtual envelope + nof constituents = 0
336 // => not allowed;
337 // empty virtual envelope has no sense
338 AliFatal("Virtual envelope must have constituents.");
339 return;
340 }
d4bb94a1 341
e118b27e 342 if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
343 // non virtual envelope + nof constituents > 0
344 // => not allowed;
345 // use VMC to place constituents
346 AliFatal("Non virtual envelope cannot have constituents.");
347 return;
348 }
349
350 if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
351 // non virtual envelope + nof constituents = 0
352 // => place envelope in ALICE by composed transformation:
6cfb12b4 353 // Tch * [Tglobal] * Tenv
e118b27e 354
355 // Compound chamber transformation with the envelope one
cfbf2f7d 356 if (geometry->IsVirtual()) {
357 TGeoHMatrix total
6cfb12b4 358 = Multiply( (*kModuleTransform),
359 appliedGlobalTransform,
067866a3 360 (*kEnvTrans) );
cfbf2f7d 361 PlaceVolume(env->GetName(), geometry->GetMotherVolume(),
362 env->GetCopyNo(), total, 0, 0, only);
363 }
364 else {
365 TGeoHMatrix total
6cfb12b4 366 = Multiply( appliedGlobalTransform,
367 (*kEnvTrans) );
cfbf2f7d 368 PlaceVolume(env->GetName(), geometry->GetVolume(),
369 env->GetCopyNo(), total, 0, 0, only);
370 }
e118b27e 371 }
372
373 if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
374 // virtual envelope + nof constituents > 0
375 // => do not place envelope and place constituents
376 // in ALICE by composed transformation:
6cfb12b4 377 // Tch * [Tglobal] * Tenv * Tconst
d4bb94a1 378
e118b27e 379 for (Int_t l=0; l<env->GetConstituents()->GetEntriesFast(); l++) {
380 AliMUONGeometryConstituent* constituent
381 = (AliMUONGeometryConstituent*)env->GetConstituents()->At(l);
382
383 // Compound chamber transformation with the envelope one + the constituent one
cfbf2f7d 384 if (geometry->IsVirtual()) {
385 TGeoHMatrix total
6cfb12b4 386 = Multiply ( (*kModuleTransform),
387 appliedGlobalTransform,
388 (*kEnvTrans),
067866a3 389 (*constituent->GetTransformation()) );
cfbf2f7d 390
391 PlaceVolume(constituent->GetName(), geometry->GetMotherVolume(),
392 constituent->GetCopyNo(), total,
393 constituent->GetNpar(), constituent->GetParam(), only);
394 }
395 else {
396 TGeoHMatrix total
6cfb12b4 397 = Multiply ( appliedGlobalTransform,
398 (*kEnvTrans),
067866a3 399 (*constituent->GetTransformation()) );
cfbf2f7d 400
401 PlaceVolume(constituent->GetName(), geometry->GetVolume(),
402 constituent->GetCopyNo(), total,
403 constituent->GetNpar(), constituent->GetParam(), only);
404 }
e118b27e 405 }
d4bb94a1 406 }
e118b27e 407 } // end of loop over envelopes
408 } // end of loop over builder geometries
409 } // end of loop over builders
d4bb94a1 410}
411
412//_____________________________________________________________________________
413void AliMUONGeometryBuilder::CreateMaterials()
414{
692de412 415/// Construct materials specific to modules via builders
d4bb94a1 416
417 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
418
419 // Get the builder
420 AliMUONVGeometryBuilder* builder
421 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
422
423 // Create materials with each builder
424 if (builder) builder->CreateMaterials();
425 }
426}
427
428//______________________________________________________________________________
6cfb12b4 429void AliMUONGeometryBuilder::InitGeometry(const TString& svmapFileName)
d4bb94a1 430{
692de412 431/// Initialize geometry
d4bb94a1 432
6cfb12b4 433 // Read alignement data if geometry is read from Root file
063619ad 434 if ( gAlice->IsRootGeometry() ) {
6cfb12b4 435 fAlign = true;
436 ReadTransformations();
437 }
438
439 // Read sensitive volume map from a file
440 fGeometry->ReadSVMap(svmapFileName);
441
d4bb94a1 442 // Set the chamber (sensitive region) GEANT identifier
443 //
444 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
445
446 // Get the builder
447 AliMUONVGeometryBuilder* builder
448 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
449
6cfb12b4 450 // Set sensitive volumes with each builder
76497dec 451 builder->SetSensitiveVolumes();
4a9de4af 452
6cfb12b4 453 if (!fAlign) {
454 // Fill local transformations from built geometry
455 builder->FillTransformations();
6cfb12b4 456 }
e118b27e 457 }
76497dec 458}
459
eea63c73 460
461
76497dec 462//______________________________________________________________________________
6cfb12b4 463void AliMUONGeometryBuilder::ReadTransformations(const TString& fileName)
76497dec 464{
6cfb12b4 465/// Read transformations from ASCII files
466/// and store them in the geometry parametrisation
76497dec 467
6cfb12b4 468 // Read transformations
469 //
470 AliMUONGeometryTransformer* geomTransformer = fGeometry->GetTransformer();
471 geomTransformer->ReadTransformations(fileName);
76497dec 472}
473
474//______________________________________________________________________________
6cfb12b4 475void AliMUONGeometryBuilder::WriteTransformations(const TString& fileName)
76497dec 476{
6cfb12b4 477/// Write transformations into files per builder
76497dec 478
6cfb12b4 479 AliMUONGeometryTransformer* geomTransformer = fGeometry->GetTransformer();
480 geomTransformer->WriteTransformations(fileName);
d4bb94a1 481}
482
6cfb12b4 483//______________________________________________________________________________
eea63c73 484void AliMUONGeometryBuilder::WriteSVMaps(const TString& fileName,
485 Bool_t rebuild)
d4bb94a1 486{
6cfb12b4 487/// Write sensitive volume maps into files per builder
488
489 // Rebuild sv maps
490 //
491 if (rebuild)
492 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
d4bb94a1 493
6cfb12b4 494 AliMUONVGeometryBuilder* builder
495 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
496
497 builder->RebuildSVMaps();
498 }
499
500 // Write maps in file
501 fGeometry->WriteSVMap(fileName);
502}
d4bb94a1 503
76497dec 504//_____________________________________________________________________________
505void AliMUONGeometryBuilder::SetAlign(Bool_t align)
506{
067866a3 507/// Set the option for alignement
76497dec 508
509 fAlign = align;
510
e118b27e 511 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
512
e118b27e 513 AliMUONVGeometryBuilder* builder
514 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
8618c022 515
516 SetAlign(builder);
517 }
76497dec 518}
eea63c73 519
520//_____________________________________________________________________________
521void AliMUONGeometryBuilder::SetAlign(const TString& fileName, Bool_t align)
522{
523/// Set the option for alignement
524
525 fTransformFileName = fileName;
526 fAlign = align;
527
528 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
529
530 AliMUONVGeometryBuilder* builder
531 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
532
533 SetAlign(builder);
534 }
535}