80 if (!CtorAllocate())
return;
82 memcpy(fEXlow,
gr.fEXlow,
n);
83 memcpy(fEYlow,
gr.fEYlow,
n);
84 memcpy(fEXhigh,
gr.fEXhigh,
n);
85 memcpy(fEYhigh,
gr.fEYhigh,
n);
121 if (!CtorAllocate())
return;
122 FillZero(0, fNpoints);
134 if (!CtorAllocate())
return;
137 if (exl) fEXlow[i] = exl[i];
139 if (exh) fEXhigh[i] = exh[i];
141 if (eyl) fEYlow[i] = eyl[i];
143 if (eyh) fEYhigh[i] = eyh[i];
157 if (!CtorAllocate())
return;
161 memcpy(fEXlow, exl,
n);
163 memset(fEXlow, 0,
n);
165 memcpy(fEXhigh, exh,
n);
167 memset(fEXhigh, 0,
n);
169 memcpy(fEYlow, eyl,
n);
171 memset(fEYlow, 0,
n);
173 memcpy(fEYhigh, eyh,
n);
175 memset(fEYhigh, 0,
n);
198 fX[i] = vx(i+ivxlow);
199 fY[i] = vy(i+ivylow);
200 fEXlow[i] = vexl(i+ivexllow);
201 fEYlow[i] = veyl(i+iveyllow);
227 fX[i] = vx(i+ivxlow);
228 fY[i] = vy(i+ivylow);
229 fEXlow[i] = vexl(i+ivexllow);
230 fEYlow[i] = veyl(i+iveyllow);
244 if (!CtorAllocate())
return;
246 for (
Int_t i = 0; i < fNpoints; i++) {
247 fEXlow[i] =
h->GetBinWidth(i+1)*
gStyle->GetErrorX();
248 fEXhigh[i] = fEXlow[i];
249 fEYlow[i] =
h->GetBinErrorLow(i+1);
250 fEYhigh[i] =
h->GetBinErrorUp(i+1);
260 :
TGraph((pass)?pass->GetNbinsX():0)
262 if (!pass || !
total) {
263 Error(
"TGraphAsymmErrors",
"Invalid histogram pointers");
266 if (!CtorAllocate())
return;
268 std::string sname =
"divide_" + std::string(pass->
GetName()) +
"_by_" +
269 std::string(
total->GetName());
274 pass->TAttLine::Copy(*
this);
275 pass->TAttFill::Copy(*
this);
276 pass->TAttMarker::Copy(*
this);
278 Divide(pass,
total, option);
305 if (!CtorAllocate())
return;
308 gSystem->ExpandPathName(fname);
310 if (!infile.good()) {
312 Error(
"TGraphAsymmErrors",
"Cannot open file: %s, TGraphAsymmErrors is Zombie", filename);
321 if (!option || !*option) {
326 format_ =
"%lg %lg %lg %lg %lg %lg";
328 format_ =
"%lg\t%lg\t%lg\t%lg\t%lg\t%lg";
330 format_ =
"%lg,%lg,%lg,%lg,%lg,%lg";
335 while (std::getline(infile,
line,
'\n')) {
336 exl = exh = eyl = eyh = 0.;
338 res = sscanf(
line.c_str(), format_.
Data(), &
x, &
y);
339 }
else if (ncol < 5) {
340 res = sscanf(
line.c_str(), format_.
Data(), &
x, &
y, &eyl, &eyh);
342 res = sscanf(
line.c_str(), format_.
Data(), &
x, &
y, &exl, &exh, &eyl, &eyh);
348 SetPointError(np, exl, exh, eyl, eyh);
363 Error(
"TGraphAsymmErrors",
"Incorrect input format! Allowed format tags are {\"%%lg\",\"%%*lg\" or \"%%*s\"}");
368 Error(
"TGraphAsymmErrors",
"Incorrect input format! Only %d tag(s) in format whereas at least 2 \"%%lg\" tags are expected!", ntokens);
371 Int_t ntokensToBeSaved = 0;
373 for (
Int_t idx = 0; idx < ntokens; idx++) {
375 if (isTokenToBeSaved[idx] == 1) {
379 if (ntokens >= 2 && (ntokensToBeSaved < 2 || ntokensToBeSaved > 6)) {
380 Error(
"TGraphAsymmErrors",
"Incorrect input format! There are %d \"%%lg\" tag(s) in format whereas 2, 3, 4, 5 or 6 are expected!", ntokensToBeSaved);
381 delete [] isTokenToBeSaved;
387 char *token =
nullptr;
391 for (
Int_t k = 0; k < 6; k++)
397 while (std::getline(infile,
line,
'\n')) {
399 if (
line[
line.size() - 1] ==
char(13)) {
402 token = R__STRTOK_R(
const_cast<char*
>(
line.c_str()), option, &rest) ;
403 while (token !=
nullptr && value_idx < ntokensToBeSaved) {
404 if (isTokenToBeSaved[token_idx]) {
408 isLineToBeSkipped =
kTRUE ;
411 value[value_idx] = token_str.
Atof() ;
415 token = R__STRTOK_R(
nullptr, option, &rest);
418 if (!isLineToBeSkipped && value_idx > 1) {
426 SetPointError(np, exl, exh, eyl, eyh);
430 isLineToBeSkipped =
kFALSE;
438 delete [] isTokenToBeSaved;
484 Double_t x,
y,exl,exh,eyl,eyh,eyl_new,eyh_new,fxy;
502 if (
f->Eval(
x,
y-eyl)<
f->Eval(
x,
y+eyh)) {
605 if(!pass || !
total) {
606 Error(
"Divide",
"one of the passed pointers is zero");
612 Error(
"Divide",
"passed histograms are not one-dimensional");
618 Bool_t bEffective =
false;
624 for (
int i = 0; i < pass->
GetNcells(); ++i) {
638 if (
total->GetSumw2()->fN > 0) {
639 for (
int i = 0; i <
total->GetNcells(); ++i) {
640 tsumw +=
total->GetBinContent(i);
641 tsumw2 +=
total->GetSumw2()->At(i);
645 tsumw =
total->GetSumOfWeights();
660 TString option = opt;
670 Bool_t bIsBayesian =
false;
679 Info(
"Divide",
"weight will be considered in the Histogram Ratio");
687 sscanf(strstr(option.
Data(),
"cl="),
"cl=%lf",&level);
688 if((level > 0) && (level < 1))
691 Warning(
"Divide",
"given confidence level %.3lf is invalid",level);
698 Bool_t usePosteriorMode =
false;
699 Bool_t useShortestInterval =
false;
703 sscanf(strstr(option.
Data(),
"b("),
"b(%lf,%lf)", &
a, &
b);
707 Warning(
"Divide",
"given shape parameter for alpha %.2lf is invalid",
a);
711 Warning(
"Divide",
"given shape parameter for beta %.2lf is invalid",
b);
720 usePosteriorMode =
true;
723 if (option.
Contains(
"sh") || (usePosteriorMode && !option.
Contains(
"cen"))) {
724 useShortestInterval =
true;
759 Bool_t bPoissonRatio =
false;
761 bPoissonRatio =
true;
773 Warning(
"Divide",
"Histograms have weights: only Normal or Bayesian error calculation is supported");
774 Info(
"Divide",
"Using now the Normal approximation for weighted histograms");
779 Error(
"Divide",
"passed histograms are not of the same dimension");
784 Error(
"Divide",
"passed histograms are not consistent");
790 Error(
"Divide",
"passed histograms are not consistent");
805 double eff, low, upper;
810 Double_t tw = 0, tw2 = 0, pw = 0, pw2 = 0, wratio = 1;
821 tw =
total->GetBinContent(
b);
822 tw2 = (
total->GetSumw2()->fN > 0) ?
total->GetSumw2()->At(
b) : tw;
832 if (pw == 0 && pw2 == 0)
837 if (tw == 0 && tw2 == 0)
842 if (pw > 0 && tw > 0)
844 wratio = (pw * t) / (p * tw);
845 else if (pw == 0 && tw > 0)
848 wratio = (psumw2 * t) / (psumw * tw);
849 else if (tw == 0 && pw > 0)
852 wratio = (pw * tsumw) / (p * tsumw2);
857 if (!plot0Bins)
continue;
862 }
else if (tw <= 0 && !plot0Bins)
872 t = std::round(
total->GetBinContent(
b));
878 if (t == 0.0 && !plot0Bins)
886 if ((bEffective && !bPoissonRatio) && tw2 <= 0) {
889 low = eff; upper = eff;
893 if (bEffective && !bPoissonRatio) {
895 double norm = tw/tw2;
896 aa = pw * norm + alpha;
897 bb = (tw - pw) * norm + beta;
900 aa = double(p) + alpha;
901 bb = double(t-p) +
beta;
903 if (usePosteriorMode)
908 if (useShortestInterval) {
919 if (bEffective && !bPoissonRatio) {
928 double variance = ( pw2 * (1. - 2 * eff) + tw2 * eff *eff ) / ( tw * tw) ;
931 double prob = 0.5 * (1.-conf);
935 if (low < 0) low = 0;
936 if (upper > 1) upper = 1.;
944 low = pBound(t,p,conf,
false);
945 upper = pBound(t,p,conf,
true);
953 low = low/(1. - low);
954 upper = upper/(1.-upper);
976 Warning(
"Divide",
"Number of graph points is different than histogram bins - %d points have been skipped",nbins-npoint);
980 Info(
"Divide",
"made a graph with %d points from %d bins",npoint,nbins);
981 Info(
"Divide",
"used confidence level: %.2lf\n",conf);
983 Info(
"Divide",
"used prior probability ~ beta(%.2lf,%.2lf)",alpha,beta);
1053 memmove(&arrays[0][obegin], &
fEXlow[ibegin],
n);
1054 memmove(&arrays[1][obegin], &
fEXhigh[ibegin],
n);
1055 memmove(&arrays[2][obegin], &
fEYlow[ibegin],
n);
1056 memmove(&arrays[3][obegin], &
fEYhigh[ibegin],
n);
1093 if (
g->GetN() == 0)
return kFALSE;
1099 if (exl ==
nullptr || exh ==
nullptr || eyl ==
nullptr || eyh ==
nullptr) {
1101 Warning(
"DoMerge",
"Merging a %s is not compatible with a TGraphAsymmErrors - errors will be ignored",
g->IsA()->GetName());
1104 for (
Int_t i = 0 ; i <
g->GetN(); i++) {
1138 if (i < 0 || i >=
fNpoints)
return -1;
1143 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
1153 if (i < 0 || i >=
fNpoints)
return -1;
1158 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
1217 "Cannot merge - an object which doesn't inherit from TGraph found in the list");
1221 int n1 = n0+
g->GetN();
1229 for (
Int_t i = 0 ; i <
g->GetN(); i++) {
1231 if (exlow)
fEXlow[n0+i] = exlow[i];
1232 if (exhigh)
fEXhigh[n0+i] = exhigh[i];
1233 if (eylow)
fEYlow[n0+i] = eylow[i];
1234 if (eyhigh)
fEYhigh[n0+i] = eyhigh[i];
1246 printf(
"x[%d]=%g, y[%d]=%g, exl[%d]=%g, exh[%d]=%g, eyl[%d]=%g, eyh[%d]=%g\n"
1247 ,i,
fX[i],i,
fY[i],i,
fEXlow[i],i,
fEXhigh[i],i,
fEYlow[i],i,
fEYhigh[i]);
1266 fNpoints, xname.Data(), yname.Data(), exlname.Data(), exhname.Data(),
1267 eylname.Data(), eyhname.Data()),
1283 TString opt = option; opt.
ToLower();
1308 Error(
"SetPointError",
"Cannot be used without gPad, requires last mouse position");
1322 if (dpx*dpx+dpy*dpy < 25) {ipoint = i;
break;}
1324 if (ipoint == -2)
return;
1412 if (
b.IsReading()) {
1414 Version_t R__v =
b.ReadVersion(&R__s, &R__c);
1476 std::vector<Double_t> fEXlowSorted(numSortedPoints);
1477 std::vector<Double_t> fEXhighSorted(numSortedPoints);
1478 std::vector<Double_t> fEYlowSorted(numSortedPoints);
1479 std::vector<Double_t> fEYhighSorted(numSortedPoints);
1482 std::generate(fEXlowSorted.begin(), fEXlowSorted.end(),
1483 [begin = low, &sorting_indices,
this]()
mutable { return fEXlow[sorting_indices[begin++]]; });
1484 std::generate(fEXhighSorted.begin(), fEXhighSorted.end(),
1485 [begin = low, &sorting_indices,
this]()
mutable { return fEXhigh[sorting_indices[begin++]]; });
1486 std::generate(fEYlowSorted.begin(), fEYlowSorted.end(),
1487 [begin = low, &sorting_indices,
this]()
mutable { return fEYlow[sorting_indices[begin++]]; });
1488 std::generate(fEYhighSorted.begin(), fEYhighSorted.end(),
1489 [begin = low, &sorting_indices,
this]()
mutable { return fEYhigh[sorting_indices[begin++]]; });
1492 std::copy(fEXlowSorted.begin(), fEXlowSorted.end(),
fEXlow + low);
1493 std::copy(fEXhighSorted.begin(), fEXhighSorted.end(),
fEXhigh + low);
1494 std::copy(fEYlowSorted.begin(), fEYlowSorted.end(),
fEYlow + low);
1495 std::copy(fEYhighSorted.begin(), fEYhighSorted.end(),
fEYhigh + low);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
short Version_t
Class version identifier (short).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
const char Option_t
Option string (const char).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
static unsigned int total
TVectorT< Double_t > TVectorD
TVectorT< Float_t > TVectorF
Double_t At(Int_t i) const
Buffer base class used for serializing objects.
Collection abstract base class.
static Double_t AgrestiCoull(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
static Double_t BetaMode(Double_t alpha, Double_t beta)
static Bool_t CheckConsistency(const TH1 &pass, const TH1 &total, Option_t *opt="")
static Double_t MidPInterval(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
static Double_t Wilson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
static Double_t Normal(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
static Double_t FeldmanCousins(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
static Double_t BetaCentralInterval(Double_t level, Double_t alpha, Double_t beta, Bool_t bUpper)
static Double_t ClopperPearson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
static Double_t BetaMean(Double_t alpha, Double_t beta)
static Bool_t BetaShortestInterval(Double_t level, Double_t alpha, Double_t beta, Double_t &lower, Double_t &upper)
static Bool_t CheckBinning(const TH1 &pass, const TH1 &total)
Double_t * GetEXlow() const override
Double_t * fEXhigh
[fNpoints] array of X high errors
Double_t GetErrorY(Int_t bin) const override
void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE) override
virtual void SetPointEXlow(Int_t i, Double_t exl)
virtual void SetPointError(Double_t exl, Double_t exh, Double_t eyl, Double_t eyh)
Double_t GetErrorXhigh(Int_t i) const override
Double_t * fEYhigh
[fNpoints] array of Y high errors
Bool_t CopyPoints(Double_t **arrays, Int_t ibegin, Int_t iend, Int_t obegin) override
virtual void AddPointError(Double_t x, Double_t y, Double_t exl=0., Double_t exh=0., Double_t eyl=0., Double_t eyh=0.)
virtual void SetPointEYhigh(Int_t i, Double_t eyh)
void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const override
void Streamer(TBuffer &) override
Stream an object of class TObject.
virtual void Divide(const TH1 *pass, const TH1 *total, Option_t *opt="cp")
virtual void BayesDivide(const TH1 *pass, const TH1 *total, Option_t *opt="")
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
Double_t * GetEYhigh() const override
virtual void SetPointEYlow(Int_t i, Double_t eyl)
void Print(Option_t *chopt="") const override
This method must be overridden when a class wants to print itself.
Double_t GetErrorYhigh(Int_t i) const override
Int_t Merge(TCollection *list) override
Double_t GetErrorXlow(Int_t i) const override
Double_t * fEYlow
[fNpoints] array of Y low errors
void UpdateArrays(const std::vector< Int_t > &sorting_indices, Int_t numSortedPoints, Int_t low) override
void SwapPoints(Int_t pos1, Int_t pos2) override
Double_t * GetEXhigh() const override
Double_t * fEXlow
[fNpoints] array of X low errors
void Apply(TF1 *f) override
Double_t ** Allocate(Int_t size) override
Double_t * GetEYlow() const override
Bool_t DoMerge(const TGraph *g) override
void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin) override
virtual void SetPointEXhigh(Int_t i, Double_t exh)
TClass * IsA() const override
Double_t GetErrorYlow(Int_t i) const override
Double_t GetErrorX(Int_t bin) const override
TGraphAsymmErrors & operator=(const TGraphAsymmErrors &gr)
~TGraphAsymmErrors() override
void Scale(Double_t c1=1., Option_t *option="y") override
static Int_t CalculateScanfFields(const char *fmt)
virtual void AddPoint(Double_t x, Double_t y)
Append a new point to the graph.
Int_t fNpoints
Number of points <= fMaxSize.
Int_t fMaxSize
!Current dimension of arrays fX and fY
virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE)
TH1F * fHistogram
Pointer to histogram used for drawing axis.
virtual Bool_t DoMerge(const TGraph *g)
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
virtual void Scale(Double_t c1=1., Option_t *option="y")
Double_t * fY
[fNpoints] array of Y points
virtual void Set(Int_t n)
Double_t ** AllocateArrays(Int_t Narrays, Int_t arraySize)
void Streamer(TBuffer &) override
Stream an object of class TObject.
virtual void SwapPoints(Int_t pos1, Int_t pos2)
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
virtual Bool_t CopyPoints(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
void SaveHistogramAndFunctions(std::ostream &out, const char *varname, Option_t *option)
Double_t * fX
[fNpoints] array of X points
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
virtual void UpdateArrays(const std::vector< Int_t > &sorting_indices, Int_t numSortedPoints, Int_t low)
TGraph & operator=(const TGraph &)
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 Int_t GetDimension() const
virtual Int_t GetNcells() const
virtual Double_t GetSumOfWeights() const
Return the sum of weights across all bins excluding under/overflows.
virtual Int_t GetNbinsX() const
virtual Double_t GetBinLowEdge(Int_t bin) const
Return bin lower edge for 1D histogram.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual TArrayD * GetSumw2()
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width for 1D histogram.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TObject()
TObject constructor.
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
static TString SavePrimitiveVector(std::ostream &out, const char *prefix, Int_t len, Double_t *arr, Int_t flag=0)
Save array in the output stream "out" as vector.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
void ToLower()
Change string to lower-case.
Int_t Atoi() const
Return integer value of string.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Double_t Atof() const
Return floating-point value contained in string.
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
const char * Data() const
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
TString & ReplaceAll(const TString &s1, const TString &s2)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
double normal_quantile_c(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the upper tail of the normal (Gaussian) distri...
double beta(double x, double y)
Calculates the beta function.
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
double ratio(double numerator, double denominator)
Int_t Finite(Double_t x)
Check if it is finite with a mask in order to be consistent in presence of fast math.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.