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) {
27 parameters.getParameter<std::vector<std::string>>("initCommands");
28 for (const auto& cmd : init_commands_) {
29 int g4Ret = G4UImanager::GetUIpointer()->ApplyCommand(cmd);
30 if (g4Ret > 0) {
31 EXCEPTION_RAISE("InitCmd",
32 "Initialization command '" + cmd +
33 "' returned a failue status from Geant4: " +
34 std::to_string(g4Ret));
35 }
36 }
37}
38
40 // just pass to the Geant4 implementation
41 theG4Source_.GeneratePrimaryVertex(event);
42 return;
43}
44
45void GeneralParticleSource::RecordConfig(const std::string& id,
46 ldmx::RunHeader& rh) {
47 rh.setStringParameter(id + " Class",
48 "simcore::generators::GeneralParticleSource");
49 std::string init_prefix{id + " Init Cmd "};
50 for (std::size_t i{0}; i < init_commands_.size(); i++) {
51 rh.setStringParameter(init_prefix + std::to_string(i),
52 init_commands_.at(i));
53 }
54}
55
56} // namespace generators
57} // namespace simcore
58
Extension of G4GeneralParticleSource.
#define DECLARE_GENERATOR(CLASS)
@macro DECLARE_GENERATOR
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:54
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:214
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)
void GeneratePrimaryVertex(G4Event *event) override
Generate the primary vertices in the Geant4 event.
G4GeneralParticleSource theG4Source_
The underlying Geant4 GPS implementation.