LDMX Software
GeneralParticleSource.cxx
Go to the documentation of this file.
1
8
9/*~~~~~~~~~~~~*/
10/* Geant4 */
11/*~~~~~~~~~~~~*/
12#include "G4Event.hh"
13#include "G4UImanager.hh"
14
15/*~~~~~~~~~~~~~~~*/
16/* Framework */
17/*~~~~~~~~~~~~~~~*/
18#include "Framework/Configure/Parameters.h"
19
20namespace simcore {
21namespace generators {
22
24 const std::string& name, const framework::config::Parameters& parameters)
25 : PrimaryGenerator(name, parameters) {
26 init_commands_ = parameters.get<std::vector<std::string>>("initCommands");
27 for (const auto& cmd : init_commands_) {
28 int g4_ret = G4UImanager::GetUIpointer()->ApplyCommand(cmd);
29 if (g4_ret > 0) {
30 EXCEPTION_RAISE("InitCmd",
31 "Initialization command '" + cmd +
32 "' returned a failue status from Geant4: " +
33 std::to_string(g4_ret));
34 }
35 }
36}
37
39 // just pass to the Geant4 implementation
40 the_g4_source_.GeneratePrimaryVertex(event);
41 return;
42}
43
44void GeneralParticleSource::RecordConfig(const std::string& id,
45 ldmx::RunHeader& rh) {
46 rh.setStringParameter(id + " Class",
47 "simcore::generators::GeneralParticleSource");
48 std::string init_prefix{id + " Init Cmd "};
49 for (std::size_t i{0}; i < init_commands_.size(); i++) {
50 rh.setStringParameter(init_prefix + std::to_string(i),
51 init_commands_.at(i));
52 }
53}
54
55} // namespace generators
56} // namespace simcore
57
Extension of G4GeneralParticleSource.
#define DECLARE_GENERATOR(CLASS)
@macro DECLARE_GENERATOR
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:57
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:222
Interface that defines a simulation primary generator.
Class that extends the functionality of G4GeneralParticleSource.
void RecordConfig(const std::string &id, ldmx::RunHeader &rh) override
Record the configuration of the primary generator into the run header.
GeneralParticleSource(const std::string &name, const framework::config::Parameters &parameters)
Constructor.
std::vector< std::string > init_commands_
storage of initialization commands (for config recording)
G4GeneralParticleSource the_g4_source_
The underlying Geant4 GPS implementation.
void GeneratePrimaryVertex(G4Event *event) override
Generate the primary vertices in the Geant4 event.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...