Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B5EventAction Class Reference

Event action. More...

#include <B5EventAction.hh>

Inheritance diagram for B5EventAction:
Collaboration diagram for B5EventAction:

Public Member Functions

 B5EventAction ()
 
virtual ~B5EventAction ()
 
virtual void BeginOfEventAction (const G4Event *)
 
virtual void EndOfEventAction (const G4Event *)
 
std::vector< G4double > & GetEmCalEdep ()
 
std::vector< G4double > & GetHadCalEdep ()
 
- Public Member Functions inherited from G4UserEventAction
 G4UserEventAction ()
 
virtual ~G4UserEventAction ()
 
virtual void SetEventManager (G4EventManager *value)
 

Additional Inherited Members

- Protected Attributes inherited from G4UserEventAction
G4EventManagerfpEventManager
 

Detailed Description

Event action.

Definition at line 42 of file B5EventAction.hh.

Constructor & Destructor Documentation

B5EventAction::B5EventAction ( )

Definition at line 51 of file B5EventAction.cc.

53  fHodHC1ID(-1),
54  fHodHC2ID(-1),
55  fDriftHC1ID(-1),
56  fDriftHC2ID(-1),
57  fEmCalHCID(-1),
58  fHadCalHCID(-1),
59  fEmCalEdep(kNofEmCells, 0.),
60  fHadCalEdep(kNofHadCells, 0.)
61 {
62  // set printing per each event
64 }
void SetPrintProgress(G4int i)
constexpr G4int kNofHadCells
Definition: B5Constants.hh:44
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
constexpr G4int kNofEmCells
Definition: B5Constants.hh:41

Here is the call graph for this function:

B5EventAction::~B5EventAction ( )
virtual

Definition at line 68 of file B5EventAction.cc.

69 {}

Member Function Documentation

void B5EventAction::BeginOfEventAction ( const G4Event )
virtual

Reimplemented from G4UserEventAction.

Definition at line 73 of file B5EventAction.cc.

74 {
75  if (fHodHC1ID==-1) {
76  auto sdManager = G4SDManager::GetSDMpointer();
77  fHodHC1ID = sdManager->GetCollectionID("hodoscope1/hodoscopeColl");
78  fHodHC2ID = sdManager->GetCollectionID("hodoscope2/hodoscopeColl");
79  fDriftHC1ID = sdManager->GetCollectionID("chamber1/driftChamberColl");
80  fDriftHC2ID = sdManager->GetCollectionID("chamber2/driftChamberColl");
81  fEmCalHCID = sdManager->GetCollectionID("EMcalorimeter/EMcalorimeterColl");
82  fHadCalHCID = sdManager->GetCollectionID("HadCalorimeter/HadCalorimeterColl");
83  }
84 }
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40

Here is the call graph for this function:

void B5EventAction::EndOfEventAction ( const G4Event event)
virtual

Reimplemented from G4UserEventAction.

Definition at line 88 of file B5EventAction.cc.

