ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4StatAnalysis.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4StatAnalysis.hh
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 //
28 //
29 // ----------------------------------------------------------------------
30 // Class G4StatAnalysis
31 //
32 // Class description:
33 //
34 // Class for statistical analysis of random variable
35 //
36 // Adapted
37 // Lux, I.
38 // Monte Carlo particle transport methods: neutron and photon
39 // calculations/authors, Ivan Lux and Laszlo Koblinger.
40 // ISBN 0-8493-6074-9
41 // 1. Neutron transport theory. 2. Photon transport theory.
42 // 3. Monte Carlo method. I. Koblinger, Laszlo. II. Title.
43 // QC793.5.N4628L88 1990
44 // 530.1 '38—dc20
45 //
46 // https://gnssn.iaea.org/NSNI/Shared%20Documents/OPEN%20Shared%20Files/MonteCarloParticleTransportMethodsNeutronAndPhotonCalculations.pdf
47 //
48 //
49 
50 #ifndef G4StatAnalysis_hh_
51 #define G4StatAnalysis_hh_
52 
53 //----------------------------------------------------------------------------//
54 
55 #include <iostream>
56 #include <iomanip>
57 #include <limits>
58 #include <fstream>
59 #include <cmath>
60 
61 #include "globals.hh"
62 #include "tls.hh"
63 
64 #include "G4Types.hh"
65 #include "G4Timer.hh"
66 #include "G4ios.hh"
67 #include "G4Allocator.hh"
68 
70 {
71 public:
72  inline G4StatAnalysis();
73  inline ~G4StatAnalysis() { }
74 
75 public:
76  // Accumulated values
77  inline G4double GetMean() const;
78  inline const G4double& GetSum() const;
79  inline const G4double& GetSumSquared() const;
80  inline const G4double& GetSum1() const;
81  inline const G4double& GetSum2() const;
82  inline const G4int& GetHits() const;
83  inline G4int GetNumNonZero() const;
84  inline G4int GetNumZero() const;
85 
86  // Some control over accumulated variables
87  inline void SetSum(const G4double& val);
88  inline void SetSumSquared(const G4double& val);
89  inline void SetSum1(const G4double& val);
90  inline void SetSum2(const G4double& val);
91  inline void SetHits(const G4int& val);
92  inline void SetZero(const G4int& val);
93 
94  // Computed values
95  inline G4double GetFOM() const;
96  inline G4double GetRelativeError() const;
97  inline G4double GetStdDev() const;
98  inline G4double GetVariance() const;
99  inline G4double GetCoeffVariation() const;
100  inline G4double GetEfficiency() const;
101  inline G4double GetR2Int() const;
102  inline G4double GetR2Eff() const;
103 
104  // Conversion
105  inline operator G4double() const;
106 
107  // Modifications
108  inline void Reset();
109  inline void Add(const G4double& _val, const G4double& _weight = 1.0);
110  inline void Rescale(const G4double& factor);
111 
112  // Output
113  inline void PrintInfo(std::ostream& os, const std::string& = "") const;
114 
115  // Operators
116  inline G4StatAnalysis& operator+=(const G4double& _val);
117  inline G4StatAnalysis& operator/=(const G4double& _val);
118  inline G4StatAnalysis& operator+=(const G4StatAnalysis&);
119  inline G4StatAnalysis& operator-=(const G4StatAnalysis&);
120 
121  // Allocators
122  inline void* operator new(size_t);
123  inline void operator delete(void*);
124 
125  // Timing (member functions)
126  inline G4double GetCpuTime() const;
127  // Timing (static functions)
128  static tms*& GetCpuClock()
129  {
130  G4ThreadLocalStatic tms* _instance = nullptr;
131  if(!_instance)
132  {
133  _instance = new tms;
134  times(_instance);
135  }
136  return _instance;
137  }
138  // Note: this above implementation was implemented in such a way as to
139  // conserve memory by eliminated every instance from requiring their own
140  // timing variables. The ResetCpuClock function below is called at the
141  // beginning of the run (G4Run constructor) to attempt to ensure the
142  // FOM is not skewed by multiple runs -- it may be necessary to
143  // manually invoke in some situations
144  static void ResetCpuClock()
145  {
146  tms*& _clock = GetCpuClock();
147  times(_clock);
148  }
149 
150 private:
151  // summation of each history^1
153  // summation from each history^2
155  // number of scoring histories
157  // number of histories that were not greater than 0.0
159 
160 public:
161  // friend operator for output
162  friend std::ostream& operator<<(std::ostream& os, const G4StatAnalysis& obj)
163  {
164  obj.PrintInfo(os);
165  return os;
166  }
167  // friend operator for addition
168  friend const G4StatAnalysis operator+(const G4StatAnalysis& lhs,
169  const G4StatAnalysis& rhs)
170  {
171  return G4StatAnalysis(lhs) += rhs;
172  }
173  // friend operator for subtraction
174  friend const G4StatAnalysis operator-(const G4StatAnalysis& lhs,
175  const G4StatAnalysis& rhs)
176  {
177  return G4StatAnalysis(lhs) -= rhs;
178  }
179 };
180 
181 #include "G4StatAnalysis.icc"
182 
183 #endif