**************************************************************************/
// $Id$
-//
+
+//-----------------------------------------------------------------------------
// Class AliMUONVGeometryBuilder
// -----------------------------
// Abstract base class for geometry construction per geometry module(s).
// Author: Ivana Hrivnacova, IPN Orsay
// 23/01/2004
-
-#include <Riostream.h>
-#include <TObjArray.h>
-#include <TSystem.h>
-#include <TGeoMatrix.h>
-#include <TVirtualMC.h>
+//-----------------------------------------------------------------------------
#include "AliMUONVGeometryBuilder.h"
#include "AliMUONGeometryModule.h"
#include "AliMUONGeometryDetElement.h"
-#include "AliMUONGeometryStore.h"
-#include "AliMUONGeometrySVMap.h"
#include "AliMUONGeometryEnvelopeStore.h"
#include "AliMUONGeometryEnvelope.h"
#include "AliMUONGeometryConstituent.h"
-#include "AliMUONVGeometryDEIndexing.h"
#include "AliMUONGeometryBuilder.h"
+#include "AliMUONStringIntMap.h"
+
+#include "AliMpDEManager.h"
+#include "AliMpExMap.h"
+
#include "AliLog.h"
-ClassImp(AliMUONVGeometryBuilder)
+#include <Riostream.h>
+#include <TObjArray.h>
+#include <TSystem.h>
+#include <TGeoMatrix.h>
+#include <TVirtualMC.h>
-const TString AliMUONVGeometryBuilder::fgkTransformFileNamePrefix = "transform_";
-const TString AliMUONVGeometryBuilder::fgkSVMapFileNamePrefix = "svmap_";
-const TString AliMUONVGeometryBuilder::fgkOutFileNameSuffix = ".out";
+/// \cond CLASSIMP
+ClassImp(AliMUONVGeometryBuilder)
+/// \endcond
//______________________________________________________________________________
-AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const TString& fileName,
- AliMUONGeometryModule* mg1, AliMUONGeometryModule* mg2,
- AliMUONGeometryModule* mg3, AliMUONGeometryModule* mg4,
- AliMUONGeometryModule* mg5, AliMUONGeometryModule* mg6)
+AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(
+ Int_t firstModuleId,
+ Int_t nofModules)
: TObject(),
- fTransformFileName(fgkTransformFileNamePrefix+fileName),
- fSVMapFileName(fgkSVMapFileNamePrefix+fileName),
- fModuleGeometries(0),
+ fGeometryModules(0),
fReferenceFrame()
{
-// Standard constructor
+/// Standard constructor
// Create the module geometries array
- fModuleGeometries = new TObjArray();
-
- if (mg1) fModuleGeometries->Add(mg1);
- if (mg2) fModuleGeometries->Add(mg2);
- if (mg3) fModuleGeometries->Add(mg3);
- if (mg4) fModuleGeometries->Add(mg4);
- if (mg5) fModuleGeometries->Add(mg5);
- if (mg6) fModuleGeometries->Add(mg6);
+ fGeometryModules = new TObjArray();
+ fGeometryModules->SetOwner(kFALSE);
+
+ for (Int_t i=0; i<nofModules; i++ )
+ fGeometryModules->Add(new AliMUONGeometryModule(firstModuleId++));
}
-
//______________________________________________________________________________
AliMUONVGeometryBuilder::AliMUONVGeometryBuilder()
: TObject(),
- fTransformFileName(),
- fSVMapFileName(),
- fModuleGeometries(0),
+ fGeometryModules(0),
fReferenceFrame()
{
-// Default constructor
+/// Default constructor
}
-
//______________________________________________________________________________
-AliMUONVGeometryBuilder::AliMUONVGeometryBuilder(const AliMUONVGeometryBuilder& rhs)
- : TObject(rhs)
+AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder()
{
-// Protected copy constructor
+/// Destructor
- AliFatal("Copy constructor is not implemented.");
+ if (fGeometryModules) {
+ fGeometryModules->Clear(); // Sets pointers to 0 since it is not the owner
+ delete fGeometryModules;
+ }
}
-//______________________________________________________________________________
-AliMUONVGeometryBuilder::~AliMUONVGeometryBuilder() {
//
- if (fModuleGeometries) {
- fModuleGeometries->Clear(); // Sets pointers to 0 since it is not the owner
- delete fModuleGeometries;
- }
-}
+// private methods
+//
//______________________________________________________________________________
-AliMUONVGeometryBuilder&
-AliMUONVGeometryBuilder::operator = (const AliMUONVGeometryBuilder& rhs)
+TGeoHMatrix
+AliMUONVGeometryBuilder::ConvertTransform(const TGeoHMatrix& transform) const
{
-// Protected assignement operator
-
- // check assignement to self
- if (this == &rhs) return *this;
+/// Convert transformation into the reference frame
- AliFatal("Assignment operator is not implemented.");
-
- return *this;
+ if ( fReferenceFrame.IsIdentity() )
+ return transform;
+ else {
+ return AliMUONGeometryBuilder::Multiply( fReferenceFrame,
+ transform,
+ fReferenceFrame.Inverse() );
+ }
}
-//
-// private methods
-//
+//______________________________________________________________________________
+TGeoHMatrix
+AliMUONVGeometryBuilder::ConvertDETransform(const TGeoHMatrix& transform) const
+{
+/// Convert DE transformation into the reference frame
+
+ if ( fReferenceFrame.IsIdentity() )
+ return transform;
+ else {
+ return AliMUONGeometryBuilder::Multiply( fReferenceFrame,
+ transform );
+ }
+}
//______________________________________________________________________________
- TString AliMUONVGeometryBuilder::ComposePath(const TString& volName,
- Int_t copyNo) const
+TString AliMUONVGeometryBuilder::ComposePath(const TString& volName,
+ Int_t copyNo) const
{
-// Compose path from given volName and copyNo
-// ---
+/// Compose path from given volName and copyNo
- TString path(volName);
- path += ".";
+ TString path = "/";
+ path += volName;
+ path += '_';
path += copyNo;
return path;
void AliMUONVGeometryBuilder::MapSV(const TString& path0,
const TString& volName, Int_t detElemId) const
{
-// Update the path with all daughters volumes recursively
-// and map it to the detection element Id if it is a sensitive volume
-// ---
+/// Update the path with all daughters volumes recursively
+/// and map it to the detection element Id if it is a sensitive volume
+
+ // Get module sensitive volumes map
+ Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
+ AliMUONStringIntMap* svMap = GetSVMap(moduleId);
Int_t nofDaughters = gMC->NofVolDaughters(volName);
if (nofDaughters == 0) {
// Get the name of the last volume in the path
Ssiz_t npos1 = path0.Last('/')+1;
- Ssiz_t npos2 = path0.Last('.');
- TString volName(path0(npos1, npos2-npos1));
+ Ssiz_t npos2 = path0.Last('_');
+ TString volName0(path0(npos1, npos2-npos1));
// Check if it is sensitive volume
- Int_t moduleId = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
AliMUONGeometryModule* geometry = GetGeometry(moduleId);
- if (geometry->IsSensitiveVolume(volName)) {
+ if ( geometry->IsSensitiveVolume(volName0) &&
+ ! svMap->Get(path0) ) {
//cout << ".. adding to the map "
// << path0 << " " << detElemId << endl;
- FillData(path0, detElemId);
+
+ // Map the sensitive volume to detection element
+ svMap->Add(path0, detElemId);
}
return;
}
TString newName = gMC->VolDaughterName(volName, i);
TString path = path0;
- path += "/";
path += ComposePath(newName, copyNo);
MapSV(path, newName, detElemId);
}
}
-//______________________________________________________________________________
-TGeoHMatrix AliMUONVGeometryBuilder::GetTransform(
- Double_t x, Double_t y, Double_t z,
- Double_t a1, Double_t a2, Double_t a3,
- Double_t a4, Double_t a5, Double_t a6) const
-{
-// Builds the transformation from the given parameters
-// ---
-
- // Compose transform
- TGeoCombiTrans transform(TGeoTranslation(x, y, z),
- TGeoRotation("rot", a1, a2, a3, a4, a5, a6));
-
- // Convert transform to the given reference frame
- TGeoHMatrix newTransform;
- if ( fReferenceFrame.IsIdentity() )
- newTransform = transform;
- else {
- newTransform
- = AliMUONGeometryBuilder::Multiply( fReferenceFrame.Inverse(),
- transform,
- fReferenceFrame );
- }
-
- return newTransform;
-}
-
+//
+// protected methods
+//
//______________________________________________________________________________
-void AliMUONVGeometryBuilder::FillData(Int_t moduleId, Int_t nofDetElements,
- Double_t x, Double_t y, Double_t z,
- Double_t a1, Double_t a2, Double_t a3,
- Double_t a4, Double_t a5, Double_t a6) const
+AliMUONGeometryModule*
+AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
{
-// Fill the transformation of the module.
-// ---
+/// Return the module geometry specified by moduleId
- moduleId--;
- // Modules numbers in the file are starting from 1
-
- // Build the transformation from the parameters
- TGeoHMatrix newTransform
- = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
-
- const Double_t* xyz = newTransform.GetTranslation();
- const Double_t* rm = newTransform.GetRotationMatrix();
- TGeoRotation rotation2;
- rotation2.SetMatrix(const_cast<Double_t*>(rm));
-
- GetGeometry(moduleId)
- ->GetDEIndexing()->SetNofDetElements(nofDetElements);
- GetGeometry(moduleId)
- ->SetTranslation(TGeoTranslation(xyz[0], xyz[1], xyz[2]));
- GetGeometry(moduleId)
- ->SetRotation(rotation2);
-}
-
-//______________________________________________________________________________
-void AliMUONVGeometryBuilder::FillData(
- Int_t detElemId, const TString& volName, Int_t copyNo,
- Double_t x, Double_t y, Double_t z,
- Double_t a1, Double_t a2, Double_t a3,
- Double_t a4, Double_t a5, Double_t a6) const
-{
-// Fill the transformation of the detection element.
-// ---
+ for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
- // Module Id
- Int_t moduleId
- = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
+ AliMUONGeometryModule* geometry
+ = (AliMUONGeometryModule*)fGeometryModules->At(i);
- // Compose path
- TString path = ComposePath(volName, copyNo);
+ if ( geometry->GetModuleId() == moduleId) return geometry;
+ }
- // Build the transformation from the parameters
- TGeoHMatrix newTransform
- = GetTransform(x, y, z, a1, a2, a3, a4, a5, a6);
-
- // Compose TGeoCombiTrans
- TGeoCombiTrans newCombiTransform(newTransform);
-
- // Get detection element store
- AliMUONGeometryStore* detElements = GetDetElements(moduleId);
+ return 0;
+}
- // Add detection element
- detElements->Add(detElemId,
- new AliMUONGeometryDetElement(detElemId, path, newCombiTransform));
-}
-
//______________________________________________________________________________
-void AliMUONVGeometryBuilder::FillData(
- const TString& sensVolumePath, Int_t detElemId) const
+AliMUONGeometryEnvelopeStore*
+AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
{
-// Fill the mapping of the sensitive volume path to the detection element.
-// ---
-
- // Module Id
- Int_t moduleId
- = AliMUONVGeometryDEIndexing::GetModuleId(detElemId);
-
- // Get module sensitive volumes map
- AliMUONGeometrySVMap* svMap = GetSVMap(moduleId);
+/// Return the envelope store of the module geometry specified by moduleId
- // Map the sensitive volume to detection element
- svMap->Add(sensVolumePath, detElemId);
-}
-
-//______________________________________________________________________________
-TString AliMUONVGeometryBuilder::ReadData1(ifstream& in) const
-{
-// Reads and fills modules transformations from a file
-// Returns true, if reading finished correctly.
-// ---
-
- TString key("CH");
- while ( key == TString("CH") ) {
- Int_t id, n;
- Double_t x, y, z;
- Double_t a1, a2, a3, a4, a5, a6;
- TString dummy;
+ AliMUONGeometryModule* geometry = GetGeometry(moduleId);
- in >> id;
- in >> n;
- in >> dummy;
- in >> x;
- in >> y;
- in >> z;
- in >> dummy;
- in >> a1;
- in >> a2;
- in >> a3;
- in >> a4;
- in >> a5;
- in >> a6;
-
- //cout << "id=" << id << " "
- // << "position= " << x << ", " << y << ", " << z << " "
- // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
- // << a4 << ", " << a5 << ", " << a6
- // << endl;
-
- // Fill data
- FillData(id, n, x, y, z, a1, a2, a3, a4, a5, a6);
-
- // Go to next line
- in >> key;
+ if (!geometry) {
+ AliFatal(Form("Module geometry %d is not defined", moduleId));
+ return 0;
}
- return key;
-}
-
-//______________________________________________________________________________
-TString AliMUONVGeometryBuilder::ReadData2(ifstream& in) const
-{
-// Reads detection elements transformations from a file
-// Returns true, if reading finished correctly.
-// ---
-
- TString key("DE");
- while ( key == TString("DE") ) {
-
- // Input data
- Int_t detElemId;
- TString volumeName;
- Int_t copyNo;
- Double_t x, y, z;
- Double_t a1, a2, a3, a4, a5, a6;
- TString dummy;
-
- in >> detElemId;
- in >> volumeName;
- in >> copyNo;
- in >> dummy;
- in >> x;
- in >> y;
- in >> z;
- in >> dummy;
- in >> a1;
- in >> a2;
- in >> a3;
- in >> a4;
- in >> a5;
- in >> a6;
-
- //cout << "detElemId=" << detElemId << " "
- // << "volume=" << volumeName << " "
- // << "copyNo=" << copyNo << " "
- // << "position= " << x << ", " << y << ", " << z << " "
- // << "rotation= " << a1 << ", " << a2 << ", " << a3 << ", "
- // << a4 << ", " << a5 << ", " << a6
- // << endl;
-
- // Fill data
- FillData(detElemId, volumeName, copyNo, x, y, z, a1, a2, a3, a4, a5, a6);
-
- // Go to next line
- in >> key;
- }
-
- return key;
-}
+ return geometry->GetEnvelopeStore();
+}
//______________________________________________________________________________
-TString AliMUONVGeometryBuilder::ReadData3(ifstream& in) const
+AliMUONStringIntMap*
+AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
{
-// Reads detection elements transformations from a file
-// Returns true, if reading finished correctly.
-// ---
-
- TString key("SV");
- while ( key == TString("SV") ) {
+/// Return the transformation store of the module geometry specified by moduleId
- // Input data
- TString volumePath;
- Int_t detElemId;
-
- in >> volumePath;
- in >> detElemId;
-
- //cout << "volumePath=" << volumePath << " "
- // << "detElemId=" << detElemId
- // << endl;
-
- // Fill data
- FillData(volumePath, detElemId);
-
- // Go to next line
- in >> key;
- }
+ AliMUONGeometryModule* geometry = GetGeometry(moduleId);
- return key;
-}
-
-//______________________________________________________________________________
-void AliMUONVGeometryBuilder::WriteTransform(ofstream& out,
- const TGeoCombiTrans* transform) const
-{
-// Writes the transformations
-// after converting them into the specified reference frame
-// ---
-
- // Convert transform to the given reference frame
- TGeoHMatrix newTransform;
- if ( fReferenceFrame.IsIdentity() )
- newTransform = *transform;
- else {
- newTransform = AliMUONGeometryBuilder::Multiply( fReferenceFrame,
- *transform,
- fReferenceFrame.Inverse() );
- }
-
- out << " pos: ";
- const Double_t* xyz = newTransform.GetTranslation();
- out << setw(10) << setprecision(4) << xyz[0] << " "
- << setw(10) << setprecision(4) << xyz[1] << " "
- << setw(10) << setprecision(4) << xyz[2];
-
- out << " rot: ";
- const Double_t* rm = newTransform.GetRotationMatrix();
- TGeoRotation rotation;
- rotation.SetMatrix(const_cast<Double_t*>(rm));
- Double_t a1, a2, a3, a4, a5, a6;
- rotation.GetAngles(a1, a2, a3, a4, a5, a6);
-
- out << setw(8) << setprecision(4) << a1 << " "
- << setw(8) << setprecision(4) << a2 << " "
- << setw(8) << setprecision(4) << a3 << " "
- << setw(8) << setprecision(4) << a4 << " "
- << setw(8) << setprecision(4) << a5 << " "
- << setw(8) << setprecision(4) << a6 << " " << endl;
-}
-
-//______________________________________________________________________________
-void AliMUONVGeometryBuilder::WriteData1(ofstream& out) const
-{
-// Writes modules transformations
-// ---
-
- for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
- AliMUONGeometryModule* geometry
- = (AliMUONGeometryModule*)fModuleGeometries->At(i);
- const TGeoCombiTrans* transform
- = geometry->GetTransformation();
-
- out << "CH "
- << setw(4) << geometry->GetModuleId() + 1 << " "
- << setw(4) << geometry->GetDetElementStore()->GetNofEntries() << " ";
-
- WriteTransform(out, transform);
+ if (!geometry) {
+ AliFatal(Form("Geometry %d is not defined", moduleId));
+ return 0;
}
- out << endl;
-}
+
+ return geometry->GetSVMap();
+}
//______________________________________________________________________________
-void AliMUONVGeometryBuilder::WriteData2(ofstream& out) const
+Int_t
+AliMUONVGeometryBuilder::GetModuleId(const TString& envName) const
{
-// Writes detection elements (envelopes) transformations
-// ---
+/// Return module Id which has the envelope with given name
+ for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
- for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
AliMUONGeometryModule* geometry
- = (AliMUONGeometryModule*)fModuleGeometries->At(i);
- const TObjArray* envelopes
- = geometry->GetEnvelopeStore()->GetEnvelopes();
-
- for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
- AliMUONGeometryEnvelope* envelope
- = (AliMUONGeometryEnvelope*)envelopes->At(j);
- const TGeoCombiTrans* transform
- = envelope->GetTransformation();
+ = (AliMUONGeometryModule*)fGeometryModules->At(i);
- // skip envelope not corresponding to detection element
- if(envelope->GetUniqueID() == 0) continue;
-
- out << "DE "
- << setw(4) << envelope->GetUniqueID() << " "
- << envelope->GetName() << " "
- << setw(4)<< envelope->GetCopyNo();
-
- WriteTransform(out, transform);
- }
- out << endl;
- }
-}
-
-//______________________________________________________________________________
-void AliMUONVGeometryBuilder::WriteData3(ofstream& out) const
-{
-// Writes association of sensitive volumes and detection elements
-// from the sensitive volume map
-// ---
-
- for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
- AliMUONGeometryModule* geometry
- = (AliMUONGeometryModule*)fModuleGeometries->At(i);
- AliMUONGeometrySVMap* svMap
- = geometry->GetSVMap();
-
- svMap->WriteMap(out);
- out << endl;
- }
-}
-
-//
-// protected methods
-//
-
-//______________________________________________________________________________
-AliMUONGeometryModule*
-AliMUONVGeometryBuilder::GetGeometry(Int_t moduleId) const
-{
-// Returns the module geometry specified by moduleId
-// ---
-
- for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
-
- AliMUONGeometryModule* geometry
- = (AliMUONGeometryModule*)fModuleGeometries->At(i);
-
- if ( geometry->GetModuleId() == moduleId) return geometry;
+ if ( geometry->GetEnvelopeStore()->FindEnvelope(envName) )
+ return geometry->GetModuleId();
}
- return 0;
+ return -1;
}
+
//______________________________________________________________________________
-AliMUONGeometryEnvelopeStore*
-AliMUONVGeometryBuilder::GetEnvelopes(Int_t moduleId) const
+void AliMUONVGeometryBuilder::SetTranslation(Int_t moduleId,
+ const TGeoTranslation& translation)
{
-// Returns the envelope store of the module geometry specified by moduleId
-// ---
+/// Set the translation to the geometry module given by moduleId,
+/// apply reference frame transformation
AliMUONGeometryModule* geometry = GetGeometry(moduleId);
if (!geometry) {
- AliFatal(Form("Module geometry %d is not defined", moduleId));
- return 0;
+ AliFatal(Form("Geometry %d is not defined", moduleId));
+ return;
}
- return geometry->GetEnvelopeStore();
+ // Apply frame transform
+ TGeoHMatrix newTransform = ConvertTransform(translation);
+
+ // Set new transformation
+ geometry->SetTransformation(newTransform);
}
+
//______________________________________________________________________________
-AliMUONGeometryStore*
-AliMUONVGeometryBuilder::GetDetElements(Int_t moduleId) const
+void AliMUONVGeometryBuilder::SetTransformation(Int_t moduleId,
+ const TGeoTranslation& translation,
+ const TGeoRotation& rotation)
{
-// Returns the detection elemnts store of the module geometry specified
-// by moduleId
-// ---
+/// Set the transformation to the geometry module given by moduleId,
+/// apply reference frame transformation
AliMUONGeometryModule* geometry = GetGeometry(moduleId);
if (!geometry) {
- AliFatal(Form("Module geometry %d is not defined", moduleId));
- return 0;
+ AliFatal(Form("Geometry %d is not defined", moduleId));
+ return;
}
- return geometry->GetDetElementStore();
+ TGeoCombiTrans transformation
+ = TGeoCombiTrans(translation, rotation);
+
+ // Apply frame transform
+ TGeoHMatrix newTransform = ConvertTransform(transformation);
+
+ // Set new transformation
+ geometry->SetTransformation(newTransform);
}
//______________________________________________________________________________
-AliMUONGeometrySVMap*
-AliMUONVGeometryBuilder::GetSVMap(Int_t moduleId) const
+void AliMUONVGeometryBuilder::SetVolume(Int_t moduleId,
+ const TString& volumeName,
+ Bool_t isVirtual)
{
-// Returns the transformation store of the module geometry specified by moduleId
-// ---
+/// Set volume name, virtuality
- AliMUONGeometryModule* geometry = GetGeometry(moduleId);
+ TString path = GetGeometry(moduleId)->GetVolumePath();
+ // cout << "in AliMUONVGeometryBuilder::SetVolume " << path.Data() << endl;
- if (!geometry) {
- AliFatal(Form("Geometry %d is not defined", moduleId));
- return 0;
- }
+ if ( path == "" ) path = "/ALIC_1";
+ path += ComposePath(volumeName, 1);
+
+ GetGeometry(moduleId)->SetVolumePath(path);
+ GetGeometry(moduleId)->SetIsVirtual(isVirtual);
+ // cout << "... set " << path.Data() << endl;
+}
+
+//______________________________________________________________________________
+void AliMUONVGeometryBuilder::SetMotherVolume(Int_t moduleId,
+ const TString& volumeName)
+{
+/// Set mother volume name
+
+ TString motherVolumeName = ComposePath(volumeName, 1);
+
+ TString path = GetGeometry(moduleId)->GetVolumePath();
+ if ( path == "" ) path = "/ALIC_1";
+ path.Insert(7, motherVolumeName);
- return geometry->GetSVMap();
-}
+ GetGeometry(moduleId)->SetVolumePath(path);
+}
//
// public functions
//
//______________________________________________________________________________
-void AliMUONVGeometryBuilder::FillTransformations() const
+void AliMUONVGeometryBuilder::SetReferenceFrame(
+ const TGeoCombiTrans& referenceFrame)
+{
+/// Set reference frame to builder and to all associated geometry
+/// modules
+
+ fReferenceFrame = referenceFrame;
+
+ for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
+ AliMUONGeometryModule* geometry
+ = (AliMUONGeometryModule*)fGeometryModules->At(i);
+ AliMUONGeometryEnvelopeStore* envelopeStore
+ = geometry->GetEnvelopeStore();
+
+ envelopeStore->SetReferenceFrame(referenceFrame);
+ }
+}
+
+//______________________________________________________________________________
+void AliMUONVGeometryBuilder::UpdateDetElements(Bool_t create) const
{
-// Fills transformations store from defined geometry.
-// ---
+/// Create or update detection elements:
+/// - if parameter create is true: detection elements are
+/// created and their global and local transformations are filled from geometry.
+/// - otherwise: only the volume path is passed from geometry
+/// to detection elements
- for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
+ for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
AliMUONGeometryModule* geometry
- = (AliMUONGeometryModule*)fModuleGeometries->At(i);
+ = (AliMUONGeometryModule*)fGeometryModules->At(i);
+
const TObjArray* envelopes
= geometry->GetEnvelopeStore()->GetEnvelopes();
- AliMUONGeometryStore* detElements = geometry->GetDetElementStore();
+ AliMpExMap* detElements
+ = geometry->GetTransformer()->GetDetElementStore();
- // Set nof detection elements to the indexing
- geometry->GetDEIndexing()
- ->SetNofDetElements(geometry->GetEnvelopeStore()->GetNofDetElements());
-
for (Int_t j=0; j<envelopes->GetEntriesFast(); j++) {
AliMUONGeometryEnvelope* envelope
= (AliMUONGeometryEnvelope*)envelopes->At(j);
// skip envelope not corresponding to detection element
- if(envelope->GetUniqueID() == 0) continue;
+ if ( envelope->GetUniqueID() == 0) continue;
// Get envelope data
Int_t detElemId = envelope->GetUniqueID();
- TString path = ComposePath(envelope->GetName(),
- envelope->GetCopyNo());
- const TGeoCombiTrans* transform = envelope->GetTransformation();
- // Add detection element transformation
- detElements->Add(detElemId,
- new AliMUONGeometryDetElement(detElemId, path, *transform));
- }
+ // Compose full volume path
+ TString volPath = geometry->GetVolumePath();
+ volPath += ComposePath(envelope->GetName(), envelope->GetCopyNo());
+
+ if ( create ) {
+ // Create detection element
+ AliMUONGeometryDetElement* detElement
+ = new AliMUONGeometryDetElement(detElemId, volPath);
+ detElements->Add(detElemId, detElement);
+
+ // Compose local transformation
+ const TGeoCombiTrans* transform = envelope->GetTransformation();
+ // Apply frame transform
+ TGeoHMatrix localTransform = ConvertDETransform(*transform);
+ detElement->SetLocalTransformation(localTransform);
+
+ // Compose global transformation
+ TGeoHMatrix globalTransform
+ = AliMUONGeometryBuilder::Multiply(
+ (*geometry->GetTransformer()->GetTransformation()),
+ localTransform );
+ ;
+ // Set the global transformation to detection element
+ detElement->SetGlobalTransformation(globalTransform);
+ }
+ else {
+ // Get existing det elements
+ AliMUONGeometryDetElement* detElement
+ = (AliMUONGeometryDetElement*)detElements->GetValue(detElemId);
+
+ // Set volume path
+ detElement->SetVolumePath(volPath);
+ }
+ }
}
}
//_____ _________________________________________________________________________
-void AliMUONVGeometryBuilder::RebuildSVMaps() const
+void AliMUONVGeometryBuilder::RebuildSVMaps(Bool_t withEnvelopes) const
{
-// Clear the SV maps in memory and fill them from defined geometry.
-// ---
+/// Clear the SV maps in memory and fill them from defined geometry.
- for (Int_t i=0; i<fModuleGeometries->GetEntriesFast(); i++) {
+ for (Int_t i=0; i<fGeometryModules->GetEntriesFast(); i++) {
AliMUONGeometryModule* geometry
- = (AliMUONGeometryModule*)fModuleGeometries->At(i);
+ = (AliMUONGeometryModule*)fGeometryModules->At(i);
// Clear the map
geometry->GetSVMap()->Clear();
= (AliMUONGeometryEnvelope*)envelopes->At(j);
// skip envelope not corresponding to detection element
- if(envelope->GetUniqueID() == 0) continue;
-
- TString path0("/ALIC.1");
- if (geometry->GetMotherVolume() != "ALIC") {
- path0 += "/";
- path0 += ComposePath(geometry->GetMotherVolume(), 1);
- }
- if (! geometry->IsVirtual() ) {
- path0 += "/";
- path0 += ComposePath(geometry->GetVolume(), 1);
+ if ( envelope->GetUniqueID() == 0 ) continue;
+
+ // Get volume path of detection element
+ AliMUONGeometryDetElement* detElement
+ = geometry->GetTransformer()->GetDetElement(envelope->GetUniqueID());
+ std::string path0 = detElement->GetVolumePath().Data();
+
+ if ( ! withEnvelopes && geometry->IsVirtual() ) {
+ std::string vName = geometry->GetTransformer()->GetVolumeName().Data();
+ std::string vPath = ComposePath(vName, 1).Data();
+ std::string::size_type vPathPos = path0.find(vPath);
+ if ( vPathPos != std::string::npos )
+ path0.erase(vPathPos, vPath.size());
}
- if (!envelope->IsVirtual()) {
- TString path = path0;
- path += "/";
- path += ComposePath(envelope->GetName(), envelope->GetCopyNo());
- MapSV(path, envelope->GetName(), envelope->GetUniqueID());
+ if ( ! withEnvelopes && envelope->IsVirtual()) {
+ std::string eName = envelope->GetName();
+ std::string ePath = ComposePath(eName, envelope->GetCopyNo()).Data();
+ std::string::size_type ePathPos = path0.find(ePath);
+ if ( ePathPos != std::string::npos )
+ path0.erase(ePathPos, ePath.size());
}
- else {
+
+ if ( ! envelope->IsVirtual() )
+ MapSV(path0, envelope->GetName(), envelope->GetUniqueID());
+ else {
for (Int_t k=0; k<envelope->GetConstituents()->GetEntriesFast(); k++) {
AliMUONGeometryConstituent* constituent
= (AliMUONGeometryConstituent*)envelope->GetConstituents()->At(k);
TString path = path0;
- path += "/";
path += ComposePath(constituent->GetName(), constituent->GetCopyNo());
MapSV(path, constituent->GetName(), envelope->GetUniqueID());
}
}
}
-//______________________________________________________________________________
-Bool_t
-AliMUONVGeometryBuilder::ReadTransformations() const
-{
-// Reads transformations from a file
-// Returns true, if reading finished correctly.
-// ---
-
- // No reading
- // if builder is not associated with any geometry module
- if (fModuleGeometries->GetEntriesFast() == 0) return false;
-
- // File path
- TString filePath = gSystem->Getenv("ALICE_ROOT");
- filePath += "/MUON/data/";
- filePath += fTransformFileName;
-
- // Open input file
- ifstream in(filePath, ios::in);
- if (!in) {
- cerr << filePath << endl;
- AliFatal("File not found.");
- return false;
- }
-
- TString key;
- in >> key;
- while ( !in.eof() ) {
- if (key == TString("CH"))
- key = ReadData1(in);
- else if (key == TString("DE"))
- key = ReadData2(in);
- else {
- AliFatal(Form("%s key not recognized", key.Data()));
- return false;
- }
- }
-
- return true;
-}
-
-//______________________________________________________________________________
-Bool_t AliMUONVGeometryBuilder::ReadSVMap() const
-{
-// Reads the sensitive volume from a file
-// Returns true, if reading finished correctly.
-// ---
-
- // No reading
- // if builder is not associated with any geometry module
- if (fModuleGeometries->GetEntriesFast() == 0) return false;
-
- // File path
- TString filePath = gSystem->Getenv("ALICE_ROOT");
- filePath += "/MUON/data/";
- filePath += fSVMapFileName;
-
- // Open input file
- ifstream in(filePath, ios::in);
- if (!in) {
- cerr << filePath << endl;
- AliFatal("File not found.");
- return false;
- }
-
- TString key;
- in >> key;
- while ( !in.eof() ) {
- if (key == TString("SV"))
- key = ReadData3(in);
- else {
- AliFatal(Form("%s key not recognized", key.Data()));
- return false;
- }
- }
-
- return true;
-}
-
-//______________________________________________________________________________
-Bool_t
-AliMUONVGeometryBuilder::WriteTransformations() const
-{
-// Writes transformations into a file
-// Returns true, if writing finished correctly.
-// ---
-
- // No writing
- // if builder is not associated with any geometry module
- if (fModuleGeometries->GetEntriesFast() == 0) return false;
-
- // File path
- TString filePath = gSystem->Getenv("ALICE_ROOT");
- filePath += "/MUON/data/";
- filePath += fTransformFileName;
- filePath += fgkOutFileNameSuffix;
-
- // Open input file
- ofstream out(filePath, ios::out);
- if (!out) {
- cerr << filePath << endl;
- AliError("File not found.");
- return false;
- }
-#if !defined (__DECCXX)
- out.setf(std::ios::fixed);
-#endif
- WriteData1(out);
- WriteData2(out);
-
- return true;
-}
-
-//______________________________________________________________________________
-Bool_t AliMUONVGeometryBuilder::WriteSVMap(Bool_t rebuild) const
-{
-// Writes sensitive volume map into a file
-// Returns true, if writing finished correctly.
-// ---
-
- // No writing
- // if builder is not associated with any geometry module
- if (fModuleGeometries->GetEntriesFast() == 0) return false;
-
- // File path
- TString filePath = gSystem->Getenv("ALICE_ROOT");
- filePath += "/MUON/data/";
- filePath += fSVMapFileName;
- filePath += fgkOutFileNameSuffix;
-
- // Open input file
- ofstream out(filePath, ios::out);
- if (!out) {
- cerr << filePath << endl;
- AliError("File not found.");
- return false;
- }
-#if !defined (__DECCXX)
- out.setf(std::ios::fixed);
-#endif
- if (rebuild) RebuildSVMaps();
-
- WriteData3(out);
-
- return true;
-}
-