herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
Counter.h
1// -*- C++ -*-
2//
3// Counter.hpp is a part of myStatistics
4// Copyright (C) 2012-2019 Simon Platzer, The Herwig Collaboration
5//
6// myStatistics is licenced under version 3 of the GPL, see COPYING for details.
7//
8#ifndef MYSTATISTICS_Counter_hpp_included
9#define MYSTATISTICS_Counter_hpp_included
10
11#include "Herwig/Utilities/XML/Element.h"
12
13namespace Statistics {
14
19 class Counter {
20
21 public:
22
27
31 virtual ~Counter();
32
33 public:
34
38 void initialize() {}
39
43 void reset() { *this = Counter(); }
44
48 void finalize() { if ( isOpen() ) close(); }
49
50 public:
51
55 void open(size_t id);
56
60 void close();
61
67 void count(double weight, size_t id);
68
69 public:
70
74 Counter& operator+=(const Counter& other);
75
79 Counter& operator-=(const Counter& other);
80
81 public:
82
86 double sumOfWeights() const { return theSumOfWeights; }
87
92
96 double sumOfEventWeights() const { return theSumOfEventWeights; }
97
101 size_t eventId() const { return theEventId; }
102
106 bool isOpen() const { return eventId() != 0; }
107
111 bool isClosed() const { return !isOpen(); }
112
113 public:
114
119 double average(double nPoints) const;
120
125 double varianceOfAverage(double nPoints) const;
126
127 public:
128
132 void fromXML(const XML::Element&);
133
138
139 private:
140
145
150
157
162
163 };
164
165}
166
167#endif // MYSTATISTICS_Counter_hpp_included
A (weighted) counter.
Definition: Counter.h:19
Counter()
Construct a new counter.
double theSumOfSquaredWeights
The sum of squared weights counted.
Definition: Counter.h:149
double sumOfSquaredWeights() const
Return the sum of squared weights.
Definition: Counter.h:91
double varianceOfAverage(double nPoints) const
Given a number of sampled points, return the variance of the average of this counter.
double theSumOfEventWeights
The sum of weights counted before the next event occured; within one event, all weights are considere...
Definition: Counter.h:156
double average(double nPoints) const
Given a number of sampled points, return the average of this counter.
double sumOfWeights() const
Return the sum of weights.
Definition: Counter.h:86
bool isClosed() const
Return true, if this counter is closed.
Definition: Counter.h:111
XML::Element toXML() const
Return an XML element for the data of this counter.
Counter & operator+=(const Counter &other)
Add a counter to this counter.
void finalize()
Finalize this counter.
Definition: Counter.h:48
size_t theEventId
The current event id.
Definition: Counter.h:161
void initialize()
Initialize this counter.
Definition: Counter.h:38
void reset()
Reset this counter.
Definition: Counter.h:43
double sumOfEventWeights() const
Return the sum of weights before the next event occured.
Definition: Counter.h:96
void open(size_t id)
Open the counter for the next event of the given id.
void close()
Close the counter and update the overall statistics.
size_t eventId() const
Return the current event id.
Definition: Counter.h:101
Counter & operator-=(const Counter &other)
Subtract a counter from this counter.
double theSumOfWeights
The sum of weights counted.
Definition: Counter.h:144
virtual ~Counter()
Destruct a counter.
bool isOpen() const
Return true, if this counter is open.
Definition: Counter.h:106
void fromXML(const XML::Element &)
Fill counter data from an XML element.
void count(double weight, size_t id)
Book a contribution to the current event.
Element represents a (tree of) XML elements.
Definition: Element.h:56