Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooHist.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooHist.h,v 1.22 2007/05/11 09:11:30 verkerke Exp $
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16#ifndef ROO_HIST
17#define ROO_HIST
18
19#include "TGraphAsymmErrors.h"
20#include "RooPlotable.h"
21#include "RooAbsData.h"
22
24class RooCurve;
25class RooFitResult;
26
27class TH1;
28
29class RooHist : public TGraphAsymmErrors, public RooPlotable {
30public:
32 RooHist(double nominalBinWidth, double nSigma= 1, double xErrorFrac=1.0, double scaleFactor=1.0);
33 RooHist(const TH1 &data, double nominalBinWidth= 0, double nSigma= 1, RooAbsData::ErrorType=RooAbsData::Poisson,
34 double xErrorFrac=1.0, bool correctForBinWidth=true, double scaleFactor=1.);
35 RooHist(const TH1 &data1, const TH1 &data2, double nominalBinWidth= 0, double nSigma= 1, RooAbsData::ErrorType=RooAbsData::Poisson,
36 double xErrorFrac=1.0, bool efficiency=false, double scaleFactor=1.0);
37 RooHist(const RooHist& hist1, const RooHist& hist2, double wgt1=1.0, double wgt2=1.0,
38 RooAbsData::ErrorType etype=RooAbsData::Poisson, double xErrorFrac=1.0) ;
39 RooHist(const RooAbsReal &f, RooAbsRealLValue &x, double xErrorFrac=1.0, double scaleFactor=1.0, const RooArgSet *normVars = nullptr, const RooFitResult* fr = nullptr);
40
41 // add a datapoint for a bin with n entries, using a Poisson error
42 void addBin(Axis_t binCenter, double n, double binWidth= 0, double xErrorFrac=1.0, double scaleFactor=1.0);
43 // add a datapoint for a bin with n entries, using a given error
44 void addBinWithError(Axis_t binCenter, double n, double elow, double ehigh, double binWidth= 0,
45 double xErrorFrac=1.0, bool correctForBinWidth=true, double scaleFactor=1.0);
46 // add a datapoint for a bin with n entries, using a given x and y error
47 void addBinWithXYError(Axis_t binCenter, double n, double exlow, double exhigh, double eylow, double eyhigh,
48 double scaleFactor=1.0);
49 // add a datapoint for the asymmetry (n1-n2)/(n1+n2), using a binomial error
50 void addAsymmetryBin(Axis_t binCenter, Int_t n1, Int_t n2, double binWidth= 0, double xErrorFrac=1.0, double scaleFactor=1.0);
51 // add a datapoint for the asymmetry (n1-n2)/(n1+n2), using sum-of-weights error
52 void addAsymmetryBinWithError(Axis_t binCenter, double n1, double n2, double en1, double en2, double binWidth= 0, double xErrorFrac=1.0, double scaleFactor=1.0);
53
54 // add a datapoint for the efficiency (n1)/(n1+n2), using a binomial error
55 void addEfficiencyBin(Axis_t binCenter, Int_t n1, Int_t n2, double binWidth= 0, double xErrorFrac=1.0, double scaleFactor=1.0);
56 // add a datapoint for the efficiency (n1)/(n1+n2), using a sum-of-weights error
57 void addEfficiencyBinWithError(Axis_t binCenter, double n1, double n2, double en1, double en2, double binWidth= 0, double xErrorFrac=1.0, double scaleFactor=1.0);
58
59 void printName(std::ostream& os) const override ;
60 void printTitle(std::ostream& os) const override ;
61 void printClassName(std::ostream& os) const override ;
62 void printMultiline(std::ostream& os, Int_t content, bool verbose=false, TString indent= "") const override;
63
64 inline void Print(Option_t *options= nullptr) const override {
65 // Printing interface
67 }
68
69 double getFitRangeNEvt() const override;
70 double getFitRangeNEvt(double xlo, double xhi) const override ;
71 /// Return (average) bin width of this RooHist.
72 double getFitRangeBinW() const override { return _nominalBinWidth ; }
73 inline double getNominalBinWidth() const { return _nominalBinWidth; }
74 inline void setRawEntries(double n) { _rawEntries = n ; }
75
76 bool hasIdenticalBinning(const RooHist& other) const ;
77
78 RooHist* makeResidHist(const RooCurve& curve,bool normalize=false, bool useAverage=false) const;
79 RooHist* makePullHist(const RooCurve& curve, bool useAverage=false) const
80 {return makeResidHist(curve,true,useAverage); }
81
82 bool isIdentical(const RooHist& other, double tol=1e-6, bool verbose=true) const ;
83
84
85protected:
86 void initialize();
87 Int_t roundBin(double y);
88
89 friend class RooPlot;
90
91 void fillResidHist(RooHist & residHist, const RooCurve& curve,bool normalize=false, bool useAverage=false) const;
92 std::unique_ptr<RooHist> createEmptyResidHist(const RooCurve& curve, bool normalize=false) const;
93
94private:
95
96 void addPoint(Axis_t binCenter, double y, double yscale, double exlow, double exhigh, double eylow, double eyhigh);
97
98 double _nominalBinWidth = 1.0; ///< Average bin width
99 double _nSigma = 1.0; ///< Number of 'sigmas' error bars represent
100 double _entries = 0.0; ///< Number of entries in histogram
101 double _rawEntries = 0.0; ///< Number of entries in source dataset
102
103 std::vector<double> _originalWeights; ///< The original bin weights that were passed to the `RooHist::addBin` functions before scaling and bin width correction
104
105 ClassDefOverride(RooHist,2) // 1-dimensional histogram with error bars
106};
107
108#endif
#define f(i)
Definition RSha256.hxx:104
#define e(i)
Definition RSha256.hxx:103
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
One-dimensional graphical representation of a real-valued function.
Definition RooCurve.h:36
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Graphical representation of binned data based on the TGraphAsymmErrors class.
Definition RooHist.h:29
RooHist * makeResidHist(const RooCurve &curve, bool normalize=false, bool useAverage=false) const
Create and return RooHist containing residuals w.r.t to given curve.
Definition RooHist.cxx:783
double _nominalBinWidth
Average bin width.
Definition RooHist.h:98
double _rawEntries
Number of entries in source dataset.
Definition RooHist.h:101
void printClassName(std::ostream &os) const override
Print class name of RooHist.
Definition RooHist.cxx:708
void addEfficiencyBin(Axis_t binCenter, Int_t n1, Int_t n2, double binWidth=0, double xErrorFrac=1.0, double scaleFactor=1.0)
Add a bin to this histogram with the value n1/(n1+n2) using an error bar calculated with Binomial sta...
Definition RooHist.cxx:556
void fillResidHist(RooHist &residHist, const RooCurve &curve, bool normalize=false, bool useAverage=false) const
Definition RooHist.cxx:727
void initialize()
Perform common initialization for all constructors.
Definition RooHist.cxx:327
void addBinWithError(Axis_t binCenter, double n, double elow, double ehigh, double binWidth=0, double xErrorFrac=1.0, bool correctForBinWidth=true, double scaleFactor=1.0)
Add a bin to this histogram with the specified bin contents and error.
Definition RooHist.cxx:477
void addEfficiencyBinWithError(Axis_t binCenter, double n1, double n2, double en1, double en2, double binWidth=0, double xErrorFrac=1.0, double scaleFactor=1.0)
Add a bin to this histogram with the value n1/(n1+n2) using an error bar calculated with Binomial sta...
Definition RooHist.cxx:578
RooHist()
Definition RooHist.h:31
void printName(std::ostream &os) const override
Print name of RooHist.
Definition RooHist.cxx:688
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Print info about this histogram to the specified output stream.
Definition RooHist.cxx:664
std::unique_ptr< RooHist > createEmptyResidHist(const RooCurve &curve, bool normalize=false) const
Definition RooHist.cxx:714
void printTitle(std::ostream &os) const override
Print title of RooHist.
Definition RooHist.cxx:698
double getFitRangeBinW() const override
Return (average) bin width of this RooHist.
Definition RooHist.h:72
std::vector< double > _originalWeights
The original bin weights that were passed to the RooHist::addBin functions before scaling and bin wid...
Definition RooHist.h:103
double getNominalBinWidth() const
Definition RooHist.h:73
void addAsymmetryBinWithError(Axis_t binCenter, double n1, double n2, double en1, double en2, double binWidth=0, double xErrorFrac=1.0, double scaleFactor=1.0)
Add a bin to this histogram with the value (n1-n2)/(n1+n2) using an error bar calculated with Binomia...
Definition RooHist.cxx:535
double _entries
Number of entries in histogram.
Definition RooHist.h:100
Int_t roundBin(double y)
Return the nearest positive integer to the input value and print a warning if an adjustment is requir...
Definition RooHist.cxx:384
void setRawEntries(double n)
Definition RooHist.h:74
bool isIdentical(const RooHist &other, double tol=1e-6, bool verbose=true) const
Return true if contents of this RooHist is identical within given relative tolerance to that of 'othe...
Definition RooHist.cxx:632
void addAsymmetryBin(Axis_t binCenter, Int_t n1, Int_t n2, double binWidth=0, double xErrorFrac=1.0, double scaleFactor=1.0)
Add a bin to this histogram with the value (n1-n2)/(n1+n2) using an error bar calculated with Binomia...
Definition RooHist.cxx:514
RooHist * makePullHist(const RooCurve &curve, bool useAverage=false) const
Definition RooHist.h:79
double _nSigma
Number of 'sigmas' error bars represent.
Definition RooHist.h:99
void addBin(Axis_t binCenter, double n, double binWidth=0, double xErrorFrac=1.0, double scaleFactor=1.0)
Add a bin to this histogram with the specified integer bin contents and using an error bar calculated...
Definition RooHist.cxx:426
void addPoint(Axis_t binCenter, double y, double yscale, double exlow, double exhigh, double eylow, double eyhigh)
Definition RooHist.cxx:398
bool hasIdenticalBinning(const RooHist &other) const
Return true if binning of this RooHist is identical to that of 'other'.
Definition RooHist.cxx:599
double getFitRangeNEvt() const override
Return the number of events of the dataset associated with this RooHist.
Definition RooHist.cxx:338
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
Definition RooHist.h:64
void addBinWithXYError(Axis_t binCenter, double n, double exlow, double exhigh, double eylow, double eyhigh, double scaleFactor=1.0)
Add a bin to this histogram with the specified bin contents and error.
Definition RooHist.cxx:498
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
Class RooPotable is a base class for objects that can be inserted into RooPlots and take advantage of...
Definition RooPlotable.h:26
virtual StyleOption defaultPrintStyle(Option_t *opt) const
virtual Int_t defaultPrintContents(Option_t *opt) const
Default choice of contents to be printed (name and value)
static std::ostream & defaultPrintStream(std::ostream *os=nullptr)
Return a reference to the current default stream to use in Print().
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
TGraph with asymmetric error bars.
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
Basic string class.
Definition TString.h:139
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16