herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
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
20namespace Herwig {
21
22using namespace ThePEG;
23
32
33public:
34
41 : theMaxWeight(0.), theMinWeight(Constants::MaxDouble),
45 theLastWeight(0.) {}
46
52
53public:
54
58 virtual double chi2() const { return 0.; }
59
63 void reset() {
64 *this = GeneralStatistics();
65 }
66
67public:
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 ?
151 }
152
156 double absWeightVariance() const {
157 return
158 selectedPoints() > 1 ?
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);
195 theAllPoints += 1;
196 }
197
201 virtual void accept() {
203 }
204
208 virtual void reject() {
209 if ( ! isfinite(lastWeight()) ) {
210 theNanPoints -= 1;
211 theAllPoints -= 1;
212 return;
213 }
219 theAllPoints -= 1;
220 }
221
222public:
223
230 void put(PersistentOStream & os) const;
231
239
243 void fromXML(const XML::Element&);
244
249
250private:
251
256
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
308inline PersistentIStream& operator>>(PersistentIStream& is, GeneralStatistics& s) {
309 s.get(is); return is;
310}
311
312}
313
314#endif /* Herwig_GeneralStatistics_H */
General Monte Carlo statistics.
unsigned long theAllPoints
The number of all points.
void get(PersistentIStream &is)
Function used to read in object persistently.
virtual double averageAbsWeightVariance() const
Return the variance of the average absolute weight.
XML::Element toXML() const
Return an XML element for the data of this statistics.
unsigned long selectedPoints() const
Return the number of selected points.
unsigned long acceptedPoints() const
Return the nnumber of accepted points.
double absWeightVariance() const
Return the variance of absolute weights.
void put(PersistentOStream &os) const
Function used to write out object persistently.
virtual double averageWeight() const
Return the average weight.
double theSumAbsWeights
The sum of absolute values of weights.
unsigned long allPoints() const
Return the number of all points.
double theMinWeight
The minimum weight encountered.
unsigned long nanPoints() const
Return the number of points where a nan or inf weight has been encountered.
double theLastWeight
The last weight encountered.
void reset()
Reset these statistics.
unsigned long theAcceptedPoints
The number of accepted points.
unsigned long theNanPoints
The number of points where an nan or inf weight was encountered.
virtual ~GeneralStatistics()
The destructor.
virtual void reject()
Reject an event.
void maxWeight(double w)
Set the maximum absolute weight.
double theMaxWeight
The maximum weight encountered.
virtual double chi2() const
Return the last calculated chi^2.
double sumWeights() const
Return the sum of weights.
virtual void select(double weight, bool doIntegral=true)
Select an event.
double sumAbsWeights() const
Return the sum of absolute weights.
virtual double averageAbsWeight() const
Return the average absolute weight.
double theSumSquaredWeights
The sum of weights squared.
unsigned long theSelectedPoints
The number of selected points.
void minWeight(double w)
Set the minimum absolute weight.
virtual double averageWeightVariance() const
Return the variance of the average weight.
void fromXML(const XML::Element &)
Fill statistics data from an XML element.
double theSumWeights
The sum of weights.
double lastWeight() const
Return the last weight encountered.
double weightVariance() const
Return the variance of weights.
GeneralStatistics()
The default constructor.
double minWeight() const
Return the minimum absolute weight.
double maxWeight() const
Return the maximum absolute weight.
virtual void accept()
Accept an event.
double sumSquaredWeights() const
Return the sum of squared weights.
Element represents a (tree of) XML elements.
Definition: Element.h:56
-*- C++ -*-
constexpr double MaxDouble
PersistentIStream & operator>>(PersistentIStream &is, HandlerGroup< HDLR > &hg)
ostream & operator<<(ostream &, const Collision &)
constexpr auto sqr(const T &x) -> decltype(x *x)