Skip to content

Commit

Permalink
fix: Add G4 log level tweaking on algorithm initialization (acts-proj…
Browse files Browse the repository at this point in the history
…ect#3570)

This adjusts the G4 loglevel to the level provided by the algorithm at algorithm construction time. Removes some unused loglevel integers from the `Geant4Manager`.
  • Loading branch information
benjaminhuth authored Aug 29, 2024
1 parent 4569230 commit e2063f0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ class Geant4Manager;
/// and loading the Geant4 library which should reset it to its original state.
struct Geant4Handle {
std::mutex mutex;
int logLevel{};
std::unique_ptr<G4RunManager> runManager;
G4VUserPhysicsList *physicsList;
std::string physicsListName;

Geant4Handle(int logLevel, std::unique_ptr<G4RunManager> runManager,
Geant4Handle(std::unique_ptr<G4RunManager> runManager,
std::unique_ptr<G4VUserPhysicsList> physicsList,
std::string physicsListName);
Geant4Handle(const Geant4Handle &) = delete;
Expand All @@ -66,12 +65,11 @@ class Geant4Manager {
std::shared_ptr<Geant4Handle> currentHandle() const;

/// This can only be called once due to Geant4 limitations
std::shared_ptr<Geant4Handle> createHandle(int logLevel,
const std::string &physicsList);
std::shared_ptr<Geant4Handle> createHandle(const std::string &physicsList);

/// This can only be called once due to Geant4 limitations
std::shared_ptr<Geant4Handle> createHandle(
int logLevel, std::unique_ptr<G4VUserPhysicsList> physicsList,
std::unique_ptr<G4VUserPhysicsList> physicsList,
std::string physicsListName);

/// Registers a named physics list factory to the manager for easy
Expand Down
14 changes: 6 additions & 8 deletions Examples/Algorithms/Geant4/src/Geant4Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@

namespace ActsExamples {

Geant4Handle::Geant4Handle(int _logLevel,
std::unique_ptr<G4RunManager> _runManager,
Geant4Handle::Geant4Handle(std::unique_ptr<G4RunManager> _runManager,
std::unique_ptr<G4VUserPhysicsList> _physicsList,
std::string _physicsListName)
: logLevel(_logLevel),
runManager(std::move(_runManager)),
: runManager(std::move(_runManager)),
physicsList(_physicsList.release()),
physicsListName(std::move(_physicsListName)) {
if (runManager == nullptr) {
Expand Down Expand Up @@ -81,12 +79,12 @@ std::shared_ptr<Geant4Handle> Geant4Manager::currentHandle() const {
}

std::shared_ptr<Geant4Handle> Geant4Manager::createHandle(
int logLevel, const std::string& physicsList) {
return createHandle(logLevel, createPhysicsList(physicsList), physicsList);
const std::string& physicsList) {
return createHandle(createPhysicsList(physicsList), physicsList);
}

std::shared_ptr<Geant4Handle> Geant4Manager::createHandle(
int logLevel, std::unique_ptr<G4VUserPhysicsList> physicsList,
std::unique_ptr<G4VUserPhysicsList> physicsList,
std::string physicsListName) {
if (!m_handle.expired()) {
throw std::runtime_error("creating a second handle is prohibited");
Expand All @@ -100,7 +98,7 @@ std::shared_ptr<Geant4Handle> Geant4Manager::createHandle(
auto runManager = std::unique_ptr<G4RunManager>(
G4RunManagerFactory::CreateRunManager(G4RunManagerType::SerialOnly));

auto handle = std::make_shared<Geant4Handle>(logLevel, std::move(runManager),
auto handle = std::make_shared<Geant4Handle>(std::move(runManager),
std::move(physicsList),
std::move(physicsListName));

Expand Down
11 changes: 6 additions & 5 deletions Examples/Algorithms/Geant4/src/Geant4Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void ActsExamples::Geant4SimulationBase::commonInitialization() {
runManager().SetUserInitialization(m_detectorConstruction);
runManager().InitializeGeometry();
}

m_geant4Instance->tweakLogging(m_geant4Level);
}

G4RunManager& ActsExamples::Geant4SimulationBase::runManager() const {
Expand Down Expand Up @@ -175,10 +177,10 @@ ActsExamples::Geant4SimulationBase::geant4Handle() const {
ActsExamples::Geant4Simulation::Geant4Simulation(const Config& cfg,
Acts::Logging::Level level)
: Geant4SimulationBase(cfg, "Geant4Simulation", level), m_cfg(cfg) {
m_geant4Instance = m_cfg.geant4Handle
? m_cfg.geant4Handle
: Geant4Manager::instance().createHandle(
m_geant4Level, m_cfg.physicsList);
m_geant4Instance =
m_cfg.geant4Handle
? m_cfg.geant4Handle
: Geant4Manager::instance().createHandle(m_cfg.physicsList);
if (m_geant4Instance->physicsListName != m_cfg.physicsList) {
throw std::runtime_error("inconsistent physics list");
}
Expand Down Expand Up @@ -339,7 +341,6 @@ ActsExamples::Geant4MaterialRecording::Geant4MaterialRecording(
m_cfg.geant4Handle
? m_cfg.geant4Handle
: Geant4Manager::instance().createHandle(
m_geant4Level,
std::make_unique<MaterialPhysicsList>(
m_logger->cloneWithSuffix("MaterialPhysicsList")),
physicsListName);
Expand Down

0 comments on commit e2063f0

Please sign in to comment.