89 {
90  auto hce = event->GetHCofThisEvent();
91  if (!hce) {
93  msg << "No hits collection of this event found." << G4endl;
94  G4Exception("B5EventAction::EndOfEventAction()",
95  "B5Code001", JustWarning, msg);
96  return;
97  }
98 
99  // Get hits collections
100  auto hHC1
101  = static_cast<B5HodoscopeHitsCollection*>(hce->GetHC(fHodHC1ID));
102 
103  auto hHC2
104  = static_cast<B5HodoscopeHitsCollection*>(hce->GetHC(fHodHC2ID));
105 
106  auto dHC1
107  = static_cast<B5DriftChamberHitsCollection*>(hce->GetHC(fDriftHC1ID));
108 
109  auto dHC2
110  = static_cast<B5DriftChamberHitsCollection*>(hce->GetHC(fDriftHC2ID));
111 
112  auto ecHC
113  = static_cast<B5EmCalorimeterHitsCollection*>(hce->GetHC(fEmCalHCID));
114 
115  auto hcHC
116  = static_cast<B5HadCalorimeterHitsCollection*>(hce->GetHC(fHadCalHCID));
117 
118  if ( (!hHC1) || (!hHC2) || (!dHC1) || (!dHC2) || (!ecHC) || (!hcHC) ) {
120  msg << "Some of hits collections of this event not found." << G4endl;
121  G4Exception("B5EventAction::EndOfEventAction()",
122  "B5Code001", JustWarning, msg);
123  return;
124  }
125 
126  //
127  // Fill histograms & ntuple
128  //
129 
130  // Get analysis manager
131  auto analysisManager = G4AnalysisManager::Instance();
132 
133  // Fill histograms
134 
135  auto nhit = dHC1->entries();
136  analysisManager->FillH1(0, nhit );
137 
138  for (auto i=0;i<nhit ;i++) {
139  auto hit = (*dHC1)[i];
140  auto localPos = hit->GetLocalPos();
141  analysisManager->FillH2(0, localPos.x(), localPos.y());
142  }
143 
144  nhit = dHC2->entries();
145  analysisManager->FillH1(1, nhit );
146 
147  for (auto i=0;i<nhit ;i++) {
148  auto hit = (*dHC2)[i];
149  auto localPos = hit->GetLocalPos();
150  analysisManager->FillH2(1, localPos.x(), localPos.y());
151  }
152 
153  // Fill ntuple
154 
155  // Dc1Hits
156  analysisManager->FillNtupleIColumn(0, dHC1->entries());
157  // Dc2Hits
158  analysisManager->FillNtupleIColumn(1, dHC1->entries());
159 
160  // ECEnergy
161  G4int totalEmHit = 0;
162  G4double totalEmE = 0.;
163  for (auto i=0;i<kNofEmCells;i++) {
164  auto hit = (*ecHC)[i];
165  auto edep = hit->GetEdep();
166  if (edep>0.) {
167  totalEmHit++;
168  totalEmE += edep;
169  }
170  fEmCalEdep[i] = edep;
171  }
172  analysisManager->FillNtupleDColumn(2, totalEmE);
173 
174  // HCEnergy
175  G4int totalHadHit = 0;
176  G4double totalHadE = 0.;
177  for (auto i=0;i<kNofHadCells;i++) {
178  auto hit = (*hcHC)[i];
179  auto edep = hit->GetEdep();
180  if (edep>0.) {
181  totalHadHit++;
182  totalHadE += edep;
183  }
184  fHadCalEdep[i] = edep;
185  }
186  analysisManager->FillNtupleDColumn(3, totalHadE);
187 
188  // Time 1
189  for (auto i=0;i<hHC1->entries();i++) {
190  analysisManager->FillNtupleDColumn(4,(*hHC1)[i]->GetTime());
191  }
192 
193  // Time 2
194  for (auto i=0;i<hHC2->entries();i++) {
195  analysisManager->FillNtupleDColumn(5,(*hHC2)[i]->GetTime());
196  }
197 
198  analysisManager->AddNtupleRow();
199 
200  //
201  // Print diagnostics
202  //
203 
204  auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
205  if ( printModulo==0 || event->GetEventID() % printModulo != 0) return;
206 
207  auto primary = event->GetPrimaryVertex(0)->GetPrimary(0);
208  G4cout
209  << G4endl
210  << ">>> Event " << event->GetEventID() << " >>> Simulation truth : "
211  << primary->GetG4code()->GetParticleName()
212  << " " << primary->GetMomentum() << G4endl;
213 
214  // Hodoscope 1
215  nhit = hHC1->entries();
216  G4cout << "Hodoscope 1 has " << nhit << " hits." << G4endl;
217  for (auto i=0;i<nhit ;i++) {
218  auto hit = (*hHC1)[i];
219  hit->Print();
220  }
221 
222  // Hodoscope 2
223  nhit = hHC2->entries();
224  G4cout << "Hodoscope 2 has " << nhit << " hits." << G4endl;
225  for (auto i=0;i<nhit ;i++) {
226  auto hit = (*hHC2)[i];
227  hit->Print();
228  }
229 
230  // Drift chamber 1
231  nhit = dHC1->entries();
232  G4cout << "Drift Chamber 1 has " << nhit << " hits." << G4endl;
233  for (auto layer=0;layer<kNofChambers;layer++) {
234  for (auto i=0;i<nhit ;i++) {
235  auto hit = (*dHC1)[i];
236  if (hit->GetLayerID()==layer) hit->Print();
237  }
238  }
239 
240  // Drift chamber 2
241  nhit = dHC2->entries();
242  G4cout << "Drift Chamber 2 has " << nhit << " hits." << G4endl;
243  for (auto layer=0;layer<kNofChambers;layer++) {
244  for (auto i=0;i<nhit ;i++) {
245  auto hit = (*dHC2)[i];
246  if (hit->GetLayerID()==layer) hit->Print();
247  }
248  }
249 
250  // EM calorimeter
251  G4cout << "EM Calorimeter has " << totalEmHit << " hits. Total Edep is "
252  << totalEmE/MeV << " (MeV)" << G4endl;
253 
254  // Had calorimeter
255  G4cout << "Hadron Calorimeter has " << totalHadHit << " hits. Total Edep is "
256  << totalHadE/MeV << " (MeV)" << G4endl;
257 }
G4int GetPrintProgress()
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
constexpr G4int kNofChambers
Definition: B5Constants.hh:38
constexpr G4int kNofHadCells
Definition: B5Constants.hh:44
int G4int
Definition: G4Types.hh:78
G4int GetEventID() const
Definition: G4Event.hh:151
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
#define G4endl
Definition: G4ios.hh:61
static constexpr double MeV
Definition: G4SIunits.hh:214
double G4double
Definition: G4Types.hh:76
constexpr G4int kNofEmCells
Definition: B5Constants.hh:41

Here is the call graph for this function:

std::vector<G4double>& B5EventAction::GetEmCalEdep ( )
inline

Definition at line 51 of file B5EventAction.hh.

51 { return fEmCalEdep; }

Here is the caller graph for this function:

std::vector<G4double>& B5EventAction::GetHadCalEdep ( )
inline

Definition at line 52 of file B5EventAction.hh.

52 { return fEmCalEdep; }

Here is the caller graph for this function:


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