X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2FAliMUONGeometryBuilder.cxx;h=7fbd5aabb9bd4e2e53ded290090f064a2e47b0e8;hb=246f008b728a930898f3f8dadca6e643db13b8fc;hp=fba0f21e9ac4cd450abc55a307220ca7fd781edc;hpb=8618c022735ab62da1eac0b583ba2da0147ab7db;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/AliMUONGeometryBuilder.cxx b/MUON/AliMUONGeometryBuilder.cxx index fba0f21e9ac..7fbd5aabb9b 100644 --- a/MUON/AliMUONGeometryBuilder.cxx +++ b/MUON/AliMUONGeometryBuilder.cxx @@ -14,32 +14,69 @@ **************************************************************************/ // $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 "AliMpDEManager.h" + #include "AliModule.h" +#include "AliSimulation.h" #include "AliLog.h" #include "AliRun.h" +#include +#include +#include +using std::endl; +/// \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, @@ -97,17 +134,34 @@ 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) + fGeometryBuilders(0), + fGeometry(0) { /// 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); } //______________________________________________________________________________ @@ -115,45 +169,24 @@ AliMUONGeometryBuilder::AliMUONGeometryBuilder() : TObject(), fModule(0), fAlign(false), + fTransformFileName(), + fSVMapFileName(), fGlobalTransformation(), - fGeometryBuilders(0) + fGeometryBuilders(0), + fGeometry(0) { /// Default constructor } -//______________________________________________________________________________ -AliMUONGeometryBuilder::AliMUONGeometryBuilder(const AliMUONGeometryBuilder& right) - : TObject(right) -{ -/// Copy constructor (not implemented) - - AliFatal("Copy constructor not provided."); -} - //______________________________________________________________________________ AliMUONGeometryBuilder::~AliMUONGeometryBuilder() { /// Destructor - if (fGeometryBuilders){ - fGeometryBuilders->Delete(); - delete fGeometryBuilders; - } + + delete fGeometryBuilders; + 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 // @@ -161,15 +194,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 + 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; @@ -214,91 +251,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::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 - 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); - AliMUONGeometryStore* detElements = geometry->GetDetElementStore(); + // Get the builder + AliMUONVGeometryBuilder* builder + = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - 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(); + // 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()); + TGeoCombiTrans appliedGlobalTransform; if (builder->ApplyGlobalTransformation()) appliedGlobalTransform = fGlobalTransformation; - // Compose global transformation - TGeoHMatrix total - = Multiply( appliedGlobalTransform, - (*geometry->GetTransformation()), - (*localTransform) ); - - // 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); - } - } -} - -//_____________________________________________________________________________ -void AliMUONGeometryBuilder::SetAlign(AliMUONVGeometryBuilder* builder) -{ -/// Set align option to all geometry modules associated with the builder - - for (Int_t j=0; jNofGeometries(); j++) { + // Loop over envelopes + const TObjArray* kEnvelopes + = geometry->GetEnvelopeStore()->GetEnvelopes(); + for (Int_t k=0; kGetEntriesFast(); k++) { - AliMUONGeometryModule* geometry = builder->Geometry(j); - - geometry->SetAlign(fAlign); - } -} + // 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"; -// -// 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) -{ -/// Add 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); - - SetAlign(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. +/// Virtual modules/envelopes are not placed + + if (fAlign) { + // Read transformations from ASCII data file + fGeometry->GetTransformer()->LoadGeometryData(fTransformFileName); + } for (Int_t i=0; iGetEntriesFast(); i++) { @@ -308,43 +388,52 @@ void AliMUONGeometryBuilder::CreateGeometry() // Create geometry + envelopes // - if (fAlign) { - if (builder->ApplyGlobalTransformation()) - builder->SetReferenceFrame(fGlobalTransformation); - 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(); - TGeoCombiTrans appliedGlobalTransform; - if (builder->ApplyGlobalTransformation()) - appliedGlobalTransform = fGlobalTransformation; - // Place the module volume if ( !geometry->IsVirtual() ) { - TGeoHMatrix total - = Multiply ( appliedGlobalTransform, - (*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); + + // 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"; @@ -367,22 +456,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 - = Multiply( appliedGlobalTransform, - (*geometry->GetTransformation()), + = Multiply( (*kModuleTransform), + appliedGlobalTransform, (*kEnvTrans) ); - PlaceVolume(env->GetName(), geometry->GetMotherVolume(), + 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); } } @@ -390,8 +480,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 @@ -400,21 +490,22 @@ void AliMUONGeometryBuilder::CreateGeometry() // Compound chamber transformation with the envelope one + the constituent one if (geometry->IsVirtual()) { TGeoHMatrix total - = Multiply ( appliedGlobalTransform, - (*geometry->GetTransformation()), - (*kEnvTrans), + = 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 - = Multiply ( (*kEnvTrans), + = Multiply ( appliedGlobalTransform, + (*kEnvTrans), (*constituent->GetTransformation()) ); - PlaceVolume(constituent->GetName(), geometry->GetVolume(), + PlaceVolume(constituent->GetName(), volName, constituent->GetCopyNo(), total, constituent->GetNpar(), constituent->GetParam(), only); } @@ -425,6 +516,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() { @@ -442,10 +592,19 @@ void AliMUONGeometryBuilder::CreateMaterials() } //______________________________________________________________________________ -void AliMUONGeometryBuilder::InitGeometry() +void AliMUONGeometryBuilder::InitGeometry(const TString& svmapFileName) { /// Initialize geometry + // Load alignement data from geometry if geometry is read from Root file + if ( AliSimulation::Instance()->IsGeometryFromFile() ) { + fAlign = true; + 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++) { @@ -454,76 +613,63 @@ void AliMUONGeometryBuilder::InitGeometry() AliMUONVGeometryBuilder* builder = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - // Read alignement data if geometry is read from Root file - if (gAlice->IsRootGeometry()) { - fAlign = true; - builder->ReadTransformations(); - } - - // 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); } } -//______________________________________________________________________________ -void AliMUONGeometryBuilder::WriteTransformations() +//________________________________________________________________ +void AliMUONGeometryBuilder::UpdateInternalGeometry() { -/// Write transformations into files per builder +/// Update geometry after applying mis-alignment: +/// reload transformations in geometry builder. - for (Int_t i=0; iGetEntriesFast(); i++) { - - // Get the builder - AliMUONVGeometryBuilder* builder - = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - - // Set reference frame - // which the transformation will be written with respect to - if (builder->ApplyGlobalTransformation()) - builder->SetReferenceFrame(fGlobalTransformation); - - // Write transformations - builder->WriteTransformations(); - } + fGeometry->GetTransformer()->LoadTransformations(); } //______________________________________________________________________________ -void AliMUONGeometryBuilder::WriteSVMaps(Bool_t rebuild) +void AliMUONGeometryBuilder::WriteSVMaps(const TString& fileName, + Bool_t rebuild, Bool_t writeEnvelopes) { /// 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->WriteSVMap(rebuild); - } + builder->RebuildSVMaps(writeEnvelopes); + } + + // Write maps in file + fGeometry->WriteSVMap(fileName); } //_____________________________________________________________________________ -void AliMUONGeometryBuilder::SetGlobalTransformation( - const TGeoCombiTrans& transform) -{ -/// Set the global transformation +void AliMUONGeometryBuilder::SetAlign(Bool_t align) +{ +/// Set the option for alignement - fGlobalTransformation = transform; -} + fAlign = align; + + for (Int_t i=0; iGetEntriesFast(); i++) { + + AliMUONVGeometryBuilder* builder + = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); + + SetAlignToBuilder(builder); + } +} //_____________________________________________________________________________ -void AliMUONGeometryBuilder::SetAlign(Bool_t align) +void AliMUONGeometryBuilder::SetAlign(const TString& fileName, Bool_t align) { -/// Set the option for alignement +/// Set the option for alignement and the transformations file name + fTransformFileName = fileName; fAlign = align; for (Int_t i=0; iGetEntriesFast(); i++) { @@ -531,6 +677,6 @@ void AliMUONGeometryBuilder::SetAlign(Bool_t align) AliMUONVGeometryBuilder* builder = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i); - SetAlign(builder); + SetAlignToBuilder(builder); } }