Geant4  10.01.p02
B4dEventAction.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: B4dEventAction.cc 75604 2013-11-04 13:17:26Z gcosmo $
27 //
30 
31 #include "B4dEventAction.hh"
32 #include "B4Analysis.hh"
33 
34 #include "G4RunManager.hh"
35 #include "G4Event.hh"
36 #include "G4SDManager.hh"
37 #include "G4HCofThisEvent.hh"
38 #include "G4UnitsTable.hh"
39 
40 #include "Randomize.hh"
41 #include <iomanip>
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 
47  fAbsoEdepHCID(-1),
48  fGapEdepHCID(-1),
49  fAbsoTrackLengthHCID(-1),
50  fGapTrackLengthHCID(-1)
51 {}
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
56 {}
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
62  const G4Event* event) const
63 {
64  G4THitsMap<G4double>* hitsCollection
65  = static_cast<G4THitsMap<G4double>*>(
66  event->GetHCofThisEvent()->GetHC(hcID));
67 
68  if ( ! hitsCollection ) {
70  msg << "Cannot access hitsCollection ID " << hcID;
71  G4Exception("B4dEventAction::GetHitsCollection()",
72  "MyCode0003", FatalException, msg);
73  }
74 
75  return hitsCollection;
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81 {
82  G4double sumValue = 0;
83  std::map<G4int, G4double*>::iterator it;
84  for ( it = hitsMap->GetMap()->begin(); it != hitsMap->GetMap()->end(); it++) {
85  sumValue += *(it->second);
86  }
87  return sumValue;
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
93  G4double absoEdep, G4double absoTrackLength,
94  G4double gapEdep, G4double gapTrackLength) const
95 {
96  // Print event statistics
97  //
98  G4cout
99  << " Absorber: total energy: "
100  << std::setw(7) << G4BestUnit(absoEdep, "Energy")
101  << " total track length: "
102  << std::setw(7) << G4BestUnit(absoTrackLength, "Length")
103  << G4endl
104  << " Gap: total energy: "
105  << std::setw(7) << G4BestUnit(gapEdep, "Energy")
106  << " total track length: "
107  << std::setw(7) << G4BestUnit(gapTrackLength, "Length")
108  << G4endl;
109 }
110 
111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112 
114 {}
115 
116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
117 
119 {
120  // Get hist collections IDs
121  if ( fAbsoEdepHCID == -1 ) {
123  = G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/Edep");
124  fGapEdepHCID
127  = G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/TrackLength");
129  = G4SDManager::GetSDMpointer()->GetCollectionID("Gap/TrackLength");
130  }
131 
132  // Get sum values from hits collections
133  //
134  G4double absoEdep = GetSum(GetHitsCollection(fAbsoEdepHCID, event));
135  G4double gapEdep = GetSum(GetHitsCollection(fGapEdepHCID, event));
136 
137  G4double absoTrackLength
139  G4double gapTrackLength
141 
142  // get analysis manager
143  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
144 
145  // fill histograms
146  //
147  analysisManager->FillH1(1, absoEdep);
148  analysisManager->FillH1(2, gapEdep);
149  analysisManager->FillH1(3, absoTrackLength);
150  analysisManager->FillH1(4, gapTrackLength);
151 
152  // fill ntuple
153  //
154  analysisManager->FillNtupleDColumn(0, absoEdep);
155  analysisManager->FillNtupleDColumn(1, gapEdep);
156  analysisManager->FillNtupleDColumn(2, absoTrackLength);
157  analysisManager->FillNtupleDColumn(3, gapTrackLength);
158  analysisManager->AddNtupleRow();
159 
160  //print per event (modulo n)
161  //
162  G4int eventID = event->GetEventID();
164  if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) {
165  G4cout << "---> End of event: " << eventID << G4endl;
166  PrintEventStatistics(absoEdep, absoTrackLength, gapEdep, gapTrackLength);
167  }
168 }
169 
170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual void BeginOfEventAction(const G4Event *event)
G4int GetPrintProgress()
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4THitsMap< G4double > * GetHitsCollection(G4int hcID, const G4Event *event) const
G4double GetSum(G4THitsMap< G4double > *hitsMap) const
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
G4int fAbsoTrackLengthHCID
G4GLOB_DLL std::ostream G4cout
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:61
virtual void EndOfEventAction(const G4Event *event)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
void PrintEventStatistics(G4double absoEdep, G4double absoTrackLength, G4double gapEdep, G4double gapTrackLength) const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
Definition of the B4dEventAction class.
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68
virtual ~B4dEventAction()
#define G4endl
Definition: G4ios.hh:61
G4int fGapTrackLengthHCID
double G4double
Definition: G4Types.hh:76