ROOT  6.06/08
Reference Guide
TGraphAsymmErrors.cxx
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: Rene Brun 03/03/99
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include <string.h>
13 
14 #include "Riostream.h"
15 #include "TEfficiency.h"
16 #include "TROOT.h"
17 #include "TGraphAsymmErrors.h"
18 #include "TStyle.h"
19 #include "TMath.h"
20 #include "TArrow.h"
21 #include "TBox.h"
22 #include "TVirtualPad.h"
23 #include "TF1.h"
24 #include "TH1.h"
25 #include "TVector.h"
26 #include "TVectorD.h"
27 #include "TClass.h"
28 #include "Math/QuantFuncMathCore.h"
29 
31 
32 /** \class TGraphAsymmErrors
33  \ingroup Hist
34 TGraph with assymetric error bars.
35 
36 The TGraphAsymmErrors painting is performed thanks to the TGraphPainter
37 class. All details about the various painting options are given in this class.
38 <p>
39 The picture below gives an example:
40 
41 Begin_Macro(source)
42 {
43  c1 = new TCanvas("c1","A Simple Graph with assymetric error bars",200,10,700,500);
44  c1->SetFillColor(42);
45  c1->SetGrid();
46  c1->GetFrame()->SetFillColor(21);
47  c1->GetFrame()->SetBorderSize(12);
48  const Int_t n = 10;
49  Double_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
50  Double_t y[n] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
51  Double_t exl[n] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
52  Double_t eyl[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
53  Double_t exh[n] = {.02,.08,.05,.05,.03,.03,.04,.05,.06,.03};
54  Double_t eyh[n] = {.6,.5,.4,.3,.2,.2,.3,.4,.5,.6};
55  gr = new TGraphAsymmErrors(n,x,y,exl,exh,eyl,eyh);
56  gr->SetTitle("TGraphAsymmErrors Example");
57  gr->SetMarkerColor(4);
58  gr->SetMarkerStyle(21);
59  gr->Draw("ALP");
60  return c1;
61 }
62 End_Macro
63 */
64 
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// TGraphAsymmErrors default constructor.
68 
70 {
71  fEXlow = 0;
72  fEYlow = 0;
73  fEXhigh = 0;
74  fEYhigh = 0;
75 }
76 
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// TGraphAsymmErrors copy constructor
80 
82  : TGraph(gr)
83 {
84  if (!CtorAllocate()) return;
85  Int_t n = fNpoints*sizeof(Double_t);
86  memcpy(fEXlow, gr.fEXlow, n);
87  memcpy(fEYlow, gr.fEYlow, n);
88  memcpy(fEXhigh, gr.fEXhigh, n);
89  memcpy(fEYhigh, gr.fEYhigh, n);
90 }
91 
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// TGraphAsymmErrors assignment operator
95 
97 {
98  if(this!=&gr) {
100  // delete arrays
101  if (fEXlow) delete [] fEXlow;
102  if (fEYlow) delete [] fEYlow;
103  if (fEXhigh) delete [] fEXhigh;
104  if (fEYhigh) delete [] fEYhigh;
105 
106  if (!CtorAllocate()) return *this;
107  Int_t n = fNpoints*sizeof(Double_t);
108  memcpy(fEXlow, gr.fEXlow, n);
109  memcpy(fEYlow, gr.fEYlow, n);
110  memcpy(fEXhigh, gr.fEXhigh, n);
111  memcpy(fEYhigh, gr.fEYhigh, n);
112  }
113  return *this;
114 }
115 
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// TGraphAsymmErrors normal constructor.
119 ///
120 /// the arrays are preset to zero
121 
123  : TGraph(n)
124 {
125  if (!CtorAllocate()) return;
126  FillZero(0, fNpoints);
127 }
128 
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// TGraphAsymmErrors normal constructor.
132 ///
133 /// if exl,h or eyl,h are null, the corresponding arrays are preset to zero
134 
135 TGraphAsymmErrors::TGraphAsymmErrors(Int_t n, const Float_t *x, const Float_t *y, const Float_t *exl, const Float_t *exh, const Float_t *eyl, const Float_t *eyh)
136  : TGraph(n,x,y)
137 {
138  if (!CtorAllocate()) return;
139 
140  for (Int_t i=0;i<n;i++) {
141  if (exl) fEXlow[i] = exl[i];
142  else fEXlow[i] = 0;
143  if (exh) fEXhigh[i] = exh[i];
144  else fEXhigh[i] = 0;
145  if (eyl) fEYlow[i] = eyl[i];
146  else fEYlow[i] = 0;
147  if (eyh) fEYhigh[i] = eyh[i];
148  else fEYhigh[i] = 0;
149  }
150 }
151 
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// TGraphAsymmErrors normal constructor.
155 ///
156 /// if exl,h or eyl,h are null, the corresponding arrays are preset to zero
157 
158 TGraphAsymmErrors::TGraphAsymmErrors(Int_t n, const Double_t *x, const Double_t *y, const Double_t *exl, const Double_t *exh, const Double_t *eyl, const Double_t *eyh)
159  : TGraph(n,x,y)
160 {
161  if (!CtorAllocate()) return;
162 
163  n = fNpoints*sizeof(Double_t);
164  if(exl) { memcpy(fEXlow, exl, n);
165  } else { memset(fEXlow, 0, n); }
166  if(exh) { memcpy(fEXhigh, exh, n);
167  } else { memset(fEXhigh, 0, n); }
168  if(eyl) { memcpy(fEYlow, eyl, n);
169  } else { memset(fEYlow, 0, n); }
170  if(eyh) { memcpy(fEYhigh, eyh, n);
171  } else { memset(fEYhigh, 0, n); }
172 }
173 
174 
175 ////////////////////////////////////////////////////////////////////////////////
176 /// Constructor with six vectors of floats in input
177 /// A grapherrors is built with the X coordinates taken from vx and Y coord from vy
178 /// and the errors from vectors vexl/h and veyl/h.
179 /// The number of points in the graph is the minimum of number of points
180 /// in vx and vy.
181 
182 TGraphAsymmErrors::TGraphAsymmErrors(const TVectorF &vx, const TVectorF &vy, const TVectorF &vexl, const TVectorF &vexh, const TVectorF &veyl, const TVectorF &veyh)
183  :TGraph()
184 {
185  fNpoints = TMath::Min(vx.GetNrows(), vy.GetNrows());
186  if (!TGraph::CtorAllocate()) return;
187  if (!CtorAllocate()) return;
188  Int_t ivxlow = vx.GetLwb();
189  Int_t ivylow = vy.GetLwb();
190  Int_t ivexllow = vexl.GetLwb();
191  Int_t ivexhlow = vexh.GetLwb();
192  Int_t iveyllow = veyl.GetLwb();
193  Int_t iveyhlow = veyh.GetLwb();
194  for (Int_t i=0;i<fNpoints;i++) {
195  fX[i] = vx(i+ivxlow);
196  fY[i] = vy(i+ivylow);
197  fEXlow[i] = vexl(i+ivexllow);
198  fEYlow[i] = veyl(i+iveyllow);
199  fEXhigh[i] = vexh(i+ivexhlow);
200  fEYhigh[i] = veyh(i+iveyhlow);
201  }
202 }
203 
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Constructor with six vectors of doubles in input
207 /// A grapherrors is built with the X coordinates taken from vx and Y coord from vy
208 /// and the errors from vectors vexl/h and veyl/h.
209 /// The number of points in the graph is the minimum of number of points
210 /// in vx and vy.
211 
212 TGraphAsymmErrors::TGraphAsymmErrors(const TVectorD &vx, const TVectorD &vy, const TVectorD &vexl, const TVectorD &vexh, const TVectorD &veyl, const TVectorD &veyh)
213  :TGraph()
214 {
215  fNpoints = TMath::Min(vx.GetNrows(), vy.GetNrows());
216  if (!TGraph::CtorAllocate()) return;
217  if (!CtorAllocate()) return;
218  Int_t ivxlow = vx.GetLwb();
219  Int_t ivylow = vy.GetLwb();
220  Int_t ivexllow = vexl.GetLwb();
221  Int_t ivexhlow = vexh.GetLwb();
222  Int_t iveyllow = veyl.GetLwb();
223  Int_t iveyhlow = veyh.GetLwb();
224  for (Int_t i=0;i<fNpoints;i++) {
225  fX[i] = vx(i+ivxlow);
226  fY[i] = vy(i+ivylow);
227  fEXlow[i] = vexl(i+ivexllow);
228  fEYlow[i] = veyl(i+iveyllow);
229  fEXhigh[i] = vexh(i+ivexhlow);
230  fEYhigh[i] = veyh(i+iveyhlow);
231  }
232 }
233 
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 /// TGraphAsymmErrors constructor importing its parameters from the TH1 object passed as argument
237 /// the low and high errors are set to the bin error of the histogram.
238 
240  : TGraph(h)
241 {
242  if (!CtorAllocate()) return;
243 
244  for (Int_t i=0;i<fNpoints;i++) {
245  fEXlow[i] = h->GetBinWidth(i+1)*gStyle->GetErrorX();
246  fEXhigh[i] = fEXlow[i];
247  fEYlow[i] = h->GetBinError(i+1);
248  fEYhigh[i] = fEYlow[i];
249  }
250 }
251 
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Creates a TGraphAsymmErrors by dividing two input TH1 histograms:
255 /// pass/total. (see TGraphAsymmErrors::Divide)
256 
258  : TGraph((pass)?pass->GetNbinsX():0)
259 {
260  if (!pass || !total) {
261  Error("TGraphAsymmErrors","Invalid histogram pointers");
262  return;
263  }
264  if (!CtorAllocate()) return;
265 
266  std::string sname = "divide_" + std::string(pass->GetName()) + "_by_" +
267  std::string(total->GetName());
268  SetName(sname.c_str());
269  SetTitle(pass->GetTitle());
270 
271  //copy style from pass
272  pass->TAttLine::Copy(*this);
273  pass->TAttFill::Copy(*this);
274  pass->TAttMarker::Copy(*this);
275 
276  Divide(pass, total, option);
277 }
278 
279 
280 ////////////////////////////////////////////////////////////////////////////////
281 /// TGraphAsymmErrors default destructor.
282 
284 {
285  if(fEXlow) delete [] fEXlow;
286  if(fEXhigh) delete [] fEXhigh;
287  if(fEYlow) delete [] fEYlow;
288  if(fEYhigh) delete [] fEYhigh;
289 }
290 
291 
292 ////////////////////////////////////////////////////////////////////////////////
293 /// apply a function to all data points
294 /// y = f(x,y)
295 ///
296 /// Errors are calculated as eyh = f(x,y+eyh)-f(x,y) and
297 /// eyl = f(x,y)-f(x,y-eyl)
298 ///
299 /// Special treatment has to be applied for the functions where the
300 /// role of "up" and "down" is reversed.
301 /// function suggested/implemented by Miroslav Helbich <helbich@mail.desy.de>
302 
304 {
305  Double_t x,y,exl,exh,eyl,eyh,eyl_new,eyh_new,fxy;
306 
307  if (fHistogram) {
308  delete fHistogram;
309  fHistogram = 0;
310  }
311  for (Int_t i=0;i<GetN();i++) {
312  GetPoint(i,x,y);
313  exl=GetErrorXlow(i);
314  exh=GetErrorXhigh(i);
315  eyl=GetErrorYlow(i);
316  eyh=GetErrorYhigh(i);
317 
318  fxy = f->Eval(x,y);
319  SetPoint(i,x,fxy);
320 
321  // in the case of the functions like y-> -1*y the roles of the
322  // upper and lower error bars is reversed
323  if (f->Eval(x,y-eyl)<f->Eval(x,y+eyh)) {
324  eyl_new = TMath::Abs(fxy - f->Eval(x,y-eyl));
325  eyh_new = TMath::Abs(f->Eval(x,y+eyh) - fxy);
326  }
327  else {
328  eyh_new = TMath::Abs(fxy - f->Eval(x,y-eyl));
329  eyl_new = TMath::Abs(f->Eval(x,y+eyh) - fxy);
330  }
331 
332  //error on x doesn't change
333  SetPointError(i,exl,exh,eyl_new,eyh_new);
334  }
335  if (gPad) gPad->Modified();
336 }
337 
338 ////////////////////////////////////////////////////////////////////////////////
339 ///This function is only kept for backward compatibility.
340 ///You should rather use the Divide method.
341 ///It calls Divide(pass,total,"cl=0.683 b(1,1) mode") which is equivalent to the
342 ///former BayesDivide method.
343 
345 {
346  Divide(pass,total,"cl=0.683 b(1,1) mode");
347 }
348 
349 ////////////////////////////////////////////////////////////////////////////////
350 /// Fill this TGraphAsymmErrors by dividing two 1-dimensional histograms pass/total
351 ///
352 /// This method serves two purposes:
353 ///
354 /// 1) calculating efficiencies:
355 /// ----------------------------
356 ///
357 /// The assumption is that the entries in "pass" are a subset of those in
358 /// "total". That is, we create an "efficiency" graph, where each entry is
359 /// between 0 and 1, inclusive.
360 ///
361 /// If the histograms are not filled with unit weights, the number of effective
362 /// entries is used to normalise the bin contents which might lead to wrong results.
363 /// \f[
364 /// \text{effective entries} = \frac{(\sum w_{i})^{2}}{\sum w_{i}^{2}}
365 /// \f]
366 /// The points are assigned a x value at the center of each histogram bin.
367 /// The y values are \f$\text{eff} = \frac{\text{pass}}{\text{total}}\f$
368 /// for all options except for the
369 /// bayesian methods where the result depends on the chosen option.
370 ///
371 /// If the denominator becomes 0 or pass > total, the corresponding bin is
372 /// skipped.
373 ///
374 /// 2) calculating ratios of two Poisson means (option 'pois'):
375 /// --------------------------------------------------------------
376 ///
377 /// The two histograms are interpreted as independent Poisson processes and the ratio
378 /// \f[
379 /// \tau = \frac{n_{1}}{n_{2}} = \frac{\varepsilon}{1 - \varepsilon}
380 /// \f]
381 /// with \f$\varepsilon = \frac{n_{1}}{n_{1} + n_{2}}\f$.
382 /// The histogram 'pass' is interpreted as \f$n_{1}\f$ and the total histogram
383 /// is used for \f$n_{2}\f$.
384 ///
385 /// The (asymmetric) uncertainties of the Poisson ratio are linked to the uncertainties
386 /// of efficiency by a parameter transformation:
387 /// \f[
388 /// \Delta \tau_{low/up} = \frac{1}{(1 - \varepsilon)^{2}} \Delta \varepsilon_{low/up}
389 /// \f]
390 /// The x errors span each histogram bin (lowedge ... lowedge+width)
391 /// The y errors depend on the chosen statistic methode which can be determined
392 /// by the options given below. For a detailed description of the used statistic
393 /// calculations please have a look at the corresponding functions!
394 ///
395 /// Options:
396 /// - v : verbose mode: prints information about the number of used bins
397 /// and calculated efficiencies with their errors
398 /// - cl=x : determine the used confidence level (0<x<1) (default is 0.683)
399 /// - cp : Clopper-Pearson interval (see TEfficiency::ClopperPearson)
400 /// - w : Wilson interval (see TEfficiency::Wilson)
401 /// - n : normal approximation propagation (see TEfficiency::Normal)
402 /// - ac : Agresti-Coull interval (see TEfficiency::AgrestiCoull)
403 /// - fc : Feldman-Cousins interval (see TEfficiency::FeldmanCousinsInterval)
404 /// - midp : Lancaster mid-P interval (see TEfficiency::MidPInterval)
405 /// - b(a,b): bayesian interval using a prior probability ~Beta(a,b); a,b > 0
406 /// (see TEfficiency::Bayesian)
407 /// - mode : use mode of posterior for Bayesian interval (default is mean)
408 /// - shortest: use shortest interval (done by default if mode is set)
409 /// - central: use central interval (done by default if mode is NOT set)
410 /// - pois: interpret histograms as poisson ratio instead of efficiency
411 /// - e0 : plot (in Bayesian case) efficiency and interval for bins where total=0
412 /// (default is to skip them)
413 ///
414 /// Note:
415 /// Unfortunately there is no straightforward approach for determining a confidence
416 /// interval for a given confidence level. The actual coverage probability of the
417 /// confidence interval oscillates significantly according to the total number of
418 /// events and the true efficiency. In order to decrease the impact of this
419 /// oscillation on the actual coverage probability a couple of approximations and
420 /// methodes has been developped. For a detailed discussion, please have a look at
421 /// this statistical paper:
422 /// http://www-stat.wharton.upenn.edu/~tcai/paper/Binomial-StatSci.pdf
423 
424 void TGraphAsymmErrors::Divide(const TH1* pass, const TH1* total, Option_t *opt)
425 {
426  //check pointers
427  if(!pass || !total) {
428  Error("Divide","one of the passed pointers is zero");
429  return;
430  }
431 
432  //check dimension of histograms; only 1-dimensional ones are accepted
433  if((pass->GetDimension() > 1) || (total->GetDimension() > 1)) {
434  Error("Divide","passed histograms are not one-dimensional");
435  return;
436  }
437 
438  //check whether histograms are filled with weights -> use number of effective
439  //entries
440  Bool_t bEffective = false;
441  //compare sum of weights with sum of squares of weights
442  Double_t stats[TH1::kNstat];
443  pass->GetStats(stats);
444  if (TMath::Abs(stats[0] -stats[1]) > 1e-6)
445  bEffective = true;
446  total->GetStats(stats);
447  if (TMath::Abs(stats[0] -stats[1]) > 1e-6)
448  bEffective = true;
449 
450  // we do not want to ignore the weights
451  // if (bEffective && (pass->GetSumw2()->fN == 0 || total->GetSumw2()->fN == 0) ) {
452  // Warning("Divide","histogram have been computed with weights but the sum of weight squares are not stored in the histogram. Error calculation is performed ignoring the weights");
453  // bEffective = false;
454  // }
455 
456  //parse option
457  TString option = opt;
458  option.ToLower();
459 
460  Bool_t bVerbose = false;
461  //pointer to function returning the boundaries of the confidence interval
462  //(is only used in the frequentist cases.)
463  Double_t (*pBound)(Double_t,Double_t,Double_t,Bool_t) = &TEfficiency::ClopperPearson; // default method
464  //confidence level
465  Double_t conf = 0.682689492137;
466  //values for bayesian statistics
467  Bool_t bIsBayesian = false;
468  Double_t alpha = 1;
469  Double_t beta = 1;
470 
471  //verbose mode
472  if(option.Contains("v")) {
473  option.ReplaceAll("v","");
474  bVerbose = true;
475  }
476 
477  //confidence level
478  if(option.Contains("cl=")) {
479  Double_t level = -1;
480  // coverity [secure_coding : FALSE]
481  sscanf(strstr(option.Data(),"cl="),"cl=%lf",&level);
482  if((level > 0) && (level < 1))
483  conf = level;
484  else
485  Warning("Divide","given confidence level %.3lf is invalid",level);
486  option.ReplaceAll("cl=","");
487  }
488 
489  //normal approximation
490  if(option.Contains("n")) {
491  option.ReplaceAll("n","");
492  pBound = &TEfficiency::Normal;
493  }
494 
495  //clopper pearson interval
496  if(option.Contains("cp")) {
497  option.ReplaceAll("cp","");
498  pBound = &TEfficiency::ClopperPearson;
499  }
500 
501  //wilson interval
502  if(option.Contains("w")) {
503  option.ReplaceAll("w","");
504  pBound = &TEfficiency::Wilson;
505  }
506 
507  //agresti coull interval
508  if(option.Contains("ac")) {
509  option.ReplaceAll("ac","");
510  pBound = &TEfficiency::AgrestiCoull;
511  }
512  // Feldman-Cousins interval
513  if(option.Contains("fc")) {
514  option.ReplaceAll("fc","");
515  pBound = &TEfficiency::FeldmanCousins;
516  }
517  // mid-P Lancaster interval
518  if(option.Contains("midp")) {
519  option.ReplaceAll("midp","");
520  pBound = &TEfficiency::MidPInterval;
521  }
522 
523  //bayesian with prior
524  if(option.Contains("b(")) {
525  Double_t a = 0;
526  Double_t b = 0;
527  sscanf(strstr(option.Data(),"b("),"b(%lf,%lf)",&a,&b);
528  if(a > 0)
529  alpha = a;
530  else
531  Warning("Divide","given shape parameter for alpha %.2lf is invalid",a);
532  if(b > 0)
533  beta = b;
534  else
535  Warning("Divide","given shape parameter for beta %.2lf is invalid",b);
536  option.ReplaceAll("b(","");
537  bIsBayesian = true;
538  }
539 
540  // use posterior mode
541  Bool_t usePosteriorMode = false;
542  if(bIsBayesian && option.Contains("mode") ) {
543  usePosteriorMode = true;
544  option.ReplaceAll("mode","");
545  }
546 
547  Bool_t plot0Bins = false;
548  if(option.Contains("e0") ) {
549  plot0Bins = true;
550  option.ReplaceAll("e0","");
551  }
552 
553  Bool_t useShortestInterval = false;
554  if (bIsBayesian && ( option.Contains("sh") || (usePosteriorMode && !option.Contains("cen") ) ) ) {
555  useShortestInterval = true;
556  }
557 
558  // interpret as Poisson ratio
559  Bool_t bPoissonRatio = false;
560  if(option.Contains("pois") ) {
561  bPoissonRatio = true;
562  option.ReplaceAll("pois","");
563  }
564 
565  // weights works only in case of Normal approximation or Bayesian for binomial interval
566  // in case of Poisson ratio we can use weights by rescaling the obtained results using the effective entries
567  if ( ( bEffective && !bPoissonRatio) && !bIsBayesian && pBound != &TEfficiency::Normal ) {
568  Warning("Divide","Histograms have weights: only Normal or Bayesian error calculation is supported");
569  Info("Divide","Using now the Normal approximation for weighted histograms");
570  }
571 
572  if(bPoissonRatio)
573  {
574  if(pass->GetDimension() != total->GetDimension()) {
575  Error("Divide","passed histograms are not of the same dimension");
576  return;
577  }
578 
579  if(!TEfficiency::CheckBinning(*pass,*total)) {
580  Error("Divide","passed histograms are not consistent");
581  return;
582  }
583  }
584  else
585  {
586  //check consistency of histograms, allowing weights
587  if(!TEfficiency::CheckConsistency(*pass,*total,"w")) {
588  Error("Divide","passed histograms are not consistent");
589  return;
590  }
591  }
592 
593  //Set the graph to have a number of points equal to the number of histogram
594  //bins
595  Int_t nbins = pass->GetNbinsX();
596  Set(nbins);
597 
598  // Ok, now set the points for each bin
599  // (Note: the TH1 bin content is shifted to the right by one:
600  // bin=0 is underflow, bin=nbins+1 is overflow.)
601 
602  //efficiency with lower and upper boundary of confidence interval
603  double eff, low, upper;
604  //this keeps track of the number of points added to the graph
605  int npoint=0;
606  //number of total and passed events
607  Double_t t = 0 , p = 0;
608  Double_t tw = 0, tw2 = 0, pw = 0, pw2 = 0, wratio = 1; // for the case of weights
609  //loop over all bins and fill the graph
610  for (Int_t b=1; b<=nbins; ++b) {
611 
612  // default value when total =0;
613  eff = 0;
614  low = 0;
615  upper = 0;
616 
617  // special case in case of weights we have to consider the sum of weights and the sum of weight squares
618  if(bEffective) {
619  tw = total->GetBinContent(b);
620  tw2 = (total->GetSumw2()->fN > 0) ? total->GetSumw2()->At(b) : tw;
621  pw = pass->GetBinContent(b);
622  pw2 = (pass->GetSumw2()->fN > 0) ? pass->GetSumw2()->At(b) : pw;
623 
624  if(bPoissonRatio)
625  {
626  // tw += pw;
627  // tw2 += pw2;
628  // compute effective entries
629  // special case is (pw=0, pw2=0) in this case is like unweighted
630  if (pw == 0 && pw2 == 0)
631  p = pw;
632  else
633  p = (pw*pw)/pw2;
634 
635  if (tw == 0 && tw2 == 0)
636  t = tw;
637  else
638  t = (tw*tw)/tw2;
639 
640  if (p > 0 && tw > 0)
641  wratio = (pw*t)/(p * tw);
642  else if (p == 0 && tw > 0)
643  wratio = t/tw;
644  else if (p > 0)
645  wratio = pw/p;
646  else {
647  // case both pw and tw are zero - we skip these bins
648  if (!plot0Bins) continue; // skip bins with total <= 0
649  }
650 
651  t += p;
652  }
653  else
654  if (tw <= 0 && !plot0Bins) continue; // skip bins with total <= 0
655 
656  // in the case of weights have the formula only for
657  // the normal and bayesian statistics (see below)
658 
659  }
660 
661  //use bin contents
662  else {
663  t = int( total->GetBinContent(b) + 0.5);
664  p = int(pass->GetBinContent(b) + 0.5);
665 
666  if(bPoissonRatio) t += p;
667 
668  if (!t && !plot0Bins) continue; // skip bins with total = 0
669  }
670 
671 
672  //using bayesian statistics
673  if(bIsBayesian) {
674  double aa,bb;
675 
676  if ((bEffective && !bPoissonRatio) && tw2 <= 0) {
677  // case of bins with zero errors
678  eff = pw/tw;
679  low = eff; upper = eff;
680  }
681  else {
682 
683  if (bEffective && !bPoissonRatio) {
684  // tw/tw2 renormalize the weights
685  double norm = tw/tw2; // case of tw2 = 0 is treated above
686  aa = pw * norm + alpha;
687  bb = (tw - pw) * norm + beta;
688  }
689  else {
690  aa = double(p) + alpha;
691  bb = double(t-p) + beta;
692  }
693  if (usePosteriorMode)
694  eff = TEfficiency::BetaMode(aa,bb);
695  else
696  eff = TEfficiency::BetaMean(aa,bb);
697 
698  if (useShortestInterval) {
699  TEfficiency::BetaShortestInterval(conf,aa,bb,low,upper);
700  }
701  else {
702  low = TEfficiency::BetaCentralInterval(conf,aa,bb,false);
703  upper = TEfficiency::BetaCentralInterval(conf,aa,bb,true);
704  }
705  }
706  }
707  // case of non-bayesian statistics
708  else {
709  if (bEffective && !bPoissonRatio) {
710 
711  if (tw > 0) {
712 
713  eff = pw/tw;
714 
715  // use normal error calculation using variance of MLE with weights (F.James 8.5.2)
716  // this is the same formula used in ROOT for TH1::Divide("B")
717 
718  double variance = ( pw2 * (1. - 2 * eff) + tw2 * eff *eff ) / ( tw * tw) ;
719  double sigma = sqrt(variance);
720 
721  double prob = 0.5 * (1.-conf);
722  double delta = ROOT::Math::normal_quantile_c(prob, sigma);
723  low = eff - delta;
724  upper = eff + delta;
725  if (low < 0) low = 0;
726  if (upper > 1) upper = 1.;
727  }
728  }
729  else {
730  // when not using weights (all cases) or in case of Poisson ratio with weights
731  if(t)
732  eff = ((Double_t)p)/t;
733 
734  low = pBound(t,p,conf,false);
735  upper = pBound(t,p,conf,true);
736  }
737  }
738  // treat as Poisson ratio
739  if(bPoissonRatio)
740  {
741  Double_t ratio = eff/(1 - eff);
742  // take the intervals in eff as intervals in the Poisson ratio
743  low = low/(1. - low);
744  upper = upper/(1.-upper);
745  eff = ratio;
746  if (bEffective) {
747  //scale result by the ratio of the weight
748  eff *= wratio;
749  low *= wratio;
750  upper *= wratio;
751  }
752  }
753  //Set the point center and its errors
754  SetPoint(npoint,pass->GetBinCenter(b),eff);
755  SetPointError(npoint,
756  pass->GetBinCenter(b)-pass->GetBinLowEdge(b),
757  pass->GetBinLowEdge(b)-pass->GetBinCenter(b)+pass->GetBinWidth(b),
758  eff-low,upper-eff);
759  npoint++;//we have added a point to the graph
760  }
761 
762  Set(npoint);//tell the graph how many points we've really added
763  if (npoint < nbins)
764  Warning("Divide","Number of graph points is different than histogram bins - %d points have been skipped",nbins-npoint);
765 
766 
767  if (bVerbose) {
768  Info("Divide","made a graph with %d points from %d bins",npoint,nbins);
769  Info("Divide","used confidence level: %.2lf\n",conf);
770  if(bIsBayesian)
771  Info("Divide","used prior probability ~ beta(%.2lf,%.2lf)",alpha,beta);
772  Print();
773  }
774 }
775 
776 ////////////////////////////////////////////////////////////////////////////////
777 /// Compute Range
778 
780 {
781  TGraph::ComputeRange(xmin,ymin,xmax,ymax);
782 
783  for (Int_t i=0;i<fNpoints;i++) {
784  if (fX[i] -fEXlow[i] < xmin) {
785  if (gPad && gPad->GetLogx()) {
786  if (fEXlow[i] < fX[i]) xmin = fX[i]-fEXlow[i];
787  else xmin = TMath::Min(xmin,fX[i]/3);
788  } else {
789  xmin = fX[i]-fEXlow[i];
790  }
791  }
792  if (fX[i] +fEXhigh[i] > xmax) xmax = fX[i]+fEXhigh[i];
793  if (fY[i] -fEYlow[i] < ymin) {
794  if (gPad && gPad->GetLogy()) {
795  if (fEYlow[i] < fY[i]) ymin = fY[i]-fEYlow[i];
796  else ymin = TMath::Min(ymin,fY[i]/3);
797  } else {
798  ymin = fY[i]-fEYlow[i];
799  }
800  }
801  if (fY[i] +fEYhigh[i] > ymax) ymax = fY[i]+fEYhigh[i];
802  }
803 }
804 
805 
806 ////////////////////////////////////////////////////////////////////////////////
807 /// Copy and release.
808 
810  Int_t ibegin, Int_t iend, Int_t obegin)
811 {
812  CopyPoints(newarrays, ibegin, iend, obegin);
813  if (newarrays) {
814  delete[] fEXlow;
815  fEXlow = newarrays[0];
816  delete[] fEXhigh;
817  fEXhigh = newarrays[1];
818  delete[] fEYlow;
819  fEYlow = newarrays[2];
820  delete[] fEYhigh;
821  fEYhigh = newarrays[3];
822  delete[] fX;
823  fX = newarrays[4];
824  delete[] fY;
825  fY = newarrays[5];
826  delete[] newarrays;
827  }
828 }
829 
830 
831 ////////////////////////////////////////////////////////////////////////////////
832 /// Copy errors from fE*** to arrays[***]
833 /// or to f*** Copy points.
834 
836  Int_t ibegin, Int_t iend, Int_t obegin)
837 {
838  if (TGraph::CopyPoints(arrays ? arrays+4 : 0, ibegin, iend, obegin)) {
839  Int_t n = (iend - ibegin)*sizeof(Double_t);
840  if (arrays) {
841  memmove(&arrays[0][obegin], &fEXlow[ibegin], n);
842  memmove(&arrays[1][obegin], &fEXhigh[ibegin], n);
843  memmove(&arrays[2][obegin], &fEYlow[ibegin], n);
844  memmove(&arrays[3][obegin], &fEYhigh[ibegin], n);
845  } else {
846  memmove(&fEXlow[obegin], &fEXlow[ibegin], n);
847  memmove(&fEXhigh[obegin], &fEXhigh[ibegin], n);
848  memmove(&fEYlow[obegin], &fEYlow[ibegin], n);
849  memmove(&fEYhigh[obegin], &fEYhigh[ibegin], n);
850  }
851  return kTRUE;
852  } else {
853  return kFALSE;
854  }
855 }
856 
857 
858 ////////////////////////////////////////////////////////////////////////////////
859 /// Should be called from ctors after fNpoints has been set
860 /// Note: This function should be called only from the constructor
861 /// since it does not delete previously existing arrays
862 
864 {
865  if (!fNpoints) {
866  fEXlow = fEYlow = fEXhigh = fEYhigh = 0;
867  return kFALSE;
868  }
869  fEXlow = new Double_t[fMaxSize];
870  fEYlow = new Double_t[fMaxSize];
871  fEXhigh = new Double_t[fMaxSize];
872  fEYhigh = new Double_t[fMaxSize];
873  return kTRUE;
874 }
875 
876 ////////////////////////////////////////////////////////////////////////////////
877 /// protected function to perform the merge operation of a graph with asymmetric errors
878 
880 {
881  if (g->GetN() == 0) return kFALSE;
882 
883  Double_t * exl = g->GetEXlow();
884  Double_t * exh = g->GetEXhigh();
885  Double_t * eyl = g->GetEYlow();
886  Double_t * eyh = g->GetEYhigh();
887  if (exl == 0 || exh == 0 || eyl == 0 || eyh == 0) {
888  if (g->IsA() != TGraph::Class() )
889  Warning("DoMerge","Merging a %s is not compatible with a TGraphAsymmErrors - errors will be ignored",g->IsA()->GetName());
890  return TGraph::DoMerge(g);
891  }
892  for (Int_t i = 0 ; i < g->GetN(); i++) {
893  Int_t ipoint = GetN();
894  Double_t x = g->GetX()[i];
895  Double_t y = g->GetY()[i];
896  SetPoint(ipoint, x, y);
897  SetPointError(ipoint, exl[i], exh[i], eyl[i], eyh[i] );
898  }
899 
900  return kTRUE;
901 }
902 
903 ////////////////////////////////////////////////////////////////////////////////
904 /// Set zero values for point arrays in the range [begin, end)
905 
907  Bool_t from_ctor)
908 {
909  if (!from_ctor) {
910  TGraph::FillZero(begin, end, from_ctor);
911  }
912  Int_t n = (end - begin)*sizeof(Double_t);
913  memset(fEXlow + begin, 0, n);
914  memset(fEXhigh + begin, 0, n);
915  memset(fEYlow + begin, 0, n);
916  memset(fEYhigh + begin, 0, n);
917 }
918 
919 
920 ////////////////////////////////////////////////////////////////////////////////
921 /// This function is called by GraphFitChisquare.
922 /// It returns the error along X at point i.
923 
925 {
926  if (i < 0 || i >= fNpoints) return -1;
927  if (!fEXlow && !fEXhigh) return -1;
928  Double_t elow=0, ehigh=0;
929  if (fEXlow) elow = fEXlow[i];
930  if (fEXhigh) ehigh = fEXhigh[i];
931  return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
932 }
933 
934 
935 ////////////////////////////////////////////////////////////////////////////////
936 /// This function is called by GraphFitChisquare.
937 /// It returns the error along Y at point i.
938 
940 {
941  if (i < 0 || i >= fNpoints) return -1;
942  if (!fEYlow && !fEYhigh) return -1;
943  Double_t elow=0, ehigh=0;
944  if (fEYlow) elow = fEYlow[i];
945  if (fEYhigh) ehigh = fEYhigh[i];
946  return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
947 }
948 
949 
950 ////////////////////////////////////////////////////////////////////////////////
951 /// Get high error on X.
952 
954 {
955  if (i<0 || i>fNpoints) return -1;
956  if (fEXhigh) return fEXhigh[i];
957  return -1;
958 }
959 
960 
961 ////////////////////////////////////////////////////////////////////////////////
962 /// Get low error on X.
963 
965 {
966  if (i<0 || i>fNpoints) return -1;
967  if (fEXlow) return fEXlow[i];
968  return -1;
969 }
970 
971 
972 ////////////////////////////////////////////////////////////////////////////////
973 /// Get high error on Y.
974 
976 {
977  if (i<0 || i>fNpoints) return -1;
978  if (fEYhigh) return fEYhigh[i];
979  return -1;
980 }
981 
982 
983 ////////////////////////////////////////////////////////////////////////////////
984 /// Get low error on Y.
985 
987 {
988  if (i<0 || i>fNpoints) return -1;
989  if (fEYlow) return fEYlow[i];
990  return -1;
991 }
992 
993 
994 ////////////////////////////////////////////////////////////////////////////////
995 /// Adds all graphs with asymmetric errors from the collection to this graph.
996 /// Returns the total number of poins in the result or -1 in case of an error.
997 
999 {
1000  TIter next(li);
1001  while (TObject* o = next()) {
1002  TGraph *g = dynamic_cast<TGraph*>(o);
1003  if (!g) {
1004  Error("Merge",
1005  "Cannot merge - an object which doesn't inherit from TGraph found in the list");
1006  return -1;
1007  }
1008  int n0 = GetN();
1009  int n1 = n0+g->GetN();
1010  Set(n1);
1011  Double_t * x = g->GetX();
1012  Double_t * y = g->GetY();
1013  Double_t * exlow = g->GetEXlow();
1014  Double_t * exhigh = g->GetEXhigh();
1015  Double_t * eylow = g->GetEYlow();
1016  Double_t * eyhigh = g->GetEYhigh();
1017  for (Int_t i = 0 ; i < g->GetN(); i++) {
1018  SetPoint(n0+i, x[i], y[i]);
1019  if (exlow) fEXlow[n0+i] = exlow[i];
1020  if (exhigh) fEXhigh[n0+i] = exhigh[i];
1021  if (eylow) fEYlow[n0+i] = eylow[i];
1022  if (eyhigh) fEYhigh[n0+i] = eyhigh[i];
1023  }
1024  }
1025  return GetN();
1026 }
1027 
1028 ////////////////////////////////////////////////////////////////////////////////
1029 /// Print graph and errors values.
1030 
1032 {
1033  for (Int_t i=0;i<fNpoints;i++) {
1034  printf("x[%d]=%g, y[%d]=%g, exl[%d]=%g, exh[%d]=%g, eyl[%d]=%g, eyh[%d]=%g\n"
1035  ,i,fX[i],i,fY[i],i,fEXlow[i],i,fEXhigh[i],i,fEYlow[i],i,fEYhigh[i]);
1036  }
1037 }
1038 
1039 
1040 ////////////////////////////////////////////////////////////////////////////////
1041 /// Save primitive as a C++ statement(s) on output stream out
1042 
1043 void TGraphAsymmErrors::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1044 {
1045  char quote = '"';
1046  out << " " << std::endl;
1047  static Int_t frameNumber = 3000;
1048  frameNumber++;
1049 
1050  Int_t i;
1051  TString fXName = TString(GetName()) + Form("_fx%d",frameNumber);
1052  TString fYName = TString(GetName()) + Form("_fy%d",frameNumber);
1053  TString fElXName = TString(GetName()) + Form("_felx%d",frameNumber);
1054  TString fElYName = TString(GetName()) + Form("_fely%d",frameNumber);
1055  TString fEhXName = TString(GetName()) + Form("_fehx%d",frameNumber);
1056  TString fEhYName = TString(GetName()) + Form("_fehy%d",frameNumber);
1057  out << " Double_t " << fXName << "[" << fNpoints << "] = {" << std::endl;
1058  for (i = 0; i < fNpoints-1; i++) out << " " << fX[i] << "," << std::endl;
1059  out << " " << fX[fNpoints-1] << "};" << std::endl;
1060  out << " Double_t " << fYName << "[" << fNpoints << "] = {" << std::endl;
1061  for (i = 0; i < fNpoints-1; i++) out << " " << fY[i] << "," << std::endl;
1062  out << " " << fY[fNpoints-1] << "};" << std::endl;
1063  out << " Double_t " << fElXName << "[" << fNpoints << "] = {" << std::endl;
1064  for (i = 0; i < fNpoints-1; i++) out << " " << fEXlow[i] << "," << std::endl;
1065  out << " " << fEXlow[fNpoints-1] << "};" << std::endl;
1066  out << " Double_t " << fElYName << "[" << fNpoints << "] = {" << std::endl;
1067  for (i = 0; i < fNpoints-1; i++) out << " " << fEYlow[i] << "," << std::endl;
1068  out << " " << fEYlow[fNpoints-1] << "};" << std::endl;
1069  out << " Double_t " << fEhXName << "[" << fNpoints << "] = {" << std::endl;
1070  for (i = 0; i < fNpoints-1; i++) out << " " << fEXhigh[i] << "," << std::endl;
1071  out << " " << fEXhigh[fNpoints-1] << "};" << std::endl;
1072  out << " Double_t " << fEhYName << "[" << fNpoints << "] = {" << std::endl;
1073  for (i = 0; i < fNpoints-1; i++) out << " " << fEYhigh[i] << "," << std::endl;
1074  out << " " << fEYhigh[fNpoints-1] << "};" << std::endl;
1075 
1076  if (gROOT->ClassSaved(TGraphAsymmErrors::Class())) out<<" ";
1077  else out << " TGraphAsymmErrors *";
1078  out << "grae = new TGraphAsymmErrors("<< fNpoints << ","
1079  << fXName << "," << fYName << ","
1080  << fElXName << "," << fEhXName << ","
1081  << fElYName << "," << fEhYName << ");"
1082  << std::endl;
1083 
1084  out << " grae->SetName(" << quote << GetName() << quote << ");" << std::endl;
1085  out << " grae->SetTitle(" << quote << GetTitle() << quote << ");" << std::endl;
1086 
1087  SaveFillAttributes(out, "grae", 0, 1001);
1088  SaveLineAttributes(out, "grae", 1, 1, 1);
1089  SaveMarkerAttributes(out, "grae", 1, 1, 1);
1090 
1091  if (fHistogram) {
1092  TString hname = fHistogram->GetName();
1093  hname += frameNumber;
1094  fHistogram->SetName(Form("Graph_%s",hname.Data()));
1095  fHistogram->SavePrimitive(out,"nodraw");
1096  out<<" grae->SetHistogram("<<fHistogram->GetName()<<");"<<std::endl;
1097  out<<" "<<std::endl;
1098  }
1099 
1100  // save list of functions
1101  TIter next(fFunctions);
1102  TObject *obj;
1103  while ((obj = next())) {
1104  obj->SavePrimitive(out, Form("nodraw #%d\n",++frameNumber));
1105  if (obj->InheritsFrom("TPaveStats")) {
1106  out << " grae->GetListOfFunctions()->Add(ptstats);" << std::endl;
1107  out << " ptstats->SetParent(grae->GetListOfFunctions());" << std::endl;
1108  } else {
1109  out << " grae->GetListOfFunctions()->Add("
1110  << Form("%s%d",obj->GetName(),frameNumber) << ");" << std::endl;
1111  }
1112  }
1113 
1114  const char *l = strstr(option,"multigraph");
1115  if (l) {
1116  out<<" multigraph->Add(grae,"<<quote<<l+10<<quote<<");"<<std::endl;
1117  } else {
1118  out<<" grae->Draw("<<quote<<option<<quote<<");"<<std::endl;
1119  }
1120 }
1121 
1122 ////////////////////////////////////////////////////////////////////////////////
1123 /// Set ex and ey values for point pointed by the mouse.
1124 
1126 {
1127  Int_t px = gPad->GetEventX();
1128  Int_t py = gPad->GetEventY();
1129 
1130  //localize point to be deleted
1131  Int_t ipoint = -2;
1132  Int_t i;
1133  // start with a small window (in case the mouse is very close to one point)
1134  for (i=0;i<fNpoints;i++) {
1135  Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
1136  Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
1137  if (dpx*dpx+dpy*dpy < 25) {ipoint = i; break;}
1138  }
1139  if (ipoint == -2) return;
1140 
1141  fEXlow[ipoint] = exl;
1142  fEYlow[ipoint] = eyl;
1143  fEXhigh[ipoint] = exh;
1144  fEYhigh[ipoint] = eyh;
1145  gPad->Modified();
1146 }
1147 
1148 
1149 ////////////////////////////////////////////////////////////////////////////////
1150 /// Set ex and ey values for point number i.
1151 
1153 {
1154  if (i < 0) return;
1155  if (i >= fNpoints) {
1156  // re-allocate the object
1158  }
1159  fEXlow[i] = exl;
1160  fEYlow[i] = eyl;
1161  fEXhigh[i] = exh;
1162  fEYhigh[i] = eyh;
1163 }
1164 
1165 
1166 ////////////////////////////////////////////////////////////////////////////////
1167 /// Set EXlow for point i
1168 
1170 {
1171  if (i < 0) return;
1172  if (i >= fNpoints) {
1173  // re-allocate the object
1175  }
1176  fEXlow[i] = exl;
1177 }
1178 
1179 
1180 ////////////////////////////////////////////////////////////////////////////////
1181 /// Set EXhigh for point i
1182 
1184 {
1185  if (i < 0) return;
1186  if (i >= fNpoints) {
1187  // re-allocate the object
1189  }
1190  fEXhigh[i] = exh;
1191 }
1192 
1193 
1194 ////////////////////////////////////////////////////////////////////////////////
1195 /// Set EYlow for point i
1196 
1198 {
1199  if (i < 0) return;
1200  if (i >= fNpoints) {
1201  // re-allocate the object
1203  }
1204  fEYlow[i] = eyl;
1205 }
1206 
1207 
1208 ////////////////////////////////////////////////////////////////////////////////
1209 /// Set EYhigh for point i
1210 
1212 {
1213  if (i < 0) return;
1214  if (i >= fNpoints) {
1215  // re-allocate the object
1217  }
1218  fEYhigh[i] = eyh;
1219 }
1220 
1221 
1222 ////////////////////////////////////////////////////////////////////////////////
1223 /// Stream an object of class TGraphAsymmErrors.
1224 
1225 void TGraphAsymmErrors::Streamer(TBuffer &b)
1226 {
1227  if (b.IsReading()) {
1228  UInt_t R__s, R__c;
1229  Version_t R__v = b.ReadVersion(&R__s, &R__c);
1230  if (R__v > 2) {
1231  b.ReadClassBuffer(TGraphAsymmErrors::Class(), this, R__v, R__s, R__c);
1232  return;
1233  }
1234  //====process old versions before automatic schema evolution
1235  TGraph::Streamer(b);
1236  fEXlow = new Double_t[fNpoints];
1237  fEYlow = new Double_t[fNpoints];
1238  fEXhigh = new Double_t[fNpoints];
1239  fEYhigh = new Double_t[fNpoints];
1240  if (R__v < 2) {
1241  Float_t *exlow = new Float_t[fNpoints];
1242  Float_t *eylow = new Float_t[fNpoints];
1243  Float_t *exhigh = new Float_t[fNpoints];
1244  Float_t *eyhigh = new Float_t[fNpoints];
1245  b.ReadFastArray(exlow,fNpoints);
1246  b.ReadFastArray(eylow,fNpoints);
1247  b.ReadFastArray(exhigh,fNpoints);
1248  b.ReadFastArray(eyhigh,fNpoints);
1249  for (Int_t i=0;i<fNpoints;i++) {
1250  fEXlow[i] = exlow[i];
1251  fEYlow[i] = eylow[i];
1252  fEXhigh[i] = exhigh[i];
1253  fEYhigh[i] = eyhigh[i];
1254  }
1255  delete [] eylow;
1256  delete [] exlow;
1257  delete [] eyhigh;
1258  delete [] exhigh;
1259  } else {
1264  }
1265  b.CheckByteCount(R__s, R__c, TGraphAsymmErrors::IsA());
1266  //====end of old versions
1267 
1268  } else {
1270  }
1271 }
1272 
1273 
1274 ////////////////////////////////////////////////////////////////////////////////
1275 /// Swap points.
1276 
1278 {
1279  SwapValues(fEXlow, pos1, pos2);
1280  SwapValues(fEXhigh, pos1, pos2);
1281  SwapValues(fEYlow, pos1, pos2);
1282  SwapValues(fEYhigh, pos1, pos2);
1283  TGraph::SwapPoints(pos1, pos2);
1284 }
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TH1.cxx:6729
Int_t fNpoints
Current dimension of arrays fX and fY.
Definition: TGraph.h:58
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
Bool_t IsReading() const
Definition: TBuffer.h:81
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.
float xmin
Definition: THbookFile.cxx:93
Double_t * fX
Definition: TGraph.h:59
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual Double_t GetBinCenter(Int_t bin) const
return bin center for 1D historam Better to use h1.GetXaxis().GetBinCenter(bin)
Definition: TH1.cxx:8476
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Compute Range.
Double_t GetErrorY(Int_t bin) const
This function is called by GraphFitChisquare.
short Version_t
Definition: RtypesCore.h:61
float Float_t
Definition: RtypesCore.h:53
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.
const char Option_t
Definition: RtypesCore.h:62
Double_t GetErrorX(Int_t bin) const
This function is called by GraphFitChisquare.
float ymin
Definition: THbookFile.cxx:93
double normal_quantile_c(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the upper tail of the normal (Gaussian) distri...
virtual Double_t * GetEYlow() const
Definition: TGraph.h:146
Double_t GetErrorYlow(Int_t i) const
Get low error on Y.
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
virtual void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy and release.
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
Int_t GetLwb() const
Definition: TVectorT.h:79
static Bool_t CheckBinning(const TH1 &pass, const TH1 &total)
Checks binning for each axis.
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
TH1 * h
Definition: legend2.C:5
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4635
Double_t GetErrorYhigh(Int_t i) const
Get high error on Y.
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
virtual Int_t Merge(TCollection *list)
Adds all graphs with asymmetric errors from the collection to this graph.
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
#define gROOT
Definition: TROOT.h:352
Basic string class.
Definition: TString.h:137
Int_t GetNrows() const
Definition: TVectorT.h:81
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1088
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
TList * fFunctions
Definition: TGraph.h:61
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void SetTitle(const char *title="")
Set graph title.
Definition: TGraph.cxx:2153
Bool_t CtorAllocate()
Should be called from ctors after fNpoints has been set Note: This function should be called only fro...
int nbins[3]
TH1F * fHistogram
Definition: TGraph.h:62
virtual Double_t GetBinLowEdge(Int_t bin) const
return bin lower edge for 1D historam Better to use h1.GetXaxis().GetBinLowEdge(bin) ...
Definition: TH1.cxx:8487
static const float upper
Definition: main.cpp:49
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
virtual void GetStats(Double_t *stats) const
fill the array stats from the contents of this histogram The array stats must be correctly dimensione...
Definition: TH1.cxx:7276
double beta(double x, double y)
Calculates the beta function.
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 != ie...
Definition: TGraph.cxx:688
virtual Int_t GetDimension() const
Definition: TH1.h:283
double sqrt(double)
Double_t GetErrorXhigh(Int_t i) const
Get high error on X.
TGraph with assymetric error bars.
Double_t x[n]
Definition: legend1.C:17
void Class()
Definition: Class.C:29
TGraph & operator=(const TGraph &)
Equal operator for this graph.
Definition: TGraph.cxx:180
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.
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.
Definition: TAttLine.cxx:257
virtual void SetPointEXhigh(Int_t i, Double_t exh)
Set EXhigh for point i.
virtual void SetPointEYlow(Int_t i, Double_t eyl)
Set EYlow for point i.
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph with asymmetric errors ...
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.
Definition: TAttMarker.cxx:226
virtual void Apply(TF1 *f)
apply a function to all data points y = f(x,y)
virtual TArrayD * GetSumw2()
Definition: TH1.h:312
virtual ~TGraphAsymmErrors()
TGraphAsymmErrors default destructor.
static Double_t BetaMean(Double_t alpha, Double_t beta)
Compute the mean (average) of the 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...
Bool_t CtorAllocate()
In constructors set fNpoints than call this method.
Definition: TGraph.cxx:714
virtual void BayesDivide(const TH1 *pass, const TH1 *total, Option_t *opt="")
This function is only kept for backward compatibility.
Float_t GetErrorX() const
Definition: TStyle.h:196
Int_t fN
Definition: TArray.h:40
float ymax
Definition: THbookFile.cxx:93
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
Get x and y values for point number i.
Definition: TGraph.cxx:1551
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
Definition: TGraph.cxx:2295
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
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 void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
Swap values.
Definition: TGraph.cxx:2304
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
Collection abstract base class.
Definition: TCollection.h:48
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
Definition: TGraph.cxx:2368
unsigned int UInt_t
Definition: RtypesCore.h:42
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.
Definition: TAttFill.cxx:229
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
char * Form(const char *fmt,...)
virtual void Divide(const TH1 *pass, const TH1 *total, Option_t *opt="cp")
Fill this TGraphAsymmErrors by dividing two 1-dimensional histograms pass/total.
Int_t GetN() const
Definition: TGraph.h:132
TLine * l
Definition: textangle.C:4
const std::string sname
Definition: testIO.cxx:45
float xmax
Definition: THbookFile.cxx:93
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
TGraphErrors * gr
Definition: legend1.C:25
Double_t * GetX() const
Definition: TGraph.h:139
Double_t GetErrorXlow(Int_t i) const
Get low error on X.
virtual void SetName(const char *name)
Change the name of this histogram.
Definition: TH1.cxx:8294
Double_t At(Int_t i) const
Definition: TArrayD.h:81
static unsigned int total
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Definition: TF1.cxx:1185
virtual Double_t GetBinWidth(Int_t bin) const
return bin width for 1D historam Better to use h1.GetXaxis().GetBinWidth(bin)
Definition: TH1.cxx:8498
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)
TGraphAsymmErrors & operator=(const TGraphAsymmErrors &gr)
TGraphAsymmErrors assignment operator.
#define ClassImp(name)
Definition: Rtypes.h:279
double f(double x)
TGraphAsymmErrors()
TGraphAsymmErrors default constructor.
double Double_t
Definition: RtypesCore.h:55
virtual Double_t * GetEXlow() const
Definition: TGraph.h:144
Double_t y[n]
Definition: legend1.C:17
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
The TH1 histogram class.
Definition: TH1.h:80
virtual void SetPointEXlow(Int_t i, Double_t exl)
Set EXlow for point i.
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.
Mother of all ROOT objects.
Definition: TObject.h:58
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...
Definition: TGraph.cxx:988
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition: TGraph.cxx:2127
Double_t * fY
Definition: TGraph.h:60
Double_t * GetY() const
Definition: TGraph.h:140
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 ClopperPearson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Clopper-Pearson interval.
1-Dim function class
Definition: TF1.h:149
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
#define gPad
Definition: TVirtualPad.h:288
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Int_t fMaxSize
Definition: TGraph.h:57
virtual Int_t GetNbinsX() const
Definition: TH1.h:296
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
virtual Double_t * GetEYhigh() const
Definition: TGraph.h:145
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.
Definition: TGraph.cxx:640
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
Definition: TGraph.cxx:2076
const Bool_t kTRUE
Definition: Rtypes.h:91
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
virtual void Print(Option_t *chopt="") const
Print graph and errors values.
const Int_t n
Definition: legend1.C:16
virtual void SetPointEYhigh(Int_t i, Double_t eyh)
Set EYhigh for point i.
virtual Double_t * GetEXhigh() const
Definition: TGraph.h:143
static Double_t BetaMode(Double_t alpha, Double_t beta)
Compute the mode of the beta distribution.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904
static Double_t Wilson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Wilson interval.
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
static Bool_t CheckConsistency(const TH1 &pass, const TH1 &total, Option_t *opt="")
Checks the consistence of the given histograms.
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8401
const char * Data() const
Definition: TString.h:349
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:702
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.