Geant4_10
RunAction.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 //
28 //
29 //
30 // $Id: RunAction.cc 74272 2013-10-02 14:48:50Z gcosmo $
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "RunAction.hh"
36 #include "HistoManager.hh"
37 
38 #include "G4Run.hh"
39 #include "G4RunManager.hh"
40 #include "G4UnitsTable.hh"
41 
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 
45 : G4UserRunAction(),
46  fHistoManager(histo),
47  fSumEAbs(0.), fSum2EAbs(0.),
48  fSumEGap(0.), fSum2EGap(0.),
49  fSumLAbs(0.), fSum2LAbs(0.),
50  fSumLGap(0.), fSum2LGap(0.)
51 {}
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
56 {}
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
60 void RunAction::BeginOfRunAction(const G4Run* aRun)
61 {
62  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
63 
64  //initialize cumulative quantities
65  //
66  fSumEAbs = fSum2EAbs =fSumEGap = fSum2EGap = 0.;
67  fSumLAbs = fSum2LAbs =fSumLGap = fSum2LGap = 0.;
68 
69  //histograms
70  //
71  fHistoManager->book();
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
77  G4double LAbs, G4double LGap)
78 {
79  //accumulate statistic
80  //
81  fSumEAbs += EAbs; fSum2EAbs += EAbs*EAbs;
82  fSumEGap += EGap; fSum2EGap += EGap*EGap;
83 
84  fSumLAbs += LAbs; fSum2LAbs += LAbs*LAbs;
85  fSumLGap += LGap; fSum2LGap += LGap*LGap;
86 }
87 
88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89 
90 void RunAction::EndOfRunAction(const G4Run* aRun)
91 {
92  G4int NbOfEvents = aRun->GetNumberOfEvent();
93  if (NbOfEvents == 0) return;
94 
95  //compute statistics: mean and rms
96  //
97  fSumEAbs /= NbOfEvents; fSum2EAbs /= NbOfEvents;
98  G4double rmsEAbs = fSum2EAbs - fSumEAbs*fSumEAbs;
99  if (rmsEAbs >0.) rmsEAbs = std::sqrt(rmsEAbs); else rmsEAbs = 0.;
100 
101  fSumEGap /= NbOfEvents; fSum2EGap /= NbOfEvents;
102  G4double rmsEGap = fSum2EGap - fSumEGap*fSumEGap;
103  if (rmsEGap >0.) rmsEGap = std::sqrt(rmsEGap); else rmsEGap = 0.;
104 
105  fSumLAbs /= NbOfEvents; fSum2LAbs /= NbOfEvents;
106  G4double rmsLAbs = fSum2LAbs - fSumLAbs*fSumLAbs;
107  if (rmsLAbs >0.) rmsLAbs = std::sqrt(rmsLAbs); else rmsLAbs = 0.;
108 
109  fSumLGap /= NbOfEvents; fSum2LGap /= NbOfEvents;
110  G4double rmsLGap = fSum2LGap - fSumLGap*fSumLGap;
111  if (rmsLGap >0.) rmsLGap = std::sqrt(rmsLGap); else rmsLGap = 0.;
112 
113  //print
114  //
115  G4cout
116  << "\n--------------------End of Run------------------------------\n"
117  << "\n mean Energy in Absorber : " << G4BestUnit(fSumEAbs,"Energy")
118  << " +- " << G4BestUnit(rmsEAbs,"Energy")
119  << "\n mean Energy in Gap : " << G4BestUnit(fSumEGap,"Energy")
120  << " +- " << G4BestUnit(rmsEGap,"Energy")
121  << G4endl;
122 
123  G4cout
124  << "\n mean trackLength in Absorber : " << G4BestUnit(fSumLAbs,"Length")
125  << " +- " << G4BestUnit(rmsLAbs,"Length")
126  << "\n mean trackLength in Gap : " << G4BestUnit(fSumLGap,"Length")
127  << " +- " << G4BestUnit(rmsLGap,"Length")
128  << "\n------------------------------------------------------------\n"
129  << G4endl;
130 
131  //save histograms
132  //
133  fHistoManager->PrintStatistic();
134  fHistoManager->save();
135 }
136 
137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
void PrintStatistic()
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
~RunAction()
Definition: RunAction.cc:52
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void fillPerEvent(G4double, G4double, G4double, G4double)
Definition: RunAction.cc:76