File indexing completed on 2026-07-30 08:26:17
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 #include "ExN04EventAction.hh"
0030
0031 #include "ExN04CalorimeterHit.hh"
0032 #include "ExN04MuonHit.hh"
0033 #include "ExN04TrackerHit.hh"
0034
0035 #include "G4Event.hh"
0036 #include "G4EventManager.hh"
0037 #include "G4HCofThisEvent.hh"
0038 #include "G4SDManager.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4UImanager.hh"
0041 #include "G4VHitsCollection.hh"
0042 #include "G4ios.hh"
0043
0044
0045 ExN04EventAction::ExN04EventAction()
0046 : G4UserEventAction(), ftrackerCollID(-1), fcalorimeterCollID(-1), fmuonCollID(-1)
0047 {}
0048
0049
0050 ExN04EventAction::~ExN04EventAction() {}
0051
0052
0053 void ExN04EventAction::BeginOfEventAction(const G4Event*)
0054 {
0055 G4SDManager* SDman = G4SDManager::GetSDMpointer();
0056 if (ftrackerCollID < 0 || fcalorimeterCollID < 0 || fmuonCollID < 0) {
0057 G4String colNam;
0058 ftrackerCollID = SDman->GetCollectionID(colNam = "trackerCollection");
0059 fcalorimeterCollID = SDman->GetCollectionID(colNam = "calCollection");
0060 fmuonCollID = SDman->GetCollectionID(colNam = "muonCollection");
0061 }
0062 }
0063
0064
0065 void ExN04EventAction::EndOfEventAction(const G4Event* evt)
0066 {
0067 G4cout << ">>> Event " << evt->GetEventID() << G4endl;
0068
0069 if (ftrackerCollID < 0 || fcalorimeterCollID < 0 || fmuonCollID < 0) return;
0070
0071 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
0072 ExN04TrackerHitsCollection* THC = NULL;
0073 ExN04CalorimeterHitsCollection* CHC = NULL;
0074 ExN04MuonHitsCollection* MHC = NULL;
0075
0076 if (HCE) {
0077 THC = (ExN04TrackerHitsCollection*)(HCE->GetHC(ftrackerCollID));
0078 CHC = (ExN04CalorimeterHitsCollection*)(HCE->GetHC(fcalorimeterCollID));
0079 MHC = (ExN04MuonHitsCollection*)(HCE->GetHC(fmuonCollID));
0080 }
0081
0082 if (THC) {
0083 G4int n_hit = THC->entries();
0084 G4cout << " " << n_hit << " hits are stored in ExN04TrackerHitsCollection." << G4endl;
0085 }
0086
0087 if (CHC) {
0088 G4int n_hit = CHC->entries();
0089 G4cout << " " << n_hit << " hits are stored in ExN04CalorimeterHitsCollection." << G4endl;
0090 G4double totE = 0;
0091 for (int i = 0; i < n_hit; i++) {
0092 totE += (*CHC)[i]->GetEdep();
0093 }
0094 G4cout << " Total energy deposition in calorimeter : " << totE / GeV << " (GeV)" << G4endl;
0095 }
0096
0097 if (MHC) {
0098 G4int n_hit = MHC->entries();
0099 G4cout << " " << n_hit << " hits are stored in ExN04MuonHitsCollection." << G4endl;
0100 }
0101 }