]>
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" | |
e118b27e | 38 | #include "AliMUONVGeometryDEIndexing.h" |
8c343c7c | 39 | #include "AliLog.h" |
d1cd2474 | 40 | |
41 | ClassImp(AliMUONVGeometryBuilder) | |
42 | ||
2811276d | 43 | const TString AliMUONVGeometryBuilder::fgkTransformFileNamePrefix = "transform_"; |
44 | const TString AliMUONVGeometryBuilder::fgkSVMapFileNamePrefix = "svmap_"; | |
45 | const TString AliMUONVGeometryBuilder::fgkOutFileNameSuffix = ".out"; | |
46 | ||
d1cd2474 | 47 | //______________________________________________________________________________ |
2811276d | 48 | AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const TString& fileName, |
e118b27e | 49 | AliMUONGeometryModule* mg1, AliMUONGeometryModule* mg2, |
50 | AliMUONGeometryModule* mg3, AliMUONGeometryModule* mg4, | |
51 | AliMUONGeometryModule* mg5, AliMUONGeometryModule* mg6) | |
d1cd2474 | 52 | : TObject(), |
2811276d | 53 | fTransformFileName(fgkTransformFileNamePrefix+fileName), |
54 | fSVMapFileName(fgkSVMapFileNamePrefix+fileName), | |
e118b27e | 55 | fModuleGeometries(0) |
d1cd2474 | 56 | { |
57 | // Standard constructor | |
58 | ||
e118b27e | 59 | // Create the module geometries array |
60 | fModuleGeometries = new TObjArray(); | |
d1cd2474 | 61 | |
e118b27e | 62 | if (mg1) fModuleGeometries->Add(mg1); |
63 | if (mg2) fModuleGeometries->Add(mg2); | |
64 | if (mg3) fModuleGeometries->Add(mg3); | |
65 | if (mg4) fModuleGeometries->Add(mg4); | |
66 | if (mg5) fModuleGeometries->Add(mg5); | |
67 | if (mg6) fModuleGeometries->Add(mg6); | |
d1cd2474 | 68 | } |
69 | ||
70 | ||
71 | //______________________________________________________________________________ | |
72 | AliMUONVGeometryBuilder::AliMUONVGeometryBuilder() | |
73 | : TObject(), | |
2811276d | 74 | fTransformFileName(), |
75 | fSVMapFileName(), | |
e118b27e | 76 | fModuleGeometries(0) |
d1cd2474 | 77 | { |
78 | // Default constructor | |
79 | } | |
80 | ||
81 | ||
82 | //______________________________________________________________________________ | |
83 | AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs) | |
84 | : TObject(rhs) | |
85 | { | |
30178c30 | 86 | // Protected copy constructor |
87 | ||
8c343c7c | 88 | AliFatal("Copy constructor is not implemented."); |
d1cd2474 | 89 | } |
90 | ||
91 | //______________________________________________________________________________ | |
92 | AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() { | |
93 | // | |
e118b27e | 94 | if (fModuleGeometries) { |
95 | fModuleGeometries->Clear(); // Sets pointers to 0 since it is not the owner | |
96 | delete fModuleGeometries; | |
86b48c39 | 97 | } |
d1cd2474 | 98 | } |
99 | ||
100 | //______________________________________________________________________________ | |
101 | AliMUONVGeometryBuilder& | |
102 | AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs) | |
103 | { | |
30178c30 | 104 | // Protected assignement operator |
105 | ||
d1cd2474 | 106 | // check assignement to self |
107 | if (this == &rhs) return *this; | |
108 | ||
8c343c7c | 109 | AliFatal("Assignment operator is not implemented."); |
d1cd2474 | 110 | |
111 | return *this; | |
112 | } | |
113 | ||
114 | // | |
2811276d | 115 | // private methods |
116 | // | |
117 | ||
118 | //______________________________________________________________________________ | |
119 | TString AliMUONVGeometryBuilder::ComposePath(const TString& volName, | |
120 | Int_t copyNo) const | |
121 | { | |
122 | // Compose path from given volName and copyNo | |
123 | // --- | |
124 | ||
125 | TString path(volName); | |
126 | path += "."; | |
127 | path += copyNo; | |
128 | ||
129 | return path; | |
130 | } | |
131 | ||
2811276d | 132 | //______________________________________________________________________________ |
133 | void AliMUONVGeometryBuilder::MapSV(const TString& path0, | |
134 | const TString& volName, Int_t detElemId) const | |
135 | { | |
136 | // Update the path with all daughters volumes recursively | |
137 | // and map it to the detection element Id if it is a sensitive volume | |
138 | // --- | |
139 | ||
140 | Int_t nofDaughters = gMC->NofVolDaughters(volName); | |
141 | if (nofDaughters == 0) { | |
142 | ||
143 | // Get the name of the last volume in the path | |
144 | Ssiz_t npos1 = path0.Last('/')+1; | |
145 | Ssiz_t npos2 = path0.Last('.'); | |
146 | TString volName(path0(npos1, npos2-npos1)); | |
147 | ||
148 | // Check if it is sensitive volume | |
e0a49962 | 149 | Int_t moduleId = AliMUONVGeometryDEIndexing::GetModuleId(detElemId); |
e118b27e | 150 | AliMUONGeometryModule* geometry = GetGeometry(moduleId); |
2811276d | 151 | if (geometry->IsSensitiveVolume(volName)) { |
152 | //cout << ".. adding to the map " | |
153 | // << path0 << " " << detElemId << endl; | |
154 | FillData(path0, detElemId); | |
155 | } | |
156 | return; | |
157 | } | |
158 | ||
159 | for (Int_t i=0; i<nofDaughters; i++) { | |
160 | Int_t copyNo = gMC->VolDaughterCopyNo(volName, i); | |
161 | TString newName = gMC->VolDaughterName(volName, i); | |
162 | ||
163 | TString path = path0; | |
164 | path += "/"; | |
165 | path += ComposePath(newName, copyNo); | |
166 | ||
167 | MapSV(path, newName, detElemId); | |
168 | } | |
169 | } | |
e118b27e | 170 | |
2811276d | 171 | //______________________________________________________________________________ |
e118b27e | 172 | void AliMUONVGeometryBuilder::FillData(Int_t moduleId, Int_t nofDetElements, |
2811276d | 173 | Double_t x, Double_t y, Double_t z, |
174 | Double_t a1, Double_t a2, Double_t a3, | |
175 | Double_t a4, Double_t a5, Double_t a6) const | |
176 | { | |
e118b27e | 177 | // Fill the transformation of the module. |
2811276d | 178 | // --- |
179 | ||
e118b27e | 180 | moduleId--; |
181 | // Modules numbers in the file are starting from 1 | |
182 | ||
183 | GetGeometry(moduleId) | |
184 | ->GetDEIndexing()->SetNofDetElements(nofDetElements); | |
185 | GetGeometry(moduleId) | |
2811276d | 186 | ->SetTranslation(TGeoTranslation(x, y, z)); |
e118b27e | 187 | GetGeometry(moduleId) |
2811276d | 188 | ->SetRotation(TGeoRotation("rot", a1, a2, a3, a4, a5, a6)); |
189 | } | |
190 | ||
191 | //______________________________________________________________________________ | |
192 | void AliMUONVGeometryBuilder::FillData( | |
193 | Int_t detElemId, const TString& volName, Int_t copyNo, | |
194 | Double_t x, Double_t y, Double_t z, | |
195 | Double_t a1, Double_t a2, Double_t a3, | |
196 | Double_t a4, Double_t a5, Double_t a6) const | |
197 | { | |
198 | // Fill the transformation of the detection element. | |
199 | // --- | |
200 | ||
e118b27e | 201 | // Module Id |
202 | Int_t moduleId | |
203 | = AliMUONVGeometryDEIndexing::GetModuleId(detElemId); | |
2811276d | 204 | |
205 | // Compose path | |
206 | TString path = ComposePath(volName, copyNo); | |
207 | ||
208 | // Compose matrix | |
209 | TGeoCombiTrans transform(path, x, y, z, | |
210 | new TGeoRotation(path, a1, a2, a3, a4, a5, a6)); | |
211 | ||
e118b27e | 212 | // Get detection element store |
213 | AliMUONGeometryStore* detElements = GetDetElements(moduleId); | |
214 | ||
215 | // Add detection element | |
216 | detElements->Add(detElemId, | |
217 | new AliMUONGeometryDetElement(detElemId, path, transform)); | |
2811276d | 218 | } |
219 | ||
220 | //______________________________________________________________________________ | |
221 | void AliMUONVGeometryBuilder::FillData( | |
222 | const TString& sensVolumePath, Int_t detElemId) const | |
223 | { | |
224 | // Fill the mapping of the sensitive volume path to the detection element. | |
225 | // --- | |
226 | ||
e118b27e | 227 | // Module Id |
228 | Int_t moduleId | |
229 | = AliMUONVGeometryDEIndexing::GetModuleId(detElemId); | |
2811276d | 230 | |
e118b27e | 231 | // Get module sensitive volumes map |
232 | AliMUONGeometrySVMap* svMap = GetSVMap(moduleId); | |
2811276d | 233 | |
234 | // Map the sensitive volume to detection element | |
235 | svMap->Add(sensVolumePath, detElemId); | |
236 | } | |
237 | ||
238 | //______________________________________________________________________________ | |
239 | TString AliMUONVGeometryBuilder::ReadData1(ifstream& in) const | |
240 | { | |
e118b27e | 241 | // Reads and fills modules transformations from a file |
2811276d | 242 | // Returns true, if reading finished correctly. |
243 | // --- | |
244 | ||
245 | TString key("CH"); | |
246 | while ( key == TString("CH") ) { | |
e118b27e | 247 | Int_t id, n; |
2811276d | 248 | Double_t x, y, z; |
249 | Double_t a1, a2, a3, a4, a5, a6; | |
250 | TString dummy; | |
251 | ||
252 | in >> id; | |
e118b27e | 253 | in >> n; |
2811276d | 254 | in >> dummy; |
255 | in >> x; | |
256 | in >> y; | |
257 | in >> z; | |
258 | in >> dummy; | |
259 | in >> a1; | |
260 | in >> a2; | |
261 | in >> a3; | |
262 | in >> a4; | |
263 | in >> a5; | |
264 | in >> a6; | |
265 | ||
266 | //cout << "id=" << id << " " | |
267 | // << "position= " << x << ", " << y << ", " << z << " " | |
268 | // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", " | |
269 | // << a4 << ", " << a5 << ", " << a6 | |
270 | // << endl; | |
271 | ||
272 | // Fill data | |
e118b27e | 273 | FillData(id, n, x, y, z, a1, a2, a3, a4, a5, a6); |
2811276d | 274 | |
275 | // Go to next line | |
276 | in >> key; | |
277 | } | |
278 | ||
279 | return key; | |
280 | } | |
281 | ||
282 | //______________________________________________________________________________ | |
283 | TString AliMUONVGeometryBuilder::ReadData2(ifstream& in) const | |
284 | { | |
285 | // Reads detection elements transformations from a file | |
286 | // Returns true, if reading finished correctly. | |
287 | // --- | |
288 | ||
289 | TString key("DE"); | |
290 | while ( key == TString("DE") ) { | |
291 | ||
292 | // Input data | |
293 | Int_t detElemId; | |
294 | TString volumeName; | |
295 | Int_t copyNo; | |
296 | Double_t x, y, z; | |
297 | Double_t a1, a2, a3, a4, a5, a6; | |
298 | TString dummy; | |
299 | ||
300 | in >> detElemId; | |
301 | in >> volumeName; | |
302 | in >> copyNo; | |
303 | in >> dummy; | |
304 | in >> x; | |
305 | in >> y; | |
306 | in >> z; | |
307 | in >> dummy; | |
308 | in >> a1; | |
309 | in >> a2; | |
310 | in >> a3; | |
311 | in >> a4; | |
312 | in >> a5; | |
313 | in >> a6; | |
314 | ||
315 | //cout << "detElemId=" << detElemId << " " | |
316 | // << "volume=" << volumeName << " " | |
317 | // << "copyNo=" << copyNo << " " | |
318 | // << "position= " << x << ", " << y << ", " << z << " " | |
319 | // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", " | |
320 | // << a4 << ", " << a5 << ", " << a6 | |
321 | // << endl; | |
322 | ||
323 | // Fill data | |
324 | FillData(detElemId, volumeName, copyNo, x, y, z, a1, a2, a3, a4, a5, a6); | |
325 | ||
326 | // Go to next line | |
327 | in >> key; | |
328 | } | |
329 | ||
330 | return key; | |
331 | } | |
332 | ||
333 | //______________________________________________________________________________ | |
334 | TString AliMUONVGeometryBuilder::ReadData3(ifstream& in) const | |
335 | { | |
336 | // Reads detection elements transformations from a file | |
337 | // Returns true, if reading finished correctly. | |
338 | // --- | |
339 | ||
340 | TString key("SV"); | |
341 | while ( key == TString("SV") ) { | |
342 | ||
343 | // Input data | |
344 | TString volumePath; | |
345 | Int_t detElemId; | |
346 | ||
347 | in >> volumePath; | |
348 | in >> detElemId; | |
349 | ||
350 | //cout << "volumePath=" << volumePath << " " | |
351 | // << "detElemId=" << detElemId | |
352 | // << endl; | |
353 | ||
354 | // Fill data | |
355 | FillData(volumePath, detElemId); | |
356 | ||
357 | // Go to next line | |
358 | in >> key; | |
359 | } | |
360 | ||
361 | return key; | |
362 | } | |
363 | ||
364 | //______________________________________________________________________________ | |
365 | void AliMUONVGeometryBuilder::WriteTransform(ofstream& out, | |
366 | const TGeoCombiTrans* transform) const | |
367 | { | |
368 | // Writes the transformations | |
369 | // --- | |
370 | ||
371 | out << " pos: "; | |
372 | const Double_t* xyz = transform->GetTranslation(); | |
373 | out << setw(10) << setprecision(4) << xyz[0] << " " | |
374 | << setw(10) << setprecision(4) << xyz[1] << " " | |
375 | << setw(10) << setprecision(4) << xyz[2]; | |
376 | ||
377 | out << " rot: "; | |
378 | Double_t a1, a2, a3, a4, a5, a6; | |
379 | TGeoRotation* rotation = transform->GetRotation(); | |
e118b27e | 380 | if (rotation) { |
381 | rotation->GetAngles(a1, a2, a3, a4, a5, a6); | |
382 | } | |
383 | else { | |
384 | TGeoRotation rotation2; | |
385 | rotation2.GetAngles(a1, a2, a3, a4, a5, a6); | |
386 | } | |
387 | ||
2811276d | 388 | out << setw(8) << setprecision(4) << a1 << " " |
389 | << setw(8) << setprecision(4) << a2 << " " | |
390 | << setw(8) << setprecision(4) << a3 << " " | |
391 | << setw(8) << setprecision(4) << a4 << " " | |
392 | << setw(8) << setprecision(4) << a5 << " " | |
393 | << setw(8) << setprecision(4) << a6 << " " << endl; | |
394 | } | |
395 | ||
396 | //______________________________________________________________________________ | |
397 | void AliMUONVGeometryBuilder::WriteData1(ofstream& out) const | |
398 | { | |
e118b27e | 399 | // Writes modules transformations |
2811276d | 400 | // --- |
401 | ||
e118b27e | 402 | for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) { |
403 | AliMUONGeometryModule* geometry | |
404 | = (AliMUONGeometryModule*)fModuleGeometries->At(i); | |
2811276d | 405 | const TGeoCombiTrans* transform |
e118b27e | 406 | = geometry->GetTransformation(); |
2811276d | 407 | |
408 | out << "CH " | |
e118b27e | 409 | << setw(4) << geometry->GetModuleId() + 1 << " " |
410 | << setw(4) << geometry->GetDetElementStore()->GetNofEntries() << " "; | |
2811276d | 411 | |
412 | WriteTransform(out, transform); | |
413 | } | |
414 | out << endl; | |
415 | } | |
416 | ||
417 | //______________________________________________________________________________ | |
418 | void AliMUONVGeometryBuilder::WriteData2(ofstream& out) const | |
419 | { | |
420 | // Writes detection elements (envelopes) transformations | |
421 | // --- | |
422 | ||
423 | ||
e118b27e | 424 | for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) { |
425 | AliMUONGeometryModule* geometry | |
426 | = (AliMUONGeometryModule*)fModuleGeometries->At(i); | |
2811276d | 427 | const TObjArray* envelopes |
e118b27e | 428 | = geometry->GetEnvelopeStore()->GetEnvelopes(); |
2811276d | 429 | |
430 | for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) { | |
431 | AliMUONGeometryEnvelope* envelope | |
432 | = (AliMUONGeometryEnvelope*)envelopes->At(j); | |
433 | const TGeoCombiTrans* transform | |
434 | = envelope->GetTransformation(); | |
435 | ||
436 | // skip envelope not corresponding to detection element | |
437 | if(envelope->GetUniqueID() == 0) continue; | |
438 | ||
439 | out << "DE " | |
440 | << setw(4) << envelope->GetUniqueID() << " " | |
441 | << envelope->GetName() << " " | |
442 | << setw(4)<< envelope->GetCopyNo(); | |
443 | ||
444 | WriteTransform(out, transform); | |
445 | } | |
446 | out << endl; | |
447 | } | |
448 | } | |
449 | ||
450 | //______________________________________________________________________________ | |
451 | void AliMUONVGeometryBuilder::WriteData3(ofstream& out) const | |
452 | { | |
453 | // Writes association of sensitive volumes and detection elements | |
454 | // from the sensitive volume map | |
455 | // --- | |
456 | ||
e118b27e | 457 | for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) { |
458 | AliMUONGeometryModule* geometry | |
459 | = (AliMUONGeometryModule*)fModuleGeometries->At(i); | |
2811276d | 460 | AliMUONGeometrySVMap* svMap |
e118b27e | 461 | = geometry->GetSVMap(); |
2811276d | 462 | |
463 | svMap->WriteMap(out); | |
464 | out << endl; | |
465 | } | |
466 | } | |
467 | ||
468 | // | |
469 | // protected methods | |
d1cd2474 | 470 | // |
471 | ||
472 | //______________________________________________________________________________ | |
e118b27e | 473 | AliMUONGeometryModule* |
474 | AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const | |
d1cd2474 | 475 | { |
e118b27e | 476 | // Returns the module geometry specified by moduleId |
d1cd2474 | 477 | // --- |
478 | ||
e118b27e | 479 | for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) { |
480 | ||
481 | AliMUONGeometryModule* geometry | |
482 | = (AliMUONGeometryModule*)fModuleGeometries->At(i); | |
483 | ||
484 | if ( geometry->GetModuleId() == moduleId) return geometry; | |
d1cd2474 | 485 | } |
486 | ||
487 | return 0; | |
488 | } | |
2811276d | 489 | |
490 | //______________________________________________________________________________ | |
491 | AliMUONGeometryEnvelopeStore* | |
e118b27e | 492 | AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const |
2811276d | 493 | { |
e118b27e | 494 | // Returns the envelope store of the module geometry specified by moduleId |
2811276d | 495 | // --- |
496 | ||
e118b27e | 497 | AliMUONGeometryModule* geometry = GetGeometry(moduleId); |
2811276d | 498 | |
e118b27e | 499 | if (!geometry) { |
500 | AliFatal(Form("Module geometry %d is not defined", moduleId)); | |
2811276d | 501 | return 0; |
502 | } | |
503 | ||
e118b27e | 504 | return geometry->GetEnvelopeStore(); |
2811276d | 505 | } |
506 | ||
507 | //______________________________________________________________________________ | |
e118b27e | 508 | AliMUONGeometryStore* |
509 | AliMUONVGeometryBuilder::GetDetElements(Int_t moduleId) const | |
2811276d | 510 | { |
e118b27e | 511 | // Returns the detection elemnts store of the module geometry specified |
512 | // by moduleId | |
2811276d | 513 | // --- |
514 | ||
e118b27e | 515 | AliMUONGeometryModule* geometry = GetGeometry(moduleId); |
2811276d | 516 | |
e118b27e | 517 | if (!geometry) { |
518 | AliFatal(Form("Module geometry %d is not defined", moduleId)); | |
2811276d | 519 | return 0; |
520 | } | |
521 | ||
e118b27e | 522 | return geometry->GetDetElementStore(); |
2811276d | 523 | } |
524 | ||
525 | //______________________________________________________________________________ | |
526 | AliMUONGeometrySVMap* | |
e118b27e | 527 | AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const |
2811276d | 528 | { |
e118b27e | 529 | // Returns the transformation store of the module geometry specified by moduleId |
2811276d | 530 | // --- |
531 | ||
e118b27e | 532 | AliMUONGeometryModule* geometry = GetGeometry(moduleId); |
2811276d | 533 | |
e118b27e | 534 | if (!geometry) { |
535 | AliFatal(Form("Geometry %d is not defined", moduleId)); | |
2811276d | 536 | return 0; |
537 | } | |
538 | ||
e118b27e | 539 | return geometry->GetSVMap(); |
2811276d | 540 | } |
541 | ||
542 | // | |
543 | // public functions | |
544 | // | |
545 | ||
546 | //______________________________________________________________________________ | |
e118b27e | 547 | void AliMUONVGeometryBuilder::FillTransformations() const |
2811276d | 548 | { |
549 | // Fills transformations store from defined geometry. | |
550 | // --- | |
551 | ||
e118b27e | 552 | for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) { |
553 | AliMUONGeometryModule* geometry | |
554 | = (AliMUONGeometryModule*)fModuleGeometries->At(i); | |
2811276d | 555 | const TObjArray* envelopes |
e118b27e | 556 | = geometry->GetEnvelopeStore()->GetEnvelopes(); |
557 | ||
558 | AliMUONGeometryStore* detElements = geometry->GetDetElementStore(); | |
559 | ||
560 | // Set nof detection elements to the indexing | |
561 | geometry->GetDEIndexing() | |
562 | ->SetNofDetElements(geometry->GetEnvelopeStore()->GetNofDetElements()); | |
2811276d | 563 | |
564 | for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) { | |
565 | AliMUONGeometryEnvelope* envelope | |
566 | = (AliMUONGeometryEnvelope*)envelopes->At(j); | |
567 | ||
568 | // skip envelope not corresponding to detection element | |
569 | if(envelope->GetUniqueID() == 0) continue; | |
570 | ||
571 | // Get envelope data | |
572 | Int_t detElemId = envelope->GetUniqueID(); | |
573 | TString path = ComposePath(envelope->GetName(), | |
574 | envelope->GetCopyNo()); | |
575 | const TGeoCombiTrans* transform = envelope->GetTransformation(); | |
576 | ||
577 | // Add detection element transformation | |
e118b27e | 578 | detElements->Add(detElemId, |
579 | new AliMUONGeometryDetElement(detElemId, path, *transform)); | |
2811276d | 580 | } |
581 | } | |
582 | } | |
583 | ||
584 | //_____ _________________________________________________________________________ | |
585 | void AliMUONVGeometryBuilder::RebuildSVMaps() const | |
586 | { | |
587 | // Clear the SV maps in memory and fill them from defined geometry. | |
588 | // --- | |
589 | ||
e118b27e | 590 | for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) { |
591 | AliMUONGeometryModule* geometry | |
592 | = (AliMUONGeometryModule*)fModuleGeometries->At(i); | |
2811276d | 593 | |
594 | // Clear the map | |
e118b27e | 595 | geometry->GetSVMap()->Clear(); |
2811276d | 596 | |
597 | // Fill the map from geometry | |
598 | const TObjArray* envelopes | |
e118b27e | 599 | = geometry->GetEnvelopeStore()->GetEnvelopes(); |
2811276d | 600 | |
601 | for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) { | |
602 | AliMUONGeometryEnvelope* envelope | |
603 | = (AliMUONGeometryEnvelope*)envelopes->At(j); | |
604 | ||
605 | // skip envelope not corresponding to detection element | |
606 | if(envelope->GetUniqueID() == 0) continue; | |
607 | ||
608 | TString path0("/ALIC.1"); | |
e118b27e | 609 | if (geometry->GetMotherVolume() != "ALIC") { |
2811276d | 610 | path0 += "/"; |
e118b27e | 611 | path0 += ComposePath(geometry->GetMotherVolume(), 1); |
2811276d | 612 | } |
d639fb9f | 613 | if (! geometry->IsVirtual() ) { |
614 | path0 += "/"; | |
615 | path0 += ComposePath(geometry->GetVolume(), 1); | |
616 | } | |
2811276d | 617 | |
618 | if (!envelope->IsVirtual()) { | |
619 | TString path = path0; | |
620 | path += "/"; | |
621 | path += ComposePath(envelope->GetName(), envelope->GetCopyNo()); | |
622 | MapSV(path, envelope->GetName(), envelope->GetUniqueID()); | |
623 | } | |
624 | else { | |
625 | for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) { | |
626 | AliMUONGeometryConstituent* constituent | |
627 | = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k); | |
628 | TString path = path0; | |
629 | path += "/"; | |
630 | path += ComposePath(constituent->GetName(), constituent->GetCopyNo()); | |
631 | MapSV(path, constituent->GetName(), envelope->GetUniqueID()); | |
632 | } | |
633 | } | |
634 | } | |
635 | } | |
636 | } | |
637 | ||
638 | //______________________________________________________________________________ | |
639 | Bool_t AliMUONVGeometryBuilder::ReadTransformations() const | |
640 | { | |
641 | // Reads transformations from a file | |
642 | // Returns true, if reading finished correctly. | |
643 | // --- | |
644 | ||
e118b27e | 645 | // No reading |
646 | // if builder is not associated with any geometry module | |
647 | if (fModuleGeometries->GetEntriesFast() == 0) return false; | |
648 | ||
2811276d | 649 | // File path |
650 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
651 | filePath += "/MUON/data/"; | |
652 | filePath += fTransformFileName; | |
653 | ||
654 | // Open input file | |
655 | ifstream in(filePath, ios::in); | |
656 | if (!in) { | |
657 | cerr << filePath << endl; | |
8c343c7c | 658 | AliFatal("File not found."); |
2811276d | 659 | return false; |
660 | } | |
661 | ||
662 | TString key; | |
663 | in >> key; | |
664 | while ( !in.eof() ) { | |
665 | if (key == TString("CH")) | |
666 | key = ReadData1(in); | |
667 | else if (key == TString("DE")) | |
668 | key = ReadData2(in); | |
669 | else { | |
8c343c7c | 670 | AliFatal(Form("%s key not recognized", key.Data())); |
2811276d | 671 | return false; |
672 | } | |
673 | } | |
674 | ||
675 | return true; | |
676 | } | |
677 | ||
678 | //______________________________________________________________________________ | |
679 | Bool_t AliMUONVGeometryBuilder::ReadSVMap() const | |
680 | { | |
681 | // Reads the sensitive volume from a file | |
682 | // Returns true, if reading finished correctly. | |
683 | // --- | |
684 | ||
e118b27e | 685 | // No reading |
686 | // if builder is not associated with any geometry module | |
687 | if (fModuleGeometries->GetEntriesFast() == 0) return false; | |
688 | ||
2811276d | 689 | // File path |
690 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
691 | filePath += "/MUON/data/"; | |
692 | filePath += fSVMapFileName; | |
693 | ||
694 | // Open input file | |
695 | ifstream in(filePath, ios::in); | |
696 | if (!in) { | |
697 | cerr << filePath << endl; | |
8c343c7c | 698 | AliFatal("File not found."); |
2811276d | 699 | return false; |
700 | } | |
701 | ||
702 | TString key; | |
703 | in >> key; | |
704 | while ( !in.eof() ) { | |
705 | if (key == TString("SV")) | |
706 | key = ReadData3(in); | |
707 | else { | |
8c343c7c | 708 | AliFatal(Form("%s key not recognized", key.Data())); |
2811276d | 709 | return false; |
710 | } | |
711 | } | |
712 | ||
713 | return true; | |
714 | } | |
715 | ||
716 | //______________________________________________________________________________ | |
717 | Bool_t AliMUONVGeometryBuilder::WriteTransformations() const | |
718 | { | |
719 | // Writes transformations into a file | |
720 | // Returns true, if writing finished correctly. | |
721 | // --- | |
722 | ||
e118b27e | 723 | // No writing |
724 | // if builder is not associated with any geometry module | |
725 | if (fModuleGeometries->GetEntriesFast() == 0) return false; | |
726 | ||
2811276d | 727 | // File path |
728 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
729 | filePath += "/MUON/data/"; | |
730 | filePath += fTransformFileName; | |
731 | filePath += fgkOutFileNameSuffix; | |
732 | ||
733 | // Open input file | |
734 | ofstream out(filePath, ios::out); | |
735 | if (!out) { | |
736 | cerr << filePath << endl; | |
8c343c7c | 737 | AliError("File not found."); |
2811276d | 738 | return false; |
739 | } | |
e516b01d | 740 | #if !defined (__DECCXX) |
2811276d | 741 | out.setf(std::ios::fixed); |
e516b01d | 742 | #endif |
2811276d | 743 | WriteData1(out); |
744 | WriteData2(out); | |
745 | ||
746 | return true; | |
747 | } | |
748 | ||
749 | //______________________________________________________________________________ | |
750 | Bool_t AliMUONVGeometryBuilder::WriteSVMap(Bool_t rebuild) const | |
751 | { | |
752 | // Writes sensitive volume map into a file | |
753 | // Returns true, if writing finished correctly. | |
754 | // --- | |
755 | ||
e118b27e | 756 | // No writing |
757 | // if builder is not associated with any geometry module | |
758 | if (fModuleGeometries->GetEntriesFast() == 0) return false; | |
759 | ||
2811276d | 760 | // File path |
761 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
762 | filePath += "/MUON/data/"; | |
763 | filePath += fSVMapFileName; | |
764 | filePath += fgkOutFileNameSuffix; | |
765 | ||
766 | // Open input file | |
767 | ofstream out(filePath, ios::out); | |
768 | if (!out) { | |
769 | cerr << filePath << endl; | |
8c343c7c | 770 | AliError("File not found."); |
2811276d | 771 | return false; |
772 | } | |
e516b01d | 773 | #if !defined (__DECCXX) |
2811276d | 774 | out.setf(std::ios::fixed); |
e516b01d | 775 | #endif |
2811276d | 776 | if (rebuild) RebuildSVMaps(); |
777 | ||
778 | WriteData3(out); | |
779 | ||
780 | return true; | |
781 | } | |
782 |