14#include "Framework/Version.h"
15#include "Randomize.hh"
17#include "SimCore/BiasOperators/XsecBiasingOperator.h"
18#include "SimCore/DetectorConstruction.h"
19#include "SimCore/Event/HepMC3GenEvent.h"
20#include "SimCore/G4User/UserEventInformation.h"
23#include "SimCore/SDs/SensitiveDetector.h"
37 dynamic_cast<RunManager*
>(RunManager::GetRunManager())
38 ->getDetectorConstruction();
43 "Included Scoring Planes",
49 auto three_vector_dump = [&header](
const std::string& name,
50 const std::vector<double>& vec) {
58 if (!beam_spot_smear.empty()) {
59 three_vector_dump(
"Smear Beam Spot [mm]", beam_spot_smear);
63 auto string_vector_dump = [&header](
const std::string& name,
64 const std::vector<std::string>& vec) {
66 for (
auto const& val : vec) {
73 parameters_.
get<std::vector<std::string>>(
"pre_init_commands", {}));
76 parameters_.
get<std::vector<std::string>>(
"post_init_commands", {}));
78 simcore::XsecBiasingOperator::Factory::get().apply(
79 [&header](
auto bop) { bop->RecordConfig(header); });
82 PrimaryGenerator::Factory::get().apply([&header, &counter](
auto gen) {
83 std::string gen_id =
"Gen" + std::to_string(counter++);
84 gen->RecordConfig(gen_id, header);
88 if (G4RunManagerKernel::GetRunManagerKernel()) {
90 G4RunManagerKernel::GetRunManagerKernel()->GetVersionString()};
93 ldmx_log(warn) <<
"Unable to access G4 RunManager Kernel. Will not store "
105 std::vector<int> seeds;
106 seeds.push_back(rseed.
getSeed(
"Simulator[0]"));
107 seeds.push_back(rseed.
getSeed(
"Simulator[1]"));
118 std::ostringstream stream;
119 G4Random::saveFullState(stream);
129 SensitiveDetector::Factory::get().apply(
130 [](
auto sd) { sd->onFinishedEvent(); });
139 auto& event_header =
event.getEventHeader();
140 updateEventHeader(event_header);
142 event_header.setStringParameter(
"eventSeed", stream.str());
147 auto hepmc3_events = event_info->getHepMC3GenEvents();
148 for (
auto& hepmc3ev : hepmc3_events) {
149 hepmc3ev.event_number =
event.getEventHeader().getEventNumber();
151 if (hepmc3_events.size() > 0)
event.add(
"SimHepMC3Events", hepmc3_events);
157 savePhotonuclearInteractions(event);
160 auto& history_store = bertini::CascadeHistoryStore::getInstance();
161 ldmx_log(debug) <<
"Checking cascade history store: "
162 << (history_store.empty() ?
"empty" :
"has histories");
163 if (!history_store.empty()) {
164 auto cascade_histories = history_store.extractHistories();
165 ldmx_log(info) <<
"Saving " << cascade_histories.size()
166 <<
" cascade histories to event";
167 event.add(
"PhotonuclearCascadeHistories", cascade_histories);
190 if (seeds.size() == 1) {
191 EXCEPTION_RAISE(
"ConfigurationException",
192 "At least two seeds need to be specified.");
199 constexpr int max_number_of_seeds{100};
200 std::vector<long> seed_vec(max_number_of_seeds, 0);
201 for (std::size_t index{0}; index < seeds.size(); ++index) {
202 seed_vec[index] =
static_cast<long>(seeds[index]);
206 G4Random::setTheSeeds(seed_vec.data());
Thread-local storage for cascade histories during simulation.
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Header file for PrimaryGenerator.
Conditions object for random number seeds.
Class providing a Geant4 run manager implementation.
Run the G4 simulation inside of ldmx-app.
const T & getCondition(const std::string &condition_name)
Access a conditions object for the current event.
void abortEvent()
Abort the event immediately.
Implements an event buffer system for storing event data.
ldmx::EventHeader & getEventHeader()
Get the event header.
Class which represents the process under execution.
System for consistent seeding of random number generators.
static const std::string CONDITIONS_OBJECT_NAME
Conditions object name.
uint64_t getSeed(const std::string &name) const
Access a given seed by name.
Class encapsulating parameters for configuring a processor.
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Implements the Geant4 detector construction.
std::string getDetectorName()
Extension of Geant4 run manager.
std::unique_ptr< RunManager > run_manager_
Manager controlling G4 simulation run.
virtual void prepEvent(framework::Event &event)
prepare a new event before entering into the Geant4 simulation
void configure(framework::config::Parameters ¶meters) override
Callback for the EventProcessor to configure itself from the given set of parameters.
void onProcessEnd() override
Callback called once processing is complete.
framework::config::Parameters parameters_
The parameters used to configure the simulation.
Producer that runs Geant4 simulation inside of ldmx-app.
void configure(framework::config::Parameters ¶meters) override
Callback for the processor to configure itself from the given set of parameters.
Simulator(const std::string &name, framework::Process &process)
Constructor.
void beforeNewRun(ldmx::RunHeader &header) override
Given a non-const reference to the new RunHeader, we can add parameters from the simulation here befo...
void setSeeds(std::vector< int > seeds)
Set the seeds to be used by the Geant4 random engine.
void onNewRun(const ldmx::RunHeader &header) override
Before the run starts (but after the conditions are configured) set up the random seeds for this run.
virtual void produce(framework::Event &event) override
Run simulation and export results to output event.
int num_events_began_
Number of events started.
void onProcessEnd() override
Callback called once processing is complete.
int run_
the run number (for accessing the run header in onFileClose
int num_events_completed_
Number of events completed.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...