Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
B5::EventAction Class Reference

Event action. More...

#include <Doxymodules_basic.h>

Inheritance diagram for B5::EventAction:
G4UserEventAction

Public Member Functions

 EventAction ()
 
 ~EventAction () override=default
 
void BeginOfEventAction (const G4Event *) override
 
void EndOfEventAction (const G4Event *) override
 
std::vector< G4double > & GetEmCalEdep ()
 
std::vector< G4double > & GetHadCalEdep ()
 

Private Attributes

std::array< G4int, kDimfHodHCID = { -1, -1 }
 
std::array< G4int, kDimfDriftHCID = { -1, -1 }
 
std::array< G4int, kDimfCalHCID = { -1, -1 }
 
std::array< std::array< G4int, kDim >, kDimfDriftHistoID {{ {{ -1, -1 }}, {{ -1, -1 }} }}
 
std::array< std::vector< G4double >, kDimfCalEdep {{ std::vector<G4double>(kNofEmCells, 0.), std::vector<G4double>(kNofHadCells, 0.) }}
 

Detailed Description

Event action.

Definition at line 191 of file Doxymodules_basic.h.

Constructor & Destructor Documentation

◆ EventAction()

B5::EventAction::EventAction ( )

Definition at line 81 of file EventAction.cc.

82{
83 // set printing per each event
84 G4RunManager::GetRunManager()->SetPrintProgress(1);
85}

◆ ~EventAction()

B5::EventAction::~EventAction ( )
overridedefault

Member Function Documentation

◆ BeginOfEventAction()

void B5::EventAction::BeginOfEventAction ( const G4Event )
override

Definition at line 89 of file EventAction.cc.

90{
91 // Find hit collections and histogram Ids by names (just once)
92 // and save them in the data members of this class
93
94 if (fHodHCID[0] == -1) {
95 auto sdManager = G4SDManager::GetSDMpointer();
96 auto analysisManager = G4AnalysisManager::Instance();
97
98 // hits collections names
99 array<G4String, kDim> hHCName
100 = {{ "hodoscope1/hodoscopeColl", "hodoscope2/hodoscopeColl" }};
101 array<G4String, kDim> dHCName
102 = {{ "chamber1/driftChamberColl", "chamber2/driftChamberColl" }};
103 array<G4String, kDim> cHCName
104 = {{ "EMcalorimeter/EMcalorimeterColl", "HadCalorimeter/HadCalorimeterColl" }};
105
106 // histograms names
107 array<array<G4String, kDim>, kDim> histoName
108 = {{ {{ "Chamber1", "Chamber2" }}, {{ "Chamber1 XY", "Chamber2 XY" }} }};
109
110 for (G4int iDet = 0; iDet < kDim; ++iDet) {
111 // hit collections IDs
112 fHodHCID[iDet] = sdManager->GetCollectionID(hHCName[iDet]);
113 fDriftHCID[iDet] = sdManager->GetCollectionID(dHCName[iDet]);
114 fCalHCID[iDet] = sdManager->GetCollectionID(cHCName[iDet]);
115 // histograms IDs
116 fDriftHistoID[kH1][iDet] = analysisManager->GetH1Id(histoName[kH1][iDet]);
117 fDriftHistoID[kH2][iDet] = analysisManager->GetH2Id(histoName[kH2][iDet]);
118 }
119 }
120}
const G4int kH1
const G4int kH2
const G4int kDim
std::array< G4int, kDim > fDriftHCID
std::array< std::array< G4int, kDim >, kDim > fDriftHistoID
std::array< G4int, kDim > fCalHCID
std::array< G4int, kDim > fHodHCID

◆ EndOfEventAction()

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

Definition at line 124 of file EventAction.cc.

