11 #include <simulation/modules/fullsim/FullSimTimingModule.h>
12 #include <simulation/kernel/RunManager.h>
13 #include <framework/gearbox/Unit.h>
14 #include <G4EventManager.hh>
15 #include <G4VSteppingVerbose.hh>
16 #include <G4RegionStore.hh>
17 #include <framework/logging/Logger.h>
36 setDescription(
"Provide more detailed timing info for FullSim module");
40 G4VSteppingVerbose* old = G4VSteppingVerbose::GetInstance();
43 G4VSteppingVerbose::SetInstance(
nullptr);
47 processStep(track, volume, time);
49 G4VSteppingVerbose::SetInstance(m_timing);
52 addParam(
"rootFile", m_rootFileName,
"Name of the output root file. If none "
53 " is given, no file will be created", std::string(
""));
73 if (runManager.GetUserPrimaryGeneratorAction()) {
84 G4SteppingManager* stepping = G4EventManager::GetEventManager()->GetTrackingManager()->GetSteppingManager();
88 stepping->SetVerboseLevel(1);
97 for (G4Region* region : * (G4RegionStore::GetInstance())) {
99 if (region->GetNumberOfRootVolumes() == 0)
continue;
105 "SimulationTiming",
"Simulation Timing;region;stepping time per event / ms",
130 const G4Region*
const region = volume->GetRegion();
147 B2RESULT(
"FullSimTiming: Total simulation stepping time: " << (
m_totalTime /
Unit::s) <<
" s");
148 B2RESULT(
"FullSimTiming: Number of simulated events: " <<
m_eventCount);
154 size_t regionWidth {6};
156 m_timingProfile->GetXaxis()->SetBinLabel(it.second + 1, it.first->GetName().c_str());
157 regionWidth = std::max(regionWidth, it.first->GetName().size());
169 size_t maxContentWidth {4};
170 size_t maxErrorWidth {4};
179 const size_t contentWidth = std::floor(std::log10(content > 0 ? content : 1) + 1);
180 const size_t errorWidth = std::floor(std::log10(error > 0 ? error : 1) + 1);
182 maxContentWidth = std::max(maxContentWidth, contentWidth + 3);
183 maxErrorWidth = std::max(maxErrorWidth, errorWidth + 3);
188 B2RESULT(
"FullSimTiming: Simulation stepping time per event and region");
191 << std::setw(regionWidth + 1) << std::left <<
m_timingProfile->GetXaxis()->GetBinLabel(i + 1) <<
" "
192 << std::right << std::fixed << std::setprecision(2)
193 << std::setw(maxContentWidth) <<
m_timingProfile->GetBinContent(i + 1) <<
" ms +- "
194 << std::setw(maxErrorWidth) <<
m_timingProfile->GetBinError(i + 1) <<
" ms ("
195 << std::setw(6) << (
m_timingProfile->GetBinContent(i + 1) / totalAvg) <<
" %)"