herwig
is hosted by
Hepforge
,
IPPP Durham
Herwig
7.3.0
Sampling
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
31
class
GeneralStatistics
{
32
33
public
:
34
40
GeneralStatistics
()
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
265
double
theSumWeights
;
266
270
double
theSumSquaredWeights
;
271
275
double
theSumAbsWeights
;
276
280
unsigned
long
theSelectedPoints
;
281
285
unsigned
long
theAcceptedPoints
;
286
290
unsigned
long
theNanPoints
;
291
295
unsigned
long
theAllPoints
;
296
300
double
theLastWeight
;
301
302
};
303
304
inline
PersistentOStream
&
operator<<
(
PersistentOStream
& os,
const
GeneralStatistics
& s) {
305
s.put(os);
return
os;
306
}
307
308
inline
PersistentIStream
&
operator>>
(
PersistentIStream
& is, GeneralStatistics& s) {
309
s.get(is);
return
is;
310
}
311
312
}
313
314
#endif
/* Herwig_GeneralStatistics_H */
Herwig::GeneralStatistics
General Monte Carlo statistics.
Definition:
GeneralStatistics.h:31
Herwig::GeneralStatistics::theAllPoints
unsigned long theAllPoints
The number of all points.
Definition:
GeneralStatistics.h:295
Herwig::GeneralStatistics::get
void get(PersistentIStream &is)
Function used to read in object persistently.
Herwig::GeneralStatistics::averageAbsWeightVariance
virtual double averageAbsWeightVariance() const
Return the variance of the average absolute weight.
Definition:
GeneralStatistics.h:172
Herwig::GeneralStatistics::toXML
XML::Element toXML() const
Return an XML element for the data of this statistics.
Herwig::GeneralStatistics::selectedPoints
unsigned long selectedPoints() const
Return the number of selected points.
Definition:
GeneralStatistics.h:112
Herwig::GeneralStatistics::acceptedPoints
unsigned long acceptedPoints() const
Return the nnumber of accepted points.
Definition:
GeneralStatistics.h:117
Herwig::GeneralStatistics::absWeightVariance
double absWeightVariance() const
Return the variance of absolute weights.
Definition:
GeneralStatistics.h:156
Herwig::GeneralStatistics::put
void put(PersistentOStream &os) const
Function used to write out object persistently.
Herwig::GeneralStatistics::averageWeight
virtual double averageWeight() const
Return the average weight.
Definition:
GeneralStatistics.h:133
Herwig::GeneralStatistics::theSumAbsWeights
double theSumAbsWeights
The sum of absolute values of weights.
Definition:
GeneralStatistics.h:275
Herwig::GeneralStatistics::allPoints
unsigned long allPoints() const
Return the number of all points.
Definition:
GeneralStatistics.h:128
Herwig::GeneralStatistics::theMinWeight
double theMinWeight
The minimum weight encountered.
Definition:
GeneralStatistics.h:260
Herwig::GeneralStatistics::nanPoints
unsigned long nanPoints() const
Return the number of points where a nan or inf weight has been encountered.
Definition:
GeneralStatistics.h:123
Herwig::GeneralStatistics::theLastWeight
double theLastWeight
The last weight encountered.
Definition:
GeneralStatistics.h:300
Herwig::GeneralStatistics::reset
void reset()
Reset these statistics.
Definition:
GeneralStatistics.h:63
Herwig::GeneralStatistics::theAcceptedPoints
unsigned long theAcceptedPoints
The number of accepted points.
Definition:
GeneralStatistics.h:285
Herwig::GeneralStatistics::theNanPoints
unsigned long theNanPoints
The number of points where an nan or inf weight was encountered.
Definition:
GeneralStatistics.h:290
Herwig::GeneralStatistics::~GeneralStatistics
virtual ~GeneralStatistics()
The destructor.
Herwig::GeneralStatistics::reject
virtual void reject()
Reject an event.
Definition:
GeneralStatistics.h:208
Herwig::GeneralStatistics::maxWeight
void maxWeight(double w)
Set the maximum absolute weight.
Definition:
GeneralStatistics.h:87
Herwig::GeneralStatistics::theMaxWeight
double theMaxWeight
The maximum weight encountered.
Definition:
GeneralStatistics.h:255
Herwig::GeneralStatistics::chi2
virtual double chi2() const
Return the last calculated chi^2.
Definition:
GeneralStatistics.h:58
Herwig::GeneralStatistics::sumWeights
double sumWeights() const
Return the sum of weights.
Definition:
GeneralStatistics.h:97
Herwig::GeneralStatistics::select
virtual void select(double weight, bool doIntegral=true)
Select an event.
Definition:
GeneralStatistics.h:179
Herwig::GeneralStatistics::sumAbsWeights
double sumAbsWeights() const
Return the sum of absolute weights.
Definition:
GeneralStatistics.h:107
Herwig::GeneralStatistics::averageAbsWeight
virtual double averageAbsWeight() const
Return the average absolute weight.
Definition:
GeneralStatistics.h:140
Herwig::GeneralStatistics::theSumSquaredWeights
double theSumSquaredWeights
The sum of weights squared.
Definition:
GeneralStatistics.h:270
Herwig::GeneralStatistics::theSelectedPoints
unsigned long theSelectedPoints
The number of selected points.
Definition:
GeneralStatistics.h:280
Herwig::GeneralStatistics::minWeight
void minWeight(double w)
Set the minimum absolute weight.
Definition:
GeneralStatistics.h:92
Herwig::GeneralStatistics::averageWeightVariance
virtual double averageWeightVariance() const
Return the variance of the average weight.
Definition:
GeneralStatistics.h:165
Herwig::GeneralStatistics::fromXML
void fromXML(const XML::Element &)
Fill statistics data from an XML element.
Herwig::GeneralStatistics::theSumWeights
double theSumWeights
The sum of weights.
Definition:
GeneralStatistics.h:265
Herwig::GeneralStatistics::lastWeight
double lastWeight() const
Return the last weight encountered.
Definition:
GeneralStatistics.h:72
Herwig::GeneralStatistics::weightVariance
double weightVariance() const
Return the variance of weights.
Definition:
GeneralStatistics.h:147
Herwig::GeneralStatistics::GeneralStatistics
GeneralStatistics()
The default constructor.
Definition:
GeneralStatistics.h:40
Herwig::GeneralStatistics::minWeight
double minWeight() const
Return the minimum absolute weight.
Definition:
GeneralStatistics.h:82
Herwig::GeneralStatistics::maxWeight
double maxWeight() const
Return the maximum absolute weight.
Definition:
GeneralStatistics.h:77
Herwig::GeneralStatistics::accept
virtual void accept()
Accept an event.
Definition:
GeneralStatistics.h:201
Herwig::GeneralStatistics::sumSquaredWeights
double sumSquaredWeights() const
Return the sum of squared weights.
Definition:
GeneralStatistics.h:102
ThePEG::PersistentIStream
ThePEG::PersistentOStream
XML::Element
Element represents a (tree of) XML elements.
Definition:
Element.h:56
Herwig
-*- C++ -*-
Definition:
BasicConsistency.h:17
ThePEG::Constants::MaxDouble
constexpr double MaxDouble
ThePEG
ThePEG::operator>>
PersistentIStream & operator>>(PersistentIStream &is, HandlerGroup< HDLR > &hg)
ThePEG::operator<<
ostream & operator<<(ostream &, const Collision &)
ThePEG::sqr
constexpr auto sqr(const T &x) -> decltype(x *x)
Generated on Thu Jun 20 2024 17:50:53 for Herwig by
1.9.6