Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
26 //
27 // $Id$
28 //
29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31 
32 #include "RunAction.hh"
33 
34 #include "G4Run.hh"
35 #include "G4RunManager.hh"
36 #include "G4UnitsTable.hh"
37 
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 
41 {}
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 
46 {}
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 
50 void RunAction::BeginOfRunAction(const G4Run* aRun)
51 {
52  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
53 
54  //inform the runManager to save random number seed
56 
57  //initialize cumulative quantities
58  //
59  sumEAbs = sum2EAbs =sumEGap = sum2EGap = 0.;
60  sumLAbs = sum2LAbs =sumLGap = sum2LGap = 0.;
61 }
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
66  G4double LAbs, G4double LGap)
67 {
68  //accumulate statistic
69  //
70  sumEAbs += EAbs; sum2EAbs += EAbs*EAbs;
71  sumEGap += EGap; sum2EGap += EGap*EGap;
72 
73  sumLAbs += LAbs; sum2LAbs += LAbs*LAbs;
74  sumLGap += LGap; sum2LGap += LGap*LGap;
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78 
79 void RunAction::EndOfRunAction(const G4Run* aRun)
80 {
81  G4int NbOfEvents = aRun->GetNumberOfEvent();
82  if (NbOfEvents == 0) return;
83 
84  //compute statistics: mean and rms
85  //
86  sumEAbs /= NbOfEvents; sum2EAbs /= NbOfEvents;
87  G4double rmsEAbs = sum2EAbs - sumEAbs*sumEAbs;
88  if (rmsEAbs >0.) rmsEAbs = std::sqrt(rmsEAbs); else rmsEAbs = 0.;
89 
90  sumEGap /= NbOfEvents; sum2EGap /= NbOfEvents;
91  G4double rmsEGap = sum2EGap - sumEGap*sumEGap;
92  if (rmsEGap >0.) rmsEGap = std::sqrt(rmsEGap); else rmsEGap = 0.;
93 
94  sumLAbs /= NbOfEvents; sum2LAbs /= NbOfEvents;
95  G4double rmsLAbs = sum2LAbs - sumLAbs*sumLAbs;
96  if (rmsLAbs >0.) rmsLAbs = std::sqrt(rmsLAbs); else rmsLAbs = 0.;
97 
98  sumLGap /= NbOfEvents; sum2LGap /= NbOfEvents;
99  G4double rmsLGap = sum2LGap - sumLGap*sumLGap;
100  if (rmsLGap >0.) rmsLGap = std::sqrt(rmsLGap); else rmsLGap = 0.;
101 
102  //print
103  //
104  G4cout
105  << "\n--------------------End of Run------------------------------\n"
106  << "\n mean Energy in Absorber : " << G4BestUnit(sumEAbs,"Energy")
107  << " +- " << G4BestUnit(rmsEAbs,"Energy")
108  << "\n mean Energy in Gap : " << G4BestUnit(sumEGap,"Energy")
109  << " +- " << G4BestUnit(rmsEGap,"Energy")
110  << G4endl;
111 
112  G4cout
113  << "\n mean trackLength in Absorber : " << G4BestUnit(sumLAbs,"Length")
114  << " +- " << G4BestUnit(rmsLAbs,"Length")
115  << "\n mean trackLength in Gap : " << G4BestUnit(sumLGap,"Length")
116  << " +- " << G4BestUnit(rmsLGap,"Length")
117  << "\n------------------------------------------------------------\n"
118  << G4endl;
119 }
120 
121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......