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