53 : _nominalBinWidth(nominalBinWidth), _nSigma(nSigma), _rawEntries(-1)
71 bool correctForBinWidth,
double scaleFactor)
72 : _nominalBinWidth(nominalBinWidth), _nSigma(nSigma), _rawEntries(-1)
75 throw std::invalid_argument(
76 "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.");
92 for(
Int_t bin= 1; bin <= nbin; bin++) {
97 addBin(
x,
y,
data.GetBinWidth(bin),xErrorFrac,scaleFactor);
123 double xErrorFrac,
bool efficiency,
double scaleFactor)
124 : _nominalBinWidth(nominalBinWidth), _nSigma(nSigma), _rawEntries(-1)
146 coutE(InputArguments) <<
"RooHist::RooHist: histograms have different number of bins" << std::endl;
149 for(
Int_t bin= 1; bin <= nbin; bin++) {
152 coutW(InputArguments) <<
"RooHist::RooHist: histograms have different centers for bin " << bin << std::endl;
197 : _nominalBinWidth(hist1._nominalBinWidth), _nSigma(hist1._nSigma), _rawEntries(-1)
209 coutE(InputArguments) <<
"RooHist::RooHist input histograms have incompatible binning, combined histogram will remain empty" << std::endl ;
217 if (wgt1!=1.0 || wgt2 != 1.0) {
218 coutW(InputArguments) <<
"RooHist::RooHist: WARNING: Poisson errors of weighted sum of two histograms is not well defined! " << std::endl
219 <<
" Summed histogram bins will rounded to nearest integer for Poisson confidence interval calculation" << std::endl ;
225 for(i=0 ; i<
n ; i++) {
243 for(i=0 ; i<
n ; i++) {
256 double dy = sqrt(wgt1*wgt1*dy1*dy1+wgt2*wgt2*dy2*dy2) ;
281 : _nSigma(1), _rawEntries(-1)
285 std::string title{
f.GetTitle()};
288 if(0 != strlen(
f.getUnit()) || 0 != strlen(
x.getUnit())) {
290 if(0 != strlen(
f.getUnit())) {
291 title +=
f.getUnit();
294 if(0 != strlen(
x.getUnit())) {
296 title +=
x.getUnit();
304 std::unique_ptr<RooAbsFunc> funcPtr{scaledFunc.
bindVars(
x, normVars,
true)};
307 int xbins =
x.numBins();
309 if(normVars) nset.
add(*normVars);
310 for(
int i=0; i<xbins; ++i){
311 double xval =
x.getBinning().binCenter(i);
312 double xwidth =
x.getBinning().binWidth(i);
314 double yval = (*funcPtr)(&xval);
315 double yerr = std::sqrt(yval);
316 if(fr) yerr =
f.getPropagatedError(*fr,nset);
317 addBinWithError(xval_ax,yval,yerr,yerr,xwidth,xErrorFrac,
false,scaleFactor) ;
350 for (
int i=0 ; i<
GetN() ; i++) {
356 if (
x>=xlo &&
x<=xhi) {
367 coutW(Plotting) <<
"RooHist::getFitRangeNEvt() WARNING: The number of normalisation events associated to histogram " <<
GetName() <<
" is not equal to number of events in this histogram."
368 <<
"\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"
369 <<
"\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:"
370 <<
"\n\t\t\t data->plotOn(frame01,CutRange(\"SB1\"));"
371 <<
"\n\t\t\t const double nData = data->sumEntries(\"\", \"SB1\"); //or the cut string such as sumEntries(\"x > 0.\");"
372 <<
"\n\t\t\t model.plotOn(frame01, RooFit::Normalization(nData, RooAbsReal::NumEvent), ProjectionRange(\"SB1\"));" << std::endl ;
387 coutW(Plotting) <<
fName <<
"::roundBin: rounding negative bin contents to zero: " <<
y << std::endl;
391 if(std::abs(
y-
n)>1
e-6) {
392 coutW(Plotting) <<
fName <<
"::roundBin: rounding non-integer bin contents: " <<
y << std::endl;
404 if(std::abs(yscale) < 0) {
405 std::swap(eylow, eyhigh);
408 SetPointError(
index, exlow, exhigh, std::abs(yscale) * eylow, std::abs(yscale) * eyhigh);
429 coutW(Plotting) <<
"RooHist::addBin(" <<
GetName() <<
") WARNING: negative entry set to zero when Poisson error bars are requested" << std::endl ;
441 double dx(0.5 * binWidth);
443 if (std::abs((
double)((
n-
Int_t(
n))>1
e-5))) {
453 coutE(Plotting) <<
"RooHist::addBin: unable to add bin with " <<
n <<
" events" << std::endl;
455 ym = ym1 + (
n-n1)*(ym2-ym1) ;
456 yp = yp1 + (
n-n1)*(yp2-yp1) ;
458 <<
") WARNING: non-integer bin entry " <<
n <<
" with Poisson errors, interpolating between Poisson errors of adjacent integer" << std::endl ;
462 coutE(Plotting) <<
"RooHist::addBin: unable to add bin with " <<
n <<
" events" << std::endl;
467 addPoint(binCenter,
n, scale*scaleFactor,dx*xErrorFrac,dx*xErrorFrac,
n-ym, yp-
n);
478 double xErrorFrac,
bool correctForBinWidth,
double scaleFactor)
481 if(binWidth > 0 && correctForBinWidth) {
486 double dx(0.5*binWidth) ;
487 addPoint(binCenter,
n, scale*scaleFactor,dx*xErrorFrac,dx*xErrorFrac, elow, ehigh);
503 addPoint(binCenter,
n, scaleFactor,exlow,exhigh, eylow, eyhigh);
519 double dx(0.5 * binWidth);
521 coutE(Plotting) <<
"RooHist::addAsymmetryBin: unable to calculate binomial error for bin with " << n1 <<
"," << n2 <<
" events" << std::endl;
525 double a= (
double)(n1-n2)/(n1+n2);
526 addPoint(binCenter,
a, scaleFactor,dx*xErrorFrac,dx*xErrorFrac,
a-ym, yp-
a);
540 double dx(0.5 * binWidth);
541 double a= (
double)(n1-n2)/(n1+n2);
543 double error = 2*sqrt( pow(en1,2)*pow(n2,2) + pow(en2,2)*pow(n1,2) ) / pow(n1+n2,2) ;
547 addPoint(binCenter,
a, scaleFactor, dx*xErrorFrac,dx*xErrorFrac,
a-ym, yp-
a);
558 double a= (
double)(n1)/(n1+n2);
563 double dx(0.5 * binWidth);
565 coutE(Plotting) <<
"RooHist::addEfficiencyBin: unable to calculate binomial error for bin with " << n1 <<
"," << n2 <<
" events" << std::endl;
569 addPoint(binCenter,
a, scaleFactor,dx*xErrorFrac,dx*xErrorFrac,
a-ym, yp-
a);
580 double a= (
double)(n1)/(n1+n2);
582 double error = sqrt( pow(en1,2)*pow(n2,2) + pow(en2,2)*pow(n1,2) ) / pow(n1+n2,2) ;
587 double dx(0.5 * binWidth);
592 addPoint(binCenter,
a, scaleFactor,dx*xErrorFrac,dx*xErrorFrac,
a-ym, yp-
a);
608 for (i=0 ; i<
GetN() ; i++) {
636 TH1F h_self(
"h_self",
"h_self",
GetN(),0,1) ;
637 TH1F h_other(
"h_other",
"h_other",
GetN(),0,1) ;
648 if(verbose) std::cout <<
"RooHist::isIdentical() tolerance exceeded M=" << M <<
" (tol=" << tol <<
"), corresponding prob = " << kprob << std::endl ;
667 os <<
indent <<
"--- RooHist ---" << std::endl;
669 os <<
indent <<
" Contains " <<
n <<
" bins" << std::endl;
671 os <<
indent <<
" Errors calculated at" <<
_nSigma <<
"-sigma CL" << std::endl;
672 os <<
indent <<
" Bin Contents:" << std::endl;
673 for(
Int_t i= 0; i <
n; i++) {
674 os <<
indent << std::setw(3) << i <<
") x= " <<
fX[i];
678 os <<
" , y = " <<
fY[i] <<
" +" <<
fEYhigh[i] <<
" -" <<
fEYlow[i] << std::endl;
719 const std::string title =
GetTitle() + std::string(
" and ") + curve.
GetTitle();
720 hist->SetName(((normalize ?
"pull_" :
"resid_") +
name).c_str()) ;
721 hist->SetTitle(((normalize ?
"Pull of " :
"Residual of ") + title).c_str()) ;
743 if (x<xstart || x>xstop) continue ;
753 yy = point - curve.
average(
x-exl,
x+exh) ;
761 double norm = (yy>0?dyl:dyh);
763 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.
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...
RooFit::OwningPtr< RooAbsFunc > bindVars(const RooArgSet &vars, const RooArgSet *nset=nullptr, bool clipInvalid=false) const
Create an interface adaptor f(vars) that binds us to the specified variables (in arbitrary order).
RooArgSet is a container object that can hold multiple RooAbsArg objects.
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.
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
Represents the product of a given set of RooAbsReal objects.
Class to manage histogram axis.
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.
RooConstVar & RooConst(double val)
static uint64_t sum(uint64_t i)