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"
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 transform
192 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
194 // Compose TGeoCombiTrans
195 TGeoCombiTrans newCombiTransform(transform);
197 // Get detection element store
198 AliMUONGeometryStore* detElements =
199 GetModuleTransformer(moduleId)->GetDetElementStore();
201 // Add detection element
202 detElements->Add(detElemId,
203 new AliMUONGeometryDetElement(detElemId, path, newCombiTransform));
206 //______________________________________________________________________________
207 TString AliMUONGeometryTransformer::ReadData1(ifstream& in)
209 // Reads and fills modules transformations from a file
210 // Returns true, if reading finished correctly.
214 while ( key == TString("CH") ) {
217 Double_t a1, a2, a3, a4, a5, a6;
234 //cout << "id=" << id << " "
235 // << "position= " << x << ", " << y << ", " << z << " "
236 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
237 // << a4 << ", " << a5 << ", " << a6
241 FillData(id, x, y, z, a1, a2, a3, a4, a5, a6);
250 //______________________________________________________________________________
251 TString AliMUONGeometryTransformer::ReadData2(ifstream& in)
253 // Reads detection elements transformations from a file
254 // Returns true, if reading finished correctly.
258 while ( key == TString("DE") ) {
265 Double_t a1, a2, a3, a4, a5, a6;
283 //cout << "detElemId=" << detElemId << " "
284 // << "volume=" << volumeName << " "
285 // << "copyNo=" << copyNo << " "
286 // << "position= " << x << ", " << y << ", " << z << " "
287 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
288 // << a4 << ", " << a5 << ", " << a6
292 FillData(detElemId, volumeName, copyNo, x, y, z, a1, a2, a3, a4, a5, a6);
301 //______________________________________________________________________________
302 void AliMUONGeometryTransformer::WriteTransform(ofstream& out,
303 const TGeoCombiTrans* transform) const
305 // Writes the transformations
309 const Double_t* xyz = transform->GetTranslation();
310 out << setw(10) << setprecision(4) << xyz[0] << " "
311 << setw(10) << setprecision(4) << xyz[1] << " "
312 << setw(10) << setprecision(4) << xyz[2];
315 const Double_t* rm = transform->GetRotationMatrix();
316 TGeoRotation rotation;
317 rotation.SetMatrix(const_cast<Double_t*>(rm));
318 Double_t a1, a2, a3, a4, a5, a6;
319 rotation.GetAngles(a1, a2, a3, a4, a5, a6);
321 out << setw(8) << setprecision(4) << a1 << " "
322 << setw(8) << setprecision(4) << a2 << " "
323 << setw(8) << setprecision(4) << a3 << " "
324 << setw(8) << setprecision(4) << a4 << " "
325 << setw(8) << setprecision(4) << a5 << " "
326 << setw(8) << setprecision(4) << a6 << " " << endl;
329 //______________________________________________________________________________
330 void AliMUONGeometryTransformer::WriteData1(ofstream& out) const
332 // Writes modules transformations
335 for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
336 AliMUONGeometryModuleTransformer* moduleTransformer
337 = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
338 const TGeoCombiTrans* transform
339 = moduleTransformer->GetTransformation();
342 << setw(4) << moduleTransformer->GetModuleId() + 1 << " "
343 << setw(4) << moduleTransformer->GetDetElementStore()->GetNofEntries() << " ";
345 WriteTransform(out, transform);
350 //______________________________________________________________________________
351 void AliMUONGeometryTransformer::WriteData2(ofstream& out) const
353 // Writes detection elements (envelopes) transformations
357 for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
358 AliMUONGeometryModuleTransformer* moduleTransformer
359 = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
360 AliMUONGeometryStore* detElements
361 = moduleTransformer->GetDetElementStore();
363 for (Int_t j=0; j<detElements->GetNofEntries(); j++) {
364 AliMUONGeometryDetElement* detElement
365 = (AliMUONGeometryDetElement*)detElements->GetEntry(j);
366 const TGeoCombiTrans* transform
367 = detElement->GetLocalTransformation();
369 // Get volume name & copy number from aligned volume
370 string volCopyNo = detElement->GetAlignedVolume().Data();
371 std::string::size_type first = volCopyNo.find('.');
372 std::string volName = volCopyNo.substr(0, first);
373 std::string copyNoStr = volCopyNo.substr(first+1, volCopyNo.length());
374 std::istringstream in(copyNoStr);
380 << setw(4) << detElement->GetId() << " "
382 << setw(4) << copyNo;
384 WriteTransform(out, transform);
394 //______________________________________________________________________________
396 AliMUONGeometryTransformer::ReadTransformations(const TString& fileName)
398 // Reads transformations from a file
399 // Returns true, if reading finished correctly.
403 TString filePath = gSystem->Getenv("ALICE_ROOT");
404 filePath += "/MUON/data/";
405 filePath += fileName;
408 ifstream in(filePath, ios::in);
410 cerr << filePath << endl;
411 AliFatal("File not found.");
417 while ( !in.eof() ) {
418 if (key == TString("CH"))
420 else if (key == TString("DE"))
423 AliFatal(Form("%s key not recognized", key.Data()));
431 //______________________________________________________________________________
433 AliMUONGeometryTransformer::WriteTransformations(const TString& fileName) const
435 // Writes transformations into a file
436 // Returns true, if writing finished correctly.
440 // if builder is not associated with any geometry module
441 if (fModuleTransformers->GetEntriesFast() == 0) return false;
444 TString filePath = gSystem->Getenv("ALICE_ROOT");
445 filePath += "/MUON/data/";
446 filePath += fileName;
449 ofstream out(filePath, ios::out);
451 cerr << filePath << endl;
452 AliError("File not found.");
455 #if !defined (__DECCXX)
456 out.setf(std::ios::fixed);
464 //_____________________________________________________________________________
465 void AliMUONGeometryTransformer::AddModuleTransformer(
466 AliMUONGeometryModuleTransformer* moduleTransformer)
468 /// Add the geometrymodule to the array
470 fModuleTransformers->AddAt(moduleTransformer,
471 moduleTransformer->GetModuleId());
474 //_____________________________________________________________________________
475 void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
476 Float_t xg, Float_t yg, Float_t zg,
477 Float_t& xl, Float_t& yl, Float_t& zl) const
479 /// Transform point from the global reference frame (ALIC)
480 /// to the local reference frame of the detection element specified
483 const AliMUONGeometryModuleTransformer* kTransformer
484 = GetModuleTransformerByDEId(detElemId);
487 kTransformer->Global2Local(detElemId, xg, yg, zg, xl, yl, zl);
490 //_____________________________________________________________________________
491 void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
492 Double_t xg, Double_t yg, Double_t zg,
493 Double_t& xl, Double_t& yl, Double_t& zl) const
495 /// Transform point from the global reference frame (ALIC)
496 /// to the local reference frame of the detection element specified
499 const AliMUONGeometryModuleTransformer* kTransformer
500 = GetModuleTransformerByDEId(detElemId);
503 kTransformer->Global2Local(detElemId, xg, yg, zg, xl, yl, zl);
506 //_____________________________________________________________________________
507 void AliMUONGeometryTransformer::Local2Global(Int_t detElemId,
508 Float_t xl, Float_t yl, Float_t zl,
509 Float_t& xg, Float_t& yg, Float_t& zg) const
511 /// Transform point from the local reference frame of the detection element
512 /// specified by detElemId to the global reference frame (ALIC).
514 const AliMUONGeometryModuleTransformer* kTransformer
515 = GetModuleTransformerByDEId(detElemId);
518 kTransformer->Local2Global(detElemId, xl, yl, zl, xg, yg, zg);
521 //_____________________________________________________________________________
522 void AliMUONGeometryTransformer::Local2Global(Int_t detElemId,
523 Double_t xl, Double_t yl, Double_t zl,
524 Double_t& xg, Double_t& yg, Double_t& zg) const
526 /// Transform point from the local reference frame of the detection element
527 /// specified by detElemId to the global reference frame (ALIC).
529 const AliMUONGeometryModuleTransformer* kTransformer
530 = GetModuleTransformerByDEId(detElemId);
533 kTransformer->Local2Global(detElemId, xl, yl, zl, xg, yg, zg);
536 //_____________________________________________________________________________
537 const AliMUONGeometryModuleTransformer*
538 AliMUONGeometryTransformer::GetModuleTransformer(Int_t index, Bool_t warn) const
540 /// Return the geometry module specified by index
542 return GetModuleTransformerNonConst(index, warn);
545 //_____________________________________________________________________________
546 const AliMUONGeometryModuleTransformer*
547 AliMUONGeometryTransformer::GetModuleTransformerByDEId(Int_t detElemId,
550 /// Return the geometry module specified by index
553 Int_t index = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
555 return GetModuleTransformer(index, warn);
558 //_____________________________________________________________________________
559 Bool_t AliMUONGeometryTransformer::HasDE(Int_t detElemId) const
561 /// Return true if detection element with given detElemId is defined
563 const AliMUONGeometryModuleTransformer* kTransformer
564 = GetModuleTransformerByDEId(detElemId, false);
566 if (!kTransformer) return false;
568 return ( kTransformer->GetDetElement(detElemId, false) != 0 );