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 //
28 //
29 //
30 // $Id$
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 :fHistoManager(histo)
46 {}
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 
51 {}
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
55 void RunAction::BeginOfRunAction(const G4Run* aRun)
56 {
57  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
58 
59  //initialize cumulative quantities
60  //
61  fSumEAbs = fSum2EAbs =fSumEGap = fSum2EGap = 0.;
62  fSumLAbs = fSum2LAbs =fSumLGap = fSum2LGap = 0.;
63 
64  //histograms
65  //
66  fHistoManager->book();
67 }
68 
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
72  G4double LAbs, G4double LGap)
73 {
74  //accumulate statistic
75  //
76  fSumEAbs += EAbs; fSum2EAbs += EAbs*EAbs;
77  fSumEGap += EGap; fSum2EGap += EGap*EGap;
78 
79  fSumLAbs += LAbs; fSum2LAbs += LAbs*LAbs;
80  fSumLGap += LGap; fSum2LGap += LGap*LGap;
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
85 void RunAction::EndOfRunAction(const G4Run* aRun)
86 {
87  G4int NbOfEvents = aRun->GetNumberOfEvent();
88  if (NbOfEvents == 0) return;
89 
90  //compute statistics: mean and rms
91  //
92  fSumEAbs /= NbOfEvents; fSum2EAbs /= NbOfEvents;
93  G4double rmsEAbs = fSum2EAbs - fSumEAbs*fSumEAbs;
94  if (rmsEAbs >0.) rmsEAbs = std::sqrt(rmsEAbs); else rmsEAbs = 0.;
95 
96  fSumEGap /= NbOfEvents; fSum2EGap /= NbOfEvents;
97  G4double rmsEGap = fSum2EGap - fSumEGap*fSumEGap;
98  if (rmsEGap >0.) rmsEGap = std::sqrt(rmsEGap); else rmsEGap = 0.;
99 
100  fSumLAbs /= NbOfEvents; fSum2LAbs /= NbOfEvents;
101  G4double rmsLAbs = fSum2LAbs - fSumLAbs*fSumLAbs;
102  if (rmsLAbs >0.) rmsLAbs = std::sqrt(rmsLAbs); else rmsLAbs = 0.;
103 
104  fSumLGap /= NbOfEvents; fSum2LGap /= NbOfEvents;
105  G4double rmsLGap = fSum2LGap - fSumLGap*fSumLGap;
106  if (rmsLGap >0.) rmsLGap = std::sqrt(rmsLGap); else rmsLGap = 0.;
107 
108  //print
109  //
110  G4cout
111  << "\n--------------------End of Run------------------------------\n"
112  << "\n mean Energy in Absorber : " << G4BestUnit(fSumEAbs,"Energy")
113  << " +- " << G4BestUnit(rmsEAbs,"Energy")
114  << "\n mean Energy in Gap : " << G4BestUnit(fSumEGap,"Energy")
115  << " +- " << G4BestUnit(rmsEGap,"Energy")
116  << G4endl;
117 
118  G4cout
119  << "\n mean trackLength in Absorber : " << G4BestUnit(fSumLAbs,"Length")
120  << " +- " << G4BestUnit(rmsLAbs,"Length")
121  << "\n mean trackLength in Gap : " << G4BestUnit(fSumLGap,"Length")
122  << " +- " << G4BestUnit(rmsLGap,"Length")
123  << "\n------------------------------------------------------------\n"
124  << G4endl;
125 
126  //save histograms
127  //
128  fHistoManager->PrintStatistic();
129  fHistoManager->save();
130 }
131 
132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......