LDMX Software
SimulatorBase.h
1#ifndef SIMCORE_SIMULATOR_BASE_H_
2#define SIMCORE_SIMULATOR_BASE_H_
3
4#include <G4CascadeParameters.hh>
5#include <G4GeometryManager.hh>
6#include <G4UImanager.hh>
7#include <G4UIsession.hh>
8
9#include "Framework/Configure/Parameters.h"
10#include "Framework/EventFile.h"
13#include "Framework/Logger.h"
14#include "SimCore/ConditionsInterface.h"
15#include "SimCore/DetectorConstruction.h"
16#include "SimCore/G4Session.h"
18#include "SimCore/G4User/UserEventInformation.h"
19#include "SimCore/Geo/Parser.h"
20#include "SimCore/RunManager.h"
21#include "SimCore/SDs/SensitiveDetector.h"
22
23namespace simcore {
25 public:
26 SimulatorBase(const std::string& name, framework::Process& process);
27 virtual ~SimulatorBase() = default;
28 void configure(framework::config::Parameters& parameters) override;
29
30 protected:
32 void onProcessEnd() override;
41 void onProcessStart() override;
44
46 G4UImanager* ui_manager_{nullptr};
47
49 std::unique_ptr<RunManager> run_manager_;
50
52 std::unique_ptr<LoggedSession> session_handle_;
53
56 static const std::vector<std::string> INVALID_COMMANDS;
57
58 /*********************************************************
59 * Python Configuration Parameters
60 *********************************************************/
63
64 std::vector<std::string> pre_init_commands_;
65
66 std::vector<std::string> post_init_commands_;
67
68 /*
69 *
70 * On succesful event, update event header properties like total PN/EN energy
71 * and event weight.
72 *
73 */
74 virtual void updateEventHeader(ldmx::EventHeader& eventHeader) const;
75
76 /*
77 * Save all tracks from the event that are marked for saving
78 */
79 virtual void saveTracks(framework::Event& event);
80
81 /*
82 * Save hits from sensitive detectors.
83 */
84 virtual void saveSDHits(framework::Event& event);
85
86 virtual void produce(framework::Event& event) override = 0;
87
88 private:
89 /*
90 * Set up logging for Geant4 during initialization
91 *
92 * If the verbosity level is set to 0, create a batch session
93 * If the verbosity level is > 1, log everything to a file.
94 * Otherwise, dump the output. If a prefix has been specified, append it ot
95 * the log message.
96 **/
97 void createLogging();
98
99 /*
100 * Create the GDML parser and load the detector geometry during
101 * initialization.
102 */
103 void buildGeometry();
104
105 /*
106 * Check that no invalid commands have been requested or that the old style
107 * of setting the run number on the simulator rather than the process object
108 * wasn't used.
109 *
110 * @see invalidCommands_
111 */
112 void verifyParameters() const;
113
114 protected:
115 /*
116 * Enable logging
117 */
118 enableLogging("SimulatorBase")
119};
120} // namespace simcore
121
122#endif /* SIMCORE_SIMULATOR_BASE_H_ */
Class that provides header information about an event such as event number and timestamp.
Base classes for all user event processing components to extend.
Classes which redirect the output of G4cout and G4cerr.
Class providing a Geant4 run manager implementation.
Class which implements the user tracking action.
Implements an event buffer system for storing event data.
Definition Event.h:42
Class which represents the process under execution.
Definition Process.h:36
Base class for a module which produces a data product.
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
Provides header information an event such as event number and timestamp.
Definition EventHeader.h:44
Handle to the conditions system, provided at construction to classes which require it.
std::unique_ptr< LoggedSession > session_handle_
Handle to the G4Session -> how to deal with G4cout and G4cerr.
G4UImanager * ui_manager_
User interface handle.
std::unique_ptr< RunManager > run_manager_
Manager controlling G4 simulation run.
ConditionsInterface conditions_intf_
Conditions interface.
virtual void produce(framework::Event &event) override=0
Process the event and put new data products into it.
void configure(framework::config::Parameters &parameters) override
Callback for the EventProcessor to configure itself from the given set of parameters.
void onProcessStart() override
Initialization of simulation.
static const std::vector< std::string > INVALID_COMMANDS
Commands not allowed to be passed from python config file This is because Simulator already runs them...
void onProcessEnd() override
Callback called once processing is complete.
framework::config::Parameters parameters_
The parameters used to configure the simulation.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...