File indexing completed on 2026-09-23 08:27:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #include "G4Event.hh"
0039 #include "G4Types.hh"
0040 #include "G4SDManager.hh"
0041
0042
0043 #include "EventAction.hh"
0044 #include "ConfigurationManager.hh"
0045 #include "PhotonSD.hh"
0046 #include "PhotonHit.hh"
0047
0048 #ifdef WITH_ROOT
0049 #include "RootIO.hh"
0050 #endif
0051
0052 #ifdef WITH_G4OPTICKS
0053 #include "OpticksFlags.hh"
0054 #include "G4Opticks.hh"
0055 #include "G4OpticksHit.hh"
0056 #include <string>
0057 #endif
0058
0059
0060 void EventAction::EndOfEventAction(const G4Event* event)
0061 {
0062 G4bool verbose = ConfigurationManager::getInstance()->isEnable_verbose();
0063 if (verbose)
0064 {
0065 G4cout << "EventAction::EndOfEventAction Event: " << event->GetEventID()
0066 << G4endl;
0067 }
0068 #ifdef WITH_G4OPTICKS
0069 if (ConfigurationManager::getInstance()->isEnable_opticks())
0070 {
0071 G4Opticks* g4ok = G4Opticks::Get();
0072 g4ok->propagateOpticalPhotons(event->GetEventID());
0073 unsigned num_hits = g4ok->getNumHit();
0074 G4cout << "EndOfEventAction: num_hits: " << num_hits << G4endl;
0075 if (num_hits > 0)
0076 {
0077 G4HCtable* hctable = G4SDManager::GetSDMpointer()->GetHCtable();
0078 for (G4int i = 0; i < hctable->entries(); ++i)
0079 {
0080 G4String sdn = hctable->GetSDname(i);
0081 std::size_t found = sdn.find("PhotonDetector");
0082 if (found != std::string::npos)
0083 {
0084 PhotonSD* aSD =
0085 (PhotonSD*) G4SDManager::GetSDMpointer()->FindSensitiveDetector(sdn);
0086 aSD->AddOpticksHits();
0087 }
0088 }
0089 }
0090 if (verbose)
0091 {
0092 G4cout << "**************************************************" << G4endl;
0093 G4cout << " EndOfEventAction: numphotons: " << g4ok->getNumPhotons()
0094 << " Gensteps: " << g4ok->getNumGensteps()
0095 << " Maxgensteps: " << g4ok->getMaxGensteps() << G4endl;
0096 G4cout << " EndOfEventAction: num_hits: " << g4ok->getNumHit() << G4endl;
0097 G4cout << g4ok->dbgdesc() << G4endl;
0098 }
0099 g4ok->reset();
0100 if (verbose)
0101 {
0102 G4cout << "========================== After reset: " << G4endl;
0103 G4cout << " EndOfEventAction: numphotons: " << g4ok->getNumPhotons()
0104 << " Gensteps: " << g4ok->getNumGensteps()
0105 << " Maxgensteps: " << g4ok->getMaxGensteps() << G4endl;
0106 G4cout << "EndOfEventAction: num_hits: " << g4ok->getNumHit() << G4endl;
0107 G4cout << g4ok->dbgdesc() << G4endl;
0108 G4cout << "**************************************************" << G4endl;
0109 }
0110 }
0111 #endif
0112
0113 #ifdef WITH_ROOT
0114
0115 if (ConfigurationManager::getInstance()->isWriteHits())
0116 {
0117 RootIO::GetInstance()->Write(event);
0118 }
0119 #endif
0120 }