13#include "Framework/EventFile.h"
16#include "Framework/Version.h"
22#include "SimCore/DetectorConstruction.h"
25#include "SimCore/Geo/ParserFactory.h"
27#include "SimCore/SensitiveDetector.h"
28#include "SimCore/UserEventInformation.h"
29#include "SimCore/XsecBiasingOperator.h"
34#include "G4BiasingProcessInterface.hh"
35#include "G4CascadeParameters.hh"
36#include "G4Electron.hh"
37#include "G4GDMLParser.hh"
38#include "G4GeometryManager.hh"
39#include "G4UImanager.hh"
40#include "G4UIsession.hh"
41#include "Randomize.hh"
55 dynamic_cast<RunManager*
>(RunManager::GetRunManager())
56 ->getDetectorConstruction();
61 "Included Scoring Planes",
64 "Use Random Seed from Event Header",
68 auto threeVectorDump = [&header](
const std::string& name,
69 const std::vector<double>& vec) {
77 if (!beamSpotSmear.empty()) {
78 threeVectorDump(
"Smear Beam Spot [mm]", beamSpotSmear);
82 auto stringVectorDump = [&header](
const std::string& name,
83 const std::vector<std::string>& vec) {
85 for (
auto const& val : vec) {
90 stringVectorDump(
"Pre Init Command",
92 "preInitCommands", {}));
93 stringVectorDump(
"Post Init Command",
95 "postInitCommands", {}));
98 [&header](
auto bop) { bop->RecordConfig(header); });
102 std::string gen_id =
"Gen" + std::to_string(counter++);
103 gen->RecordConfig(gen_id, header);
107 if (G4RunManagerKernel::GetRunManagerKernel()) {
109 G4RunManagerKernel::GetRunManagerKernel()->GetVersionString()};
112 ldmx_log(warn) <<
"Unable to access G4 RunManager Kernel. Will not store "
113 "G4 Version string.";
121 getCondition<framework::RandomNumberSeedService>(
123 std::vector<int> seeds;
124 seeds.push_back(rseed.
getSeed(
"Simulator[0]"));
125 seeds.push_back(rseed.
getSeed(
"Simulator[1]"));
136 std::ostringstream stream;
137 G4Random::saveFullState(stream);
146 [](
auto sd) { sd->OnFinishedEvent(); });
155 auto& event_header =
event.getEventHeader();
156 updateEventHeader(event_header);
158 event_header.setStringParameter(
"eventSeed", stream.str());
171 std::cout <<
"[ Simulator ] : "
184 if (seeds.size() == 1) {
185 EXCEPTION_RAISE(
"ConfigurationException",
186 "At least two seeds need to be specified.");
193 constexpr int max_number_of_seeds{100};
194 std::vector<long> seedVec(max_number_of_seeds, 0);
195 for (std::size_t index{0}; index < seeds.size(); ++index) {
196 seedVec[index] =
static_cast<long>(seeds[index]);
200 G4Random::setTheSeeds(seedVec.data());
Class which defines basic APrime physics.
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Classes which redirect the output of G4cout and G4cerr.
Header file for PrimaryGenerator.
Class which represents the process under execution.
Conditions object for random number seeds.
Run the G4 simulation inside of ldmx-app.
Class which implements the user tracking action.
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.
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Implements the Geant4 detector construction.
std::string getDetectorName()
void apply(UnaryFunction f) const
Apply the input UnaryFunction to each entry in the inventory.
static Factory & get()
get the factory instance
Extension of Geant4 run manager.
std::unique_ptr< RunManager > runManager_
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.
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.
int numEventsBegan_
Number of events started.
virtual void produce(framework::Event &event) override
Run simulation and export results to output event.
int numEventsCompleted_
Number of events completed.
void onProcessEnd() override
Callback called once processing is complete.
int run_
the run number (for accessing the run header in onFileClose