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 "SimCore/ConditionsInterface.h"
14#include "SimCore/DetectorConstruction.h"
15#include "SimCore/G4Session.h"
17#include "SimCore/Geo/ParserFactory.h"
18#include "SimCore/RunManager.h"
19#include "SimCore/SensitiveDetector.h"
20#include "SimCore/UserEventInformation.h"
21namespace simcore {
23 public:
24 SimulatorBase(const std::string& name, framework::Process& process);
25 virtual ~SimulatorBase() = default;
26 void configure(framework::config::Parameters& parameters) override;
27
28 protected:
30 void onProcessEnd() override;
39 void onProcessStart() override;
42
44 G4UImanager* uiManager_{nullptr};
45
47 std::unique_ptr<RunManager> runManager_;
48
50 std::unique_ptr<G4UIsession> sessionHandle_;
51
54 static const std::vector<std::string> invalidCommands_;
55
56 /*********************************************************
57 * Python Configuration Parameters
58 *********************************************************/
59
61 int verbosity_{1};
64
65 std::vector<std::string> preInitCommands_;
66
67 std::vector<std::string> postInitCommands_;
68
69 /*
70 *
71 * On succesful event, update event header properties like total PN/EN energy
72 * and event weight.
73 *
74 */
75 virtual void updateEventHeader(ldmx::EventHeader& eventHeader) const;
76
77 /*
78 * Save all tracks from the event that are marked for saving
79 */
80 virtual void saveTracks(framework::Event& event);
81
82 /*
83 * Save hits from sensitive detectors.
84 */
85 virtual void saveSDHits(framework::Event& event);
86
87 virtual void produce(framework::Event& event) override = 0;
88
89 private:
90 /*
91 * Set up logging for Geant4 during initialization
92 *
93 * If the verbosity level is set to 0, create a batch session
94 * If the verbosity level is > 1, log everything to a file.
95 * Otherwise, dump the output. If a prefix has been specified, append it ot
96 * the log message.
97 **/
98 void createLogging();
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} // namespace simcore
115
116#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:41
Class which represents the process under execution.
Definition Process.h:36
Base class for a module which produces a data product.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
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.
G4UImanager * uiManager_
User interface handle.
ConditionsInterface conditionsIntf_
Conditions interface.
std::unique_ptr< RunManager > runManager_
Manager controlling G4 simulation run.
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.
int verbosity_
Vebosity for the simulation.
std::unique_ptr< G4UIsession > sessionHandle_
Handle to the G4Session -> how to deal with G4cout and G4cerr.
void onProcessStart() override
Initialization of simulation.
void onProcessEnd() override
Callback called once processing is complete.
static const std::vector< std::string > invalidCommands_
Commands not allowed to be passed from python config file This is because Simulator already runs them...
framework::config::Parameters parameters_
The parameters used to configure the simulation.