From 5d2c65a00535efb8185ec8787de6d17cf3092230 Mon Sep 17 00:00:00 2001 From: Julian Wollrath Date: Thu, 13 Aug 2026 14:31:20 +0200 Subject: [PATCH] Simplify ignoring empty and commented lines in steering file --- src/musrDetectorConstruction.cc | 312 +++++----- src/musrParameters.cc | 2 +- src/musrPhysicsList.cc | 960 +++++++++++++++--------------- src/musrPrimaryGeneratorAction.cc | 2 +- 4 files changed, 638 insertions(+), 638 deletions(-) diff --git a/src/musrDetectorConstruction.cc b/src/musrDetectorConstruction.cc index 12c7c16..d34bd58 100644 --- a/src/musrDetectorConstruction.cc +++ b/src/musrDetectorConstruction.cc @@ -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(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 photonEnergies; - std::vector 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(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 photonEnergies; + std::vector 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); } } } diff --git a/src/musrParameters.cc b/src/musrParameters.cc index c4f8254..f3da5d3 100644 --- a/src/musrParameters.cc +++ b/src/musrParameters.cc @@ -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=\""<SetWLSTimeProfile("delta"); - // - // opticalPhysics->SetScintillationYieldFactor(1.0); - // opticalPhysics->SetScintillationExcitationRatio(0.0); - // - // opticalPhysics->SetMaxNumPhotonsPerStep(100); - // opticalPhysics->SetMaxBetaChangePerStep(10.0); - // - // opticalPhysics->SetTrackSecondariesFirst(true); - } + defaultCutValue = 0.1 * CLHEP::mm; + cutForGamma = 0.1 * CLHEP::mm; + cutForElectron = 0.1 * CLHEP::mm; + cutForMuon = 0.01 * CLHEP::mm; + SetVerboseLevel(0); + if (musrParameters::boolG4OpticalPhotons) { + // // * Optical Physics + // G4OpticalPhysics* opticalPhysics = new G4OpticalPhysics(); + // RegisterPhysics( opticalPhysics ); + // + // // adjust some parameters for the optical physics + // opticalPhysics->SetWLSTimeProfile("delta"); + // + // opticalPhysics->SetScintillationYieldFactor(1.0); + // opticalPhysics->SetScintillationExcitationRatio(0.0); + // + // opticalPhysics->SetMaxNumPhotonsPerStep(100); + // opticalPhysics->SetMaxBetaChangePerStep(10.0); + // + // opticalPhysics->SetTrackSecondariesFirst(true); + } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... -musrPhysicsList::~musrPhysicsList() -{} +musrPhysicsList::~musrPhysicsList() {} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void musrPhysicsList::ConstructParticle() { + ConstructBosons(); + ConstructLeptons(); + ConstructMesons(); + ConstructBaryons(); - ConstructBosons(); - ConstructLeptons(); - ConstructMesons(); - ConstructBaryons(); - - if (musrParameters::boolG4OpticalPhotons) { - // optical photon - G4OpticalPhoton::OpticalPhotonDefinition(); - } - - + if (musrParameters::boolG4OpticalPhotons) { + // optical photon + G4OpticalPhoton::OpticalPhotonDefinition(); + } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void musrPhysicsList::ConstructBosons() { - // pseudo-particles - G4Geantino::GeantinoDefinition(); - G4ChargedGeantino::ChargedGeantinoDefinition(); + // pseudo-particles + G4Geantino::GeantinoDefinition(); + G4ChargedGeantino::ChargedGeantinoDefinition(); - // gamma - G4Gamma::GammaDefinition(); + // gamma + G4Gamma::GammaDefinition(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void musrPhysicsList::ConstructLeptons() { - // leptons - // e+/- - G4Electron::ElectronDefinition(); - G4Positron::PositronDefinition(); - // mu+/- - G4MuonPlus::MuonPlusDefinition(); - G4MuonMinus::MuonMinusDefinition(); - //cks - // G4DecayTable* MuonPlusDecayTable = new G4DecayTable(); - // MuonPlusDecayTable -> Insert(new musrMuonDecayChannel("mu+",1.00)); - // G4MuonPlus::MuonPlusDefinition() -> SetDecayTable(MuonPlusDecayTable); - //csk - // - // Muonium - TS - musrMuonium::MuoniumDefinition(); - // - // nu_e - G4NeutrinoE::NeutrinoEDefinition(); - G4AntiNeutrinoE::AntiNeutrinoEDefinition(); - // nu_mu - G4NeutrinoMu::NeutrinoMuDefinition(); - G4AntiNeutrinoMu::AntiNeutrinoMuDefinition(); + // leptons + // e+/- + G4Electron::ElectronDefinition(); + G4Positron::PositronDefinition(); + // mu+/- + G4MuonPlus::MuonPlusDefinition(); + G4MuonMinus::MuonMinusDefinition(); + // cks + // G4DecayTable* MuonPlusDecayTable = new G4DecayTable(); + // MuonPlusDecayTable -> Insert(new musrMuonDecayChannel("mu+",1.00)); + // G4MuonPlus::MuonPlusDefinition() -> SetDecayTable(MuonPlusDecayTable); + // csk + // + // Muonium - TS + musrMuonium::MuoniumDefinition(); + // + // nu_e + G4NeutrinoE::NeutrinoEDefinition(); + G4AntiNeutrinoE::AntiNeutrinoEDefinition(); + // nu_mu + G4NeutrinoMu::NeutrinoMuDefinition(); + G4AntiNeutrinoMu::AntiNeutrinoMuDefinition(); - //cks: Trial to use Geant4 muon decay with spin - G4DecayTable* MuonPlusDecayTable = new G4DecayTable(); - // MuonPlusDecayTable -> Insert(new G4MuonDecayChannelWithSpin("mu+",1.00)); - MuonPlusDecayTable -> Insert(new G4MuonDecayChannelWithSpin("mu+",0.986)); - MuonPlusDecayTable -> Insert(new G4MuonRadiativeDecayChannelWithSpin("mu+",0.014)); - G4MuonPlus::MuonPlusDefinition() -> SetDecayTable(MuonPlusDecayTable); - // - G4DecayTable* MuonMinusDecayTable = new G4DecayTable(); - // MuonMinusDecayTable -> Insert(new G4MuonDecayChannelWithSpin("mu-",1.00)); - MuonMinusDecayTable -> Insert(new G4MuonDecayChannelWithSpin("mu-",0.986)); - MuonMinusDecayTable -> Insert(new G4MuonRadiativeDecayChannelWithSpin("mu-",0.014)); - G4MuonMinus::MuonMinusDefinition() -> SetDecayTable(MuonMinusDecayTable); - //csk - // - //TS: Using the muonium decay with and without spin - G4DecayTable* MuoniumDecayTable = new G4DecayTable(); - MuoniumDecayTable -> Insert(new MuDecayChannel("Mu",0.50)); - MuoniumDecayTable -> Insert(new MuDecayChannelWithSpin("Mu",0.5)); - musrMuonium::MuoniumDefinition() -> SetDecayTable(MuoniumDecayTable); - //MuoniumDecayTable ->DumpInfo(); // Info on muonium decay channels + // cks: Trial to use Geant4 muon decay with spin + G4DecayTable *MuonPlusDecayTable = new G4DecayTable(); + // MuonPlusDecayTable -> Insert(new G4MuonDecayChannelWithSpin("mu+",1.00)); + MuonPlusDecayTable->Insert(new G4MuonDecayChannelWithSpin("mu+", 0.986)); + MuonPlusDecayTable->Insert(new G4MuonRadiativeDecayChannelWithSpin("mu+", 0.014)); + G4MuonPlus::MuonPlusDefinition()->SetDecayTable(MuonPlusDecayTable); + // + G4DecayTable *MuonMinusDecayTable = new G4DecayTable(); + // MuonMinusDecayTable -> Insert(new G4MuonDecayChannelWithSpin("mu-",1.00)); + MuonMinusDecayTable->Insert(new G4MuonDecayChannelWithSpin("mu-", 0.986)); + MuonMinusDecayTable->Insert(new G4MuonRadiativeDecayChannelWithSpin("mu-", 0.014)); + G4MuonMinus::MuonMinusDefinition()->SetDecayTable(MuonMinusDecayTable); + // csk + // + // TS: Using the muonium decay with and without spin + G4DecayTable *MuoniumDecayTable = new G4DecayTable(); + MuoniumDecayTable->Insert(new MuDecayChannel("Mu", 0.50)); + MuoniumDecayTable->Insert(new MuDecayChannelWithSpin("Mu", 0.5)); + musrMuonium::MuoniumDefinition()->SetDecayTable(MuoniumDecayTable); + // MuoniumDecayTable ->DumpInfo(); // Info on muonium decay channels } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void musrPhysicsList::ConstructMesons() { - // mesons - // light mesons - G4PionPlus::PionPlusDefinition(); - G4PionMinus::PionMinusDefinition(); - G4PionZero::PionZeroDefinition(); - G4Eta::EtaDefinition(); - G4EtaPrime::EtaPrimeDefinition(); - G4KaonPlus::KaonPlusDefinition(); - G4KaonMinus::KaonMinusDefinition(); - G4KaonZero::KaonZeroDefinition(); - G4AntiKaonZero::AntiKaonZeroDefinition(); - G4KaonZeroLong::KaonZeroLongDefinition(); - G4KaonZeroShort::KaonZeroShortDefinition(); + // mesons + // light mesons + G4PionPlus::PionPlusDefinition(); + G4PionMinus::PionMinusDefinition(); + G4PionZero::PionZeroDefinition(); + G4Eta::EtaDefinition(); + G4EtaPrime::EtaPrimeDefinition(); + G4KaonPlus::KaonPlusDefinition(); + G4KaonMinus::KaonMinusDefinition(); + G4KaonZero::KaonZeroDefinition(); + G4AntiKaonZero::AntiKaonZeroDefinition(); + G4KaonZeroLong::KaonZeroLongDefinition(); + G4KaonZeroShort::KaonZeroShortDefinition(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void musrPhysicsList::ConstructBaryons() { - // baryons - G4Proton::ProtonDefinition(); - G4AntiProton::AntiProtonDefinition(); + // baryons + G4Proton::ProtonDefinition(); + G4AntiProton::AntiProtonDefinition(); - G4Neutron::NeutronDefinition(); - G4AntiNeutron::AntiNeutronDefinition(); + G4Neutron::NeutronDefinition(); + G4AntiNeutron::AntiNeutronDefinition(); - // ions - G4IonConstructor iConstructor; - iConstructor.ConstructParticle(); + // ions + G4IonConstructor iConstructor; + iConstructor.ConstructParticle(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void musrPhysicsList::ConstructProcess() { - AddTransportation(); - ConstructEM(); - ConstructGeneral(); + AddTransportation(); + ConstructEM(); + ConstructGeneral(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -237,30 +230,30 @@ void musrPhysicsList::ConstructProcess() #include "G4UserSpecialCuts.hh" -//#include "musrAtRestSpinRotation.hh" +// #include "musrAtRestSpinRotation.hh" -//cks 14.12.2011 // For low energy physics processes: -//cks 14.12.2011 #include "G4LowEnergyCompton.hh" -//cks 14.12.2011 //#include "G4LowEnergyPolarizedCompton.hh" -//cks 14.12.2011 #include "G4LowEnergyGammaConversion.hh" -//cks 14.12.2011 #include "G4LowEnergyPhotoElectric.hh" -//cks 14.12.2011 #include "G4LowEnergyRayleigh.hh" -//cks 14.12.2011 #include "G4LowEnergyBremsstrahlung.hh" -//cks 14.12.2011 #include "G4LowEnergyIonisation.hh" -//cks 14.12.2011 #include "G4hLowEnergyIonisation.hh" +// cks 14.12.2011 // For low energy physics processes: +// cks 14.12.2011 #include "G4LowEnergyCompton.hh" +// cks 14.12.2011 //#include "G4LowEnergyPolarizedCompton.hh" +// cks 14.12.2011 #include "G4LowEnergyGammaConversion.hh" +// cks 14.12.2011 #include "G4LowEnergyPhotoElectric.hh" +// cks 14.12.2011 #include "G4LowEnergyRayleigh.hh" +// cks 14.12.2011 #include "G4LowEnergyBremsstrahlung.hh" +// cks 14.12.2011 #include "G4LowEnergyIonisation.hh" +// cks 14.12.2011 #include "G4hLowEnergyIonisation.hh" -//cks 14.12.2011 // For Penelope processes: -//cks 14.12.2011 #include "G4PenelopeCompton.hh" -//cks 14.12.2011 #include "G4PenelopeGammaConversion.hh" -//cks 14.12.2011 #include "G4PenelopePhotoElectric.hh" -//cks 14.12.2011 #include "G4PenelopeRayleigh.hh" -//cks 14.12.2011 #include "G4PenelopeIonisation.hh" -//cks 14.12.2011 #include "G4PenelopeBremsstrahlung.hh" -//cks 14.12.2011 #include "G4PenelopeAnnihilation.hh" +// cks 14.12.2011 // For Penelope processes: +// cks 14.12.2011 #include "G4PenelopeCompton.hh" +// cks 14.12.2011 #include "G4PenelopeGammaConversion.hh" +// cks 14.12.2011 #include "G4PenelopePhotoElectric.hh" +// cks 14.12.2011 #include "G4PenelopeRayleigh.hh" +// cks 14.12.2011 #include "G4PenelopeIonisation.hh" +// cks 14.12.2011 #include "G4PenelopeBremsstrahlung.hh" +// cks 14.12.2011 #include "G4PenelopeAnnihilation.hh" // For Coulomb scattering instead of multiple scattering #include "G4CoulombScattering.hh" -//cks 14.12.2011 #include "G4CoulombScatteringModel.hh" +// cks 14.12.2011 #include "G4CoulombScatteringModel.hh" // For Muonium formation in the Carbon foil #include "musrMuFormation.hh" // includes the yield function Y = Y(E). @@ -278,9 +271,9 @@ void musrPhysicsList::ConstructProcess() // For models #include "G4ProcessTable.hh" #include "G4WentzelVIModel.hh" -//#include "G4UrbanMscModel90.hh" -//cks 14.12.2011 #include "G4UrbanMscModel92.hh" -//#include "G4UrbanMscModel93.hh" +// #include "G4UrbanMscModel90.hh" +// cks 14.12.2011 #include "G4UrbanMscModel92.hh" +// #include "G4UrbanMscModel93.hh" #include "G4UrbanMscModel.hh" #include @@ -288,329 +281,335 @@ void musrPhysicsList::ConstructProcess() void musrPhysicsList::ConstructEM() { - // cks 2008.08.22. - Adding the possibility to define the processes from the steering file: - std::ifstream steeringFile(musrParameters::mySteeringFileName.c_str()); - if (!steeringFile.is_open()) { - eMessage = "musrPhysicsList::ConstructEM(): Failed to open macro file \"" + musrParameters::mySteeringFileName + "\" ."; - musrErrorMessage::GetInstance()->musrError(FATAL,eMessage,false); - } - else {G4cout<<"musrPhysicsList: The Physics processes are being defined:"<> command >> subcommand >> option)) continue; - if ((command!="/musr/ignore")&&(command!="/musr/command")) continue; - if (subcommand!="process") continue; - - float tmpCutValue; - if ((option=="addProcess")||(option=="addDiscreteProcess")|| - (option=="addModel")||(option=="SetLossFluctuations_OFF")) { - std::string charParticleName, charProcessName; - - if (!(lineStream >> charParticleName >> charProcessName)) { - ReportProblemWithProcessDefinition(line); - } - - G4cout<<"musrPhysicsList: Defining process "< FindParticle(stringParticleName); - - if (particleDefinition==nullptr) { - if ((stringParticleName=="opticalphoton")&& (!(musrParameters::boolG4OpticalPhotons))) { - musrErrorMessage::GetInstance()->musrError(INFO, - "musrPhysicsList: Ignoring optical photon process definition because G4OpticalPhotons in *.mac file is set to false",false); - continue; - } - eMessage = std::string("musrPhysicsList: Partile \"") + charParticleName + "\" not found in G4ParticleTable when trying to find or assign process \"" + charProcessName + "\"."; - musrErrorMessage::GetInstance()->musrError(FATAL,eMessage,false); - } - G4ProcessManager* pManager = particleDefinition->GetProcessManager(); - - if (option=="addDiscreteProcess") { - if (stringProcessName=="G4PhotoElectricEffect") pManager->AddDiscreteProcess(new G4PhotoElectricEffect); - else if (stringProcessName=="G4ComptonScattering") pManager->AddDiscreteProcess(new G4ComptonScattering); - else if (stringProcessName=="G4GammaConversion") pManager->AddDiscreteProcess(new G4GammaConversion); - else if (stringProcessName=="G4RayleighScattering") pManager->AddDiscreteProcess(new G4RayleighScattering); -//cks 14.12.2011 else if (stringProcessName=="G4PenelopePhotoElectric") pManager->AddDiscreteProcess(new G4PenelopePhotoElectric); -//cks 14.12.2011 else if (stringProcessName=="G4PenelopeCompton") pManager->AddDiscreteProcess(new G4PenelopeCompton); -//cks 14.12.2011 else if (stringProcessName=="G4PenelopeGammaConversion") pManager->AddDiscreteProcess(new G4PenelopeGammaConversion); -//cks 14.12.2011 else if (stringProcessName=="G4PenelopeRayleigh") pManager->AddDiscreteProcess(new G4PenelopeRayleigh); -//cks 14.12.2011 else if (stringProcessName=="G4LowEnergyPhotoElectric") pManager->AddDiscreteProcess(new G4LowEnergyPhotoElectric); -//cks 14.12.2011 else if (stringProcessName=="G4LowEnergyCompton") pManager->AddDiscreteProcess(new G4LowEnergyCompton); -//cks 14.12.2011 else if (stringProcessName=="G4LowEnergyGammaConversion") pManager->AddDiscreteProcess(new G4LowEnergyGammaConversion); -//cks 14.12.2011 else if (stringProcessName=="G4LowEnergyRayleigh") pManager->AddDiscreteProcess(new G4LowEnergyRayleigh); - - else if (stringProcessName=="G4CoulombScattering") pManager->AddDiscreteProcess(new G4CoulombScattering); - else if (stringProcessName=="G4OpAbsorption") pManager->AddDiscreteProcess(new G4OpAbsorption); - else if (stringProcessName=="G4OpRayleigh") pManager->AddDiscreteProcess(new G4OpRayleigh); - else if (stringProcessName=="G4OpBoundaryProcess") pManager->AddDiscreteProcess(new G4OpBoundaryProcess); - else if (stringProcessName=="G4OpWLS") pManager->AddDiscreteProcess(new G4OpWLS); - else if (stringProcessName=="G4Cerenkov") { - G4Cerenkov* myCerenkov = new G4Cerenkov(); - myCerenkov->SetMaxNumPhotonsPerStep(20); // settings from GEANT example N06 - myCerenkov->SetMaxBetaChangePerStep(10.0); - myCerenkov->SetTrackSecondariesFirst(false); // as for Scintillation, do main high energy particles first - pManager->AddDiscreteProcess(myCerenkov); // added JSL - } - else { - eMessage = std::string("musrPhysicsList: Process \"") + charProcessName + - "\" is not implemented in musrPhysicsList.cc for addDiscreteProcess. It can be easily added."; - musrErrorMessage::GetInstance()->musrError(FATAL,eMessage,false); - } - } - else if (option=="addProcess") { - G4int nr1, nr2, nr3; - std::string charRegion1, charRegion2, charRegion3, charControlString; - - if (!(lineStream >> nr1 >> nr2 >> nr3)) { - ReportProblemWithProcessDefinition(line); - } - lineStream >> charRegion1 >> charRegion2 >> charRegion3 >> charControlString; - - if (stringProcessName=="G4eMultipleScattering") pManager->AddProcess(new G4eMultipleScattering,nr1,nr2,nr3); - else if (stringProcessName=="G4eIonisation") pManager->AddProcess(new G4eIonisation,nr1,nr2,nr3); - else if (stringProcessName=="G4eBremsstrahlung") pManager->AddProcess(new G4eBremsstrahlung,nr1,nr2,nr3); - else if (stringProcessName=="G4eplusAnnihilation") pManager->AddProcess(new G4eplusAnnihilation,nr1,nr2,nr3); -//cks 14.12.2011 else if (stringProcessName=="G4PenelopeIonisation") pManager->AddProcess(new G4PenelopeIonisation,nr1,nr2,nr3); -//cks 14.12.2011 else if (stringProcessName=="G4PenelopeBremsstrahlung") pManager->AddProcess(new G4PenelopeBremsstrahlung,nr1,nr2,nr3); -//cks 14.12.2011 else if (stringProcessName=="G4PenelopeAnnihilation") pManager->AddProcess(new G4PenelopeAnnihilation,nr1,nr2,nr3); - // else if (stringProcessName=="G4LowEnergyIonisation") pManager->AddProcess(new G4LowEnergyIonisation,nr1,nr2,nr3); - // else if (stringProcessName=="G4LowEnergyBremsstrahlung") pManager->AddProcess(new G4LowEnergyBremsstrahlung,nr1,nr2,nr3); - else if (stringProcessName=="G4MuMultipleScattering") pManager->AddProcess(new G4MuMultipleScattering,nr1,nr2,nr3); - else if (stringProcessName=="G4MuIonisation") pManager->AddProcess(new G4MuIonisation,nr1,nr2,nr3); - else if (stringProcessName=="G4MuBremsstrahlung") pManager->AddProcess(new G4MuBremsstrahlung,nr1,nr2,nr3); - else if (stringProcessName=="G4MuPairProduction") pManager->AddProcess(new G4MuPairProduction,nr1,nr2,nr3); - // cks 2009-06-08 G4StepLimiter and/or G4UserSpecialCuts are needed to activate the "G4UserLimits" - else if (stringProcessName=="G4StepLimiter") pManager->AddProcess(new G4StepLimiter,nr1,nr2,nr3); - else if (stringProcessName=="G4UserSpecialCuts") pManager->AddProcess(new G4UserSpecialCuts,nr1,nr2,nr3); -// else if (stringProcessName=="G4DecayWithSpin") pManager->AddProcess(new G4DecayWithSpin,nr1,nr2,nr3); - // else if (stringProcessName=="G4hIonisation") pManager->AddProcess(new G4hIonisation,nr1,nr2,nr3); - // else if (stringProcessName=="G4hLowEnergyIonisation") pManager->AddProcess(new G4hLowEnergyIonisation,nr1,nr2,nr3); - else if (stringProcessName=="musrMuFormation") pManager->AddProcess(new musrMuFormation,nr1,nr2,nr3); - else if (stringProcessName=="musrMuEnergyLossLandau") pManager->AddProcess(new musrMuEnergyLossLandau,nr1,nr2,nr3); - else if (stringProcessName=="G4Scintillation") { - G4Scintillation* myScintillation = new G4Scintillation(); - // if (musrParameters::finiteRiseTimeInScintillator) myScintillation->SetFiniteRiseTime(true); - pManager->AddProcess(myScintillation,nr1,nr2,nr3); - } - else if (stringProcessName=="G4Cerenkov") { - G4Cerenkov* myCerenkov = new G4Cerenkov(); - myCerenkov->SetMaxNumPhotonsPerStep(20); // settings from GEANT example N06 - myCerenkov->SetMaxBetaChangePerStep(10.0); - myCerenkov->SetTrackSecondariesFirst(false); // as for Scintillation, do main high energy particles first - pManager->AddProcess(myCerenkov,nr1,nr2,nr3); // added JSL - pManager->SetProcessOrdering(myCerenkov,idxPostStep); // from Example N06 - } - // cks: musrMuScatter could be uncommented here, but testing is needed, because Toni has some strange comments - // in his original "musrPhysicsList.cc about implementing musrMuScatter. - // else if (stringProcessName=="musrMuScatter") pManager->AddProcess(new musrMuScatter,nr1,nr2,nr3); - // - // The G4MultipleScattering is obsolete in Geant4.9.4 - // else if (stringProcessName=="MultipleAndCoulombScattering") { - // G4MultipleScattering* multScat = new G4MultipleScattering(); - // // G4CoulombScattering* coulScat = new G4CoulombScattering(); - // G4CoulombScatteringModel* coulScatModel = new G4CoulombScatteringModel(); - // if (strcmp(charRegion1,"")!=0) { - // G4Region* regionForCoulomb = FindG4Region(charRegion1,line); - // G4cout<<" Adding Coulomb scattering model to multiple scattering model for region "<AddEmModel(0,coulScatModel,regionForCoulomb); - // // multScat->AddEmModel(0,multScat,regionForCoulomb); - // } - // if (strcmp(charRegion2,"")!=0) { - // G4Region* regionForCoulomb = FindG4Region(charRegion2,line); - // G4cout<<" Adding Coulomb scattering model to multiple scattering model for region "<AddEmModel(0,coulScatModel,regionForCoulomb); - // } - // if (strcmp(charRegion3,"")!=0) { - // G4Region* regionForCoulomb = FindG4Region(charRegion3,line); - // G4cout<<" Adding Coulomb scattering model to multiple scattering model for region "<AddEmModel(0,coulScatModel,regionForCoulomb); - // } - // if (strcmp(charControlString,"")!=0) { - // G4cout<<"More than 3 regions requested for Coulomb Scattering, but presently only up to 3 such regions are supported."<AddProcess(multScat,nr1,nr2,nr3); - // } - else { - eMessage = std::string("musrPhysicsList: Process \"") + charProcessName + - "\" is not implemented in musrPhysicsList.cc for addProcess. It can be easily added."; - musrErrorMessage::GetInstance()->musrError(FATAL,eMessage,false); - } - } - else if (option=="addModel") { - G4ProcessTable* processTable = G4ProcessTable::GetProcessTable(); - // G4VProcess* myProc = processTable->FindProcess(charProcessName,particleDefinition); - // pManager - - G4int modelPriority; - std::string charModelName; - if (!(lineStream >> charModelName >> modelPriority)) { - ReportProblemWithProcessDefinition(line); - } - G4String stringModelName = charModelName; - G4cout<<" Adding model "<musrError(FATAL,eMessage,false); - // } - if ((stringModelName=="G4WentzelVIModel")&&(stringProcessName=="G4MuMultipleScattering")) { - G4MuMultipleScattering* mmm = (G4MuMultipleScattering*) processTable->FindProcess("muMsc",particleDefinition); - mmm->AddEmModel(modelPriority, new G4WentzelVIModel()); - } - else if ((stringModelName=="G4UrbanMscModel")&&(stringProcessName=="G4MuMultipleScattering")) { - G4MuMultipleScattering* mmm = (G4MuMultipleScattering*) processTable->FindProcess("muMsc",particleDefinition); - mmm->AddEmModel(modelPriority, new G4UrbanMscModel()); - } -//cks 14.12.2011 else if ((stringModelName=="G4UrbanMscModel92")&&(stringProcessName=="G4MuMultipleScattering")) { -//cks 14.12.2011 G4MuMultipleScattering* mmm = (G4MuMultipleScattering*) processTable->FindProcess("muMsc",particleDefinition); -//cks 14.12.2011 mmm->AddEmModel(modelPriority, new G4UrbanMscModel92()); -//cks 14.12.2011 } -// else if ((stringModelName=="G4UrbanMscModel93")&&(stringProcessName=="G4MuMultipleScattering")) { -// G4MuMultipleScattering* mmm = (G4MuMultipleScattering*) processTable->FindProcess("muMsc",particleDefinition); -// mmm->AddEmModel(modelPriority, new G4UrbanMscModel93()); -// } - else { - eMessage = std::string("musrPhysicsList: Model \"") + charModelName + - "\" is not implemented for \"" + charProcessName + "\" in musrPhysicsList.cc for addModel. It can be easily added."; - musrErrorMessage::GetInstance()->musrError(FATAL,eMessage,false); - } - - } - - else if (option=="SetLossFluctuations_OFF") { - G4ProcessTable* processTable = G4ProcessTable::GetProcessTable(); - if (charProcessName=="G4eIonisation") { - G4cout<<"musrPhysicsList.cc: Switching off loss fluctuations for "<FindProcess("eIoni",particleDefinition); - mmm->SetLossFluctuations(false); - } - else if (charProcessName=="G4MuIonisation") { - G4cout<<"musrPhysicsList.cc: Switching off loss fluctuations for "<FindProcess("muIoni",particleDefinition); - mmm->SetLossFluctuations(false); - } - else { - G4cout<<"musrPhysicsList.cc: Switching off loss fluctuations for " - <> tmpCutValue)) { - ReportProblemWithProcessDefinition(line); - } - cutForGamma = tmpCutValue; - } - - else if (option=="cutForElectron") { - if (!(lineStream >> tmpCutValue)) { - ReportProblemWithProcessDefinition(line); - } - cutForElectron = tmpCutValue; - } - - //cks UNFORTUNATELY cutForMuon does not work!!! - // else if (strcmp(option,"cutForMuon")==0) { - // sscanf(&line[0],"%*s %*s %*s %g",&tmpCutValue); - // cutForMuon = tmpCutValue; - // } - - - else ReportProblemWithProcessDefinition(line); - } - } - G4cout<<"\n\n\n\n"<GetMyTypeOfProcesses(); - //del G4cout<<"musrPhysicsList::ConstructEM(): myTypeOfProcesses="<reset(); - while( (*GetParticleIterator())() ){ - G4ParticleDefinition* particle = GetParticleIterator()->value(); - G4ProcessManager* pmanager = particle->GetProcessManager(); - G4String particleName = particle->GetParticleName(); - - if ((particleName == "gamma")||(particleName == "e-")||(particleName == "e+")) { - // do nothing - } - - else if ((particleName=="mu+")||(particleName=="mu-")) { //muon - G4DecayWithSpin* theDecayProcess = new G4DecayWithSpin(); - // theDecayProcess->SetVerboseLevel(2); - pmanager->AddProcess(theDecayProcess); - pmanager ->SetProcessOrderingToLast(theDecayProcess, idxAtRest); - pmanager ->SetProcessOrdering(theDecayProcess, idxPostStep); + if (!steeringFile.is_open()) { + musrErrorMessage::GetInstance()->musrError( + FATAL, "musrPhysicsList::ConstructEM(): Failed to open macro file \"" + musrParameters::mySteeringFileName + "\" .", false); + } else { + G4cout << "musrPhysicsList: The Physics processes are being defined:" << G4endl; } - else if (particleName=="Mu") { - // TS: - // Muonium "scattering" Kamil: the following 3 lines could be replaced by reading the musrMuScatter - // process through the steering file - G4VProcess* aMuScatt = new musrMuScatter(); - pmanager->AddProcess(aMuScatt); - pmanager->SetProcessOrdering(aMuScatt, idxPostStep, 1); - // - G4Decay* theDecayProcess = new G4Decay(); - //musrDecayWithSpin* theDecayProcess = new musrDecayWithSpin(); - pmanager->AddProcess(theDecayProcess); - pmanager->SetProcessOrderingToLast(theDecayProcess, idxAtRest); - pmanager->SetProcessOrdering(theDecayProcess, idxPostStep); + std::vector steeringLines; + std::string line; + + while (std::getline(steeringFile, line)) { + if (!line.empty() && (line.at(0) != '#')) + steeringLines.push_back(line); } - - - else if ((!particle->IsShortLived()) && - (particle->GetPDGCharge() != 0.0) && - (particle->GetParticleName() != "chargedgeantino")) { - //all others charged particles except geantino - pmanager->AddProcess(new G4hMultipleScattering,-1, 1,1); - // if (myTypeOfProcesses=="highenergy") { - // pmanager->AddProcess(new G4hIonisation, -1, 2,2); - // } - // else { - pmanager->AddProcess(new G4hIonisation, -1, 2,2); - // } - ///pmanager->AddProcess(new G4UserSpecialCuts, -1,-1,3); + + steeringFile.close(); + + for (const auto &line : steeringLines) { + std::istringstream lineStream(line); + std::string command, subcommand, option; + + if (!(lineStream >> command >> subcommand >> option)) + continue; + if ((command != "/musr/ignore") && (command != "/musr/command")) + continue; + if (subcommand != "process") + continue; + + float tmpCutValue; + if ((option == "addProcess") || (option == "addDiscreteProcess") || (option == "addModel") || (option == "SetLossFluctuations_OFF")) { + std::string charParticleName, charProcessName; + + if (!(lineStream >> charParticleName >> charProcessName)) { + ReportProblemWithProcessDefinition(line); + } + + G4cout << "musrPhysicsList: Defining process " << charProcessName << " for " << charParticleName << G4endl; + G4String stringProcessName = charProcessName; + G4String stringParticleName = charParticleName; + G4ParticleDefinition *particleDefinition = G4ParticleTable::GetParticleTable()->FindParticle(stringParticleName); + + if (particleDefinition == nullptr) { + if ((stringParticleName == "opticalphoton") && (!(musrParameters::boolG4OpticalPhotons))) { + musrErrorMessage::GetInstance()->musrError( + INFO, "musrPhysicsList: Ignoring optical photon process definition because G4OpticalPhotons in *.mac file is set to false", + false); + continue; + } + eMessage = std::string("musrPhysicsList: Partile \"") + charParticleName + + "\" not found in G4ParticleTable when trying to find or assign process \"" + charProcessName + "\"."; + musrErrorMessage::GetInstance()->musrError(FATAL, eMessage, false); + } + G4ProcessManager *pManager = particleDefinition->GetProcessManager(); + + if (option == "addDiscreteProcess") { + if (stringProcessName == "G4PhotoElectricEffect") + pManager->AddDiscreteProcess(new G4PhotoElectricEffect); + else if (stringProcessName == "G4ComptonScattering") + pManager->AddDiscreteProcess(new G4ComptonScattering); + else if (stringProcessName == "G4GammaConversion") + pManager->AddDiscreteProcess(new G4GammaConversion); + else if (stringProcessName == "G4RayleighScattering") + pManager->AddDiscreteProcess(new G4RayleighScattering); + // cks 14.12.2011 else if (stringProcessName=="G4PenelopePhotoElectric") pManager->AddDiscreteProcess(new + // G4PenelopePhotoElectric); cks 14.12.2011 else if (stringProcessName=="G4PenelopeCompton") + // pManager->AddDiscreteProcess(new G4PenelopeCompton); cks 14.12.2011 else if + // (stringProcessName=="G4PenelopeGammaConversion") pManager->AddDiscreteProcess(new G4PenelopeGammaConversion); cks 14.12.2011 + // else if (stringProcessName=="G4PenelopeRayleigh") pManager->AddDiscreteProcess(new G4PenelopeRayleigh); cks 14.12.2011 + // else if (stringProcessName=="G4LowEnergyPhotoElectric") pManager->AddDiscreteProcess(new G4LowEnergyPhotoElectric); + // cks 14.12.2011 else if (stringProcessName=="G4LowEnergyCompton") pManager->AddDiscreteProcess(new + // G4LowEnergyCompton); cks 14.12.2011 else if (stringProcessName=="G4LowEnergyGammaConversion") + // pManager->AddDiscreteProcess(new G4LowEnergyGammaConversion); cks 14.12.2011 else if + // (stringProcessName=="G4LowEnergyRayleigh") pManager->AddDiscreteProcess(new G4LowEnergyRayleigh); + + else if (stringProcessName == "G4CoulombScattering") + pManager->AddDiscreteProcess(new G4CoulombScattering); + else if (stringProcessName == "G4OpAbsorption") + pManager->AddDiscreteProcess(new G4OpAbsorption); + else if (stringProcessName == "G4OpRayleigh") + pManager->AddDiscreteProcess(new G4OpRayleigh); + else if (stringProcessName == "G4OpBoundaryProcess") + pManager->AddDiscreteProcess(new G4OpBoundaryProcess); + else if (stringProcessName == "G4OpWLS") + pManager->AddDiscreteProcess(new G4OpWLS); + else if (stringProcessName == "G4Cerenkov") { + G4Cerenkov *myCerenkov = new G4Cerenkov(); + myCerenkov->SetMaxNumPhotonsPerStep(20); // settings from GEANT example N06 + myCerenkov->SetMaxBetaChangePerStep(10.0); + myCerenkov->SetTrackSecondariesFirst(false); // as for Scintillation, do main high energy particles first + pManager->AddDiscreteProcess(myCerenkov); // added JSL + } else { + eMessage = std::string("musrPhysicsList: Process \"") + charProcessName + + "\" is not implemented in musrPhysicsList.cc for addDiscreteProcess. It can be easily added."; + musrErrorMessage::GetInstance()->musrError(FATAL, eMessage, false); + } + } else if (option == "addProcess") { + G4int nr1, nr2, nr3; + std::string charRegion1, charRegion2, charRegion3, charControlString; + + if (!(lineStream >> nr1 >> nr2 >> nr3)) { + ReportProblemWithProcessDefinition(line); + } + lineStream >> charRegion1 >> charRegion2 >> charRegion3 >> charControlString; + + if (stringProcessName == "G4eMultipleScattering") + pManager->AddProcess(new G4eMultipleScattering, nr1, nr2, nr3); + else if (stringProcessName == "G4eIonisation") + pManager->AddProcess(new G4eIonisation, nr1, nr2, nr3); + else if (stringProcessName == "G4eBremsstrahlung") + pManager->AddProcess(new G4eBremsstrahlung, nr1, nr2, nr3); + else if (stringProcessName == "G4eplusAnnihilation") + pManager->AddProcess(new G4eplusAnnihilation, nr1, nr2, nr3); + // cks 14.12.2011 else if (stringProcessName=="G4PenelopeIonisation") pManager->AddProcess(new + // G4PenelopeIonisation,nr1,nr2,nr3); cks 14.12.2011 else if (stringProcessName=="G4PenelopeBremsstrahlung") + // pManager->AddProcess(new G4PenelopeBremsstrahlung,nr1,nr2,nr3); cks 14.12.2011 else if + // (stringProcessName=="G4PenelopeAnnihilation") pManager->AddProcess(new G4PenelopeAnnihilation,nr1,nr2,nr3); + // else if (stringProcessName=="G4LowEnergyIonisation") pManager->AddProcess(new G4LowEnergyIonisation,nr1,nr2,nr3); + // else if (stringProcessName=="G4LowEnergyBremsstrahlung") pManager->AddProcess(new G4LowEnergyBremsstrahlung,nr1,nr2,nr3); + else if (stringProcessName == "G4MuMultipleScattering") + pManager->AddProcess(new G4MuMultipleScattering, nr1, nr2, nr3); + else if (stringProcessName == "G4MuIonisation") + pManager->AddProcess(new G4MuIonisation, nr1, nr2, nr3); + else if (stringProcessName == "G4MuBremsstrahlung") + pManager->AddProcess(new G4MuBremsstrahlung, nr1, nr2, nr3); + else if (stringProcessName == "G4MuPairProduction") + pManager->AddProcess(new G4MuPairProduction, nr1, nr2, nr3); + // cks 2009-06-08 G4StepLimiter and/or G4UserSpecialCuts are needed to activate the "G4UserLimits" + else if (stringProcessName == "G4StepLimiter") + pManager->AddProcess(new G4StepLimiter, nr1, nr2, nr3); + else if (stringProcessName == "G4UserSpecialCuts") + pManager->AddProcess(new G4UserSpecialCuts, nr1, nr2, nr3); + // else if (stringProcessName=="G4DecayWithSpin") pManager->AddProcess(new G4DecayWithSpin,nr1,nr2,nr3); + // else if (stringProcessName=="G4hIonisation") pManager->AddProcess(new G4hIonisation,nr1,nr2,nr3); + // else if (stringProcessName=="G4hLowEnergyIonisation") pManager->AddProcess(new G4hLowEnergyIonisation,nr1,nr2,nr3); + else if (stringProcessName == "musrMuFormation") + pManager->AddProcess(new musrMuFormation, nr1, nr2, nr3); + else if (stringProcessName == "musrMuEnergyLossLandau") + pManager->AddProcess(new musrMuEnergyLossLandau, nr1, nr2, nr3); + else if (stringProcessName == "G4Scintillation") { + G4Scintillation *myScintillation = new G4Scintillation(); + // if (musrParameters::finiteRiseTimeInScintillator) myScintillation->SetFiniteRiseTime(true); + pManager->AddProcess(myScintillation, nr1, nr2, nr3); + } else if (stringProcessName == "G4Cerenkov") { + G4Cerenkov *myCerenkov = new G4Cerenkov(); + myCerenkov->SetMaxNumPhotonsPerStep(20); // settings from GEANT example N06 + myCerenkov->SetMaxBetaChangePerStep(10.0); + myCerenkov->SetTrackSecondariesFirst(false); // as for Scintillation, do main high energy particles first + pManager->AddProcess(myCerenkov, nr1, nr2, nr3); // added JSL + pManager->SetProcessOrdering(myCerenkov, idxPostStep); // from Example N06 + } + // cks: musrMuScatter could be uncommented here, but testing is needed, because Toni has some strange comments + // in his original "musrPhysicsList.cc about implementing musrMuScatter. + // else if (stringProcessName=="musrMuScatter") pManager->AddProcess(new musrMuScatter,nr1,nr2,nr3); + // + // The G4MultipleScattering is obsolete in Geant4.9.4 + // else if (stringProcessName=="MultipleAndCoulombScattering") { + // G4MultipleScattering* multScat = new G4MultipleScattering(); + // // G4CoulombScattering* coulScat = new G4CoulombScattering(); + // G4CoulombScatteringModel* coulScatModel = new G4CoulombScatteringModel(); + // if (strcmp(charRegion1,"")!=0) { + // G4Region* regionForCoulomb = FindG4Region(charRegion1,line); + // G4cout<<" Adding Coulomb scattering model to multiple scattering model for region "<AddEmModel(0,coulScatModel,regionForCoulomb); + // // multScat->AddEmModel(0,multScat,regionForCoulomb); + // } + // if (strcmp(charRegion2,"")!=0) { + // G4Region* regionForCoulomb = FindG4Region(charRegion2,line); + // G4cout<<" Adding Coulomb scattering model to multiple scattering model for region "<AddEmModel(0,coulScatModel,regionForCoulomb); + // } + // if (strcmp(charRegion3,"")!=0) { + // G4Region* regionForCoulomb = FindG4Region(charRegion3,line); + // G4cout<<" Adding Coulomb scattering model to multiple scattering model for region "<AddEmModel(0,coulScatModel,regionForCoulomb); + // } + // if (strcmp(charControlString,"")!=0) { + // G4cout<<"More than 3 regions requested for Coulomb Scattering, but presently only up to 3 such regions are + // supported."<AddProcess(multScat,nr1,nr2,nr3); + // } + else { + eMessage = std::string("musrPhysicsList: Process \"") + charProcessName + + "\" is not implemented in musrPhysicsList.cc for addProcess. It can be easily added."; + musrErrorMessage::GetInstance()->musrError(FATAL, eMessage, false); + } + } else if (option == "addModel") { + G4ProcessTable *processTable = G4ProcessTable::GetProcessTable(); + // G4VProcess* myProc = processTable->FindProcess(charProcessName,particleDefinition); + // pManager + + G4int modelPriority; + std::string charModelName; + if (!(lineStream >> charModelName >> modelPriority)) { + ReportProblemWithProcessDefinition(line); + } + G4String stringModelName = charModelName; + G4cout << " Adding model " << charModelName << " with priority " << modelPriority << " to process " << charProcessName << "." + << G4endl; + // if (myProc==nullptr) { + // sprintf(eMessage,"musrPhysicsList: Trying to add model \"%s\" , but the process \"%s\" not found in G4ProcessTable.", + // charModelName,charProcessName); + // musrErrorMessage::GetInstance()->musrError(FATAL,eMessage,false); + // } + if ((stringModelName == "G4WentzelVIModel") && (stringProcessName == "G4MuMultipleScattering")) { + G4MuMultipleScattering *mmm = (G4MuMultipleScattering *)processTable->FindProcess("muMsc", particleDefinition); + mmm->AddEmModel(modelPriority, new G4WentzelVIModel()); + } else if ((stringModelName == "G4UrbanMscModel") && (stringProcessName == "G4MuMultipleScattering")) { + G4MuMultipleScattering *mmm = (G4MuMultipleScattering *)processTable->FindProcess("muMsc", particleDefinition); + mmm->AddEmModel(modelPriority, new G4UrbanMscModel()); + } + // cks 14.12.2011 else if ((stringModelName=="G4UrbanMscModel92")&&(stringProcessName=="G4MuMultipleScattering")) { + // cks 14.12.2011 G4MuMultipleScattering* mmm = (G4MuMultipleScattering*) + // processTable->FindProcess("muMsc",particleDefinition); cks 14.12.2011 mmm->AddEmModel(modelPriority, new + // G4UrbanMscModel92()); cks 14.12.2011 } else if + //((stringModelName=="G4UrbanMscModel93")&&(stringProcessName=="G4MuMultipleScattering")) { G4MuMultipleScattering* mmm = + //(G4MuMultipleScattering*) processTable->FindProcess("muMsc",particleDefinition); mmm->AddEmModel(modelPriority, new + // G4UrbanMscModel93()); + // } + else { + eMessage = std::string("musrPhysicsList: Model \"") + charModelName + "\" is not implemented for \"" + charProcessName + + "\" in musrPhysicsList.cc for addModel. It can be easily added."; + musrErrorMessage::GetInstance()->musrError(FATAL, eMessage, false); + } + + } + + else if (option == "SetLossFluctuations_OFF") { + G4ProcessTable *processTable = G4ProcessTable::GetProcessTable(); + if (charProcessName == "G4eIonisation") { + G4cout << "musrPhysicsList.cc: Switching off loss fluctuations for " << charParticleName << " in " << charProcessName << G4endl; + G4eIonisation *mmm = (G4eIonisation *)processTable->FindProcess("eIoni", particleDefinition); + mmm->SetLossFluctuations(false); + } else if (charProcessName == "G4MuIonisation") { + G4cout << "musrPhysicsList.cc: Switching off loss fluctuations for " << charParticleName << " in " << charProcessName << G4endl; + G4MuIonisation *mmm = (G4MuIonisation *)processTable->FindProcess("muIoni", particleDefinition); + mmm->SetLossFluctuations(false); + } else { + G4cout << "musrPhysicsList.cc: Switching off loss fluctuations for " << charParticleName << " in " << charProcessName + << " NOT SUPPORTED YET" << G4endl; + } + } + + } else if (option == "cutForGamma") { + if (!(lineStream >> tmpCutValue)) { + ReportProblemWithProcessDefinition(line); + } + cutForGamma = tmpCutValue; + } else if (option == "cutForElectron") { + if (!(lineStream >> tmpCutValue)) { + ReportProblemWithProcessDefinition(line); + } + cutForElectron = tmpCutValue; + } else { + ReportProblemWithProcessDefinition(line); + } + } + G4cout << "\n\n\n\n" << G4endl; + // csk 2008.08.22. + + // del G4String myTypeOfProcesses = musrParameters::GetInstance()->GetMyTypeOfProcesses(); + // del G4cout<<"musrPhysicsList::ConstructEM(): myTypeOfProcesses="<reset(); + while ((*GetParticleIterator())()) { + G4ParticleDefinition *particle = GetParticleIterator()->value(); + G4ProcessManager *pmanager = particle->GetProcessManager(); + G4String particleName = particle->GetParticleName(); + + if ((particleName == "gamma") || (particleName == "e-") || (particleName == "e+")) { + // do nothing + } else if ((particleName == "mu+") || (particleName == "mu-")) { // muon + G4DecayWithSpin *theDecayProcess = new G4DecayWithSpin(); + // theDecayProcess->SetVerboseLevel(2); + pmanager->AddProcess(theDecayProcess); + pmanager->SetProcessOrderingToLast(theDecayProcess, idxAtRest); + pmanager->SetProcessOrdering(theDecayProcess, idxPostStep); + } else if (particleName == "Mu") { + // TS: + // Muonium "scattering" Kamil: the following 3 lines could be replaced by reading the musrMuScatter + // process through the steering file + G4VProcess *aMuScatt = new musrMuScatter(); + pmanager->AddProcess(aMuScatt); + pmanager->SetProcessOrdering(aMuScatt, idxPostStep, 1); + // + G4Decay *theDecayProcess = new G4Decay(); + // musrDecayWithSpin* theDecayProcess = new musrDecayWithSpin(); + pmanager->AddProcess(theDecayProcess); + pmanager->SetProcessOrderingToLast(theDecayProcess, idxAtRest); + pmanager->SetProcessOrdering(theDecayProcess, idxPostStep); + } else if ((!particle->IsShortLived()) && (particle->GetPDGCharge() != 0.0) && (particle->GetParticleName() != "chargedgeantino")) { + // all others charged particles except geantino + pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1); + // if (myTypeOfProcesses=="highenergy") { + // pmanager->AddProcess(new G4hIonisation, -1, 2,2); + // } + // else { + pmanager->AddProcess(new G4hIonisation, -1, 2, 2); + // } + /// pmanager->AddProcess(new G4UserSpecialCuts, -1,-1,3); + } } - } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... - - #include "G4Decay.hh" -void musrPhysicsList::ConstructGeneral() { - if (musrParameters::boolG4GeneralParticleSource) { - G4RadioactiveDecay* theRadioactiveDecay = new G4RadioactiveDecay(); - G4GenericIon* ion = G4GenericIon::GenericIon(); - - GetParticleIterator()->reset(); - while( (*GetParticleIterator())() ){ - G4ParticleDefinition* particle = GetParticleIterator()->value(); - G4ProcessManager* pmanager = particle->GetProcessManager(); - - if (particle == ion) { - pmanager->AddProcess(theRadioactiveDecay, 0, -1, 3); - } - } - } -} +void musrPhysicsList::ConstructGeneral() +{ + if (musrParameters::boolG4GeneralParticleSource) { + G4RadioactiveDecay *theRadioactiveDecay = new G4RadioactiveDecay(); + G4GenericIon *ion = G4GenericIon::GenericIon(); + GetParticleIterator()->reset(); + while ((*GetParticleIterator())()) { + G4ParticleDefinition *particle = GetParticleIterator()->value(); + G4ProcessManager *pmanager = particle->GetProcessManager(); + + if (particle == ion) { + pmanager->AddProcess(theRadioactiveDecay, 0, -1, 3); + } + } + } +} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... #include "G4Region.hh" @@ -619,48 +618,49 @@ void musrPhysicsList::ConstructGeneral() { void musrPhysicsList::SetCuts() { - //G4VUserPhysicsList::SetCutsWithDefault method sets - //the default cut value for all particle types - // - //cks 6.10.2009 SetCutsWithDefault(); + // G4VUserPhysicsList::SetCutsWithDefault method sets + // the default cut value for all particle types + // + // cks 6.10.2009 SetCutsWithDefault(); - // set cut values for gamma at first and for e- second and next for e+, - // because some processes for e+/e- need cut values for gamma - SetCutValue(cutForGamma, "gamma"); - SetCutValue(cutForElectron, "e-"); - SetCutValue(cutForElectron, "e+"); - //cks - This command does not work for muons: SetCutValue(cutForMuon, "mu-"); - //cks - This command does not work for muons: SetCutValue(cutForMuon, "mu+"); + // set cut values for gamma at first and for e- second and next for e+, + // because some processes for e+/e- need cut values for gamma + SetCutValue(cutForGamma, "gamma"); + SetCutValue(cutForElectron, "e-"); + SetCutValue(cutForElectron, "e+"); + // cks - This command does not work for muons: SetCutValue(cutForMuon, "mu-"); + // cks - This command does not work for muons: SetCutValue(cutForMuon, "mu+"); - // G4cout<<"Kamil: cutForGamma = "<0) DumpCutValuesTable(); - DumpCutValuesTable(); + if (verboseLevel > 0) + DumpCutValuesTable(); + DumpCutValuesTable(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... -void musrPhysicsList::ReportProblemWithProcessDefinition(const std::string& myString) { - G4cout<<"\nE R R O R in musrPhysicsList.cc: " - <<"Unknown keyword requested in the steering (*.mac) file :"<GetRegion(regionName,false); - if( myRegion != nullptr ) { // G4Region found - return myRegion; - } - else { // G4Region not found - G4cout<<"musrPhysicsList: G4Region "<GetRegion(regionName, false); + if (myRegion != nullptr) { // G4Region found + return myRegion; + } else { // G4Region not found + G4cout << "musrPhysicsList: G4Region " << regionName << " not found." << G4endl; + G4cout << " The critical command line of the steering file is:" << G4endl; + G4cout << " " << lineOfSteeringFile << G4endl; + G4cout << " S T O P F O R C E D" << G4endl; + exit(1); + } } diff --git a/src/musrPrimaryGeneratorAction.cc b/src/musrPrimaryGeneratorAction.cc index 72c5e8b..5cc4332 100644 --- a/src/musrPrimaryGeneratorAction.cc +++ b/src/musrPrimaryGeneratorAction.cc @@ -461,7 +461,7 @@ void musrPrimaryGeneratorAction::SetMuonDecayTimeLimits(G4ThreeVector decayTimeL //=============================================================================== void musrPrimaryGeneratorAction::SetTurtleInput(G4String turtleFileName) { takeMuonsFromTurtleFile = true; - fTurtleFile = std::make_unique(turtleFileName.c_str()); + fTurtleFile = std::make_unique(turtleFileName); if (!fTurtleFile->is_open()) { G4cout << "E R R O R : Failed to open TURTLE input file \"" << turtleFileName <<"\"."<< G4endl;