4 // Author: I. Hrivnacova
6 // Class AliModulesComposition
7 // ---------------------------
8 // See the class description in the header file.
10 #include "AliModulesComposition.h"
11 #include "AliSingleModuleConstruction.h"
12 #include "AliMoreModulesConstruction.h"
13 #include "AliDetSwitch.h"
14 #include "AliMagneticField.h"
15 #include "AliGlobals.h"
18 #include "TG4XMLGeometryGenerator.h"
19 #include "TG4GeometryManager.h"
21 #include <G4Material.hh>
22 #include <G4VPhysicalVolume.hh>
24 //_____________________________________________________________________________
25 AliModulesComposition::AliModulesComposition()
26 : fReadGeometry(false),
27 fWriteGeometry(false),
32 fMoreModulesConstruction = new AliMoreModulesConstruction();
35 //_____________________________________________________________________________
36 AliModulesComposition::AliModulesComposition(const AliModulesComposition& right)
40 AliGlobals::Exception("AliModulesComposition is protected from copying.");
43 //_____________________________________________________________________________
44 AliModulesComposition::~AliModulesComposition() {
46 delete fMoreModulesConstruction;
47 delete fMagneticField;
49 // destroy det switch vector
51 for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
54 // destroy det construction vector
55 SingleModuleIterator itm;
56 for (itm = fModuleConstructionVector.begin();
57 itm != fModuleConstructionVector.end(); it++)
63 //_____________________________________________________________________________
64 AliModulesComposition&
65 AliModulesComposition::operator=(const AliModulesComposition& right)
67 // check assignement to self
68 if (this == &right) return *this;
70 AliGlobals::Exception("AliModulesComposition is protected from assigning.");
77 //_____________________________________________________________________________
78 void AliModulesComposition::AddDetSwitch(AliDetSwitch* detSwitch)
80 // Adds detSwitch to the detSwitch vector.
83 fDetSwitchVector.push_back(detSwitch);
84 fMessenger.SetCandidates();
87 //_____________________________________________________________________________
88 void AliModulesComposition::AddSingleModuleConstruction(
89 const G4String& name, G4int version,
90 AliModuleType moduleType)
92 // Adds SingleModuleConstruction.
95 fModuleConstructionVector
96 .push_back(new AliSingleModuleConstruction(name, version, moduleType));
99 //_____________________________________________________________________________
100 void AliModulesComposition::AddMoreModuleConstruction(
101 const G4String& name, G4int version,
102 AliModuleType moduleType)
104 // Adds module to MoreModulesConstruction (construction of dependent
108 fMoreModulesConstruction->AddModule(name, version, moduleType);
111 //_____________________________________________________________________________
112 void AliModulesComposition::ConstructModules()
114 // Construct geometry of all modules (both standalone and dependent.)
117 // set common options
118 SetReadGeometryToModules(fReadGeometry);
119 SetWriteGeometryToModules(fWriteGeometry);
121 // configure single modules
122 SingleModuleIterator it;
123 for (it = fModuleConstructionVector.begin();
124 it != fModuleConstructionVector.end(); it++) {
126 (*it)->Configure(*AliFiles::Instance());
127 cout << "Module " << (*it)->GetDetName() << " configured." << endl;
130 // configure dependent modules
131 if (fMoreModulesConstruction->GetNofModules() > 0)
132 fMoreModulesConstruction->Configure(*AliFiles::Instance());
134 // construct single modules
135 for (it = fModuleConstructionVector.begin();
136 it != fModuleConstructionVector.end(); it++) {
138 G4cout << "Module " << (*it)->GetDetName()
139 << " will be constructed now." << G4endl;
143 // construct dependent modules
144 if (fMoreModulesConstruction->GetNofModules() > 0) {
145 G4cout << "Dependent modules will be constructed now." << G4endl;
146 fMoreModulesConstruction->Construct();
150 //_____________________________________________________________________________
151 AliDetSwitch* AliModulesComposition::GetDetSwitch(
152 const G4String& moduleName) const
154 // Returns the detector switch with given detector name.
157 DetSwitchConstIterator it;
158 for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
159 if ((*it)->GetDetName() == moduleName) return *it;
161 G4String text = "AliModulesComposition::GetDetSwitch:\n";
162 text = text + "Wrong detector name for " + moduleName;
163 AliGlobals::Exception(text);
167 //_____________________________________________________________________________
168 void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
170 // Sets readGeometry control to all modules.
173 // single module constructions
174 SingleModuleIterator it;
175 for (it = fModuleConstructionVector.begin();
176 it != fModuleConstructionVector.end(); it++)
177 (*it)->SetReadGeometry(readGeometry);
179 // more modules construction
180 for (G4int i=0; i<fMoreModulesConstruction->GetNofModules(); i++)
181 fMoreModulesConstruction
182 ->GetModuleConstruction(i)->SetReadGeometry(readGeometry);
185 //_____________________________________________________________________________
186 void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
188 // Sets writeGeometry control to all modules.
191 // single module constructions
192 SingleModuleIterator it;
193 for (it = fModuleConstructionVector.begin();
194 it != fModuleConstructionVector.end(); it++)
195 (*it)->SetWriteGeometry(writeGeometry);
197 // more modules construction
198 for (G4int i=0; i<fMoreModulesConstruction->GetNofModules(); i++)
199 fMoreModulesConstruction
200 ->GetModuleConstruction(i)->SetWriteGeometry(writeGeometry);
203 //_____________________________________________________________________________
204 void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
206 // Sets processConfig control to all modules.
209 // single module constructions
210 SingleModuleIterator it;
211 for (it = fModuleConstructionVector.begin();
212 it != fModuleConstructionVector.end(); it++)
213 (*it)->SetProcessConfig(processConfig);
215 // more modules construction
216 for (G4int i=0; i<fMoreModulesConstruction->GetNofModules(); i++)
217 fMoreModulesConstruction
218 ->GetModuleConstruction(i)->SetProcessConfig(processConfig);
223 //_____________________________________________________________________________
224 void AliModulesComposition::SwitchDetOn(const G4String& moduleNameVer)
226 // Switchs on module specified by name and version.
229 DetSwitchIterator it;
231 if (moduleNameVer == "ALL") {
232 for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
233 (*it)->SwitchOnDefault();
235 else if (moduleNameVer == "NONE") {
236 for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
240 // get version number
241 G4int len = moduleNameVer.length();
242 G4String moduleName = moduleNameVer.substr(0, len-1);
243 G4String version = moduleNameVer.substr(len-1, 1);
244 G4int iVersion = AliGlobals::StringToInt(version);
247 // in case the version number is not provided
248 // the default one is set
249 SwitchDetOnDefault(moduleNameVer);
252 SwitchDetOn(moduleName, iVersion);
256 //_____________________________________________________________________________
257 void AliModulesComposition::SwitchDetOn(const G4String& moduleName,
260 // Switchs on module specified by name and version.
263 GetDetSwitch(moduleName)->SwitchOn(version);
266 //_____________________________________________________________________________
267 void AliModulesComposition::SwitchDetOnDefault(const G4String& moduleName)
269 // Switchs on module specified by name with default version.
272 GetDetSwitch(moduleName)->SwitchOnDefault();
275 //_____________________________________________________________________________
276 void AliModulesComposition::SwitchDetOff(const G4String& moduleName)
278 // Switchs off module specified by name.
281 if (moduleName == "ALL") {
282 DetSwitchIterator it;
283 for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
287 GetDetSwitch(moduleName)->SwitchOff();
290 //_____________________________________________________________________________
291 void AliModulesComposition::PrintSwitchedDets() const
293 // Lists switched detectors.
296 G4String svList = GetSwitchedDetsList();
298 G4cout << "Switched Alice detectors: " << G4endl;
299 G4cout << "--------------------------" << G4endl;
300 G4cout << svList << G4endl;
303 //_____________________________________________________________________________
304 void AliModulesComposition::PrintAvailableDets() const
306 // Lists available detectors.
309 G4String avList = GetAvailableDetsList();
311 G4cout << "Available Alice detectors: " << G4endl;
312 G4cout << "---------------------------" << G4endl;
313 G4cout << avList << G4endl;
316 //_____________________________________________________________________________
317 void AliModulesComposition::PrintMaterials() const
319 // Prints all materials.
322 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
326 //_____________________________________________________________________________
327 void AliModulesComposition::GenerateXMLGeometry() const
329 // Generates XML geometry file from the top volume.
330 // The file name is set according the last switched detector
331 // registered in the det switch vector.
334 G4VPhysicalVolume* world = AliSingleModuleConstruction::GetWorld();
337 // according to last switched detector
339 G4String detVersion = "";
341 for (G4int i=fDetSwitchVector.size()-1; i>=0; i--) {
342 version = fDetSwitchVector[i]->GetSwitchedVersion();
344 detName = fDetSwitchVector[i]->GetDetName();
345 AliGlobals::AppendNumberToString(detVersion,version);
350 = AliFiles::Instance()->GetXMLFilePath(detName, version);
352 // set top volume name
353 G4String topName = world->GetName() + "_comp";
357 TG4XMLGeometryGenerator xml;
358 xml.OpenFile(filePath);
360 // generate materials
361 // not yet implemented
362 // xml.GenerateMaterials(version, "today", "Generated from G4",
363 // "v4", world->GetLogicalVolume());
365 // generate volumes tree
366 xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4",
367 topName, world->GetLogicalVolume());
371 G4cout << "File " << detName << "v" << version << ".xml has been generated."
375 //_____________________________________________________________________________
376 G4String AliModulesComposition::GetSwitchedDetsList() const
378 // Returns list of switched detectors.
381 G4String svList = "";
382 G4int nofSwitchedDets = 0;
383 DetSwitchConstIterator it;
385 for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) {
386 G4int iVersion = (*it)->GetSwitchedVersion();
389 G4String moduleNameVer = (*it)->GetDetName();
390 AliGlobals::AppendNumberToString(moduleNameVer, iVersion);
391 svList += moduleNameVer;
396 if (nofSwitchedDets == fDetSwitchVector.size()) svList = "ALL: " + svList;
397 if (nofSwitchedDets == 0) svList = "NONE";
402 //_____________________________________________________________________________
403 G4String AliModulesComposition::GetAvailableDetsList() const
405 // Returns list of available detectors.
408 G4String svList = "";
409 DetSwitchConstIterator it;
411 for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
412 for (G4int iv=0; iv<(*it)->GetNofVersions(); iv++) {
413 G4String moduleNameVer = (*it)->GetDetName();
414 AliGlobals::AppendNumberToString(moduleNameVer, iv);
415 svList += moduleNameVer;
422 //_____________________________________________________________________________
423 G4String AliModulesComposition::GetAvailableDetsListWithCommas() const
425 // Returns list of available detectors with commas.
428 G4String svList = "";
430 DetSwitchConstIterator it;
432 for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
433 for (G4int iv=0; iv<(*it)->GetNofVersions(); iv++) {
434 G4String moduleNameVer = (*it)->GetDetName();
435 AliGlobals::AppendNumberToString(moduleNameVer, iv);
436 svList += moduleNameVer;
437 if (iv < (*it)->GetNofVersions()-1) svList += "/";
438 else if (id++ < fDetSwitchVector.size()-1) svList += ", ";
444 //_____________________________________________________________________________
445 G4String AliModulesComposition::GetDetNamesList() const
447 // Returns list of detector names.
450 G4String svList = "";
451 DetSwitchConstIterator it;
453 for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) {
454 svList += (*it)->GetDetName();
461 //_____________________________________________________________________________
462 G4String AliModulesComposition::GetDetNamesListWithCommas() const
464 // Returns list of detector names with commas.
467 G4String svList = "";
469 DetSwitchConstIterator it;
471 for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) {
472 svList += (*it)->GetDetName();
473 if (id++ < fDetSwitchVector.size()-1) svList += ", ";
479 //_____________________________________________________________________________
480 void AliModulesComposition::SetMagField(G4double fieldValue)
482 // Sets uniform magnetic field to specified value.
485 // create fields if it does not exist
486 if (!fMagneticField) fMagneticField = new AliMagneticField();
489 fMagneticField->SetFieldValue(fieldValue);