Warning, file /geant4/examples/basic/B4/B4d/src/EventAction.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 "G4AnalysisManager.hh"
0033 #include "G4Event.hh"
0034 #include "G4HCofThisEvent.hh"
0035 #include "G4RunManager.hh"
0036 #include "G4SDManager.hh"
0037 #include "G4THitsMap.hh"
0038 #include "G4UnitsTable.hh"
0039
0040 #include <iomanip>
0041
0042 namespace B4d
0043 {
0044
0045
0046
0047 G4THitsMap<G4double>* EventAction::GetHitsCollection(G4int hcID, const G4Event* event) const
0048 {
0049 auto hitsCollection = static_cast<G4THitsMap<G4double>*>(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 G4double EventAction::GetSum(G4THitsMap<G4double>* hitsMap) const
0063 {
0064 G4double sumValue = 0.;
0065 for (auto it : *hitsMap->GetMap()) {
0066
0067 sumValue += *(it.second);
0068 }
0069 return sumValue;
0070 }
0071
0072
0073
0074 void EventAction::PrintEventStatistics(G4double absoEdep, G4double absoTrackLength,
0075 G4double gapEdep, G4double gapTrackLength) const
0076 {
0077
0078
0079 G4cout << " Absorber: total energy: " << std::setw(7) << G4BestUnit(absoEdep, "Energy")
0080 << " total track length: " << std::setw(7) << G4BestUnit(absoTrackLength, "Length")
0081 << G4endl << " Gap: total energy: " << std::setw(7) << G4BestUnit(gapEdep, "Energy")
0082 << " total track length: " << std::setw(7) << G4BestUnit(gapTrackLength, "Length")
0083 << G4endl;
0084 }
0085
0086
0087
0088 void EventAction::BeginOfEventAction(const G4Event* ) {}
0089
0090
0091
0092 void EventAction::EndOfEventAction(const G4Event* event)
0093 {
0094
0095 if (fAbsoEdepHCID == -1) {
0096 fAbsoEdepHCID = G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/Edep");
0097 fGapEdepHCID = G4SDManager::GetSDMpointer()->GetCollectionID("Gap/Edep");
0098 fAbsoTrackLengthHCID = G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/TrackLength");
0099 fGapTrackLengthHCID = G4SDManager::GetSDMpointer()->GetCollectionID("Gap/TrackLength");
0100 }
0101
0102
0103
0104 auto absoEdep = GetSum(GetHitsCollection(fAbsoEdepHCID, event));
0105 auto gapEdep = GetSum(GetHitsCollection(fGapEdepHCID, event));
0106
0107 auto absoTrackLength = GetSum(GetHitsCollection(fAbsoTrackLengthHCID, event));
0108 auto gapTrackLength = GetSum(GetHitsCollection(fGapTrackLengthHCID, event));
0109
0110
0111 auto analysisManager = G4AnalysisManager::Instance();
0112
0113
0114
0115 analysisManager->FillH1(0, absoEdep);
0116 analysisManager->FillH1(1, gapEdep);
0117 analysisManager->FillH1(2, absoTrackLength);
0118 analysisManager->FillH1(3, gapTrackLength);
0119
0120
0121
0122 analysisManager->FillNtupleDColumn(0, absoEdep);
0123 analysisManager->FillNtupleDColumn(1, gapEdep);
0124 analysisManager->FillNtupleDColumn(2, absoTrackLength);
0125 analysisManager->FillNtupleDColumn(3, gapTrackLength);
0126 analysisManager->AddNtupleRow();
0127
0128
0129
0130 auto eventID = event->GetEventID();
0131 auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
0132 if ((printModulo > 0) && (eventID % printModulo == 0)) {
0133 PrintEventStatistics(absoEdep, absoTrackLength, gapEdep, gapTrackLength);
0134 G4cout << "--> End of event: " << eventID << "\n" << G4endl;
0135 }
0136 }
0137
0138
0139
0140 }