ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 /// Begin_Latex effective entries = #frac{(#sum w_{i})^{2}}{#sum w_{i}^{2}}End_Latex
364 ///
365 /// The points are assigned a x value at the center of each histogram bin.
366 /// The y values are Begin_Latex eff = #frac{pass}{total} End_Latex for all options except for the
367 /// bayesian methods where the result depends on the chosen option.
368 ///
369 /// If the denominator becomes 0 or pass > total, the corresponding bin is
370 /// skipped.
371 ///
372 /// 2) calculating ratios of two Poisson means (option 'pois'):
373 /// --------------------------------------------------------------
374 ///
375 /// The two histograms are interpreted as independent Poisson processes and the ratio
376 /// Begin_Latex #tau = #frac{n_{1}}{n_{2}} = #frac{#varepsilon}{1 - #varepsilon} with #varepsilon = #frac{n_{1}}{n_{1} + n_{2}} End_Latex
377 /// The histogram 'pass' is interpreted as n_{1} and the total histogram
378 /// is used for n_{2}
379 ///
380 /// The (asymmetric) uncertainties of the Poisson ratio are linked to the uncertainties
381 /// of efficiency by a parameter transformation:
382 /// Begin_Latex #Delta #tau_{low/up} = #frac{1}{(1 - #varepsilon)^{2}} #Delta #varepsilon_{low/up} End_Latex
383 ///
384 /// The x errors span each histogram bin (lowedge ... lowedge+width)
385 /// The y errors depend on the chosen statistic methode which can be determined
386 /// by the options given below. For a detailed description of the used statistic
387 /// calculations please have a look at the corresponding functions!
388 ///
389 /// Options:
390 /// - v : verbose mode: prints information about the number of used bins
391 /// and calculated efficiencies with their errors
392 /// - cl=x : determine the used confidence level (0<x<1) (default is 0.683)
393 /// - cp : Clopper-Pearson interval (see TEfficiency::ClopperPearson)
394 /// - w : Wilson interval (see TEfficiency::Wilson)
395 /// - n : normal approximation propagation (see TEfficiency::Normal)
396 /// - ac : Agresti-Coull interval (see TEfficiency::AgrestiCoull)
397 /// - fc : Feldman-Cousins interval (see TEfficiency::FeldmanCousinsInterval)
398 /// - midp : Lancaster mid-P interval (see TEfficiency::MidPInterval)
399 /// - b(a,b): bayesian interval using a prior probability ~Beta(a,b); a,b > 0
400 /// (see TEfficiency::Bayesian)
401 /// - mode : use mode of posterior for Bayesian interval (default is mean)
402 /// - shortest: use shortest interval (done by default if mode is set)
403 /// - central: use central interval (done by default if mode is NOT set)
404 /// - pois: interpret histograms as poisson ratio instead of efficiency
405 /// - e0 : plot (in Bayesian case) efficiency and interval for bins where total=0
406 /// (default is to skip them)
407 ///
408 /// Note:
409 /// Unfortunately there is no straightforward approach for determining a confidence
410 /// interval for a given confidence level. The actual coverage probability of the
411 /// confidence interval oscillates significantly according to the total number of
412 /// events and the true efficiency. In order to decrease the impact of this
413 /// oscillation on the actual coverage probability a couple of approximations and
414 /// methodes has been developped. For a detailed discussion, please have a look at
415 /// this statistical paper:
416 /// <a href="http://www-stat.wharton.upenn.edu/~tcai/paper/Binomial-StatSci.pdf"
417 /// > http://www-stat.wharton.upenn.edu/~tcai/paper/Binomial-StatSci.pdf</a>
418 
419 void TGraphAsymmErrors::Divide(const TH1* pass, const TH1* total, Option_t *opt)
420 {
421  //check pointers
422  if(!pass || !total) {
423  Error("Divide","one of the passed pointers is zero");
424  return;
425  }
426 
427  //check dimension of histograms; only 1-dimensional ones are accepted
428  if((pass->GetDimension() > 1) || (total->GetDimension() > 1)) {
429  Error("Divide","passed histograms are not one-dimensional");
430  return;
431  }
432 
433  //check whether histograms are filled with weights -> use number of effective
434  //entries
435  Bool_t bEffective = false;
436  //compare sum of weights with sum of squares of weights
437  Double_t stats[TH1::kNstat];
438  pass->GetStats(stats);
439  if (TMath::Abs(stats[0] -stats[1]) > 1e-6)
440  bEffective = true;
441  total->GetStats(stats);
442  if (TMath::Abs(stats[0] -stats[1]) > 1e-6)
443  bEffective = true;
444 
445  // we do not want to ignore the weights
446  // if (bEffective && (pass->GetSumw2()->fN == 0 || total->GetSumw2()->fN == 0) ) {
447  // 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");
448  // bEffective = false;
449  // }
450 
451  //parse option
452  TString option = opt;
453  option.ToLower();
454 
455  Bool_t bVerbose = false;
456  //pointer to function returning the boundaries of the confidence interval
457  //(is only used in the frequentist cases.)
458  Double_t (*pBound)(Double_t,Double_t,Double_t,Bool_t) = &TEfficiency::ClopperPearson; // default method
459  //confidence level
460  Double_t conf = 0.682689492137;
461  //values for bayesian statistics
462  Bool_t bIsBayesian = false;
463  Double_t alpha = 1;
464  Double_t beta = 1;
465 
466  //verbose mode
467  if(option.Contains("v")) {
468  option.ReplaceAll("v","");
469  bVerbose = true;
470  }
471 
472  //confidence level
473  if(option.Contains("cl=")) {
474  Double_t level = -1;
475  // coverity [secure_coding : FALSE]
476  sscanf(strstr(option.Data(),"cl="),"cl=%lf",&level);
477  if((level > 0) && (level < 1))
478  conf = level;
479  else
480  Warning("Divide","given confidence level %.3lf is invalid",level);
481  option.ReplaceAll("cl=","");
482  }
483 
484  //normal approximation
485  if(option.Contains("n")) {
486  option.ReplaceAll("n","");
487  pBound = &TEfficiency::Normal;
488  }
489 
490  //clopper pearson interval
491  if(option.Contains("cp")) {
492  option.ReplaceAll("cp","");
493  pBound = &TEfficiency::ClopperPearson;
494  }
495 
496  //wilson interval
497  if(option.Contains("w")) {
498  option.ReplaceAll("w","");
499  pBound = &TEfficiency::Wilson;
500  }
501 
502  //agresti coull interval
503  if(option.Contains("ac")) {
504  option.ReplaceAll("ac","");
505  pBound = &TEfficiency::AgrestiCoull;
506  }
507  // Feldman-Cousins interval
508  if(option.Contains("fc")) {
509  option.ReplaceAll("fc","");
510  pBound = &TEfficiency::FeldmanCousins;
511  }
512  // mid-P Lancaster interval
513  if(option.Contains("midp")) {
514  option.ReplaceAll("midp","");
515  pBound = &TEfficiency::MidPInterval;
516  }
517 
518  //bayesian with prior
519  if(option.Contains("b(")) {
520  Double_t a = 0;
521  Double_t b = 0;
522  sscanf(strstr(option.Data(),"b("),"b(%lf,%lf)",&a,&b);
523  if(a > 0)
524  alpha = a;
525  else
526  Warning("Divide","given shape parameter for alpha %.2lf is invalid",a);
527  if(b > 0)
528  beta = b;
529  else
530  Warning("Divide","given shape parameter for beta %.2lf is invalid",b);
531  option.ReplaceAll("b(","");
532  bIsBayesian = true;
533  }
534 
535  // use posterior mode
536  Bool_t usePosteriorMode = false;
537  if(bIsBayesian && option.Contains("mode") ) {
538  usePosteriorMode = true;
539  option.ReplaceAll("mode","");
540  }
541 
542  Bool_t plot0Bins = false;
543  if(option.Contains("e0") ) {
544  plot0Bins = true;
545  option.ReplaceAll("e0","");
546  }
547 
548  Bool_t useShortestInterval = false;
549  if (bIsBayesian && ( option.Contains("sh") || (usePosteriorMode && !option.Contains("cen") ) ) ) {
550  useShortestInterval = true;
551  }
552 
553  // interpret as Poisson ratio
554  Bool_t bPoissonRatio = false;
555  if(option.Contains("pois") ) {
556  bPoissonRatio = true;
557  option.ReplaceAll("pois","");
558  }
559 
560  // weights works only in case of Normal approximation or Bayesian for binomial interval
561  // in case of Poisson ratio we can use weights by rescaling the obtained results using the effective entries
562  if ( ( bEffective && !bPoissonRatio) && !bIsBayesian && pBound != &TEfficiency::Normal ) {
563  Warning("Divide","Histograms have weights: only Normal or Bayesian error calculation is supported");
564  Info("Divide","Using now the Normal approximation for weighted histograms");
565  }
566 
567  if(bPoissonRatio)
568  {
569  if(pass->GetDimension() != total->GetDimension()) {
570  Error("Divide","passed histograms are not of the same dimension");
571  return;
572  }
573 
574  if(!TEfficiency::CheckBinning(*pass,*total)) {
575  Error("Divide","passed histograms are not consistent");
576  return;
577  }
578  }
579  else
580  {
581  //check consistency of histograms, allowing weights
582  if(!TEfficiency::CheckConsistency(*pass,*total,"w")) {
583  Error("Divide","passed histograms are not consistent");
584  return;
585  }
586  }
587 
588  //Set the graph to have a number of points equal to the number of histogram
589  //bins
590  Int_t nbins = pass->GetNbinsX();
591  Set(nbins);
592 
593  // Ok, now set the points for each bin
594  // (Note: the TH1 bin content is shifted to the right by one:
595  // bin=0 is underflow, bin=nbins+1 is overflow.)
596 
597  //efficiency with lower and upper boundary of confidence interval
598  double eff, low, upper;
599  //this keeps track of the number of points added to the graph
600  int npoint=0;
601  //number of total and passed events
602  Double_t t = 0 , p = 0;
603  Double_t tw = 0, tw2 = 0, pw = 0, pw2 = 0, wratio = 1; // for the case of weights
604  //loop over all bins and fill the graph
605  for (Int_t b=1; b<=nbins; ++b) {
606 
607  // default value when total =0;
608  eff = 0;
609  low = 0;
610  upper = 0;
611 
612  // special case in case of weights we have to consider the sum of weights and the sum of weight squares
613  if(bEffective) {
614  tw = total->GetBinContent(b);
615  tw2 = (total->GetSumw2()->fN > 0) ? total->GetSumw2()->At(b) : tw;
616  pw = pass->GetBinContent(b);
617  pw2 = (pass->GetSumw2()->fN > 0) ? pass->GetSumw2()->At(b) : pw;
618 
619  if(bPoissonRatio)
620  {
621  // tw += pw;
622  // tw2 += pw2;
623  // compute effective entries
624  // special case is (pw=0, pw2=0) in this case is like unweighted
625  if (pw == 0 && pw2 == 0)
626  p = pw;
627  else
628  p = (pw*pw)/pw2;
629 
630  if (tw == 0 && tw2 == 0)
631  t = tw;
632  else
633  t = (tw*tw)/tw2;
634 
635  if (p > 0 && tw > 0)
636  wratio = (pw*t)/(p * tw);
637  else if (p == 0 && tw > 0)
638  wratio = t/tw;
639  else if (p > 0)
640  wratio = pw/p;
641  else {
642  // case both pw and tw are zero - we skip these bins
643  if (!plot0Bins) continue; // skip bins with total <= 0
644  }
645 
646  t += p;
647  }
648  else
649  if (tw <= 0 && !plot0Bins) continue; // skip bins with total <= 0
650 
651  // in the case of weights have the formula only for
652  // the normal and bayesian statistics (see below)
653 
654  }
655 
656  //use bin contents
657  else {
658  t = int( total->GetBinContent(b) + 0.5);
659  p = int(pass->GetBinContent(b) + 0.5);
660 
661  if(bPoissonRatio) t += p;
662 
663  if (!t && !plot0Bins) continue; // skip bins with total = 0
664  }
665 
666 
667  //using bayesian statistics
668  if(bIsBayesian) {
669  double aa,bb;
670 
671  if ((bEffective && !bPoissonRatio) && tw2 <= 0) {
672  // case of bins with zero errors
673  eff = pw/tw;
674  low = eff; upper = eff;
675  }
676  else {
677 
678  if (bEffective && !bPoissonRatio) {
679  // tw/tw2 renormalize the weights
680  double norm = tw/tw2; // case of tw2 = 0 is treated above
681  aa = pw * norm + alpha;
682  bb = (tw - pw) * norm + beta;
683  }
684  else {
685  aa = double(p) + alpha;
686  bb = double(t-p) + beta;
687  }
688  if (usePosteriorMode)
689  eff = TEfficiency::BetaMode(aa,bb);
690  else
691  eff = TEfficiency::BetaMean(aa,bb);
692 
693  if (useShortestInterval) {
694  TEfficiency::BetaShortestInterval(conf,aa,bb,low,upper);
695  }
696  else {
697  low = TEfficiency::BetaCentralInterval(conf,aa,bb,false);
698  upper = TEfficiency::BetaCentralInterval(conf,aa,bb,true);
699  }
700  }
701  }
702  // case of non-bayesian statistics
703  else {
704  if (bEffective && !bPoissonRatio) {
705 
706  if (tw > 0) {
707 
708  eff = pw/tw;
709 
710  // use normal error calculation using variance of MLE with weights (F.James 8.5.2)
711  // this is the same formula used in ROOT for TH1::Divide("B")
712 
713  double variance = ( pw2 * (1. - 2 * eff) + tw2 * eff *eff ) / ( tw * tw) ;
714  double sigma = sqrt(variance);
715 
716  double prob = 0.5 * (1.-conf);
717  double delta = ROOT::Math::normal_quantile_c(prob, sigma);
718  low = eff - delta;
719  upper = eff + delta;
720  if (low < 0) low = 0;
721  if (upper > 1) upper = 1.;
722  }
723  }
724  else {
725  // when not using weights (all cases) or in case of Poisson ratio with weights
726  if(t)
727  eff = ((Double_t)p)/t;
728 
729  low = pBound(t,p,conf,false);
730  upper = pBound(t,p,conf,true);
731  }
732  }
733  // treat as Poisson ratio
734  if(bPoissonRatio)
735  {
736  Double_t ratio = eff/(1 - eff);
737  // take the intervals in eff as intervals in the Poisson ratio
738  low = low/(1. - low);
739  upper = upper/(1.-upper);
740  eff = ratio;
741  if (bEffective) {
742  //scale result by the ratio of the weight
743  eff *= wratio;
744  low *= wratio;
745  upper *= wratio;
746  }
747  }
748  //Set the point center and its errors
749  SetPoint(npoint,pass->GetBinCenter(b),eff);
750  SetPointError(npoint,
751  pass->GetBinCenter(b)-pass->GetBinLowEdge(b),
752  pass->GetBinLowEdge(b)-pass->GetBinCenter(b)+pass->GetBinWidth(b),
753  eff-low,upper-eff);
754  npoint++;//we have added a point to the graph
755  }
756 
757  Set(npoint);//tell the graph how many points we've really added
758  if (npoint < nbins)
759  Warning("Divide","Number of graph points is different than histogram bins - %d points have been skipped",nbins-npoint);
760 
761 
762  if (bVerbose) {
763  Info("Divide","made a graph with %d points from %d bins",npoint,nbins);
764  Info("Divide","used confidence level: %.2lf\n",conf);
765  if(bIsBayesian)
766  Info("Divide","used prior probability ~ beta(%.2lf,%.2lf)",alpha,beta);
767  Print();
768  }
769 }
770 
771 ////////////////////////////////////////////////////////////////////////////////
772 /// Compute Range
773 
775 {
776  TGraph::ComputeRange(xmin,ymin,xmax,ymax);
777 
778  for (Int_t i=0;i<fNpoints;i++) {
779  if (fX[i] -fEXlow[i] < xmin) {
780  if (gPad && gPad->GetLogx()) {
781  if (fEXlow[i] < fX[i]) xmin = fX[i]-fEXlow[i];
782  else xmin = TMath::Min(xmin,fX[i]/3);
783  } else {
784  xmin = fX[i]-fEXlow[i];
785  }
786  }
787  if (fX[i] +fEXhigh[i] > xmax) xmax = fX[i]+fEXhigh[i];
788  if (fY[i] -fEYlow[i] < ymin) {
789  if (gPad && gPad->GetLogy()) {
790  if (fEYlow[i] < fY[i]) ymin = fY[i]-fEYlow[i];
791  else ymin = TMath::Min(ymin,fY[i]/3);
792  } else {
793  ymin = fY[i]-fEYlow[i];
794  }
795  }
796  if (fY[i] +fEYhigh[i] > ymax) ymax = fY[i]+fEYhigh[i];
797  }
798 }
799 
800 
801 ////////////////////////////////////////////////////////////////////////////////
802 /// Copy and release.
803 
805  Int_t ibegin, Int_t iend, Int_t obegin)
806 {
807  CopyPoints(newarrays, ibegin, iend, obegin);
808  if (newarrays) {
809  delete[] fEXlow;
810  fEXlow = newarrays[0];
811  delete[] fEXhigh;
812  fEXhigh = newarrays[1];
813  delete[] fEYlow;
814  fEYlow = newarrays[2];
815  delete[] fEYhigh;
816  fEYhigh = newarrays[3];
817  delete[] fX;
818  fX = newarrays[4];
819  delete[] fY;
820  fY = newarrays[5];
821  delete[] newarrays;
822  }
823 }
824 
825 
826 ////////////////////////////////////////////////////////////////////////////////
827 /// Copy errors from fE*** to arrays[***]
828 /// or to f*** Copy points.
829 
831  Int_t ibegin, Int_t iend, Int_t obegin)
832 {
833  if (TGraph::CopyPoints(arrays ? arrays+4 : 0, ibegin, iend, obegin)) {
834  Int_t n = (iend - ibegin)*sizeof(Double_t);
835  if (arrays) {
836  memmove(&arrays[0][obegin], &fEXlow[ibegin], n);
837  memmove(&arrays[1][obegin], &fEXhigh[ibegin], n);
838  memmove(&arrays[2][obegin], &fEYlow[ibegin], n);
839  memmove(&arrays[3][obegin], &fEYhigh[ibegin], n);
840  } else {
841  memmove(&fEXlow[obegin], &fEXlow[ibegin], n);
842  memmove(&fEXhigh[obegin], &fEXhigh[ibegin], n);
843  memmove(&fEYlow[obegin], &fEYlow[ibegin], n);
844  memmove(&fEYhigh[obegin], &fEYhigh[ibegin], n);
845  }
846  return kTRUE;
847  } else {
848  return kFALSE;
849  }
850 }
851 
852 
853 ////////////////////////////////////////////////////////////////////////////////
854 /// Should be called from ctors after fNpoints has been set
855 /// Note: This function should be called only from the constructor
856 /// since it does not delete previously existing arrays
857 
859 {
860  if (!fNpoints) {
861  fEXlow = fEYlow = fEXhigh = fEYhigh = 0;
862  return kFALSE;
863  }
864  fEXlow = new Double_t[fMaxSize];
865  fEYlow = new Double_t[fMaxSize];
866  fEXhigh = new Double_t[fMaxSize];
867  fEYhigh = new Double_t[fMaxSize];
868  return kTRUE;
869 }
870 
871 ////////////////////////////////////////////////////////////////////////////////
872 /// protected function to perform the merge operation of a graph with asymmetric errors
873 
875 {
876  if (g->GetN() == 0) return kFALSE;
877 
878  Double_t * exl = g->GetEXlow();
879  Double_t * exh = g->GetEXhigh();
880  Double_t * eyl = g->GetEYlow();
881  Double_t * eyh = g->GetEYhigh();
882  if (exl == 0 || exh == 0 || eyl == 0 || eyh == 0) {
883  if (g->IsA() != TGraph::Class() )
884  Warning("DoMerge","Merging a %s is not compatible with a TGraphAsymmErrors - errors will be ignored",g->IsA()->GetName());
885  return TGraph::DoMerge(g);
886  }
887  for (Int_t i = 0 ; i < g->GetN(); i++) {
888  Int_t ipoint = GetN();
889  Double_t x = g->GetX()[i];
890  Double_t y = g->GetY()[i];
891  SetPoint(ipoint, x, y);
892  SetPointError(ipoint, exl[i], exh[i], eyl[i], eyh[i] );
893  }
894 
895  return kTRUE;
896 }
897 
898 ////////////////////////////////////////////////////////////////////////////////
899 /// Set zero values for point arrays in the range [begin, end)
900 
902  Bool_t from_ctor)
903 {
904  if (!from_ctor) {
905  TGraph::FillZero(begin, end, from_ctor);
906  }
907  Int_t n = (end - begin)*sizeof(Double_t);
908  memset(fEXlow + begin, 0, n);
909  memset(fEXhigh + begin, 0, n);
910  memset(fEYlow + begin, 0, n);
911  memset(fEYhigh + begin, 0, n);
912 }
913 
914 
915 ////////////////////////////////////////////////////////////////////////////////
916 /// This function is called by GraphFitChisquare.
917 /// It returns the error along X at point i.
918 
920 {
921  if (i < 0 || i >= fNpoints) return -1;
922  if (!fEXlow && !fEXhigh) return -1;
923  Double_t elow=0, ehigh=0;
924  if (fEXlow) elow = fEXlow[i];
925  if (fEXhigh) ehigh = fEXhigh[i];
926  return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
927 }
928 
929 
930 ////////////////////////////////////////////////////////////////////////////////
931 /// This function is called by GraphFitChisquare.
932 /// It returns the error along Y at point i.
933 
935 {
936  if (i < 0 || i >= fNpoints) return -1;
937  if (!fEYlow && !fEYhigh) return -1;
938  Double_t elow=0, ehigh=0;
939  if (fEYlow) elow = fEYlow[i];
940  if (fEYhigh) ehigh = fEYhigh[i];
941  return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
942 }
943 
944 
945 ////////////////////////////////////////////////////////////////////////////////
946 /// Get high error on X.
947 
949 {
950  if (i<0 || i>fNpoints) return -1;
951  if (fEXhigh) return fEXhigh[i];
952  return -1;
953 }
954 
955 
956 ////////////////////////////////////////////////////////////////////////////////
957 /// Get low error on X.
958 
960 {
961  if (i<0 || i>fNpoints) return -1;
962  if (fEXlow) return fEXlow[i];
963  return -1;
964 }
965 
966 
967 ////////////////////////////////////////////////////////////////////////////////
968 /// Get high error on Y.
969 
971 {
972  if (i<0 || i>fNpoints) return -1;
973  if (fEYhigh) return fEYhigh[i];
974  return -1;
975 }
976 
977 
978 ////////////////////////////////////////////////////////////////////////////////
979 /// Get low error on Y.
980 
982 {
983  if (i<0 || i>fNpoints) return -1;
984  if (fEYlow) return fEYlow[i];
985  return -1;
986 }
987 
988 
989 ////////////////////////////////////////////////////////////////////////////////
990 /// Adds all graphs with asymmetric errors from the collection to this graph.
991 /// Returns the total number of poins in the result or -1 in case of an error.
992 
994 {
995  TIter next(li);
996  while (TObject* o = next()) {
997  TGraph *g = dynamic_cast<TGraph*>(o);
998  if (!g) {
999  Error("Merge",
1000  "Cannot merge - an object which doesn't inherit from TGraph found in the list");
1001  return -1;
1002  }
1003  int n0 = GetN();
1004  int n1 = n0+g->GetN();
1005  Set(n1);
1006  Double_t * x = g->GetX();
1007  Double_t * y = g->GetY();
1008  Double_t * exlow = g->GetEXlow();
1009  Double_t * exhigh = g->GetEXhigh();
1010  Double_t * eylow = g->GetEYlow();
1011  Double_t * eyhigh = g->GetEYhigh();
1012  for (Int_t i = 0 ; i < g->GetN(); i++) {
1013  SetPoint(n0+i, x[i], y[i]);
1014  if (exlow) fEXlow[n0+i] = exlow[i];
1015  if (exhigh) fEXhigh[n0+i] = exhigh[i];
1016  if (eylow) fEYlow[n0+i] = eylow[i];
1017  if (eyhigh) fEYhigh[n0+i] = eyhigh[i];
1018  }
1019  }
1020  return GetN();
1021 }
1022 
1023 ////////////////////////////////////////////////////////////////////////////////
1024 /// Print graph and errors values.
1025 
1027 {
1028  for (Int_t i=0;i<fNpoints;i++) {
1029  printf("x[%d]=%g, y[%d]=%g, exl[%d]=%g, exh[%d]=%g, eyl[%d]=%g, eyh[%d]=%g\n"
1030  ,i,fX[i],i,fY[i],i,fEXlow[i],i,fEXhigh[i],i,fEYlow[i],i,fEYhigh[i]);
1031  }
1032 }
1033 
1034 
1035 ////////////////////////////////////////////////////////////////////////////////
1036 /// Save primitive as a C++ statement(s) on output stream out
1037 
1038 void TGraphAsymmErrors::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1039 {
1040  char quote = '"';
1041  out << " " << std::endl;
1042  static Int_t frameNumber = 3000;
1043  frameNumber++;
1044 
1045  Int_t i;
1046  TString fXName = TString(GetName()) + Form("_fx%d",frameNumber);
1047  TString fYName = TString(GetName()) + Form("_fy%d",frameNumber);
1048  TString fElXName = TString(GetName()) + Form("_felx%d",frameNumber);
1049  TString fElYName = TString(GetName()) + Form("_fely%d",frameNumber);
1050  TString fEhXName = TString(GetName()) + Form("_fehx%d",frameNumber);
1051  TString fEhYName = TString(GetName()) + Form("_fehy%d",frameNumber);
1052  out << " Double_t " << fXName << "[" << fNpoints << "] = {" << std::endl;
1053  for (i = 0; i < fNpoints-1; i++) out << " " << fX[i] << "," << std::endl;
1054  out << " " << fX[fNpoints-1] << "};" << std::endl;
1055  out << " Double_t " << fYName << "[" << fNpoints << "] = {" << std::endl;
1056  for (i = 0; i < fNpoints-1; i++) out << " " << fY[i] << "," << std::endl;
1057  out << " " << fY[fNpoints-1] << "};" << std::endl;
1058  out << " Double_t " << fElXName << "[" << fNpoints << "] = {" << std::endl;
1059  for (i = 0; i < fNpoints-1; i++) out << " " << fEXlow[i] << "," << std::endl;
1060  out << " " << fEXlow[fNpoints-1] << "};" << std::endl;
1061  out << " Double_t " << fElYName << "[" << fNpoints << "] = {" << std::endl;
1062  for (i = 0; i < fNpoints-1; i++) out << " " << fEYlow[i] << "," << std::endl;
1063  out << " " << fEYlow[fNpoints-1] << "};" << std::endl;
1064  out << " Double_t " << fEhXName << "[" << fNpoints << "] = {" << std::endl;
1065  for (i = 0; i < fNpoints-1; i++) out << " " << fEXhigh[i] << "," << std::endl;
1066  out << " " << fEXhigh[fNpoints-1] << "};" << std::endl;
1067  out << " Double_t " << fEhYName << "[" << fNpoints << "] = {" << std::endl;
1068  for (i = 0; i < fNpoints-1; i++) out << " " << fEYhigh[i] << "," << std::endl;
1069  out << " " << fEYhigh[fNpoints-1] << "};" << std::endl;
1070 
1071  if (gROOT->ClassSaved(TGraphAsymmErrors::Class())) out<<" ";
1072  else out << " TGraphAsymmErrors *";
1073  out << "grae = new TGraphAsymmErrors("<< fNpoints << ","
1074  << fXName << "," << fYName << ","
1075  << fElXName << "," << fEhXName << ","
1076  << fElYName << "," << fEhYName << ");"
1077  << std::endl;
1078 
1079  out << " grae->SetName(" << quote << GetName() << quote << ");" << std::endl;
1080  out << " grae->SetTitle(" << quote << GetTitle() << quote << ");" << std::endl;
1081 
1082  SaveFillAttributes(out, "grae", 0, 1001);
1083  SaveLineAttributes(out, "grae", 1, 1, 1);
1084  SaveMarkerAttributes(out, "grae", 1, 1, 1);
1085 
1086  if (fHistogram) {
1087  TString hname = fHistogram->GetName();
1088  hname += frameNumber;
1089  fHistogram->SetName(Form("Graph_%s",hname.Data()));
1090  fHistogram->SavePrimitive(out,"nodraw");
1091  out<<" grae->SetHistogram("<<fHistogram->GetName()<<");"<<std::endl;
1092  out<<" "<<std::endl;
1093  }
1094 
1095  // save list of functions
1097  TObject *obj;
1098  while ((obj = next())) {
1099  obj->SavePrimitive(out, Form("nodraw #%d\n",++frameNumber));
1100  if (obj->InheritsFrom("TPaveStats")) {
1101  out << " grae->GetListOfFunctions()->Add(ptstats);" << std::endl;
1102  out << " ptstats->SetParent(grae->GetListOfFunctions());" << std::endl;
1103  } else {
1104  out << " grae->GetListOfFunctions()->Add("
1105  << Form("%s%d",obj->GetName(),frameNumber) << ");" << std::endl;
1106  }
1107  }
1108 
1109  const char *l = strstr(option,"multigraph");
1110  if (l) {
1111  out<<" multigraph->Add(grae,"<<quote<<l+10<<quote<<");"<<std::endl;
1112  } else {
1113  out<<" grae->Draw("<<quote<<option<<quote<<");"<<std::endl;
1114  }
1115 }
1116 
1117 ////////////////////////////////////////////////////////////////////////////////
1118 /// Set ex and ey values for point pointed by the mouse.
1119 
1121 {
1122  Int_t px = gPad->GetEventX();
1123  Int_t py = gPad->GetEventY();
1124 
1125  //localize point to be deleted
1126  Int_t ipoint = -2;
1127  Int_t i;
1128  // start with a small window (in case the mouse is very close to one point)
1129  for (i=0;i<fNpoints;i++) {
1130  Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
1131  Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
1132  if (dpx*dpx+dpy*dpy < 25) {ipoint = i; break;}
1133  }
1134  if (ipoint == -2) return;
1135 
1136  fEXlow[ipoint] = exl;
1137  fEYlow[ipoint] = eyl;
1138  fEXhigh[ipoint] = exh;
1139  fEYhigh[ipoint] = eyh;
1140  gPad->Modified();
1141 }
1142 
1143 
1144 ////////////////////////////////////////////////////////////////////////////////
1145 /// Set ex and ey values for point number i.
1146 
1148 {
1149  if (i < 0) return;
1150  if (i >= fNpoints) {
1151  // re-allocate the object
1153  }
1154  fEXlow[i] = exl;
1155  fEYlow[i] = eyl;
1156  fEXhigh[i] = exh;
1157  fEYhigh[i] = eyh;
1158 }
1159 
1160 
1161 ////////////////////////////////////////////////////////////////////////////////
1162 /// Set EXlow for point i
1163 
1165 {
1166  if (i < 0) return;
1167  if (i >= fNpoints) {
1168  // re-allocate the object
1170  }
1171  fEXlow[i] = exl;
1172 }
1173 
1174 
1175 ////////////////////////////////////////////////////////////////////////////////
1176 /// Set EXhigh for point i
1177 
1179 {
1180  if (i < 0) return;
1181  if (i >= fNpoints) {
1182  // re-allocate the object
1184  }
1185  fEXhigh[i] = exh;
1186 }
1187 
1188 
1189 ////////////////////////////////////////////////////////////////////////////////
1190 /// Set EYlow for point i
1191 
1193 {
1194  if (i < 0) return;
1195  if (i >= fNpoints) {
1196  // re-allocate the object
1198  }
1199  fEYlow[i] = eyl;
1200 }
1201 
1202 
1203 ////////////////////////////////////////////////////////////////////////////////
1204 /// Set EYhigh for point i
1205 
1207 {
1208  if (i < 0) return;
1209  if (i >= fNpoints) {
1210  // re-allocate the object
1212  }
1213  fEYhigh[i] = eyh;
1214 }
1215 
1216 
1217 ////////////////////////////////////////////////////////////////////////////////
1218 /// Stream an object of class TGraphAsymmErrors.
1219 
1220 void TGraphAsymmErrors::Streamer(TBuffer &b)
1221 {
1222  if (b.IsReading()) {
1223  UInt_t R__s, R__c;
1224  Version_t R__v = b.ReadVersion(&R__s, &R__c);
1225  if (R__v > 2) {
1226  b.ReadClassBuffer(TGraphAsymmErrors::Class(), this, R__v, R__s, R__c);
1227  return;
1228  }
1229  //====process old versions before automatic schema evolution
1230  TGraph::Streamer(b);
1231  fEXlow = new Double_t[fNpoints];
1232  fEYlow = new Double_t[fNpoints];
1233  fEXhigh = new Double_t[fNpoints];
1234  fEYhigh = new Double_t[fNpoints];
1235  if (R__v < 2) {
1236  Float_t *exlow = new Float_t[fNpoints];
1237  Float_t *eylow = new Float_t[fNpoints];
1238  Float_t *exhigh = new Float_t[fNpoints];
1239  Float_t *eyhigh = new Float_t[fNpoints];
1240  b.ReadFastArray(exlow,fNpoints);
1241  b.ReadFastArray(eylow,fNpoints);
1242  b.ReadFastArray(exhigh,fNpoints);
1243  b.ReadFastArray(eyhigh,fNpoints);
1244  for (Int_t i=0;i<fNpoints;i++) {
1245  fEXlow[i] = exlow[i];
1246  fEYlow[i] = eylow[i];
1247  fEXhigh[i] = exhigh[i];
1248  fEYhigh[i] = eyhigh[i];
1249  }
1250  delete [] eylow;
1251  delete [] exlow;
1252  delete [] eyhigh;
1253  delete [] exhigh;
1254  } else {
1259  }
1260  b.CheckByteCount(R__s, R__c, TGraphAsymmErrors::IsA());
1261  //====end of old versions
1262 
1263  } else {
1265  }
1266 }
1267 
1268 
1269 ////////////////////////////////////////////////////////////////////////////////
1270 /// Swap points.
1271 
1273 {
1274  SwapValues(fEXlow, pos1, pos2);
1275  SwapValues(fEXhigh, pos1, pos2);
1276  SwapValues(fEYlow, pos1, pos2);
1277  SwapValues(fEYhigh, pos1, pos2);
1278  TGraph::SwapPoints(pos1, pos2);
1279 }
virtual Double_t * GetEYlow() const
Definition: TGraph.h:146
Double_t GetErrorYhigh(Int_t i) const
Get high error on Y.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TH1.cxx:6723
Int_t fNpoints
Current dimension of arrays fX and fY.
Definition: TGraph.h:58
Double_t At(Int_t i) const
Definition: TArrayD.h:81
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
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 GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4629
Bool_t IsReading() const
Definition: TBuffer.h:83
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
short Version_t
Definition: RtypesCore.h:61
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
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.
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:7270
const char Option_t
Definition: RtypesCore.h:62
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...
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
virtual Int_t GetDimension() const
Definition: TH1.h:283
static Bool_t CheckBinning(const TH1 &pass, const TH1 &total)
Checks binning for each axis.
Int_t GetNrows() const
Definition: TVectorT.h:81
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
TH1 * h
Definition: legend2.C:5
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
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:344
Basic string class.
Definition: TString.h:137
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1075
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]
virtual Int_t GetNbinsX() const
Definition: TH1.h:296
TH1F * fHistogram
Definition: TGraph.h:62
Double_t GetErrorXhigh(Int_t i) const
Get high error on X.
Float_t py
Definition: hprod.C:33
Int_t GetN() const
Definition: TGraph.h:132
static const float upper
Definition: main.cpp:49
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
TFile * f
double beta(double x, double y)
Calculates the beta function.
virtual Double_t GetBinWidth(Int_t bin) const
return bin width for 1D historam Better to use h1.GetXaxis().GetBinWidth(bin)
Definition: TH1.cxx:8492
const char * Data() const
Definition: TString.h:349
Double_t * GetY() const
Definition: TGraph.h:140
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
double sqrt(double)
TGraph with assymetric error bars.
Double_t x[n]
Definition: legend1.C:17
virtual void Print(Option_t *chopt="") const
Print graph and errors values.
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:8481
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 Double_t * GetEXhigh() const
Definition: TGraph.h:143
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
void Class()
Definition: Class.C:29
Double_t GetErrorYlow(Int_t i) const
Get low error on Y.
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 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 Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph with asymmetric errors ...
const Double_t sigma
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 void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Compute Range.
virtual ~TGraphAsymmErrors()
TGraphAsymmErrors default destructor.
static Double_t BetaMean(Double_t alpha, Double_t beta)
Compute the mean (average) of the beta distribution.
char * out
Definition: TBase64.cxx:29
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.
Int_t fN
Definition: TArray.h:40
virtual Double_t GetBinCenter(Int_t bin) const
return bin center for 1D historam Better to use h1.GetXaxis().GetBinCenter(bin)
Definition: TH1.cxx:8470
virtual Double_t * GetEYhigh() const
Definition: TGraph.h:145
TThread * t[5]
Definition: threadsh1.C:13
float ymax
Definition: THbookFile.cxx:93
Double_t * GetX() const
Definition: TGraph.h:139
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
Collection abstract base class.
Definition: TCollection.h:48
TClass * IsA() const
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
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.
TLine * l
Definition: textangle.C:4
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
const std::string sname
Definition: testIO.cxx:45
float xmax
Definition: THbookFile.cxx:93
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
Float_t GetErrorX() const
Definition: TStyle.h:196
TGraphErrors * gr
Definition: legend1.C:25
TH1F * total
Definition: threadsh2.C:15
virtual void SetName(const char *name)
Change the name of this histogram.
Definition: TH1.cxx:8288
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
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
Int_t GetLwb() const
Definition: TVectorT.h:79
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
double Double_t
Definition: RtypesCore.h:55
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
Double_t y[n]
Definition: legend1.C:17
The TH1 histogram class.
Definition: TH1.h:80
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 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 Double_t * GetEXlow() const
Definition: TGraph.h:144
Float_t px
Definition: hprod.C:33
Double_t GetErrorX(Int_t bin) const
This function is called by GraphFitChisquare.
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
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.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
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
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:1162
#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
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
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
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8395
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
const Int_t n
Definition: legend1.C:16
virtual void SetPointEYhigh(Int_t i, Double_t eyh)
Set EYhigh for point i.
static Double_t BetaMode(Double_t alpha, Double_t beta)
Compute the mode of the beta distribution.
static Double_t Wilson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Wilson interval.
Double_t GetErrorY(Int_t bin) const
This function is called by GraphFitChisquare.
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 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.
Double_t GetErrorXlow(Int_t i) const
Get low error on X.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904