herwig
is hosted by
Hepforge
,
IPPP Durham
Herwig
7.3.0
Utilities
Histogram.h
1
// -*- C++ -*-
2
//
3
// Histogram.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_Histogram_H
10
#define HERWIG_Histogram_H
11
//
12
// This is the declaration of the Histogram class.
13
//
14
#include "Histogram.fh"
15
#include "ThePEG/Interface/Interfaced.h"
16
#include "Statistic.h"
17
#include <string>
18
19
namespace
Herwig
{
20
21
using namespace
ThePEG
;
22
27
namespace
HistogramOptions {
28
const
unsigned
int
None
= 0;
29
const
unsigned
int
Frame
= 1;
30
const
unsigned
int
Errorbars
= 1 << 1;
31
const
unsigned
int
Xlog
= 1 << 2;
32
const
unsigned
int
Ylog
= 1 << 3;
33
const
unsigned
int
Smooth
= 1 << 4;
34
const
unsigned
int
Rawcount
= 1 << 5;
35
}
36
43
class
Histogram
:
public
Interfaced
{
44
45
public
:
46
55
Histogram
(
double
lower=0.,
double
upper=0.,
unsigned
int
nbin=0)
56
:
_globalStats
(),
_havedata
(false),
_bins
(nbin+2),
_prefactor
(1.),
_total
(0.) {
57
if
(upper<lower) swap(upper,lower);
58
_bins
[0].limit=-1.e100;
59
double
limit(lower);
60
double
width((upper-lower)/nbin);
61
for
(
unsigned
int
ix=1; ix <= nbin; ++ix) {
62
_bins
[ix].limit=limit;
63
limit += width;
64
}
65
_bins
.back().limit=limit;
66
}
67
72
Histogram
(vector<double> limits)
73
:
_globalStats
(),
_havedata
(false),
_bins
(limits.size()+1),
_prefactor
(1.),
_total
(0.) {
74
_bins
[0].limit=-1.e100;
75
for
(
size_t
i=1; i<=limits.size(); ++i)
76
_bins
[i].limit=limits[i-1];
77
}
78
85
Histogram
(vector<double> limits, vector<double> data, vector<double> dataerror)
86
:
_globalStats
(),
_havedata
(true),
_bins
(limits.size()+1),
_prefactor
(1.),
_total
(0.) {
87
_bins
[0].limit=-1.e100;
88
for
(
size_t
i=1; i<=limits.size(); ++i)
89
_bins
[i].limit=limits[i-1];
90
91
// no data goes into _bins[0] or _bins.back()!
92
for
(
size_t
i=1; i<=min(limits.size()-1,data.size()); ++i)
93
_bins
[i].data=data[i-1];
94
95
for
(
size_t
i=1; i<=min(limits.size()-1,dataerror.size()); ++i)
96
_bins
[i].dataerror=dataerror[i-1];
97
}
98
100
101
public
:
102
106
void
operator +=
(
double
input) {
107
addWeighted
(input,1.0);
108
}
109
113
void
addWeighted
(
double
input,
double
weight) {
114
if
(std::isnan(input))
return
;
115
unsigned
int
ibin;
116
for
(ibin=1; ibin<
_bins
.size(); ++ibin) {
117
if
(input<
_bins
[ibin].limit)
118
break
;
119
}
120
_bins
[ibin-1].contents += weight;
121
_bins
[ibin-1].contentsSq +=
sqr
(weight);
122
_globalStats
+= weight * input;
123
_total
+= weight;
124
}
125
129
unsigned
int
numberOfBins
()
const
{
130
return
_bins
.size()-2;
131
}
132
133
137
double
prefactor
()
const
{
138
return
_prefactor
;
139
}
140
144
void
prefactor
(
double
in ) {
145
_prefactor
=in;
146
}
147
151
const
Statistic
&
globalStatistics
()
const
{
152
return
_globalStats
;
153
}
154
158
void
normaliseToData
();
159
163
void
normaliseToCrossSection
();
164
171
void
chiSquared
(
double
& chisq,
172
unsigned
int
& ndegrees,
double
minfrac=0.)
const
;
173
188
void
rivetOutput
(ostream & out,
189
string
histogramname =
string
(
"default"
),
190
string
analysisname =
string
(
"default"
),
191
string
title =
string
(),
192
string
xlabel =
string
(),
193
string
ylabel =
string
(),
194
bool
rawcount =
false
,
195
double
multiplicator = 1.0)
const
;
196
210
void
topdrawOutput
(ostream & out,
211
unsigned
int
flags = 0,
212
string
colour =
string
(
"BLACK"
),
213
string
title =
string
(),
214
string
titlecase =
string
(),
215
string
left
=
string
(),
216
string
leftcase =
string
(),
217
string
bottom =
string
(),
218
string
bottomcase =
string
()
219
)
const
;
220
221
void
topdrawMCatNLO(ostream & out,
222
unsigned
int
flags =0 ,
223
string
colour =
string
(
"BLACK"
),
224
string
title =
string
()
225
)
const
;
226
242
void
topdrawOutputAverage
(ostream & out,
243
bool
frame,
244
bool
errorbars,
245
bool
xlog,
bool
ylog,
246
string
colour=
string
(
"BLACK"
),
247
string
title=
string
(),
248
string
titlecase =
string
(),
249
string
left
=
string
(),
250
string
leftcase =
string
(),
251
string
bottom=
string
(),
252
string
bottomcase =
string
())
const
;
253
259
unsigned
int
visibleEntries
()
const
;
260
264
double
dataNorm
()
const
;
265
269
void
simpleOutput
(ostream & out,
bool
errorbars,
bool
normdata=
false
);
270
274
vector<double>
dumpBins
()
const
;
275
279
Histogram
ratioWith
(
const
Histogram
& h2)
const
;
280
281
289
static
290
vector<double>
LogBins
(
double
xmin,
unsigned
nbins,
double
base = 10.0);
291
292
293
public
:
294
301
static
void
Init
();
302
303
protected
:
304
311
virtual
IBPtr
clone
()
const
;
312
317
virtual
IBPtr
fullclone
()
const
;
319
320
private
:
321
326
Histogram
&
operator=
(
const
Histogram
&) =
delete
;
327
328
private
:
329
333
Statistic
_globalStats
;
334
338
bool
_havedata
;
339
343
struct
Bin
{
347
Bin
() :
contents
(0.0),
contentsSq
(0.0),
348
limit
(0.0),
data
(0.0),
dataerror
(0.0),
points
(0) {}
352
double
contents
;
353
357
double
contentsSq
;
358
362
double
limit
;
363
367
double
data
;
368
372
double
dataerror
;
373
377
long
points
;
378
};
379
383
vector<Bin>
_bins
;
384
388
double
_prefactor
;
389
393
double
_total
;
394
395
396
public
:
397
401
vector<Bin>
bins
()
const
{
return
_bins
; }
402
403
};
404
405
}
406
407
#endif
/* HERWIG_Histogram_H */
Herwig::Histogram
The Histogram class is a simple histogram for the Analysis handlers.
Definition:
Histogram.h:43
Herwig::Histogram::globalStatistics
const Statistic & globalStatistics() const
Access to the statistics on the total entry of the histogram.
Definition:
Histogram.h:151
Herwig::Histogram::operator=
Histogram & operator=(const Histogram &)=delete
The assignment operator is private and must never be called.
Herwig::Histogram::bins
vector< Bin > bins() const
The vector of bins.
Definition:
Histogram.h:401
Herwig::Histogram::numberOfBins
unsigned int numberOfBins() const
Number of bins (not counting the overflow)
Definition:
Histogram.h:129
Herwig::Histogram::simpleOutput
void simpleOutput(ostream &out, bool errorbars, bool normdata=false)
Output into a simple ascii file, easily readable by gnuplot.
Herwig::Histogram::visibleEntries
unsigned int visibleEntries() const
get the number of visible entries (all entries without those in the under- and overflow bins) in the ...
Herwig::Histogram::_havedata
bool _havedata
Set to true if there is experimental data available.
Definition:
Histogram.h:338
Herwig::Histogram::prefactor
void prefactor(double in)
Set the prefactor.
Definition:
Histogram.h:144
Herwig::Histogram::clone
virtual IBPtr clone() const
Make a simple clone of this object.
Herwig::Histogram::dataNorm
double dataNorm() const
Compute the normalisation of the data.
Herwig::Histogram::_total
double _total
Total entry.
Definition:
Histogram.h:393
Herwig::Histogram::normaliseToCrossSection
void normaliseToCrossSection()
Normalise the distributions to the total cross section.
Herwig::Histogram::dumpBins
vector< double > dumpBins() const
Dump bin data into a vector.
Herwig::Histogram::_prefactor
double _prefactor
Prefactors to multiply the output by.
Definition:
Histogram.h:388
Herwig::Histogram::Histogram
Histogram(vector< double > limits, vector< double > data, vector< double > dataerror)
Constructor with data included.
Definition:
Histogram.h:85
Herwig::Histogram::chiSquared
void chiSquared(double &chisq, unsigned int &ndegrees, double minfrac=0.) const
Return the chi squared.
Herwig::Histogram::Histogram
Histogram(vector< double > limits)
Constructor for variable width bins.
Definition:
Histogram.h:72
Herwig::Histogram::rivetOutput
void rivetOutput(ostream &out, string histogramname=string("default"), string analysisname=string("default"), string title=string(), string xlabel=string(), string ylabel=string(), bool rawcount=false, double multiplicator=1.0) const
Output as file ready for usage with flat2aida and other Rivet tools.
Herwig::Histogram::prefactor
double prefactor() const
Get the prefactor.
Definition:
Histogram.h:137
Herwig::Histogram::fullclone
virtual IBPtr fullclone() const
Make a clone of this object, possibly modifying the cloned object to make it sane.
Herwig::Histogram::LogBins
static vector< double > LogBins(double xmin, unsigned nbins, double base=10.0)
Returns limits for bins with exponentially increasing widths.
Herwig::Histogram::ratioWith
Histogram ratioWith(const Histogram &h2) const
Returns a new histogram containing bin-by-bin ratios of two histograms.
Herwig::Histogram::_globalStats
Statistic _globalStats
Global statistics of all data that went into the histogram.
Definition:
Histogram.h:333
Herwig::Histogram::Init
static void Init()
The standard Init function used to initialize the interfaces.
Herwig::Histogram::topdrawOutput
void topdrawOutput(ostream &out, unsigned int flags=0, string colour=string("BLACK"), string title=string(), string titlecase=string(), string left=string(), string leftcase=string(), string bottom=string(), string bottomcase=string()) const
Output as a topdrawer file.
Herwig::Histogram::_bins
vector< Bin > _bins
The histogram bins.
Definition:
Histogram.h:383
Herwig::Histogram::operator+=
void operator+=(double input)
Operator to add a point to the histogrma with unit weight.
Definition:
Histogram.h:106
Herwig::Histogram::normaliseToData
void normaliseToData()
Normalise the distributions to the data.
Herwig::Histogram::topdrawOutputAverage
void topdrawOutputAverage(ostream &out, bool frame, bool errorbars, bool xlog, bool ylog, string colour=string("BLACK"), string title=string(), string titlecase=string(), string left=string(), string leftcase=string(), string bottom=string(), string bottomcase=string()) const
Output as a topdrawer file.
Herwig::Histogram::Histogram
Histogram(double lower=0., double upper=0., unsigned int nbin=0)
The default constructor.
Definition:
Histogram.h:55
Herwig::Histogram::addWeighted
void addWeighted(double input, double weight)
Function to add a weighted point to the histogram.
Definition:
Histogram.h:113
Herwig::Statistic
The Statistic class is a simple class designed to store a variable for statistical analysis.
Definition:
Statistic.h:23
ThePEG::Interfaced
Herwig::HistogramOptions::Xlog
const unsigned int Xlog
log scale for x-axis
Definition:
Histogram.h:31
Herwig::HistogramOptions::Smooth
const unsigned int Smooth
smooth the line
Definition:
Histogram.h:33
Herwig::HistogramOptions::Errorbars
const unsigned int Errorbars
Plot error bars.
Definition:
Histogram.h:30
Herwig::HistogramOptions::Rawcount
const unsigned int Rawcount
don't normalize to unit area
Definition:
Histogram.h:34
Herwig::HistogramOptions::Frame
const unsigned int Frame
Plot on new frame.
Definition:
Histogram.h:29
Herwig::HistogramOptions::None
const unsigned int None
No options.
Definition:
Histogram.h:28
Herwig::HistogramOptions::Ylog
const unsigned int Ylog
log scale for y-axis
Definition:
Histogram.h:32
Herwig
-*- C++ -*-
Definition:
BasicConsistency.h:17
ThePEG
ThePEG::IBPtr
ThePEG::Ptr< InterfacedBase >::pointer IBPtr
ThePEG::sqr
constexpr auto sqr(const T &x) -> decltype(x *x)
ThePEG::left
ostream & left(ostream &os)
Herwig::Histogram::Bin
One bin of the histogram.
Definition:
Histogram.h:343
Herwig::Histogram::Bin::limit
double limit
The limit for the bin.
Definition:
Histogram.h:362
Herwig::Histogram::Bin::contentsSq
double contentsSq
Contents squared for the error.
Definition:
Histogram.h:357
Herwig::Histogram::Bin::Bin
Bin()
Default constructor.
Definition:
Histogram.h:347
Herwig::Histogram::Bin::points
long points
The number of points in the bin.
Definition:
Histogram.h:377
Herwig::Histogram::Bin::data
double data
The experimental value for the bin.
Definition:
Histogram.h:367
Herwig::Histogram::Bin::dataerror
double dataerror
The error on the experimental value for the bin.
Definition:
Histogram.h:372
Herwig::Histogram::Bin::contents
double contents
Contents of the bin.
Definition:
Histogram.h:352
Generated on Thu Jun 20 2024 17:50:53 for Herwig by
1.9.6