52 TGraphAsymmErrors(), _nominalBinWidth(nominalBinWidth), _nSigma(nSigma), _rawEntries(-1)
70 bool correctForBinWidth,
double scaleFactor) :
71 TGraphAsymmErrors(), _nominalBinWidth(nominalBinWidth), _nSigma(nSigma), _rawEntries(-1)
74 throw std::invalid_argument(
75 "To ensure consistent behavior prior releases, it's not possible to create a RooHist from a TH1 with no bin width correction when using Poisson errors.");
91 for(
Int_t bin= 1; bin <= nbin; bin++) {
96 addBin(
x,
y,
data.GetBinWidth(bin),xErrorFrac,scaleFactor);
123 TGraphAsymmErrors(), _nominalBinWidth(nominalBinWidth), _nSigma(nSigma), _rawEntries(-1)
145 coutE(InputArguments) <<
"RooHist::RooHist: histograms have different number of bins" << std::endl;
148 for(
Int_t bin= 1; bin <= nbin; bin++) {
151 coutW(InputArguments) <<
"RooHist::RooHist: histograms have different centers for bin " << bin << std::endl;
208 coutE(InputArguments) <<
"RooHist::RooHist input histograms have incompatible binning, combined histogram will remain empty" << std::endl ;
216 if (wgt1!=1.0 || wgt2 != 1.0) {
217 coutW(InputArguments) <<
"RooHist::RooHist: WARNING: Poisson errors of weighted sum of two histograms is not well defined! " << std::endl
218 <<
" Summed histogram bins will rounded to nearest integer for Poisson confidence interval calculation" << std::endl ;
223 for(i=0 ; i<
n ; i++) {
236 for(i=0 ; i<
n ; i++) {
243 double dy = sqrt(wgt1*wgt1*dy1*dy1+wgt2*wgt2*dy2*dy2) ;
271 std::string title{
f.GetTitle()};
274 if(0 != strlen(
f.getUnit()) || 0 != strlen(
x.getUnit())) {
276 if(0 != strlen(
f.getUnit())) {
277 title +=
f.getUnit();
280 if(0 != strlen(
x.getUnit())) {
282 title +=
x.getUnit();
289 std::unique_ptr<RooAbsFunc> rawPtr;
290 std::unique_ptr<RooAbsFunc> funcPtr{
f.bindVars(
x,normVars,
true)};
293 if(scaleFactor != 1) {
294 rawPtr= std::move(funcPtr);
295 funcPtr = std::make_unique<RooScaledFunc>(*rawPtr,scaleFactor);
302 int xbins =
x.numBins();
304 if(normVars) nset.
add(*normVars);
305 for(
int i=0; i<xbins; ++i){
306 double xval =
x.getBinning().binCenter(i);
307 double xwidth =
x.getBinning().binWidth(i);
309 double yval = (*funcPtr)(&xval);
310 double yerr = std::sqrt(yval);
311 if(fr) yerr =
f.getPropagatedError(*fr,nset);
312 addBinWithError(xval_ax,yval,yerr,yerr,xwidth,xErrorFrac,
false,scaleFactor) ;
345 for (
int i=0 ; i<
GetN() ; i++) {
350 if (
x>=xlo &&
x<=xhi) {
361 coutW(Plotting) <<
"RooHist::getFitRangeNEvt() WARNING: The number of normalisation events associated to histogram " <<
GetName() <<
" is not equal to number of events in this histogram."
362 <<
"\n\t\t This is due a cut being applied while plotting the data. Automatic normalisation over a sub-range of a plot variable assumes"
363 <<
"\n\t\t that the effect of that cut is uniform across the plot, which may be an incorrect assumption. To obtain a correct normalisation, it needs to be passed explicitly:"
364 <<
"\n\t\t\t data->plotOn(frame01,CutRange(\"SB1\"));"
365 <<
"\n\t\t\t const double nData = data->sumEntries(\"\", \"SB1\"); //or the cut string such as sumEntries(\"x > 0.\");"
366 <<
"\n\t\t\t model.plotOn(frame01, RooFit::Normalization(nData, RooAbsReal::NumEvent), ProjectionRange(\"SB1\"));" << std::endl ;
381 coutW(Plotting) <<
fName <<
"::roundBin: rounding negative bin contents to zero: " <<
y << std::endl;
385 if(std::abs(
y-
n)>1
e-6) {
386 coutW(Plotting) <<
fName <<
"::roundBin: rounding non-integer bin contents: " <<
y << std::endl;
398 if(std::abs(yscale) < 0) {
399 std::swap(eylow, eyhigh);
402 SetPointError(
index, exlow, exhigh, std::abs(yscale) * eylow, std::abs(yscale) * eyhigh);
423 coutW(Plotting) <<
"RooHist::addBin(" <<
GetName() <<
") WARNING: negative entry set to zero when Poisson error bars are requested" << std::endl ;
433 double ym,yp,dx(0.5*binWidth);
435 if (std::abs((
double)((
n-
Int_t(
n))>1
e-5))) {
437 double ym1(0),yp1(0),ym2(0),yp2(0) ;
442 coutE(Plotting) <<
"RooHist::addBin: unable to add bin with " <<
n <<
" events" << std::endl;
444 ym = ym1 + (
n-n1)*(ym2-ym1) ;
445 yp = yp1 + (
n-n1)*(yp2-yp1) ;
447 <<
") WARNING: non-integer bin entry " <<
n <<
" with Poisson errors, interpolating between Poisson errors of adjacent integer" << std::endl ;
451 coutE(Plotting) <<
"RooHist::addBin: unable to add bin with " <<
n <<
" events" << std::endl;
456 addPoint(binCenter,
n, scale*scaleFactor,dx*xErrorFrac,dx*xErrorFrac,
n-ym, yp-
n);
467 double xErrorFrac,
bool correctForBinWidth,
double scaleFactor)
470 if(binWidth > 0 && correctForBinWidth) {
475 double dx(0.5*binWidth) ;
476 addPoint(binCenter,
n, scale*scaleFactor,dx*xErrorFrac,dx*xErrorFrac, elow, ehigh);
492 addPoint(binCenter,
n, scaleFactor,exlow,exhigh, eylow, eyhigh);
506 double ym,yp,dx(0.5*binWidth);
508 coutE(Plotting) <<
"RooHist::addAsymmetryBin: unable to calculate binomial error for bin with " << n1 <<
"," << n2 <<
" events" << std::endl;
512 double a= (
double)(n1-n2)/(n1+n2);
513 addPoint(binCenter,
a, scaleFactor,dx*xErrorFrac,dx*xErrorFrac,
a-ym, yp-
a);
525 double ym,yp,dx(0.5*binWidth);
526 double a= (
double)(n1-n2)/(n1+n2);
528 double error = 2*sqrt( pow(en1,2)*pow(n2,2) + pow(en2,2)*pow(n1,2) ) / pow(n1+n2,2) ;
532 addPoint(binCenter,
a, scaleFactor, dx*xErrorFrac,dx*xErrorFrac,
a-ym, yp-
a);
543 double a= (
double)(n1)/(n1+n2);
546 double ym,yp,dx(0.5*binWidth);
548 coutE(Plotting) <<
"RooHist::addEfficiencyBin: unable to calculate binomial error for bin with " << n1 <<
"," << n2 <<
" events" << std::endl;
552 addPoint(binCenter,
a, scaleFactor,dx*xErrorFrac,dx*xErrorFrac,
a-ym, yp-
a);
563 double a= (
double)(n1)/(n1+n2);
565 double error = sqrt( pow(en1,2)*pow(n2,2) + pow(en2,2)*pow(n1,2) ) / pow(n1+n2,2) ;
568 double ym,yp,dx(0.5*binWidth);
573 addPoint(binCenter,
a, scaleFactor,dx*xErrorFrac,dx*xErrorFrac,
a-ym, yp-
a);
589 for (i=0 ; i<
GetN() ; i++) {
614 TH1F h_self(
"h_self",
"h_self",
GetN(),0,1) ;
615 TH1F h_other(
"h_other",
"h_other",
GetN(),0,1) ;
626 if(verbose) std::cout <<
"RooHist::isIdentical() tolerance exceeded M=" << M <<
" (tol=" << tol <<
"), corresponding prob = " << kprob << std::endl ;
645 os <<
indent <<
"--- RooHist ---" << std::endl;
647 os <<
indent <<
" Contains " <<
n <<
" bins" << std::endl;
649 os <<
indent <<
" Errors calculated at" <<
_nSigma <<
"-sigma CL" << std::endl;
650 os <<
indent <<
" Bin Contents:" << std::endl;
651 for(
Int_t i= 0; i <
n; i++) {
652 os <<
indent << std::setw(3) << i <<
") x= " <<
fX[i];
656 os <<
" , y = " <<
fY[i] <<
" +" <<
fEYhigh[i] <<
" -" <<
fEYlow[i] << std::endl;
697 const std::string title =
GetTitle() + std::string(
" and ") + curve.
GetTitle();
698 hist->SetName(((normalize ?
"pull_" :
"resid_") +
name).c_str()) ;
699 hist->SetTitle(((normalize ?
"Pull of " :
"Residual of ") + title).c_str()) ;
708 double xstart,xstop,
y ;
718 if (x<xstart || x>xstop) continue ;
728 yy = point - curve.
average(
x-exl,
x+exh) ;
736 double norm = (yy>0?dyl:dyh);
738 coutW(Plotting) <<
"RooHist::makeResisHist(" <<
GetName() <<
") WARNING: point " << i <<
" has zero error, setting residual to zero" << std::endl;
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t SetMarkerStyle
Option_t Option_t TPoint TPoint const char y1
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
A RooCurve is a one-dimensional graphical representation of a real-valued function.
double interpolate(double x, double tolerance=1e-10) const
Return linearly interpolated value of curve at xvalue.
double average(double lo, double hi) const
Return average curve value in [xFirst,xLast] by integrating curve between points and dividing by xLas...
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
A RooHist is a graphical representation of binned data based on the TGraphAsymmErrors class.
RooHist * makeResidHist(const RooCurve &curve, bool normalize=false, bool useAverage=false) const
Create and return RooHist containing residuals w.r.t to given curve.
double _nominalBinWidth
Average bin width.
double _rawEntries
Number of entries in source dataset.
void printClassName(std::ostream &os) const override
Print class name of RooHist.
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...
void fillResidHist(RooHist &residHist, const RooCurve &curve, bool normalize=false, bool useAverage=false) const
void initialize()
Perform common initialization for all constructors.
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.
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...
void printName(std::ostream &os) const override
Print name of RooHist.
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.
std::unique_ptr< RooHist > createEmptyResidHist(const RooCurve &curve, bool normalize=false) const
void printTitle(std::ostream &os) const override
Print title of RooHist.
std::vector< double > _originalWeights
The original bin weights that were passed to the RooHist::addBin functions before scaling and bin wid...
double getNominalBinWidth() const
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...
double _entries
Number of entries in histogram.
Int_t roundBin(double y)
Return the nearest positive integer to the input value and print a warning if an adjustment is requir...
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...
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...
double _nSigma
Number of 'sigmas' error bars represent.
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...
void addPoint(Axis_t binCenter, double y, double yscale, double exlow, double exhigh, double eylow, double eyhigh)
bool hasIdenticalBinning(const RooHist &other) const
Return true if binning of this RooHist is identical to that of 'other'.
double getFitRangeNEvt() const override
Return the number of events of the dataset associated with this RooHist.
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.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print detailed information.
void updateYAxisLimits(double y)
void setYAxisLabel(const char *label)
const char * getYAxisLabel() const
Class to manage histogram axis.
TGraph with asymmetric error bars.
Double_t * fEXhigh
[fNpoints] array of X high errors
Double_t GetErrorY(Int_t bin) const override
Returns the combined error along Y at point i by computing the average of the lower and upper varianc...
virtual void SetPointError(Double_t exl, Double_t exh, Double_t eyl, Double_t eyh)
Set ex and ey values for point pointed by the mouse.
Double_t GetErrorXhigh(Int_t i) const override
Get high error on X.
Double_t * fEYhigh
[fNpoints] array of Y high errors
Double_t GetErrorYhigh(Int_t i) const override
Get high error on Y.
Double_t GetErrorXlow(Int_t i) const override
Get low error on X.
Double_t * fEYlow
[fNpoints] array of Y low errors
Double_t * fEXlow
[fNpoints] array of X low errors
Double_t GetErrorYlow(Int_t i) const override
Get low error on Y.
Double_t GetErrorX(Int_t bin) const override
Returns the combined error along X at point i by computing the average of the lower and upper varianc...
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Double_t * fY
[fNpoints] array of Y points
void SetName(const char *name="") override
Set graph name.
Double_t * fX
[fNpoints] array of X points
void SetTitle(const char *title="") override
Change (i.e.
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
Get x and y values for point number i.
1-D histogram with a float per channel (see TH1 documentation)}
TH1 is the base class of all histogram classes in ROOT.
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
virtual Int_t GetNbinsX() const
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width for 1D histogram.
virtual Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const
Statistical test of compatibility in shape between this histogram and h2, using Kolmogorov test.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
static uint64_t sum(uint64_t i)