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);
123 G4cout << "Created module construction for "
124 << modName << "v" << modVersion << "." << G4endl;
127 // do not process Config.C
128 // (it was processed when creating modules by gAlice)
129 SetProcessConfigToModules(false);
132 //_____________________________________________________________________________
133 void AliDetConstruction::CreateDetectors()
135 // Creates AliModules and their module constructions
136 // according to the fDetSwitchVector
139 // add top volume (AliBODY) construction first
140 AddModule("BODY", 0, kStructure);
142 // add modules constructions
143 for (G4int i=0; i<fDetSwitchVector.GetSize(); i++)
145 AliDetSwitch* detSwitch = fDetSwitchVector.GetDetSwitch(i);
146 G4String detName = detSwitch->GetDetName();
147 G4int version = detSwitch->GetSwitchedVersion();
148 AliModuleType type = detSwitch->GetType();
151 AddModule(detName, version, type);
155 //_____________________________________________________________________________
156 void AliDetConstruction::CheckDependence(const G4String& master,
157 const G4String& slave)
159 // Checks modules dependence.
160 // If master is switch on and slave off, the default version
161 // of slave is switched on and a warning is issued.
164 AliDetSwitch* masterSwitch = fDetSwitchVector.GetDetSwitch(master);
165 AliDetSwitch* slaveSwitch = fDetSwitchVector.GetDetSwitch(slave);
167 if ( masterSwitch->GetSwitchedVersion() > -1 &&
168 slaveSwitch->GetSwitchedVersion() < 0 ) {
170 slaveSwitch->SwitchOnDefault();
173 G4String text = "AliDetConstruction::CheckDetDependence: \n";
174 text = text + " Switched " + master + " requires " + slave + ".\n";
175 text = text + " The det switch for " + slave + " has been changed.";
176 AliGlobals::Warning(text);
180 //_____________________________________________________________________________
181 void AliDetConstruction::CheckDetDependencies()
183 // Checks modules dependencies.
186 CheckDependence("MUON", "DIPO");
187 CheckDependence("TOF", "FRAME");
188 CheckDependence("TRD", "FRAME");
189 CheckDependence("ZDC", "PIPE");
190 CheckDependence("ZDC", "ABSO");
191 CheckDependence("ZDC", "DIPO");
192 CheckDependence("ZDC", "SHIL");
197 //_____________________________________________________________________________
198 G4VPhysicalVolume* AliDetConstruction::Construct()
200 // Constructs geometry.
201 // This method is called by G4RunManager in initialization.
204 if (gAlice->Modules()->GetLast() < 0) {
205 // create geometry (including AliModules) according to
206 // the fDetSwitchVector
207 CheckDetDependencies();
211 // create geometry for AliModules
212 // that have been created and registered by gAlice
215 // construct modules geometry
218 return TG4GeometryServices::Instance()->GetWorld();
221 //_____________________________________________________________________________
222 void AliDetConstruction::GenerateXMLGeometry() const
224 // Generates XML geometry file from the top volume.
225 // The file name is set according the last switched detector
226 // registered in the det switch vector.
229 G4VPhysicalVolume* world = TG4GeometryServices::Instance()->GetWorld();
232 // according to last switched detector
234 G4String detVersion = "";
236 for (G4int i=fDetSwitchVector.GetSize()-1; i>=0; i--) {
237 version = fDetSwitchVector.GetDetSwitch(i)->GetSwitchedVersion();
239 detName = fDetSwitchVector.GetDetSwitch(i)->GetDetName();
240 AliGlobals::AppendNumberToString(detVersion,version);
245 = AliFiles::Instance()->GetXMLFilePath(detName, version);
247 // set top volume name
248 G4String topName = world->GetName() + "_comp";
252 TG4XMLGeometryGenerator xml;
253 xml.OpenFile(filePath);
255 // generate materials
257 // xml.GenerateMaterials(version, "today", "Generated from G4",
258 // "v4", world->GetLogicalVolume());
260 // generate volumes tree
261 xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4",
262 topName, world->GetLogicalVolume());
266 G4cout << "File " << detName << "v" << version << ".xml has been generated."