DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4OutputAction.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 #ifndef DDG4_GEANT4OUTPUTACTION_H
14 #define DDG4_GEANT4OUTPUTACTION_H
15 
16 // Framework include files
17 #include <DDG4/Geant4EventAction.h>
18 
19 // Forward declarations
20 class G4Run;
21 class G4Event;
22 class G4VHitsCollection;
23 
24 
26 namespace dd4hep {
27 
29  namespace sim {
30 
31  // Forward declarations
32  class Geant4ParticleMap;
33 
35 
41  protected:
43  template <typename T> class OutputContext {
44  public:
45  const T* context;
46  void* userData;
47  OutputContext(const T* c)
48  : context(c), userData(0) {
49  }
50  template <typename U> U* data() const {
51  return (U*) userData;
52  }
53  };
54 
56  std::string m_output { };
58  bool m_errorFatal { true };
60  Geant4ParticleMap* m_truth { nullptr };
61  public:
63  Geant4OutputAction() = delete;
67  Geant4OutputAction(Geant4Context* c, const std::string& nam);
69  virtual ~Geant4OutputAction();
71  virtual void configureFiber(Geant4Context* ctxt) override;
72 
74  virtual void begin(const G4Event* event) override;
76  virtual void end(const G4Event* event) override;
78  virtual void beginRun(const G4Run* run);
80  virtual void endRun(const G4Run* run);
81 
83  virtual void saveRun(const G4Run* run);
85  virtual void saveEvent(OutputContext<G4Event>& ctxt);
87  virtual void saveCollection(OutputContext<G4Event>& ctxt, G4VHitsCollection* collection);
89  virtual void commit(OutputContext<G4Event>& ctxt);
90  };
91 
92  } // End namespace sim
93 } // End namespace dd4hep
94 #endif // DDG4_GEANT4OUTPUTACTION_H
dd4hep::sim::Geant4OutputAction::Geant4OutputAction
Geant4OutputAction()=delete
Inhibit default constructor.
dd4hep::sim::Geant4OutputAction::endRun
virtual void endRun(const G4Run *run)
Callback to store the Geant4 run information.
Definition: Geant4OutputAction.cpp:112
dd4hep::sim::Geant4OutputAction::saveRun
virtual void saveRun(const G4Run *run)
Callback to store the Geant4 event.
Definition: Geant4OutputAction.cpp:116
Geant4EventAction.h
G4VHitsCollection
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:47
dd4hep::sim::Geant4OutputAction
Base class to output Geant4 event data to persistent media.
Definition: Geant4OutputAction.h:40
dd4hep::sim::Geant4OutputAction::OutputContext
Helper class for thread savety.
Definition: Geant4OutputAction.h:43
dd4hep::sim::Geant4OutputAction::OutputContext::OutputContext
OutputContext(const T *c)
Definition: Geant4OutputAction.h:47
dd4hep::sim::Geant4ParticleMap
Data structure to map particles produced during the generation and the simulation.
Definition: Geant4Particle.h:337
dd4hep::sim::Geant4EventAction
Concrete basic implementation of the Geant4 event action.
Definition: Geant4EventAction.h:53
dd4hep::sim::Geant4OutputAction::commit
virtual void commit(OutputContext< G4Event > &ctxt)
Commit data at end of filling procedure.
Definition: Geant4OutputAction.cpp:104
dd4hep::sim::Geant4OutputAction::m_truth
Geant4ParticleMap * m_truth
Reference to MC truth object.
Definition: Geant4OutputAction.h:60
dd4hep::sim::Geant4OutputAction::beginRun
virtual void beginRun(const G4Run *run)
Callback to initialize storing the Geant4 information.
Definition: Geant4OutputAction.cpp:108
dd4hep::sim::Geant4OutputAction::saveEvent
virtual void saveEvent(OutputContext< G4Event > &ctxt)
Callback to store the Geant4 event.
Definition: Geant4OutputAction.cpp:120
dd4hep::sim::Geant4OutputAction::end
virtual void end(const G4Event *event) override
End-of-event callback.
Definition: Geant4OutputAction.cpp:55
dd4hep::sim::Geant4OutputAction::begin
virtual void begin(const G4Event *event) override
begin-of-event callback
Definition: Geant4OutputAction.cpp:51
dd4hep::sim::Geant4OutputAction::m_output
std::string m_output
Property: "Output" output destination.
Definition: Geant4OutputAction.h:56
dd4hep::sim::Geant4OutputAction::~Geant4OutputAction
virtual ~Geant4OutputAction()
Default destructor.
Definition: Geant4OutputAction.cpp:39
dd4hep::sim::Geant4OutputAction::OutputContext::context
const T * context
Definition: Geant4OutputAction.h:45
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::sim::Geant4OutputAction::saveCollection
virtual void saveCollection(OutputContext< G4Event > &ctxt, G4VHitsCollection *collection)
Callback to store each Geant4 hit collection.
Definition: Geant4OutputAction.cpp:124
dd4hep::sim::Geant4OutputAction::OutputContext::userData
void * userData
Definition: Geant4OutputAction.h:46
dd4hep::sim::Geant4OutputAction::m_errorFatal
bool m_errorFatal
Property: "HandleErrorsAsFatal" Handle errors as fatal and rethrow eventual exceptions.
Definition: Geant4OutputAction.h:58
dd4hep::sim::Geant4OutputAction::configureFiber
virtual void configureFiber(Geant4Context *ctxt) override
Set or update client for the use in a new thread fiber.
Definition: Geant4OutputAction.cpp:44
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4OutputAction::OutputContext::data
U * data() const
Definition: Geant4OutputAction.h:50
dd4hep::sim::Geant4OutputAction::Geant4OutputAction
Geant4OutputAction(const Geant4OutputAction &copy)=delete
Inhibit copy constructor.