1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
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 purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 // Class AliMUONVGeometryBuilder
19 // -----------------------------
20 // Abstract base class for geometry construction per chamber(s).
21 // Author: Ivana Hrivnacova, IPN Orsay
24 #include <Riostream.h>
25 #include <TObjArray.h>
27 #include <TGeoMatrix.h>
28 #include <TVirtualMC.h>
30 #include "AliMUONVGeometryBuilder.h"
31 #include "AliMUONChamber.h"
32 #include "AliMUONChamberGeometry.h"
33 #include "AliMUONGeometryTransformStore.h"
34 #include "AliMUONGeometrySVMap.h"
35 #include "AliMUONGeometryEnvelopeStore.h"
36 #include "AliMUONGeometryEnvelope.h"
37 #include "AliMUONGeometryConstituent.h"
38 #include "AliMUONConstants.h"
40 ClassImp(AliMUONVGeometryBuilder)
42 const TString AliMUONVGeometryBuilder::fgkTransformFileNamePrefix = "transform_";
43 const TString AliMUONVGeometryBuilder::fgkSVMapFileNamePrefix = "svmap_";
44 const TString AliMUONVGeometryBuilder::fgkOutFileNameSuffix = ".out";
46 //______________________________________________________________________________
47 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const TString& fileName,
48 AliMUONChamber* ch1, AliMUONChamber* ch2,
49 AliMUONChamber* ch3, AliMUONChamber* ch4,
50 AliMUONChamber* ch5, AliMUONChamber* ch6)
52 fTransformFileName(fgkTransformFileNamePrefix+fileName),
53 fSVMapFileName(fgkSVMapFileNamePrefix+fileName),
56 // Standard constructor
58 // Create the chambers array
59 fChambers = new TObjArray();
61 if (ch1) fChambers->Add(ch1);
62 if (ch2) fChambers->Add(ch2);
63 if (ch3) fChambers->Add(ch3);
64 if (ch4) fChambers->Add(ch4);
65 if (ch5) fChambers->Add(ch5);
66 if (ch6) fChambers->Add(ch6);
70 //______________________________________________________________________________
71 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
77 // Default constructor
81 //______________________________________________________________________________
82 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
85 // Protected copy constructor
87 Fatal("Copy constructor",
88 "Copy constructor is not implemented.");
91 //______________________________________________________________________________
92 AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() {
95 fChambers->Clear(); // Sets pointers to 0 sinche it is not the owner
100 //______________________________________________________________________________
101 AliMUONVGeometryBuilder&
102 AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs)
104 // Protected assignement operator
106 // check assignement to self
107 if (this == &rhs) return *this;
110 "Assignment operator is not implemented.");
119 //______________________________________________________________________________
120 TString AliMUONVGeometryBuilder::ComposePath(const TString& volName,
123 // Compose path from given volName and copyNo
126 TString path(volName);
134 //______________________________________________________________________________
135 void AliMUONVGeometryBuilder::MapSV(const TString& path0,
136 const TString& volName, Int_t detElemId) const
138 // Update the path with all daughters volumes recursively
139 // and map it to the detection element Id if it is a sensitive volume
142 Int_t nofDaughters = gMC->NofVolDaughters(volName);
143 if (nofDaughters == 0) {
145 // Get the name of the last volume in the path
146 Ssiz_t npos1 = path0.Last('/')+1;
147 Ssiz_t npos2 = path0.Last('.');
148 TString volName(path0(npos1, npos2-npos1));
150 // Check if it is sensitive volume
151 Int_t chamberId = AliMUONConstants::GetChamberId(detElemId);
152 AliMUONChamberGeometry* geometry = GetChamber(chamberId)->GetGeometry();
153 if (geometry->IsSensitiveVolume(volName)) {
154 //cout << ".. adding to the map "
155 // << path0 << " " << detElemId << endl;
156 FillData(path0, detElemId);
161 for (Int_t i=0; i<nofDaughters; i++) {
162 Int_t copyNo = gMC->VolDaughterCopyNo(volName, i);
163 TString newName = gMC->VolDaughterName(volName, i);
165 TString path = path0;
167 path += ComposePath(newName, copyNo);
169 MapSV(path, newName, detElemId);
174 //______________________________________________________________________________
175 void AliMUONVGeometryBuilder::MapSV(const TString& /*path0*/,
176 const TString& /*volName*/,
177 Int_t /*detElemId*/) const
179 // Update the path with all daughters volumes recursively
180 // and map it to the detection element Id if it is a sensitive volume
183 Warning("MapSV", "Not yet available");
186 //______________________________________________________________________________
187 void AliMUONVGeometryBuilder::FillData(Int_t chamberId,
188 Double_t x, Double_t y, Double_t z,
189 Double_t a1, Double_t a2, Double_t a3,
190 Double_t a4, Double_t a5, Double_t a6) const
192 // Fill the transformation of the chamber.
196 // Chambers numbers in the file are starting from 1
198 GetChamber(chamberId)->GetGeometry()
199 ->SetTranslation(TGeoTranslation(x, y, z));
200 GetChamber(chamberId)->GetGeometry()
201 ->SetRotation(TGeoRotation("rot", a1, a2, a3, a4, a5, a6));
204 //______________________________________________________________________________
205 void AliMUONVGeometryBuilder::FillData(
206 Int_t detElemId, const TString& volName, Int_t copyNo,
207 Double_t x, Double_t y, Double_t z,
208 Double_t a1, Double_t a2, Double_t a3,
209 Double_t a4, Double_t a5, Double_t a6) const
211 // Fill the transformation of the detection element.
215 Int_t chamberId = AliMUONConstants::GetChamberId(detElemId);
217 // Get chamber transformations
218 AliMUONGeometryTransformStore* transforms
219 = GetTransforms(chamberId);
222 TString path = ComposePath(volName, copyNo);
225 TGeoCombiTrans transform(path, x, y, z,
226 new TGeoRotation(path, a1, a2, a3, a4, a5, a6));
228 // Add detection element transformation
229 transforms->Add(detElemId, path, transform);
232 //______________________________________________________________________________
233 void AliMUONVGeometryBuilder::FillData(
234 const TString& sensVolumePath, Int_t detElemId) const
236 // Fill the mapping of the sensitive volume path to the detection element.
240 Int_t chamberId = AliMUONConstants::GetChamberId(detElemId);
242 // Get chamber transformations
243 AliMUONGeometrySVMap* svMap = GetSVMap(chamberId);
245 // Map the sensitive volume to detection element
246 svMap->Add(sensVolumePath, detElemId);
249 //______________________________________________________________________________
250 TString AliMUONVGeometryBuilder::ReadData1(ifstream& in) const
252 // Reads and fills chambers transformations from a file
253 // Returns true, if reading finished correctly.
257 while ( key == TString("CH") ) {
260 Double_t a1, a2, a3, a4, a5, a6;
276 //cout << "id=" << id << " "
277 // << "position= " << x << ", " << y << ", " << z << " "
278 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
279 // << a4 << ", " << a5 << ", " << a6
283 FillData(id, x, y, z, a1, a2, a3, a4, a5, a6);
292 //______________________________________________________________________________
293 TString AliMUONVGeometryBuilder::ReadData2(ifstream& in) const
295 // Reads detection elements transformations from a file
296 // Returns true, if reading finished correctly.
300 while ( key == TString("DE") ) {
307 Double_t a1, a2, a3, a4, a5, a6;
325 //cout << "detElemId=" << detElemId << " "
326 // << "volume=" << volumeName << " "
327 // << "copyNo=" << copyNo << " "
328 // << "position= " << x << ", " << y << ", " << z << " "
329 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
330 // << a4 << ", " << a5 << ", " << a6
334 FillData(detElemId, volumeName, copyNo, x, y, z, a1, a2, a3, a4, a5, a6);
343 //______________________________________________________________________________
344 TString AliMUONVGeometryBuilder::ReadData3(ifstream& in) const
346 // Reads detection elements transformations from a file
347 // Returns true, if reading finished correctly.
351 while ( key == TString("SV") ) {
360 //cout << "volumePath=" << volumePath << " "
361 // << "detElemId=" << detElemId
365 FillData(volumePath, detElemId);
374 //______________________________________________________________________________
375 void AliMUONVGeometryBuilder::WriteTransform(ofstream& out,
376 const TGeoCombiTrans* transform) const
378 // Writes the transformations
382 const Double_t* xyz = transform->GetTranslation();
383 out << setw(10) << setprecision(4) << xyz[0] << " "
384 << setw(10) << setprecision(4) << xyz[1] << " "
385 << setw(10) << setprecision(4) << xyz[2];
388 Double_t a1, a2, a3, a4, a5, a6;
389 TGeoRotation* rotation = transform->GetRotation();
390 rotation->GetAngles(a1, a2, a3, a4, a5, a6);
391 out << setw(8) << setprecision(4) << a1 << " "
392 << setw(8) << setprecision(4) << a2 << " "
393 << setw(8) << setprecision(4) << a3 << " "
394 << setw(8) << setprecision(4) << a4 << " "
395 << setw(8) << setprecision(4) << a5 << " "
396 << setw(8) << setprecision(4) << a6 << " " << endl;
399 //______________________________________________________________________________
400 void AliMUONVGeometryBuilder::WriteData1(ofstream& out) const
402 // Writes chamber transformations
405 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
406 AliMUONChamber* chamber
407 = (AliMUONChamber*)fChambers->At(i);
408 AliMUONChamberGeometry* chamberGeometry
409 = chamber->GetGeometry();
410 const TGeoCombiTrans* transform
411 = chamberGeometry->GetTransformation();
414 << setw(4) << chamber->GetId() + 1 << " ";
416 WriteTransform(out, transform);
421 //______________________________________________________________________________
422 void AliMUONVGeometryBuilder::WriteData2(ofstream& out) const
424 // Writes detection elements (envelopes) transformations
428 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
429 AliMUONChamber* chamber
430 = (AliMUONChamber*)fChambers->At(i);
431 AliMUONChamberGeometry* chamberGeometry
432 = chamber->GetGeometry();
433 const TObjArray* envelopes
434 = chamberGeometry->GetEnvelopeStore()->GetEnvelopes();
436 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
437 AliMUONGeometryEnvelope* envelope
438 = (AliMUONGeometryEnvelope*)envelopes->At(j);
439 const TGeoCombiTrans* transform
440 = envelope->GetTransformation();
442 // skip envelope not corresponding to detection element
443 if(envelope->GetUniqueID() == 0) continue;
446 << setw(4) << envelope->GetUniqueID() << " "
447 << envelope->GetName() << " "
448 << setw(4)<< envelope->GetCopyNo();
450 WriteTransform(out, transform);
456 //______________________________________________________________________________
457 void AliMUONVGeometryBuilder::WriteData3(ofstream& out) const
459 // Writes association of sensitive volumes and detection elements
460 // from the sensitive volume map
463 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
464 AliMUONChamber* chamber
465 = (AliMUONChamber*)fChambers->At(i);
466 AliMUONChamberGeometry* chamberGeometry
467 = chamber->GetGeometry();
468 AliMUONGeometrySVMap* svMap
469 = chamberGeometry->GetSVMap();
471 svMap->WriteMap(out);
480 //______________________________________________________________________________
481 AliMUONChamber* AliMUONVGeometryBuilder::GetChamber(Int_t chamberId) const
483 // Returns the chamber specified by chamberId
486 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
487 AliMUONChamber* chamber = (AliMUONChamber*)fChambers->At(i);
488 if ( chamber->GetId() == chamberId) return chamber;
494 //______________________________________________________________________________
495 AliMUONGeometryEnvelopeStore*
496 AliMUONVGeometryBuilder::GetEnvelopes(Int_t chamberId) const
498 // Returns the envelope store of the chamber specified by chamberId
501 AliMUONChamber* chamber = GetChamber(chamberId);
504 Fatal("GetEnvelopes", "Chamber %d is not defined", chamberId);
508 return chamber->GetGeometry()->GetEnvelopeStore();
511 //______________________________________________________________________________
512 AliMUONGeometryTransformStore*
513 AliMUONVGeometryBuilder::GetTransforms(Int_t chamberId) const
515 // Returns the transformation store of the chamber specified by chamberId
518 AliMUONChamber* chamber = GetChamber(chamberId);
521 Fatal("GetTransforms", "Chamber %d is not defined", chamberId);
525 return chamber->GetGeometry()->GetTransformStore();
528 //______________________________________________________________________________
529 AliMUONGeometrySVMap*
530 AliMUONVGeometryBuilder::GetSVMap(Int_t chamberId) const
532 // Returns the transformation store of the chamber specified by chamberId
535 AliMUONChamber* chamber = GetChamber(chamberId);
538 Fatal("GetSVMap", "Chamber %d is not defined", chamberId);
542 return chamber->GetGeometry()->GetSVMap();
549 //______________________________________________________________________________
550 void AliMUONVGeometryBuilder:: FillTransformations() const
552 // Fills transformations store from defined geometry.
555 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
556 AliMUONChamber* chamber
557 = (AliMUONChamber*)fChambers->At(i);
558 AliMUONChamberGeometry* chamberGeometry
559 = chamber->GetGeometry();
560 const TObjArray* envelopes
561 = chamberGeometry->GetEnvelopeStore()->GetEnvelopes();
562 AliMUONGeometryTransformStore* transforms
563 = chamberGeometry->GetTransformStore();
565 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
566 AliMUONGeometryEnvelope* envelope
567 = (AliMUONGeometryEnvelope*)envelopes->At(j);
569 // skip envelope not corresponding to detection element
570 if(envelope->GetUniqueID() == 0) continue;
573 Int_t detElemId = envelope->GetUniqueID();
574 TString path = ComposePath(envelope->GetName(),
575 envelope->GetCopyNo());
576 const TGeoCombiTrans* transform = envelope->GetTransformation();
578 // Add detection element transformation
579 transforms->Add(detElemId, path, *transform);
584 //_____ _________________________________________________________________________
585 void AliMUONVGeometryBuilder::RebuildSVMaps() const
587 // Clear the SV maps in memory and fill them from defined geometry.
590 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
591 AliMUONChamber* chamber
592 = (AliMUONChamber*)fChambers->At(i);
593 AliMUONChamberGeometry* chamberGeometry
594 = chamber->GetGeometry();
597 chamberGeometry->GetSVMap()->Clear();
599 // Fill the map from geometry
600 const TObjArray* envelopes
601 = chamberGeometry->GetEnvelopeStore()->GetEnvelopes();
603 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
604 AliMUONGeometryEnvelope* envelope
605 = (AliMUONGeometryEnvelope*)envelopes->At(j);
607 // skip envelope not corresponding to detection element
608 if(envelope->GetUniqueID() == 0) continue;
610 TString path0("/ALIC.1");
611 if (chamberGeometry->GetMotherVolume() != "ALIC") {
613 path0 += ComposePath(chamberGeometry->GetMotherVolume(), 1);
616 if (!envelope->IsVirtual()) {
617 TString path = path0;
619 path += ComposePath(envelope->GetName(), envelope->GetCopyNo());
620 MapSV(path, envelope->GetName(), envelope->GetUniqueID());
623 for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
624 AliMUONGeometryConstituent* constituent
625 = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
626 TString path = path0;
628 path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
629 MapSV(path, constituent->GetName(), envelope->GetUniqueID());
636 //______________________________________________________________________________
637 Bool_t AliMUONVGeometryBuilder::ReadTransformations() const
639 // Reads transformations from a file
640 // Returns true, if reading finished correctly.
644 TString filePath = gSystem->Getenv("ALICE_ROOT");
645 filePath += "/MUON/data/";
646 filePath += fTransformFileName;
649 ifstream in(filePath, ios::in);
651 cerr << filePath << endl;
652 Fatal("ReadTransformations", "File not found.");
658 while ( !in.eof() ) {
659 if (key == TString("CH"))
661 else if (key == TString("DE"))
664 Fatal("ReadTransformations", "%s key not recognized", key.Data());
672 //______________________________________________________________________________
673 Bool_t AliMUONVGeometryBuilder::ReadSVMap() const
675 // Reads the sensitive volume from a file
676 // Returns true, if reading finished correctly.
680 TString filePath = gSystem->Getenv("ALICE_ROOT");
681 filePath += "/MUON/data/";
682 filePath += fSVMapFileName;
685 ifstream in(filePath, ios::in);
687 cerr << filePath << endl;
688 Fatal("ReadSVMap", "File not found.");
694 while ( !in.eof() ) {
695 if (key == TString("SV"))
698 Fatal("ReadSVMap", "%s key not recognized", key.Data());
706 //______________________________________________________________________________
707 Bool_t AliMUONVGeometryBuilder::WriteTransformations() const
709 // Writes transformations into a file
710 // Returns true, if writing finished correctly.
714 TString filePath = gSystem->Getenv("ALICE_ROOT");
715 filePath += "/MUON/data/";
716 filePath += fTransformFileName;
717 filePath += fgkOutFileNameSuffix;
720 ofstream out(filePath, ios::out);
722 cerr << filePath << endl;
723 Error("WriteTransformations", "File not found.");
726 out.setf(std::ios::fixed);
734 //______________________________________________________________________________
735 Bool_t AliMUONVGeometryBuilder::WriteSVMap(Bool_t rebuild) const
737 // Writes sensitive volume map into a file
738 // Returns true, if writing finished correctly.
742 TString filePath = gSystem->Getenv("ALICE_ROOT");
743 filePath += "/MUON/data/";
744 filePath += fSVMapFileName;
745 filePath += fgkOutFileNameSuffix;
748 ofstream out(filePath, ios::out);
750 cerr << filePath << endl;
751 Error("WriteTransformations", "File not found.");
754 out.setf(std::ios::fixed);
756 if (rebuild) RebuildSVMaps();