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("ABSO", 1, 0, kStructure));
32 fDetSwitchVector.Add(new AliDetSwitch("DIPO", 3, 2, kStructure));
33 fDetSwitchVector.Add(new AliDetSwitch("FRAME", 3, 2, kStructure));
34 fDetSwitchVector.Add(new AliDetSwitch("HALL", 1, 0, kStructure));
35 //fDetSwitchVector.Add(new AliDetSwitch("MAG", 1, 0, kStructure));
36 fDetSwitchVector.Add(new AliDetSwitch("MAG", 1, 0, kStructure));
37 fDetSwitchVector.Add(new AliDetSwitch("PIPE", 5, 0, kStructure));
38 fDetSwitchVector.Add(new AliDetSwitch("SHIL", 1, 0, kStructure));
39 fDetSwitchVector.Add(new AliDetSwitch("CASTOR", 2, 1));
40 fDetSwitchVector.Add(new AliDetSwitch("FMD", 2, 1));
41 fDetSwitchVector.Add(new AliDetSwitch("ITS", 7, 5));
42 fDetSwitchVector.Add(new AliDetSwitch("MUON", 2, 1));
43 //fDetSwitchVector.Add(new AliDetSwitch("MUON", 2, 1));
44 fDetSwitchVector.Add(new AliDetSwitch("PHOS", 2, 1));
45 fDetSwitchVector.Add(new AliDetSwitch("PMD", 3, 1));
46 fDetSwitchVector.Add(new AliDetSwitch("RICH", 3, 1));
47 fDetSwitchVector.Add(new AliDetSwitch("START", 2, 1));
48 fDetSwitchVector.Add(new AliDetSwitch("TOF", 5, 2));
49 fDetSwitchVector.Add(new AliDetSwitch("TPC", 4, 2));
50 fDetSwitchVector.Add(new AliDetSwitch("TRD", 2, 1));
51 fDetSwitchVector.Add(new AliDetSwitch("ZDC", 3, 2));
53 // instantiate LVtree browser
54 AliLVTree::Instance();
57 //_____________________________________________________________________________
58 AliDetConstruction::AliDetConstruction(const AliDetConstruction& right)
59 : AliModulesComposition(right)
61 // AliModuleComposition is protected from copying
64 //_____________________________________________________________________________
65 AliDetConstruction::~AliDetConstruction()
67 // delete LVtree browser
68 delete AliLVTree::Instance();
73 //_____________________________________________________________________________
75 AliDetConstruction::operator=(const AliDetConstruction& right)
77 // check assignement to self
78 if (this == &right) return *this;
80 // base class assignement
81 // AliModuleComposition is protected from assigning
82 AliModulesComposition::operator=(right);
89 //_____________________________________________________________________________
90 void AliDetConstruction::BuildDetectors()
92 // Create module constructions for AliModules
93 // that have been created and registered by gAlice
96 TObjArray* pDetectors = gAlice->Detectors();
97 TIter next(pDetectors);
99 // the first AliModule is expected to be the top volume
100 AliModule *module = (AliModule*)next();
101 if (G4String(module->GetName()) != "BODY") {
102 G4String text = "AliDetConstruction::BuildDetectors():\n";
103 text = text + " Instead of BODY - the first module ";
104 text = text + module->GetName() + " has been found.";
105 AliGlobals::Exception(text);
107 AddModule("BODY", 0, kStructure);
110 while ((module = (AliModule*)next())) {
112 // register moduleConstruction in fDetSwitchVector
113 // in order to keep availability of /aliDet/list command
114 G4String modName = module->GetName();
115 G4int modVersion = module->IsVersion();
117 // skip registering of the top volume
120 fDetSwitchVector.SwitchDetOn(modName, modVersion);
122 // all modules will be processed alltogether
123 AddModule(modName, modVersion);
125 G4cout << "Created module construction for "
126 << 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::CheckDetDependencies()
160 // Checks modules dependencies.
161 // Dependent modules FRAME, TOF, TRD
162 // TOF always requires FRAMEv1
163 // TRD can be built with both (??)
167 // get switched versions of dependent modules
168 G4int verMUON = fDetSwitchVector.GetDetSwitch("MUON")->GetSwitchedVersion();
169 G4int verTOF = fDetSwitchVector.GetDetSwitch("TOF")->GetSwitchedVersion();
170 G4int verTRD = fDetSwitchVector.GetDetSwitch("TRD")->GetSwitchedVersion();
171 G4int verZDC = fDetSwitchVector.GetDetSwitch("ZDC")->GetSwitchedVersion();
172 G4int verFRAME = fDetSwitchVector.GetDetSwitch("FRAME")->GetSwitchedVersion();
174 // check dependencies
177 // MUON requires DIPO
178 if(fDetSwitchVector.GetDetSwitch("DIPO")->GetSwitchedVersion()<0) {
179 fDetSwitchVector.GetDetSwitch("DIPO")->SwitchOnDefault();
180 G4String text = "AliDetConstruction::CheckDetDependencies: \n";
181 text = text + " Switched MUON requires DIPO.\n";
182 text = text + " The det switch for DIPO has been changed.";
183 AliGlobals::Warning(text);
187 // TOF requires FRAME
189 fDetSwitchVector.GetDetSwitch("FRAME")->SwitchOnDefault();
190 G4String text = "AliDetConstruction::CheckDetDependencies: \n";
191 text = text + " Switched TOF requires FRAME.\n";
192 text = text + " The det switch for FRAME has been changed.";
193 AliGlobals::Warning(text);
197 // TRD requires FRAME
198 verFRAME = fDetSwitchVector.GetDetSwitch("FRAME")->GetSwitchedVersion();
200 fDetSwitchVector.GetDetSwitch("FRAME")->SwitchOnDefault();
201 G4String text = "AliDetConstruction::CheckDetDependencies: \n";
202 text = text + " Switched TRD requires FRAME.\n";
203 text = text + " The det switch for FRAME has been changed.";
204 AliGlobals::Warning(text);
208 // ZDC requires PIPE, ABSO, DIPO, SHIL
209 G4int verPIPE = fDetSwitchVector.GetDetSwitch("PIPE")->GetSwitchedVersion();
210 G4int verABSO = fDetSwitchVector.GetDetSwitch("ABSO")->GetSwitchedVersion();
211 G4int verDIPO = fDetSwitchVector.GetDetSwitch("DIPO")->GetSwitchedVersion();
212 G4int verSHIL = fDetSwitchVector.GetDetSwitch("SHIL")->GetSwitchedVersion();
213 if ( verPIPE != 1 || verABSO !=0 || verDIPO == -1 || verSHIL == -1) {
214 G4String text = "AliDetConstruction::CheckDetDependencies: \n";
215 text = text + " Switched ZDC requires PIPE, ABSO, DIPO and SHIL.\n";
217 fDetSwitchVector.GetDetSwitch("PIPE")->SwitchOnDefault();
218 text = text + " The det switch for PIPE has been changed.\n";
221 fDetSwitchVector.GetDetSwitch("ABSO")->SwitchOnDefault();
222 text = text + " The det switch for ABSO has been changed.\n";
225 fDetSwitchVector.GetDetSwitch("DIPO")->SwitchOnDefault();
226 text = text + " The det switch for DIPO has been changed.\n";
229 fDetSwitchVector.GetDetSwitch("SHIL")->SwitchOnDefault();
230 text = text + " The det switch for SHIL has been changed.";
232 AliGlobals::Warning(text);
239 //_____________________________________________________________________________
240 G4VPhysicalVolume* AliDetConstruction::Construct()
242 // Constructs geometry.
243 // This method is called by G4RunManager in initialization.
246 if (gAlice->Modules()->GetLast() < 0) {
247 // create geometry (including AliModules) according to
248 // the fDetSwitchVector
249 CheckDetDependencies();
253 // create geometry for AliModules
254 // that have been created and registered by gAlice
257 // construct modules geometry
260 return TG4GeometryServices::Instance()->GetWorld();
263 //_____________________________________________________________________________
264 void AliDetConstruction::GenerateXMLGeometry() const
266 // Generates XML geometry file from the top volume.
267 // The file name is set according the last switched detector
268 // registered in the det switch vector.
271 G4VPhysicalVolume* world = TG4GeometryServices::Instance()->GetWorld();
274 // according to last switched detector
276 G4String detVersion = "";
278 for (G4int i=fDetSwitchVector.GetSize()-1; i>=0; i--) {
279 version = fDetSwitchVector.GetDetSwitch(i)->GetSwitchedVersion();
281 detName = fDetSwitchVector.GetDetSwitch(i)->GetDetName();
282 AliGlobals::AppendNumberToString(detVersion,version);
287 = AliFiles::Instance()->GetXMLFilePath(detName, version);
289 // set top volume name
290 G4String topName = world->GetName() + "_comp";
294 TG4XMLGeometryGenerator xml;
295 xml.OpenFile(filePath);
297 // generate materials
299 // xml.GenerateMaterials(version, "today", "Generated from G4",
300 // "v4", world->GetLogicalVolume());
302 // generate volumes tree
303 xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4",
304 topName, world->GetLogicalVolume());
308 G4cout << "File " << detName << "v" << version << ".xml has been generated."