Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:24

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DDG4_GEANT4OUTPUTACTION_H
0014 #define DDG4_GEANT4OUTPUTACTION_H
0015 
0016 // Framework include files
0017 #include <DDG4/Geant4EventAction.h>
0018 
0019 // Forward declarations
0020 class G4Run;
0021 class G4Event;
0022 class G4VHitsCollection;
0023 
0024 
0025 /// Namespace for the AIDA detector description toolkit
0026 namespace dd4hep {
0027 
0028   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0029   namespace sim {
0030 
0031     // Forward declarations
0032     class Geant4ParticleMap;
0033 
0034     /// Base class to output Geant4 event data to persistent media
0035     /**
0036      *  \author  M.Frank
0037      *  \version 1.0
0038      *  \ingroup DD4HEP_SIMULATION
0039      */
0040     class Geant4OutputAction: public Geant4EventAction {
0041     protected:
0042       /// Helper class for thread savety
0043       template <typename T> class OutputContext {
0044       public:
0045         const T* context;
0046         void* userData;
0047         OutputContext(const T* c)
0048           : context(c), userData(0) {
0049         }
0050         template <typename U> U* data() const {
0051           return (U*) userData;
0052         }
0053       };
0054 
0055       /// Property: "Output" output destination
0056       std::string        m_output  {  };
0057       /// Property: "HandleErrorsAsFatal" Handle errors as fatal and rethrow eventual exceptions
0058       bool               m_errorFatal { true };
0059       /// Reference to MC truth object
0060       Geant4ParticleMap* m_truth   { nullptr };
0061     public:
0062       /// Inhibit default constructor
0063       Geant4OutputAction() = delete;
0064       /// Inhibit copy constructor
0065       Geant4OutputAction(const Geant4OutputAction& copy) = delete;
0066       /// Standard constructor
0067       Geant4OutputAction(Geant4Context* c, const std::string& nam);
0068       /// Default destructor
0069       virtual ~Geant4OutputAction();
0070       /// Set or update client for the use in a new thread fiber
0071       virtual void configureFiber(Geant4Context* ctxt)  override;
0072 
0073       /// begin-of-event callback
0074       virtual void begin(const G4Event* event)  override;
0075       /// End-of-event callback
0076       virtual void end(const G4Event* event)  override;
0077       /// Callback to initialize storing the Geant4 information
0078       virtual void beginRun(const G4Run* run);
0079       /// Callback to store the Geant4 run information
0080       virtual void endRun(const G4Run* run);
0081 
0082       /// Callback to store the Geant4 event
0083       virtual void saveRun(const G4Run* run);
0084       /// Callback to store the Geant4 event
0085       virtual void saveEvent(OutputContext<G4Event>& ctxt);
0086       /// Callback to store each Geant4 hit collection
0087       virtual void saveCollection(OutputContext<G4Event>& ctxt, G4VHitsCollection* collection);
0088       /// Commit data at end of filling procedure
0089       virtual void commit(OutputContext<G4Event>& ctxt);
0090     };
0091 
0092   }    // End namespace sim
0093 }      // End namespace dd4hep
0094 #endif // DDG4_GEANT4OUTPUTACTION_H