]>
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 | } |
613 | ||
614 | if (!envelope->IsVirtual()) { | |
615 | TString path = path0; | |
616 | path += "/"; | |
617 | path += ComposePath(envelope->GetName(), envelope->GetCopyNo()); | |
618 | MapSV(path, envelope->GetName(), envelope->GetUniqueID()); | |
619 | } | |
620 | else { | |
621 | for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) { | |
622 | AliMUONGeometryConstituent* constituent | |
623 | = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k); | |
624 | TString path = path0; | |
625 | path += "/"; | |
626 | path += ComposePath(constituent->GetName(), constituent->GetCopyNo()); | |
627 | MapSV(path, constituent->GetName(), envelope->GetUniqueID()); | |
628 | } | |
629 | } | |
630 | } | |
631 | } | |
632 | } | |
633 | ||
634 | //______________________________________________________________________________ | |
635 | Bool_t AliMUONVGeometryBuilder::ReadTransformations() const | |
636 | { | |
637 | // Reads transformations from a file | |
638 | // Returns true, if reading finished correctly. | |
639 | // --- | |
640 | ||
e118b27e | 641 | // No reading |
642 | // if builder is not associated with any geometry module | |
643 | if (fModuleGeometries->GetEntriesFast() == 0) return false; | |
644 | ||
2811276d | 645 | // File path |
646 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
647 | filePath += "/MUON/data/"; | |
648 | filePath += fTransformFileName; | |
649 | ||
650 | // Open input file | |
651 | ifstream in(filePath, ios::in); | |
652 | if (!in) { | |
653 | cerr << filePath << endl; | |
8c343c7c | 654 | AliFatal("File not found."); |
2811276d | 655 | return false; |
656 | } | |
657 | ||
658 | TString key; | |
659 | in >> key; | |
660 | while ( !in.eof() ) { | |
661 | if (key == TString("CH")) | |
662 | key = ReadData1(in); | |
663 | else if (key == TString("DE")) | |
664 | key = ReadData2(in); | |
665 | else { | |
8c343c7c | 666 | AliFatal(Form("%s key not recognized", key.Data())); |
2811276d | 667 | return false; |
668 | } | |
669 | } | |
670 | ||
671 | return true; | |
672 | } | |
673 | ||
674 | //______________________________________________________________________________ | |
675 | Bool_t AliMUONVGeometryBuilder::ReadSVMap() const | |
676 | { | |
677 | // Reads the sensitive volume from a file | |
678 | // Returns true, if reading finished correctly. | |
679 | // --- | |
680 | ||
e118b27e | 681 | // No reading |
682 | // if builder is not associated with any geometry module | |
683 | if (fModuleGeometries->GetEntriesFast() == 0) return false; | |
684 | ||
2811276d | 685 | // File path |
686 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
687 | filePath += "/MUON/data/"; | |
688 | filePath += fSVMapFileName; | |
689 | ||
690 | // Open input file | |
691 | ifstream in(filePath, ios::in); | |
692 | if (!in) { | |
693 | cerr << filePath << endl; | |
8c343c7c | 694 | AliFatal("File not found."); |
2811276d | 695 | return false; |
696 | } | |
697 | ||
698 | TString key; | |
699 | in >> key; | |
700 | while ( !in.eof() ) { | |
701 | if (key == TString("SV")) | |
702 | key = ReadData3(in); | |
703 | else { | |
8c343c7c | 704 | AliFatal(Form("%s key not recognized", key.Data())); |
2811276d | 705 | return false; |
706 | } | |
707 | } | |
708 | ||
709 | return true; | |
710 | } | |
711 | ||
712 | //______________________________________________________________________________ | |
713 | Bool_t AliMUONVGeometryBuilder::WriteTransformations() const | |
714 | { | |
715 | // Writes transformations into a file | |
716 | // Returns true, if writing finished correctly. | |
717 | // --- | |
718 | ||
e118b27e | 719 | // No writing |
720 | // if builder is not associated with any geometry module | |
721 | if (fModuleGeometries->GetEntriesFast() == 0) return false; | |
722 | ||
2811276d | 723 | // File path |
724 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
725 | filePath += "/MUON/data/"; | |
726 | filePath += fTransformFileName; | |
727 | filePath += fgkOutFileNameSuffix; | |
728 | ||
729 | // Open input file | |
730 | ofstream out(filePath, ios::out); | |
731 | if (!out) { | |
732 | cerr << filePath << endl; | |
8c343c7c | 733 | AliError("File not found."); |
2811276d | 734 | return false; |
735 | } | |
e516b01d | 736 | #if !defined (__DECCXX) |
2811276d | 737 | out.setf(std::ios::fixed); |
e516b01d | 738 | #endif |
2811276d | 739 | WriteData1(out); |
740 | WriteData2(out); | |
741 | ||
742 | return true; | |
743 | } | |
744 | ||
745 | //______________________________________________________________________________ | |
746 | Bool_t AliMUONVGeometryBuilder::WriteSVMap(Bool_t rebuild) const | |
747 | { | |
748 | // Writes sensitive volume map into a file | |
749 | // Returns true, if writing finished correctly. | |
750 | // --- | |
751 | ||
e118b27e | 752 | // No writing |
753 | // if builder is not associated with any geometry module | |
754 | if (fModuleGeometries->GetEntriesFast() == 0) return false; | |
755 | ||
2811276d | 756 | // File path |
757 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
758 | filePath += "/MUON/data/"; | |
759 | filePath += fSVMapFileName; | |
760 | filePath += fgkOutFileNameSuffix; | |
761 | ||
762 | // Open input file | |
763 | ofstream out(filePath, ios::out); | |
764 | if (!out) { | |
765 | cerr << filePath << endl; | |
8c343c7c | 766 | AliError("File not found."); |
2811276d | 767 | return false; |
768 | } | |
e516b01d | 769 | #if !defined (__DECCXX) |
2811276d | 770 | out.setf(std::ios::fixed); |
e516b01d | 771 | #endif |
2811276d | 772 | if (rebuild) RebuildSVMaps(); |
773 | ||
774 | WriteData3(out); | |
775 | ||
776 | return true; | |
777 | } | |
778 |