Loading...
Searching...
No Matches
EventAction.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27/// \file B4/B4d/src/EventAction.cc
28/// \brief Implementation of the B4d::EventAction class
29
30#include "EventAction.hh"
31
32#include "G4AnalysisManager.hh"
33#include "G4RunManager.hh"
34#include "G4Event.hh"
35#include "G4SDManager.hh"
36#include "G4HCofThisEvent.hh"
37#include "G4UnitsTable.hh"
38
39#include "Randomize.hh"
40#include <iomanip>
41
42namespace B4d
43{
44
45//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46
49 const G4Event* event) const
50{
51 auto hitsCollection
52 = static_cast<G4THitsMap<G4double>*>(
53 event->GetHCofThisEvent()->GetHC(hcID));
54
55 if ( ! hitsCollection ) {
56 G4ExceptionDescription msg;
57 msg << "Cannot access hitsCollection ID " << hcID;
58 G4Exception("EventAction::GetHitsCollection()",
59 "MyCode0003", FatalException, msg);
60 }
61
62 return hitsCollection;
63}
64
65//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66
68{
69 G4double sumValue = 0.;
70 for ( auto it : *hitsMap->GetMap() ) {
71 // hitsMap->GetMap() returns the map of std::map<G4int, G4double*>
72 sumValue += *(it.second);
73 }
74 return sumValue;
75}
76
77//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78
80 G4double absoEdep, G4double absoTrackLength,
81 G4double gapEdep, G4double gapTrackLength) const
82{
83 // Print event statistics
84 //
85 G4cout
86 << " Absorber: total energy: "
87 << std::setw(7) << G4BestUnit(absoEdep, "Energy")
88 << " total track length: "
89 << std::setw(7) << G4BestUnit(absoTrackLength, "Length")
90 << G4endl
91 << " Gap: total energy: "
92 << std::setw(7) << G4BestUnit(gapEdep, "Energy")
93 << " total track length: "
94 << std::setw(7) << G4BestUnit(gapTrackLength, "Length")
95 << G4endl;
96}
97
98//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99
101{}
102
103//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
104
106{
107 // Get hist collections IDs
108 if ( fAbsoEdepHCID == -1 ) {
110 = G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/Edep");
112 = G4SDManager::GetSDMpointer()->GetCollectionID("Gap/Edep");
114 = G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/TrackLength");
116 = G4SDManager::GetSDMpointer()->GetCollectionID("Gap/TrackLength");
117 }
118
119 // Get sum values from hits collections
120 //
121 auto absoEdep = GetSum(GetHitsCollection(fAbsoEdepHCID, event));
122 auto gapEdep = GetSum(GetHitsCollection(fGapEdepHCID, event));
123
124 auto absoTrackLength
126 auto gapTrackLength
128
129 // get analysis manager
130 auto analysisManager = G4AnalysisManager::Instance();
131
132 // fill histograms
133 //
134 analysisManager->FillH1(0, absoEdep);
135 analysisManager->FillH1(1, gapEdep);
136 analysisManager->FillH1(2, absoTrackLength);
137 analysisManager->FillH1(3, gapTrackLength);
138
139 // fill ntuple
140 //
141 analysisManager->FillNtupleDColumn(0, absoEdep);
142 analysisManager->FillNtupleDColumn(1, gapEdep);
143 analysisManager->FillNtupleDColumn(2, absoTrackLength);
144 analysisManager->FillNtupleDColumn(3, gapTrackLength);
145 analysisManager->AddNtupleRow();
146
147 //print per event (modulo n)
148 //
149 auto eventID = event->GetEventID();
150 auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
151 if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) {
152 PrintEventStatistics(absoEdep, absoTrackLength, gapEdep, gapTrackLength);
153 G4cout << "--> End of event: " << eventID << "\n" << G4endl;
154 }
155}
156
157//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
158
159}
G4int fAbsoTrackLengthHCID
void EndOfEventAction(const G4Event *event) override
G4double GetSum(G4THitsMap< G4double > *hitsMap) const
G4THitsMap< G4double > * GetHitsCollection(G4int hcID, const G4Event *event) const
void PrintEventStatistics(G4double absoEdep, G4double absoTrackLength, G4double gapEdep, G4double gapTrackLength) const
G4int fGapTrackLengthHCID
void BeginOfEventAction(const G4Event *event) override

Applications | User Support | Publications | Collaboration