Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B4cEventAction.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 // $Id: B4cEventAction.cc 100946 2016-11-03 11:28:08Z gcosmo $
27 //
30 
31 #include "B4cEventAction.hh"
32 #include "B4cCalorimeterSD.hh"
33 #include "B4cCalorHit.hh"
34 #include "B4Analysis.hh"
35 
36 #include "G4RunManager.hh"
37 #include "G4Event.hh"
38 #include "G4SDManager.hh"
39 #include "G4HCofThisEvent.hh"
40 #include "G4UnitsTable.hh"
41 
42 #include "Randomize.hh"
43 #include <iomanip>
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46 
49  fAbsHCID(-1),
50  fGapHCID(-1)
51 {}
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
56 {}
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 B4cEventAction::GetHitsCollection(G4int hcID,
62  const G4Event* event) const
63 {
64  auto hitsCollection
65  = static_cast<B4cCalorHitsCollection*>(
66  event->GetHCofThisEvent()->GetHC(hcID));
67 
68  if ( ! hitsCollection ) {
70  msg << "Cannot access hitsCollection ID " << hcID;
71  G4Exception("B4cEventAction::GetHitsCollection()",
72  "MyCode0003", FatalException, msg);
73  }
74 
75  return hitsCollection;
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
80 void B4cEventAction::PrintEventStatistics(
81  G4double absoEdep, G4double absoTrackLength,
82  G4double gapEdep, G4double gapTrackLength) const
83 {
84  // print event statistics
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 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99 
101 {}
102 
103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
104 
106 {
107  // Get hits collections IDs (only once)
108  if ( fAbsHCID == -1 ) {
109  fAbsHCID
110  = G4SDManager::GetSDMpointer()->GetCollectionID("AbsorberHitsCollection");
111  fGapHCID
112  = G4SDManager::GetSDMpointer()->GetCollectionID("GapHitsCollection");
113  }
114 
115  // Get hits collections
116  auto absoHC = GetHitsCollection(fAbsHCID, event);
117  auto gapHC = GetHitsCollection(fGapHCID, event);
118 
119  // Get hit with total values
120  auto absoHit = (*absoHC)[absoHC->entries()-1];
121  auto gapHit = (*gapHC)[gapHC->entries()-1];
122 
123  // Print per event (modulo n)
124  //
125  auto eventID = event->GetEventID();
126  auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
127  if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) {
128  G4cout << "---> End of event: " << eventID << G4endl;
129 
130  PrintEventStatistics(
131  absoHit->GetEdep(), absoHit->GetTrackLength(),
132  gapHit->GetEdep(), gapHit->GetTrackLength());
133  }
134 
135  // Fill histograms, ntuple
136  //
137 
138  // get analysis manager
139  auto analysisManager = G4AnalysisManager::Instance();
140 
141  // fill histograms
142  analysisManager->FillH1(0, absoHit->GetEdep());
143  analysisManager->FillH1(1, gapHit->GetEdep());
144  analysisManager->FillH1(2, absoHit->GetTrackLength());
145  analysisManager->FillH1(3, gapHit->GetTrackLength());
146 
147  // fill ntuple
148  analysisManager->FillNtupleDColumn(0, absoHit->GetEdep());
149  analysisManager->FillNtupleDColumn(1, gapHit->GetEdep());
150  analysisManager->FillNtupleDColumn(2, absoHit->GetTrackLength());
151  analysisManager->FillNtupleDColumn(3, gapHit->GetTrackLength());
152  analysisManager->AddNtupleRow();
153 }
154 
155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4int GetPrintProgress()
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
virtual void BeginOfEventAction(const G4Event *event)
virtual void EndOfEventAction(const G4Event *event)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
Definition of the B4cCalorimeterSD class.
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
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
Definition of the B4cEventAction class.
virtual ~B4cEventAction()
Definition of the B4cCalorHit class.