140 if (exl)
fEXlow[i] = exl[i];
144 if (eyl)
fEYlow[i] = eyl[i];
163 if(exl) { memcpy(
fEXlow, exl,
n);
164 }
else { memset(
fEXlow, 0,
n); }
167 if(eyl) { memcpy(
fEYlow, eyl,
n);
168 }
else { memset(
fEYlow, 0,
n); }
194 fX[i] = vx(i+ivxlow);
195 fY[i] = vy(i+ivylow);
196 fEXlow[i] = vexl(i+ivexllow);
197 fEYlow[i] = veyl(i+iveyllow);
224 fX[i] = vx(i+ivxlow);
225 fY[i] = vy(i+ivylow);
226 fEXlow[i] = vexl(i+ivexllow);
227 fEYlow[i] = veyl(i+iveyllow);
246 fEYlow[i] =
h->GetBinErrorLow(i+1);
247 fEYhigh[i] =
h->GetBinErrorUp(i+1);;
257 :
TGraph((pass)?pass->GetNbinsX():0)
259 if (!pass || !
total) {
260 Error(
"TGraphAsymmErrors",
"Invalid histogram pointers");
265 std::string sname =
"divide_" + std::string(pass->
GetName()) +
"_by_" +
266 std::string(
total->GetName());
271 pass->TAttLine::Copy(*
this);
272 pass->TAttFill::Copy(*
this);
273 pass->TAttMarker::Copy(*
this);
302 std::ifstream infile(fname.
Data());
303 if (!infile.good()) {
305 Error(
"TGraphAsymmErrors",
"Cannot open file: %s, TGraphAsymmErrors is Zombie", filename);
312 if (strcmp(option,
"") == 0) {
316 while (std::getline(infile,
line,
'\n')) {
317 exl = exh = eyl = eyh = 0;
319 res = sscanf(
line.c_str(), format, &
x, &
y);
320 }
else if (ncol < 5) {
321 res = sscanf(
line.c_str(), format, &
x, &
y, &eyl, &eyh);
323 res = sscanf(
line.c_str(), format, &
x, &
y, &exl, &exh, &eyl, &eyh);
345 Error(
"TGraphAsymmErrors",
"Incorrect input format! Allowed format tags are {\"%%lg\",\"%%*lg\" or \"%%*s\"}");
350 Error(
"TGraphAsymmErrors",
"Incorrect input format! Only %d tag(s) in format whereas at least 2 \"%%lg\" tags are expected!", ntokens);
353 Int_t ntokensToBeSaved = 0 ;
355 for (
Int_t idx = 0; idx < ntokens; idx++) {
357 if (isTokenToBeSaved[idx] == 1) {
361 if (ntokens >= 2 && (ntokensToBeSaved < 2 || ntokensToBeSaved > 4)) {
362 Error(
"TGraphAsymmErrors",
"Incorrect input format! There are %d \"%%lg\" tag(s) in format whereas 2,3 or 4 are expected!", ntokensToBeSaved);
363 delete [] isTokenToBeSaved ;
369 char * token = NULL ;
371 Int_t token_idx = 0 ;
373 for (
Int_t k = 0; k < 6; k++) {
376 Int_t value_idx = 0 ;
380 while (std::getline(infile,
line,
'\n')) {
382 if (
line[
line.size() - 1] ==
char(13)) {
386 while (token != NULL && value_idx < ntokensToBeSaved) {
387 if (isTokenToBeSaved[token_idx]) {
391 isLineToBeSkipped =
kTRUE ;
394 value[value_idx] = token_str.
Atof() ;
401 if (!isLineToBeSkipped && value_idx > 1) {
413 isLineToBeSkipped =
kFALSE ;
421 delete [] isTokenToBeSaved ;
458 Double_t x,
y,exl,exh,eyl,eyh,eyl_new,eyh_new,fxy;
476 if (
f->Eval(
x,
y-eyl)<
f->Eval(
x,
y+eyh)) {
580 if(!pass || !
total) {
581 Error(
"Divide",
"one of the passed pointers is zero");
587 Error(
"Divide",
"passed histograms are not one-dimensional");
593 Bool_t bEffective =
false;
599 for (
int i = 0; i < pass->
GetNcells(); ++i) {
613 if (
total->GetSumw2()->fN > 0) {
614 for (
int i = 0; i <
total->GetNcells(); ++i) {
615 tsumw +=
total->GetBinContent(i);
616 tsumw2 +=
total->GetSumw2()->At(i);
620 tsumw =
total->GetSumOfWeights();
645 Bool_t bIsBayesian =
false;
654 Info(
"Divide",
"weight will be considered in the Histogram Ratio");
662 sscanf(strstr(option.
Data(),
"cl="),
"cl=%lf",&level);
663 if((level > 0) && (level < 1))
666 Warning(
"Divide",
"given confidence level %.3lf is invalid",level);
673 Bool_t usePosteriorMode =
false;
674 Bool_t useShortestInterval =
false;
678 sscanf(strstr(option.
Data(),
"b("),
"b(%lf,%lf)", &
a, &
b);
682 Warning(
"Divide",
"given shape parameter for alpha %.2lf is invalid",
a);
686 Warning(
"Divide",
"given shape parameter for beta %.2lf is invalid",
b);
695 usePosteriorMode =
true;
698 if (option.
Contains(
"sh") || (usePosteriorMode && !option.
Contains(
"cen"))) {
699 useShortestInterval =
true;
734 Bool_t bPoissonRatio =
false;
736 bPoissonRatio =
true;
748 Warning(
"Divide",
"Histograms have weights: only Normal or Bayesian error calculation is supported");
749 Info(
"Divide",
"Using now the Normal approximation for weighted histograms");
754 Error(
"Divide",
"passed histograms are not of the same dimension");
759 Error(
"Divide",
"passed histograms are not consistent");
765 Error(
"Divide",
"passed histograms are not consistent");
780 double eff, low, upper;
785 Double_t tw = 0, tw2 = 0, pw = 0, pw2 = 0, wratio = 1;
796 tw =
total->GetBinContent(
b);
797 tw2 = (
total->GetSumw2()->fN > 0) ?
total->GetSumw2()->At(
b) : tw;
807 if (pw == 0 && pw2 == 0)
812 if (tw == 0 && tw2 == 0)
817 if (pw > 0 && tw > 0)
819 wratio = (pw * t) / (p * tw);
820 else if (pw == 0 && tw > 0)
823 wratio = (psumw2 * t) / (psumw * tw);
824 else if (tw == 0 && pw > 0)
827 wratio = (pw * tsumw) / (p * tsumw2);
832 if (!plot0Bins)
continue;
837 }
else if (tw <= 0 && !plot0Bins)
847 t = std::round(
total->GetBinContent(
b));
853 if (t == 0.0 && !plot0Bins)
861 if ((bEffective && !bPoissonRatio) && tw2 <= 0) {
864 low = eff; upper = eff;
868 if (bEffective && !bPoissonRatio) {
870 double norm = tw/tw2;
871 aa = pw * norm + alpha;
872 bb = (tw - pw) * norm +
beta;
878 if (usePosteriorMode)
883 if (useShortestInterval) {
894 if (bEffective && !bPoissonRatio) {
903 double variance = ( pw2 * (1. - 2 * eff) + tw2 * eff *eff ) / ( tw * tw) ;
906 double prob = 0.5 * (1.-conf);
910 if (low < 0) low = 0;
911 if (upper > 1) upper = 1.;
919 low = pBound(t,p,conf,
false);
920 upper = pBound(t,p,conf,
true);
928 low = low/(1. - low);
929 upper = upper/(1.-upper);
951 Warning(
"Divide",
"Number of graph points is different than histogram bins - %d points have been skipped",nbins-npoint);
955 Info(
"Divide",
"made a graph with %d points from %d bins",npoint,nbins);
956 Info(
"Divide",
"used confidence level: %.2lf\n",conf);
958 Info(
"Divide",
"used prior probability ~ beta(%.2lf,%.2lf)",alpha,
beta);
1028 memmove(&arrays[0][obegin], &
fEXlow[ibegin],
n);
1029 memmove(&arrays[1][obegin], &
fEXhigh[ibegin],
n);
1030 memmove(&arrays[2][obegin], &
fEYlow[ibegin],
n);
1031 memmove(&arrays[3][obegin], &
fEYhigh[ibegin],
n);
1068 if (
g->GetN() == 0)
return kFALSE;
1074 if (exl == 0 || exh == 0 || eyl == 0 || eyh == 0) {
1076 Warning(
"DoMerge",
"Merging a %s is not compatible with a TGraphAsymmErrors - errors will be ignored",
g->IsA()->GetName());
1079 for (
Int_t i = 0 ; i <
g->GetN(); i++) {
1113 if (i < 0 || i >=
fNpoints)
return -1;
1118 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
1128 if (i < 0 || i >=
fNpoints)
return -1;
1133 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
1192 "Cannot merge - an object which doesn't inherit from TGraph found in the list");
1196 int n1 = n0+
g->GetN();
1204 for (
Int_t i = 0 ; i <
g->GetN(); i++) {
1206 if (exlow)
fEXlow[n0+i] = exlow[i];
1207 if (exhigh)
fEXhigh[n0+i] = exhigh[i];
1208 if (eylow)
fEYlow[n0+i] = eylow[i];
1209 if (eyhigh)
fEYhigh[n0+i] = eyhigh[i];
1221 printf(
"x[%d]=%g, y[%d]=%g, exl[%d]=%g, exh[%d]=%g, eyl[%d]=%g, eyh[%d]=%g\n"
1222 ,i,
fX[i],i,
fY[i],i,
fEXlow[i],i,
fEXhigh[i],i,
fEYlow[i],i,
fEYhigh[i]);
1233 out <<
" " << std::endl;
1234 static Int_t frameNumber = 3000;
1244 out <<
" Double_t " << fXName <<
"[" <<
fNpoints <<
"] = {" << std::endl;
1245 for (i = 0; i <
fNpoints-1; i++) out <<
" " <<
fX[i] <<
"," << std::endl;
1246 out <<
" " <<
fX[
fNpoints-1] <<
"};" << std::endl;
1247 out <<
" Double_t " << fYName <<
"[" <<
fNpoints <<
"] = {" << std::endl;
1248 for (i = 0; i <
fNpoints-1; i++) out <<
" " <<
fY[i] <<
"," << std::endl;
1249 out <<
" " <<
fY[
fNpoints-1] <<
"};" << std::endl;
1250 out <<
" Double_t " << fElXName <<
"[" <<
fNpoints <<
"] = {" << std::endl;
1251 for (i = 0; i <
fNpoints-1; i++) out <<
" " <<
fEXlow[i] <<
"," << std::endl;
1253 out <<
" Double_t " << fElYName <<
"[" <<
fNpoints <<
"] = {" << std::endl;
1254 for (i = 0; i <
fNpoints-1; i++) out <<
" " <<
fEYlow[i] <<
"," << std::endl;
1256 out <<
" Double_t " << fEhXName <<
"[" <<
fNpoints <<
"] = {" << std::endl;
1257 for (i = 0; i <
fNpoints-1; i++) out <<
" " <<
fEXhigh[i] <<
"," << std::endl;
1259 out <<
" Double_t " << fEhYName <<
"[" <<
fNpoints <<
"] = {" << std::endl;
1260 for (i = 0; i <
fNpoints-1; i++) out <<
" " <<
fEYhigh[i] <<
"," << std::endl;
1264 else out <<
" TGraphAsymmErrors *";
1265 out <<
"grae = new TGraphAsymmErrors("<<
fNpoints <<
","
1266 << fXName <<
"," << fYName <<
","
1267 << fElXName <<
"," << fEhXName <<
","
1268 << fElYName <<
"," << fEhYName <<
");"
1271 out <<
" grae->SetName(" << quote <<
GetName() << quote <<
");" << std::endl;
1272 out <<
" grae->SetTitle(" << quote <<
GetTitle() << quote <<
");" << std::endl;
1280 hname += frameNumber;
1284 out<<
" "<<std::endl;
1290 while ((obj = next())) {
1293 out <<
" grae->GetListOfFunctions()->Add(ptstats);" << std::endl;
1294 out <<
" ptstats->SetParent(grae->GetListOfFunctions());" << std::endl;
1299 out <<
" " << objname <<
"->SetParent(grae);\n";
1301 out <<
" grae->GetListOfFunctions()->Add("
1302 << objname <<
");" << std::endl;
1306 const char *
l = strstr(option,
"multigraph");
1308 out<<
" multigraph->Add(grae,"<<quote<<
l+10<<quote<<
");"<<std::endl;
1310 out<<
" grae->Draw("<<quote<<option<<quote<<
");"<<std::endl;
1329 if (dpx*dpx+dpy*dpy < 25) {ipoint = i;
break;}
1331 if (ipoint == -2)
return;
1417void TGraphAsymmErrors::Streamer(
TBuffer &
b)
1419 if (
b.IsReading()) {
1421 Version_t R__v =
b.ReadVersion(&R__s, &R__c);
1427 TGraph::Streamer(
b);
1457 b.CheckByteCount(R__s, R__c, TGraphAsymmErrors::IsA());
char * R__STRTOK_R(char *str, const char *delim, char **saveptr)
static unsigned int total
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
Double_t At(Int_t i) const
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
Buffer base class used for serializing objects.
Collection abstract base class.
static Double_t BetaMode(Double_t alpha, Double_t beta)
Compute the mode of the beta distribution.
static Bool_t BetaShortestInterval(Double_t level, Double_t alpha, Double_t beta, Double_t &lower, Double_t &upper)
Calculates the boundaries for a shortest confidence interval for a Beta distribution.
static Double_t BetaMean(Double_t alpha, Double_t beta)
Compute the mean (average) of the beta distribution.
static Double_t AgrestiCoull(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Agresti-Coull interval.
static Double_t FeldmanCousins(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Feldman-Cousins interval.
static Bool_t CheckBinning(const TH1 &pass, const TH1 &total)
Checks binning for each axis.
static Double_t BetaCentralInterval(Double_t level, Double_t alpha, Double_t beta, Bool_t bUpper)
Calculates the boundaries for a central confidence interval for a Beta distribution.
static Double_t MidPInterval(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries using the mid-P binomial interval (Lancaster method) from B.
static Double_t Normal(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Returns the confidence limits for the efficiency supposing that the efficiency follows a normal distr...
static Double_t Wilson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Wilson interval.
static Bool_t CheckConsistency(const TH1 &pass, const TH1 &total, Option_t *opt="")
Checks the consistence of the given histograms.
static Double_t ClopperPearson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Clopper-Pearson interval.
TGraph with asymmetric error bars.
virtual void Print(Option_t *chopt="") const
Print graph and errors values.
virtual Double_t ** Allocate(Int_t size)
Allocate internal data structures for size points.
virtual void SetPointEYlow(Int_t i, Double_t eyl)
Set EYlow for point i.
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Compute Range.
Double_t * fEXhigh
[fNpoints] array of X high errors
virtual ~TGraphAsymmErrors()
TGraphAsymmErrors default destructor.
virtual void Divide(const TH1 *pass, const TH1 *total, Option_t *opt="cp")
Fill this TGraphAsymmErrors by dividing two 1-dimensional histograms pass/total.
Bool_t CtorAllocate()
Should be called from ctors after fNpoints has been set Note: This function should be called only fro...
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 GetErrorYhigh(Int_t i) const
Get high error on Y.
virtual void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy and release.
Double_t * fEYhigh
[fNpoints] array of Y high errors
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
virtual void SetPointEXlow(Int_t i, Double_t exl)
Set EXlow for point i.
Double_t GetErrorYlow(Int_t i) const
Get low error on Y.
virtual void SetPointEYhigh(Int_t i, Double_t eyh)
Set EYhigh for point i.
virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE)
Set zero values for point arrays in the range [begin, end)
virtual void BayesDivide(const TH1 *pass, const TH1 *total, Option_t *opt="")
This function is only kept for backward compatibility.
Double_t GetErrorXlow(Int_t i) const
Get low error on X.
Double_t * fEYlow
[fNpoints] array of Y low errors
Double_t GetErrorXhigh(Int_t i) const
Get high error on X.
virtual void Apply(TF1 *f)
Apply a function to all data points y = f(x,y)
virtual Int_t Merge(TCollection *list)
Adds all graphs with asymmetric errors from the collection to this graph.
Double_t * fEXlow
[fNpoints] array of X low errors
Double_t GetErrorY(Int_t bin) const
This function is called by GraphFitChisquare.
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph with asymmetric errors
virtual void SetPointEXhigh(Int_t i, Double_t exh)
Set EXhigh for point i.
virtual Bool_t CopyPoints(Double_t **arrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy errors from fE*** to arrays[] or to f Copy points.
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
TGraphAsymmErrors()
TGraphAsymmErrors default constructor.
TGraphAsymmErrors & operator=(const TGraphAsymmErrors &gr)
TGraphAsymmErrors assignment operator.
Double_t GetErrorX(Int_t bin) const
This function is called by GraphFitChisquare.
static Int_t CalculateScanfFields(const char *fmt)
Calculate scan fields.
A TGraph is an object made of two arrays X and Y with npoints each.
Int_t fNpoints
Number of points <= fMaxSize.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Int_t fMaxSize
!Current dimension of arrays fX and fY
TH1F * fHistogram
Pointer to histogram used for drawing axis.
virtual void SetName(const char *name="")
Set graph name.
virtual void SetTitle(const char *title="")
Change (i.e.
Double_t * fY
[fNpoints] array of Y points
Bool_t CtorAllocate()
In constructors set fNpoints than call this method.
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Compute the x/y range of the points in this graph.
Double_t ** AllocateArrays(Int_t Narrays, Int_t arraySize)
Allocate arrays.
TList * fFunctions
Pointer to list of functions (fits and user)
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
Swap values.
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE)
Set zero values for point arrays in the range [begin, end) Should be redefined in descendant classes.
Double_t * fX
[fNpoints] array of X points
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
Get x and y values for point number i.
virtual Bool_t CopyPoints(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy points from fX and fY to arrays[0] and arrays[1] or to fX and fY if arrays == 0 and ibegin !...
TGraph & operator=(const TGraph &)
Equal operator for this graph.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
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 Int_t GetNbinsX() const
virtual Double_t GetBinLowEdge(Int_t bin) const
Return bin lower edge for 1D histogram.
virtual void SetName(const char *name)
Change the name of this 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.
virtual Double_t GetSumOfWeights() const
Return the sum of weights excluding under/overflows.
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
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.
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.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Float_t GetErrorX() const
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
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.
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)
Short_t Min(Short_t a, Short_t b)