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 // configure single modules
110 G4int nofDets = fModuleConstructionVector.entries();
112 for (i=0; i<nofDets; i++) {
113 fModuleConstructionVector[i]->Configure(*AliFiles::Instance());
114 cout << "Module " << fModuleConstructionVector[i]->GetDetName()
115 << " configured." << endl;
117 if (fForceAllLVSensitive)
118 SetAllLVSensitiveToModules(fForceAllLVSensitive);
119 // override the setAllLVSensitive by Config.in macro
122 // configure dependent modules
123 G4int nofModules = fMoreModulesConstruction->GetNofModules();
125 fMoreModulesConstruction->Configure(*AliFiles::Instance());
126 if (fForceAllLVSensitive)
127 SetAllLVSensitiveToModules(fForceAllLVSensitive);
128 // override the setAllLVSensitive by Config.in macro
132 // construct single modules
133 for (i=0; i<nofDets; i++) {
134 G4cout << "Module " << fModuleConstructionVector[i]->GetDetName()
135 << " will be constructed now." << G4endl;
136 fModuleConstructionVector[i]->Construct();
139 // construct dependent modules
141 G4cout << "Dependent modules will be constructed now." << G4endl;
142 fMoreModulesConstruction->Construct();
145 // fill medium Id vector
146 TG4GeometryManager::Instance()->FillMediumIdVector();
147 // this step can be done only after the sensitive
148 // detectors have been created
151 AliDetSwitch* AliModulesComposition::GetDetSwitch(const G4String& detName)
153 // Returns the detector switch with given detector name.
156 AliDetSwitch* detSwitch = 0;
157 for (G4int id=0; id<fDetSwitchVector.entries(); id++) {
158 detSwitch = fDetSwitchVector[id];
159 if (detSwitch->GetDetName() == detName) return detSwitch;
166 void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
168 // Sets readGeometry control to all modules.
171 // single module constructions
172 G4int nofDets = fModuleConstructionVector.entries();
174 for (i=0; i<nofDets; i++)
175 fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
177 // more modules construction
178 nofDets = fMoreModulesConstruction->GetNofModules();
179 for (i=0; i<nofDets; i++) {
180 AliSingleModuleConstruction* moduleConstruction
181 = fMoreModulesConstruction->GetModuleConstruction(i);
182 moduleConstruction->SetReadGeometry(readGeometry);
186 void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
188 // Sets writeGeometry control to all modules.
191 // single module constructions
192 G4int nofDets = fModuleConstructionVector.entries();
194 for (i=0; i<nofDets; i++)
195 fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
197 // more modules construction
198 nofDets = fMoreModulesConstruction->GetNofModules();
199 for (i=0; i<nofDets; i++) {
200 AliSingleModuleConstruction* moduleConstruction
201 = fMoreModulesConstruction->GetModuleConstruction(i);
202 moduleConstruction->SetWriteGeometry(writeGeometry);
206 void AliModulesComposition::SetAllLVSensitiveToModules(G4bool allSensitive)
208 // Sets setAllSensitive control to all modules.
211 // single module constructions
212 G4int nofDets = fModuleConstructionVector.entries();
214 for (i=0; i<nofDets; i++)
215 fModuleConstructionVector[i]->SetAllLVSensitive(allSensitive);
217 // more modules construction
218 nofDets = fMoreModulesConstruction->GetNofModules();
219 for (i=0; i<nofDets; i++) {
220 AliSingleModuleConstruction* moduleConstruction
221 = fMoreModulesConstruction->GetModuleConstruction(i);
222 moduleConstruction->SetAllLVSensitive(allSensitive);
226 void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
228 // Sets processConfig control to all modules.
231 // single module constructions
232 G4int nofDets = fModuleConstructionVector.entries();
234 for (i=0; i<nofDets; i++)
235 fModuleConstructionVector[i]->SetProcessConfig(processConfig);
237 // more modules construction
238 nofDets = fMoreModulesConstruction->GetNofModules();
239 for (i=0; i<nofDets; i++) {
240 AliSingleModuleConstruction* moduleConstruction
241 = fMoreModulesConstruction->GetModuleConstruction(i);
242 moduleConstruction->SetProcessConfig(processConfig);
248 void AliModulesComposition::SwitchDetOn(G4String moduleNameVer)
250 // Switchs on module specified by name and version.
253 G4int nofDets = fDetSwitchVector.entries();
254 if (moduleNameVer == "ALL") {
255 for (G4int id=0; id<nofDets; id++) fDetSwitchVector[id]->SwitchOnDefault();
257 else if (moduleNameVer == "PPR") {
258 for (G4int id=0; id<nofDets; id++) fDetSwitchVector[id]->SwitchOnPPR();
259 AliFiles::Instance()->SetMacroName("ConfigPPR");
261 else if (moduleNameVer == "NONE") {
262 for (G4int id=0; id<nofDets; id++)
263 fDetSwitchVector[id]->SwitchOff();
266 // get version number
267 G4int len = moduleNameVer.length();
268 G4String moduleName = moduleNameVer(0, len-1);
269 G4String version = moduleNameVer(len-1, 1);
270 G4int iVersion = AliGlobals::StringToInt(version);
273 // in case the version number is not provided
274 // the default one is set
275 SwitchDetOnDefault(moduleNameVer);
278 SwitchDetOn(moduleName, iVersion);
282 void AliModulesComposition::SwitchDetOn(G4String moduleName, G4int version)
284 // Switchs on module specified by name and version.
287 G4int nofDets = fDetSwitchVector.entries();
288 for (G4int id=0; id<nofDets; id++) {
289 G4String iDetName = fDetSwitchVector[id]->GetDetName();
290 if (iDetName == moduleName) {
291 fDetSwitchVector[id]->SwitchOn(version);
295 AliGlobals::Exception(
296 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
299 void AliModulesComposition::SwitchDetOnDefault(G4String moduleName)
301 // Switchs on module specified by name with default version.
304 G4int nofDets = fDetSwitchVector.entries();
305 for (G4int id=0; id<nofDets; id++) {
306 G4String iDetName = fDetSwitchVector[id]->GetDetName();
307 if (iDetName == moduleName) {
308 fDetSwitchVector[id]->SwitchOnDefault();
312 AliGlobals::Exception(
313 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
316 void AliModulesComposition::SwitchDetOnPPR(G4String moduleName)
318 // Switchs on module specified by name with PPR version.
321 G4int nofDets = fDetSwitchVector.entries();
322 for (G4int id=0; id<nofDets; id++) {
323 G4String iDetName = fDetSwitchVector[id]->GetDetName();
324 if (iDetName == moduleName) {
325 fDetSwitchVector[id]->SwitchOnPPR();
329 AliGlobals::Exception(
330 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
333 void AliModulesComposition::SwitchDetOff(G4String moduleName)
335 // Switchs off module specified by name.
338 G4int nofDets = fDetSwitchVector.entries();
339 if (moduleName == "ALL") {
340 for (G4int id=0; id<nofDets; id++)
341 fDetSwitchVector[id]->SwitchOff();
344 for (G4int id=0; id<nofDets; id++) {
345 G4String iDetName = fDetSwitchVector[id]->GetDetName();
346 if (iDetName == moduleName) {
347 fDetSwitchVector[id]->SwitchOff();
352 AliGlobals::Exception(
353 "AliModulesComposition: Wrong detector name for " + moduleName + ".");
356 void AliModulesComposition::PrintSwitchedDets() const
358 // Lists switched detectors.
361 G4String svList = GetSwitchedDetsList();
363 G4cout << "Switched Alice detectors: " << G4endl;
364 G4cout << "--------------------------" << G4endl;
365 G4cout << svList << G4endl;
368 void AliModulesComposition::PrintAvailableDets() const
370 // Lists available detectors.
373 G4String avList = GetAvailableDetsList();
375 G4cout << "Available Alice detectors: " << G4endl;
376 G4cout << "---------------------------" << G4endl;
377 G4cout << avList << G4endl;
380 void AliModulesComposition::PrintMaterials() const
382 // Prints all materials.
385 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
389 void AliModulesComposition::GenerateXMLGeometry() const
391 // Generates XML geometry file from the top volume.
392 // The file name is set according the last switched detector
393 // registered in the det switch vector.
396 G4VPhysicalVolume* world = AliSingleModuleConstruction::GetWorld();
399 // according to last switched detector
401 G4String detVersion = "";
403 for (G4int i=fDetSwitchVector.entries()-1; i>=0; i--) {
404 version = fDetSwitchVector[i]->GetSwitchedVersion();
406 detName = fDetSwitchVector[i]->GetDetName();
407 AliGlobals::AppendNumberToString(detVersion,version);
412 = AliFiles::Instance()->GetXMLFilePath(detName, version);
414 // set top volume name
415 G4String topName = world->GetName() + "_comp";
419 TG4XMLGeometryGenerator xml;
420 xml.OpenFile(filePath);
422 // generate materials
423 // not yet implemented
424 // xml.GenerateMaterials(version, "today", "Generated from G4",
425 // "v4", world->GetLogicalVolume());
427 // generate volumes tree
428 xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4",
429 topName, world->GetLogicalVolume());
433 G4cout << "File " << detName << "v" << version << ".xml has been generated."
438 G4String AliModulesComposition::GetSwitchedDetsList() const
440 // Returns list of switched detectors.
443 G4String svList = "";
445 G4int nofDets = fDetSwitchVector.entries();
446 G4int nofSwitchedDets = 0;
447 for (G4int id=0; id<nofDets; id++) {
448 G4int iVersion = fDetSwitchVector[id]->GetSwitchedVersion();
451 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
452 AliGlobals::AppendNumberToString(moduleNameVer, iVersion);
453 svList += moduleNameVer;
458 if (nofSwitchedDets == nofDets) svList = "ALL: " + svList;
459 if (nofSwitchedDets == 0) svList = "NONE";
464 G4String AliModulesComposition::GetAvailableDetsList() const
466 // Returns list of available detectors.
469 G4String svList = "";
471 G4int nofDets = fDetSwitchVector.entries();
472 for (G4int id=0; id<nofDets; id++) {
473 G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
474 for (G4int iv=0; iv<nofVersions; iv++) {
475 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
476 AliGlobals::AppendNumberToString(moduleNameVer, iv);
477 svList += moduleNameVer;
485 G4String AliModulesComposition::GetAvailableDetsListWithCommas() const
487 // Returns list of available detectors with commas.
490 G4String svList = "";
492 G4int nofDets = fDetSwitchVector.entries();
493 for (G4int id=0; id<nofDets; id++) {
494 G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
495 for (G4int iv=0; iv<nofVersions; iv++) {
496 G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
497 AliGlobals::AppendNumberToString(moduleNameVer, iv);
498 svList += moduleNameVer;
499 if (iv<nofVersions-1) svList += "/";
500 else if (id < nofDets-1) svList += ", ";
507 G4String AliModulesComposition::GetDetNamesList() const
509 // Returns list of detector names.
512 G4String svList = "";
514 G4int nofDets = fDetSwitchVector.entries();
515 for (G4int id=0; id<nofDets; id++) {
516 svList += fDetSwitchVector[id]->GetDetName();
523 G4String AliModulesComposition::GetDetNamesListWithCommas() const
525 // Returns list of detector names with commas.
528 G4String svList = "";
530 G4int nofDets = fDetSwitchVector.entries();
531 for (G4int id=0; id<nofDets; id++) {
532 svList += fDetSwitchVector[id]->GetDetName();
533 if (id < nofDets-1) svList += ", ";
539 void AliModulesComposition::SetMagField(G4double fieldValue)
541 // Sets uniform magnetic field to specified value.
544 // create fields if it does not exist
545 if (!fMagneticField) fMagneticField = new AliMagneticField();
548 fMagneticField->SetFieldValue(fieldValue);