4 // See the class description in the header file.
6 #include "AliModulesComposition.h"
7 #include "AliModulesCompositionMessenger.h"
8 #include "AliSingleModuleConstruction.h"
9 #include "AliMoreModulesConstruction.h"
10 #include "AliDetSwitch.h"
11 #include "AliMagneticField.h"
12 #include "AliGlobals.h"
14 #include "TG4GeometryManager.h"
15 #include "TG4XMLGeometryGenerator.h"
17 #include <G4Material.hh>
18 #include <G4VPhysicalVolume.hh>
20 AliModulesComposition::AliModulesComposition()
21 : fAllLVSensitive(false),
22 fForceAllLVSensitive(true),
24 fWriteGeometry(false),
28 fMoreModulesConstruction = new AliMoreModulesConstruction();
29 fMessenger = new AliModulesCompositionMessenger(this);
32 AliModulesComposition::AliModulesComposition(const AliModulesComposition& right)
35 AliGlobals::Exception("AliModulesComposition is protected from copying.");
38 AliModulesComposition::~AliModulesComposition() {
40 delete fMoreModulesConstruction;
41 delete fMagneticField;
44 // destroy det switch vector
45 fDetSwitchVector.clearAndDestroy();
47 // destroy det construction vector
48 fModuleConstructionVector.clearAndDestroy();
53 AliModulesComposition&
54 AliModulesComposition::operator=(const AliModulesComposition& right)
56 // check assignement to self
57 if (this == &right) return *this;
59 AliGlobals::Exception("AliModulesComposition is protected from assigning.");
66 void AliModulesComposition::AddDetSwitch(AliDetSwitch* detSwitch)
68 // Adds detSwitch to the detSwitch vector.
71 fDetSwitchVector.insert(detSwitch);
72 fMessenger->SetCandidates();
75 void AliModulesComposition::AddSingleModuleConstruction(G4String moduleName,
76 G4int version, AliModuleType moduleType)
78 // Adds SingleModuleConstruction.
81 AliSingleModuleConstruction* moduleConstruction
82 = new AliSingleModuleConstruction(moduleName, version, moduleType);
83 fModuleConstructionVector.insert(moduleConstruction);
86 void AliModulesComposition::AddMoreModuleConstruction(G4String moduleName,
87 G4int version, AliModuleType moduleType)
89 // Adds module to MoreModulesConstruction (construction of dependent
93 fMoreModulesConstruction->AddModule(moduleName, version, moduleType);
96 void AliModulesComposition::ConstructModules()
98 // Construct geometry of all modules (both standalone and dependent.)
101 // set common options
102 SetReadGeometryToModules(fReadGeometry);
103 SetWriteGeometryToModules(fWriteGeometry);
104 SetAllLVSensitiveToModules(fAllLVSensitive);
105 // common setAllLVSensitive is overridden by Config.in
108 // one module constructions
109 G4int nofDets = fModuleConstructionVector.entries();
110 for (G4int i=0; i<nofDets; i++) {
111 fModuleConstructionVector[i]->Configure();
113 if (fForceAllLVSensitive)
114 SetAllLVSensitiveToModules(fForceAllLVSensitive);
115 // override the setAllLVSensitive by Config.in macro
118 for (G4int i=0; i<nofDets; i++) {
119 G4cout << "Module " << fModuleConstructionVector[i]->GetDetName()
120 << " will be constructed now." << G4endl;
121 fModuleConstructionVector[i]->Construct();
124 // more modules construction
125 G4int nofModules = fMoreModulesConstruction->GetNofModules();
127 fMoreModulesConstruction->Configure();
128 if (fForceAllLVSensitive)
129 SetAllLVSensitiveToModules(fForceAllLVSensitive);
130 // override the setAllLVSensitive by Config.in macro
133 G4cout << "Dependent modules will be constructed now." << G4endl;
134 fMoreModulesConstruction->Construct();
137 // fill medium Id vector
138 TG4GeometryManager::Instance()->FillMediumIdVector();
139 // this step can be done only after the sensitive
140 // detectors have been created
143 void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
145 // Sets readGeometry control to all modules.
148 // single module constructions
149 G4int nofDets = fModuleConstructionVector.entries();
151 for (i=0; i<nofDets; i++)
152 fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
154 // more modules construction
155 nofDets = fMoreModulesConstruction->GetNofModules();
156 for (i=0; i<nofDets; i++) {
157 AliSingleModuleConstruction* moduleConstruction
158 = fMoreModulesConstruction->GetModuleConstruction(i);
159 moduleConstruction->SetReadGeometry(readGeometry);
163 void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
165 // Sets writeGeometry control to all modules.
168 // single module constructions
169 G4int nofDets = fModuleConstructionVector.entries();
171 for (i=0; i<nofDets; i++)
172 fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
174 // more modules construction
175 nofDets = fMoreModulesConstruction->GetNofModules();
176 for (i=0; i<nofDets; i++) {
177 AliSingleModuleConstruction* moduleConstruction
178 = fMoreModulesConstruction->GetModuleConstruction(i);
179 moduleConstruction->SetWriteGeometry(writeGeometry);
183 void AliModulesComposition::SetAllLVSensitiveToModules(G4bool allSensitive)
185 // Sets setAllSensitive control to all modules.
188 // single module constructions
189 G4int nofDets = fModuleConstructionVector.entries();
191 for (i=0; i<nofDets; i++)
192 fModuleConstructionVector[i]->SetAllLVSensitive(allSensitive);
194 // more modules construction
195 nofDets = fMoreModulesConstruction->GetNofModules();
196 for (i=0; i<nofDets; i++) {
197 AliSingleModuleConstruction* moduleConstruction
198 = fMoreModulesConstruction->GetModuleConstruction(i);
199 moduleConstruction->SetAllLVSensitive(allSensitive);
203 void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
205 // Sets processConfig control to all modules.
208 // single module constructions
209 G4int nofDets = fModuleConstructionVector.entries();
211 for (i=0; i<nofDets; i++)
212 fModuleConstructionVector[i]->SetProcessConfig(processConfig);
214 // more modules construction
215 nofDets = fMoreModulesConstruction->GetNofModules();
216 for (i=0; i<nofDets; i++) {
217 AliSingleModuleConstruction* moduleConstruction
218 = fMoreModulesConstruction->GetModuleConstruction(i);
219 moduleConstruction->SetProcessConfig(processConfig);
225 void AliModulesComposition::SwitchDetOn(G4String moduleNameVer)
227 // Switchs on module specified by name and version.
230 G4int nofDets = fDetSwitchVector.entries();
231 if (moduleNameVer == "ALL") {
232 for (G4int id=0; id<nofDets; id++) {
233 G4int defaultVersion = fDetSwitchVector[id]->GetDefaultVersion();
234 fDetSwitchVector[id]->SwitchOn(defaultVersion);
237 else if (moduleNameVer == "NONE") {
238 for (G4int id=0; id<nofDets; id++)
239 fDetSwitchVector[id]->SwitchOff();
242 // get version number
243 G4int len = moduleNameVer.length();
244 G4String moduleName = moduleNameVer(0, len-1);
245 G4String version = moduleNameVer(len-1, 1);
246 G4int iVersion = AliGlobals::StringToInt(version);
249 // in case the version number is not provided
250 // the default one is set
251 SwitchDetOnDefault(moduleNameVer);
254 SwitchDetOn(moduleName, iVersion);
258 void AliModulesComposition::SwitchDetOn(G4String moduleName, G4int version)
260 // Switchs on module specified by name and version.
263 G4int nofDets = fDetSwitchVector.entries();
264 for (G4int id=0; id<nofDets; id++) {
265 G4String iDetName = fDetSwitchVector[id]->GetDetName();
266 if (iDetName == moduleName) {
267 fDetSwitchVector[id]->SwitchOn(version);
271 AliGlobals::Exception(
272 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
275 void AliModulesComposition::SwitchDetOnDefault(G4String moduleName)
277 // Switchs on module specified by name with default version.
280 G4int nofDets = fDetSwitchVector.entries();
281 for (G4int id=0; id<nofDets; id++) {
282 G4String iDetName = fDetSwitchVector[id]->GetDetName();
283 if (iDetName == moduleName) {
284 fDetSwitchVector[id]->SwitchOnDefault();
288 AliGlobals::Exception(
289 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
292 void AliModulesComposition::SwitchDetOff(G4String moduleName)
294 // Switchs off module specified by name.
297 G4int nofDets = fDetSwitchVector.entries();
298 if (moduleName == "ALL") {
299 for (G4int id=0; id<nofDets; id++)
300 fDetSwitchVector[id]->SwitchOff();
303 for (G4int id=0; id<nofDets; id++) {
304 G4String iDetName = fDetSwitchVector[id]->GetDetName();
305 if (iDetName == moduleName) {
306 fDetSwitchVector[id]->SwitchOff();
311 AliGlobals::Exception(
312 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
315 void AliModulesComposition::PrintSwitchedDets() const
317 // Lists switched detectors.
320 G4String svList = GetSwitchedDetsList();
322 G4cout << "Switched Alice detectors: " << G4endl;
323 G4cout << "--------------------------" << G4endl;
324 G4cout << svList << G4endl;
327 void AliModulesComposition::PrintAvailableDets() const
329 // Lists available detectors.
332 G4String avList = GetAvailableDetsList();
334 G4cout << "Available Alice detectors: " << G4endl;
335 G4cout << "---------------------------" << G4endl;
336 G4cout << avList << G4endl;
339 void AliModulesComposition::PrintMaterials() const
341 // Prints all materials.
344 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
348 void AliModulesComposition::GenerateXMLGeometry() const
350 // Generates XML geometry file from the top volume.
351 // The file name is set according the last switched detector
352 // registered in the det switch vector.
355 G4VPhysicalVolume* world = AliSingleModuleConstruction::GetWorld();
359 G4String version = "v";
360 G4String filePath= getenv("AG4_INSTALL");
361 filePath = filePath + "/xml/";
362 for (G4int i=fDetSwitchVector.entries()-1; i>=0; i--) {
363 G4int versionNumber = fDetSwitchVector[i]->GetSwitchedVersion();
364 if (versionNumber > -1) {
365 detName = fDetSwitchVector[i]->GetDetName();
366 AliGlobals::AppendNumberToString(version, versionNumber);
367 filePath = filePath + detName + version + ".xml";
372 // set top volume name
373 G4String topName = world->GetName() + "_comp";
377 TG4XMLGeometryGenerator xml;
378 xml.OpenFile(filePath);
380 // generate materials
381 // not yet implemented
382 // xml.GenerateMaterials(version, "today", "Generated from G4",
383 // "v4", world->GetLogicalVolume());
385 // generate volumes tree
386 xml.GenerateSection(detName, version, "today", "Generated from Geant4",
387 topName, world->GetLogicalVolume());
391 G4cout << "File " << detName << version << ".xml has been generated."
396 G4String AliModulesComposition::GetSwitchedDetsList() const
398 // Returns list of switched detectors.
401 G4String svList = "";
403 G4int nofDets = fDetSwitchVector.entries();
404 G4int nofSwitchedDets = 0;
405 for (G4int id=0; id<nofDets; id++) {
406 G4int iVersion = fDetSwitchVector[id]->GetSwitchedVersion();
409 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
410 AliGlobals::AppendNumberToString(moduleNameVer, iVersion);
411 svList += moduleNameVer;
416 if (nofSwitchedDets == nofDets) svList = "ALL: " + svList;
417 if (nofSwitchedDets == 0) svList = "NONE";
422 const G4RWTPtrOrderedVector<AliDetSwitch>&
423 AliModulesComposition::GetDetSwitchVector() const
425 // Returns detSwitch vector.
428 //const AliDetSwitchVector& vector = fDetSwitchVector;
429 const G4RWTPtrOrderedVector<AliDetSwitch>& vector = fDetSwitchVector;
433 G4String AliModulesComposition::GetAvailableDetsList() const
435 // Returns list of available detectors.
438 G4String svList = "";
440 G4int nofDets = fDetSwitchVector.entries();
441 for (G4int id=0; id<nofDets; id++) {
442 G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
443 for (G4int iv=0; iv<nofVersions; iv++) {
444 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
445 AliGlobals::AppendNumberToString(moduleNameVer, iv);
446 svList += moduleNameVer;
454 G4String AliModulesComposition::GetAvailableDetsListWithCommas() const
456 // Returns list of available detectors with commas.
459 G4String svList = "";
461 G4int nofDets = fDetSwitchVector.entries();
462 for (G4int id=0; id<nofDets; id++) {
463 G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
464 for (G4int iv=0; iv<nofVersions; iv++) {
465 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
466 AliGlobals::AppendNumberToString(moduleNameVer, iv);
467 svList += moduleNameVer;
468 if (iv<nofVersions-1) svList += "/";
469 else if (id < nofDets-1) svList += ", ";
476 G4String AliModulesComposition::GetDetNamesList() const
478 // Returns list of detector names.
481 G4String svList = "";
483 G4int nofDets = fDetSwitchVector.entries();
484 for (G4int id=0; id<nofDets; id++) {
485 svList += fDetSwitchVector[id]->GetDetName();
492 G4String AliModulesComposition::GetDetNamesListWithCommas() const
494 // Returns list of detector names with commas.
497 G4String svList = "";
499 G4int nofDets = fDetSwitchVector.entries();
500 for (G4int id=0; id<nofDets; id++) {
501 svList += fDetSwitchVector[id]->GetDetName();
502 if (id < nofDets-1) svList += ", ";
508 void AliModulesComposition::SetMagField(G4double fieldValue)
510 // Sets uniform magnetic field to specified value.
513 // create fields if it does not exist
514 if (!fMagneticField) fMagneticField = new AliMagneticField();
517 fMagneticField->SetFieldValue(fieldValue);