125{
126 //
127 // Fill histograms & ntuple
128 //
129
130 // Get analysis manager
131 auto analysisManager = G4AnalysisManager::Instance();
132
133 // Drift chambers hits
134 for (G4int iDet = 0; iDet < kDim; ++iDet) {
135 auto hc = GetHC(event, fDriftHCID[iDet]);
136 if ( ! hc ) return;
137
138 auto nhit = hc->GetSize();
139 analysisManager->FillH1(fDriftHistoID[kH1][iDet], nhit );
140 // columns 0, 1
141 analysisManager->FillNtupleIColumn(iDet, nhit);
142
143 for (unsigned long i = 0; i < nhit; ++i) {
144 auto hit = static_cast<DriftChamberHit*>(hc->GetHit(i));
145 auto localPos = hit->GetLocalPos();
146 analysisManager->FillH2(fDriftHistoID[kH2][iDet], localPos.x(), localPos.y());
147 }
148 }
149
150 // Em/Had Calorimeters hits
151 array<G4int, kDim> totalCalHit = {{ 0, 0 }};
152 array<G4double, kDim> totalCalEdep = {{ 0., 0. }};
153
154 for (G4int iDet = 0; iDet < kDim; ++iDet) {
155 auto hc = GetHC(event, fCalHCID[iDet]);
156 if ( ! hc ) return;
157
158 totalCalHit[iDet] = 0;
159 totalCalEdep[iDet] = 0.;
160 for (unsigned long i = 0; i < hc->GetSize(); ++i) {
161 G4double edep = 0.;
162 // The EM and Had calorimeter hits are of different types
163 if (iDet == 0) {
164 auto hit = static_cast<EmCalorimeterHit*>(hc->GetHit(i));
165 edep = hit->GetEdep();
166 } else {
167 auto hit = static_cast<HadCalorimeterHit*>(hc->GetHit(i));
168 edep = hit->GetEdep();
169 }
170 if ( edep > 0. ) {
171 totalCalHit[iDet]++;
172 totalCalEdep[iDet] += edep;
173 }
174 fCalEdep[iDet][i] = edep;
175 }
176 // columns 2, 3
177 analysisManager->FillNtupleDColumn(iDet + 2, totalCalEdep[iDet]);
178 }
179
180 // Hodoscopes hits
181 for (G4int iDet = 0; iDet < kDim; ++iDet) {
182 auto hc = GetHC(event, fHodHCID[iDet]);
183 if ( ! hc ) return;
184
185 for (unsigned int i = 0; i<hc->GetSize(); ++i) {
186 auto hit = static_cast<HodoscopeHit*>(hc->GetHit(i));
187 // columns 4, 5
188 analysisManager->FillNtupleDColumn(iDet + 4, hit->GetTime());
189 }
190 }
191 analysisManager->AddNtupleRow();
192
193 //
194 // Print diagnostics
195 //
196
197 auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
198 if ( printModulo == 0 || event->GetEventID() % printModulo != 0) return;
199
200 auto primary = event->GetPrimaryVertex(0)->GetPrimary(0);
201 G4cout
202 << G4endl
203 << ">>> Event " << event->GetEventID() << " >>> Simulation truth : "
204 << primary->GetG4code()->GetParticleName()
205 << " " << primary->GetMomentum() << G4endl;
206
207 // Hodoscopes
208 for (G4int iDet = 0; iDet < kDim; ++iDet) {
209 auto hc = GetHC(event, fHodHCID[iDet]);
210 if ( ! hc ) return;
211 G4cout << "Hodoscope " << iDet + 1 << " has " << hc->GetSize() << " hits." << G4endl;
212 for (unsigned int i = 0; i<hc->GetSize(); ++i) {
213 hc->GetHit(i)->Print();
214 }
215 }
216
217 // Drift chambers
218 for (G4int iDet = 0; iDet < kDim; ++iDet) {
219 auto hc = GetHC(event, fDriftHCID[iDet]);
220 if ( ! hc ) return;
221 G4cout << "Drift Chamber " << iDet + 1 << " has " << hc->GetSize() << " hits." << G4endl;
222 for (auto layer = 0; layer < kNofChambers; ++layer) {
223 for (unsigned int i = 0; i < hc->GetSize(); i++) {
224 auto hit = static_cast<DriftChamberHit*>(hc->GetHit(i));
225 if (hit->GetLayerID() == layer) hit->Print();
226 }
227 }
228 }
229
230 // Calorimeters
231 array<G4String, kDim> calName = {{ "EM", "Hadron" }};
232 for (G4int iDet = 0; iDet < kDim; ++iDet) {
233 G4cout << calName[iDet] << " Calorimeter has " << totalCalHit[iDet] << " hits."
234 << " Total Edep is " << totalCalEdep[iDet]/MeV << " (MeV)" << G4endl;
235 }
236}
std::array< std::vector< G4double >, kDim > fCalEdep
constexpr G4int kNofChambers
Definition Constants.hh:40

◆ GetEmCalEdep()

std::vector< G4double > & B5::EventAction::GetEmCalEdep ( )
inline

Definition at line 62 of file EventAction.hh.

62{ return fCalEdep[kEm]; }
const G4int kEm

◆ GetHadCalEdep()

std::vector< G4double > & B5::EventAction::GetHadCalEdep ( )
inline

Definition at line 63 of file EventAction.hh.

63{ return fCalEdep[kHad]; }
const G4int kHad

Member Data Documentation

◆ fHodHCID

std::array<G4int, kDim> B5::EventAction::fHodHCID = { -1, -1 }
private

Definition at line 67 of file EventAction.hh.

67{ -1, -1 };

◆ fDriftHCID

std::array<G4int, kDim> B5::EventAction::fDriftHCID = { -1, -1 }
private

Definition at line 68 of file EventAction.hh.

68{ -1, -1 };

◆ fCalHCID

std::array<G4int, kDim> B5::EventAction::fCalHCID = { -1, -1 }
private

Definition at line 69 of file EventAction.hh.

69{ -1, -1 };

◆ fDriftHistoID

std::array<std::array<G4int, kDim>, kDim> B5::EventAction::fDriftHistoID {{ {{ -1, -1 }}, {{ -1, -1 }} }}
private

Definition at line 71 of file EventAction.hh.

72{{ {{ -1, -1 }}, {{ -1, -1 }} }};

◆ fCalEdep

std::array<std::vector<G4double>, kDim> B5::EventAction::fCalEdep {{ std::vector<G4double>(kNofEmCells, 0.), std::vector<G4double>(kNofHadCells, 0.) }}
private

Definition at line 77 of file EventAction.hh.

78{{ std::vector<G4double>(kNofEmCells, 0.), std::vector<G4double>(kNofHadCells, 0.) }};
constexpr G4int kNofHadCells
Definition Constants.hh:46
constexpr G4int kNofEmCells
Definition Constants.hh:43

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

Applications | User Support | Publications | Collaboration