Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B4aEventAction.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$
27 //
30 
31 #include "B4aEventAction.hh"
32 #include "B4RunAction.hh"
33 #include "B4Analysis.hh"
34 
35 #include "G4RunManager.hh"
36 #include "G4Event.hh"
37 #include "G4GenericMessenger.hh"
38 #include "G4UnitsTable.hh"
39 
40 #include "Randomize.hh"
41 #include <iomanip>
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 
47  fMessenger(0),
48  fEnergyAbs(0.),
49  fEnergyGap(0.),
50  fTrackLAbs(0.),
51  fTrackLGap(0.),
52  fPrintModulo(1)
53 {
54  // Define /B4/event commands using generic messenger class
55  fMessenger = new G4GenericMessenger(this, "/B4/event/", "Event control");
56 
57  // Define /B4/event/setPrintModulo command
58  G4GenericMessenger::Command& setPrintModulo
59  = fMessenger->DeclareProperty("setPrintModulo",
60  fPrintModulo,
61  "Print events modulo n");
62  setPrintModulo.SetRange("value>0");
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
68 {
69  delete fMessenger;
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
75 {
76 
77  G4int eventID = evt->GetEventID();
78  if ( eventID % fPrintModulo == 0 ) {
79  G4cout << "\n---> Begin of event: " << eventID << G4endl;
80  //CLHEP::HepRandom::showEngineStatus();
81  }
82 
83  // initialisation per event
84  fEnergyAbs = 0.;
85  fEnergyGap = 0.;
86  fTrackLAbs = 0.;
87  fTrackLGap = 0.;
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
93 {
94  // Accumulate statistics
95  //
96 
97  // get analysis manager
98  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
99 
100  // fill histograms
101  analysisManager->FillH1(1, fEnergyAbs);
102  analysisManager->FillH1(2, fEnergyGap);
103  analysisManager->FillH1(3, fTrackLAbs);
104  analysisManager->FillH1(4, fTrackLGap);
105 
106  // fill ntuple
107  analysisManager->FillNtupleDColumn(0, fEnergyAbs);
108  analysisManager->FillNtupleDColumn(1, fEnergyGap);
109  analysisManager->FillNtupleDColumn(2, fTrackLAbs);
110  analysisManager->FillNtupleDColumn(3, fTrackLGap);
111  analysisManager->AddNtupleRow();
112 
113  // Print per event (modulo n)
114  //
115  G4int eventID = evt->GetEventID();
116  if ( eventID % fPrintModulo == 0) {
117  G4cout << "---> End of event: " << eventID << G4endl;
118 
119  G4cout
120  << " Absorber: total energy: " << std::setw(7)
121  << G4BestUnit(fEnergyAbs,"Energy")
122  << " total track length: " << std::setw(7)
123  << G4BestUnit(fTrackLAbs,"Length")
124  << G4endl
125  << " Gap: total energy: " << std::setw(7)
126  << G4BestUnit(fEnergyGap,"Energy")
127  << " total track length: " << std::setw(7)
128  << G4BestUnit(fTrackLGap,"Length")
129  << G4endl;
130  }
131 }
132 
133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......