**************************************************************************/
// $Id$
-//
+
+//-----------------------------------------------------------------------------
// Class AliMUONGeometryBuilder
// ----------------------------
// Manager class for geometry construction via geometry builders.
-//
// Author: Ivana Hrivnacova, IPN Orsay
-
-#include <TObjArray.h>
-#include <TVirtualMC.h>
+//-----------------------------------------------------------------------------
#include "AliMUONGeometryBuilder.h"
#include "AliMUONVGeometryBuilder.h"
#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 <TObjArray.h>
+#include <TVirtualMC.h>
+#include <TGeoManager.h>
+using std::endl;
+/// \cond CLASSIMP
ClassImp(AliMUONGeometryBuilder)
+/// \endcond
-// static data members
-
-const TString AliMUONGeometryBuilder::fgkDefaultTransformFileName = "transform.dat";
-const TString AliMUONGeometryBuilder::fgkDefaultSVMapFileName = "svmap.dat";
-const TString AliMUONGeometryBuilder::fgkOutFileNameExtension = ".out";
-
+//
// 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,
return m1 * m2 * m3 * m4;
}
+//
+// ctors, dtor
+//
+
//______________________________________________________________________________
AliMUONGeometryBuilder::AliMUONGeometryBuilder(AliModule* module)
: TObject(),
fModule(module),
fAlign(false),
- fTransformFileName(fgkDefaultTransformFileName),
- fSVMapFileName(fgkDefaultSVMapFileName),
+ fTransformFileName(GetDefaultTransformFileName()),
+ fSVMapFileName(GetDefaultSVMapFileName()),
fGlobalTransformation(),
fGeometryBuilders(0),
fGeometry(0)
/// Default constructor
}
-//______________________________________________________________________________
-AliMUONGeometryBuilder::AliMUONGeometryBuilder(const AliMUONGeometryBuilder& right)
- : TObject(right)
-{
-/// Copy constructor (not implemented)
-
- AliFatal("Copy constructor not provided.");
-}
-
//______________________________________________________________________________
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
//
//______________________________________________________________________________
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
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; j<builder->NofGeometries(); j++) {
+ if (fAlign) {
+ // Read transformations from ASCII data file
+ fGeometry->GetTransformer()
+ ->LoadGeometryData(fTransformFileName);
+ }
+
+ for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); 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; j<builder->NofGeometries(); 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; k<kEnvelopes->GetEntriesFast(); 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; i<geomBuilder->NofGeometries(); 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; l<env->GetConstituents()->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; i<fGeometryBuilders->GetEntriesFast(); i++) {
for (Int_t j=0; j<builder->NofGeometries(); 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");
}
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";
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
= 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);
}
}
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; l<env->GetConstituents()->GetEntriesFast(); l++) {
(*kEnvTrans),
(*constituent->GetTransformation()) );
- PlaceVolume(constituent->GetName(), geometry->GetMotherVolume(),
+ PlaceVolume(constituent->GetName(), motherVolName,
constituent->GetCopyNo(), total,
constituent->GetNpar(), constituent->GetParam(), only);
}
(*kEnvTrans),
(*constituent->GetTransformation()) );
- PlaceVolume(constituent->GetName(), geometry->GetVolume(),
+ PlaceVolume(constituent->GetName(), volName,
constituent->GetCopyNo(), total,
constituent->GetNpar(), constituent->GetParam(), only);
}
} // 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; j<builder->NofGeometries(); 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; i<geomBuilder->NofGeometries(); 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; i<fGeometryBuilders->GetEntriesFast(); 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()
{
{
/// 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; i<fGeometryBuilders->GetEntriesFast(); i++) {
// Set sensitive volumes with each builder
builder->SetSensitiveVolumes();
-
- if (!fAlign) {
- // Fill local transformations from built geometry
- builder->FillTransformations();
- }
}
}
-
-
-//______________________________________________________________________________
-void AliMUONGeometryBuilder::ReadTransformations(const TString& fileName)
-{
-/// Read transformations from ASCII files
-/// and store them in the geometry parametrisation
-
- // Read transformations
- //
- AliMUONGeometryTransformer* geomTransformer = fGeometry->GetTransformer();
- geomTransformer->ReadTransformations(fileName);
-}
-
-//______________________________________________________________________________
-void AliMUONGeometryBuilder::WriteTransformations(const TString& fileName)
+//________________________________________________________________
+void AliMUONGeometryBuilder::UpdateInternalGeometry()
{
-/// Write transformations into files per builder
+/// Update geometry after applying mis-alignment:
+/// reload transformations in geometry builder.
- AliMUONGeometryTransformer* geomTransformer = fGeometry->GetTransformer();
- geomTransformer->WriteTransformations(fileName);
+ fGeometry->GetTransformer()->LoadTransformations();
}
//______________________________________________________________________________
void AliMUONGeometryBuilder::WriteSVMaps(const TString& fileName,
- Bool_t rebuild)
+ Bool_t rebuild, Bool_t writeEnvelopes)
{
/// Write sensitive volume maps into files per builder
AliMUONVGeometryBuilder* builder
= (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
- builder->RebuildSVMaps();
+ builder->RebuildSVMaps(writeEnvelopes);
}
// Write maps in file
AliMUONVGeometryBuilder* builder
= (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
- SetAlign(builder);
+ SetAlignToBuilder(builder);
}
}
//_____________________________________________________________________________
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;
AliMUONVGeometryBuilder* builder
= (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
- SetAlign(builder);
+ SetAlignToBuilder(builder);
}
}