File indexing completed on 2026-09-23 08:28:34
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 "EventAction.hh"
0030
0031 #include "CalorHit.hh"
0032
0033 #include "G4AnalysisManager.hh"
0034 #include "G4Event.hh"
0035 #include "G4HCofThisEvent.hh"
0036 #include "G4RunManager.hh"
0037 #include "G4SDManager.hh"
0038 #include "G4UnitsTable.hh"
0039
0040 #include <iomanip>
0041
0042 namespace B4c
0043 {
0044
0045
0046
0047 CalorHitsCollection* EventAction::GetHitsCollection(G4int hcID, const G4Event* event) const
0048 {
0049 auto hitsCollection = static_cast<CalorHitsCollection*>(event->GetHCofThisEvent()->GetHC(hcID));
0050
0051 if (!hitsCollection) {
0052 G4ExceptionDescription msg;
0053 msg << "Cannot access hitsCollection ID " << hcID;
0054 G4Exception("EventAction::GetHitsCollection()", "MyCode0003", FatalException, msg);
0055 }
0056
0057 return hitsCollection;
0058 }
0059
0060
0061
0062 void EventAction::PrintEventStatistics(G4double absoEdep, G4double absoTrackLength,
0063 G4double gapEdep, G4double gapTrackLength) const
0064 {
0065
0066 G4cout << " Absorber: total energy: " << std::setw(7) << G4BestUnit(absoEdep, "Energy")
0067 << " total track length: " << std::setw(7) << G4BestUnit(absoTrackLength, "Length")
0068 << G4endl << " Gap: total energy: " << std::setw(7) << G4BestUnit(gapEdep, "Energy")
0069 << " total track length: " << std::setw(7) << G4BestUnit(gapTrackLength, "Length")
0070 << G4endl;
0071 }
0072
0073
0074
0075 void EventAction::BeginOfEventAction(const G4Event* ) {}
0076
0077
0078
0079 void EventAction::EndOfEventAction(const G4Event* event)
0080 {
0081
0082 if (fAbsHCID == -1) {
0083 fAbsHCID = G4SDManager::GetSDMpointer()->GetCollectionID("AbsorberHitsCollection");
0084 fGapHCID = G4SDManager::GetSDMpointer()->GetCollectionID("GapHitsCollection");
0085 }
0086
0087
0088 auto absoHC = GetHitsCollection(fAbsHCID, event);
0089 auto gapHC = GetHitsCollection(fGapHCID, event);
0090
0091
0092 auto absoHit = (*absoHC)[absoHC->entries() - 1];
0093 auto gapHit = (*gapHC)[gapHC->entries() - 1];
0094
0095
0096
0097 auto eventID = event->GetEventID();
0098 auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
0099 if ((printModulo > 0) && (eventID % printModulo == 0)) {
0100 PrintEventStatistics(absoHit->GetEdep(), absoHit->GetTrackLength(), gapHit->GetEdep(),
0101 gapHit->GetTrackLength());
0102 G4cout << "--> End of event: " << eventID << "\n" << G4endl;
0103 }
0104
0105
0106
0107
0108
0109 auto analysisManager = G4AnalysisManager::Instance();
0110
0111
0112 analysisManager->FillH1(0, absoHit->GetEdep());
0113 analysisManager->FillH1(1, gapHit->GetEdep());
0114 analysisManager->FillH1(2, absoHit->GetTrackLength());
0115 analysisManager->FillH1(3, gapHit->GetTrackLength());
0116
0117
0118 analysisManager->FillNtupleDColumn(0, absoHit->GetEdep());
0119 analysisManager->FillNtupleDColumn(1, gapHit->GetEdep());
0120 analysisManager->FillNtupleDColumn(2, absoHit->GetTrackLength());
0121 analysisManager->FillNtupleDColumn(3, gapHit->GetTrackLength());
0122 analysisManager->AddNtupleRow();
0123 }
0124
0125
0126
0127 }