// $Id$ // Category: geometry // // See the class description in the header file. #include "AliModulesComposition.h" #include "AliModulesCompositionMessenger.h" #include "AliSingleModuleConstruction.h" #include "AliMoreModulesConstruction.h" #include "AliDetSwitch.h" #include "AliMagneticField.h" #include "AliGlobals.h" #include "AliFiles.h" #include "TG4XMLGeometryGenerator.h" #include "TG4GeometryManager.h" #include #include //_____________________________________________________________________________ AliModulesComposition::AliModulesComposition() : fReadGeometry(false), fWriteGeometry(false), fMagneticField(0) { // fMoreModulesConstruction = new AliMoreModulesConstruction(); fMessenger = new AliModulesCompositionMessenger(this); } //_____________________________________________________________________________ AliModulesComposition::AliModulesComposition(const AliModulesComposition& right) { // AliGlobals::Exception("AliModulesComposition is protected from copying."); } //_____________________________________________________________________________ AliModulesComposition::~AliModulesComposition() { // delete fMoreModulesConstruction; delete fMagneticField; delete fMessenger; // destroy det switch vector fDetSwitchVector.clearAndDestroy(); // destroy det construction vector fModuleConstructionVector.clearAndDestroy(); } // operators //_____________________________________________________________________________ AliModulesComposition& AliModulesComposition::operator=(const AliModulesComposition& right) { // check assignement to self if (this == &right) return *this; AliGlobals::Exception("AliModulesComposition is protected from assigning."); return *this; } // protected methods //_____________________________________________________________________________ void AliModulesComposition::AddDetSwitch(AliDetSwitch* detSwitch) { // Adds detSwitch to the detSwitch vector. // --- fDetSwitchVector.insert(detSwitch); fMessenger->SetCandidates(); } //_____________________________________________________________________________ void AliModulesComposition::AddSingleModuleConstruction(G4String moduleName, G4int version, AliModuleType moduleType) { // Adds SingleModuleConstruction. // --- AliSingleModuleConstruction* moduleConstruction = new AliSingleModuleConstruction(moduleName, version, moduleType); fModuleConstructionVector.insert(moduleConstruction); } //_____________________________________________________________________________ void AliModulesComposition::AddMoreModuleConstruction(G4String moduleName, G4int version, AliModuleType moduleType) { // Adds module to MoreModulesConstruction (construction of dependent // modules.) // --- fMoreModulesConstruction->AddModule(moduleName, version, moduleType); } //_____________________________________________________________________________ void AliModulesComposition::ConstructModules() { // Construct geometry of all modules (both standalone and dependent.) // --- // set common options SetReadGeometryToModules(fReadGeometry); SetWriteGeometryToModules(fWriteGeometry); // configure single modules G4int nofDets = fModuleConstructionVector.entries(); G4int i; for (i=0; iConfigure(*AliFiles::Instance()); cout << "Module " << fModuleConstructionVector[i]->GetDetName() << " configured." << endl; } // configure dependent modules G4int nofModules = fMoreModulesConstruction->GetNofModules(); if (nofModules>0) { fMoreModulesConstruction->Configure(*AliFiles::Instance()); } // construct single modules for (i=0; iGetDetName() << " will be constructed now." << G4endl; fModuleConstructionVector[i]->Construct(); } // construct dependent modules if (nofModules>0) { G4cout << "Dependent modules will be constructed now." << G4endl; fMoreModulesConstruction->Construct(); } } //_____________________________________________________________________________ AliDetSwitch* AliModulesComposition::GetDetSwitch(const G4String& detName) { // Returns the detector switch with given detector name. // --- AliDetSwitch* detSwitch = 0; for (G4int id=0; idGetDetName() == detName) return detSwitch; } return detSwitch; } //_____________________________________________________________________________ void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry) { // Sets readGeometry control to all modules. // --- // single module constructions G4int nofDets = fModuleConstructionVector.entries(); G4int i; for (i=0; iSetReadGeometry(readGeometry); // more modules construction nofDets = fMoreModulesConstruction->GetNofModules(); for (i=0; iGetModuleConstruction(i); moduleConstruction->SetReadGeometry(readGeometry); } } //_____________________________________________________________________________ void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry) { // Sets writeGeometry control to all modules. // --- // single module constructions G4int nofDets = fModuleConstructionVector.entries(); G4int i; for (i=0; iSetWriteGeometry(writeGeometry); // more modules construction nofDets = fMoreModulesConstruction->GetNofModules(); for (i=0; iGetModuleConstruction(i); moduleConstruction->SetWriteGeometry(writeGeometry); } } //_____________________________________________________________________________ void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig) { // Sets processConfig control to all modules. // --- // single module constructions G4int nofDets = fModuleConstructionVector.entries(); G4int i; for (i=0; iSetProcessConfig(processConfig); // more modules construction nofDets = fMoreModulesConstruction->GetNofModules(); for (i=0; iGetModuleConstruction(i); moduleConstruction->SetProcessConfig(processConfig); } } // public methods //_____________________________________________________________________________ void AliModulesComposition::SwitchDetOn(G4String moduleNameVer) { // Switchs on module specified by name and version. // --- G4int nofDets = fDetSwitchVector.entries(); if (moduleNameVer == "ALL") { for (G4int id=0; idSwitchOnDefault(); } else if (moduleNameVer == "PPR") { for (G4int id=0; idSwitchOnPPR(); AliFiles::Instance()->SetMacroName("ConfigPPR"); } else if (moduleNameVer == "NONE") { for (G4int id=0; idSwitchOff(); } else { // get version number G4int len = moduleNameVer.length(); G4String moduleName = moduleNameVer(0, len-1); G4String version = moduleNameVer(len-1, 1); G4int iVersion = AliGlobals::StringToInt(version); if (iVersion < 0) { // in case the version number is not provided // the default one is set SwitchDetOnDefault(moduleNameVer); } else SwitchDetOn(moduleName, iVersion); } } //_____________________________________________________________________________ void AliModulesComposition::SwitchDetOn(G4String moduleName, G4int version) { // Switchs on module specified by name and version. // --- G4int nofDets = fDetSwitchVector.entries(); for (G4int id=0; idGetDetName(); if (iDetName == moduleName) { fDetSwitchVector[id]->SwitchOn(version); return; } } AliGlobals::Exception( "AliModulesComposition: Wrong detector name for " + moduleName + "."); } //_____________________________________________________________________________ void AliModulesComposition::SwitchDetOnDefault(G4String moduleName) { // Switchs on module specified by name with default version. // --- G4int nofDets = fDetSwitchVector.entries(); for (G4int id=0; idGetDetName(); if (iDetName == moduleName) { fDetSwitchVector[id]->SwitchOnDefault(); return; } } AliGlobals::Exception( "AliModulesComposition: Wrong detector name for " + moduleName + "."); } //_____________________________________________________________________________ void AliModulesComposition::SwitchDetOnPPR(G4String moduleName) { // Switchs on module specified by name with PPR version. // --- G4int nofDets = fDetSwitchVector.entries(); for (G4int id=0; idGetDetName(); if (iDetName == moduleName) { fDetSwitchVector[id]->SwitchOnPPR(); return; } } AliGlobals::Exception( "AliModulesComposition: Wrong detector name for " + moduleName + "."); } //_____________________________________________________________________________ void AliModulesComposition::SwitchDetOff(G4String moduleName) { // Switchs off module specified by name. // --- G4int nofDets = fDetSwitchVector.entries(); if (moduleName == "ALL") { for (G4int id=0; idSwitchOff(); } else { for (G4int id=0; idGetDetName(); if (iDetName == moduleName) { fDetSwitchVector[id]->SwitchOff(); return; } } } AliGlobals::Exception( "AliModulesComposition: Wrong detector name for " + moduleName + "."); } //_____________________________________________________________________________ void AliModulesComposition::PrintSwitchedDets() const { // Lists switched detectors. // --- G4String svList = GetSwitchedDetsList(); G4cout << "Switched Alice detectors: " << G4endl; G4cout << "--------------------------" << G4endl; G4cout << svList << G4endl; } //_____________________________________________________________________________ void AliModulesComposition::PrintAvailableDets() const { // Lists available detectors. // --- G4String avList = GetAvailableDetsList(); G4cout << "Available Alice detectors: " << G4endl; G4cout << "---------------------------" << G4endl; G4cout << avList << G4endl; } //_____________________________________________________________________________ void AliModulesComposition::PrintMaterials() const { // Prints all materials. // --- const G4MaterialTable* matTable = G4Material::GetMaterialTable(); G4cout << *matTable; } //_____________________________________________________________________________ void AliModulesComposition::GenerateXMLGeometry() const { // Generates XML geometry file from the top volume. // The file name is set according the last switched detector // registered in the det switch vector. // --- G4VPhysicalVolume* world = AliSingleModuleConstruction::GetWorld(); // XML filename // according to last switched detector G4String detName; G4String detVersion = ""; G4int version = -1; for (G4int i=fDetSwitchVector.entries()-1; i>=0; i--) { version = fDetSwitchVector[i]->GetSwitchedVersion(); if (version > -1) { detName = fDetSwitchVector[i]->GetDetName(); AliGlobals::AppendNumberToString(detVersion,version); break; } } G4String filePath = AliFiles::Instance()->GetXMLFilePath(detName, version); // set top volume name G4String topName = world->GetName() + "_comp"; // generate XML TG4XMLGeometryGenerator xml; xml.OpenFile(filePath); // generate materials // not yet implemented // xml.GenerateMaterials(version, "today", "Generated from G4", // "v4", world->GetLogicalVolume()); // generate volumes tree xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4", topName, world->GetLogicalVolume()); xml.CloseFile(); // set verbose G4cout << "File " << detName << "v" << version << ".xml has been generated." << G4endl; } //_____________________________________________________________________________ G4String AliModulesComposition::GetSwitchedDetsList() const { // Returns list of switched detectors. // --- G4String svList = ""; G4int nofDets = fDetSwitchVector.entries(); G4int nofSwitchedDets = 0; for (G4int id=0; idGetSwitchedVersion(); if (iVersion > -1) { nofSwitchedDets++; G4String moduleNameVer = fDetSwitchVector[id]->GetDetName(); AliGlobals::AppendNumberToString(moduleNameVer, iVersion); svList += moduleNameVer; svList += " "; } } if (nofSwitchedDets == nofDets) svList = "ALL: " + svList; if (nofSwitchedDets == 0) svList = "NONE"; return svList; } //_____________________________________________________________________________ G4String AliModulesComposition::GetAvailableDetsList() const { // Returns list of available detectors. // --- G4String svList = ""; G4int nofDets = fDetSwitchVector.entries(); for (G4int id=0; idGetNofVersions(); for (G4int iv=0; ivGetDetName(); AliGlobals::AppendNumberToString(moduleNameVer, iv); svList += moduleNameVer; svList += " "; } } return svList; } //_____________________________________________________________________________ G4String AliModulesComposition::GetAvailableDetsListWithCommas() const { // Returns list of available detectors with commas. // --- G4String svList = ""; G4int nofDets = fDetSwitchVector.entries(); for (G4int id=0; idGetNofVersions(); for (G4int iv=0; ivGetDetName(); AliGlobals::AppendNumberToString(moduleNameVer, iv); svList += moduleNameVer; if (ivGetDetName(); svList += " "; } return svList; } //_____________________________________________________________________________ G4String AliModulesComposition::GetDetNamesListWithCommas() const { // Returns list of detector names with commas. // --- G4String svList = ""; G4int nofDets = fDetSwitchVector.entries(); for (G4int id=0; idGetDetName(); if (id < nofDets-1) svList += ", "; } return svList; } //_____________________________________________________________________________ void AliModulesComposition::SetMagField(G4double fieldValue) { // Sets uniform magnetic field to specified value. // --- // create fields if it does not exist if (!fMagneticField) fMagneticField = new AliMagneticField(); // set value fMagneticField->SetFieldValue(fieldValue); }