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. *
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 **************************************************************************/
18 // Class AliMUONGeometryBuilder
19 // ----------------------------
20 // Manager class for geometry construction via geometry builders.
22 // Author: Ivana Hrivnacova, IPN Orsay
24 #include <TObjArray.h>
25 #include <TVirtualMC.h>
27 #include "AliMUONGeometryBuilder.h"
28 #include "AliMUONVGeometryBuilder.h"
29 #include "AliMUONGeometryModule.h"
30 #include "AliMUONGeometryEnvelope.h"
31 #include "AliMUONGeometryEnvelopeStore.h"
32 #include "AliMUONGeometryDetElement.h"
33 #include "AliMUONGeometryStore.h"
34 #include "AliMUONGeometryConstituent.h"
35 #include "AliModule.h"
40 ClassImp(AliMUONGeometryBuilder)
42 //______________________________________________________________________________
43 AliMUONGeometryBuilder::AliMUONGeometryBuilder(AliModule* module)
47 fGlobalTransformation(),
50 // Standard constructor
52 fGeometryBuilders = new TObjArray(100);
55 //______________________________________________________________________________
56 AliMUONGeometryBuilder::AliMUONGeometryBuilder()
60 fGlobalTransformation(),
63 // Default constructor
66 //______________________________________________________________________________
67 AliMUONGeometryBuilder::AliMUONGeometryBuilder(const AliMUONGeometryBuilder& right)
70 // copy constructor (not implemented)
72 AliFatal("Copy constructor not provided.");
75 //______________________________________________________________________________
76 AliMUONGeometryBuilder::~AliMUONGeometryBuilder()
79 if (fGeometryBuilders){
80 fGeometryBuilders->Delete();
81 delete fGeometryBuilders;
85 //______________________________________________________________________________
86 AliMUONGeometryBuilder&
87 AliMUONGeometryBuilder::operator=(const AliMUONGeometryBuilder& right)
89 // assignement operator (not implemented)
91 // check assignement to self
92 if (this == &right) return *this;
94 AliFatal("Assignement operator not provided.");
103 //______________________________________________________________________________
104 void 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
108 // Place the volume specified by name with the given transformation matrix
111 // Do not apply global transformation
112 // if mother volume was already placed in
113 // the new system of coordinates (that is MUON in negative Z)
114 // (as it is applied on the mother volume)
115 TGeoHMatrix transform(matrix);
116 if (mName == TString("DDIP"))
117 transform = fGlobalTransformation.Inverse() * transform;
119 // Decompose transformation
120 const Double_t* xyz = transform.GetTranslation();
121 const Double_t* rm = transform.GetRotationMatrix();
123 //cout << "Got translation: "
124 // << xyz[0] << " " << xyz[1] << " " << xyz[2] << endl;
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;
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;
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);
153 // << theta1 << " " << phi1 << " "
154 // << theta2 << " " << phi2 << " "
155 // << theta3 << " " << phi3 << endl;
157 fModule->AliMatrix(krot, theta1, phi1, theta2, phi2, theta3, phi3);
160 // Place the volume in ALIC
162 gMC->Gspos(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only);
164 gMC->Gsposp(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only,
169 //______________________________________________________________________________
170 void AliMUONGeometryBuilder::FillGlobalTransformations(
171 AliMUONVGeometryBuilder* builder)
173 // Compute and set global transformations to detection elements
174 // for each chamber geometry
177 for (Int_t j=0; j<builder->NofGeometries(); j++) {
179 AliMUONGeometryModule* geometry = builder->Geometry(j);
180 AliMUONGeometryStore* detElements = geometry->GetDetElementStore();
182 for (Int_t k=0; k<detElements->GetNofEntries(); k++) {
184 AliMUONGeometryDetElement* detElement
185 = (AliMUONGeometryDetElement*)detElements->GetEntry(k);
187 if (!detElement) AliFatal("Detection element not found.")
189 const TGeoCombiTrans* localTransform
190 = detElement->GetLocalTransformation();
192 // Compose global transformation
194 = fGlobalTransformation *
195 (*geometry->GetTransformation()) *
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);
205 // Set the global transformation to detection element
206 detElement->SetGlobalTransformation(globalTransform);
215 //_____________________________________________________________________________
216 void AliMUONGeometryBuilder::AddBuilder(AliMUONVGeometryBuilder* geomBuilder)
218 // Adds the geometry builder to the list
221 fGeometryBuilders->Add(geomBuilder);
224 //______________________________________________________________________________
225 void AliMUONGeometryBuilder::CreateGeometry()
228 // Construct geometry using geometry builders.
231 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
234 AliMUONVGeometryBuilder* builder
235 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
237 // Create geometry + envelopes
240 builder->ReadTransformations();
241 builder->CreateGeometry();
244 builder->CreateGeometry();
245 builder->SetTransformations();
248 // Place module volumes and envelopes
250 for (Int_t j=0; j<builder->NofGeometries(); j++) {
252 AliMUONGeometryModule* geometry = builder->Geometry(j);
254 // Place the module volume
255 if ( !geometry->IsVirtual() ) {
257 = fGlobalTransformation *
258 (*geometry->GetTransformation());
260 PlaceVolume(geometry->GetVolume(), geometry->GetMotherVolume(),
261 1, total, 0, 0, "ONLY");
264 // Loop over envelopes
265 const TObjArray* kEnvelopes = geometry->GetEnvelopeStore()->GetEnvelopes();
266 for (Int_t k=0; k<kEnvelopes->GetEntriesFast(); k++) {
269 AliMUONGeometryEnvelope* env = (AliMUONGeometryEnvelope*)kEnvelopes->At(k);
270 const TGeoCombiTrans* kEnvTrans = env->GetTransformation();
271 const char* only = "ONLY";
272 if (env->IsMANY()) only = "MANY";
274 if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
275 // virtual envelope + nof constituents = 0
277 // empty virtual envelope has no sense
278 AliFatal("Virtual envelope must have constituents.");
282 if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
283 // non virtual envelope + nof constituents > 0
285 // use VMC to place constituents
286 AliFatal("Non virtual envelope cannot have constituents.");
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
295 // Compound chamber transformation with the envelope one
296 if (geometry->IsVirtual()) {
298 = fGlobalTransformation *
299 (*geometry->GetTransformation()) *
301 PlaceVolume(env->GetName(), geometry->GetMotherVolume(),
302 env->GetCopyNo(), total, 0, 0, only);
307 PlaceVolume(env->GetName(), geometry->GetVolume(),
308 env->GetCopyNo(), total, 0, 0, only);
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
318 for (Int_t l=0; l<env->GetConstituents()->GetEntriesFast(); l++) {
319 AliMUONGeometryConstituent* constituent
320 = (AliMUONGeometryConstituent*)env->GetConstituents()->At(l);
322 // Compound chamber transformation with the envelope one + the constituent one
323 if (geometry->IsVirtual()) {
325 = fGlobalTransformation *
326 (*geometry->GetTransformation()) *
328 (*constituent->GetTransformation());
330 PlaceVolume(constituent->GetName(), geometry->GetMotherVolume(),
331 constituent->GetCopyNo(), total,
332 constituent->GetNpar(), constituent->GetParam(), only);
337 (*constituent->GetTransformation());
339 PlaceVolume(constituent->GetName(), geometry->GetVolume(),
340 constituent->GetCopyNo(), total,
341 constituent->GetNpar(), constituent->GetParam(), only);
345 } // end of loop over envelopes
346 } // end of loop over builder geometries
347 } // end of loop over builders
350 //_____________________________________________________________________________
351 void AliMUONGeometryBuilder::CreateMaterials()
354 // Construct materials specific to modules via builders
357 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
360 AliMUONVGeometryBuilder* builder
361 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
363 // Create materials with each builder
364 if (builder) builder->CreateMaterials();
368 //______________________________________________________________________________
369 void AliMUONGeometryBuilder::InitGeometry()
371 // Initialize geometry
374 // Set the chamber (sensitive region) GEANT identifier
376 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
379 AliMUONVGeometryBuilder* builder
380 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
382 // Read alignement data if geometry is read from Root file
383 if (gAlice->IsRootGeometry()) {
385 builder->ReadTransformations();
388 // Set sesitive volumes with each builder
389 builder->SetSensitiveVolumes();
392 // Read sensitive volume map from a file
393 builder->ReadSVMap();
394 if (!fAlign) builder->FillTransformations();
396 // Compute global transformations of detection elements
397 FillGlobalTransformations(builder);
401 //______________________________________________________________________________
402 void AliMUONGeometryBuilder::WriteTransformations()
404 // Writes transformations into files per builder
407 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
410 AliMUONVGeometryBuilder* builder
411 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
413 // Write transformations
414 builder->WriteTransformations();
418 //______________________________________________________________________________
419 void AliMUONGeometryBuilder::WriteSVMaps(Bool_t rebuild)
421 // Writes sensitive volume maps into files per builder
424 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
427 AliMUONVGeometryBuilder* builder
428 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
430 // Write transformations
431 builder->WriteSVMap(rebuild);
435 //_____________________________________________________________________________
436 void AliMUONGeometryBuilder::SetGlobalTransformation(
437 const TGeoCombiTrans& transform)
439 // Sets the global transformation
442 fGlobalTransformation = transform;
445 //_____________________________________________________________________________
446 void AliMUONGeometryBuilder::SetAlign(Bool_t align)
448 // Sets the option for alignement
453 for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
456 AliMUONVGeometryBuilder* builder
457 = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
459 for (Int_t j=0; j<builder->NofGeometries(); j++) {
461 AliMUONGeometryModule* geometry = builder->Geometry(j);
463 geometry->SetAlign(align);