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. *
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 **************************************************************************/
18 // Class AliMUONGeometryTransformer
19 // ----------------------------
20 // Top container class for geometry transformations
22 // Author: Ivana Hrivnacova, IPN Orsay
26 #include <Riostream.h>
27 #include <TObjArray.h>
32 #include "AliMUONGeometryTransformer.h"
33 #include "AliMUONGeometryModuleTransformer.h"
34 #include "AliMUONGeometryDetElement.h"
35 #include "AliMUONGeometryDEIndexing.h"
36 #include "AliMUONGeometryStore.h"
37 #include "AliMUONGeometryBuilder.h"
40 ClassImp(AliMUONGeometryTransformer)
42 //______________________________________________________________________________
43 AliMUONGeometryTransformer::AliMUONGeometryTransformer(Bool_t isOwner)
45 fModuleTransformers(0)
47 /// Standard constructor
49 // Create array for geometry modules
50 fModuleTransformers = new TObjArray();
51 fModuleTransformers->SetOwner(isOwner);
54 //______________________________________________________________________________
55 AliMUONGeometryTransformer::AliMUONGeometryTransformer()
57 fModuleTransformers(0)
59 /// Default constructor
62 //______________________________________________________________________________
63 AliMUONGeometryTransformer::AliMUONGeometryTransformer(
64 const AliMUONGeometryTransformer& right)
67 /// Copy constructor (not implemented)
69 AliFatal("Copy constructor not provided.");
72 //______________________________________________________________________________
73 AliMUONGeometryTransformer::~AliMUONGeometryTransformer()
77 delete fModuleTransformers;
80 //______________________________________________________________________________
81 AliMUONGeometryTransformer&
82 AliMUONGeometryTransformer::operator=(const AliMUONGeometryTransformer& right)
84 /// Assignement operator (not implemented)
86 // check assignement to self
87 if (this == &right) return *this;
89 AliFatal("Assignement operator not provided.");
98 //_____________________________________________________________________________
99 AliMUONGeometryModuleTransformer*
100 AliMUONGeometryTransformer::GetModuleTransformerNonConst(
101 Int_t index, Bool_t warn) const
103 /// Return the geometry module specified by index
105 if (index < 0 || index >= fModuleTransformers->GetEntriesFast()) {
108 << "Index: " << index << " outside limits" << std::endl;
113 return (AliMUONGeometryModuleTransformer*) fModuleTransformers->At(index);
116 //______________________________________________________________________________
117 TString AliMUONGeometryTransformer::ComposePath(const TString& volName,
120 // Compose path from given volName and copyNo
123 TString path(volName);
130 //______________________________________________________________________________
131 TGeoHMatrix AliMUONGeometryTransformer::GetTransform(
132 Double_t x, Double_t y, Double_t z,
133 Double_t a1, Double_t a2, Double_t a3,
134 Double_t a4, Double_t a5, Double_t a6) const
136 // Builds the transformation from the given parameters
140 return TGeoCombiTrans(TGeoTranslation(x, y, z),
141 TGeoRotation("rot", a1, a2, a3, a4, a5, a6));
145 //______________________________________________________________________________
146 void AliMUONGeometryTransformer::FillData(Int_t moduleId,
147 Double_t x, Double_t y, Double_t z,
148 Double_t a1, Double_t a2, Double_t a3,
149 Double_t a4, Double_t a5, Double_t a6)
151 // Fill the transformation of the module.
154 // Get/Create geometry module parametrisation
156 // Modules numbers in the file are starting from 1
158 AliMUONGeometryModuleTransformer* moduleTransformer
159 = GetModuleTransformerNonConst(moduleId, false);
161 if ( !moduleTransformer) {
162 moduleTransformer = new AliMUONGeometryModuleTransformer(moduleId);
163 AddModuleTransformer(moduleTransformer);
166 // Build the transformation from the parameters
167 TGeoHMatrix transform
168 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
170 moduleTransformer->SetTransformation(transform);
174 //______________________________________________________________________________
175 void AliMUONGeometryTransformer::FillData(
176 Int_t detElemId, const TString& volName, Int_t copyNo,
177 Double_t x, Double_t y, Double_t z,
178 Double_t a1, Double_t a2, Double_t a3,
179 Double_t a4, Double_t a5, Double_t a6)
181 // Fill the transformation of the detection element.
186 = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
189 TString path = ComposePath(volName, copyNo);
191 // Build the transformation from the parameters
192 TGeoHMatrix localTransform
193 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
195 // Get detection element store
196 AliMUONGeometryStore* detElements =
197 GetModuleTransformer(moduleId)->GetDetElementStore();
199 // Add detection element
200 AliMUONGeometryDetElement* detElement
201 = new AliMUONGeometryDetElement(detElemId, path, localTransform);
202 detElements->Add(detElemId, detElement);
204 // Compute global transformation
205 const AliMUONGeometryModuleTransformer* kModuleTransformer
206 = GetModuleTransformer(moduleId);
207 if ( ! kModuleTransformer ) {
208 AliFatal(Form("Module transformation not defined, detElemId %d",
212 TGeoHMatrix globalTransform
213 = AliMUONGeometryBuilder::Multiply(
214 *kModuleTransformer->GetTransformation(),
216 detElement->SetGlobalTransformation(globalTransform);
219 //______________________________________________________________________________
220 TString AliMUONGeometryTransformer::ReadData1(ifstream& in)
222 // Reads and fills modules transformations from a file
223 // Returns true, if reading finished correctly.
227 while ( key == TString("CH") ) {
230 Double_t a1, a2, a3, a4, a5, a6;
247 //cout << "id=" << id << " "
248 // << "position= " << x << ", " << y << ", " << z << " "
249 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
250 // << a4 << ", " << a5 << ", " << a6
254 FillData(id, x, y, z, a1, a2, a3, a4, a5, a6);
263 //______________________________________________________________________________
264 TString AliMUONGeometryTransformer::ReadData2(ifstream& in)
266 // Reads detection elements transformations from a file
267 // Returns true, if reading finished correctly.
271 while ( key == TString("DE") ) {
278 Double_t a1, a2, a3, a4, a5, a6;
296 //cout << "detElemId=" << detElemId << " "
297 // << "volume=" << volumeName << " "
298 // << "copyNo=" << copyNo << " "
299 // << "position= " << x << ", " << y << ", " << z << " "
300 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
301 // << a4 << ", " << a5 << ", " << a6
305 FillData(detElemId, volumeName, copyNo, x, y, z, a1, a2, a3, a4, a5, a6);
314 //______________________________________________________________________________
315 void AliMUONGeometryTransformer::WriteTransform(ofstream& out,
316 const TGeoCombiTrans* transform) const
318 // Writes the transformations
322 const Double_t* xyz = transform->GetTranslation();
323 out << setw(10) << setprecision(4) << xyz[0] << " "
324 << setw(10) << setprecision(4) << xyz[1] << " "
325 << setw(10) << setprecision(4) << xyz[2];
328 const Double_t* rm = transform->GetRotationMatrix();
329 TGeoRotation rotation;
330 rotation.SetMatrix(const_cast<Double_t*>(rm));
331 Double_t a1, a2, a3, a4, a5, a6;
332 rotation.GetAngles(a1, a2, a3, a4, a5, a6);
334 out << setw(8) << setprecision(4) << a1 << " "
335 << setw(8) << setprecision(4) << a2 << " "
336 << setw(8) << setprecision(4) << a3 << " "
337 << setw(8) << setprecision(4) << a4 << " "
338 << setw(8) << setprecision(4) << a5 << " "
339 << setw(8) << setprecision(4) << a6 << " " << endl;
342 //______________________________________________________________________________
343 void AliMUONGeometryTransformer::WriteData1(ofstream& out) const
345 // Writes modules transformations
348 for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
349 AliMUONGeometryModuleTransformer* moduleTransformer
350 = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
351 const TGeoCombiTrans* transform
352 = moduleTransformer->GetTransformation();
355 << setw(4) << moduleTransformer->GetModuleId() + 1 << " "
356 << setw(4) << moduleTransformer->GetDetElementStore()->GetNofEntries() << " ";
358 WriteTransform(out, transform);
363 //______________________________________________________________________________
364 void AliMUONGeometryTransformer::WriteData2(ofstream& out) const
366 // Writes detection elements (envelopes) transformations
370 for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
371 AliMUONGeometryModuleTransformer* moduleTransformer
372 = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
373 AliMUONGeometryStore* detElements
374 = moduleTransformer->GetDetElementStore();
376 for (Int_t j=0; j<detElements->GetNofEntries(); j++) {
377 AliMUONGeometryDetElement* detElement
378 = (AliMUONGeometryDetElement*)detElements->GetEntry(j);
379 const TGeoCombiTrans* transform
380 = detElement->GetLocalTransformation();
382 // Get volume name & copy number from aligned volume
383 string volCopyNo = detElement->GetAlignedVolume().Data();
384 std::string::size_type first = volCopyNo.find('.');
385 std::string volName = volCopyNo.substr(0, first);
386 std::string copyNoStr = volCopyNo.substr(first+1, volCopyNo.length());
387 std::istringstream in(copyNoStr);
393 << setw(4) << detElement->GetId() << " "
395 << setw(4) << copyNo;
397 WriteTransform(out, transform);
407 //______________________________________________________________________________
409 AliMUONGeometryTransformer::ReadTransformations(const TString& fileName)
411 // Reads transformations from a file
412 // Returns true, if reading finished correctly.
416 TString filePath = gSystem->Getenv("ALICE_ROOT");
417 filePath += "/MUON/data/";
418 filePath += fileName;
421 ifstream in(filePath, ios::in);
423 cerr << filePath << endl;
424 AliFatal("File not found.");
430 while ( !in.eof() ) {
431 if (key == TString("CH"))
433 else if (key == TString("DE"))
436 AliFatal(Form("%s key not recognized", key.Data()));
444 //______________________________________________________________________________
446 AliMUONGeometryTransformer::WriteTransformations(const TString& fileName) const
448 // Writes transformations into a file
449 // Returns true, if writing finished correctly.
453 // if builder is not associated with any geometry module
454 if (fModuleTransformers->GetEntriesFast() == 0) return false;
457 TString filePath = gSystem->Getenv("ALICE_ROOT");
458 filePath += "/MUON/data/";
459 filePath += fileName;
462 ofstream out(filePath, ios::out);
464 cerr << filePath << endl;
465 AliError("File not found.");
468 #if !defined (__DECCXX)
469 out.setf(std::ios::fixed);
477 //_____________________________________________________________________________
478 void AliMUONGeometryTransformer::AddModuleTransformer(
479 AliMUONGeometryModuleTransformer* moduleTransformer)
481 /// Add the geometrymodule to the array
483 fModuleTransformers->AddAt(moduleTransformer,
484 moduleTransformer->GetModuleId());
487 //_____________________________________________________________________________
488 void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
489 Float_t xg, Float_t yg, Float_t zg,
490 Float_t& xl, Float_t& yl, Float_t& zl) const
492 /// Transform point from the global reference frame (ALIC)
493 /// to the local reference frame of the detection element specified
496 const AliMUONGeometryModuleTransformer* kTransformer
497 = GetModuleTransformerByDEId(detElemId);
500 kTransformer->Global2Local(detElemId, xg, yg, zg, xl, yl, zl);
503 //_____________________________________________________________________________
504 void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
505 Double_t xg, Double_t yg, Double_t zg,
506 Double_t& xl, Double_t& yl, Double_t& zl) const
508 /// Transform point from the global reference frame (ALIC)
509 /// to the local reference frame of the detection element specified
512 const AliMUONGeometryModuleTransformer* kTransformer
513 = GetModuleTransformerByDEId(detElemId);
516 kTransformer->Global2Local(detElemId, xg, yg, zg, xl, yl, zl);
519 //_____________________________________________________________________________
520 void AliMUONGeometryTransformer::Local2Global(Int_t detElemId,
521 Float_t xl, Float_t yl, Float_t zl,
522 Float_t& xg, Float_t& yg, Float_t& zg) const
524 /// Transform point from the local reference frame of the detection element
525 /// specified by detElemId to the global reference frame (ALIC).
527 const AliMUONGeometryModuleTransformer* kTransformer
528 = GetModuleTransformerByDEId(detElemId);
531 kTransformer->Local2Global(detElemId, xl, yl, zl, xg, yg, zg);
534 //_____________________________________________________________________________
535 void AliMUONGeometryTransformer::Local2Global(Int_t detElemId,
536 Double_t xl, Double_t yl, Double_t zl,
537 Double_t& xg, Double_t& yg, Double_t& zg) const
539 /// Transform point from the local reference frame of the detection element
540 /// specified by detElemId to the global reference frame (ALIC).
542 const AliMUONGeometryModuleTransformer* kTransformer
543 = GetModuleTransformerByDEId(detElemId);
546 kTransformer->Local2Global(detElemId, xl, yl, zl, xg, yg, zg);
549 //_____________________________________________________________________________
550 const AliMUONGeometryModuleTransformer*
551 AliMUONGeometryTransformer::GetModuleTransformer(Int_t index, Bool_t warn) const
553 /// Return the geometry module specified by index
555 return GetModuleTransformerNonConst(index, warn);
558 //_____________________________________________________________________________
559 const AliMUONGeometryModuleTransformer*
560 AliMUONGeometryTransformer::GetModuleTransformerByDEId(Int_t detElemId,
563 /// Return the geometry module specified by index
566 Int_t index = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
568 return GetModuleTransformer(index, warn);
571 //_____________________________________________________________________________
572 Bool_t AliMUONGeometryTransformer::HasDE(Int_t detElemId) const
574 /// Return true if detection element with given detElemId is defined
576 const AliMUONGeometryModuleTransformer* kTransformer
577 = GetModuleTransformerByDEId(detElemId, false);
579 if (!kTransformer) return false;
581 return ( kTransformer->GetDetElement(detElemId, false) != 0 );