Geant4  10.02.p01
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 88427 2015-02-19 08:19:38Z 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 
62  const G4Event* event) const
63 {
64  B4cCalorHitsCollection* 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 
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
118 
119  // Get hit with total values
120  B4cCalorHit* absoHit = (*absoHC)[absoHC->entries()-1];
121  B4cCalorHit* gapHit = (*gapHC)[gapHC->entries()-1];
122 
123  // Print per event (modulo n)
124  //
125  G4int eventID = event->GetEventID();
127  if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) {
128  G4cout << "---> End of event: " << eventID << G4endl;
129 
131  absoHit->GetEdep(), absoHit->GetTrackLength(),
132  gapHit->GetEdep(), gapHit->GetTrackLength());
133  }
134 
135  // Fill histograms, ntuple
136  //
137 
138  // get analysis manager
139  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
140 
141  // fill histograms
142  analysisManager->FillH1(1, absoHit->GetEdep());
143  analysisManager->FillH1(2, gapHit->GetEdep());
144  analysisManager->FillH1(3, absoHit->GetTrackLength());
145  analysisManager->FillH1(4, 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:131
G4double GetTrackLength() const
Definition: B4cCalorHit.hh:109
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
virtual void BeginOfEventAction(const G4Event *event)
G4int entries() const
virtual void EndOfEventAction(const G4Event *event)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
Calorimeter hit class.
Definition: B4cCalorHit.hh:46
G4double GetEdep() const
Definition: B4cCalorHit.hh:105
void PrintEventStatistics(G4double absoEdep, G4double absoTrackLength, G4double gapEdep, G4double gapTrackLength) const
Definition of the B4cCalorimeterSD class.
B4cCalorHitsCollection * GetHitsCollection(G4int hcID, const G4Event *event) const
G4GLOB_DLL std::ostream G4cout
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:66
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.