X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2FAliMUONGeometryBuilder.cxx;h=9d6e258628361a2e6e6ab1b1d3ab8aeaa63d43b5;hb=e4f80cd8939abda561b24d7f886037fa55f8e174;hp=083884d2bfdf5cccfad0df729806b92ac2653967;hpb=cfbf2f7dd31c53463c295f0de7a4542a792d0d98;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/AliMUONGeometryBuilder.cxx b/MUON/AliMUONGeometryBuilder.cxx index 083884d2bfd..9d6e2586283 100644 --- a/MUON/AliMUONGeometryBuilder.cxx +++ b/MUON/AliMUONGeometryBuilder.cxx @@ -15,39 +15,123 @@ // $Id$ // +// ---------------------------- // Class AliMUONGeometryBuilder // ---------------------------- // Manager class for geometry construction via geometry builders. -// // Author: Ivana Hrivnacova, IPN Orsay -#include -#include - #include "AliMUONGeometryBuilder.h" #include "AliMUONVGeometryBuilder.h" +#include "AliMUONGeometry.h" +#include "AliMUONGeometryTransformer.h" #include "AliMUONGeometryModule.h" +#include "AliMUONGeometryModuleTransformer.h" #include "AliMUONGeometryEnvelope.h" #include "AliMUONGeometryEnvelopeStore.h" #include "AliMUONGeometryDetElement.h" #include "AliMUONGeometryStore.h" -#include "AliMUONGeometryConstituent.h" +#include "AliMUONGeometryConstituent.h" + #include "AliModule.h" #include "AliLog.h" +#include "AliRun.h" -ClassImp(AliMUONGeometryBuilder) +#include +#include +#include + +// static data members +const TString AliMUONGeometryBuilder::fgkDefaultVolPathsFileName = "volpath.dat"; +const TString AliMUONGeometryBuilder::fgkDefaultTransformFileName = "transform.dat"; +const TString AliMUONGeometryBuilder::fgkDefaultSVMapFileName = "svmap.dat"; +const TString AliMUONGeometryBuilder::fgkOutFileNameExtension = ".out"; + +ClassImp(AliMUONGeometryBuilder) + +// static functions + +//______________________________________________________________________________ +TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1, + const TGeoMatrix& m2) +{ +/// Temporary fix for problem with matrix multiplication in Root 5.02/00 + + if (m1.IsIdentity() && m2.IsIdentity()) return TGeoHMatrix(); + + if (m1.IsIdentity()) return m2; + + if (m2.IsIdentity()) return m1; + + return m1 * m2; +} + +//______________________________________________________________________________ +TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1, + const TGeoMatrix& m2, + const TGeoMatrix& m3) +{ +/// Temporary fix for problem with matrix multiplication in Root 5.02/00 + + if (m1.IsIdentity() && m2.IsIdentity() & m3.IsIdentity()) + return TGeoHMatrix(); + + if (m1.IsIdentity()) return Multiply(m2, m3); + + if (m2.IsIdentity()) return Multiply(m1, m3); + + if (m3.IsIdentity()) return Multiply(m1, m2); + + return m1 * m2 * m3; +} + +//______________________________________________________________________________ +TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1, + const TGeoMatrix& m2, + const TGeoMatrix& m3, + const TGeoMatrix& m4) +{ +/// Temporary fix for problem with matrix multiplication in Root 5.02/00 + + if (m1.IsIdentity() && m2.IsIdentity() & m3.IsIdentity() & m4.IsIdentity()) + return TGeoHMatrix(); + + if (m1.IsIdentity()) return Multiply(m2, m3, m4); + + if (m2.IsIdentity()) return Multiply(m1, m3, m4); + + if (m3.IsIdentity()) return Multiply(m1, m2, m4); + + if (m4.IsIdentity()) return Multiply(m1, m2, m3); + + return m1 * m2 * m3 * m4; +} + //______________________________________________________________________________ AliMUONGeometryBuilder::AliMUONGeometryBuilder(AliModule* module) : TObject(), fModule(module), fAlign(false), + fTransformFileName(fgkDefaultTransformFileName), + fSVMapFileName(fgkDefaultSVMapFileName), fGlobalTransformation(), - fGeometryBuilders(0) + fGeometryBuilders(0), + fGeometry(0) { -// Standard constructor +/// Standard constructor - fGeometryBuilders = new TObjArray(100); + fGeometryBuilders = new TObjArray(); + fGeometryBuilders->SetOwner(true); + + fGeometry = new AliMUONGeometry(true); + + // Define the global transformation: + // Transformation from the old ALICE coordinate system to a new one: + // x->-x, z->-z + TGeoRotation* rotGlobal + = new TGeoRotation("rotGlobal", 90., 180., 90., 90., 180., 0.); + fGlobalTransformation = TGeoCombiTrans(0., 0., 0., rotGlobal); } //______________________________________________________________________________ @@ -55,17 +139,20 @@ AliMUONGeometryBuilder::AliMUONGeometryBuilder() : TObject(), fModule(0), fAlign(false), + fTransformFileName(), + fSVMapFileName(), fGlobalTransformation(), - fGeometryBuilders(0) + fGeometryBuilders(0), + fGeometry(0) { -// Default constructor +/// Default constructor } //______________________________________________________________________________ AliMUONGeometryBuilder::AliMUONGeometryBuilder(const AliMUONGeometryBuilder& right) : TObject(right) { - // copy constructor (not implemented) +/// Copy constructor (not implemented) AliFatal("Copy constructor not provided."); } @@ -73,18 +160,17 @@ AliMUONGeometryBuilder::AliMUONGeometryBuilder(const AliMUONGeometryBuilder& rig //______________________________________________________________________________ AliMUONGeometryBuilder::~AliMUONGeometryBuilder() { -// Destructor - if (fGeometryBuilders){ - fGeometryBuilders->Delete(); - delete fGeometryBuilders; - } +/// Destructor + + delete fGeometryBuilders; + delete fGeometry; } //______________________________________________________________________________ AliMUONGeometryBuilder& AliMUONGeometryBuilder::operator=(const AliMUONGeometryBuilder& right) { - // assignement operator (not implemented) +/// Assignement operator (not implemented) // check assignement to self if (this == &right) return *this; @@ -101,16 +187,19 @@ AliMUONGeometryBuilder::operator=(const AliMUONGeometryBuilder& right) //______________________________________________________________________________ void AliMUONGeometryBuilder::PlaceVolume(const TString& name, const TString& mName, Int_t copyNo, const TGeoHMatrix& matrix, - Int_t npar, Double_t* param, const char* only) const + Int_t npar, Double_t* param, const char* only, + Bool_t makeAssembly) const { -// Place the volume specified by name with the given transformation matrix -// --- +/// Place the volume specified by name with the given transformation matrix + + if (makeAssembly) + gGeoManager->MakeVolumeAssembly(name.Data()); + TGeoHMatrix transform(matrix); // Do not apply global transformation // if mother volume was already placed in // the new system of coordinates (that is MUON in negative Z) // (as it is applied on the mother volume) - TGeoHMatrix transform(matrix); if (mName == TString("DDIP")) transform = fGlobalTransformation.Inverse() * transform; @@ -155,76 +244,120 @@ void AliMUONGeometryBuilder::PlaceVolume(const TString& name, const TString& mNa fModule->AliMatrix(krot, theta1, phi1, theta2, phi2, theta3, phi3); } - // Place the volume in ALIC + // Place the volume if (npar == 0) gMC->Gspos(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only); else gMC->Gsposp(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only, param, npar); - } //______________________________________________________________________________ -void AliMUONGeometryBuilder::FillGlobalTransformations( - AliMUONVGeometryBuilder* builder) +void AliMUONGeometryBuilder::CreateGeometryWithTGeo() { -// Compute and set global transformations to detection elements -// for each chamber geometry -// --- +/// Construct geometry using geometry builders. +/// Virtual modules/envelopes are placed as TGeoVolume assembly + + if (fAlign) { + // Read transformations from ASCII data file + fGeometry->GetTransformer() + ->ReadGeometryData(fgkDefaultVolPathsFileName, fTransformFileName); + } + + for (Int_t i=0; iGetEntriesFast(); i++) { - for (Int_t j=0; jNofGeometries(); j++) { + // Get the builder + AliMUONVGeometryBuilder* builder + = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - AliMUONGeometryModule* geometry = builder->Geometry(j); - AliMUONGeometryStore* detElements = geometry->GetDetElementStore(); + // Create geometry + envelopes + // + builder->CreateGeometry(); + if (!fAlign) builder->SetTransformations(); + + // Place module volumes and envelopes + // + for (Int_t j=0; jNofGeometries(); j++) { - for (Int_t k=0; kGetNofEntries(); k++) { - - AliMUONGeometryDetElement* detElement - = (AliMUONGeometryDetElement*)detElements->GetEntry(k); - - if (!detElement) AliFatal("Detection element not found.") - - const TGeoCombiTrans* localTransform - = detElement->GetLocalTransformation(); - - // Compose global transformation - TGeoHMatrix total - = fGlobalTransformation * - (*geometry->GetTransformation()) * - (*localTransform); + AliMUONGeometryModule* geometry = builder->Geometry(j); + AliMUONGeometryModuleTransformer* transformer= geometry->GetTransformer(); + const TGeoHMatrix* kModuleTransform = transformer->GetTransformation(); + TString volName = transformer->GetVolumeName(); + TString motherVolName = transformer->GetMotherVolumeName(); + + // Place the module volume + PlaceVolume(volName, motherVolName, + 1, *kModuleTransform, 0, 0, "ONLY", geometry->IsVirtual()); + + TGeoCombiTrans appliedGlobalTransform; + if (builder->ApplyGlobalTransformation()) + appliedGlobalTransform = fGlobalTransformation; + + // Loop over envelopes + const TObjArray* kEnvelopes + = geometry->GetEnvelopeStore()->GetEnvelopes(); + for (Int_t k=0; kGetEntriesFast(); k++) { + + // Get envelope + AliMUONGeometryEnvelope* env + = (AliMUONGeometryEnvelope*)kEnvelopes->At(k); - // Convert TGeoHMatrix to TGeoCombiTrans - TGeoCombiTrans globalTransform(localTransform->GetName()); - globalTransform.SetTranslation(total.GetTranslation()); - TGeoRotation rotation; - rotation.SetMatrix(total.GetRotationMatrix()); - globalTransform.SetRotation(rotation); - - // Set the global transformation to detection element - detElement->SetGlobalTransformation(globalTransform); - } - } -} + const TGeoCombiTrans* kEnvTrans = env->GetTransformation(); + const char* only = "ONLY"; + if (env->IsMANY()) only = "MANY"; -// -// public functions -// + if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) { + // virtual envelope + nof constituents = 0 + // => not allowed; + // empty virtual envelope has no sense + AliFatal("Virtual envelope must have constituents."); + return; + } -//_____________________________________________________________________________ -void AliMUONGeometryBuilder::AddBuilder(AliMUONVGeometryBuilder* geomBuilder) -{ -// Adds the geometry builder to the list -// --- + if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) { + // non virtual envelope + nof constituents > 0 + // => not allowed; + // use VMC to place constituents + AliFatal("Non virtual envelope cannot have constituents."); + return; + } - fGeometryBuilders->Add(geomBuilder); + // Place envelope in geometry module by composed transformation: + // [Tglobal] * Tenv + TGeoHMatrix total + = Multiply( appliedGlobalTransform, + (*kEnvTrans) ); + PlaceVolume(env->GetName(), volName, + env->GetCopyNo(), total, 0, 0, only, env->IsVirtual()); + + if ( env->IsVirtual() ) { + // Place constituents in the envelope + for (Int_t l=0; lGetConstituents()->GetEntriesFast(); l++) { + AliMUONGeometryConstituent* constituent + = (AliMUONGeometryConstituent*)env->GetConstituents()->At(l); + + PlaceVolume(constituent->GetName(), env->GetName(), + constituent->GetCopyNo(), + *constituent->GetTransformation() , + constituent->GetNpar(), constituent->GetParam(), only); + } + } + } // end of loop over envelopes + } // end of loop over builder geometries + } // end of loop over builders } //______________________________________________________________________________ -void AliMUONGeometryBuilder::CreateGeometry() +void AliMUONGeometryBuilder::CreateGeometryWithoutTGeo() { -// -// Construct geometry using geometry builders. -// +/// Construct geometry using geometry builders. +/// Virtual modules/enevlopes are not placed + + if (fAlign) { + // Read transformations from ASCII data file + fGeometry->GetTransformer() + ->ReadGeometryData(fgkDefaultVolPathsFileName, fTransformFileName); + } for (Int_t i=0; iGetEntriesFast(); i++) { @@ -234,37 +367,38 @@ void AliMUONGeometryBuilder::CreateGeometry() // Create geometry + envelopes // - if (fAlign) { - builder->ReadTransformations(); - builder->CreateGeometry(); - } - else { - builder->CreateGeometry(); - builder->SetTransformations(); - } - + builder->CreateGeometry(); + if (!fAlign) builder->SetTransformations(); + // Place module volumes and envelopes // for (Int_t j=0; jNofGeometries(); j++) { AliMUONGeometryModule* geometry = builder->Geometry(j); + AliMUONGeometryModuleTransformer* transformer= geometry->GetTransformer(); + const TGeoHMatrix* kModuleTransform = transformer->GetTransformation(); + TString volName = transformer->GetVolumeName(); + TString motherVolName = transformer->GetMotherVolumeName(); // Place the module volume if ( !geometry->IsVirtual() ) { - TGeoHMatrix total - = fGlobalTransformation * - (*geometry->GetTransformation()); - - PlaceVolume(geometry->GetVolume(), geometry->GetMotherVolume(), - 1, total, 0, 0, "ONLY"); + PlaceVolume(volName, motherVolName, + 1, *kModuleTransform, 0, 0, "ONLY"); } + TGeoCombiTrans appliedGlobalTransform; + if (builder->ApplyGlobalTransformation()) + appliedGlobalTransform = fGlobalTransformation; + // Loop over envelopes - const TObjArray* kEnvelopes = geometry->GetEnvelopeStore()->GetEnvelopes(); + const TObjArray* kEnvelopes + = geometry->GetEnvelopeStore()->GetEnvelopes(); for (Int_t k=0; kGetEntriesFast(); k++) { // Get envelope - AliMUONGeometryEnvelope* env = (AliMUONGeometryEnvelope*)kEnvelopes->At(k); + AliMUONGeometryEnvelope* env + = (AliMUONGeometryEnvelope*)kEnvelopes->At(k); + const TGeoCombiTrans* kEnvTrans = env->GetTransformation(); const char* only = "ONLY"; if (env->IsMANY()) only = "MANY"; @@ -287,22 +421,23 @@ void AliMUONGeometryBuilder::CreateGeometry() if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) { // non virtual envelope + nof constituents = 0 - // => place envelope in ALICE by composed transformation: - // Tglobal * Tch * Tenv + // => place envelope by composed transformation: + // Tch * [Tglobal] * Tenv // Compound chamber transformation with the envelope one if (geometry->IsVirtual()) { TGeoHMatrix total - = fGlobalTransformation * - (*geometry->GetTransformation()) * - (*kEnvTrans); - PlaceVolume(env->GetName(), geometry->GetMotherVolume(), + = Multiply( (*kModuleTransform), + appliedGlobalTransform, + (*kEnvTrans) ); + PlaceVolume(env->GetName(), motherVolName, env->GetCopyNo(), total, 0, 0, only); } else { TGeoHMatrix total - = (*kEnvTrans); - PlaceVolume(env->GetName(), geometry->GetVolume(), + = Multiply( appliedGlobalTransform, + (*kEnvTrans) ); + PlaceVolume(env->GetName(), volName, env->GetCopyNo(), total, 0, 0, only); } } @@ -310,8 +445,8 @@ void AliMUONGeometryBuilder::CreateGeometry() if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) { // virtual envelope + nof constituents > 0 // => do not place envelope and place constituents - // in ALICE by composed transformation: - // Tglobal * Tch * Tenv * Tconst + // by composed transformation: + // Tch * [Tglobal] * Tenv * Tconst for (Int_t l=0; lGetConstituents()->GetEntriesFast(); l++) { AliMUONGeometryConstituent* constituent @@ -320,21 +455,22 @@ void AliMUONGeometryBuilder::CreateGeometry() // Compound chamber transformation with the envelope one + the constituent one if (geometry->IsVirtual()) { TGeoHMatrix total - = fGlobalTransformation * - (*geometry->GetTransformation()) * - (*kEnvTrans) * - (*constituent->GetTransformation()); + = Multiply ( (*kModuleTransform), + appliedGlobalTransform, + (*kEnvTrans), + (*constituent->GetTransformation()) ); - PlaceVolume(constituent->GetName(), geometry->GetMotherVolume(), + PlaceVolume(constituent->GetName(), motherVolName, constituent->GetCopyNo(), total, constituent->GetNpar(), constituent->GetParam(), only); } else { TGeoHMatrix total - = (*kEnvTrans) * - (*constituent->GetTransformation()); + = Multiply ( appliedGlobalTransform, + (*kEnvTrans), + (*constituent->GetTransformation()) ); - PlaceVolume(constituent->GetName(), geometry->GetVolume(), + PlaceVolume(constituent->GetName(), volName, constituent->GetCopyNo(), total, constituent->GetNpar(), constituent->GetParam(), only); } @@ -346,11 +482,58 @@ void AliMUONGeometryBuilder::CreateGeometry() } //_____________________________________________________________________________ -void AliMUONGeometryBuilder::CreateMaterials() +void AliMUONGeometryBuilder::SetAlign(AliMUONVGeometryBuilder* builder) { +/// Set align option to all geometry modules associated with the builder + + for (Int_t j=0; jNofGeometries(); j++) { + + AliMUONGeometryModule* geometry = builder->Geometry(j); + + geometry->SetAlign(fAlign); + } +} + // -// Construct materials specific to modules via builders +// public functions // + +//_____________________________________________________________________________ +void AliMUONGeometryBuilder::AddBuilder(AliMUONVGeometryBuilder* geomBuilder) +{ +/// Add the geometry builder to the list + + fGeometryBuilders->Add(geomBuilder); + + // Pass geometry modules created in the to the geometry parametrisation + for (Int_t i=0; iNofGeometries(); i++) { + fGeometry->AddModule(geomBuilder->Geometry(i)); + } + + if (geomBuilder->ApplyGlobalTransformation()) + geomBuilder->SetReferenceFrame(fGlobalTransformation); + + SetAlign(geomBuilder); +} + +//______________________________________________________________________________ +void AliMUONGeometryBuilder::CreateGeometry() +{ +/// Construct geometry using geometry builders. + + if ( gMC->IsRootGeometrySupported() && + TString(gMC->ClassName()) != "TGeant4" ) { + + CreateGeometryWithTGeo(); + } + else + CreateGeometryWithoutTGeo(); +} + +//_____________________________________________________________________________ +void AliMUONGeometryBuilder::CreateMaterials() +{ +/// Construct materials specific to modules via builders for (Int_t i=0; iGetEntriesFast(); i++) { @@ -364,11 +547,21 @@ void AliMUONGeometryBuilder::CreateMaterials() } //______________________________________________________________________________ -void AliMUONGeometryBuilder::InitGeometry() +void AliMUONGeometryBuilder::InitGeometry(const TString& svmapFileName) { - // Initialize geometry - // --- +/// Initialize geometry + + // Load alignement data from geometry if geometry is read from Root file + if ( gAlice->IsRootGeometry() ) { + fAlign = true; + fGeometry->GetTransformer() + ->ReadGeometryData(fgkDefaultVolPathsFileName, gGeoManager); + } + + // Read sensitive volume map from a file + fGeometry->ReadSVMap(svmapFileName); + // Set the chamber (sensitive region) GEANT identifier // for (Int_t i=0; iGetEntriesFast(); i++) { @@ -377,81 +570,70 @@ void AliMUONGeometryBuilder::InitGeometry() AliMUONVGeometryBuilder* builder = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - // Set sesitive volumes with each builder + // Set sensitive volumes with each builder builder->SetSensitiveVolumes(); - - // Read sensitive volume map from a file - builder->ReadSVMap(); - if (!fAlign) builder->FillTransformations(); - // Compute global transformations of detection elements - FillGlobalTransformations(builder); + if (!fAlign) { + // Create detection elements from built geometry + builder->CreateDetElements(); + } } } //______________________________________________________________________________ -void AliMUONGeometryBuilder::WriteTransformations() +void AliMUONGeometryBuilder::WriteSVMaps(const TString& fileName, + Bool_t rebuild) { - // Writes transformations into files per builder - // --- +/// Write sensitive volume maps into files per builder - for (Int_t i=0; iGetEntriesFast(); i++) { + // Rebuild sv maps + // + if (rebuild) + for (Int_t i=0; iGetEntriesFast(); i++) { - // Get the builder - AliMUONVGeometryBuilder* builder - = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); + AliMUONVGeometryBuilder* builder + = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - // Write transformations - builder->WriteTransformations(); - } + Bool_t writeEnvelopes = false; + if ( gMC->IsRootGeometrySupported() && + TString(gMC->ClassName()) != "TGeant4") writeEnvelopes = true; + + builder->RebuildSVMaps(writeEnvelopes); + } + + // Write maps in file + fGeometry->WriteSVMap(fileName); } -//______________________________________________________________________________ -void AliMUONGeometryBuilder::WriteSVMaps(Bool_t rebuild) -{ - // Writes sensitive volume maps into files per builder - // --- +//_____________________________________________________________________________ +void AliMUONGeometryBuilder::SetAlign(Bool_t align) +{ +/// Set the option for alignement + + fAlign = align; for (Int_t i=0; iGetEntriesFast(); i++) { - // Get the builder AliMUONVGeometryBuilder* builder = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - - // Write transformations - builder->WriteSVMap(rebuild); - } + + SetAlign(builder); + } } //_____________________________________________________________________________ -void AliMUONGeometryBuilder::SetGlobalTransformation( - const TGeoCombiTrans& transform) -{ -// Sets the global transformation -// --- - - fGlobalTransformation = transform; -} - -//_____________________________________________________________________________ -void AliMUONGeometryBuilder::SetAlign(Bool_t align) +void AliMUONGeometryBuilder::SetAlign(const TString& fileName, Bool_t align) { -// Sets the option for alignement -// --- +/// Set the option for alignement + fTransformFileName = fileName; fAlign = align; for (Int_t i=0; iGetEntriesFast(); i++) { - // Get the builder AliMUONVGeometryBuilder* builder = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - - for (Int_t j=0; jNofGeometries(); j++) { - - AliMUONGeometryModule* geometry = builder->Geometry(j); - - geometry->SetAlign(align); - } - } + + SetAlign(builder); + } }