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"
15 #include "TG4GeometryManager.h"
16 #include "TG4XMLGeometryGenerator.h"
18 #include <G4Material.hh>
19 #include <G4VPhysicalVolume.hh>
21 AliModulesComposition::AliModulesComposition()
22 : fAllLVSensitive(false),
23 fForceAllLVSensitive(true),
25 fWriteGeometry(false),
29 fMoreModulesConstruction = new AliMoreModulesConstruction();
30 fMessenger = new AliModulesCompositionMessenger(this);
33 AliModulesComposition::AliModulesComposition(const AliModulesComposition& right)
36 AliGlobals::Exception("AliModulesComposition is protected from copying.");
39 AliModulesComposition::~AliModulesComposition() {
41 delete fMoreModulesConstruction;
42 delete fMagneticField;
45 // destroy det switch vector
46 fDetSwitchVector.clearAndDestroy();
48 // destroy det construction vector
49 fModuleConstructionVector.clearAndDestroy();
54 AliModulesComposition&
55 AliModulesComposition::operator=(const AliModulesComposition& right)
57 // check assignement to self
58 if (this == &right) return *this;
60 AliGlobals::Exception("AliModulesComposition is protected from assigning.");
67 void AliModulesComposition::AddDetSwitch(AliDetSwitch* detSwitch)
69 // Adds detSwitch to the detSwitch vector.
72 fDetSwitchVector.insert(detSwitch);
73 fMessenger->SetCandidates();
76 void AliModulesComposition::AddSingleModuleConstruction(G4String moduleName,
77 G4int version, AliModuleType moduleType)
79 // Adds SingleModuleConstruction.
82 AliSingleModuleConstruction* moduleConstruction
83 = new AliSingleModuleConstruction(moduleName, version, moduleType);
84 fModuleConstructionVector.insert(moduleConstruction);
87 void AliModulesComposition::AddMoreModuleConstruction(G4String moduleName,
88 G4int version, AliModuleType moduleType)
90 // Adds module to MoreModulesConstruction (construction of dependent
94 fMoreModulesConstruction->AddModule(moduleName, version, moduleType);
97 void AliModulesComposition::ConstructModules()
99 // Construct geometry of all modules (both standalone and dependent.)
102 // set common options
103 SetReadGeometryToModules(fReadGeometry);
104 SetWriteGeometryToModules(fWriteGeometry);
105 SetAllLVSensitiveToModules(fAllLVSensitive);
106 // common setAllLVSensitive is overridden by Config.in
109 // one module constructions
110 G4int nofDets = fModuleConstructionVector.entries();
112 for (i=0; i<nofDets; i++) {
113 fModuleConstructionVector[i]->Configure(*AliFiles::Instance());
115 if (fForceAllLVSensitive)
116 SetAllLVSensitiveToModules(fForceAllLVSensitive);
117 // override the setAllLVSensitive by Config.in macro
120 for (i=0; i<nofDets; i++) {
121 G4cout << "Module " << fModuleConstructionVector[i]->GetDetName()
122 << " will be constructed now." << G4endl;
123 fModuleConstructionVector[i]->Construct();
126 // more modules construction
127 G4int nofModules = fMoreModulesConstruction->GetNofModules();
129 fMoreModulesConstruction->Configure(*AliFiles::Instance());
130 if (fForceAllLVSensitive)
131 SetAllLVSensitiveToModules(fForceAllLVSensitive);
132 // override the setAllLVSensitive by Config.in macro
135 G4cout << "Dependent modules will be constructed now." << G4endl;
136 fMoreModulesConstruction->Construct();
139 // fill medium Id vector
140 TG4GeometryManager::Instance()->FillMediumIdVector();
141 // this step can be done only after the sensitive
142 // detectors have been created
145 void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
147 // Sets readGeometry control to all modules.
150 // single module constructions
151 G4int nofDets = fModuleConstructionVector.entries();
153 for (i=0; i<nofDets; i++)
154 fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
156 // more modules construction
157 nofDets = fMoreModulesConstruction->GetNofModules();
158 for (i=0; i<nofDets; i++) {
159 AliSingleModuleConstruction* moduleConstruction
160 = fMoreModulesConstruction->GetModuleConstruction(i);
161 moduleConstruction->SetReadGeometry(readGeometry);
165 void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
167 // Sets writeGeometry control to all modules.
170 // single module constructions
171 G4int nofDets = fModuleConstructionVector.entries();
173 for (i=0; i<nofDets; i++)
174 fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
176 // more modules construction
177 nofDets = fMoreModulesConstruction->GetNofModules();
178 for (i=0; i<nofDets; i++) {
179 AliSingleModuleConstruction* moduleConstruction
180 = fMoreModulesConstruction->GetModuleConstruction(i);
181 moduleConstruction->SetWriteGeometry(writeGeometry);
185 void AliModulesComposition::SetAllLVSensitiveToModules(G4bool allSensitive)
187 // Sets setAllSensitive control to all modules.
190 // single module constructions
191 G4int nofDets = fModuleConstructionVector.entries();
193 for (i=0; i<nofDets; i++)
194 fModuleConstructionVector[i]->SetAllLVSensitive(allSensitive);
196 // more modules construction
197 nofDets = fMoreModulesConstruction->GetNofModules();
198 for (i=0; i<nofDets; i++) {
199 AliSingleModuleConstruction* moduleConstruction
200 = fMoreModulesConstruction->GetModuleConstruction(i);
201 moduleConstruction->SetAllLVSensitive(allSensitive);
205 void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
207 // Sets processConfig control to all modules.
210 // single module constructions
211 G4int nofDets = fModuleConstructionVector.entries();
213 for (i=0; i<nofDets; i++)
214 fModuleConstructionVector[i]->SetProcessConfig(processConfig);
216 // more modules construction
217 nofDets = fMoreModulesConstruction->GetNofModules();
218 for (i=0; i<nofDets; i++) {
219 AliSingleModuleConstruction* moduleConstruction
220 = fMoreModulesConstruction->GetModuleConstruction(i);
221 moduleConstruction->SetProcessConfig(processConfig);
227 void AliModulesComposition::SwitchDetOn(G4String moduleNameVer)
229 // Switchs on module specified by name and version.
232 G4int nofDets = fDetSwitchVector.entries();
233 if (moduleNameVer == "ALL") {
234 for (G4int id=0; id<nofDets; id++) fDetSwitchVector[id]->SwitchOnDefault();
236 else if (moduleNameVer == "PPR") {
237 for (G4int id=0; id<nofDets; id++) fDetSwitchVector[id]->SwitchOnPPR();
238 AliFiles::Instance()->SetMacroName("ConfigPPR");
240 else if (moduleNameVer == "NONE") {
241 for (G4int id=0; id<nofDets; id++)
242 fDetSwitchVector[id]->SwitchOff();
245 // get version number
246 G4int len = moduleNameVer.length();
247 G4String moduleName = moduleNameVer(0, len-1);
248 G4String version = moduleNameVer(len-1, 1);
249 G4int iVersion = AliGlobals::StringToInt(version);
252 // in case the version number is not provided
253 // the default one is set
254 SwitchDetOnDefault(moduleNameVer);
257 SwitchDetOn(moduleName, iVersion);
261 void AliModulesComposition::SwitchDetOn(G4String moduleName, G4int version)
263 // Switchs on module specified by name and version.
266 G4int nofDets = fDetSwitchVector.entries();
267 for (G4int id=0; id<nofDets; id++) {
268 G4String iDetName = fDetSwitchVector[id]->GetDetName();
269 if (iDetName == moduleName) {
270 fDetSwitchVector[id]->SwitchOn(version);
274 AliGlobals::Exception(
275 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
278 void AliModulesComposition::SwitchDetOnDefault(G4String moduleName)
280 // Switchs on module specified by name with default version.
283 G4int nofDets = fDetSwitchVector.entries();
284 for (G4int id=0; id<nofDets; id++) {
285 G4String iDetName = fDetSwitchVector[id]->GetDetName();
286 if (iDetName == moduleName) {
287 fDetSwitchVector[id]->SwitchOnDefault();
291 AliGlobals::Exception(
292 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
295 void AliModulesComposition::SwitchDetOnPPR(G4String moduleName)
297 // Switchs on module specified by name with PPR version.
300 G4int nofDets = fDetSwitchVector.entries();
301 for (G4int id=0; id<nofDets; id++) {
302 G4String iDetName = fDetSwitchVector[id]->GetDetName();
303 if (iDetName == moduleName) {
304 fDetSwitchVector[id]->SwitchOnPPR();
308 AliGlobals::Exception(
309 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
312 void AliModulesComposition::SwitchDetOff(G4String moduleName)
314 // Switchs off module specified by name.
317 G4int nofDets = fDetSwitchVector.entries();
318 if (moduleName == "ALL") {
319 for (G4int id=0; id<nofDets; id++)
320 fDetSwitchVector[id]->SwitchOff();
323 for (G4int id=0; id<nofDets; id++) {
324 G4String iDetName = fDetSwitchVector[id]->GetDetName();
325 if (iDetName == moduleName) {
326 fDetSwitchVector[id]->SwitchOff();
331 AliGlobals::Exception(
332 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
335 void AliModulesComposition::PrintSwitchedDets() const
337 // Lists switched detectors.
340 G4String svList = GetSwitchedDetsList();
342 G4cout << "Switched Alice detectors: " << G4endl;
343 G4cout << "--------------------------" << G4endl;
344 G4cout << svList << G4endl;
347 void AliModulesComposition::PrintAvailableDets() const
349 // Lists available detectors.
352 G4String avList = GetAvailableDetsList();
354 G4cout << "Available Alice detectors: " << G4endl;
355 G4cout << "---------------------------" << G4endl;
356 G4cout << avList << G4endl;
359 void AliModulesComposition::PrintMaterials() const
361 // Prints all materials.
364 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
368 void AliModulesComposition::GenerateXMLGeometry() const
370 // Generates XML geometry file from the top volume.
371 // The file name is set according the last switched detector
372 // registered in the det switch vector.
375 G4VPhysicalVolume* world = AliSingleModuleConstruction::GetWorld();
378 // according to last switched detector
381 for (G4int i=fDetSwitchVector.entries()-1; i>=0; i--) {
382 version = fDetSwitchVector[i]->GetSwitchedVersion();
384 detName = fDetSwitchVector[i]->GetDetName();
389 = AliFiles::Instance()->GetXMLFilePath(detName, version);
391 // set top volume name
392 G4String topName = world->GetName() + "_comp";
396 TG4XMLGeometryGenerator xml;
397 xml.OpenFile(filePath);
399 // generate materials
400 // not yet implemented
401 // xml.GenerateMaterials(version, "today", "Generated from G4",
402 // "v4", world->GetLogicalVolume());
404 // generate volumes tree
405 xml.GenerateSection(detName, version, "today", "Generated from Geant4",
406 topName, world->GetLogicalVolume());
410 G4cout << "File " << detName << "v" << version << ".xml has been generated."
415 G4String AliModulesComposition::GetSwitchedDetsList() const
417 // Returns list of switched detectors.
420 G4String svList = "";
422 G4int nofDets = fDetSwitchVector.entries();
423 G4int nofSwitchedDets = 0;
424 for (G4int id=0; id<nofDets; id++) {
425 G4int iVersion = fDetSwitchVector[id]->GetSwitchedVersion();
428 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
429 AliGlobals::AppendNumberToString(moduleNameVer, iVersion);
430 svList += moduleNameVer;
435 if (nofSwitchedDets == nofDets) svList = "ALL: " + svList;
436 if (nofSwitchedDets == 0) svList = "NONE";
441 const G4RWTPtrOrderedVector<AliDetSwitch>&
442 AliModulesComposition::GetDetSwitchVector() const
444 // Returns detSwitch vector.
447 //const AliDetSwitchVector& vector = fDetSwitchVector;
448 const G4RWTPtrOrderedVector<AliDetSwitch>& vector = fDetSwitchVector;
452 G4String AliModulesComposition::GetAvailableDetsList() const
454 // Returns list of available detectors.
457 G4String svList = "";
459 G4int nofDets = fDetSwitchVector.entries();
460 for (G4int id=0; id<nofDets; id++) {
461 G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
462 for (G4int iv=0; iv<nofVersions; iv++) {
463 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
464 AliGlobals::AppendNumberToString(moduleNameVer, iv);
465 svList += moduleNameVer;
473 G4String AliModulesComposition::GetAvailableDetsListWithCommas() const
475 // Returns list of available detectors with commas.
478 G4String svList = "";
480 G4int nofDets = fDetSwitchVector.entries();
481 for (G4int id=0; id<nofDets; id++) {
482 G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
483 for (G4int iv=0; iv<nofVersions; iv++) {
484 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
485 AliGlobals::AppendNumberToString(moduleNameVer, iv);
486 svList += moduleNameVer;
487 if (iv<nofVersions-1) svList += "/";
488 else if (id < nofDets-1) svList += ", ";
495 G4String AliModulesComposition::GetDetNamesList() const
497 // Returns list of detector names.
500 G4String svList = "";
502 G4int nofDets = fDetSwitchVector.entries();
503 for (G4int id=0; id<nofDets; id++) {
504 svList += fDetSwitchVector[id]->GetDetName();
511 G4String AliModulesComposition::GetDetNamesListWithCommas() const
513 // Returns list of detector names with commas.
516 G4String svList = "";
518 G4int nofDets = fDetSwitchVector.entries();
519 for (G4int id=0; id<nofDets; id++) {
520 svList += fDetSwitchVector[id]->GetDetName();
521 if (id < nofDets-1) svList += ", ";
527 void AliModulesComposition::SetMagField(G4double fieldValue)
529 // Sets uniform magnetic field to specified value.
532 // create fields if it does not exist
533 if (!fMagneticField) fMagneticField = new AliMagneticField();
536 fMagneticField->SetFieldValue(fieldValue);