Skip to content

Commit

Permalink
making mains clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
martinunland committed Jun 7, 2024
1 parent 9205aa8 commit 41c706e
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 270 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions common/framework/include/OMSim.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,33 @@ 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;
G4UserEventAction *mEventAction = nullptr;
G4UserTrackingAction *mTracking = nullptr;
G4UserSteppingAction *mStepping = nullptr;
G4TouchableHistory *mHistory = nullptr;
G4double mStartingTime;



G4double mStartingTime=0;
};

#endif // OMSIM_H
2 changes: 1 addition & 1 deletion common/framework/include/OMSimLogger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "spdlog/fmt/fmt.h"

// Global logger instance
extern std::shared_ptr<spdlog::logger> global_logger;
extern std::shared_ptr<spdlog::logger> globalLogger;

// Custom logging function
void customLog(spdlog::level::level_enum log_level, const char* file, int line, const char* func, const std::string& message);
Expand Down
122 changes: 99 additions & 23 deletions common/framework/src/OMSim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
#include <boost/program_options.hpp>

namespace po = boost::program_options;
extern std::shared_ptr<spdlog::logger> global_logger;
extern std::shared_ptr<spdlog::logger> 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<std::string>()->default_value("info"), "Granularity of logger, defaults to info [trace, debug, info, warn, error, critical, off]")
("output_file,o", po::value<std::string>()->default_value("output"), "filename for output")
("numevents,n", po::value<G4int>()->default_value(0), "number of events")
Expand All @@ -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<G4int>()->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<G4int>()->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<G4int>()->default_value(1), "DEPRECATED. Index to select gel type [Wacker = 0, Chiba = 1, IceCube = 2, Wacker_company = 3]")
("reflective_surface", po::value<G4int>()->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<G4int>()->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)
Expand All @@ -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<std::string>("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<bool>("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.
Expand Down Expand Up @@ -167,11 +173,81 @@ void OMSim::initialiseSimulation(OMSimDetectorConstruction* pDetectorConstructio
lUIinterface.applyCommand("/control/execute ", lArgs.get<bool>("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.");
}
4 changes: 2 additions & 2 deletions common/framework/src/OMSimLogger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions common/geometry_construction/include/abcDetectorComponent.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion common/geometry_construction/src/OMSimMDOMFlasher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
mDOMFlasher::mDOMFlasher(InputDataManager *pData)
{
mData = pData;
mCheckOverlaps = OMSimCommandArgsTable::getInstance().get<bool>("check_overlaps");
construction();
}

Expand Down
9 changes: 9 additions & 0 deletions common/geometry_construction/src/abcDetectorComponent.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#include "abcDetectorComponent.hh"
#include "OMSimPMTConstruction.hh"
#include "OMSimLogger.hh"
#include "OMSimCommandArgsTable.hh"

#include <G4LogicalVolume.hh>
#include <G4PVPlacement.hh>
#include <G4SystemOfUnits.hh>
#include <G4Transform3D.hh>



abcDetectorComponent::abcDetectorComponent()
{
mCheckOverlaps = OMSimCommandArgsTable::getInstance().get<bool>("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.
Expand Down
Loading

0 comments on commit 41c706e

Please sign in to comment.