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