DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4InputAction.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
24 #ifndef DDG4_GEANT4INPUTACTION_H
25 #define DDG4_GEANT4INPUTACTION_H
26 
27 // Framework include files
28 #include <DDG4/Geant4Vertex.h>
29 #include <DDG4/Geant4Particle.h>
31 #include <Parsers/Parsers.h>
32 
33 // C/C++ include files
34 #include <memory>
35 #include <set>
36 #include <vector>
37 
38 // Forward declarations
39 class G4Event;
40 class G4Run;
41 
43 namespace dd4hep {
44 
46  namespace sim {
47 
48  class Geant4InputAction;
49 
51 
61 
62  public:
65  typedef std::vector<Particle*> Particles;
66  typedef std::vector<Vertex*> Vertices;
76  };
77  protected:
79  std::string m_name;
81  bool m_directAccess { false };
83  int m_currEvent { 0 };
86 
88 
91  template <typename T>
92  void _getParameterValue( std::map< std::string, std::string > & parameters,
93  std::string const& parameterName,
94  T& parameter, T defaultValue ) {
95 
96  if( parameters.find( parameterName ) != parameters.end() ) {
97  dd4hep::Parsers::parse( parameter, parameters.at( parameterName ) );
98  parameters.erase( parameterName );
99  } else {
100  parameter = std::move(defaultValue);
101  }
102  }
103 
104  public:
106  Geant4EventReader(const std::string& nam);
108  virtual ~Geant4EventReader();
110  Geant4Context* context() const;
112  void setInputAction(Geant4InputAction* action);
114  const std::string& name() const { return m_name; }
116  bool hasDirectAccess() const { return m_directAccess; }
118  int currentEventNumber() const { return m_currEvent; }
120 
127  virtual EventReaderStatus moveToEvent(int event_number);
129  virtual EventReaderStatus skipEvent();
131 
133  virtual EventReaderStatus readParticles(int event_number,
134  Vertices& vertices,
135  Particles& particles) = 0;
136 
138  virtual EventReaderStatus setParameters( std::map< std::string, std::string > & ) {return EVENT_READER_OK; }
139 
141  virtual void checkParameters( std::map< std::string, std::string >& );
142 
144  virtual void registerRunParameters() {}
145  };
146 
148 
158 
159  public:
162  typedef std::vector<Particle*> Particles;
163  typedef std::vector<Vertex*> Vertices;
164  protected:
166  std::string m_input;
170  int m_mask;
172  double m_momScale;
178  bool m_abort;
180  std::map< std::string, std::string> m_parameters;
181 
183  std::set<int> m_alternativeDecayStatuses = {};
184 
186  void beginRun(const G4Run*);
187 
189  void createReader();
190  public:
192  int readParticles(int event_number,
193  Vertices& vertices,
194  Particles& particles);
195  using PropertyMask = dd4hep::detail::ReferenceBitMask<int>;
197  void setGeneratorStatus(int generatorStatus, PropertyMask& status);
198 
200  std::string issue(int i) const;
201 
207  Particles* new_particles() const { return new Particles; }
209  virtual void operator()(G4Event* event) override;
210  };
211  } /* End namespace sim */
212 } /* End namespace dd4hep */
213 #endif // DDG4_GEANT4INPUTACTION_H
dd4hep::sim::Geant4EventReader::Vertex
Geant4Vertex Vertex
Definition: Geant4InputAction.h:63
dd4hep::sim::Geant4EventReader::EVENT_READER_EOF
@ EVENT_READER_EOF
Definition: Geant4InputAction.h:75
dd4hep::sim::Geant4EventReader::EVENT_READER_NO_DIRECT
@ EVENT_READER_NO_DIRECT
Definition: Geant4InputAction.h:71
dd4hep::sim::Geant4InputAction::m_reader
Geant4EventReader * m_reader
Event reader object.
Definition: Geant4InputAction.h:174
dd4hep::sim::Geant4EventReader::context
Geant4Context * context() const
Get the context (from the input action)
Definition: Geant4InputAction.cpp:41
dd4hep::sim::Geant4EventReader::EventReaderStatus
EventReaderStatus
Status codes of the event reader object. Anything with NOT low-bit set is an error.
Definition: Geant4InputAction.h:68
dd4hep::sim::Geant4InputAction::m_abort
bool m_abort
Flag to call abortEvent in case of failure (default: true)
Definition: Geant4InputAction.h:178
dd4hep::sim::Geant4EventReader::Particles
std::vector< Particle * > Particles
Definition: Geant4InputAction.h:65
Geant4InputAction
Basic geant4 event reader class. This interface/base-class must be implemented by concrete readers.
dd4hep::sim::Geant4InputAction::m_mask
int m_mask
Property; interaction mask.
Definition: Geant4InputAction.h:170
dd4hep::sim::Geant4InputAction::m_currentEventNumber
int m_currentEventNumber
current event number without initially skipped events
Definition: Geant4InputAction.h:176
dd4hep::sim::Geant4EventReader::_getParameterValue
void _getParameterValue(std::map< std::string, std::string > &parameters, std::string const &parameterName, T &parameter, T defaultValue)
transform the string parameter value into the type of parameter
Definition: Geant4InputAction.h:92
dd4hep::sim::Geant4EventReader::~Geant4EventReader
virtual ~Geant4EventReader()
Default destructor.
Definition: Geant4InputAction.cpp:37
dd4hep::sim::Geant4InputAction::m_firstEvent
int m_firstEvent
Property: SYNCEVT.
Definition: Geant4InputAction.h:168
dd4hep::sim::Geant4EventReader::m_currEvent
int m_currEvent
Current event number.
Definition: Geant4InputAction.h:83
dd4hep::sim::Geant4EventReader::EVENT_READER_ERROR
@ EVENT_READER_ERROR
Definition: Geant4InputAction.h:69
dd4hep::sim::Geant4InputAction::PropertyMask
dd4hep::detail::ReferenceBitMask< int > PropertyMask
Definition: Geant4InputAction.h:195
dd4hep::sim::Geant4InputAction::operator()
virtual void operator()(G4Event *event) override
Callback to generate primary particles.
dd4hep::sim::Geant4EventReader::readParticles
virtual EventReaderStatus readParticles(int event_number, Vertices &vertices, Particles &particles)=0
Read an event and fill a vector of MCParticles.
dd4hep::sim::Geant4EventReader::Particle
Geant4Particle Particle
Definition: Geant4InputAction.h:64
dd4hep::sim::Geant4InputAction::beginRun
void beginRun(const G4Run *)
Perform some actions before the run starts, like opening the event inputs.
Geant4GeneratorAction.h
dd4hep::sim::Geant4InputAction::m_input
std::string m_input
Property: input file.
Definition: Geant4InputAction.h:166
dd4hep::sim::Geant4EventReader::moveToEvent
virtual EventReaderStatus moveToEvent(int event_number)
Move to the indicated event number.
Definition: Geant4InputAction.cpp:113
dd4hep::sim::Geant4InputAction::Geant4InputAction
Geant4InputAction(Geant4Context *context, const std::string &name)
Standard constructor.
dd4hep::sim::Geant4EventReader::EVENT_READER_NO_FACTORY
@ EVENT_READER_NO_FACTORY
Definition: Geant4InputAction.h:73
dd4hep::sim::Geant4EventReader::registerRunParameters
virtual void registerRunParameters()
Register Run Parameters.
Definition: Geant4InputAction.h:144
dd4hep::sim::Geant4GeneratorAction
Concrete implementation of the Geant4 generator action base class.
Definition: Geant4GeneratorAction.h:47
dd4hep::sim::Geant4EventReader::currentEventNumber
int currentEventNumber() const
return current Event Number
Definition: Geant4InputAction.h:118
dd4hep::sim::Geant4EventReader::skipEvent
virtual EventReaderStatus skipEvent()
Skip event. To be implemented for sequential sources.
Definition: Geant4InputAction.cpp:55
dd4hep::sim::Geant4EventReader::setParameters
virtual EventReaderStatus setParameters(std::map< std::string, std::string > &)
pass parameters to the event reader object
Definition: Geant4InputAction.h:138
dd4hep::Parsers::parse
int parse(Property &result, const std::string &input)
Definition: ComponentProperties.cpp:187
dd4hep::sim::Geant4EventReader::m_name
std::string m_name
File name to be opened and read.
Definition: Geant4InputAction.h:79
dd4hep::sim::Geant4EventReader::m_directAccess
bool m_directAccess
Flag if direct event access is supported. To be explicitly set by subclass constructors.
Definition: Geant4InputAction.h:81
dd4hep::sim::Geant4InputAction::issue
std::string issue(int i) const
helper to report Geant4 exceptions
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4InputAction::setGeneratorStatus
void setGeneratorStatus(int generatorStatus, PropertyMask &status)
Convert the generator status into a common set of generator status bits.
dd4hep::sim::Geant4EventReader::m_inputAction
Geant4InputAction * m_inputAction
The input action context.
Definition: Geant4InputAction.h:85
dd4hep::sim::Geant4InputAction::~Geant4InputAction
virtual ~Geant4InputAction()
Default destructor.
dd4hep::sim::Geant4EventReader
Basic geant4 event reader class. This interface/base-class must be implemented by concrete readers.
Definition: Geant4InputAction.h:60
Geant4Vertex.h
dd4hep::sim::Geant4EventReader::checkParameters
virtual void checkParameters(std::map< std::string, std::string > &)
make sure that all parameters have been processed, otherwise throw exceptions
Definition: Geant4InputAction.cpp:71
dd4hep::sim::Geant4EventReader::EVENT_READER_IO_ERROR
@ EVENT_READER_IO_ERROR
Definition: Geant4InputAction.h:74
dd4hep::sim::Geant4EventReader::EVENT_READER_OK
@ EVENT_READER_OK
Definition: Geant4InputAction.h:70
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4InputAction::Vertex
Geant4Vertex Vertex
Definition: Geant4InputAction.h:160
Geant4Particle.h
dd4hep::sim::Geant4EventReader::EVENT_READER_NO_PRIMARIES
@ EVENT_READER_NO_PRIMARIES
Definition: Geant4InputAction.h:72
dd4hep::sim::Geant4Particle
Data structure to store the MC particle information.
Definition: Geant4Particle.h:103
dd4hep::sim::Geant4Vertex
Data structure to store the MC vertex information.
Definition: Geant4Vertex.h:45
dd4hep::sim::Geant4InputAction::m_alternativeDecayStatuses
std::set< int > m_alternativeDecayStatuses
Property: set of alternative decay statuses that MC generators might use for unstable particles.
Definition: Geant4InputAction.h:183
dd4hep::sim::Geant4InputAction::createReader
void createReader()
Create the input reader.
dd4hep::sim::Geant4InputAction::Vertices
std::vector< Vertex * > Vertices
Definition: Geant4InputAction.h:163
dd4hep::sim::Geant4EventReader::Vertices
std::vector< Vertex * > Vertices
Definition: Geant4InputAction.h:66
dd4hep::sim::Geant4EventReader::setInputAction
void setInputAction(Geant4InputAction *action)
Set the input action.
Definition: Geant4InputAction.cpp:50
dd4hep::sim::Geant4InputAction::m_momScale
double m_momScale
Property: Momentum downscaler for debugging.
Definition: Geant4InputAction.h:172
dd4hep::sim::Geant4EventReader::hasDirectAccess
bool hasDirectAccess() const
Flag if direct event access (by event sequence number) is supported (Default: false)
Definition: Geant4InputAction.h:116
dd4hep::sim::Geant4EventReader::Geant4EventReader
Geant4EventReader(const std::string &nam)
Initializing constructor.
Definition: Geant4InputAction.cpp:32
dd4hep::sim::Geant4InputAction::Particles
std::vector< Particle * > Particles
Definition: Geant4InputAction.h:162
dd4hep::sim::Geant4InputAction::m_parameters
std::map< std::string, std::string > m_parameters
Property: named parameters to configure file readers or input actions.
Definition: Geant4InputAction.h:180
dd4hep::sim::Geant4EventReader::name
const std::string & name() const
File name.
Definition: Geant4InputAction.h:114
dd4hep::sim::Geant4InputAction::readParticles
int readParticles(int event_number, Vertices &vertices, Particles &particles)
Read an event and return a LCCollectionVec of MCParticles.
dd4hep::sim::Geant4InputAction::Particle
Geant4Particle Particle
Definition: Geant4InputAction.h:161
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
dd4hep::sim::Geant4InputAction::new_particles
Particles * new_particles() const
Create particle vector.
Definition: Geant4InputAction.h:207