// $Id$
// Category: geometry
//
+// Author: I. Hrivnacova
+//
+// Class AliDetConstruction
+// ------------------------
// See the class description in the header file.
#include "AliDetConstruction.h"
-#include "AliSingleModuleConstruction.h"
#include "AliDetSwitch.h"
+#include "AliLVTree.h"
#include "AliGlobals.h"
+#include "AliFiles.h"
#include "AliRun.h"
#include "AliModule.h"
+#include "TG4XMLGeometryGenerator.h"
+#include "TG4GeometryServices.h"
+
+#include <G4VPhysicalVolume.hh>
+
+//_____________________________________________________________________________
AliDetConstruction::AliDetConstruction()
- : fTopVolumeName("ALIC")
+ : AliModulesComposition()
{
// initialize det switch vector:
- // moduleName nofVersions defaultVersion PPRVersion [type isStandalone]
- // det switch objects are deleted in
- // tbe base class (AliModulesCompositions) destructor
-
- AliDetSwitch* detSwitch;
- detSwitch = new AliDetSwitch("ABSO", 1, 0, 0, kStructure);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("DIPO", 3, 2, 2, kStructure, false);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("FRAME", 2, 1, 1, kStructure, false);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("HALL", 1, 0, 0, kStructure);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("MAG", 1, 0, 0, kStructure);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("PIPE", 4, 0, 0, kStructure);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("SHIL", 1, 0, 0, kStructure);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("CASTOR", 2, 1, 1);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("FMD", 2, 0, 0);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("ITS", 10, 7, 7);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("MUON", 2, 0, 0);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("PHOS", 5, 1, 1);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("PMD", 3, 1, 1);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("RICH", 3, 1, 1);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("START", 2, 1, 1);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("TOF", 5, 2, 2, kDetector, false);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("TPC", 4, 2, 2);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("TRD", 2, 1, 1, kDetector, false);
- AddDetSwitch(detSwitch);
- detSwitch = new AliDetSwitch("ZDC", 2, 1, 1, kDetector, false);
- AddDetSwitch(detSwitch);
+ // moduleName nofVersions defaultVersion [type]
+ // det switch objects are deleted in fDetSwitchVector destructor
+
+ fDetSwitchVector.Add(new AliDetSwitch("MAG", 1, 0, kStructure));
+ fDetSwitchVector.Add(new AliDetSwitch("ABSO", 1, 0, kStructure));
+ fDetSwitchVector.Add(new AliDetSwitch("DIPO", 3, 2, kStructure));
+ fDetSwitchVector.Add(new AliDetSwitch("FRAME", 3, 2, kStructure));
+ fDetSwitchVector.Add(new AliDetSwitch("HALL", 1, 0, kStructure));
+ fDetSwitchVector.Add(new AliDetSwitch("PIPE", 5, 0, kStructure));
+ fDetSwitchVector.Add(new AliDetSwitch("SHIL", 2, 1, kStructure));
+ fDetSwitchVector.Add(new AliDetSwitch("CASTOR", 2, 1));
+ fDetSwitchVector.Add(new AliDetSwitch("FMD", 2, 1));
+ fDetSwitchVector.Add(new AliDetSwitch("ITS", 7, 5));
+ fDetSwitchVector.Add(new AliDetSwitch("MUON", 2, 1));
+ fDetSwitchVector.Add(new AliDetSwitch("PHOS", 2, 1));
+ fDetSwitchVector.Add(new AliDetSwitch("PMD", 3, 1));
+ fDetSwitchVector.Add(new AliDetSwitch("RICH", 3, 1));
+ fDetSwitchVector.Add(new AliDetSwitch("START", 2, 1));
+ fDetSwitchVector.Add(new AliDetSwitch("TOF", 5, 2));
+ fDetSwitchVector.Add(new AliDetSwitch("TPC", 4, 2));
+ fDetSwitchVector.Add(new AliDetSwitch("TRD", 2, 1));
+ fDetSwitchVector.Add(new AliDetSwitch("ZDC", 3, 2));
+
+ // update messenger
+ fDetSwitchVector.UpdateMessenger();
+
+ // instantiate LVtree browser
+ AliLVTree::Instance();
}
+//_____________________________________________________________________________
AliDetConstruction::AliDetConstruction(const AliDetConstruction& right)
: AliModulesComposition(right)
{
// AliModuleComposition is protected from copying
}
-AliDetConstruction::~AliDetConstruction() {
-//
+//_____________________________________________________________________________
+AliDetConstruction::~AliDetConstruction()
+{
+ // delete LVtree browser
+ delete AliLVTree::Instance();
}
// operators
+//_____________________________________________________________________________
AliDetConstruction&
AliDetConstruction::operator=(const AliDetConstruction& right)
{
// private methods
+//_____________________________________________________________________________
void AliDetConstruction::BuildDetectors()
{
// Create module constructions for AliModules
text = text + module->GetName() + " has been found.";
AliGlobals::Exception(text);
}
- AddSingleModuleConstruction("BODY", 0, kStructure);
+ AddModule("BODY", 0, kStructure);
G4bool first = true;
while ((module = (AliModule*)next())) {
+
// register moduleConstruction in fDetSwitchVector
- // in order to keep availability of /AlDet/list command
+ // in order to keep availability of /aliDet/list command
G4String modName = module->GetName();
G4int modVersion = module->IsVersion();
if (first)
// skip registering of the top volume
first = false;
else
- SwitchDetOn(modName, modVersion);
+ fDetSwitchVector.SwitchDetOn(modName, modVersion);
// all modules will be processed alltogether
- AddMoreModuleConstruction(modName, modVersion);
+ AddModule(modName, modVersion, fDetSwitchVector.GetDetSwitch(modName)->GetType());
- G4cout << "Created module construction for "
- << modName << "v" << modVersion << "." << G4endl;
+ if (VerboseLevel() > 0) {
+ G4cout << "Created module construction for "
+ << modName << "v" << modVersion << "." << G4endl;
+ }
}
// do not process Config.C
SetProcessConfigToModules(false);
}
+//_____________________________________________________________________________
void AliDetConstruction::CreateDetectors()
{
// Creates AliModules and their module constructions
// ---
// add top volume (AliBODY) construction first
- AddSingleModuleConstruction("BODY", 0, kStructure);
+ AddModule("BODY", 0, kStructure);
// add modules constructions
- const G4RWTPtrOrderedVector<AliDetSwitch>& krDetSwitchVector
- = GetDetSwitchVector();
- for (G4int id=0; id<krDetSwitchVector.entries(); id++)
+ for (G4int i=0; i<fDetSwitchVector.GetSize(); i++)
{
- G4String detName = krDetSwitchVector[id]->GetDetName();
- G4int version = krDetSwitchVector[id]->GetSwitchedVersion();
- G4bool isStandalone = krDetSwitchVector[id]->IsStandalone();
- AliModuleType type = krDetSwitchVector[id]->GetType();
+ AliDetSwitch* detSwitch = fDetSwitchVector.GetDetSwitch(i);
+ G4String detName = detSwitch->GetDetName();
+ G4int version = detSwitch->GetSwitchedVersion();
+ AliModuleType type = detSwitch->GetType();
if (version > -1)
- if (isStandalone)
- AddSingleModuleConstruction(detName, version, type);
- else
- AddMoreModuleConstruction(detName, version, type);
+ AddModule(detName, version, type);
}
}
-void AliDetConstruction::CheckDetDependencies()
+//_____________________________________________________________________________
+void AliDetConstruction::CheckDependence(const G4String& master,
+ const G4String& slave)
{
-// Checks modules dependencies.
-// Dependent modules FRAME, TOF, TRD
-// TOF always requires FRAMEv1
-// TRD can be built with both (??)
-// ZDC requires DIPO
+// Checks modules dependence.
+// If master is switch on and slave off, the default version
+// of slave is switched on and a warning is issued.
// ---
- const G4RWTPtrOrderedVector<AliDetSwitch>& krDetSwitchVector
- = GetDetSwitchVector();
-
- // get switched versions of dependent modules
- G4int nofDets = krDetSwitchVector.entries();
- G4int verFRAME = -1;
- G4int verDIPO = -1;
- G4int verTOF = -1;
- G4int verTRD = -1;
- G4int verZDC = -1;
- AliDetSwitch* detSwitchFRAME = 0;
- AliDetSwitch* detSwitchDIPO = 0;
- for (G4int id=0; id<nofDets; id++) {
- G4String detName = krDetSwitchVector[id]->GetDetName();
- if (detName == "FRAME") {
- verFRAME = krDetSwitchVector[id]->GetSwitchedVersion();
- detSwitchFRAME = krDetSwitchVector[id];
- }
- if (detName == "DIPO") {
- verDIPO = krDetSwitchVector[id]->GetSwitchedVersion();
- detSwitchDIPO = krDetSwitchVector[id];
- }
- if (detName == "TOF")
- verTOF = krDetSwitchVector[id]->GetSwitchedVersion();
- if (detName == "TRD")
- verTRD = krDetSwitchVector[id]->GetSwitchedVersion();
- if (detName == "ZDC")
- verZDC = krDetSwitchVector[id]->GetSwitchedVersion();
+ AliDetSwitch* masterSwitch = fDetSwitchVector.GetDetSwitch(master);
+ AliDetSwitch* slaveSwitch = fDetSwitchVector.GetDetSwitch(slave);
+
+ if ( masterSwitch->GetSwitchedVersion() > -1 &&
+ slaveSwitch->GetSwitchedVersion() < 0 ) {
+
+ slaveSwitch->SwitchOnDefault();
+
+ // warning
+ G4String text = "AliDetConstruction::CheckDetDependence: \n";
+ text = text + " Switched " + master + " requires " + slave + ".\n";
+ text = text + " The det switch for " + slave + " has been changed.";
+ AliGlobals::Warning(text);
}
+}
- // check dependencies
- if (verTRD > -1 && verTOF > -1) {
- // both TRD and TOF
- if (verFRAME != 1) {
- detSwitchFRAME->SwitchOn(1);
- G4String text = "AliDetConstruction::CheckDetDependencies: \n";
- text = text + " Switched TOF and TRD require FRAME v1.\n";
- text = text + " The det switch for FRAME has been changed.";
- AliGlobals::Warning(text);
- }
- }
- else if (verTRD > -1 && verTOF == -1) {
- // only TRD
- if (verFRAME < 0) {
- detSwitchFRAME->SwitchOn(1);
- G4String text = "AliDetConstruction::CheckDetDependencies: \n";
- text = text + " Switched TRD require FRAME.\n";
- text = text + " The det switch for FRAME has been changed.";
- AliGlobals::Warning(text);
- }
- }
- else if (verTRD == -1 && verTOF > -1) {
- // only TOF
- if (verFRAME != 1) {
- detSwitchFRAME->SwitchOn(1);
- G4String text = "AliDetConstruction::CheckDetDependencies: \n";
- text = text + " Switched TOF requires FRAME v1.\n";
- text = text + " The det switch for FRAME has been changed.";
- AliGlobals::Warning(text);
- }
- }
- if (verZDC > 0 && verDIPO == -1) {
- detSwitchDIPO->SwitchOnDefault();
- G4String text = "AliDetConstruction::CheckDetDependencies: \n";
- text = text + " Switched ZDC requires DIPO.\n";
- text = text + " The det switch for DIPO has been changed.";
- AliGlobals::Warning(text);
- }
+//_____________________________________________________________________________
+void AliDetConstruction::CheckDetDependencies()
+{
+// Checks modules dependencies.
+// ---
+
+ CheckDependence("MUON", "DIPO");
+ CheckDependence("TOF", "FRAME");
+ CheckDependence("TRD", "FRAME");
+ CheckDependence("ZDC", "PIPE");
+ CheckDependence("ZDC", "ABSO");
+ CheckDependence("ZDC", "DIPO");
+ CheckDependence("ZDC", "SHIL");
}
// public methods
+//_____________________________________________________________________________
G4VPhysicalVolume* AliDetConstruction::Construct()
{
// Constructs geometry.
// construct modules geometry
ConstructModules();
- return AliSingleModuleConstruction::GetWorld();
+ return TG4GeometryServices::Instance()->GetWorld();
}
+//_____________________________________________________________________________
+void AliDetConstruction::GenerateXMLGeometry() const
+{
+// Generates XML geometry file from the top volume.
+// The file name is set according the last switched detector
+// registered in the det switch vector.
+// ---
+
+ G4VPhysicalVolume* world = TG4GeometryServices::Instance()->GetWorld();
+
+ // XML filename
+ // according to last switched detector
+ G4String detName;
+ G4String detVersion = "";
+ G4int version = -1;
+ for (G4int i=fDetSwitchVector.GetSize()-1; i>=0; i--) {
+ version = fDetSwitchVector.GetDetSwitch(i)->GetSwitchedVersion();
+ if (version > -1) {
+ detName = fDetSwitchVector.GetDetSwitch(i)->GetDetName();
+ AliGlobals::AppendNumberToString(detVersion,version);
+ break;
+ }
+ }
+ G4String filePath
+ = AliFiles::Instance()->GetXMLFilePath(detName, version);
+
+ // set top volume name
+ G4String topName = world->GetName() + "_comp";
+
+ // generate XML
+
+ TG4XMLGeometryGenerator xml;
+ xml.OpenFile(filePath);
+
+ // generate materials
+ // not implemented
+ // xml.GenerateMaterials(version, "today", "Generated from G4",
+ // "v4", world->GetLogicalVolume());
+
+ // generate volumes tree
+ xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4",
+ topName, world->GetLogicalVolume());
+ xml.CloseFile();
+
+ if (VerboseLevel() > 0) {
+ G4cout << "File " << detName << "v" << version << ".xml has been generated."
+ << G4endl;
+ }
+}
+