X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2FAliMUONGeometryBuilder.cxx;h=74cfb99141e9d9190fccf176e52091a9acfccde3;hb=b7474abb6e3c8c4a0f3c5dfc6c8bc3a86802e4ab;hp=06314bbb6311391a9de3a128141ac5b0be1a37ec;hpb=063619ad78f764d815dde89aa2be7dc69b3e7dab;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/AliMUONGeometryBuilder.cxx b/MUON/AliMUONGeometryBuilder.cxx index 06314bbb631..74cfb99141e 100644 --- a/MUON/AliMUONGeometryBuilder.cxx +++ b/MUON/AliMUONGeometryBuilder.cxx @@ -14,15 +14,13 @@ **************************************************************************/ // $Id$ -// + +//----------------------------------------------------------------------------- // Class AliMUONGeometryBuilder // ---------------------------- // Manager class for geometry construction via geometry builders. -// // Author: Ivana Hrivnacova, IPN Orsay - -#include -#include +//----------------------------------------------------------------------------- #include "AliMUONGeometryBuilder.h" #include "AliMUONVGeometryBuilder.h" @@ -33,16 +31,51 @@ #include "AliMUONGeometryEnvelope.h" #include "AliMUONGeometryEnvelopeStore.h" #include "AliMUONGeometryDetElement.h" -#include "AliMUONGeometryStore.h" #include "AliMUONGeometryConstituent.h" + +#include "AliMpDEManager.h" + #include "AliModule.h" +#include "AliSimulation.h" #include "AliLog.h" #include "AliRun.h" +#include +#include +#include +/// \cond CLASSIMP ClassImp(AliMUONGeometryBuilder) - +/// \endcond + +// // static functions +// + +//______________________________________________________________________________ +const TString& AliMUONGeometryBuilder::GetDefaultTransformFileName() +{ + ///< default transformations file name + static const TString kDefaultTransformFileName = "transform.dat"; + return kDefaultTransformFileName; +} + +//______________________________________________________________________________ +const TString& AliMUONGeometryBuilder::GetDefaultSVMapFileName() +{ + ///< default svmaps file name + static const TString kDefaultSVMapFileName = "svmap.dat"; + return kDefaultSVMapFileName; +} + +//______________________________________________________________________________ +const TString& AliMUONGeometryBuilder::GetOutFileNameExtension() +{ + ///< default output file name extension + static const TString kOutFileNameExtension = ".out"; + return kOutFileNameExtension; +} + //______________________________________________________________________________ TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1, @@ -100,11 +133,17 @@ TGeoHMatrix AliMUONGeometryBuilder::Multiply(const TGeoMatrix& m1, return m1 * m2 * m3 * m4; } +// +// ctors, dtor +// + //______________________________________________________________________________ AliMUONGeometryBuilder::AliMUONGeometryBuilder(AliModule* module) : TObject(), fModule(module), fAlign(false), + fTransformFileName(GetDefaultTransformFileName()), + fSVMapFileName(GetDefaultSVMapFileName()), fGlobalTransformation(), fGeometryBuilders(0), fGeometry(0) @@ -129,6 +168,8 @@ AliMUONGeometryBuilder::AliMUONGeometryBuilder() : TObject(), fModule(0), fAlign(false), + fTransformFileName(), + fSVMapFileName(), fGlobalTransformation(), fGeometryBuilders(0), fGeometry(0) @@ -136,15 +177,6 @@ AliMUONGeometryBuilder::AliMUONGeometryBuilder() /// Default constructor } -//______________________________________________________________________________ -AliMUONGeometryBuilder::AliMUONGeometryBuilder(const AliMUONGeometryBuilder& right) - : TObject(right) -{ -/// Copy constructor (not implemented) - - AliFatal("Copy constructor not provided."); -} - //______________________________________________________________________________ AliMUONGeometryBuilder::~AliMUONGeometryBuilder() { @@ -154,20 +186,6 @@ AliMUONGeometryBuilder::~AliMUONGeometryBuilder() delete fGeometry; } -//______________________________________________________________________________ -AliMUONGeometryBuilder& -AliMUONGeometryBuilder::operator=(const AliMUONGeometryBuilder& right) -{ -/// Assignement operator (not implemented) - - // check assignement to self - if (this == &right) return *this; - - AliFatal("Assignement operator not provided."); - - return *this; -} - // // private functions // @@ -175,10 +193,14 @@ 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 + if (makeAssembly) + gGeoManager->MakeVolumeAssembly(name.Data()); + TGeoHMatrix transform(matrix); // Do not apply global transformation // if mother volume was already placed in @@ -228,56 +250,134 @@ 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::SetAlign(AliMUONVGeometryBuilder* builder) +//______________________________________________________________________________ +void AliMUONGeometryBuilder::CreateGeometryWithTGeo() { -/// Set align option to all geometry modules associated with the builder +/// Construct geometry using geometry builders. +/// Virtual modules/envelopes are placed as TGeoVolume assembly - for (Int_t j=0; jNofGeometries(); j++) { + if (fAlign) { + // Read transformations from ASCII data file + fGeometry->GetTransformer() + ->LoadGeometryData(fTransformFileName); + } + + for (Int_t i=0; iGetEntriesFast(); i++) { - AliMUONGeometryModule* geometry = builder->Geometry(j); + // Get the builder + AliMUONVGeometryBuilder* builder + = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); + + // Create geometry + envelopes + // + builder->CreateGeometry(); + builder->SetVolumes(); + 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 + PlaceVolume(volName, motherVolName, + 1, *kModuleTransform, 0, 0, "ONLY", geometry->IsVirtual()); - geometry->SetAlign(fAlign); - } -} + TGeoCombiTrans appliedGlobalTransform; + if (builder->ApplyGlobalTransformation()) + appliedGlobalTransform = fGlobalTransformation; -// -// public functions -// + // Loop over envelopes + const TObjArray* kEnvelopes + = geometry->GetEnvelopeStore()->GetEnvelopes(); + for (Int_t k=0; kGetEntriesFast(); k++) { -//_____________________________________________________________________________ -void AliMUONGeometryBuilder::AddBuilder(AliMUONVGeometryBuilder* geomBuilder) -{ -/// Add the geometry builder to the list + // Get envelope + AliMUONGeometryEnvelope* env + = (AliMUONGeometryEnvelope*)kEnvelopes->At(k); + + // Check consistency of detElemId and module Id + if ( env->GetUniqueID() > 0 && + AliMpDEManager::GetGeomModuleId(env->GetUniqueID()) + != geometry->GetModuleId() ) { + + AliErrorStream() + << "Detection element " << env->GetUniqueID() + << " is being placed in geometry module " << geometry->GetModuleId() + << " but should go in " + << AliMpDEManager::GetGeomModuleId(env->GetUniqueID()) + << endl; + AliFatal("Inconsistent IDs"); + } + + const TGeoCombiTrans* kEnvTrans = env->GetTransformation(); + const char* only = "ONLY"; + if (env->IsMANY()) only = "MANY"; - 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); + 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; + } + + 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; + } + + // 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. +/// Virtual modules/envelopes are not placed - if (fAlign) ReadTransformations(); + if (fAlign) { + // Read transformations from ASCII data file + fGeometry->GetTransformer()->LoadGeometryData(fTransformFileName); + } for (Int_t i=0; iGetEntriesFast(); i++) { @@ -295,12 +395,14 @@ void AliMUONGeometryBuilder::CreateGeometry() for (Int_t j=0; jNofGeometries(); j++) { AliMUONGeometryModule* geometry = builder->Geometry(j); - const TGeoCombiTrans* kModuleTransform - = geometry->GetTransformer()->GetTransformation(); + AliMUONGeometryModuleTransformer* transformer= geometry->GetTransformer(); + const TGeoHMatrix* kModuleTransform = transformer->GetTransformation(); + TString volName = transformer->GetVolumeName(); + TString motherVolName = transformer->GetMotherVolumeName(); // Place the module volume if ( !geometry->IsVirtual() ) { - PlaceVolume(geometry->GetVolume(), geometry->GetMotherVolume(), + PlaceVolume(volName, motherVolName, 1, *kModuleTransform, 0, 0, "ONLY"); } @@ -317,6 +419,20 @@ void AliMUONGeometryBuilder::CreateGeometry() AliMUONGeometryEnvelope* env = (AliMUONGeometryEnvelope*)kEnvelopes->At(k); + // Check consistency of detElemId and module Id + if ( env->GetUniqueID() > 0 && + AliMpDEManager::GetGeomModuleId(env->GetUniqueID()) + != geometry->GetModuleId() ) { + + AliErrorStream() + << "Detection element " << env->GetUniqueID() + << " is being placed in geometry module " << geometry->GetModuleId() + << " but should go in " + << AliMpDEManager::GetGeomModuleId(env->GetUniqueID()) + << endl; + AliFatal("Inconsistent IDs"); + } + const TGeoCombiTrans* kEnvTrans = env->GetTransformation(); const char* only = "ONLY"; if (env->IsMANY()) only = "MANY"; @@ -339,7 +455,7 @@ void AliMUONGeometryBuilder::CreateGeometry() if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) { // non virtual envelope + nof constituents = 0 - // => place envelope in ALICE by composed transformation: + // => place envelope by composed transformation: // Tch * [Tglobal] * Tenv // Compound chamber transformation with the envelope one @@ -348,14 +464,14 @@ void AliMUONGeometryBuilder::CreateGeometry() = Multiply( (*kModuleTransform), appliedGlobalTransform, (*kEnvTrans) ); - PlaceVolume(env->GetName(), geometry->GetMotherVolume(), + PlaceVolume(env->GetName(), motherVolName, env->GetCopyNo(), total, 0, 0, only); } else { TGeoHMatrix total = Multiply( appliedGlobalTransform, (*kEnvTrans) ); - PlaceVolume(env->GetName(), geometry->GetVolume(), + PlaceVolume(env->GetName(), volName, env->GetCopyNo(), total, 0, 0, only); } } @@ -363,7 +479,7 @@ 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: + // by composed transformation: // Tch * [Tglobal] * Tenv * Tconst for (Int_t l=0; lGetConstituents()->GetEntriesFast(); l++) { @@ -378,7 +494,7 @@ void AliMUONGeometryBuilder::CreateGeometry() (*kEnvTrans), (*constituent->GetTransformation()) ); - PlaceVolume(constituent->GetName(), geometry->GetMotherVolume(), + PlaceVolume(constituent->GetName(), motherVolName, constituent->GetCopyNo(), total, constituent->GetNpar(), constituent->GetParam(), only); } @@ -388,7 +504,7 @@ void AliMUONGeometryBuilder::CreateGeometry() (*kEnvTrans), (*constituent->GetTransformation()) ); - PlaceVolume(constituent->GetName(), geometry->GetVolume(), + PlaceVolume(constituent->GetName(), volName, constituent->GetCopyNo(), total, constituent->GetNpar(), constituent->GetParam(), only); } @@ -399,6 +515,65 @@ void AliMUONGeometryBuilder::CreateGeometry() } // end of loop over builders } +//_____________________________________________________________________________ +void AliMUONGeometryBuilder::SetAlignToBuilder(AliMUONVGeometryBuilder* builder) const +{ +/// 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); + } +} + +// +// 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); + + SetAlignToBuilder(geomBuilder); +} + +//______________________________________________________________________________ +void AliMUONGeometryBuilder::CreateGeometry() +{ +/// Construct geometry using geometry builders. + + if ( gMC->IsRootGeometrySupported() ) { + + CreateGeometryWithTGeo(); + } + else + CreateGeometryWithoutTGeo(); + + for (Int_t i=0; iGetEntriesFast(); i++) { + + // Get the builder + AliMUONVGeometryBuilder* builder + = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); + + // Update detection elements from built geometry + Bool_t create = ! fAlign; + builder->UpdateDetElements(create); + } +} + //_____________________________________________________________________________ void AliMUONGeometryBuilder::CreateMaterials() { @@ -420,15 +595,15 @@ void AliMUONGeometryBuilder::InitGeometry(const TString& svmapFileName) { /// Initialize geometry - // Read alignement data if geometry is read from Root file - if ( gAlice->IsRootGeometry() ) { + // Load alignement data from geometry if geometry is read from Root file + if ( AliSimulation::Instance()->IsGeometryFromFile() ) { fAlign = true; - ReadTransformations(); - } + fGeometry->GetTransformer()->LoadGeometryData(); + } // Read sensitive volume map from a file fGeometry->ReadSVMap(svmapFileName); - + // Set the chamber (sensitive region) GEANT identifier // for (Int_t i=0; iGetEntriesFast(); i++) { @@ -439,38 +614,21 @@ void AliMUONGeometryBuilder::InitGeometry(const TString& svmapFileName) // Set sensitive volumes with each builder builder->SetSensitiveVolumes(); - - if (!fAlign) { - // Fill local transformations from built geometry - builder->FillTransformations(); - } } } -//______________________________________________________________________________ -void AliMUONGeometryBuilder::ReadTransformations(const TString& fileName) +//________________________________________________________________ +void AliMUONGeometryBuilder::UpdateInternalGeometry() { -/// Read transformations from ASCII files -/// and store them in the geometry parametrisation +/// Update geometry after applying mis-alignment: +/// reload transformations in geometry builder. - // Read transformations - // - AliMUONGeometryTransformer* geomTransformer = fGeometry->GetTransformer(); - geomTransformer->ReadTransformations(fileName); + fGeometry->GetTransformer()->LoadTransformations(); } //______________________________________________________________________________ -void AliMUONGeometryBuilder::WriteTransformations(const TString& fileName) -{ -/// Write transformations into files per builder - - AliMUONGeometryTransformer* geomTransformer = fGeometry->GetTransformer(); - geomTransformer->WriteTransformations(fileName); -} - -//______________________________________________________________________________ -void AliMUONGeometryBuilder::WriteSVMaps(Bool_t rebuild, - const TString& fileName) +void AliMUONGeometryBuilder::WriteSVMaps(const TString& fileName, + Bool_t rebuild, Bool_t writeEnvelopes) { /// Write sensitive volume maps into files per builder @@ -482,7 +640,7 @@ void AliMUONGeometryBuilder::WriteSVMaps(Bool_t rebuild, AliMUONVGeometryBuilder* builder = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - builder->RebuildSVMaps(); + builder->RebuildSVMaps(writeEnvelopes); } // Write maps in file @@ -501,6 +659,23 @@ void AliMUONGeometryBuilder::SetAlign(Bool_t align) AliMUONVGeometryBuilder* builder = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - SetAlign(builder); + SetAlignToBuilder(builder); + } +} + +//_____________________________________________________________________________ +void AliMUONGeometryBuilder::SetAlign(const TString& fileName, Bool_t align) +{ +/// Set the option for alignement and the transformations file name + + fTransformFileName = fileName; + fAlign = align; + + for (Int_t i=0; iGetEntriesFast(); i++) { + + AliMUONVGeometryBuilder* builder + = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); + + SetAlignToBuilder(builder); } }