File indexing completed on 2026-08-06 09:24:28
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef HERWIG_Histogram_H
0010 #define HERWIG_Histogram_H
0011
0012
0013
0014 #include "Histogram.fh"
0015 #include "ThePEG/Interface/Interfaced.h"
0016 #include "Statistic.h"
0017 #include <string>
0018
0019 namespace Herwig {
0020
0021 using namespace ThePEG;
0022
0023
0024
0025
0026
0027 namespace HistogramOptions {
0028 const unsigned int None = 0;
0029 const unsigned int Frame = 1;
0030 const unsigned int Errorbars = 1 << 1;
0031 const unsigned int Xlog = 1 << 2;
0032 const unsigned int Ylog = 1 << 3;
0033 const unsigned int Smooth = 1 << 4;
0034 const unsigned int Rawcount = 1 << 5;
0035 }
0036
0037
0038
0039
0040
0041
0042
0043 class Histogram: public Interfaced {
0044
0045 public:
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 Histogram(double lower=0., double upper=0., unsigned int nbin=0)
0056 : _globalStats(), _havedata(false), _bins(nbin+2),_prefactor(1.),_total(0.) {
0057 if (upper<lower) swap(upper,lower);
0058 _bins[0].limit=-1.e100;
0059 double limit(lower);
0060 double width((upper-lower)/nbin);
0061 for(unsigned int ix=1; ix <= nbin; ++ix) {
0062 _bins[ix].limit=limit;
0063 limit += width;
0064 }
0065 _bins.back().limit=limit;
0066 }
0067
0068
0069
0070
0071
0072 Histogram(vector<double> limits)
0073 : _globalStats(), _havedata(false), _bins(limits.size()+1), _prefactor(1.),_total(0.) {
0074 _bins[0].limit=-1.e100;
0075 for (size_t i=1; i<=limits.size(); ++i)
0076 _bins[i].limit=limits[i-1];
0077 }
0078
0079
0080
0081
0082
0083
0084
0085 Histogram(vector<double> limits, vector<double> data, vector<double> dataerror)
0086 : _globalStats(), _havedata(true), _bins(limits.size()+1), _prefactor(1.),_total(0.) {
0087 _bins[0].limit=-1.e100;
0088 for (size_t i=1; i<=limits.size(); ++i)
0089 _bins[i].limit=limits[i-1];
0090
0091
0092 for (size_t i=1; i<=min(limits.size()-1,data.size()); ++i)
0093 _bins[i].data=data[i-1];
0094
0095 for (size_t i=1; i<=min(limits.size()-1,dataerror.size()); ++i)
0096 _bins[i].dataerror=dataerror[i-1];
0097 }
0098
0099
0100
0101 public:
0102
0103
0104
0105
0106 void operator += (double input) {
0107 addWeighted(input,1.0);
0108 }
0109
0110
0111
0112
0113 void addWeighted(double input, double weight) {
0114 if(std::isnan(input)) return;
0115 unsigned int ibin;
0116 for(ibin=1; ibin<_bins.size(); ++ibin) {
0117 if(input<_bins[ibin].limit)
0118 break;
0119 }
0120 _bins[ibin-1].contents += weight;
0121 _bins[ibin-1].contentsSq += sqr(weight);
0122 _globalStats += weight * input;
0123 _total += weight;
0124 }
0125
0126
0127
0128
0129 unsigned int numberOfBins() const {
0130 return _bins.size()-2;
0131 }
0132
0133
0134
0135
0136
0137 double prefactor() const {
0138 return _prefactor;
0139 }
0140
0141
0142
0143
0144 void prefactor(double in ) {
0145 _prefactor=in;
0146 }
0147
0148
0149
0150
0151 const Statistic & globalStatistics() const {
0152 return _globalStats;
0153 }
0154
0155
0156
0157
0158 void normaliseToData();
0159
0160
0161
0162
0163 void normaliseToCrossSection();
0164
0165
0166
0167
0168
0169
0170
0171 void chiSquared(double & chisq,
0172 unsigned int & ndegrees, double minfrac=0.) const;
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 void rivetOutput(ostream & out,
0189 string histogramname = string("default"),
0190 string analysisname = string("default"),
0191 string title = string(),
0192 string xlabel = string(),
0193 string ylabel = string(),
0194 bool rawcount = false,
0195 double multiplicator = 1.0) const;
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210 void topdrawOutput(ostream & out,
0211 unsigned int flags = 0,
0212 string colour = string("BLACK"),
0213 string title = string(),
0214 string titlecase = string(),
0215 string left = string(),
0216 string leftcase = string(),
0217 string bottom = string(),
0218 string bottomcase = string()
0219 ) const;
0220
0221 void topdrawMCatNLO(ostream & out,
0222 unsigned int flags =0 ,
0223 string colour = string("BLACK"),
0224 string title = string()
0225 ) const;
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242 void topdrawOutputAverage(ostream & out,
0243 bool frame,
0244 bool errorbars,
0245 bool xlog, bool ylog,
0246 string colour=string("BLACK"),
0247 string title=string(),
0248 string titlecase =string(),
0249 string left=string(),
0250 string leftcase =string(),
0251 string bottom=string(),
0252 string bottomcase =string()) const;
0253
0254
0255
0256
0257
0258
0259 unsigned int visibleEntries() const;
0260
0261
0262
0263
0264 double dataNorm() const;
0265
0266
0267
0268
0269 void simpleOutput(ostream & out, bool errorbars, bool normdata=false);
0270
0271
0272
0273
0274 vector<double> dumpBins() const;
0275
0276
0277
0278
0279 Histogram ratioWith(const Histogram & h2) const;
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289 static
0290 vector<double> LogBins(double xmin, unsigned nbins, double base = 10.0);
0291
0292
0293 public:
0294
0295
0296
0297
0298
0299
0300
0301 static void Init();
0302
0303 protected:
0304
0305
0306
0307
0308
0309
0310
0311 virtual IBPtr clone() const;
0312
0313
0314
0315
0316
0317 virtual IBPtr fullclone() const;
0318
0319
0320 private:
0321
0322
0323
0324
0325
0326 Histogram & operator=(const Histogram &) = delete;
0327
0328 private:
0329
0330
0331
0332
0333 Statistic _globalStats;
0334
0335
0336
0337
0338 bool _havedata;
0339
0340
0341
0342
0343 struct Bin {
0344
0345
0346
0347 Bin() : contents(0.0), contentsSq(0.0),
0348 limit(0.0), data(0.0), dataerror(0.0), points(0) {}
0349
0350
0351
0352 double contents;
0353
0354
0355
0356
0357 double contentsSq;
0358
0359
0360
0361
0362 double limit;
0363
0364
0365
0366
0367 double data;
0368
0369
0370
0371
0372 double dataerror;
0373
0374
0375
0376
0377 long points;
0378 };
0379
0380
0381
0382
0383 vector<Bin> _bins;
0384
0385
0386
0387
0388 double _prefactor;
0389
0390
0391
0392
0393 double _total;
0394
0395
0396 public:
0397
0398
0399
0400
0401 vector<Bin> bins() const { return _bins; }
0402
0403 };
0404
0405 }
0406
0407 #endif