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 "AliMUONGeometryStore.h"
35 #include "AliMUONGeometryBuilder.h"
38 ClassImp(AliMUONGeometryTransformer)
40 //______________________________________________________________________________
41 AliMUONGeometryTransformer::AliMUONGeometryTransformer(Bool_t isOwner)
43 fModuleTransformers(0)
45 /// Standard constructor
47 // Create array for geometry modules
48 fModuleTransformers = new TObjArray();
49 fModuleTransformers->SetOwner(isOwner);
52 //______________________________________________________________________________
53 AliMUONGeometryTransformer::AliMUONGeometryTransformer()
55 fModuleTransformers(0)
57 /// Default constructor
60 //______________________________________________________________________________
61 AliMUONGeometryTransformer::AliMUONGeometryTransformer(
62 const AliMUONGeometryTransformer& right)
65 /// Copy constructor (not implemented)
67 AliFatal("Copy constructor not provided.");
70 //______________________________________________________________________________
71 AliMUONGeometryTransformer::~AliMUONGeometryTransformer()
75 delete fModuleTransformers;
78 //______________________________________________________________________________
79 AliMUONGeometryTransformer&
80 AliMUONGeometryTransformer::operator=(const AliMUONGeometryTransformer& right)
82 /// Assignement operator (not implemented)
84 // check assignement to self
85 if (this == &right) return *this;
87 AliFatal("Assignement operator not provided.");
96 //_____________________________________________________________________________
97 AliMUONGeometryModuleTransformer*
98 AliMUONGeometryTransformer::GetModuleTransformerNonConst(
99 Int_t index, Bool_t warn) const
101 /// Return the geometry module specified by index
103 if (index < 0 || index >= fModuleTransformers->GetEntriesFast()) {
106 << "Index: " << index << " outside limits" << std::endl;
111 return (AliMUONGeometryModuleTransformer*) fModuleTransformers->At(index);
114 //______________________________________________________________________________
115 TString AliMUONGeometryTransformer::ComposePath(const TString& volName,
118 // Compose path from given volName and copyNo
121 TString path(volName);
128 //______________________________________________________________________________
129 TGeoHMatrix AliMUONGeometryTransformer::GetTransform(
130 Double_t x, Double_t y, Double_t z,
131 Double_t a1, Double_t a2, Double_t a3,
132 Double_t a4, Double_t a5, Double_t a6) const
134 // Builds the transformation from the given parameters
138 return TGeoCombiTrans(TGeoTranslation(x, y, z),
139 TGeoRotation("rot", a1, a2, a3, a4, a5, a6));
143 //______________________________________________________________________________
144 void AliMUONGeometryTransformer::FillData(Int_t moduleId,
145 Double_t x, Double_t y, Double_t z,
146 Double_t a1, Double_t a2, Double_t a3,
147 Double_t a4, Double_t a5, Double_t a6)
149 // Fill the transformation of the module.
152 // Get/Create geometry module parametrisation
154 // Modules numbers in the file are starting from 1
156 AliMUONGeometryModuleTransformer* moduleTransformer
157 = GetModuleTransformerNonConst(moduleId, false);
159 if ( !moduleTransformer) {
160 moduleTransformer = new AliMUONGeometryModuleTransformer(moduleId);
161 AddModuleTransformer(moduleTransformer);
164 // Build the transformation from the parameters
165 TGeoHMatrix transform
166 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
168 moduleTransformer->SetTransformation(transform);
172 //______________________________________________________________________________
173 void AliMUONGeometryTransformer::FillData(
174 Int_t detElemId, const TString& volName, Int_t copyNo,
175 Double_t x, Double_t y, Double_t z,
176 Double_t a1, Double_t a2, Double_t a3,
177 Double_t a4, Double_t a5, Double_t a6)
179 // Fill the transformation of the detection element.
183 Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
186 TString path = ComposePath(volName, copyNo);
188 // Build the transformation from the parameters
189 TGeoHMatrix localTransform
190 = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
192 // Get detection element store
193 AliMUONGeometryStore* detElements =
194 GetModuleTransformer(moduleId)->GetDetElementStore();
196 // Add detection element
197 AliMUONGeometryDetElement* detElement
198 = new AliMUONGeometryDetElement(detElemId, path, localTransform);
199 detElements->Add(detElemId, detElement);
201 // Compute global transformation
202 const AliMUONGeometryModuleTransformer* kModuleTransformer
203 = GetModuleTransformer(moduleId);
204 if ( ! kModuleTransformer ) {
205 AliFatal(Form("Module transformation not defined, detElemId %d",
209 TGeoHMatrix globalTransform
210 = AliMUONGeometryBuilder::Multiply(
211 *kModuleTransformer->GetTransformation(),
213 detElement->SetGlobalTransformation(globalTransform);
216 //______________________________________________________________________________
217 TString AliMUONGeometryTransformer::ReadData1(ifstream& in)
219 // Reads and fills modules transformations from a file
220 // Returns true, if reading finished correctly.
224 while ( key == TString("CH") ) {
227 Double_t a1, a2, a3, a4, a5, a6;
244 //cout << "id=" << id << " "
245 // << "position= " << x << ", " << y << ", " << z << " "
246 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
247 // << a4 << ", " << a5 << ", " << a6
251 FillData(id, x, y, z, a1, a2, a3, a4, a5, a6);
260 //______________________________________________________________________________
261 TString AliMUONGeometryTransformer::ReadData2(ifstream& in)
263 // Reads detection elements transformations from a file
264 // Returns true, if reading finished correctly.
268 while ( key == TString("DE") ) {
275 Double_t a1, a2, a3, a4, a5, a6;
293 //cout << "detElemId=" << detElemId << " "
294 // << "volume=" << volumeName << " "
295 // << "copyNo=" << copyNo << " "
296 // << "position= " << x << ", " << y << ", " << z << " "
297 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
298 // << a4 << ", " << a5 << ", " << a6
302 FillData(detElemId, volumeName, copyNo, x, y, z, a1, a2, a3, a4, a5, a6);
311 //______________________________________________________________________________
312 void AliMUONGeometryTransformer::WriteTransform(ofstream& out,
313 const TGeoCombiTrans* transform) const
315 // Writes the transformations
319 const Double_t* xyz = transform->GetTranslation();
320 out << setw(10) << setprecision(4) << xyz[0] << " "
321 << setw(10) << setprecision(4) << xyz[1] << " "
322 << setw(10) << setprecision(4) << xyz[2];
325 const Double_t* rm = transform->GetRotationMatrix();
326 TGeoRotation rotation;
327 rotation.SetMatrix(const_cast<Double_t*>(rm));
328 Double_t a1, a2, a3, a4, a5, a6;
329 rotation.GetAngles(a1, a2, a3, a4, a5, a6);
331 out << setw(8) << setprecision(4) << a1 << " "
332 << setw(8) << setprecision(4) << a2 << " "
333 << setw(8) << setprecision(4) << a3 << " "
334 << setw(8) << setprecision(4) << a4 << " "
335 << setw(8) << setprecision(4) << a5 << " "
336 << setw(8) << setprecision(4) << a6 << " " << endl;
339 //______________________________________________________________________________
340 void AliMUONGeometryTransformer::WriteData1(ofstream& out) const
342 // Writes modules transformations
345 for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
346 AliMUONGeometryModuleTransformer* moduleTransformer
347 = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
348 const TGeoCombiTrans* transform
349 = moduleTransformer->GetTransformation();
352 << setw(4) << moduleTransformer->GetModuleId() + 1 << " "
353 << setw(4) << moduleTransformer->GetDetElementStore()->GetNofEntries() << " ";
355 WriteTransform(out, transform);
360 //______________________________________________________________________________
361 void AliMUONGeometryTransformer::WriteData2(ofstream& out) const
363 // Writes detection elements (envelopes) transformations
367 for (Int_t i=0; i<fModuleTransformers->GetEntriesFast(); i++) {
368 AliMUONGeometryModuleTransformer* moduleTransformer
369 = (AliMUONGeometryModuleTransformer*)fModuleTransformers->At(i);
370 AliMUONGeometryStore* detElements
371 = moduleTransformer->GetDetElementStore();
373 for (Int_t j=0; j<detElements->GetNofEntries(); j++) {
374 AliMUONGeometryDetElement* detElement
375 = (AliMUONGeometryDetElement*)detElements->GetEntry(j);
376 const TGeoCombiTrans* transform
377 = detElement->GetLocalTransformation();
379 // Get volume name & copy number from aligned volume
380 string volCopyNo = detElement->GetAlignedVolume().Data();
381 std::string::size_type first = volCopyNo.find('.');
382 std::string volName = volCopyNo.substr(0, first);
383 std::string copyNoStr = volCopyNo.substr(first+1, volCopyNo.length());
384 std::istringstream in(copyNoStr);
390 << setw(4) << detElement->GetId() << " "
392 << setw(4) << copyNo;
394 WriteTransform(out, transform);
404 //______________________________________________________________________________
406 AliMUONGeometryTransformer::ReadTransformations(const TString& fileName)
408 // Reads transformations from a file
409 // Returns true, if reading finished correctly.
413 TString filePath = gSystem->Getenv("ALICE_ROOT");
414 filePath += "/MUON/data/";
415 filePath += fileName;
418 ifstream in(filePath, ios::in);
420 cerr << filePath << endl;
421 AliFatal("File not found.");
427 while ( !in.eof() ) {
428 if (key == TString("CH"))
430 else if (key == TString("DE"))
433 AliFatal(Form("%s key not recognized", key.Data()));
441 //______________________________________________________________________________
443 AliMUONGeometryTransformer::WriteTransformations(const TString& fileName) const
445 // Writes transformations into a file
446 // Returns true, if writing finished correctly.
450 // if builder is not associated with any geometry module
451 if (fModuleTransformers->GetEntriesFast() == 0) return false;
454 TString filePath = gSystem->Getenv("ALICE_ROOT");
455 filePath += "/MUON/data/";
456 filePath += fileName;
459 ofstream out(filePath, ios::out);
461 cerr << filePath << endl;
462 AliError("File not found.");
465 #if !defined (__DECCXX)
466 out.setf(std::ios::fixed);
474 //_____________________________________________________________________________
475 void AliMUONGeometryTransformer::AddModuleTransformer(
476 AliMUONGeometryModuleTransformer* moduleTransformer)
478 /// Add the geometrymodule to the array
480 fModuleTransformers->AddAt(moduleTransformer,
481 moduleTransformer->GetModuleId());
484 //_____________________________________________________________________________
485 void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
486 Float_t xg, Float_t yg, Float_t zg,
487 Float_t& xl, Float_t& yl, Float_t& zl) const
489 /// Transform point from the global reference frame (ALIC)
490 /// to the local reference frame of the detection element specified
493 const AliMUONGeometryModuleTransformer* kTransformer
494 = GetModuleTransformerByDEId(detElemId);
497 kTransformer->Global2Local(detElemId, xg, yg, zg, xl, yl, zl);
500 //_____________________________________________________________________________
501 void AliMUONGeometryTransformer::Global2Local(Int_t detElemId,
502 Double_t xg, Double_t yg, Double_t zg,
503 Double_t& xl, Double_t& yl, Double_t& zl) const
505 /// Transform point from the global reference frame (ALIC)
506 /// to the local reference frame of the detection element specified
509 const AliMUONGeometryModuleTransformer* kTransformer
510 = GetModuleTransformerByDEId(detElemId);
513 kTransformer->Global2Local(detElemId, xg, yg, zg, xl, yl, zl);
516 //_____________________________________________________________________________
517 void AliMUONGeometryTransformer::Local2Global(Int_t detElemId,
518 Float_t xl, Float_t yl, Float_t zl,
519 Float_t& xg, Float_t& yg, Float_t& zg) const
521 /// Transform point from the local reference frame of the detection element
522 /// specified by detElemId to the global reference frame (ALIC).
524 const AliMUONGeometryModuleTransformer* kTransformer
525 = GetModuleTransformerByDEId(detElemId);
528 kTransformer->Local2Global(detElemId, xl, yl, zl, xg, yg, zg);
531 //_____________________________________________________________________________
532 void AliMUONGeometryTransformer::Local2Global(Int_t detElemId,
533 Double_t xl, Double_t yl, Double_t zl,
534 Double_t& xg, Double_t& yg, Double_t& zg) const
536 /// Transform point from the local reference frame of the detection element
537 /// specified by detElemId to the global reference frame (ALIC).
539 const AliMUONGeometryModuleTransformer* kTransformer
540 = GetModuleTransformerByDEId(detElemId);
543 kTransformer->Local2Global(detElemId, xl, yl, zl, xg, yg, zg);
546 //_____________________________________________________________________________
547 const AliMUONGeometryModuleTransformer*
548 AliMUONGeometryTransformer::GetModuleTransformer(Int_t index, Bool_t warn) const
550 /// Return the geometry module specified by index
552 return GetModuleTransformerNonConst(index, warn);
555 //_____________________________________________________________________________
556 const AliMUONGeometryModuleTransformer*
557 AliMUONGeometryTransformer::GetModuleTransformerByDEId(Int_t detElemId,
560 /// Return the geometry module specified by index
563 Int_t index = AliMUONGeometryStore::GetModuleId(detElemId);
565 return GetModuleTransformer(index, warn);
568 //_____________________________________________________________________________
569 Bool_t AliMUONGeometryTransformer::HasDE(Int_t detElemId) const
571 /// Return true if detection element with given detElemId is defined
573 const AliMUONGeometryModuleTransformer* kTransformer
574 = GetModuleTransformerByDEId(detElemId, false);
576 if (!kTransformer) return false;
578 return ( kTransformer->GetDetElement(detElemId, false) != 0 );