G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
EventAction.cc
Go to the documentation of this file.
1// ********************************************************************
2// * License and Disclaimer *
3// * *
4// * The Geant4 software is copyright of the Copyright Holders of *
5// * the Geant4 Collaboration. It is provided under the terms and *
6// * conditions of the Geant4 Software License, included in the file *
7// * LICENSE and available at http://cern.ch/geant4/license . These *
8// * include a list of copyright holders. *
9// * *
10// * Neither the authors of this software system, nor their employing *
11// * institutes,nor the agencies providing financial support for this *
12// * work make any representation or warranty, express or implied, *
13// * regarding this software system or assume any liability for its *
14// * use. Please see the license in the file LICENSE and URL above *
15// * for the full disclaimer and the limitation of liability. *
16// * *
17// * This code implementation is the result of the scientific and *
18// * technical work of the GEANT4 collaboration. *
19// * By using, copying, modifying or distributing the software (or *
20// * any work based on the software) you agree to acknowledge its *
21// * use in resulting scientific publications, and indicate your *
22// * acceptance of all terms of the Geant4 Software license. *
23// ********************************************************************
24//
27
28#include "EventAction.hh"
29
30#include "CalorHit.hh"
31
32#include "G4AnalysisManager.hh"
33#include "G4Event.hh"
34#include "G4HCofThisEvent.hh"
35#include "G4RunManager.hh"
36#include "G4SDManager.hh"
37#include "G4UnitsTable.hh"
38
39#include <iomanip>
40
41namespace B4c {
42
43//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44
45CalorHitsCollection* EventAction::GetHitsCollection(G4int hcID, const G4Event* event) const {
46 auto hitsCollection = static_cast<CalorHitsCollection*>(event->GetHCofThisEvent()->GetHC(hcID));
47
48 if (!hitsCollection) {
49 G4ExceptionDescription msg;
50 msg << "Cannot access hitsCollection ID " << hcID;
51 G4Exception("EventAction::GetHitsCollection()", "MyCode0003", FatalException, msg);
52 }
53
54 return hitsCollection;
55}
56
57//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58
59void EventAction::PrintEventStatistics(G4double absoEdep, G4double absoTrackLength,
60 G4double gapEdep, G4double gapTrackLength) const {
61 // print event statistics
62 G4cout << " Absorber: total energy: " << std::setw(7) << G4BestUnit(absoEdep, "Energy")
63 << " total track length: " << std::setw(7) << G4BestUnit(absoTrackLength, "Length")
64 << G4endl << " Gap: total energy: " << std::setw(7) << G4BestUnit(gapEdep, "Energy")
65 << " total track length: " << std::setw(7) << G4BestUnit(gapTrackLength, "Length")
66 << G4endl;
67}
68
69//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70
71void EventAction::BeginOfEventAction(const G4Event* /*event*/) {}
72
73//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74
75void EventAction::EndOfEventAction(const G4Event* event) {
76 // Get hits collections IDs (only once)
77 if (fAbsHCID == -1) {
78 fAbsHCID = G4SDManager::GetSDMpointer()->GetCollectionID("AbsorberHitsCollection");
79 fGapHCID = G4SDManager::GetSDMpointer()->GetCollectionID("GapHitsCollection");
80 }
81
82 // Get hits collections
83 auto absoHC = GetHitsCollection(fAbsHCID, event);
84 auto gapHC = GetHitsCollection(fGapHCID, event);
85
86 // Get hit with total values
87 auto absoHit = (*absoHC)[absoHC->entries() - 1];
88 auto gapHit = (*gapHC)[gapHC->entries() - 1];
89
90 // Print per event (modulo n)
91 //
92 auto eventID = event->GetEventID();
93 auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
94 if ((printModulo > 0) && (eventID % printModulo == 0)) {
95 PrintEventStatistics(absoHit->GetEdep(), absoHit->GetTrackLength(), gapHit->GetEdep(),
96 gapHit->GetTrackLength());
97 G4cout << "--> End of event: " << eventID << "\n" << G4endl;
98 }
99
100 // Fill histograms, ntuple
101 //
102
103 // get analysis manager
104 auto analysisManager = G4AnalysisManager::Instance();
105
106 // fill histograms
107 analysisManager->FillH1(0, absoHit->GetEdep());
108 analysisManager->FillH1(1, gapHit->GetEdep());
109 analysisManager->FillH1(2, absoHit->GetTrackLength());
110 analysisManager->FillH1(3, gapHit->GetTrackLength());
111
112 // fill ntuple
113 analysisManager->FillNtupleDColumn(0, absoHit->GetEdep());
114 analysisManager->FillNtupleDColumn(1, gapHit->GetEdep());
115 analysisManager->FillNtupleDColumn(2, absoHit->GetTrackLength());
116 analysisManager->FillNtupleDColumn(3, gapHit->GetTrackLength());
117 analysisManager->AddNtupleRow();
118}
119
120//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
121
122} // namespace B4c
Definition of the B4c::CalorHit class.
void EndOfEventAction(const G4Event *event) override
void BeginOfEventAction(const G4Event *event) override
G4THitsCollection< CalorHit > CalorHitsCollection
Definition CalorHit.hh:77