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 "TG4XMLGeometryGenerator.h"
16 #include "TG4GeometryManager.h"
18 #include <G4Material.hh>
19 #include <G4VPhysicalVolume.hh>
21 //_____________________________________________________________________________
22 AliModulesComposition::AliModulesComposition()
23 : fReadGeometry(false),
24 fWriteGeometry(false),
28 fMoreModulesConstruction = new AliMoreModulesConstruction();
29 fMessenger = new AliModulesCompositionMessenger(this);
32 //_____________________________________________________________________________
33 AliModulesComposition::AliModulesComposition(const AliModulesComposition& right)
36 AliGlobals::Exception("AliModulesComposition is protected from copying.");
39 //_____________________________________________________________________________
40 AliModulesComposition::~AliModulesComposition() {
42 delete fMoreModulesConstruction;
43 delete fMagneticField;
46 // destroy det switch vector
47 fDetSwitchVector.clearAndDestroy();
49 // destroy det construction vector
50 fModuleConstructionVector.clearAndDestroy();
55 //_____________________________________________________________________________
56 AliModulesComposition&
57 AliModulesComposition::operator=(const AliModulesComposition& right)
59 // check assignement to self
60 if (this == &right) return *this;
62 AliGlobals::Exception("AliModulesComposition is protected from assigning.");
69 //_____________________________________________________________________________
70 void AliModulesComposition::AddDetSwitch(AliDetSwitch* detSwitch)
72 // Adds detSwitch to the detSwitch vector.
75 fDetSwitchVector.insert(detSwitch);
76 fMessenger->SetCandidates();
79 //_____________________________________________________________________________
80 void AliModulesComposition::AddSingleModuleConstruction(G4String moduleName,
81 G4int version, AliModuleType moduleType)
83 // Adds SingleModuleConstruction.
86 AliSingleModuleConstruction* moduleConstruction
87 = new AliSingleModuleConstruction(moduleName, version, moduleType);
88 fModuleConstructionVector.insert(moduleConstruction);
91 //_____________________________________________________________________________
92 void AliModulesComposition::AddMoreModuleConstruction(G4String moduleName,
93 G4int version, AliModuleType moduleType)
95 // Adds module to MoreModulesConstruction (construction of dependent
99 fMoreModulesConstruction->AddModule(moduleName, version, moduleType);
102 //_____________________________________________________________________________
103 void AliModulesComposition::ConstructModules()
105 // Construct geometry of all modules (both standalone and dependent.)
108 // set common options
109 SetReadGeometryToModules(fReadGeometry);
110 SetWriteGeometryToModules(fWriteGeometry);
112 // configure single modules
113 G4int nofDets = fModuleConstructionVector.entries();
115 for (i=0; i<nofDets; i++) {
116 fModuleConstructionVector[i]->Configure(*AliFiles::Instance());
117 cout << "Module " << fModuleConstructionVector[i]->GetDetName()
118 << " configured." << endl;
121 // configure dependent modules
122 G4int nofModules = fMoreModulesConstruction->GetNofModules();
124 fMoreModulesConstruction->Configure(*AliFiles::Instance());
127 // construct single modules
128 for (i=0; i<nofDets; i++) {
129 G4cout << "Module " << fModuleConstructionVector[i]->GetDetName()
130 << " will be constructed now." << G4endl;
131 fModuleConstructionVector[i]->Construct();
134 // construct dependent modules
136 G4cout << "Dependent modules will be constructed now." << G4endl;
137 fMoreModulesConstruction->Construct();
141 //_____________________________________________________________________________
142 AliDetSwitch* AliModulesComposition::GetDetSwitch(const G4String& detName)
144 // Returns the detector switch with given detector name.
147 AliDetSwitch* detSwitch = 0;
148 for (G4int id=0; id<fDetSwitchVector.entries(); id++) {
149 detSwitch = fDetSwitchVector[id];
150 if (detSwitch->GetDetName() == detName) return detSwitch;
156 //_____________________________________________________________________________
157 void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
159 // Sets readGeometry control to all modules.
162 // single module constructions
163 G4int nofDets = fModuleConstructionVector.entries();
165 for (i=0; i<nofDets; i++)
166 fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
168 // more modules construction
169 nofDets = fMoreModulesConstruction->GetNofModules();
170 for (i=0; i<nofDets; i++) {
171 AliSingleModuleConstruction* moduleConstruction
172 = fMoreModulesConstruction->GetModuleConstruction(i);
173 moduleConstruction->SetReadGeometry(readGeometry);
177 //_____________________________________________________________________________
178 void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
180 // Sets writeGeometry control to all modules.
183 // single module constructions
184 G4int nofDets = fModuleConstructionVector.entries();
186 for (i=0; i<nofDets; i++)
187 fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
189 // more modules construction
190 nofDets = fMoreModulesConstruction->GetNofModules();
191 for (i=0; i<nofDets; i++) {
192 AliSingleModuleConstruction* moduleConstruction
193 = fMoreModulesConstruction->GetModuleConstruction(i);
194 moduleConstruction->SetWriteGeometry(writeGeometry);
198 //_____________________________________________________________________________
199 void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
201 // Sets processConfig control to all modules.
204 // single module constructions
205 G4int nofDets = fModuleConstructionVector.entries();
207 for (i=0; i<nofDets; i++)
208 fModuleConstructionVector[i]->SetProcessConfig(processConfig);
210 // more modules construction
211 nofDets = fMoreModulesConstruction->GetNofModules();
212 for (i=0; i<nofDets; i++) {
213 AliSingleModuleConstruction* moduleConstruction
214 = fMoreModulesConstruction->GetModuleConstruction(i);
215 moduleConstruction->SetProcessConfig(processConfig);
221 //_____________________________________________________________________________
222 void AliModulesComposition::SwitchDetOn(G4String moduleNameVer)
224 // Switchs on module specified by name and version.
227 G4int nofDets = fDetSwitchVector.entries();
228 if (moduleNameVer == "ALL") {
229 for (G4int id=0; id<nofDets; id++) fDetSwitchVector[id]->SwitchOnDefault();
231 else if (moduleNameVer == "PPR") {
232 for (G4int id=0; id<nofDets; id++) fDetSwitchVector[id]->SwitchOnPPR();
233 AliFiles::Instance()->SetMacroName("ConfigPPR");
235 else if (moduleNameVer == "NONE") {
236 for (G4int id=0; id<nofDets; id++)
237 fDetSwitchVector[id]->SwitchOff();
240 // get version number
241 G4int len = moduleNameVer.length();
242 G4String moduleName = moduleNameVer(0, len-1);
243 G4String version = moduleNameVer(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(G4String moduleName, G4int version)
259 // Switchs on module specified by name and version.
262 G4int nofDets = fDetSwitchVector.entries();
263 for (G4int id=0; id<nofDets; id++) {
264 G4String iDetName = fDetSwitchVector[id]->GetDetName();
265 if (iDetName == moduleName) {
266 fDetSwitchVector[id]->SwitchOn(version);
270 AliGlobals::Exception(
271 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
274 //_____________________________________________________________________________
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 //_____________________________________________________________________________
293 void AliModulesComposition::SwitchDetOnPPR(G4String moduleName)
295 // Switchs on module specified by name with PPR version.
298 G4int nofDets = fDetSwitchVector.entries();
299 for (G4int id=0; id<nofDets; id++) {
300 G4String iDetName = fDetSwitchVector[id]->GetDetName();
301 if (iDetName == moduleName) {
302 fDetSwitchVector[id]->SwitchOnPPR();
306 AliGlobals::Exception(
307 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
310 //_____________________________________________________________________________
311 void AliModulesComposition::SwitchDetOff(G4String moduleName)
313 // Switchs off module specified by name.
316 G4int nofDets = fDetSwitchVector.entries();
317 if (moduleName == "ALL") {
318 for (G4int id=0; id<nofDets; id++)
319 fDetSwitchVector[id]->SwitchOff();
322 for (G4int id=0; id<nofDets; id++) {
323 G4String iDetName = fDetSwitchVector[id]->GetDetName();
324 if (iDetName == moduleName) {
325 fDetSwitchVector[id]->SwitchOff();
330 AliGlobals::Exception(
331 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
334 //_____________________________________________________________________________
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 //_____________________________________________________________________________
348 void AliModulesComposition::PrintAvailableDets() const
350 // Lists available detectors.
353 G4String avList = GetAvailableDetsList();
355 G4cout << "Available Alice detectors: " << G4endl;
356 G4cout << "---------------------------" << G4endl;
357 G4cout << avList << G4endl;
360 //_____________________________________________________________________________
361 void AliModulesComposition::PrintMaterials() const
363 // Prints all materials.
366 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
370 //_____________________________________________________________________________
371 void AliModulesComposition::GenerateXMLGeometry() const
373 // Generates XML geometry file from the top volume.
374 // The file name is set according the last switched detector
375 // registered in the det switch vector.
378 G4VPhysicalVolume* world = AliSingleModuleConstruction::GetWorld();
381 // according to last switched detector
383 G4String detVersion = "";
385 for (G4int i=fDetSwitchVector.entries()-1; i>=0; i--) {
386 version = fDetSwitchVector[i]->GetSwitchedVersion();
388 detName = fDetSwitchVector[i]->GetDetName();
389 AliGlobals::AppendNumberToString(detVersion,version);
394 = AliFiles::Instance()->GetXMLFilePath(detName, version);
396 // set top volume name
397 G4String topName = world->GetName() + "_comp";
401 TG4XMLGeometryGenerator xml;
402 xml.OpenFile(filePath);
404 // generate materials
405 // not yet implemented
406 // xml.GenerateMaterials(version, "today", "Generated from G4",
407 // "v4", world->GetLogicalVolume());
409 // generate volumes tree
410 xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4",
411 topName, world->GetLogicalVolume());
415 G4cout << "File " << detName << "v" << version << ".xml has been generated."
419 //_____________________________________________________________________________
420 G4String AliModulesComposition::GetSwitchedDetsList() const
422 // Returns list of switched detectors.
425 G4String svList = "";
427 G4int nofDets = fDetSwitchVector.entries();
428 G4int nofSwitchedDets = 0;
429 for (G4int id=0; id<nofDets; id++) {
430 G4int iVersion = fDetSwitchVector[id]->GetSwitchedVersion();
433 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
434 AliGlobals::AppendNumberToString(moduleNameVer, iVersion);
435 svList += moduleNameVer;
440 if (nofSwitchedDets == nofDets) svList = "ALL: " + svList;
441 if (nofSwitchedDets == 0) svList = "NONE";
446 //_____________________________________________________________________________
447 G4String AliModulesComposition::GetAvailableDetsList() const
449 // Returns list of available detectors.
452 G4String svList = "";
454 G4int nofDets = fDetSwitchVector.entries();
455 for (G4int id=0; id<nofDets; id++) {
456 G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
457 for (G4int iv=0; iv<nofVersions; iv++) {
458 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
459 AliGlobals::AppendNumberToString(moduleNameVer, iv);
460 svList += moduleNameVer;
468 //_____________________________________________________________________________
469 G4String AliModulesComposition::GetAvailableDetsListWithCommas() const
471 // Returns list of available detectors with commas.
474 G4String svList = "";
476 G4int nofDets = fDetSwitchVector.entries();
477 for (G4int id=0; id<nofDets; id++) {
478 G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
479 for (G4int iv=0; iv<nofVersions; iv++) {
480 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
481 AliGlobals::AppendNumberToString(moduleNameVer, iv);
482 svList += moduleNameVer;
483 if (iv<nofVersions-1) svList += "/";
484 else if (id < nofDets-1) svList += ", ";
491 //_____________________________________________________________________________
492 G4String AliModulesComposition::GetDetNamesList() const
494 // Returns list of detector names.
497 G4String svList = "";
499 G4int nofDets = fDetSwitchVector.entries();
500 for (G4int id=0; id<nofDets; id++) {
501 svList += fDetSwitchVector[id]->GetDetName();
508 //_____________________________________________________________________________
509 G4String AliModulesComposition::GetDetNamesListWithCommas() const
511 // Returns list of detector names with commas.
514 G4String svList = "";
516 G4int nofDets = fDetSwitchVector.entries();
517 for (G4int id=0; id<nofDets; id++) {
518 svList += fDetSwitchVector[id]->GetDetName();
519 if (id < nofDets-1) svList += ", ";
525 //_____________________________________________________________________________
526 void AliModulesComposition::SetMagField(G4double fieldValue)
528 // Sets uniform magnetic field to specified value.
531 // create fields if it does not exist
532 if (!fMagneticField) fMagneticField = new AliMagneticField();
535 fMagneticField->SetFieldValue(fieldValue);