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>
31 #include "AliMUONGeometryTransformer.h"
32 #include "AliMUONGeometryModuleTransformer.h"
33 #include "AliMUONGeometryDetElement.h"
34 #include "AliMUONGeometryDEIndexing.h"
35 #include "AliMUONGeometryStore.h"
36 #include "AliMUONGeometryBuilder.h"
39 ClassImp(AliMUONGeometryTransformer)
41 //______________________________________________________________________________
42 AliMUONGeometryTransformer::AliMUONGeometryTransformer(Bool_t isOwner)
44 fModuleTransformers(0)
46 /// Standard constructor
48 // Create array for geometry modules
49 fModuleTransformers = new TObjArray();
50 fModuleTransformers->SetOwner(isOwner);
53 //______________________________________________________________________________
54 AliMUONGeometryTransformer::AliMUONGeometryTransformer()
56 fModuleTransformers(0)
58 /// Default constructor
61 //______________________________________________________________________________
62 AliMUONGeometryTransformer::AliMUONGeometryTransformer(
63 const AliMUONGeometryTransformer& right)
66 /// Copy constructor (not implemented)
68 AliFatal("Copy constructor not provided.");
71 //______________________________________________________________________________
72 AliMUONGeometryTransformer::~AliMUONGeometryTransformer()
76 delete fModuleTransformers;
79 //______________________________________________________________________________
80 AliMUONGeometryTransformer&
81 AliMUONGeometryTransformer::operator=(const AliMUONGeometryTransformer& right)
83 /// Assignement operator (not implemented)
85 // check assignement to self
86 if (this == &right) return *this;
88 AliFatal("Assignement operator not provided.");
97 //_____________________________________________________________________________
98 AliMUONGeometryModuleTransformer*
99 AliMUONGeometryTransformer::GetModuleTransformerNonConst(
100 Int_t index, Bool_t warn) const
102 /// Return the geometry module specified by index
104 if (index < 0 || index >= fModuleTransformers->GetEntriesFast()) {
107 << "Index: " << index << " outside limits" << std::endl;
112 return (AliMUONGeometryModuleTransformer*) fModuleTransformers->At(index);
115 //______________________________________________________________________________
116 TString AliMUONGeometryTransformer::ComposePath(const TString& volName,
119 // Compose path from given volName and copyNo
122 TString path(volName);
129 //______________________________________________________________________________
130 TGeoHMatrix AliMUONGeometryTransformer::GetTransform(
131 Double_t x, Double_t y, Double_t z,
132 Double_t a1, Double_t a2, Double_t a3,
133 Double_t a4, Double_t a5, Double_t a6) const
135 // Builds the transformation from the given parameters
139 return TGeoCombiTrans(TGeoTranslation(x, y, z),
140 TGeoRotation("rot", a1, a2, a3, a4, a5, a6));
144 //______________________________________________________________________________
145 void AliMUONGeometryTransformer::FillData(Int_t moduleId,
146 Double_t x, Double_t y, Double_t z,
147 Double_t a1, Double_t a2, Double_t a3,
148 Double_t a4, Double_t a5, Double_t a6)
150 // Fill the transformation of the module.
153 // Get/Create geometry module parametrisation
155 // Modules numbers in the file are starting from 1
157 AliMUONGeometryModuleTransformer* moduleTransformer
158 = GetModuleTransformerNonConst(moduleId, false);
160 if ( !moduleTransformer) {
161 moduleTransformer = new AliMUONGeometryModuleTransformer(moduleId);
162 AddModuleTransformer(moduleTransformer);
165 // Build the transformation from the parameters
166 TGeoHMatrix transform
167 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
169 moduleTransformer->SetTransformation(transform);
173 //______________________________________________________________________________
174 void AliMUONGeometryTransformer::FillData(
175 Int_t detElemId, const TString& volName, Int_t copyNo,
176 Double_t x, Double_t y, Double_t z,
177 Double_t a1, Double_t a2, Double_t a3,
178 Double_t a4, Double_t a5, Double_t a6)
180 // Fill the transformation of the detection element.
185 = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
188 TString path = ComposePath(volName, copyNo);
190 // Build the transformation from the parameters
191 TGeoHMatrix localTransform
192 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
194 // Get detection element store
195 AliMUONGeometryStore* detElements =
196 GetModuleTransformer(moduleId)->GetDetElementStore();
198 // Add detection element
199 AliMUONGeometryDetElement* detElement
200 = new AliMUONGeometryDetElement(detElemId, path, localTransform);
201 detElements->Add(detElemId, detElement);
203 // Compute global transformation
204 const AliMUONGeometryModuleTransformer* kModuleTransformer
205 = GetModuleTransformer(moduleId);
206 if ( ! kModuleTransformer ) {
207 AliFatal(Form("Module transformation not defined, detElemId %d",
211 TGeoHMatrix globalTransform
212 = AliMUONGeometryBuilder::Multiply(
213 *kModuleTransformer->GetTransformation(),
215 detElement->SetGlobalTransformation(globalTransform);
218 //______________________________________________________________________________
219 TString AliMUONGeometryTransformer::ReadData1(ifstream& in)
221 // Reads and fills modules transformations from a file
222 // Returns true, if reading finished correctly.
226 while ( key == TString("CH") ) {
229 Double_t a1, a2, a3, a4, a5, a6;
246 //cout << "id=" << id << " "
247 // << "position= " << x << ", " << y << ", " << z << " "
248 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
249 // << a4 << ", " << a5 << ", " << a6
253 FillData(id, x, y, z, a1, a2, a3, a4, a5, a6);
262 //______________________________________________________________________________
263 TString AliMUONGeometryTransformer::ReadData2(ifstream& in)
265 // Reads detection elements transformations from a file
266 // Returns true, if reading finished correctly.
270 while ( key == TString("DE") ) {
277 Double_t a1, a2, a3, a4, a5, a6;
295 //cout << "detElemId=" << detElemId << " "
296 // << "volume=" << volumeName << " "
297 // << "copyNo=" << copyNo << " "
298 // << "position= " << x << ", " << y << ", " << z << " "
299 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
300 // << a4 << ", " << a5 << ", " << a6
304 FillData(detElemId, volumeName, copyNo, x, y, z, a1, a2, a3, a4, a5, a6);
313 //______________________________________________________________________________
314 void AliMUONGeometryTransformer::WriteTransform(ofstream& out,
315 const TGeoCombiTrans* transform) const
317 // Writes the transformations
321 const Double_t* xyz = transform->GetTranslation();
322 out << setw(10) << setprecision(4) << xyz[0] << " "
323 << setw(10) << setprecision(4) << xyz[1] << " "
324 << setw(10) << setprecision(4) << xyz[2];
327 const Double_t* rm = transform->GetRotationMatrix();
328 TGeoRotation rotation;
329 rotation.SetMatrix(const_cast<Double_t*>(rm));
330 Double_t a1, a2, a3, a4, a5, a6;
331 rotation.GetAngles(a1, a2, a3, a4, a5, a6);
333 out << setw(8) << setprecision(4) << a1 << " "
334 << setw(8) << setprecision(4) << a2 << " "
335 << setw(8) << setprecision(4) << a3 << " "
336 << setw(8) << setprecision(4) << a4 << " "
337 << setw(8) << setprecision(4) << a5 << " "
338 << setw(8) << setprecision(4) << a6 << " " << endl;
341 //______________________________________________________________________________
342 void AliMUONGeometryTransformer::WriteData1(ofstream& out) const
344 // Writes modules transformations
347 for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
348 AliMUONGeometryModuleTransformer* moduleTransformer
349 = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
350 const TGeoCombiTrans* transform
351 = moduleTransformer->GetTransformation();
354 << setw(4) << moduleTransformer->GetModuleId() + 1 << " "
355 << setw(4) << moduleTransformer->GetDetElementStore()->GetNofEntries() << " ";
357 WriteTransform(out, transform);
362 //______________________________________________________________________________
363 void AliMUONGeometryTransformer::WriteData2(ofstream& out) const
365 // Writes detection elements (envelopes) transformations
369 for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
370 AliMUONGeometryModuleTransformer* moduleTransformer
371 = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
372 AliMUONGeometryStore* detElements
373 = moduleTransformer->GetDetElementStore();
375 for (Int_t j=0; j<detElements->GetNofEntries(); j++) {
376 AliMUONGeometryDetElement* detElement
377 = (AliMUONGeometryDetElement*)detElements->GetEntry(j);
378 const TGeoCombiTrans* transform
379 = detElement->GetLocalTransformation();
381 // Get volume name & copy number from aligned volume
382 string volCopyNo = detElement->GetAlignedVolume().Data();
383 std::string::size_type first = volCopyNo.find('.');
384 std::string volName = volCopyNo.substr(0, first);
385 std::string copyNoStr = volCopyNo.substr(first+1, volCopyNo.length());
386 std::istringstream in(copyNoStr);
392 << setw(4) << detElement->GetId() << " "
394 << setw(4) << copyNo;
396 WriteTransform(out, transform);
406 //______________________________________________________________________________
408 AliMUONGeometryTransformer::ReadTransformations(const TString& fileName)
410 // Reads transformations from a file
411 // Returns true, if reading finished correctly.
415 TString filePath = gSystem->Getenv("ALICE_ROOT");
416 filePath += "/MUON/data/";
417 filePath += fileName;
420 ifstream in(filePath, ios::in);
422 cerr << filePath << endl;
423 AliFatal("File not found.");
429 while ( !in.eof() ) {
430 if (key == TString("CH"))
432 else if (key == TString("DE"))
435 AliFatal(Form("%s key not recognized", key.Data()));
443 //______________________________________________________________________________
445 AliMUONGeometryTransformer::WriteTransformations(const TString& fileName) const
447 // Writes transformations into a file
448 // Returns true, if writing finished correctly.
452 // if builder is not associated with any geometry module
453 if (fModuleTransformers->GetEntriesFast() == 0) return false;
456 TString filePath = gSystem->Getenv("ALICE_ROOT");
457 filePath += "/MUON/data/";
458 filePath += fileName;
461 ofstream out(filePath, ios::out);
463 cerr << filePath << endl;
464 AliError("File not found.");
467 #if !defined (__DECCXX)
468 out.setf(std::ios::fixed);
476 //_____________________________________________________________________________
477 void AliMUONGeometryTransformer::AddModuleTransformer(
478 AliMUONGeometryModuleTransformer* moduleTransformer)
480 /// Add the geometrymodule to the array
482 fModuleTransformers->AddAt(moduleTransformer,
483 moduleTransformer->GetModuleId());
486 //_____________________________________________________________________________
487 void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
488 Float_t xg, Float_t yg, Float_t zg,
489 Float_t& xl, Float_t& yl, Float_t& zl) const
491 /// Transform point from the global reference frame (ALIC)
492 /// to the local reference frame of the detection element specified
495 const AliMUONGeometryModuleTransformer* kTransformer
496 = GetModuleTransformerByDEId(detElemId);
499 kTransformer->Global2Local(detElemId, xg, yg, zg, xl, yl, zl);
502 //_____________________________________________________________________________
503 void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
504 Double_t xg, Double_t yg, Double_t zg,
505 Double_t& xl, Double_t& yl, Double_t& zl) const
507 /// Transform point from the global reference frame (ALIC)
508 /// to the local reference frame of the detection element specified
511 const AliMUONGeometryModuleTransformer* kTransformer
512 = GetModuleTransformerByDEId(detElemId);
515 kTransformer->Global2Local(detElemId, xg, yg, zg, xl, yl, zl);
518 //_____________________________________________________________________________
519 void AliMUONGeometryTransformer::Local2Global(Int_t detElemId,
520 Float_t xl, Float_t yl, Float_t zl,
521 Float_t& xg, Float_t& yg, Float_t& zg) const
523 /// Transform point from the local reference frame of the detection element
524 /// specified by detElemId to the global reference frame (ALIC).
526 const AliMUONGeometryModuleTransformer* kTransformer
527 = GetModuleTransformerByDEId(detElemId);
530 kTransformer->Local2Global(detElemId, xl, yl, zl, xg, yg, zg);
533 //_____________________________________________________________________________
534 void AliMUONGeometryTransformer::Local2Global(Int_t detElemId,
535 Double_t xl, Double_t yl, Double_t zl,
536 Double_t& xg, Double_t& yg, Double_t& zg) const
538 /// Transform point from the local reference frame of the detection element
539 /// specified by detElemId to the global reference frame (ALIC).
541 const AliMUONGeometryModuleTransformer* kTransformer
542 = GetModuleTransformerByDEId(detElemId);
545 kTransformer->Local2Global(detElemId, xl, yl, zl, xg, yg, zg);
548 //_____________________________________________________________________________
549 const AliMUONGeometryModuleTransformer*
550 AliMUONGeometryTransformer::GetModuleTransformer(Int_t index, Bool_t warn) const
552 /// Return the geometry module specified by index
554 return GetModuleTransformerNonConst(index, warn);
557 //_____________________________________________________________________________
558 const AliMUONGeometryModuleTransformer*
559 AliMUONGeometryTransformer::GetModuleTransformerByDEId(Int_t detElemId,
562 /// Return the geometry module specified by index
565 Int_t index = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
567 return GetModuleTransformer(index, warn);
570 //_____________________________________________________________________________
571 Bool_t AliMUONGeometryTransformer::HasDE(Int_t detElemId) const
573 /// Return true if detection element with given detElemId is defined
575 const AliMUONGeometryModuleTransformer* kTransformer
576 = GetModuleTransformerByDEId(detElemId, false);
578 if (!kTransformer) return false;
580 return ( kTransformer->GetDetElement(detElemId, false) != 0 );