Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:33

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 
0014 // Framework include files
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/InstanceCount.h>
0017 #include <DDG4/Geant4Particle.h>
0018 #include <DDG4/Geant4RunAction.h>
0019 #include <DDG4/Geant4OutputAction.h>
0020 
0021 // Geant 4 includes
0022 #include <G4HCofThisEvent.hh>
0023 #include <G4Event.hh>
0024 
0025 using namespace dd4hep::sim;
0026 
0027 /// Standard constructor
0028 Geant4OutputAction::Geant4OutputAction(Geant4Context* ctxt, const std::string& nam)
0029   : Geant4EventAction(ctxt, nam)
0030 {
0031   InstanceCount::increment(this);
0032   declareProperty("Output", m_output);
0033   declareProperty("HandleErrorsAsFatal", m_errorFatal=true);
0034   // Need to instantiate run action to configure fibers
0035   ctxt->runAction();
0036 }
0037 
0038 /// Default destructor
0039 Geant4OutputAction::~Geant4OutputAction() {
0040   InstanceCount::decrement(this);
0041 }
0042 
0043 /// Set or update client for the use in a new thread fiber with seperate action sequences
0044 void Geant4OutputAction::configureFiber(Geant4Context* thread_ctxt)  {
0045   Geant4EventAction::configureFiber(thread_ctxt);
0046   thread_ctxt->runAction().callAtBegin(this, &Geant4OutputAction::beginRun);
0047   thread_ctxt->runAction().callAtEnd(this, &Geant4OutputAction::endRun);
0048 }
0049 
0050 /// begin-of-event callback
0051 void Geant4OutputAction::begin(const G4Event* /* event */) {
0052 }
0053 
0054 /// End-of-event callback
0055 void Geant4OutputAction::end(const G4Event* evt) {
0056   OutputContext < G4Event > ctxt(evt);
0057   G4HCofThisEvent* hce = evt->GetHCofThisEvent();
0058   if ( hce )  {
0059     int nCol = hce->GetNumberOfCollections();
0060     try  {
0061       m_truth = context()->event().extension<Geant4ParticleMap>(false);
0062       if ( m_truth && !m_truth->isValid() )  {
0063         m_truth = 0;
0064         printout(WARNING,name(),"+++ [Event:%d] No valid MC truth info present. "
0065                  "Is a Particle handler installed ?",evt->GetEventID());
0066       }
0067       try  {
0068         saveEvent(ctxt);
0069         for (int i = 0; i < nCol; ++i) {
0070           G4VHitsCollection* hc = hce->GetHC(i);
0071           saveCollection(ctxt, hc);
0072         }
0073       }
0074       catch(const std::exception& e)   {
0075         printout(ERROR,name(),"+++ [Event:%d] Exception while saving event:%s",
0076                  evt->GetEventID(),e.what());
0077         if ( m_errorFatal ) throw;
0078       }
0079       catch(...)   {
0080         printout(ERROR,name(),"+++ [Event:%d] UNKNWON Exception while saving event",
0081                  evt->GetEventID());
0082         if ( m_errorFatal ) throw;
0083       }
0084       commit(ctxt);
0085     }
0086     catch(const std::exception& e)   {
0087       printout(ERROR,name(),"+++ [Event:%d] Exception while saving event:%s",
0088                evt->GetEventID(),e.what());
0089       if ( m_errorFatal ) throw;
0090     }
0091     catch(...)   {
0092       printout(ERROR,name(),"+++ [Event:%d] UNKNWON Exception while saving event",
0093                evt->GetEventID());
0094       if ( m_errorFatal ) throw;
0095     }
0096     m_truth = 0;
0097     return;
0098   }
0099   printout(WARNING,"Geant4OutputAction",
0100            "+++ The value of G4HCofThisEvent is NULL. No collections saved!");
0101 }
0102 
0103 /// Commit data at end of filling procedure
0104 void Geant4OutputAction::commit(OutputContext<G4Event>& /* ctxt */) {
0105 }
0106 
0107 /// Callback to initialize the storing of the Geant4 information
0108 void Geant4OutputAction::beginRun(const G4Run* /* run */) {
0109 }
0110 
0111 /// Callback to store the Geant4 run information
0112 void Geant4OutputAction::endRun(const G4Run* /* run */) {
0113 }
0114 
0115 /// Callback to store the Geant4 run information
0116 void Geant4OutputAction::saveRun(const G4Run* /* run */) {
0117 }
0118 
0119 /// Callback to store the Geant4 event
0120 void Geant4OutputAction::saveEvent(OutputContext<G4Event>& /* ctxt */) {
0121 }
0122 
0123 /// Callback to store each Geant4 hit collection
0124 void Geant4OutputAction::saveCollection(OutputContext<G4Event>& /* ctxt */, G4VHitsCollection* /* collection */) {
0125 }
0126