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/B4c/src/EventAction.cc
28/// \brief Implementation of the B4c::EventAction class
29
30#include "EventAction.hh"
31#include "CalorimeterSD.hh"
32#include "CalorHit.hh"
33
34#include "G4AnalysisManager.hh"
35#include "G4RunManager.hh"
36#include "G4Event.hh"
37#include "G4SDManager.hh"
38#include "G4HCofThisEvent.hh"
39#include "G4UnitsTable.hh"
40
41#include "Randomize.hh"
42#include <iomanip>
43
44namespace B4c
45{
46
47//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48
51 const G4Event* event) const
52{
53 auto hitsCollection
54 = static_cast<CalorHitsCollection*>(
55 event->GetHCofThisEvent()->GetHC(hcID));
56
57 if ( ! hitsCollection ) {
58 G4ExceptionDescription msg;
59 msg << "Cannot access hitsCollection ID " << hcID;
60 G4Exception("EventAction::GetHitsCollection()",
61 "MyCode0003", FatalException, msg);
62 }
63
64 return hitsCollection;
65}
66
67//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68
70 G4double absoEdep, G4double absoTrackLength,
71 G4double gapEdep, G4double gapTrackLength) const
72{
73 // print event statistics
74 G4cout
75 << " Absorber: total energy: "
76 << std::setw(7) << G4BestUnit(absoEdep, "Energy")
77 << " total track length: "
78 << std::setw(7) << G4BestUnit(absoTrackLength, "Length")
79 << G4endl
80 << " Gap: total energy: "
81 << std::setw(7) << G4BestUnit(gapEdep, "Energy")
82 << " total track length: "
83 << std::setw(7) << G4BestUnit(gapTrackLength, "Length")
84 << G4endl;
85}
86
87//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88
90{}
91
92//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93
95{
96 // Get hits collections IDs (only once)
97 if ( fAbsHCID == -1 ) {
99 = G4SDManager::GetSDMpointer()->GetCollectionID("AbsorberHitsCollection");
101 = G4SDManager::GetSDMpointer()->GetCollectionID("GapHitsCollection");
102 }
103
104 // Get hits collections
105 auto absoHC = GetHitsCollection(fAbsHCID, event);
106 auto gapHC = GetHitsCollection(fGapHCID, event);
107
108 // Get hit with total values
109 auto absoHit = (*absoHC)[absoHC->entries()-1];
110 auto gapHit = (*gapHC)[gapHC->entries()-1];
111
112 // Print per event (modulo n)
113 //
114 auto eventID = event->GetEventID();
115 auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
116 if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) {
118 absoHit->GetEdep(), absoHit->GetTrackLength(),
119 gapHit->GetEdep(), gapHit->GetTrackLength());
120 G4cout << "--> End of event: " << eventID << "\n" << G4endl;
121 }
122
123 // Fill histograms, ntuple
124 //
125
126 // get analysis manager
127 auto analysisManager = G4AnalysisManager::Instance();
128
129 // fill histograms
130 analysisManager->FillH1(0, absoHit->GetEdep());
131 analysisManager->FillH1(1, gapHit->GetEdep());
132 analysisManager->FillH1(2, absoHit->GetTrackLength());
133 analysisManager->FillH1(3, gapHit->GetTrackLength());
134
135 // fill ntuple
136 analysisManager->FillNtupleDColumn(0, absoHit->GetEdep());
137 analysisManager->FillNtupleDColumn(1, gapHit->GetEdep());
138 analysisManager->FillNtupleDColumn(2, absoHit->GetTrackLength());
139 analysisManager->FillNtupleDColumn(3, gapHit->GetTrackLength());
140 analysisManager->AddNtupleRow();
141}
142
143//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
144
145}
Definition of the B4c::CalorHit class.
Definition of the B4c::CalorimeterSD class.
void EndOfEventAction(const G4Event *event) override
CalorHitsCollection * GetHitsCollection(G4int hcID, const G4Event *event) const
void BeginOfEventAction(const G4Event *event) override
void PrintEventStatistics(G4double absoEdep, G4double absoTrackLength, G4double gapEdep, G4double gapTrackLength) const
G4THitsCollection< CalorHit > CalorHitsCollection
Definition CalorHit.hh:80

Applications | User Support | Publications | Collaboration