From 41c706e2d8240f77aeb2a82b0e653bd78f99ad47 Mon Sep 17 00:00:00 2001 From: martinunland Date: Fri, 7 Jun 2024 16:37:07 +0200 Subject: [PATCH] making mains clearer --- CMakeLists.txt | 4 +- common/framework/include/OMSim.hh | 20 ++- common/framework/include/OMSimLogger.hh | 2 +- common/framework/src/OMSim.cc | 122 +++++++++++++---- common/framework/src/OMSimLogger.cc | 4 +- .../include/abcDetectorComponent.hh | 4 +- .../src/OMSimMDOMFlasher.cc | 1 - .../src/abcDetectorComponent.cc | 9 ++ effective_area/OMSim_effective_area.cc | 96 +++++--------- .../src/OMSimEffectiveAreaDetector.cc | 1 - .../OMSim_radioactive_decays.cc | 124 +++++------------- supernova/OMSim_supernova.cc | 119 ++++++----------- 12 files changed, 236 insertions(+), 270 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0519cfad6a..22c509ad42 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,8 +45,8 @@ include(${ROOT_USE_FILE}) add_subdirectory(common) add_subdirectory(effective_area) -#add_subdirectory(radioactive_decays) -#add_subdirectory(supernova) +add_subdirectory(radioactive_decays) +add_subdirectory(supernova) # Copy auxiliary files from source directory to binary directory set(mdom_aux diff --git a/common/framework/include/OMSim.hh b/common/framework/include/OMSim.hh index 50c24ec2f2..a7509796ea 100644 --- a/common/framework/include/OMSim.hh +++ b/common/framework/include/OMSim.hh @@ -49,17 +49,22 @@ public: void ensureOutputDirectoryExists(const std::string &filepath); void initialiseSimulation(OMSimDetectorConstruction* pDetectorConstruction); - void startVisualisation(); void configureLogger(); + bool handleArguments(int pArgumentCount, char *pArgumentVector[]); + void startVisualisationIfRequested(); //OMSimDetectorConstruction* getDetectorConstruction(); - po::options_description mGeneralArgs; + G4Navigator* getNavigator(){return mNavigator;}; + void extendOptions(po::options_description pNewOptions); + po::options_description mGeneralOptions; private: - G4RunManager *mRunManager; - G4VisExecutive *mVisManager; - G4Navigator *mNavigator; + po::variables_map parseArguments(int pArgumentCount, char *pArgumentVector[]); + void setUserArgumentsToArgTable(po::variables_map pVariablesMap); + G4RunManager *mRunManager = nullptr; + G4VisExecutive *mVisManager = nullptr; + G4Navigator *mNavigator = nullptr; G4VUserPhysicsList *mPhysics = nullptr; G4VUserPrimaryGeneratorAction *mGenAction = nullptr; G4UserRunAction *mRunAction = nullptr; @@ -67,7 +72,10 @@ private: G4UserTrackingAction *mTracking = nullptr; G4UserSteppingAction *mStepping = nullptr; G4TouchableHistory *mHistory = nullptr; - G4double mStartingTime; + + + + G4double mStartingTime=0; }; #endif // OMSIM_H diff --git a/common/framework/include/OMSimLogger.hh b/common/framework/include/OMSimLogger.hh index e25b834c59..0982dcfe33 100644 --- a/common/framework/include/OMSimLogger.hh +++ b/common/framework/include/OMSimLogger.hh @@ -7,7 +7,7 @@ #include "spdlog/fmt/fmt.h" // Global logger instance -extern std::shared_ptr global_logger; +extern std::shared_ptr globalLogger; // Custom logging function void customLog(spdlog::level::level_enum log_level, const char* file, int line, const char* func, const std::string& message); diff --git a/common/framework/src/OMSim.cc b/common/framework/src/OMSim.cc index 29ef408ebc..46798ce292 100644 --- a/common/framework/src/OMSim.cc +++ b/common/framework/src/OMSim.cc @@ -13,20 +13,20 @@ #include namespace po = boost::program_options; -extern std::shared_ptr global_logger; +extern std::shared_ptr globalLogger; /** * This constructor initializes the Geant4 run manager, visualization manager, * and navigator. It also sets up the command line arguments for the simulation. */ -OMSim::OMSim() : mGeneralArgs("General options") +OMSim::OMSim() : mGeneralOptions("General options") { mStartingTime = clock() / CLOCKS_PER_SEC; - mRunManager = new G4RunManager; - mVisManager = new G4VisExecutive; + mRunManager = new G4RunManager(); + mVisManager = new G4VisExecutive(); mNavigator = new G4Navigator(); - mGeneralArgs.add_options()("help", "produce help message") + mGeneralOptions.add_options()("help", "produce help message") ("log_level", po::value()->default_value("info"), "Granularity of logger, defaults to info [trace, debug, info, warn, error, critical, off]") ("output_file,o", po::value()->default_value("output"), "filename for output") ("numevents,n", po::value()->default_value(0), "number of events") @@ -40,11 +40,18 @@ OMSim::OMSim() : mGeneralArgs("General options") ("pmt_response", po::bool_switch(), "if given, simulates PMT response using scan data (currently only for mDOM PMT)") ("place_harness",po::bool_switch(),"place OM harness (if implemented)") ("detector_type", po::value()->default_value(2), "module type [custom = 0, Single PMT = 1, mDOM = 2, pDDOM = 3, LOM16 = 4]") - ("check_overlaps", po::bool_switch()->default_value(true), "check overlaps between volumes during construction") + ("check_overlaps", po::bool_switch()->default_value(false), "check overlaps between volumes during construction") ("glass", po::value()->default_value(0), "DEPRECATED. Index to select glass type [VITROVEX = 0, Chiba = 1, Kopp = 2, myVitroVex = 3, myChiba = 4, WOMQuartz = 5, fusedSilica = 6]") ("gel", po::value()->default_value(1), "DEPRECATED. Index to select gel type [Wacker = 0, Chiba = 1, IceCube = 2, Wacker_company = 3]") ("reflective_surface", po::value()->default_value(0), "DEPRECATED. Index to select reflective surface type [Refl_V95Gel = 0, Refl_V98Gel = 1, Refl_Aluminium = 2, Refl_Total98 = 3]") ("pmt_model", po::value()->default_value(0), "DEPRECATED. R15458 (mDOM) = 0, R7081 (DOM) = 1, 4inch (LOM) = 2, R5912_20_100 (D-Egg)= 3"); + + + globalLogger = spdlog::stdout_color_mt("console"); + globalLogger->set_level(spdlog::level::info); // Set the desired log level + globalLogger->set_pattern("%^[%Y-%m-%d %H:%M:%S.%e][%l][%s:%#]%$ %v"); + spdlog::set_default_logger(globalLogger); + } spdlog::level::level_enum getLogLevelFromString(const std::string &pLevelString) @@ -68,27 +75,26 @@ spdlog::level::level_enum getLogLevelFromString(const std::string &pLevelString) void OMSim::configureLogger() { - G4cout << ":::::::::::::::::::" << G4endl; - global_logger = spdlog::stdout_color_mt("console"); std::string lLogLevel = OMSimCommandArgsTable::getInstance().get("log_level"); - global_logger->set_level(getLogLevelFromString(lLogLevel)); // Set the desired log level - global_logger->set_pattern("%^[%Y-%m-%d %H:%M:%S.%e][%l][%s:%#]%$ %v"); - spdlog::set_default_logger(global_logger); + globalLogger->set_level(getLogLevelFromString(lLogLevel)); // Set the desired log level + spdlog::set_default_logger(globalLogger); log_trace("Logger configured to level {}", lLogLevel); } - /** * @brief UIEx session is started for visualisation. */ -void OMSim::startVisualisation() +void OMSim::startVisualisationIfRequested() { - OMSimUIinterface &lUIinterface = OMSimUIinterface::getInstance(); - char *argumv[] = {"all", NULL}; - G4UIExecutive *UIEx = new G4UIExecutive(1, argumv); - lUIinterface.applyCommand("/control/execute ../aux/init_vis.mac"); - UIEx->SessionStart(); - delete UIEx; + if (OMSimCommandArgsTable::getInstance().get("visual")) + { + OMSimUIinterface &lUIinterface = OMSimUIinterface::getInstance(); + char *argumv[] = {"all", NULL}; + G4UIExecutive *UIEx = new G4UIExecutive(1, argumv); + lUIinterface.applyCommand("/control/execute ../aux/init_vis.mac"); + UIEx->SessionStart(); + delete UIEx; + } } /** * @brief Ensure that the output directory for the simulation results exists. @@ -167,11 +173,81 @@ void OMSim::initialiseSimulation(OMSimDetectorConstruction* pDetectorConstructio lUIinterface.applyCommand("/control/execute ", lArgs.get("visual")); } +void OMSim::extendOptions(po::options_description pNewOptions) +{ + mGeneralOptions.add(pNewOptions); +} + + +po::variables_map OMSim::parseArguments(int pArgumentCount, char *pArgumentVector[]) +{ + po::variables_map lVariablesMap; + try { + po::store(po::parse_command_line(pArgumentCount, pArgumentVector, mGeneralOptions), lVariablesMap); + } catch (std::invalid_argument& e) { + std::cerr << "Invalid argument: " << e.what() << std::endl; + } catch (std::exception& e) { + std::cerr << "An exception occurred: " << e.what() << std::endl; + } catch (...) { + std::cerr << "An unknown exception occurred." << std::endl; + } + po::notify(lVariablesMap); + + return lVariablesMap; +} + +void OMSim::setUserArgumentsToArgTable(po::variables_map pVariablesMap) +{ + OMSimCommandArgsTable &lArgs = OMSimCommandArgsTable::getInstance(); + // Now store the parsed parameters in the OMSimCommandArgsTable instance + for (const auto &option : pVariablesMap) + { + lArgs.setParameter(option.first, option.second.value()); + } + // Now that all parameters are set, "finalize" the OMSimCommandArgsTable instance so that the parameters cannot be modified anymore + lArgs.finalize(); +} + +bool OMSim::handleArguments(int pArgumentCount, char *pArgumentVector[]) +{ + + po::variables_map lVariablesMap = parseArguments(pArgumentCount, pArgumentVector); + + //check if user needs help + if (lVariablesMap.count("help")) + { + std::cout << mGeneralOptions << "\n"; + return false; + } + + //If no help needed continue and set arguments to arg table + setUserArgumentsToArgTable(lVariablesMap); + return true; +} + + + + OMSim::~OMSim() { - delete mNavigator; - delete mVisManager; - delete mRunManager; + log_trace("OMSim destructor"); + if (mRunManager) { + log_trace("Deleting RunManager"); + delete mRunManager; + mRunManager = nullptr; + } + + if (mVisManager) { + log_trace("Deleting VisManager"); + delete mVisManager; + mVisManager = nullptr; + } + + if (mNavigator) { + log_trace("Deleting Navigator"); + delete mNavigator; + mNavigator = nullptr; + } double lFinishtime = clock() / CLOCKS_PER_SEC; - G4cout << "Computation time: " << lFinishtime - mStartingTime << " seconds." << G4endl; + log_info("Computation time: {} {}", lFinishtime - mStartingTime, " seconds."); } \ No newline at end of file diff --git a/common/framework/src/OMSimLogger.cc b/common/framework/src/OMSimLogger.cc index dcad3ad344..0e0d14e872 100644 --- a/common/framework/src/OMSimLogger.cc +++ b/common/framework/src/OMSimLogger.cc @@ -3,7 +3,7 @@ // Definition of the customLog function void customLog(spdlog::level::level_enum log_level, const char* file, int line, const char* func, const std::string& message) { - if (global_logger && global_logger->should_log(log_level)) { - global_logger->log(spdlog::source_loc{file, line, func}, log_level, message); + if (globalLogger && globalLogger->should_log(log_level)) { + globalLogger->log(spdlog::source_loc{file, line, func}, log_level, message); } } diff --git a/common/geometry_construction/include/abcDetectorComponent.hh b/common/geometry_construction/include/abcDetectorComponent.hh index f2477c7bb6..6b6899cc6e 100644 --- a/common/geometry_construction/include/abcDetectorComponent.hh +++ b/common/geometry_construction/include/abcDetectorComponent.hh @@ -26,11 +26,11 @@ class abcDetectorComponent { public: - abcDetectorComponent(){}; + abcDetectorComponent(); virtual void construction() = 0; ///< Abstract method you have to define in order to make a derived class from abcDetectorComponent InputDataManager *mData; ///< Instance of OMSimInputdata, which should be started only once. - bool mCheckOverlaps = true; + bool mCheckOverlaps = false; /** * @struct abcDetectorComponent::Component diff --git a/common/geometry_construction/src/OMSimMDOMFlasher.cc b/common/geometry_construction/src/OMSimMDOMFlasher.cc index 2fa882f205..b5efb41a69 100644 --- a/common/geometry_construction/src/OMSimMDOMFlasher.cc +++ b/common/geometry_construction/src/OMSimMDOMFlasher.cc @@ -14,7 +14,6 @@ mDOMFlasher::mDOMFlasher(InputDataManager *pData) { mData = pData; - mCheckOverlaps = OMSimCommandArgsTable::getInstance().get("check_overlaps"); construction(); } diff --git a/common/geometry_construction/src/abcDetectorComponent.cc b/common/geometry_construction/src/abcDetectorComponent.cc index 8c5a5ce49e..cff8d364d3 100644 --- a/common/geometry_construction/src/abcDetectorComponent.cc +++ b/common/geometry_construction/src/abcDetectorComponent.cc @@ -1,12 +1,21 @@ #include "abcDetectorComponent.hh" #include "OMSimPMTConstruction.hh" #include "OMSimLogger.hh" +#include "OMSimCommandArgsTable.hh" #include #include #include #include + + +abcDetectorComponent::abcDetectorComponent() +{ + mCheckOverlaps = OMSimCommandArgsTable::getInstance().get("check_overlaps"); +} + + /** * @brief Append component to Components vector. * @details This function is used to add a new component to the 'Components' vector. Each component contains the solid volume, logical volume, position, rotation, and a unique name. diff --git a/effective_area/OMSim_effective_area.cc b/effective_area/OMSim_effective_area.cc index be4b5a321c..3940ce5f97 100755 --- a/effective_area/OMSim_effective_area.cc +++ b/effective_area/OMSim_effective_area.cc @@ -9,11 +9,11 @@ #include "OMSimEffectiveAreaAnalyisis.hh" #include "OMSimEffectiveAreaDetector.hh" -std::shared_ptr global_logger; +std::shared_ptr globalLogger; namespace po = boost::program_options; -void effectiveAreaSimulation() +void runEffectiveAreaSimulation() { OMSimEffectiveAreaAnalyisis lAnalysisManager; OMSimCommandArgsTable &lArgs = OMSimCommandArgsTable::getInstance(); @@ -48,75 +48,41 @@ void effectiveAreaSimulation() } } -int main(int argc, char *argv[]) +/** + * @brief Add options for the user input arguments for the effective area module + */ +void addModuleOptions(OMSim* pSimulation) { - try - { - OMSim lSimulation; - // Do not use G4String as type here... - po::options_description lSpecific("Effective area specific arguments"); - - lSpecific.add_options() - ("world_radius,w", po::value()->default_value(3.0), "radius of world sphere in m") - ("radius,r", po::value()->default_value(300.0), "plane wave radius in mm") - ("distance,d", po::value()->default_value(2000), "plane wave distance from origin, in mm") - ("theta,t", po::value()->default_value(0.0), "theta (= zenith) in deg") - ("phi,f", po::value()->default_value(0.0), "phi (= azimuth) in deg") - ("wavelength,l", po::value()->default_value(400.0), "wavelength of incoming light in nm") - ("angles_file,i", po::value(), "The input angle pairs file to be scanned. The file should contain two columns, the first column with the theta (zenith) and the second with phi (azimuth) in degrees.") - ("no_header", po::bool_switch(), "if given, the header of the output file will not be written"); - - - po::options_description lAllargs("Allowed input arguments"); - lAllargs.add(lSimulation.mGeneralArgs).add(lSpecific); - - - po::variables_map lVariablesMap; - try { - po::store(po::parse_command_line(argc, argv, lAllargs), lVariablesMap); - } catch (std::invalid_argument& e) { - std::cerr << "Invalid argument: " << e.what() << std::endl; - } catch (std::exception& e) { - std::cerr << "An exception occurred: " << e.what() << std::endl; - } catch (...) { - std::cerr << "An unknown exception occurred." << std::endl; - } - - po::notify(lVariablesMap); - - if (lVariablesMap.count("help")) - { - std::cout << lAllargs << "\n"; - return 0; - } + po::options_description lSpecific("Effective area specific arguments"); + + // Do not use G4String as type here... + lSpecific.add_options() + ("world_radius,w", po::value()->default_value(3.0), "radius of world sphere in m") + ("radius,r", po::value()->default_value(300.0), "plane wave radius in mm") + ("distance,d", po::value()->default_value(2000), "plane wave distance from origin, in mm") + ("theta,t", po::value()->default_value(0.0), "theta (= zenith) in deg") + ("phi,f", po::value()->default_value(0.0), "phi (= azimuth) in deg") + ("wavelength,l", po::value()->default_value(400.0), "wavelength of incoming light in nm") + ("angles_file,i", po::value(), "The input angle pairs file to be scanned. The file should contain two columns, the first column with the theta (zenith) and the second with phi (azimuth) in degrees.") + ("no_header", po::bool_switch(), "if given, the header of the output file will not be written"); + + pSimulation->extendOptions(lSpecific); +} - OMSimCommandArgsTable &lArgs = OMSimCommandArgsTable::getInstance(); - // Now store the parsed parameters in the OMSimCommandArgsTable instance - for (const auto &option : lVariablesMap) - { - lArgs.setParameter(option.first, option.second.value()); - } +int main(int pArgumentCount, char *pArgumentVector[]) +{ - // Now that all parameters are set, "finalize" the OMSimCommandArgsTable instance so that the parameters cannot be modified anymore - lArgs.finalize(); + OMSim lSimulation; + addModuleOptions(&lSimulation); + bool lContinue = lSimulation.handleArguments(pArgumentCount, pArgumentVector); + if (!lContinue) return 0; - OMSimEffectiveAreaDetector* lDetectorConstruction = new OMSimEffectiveAreaDetector(); - lSimulation.initialiseSimulation(lDetectorConstruction); + OMSimEffectiveAreaDetector* lDetectorConstruction = new OMSimEffectiveAreaDetector(); + lSimulation.initialiseSimulation(lDetectorConstruction); - effectiveAreaSimulation(); - if(lArgs.get("visual")) lSimulation.startVisualisation(); - - } - catch (std::exception &e) - { - std::cerr << "error: " << e.what() << "\n"; - return 1; - } - catch (...) - { - std::cerr << "Exception of unknown type!\n"; - } + runEffectiveAreaSimulation(); + lSimulation.startVisualisationIfRequested(); return 0; } diff --git a/effective_area/src/OMSimEffectiveAreaDetector.cc b/effective_area/src/OMSimEffectiveAreaDetector.cc index 4c91b60a16..518a817478 100644 --- a/effective_area/src/OMSimEffectiveAreaDetector.cc +++ b/effective_area/src/OMSimEffectiveAreaDetector.cc @@ -89,7 +89,6 @@ void OMSimEffectiveAreaDetector::constructDetector() if (lOpticalModule) { - log_critical("Here"); lOpticalModule->placeIt(G4ThreeVector(0, 0, 0), G4RotationMatrix(), mWorldLogical, ""); lOpticalModule->configureSensitiveVolume(this); } diff --git a/radioactive_decays/OMSim_radioactive_decays.cc b/radioactive_decays/OMSim_radioactive_decays.cc index da1b9a7067..1abb395904 100755 --- a/radioactive_decays/OMSim_radioactive_decays.cc +++ b/radioactive_decays/OMSim_radioactive_decays.cc @@ -12,7 +12,7 @@ #include "OMSimDecaysAnalysis.hh" #include "OMSimRadDecaysDetector.hh" -std::shared_ptr global_logger; +std::shared_ptr globalLogger; namespace po = boost::program_options; @@ -22,7 +22,7 @@ namespace po = boost::program_options; * for which the decay simulation is to be performed. * @see OMSimDecaysGPS, OMSimDecaysAnalysis */ -void decaysInOM(OMSimRadDecaysDetector *pDetector) +void runRadioactiveDecays(OMSimRadDecaysDetector *pDetector) { OMSimDecaysAnalysis &lAnalysisManager = OMSimDecaysAnalysis::getInstance(); OMSimCommandArgsTable &lArgs = OMSimCommandArgsTable::getInstance(); @@ -56,100 +56,44 @@ void decaysInOM(OMSimRadDecaysDetector *pDetector) } - /** - * @brief Main entry point for the radioactive decay study simulation. - * @details Initializes the simulation environment, parses command line arguments, - * sets up the simulation parameters, and starts the decay simulation. - * It also handles any exceptions that may occur during the initialization - * and execution of the simulation. - * @warning This simulation has been tested only for Vitrovex glass (mDOM/LOM16) and - * the 80mm mDOM PMTs. Okamoto glass (D-Egg/LOM18) is currently under investigation. - * @param argc Number of command-line arguments. - * @param argv Array of command-line argument strings. - * @return Returns 0 on successful execution, 1 on failure. - * @see OMSim, OMSimDecaysGPS, OMSimDecaysAnalysis, OMSimRadDecaysDetector + * @brief Add options for the user input arguments for the radioactive decays module */ -int main(int argc, char *argv[]) +void addModuleOptions(OMSim* pSimulation) { - try - { - OMSim lSimulation; - // Do not use G4String as type here... - po::options_description lSpecific("User arguments for radioactive decays simulation"); - - lSpecific.add_options() - ("world_radius,w", po::value()->default_value(3.0), "radius of world sphere in m") - ("radius,r", po::value()->default_value(300.0), "plane wave radius in mm") - ("no_PV_decays", po::bool_switch(), "skips the simulation of decays in pressure vessel") - ("no_PMT_decays", po::bool_switch(), "skips the simulation of decays in PMT glass") - ("multiplicity_study", po::bool_switch(), "only multiplicity is calculated and written in output. Hit information is not written in output (file would be too large!).") - ("scint_off", po::bool_switch(), "deactivates scintillation process.") - ("cherenkov_off", po::bool_switch(), "deactivates Cherenkov process.") - ("temperature", po::value(), "temperature in C° (scintillation is temperature dependent)") - ("time_window", po::value()->default_value(60.0), "time length in which the decays are simulated.") - ("yield_alphas", po::value(), "scintillation yield for alpha particles. This affects all materials with scintillation properties!") - ("yield_electrons", po::value(), "scintillation yield for electrons. This affects all materials with scintillation properties!") - ("no_header", po::bool_switch(), "if given, the header of the output file will not be written"); - - po::options_description lAllargs("Allowed input arguments"); - lAllargs.add(lSimulation.mGeneralArgs).add(lSpecific); - - po::variables_map lVariablesMap; - try - { - po::store(po::parse_command_line(argc, argv, lAllargs), lVariablesMap); - } - catch (std::invalid_argument &e) - { - std::cerr << "Invalid argument: " << e.what() << std::endl; - } - catch (std::exception &e) - { - std::cerr << "An exception occurred: " << e.what() << std::endl; - } - catch (...) - { - std::cerr << "An unknown exception occurred." << std::endl; - } - - po::notify(lVariablesMap); - - if (lVariablesMap.count("help")) - { - std::cout << lAllargs << "\n"; - return 0; - } - - OMSimCommandArgsTable &lArgs = OMSimCommandArgsTable::getInstance(); - - // Now store the parsed parameters in the OMSimCommandArgsTable instance - for (const auto &option : lVariablesMap) - { - lArgs.setParameter(option.first, option.second.value()); - } + po::options_description lSpecific("User arguments for radioactive decays simulation"); + + // Do not use G4String as type here... + lSpecific.add_options() + ("world_radius,w", po::value()->default_value(3.0), "radius of world sphere in m") + ("radius,r", po::value()->default_value(300.0), "plane wave radius in mm") + ("no_PV_decays", po::bool_switch(), "skips the simulation of decays in pressure vessel") + ("no_PMT_decays", po::bool_switch(), "skips the simulation of decays in PMT glass") + ("multiplicity_study", po::bool_switch(), "only multiplicity is calculated and written in output. Hit information is not written in output (file would be too large!).") + ("scint_off", po::bool_switch(), "deactivates scintillation process.") + ("cherenkov_off", po::bool_switch(), "deactivates Cherenkov process.") + ("temperature", po::value(), "temperature in C° (scintillation is temperature dependent)") + ("time_window", po::value()->default_value(60.0), "time length in which the decays are simulated.") + ("yield_alphas", po::value(), "scintillation yield for alpha particles. This affects all materials with scintillation properties!") + ("yield_electrons", po::value(), "scintillation yield for electrons. This affects all materials with scintillation properties!") + ("no_header", po::bool_switch(), "if given, the header of the output file will not be written"); + + pSimulation->extendOptions(lSpecific); +} - // Now that all parameters are set, "finalize" the OMSimCommandArgsTable instance so that the parameters cannot be modified anymore - lArgs.finalize(); +int main(int pArgumentCount, char *pArgumentVector[]) +{ - OMSimRadDecaysDetector *lDetectorConstruction = new OMSimRadDecaysDetector(); - lSimulation.initialiseSimulation(lDetectorConstruction); - decaysInOM(lDetectorConstruction); + OMSim lSimulation; + addModuleOptions(&lSimulation); + bool lContinue = lSimulation.handleArguments(pArgumentCount, pArgumentVector); + if (!lContinue) return 0; - if (lArgs.get("visual")) - lSimulation.startVisualisation(); - } - catch (std::exception &e) - { - std::cerr << "error: " << e.what() - << std::endl; - return 1; - } - catch (...) - { - std::cerr << "Exception of unknown type!" - << std::endl; - } + OMSimRadDecaysDetector *lDetectorConstruction = new OMSimRadDecaysDetector(); + lSimulation.initialiseSimulation(lDetectorConstruction); + runRadioactiveDecays(lDetectorConstruction); + + lSimulation.startVisualisationIfRequested(); return 0; } diff --git a/supernova/OMSim_supernova.cc b/supernova/OMSim_supernova.cc index d0e6713392..ed5f20c2a1 100755 --- a/supernova/OMSim_supernova.cc +++ b/supernova/OMSim_supernova.cc @@ -11,7 +11,7 @@ #include "G4Navigator.hh" #include "OMSimSNdetector.hh" -std::shared_ptr global_logger; +std::shared_ptr globalLogger; // TODO: change this global. getInstance? G4Navigator* gNavigator =nullptr; @@ -19,19 +19,19 @@ void setGlobalNavigator(G4Navigator* pNavigator){gNavigator = pNavigator;} namespace po = boost::program_options; -void PrepareAnalysis() { +void prepareAnalysis() { OMSimSNAnalysis &lAnalysisManager = OMSimSNAnalysis::getInstance(); OMSimCommandArgsTable &lArgs = OMSimCommandArgsTable::getInstance(); - G4String ldataoutputname = lArgs.get("output_file") + ".dat"; - G4String linfooutputname = lArgs.get("output_file") + "_info.dat"; + G4String lDataOutputName = lArgs.get("output_file") + ".dat"; + G4String lInfoOutputName = lArgs.get("output_file") + "_info.dat"; if (!lArgs.get("SNfixEnergy")) { - lAnalysisManager.maininfofile.open(linfooutputname, std::ios::out| std::ios::trunc); + lAnalysisManager.maininfofile.open(lInfoOutputName, std::ios::out| std::ios::trunc); } - lAnalysisManager.datafile.open(ldataoutputname, std::ios::out| std::ios::trunc); + lAnalysisManager.datafile.open(lDataOutputName, std::ios::out| std::ios::trunc); lAnalysisManager.WriteHeaders(); } -void SupernovaNeutrinoSimulation() +void runSupernovaNeutrinoSimulation() { OMSimCommandArgsTable &lArgs = OMSimCommandArgsTable::getInstance(); OMSimHitManager &lHitManager = OMSimHitManager::getInstance(); @@ -41,83 +41,48 @@ void SupernovaNeutrinoSimulation() OMSimUIinterface &lUIinterface = OMSimUIinterface::getInstance(); lUIinterface.applyCommand("/selectGun", lArgs.getInstance().get("SNgun")); - PrepareAnalysis(); + prepareAnalysis(); lUIinterface.runBeamOn(); } -int main(int argc, char *argv[]) +/** + * @brief Add options for the user input arguments for the SN module + */ +void addModuleOptions(OMSim* pSimulation) +{ + po::options_description lSpecific("Effective area specific arguments"); + + // Do not use G4String as type here... + lSpecific.add_options() + ("wheight,wh", po::value()->default_value(20), "Height of cylindrical world volume, in m") + ("wradius,wr", po::value()->default_value(20), "Radius of cylindrical world volume, in m") + ("SNtype", po::value()->default_value(0), "0=27 solar mass type II (ls220), 1=9.6 solar mass type II (ls220). Models 2,3,4 correspond to old tests with other models.") + ("SNgun", po::value()->default_value(0), "Select interaction to simulate: 0=IBD (no neutron capture included), 1=ENES") + ("SNfixEnergy", po::bool_switch(), "Instead of using the energy distribution of the model, it generates all neutrinos from an energy distribution with fixed mean energy and alpha") + ("SNmeanE", po::value()->default_value(10.0), "If --SNfixEnergy, use this mean energy to generate the neutrinos ") + ("SNalpha", po::value()->default_value(2.5), "If --SNfixEnergy, pinching (alpha) parameter of nu/nubar energy spectrum"); + + + pSimulation->extendOptions(lSpecific); +} + + +int main(int pArgumentCount, char *pArgumentVector[]) { - try - { - OMSim lSimulation; - setGlobalNavigator(lSimulation.getNavigator()); - // Do not use G4String as type here... - po::options_description lSpecific("SN simulation specific arguments"); - - lSpecific.add_options() - ("wheight,wh", po::value()->default_value(20), "Height of cylindrical world volume, in m") - ("wradius,wr", po::value()->default_value(20), "Radius of cylindrical world volume, in m") - ("SNtype", po::value()->default_value(0), "0=27 solar mass type II (ls220), 1=9.6 solar mass type II (ls220). Models 2,3,4 correspond to old tests with other models.") - ("SNgun", po::value()->default_value(0), "Select interaction to simulate: 0=IBD (no neutron capture included), 1=ENES") - ("SNfixEnergy", po::bool_switch(), "Instead of using the energy distribution of the model, it generates all neutrinos from an energy distribution with fixed mean energy and alpha") - ("SNmeanE", po::value()->default_value(10.0), "If --SNfixEnergy, use this mean energy to generate the neutrinos ") - ("SNalpha", po::value()->default_value(2.5), "If --SNfixEnergy, pinching (alpha) parameter of nu/nubar energy spectrum"); - - - po::options_description lAllargs("Allowed input arguments"); - lAllargs.add(lSimulation.mGeneralArgs).add(lSpecific); - - - po::variables_map lVariablesMap; - try { - po::store(po::parse_command_line(argc, argv, lAllargs), lVariablesMap); - } catch (std::invalid_argument& e) { - std::cerr << "Invalid argument: " << e.what() << std::endl; - } catch (std::exception& e) { - std::cerr << "An exception occurred: " << e.what() << std::endl; - } catch (...) { - std::cerr << "An unknown exception occurred." << std::endl; - } - - po::notify(lVariablesMap); - - if (lVariablesMap.count("help")) - { - std::cout << lAllargs << "\n"; - return 0; - } - - OMSimCommandArgsTable &lArgs = OMSimCommandArgsTable::getInstance(); - - // Now store the parsed parameters in the OMSimCommandArgsTable instance - for (const auto &option : lVariablesMap) - { - lArgs.setParameter(option.first, option.second.value()); - } - - // Now that all parameters are set, "finalize" the OMSimCommandArgsTable instance so that the parameters cannot be modified anymore - lArgs.finalize(); - - OMSimSNdetector* lDetectorConstruction = new OMSimSNdetector(); - lSimulation.initialiseSimulation(lDetectorConstruction); - - SupernovaNeutrinoSimulation(); - - if(lArgs.get("visual")) lSimulation.startVisualisation(); - - } - catch (std::exception &e) - { - std::cerr << "error: " << e.what() << "\n"; - return 1; - } - catch (...) - { - std::cerr << "Exception of unknown type!\n"; - } + OMSim lSimulation; + addModuleOptions(&lSimulation); + bool lContinue = lSimulation.handleArguments(pArgumentCount, pArgumentVector); + if (!lContinue) return 0; + + OMSimSNdetector* lDetectorConstruction = new OMSimSNdetector(); + lSimulation.initialiseSimulation(lDetectorConstruction); + + runSupernovaNeutrinoSimulation(); + + lSimulation.startVisualisationIfRequested(); return 0; }