herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
GeneralStatistics.h
1 // -*- C++ -*-
2 //
3 // GeneralStatictis.h is a part of Herwig - A multi-purpose Monte Carlo event generator
4 // Copyright (C) 2002-2019 The Herwig Collaboration
5 //
6 // Herwig is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef Herwig_GeneralStatistics_H
10 #define Herwig_GeneralStatistics_H
11 //
12 // This is the declaration of the GeneralStatistics class.
13 //
14 
15 #include "ThePEG/Persistency/PersistentOStream.h"
16 #include "ThePEG/Persistency/PersistentIStream.h"
17 
18 #include "Herwig/Utilities/XML/Element.h"
19 
20 namespace Herwig {
21 
22 using namespace ThePEG;
23 
32 
33 public:
34 
41  : theMaxWeight(0.), theMinWeight(Constants::MaxDouble),
42  theSumWeights(0.), theSumSquaredWeights(0.), theSumAbsWeights(0.),
43  theSelectedPoints(0), theAcceptedPoints(0),
44  theNanPoints(0), theAllPoints(0),
45  theLastWeight(0.) {}
46 
50  virtual ~GeneralStatistics();
52 
53 public:
54 
58  virtual double chi2() const { return 0.; }
59 
63  void reset() {
64  *this = GeneralStatistics();
65  }
66 
67 public:
68 
72  double lastWeight() const { return theLastWeight; }
73 
77  double maxWeight() const { return theMaxWeight; }
78 
82  double minWeight() const { return theMinWeight; }
83 
87  void maxWeight(double w) { theMaxWeight = w; }
88 
92  void minWeight(double w) { theMinWeight = w; }
93 
97  double sumWeights() const { return theSumWeights; }
98 
102  double sumSquaredWeights() const { return theSumSquaredWeights; }
103 
107  double sumAbsWeights() const { return theSumAbsWeights; }
108 
112  unsigned long selectedPoints() const { return theSelectedPoints; }
113 
117  unsigned long acceptedPoints() const { return theAcceptedPoints; }
118 
123  unsigned long nanPoints() const { return theNanPoints; }
124 
128  unsigned long allPoints() const { return theAllPoints; }
129 
133  virtual double averageWeight() const {
134  return selectedPoints() > 0 ? sumWeights()/selectedPoints() : 0.;
135  }
136 
140  virtual double averageAbsWeight() const {
141  return selectedPoints() > 0 ? sumAbsWeights()/selectedPoints() : 0.;
142  }
143 
147  double weightVariance() const {
148  return
149  selectedPoints() > 1 ?
150  abs(sumSquaredWeights() - sqr(sumWeights())/selectedPoints())/(selectedPoints()-1) : 0.;
151  }
152 
156  double absWeightVariance() const {
157  return
158  selectedPoints() > 1 ?
159  abs(sumSquaredWeights() - sqr(sumAbsWeights())/selectedPoints())/(selectedPoints()-1) : 0.;
160  }
161 
165  virtual double averageWeightVariance() const {
166  return selectedPoints() > 1 ? weightVariance()/selectedPoints() : 0.;
167  }
168 
172  virtual double averageAbsWeightVariance() const {
173  return selectedPoints() > 1 ? absWeightVariance()/selectedPoints() : 0;
174  }
175 
179  virtual void select(double weight, bool doIntegral = true) {
180  if ( ! isfinite(weight) ) {
181  theLastWeight = weight;
182  theNanPoints += 1;
183  theAllPoints += 1;
184  return;
185  }
186  theLastWeight = weight;
187  theMaxWeight = max(theMaxWeight,abs(weight));
188  theMinWeight = min(theMinWeight,abs(weight));
189  if ( !doIntegral )
190  return;
191  theSumWeights += weight;
192  theSumSquaredWeights += sqr(weight);
193  theSumAbsWeights += abs(weight);
194  theSelectedPoints += 1;
195  theAllPoints += 1;
196  }
197 
201  virtual void accept() {
202  theAcceptedPoints += 1;
203  }
204 
208  virtual void reject() {
209  if ( ! isfinite(lastWeight()) ) {
210  theNanPoints -= 1;
211  theAllPoints -= 1;
212  return;
213  }
214  theSumWeights -= lastWeight();
215  theSumSquaredWeights -= sqr(lastWeight());
216  theSumAbsWeights -= abs(lastWeight());
217  theSelectedPoints -= 1;
218  theAcceptedPoints -= 1;
219  theAllPoints -= 1;
220  }
221 
222 public:
223 
230  void put(PersistentOStream & os) const;
231 
237  void get(PersistentIStream & is);
239 
243  void fromXML(const XML::Element&);
244 
248  XML::Element toXML() const;
249 
250 private:
251 
255  double theMaxWeight;
256 
260  double theMinWeight;
261 
266 
271 
276 
280  unsigned long theSelectedPoints;
281 
285  unsigned long theAcceptedPoints;
286 
290  unsigned long theNanPoints;
291 
295  unsigned long theAllPoints;
296 
301 
302 };
303 
305  s.put(os); return os;
306 }
307 
309  s.get(is); return is;
310 }
311 
312 }
313 
314 #endif /* Herwig_GeneralStatistics_H */
unsigned long theNanPoints
The number of points where an nan or inf weight was encountered.
virtual void select(double weight, bool doIntegral=true)
Select an event.
double theMinWeight
The minimum weight encountered.
virtual double averageWeightVariance() const
Return the variance of the average weight.
virtual double averageAbsWeight() const
Return the average absolute weight.
void put(PersistentOStream &os) const
Function used to write out object persistently.
virtual double averageAbsWeightVariance() const
Return the variance of the average absolute weight.
double theSumSquaredWeights
The sum of weights squared.
unsigned long acceptedPoints() const
Return the nnumber of accepted points.
GeneralStatistics()
The default constructor.
void minWeight(double w)
Set the minimum absolute weight.
void get(PersistentIStream &is)
Function used to read in object persistently.
constexpr auto sqr(const T &x) -> decltype(x *x)
General Monte Carlo statistics.
virtual double chi2() const
Return the last calculated chi^2.
void maxWeight(double w)
Set the maximum absolute weight.
double theSumWeights
The sum of weights.
void reset()
Reset these statistics.
double theSumAbsWeights
The sum of absolute values of weights.
ostream & operator<<(ostream &, const DecayIntegrator &)
Output information on the DecayIntegrator for debugging purposes.
virtual void accept()
Accept an event.
double minWeight() const
Return the minimum absolute weight.
unsigned long theSelectedPoints
The number of selected points.
unsigned long allPoints() const
Return the number of all points.
PersistentIStream & operator>>(PersistentIStream &is, map< ShowerInteraction, T, Cmp, A > &m)
Read a map with ShowerInteraction as the key.
constexpr double MaxDouble
double lastWeight() const
Return the last weight encountered.
double maxWeight() const
Return the maximum absolute weight.
unsigned long selectedPoints() const
Return the number of selected points.
double sumAbsWeights() const
Return the sum of absolute weights.
unsigned long nanPoints() const
Return the number of points where a nan or inf weight has been encountered.
double weightVariance() const
Return the variance of weights.
double absWeightVariance() const
Return the variance of absolute weights.
Element represents a (tree of) XML elements.
Definition: Element.h:56
virtual void reject()
Reject an event.
double theLastWeight
The last weight encountered.
unsigned long theAcceptedPoints
The number of accepted points.
unsigned long theAllPoints
The number of all points.
-*- C++ -*-
double sumWeights() const
Return the sum of weights.
double sumSquaredWeights() const
Return the sum of squared weights.
double theMaxWeight
The maximum weight encountered.
virtual double averageWeight() const
Return the average weight.