herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
Statistics/Histogram.h
1 // -*- C++ -*-
2 //
3 // Histogram.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_Histogram_hpp_included
9 #define MYSTATISTICS_Histogram_hpp_included
10 
11 #include <map>
12 #include <vector>
13 #include <string>
14 #include <iostream>
15 
16 #include "EventContribution.h"
17 #include "Bin.h"
18 
19 namespace Statistics {
20 
25  class Histogram {
26 
27  public:
28 
32  Histogram();
33 
37  virtual ~Histogram();
38 
43  Histogram(const std::string& newName,
44  const std::vector<double>& newBoundaries,
45  bool newNoUnderflow = false,
46  bool newNoOverflow = false);
47 
52  Histogram(const std::string& newName,
53  const std::vector<double>& newBoundaries,
54  const std::pair<double,double>& newPeriodicity);
55 
59  static std::vector<double> regularBinEdges(double lower, double upper, size_t nBins);
60 
64  static std::vector<double> logBinEdges(double lower, double upper, size_t nBins);
65 
66  public:
67 
71  void initialize();
72 
76  void reset();
77 
81  void finalize();
82 
83  public:
84 
88  bool count(EventContribution event, size_t id);
89 
90  public:
91 
95  bool isCompatible(const Histogram& other) const;
96 
100  Histogram& operator+=(const Histogram& other);
101 
105  Histogram& operator-=(const Histogram& other);
106 
107  public:
108 
112  const std::string& name() const { return theName; }
113 
117  const Bin& underflow() const { return theUnderflow; }
118 
122  const std::vector<Bin>& bins() const { return theBins; }
123 
127  const Bin& overflow() const { return theOverflow; }
128 
132  bool noUnderflow() const { return theNoUnderflow; }
133 
137  bool noOverflow() const { return theNoOverflow; }
138 
139 
143  bool isPeriodic() const { return theIsPeriodic; }
144 
148  const std::pair<double,double>& periodicity() const { return thePeriodicity; }
149 
150  public:
151 
155  void fromXML(const XML::Element&);
156 
160  XML::Element toXML() const;
161 
162  private:
163 
167  std::string theName;
168 
173 
177  std::vector<Bin> theBins;
178 
183 
188 
193 
198 
202  std::pair<double,double> thePeriodicity;
203 
207  void fillBinMap();
208 
212  Bin& binByIndex(int);
213 
217  std::map<double,int> binMap;
218 
219  };
220 
221 }
222 
223 #endif // MYSTATISTICS_Histogram_hpp_included
A (one dimensional) histogram.
void reset()
Reset this histogram.
Histogram & operator+=(const Histogram &other)
Add a histogram to this histogram.
bool isPeriodic() const
Return true, if the quantity considered is periodic.
Bin & binByIndex(int)
Return a bin by index.
A bin in a (one dimensional) histogram.
Definition: Bin.h:22
bool noUnderflow() const
True, if there is no underflow.
void finalize()
Finalize this histogram.
virtual ~Histogram()
Destructor.
void initialize()
Initialize this histogram.
Definition: Bin.h:16
Histogram & operator-=(const Histogram &other)
Subtract a histogram from this histogram.
bool theNoOverflow
True, if there is no overflow.
Bin theUnderflow
The underflow bin.
bool isCompatible(const Histogram &other) const
Return true, if this histogram is compatible with another one.
Histogram()
Default constructor.
void fromXML(const XML::Element &)
Fill histogram data from an XML element.
const std::vector< Bin > & bins() const
Return the bins.
static std::vector< double > logBinEdges(double lower, double upper, size_t nBins)
Create logarithmicaly spaced bin edges.
std::string theName
The id of the histogram.
XML::Element toXML() const
Return an XML element for the data of this histogram.
void fillBinMap()
Fill the bin map.
static std::vector< double > regularBinEdges(double lower, double upper, size_t nBins)
Create equally spaced bin edges.
bool theIsPeriodic
True, if the quantity considered is periodic.
std::vector< Bin > theBins
The bins.
const std::pair< double, double > & periodicity() const
Return the periodicity interval, if appropriate.
std::pair< double, double > thePeriodicity
The periodicity of the quantity considered.
A pointlike or boxlike eventContribution; serves to define the EventContribution concept.
Element represents a (tree of) XML elements.
Definition: Element.h:56
const Bin & overflow() const
Return the overflow bin.
Bin theOverflow
The overflow bin.
const std::string & name() const
Return the id of the histogram.
bool count(EventContribution event, size_t id)
Book a contribution to the current event.
bool theNoUnderflow
True, if there is no underflow.
const Bin & underflow() const
Return the underflow bin.
bool noOverflow() const
True, if there is no overflow.
std::map< double, int > binMap
Map bin upper boundaries to bins.