herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
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
19namespace Statistics {
20
25 class Histogram {
26
27 public:
28
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
101
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
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
208
213
217 std::map<double,int> binMap;
218
219 };
220
221}
222
223#endif // MYSTATISTICS_Histogram_hpp_included
A bin in a (one dimensional) histogram.
Definition: Bin.h:23
A pointlike or boxlike eventContribution; serves to define the EventContribution concept.
A (one dimensional) histogram.
std::string theName
The id of the histogram.
Bin theUnderflow
The underflow bin.
void finalize()
Finalize this histogram.
Histogram & operator+=(const Histogram &other)
Add a histogram to this histogram.
bool isPeriodic() const
Return true, if the quantity considered is periodic.
bool count(EventContribution event, size_t id)
Book a contribution to the current event.
bool theNoUnderflow
True, if there is no underflow.
const std::vector< Bin > & bins() const
Return the bins.
const Bin & underflow() const
Return the underflow bin.
std::vector< Bin > theBins
The bins.
XML::Element toXML() const
Return an XML element for the data of this histogram.
bool noOverflow() const
True, if there is no overflow.
Histogram & operator-=(const Histogram &other)
Subtract a histogram from this histogram.
bool noUnderflow() const
True, if there is no underflow.
Histogram(const std::string &newName, const std::vector< double > &newBoundaries, bool newNoUnderflow=false, bool newNoOverflow=false)
Constructor giving a name and bin boundaries; bin boundaries are subsequent boundaries.
bool theNoOverflow
True, if there is no overflow.
std::pair< double, double > thePeriodicity
The periodicity of the quantity considered.
std::map< double, int > binMap
Map bin upper boundaries to bins.
bool theIsPeriodic
True, if the quantity considered is periodic.
Bin & binByIndex(int)
Return a bin by index.
void fromXML(const XML::Element &)
Fill histogram data from an XML element.
static std::vector< double > regularBinEdges(double lower, double upper, size_t nBins)
Create equally spaced bin edges.
Histogram()
Default constructor.
const Bin & overflow() const
Return the overflow bin.
static std::vector< double > logBinEdges(double lower, double upper, size_t nBins)
Create logarithmicaly spaced bin edges.
bool isCompatible(const Histogram &other) const
Return true, if this histogram is compatible with another one.
void initialize()
Initialize this histogram.
const std::pair< double, double > & periodicity() const
Return the periodicity interval, if appropriate.
void reset()
Reset this histogram.
const std::string & name() const
Return the id of the histogram.
Histogram(const std::string &newName, const std::vector< double > &newBoundaries, const std::pair< double, double > &newPeriodicity)
Constructor giving a name, bin boundaries and periodicity interval; bin boundaries are subsequent bou...
Bin theOverflow
The overflow bin.
void fillBinMap()
Fill the bin map.
virtual ~Histogram()
Destructor.
Element represents a (tree of) XML elements.
Definition: Element.h:56