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