]>
Commit | Line | Data |
---|---|---|
afc8e661 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * SigmaEffect_thetadegrees * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpeateose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | // | |
f7006443 | 18 | // ---------------------------- |
afc8e661 | 19 | // Class AliMUONGeometryTransformer |
20 | // ---------------------------- | |
21 | // Top container class for geometry transformations | |
afc8e661 | 22 | // Author: Ivana Hrivnacova, IPN Orsay |
23 | ||
afc8e661 | 24 | #include "AliMUONGeometryTransformer.h" |
25 | #include "AliMUONGeometryModuleTransformer.h" | |
26 | #include "AliMUONGeometryDetElement.h" | |
2864a3ac | 27 | #include "AliMUONGeometryBuilder.h" |
afc8e661 | 28 | |
ea7ea157 | 29 | #include "AliMpDEManager.h" |
327d1302 | 30 | #include "AliMpConstants.h" |
ea7ea157 | 31 | #include "AliMpExMap.h" |
88544f7e | 32 | #include "AliMpCDB.h" |
ea7ea157 | 33 | |
a7d4e65b | 34 | #include "AliLog.h" |
35 | #include "AliAlignObjMatrix.h" | |
bf16b32c | 36 | #include "AliAlignObj.h" |
a7d4e65b | 37 | |
38 | #include <Riostream.h> | |
39 | #include <TSystem.h> | |
40 | #include <TClonesArray.h> | |
41 | #include <TGeoManager.h> | |
42 | #include <TGeoPhysicalNode.h> | |
a6269834 | 43 | #include <TFile.h> |
327d1302 | 44 | #include <TString.h> |
a7d4e65b | 45 | |
46 | #include <sstream> | |
afc8e661 | 47 | |
a9aad96e | 48 | /// \cond CLASSIMP |
afc8e661 | 49 | ClassImp(AliMUONGeometryTransformer) |
a9aad96e | 50 | /// \endcond |
327d1302 | 51 | |
52 | const TString AliMUONGeometryTransformer::fgkDefaultDetectorName = "MUON"; | |
afc8e661 | 53 | |
54 | //______________________________________________________________________________ | |
327d1302 | 55 | AliMUONGeometryTransformer::AliMUONGeometryTransformer() |
d4d05625 | 56 | |
afc8e661 | 57 | : TObject(), |
327d1302 | 58 | fDetectorName(fgkDefaultDetectorName), |
a7d4e65b | 59 | fModuleTransformers(0), |
60 | fMisAlignArray(0) | |
afc8e661 | 61 | { |
62 | /// Standard constructor | |
63 | ||
64 | // Create array for geometry modules | |
ea7ea157 | 65 | fModuleTransformers = new TObjArray(100); |
327d1302 | 66 | fModuleTransformers->SetOwner(true); |
afc8e661 | 67 | } |
68 | ||
69 | //______________________________________________________________________________ | |
327d1302 | 70 | AliMUONGeometryTransformer::AliMUONGeometryTransformer(TRootIOCtor* /*ioCtor*/) |
afc8e661 | 71 | : TObject(), |
d4d05625 | 72 | fDetectorName(), |
a7d4e65b | 73 | fModuleTransformers(0), |
74 | fMisAlignArray(0) | |
afc8e661 | 75 | { |
76 | /// Default constructor | |
77 | } | |
78 | ||
afc8e661 | 79 | //______________________________________________________________________________ |
80 | AliMUONGeometryTransformer::~AliMUONGeometryTransformer() | |
81 | { | |
82 | /// Destructor | |
83 | ||
84 | delete fModuleTransformers; | |
a7d4e65b | 85 | delete fMisAlignArray; |
afc8e661 | 86 | } |
87 | ||
afc8e661 | 88 | // |
89 | // private methods | |
90 | // | |
91 | ||
88544f7e | 92 | //_____________________________________________________________________________ |
93 | Bool_t AliMUONGeometryTransformer::LoadMapping() const | |
94 | { | |
95 | /// Load mapping from CDB | |
96 | ||
97 | if ( ! AliMpCDB::LoadMpSegmentation() ) | |
98 | { | |
99 | AliFatal("Could not access mapping from OCDB !"); | |
100 | return false; | |
101 | } | |
102 | ||
103 | return true; | |
104 | } | |
105 | ||
afc8e661 | 106 | //_____________________________________________________________________________ |
107 | AliMUONGeometryModuleTransformer* | |
108 | AliMUONGeometryTransformer::GetModuleTransformerNonConst( | |
109 | Int_t index, Bool_t warn) const | |
110 | { | |
111 | /// Return the geometry module specified by index | |
112 | ||
113 | if (index < 0 || index >= fModuleTransformers->GetEntriesFast()) { | |
114 | if (warn) { | |
115 | AliWarningStream() | |
116 | << "Index: " << index << " outside limits" << std::endl; | |
117 | } | |
118 | return 0; | |
119 | } | |
120 | ||
121 | return (AliMUONGeometryModuleTransformer*) fModuleTransformers->At(index); | |
122 | } | |
123 | ||
afc8e661 | 124 | //______________________________________________________________________________ |
125 | TGeoHMatrix AliMUONGeometryTransformer::GetTransform( | |
126 | Double_t x, Double_t y, Double_t z, | |
127 | Double_t a1, Double_t a2, Double_t a3, | |
128 | Double_t a4, Double_t a5, Double_t a6) const | |
129 | { | |
a9aad96e | 130 | /// Build the transformation from the given parameters |
afc8e661 | 131 | |
132 | // Compose transform | |
133 | return TGeoCombiTrans(TGeoTranslation(x, y, z), | |
134 | TGeoRotation("rot", a1, a2, a3, a4, a5, a6)); | |
135 | } | |
136 | ||
137 | ||
a7d4e65b | 138 | //______________________________________________________________________________ |
139 | void AliMUONGeometryTransformer::FillModuleTransform(Int_t moduleId, | |
afc8e661 | 140 | Double_t x, Double_t y, Double_t z, |
141 | Double_t a1, Double_t a2, Double_t a3, | |
142 | Double_t a4, Double_t a5, Double_t a6) | |
143 | { | |
a9aad96e | 144 | /// Fill the transformation of the module. |
afc8e661 | 145 | |
afc8e661 | 146 | AliMUONGeometryModuleTransformer* moduleTransformer |
317aa7dc | 147 | = GetModuleTransformerNonConst(moduleId, false); |
afc8e661 | 148 | |
149 | if ( !moduleTransformer) { | |
a7d4e65b | 150 | AliErrorStream() |
151 | << "Module " << moduleId << " has not volume path defined." << endl; | |
afc8e661 | 152 | } |
153 | ||
154 | // Build the transformation from the parameters | |
155 | TGeoHMatrix transform | |
156 | = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6); | |
157 | ||
158 | moduleTransformer->SetTransformation(transform); | |
afc8e661 | 159 | } |
160 | ||
161 | //______________________________________________________________________________ | |
a7d4e65b | 162 | void AliMUONGeometryTransformer::FillDetElemTransform( |
163 | Int_t detElemId, | |
afc8e661 | 164 | Double_t x, Double_t y, Double_t z, |
165 | Double_t a1, Double_t a2, Double_t a3, | |
166 | Double_t a4, Double_t a5, Double_t a6) | |
167 | { | |
a9aad96e | 168 | /// Fill the transformation of the detection element. |
afc8e661 | 169 | |
170 | // Module Id | |
ea7ea157 | 171 | Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId); |
afc8e661 | 172 | |
a7d4e65b | 173 | // Get module transformer |
2864a3ac | 174 | const AliMUONGeometryModuleTransformer* kModuleTransformer |
175 | = GetModuleTransformer(moduleId); | |
a7d4e65b | 176 | |
2864a3ac | 177 | if ( ! kModuleTransformer ) { |
a7d4e65b | 178 | AliFatal(Form("Module transformer not defined, detElemId: %d", detElemId)); |
179 | return; | |
2864a3ac | 180 | } |
181 | ||
a7d4e65b | 182 | // Get detection element |
183 | AliMUONGeometryDetElement* detElement | |
184 | = kModuleTransformer->GetDetElement(detElemId); | |
185 | ||
186 | if ( ! detElement ) { | |
187 | AliFatal(Form("Det element %d has not volume path defined", detElemId)); | |
188 | return; | |
189 | } | |
190 | ||
191 | // Build the transformation from the parameters | |
192 | TGeoHMatrix localTransform | |
193 | = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6); | |
194 | detElement->SetLocalTransformation(localTransform); | |
195 | ||
196 | // Compute global transformation | |
2864a3ac | 197 | TGeoHMatrix globalTransform |
198 | = AliMUONGeometryBuilder::Multiply( | |
199 | *kModuleTransformer->GetTransformation(), | |
200 | localTransform ); | |
201 | detElement->SetGlobalTransformation(globalTransform); | |
afc8e661 | 202 | } |
a7d4e65b | 203 | |
afc8e661 | 204 | //______________________________________________________________________________ |
a7d4e65b | 205 | TString AliMUONGeometryTransformer::ReadModuleTransforms(ifstream& in) |
afc8e661 | 206 | { |
a9aad96e | 207 | /// Read and fill modules transformations from the stream. |
208 | /// Return true, if reading finished correctly. | |
afc8e661 | 209 | |
ea7ea157 | 210 | TString key(AliMUONGeometryModuleTransformer::GetModuleNamePrefix()); |
211 | while ( key == AliMUONGeometryModuleTransformer::GetModuleNamePrefix() ) { | |
a7d4e65b | 212 | Int_t id; |
afc8e661 | 213 | Double_t x, y, z; |
214 | Double_t a1, a2, a3, a4, a5, a6; | |
215 | TString dummy; | |
216 | ||
217 | in >> id; | |
afc8e661 | 218 | in >> dummy; |
219 | in >> x; | |
220 | in >> y; | |
221 | in >> z; | |
222 | in >> dummy; | |
223 | in >> a1; | |
224 | in >> a2; | |
225 | in >> a3; | |
226 | in >> a4; | |
227 | in >> a5; | |
228 | in >> a6; | |
229 | ||
a7d4e65b | 230 | //cout << "moduleId=" << id << " " |
afc8e661 | 231 | // << "position= " << x << ", " << y << ", " << z << " " |
232 | // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", " | |
233 | // << a4 << ", " << a5 << ", " << a6 | |
234 | // << endl; | |
235 | ||
236 | // Fill data | |
a7d4e65b | 237 | FillModuleTransform(id, x, y, z, a1, a2, a3, a4, a5, a6); |
afc8e661 | 238 | |
239 | // Go to next line | |
240 | in >> key; | |
241 | } | |
242 | ||
243 | return key; | |
244 | } | |
245 | ||
246 | //______________________________________________________________________________ | |
a7d4e65b | 247 | TString AliMUONGeometryTransformer::ReadDetElemTransforms(ifstream& in) |
afc8e661 | 248 | { |
a9aad96e | 249 | /// Read detection elements transformations from the stream. |
250 | /// Return true, if reading finished correctly. | |
afc8e661 | 251 | |
ea7ea157 | 252 | TString key(AliMUONGeometryDetElement::GetDENamePrefix()); |
253 | while ( key == AliMUONGeometryDetElement::GetDENamePrefix() ) { | |
afc8e661 | 254 | |
255 | // Input data | |
256 | Int_t detElemId; | |
afc8e661 | 257 | Double_t x, y, z; |
258 | Double_t a1, a2, a3, a4, a5, a6; | |
259 | TString dummy; | |
260 | ||
261 | in >> detElemId; | |
afc8e661 | 262 | in >> dummy; |
263 | in >> x; | |
264 | in >> y; | |
265 | in >> z; | |
266 | in >> dummy; | |
267 | in >> a1; | |
268 | in >> a2; | |
269 | in >> a3; | |
270 | in >> a4; | |
271 | in >> a5; | |
272 | in >> a6; | |
273 | ||
274 | //cout << "detElemId=" << detElemId << " " | |
afc8e661 | 275 | // << "position= " << x << ", " << y << ", " << z << " " |
276 | // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", " | |
a7d4e65b | 277 | // << a4 << ", " << a5 << ", " << a6 |
afc8e661 | 278 | // << endl; |
279 | ||
280 | // Fill data | |
a7d4e65b | 281 | FillDetElemTransform(detElemId, x, y, z, a1, a2, a3, a4, a5, a6); |
afc8e661 | 282 | |
283 | // Go to next line | |
284 | in >> key; | |
285 | } | |
286 | ||
287 | return key; | |
288 | } | |
289 | ||
a7d4e65b | 290 | //______________________________________________________________________________ |
291 | Bool_t | |
292 | AliMUONGeometryTransformer::ReadTransformations(const TString& fileName) | |
293 | { | |
a9aad96e | 294 | /// Read transformations from a file. |
295 | /// Return true, if reading finished correctly. | |
a7d4e65b | 296 | |
297 | // File path | |
298 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
299 | filePath += "/MUON/data/"; | |
300 | filePath += fileName; | |
301 | ||
302 | // Open input file | |
303 | ifstream in(filePath, ios::in); | |
304 | if (!in) { | |
305 | cerr << filePath << endl; | |
306 | AliFatal("File not found."); | |
307 | return false; | |
308 | } | |
309 | ||
310 | TString key; | |
311 | in >> key; | |
312 | while ( !in.eof() ) { | |
ea7ea157 | 313 | if ( key == AliMUONGeometryModuleTransformer::GetModuleNamePrefix() ) |
a7d4e65b | 314 | key = ReadModuleTransforms(in); |
ea7ea157 | 315 | else if ( key == AliMUONGeometryDetElement::GetDENamePrefix() ) |
a7d4e65b | 316 | key = ReadDetElemTransforms(in); |
317 | else { | |
318 | AliFatal(Form("%s key not recognized", key.Data())); | |
319 | return false; | |
320 | } | |
321 | } | |
322 | ||
323 | return true; | |
324 | } | |
325 | ||
326 | //______________________________________________________________________________ | |
327 | Bool_t | |
327d1302 | 328 | AliMUONGeometryTransformer::LoadTransformations() |
a7d4e65b | 329 | { |
327d1302 | 330 | /// Load transformations for defined modules and detection elements |
331 | /// using AliGeomManager | |
a7d4e65b | 332 | |
327d1302 | 333 | if ( ! AliGeomManager::GetGeometry() ) { |
334 | AliFatal("Geometry has to be laoded in AliGeomManager first."); | |
335 | return false; | |
336 | } | |
a7d4e65b | 337 | |
327d1302 | 338 | for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) { |
339 | AliMUONGeometryModuleTransformer* moduleTransformer | |
340 | = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); | |
341 | ||
342 | // Module symbolic name | |
343 | TString symname = GetModuleSymName(moduleTransformer->GetModuleId()); | |
344 | ||
345 | // Set matrix from physical node | |
346 | TGeoHMatrix* matrix = AliGeomManager::GetMatrix(symname); | |
88544f7e | 347 | if ( ! matrix ) { |
327d1302 | 348 | AliErrorStream() << "Geometry module matrix not found." << endl; |
349 | return false; | |
350 | } | |
351 | moduleTransformer->SetTransformation(*matrix); | |
352 | ||
353 | // Loop over detection elements | |
354 | AliMpExMap* detElements = moduleTransformer->GetDetElementStore(); | |
355 | ||
356 | for (Int_t j=0; j<detElements->GetSize(); j++) { | |
357 | AliMUONGeometryDetElement* detElement | |
358 | = (AliMUONGeometryDetElement*)detElements->GetObject(j); | |
359 | ||
360 | // Det element symbolic name | |
361 | TString symname = GetDESymName(detElement->GetId()); | |
362 | ||
363 | // Set global matrix from physical node | |
364 | TGeoHMatrix* globalMatrix = AliGeomManager::GetMatrix(symname); | |
88544f7e | 365 | if ( ! globalMatrix ) { |
327d1302 | 366 | AliErrorStream() << "Detection element matrix not found." << endl; |
367 | return false; | |
368 | } | |
369 | detElement->SetGlobalTransformation(*globalMatrix); | |
370 | ||
371 | // Set local matrix | |
372 | TGeoHMatrix localMatrix = | |
373 | AliMUONGeometryBuilder::Multiply( | |
374 | (*matrix).Inverse(), (*globalMatrix) ); | |
375 | detElement->SetLocalTransformation(localMatrix); | |
376 | } | |
377 | } | |
378 | return true; | |
379 | } | |
a7d4e65b | 380 | |
afc8e661 | 381 | //______________________________________________________________________________ |
382 | void AliMUONGeometryTransformer::WriteTransform(ofstream& out, | |
a7d4e65b | 383 | const TGeoMatrix* transform) const |
afc8e661 | 384 | { |
a9aad96e | 385 | /// Write given transformation |
afc8e661 | 386 | |
387 | out << " pos: "; | |
388 | const Double_t* xyz = transform->GetTranslation(); | |
389 | out << setw(10) << setprecision(4) << xyz[0] << " " | |
390 | << setw(10) << setprecision(4) << xyz[1] << " " | |
391 | << setw(10) << setprecision(4) << xyz[2]; | |
392 | ||
393 | out << " rot: "; | |
394 | const Double_t* rm = transform->GetRotationMatrix(); | |
395 | TGeoRotation rotation; | |
396 | rotation.SetMatrix(const_cast<Double_t*>(rm)); | |
397 | Double_t a1, a2, a3, a4, a5, a6; | |
398 | rotation.GetAngles(a1, a2, a3, a4, a5, a6); | |
399 | ||
400 | out << setw(8) << setprecision(4) << a1 << " " | |
401 | << setw(8) << setprecision(4) << a2 << " " | |
402 | << setw(8) << setprecision(4) << a3 << " " | |
403 | << setw(8) << setprecision(4) << a4 << " " | |
404 | << setw(8) << setprecision(4) << a5 << " " | |
405 | << setw(8) << setprecision(4) << a6 << " " << endl; | |
406 | } | |
407 | ||
a7d4e65b | 408 | //______________________________________________________________________________ |
409 | void AliMUONGeometryTransformer::WriteModuleTransforms(ofstream& out) const | |
410 | { | |
a9aad96e | 411 | /// Write module transformations for all module transformers |
afc8e661 | 412 | |
413 | for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) { | |
414 | AliMUONGeometryModuleTransformer* moduleTransformer | |
415 | = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); | |
a7d4e65b | 416 | const TGeoMatrix* transform |
afc8e661 | 417 | = moduleTransformer->GetTransformation(); |
418 | ||
a7d4e65b | 419 | // Write data on out |
ea7ea157 | 420 | out << AliMUONGeometryModuleTransformer::GetModuleNamePrefix() << " " |
421 | << setw(4) << moduleTransformer->GetModuleId(); | |
afc8e661 | 422 | |
423 | WriteTransform(out, transform); | |
424 | } | |
425 | out << endl; | |
426 | } | |
427 | ||
428 | //______________________________________________________________________________ | |
a7d4e65b | 429 | void AliMUONGeometryTransformer::WriteDetElemTransforms(ofstream& out) const |
afc8e661 | 430 | { |
a9aad96e | 431 | /// Write detection element transformations for all detection elements in all |
432 | /// module transformers | |
afc8e661 | 433 | |
afc8e661 | 434 | for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) { |
435 | AliMUONGeometryModuleTransformer* moduleTransformer | |
436 | = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); | |
ea7ea157 | 437 | AliMpExMap* detElements = moduleTransformer->GetDetElementStore(); |
afc8e661 | 438 | |
ea7ea157 | 439 | for (Int_t j=0; j<detElements->GetSize(); j++) { |
afc8e661 | 440 | AliMUONGeometryDetElement* detElement |
ea7ea157 | 441 | = (AliMUONGeometryDetElement*)detElements->GetObject(j); |
a7d4e65b | 442 | const TGeoMatrix* transform |
afc8e661 | 443 | = detElement->GetLocalTransformation(); |
444 | ||
afc8e661 | 445 | // Write data on out |
ea7ea157 | 446 | out << AliMUONGeometryDetElement::GetDENamePrefix() << " " |
447 | << setw(4) << detElement->GetId(); | |
afc8e661 | 448 | |
449 | WriteTransform(out, transform); | |
450 | } | |
451 | out << endl; | |
452 | } | |
453 | } | |
454 | ||
d4d05625 | 455 | //______________________________________________________________________________ |
456 | TString AliMUONGeometryTransformer::GetModuleSymName(Int_t moduleId) const | |
457 | { | |
458 | /// Return the module symbolic name (use for alignment) | |
459 | ||
327d1302 | 460 | return "/" + fDetectorName + "/" |
461 | + AliMUONGeometryModuleTransformer::GetModuleName(moduleId); | |
d4d05625 | 462 | } |
463 | ||
464 | //______________________________________________________________________________ | |
465 | TString AliMUONGeometryTransformer::GetDESymName(Int_t detElemId) const | |
466 | { | |
9c4d2d12 | 467 | /// Return the detection element symbolic name (used for alignment) |
d4d05625 | 468 | |
d4d05625 | 469 | // Module Id |
ea7ea157 | 470 | Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId); |
d4d05625 | 471 | |
327d1302 | 472 | return GetModuleSymName(moduleId) + "/" |
473 | + AliMUONGeometryDetElement::GetDEName(detElemId); | |
d4d05625 | 474 | } |
475 | ||
afc8e661 | 476 | // |
477 | // public functions | |
478 | // | |
479 | ||
480 | //______________________________________________________________________________ | |
481 | Bool_t | |
327d1302 | 482 | AliMUONGeometryTransformer::LoadGeometryData(const TString& fileName) |
afc8e661 | 483 | { |
327d1302 | 484 | /// Read geometry data either from ASCII file with transformations or |
485 | /// from root geometry file (if fileName has ".root" extension) | |
a7d4e65b | 486 | |
327d1302 | 487 | CreateModules(); |
a7d4e65b | 488 | |
489 | // Get file extension | |
327d1302 | 490 | std::string fileName2 = fileName.Data(); |
491 | std::string rootExt = fileName2.substr(fileName2.size()-5, fileName2.size()); | |
a7d4e65b | 492 | |
327d1302 | 493 | if ( rootExt != ".root" ) |
494 | return ReadTransformations(fileName); | |
495 | else { | |
496 | // Load root geometry | |
497 | AliGeomManager::LoadGeometry(fileName.Data()); | |
498 | return LoadTransformations(); | |
499 | } | |
a7d4e65b | 500 | } |
501 | ||
502 | //______________________________________________________________________________ | |
503 | Bool_t | |
327d1302 | 504 | AliMUONGeometryTransformer::LoadGeometryData() |
a7d4e65b | 505 | { |
327d1302 | 506 | /// Load geometry data from already loaded Root geometry using AliGeomManager |
a7d4e65b | 507 | |
327d1302 | 508 | if ( ! AliGeomManager::GetGeometry() ) { |
509 | AliErrorStream() << "Geometry has not been loaded in AliGeomManager" << endl; | |
510 | return false; | |
511 | } | |
afc8e661 | 512 | |
327d1302 | 513 | CreateModules(); |
a7d4e65b | 514 | |
327d1302 | 515 | return LoadTransformations(); |
a7d4e65b | 516 | } |
afc8e661 | 517 | |
518 | //______________________________________________________________________________ | |
519 | Bool_t | |
520 | AliMUONGeometryTransformer::WriteTransformations(const TString& fileName) const | |
521 | { | |
a9aad96e | 522 | /// Write transformations into a file. |
523 | /// Return true, if writing finished correctly. | |
afc8e661 | 524 | |
525 | // No writing | |
526 | // if builder is not associated with any geometry module | |
527 | if (fModuleTransformers->GetEntriesFast() == 0) return false; | |
528 | ||
529 | // File path | |
530 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
531 | filePath += "/MUON/data/"; | |
532 | filePath += fileName; | |
533 | ||
a7d4e65b | 534 | // Open output file |
afc8e661 | 535 | ofstream out(filePath, ios::out); |
536 | if (!out) { | |
537 | cerr << filePath << endl; | |
538 | AliError("File not found."); | |
539 | return false; | |
540 | } | |
541 | #if !defined (__DECCXX) | |
542 | out.setf(std::ios::fixed); | |
543 | #endif | |
a7d4e65b | 544 | WriteModuleTransforms(out); |
545 | WriteDetElemTransforms(out); | |
546 | ||
547 | return true; | |
548 | } | |
549 | ||
550 | //______________________________________________________________________________ | |
551 | Bool_t | |
552 | AliMUONGeometryTransformer::WriteMisAlignmentData(const TString& fileName) const | |
553 | { | |
a9aad96e | 554 | /// Write misalignment data into a file |
555 | /// Return true, if writing finished correctly. | |
a7d4e65b | 556 | |
557 | // No writing | |
558 | // if builder is not associated with any geometry module | |
559 | if ( fModuleTransformers->GetEntriesFast() == 0 ) { | |
560 | AliWarningStream() << "No geometry modules defined." << endl; | |
561 | return false; | |
562 | } | |
563 | ||
564 | // No writing | |
565 | // if builder has no mis-alignment data | |
566 | if ( ! fMisAlignArray ) { | |
567 | AliWarningStream() << "No mis-alignment data defined." << endl; | |
568 | return false; | |
569 | } | |
570 | ||
571 | // File path | |
572 | TString filePath = gSystem->Getenv("ALICE_ROOT"); | |
573 | filePath += "/MUON/data/"; | |
574 | filePath += fileName; | |
575 | ||
576 | // Write mis-alignment data in the root file | |
577 | TFile file(fileName.Data(), "RECREATE"); | |
578 | fMisAlignArray->Write(); | |
579 | file.Close(); | |
afc8e661 | 580 | |
581 | return true; | |
582 | } | |
583 | ||
584 | //_____________________________________________________________________________ | |
585 | void AliMUONGeometryTransformer::AddModuleTransformer( | |
586 | AliMUONGeometryModuleTransformer* moduleTransformer) | |
587 | { | |
a9aad96e | 588 | /// Add the module transformer to the array |
afc8e661 | 589 | |
ea7ea157 | 590 | // Expand the size if not sufficient |
591 | Int_t moduleId = moduleTransformer->GetModuleId(); | |
592 | if ( moduleId >= fModuleTransformers->GetSize() ) | |
593 | fModuleTransformers->Expand(moduleId+1); | |
594 | ||
595 | fModuleTransformers->AddAt(moduleTransformer, moduleId); | |
afc8e661 | 596 | } |
597 | ||
a7d4e65b | 598 | //_____________________________________________________________________________ |
599 | void AliMUONGeometryTransformer::AddMisAlignModule(Int_t moduleId, | |
600 | const TGeoHMatrix& matrix) | |
601 | { | |
a9aad96e | 602 | /// Build AliAlignObjMatrix with module ID, its volumePath |
a7d4e65b | 603 | /// and the given delta transformation matrix |
604 | ||
605 | if ( ! fMisAlignArray ) | |
606 | fMisAlignArray = new TClonesArray("AliAlignObjMatrix", 200); | |
607 | ||
608 | const AliMUONGeometryModuleTransformer* kTransformer | |
609 | = GetModuleTransformer(moduleId); | |
610 | if ( ! kTransformer ) { | |
611 | AliErrorStream() << "Module " << moduleId << " not found." << endl; | |
612 | return; | |
613 | } | |
614 | ||
bf16b32c | 615 | // Get unique align object ID |
ae079791 | 616 | Int_t volId = AliGeomManager::LayerToVolUID(AliGeomManager::kMUON, moduleId); |
bf16b32c | 617 | |
a7d4e65b | 618 | // Create mis align matrix |
619 | TClonesArray& refArray =*fMisAlignArray; | |
620 | Int_t pos = fMisAlignArray->GetEntriesFast(); | |
d4d05625 | 621 | new (refArray[pos]) AliAlignObjMatrix(GetModuleSymName(moduleId), volId, |
b760c02e | 622 | const_cast<TGeoHMatrix&>(matrix),kTRUE); |
a7d4e65b | 623 | } |
624 | ||
625 | //_____________________________________________________________________________ | |
626 | void AliMUONGeometryTransformer::AddMisAlignDetElement(Int_t detElemId, | |
627 | const TGeoHMatrix& matrix) | |
628 | { | |
a9aad96e | 629 | /// Build AliAlignObjMatrix with detection element ID, its volumePath |
a7d4e65b | 630 | /// and the given delta transformation matrix |
631 | ||
632 | if ( ! fMisAlignArray ) | |
633 | fMisAlignArray = new TClonesArray("AliAlignObjMatrix", 200); | |
634 | ||
635 | const AliMUONGeometryDetElement* kDetElement | |
636 | = GetDetElement(detElemId); | |
637 | ||
638 | if ( ! kDetElement ) { | |
639 | AliErrorStream() << "Det element " << detElemId << " not found." << endl; | |
640 | return; | |
641 | } | |
642 | ||
bf16b32c | 643 | // Get unique align object ID |
ae079791 | 644 | Int_t volId = AliGeomManager::LayerToVolUID(AliGeomManager::kMUON, detElemId); |
bf16b32c | 645 | |
a7d4e65b | 646 | // Create mis align matrix |
647 | TClonesArray& refArray =*fMisAlignArray; | |
648 | Int_t pos = fMisAlignArray->GetEntriesFast(); | |
d4d05625 | 649 | new(refArray[pos]) AliAlignObjMatrix(GetDESymName(detElemId), volId, |
b760c02e | 650 | const_cast<TGeoHMatrix&>(matrix),kTRUE); |
a7d4e65b | 651 | } |
652 | ||
327d1302 | 653 | //______________________________________________________________________________ |
654 | void AliMUONGeometryTransformer::CreateModules() | |
655 | { | |
656 | /// Create modules and their detection elements using info from mapping; | |
657 | /// but do not fill matrices | |
658 | ||
88544f7e | 659 | // Load mapping as its info is used to define modules & DEs |
660 | LoadMapping(); | |
327d1302 | 661 | |
662 | // Loop over geometry module | |
663 | for (Int_t moduleId = 0; moduleId < AliMpConstants::NofGeomModules(); ++moduleId ) { | |
664 | ||
665 | // Create geometry module transformer | |
666 | AliMUONGeometryModuleTransformer* moduleTransformer | |
667 | = new AliMUONGeometryModuleTransformer(moduleId); | |
668 | AddModuleTransformer(moduleTransformer); | |
669 | } | |
670 | ||
671 | // Loop over detection elements | |
672 | AliMpDEIterator it; | |
673 | for ( it.First(); ! it.IsDone(); it.Next() ) { | |
674 | ||
675 | Int_t detElemId = it.CurrentDEId(); | |
676 | Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId); | |
677 | ||
678 | // Get detection element store | |
679 | AliMpExMap* detElements = | |
680 | GetModuleTransformer(moduleId)->GetDetElementStore(); | |
681 | ||
682 | // Add detection element | |
683 | AliMUONGeometryDetElement* detElement | |
684 | = new AliMUONGeometryDetElement(detElemId); | |
685 | detElements->Add(detElemId, detElement); | |
686 | } | |
687 | } | |
688 | ||
d4d05625 | 689 | //_____________________________________________________________________________ |
690 | void AliMUONGeometryTransformer::AddAlignableVolumes() const | |
691 | { | |
df22c125 | 692 | /// Set symbolic names and matrices to alignable objects to TGeo |
d4d05625 | 693 | |
694 | if ( ! gGeoManager ) { | |
695 | AliWarning("TGeoManager not defined."); | |
696 | return; | |
697 | } | |
698 | ||
699 | // Modules | |
700 | for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) { | |
701 | AliMUONGeometryModuleTransformer* module | |
702 | = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); | |
703 | ||
704 | // Set module symbolic name | |
df22c125 | 705 | TGeoPNEntry* pnEntry |
327d1302 | 706 | = gGeoManager->SetAlignableEntry(GetModuleSymName(module->GetModuleId()), |
df22c125 | 707 | module->GetVolumePath()); |
327d1302 | 708 | if ( ! pnEntry ) { |
709 | AliErrorStream() | |
710 | << "Volume path for geometry module " | |
711 | << module->GetModuleId() | |
712 | << " not found in geometry." << endl; | |
713 | } | |
714 | else { | |
715 | // Set module matrix | |
716 | pnEntry->SetMatrix(new TGeoHMatrix(*module->GetTransformation())); | |
717 | // the matrix will be deleted via TGeoManager | |
718 | } | |
d4d05625 | 719 | |
720 | // Detection elements | |
ea7ea157 | 721 | AliMpExMap* detElements = module->GetDetElementStore(); |
d4d05625 | 722 | |
ea7ea157 | 723 | for (Int_t j=0; j<detElements->GetSize(); j++) { |
d4d05625 | 724 | AliMUONGeometryDetElement* detElement |
ea7ea157 | 725 | = (AliMUONGeometryDetElement*)detElements->GetObject(j); |
d4d05625 | 726 | |
727 | // Set detection element symbolic name | |
df22c125 | 728 | TGeoPNEntry* pnEntry |
729 | = gGeoManager->SetAlignableEntry(GetDESymName(detElement->GetId()), | |
730 | detElement->GetVolumePath()); | |
327d1302 | 731 | if ( ! pnEntry ) { |
732 | AliErrorStream() | |
733 | << "Volume path for detection element " | |
734 | << detElement->GetId() | |
735 | << " not found in geometry." << endl; | |
736 | } | |
737 | else { | |
738 | // Set detection element matrix | |
739 | pnEntry->SetMatrix(new TGeoHMatrix(*detElement->GetGlobalTransformation())); | |
740 | // the matrix will be deleted via TGeoManager | |
741 | } | |
d4d05625 | 742 | } |
743 | } | |
744 | } | |
745 | ||
afc8e661 | 746 | //_____________________________________________________________________________ |
ae612121 | 747 | TClonesArray* AliMUONGeometryTransformer::CreateZeroAlignmentData() const |
748 | { | |
749 | /// Create array with zero alignment data | |
750 | ||
751 | // Create array for zero-alignment objects | |
752 | TClonesArray* array = new TClonesArray("AliAlignObjMatrix", 200); | |
753 | TClonesArray& refArray =*array; | |
754 | array->SetOwner(true); | |
755 | ||
756 | // Identity matrix | |
757 | TGeoHMatrix matrix; | |
758 | ||
759 | // Modules | |
760 | for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) { | |
761 | AliMUONGeometryModuleTransformer* module | |
762 | = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); | |
763 | ||
ae612121 | 764 | Int_t moduleId = module->GetModuleId(); |
765 | ||
766 | // Align object ID | |
ae079791 | 767 | Int_t volId = AliGeomManager::LayerToVolUID(AliGeomManager::kMUON, moduleId); |
ae612121 | 768 | |
769 | // Create mis align matrix | |
770 | Int_t pos = array->GetEntriesFast(); | |
d4d05625 | 771 | new (refArray[pos]) AliAlignObjMatrix(GetModuleSymName(moduleId), volId, matrix, kTRUE); |
ae612121 | 772 | } |
773 | ||
774 | // Detection elements | |
775 | for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) { | |
776 | AliMUONGeometryModuleTransformer* moduleTransformer | |
777 | = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i); | |
ea7ea157 | 778 | AliMpExMap* detElements = moduleTransformer->GetDetElementStore(); |
ae612121 | 779 | |
ea7ea157 | 780 | for (Int_t j=0; j<detElements->GetSize(); j++) { |
ae612121 | 781 | AliMUONGeometryDetElement* detElement |
ea7ea157 | 782 | = (AliMUONGeometryDetElement*)detElements->GetObject(j); |
ae612121 | 783 | |
ae612121 | 784 | Int_t detElemId = detElement->GetId(); |
785 | ||
786 | // Align object ID | |
ae079791 | 787 | Int_t volId = AliGeomManager::LayerToVolUID(AliGeomManager::kMUON, detElemId); |
ae612121 | 788 | |
789 | // Create mis align matrix | |
790 | Int_t pos = array->GetEntriesFast(); | |
d4d05625 | 791 | new (refArray[pos]) AliAlignObjMatrix(GetDESymName(detElemId), volId, matrix, kTRUE); |
ae612121 | 792 | } |
793 | } | |
794 | ||
795 | return array; | |
796 | } | |
797 | ||
798 | //_____________________________________________________________________________ | |
f384585c | 799 | void AliMUONGeometryTransformer::ClearMisAlignmentData() |
800 | { | |
801 | /// Clear the array of misalignment data | |
802 | ||
803 | if ( ! fMisAlignArray ) return; | |
804 | ||
805 | fMisAlignArray->Delete(); | |
806 | } | |
807 | ||
808 | //_____________________________________________________________________________ | |
afc8e661 | 809 | void AliMUONGeometryTransformer::Global2Local(Int_t detElemId, |
810 | Float_t xg, Float_t yg, Float_t zg, | |
811 | Float_t& xl, Float_t& yl, Float_t& zl) const | |
812 | { | |
813 | /// Transform point from the global reference frame (ALIC) | |
814 | /// to the local reference frame of the detection element specified | |
815 | /// by detElemId. | |
f7006443 | 816 | |
afc8e661 | 817 | const AliMUONGeometryModuleTransformer* kTransformer |
818 | = GetModuleTransformerByDEId(detElemId); | |
819 | ||
820 | if (kTransformer) | |
821 | kTransformer->Global2Local(detElemId, xg, yg, zg, xl, yl, zl); | |
822 | } | |
823 | ||
824 | //_____________________________________________________________________________ | |
825 | void AliMUONGeometryTransformer::Global2Local(Int_t detElemId, | |
826 | Double_t xg, Double_t yg, Double_t zg, | |
827 | Double_t& xl, Double_t& yl, Double_t& zl) const | |
828 | { | |
829 | /// Transform point from the global reference frame (ALIC) | |
830 | /// to the local reference frame of the detection element specified | |
831 | /// by detElemId. | |
f7006443 | 832 | |
afc8e661 | 833 | const AliMUONGeometryModuleTransformer* kTransformer |
834 | = GetModuleTransformerByDEId(detElemId); | |
835 | ||
836 | if (kTransformer) | |
837 | kTransformer->Global2Local(detElemId, xg, yg, zg, xl, yl, zl); | |
838 | } | |
839 | ||
840 | //_____________________________________________________________________________ | |
841 | void AliMUONGeometryTransformer::Local2Global(Int_t detElemId, | |
842 | Float_t xl, Float_t yl, Float_t zl, | |
843 | Float_t& xg, Float_t& yg, Float_t& zg) const | |
844 | { | |
845 | /// Transform point from the local reference frame of the detection element | |
846 | /// specified by detElemId to the global reference frame (ALIC). | |
847 | ||
848 | const AliMUONGeometryModuleTransformer* kTransformer | |
849 | = GetModuleTransformerByDEId(detElemId); | |
850 | ||
851 | if (kTransformer) | |
852 | kTransformer->Local2Global(detElemId, xl, yl, zl, xg, yg, zg); | |
853 | } | |
854 | ||
855 | //_____________________________________________________________________________ | |
856 | void AliMUONGeometryTransformer::Local2Global(Int_t detElemId, | |
857 | Double_t xl, Double_t yl, Double_t zl, | |
858 | Double_t& xg, Double_t& yg, Double_t& zg) const | |
859 | { | |
860 | /// Transform point from the local reference frame of the detection element | |
861 | /// specified by detElemId to the global reference frame (ALIC). | |
862 | ||
863 | const AliMUONGeometryModuleTransformer* kTransformer | |
864 | = GetModuleTransformerByDEId(detElemId); | |
865 | ||
866 | if (kTransformer) | |
867 | kTransformer->Local2Global(detElemId, xl, yl, zl, xg, yg, zg); | |
868 | } | |
869 | ||
870 | //_____________________________________________________________________________ | |
871 | const AliMUONGeometryModuleTransformer* | |
872 | AliMUONGeometryTransformer::GetModuleTransformer(Int_t index, Bool_t warn) const | |
873 | { | |
a9aad96e | 874 | /// Return the geometry module transformer specified by index |
afc8e661 | 875 | |
876 | return GetModuleTransformerNonConst(index, warn); | |
877 | } | |
878 | ||
879 | //_____________________________________________________________________________ | |
880 | const AliMUONGeometryModuleTransformer* | |
881 | AliMUONGeometryTransformer::GetModuleTransformerByDEId(Int_t detElemId, | |
882 | Bool_t warn) const | |
883 | { | |
a9aad96e | 884 | /// Return the geometry module transformer specified by detection element ID |
afc8e661 | 885 | |
886 | // Get module index | |
ea7ea157 | 887 | Int_t index = AliMpDEManager::GetGeomModuleId(detElemId); |
afc8e661 | 888 | |
889 | return GetModuleTransformer(index, warn); | |
890 | } | |
317aa7dc | 891 | |
a7d4e65b | 892 | //_____________________________________________________________________________ |
893 | const AliMUONGeometryDetElement* | |
894 | AliMUONGeometryTransformer::GetDetElement(Int_t detElemId, Bool_t warn) const | |
895 | { | |
a9aad96e | 896 | /// Return detection element with given detElemId |
a7d4e65b | 897 | |
898 | const AliMUONGeometryModuleTransformer* kTransformer | |
899 | = GetModuleTransformerByDEId(detElemId, warn); | |
900 | ||
901 | if (!kTransformer) return 0; | |
902 | ||
903 | return kTransformer->GetDetElement(detElemId, warn); | |
904 | } | |
905 | ||
317aa7dc | 906 | //_____________________________________________________________________________ |
907 | Bool_t AliMUONGeometryTransformer::HasDE(Int_t detElemId) const | |
908 | { | |
909 | /// Return true if detection element with given detElemId is defined | |
910 | ||
911 | const AliMUONGeometryModuleTransformer* kTransformer | |
912 | = GetModuleTransformerByDEId(detElemId, false); | |
913 | ||
914 | if (!kTransformer) return false; | |
915 | ||
916 | return ( kTransformer->GetDetElement(detElemId, false) != 0 ); | |
917 | } | |
918 | ||
919 |