File indexing completed on 2025-01-18 09:55:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #ifndef DDG4_GEANT4INPUTACTION_H
0025 #define DDG4_GEANT4INPUTACTION_H
0026
0027
0028 #include <DDG4/Geant4Vertex.h>
0029 #include <DDG4/Geant4Particle.h>
0030 #include <DDG4/Geant4GeneratorAction.h>
0031 #include <Parsers/Parsers.h>
0032
0033
0034 #include <memory>
0035 #include <set>
0036 #include <vector>
0037
0038
0039 class G4Event;
0040 class G4Run;
0041
0042
0043 namespace dd4hep {
0044
0045
0046 namespace sim {
0047
0048 class Geant4InputAction;
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 class Geant4EventReader {
0061
0062 public:
0063 typedef Geant4Vertex Vertex;
0064 typedef Geant4Particle Particle;
0065 typedef std::vector<Particle*> Particles;
0066 typedef std::vector<Vertex*> Vertices;
0067
0068 enum EventReaderStatus {
0069 EVENT_READER_ERROR=0,
0070 EVENT_READER_OK=1,
0071 EVENT_READER_NO_DIRECT=2,
0072 EVENT_READER_NO_PRIMARIES=4,
0073 EVENT_READER_NO_FACTORY=6,
0074 EVENT_READER_IO_ERROR=8,
0075 EVENT_READER_EOF=10
0076 };
0077 protected:
0078
0079 std::string m_name;
0080
0081 bool m_directAccess { false };
0082
0083 int m_currEvent { 0 };
0084
0085 Geant4InputAction *m_inputAction { nullptr };
0086
0087
0088
0089
0090
0091 template <typename T>
0092 void _getParameterValue( std::map< std::string, std::string > & parameters,
0093 std::string const& parameterName,
0094 T& parameter, T defaultValue ) {
0095
0096 if( parameters.find( parameterName ) != parameters.end() ) {
0097 dd4hep::Parsers::parse( parameter, parameters.at( parameterName ) );
0098 parameters.erase( parameterName );
0099 } else {
0100 parameter = std::move(defaultValue);
0101 }
0102 }
0103
0104 public:
0105
0106 Geant4EventReader(const std::string& nam);
0107
0108 virtual ~Geant4EventReader();
0109
0110 Geant4Context* context() const;
0111
0112 void setInputAction(Geant4InputAction* action);
0113
0114 const std::string& name() const { return m_name; }
0115
0116 bool hasDirectAccess() const { return m_directAccess; }
0117
0118 int currentEventNumber() const { return m_currEvent; }
0119
0120
0121
0122
0123
0124
0125
0126
0127 virtual EventReaderStatus moveToEvent(int event_number);
0128
0129 virtual EventReaderStatus skipEvent();
0130
0131
0132
0133 virtual EventReaderStatus readParticles(int event_number,
0134 Vertices& vertices,
0135 Particles& particles) = 0;
0136
0137
0138 virtual EventReaderStatus setParameters( std::map< std::string, std::string > & ) {return EVENT_READER_OK; }
0139
0140
0141 virtual void checkParameters( std::map< std::string, std::string >& );
0142
0143
0144 virtual void registerRunParameters() {}
0145 };
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 class Geant4InputAction : public Geant4GeneratorAction {
0158
0159 public:
0160 typedef Geant4Vertex Vertex;
0161 typedef Geant4Particle Particle;
0162 typedef std::vector<Particle*> Particles;
0163 typedef std::vector<Vertex*> Vertices;
0164 protected:
0165
0166 std::string m_input;
0167
0168 int m_firstEvent;
0169
0170 int m_mask;
0171
0172 double m_momScale;
0173
0174 Geant4EventReader* m_reader;
0175
0176 int m_currentEventNumber;
0177
0178 bool m_abort;
0179
0180 std::map< std::string, std::string> m_parameters;
0181
0182
0183 std::set<int> m_alternativeDecayStatuses = {};
0184
0185
0186 void beginRun(const G4Run*);
0187
0188
0189 void createReader();
0190 public:
0191
0192 int readParticles(int event_number,
0193 Vertices& vertices,
0194 Particles& particles);
0195 using PropertyMask = dd4hep::detail::ReferenceBitMask<int>;
0196
0197 void setGeneratorStatus(int generatorStatus, PropertyMask& status);
0198
0199
0200 std::string issue(int i) const;
0201
0202
0203 Geant4InputAction(Geant4Context* context, const std::string& name);
0204
0205 virtual ~Geant4InputAction();
0206
0207 Particles* new_particles() const { return new Particles; }
0208
0209 virtual void operator()(G4Event* event) override;
0210 };
0211 }
0212 }
0213 #endif