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"
41 ClassImp(AliMUONVGeometryBuilder)
43 const TString AliMUONVGeometryBuilder::fgkTransformFileNamePrefix = "transform_";
44 const TString AliMUONVGeometryBuilder::fgkSVMapFileNamePrefix = "svmap_";
45 const TString AliMUONVGeometryBuilder::fgkOutFileNameSuffix = ".out";
47 //______________________________________________________________________________
48 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const TString& fileName,
49 AliMUONChamber* ch1, AliMUONChamber* ch2,
50 AliMUONChamber* ch3, AliMUONChamber* ch4,
51 AliMUONChamber* ch5, AliMUONChamber* ch6)
53 fTransformFileName(fgkTransformFileNamePrefix+fileName),
54 fSVMapFileName(fgkSVMapFileNamePrefix+fileName),
57 // Standard constructor
59 // Create the chambers array
60 fChambers = new TObjArray();
62 if (ch1) fChambers->Add(ch1);
63 if (ch2) fChambers->Add(ch2);
64 if (ch3) fChambers->Add(ch3);
65 if (ch4) fChambers->Add(ch4);
66 if (ch5) fChambers->Add(ch5);
67 if (ch6) fChambers->Add(ch6);
71 //______________________________________________________________________________
72 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
78 // Default constructor
82 //______________________________________________________________________________
83 AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
86 // Protected copy constructor
88 AliFatal("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;
109 AliFatal("Assignment operator is not implemented.");
118 //______________________________________________________________________________
119 TString AliMUONVGeometryBuilder::ComposePath(const TString& volName,
122 // Compose path from given volName and copyNo
125 TString path(volName);
133 //______________________________________________________________________________
134 void AliMUONVGeometryBuilder::MapSV(const TString& path0,
135 const TString& volName, Int_t detElemId) const
137 // Update the path with all daughters volumes recursively
138 // and map it to the detection element Id if it is a sensitive volume
141 Int_t nofDaughters = gMC->NofVolDaughters(volName);
142 if (nofDaughters == 0) {
144 // Get the name of the last volume in the path
145 Ssiz_t npos1 = path0.Last('/')+1;
146 Ssiz_t npos2 = path0.Last('.');
147 TString volName(path0(npos1, npos2-npos1));
149 // Check if it is sensitive volume
150 Int_t chamberId = AliMUONConstants::GetChamberId(detElemId);
151 AliMUONChamberGeometry* geometry = GetChamber(chamberId)->GetGeometry();
152 if (geometry->IsSensitiveVolume(volName)) {
153 //cout << ".. adding to the map "
154 // << path0 << " " << detElemId << endl;
155 FillData(path0, detElemId);
160 for (Int_t i=0; i<nofDaughters; i++) {
161 Int_t copyNo = gMC->VolDaughterCopyNo(volName, i);
162 TString newName = gMC->VolDaughterName(volName, i);
164 TString path = path0;
166 path += ComposePath(newName, copyNo);
168 MapSV(path, newName, detElemId);
173 //______________________________________________________________________________
174 void AliMUONVGeometryBuilder::MapSV(const TString& /*path0*/,
175 const TString& /*volName*/,
176 Int_t /*detElemId*/) const
178 // Update the path with all daughters volumes recursively
179 // and map it to the detection element Id if it is a sensitive volume
182 AliWarning("Not yet available");
185 //______________________________________________________________________________
186 void AliMUONVGeometryBuilder::FillData(Int_t chamberId,
187 Double_t x, Double_t y, Double_t z,
188 Double_t a1, Double_t a2, Double_t a3,
189 Double_t a4, Double_t a5, Double_t a6) const
191 // Fill the transformation of the chamber.
195 // Chambers numbers in the file are starting from 1
197 GetChamber(chamberId)->GetGeometry()
198 ->SetTranslation(TGeoTranslation(x, y, z));
199 GetChamber(chamberId)->GetGeometry()
200 ->SetRotation(TGeoRotation("rot", a1, a2, a3, a4, a5, a6));
203 //______________________________________________________________________________
204 void AliMUONVGeometryBuilder::FillData(
205 Int_t detElemId, const TString& volName, Int_t copyNo,
206 Double_t x, Double_t y, Double_t z,
207 Double_t a1, Double_t a2, Double_t a3,
208 Double_t a4, Double_t a5, Double_t a6) const
210 // Fill the transformation of the detection element.
214 Int_t chamberId = AliMUONConstants::GetChamberId(detElemId);
216 // Get chamber transformations
217 AliMUONGeometryTransformStore* transforms
218 = GetTransforms(chamberId);
221 TString path = ComposePath(volName, copyNo);
224 TGeoCombiTrans transform(path, x, y, z,
225 new TGeoRotation(path, a1, a2, a3, a4, a5, a6));
227 // Add detection element transformation
228 transforms->Add(detElemId, path, transform);
231 //______________________________________________________________________________
232 void AliMUONVGeometryBuilder::FillData(
233 const TString& sensVolumePath, Int_t detElemId) const
235 // Fill the mapping of the sensitive volume path to the detection element.
239 Int_t chamberId = AliMUONConstants::GetChamberId(detElemId);
241 // Get chamber transformations
242 AliMUONGeometrySVMap* svMap = GetSVMap(chamberId);
244 // Map the sensitive volume to detection element
245 svMap->Add(sensVolumePath, detElemId);
248 //______________________________________________________________________________
249 TString AliMUONVGeometryBuilder::ReadData1(ifstream& in) const
251 // Reads and fills chambers transformations from a file
252 // Returns true, if reading finished correctly.
256 while ( key == TString("CH") ) {
259 Double_t a1, a2, a3, a4, a5, a6;
275 //cout << "id=" << id << " "
276 // << "position= " << x << ", " << y << ", " << z << " "
277 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
278 // << a4 << ", " << a5 << ", " << a6
282 FillData(id, x, y, z, a1, a2, a3, a4, a5, a6);
291 //______________________________________________________________________________
292 TString AliMUONVGeometryBuilder::ReadData2(ifstream& in) const
294 // Reads detection elements transformations from a file
295 // Returns true, if reading finished correctly.
299 while ( key == TString("DE") ) {
306 Double_t a1, a2, a3, a4, a5, a6;
324 //cout << "detElemId=" << detElemId << " "
325 // << "volume=" << volumeName << " "
326 // << "copyNo=" << copyNo << " "
327 // << "position= " << x << ", " << y << ", " << z << " "
328 // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
329 // << a4 << ", " << a5 << ", " << a6
333 FillData(detElemId, volumeName, copyNo, x, y, z, a1, a2, a3, a4, a5, a6);
342 //______________________________________________________________________________
343 TString AliMUONVGeometryBuilder::ReadData3(ifstream& in) const
345 // Reads detection elements transformations from a file
346 // Returns true, if reading finished correctly.
350 while ( key == TString("SV") ) {
359 //cout << "volumePath=" << volumePath << " "
360 // << "detElemId=" << detElemId
364 FillData(volumePath, detElemId);
373 //______________________________________________________________________________
374 void AliMUONVGeometryBuilder::WriteTransform(ofstream& out,
375 const TGeoCombiTrans* transform) const
377 // Writes the transformations
381 const Double_t* xyz = transform->GetTranslation();
382 out << setw(10) << setprecision(4) << xyz[0] << " "
383 << setw(10) << setprecision(4) << xyz[1] << " "
384 << setw(10) << setprecision(4) << xyz[2];
387 Double_t a1, a2, a3, a4, a5, a6;
388 TGeoRotation* rotation = transform->GetRotation();
389 rotation->GetAngles(a1, a2, a3, a4, a5, a6);
390 out << setw(8) << setprecision(4) << a1 << " "
391 << setw(8) << setprecision(4) << a2 << " "
392 << setw(8) << setprecision(4) << a3 << " "
393 << setw(8) << setprecision(4) << a4 << " "
394 << setw(8) << setprecision(4) << a5 << " "
395 << setw(8) << setprecision(4) << a6 << " " << endl;
398 //______________________________________________________________________________
399 void AliMUONVGeometryBuilder::WriteData1(ofstream& out) const
401 // Writes chamber transformations
404 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
405 AliMUONChamber* chamber
406 = (AliMUONChamber*)fChambers->At(i);
407 AliMUONChamberGeometry* chamberGeometry
408 = chamber->GetGeometry();
409 const TGeoCombiTrans* transform
410 = chamberGeometry->GetTransformation();
413 << setw(4) << chamber->GetId() + 1 << " ";
415 WriteTransform(out, transform);
420 //______________________________________________________________________________
421 void AliMUONVGeometryBuilder::WriteData2(ofstream& out) const
423 // Writes detection elements (envelopes) transformations
427 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
428 AliMUONChamber* chamber
429 = (AliMUONChamber*)fChambers->At(i);
430 AliMUONChamberGeometry* chamberGeometry
431 = chamber->GetGeometry();
432 const TObjArray* envelopes
433 = chamberGeometry->GetEnvelopeStore()->GetEnvelopes();
435 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
436 AliMUONGeometryEnvelope* envelope
437 = (AliMUONGeometryEnvelope*)envelopes->At(j);
438 const TGeoCombiTrans* transform
439 = envelope->GetTransformation();
441 // skip envelope not corresponding to detection element
442 if(envelope->GetUniqueID() == 0) continue;
445 << setw(4) << envelope->GetUniqueID() << " "
446 << envelope->GetName() << " "
447 << setw(4)<< envelope->GetCopyNo();
449 WriteTransform(out, transform);
455 //______________________________________________________________________________
456 void AliMUONVGeometryBuilder::WriteData3(ofstream& out) const
458 // Writes association of sensitive volumes and detection elements
459 // from the sensitive volume map
462 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
463 AliMUONChamber* chamber
464 = (AliMUONChamber*)fChambers->At(i);
465 AliMUONChamberGeometry* chamberGeometry
466 = chamber->GetGeometry();
467 AliMUONGeometrySVMap* svMap
468 = chamberGeometry->GetSVMap();
470 svMap->WriteMap(out);
479 //______________________________________________________________________________
480 AliMUONChamber* AliMUONVGeometryBuilder::GetChamber(Int_t chamberId) const
482 // Returns the chamber specified by chamberId
485 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
486 AliMUONChamber* chamber = (AliMUONChamber*)fChambers->At(i);
487 if ( chamber->GetId() == chamberId) return chamber;
493 //______________________________________________________________________________
494 AliMUONGeometryEnvelopeStore*
495 AliMUONVGeometryBuilder::GetEnvelopes(Int_t chamberId) const
497 // Returns the envelope store of the chamber specified by chamberId
500 AliMUONChamber* chamber = GetChamber(chamberId);
503 AliFatal(Form("Chamber %d is not defined", chamberId));
507 return chamber->GetGeometry()->GetEnvelopeStore();
510 //______________________________________________________________________________
511 AliMUONGeometryTransformStore*
512 AliMUONVGeometryBuilder::GetTransforms(Int_t chamberId) const
514 // Returns the transformation store of the chamber specified by chamberId
517 AliMUONChamber* chamber = GetChamber(chamberId);
520 AliFatal(Form("Chamber %d is not defined", chamberId));
524 return chamber->GetGeometry()->GetTransformStore();
527 //______________________________________________________________________________
528 AliMUONGeometrySVMap*
529 AliMUONVGeometryBuilder::GetSVMap(Int_t chamberId) const
531 // Returns the transformation store of the chamber specified by chamberId
534 AliMUONChamber* chamber = GetChamber(chamberId);
537 AliFatal(Form("Chamber %d is not defined", chamberId));
541 return chamber->GetGeometry()->GetSVMap();
548 //______________________________________________________________________________
549 void AliMUONVGeometryBuilder:: FillTransformations() const
551 // Fills transformations store from defined geometry.
554 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
555 AliMUONChamber* chamber
556 = (AliMUONChamber*)fChambers->At(i);
557 AliMUONChamberGeometry* chamberGeometry
558 = chamber->GetGeometry();
559 const TObjArray* envelopes
560 = chamberGeometry->GetEnvelopeStore()->GetEnvelopes();
561 AliMUONGeometryTransformStore* transforms
562 = chamberGeometry->GetTransformStore();
564 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
565 AliMUONGeometryEnvelope* envelope
566 = (AliMUONGeometryEnvelope*)envelopes->At(j);
568 // skip envelope not corresponding to detection element
569 if(envelope->GetUniqueID() == 0) continue;
572 Int_t detElemId = envelope->GetUniqueID();
573 TString path = ComposePath(envelope->GetName(),
574 envelope->GetCopyNo());
575 const TGeoCombiTrans* transform = envelope->GetTransformation();
577 // Add detection element transformation
578 transforms->Add(detElemId, path, *transform);
583 //_____ _________________________________________________________________________
584 void AliMUONVGeometryBuilder::RebuildSVMaps() const
586 // Clear the SV maps in memory and fill them from defined geometry.
589 for (Int_t i=0; i<fChambers->GetEntriesFast(); i++) {
590 AliMUONChamber* chamber
591 = (AliMUONChamber*)fChambers->At(i);
592 AliMUONChamberGeometry* chamberGeometry
593 = chamber->GetGeometry();
596 chamberGeometry->GetSVMap()->Clear();
598 // Fill the map from geometry
599 const TObjArray* envelopes
600 = chamberGeometry->GetEnvelopeStore()->GetEnvelopes();
602 for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
603 AliMUONGeometryEnvelope* envelope
604 = (AliMUONGeometryEnvelope*)envelopes->At(j);
606 // skip envelope not corresponding to detection element
607 if(envelope->GetUniqueID() == 0) continue;
609 TString path0("/ALIC.1");
610 if (chamberGeometry->GetMotherVolume() != "ALIC") {
612 path0 += ComposePath(chamberGeometry->GetMotherVolume(), 1);
615 if (!envelope->IsVirtual()) {
616 TString path = path0;
618 path += ComposePath(envelope->GetName(), envelope->GetCopyNo());
619 MapSV(path, envelope->GetName(), envelope->GetUniqueID());
622 for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
623 AliMUONGeometryConstituent* constituent
624 = (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
625 TString path = path0;
627 path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
628 MapSV(path, constituent->GetName(), envelope->GetUniqueID());
635 //______________________________________________________________________________
636 Bool_t AliMUONVGeometryBuilder::ReadTransformations() const
638 // Reads transformations from a file
639 // Returns true, if reading finished correctly.
643 TString filePath = gSystem->Getenv("ALICE_ROOT");
644 filePath += "/MUON/data/";
645 filePath += fTransformFileName;
648 ifstream in(filePath, ios::in);
650 cerr << filePath << endl;
651 AliFatal("File not found.");
657 while ( !in.eof() ) {
658 if (key == TString("CH"))
660 else if (key == TString("DE"))
663 AliFatal(Form("%s key not recognized", key.Data()));
671 //______________________________________________________________________________
672 Bool_t AliMUONVGeometryBuilder::ReadSVMap() const
674 // Reads the sensitive volume from a file
675 // Returns true, if reading finished correctly.
679 TString filePath = gSystem->Getenv("ALICE_ROOT");
680 filePath += "/MUON/data/";
681 filePath += fSVMapFileName;
684 ifstream in(filePath, ios::in);
686 cerr << filePath << endl;
687 AliFatal("File not found.");
693 while ( !in.eof() ) {
694 if (key == TString("SV"))
697 AliFatal(Form("%s key not recognized", key.Data()));
705 //______________________________________________________________________________
706 Bool_t AliMUONVGeometryBuilder::WriteTransformations() const
708 // Writes transformations into a file
709 // Returns true, if writing finished correctly.
713 TString filePath = gSystem->Getenv("ALICE_ROOT");
714 filePath += "/MUON/data/";
715 filePath += fTransformFileName;
716 filePath += fgkOutFileNameSuffix;
719 ofstream out(filePath, ios::out);
721 cerr << filePath << endl;
722 AliError("File not found.");
725 #if !defined (__DECCXX)
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 AliError("File not found.");
754 #if !defined (__DECCXX)
755 out.setf(std::ios::fixed);
757 if (rebuild) RebuildSVMaps();