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));
52 fDetSwitchVector.UpdateMessenger();
54 // instantiate LVtree browser
55 AliLVTree::Instance();
58 //_____________________________________________________________________________
59 AliDetConstruction::AliDetConstruction(const AliDetConstruction& right)
60 : AliModulesComposition(right)
62 // AliModuleComposition is protected from copying
65 //_____________________________________________________________________________
66 AliDetConstruction::~AliDetConstruction()
68 // delete LVtree browser
69 delete AliLVTree::Instance();
74 //_____________________________________________________________________________
76 AliDetConstruction::operator=(const AliDetConstruction& right)
78 // check assignement to self
79 if (this == &right) return *this;
81 // base class assignement
82 // AliModuleComposition is protected from assigning
83 AliModulesComposition::operator=(right);
90 //_____________________________________________________________________________
91 void AliDetConstruction::BuildDetectors()
93 // Create module constructions for AliModules
94 // that have been created and registered by gAlice
97 TObjArray* pDetectors = gAlice->Detectors();
98 TIter next(pDetectors);
100 // the first AliModule is expected to be the top volume
101 AliModule *module = (AliModule*)next();
102 if (G4String(module->GetName()) != "BODY") {
103 G4String text = "AliDetConstruction::BuildDetectors():\n";
104 text = text + " Instead of BODY - the first module ";
105 text = text + module->GetName() + " has been found.";
106 AliGlobals::Exception(text);
108 AddModule("BODY", 0, kStructure);
111 while ((module = (AliModule*)next())) {
113 // register moduleConstruction in fDetSwitchVector
114 // in order to keep availability of /aliDet/list command
115 G4String modName = module->GetName();
116 G4int modVersion = module->IsVersion();
118 // skip registering of the top volume
121 fDetSwitchVector.SwitchDetOn(modName, modVersion);
123 // all modules will be processed alltogether
124 AddModule(modName, modVersion, fDetSwitchVector.GetDetSwitch(modName)->GetType());
126 if (VerboseLevel() > 0) {
127 G4cout << "Created module construction for "
128 << modName << "v" << modVersion << "." << G4endl;
132 // do not process Config.C
133 // (it was processed when creating modules by gAlice)
134 SetProcessConfigToModules(false);
137 //_____________________________________________________________________________
138 void AliDetConstruction::CreateDetectors()
140 // Creates AliModules and their module constructions
141 // according to the fDetSwitchVector
144 // add top volume (AliBODY) construction first
145 AddModule("BODY", 0, kStructure);
147 // add modules constructions
148 for (G4int i=0; i<fDetSwitchVector.GetSize(); i++)
150 AliDetSwitch* detSwitch = fDetSwitchVector.GetDetSwitch(i);
151 G4String detName = detSwitch->GetDetName();
152 G4int version = detSwitch->GetSwitchedVersion();
153 AliModuleType type = detSwitch->GetType();
156 AddModule(detName, version, type);
160 //_____________________________________________________________________________
161 void AliDetConstruction::CheckDependence(const G4String& master,
162 const G4String& slave)
164 // Checks modules dependence.
165 // If master is switch on and slave off, the default version
166 // of slave is switched on and a warning is issued.
169 AliDetSwitch* masterSwitch = fDetSwitchVector.GetDetSwitch(master);
170 AliDetSwitch* slaveSwitch = fDetSwitchVector.GetDetSwitch(slave);
172 if ( masterSwitch->GetSwitchedVersion() > -1 &&
173 slaveSwitch->GetSwitchedVersion() < 0 ) {
175 slaveSwitch->SwitchOnDefault();
178 G4String text = "AliDetConstruction::CheckDetDependence: \n";
179 text = text + " Switched " + master + " requires " + slave + ".\n";
180 text = text + " The det switch for " + slave + " has been changed.";
181 AliGlobals::Warning(text);
185 //_____________________________________________________________________________
186 void AliDetConstruction::CheckDetDependencies()
188 // Checks modules dependencies.
191 CheckDependence("MUON", "DIPO");
192 CheckDependence("TOF", "FRAME");
193 CheckDependence("TRD", "FRAME");
194 CheckDependence("ZDC", "PIPE");
195 CheckDependence("ZDC", "ABSO");
196 CheckDependence("ZDC", "DIPO");
197 CheckDependence("ZDC", "SHIL");
202 //_____________________________________________________________________________
203 G4VPhysicalVolume* AliDetConstruction::Construct()
205 // Constructs geometry.
206 // This method is called by G4RunManager in initialization.
209 if (gAlice->Modules()->GetLast() < 0) {
210 // create geometry (including AliModules) according to
211 // the fDetSwitchVector
212 CheckDetDependencies();
216 // create geometry for AliModules
217 // that have been created and registered by gAlice
220 // construct modules geometry
223 return TG4GeometryServices::Instance()->GetWorld();
226 //_____________________________________________________________________________
227 void AliDetConstruction::GenerateXMLGeometry() const
229 // Generates XML geometry file from the top volume.
230 // The file name is set according the last switched detector
231 // registered in the det switch vector.
234 G4VPhysicalVolume* world = TG4GeometryServices::Instance()->GetWorld();
237 // according to last switched detector
239 G4String detVersion = "";
241 for (G4int i=fDetSwitchVector.GetSize()-1; i>=0; i--) {
242 version = fDetSwitchVector.GetDetSwitch(i)->GetSwitchedVersion();
244 detName = fDetSwitchVector.GetDetSwitch(i)->GetDetName();
245 AliGlobals::AppendNumberToString(detVersion,version);
250 = AliFiles::Instance()->GetXMLFilePath(detName, version);
252 // set top volume name
253 G4String topName = world->GetName() + "_comp";
257 TG4XMLGeometryGenerator xml;
258 xml.OpenFile(filePath);
260 // generate materials
262 // xml.GenerateMaterials(version, "today", "Generated from G4",
263 // "v4", world->GetLogicalVolume());
265 // generate volumes tree
266 xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4",
267 topName, world->GetLogicalVolume());
270 if (VerboseLevel() > 0) {
271 G4cout << "File " << detName << "v" << version << ".xml has been generated."