4 // Author: I. Hrivnacova
6 // Class AliDetConstruction
7 // ------------------------
8 // See the class description in the header file.
10 #include "AliDetConstruction.h"
11 #include "AliDetSwitch.h"
12 #include "AliLVTree.h"
13 #include "AliGlobals.h"
16 #include "AliModule.h"
18 #include "TG4XMLGeometryGenerator.h"
19 #include "TG4GeometryServices.h"
21 #include <G4VPhysicalVolume.hh>
23 //_____________________________________________________________________________
24 AliDetConstruction::AliDetConstruction()
25 : AliModulesComposition()
27 // initialize det switch vector:
28 // moduleName nofVersions defaultVersion [type]
29 // det switch objects are deleted in fDetSwitchVector destructor
31 fDetSwitchVector.Add(new AliDetSwitch("MAG", 1, 0, kStructure));
32 fDetSwitchVector.Add(new AliDetSwitch("ABSO", 1, 0, kStructure));
33 fDetSwitchVector.Add(new AliDetSwitch("DIPO", 3, 2, kStructure));
34 fDetSwitchVector.Add(new AliDetSwitch("FRAME", 3, 2, kStructure));
35 fDetSwitchVector.Add(new AliDetSwitch("HALL", 1, 0, kStructure));
36 fDetSwitchVector.Add(new AliDetSwitch("PIPE", 5, 0, kStructure));
37 fDetSwitchVector.Add(new AliDetSwitch("SHIL", 2, 1, kStructure));
38 fDetSwitchVector.Add(new AliDetSwitch("CASTOR", 2, 1));
39 fDetSwitchVector.Add(new AliDetSwitch("FMD", 2, 1));
40 fDetSwitchVector.Add(new AliDetSwitch("ITS", 7, 5));
41 fDetSwitchVector.Add(new AliDetSwitch("MUON", 2, 1));
42 fDetSwitchVector.Add(new AliDetSwitch("PHOS", 2, 1));
43 fDetSwitchVector.Add(new AliDetSwitch("PMD", 3, 1));
44 fDetSwitchVector.Add(new AliDetSwitch("RICH", 3, 1));
45 fDetSwitchVector.Add(new AliDetSwitch("START", 2, 1));
46 fDetSwitchVector.Add(new AliDetSwitch("TOF", 5, 2));
47 fDetSwitchVector.Add(new AliDetSwitch("TPC", 4, 2));
48 fDetSwitchVector.Add(new AliDetSwitch("TRD", 2, 1));
49 fDetSwitchVector.Add(new AliDetSwitch("ZDC", 3, 2));
51 // instantiate LVtree browser
52 AliLVTree::Instance();
55 //_____________________________________________________________________________
56 AliDetConstruction::AliDetConstruction(const AliDetConstruction& right)
57 : AliModulesComposition(right)
59 // AliModuleComposition is protected from copying
62 //_____________________________________________________________________________
63 AliDetConstruction::~AliDetConstruction()
65 // delete LVtree browser
66 delete AliLVTree::Instance();
71 //_____________________________________________________________________________
73 AliDetConstruction::operator=(const AliDetConstruction& right)
75 // check assignement to self
76 if (this == &right) return *this;
78 // base class assignement
79 // AliModuleComposition is protected from assigning
80 AliModulesComposition::operator=(right);
87 //_____________________________________________________________________________
88 void AliDetConstruction::BuildDetectors()
90 // Create module constructions for AliModules
91 // that have been created and registered by gAlice
94 TObjArray* pDetectors = gAlice->Detectors();
95 TIter next(pDetectors);
97 // the first AliModule is expected to be the top volume
98 AliModule *module = (AliModule*)next();
99 if (G4String(module->GetName()) != "BODY") {
100 G4String text = "AliDetConstruction::BuildDetectors():\n";
101 text = text + " Instead of BODY - the first module ";
102 text = text + module->GetName() + " has been found.";
103 AliGlobals::Exception(text);
105 AddModule("BODY", 0, kStructure);
108 while ((module = (AliModule*)next())) {
110 // register moduleConstruction in fDetSwitchVector
111 // in order to keep availability of /aliDet/list command
112 G4String modName = module->GetName();
113 G4int modVersion = module->IsVersion();
115 // skip registering of the top volume
118 fDetSwitchVector.SwitchDetOn(modName, modVersion);
120 // all modules will be processed alltogether
121 AddModule(modName, modVersion, fDetSwitchVector.GetDetSwitch(modName)->GetType());
123 if (VerboseLevel() > 0) {
124 G4cout << "Created module construction for "
125 << modName << "v" << modVersion << "." << G4endl;
129 // do not process Config.C
130 // (it was processed when creating modules by gAlice)
131 SetProcessConfigToModules(false);
134 //_____________________________________________________________________________
135 void AliDetConstruction::CreateDetectors()
137 // Creates AliModules and their module constructions
138 // according to the fDetSwitchVector
141 // add top volume (AliBODY) construction first
142 AddModule("BODY", 0, kStructure);
144 // add modules constructions
145 for (G4int i=0; i<fDetSwitchVector.GetSize(); i++)
147 AliDetSwitch* detSwitch = fDetSwitchVector.GetDetSwitch(i);
148 G4String detName = detSwitch->GetDetName();
149 G4int version = detSwitch->GetSwitchedVersion();
150 AliModuleType type = detSwitch->GetType();
153 AddModule(detName, version, type);
157 //_____________________________________________________________________________
158 void AliDetConstruction::CheckDependence(const G4String& master,
159 const G4String& slave)
161 // Checks modules dependence.
162 // If master is switch on and slave off, the default version
163 // of slave is switched on and a warning is issued.
166 AliDetSwitch* masterSwitch = fDetSwitchVector.GetDetSwitch(master);
167 AliDetSwitch* slaveSwitch = fDetSwitchVector.GetDetSwitch(slave);
169 if ( masterSwitch->GetSwitchedVersion() > -1 &&
170 slaveSwitch->GetSwitchedVersion() < 0 ) {
172 slaveSwitch->SwitchOnDefault();
175 G4String text = "AliDetConstruction::CheckDetDependence: \n";
176 text = text + " Switched " + master + " requires " + slave + ".\n";
177 text = text + " The det switch for " + slave + " has been changed.";
178 AliGlobals::Warning(text);
182 //_____________________________________________________________________________
183 void AliDetConstruction::CheckDetDependencies()
185 // Checks modules dependencies.
188 CheckDependence("MUON", "DIPO");
189 CheckDependence("TOF", "FRAME");
190 CheckDependence("TRD", "FRAME");
191 CheckDependence("ZDC", "PIPE");
192 CheckDependence("ZDC", "ABSO");
193 CheckDependence("ZDC", "DIPO");
194 CheckDependence("ZDC", "SHIL");
199 //_____________________________________________________________________________
200 G4VPhysicalVolume* AliDetConstruction::Construct()
202 // Constructs geometry.
203 // This method is called by G4RunManager in initialization.
206 if (gAlice->Modules()->GetLast() < 0) {
207 // create geometry (including AliModules) according to
208 // the fDetSwitchVector
209 CheckDetDependencies();
213 // create geometry for AliModules
214 // that have been created and registered by gAlice
217 // construct modules geometry
220 return TG4GeometryServices::Instance()->GetWorld();
223 //_____________________________________________________________________________
224 void AliDetConstruction::GenerateXMLGeometry() const
226 // Generates XML geometry file from the top volume.
227 // The file name is set according the last switched detector
228 // registered in the det switch vector.
231 G4VPhysicalVolume* world = TG4GeometryServices::Instance()->GetWorld();
234 // according to last switched detector
236 G4String detVersion = "";
238 for (G4int i=fDetSwitchVector.GetSize()-1; i>=0; i--) {
239 version = fDetSwitchVector.GetDetSwitch(i)->GetSwitchedVersion();
241 detName = fDetSwitchVector.GetDetSwitch(i)->GetDetName();
242 AliGlobals::AppendNumberToString(detVersion,version);
247 = AliFiles::Instance()->GetXMLFilePath(detName, version);
249 // set top volume name
250 G4String topName = world->GetName() + "_comp";
254 TG4XMLGeometryGenerator xml;
255 xml.OpenFile(filePath);
257 // generate materials
259 // xml.GenerateMaterials(version, "today", "Generated from G4",
260 // "v4", world->GetLogicalVolume());
262 // generate volumes tree
263 xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4",
264 topName, world->GetLogicalVolume());
267 if (VerboseLevel() > 0) {
268 G4cout << "File " << detName << "v" << version << ".xml has been generated."