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5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/HEPNumerics/include/G4StatAnalysis.hh (Version 11.3.0) and /global/HEPNumerics/include/G4StatAnalysis.hh (Version 10.5)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4StatAnalysis                              <<  26 //
                                                   >>  27 //
                                                   >>  28 //
                                                   >>  29 // ----------------------------------------------------------------------
                                                   >>  30 // Class G4StatAnalysis
 27 //                                                 31 //
 28 // Class description:                              32 // Class description:
 29 //                                                 33 //
 30 //  Class for statistical analysis of random v     34 //  Class for statistical analysis of random variable
 31 //                                                 35 //
 32 //  Adapted from:                              <<  36 //  Adapted
 33 //  Lux, I.                                        37 //  Lux, I.
 34 //      Monte Carlo particle transport methods     38 //      Monte Carlo particle transport methods: neutron and photon
 35 //      calculations/authors, Ivan Lux and Las     39 //      calculations/authors, Ivan Lux and Laszlo Koblinger.
 36 //      ISBN 0-8493-6074-9                         40 //      ISBN 0-8493-6074-9
 37 //  1. Neutron transport theory. 2. Photon tra     41 //  1. Neutron transport theory. 2. Photon transport theory.
 38 //  3. Monte Carlo method. I. Koblinger, Laszl     42 //  3. Monte Carlo method. I. Koblinger, Laszlo. II. Title.
 39 //     QC793.5.N4628L88 1990 530.1 '38'20      <<  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 //
 40                                                    49 
 41 // Author: J.Madsen, 25.10.2018                <<  50 #ifndef G4StatAnalysis_hh_
 42 // ------------------------------------------- <<  51 #define G4StatAnalysis_hh_
 43 #ifndef G4StatAnalysis_hh                      <<  52 
 44 #define G4StatAnalysis_hh 1                    <<  53 //----------------------------------------------------------------------------//
 45                                                    54 
 46 #include <cmath>                               << 
 47 #include <fstream>                             << 
 48 #include <iomanip>                             << 
 49 #include <iostream>                                55 #include <iostream>
                                                   >>  56 #include <iomanip>
 50 #include <limits>                                  57 #include <limits>
 51 #include <optional>                            <<  58 #include <fstream>
                                                   >>  59 #include <cmath>
 52                                                    60 
 53 #include "globals.hh"                              61 #include "globals.hh"
 54 #include "tls.hh"                                  62 #include "tls.hh"
 55                                                    63 
 56 #include "G4Allocator.hh"                      << 
 57 #include "G4Timer.hh"                          << 
 58 #include "G4Types.hh"                              64 #include "G4Types.hh"
                                                   >>  65 #include "G4Timer.hh"
 59 #include "G4ios.hh"                                66 #include "G4ios.hh"
                                                   >>  67 #include "G4Allocator.hh"
 60                                                    68 
 61 class G4StatAnalysis                               69 class G4StatAnalysis
 62 {                                                  70 {
 63  public:                                       <<  71 public:
 64   inline G4StatAnalysis();                     <<  72     inline G4StatAnalysis();
 65   inline ~G4StatAnalysis() {}                  <<  73     inline ~G4StatAnalysis() { }
 66                                                <<  74 
 67   // Accumulated values                        <<  75 public:
 68   inline G4double GetMean() const;             <<  76     // Accumulated values
 69   inline const G4double& GetSum() const;       <<  77     inline G4double         GetMean() const;
 70   inline const G4double& GetSumSquared() const <<  78     inline const G4double&  GetSum() const;
 71   inline const G4double& GetSum1() const;      <<  79     inline const G4double&  GetSumSquared() const;
 72   inline const G4double& GetSum2() const;      <<  80     inline const G4double&  GetSum1() const;
 73   inline const G4int& GetHits() const;         <<  81     inline const G4double&  GetSum2() const;
 74   inline G4int GetNumNonZero() const;          <<  82     inline const G4int&     GetHits() const;
 75   inline G4int GetNumZero() const;             <<  83     inline G4int            GetNumNonZero() const;
 76                                                <<  84     inline G4int            GetNumZero() const;
 77   // Some control over accumulated variables   <<  85 
 78   inline void SetSum(const G4double& val);     <<  86     // Some control over accumulated variables
 79   inline void SetSumSquared(const G4double& va <<  87     inline void SetSum(const G4double& val);
 80   inline void SetSum1(const G4double& val);    <<  88     inline void SetSumSquared(const G4double& val);
 81   inline void SetSum2(const G4double& val);    <<  89     inline void SetSum1(const G4double& val);
 82   inline void SetHits(const G4int& val);       <<  90     inline void SetSum2(const G4double& val);
 83   inline void SetZero(const G4int& val);       <<  91     inline void SetHits(const G4int& val);
 84                                                <<  92     inline void SetZero(const G4int& val);
 85   // Computed values                           <<  93 
 86   inline G4double GetFOM() const;              <<  94     // Computed values
 87   inline G4double GetRelativeError() const;    <<  95     inline G4double GetFOM() const;
 88   inline G4double GetStdDev() const;           <<  96     inline G4double GetRelativeError() const;
 89   inline G4double GetVariance() const;         <<  97     inline G4double GetStdDev() const;
 90   inline G4double GetCoeffVariation() const;   <<  98     inline G4double GetVariance() const;
 91   inline G4double GetEfficiency() const;       <<  99     inline G4double GetCoeffVariation() const;
 92   inline G4double GetR2Int() const;            << 100     inline G4double GetEfficiency() const;
 93   inline G4double GetR2Eff() const;            << 101     inline G4double GetR2Int() const;
 94                                                << 102     inline G4double GetR2Eff() const;
 95   // Conversion                                << 103 
 96   inline operator G4double() const;            << 104     // Conversion
 97                                                << 105     inline operator G4double() const;
 98   // Modifications                             << 106 
 99   inline void Reset();                         << 107     // Modifications
100   inline void Add(const G4double& _val, const  << 108     inline void Reset();
101   inline void Rescale(const G4double& factor); << 109     inline void Add(const G4double& _val, const G4double& _weight = 1.0);
102                                                << 110     inline void Rescale(const G4double& factor);
103   // Output                                    << 111 
104   inline void PrintInfo(std::ostream& os, cons << 112     // Output
105                                                << 113     inline void PrintInfo(std::ostream& os, const std::string& = "") const;
106   // Operators                                 << 114 
107   inline G4StatAnalysis& operator+=(const G4do << 115     // Operators
108   inline G4StatAnalysis& operator/=(const G4do << 116     inline G4StatAnalysis& operator+=(const G4double& _val);
109   inline G4StatAnalysis& operator+=(const G4St << 117     inline G4StatAnalysis& operator/=(const G4double& _val);
110   inline G4StatAnalysis& operator-=(const G4St << 118     inline G4StatAnalysis& operator+=(const G4StatAnalysis&);
111                                                << 119     inline G4StatAnalysis& operator-=(const G4StatAnalysis&);
112   // Allocators                                << 120 
113   inline void* operator new(std::size_t);      << 121     // Allocators
114   inline void operator delete(void*);          << 122     inline void* operator new(size_t);
115                                                << 123     inline void  operator delete(void*);
116   // Timing (member functions)                 << 124 
117   inline G4double GetCpuTime() const;          << 125     // Timing (member functions)
118   // Timing (static functions)                 << 126     inline G4double GetCpuTime() const;
119   static tms* GetCpuClock()                    << 127     // Timing (static functions)
120   {                                            << 128     static tms*& GetCpuClock()
121     G4ThreadLocalStatic std::optional<tms> _in << 129     {
122     if(_instance == std::nullopt)              << 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
                                                   >> 152     G4double    fSum1;
                                                   >> 153     // summation from each history^2
                                                   >> 154     G4double    fSum2;
                                                   >> 155     // number of scoring histories
                                                   >> 156     G4int       fHits;
                                                   >> 157     // number of histories that were not greater than 0.0
                                                   >> 158     G4int       fZero;
                                                   >> 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)
123     {                                             176     {
124       _instance = tms();                       << 177         return G4StatAnalysis(lhs) -= rhs;
125       times(&_instance.value());               << 
126     }                                             178     }
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 };                                                179 };
166                                                   180 
167 #include "G4StatAnalysis.icc"                     181 #include "G4StatAnalysis.icc"
168                                                   182 
169 #endif                                            183 #endif
170                                                   184