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