Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move RunManager and Biasing to logging system #1630

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SimCore/include/SimCore/RunManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/* Framework */
/*~~~~~~~~~~~~~~~*/
#include "Framework/Configure/Parameters.h"
#include "Framework/EventProcessor.h"
#include "SimCore/KaonPhysics.h"

namespace simcore {
Expand Down Expand Up @@ -108,6 +109,9 @@ class RunManager : public G4RunManager {
*/
bool useRootSeed_{false};

/// Enable logging
enableLogging("RunManager")

}; // RunManager
} // namespace simcore

Expand Down
3 changes: 2 additions & 1 deletion SimCore/include/SimCore/XsecBiasingOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Framework/Configure/Parameters.h"
#include "Framework/EventProcessor.h"
#include "Framework/Logger.h"
#include "Framework/RunHeader.h"
#include "SimCore/Factory.h"

Expand Down Expand Up @@ -177,7 +178,7 @@ class XsecBiasingOperator : public G4VBiasingOperator {
return nullptr;
}
/// Enable logging
enableLogging("EcalProcessFilter")
framework::logging::logger theLog_;

}; // XsecBiasingOperator
} // namespace simcore
Expand Down
27 changes: 11 additions & 16 deletions SimCore/src/SimCore/RunManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ void RunManager::setupPhysics() {
parallelWorldPath_ = parameters_.getParameter<std::string>("scoringPlanes");
isPWEnabled_ = !parallelWorldPath_.empty();
if (isPWEnabled_) {
std::cout
<< "[ RunManager ]: Parallel worlds physics list has been registered."
<< std::endl;
ldmx_log(debug) << "Parallel worlds physics list has been registered";
pList->RegisterPhysics(new G4ParallelWorldPhysics("ldmxParallelWorld"));
}

Expand All @@ -69,8 +67,8 @@ void RunManager::setupPhysics() {
parameters_.getParameter<std::vector<framework::config::Parameters>>(
"biasing_operators", {})};
if (!biasing_operators.empty()) {
std::cout << "[ RunManager ]: Biasing enabled with "
<< biasing_operators.size() << " operator(s)." << std::endl;
ldmx_log(info) << " Biasing enabled with " << biasing_operators.size()
<< " operator(s)";

// create all the biasing operators that will be used
for (framework::config::Parameters& bop : biasing_operators) {
Expand All @@ -85,12 +83,12 @@ void RunManager::setupPhysics() {
// specify which particles are going to be biased
// this will put a biasing interface wrapper around *all* processes
// associated with these particles
simcore::XsecBiasingOperator::Factory::get().apply([biasingPhysics](
auto bop) {
std::cout << "[ RunManager ]: Biasing operator '" << bop->GetName()
<< "' set to bias " << bop->getParticleToBias() << std::endl;
biasingPhysics->Bias(bop->getParticleToBias());
});
simcore::XsecBiasingOperator::Factory::get().apply(
[this, biasingPhysics](auto bop) {
ldmx_log(info) << "Biasing operator '" << bop->GetName()
<< "' set to bias " << bop->getParticleToBias();
biasingPhysics->Bias(bop->getParticleToBias());
});

// Register the physics constructor to the physics list:
pList->RegisterPhysics(biasingPhysics);
Expand All @@ -105,8 +103,7 @@ void RunManager::Initialize() {
// The parallel world needs to be registered before the mass world is
// constructed i.e. before G4RunManager::Initialize() is called.
if (isPWEnabled_) {
std::cout << "[ RunManager ]: Parallel worlds have been enabled."
<< std::endl;
ldmx_log(debug) << "Parallel worlds have been enabled";

auto validateGeometry_{parameters_.getParameter<bool>("validate_detector")};
G4GDMLParser* pwParser = new G4GDMLParser();
Expand Down Expand Up @@ -182,9 +179,7 @@ void RunManager::TerminateOneEvent() {
reactivate_dark_brem(G4Electron::Definition()->GetProcessManager());

if (this->GetVerboseLevel() > 1) {
std::cout << "[ RunManager ] : "
<< "Reset the dark brem process (if it was activated)."
<< std::endl;
ldmx_log(debug) << "Reset the dark brem process (if it was activated)";
}
}

Expand Down
5 changes: 2 additions & 3 deletions SimCore/src/SimCore/XsecBiasingOperator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace simcore {

XsecBiasingOperator::XsecBiasingOperator(
std::string name, const framework::config::Parameters& parameters)
: G4VBiasingOperator(name) {}
: G4VBiasingOperator(name), theLog_{framework::logging::makeLogger(name)} {}

void XsecBiasingOperator::StartRun() {
if (this->getParticleToBias().compare("gamma") == 0) {
Expand All @@ -23,8 +23,7 @@ void XsecBiasingOperator::StartRun() {
this->getParticleToBias() + "'.");
}

std::cout << "[ XsecBiasingOperator ]: Biasing particles of type "
<< this->getParticleToBias() << std::endl;
ldmx_log(info) << "Biasing particles of type " << this->getParticleToBias();

if (processIsBiased(this->getProcessToBias())) {
xsecOperation_ =
Expand Down