22 dynamic_cast<RunManager*
>(RunManager::GetRunManager())
23 ->getDetectorConstruction();
28 "Included Scoring Planes",
34 auto three_vector_dump = [&header](
const std::string& name,
35 const std::vector<double>& vec) {
43 if (!beam_spot_smear.empty()) {
44 three_vector_dump(
"Smear Beam Spot [mm]", beam_spot_smear);
48 auto string_vector_dump = [&header](
const std::string& name,
49 const std::vector<std::string>& vec) {
51 for (
auto const& val : vec) {
61 parameters_.
get<std::vector<std::string>>(
"postInitCommands", {}));
63 simcore::XsecBiasingOperator::Factory::get().apply(
64 [&header](
auto bop) { bop->RecordConfig(header); });
67 PrimaryGenerator::Factory::get().apply([&header, &counter](
auto gen) {
68 std::string gen_id =
"Gen" + std::to_string(counter++);
69 gen->RecordConfig(gen_id, header);
73 if (G4RunManagerKernel::GetRunManagerKernel()) {
75 G4RunManagerKernel::GetRunManagerKernel()->GetVersionString()};
78 ldmx_log(warn) <<
"Unable to access G4 RunManager Kernel. Will not store "
90 std::vector<int> seeds;
91 seeds.push_back(rseed.
getSeed(
"Simulator[0]"));
92 seeds.push_back(rseed.
getSeed(
"Simulator[1]"));
103 std::ostringstream stream;
104 G4Random::saveFullState(stream);
112 SensitiveDetector::Factory::get().apply(
113 [](
auto sd) { sd->onFinishedEvent(); });
122 auto& event_header =
event.getEventHeader();
123 updateEventHeader(event_header);
125 event_header.setStringParameter(
"eventSeed", stream.str());
130 auto hepmc3_events = event_info->getHepMC3GenEvents();
131 for (
auto& hepmc3ev : hepmc3_events) {
132 hepmc3ev.event_number =
event.getEventHeader().getEventNumber();
134 if (hepmc3_events.size() > 0)
event.add(
"SimHepMC3Events", hepmc3_events);
160 if (seeds.size() == 1) {
161 EXCEPTION_RAISE(
"ConfigurationException",
162 "At least two seeds need to be specified.");
169 constexpr int max_number_of_seeds{100};
170 std::vector<long> seed_vec(max_number_of_seeds, 0);
171 for (std::size_t index{0}; index < seeds.size(); ++index) {
172 seed_vec[index] =
static_cast<long>(seeds[index]);
176 G4Random::setTheSeeds(seed_vec.data());
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
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.
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 ...