ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RunAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RunAction.cc
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 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "RunAction.hh"
35 #include "HistoManager.hh"
36 
37 #include "G4Run.hh"
38 #include "G4RunManager.hh"
39 #include "G4UnitsTable.hh"
40 
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42 
44 : G4UserRunAction(),
45  fHistoManager(histo),
46  fSumEAbs(0.), fSum2EAbs(0.),
47  fSumEGap(0.), fSum2EGap(0.),
48  fSumLAbs(0.), fSum2LAbs(0.),
49  fSumLGap(0.), fSum2LGap(0.)
50 {}
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
55 {}
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
59 void RunAction::BeginOfRunAction(const G4Run* aRun)
60 {
61  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
62 
63  //initialize cumulative quantities
64  //
67 
68  //histograms
69  //
70  fHistoManager->Book();
71 }
72 
73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 
76  G4double LAbs, G4double LGap)
77 {
78  //accumulate statistic
79  //
80  fSumEAbs += EAbs; fSum2EAbs += EAbs*EAbs;
81  fSumEGap += EGap; fSum2EGap += EGap*EGap;
82 
83  fSumLAbs += LAbs; fSum2LAbs += LAbs*LAbs;
84  fSumLGap += LGap; fSum2LGap += LGap*LGap;
85 }
86 
87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88 
89 void RunAction::EndOfRunAction(const G4Run* aRun)
90 {
91  G4int NbOfEvents = aRun->GetNumberOfEvent();
92  if (NbOfEvents == 0) return;
93 
94  //compute statistics: mean and rms
95  //
96  fSumEAbs /= NbOfEvents; fSum2EAbs /= NbOfEvents;
97  G4double rmsEAbs = fSum2EAbs - fSumEAbs*fSumEAbs;
98  if (rmsEAbs >0.) rmsEAbs = std::sqrt(rmsEAbs); else rmsEAbs = 0.;
99 
100  fSumEGap /= NbOfEvents; fSum2EGap /= NbOfEvents;
101  G4double rmsEGap = fSum2EGap - fSumEGap*fSumEGap;
102  if (rmsEGap >0.) rmsEGap = std::sqrt(rmsEGap); else rmsEGap = 0.;
103 
104  fSumLAbs /= NbOfEvents; fSum2LAbs /= NbOfEvents;
105  G4double rmsLAbs = fSum2LAbs - fSumLAbs*fSumLAbs;
106  if (rmsLAbs >0.) rmsLAbs = std::sqrt(rmsLAbs); else rmsLAbs = 0.;
107 
108  fSumLGap /= NbOfEvents; fSum2LGap /= NbOfEvents;
109  G4double rmsLGap = fSum2LGap - fSumLGap*fSumLGap;
110  if (rmsLGap >0.) rmsLGap = std::sqrt(rmsLGap); else rmsLGap = 0.;
111 
112  //print
113  //
114  G4cout
115  << "\n--------------------End of Run------------------------------\n"
116  << "\n mean Energy in Absorber : " << G4BestUnit(fSumEAbs,"Energy")
117  << " +- " << G4BestUnit(rmsEAbs,"Energy")
118  << "\n mean Energy in Gap : " << G4BestUnit(fSumEGap,"Energy")
119  << " +- " << G4BestUnit(rmsEGap,"Energy")
120  << G4endl;
121 
122  G4cout
123  << "\n mean trackLength in Absorber : " << G4BestUnit(fSumLAbs,"Length")
124  << " +- " << G4BestUnit(rmsLAbs,"Length")
125  << "\n mean trackLength in Gap : " << G4BestUnit(fSumLGap,"Length")
126  << " +- " << G4BestUnit(rmsLGap,"Length")
127  << "\n------------------------------------------------------------\n"
128  << G4endl;
129 
130  //save histograms
131  //
133  fHistoManager->Save();
134 }
135 
136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......