herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
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 
13 namespace Statistics {
14 
19  class Counter {
20 
21  public:
22 
26  Counter();
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 
91  double sumOfSquaredWeights() const { return theSumOfSquaredWeights; }
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 
137  XML::Element toXML() const;
138 
139  private:
140 
145 
150 
157 
161  size_t theEventId;
162 
163  };
164 
165 }
166 
167 #endif // MYSTATISTICS_Counter_hpp_included
void fromXML(const XML::Element &)
Fill counter data from an XML element.
Counter & operator-=(const Counter &other)
Subtract a counter from this counter.
void close()
Close the counter and update the overall statistics.
void finalize()
Finalize this counter.
Definition: Counter.h:48
double sumOfWeights() const
Return the sum of weights.
Definition: Counter.h:86
Counter & operator+=(const Counter &other)
Add a counter to this counter.
size_t theEventId
The current event id.
Definition: Counter.h:161
Definition: Bin.h:16
A (weighted) counter.
Definition: Counter.h:19
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.
bool isClosed() const
Return true, if this counter is closed.
Definition: Counter.h:111
void initialize()
Initialize this counter.
Definition: Counter.h:38
bool isOpen() const
Return true, if this counter is open.
Definition: Counter.h:106
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 theSumOfWeights
The sum of weights counted.
Definition: Counter.h:144
Element represents a (tree of) XML elements.
Definition: Element.h:56
void reset()
Reset this counter.
Definition: Counter.h:43
virtual ~Counter()
Destruct a counter.
XML::Element toXML() const
Return an XML element for the data of this counter.
double sumOfSquaredWeights() const
Return the sum of squared weights.
Definition: Counter.h:91
Counter()
Construct a new counter.
size_t eventId() const
Return the current event id.
Definition: Counter.h:101
double theSumOfSquaredWeights
The sum of squared weights counted.
Definition: Counter.h:149
void count(double weight, size_t id)
Book a contribution to the current event.
double average(double nPoints) const
Given a number of sampled points, return the average of this counter.