Simplify ignoring empty and commented lines in steering file

This commit is contained in:
wollra_j committed 2026-08-13 14:31:20 +02:00
1 parent 3209bce1f9
commit 5d2c65a005
4 files changed
+638 -638

No files matched your search

+156 -156
View File
@@ -140,7 +140,8 @@ G4VPhysicalVolume *musrDetectorConstruction::Construct()
// Write out the configuration file into the output file:
G4cout << "\n\n....oooOO0OOooo........oooOO0OOooo......Configuration file used for this run....oooOO0OOooo........oooOO0OOooo......" << G4endl;
while (std::getline(steeringFile, line)) {
steeringLines.push_back(line);
if (!line.empty() && (line.at(0) != '#'))
steeringLines.push_back(line);
G4cout << line << G4endl;
}
G4cout << "....oooOO0OOooo........oooOO0OOooo......End of the configuration file.....oooOO0OOooo........oooOO0OOooo......\n\n" << G4endl;
@@ -148,92 +149,91 @@ G4VPhysicalVolume *musrDetectorConstruction::Construct()
steeringFile.close();
for (const auto &line : steeringLines) {
if (!line.empty() && (line.at(0) != '#') && (line.at(0) != '\r')) {
std::istringstream lineStream(line);
std::string command;
std::istringstream lineStream(line);
std::string command;
lineStream >> command;
if ((command != "/musr/ignore") && (command != "/musr/command"))
continue;
if (!(lineStream >> command))
continue;
if ((command != "/musr/ignore") && (command != "/musr/command"))
continue;
std::string subcommand = "Unset";
lineStream >> subcommand;
std::string subcommand = "Unset";
lineStream >> subcommand;
if (subcommand == "rotation") {
// Define rotation matrix, which might be later on used for some volumes
ParseRotationCommand(line);
} else if (subcommand == "arrayDef") {
// Define array, which is needed for G4Polycone definition
ParseArrayDefCommand(line);
} else if (subcommand == "construct") {
if (G4VPhysicalVolume *worldVolume = ParseConstructCommand(line, myRootOutput, mySteppingAction)) {
pointerToWorldVolume = worldVolume;
}
} else if (subcommand == "visattributes") {
ParseVisAttributesCommand(line);
} else if (subcommand == "opticalSurface") {
// cks: Optical Boundary (needed only when simulating optical photons)
ParseOpticalSurfaceCommand(line);
} else if (subcommand == "OPSA") {
// optical photon signal analysis
ParseOPSACommand(line);
} else if (subcommand == "globalfield") {
// cks: Implementation of the Global Field (to allow overlapping fields) based
// on the Peter Gumplinger's implementation of G4BeamLine code into Geant4.
ParseGlobalFieldCommand(line, myRootOutput);
} else if (subcommand == "SetUserLimits") {
// Set range cut for a given volume, if requested by the macro file
ParseSetUserLimitsCommand(line);
} else if (subcommand == "rootOutputDirectoryName") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "storeOnlyEventsWithHitInDetID") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "storeOnlyEventsWithMuonsDecayedInDetID") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "storeOnlyEventsWithHits") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "storeOnlyTheFirstTimeHit") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "killAllElectrons") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "killAllPositrons") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "killAllGammas") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "killAllNeutrinos") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "maximumTimePerEvent") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "maximumNrOfStepsPerTrack") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "getDetectorMass") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "signalSeparationTime") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "maximumRunTimeAllowed") { // in seconds
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "logicalVolumeToBeReweighted") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "region") {
// Set G4Regions - intended mainly for the coulomb scattering or special production cuts (added on
// 2008.08.21)
ParseRegionCommand(line);
} else if (subcommand == "rootOutput") {
// Set the variables which the user does not want to store in the output root file.
ParseRootOutputCommand(line, myRootOutput);
} else if ((subcommand == "process") || (subcommand == "G4OpticalPhotons") || (subcommand == "G4OpticalPhotonsUnprocess") ||
(subcommand == "materialPropertiesTable") || (subcommand == "setMaterialPropertiesTable")) {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "SetLandauMPV") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "SetLandauSigma") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "writeFile") {
// FIXME: Would be better and much cleaner to handle this in musrDetectorMessenger
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else {
ReportGeometryProblem(line);
if (subcommand == "rotation") {
// Define rotation matrix, which might be later on used for some volumes
ParseRotationCommand(line);
} else if (subcommand == "arrayDef") {
// Define array, which is needed for G4Polycone definition
ParseArrayDefCommand(line);
} else if (subcommand == "construct") {
if (G4VPhysicalVolume *worldVolume = ParseConstructCommand(line, myRootOutput, mySteppingAction)) {
pointerToWorldVolume = worldVolume;
}
} else if (subcommand == "visattributes") {
ParseVisAttributesCommand(line);
} else if (subcommand == "opticalSurface") {
// cks: Optical Boundary (needed only when simulating optical photons)
ParseOpticalSurfaceCommand(line);
} else if (subcommand == "OPSA") {
// optical photon signal analysis
ParseOPSACommand(line);
} else if (subcommand == "globalfield") {
// cks: Implementation of the Global Field (to allow overlapping fields) based
// on the Peter Gumplinger's implementation of G4BeamLine code into Geant4.
ParseGlobalFieldCommand(line, myRootOutput);
} else if (subcommand == "SetUserLimits") {
// Set range cut for a given volume, if requested by the macro file
ParseSetUserLimitsCommand(line);
} else if (subcommand == "rootOutputDirectoryName") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "storeOnlyEventsWithHitInDetID") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "storeOnlyEventsWithMuonsDecayedInDetID") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "storeOnlyEventsWithHits") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "storeOnlyTheFirstTimeHit") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "killAllElectrons") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "killAllPositrons") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "killAllGammas") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "killAllNeutrinos") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "maximumTimePerEvent") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "maximumNrOfStepsPerTrack") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "getDetectorMass") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "signalSeparationTime") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "maximumRunTimeAllowed") { // in seconds
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "logicalVolumeToBeReweighted") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "region") {
// Set G4Regions - intended mainly for the coulomb scattering or special production cuts (added on
// 2008.08.21)
ParseRegionCommand(line);
} else if (subcommand == "rootOutput") {
// Set the variables which the user does not want to store in the output root file.
ParseRootOutputCommand(line, myRootOutput);
} else if ((subcommand == "process") || (subcommand == "G4OpticalPhotons") || (subcommand == "G4OpticalPhotonsUnprocess") ||
(subcommand == "materialPropertiesTable") || (subcommand == "setMaterialPropertiesTable")) {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "SetLandauMPV") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "SetLandauSigma") {
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else if (subcommand == "writeFile") {
// FIXME: Would be better and much cleaner to handle this in musrDetectorMessenger
ParseSimulationSettingCommand(line, myRootOutput, mySteppingAction);
} else {
ReportGeometryProblem(line);
}
}
@@ -2056,89 +2056,89 @@ void musrDetectorConstruction::DefineMaterials()
if (steeringFile.is_open()) {
while (std::getline(steeringFile, line)) {
steeringLines.push_back(line);
if (!line.empty() && (line.at(0) != '#'))
steeringLines.push_back(line);
}
}
steeringFile.close();
for (const auto &line : steeringLines) {
if ((line.at(0) != '#') && (line.at(0) != '\n') && (line.at(0) != '\r')) {
std::istringstream lineStream(line);
std::string command;
std::istringstream lineStream(line);
std::string command;
lineStream >> command;
if ((command != "/musr/ignore") && (command != "/musr/command"))
continue;
if (!(lineStream >> command))
continue;
if ((command != "/musr/ignore") && (command != "/musr/command"))
continue;
std::string subcommand = "Unset";
std::string arg = "Unset";
std::string subcommand = "Unset";
std::string arg = "Unset";
lineStream >> subcommand >> arg;
lineStream >> subcommand >> arg;
if (subcommand == "materialPropertiesTable") {
std::string materialPropertiesTableName = arg;
G4MaterialPropertiesTable *MPT_tmp;
itMPT = materialPropertiesTableMap.find(materialPropertiesTableName);
if (itMPT == materialPropertiesTableMap.end()) { // G4MaterialPropertiesTable of this name does not exist yet --> create it
MPT_tmp = new G4MaterialPropertiesTable();
materialPropertiesTableMap.insert(std::pair<std::string, G4MaterialPropertiesTable *>(materialPropertiesTableName, MPT_tmp));
} else {
MPT_tmp = itMPT->second;
}
std::string propertyName;
int nEntries;
lineStream >> propertyName >> nEntries;
if (nEntries == 0) { // AddConstProperty
double value;
lineStream >> value;
MPT_tmp->AddConstProperty(propertyName, value);
if ((propertyName == "FASTSCINTILLATIONRISETIME") || (propertyName == "SLOWSCINTILLATIONRISETIME")) {
if (value != 0) {
musrParameters::finiteRiseTimeInScintillator = true;
}
}
} else { // AddProperty
double value;
std::vector<G4double> photonEnergies;
std::vector<G4double> values;
for (int i = 0; i < nEntries; i++) {
lineStream >> value;
photonEnergies.push_back(value);
}
for (int i = 0; i < nEntries; i++) {
lineStream >> value;
values.push_back(value);
}
MPT_tmp->AddProperty(propertyName, photonEnergies, values, nEntries);
}
} else if (subcommand == "setMaterialPropertiesTable") {
std::string materialName = "Unset";
std::string materialPropertiesTableName = arg;
lineStream >> materialName;
G4NistManager *man = G4NistManager::Instance();
G4Material *myMaterial = man->FindOrBuildMaterial(materialName);
G4MaterialPropertiesTable *MPT_tmp = nullptr;
itMPT = materialPropertiesTableMap.find(materialPropertiesTableName);
if (itMPT == materialPropertiesTableMap.end()) { // G4MaterialPropertiesTable of this name does not exist --> problem
G4cout << "\n\n musrDetectorConstruction::DefineMaterials(): Material Properties Table \"" << materialPropertiesTableName
<< "\" should be assigned to material \"" << materialName << "\"" << G4endl;
G4cout << " but the table was not defined yet (by command /musr/command "
"materialPropertiesTable )"
<< G4endl;
G4cout << " ===> S T O P F O R C E D" << G4endl;
G4cout << line << G4endl;
exit(1);
} else {
MPT_tmp = itMPT->second;
}
myMaterial->SetMaterialPropertiesTable(MPT_tmp);
if (subcommand == "materialPropertiesTable") {
std::string materialPropertiesTableName = arg;
G4MaterialPropertiesTable *MPT_tmp;
itMPT = materialPropertiesTableMap.find(materialPropertiesTableName);
if (itMPT == materialPropertiesTableMap.end()) { // G4MaterialPropertiesTable of this name does not exist yet --> create it
MPT_tmp = new G4MaterialPropertiesTable();
materialPropertiesTableMap.insert(std::pair<std::string, G4MaterialPropertiesTable *>(materialPropertiesTableName, MPT_tmp));
} else {
MPT_tmp = itMPT->second;
}
std::string propertyName;
int nEntries;
lineStream >> propertyName >> nEntries;
if (nEntries == 0) { // AddConstProperty
double value;
lineStream >> value;
MPT_tmp->AddConstProperty(propertyName, value);
if ((propertyName == "FASTSCINTILLATIONRISETIME") || (propertyName == "SLOWSCINTILLATIONRISETIME")) {
if (value != 0) {
musrParameters::finiteRiseTimeInScintillator = true;
}
}
} else { // AddProperty
double value;
std::vector<G4double> photonEnergies;
std::vector<G4double> values;
for (int i = 0; i < nEntries; i++) {
lineStream >> value;
photonEnergies.push_back(value);
}
for (int i = 0; i < nEntries; i++) {
lineStream >> value;
values.push_back(value);
}
MPT_tmp->AddProperty(propertyName, photonEnergies, values, nEntries);
}
} else if (subcommand == "setMaterialPropertiesTable") {
std::string materialName = "Unset";
std::string materialPropertiesTableName = arg;
lineStream >> materialName;
G4NistManager *man = G4NistManager::Instance();
G4Material *myMaterial = man->FindOrBuildMaterial(materialName);
G4MaterialPropertiesTable *MPT_tmp = nullptr;
itMPT = materialPropertiesTableMap.find(materialPropertiesTableName);
if (itMPT == materialPropertiesTableMap.end()) { // G4MaterialPropertiesTable of this name does not exist --> problem
G4cout << "\n\n musrDetectorConstruction::DefineMaterials(): Material Properties Table \"" << materialPropertiesTableName
<< "\" should be assigned to material \"" << materialName << "\"" << G4endl;
G4cout << " but the table was not defined yet (by command /musr/command "
"materialPropertiesTable )"
<< G4endl;
G4cout << " ===> S T O P F O R C E D" << G4endl;
G4cout << line << G4endl;
exit(1);
} else {
MPT_tmp = itMPT->second;
}
myMaterial->SetMaterialPropertiesTable(MPT_tmp);
}
}
}
+1 -1
View File
@@ -45,7 +45,7 @@ musrParameters::musrParameters(G4String steeringFileName)
// Read in the parameters, which have to be known before the detector construction is run
// (and therefore the parameters can not be read in in the musrDetectorConstruction.cc class).
std::ifstream steeringFile(steeringFileName.c_str());
std::ifstream steeringFile(steeringFileName);
if (!steeringFile.is_open()) {
G4cout<<"musrParameters::musrParameters: steeringFileName=\""<<steeringFileName
<<"\" not opened for some reason."<<G4endl;
+480 -480
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -461,7 +461,7 @@ void musrPrimaryGeneratorAction::SetMuonDecayTimeLimits(G4ThreeVector decayTimeL
//===============================================================================
void musrPrimaryGeneratorAction::SetTurtleInput(G4String turtleFileName) {
takeMuonsFromTurtleFile = true;
fTurtleFile = std::make_unique<std::ifstream>(turtleFileName.c_str());
fTurtleFile = std::make_unique<std::ifstream>(turtleFileName);
if (!fTurtleFile->is_open()) {
G4cout << "E R R O R : Failed to open TURTLE input file \"" << turtleFileName
<<"\"."<< G4endl;