Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // G4StatAnalysis 27 // 28 // Class description: 29 // 30 // Class for statistical analysis of random v 31 // 32 // Adapted from: 33 // Lux, I. 34 // Monte Carlo particle transport methods 35 // calculations/authors, Ivan Lux and Las 36 // ISBN 0-8493-6074-9 37 // 1. Neutron transport theory. 2. Photon tra 38 // 3. Monte Carlo method. I. Koblinger, Laszl 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 #include <optional> 52 53 #include "globals.hh" 54 #include "tls.hh" 55 56 #include "G4Allocator.hh" 57 #include "G4Timer.hh" 58 #include "G4Types.hh" 59 #include "G4ios.hh" 60 61 class G4StatAnalysis 62 { 63 public: 64 inline G4StatAnalysis(); 65 inline ~G4StatAnalysis() {} 66 67 // Accumulated values 68 inline G4double GetMean() const; 69 inline const G4double& GetSum() const; 70 inline const G4double& GetSumSquared() const 71 inline const G4double& GetSum1() const; 72 inline const G4double& GetSum2() const; 73 inline const G4int& GetHits() const; 74 inline G4int GetNumNonZero() const; 75 inline G4int GetNumZero() const; 76 77 // Some control over accumulated variables 78 inline void SetSum(const G4double& val); 79 inline void SetSumSquared(const G4double& va 80 inline void SetSum1(const G4double& val); 81 inline void SetSum2(const G4double& val); 82 inline void SetHits(const G4int& val); 83 inline void SetZero(const G4int& val); 84 85 // Computed values 86 inline G4double GetFOM() const; 87 inline G4double GetRelativeError() const; 88 inline G4double GetStdDev() const; 89 inline G4double GetVariance() const; 90 inline G4double GetCoeffVariation() const; 91 inline G4double GetEfficiency() const; 92 inline G4double GetR2Int() const; 93 inline G4double GetR2Eff() const; 94 95 // Conversion 96 inline operator G4double() const; 97 98 // Modifications 99 inline void Reset(); 100 inline void Add(const G4double& _val, const 101 inline void Rescale(const G4double& factor); 102 103 // Output 104 inline void PrintInfo(std::ostream& os, cons 105 106 // Operators 107 inline G4StatAnalysis& operator+=(const G4do 108 inline G4StatAnalysis& operator/=(const G4do 109 inline G4StatAnalysis& operator+=(const G4St 110 inline G4StatAnalysis& operator-=(const G4St 111 112 // Allocators 113 inline void* operator new(std::size_t); 114 inline void operator delete(void*); 115 116 // Timing (member functions) 117 inline G4double GetCpuTime() const; 118 // Timing (static functions) 119 static tms* GetCpuClock() 120 { 121 G4ThreadLocalStatic std::optional<tms> _in 122 if(_instance == std::nullopt) 123 { 124 _instance = tms(); 125 times(&_instance.value()); 126 } 127 return &_instance.value(); 128 } 129 // Note: this above implementation was imple 130 // conserve memory by eliminated every insta 131 // timing variables. The ResetCpuClock funct 132 // beginning of the run (G4Run constructor) 133 // FOM is not skewed by multiple runs -- it 134 // manually invoke in some situations 135 static void ResetCpuClock() 136 { 137 tms* _clock = GetCpuClock(); 138 times(_clock); 139 } 140 141 // friend operator for output 142 friend std::ostream& operator<<(std::ostream 143 { 144 obj.PrintInfo(os); 145 return os; 146 } 147 // friend operator for addition 148 friend const G4StatAnalysis operator+(const 149 const 150 { 151 return G4StatAnalysis(lhs) += rhs; 152 } 153 // friend operator for subtraction 154 friend const G4StatAnalysis operator-(const 155 const 156 { 157 return G4StatAnalysis(lhs) -= rhs; 158 } 159 160 private: 161 G4double fSum1 = 0.0; // summation of each 162 G4double fSum2 = 0.0; // summation from eac 163 G4int fHits = 0; // number of scoring 164 G4int fZero = 0; // number of historie 165 }; 166 167 #include "G4StatAnalysis.icc" 168 169 #endif 170