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