Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
B4d::EventAction Class Reference
basic » B4 » B4d

Event action class. More...

#include <Doxymodules_basic.h>

Inheritance diagram for B4d::EventAction:
G4UserEventAction

Public Member Functions

 EventAction ()=default
 
 ~EventAction () override=default
 
void BeginOfEventAction (const G4Event *event) override
 
void EndOfEventAction (const G4Event *event) override
 

Private Member Functions

G4THitsMap< G4double > * GetHitsCollection (G4int hcID, const G4Event *event) const
 
G4double GetSum (G4THitsMap< G4double > *hitsMap) const
 
void PrintEventStatistics (G4double absoEdep, G4double absoTrackLength, G4double gapEdep, G4double gapTrackLength) const
 

Private Attributes

G4int fAbsoEdepHCID = -1
 
G4int fGapEdepHCID = -1
 
G4int fAbsoTrackLengthHCID = -1
 
G4int fGapTrackLengthHCID = -1
 

Detailed Description

Event action class.

In EndOfEventAction(), it prints the accumulated quantities of the energy deposit and track lengths of charged particles in Absober and Gap layers stored in the hits collections.

Definition at line 174 of file Doxymodules_basic.h.

Constructor & Destructor Documentation

◆ EventAction()

B4d::EventAction::EventAction ( )
default

◆ ~EventAction()

B4d::EventAction::~EventAction ( )
overridedefault

Member Function Documentation

◆ BeginOfEventAction()

void B4d::EventAction::BeginOfEventAction ( const G4Event event)
override

Definition at line 100 of file EventAction.cc.

101{}

◆ EndOfEventAction()

void B4d::EventAction::EndOfEventAction ( const G4Event event)
override

Definition at line 105 of file EventAction.cc.

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}
G4int fAbsoTrackLengthHCID
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

◆ GetHitsCollection()

G4THitsMap< G4double > * B4d::EventAction::GetHitsCollection ( G4int  hcID,
const G4Event event 
) const
private

Definition at line 48 of file EventAction.cc.

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}

◆ GetSum()

G4double B4d::EventAction::GetSum ( G4THitsMap< G4double > *  hitsMap) const
private

Definition at line 67 of file EventAction.cc.

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}

◆ PrintEventStatistics()

void B4d::EventAction::PrintEventStatistics ( G4double  absoEdep,
G4double  absoTrackLength,
G4double  gapEdep,
G4double  gapTrackLength 
) const
private

Definition at line 79 of file EventAction.cc.

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}

Member Data Documentation

◆ fAbsoEdepHCID

G4int B4d::EventAction::fAbsoEdepHCID = -1
private

Definition at line 65 of file EventAction.hh.

◆ fGapEdepHCID

G4int B4d::EventAction::fGapEdepHCID = -1
private

Definition at line 66 of file EventAction.hh.

◆ fAbsoTrackLengthHCID

G4int B4d::EventAction::fAbsoTrackLengthHCID = -1
private

Definition at line 67 of file EventAction.hh.

◆ fGapTrackLengthHCID

G4int B4d::EventAction::fGapTrackLengthHCID = -1
private

Definition at line 68 of file EventAction.hh.


The documentation for this class was generated from the following files:

Applications | User Support | Publications | Collaboration