Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGraphMultiErrors.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Simon Spies 18/02/19
3
4/*************************************************************************
5 * Copyright (C) 2018-2019, 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 "TROOT.h"
13#include "TStyle.h"
14#include "TVirtualPad.h"
15#include "TEfficiency.h"
16#include "Riostream.h"
17
18#include "TArrayD.h"
19#include "TVector.h"
20#include "TH1.h"
21#include "TF1.h"
22#include "TMath.h"
24
25#include "TGraphMultiErrors.h"
26
28
29/** \class TGraphMultiErrors
30 \ingroup Hist
31TGraph with asymmetric error bars and multiple y error dimensions.
32
33The TGraphMultiErrors painting is performed thanks to the TGraphPainter
34class. All details about the various painting options are given in this class.
35
36The picture below gives an example:
37
38Begin_Macro(source)
39{
40 auto c1 = new TCanvas("c1", "A Simple Graph with multiple y-errors", 200, 10, 700, 500);
41 c1->SetGrid();
42 c1->GetFrame()->SetBorderSize(12);
43 const Int_t np = 5;
44 Double_t x[np] = {0, 1, 2, 3, 4};
45 Double_t y[np] = {0, 2, 4, 1, 3};
46 Double_t exl[np] = {0.3, 0.3, 0.3, 0.3, 0.3};
47 Double_t exh[np] = {0.3, 0.3, 0.3, 0.3, 0.3};
48 Double_t eylstat[np] = {1, 0.5, 1, 0.5, 1};
49 Double_t eyhstat[np] = {0.5, 1, 0.5, 1, 2};
50 Double_t eylsys[np] = {0.5, 0.4, 0.8, 0.3, 1.2};
51 Double_t eyhsys[np] = {0.6, 0.7, 0.6, 0.4, 0.8};
52 auto gme = new TGraphMultiErrors("gme", "TGraphMultiErrors Example", np, x, y, exl, exh, eylstat, eyhstat);
53 gme->AddYError(np, eylsys, eyhsys);
54 gme->SetMarkerStyle(20);
55 gme->SetLineColor(kRed);
56 gme->GetAttLine(0)->SetLineColor(kRed);
57 gme->GetAttLine(1)->SetLineColor(kBlue);
58 gme->GetAttFill(1)->SetFillStyle(0);
59 gme->Draw("APS ; Z ; 5 s=0.5");
60}
61End_Macro
62*/
63////////////////////////////////////////////////////////////////////////////////
64/// TGraphMultiErrors default constructor.
65
67 : TGraph(), fNYErrors(0), fSumErrorsMode(TGraphMultiErrors::kOnlyFirst), fExL(nullptr), fExH(nullptr)
68{
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// TGraphMultiErrors default constructor with name and title.
73
75{
76 SetNameTitle(name, title);
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// TGraphMultiErrors normal constructor with np points and ne y-errors.
81///
82/// All values are initialized to 0.
83
85 : TGraph(np), fNYErrors(ne), fSumErrorsMode(TGraphMultiErrors::kOnlyFirst)
86{
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// TGraphMultiErrors normal constructor with name, title, np points and ne y-errors.
92///
93/// All values are initialized to 0.
94
96 : TGraphMultiErrors(np, ne)
97{
98 SetNameTitle(name, title);
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// TGraphMultiErrors normal constructor with np points and a single y-error.
103///
104/// The signature of this constructor is equal to the corresponding constructor of TGraphAsymmErrors.
105/// If exL,H or eyL,H are NULL, the corresponding values are preset to zero.
106
108 const Float_t *exH, const Float_t *eyL, const Float_t *eyH, Int_t m)
109 : TGraph(np, x, y), fNYErrors(1), fSumErrorsMode(m)
110{
111 if (!CtorAllocate())
112 return;
113
114 for (Int_t i = 0; i < fNpoints; i++) {
115 if (exL)
116 fExL[i] = exL[i];
117 else
118 fExL[i] = 0.;
119 if (exH)
120 fExH[i] = exH[i];
121 else
122 fExH[i] = 0.;
123 if (eyL)
124 fEyL[0][i] = eyL[i];
125 else
126 fEyL[0][i] = 0.;
127 if (eyH)
128 fEyH[0][i] = eyH[i];
129 else
130 fEyH[0][i] = 0.;
131 }
132
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// TGraphMultiErrors normal constructor with name, title, np points and a single y-error.
138///
139/// If exL,H or eyL,H are NULL, the corresponding values are preset to zero.
140
142 const Float_t *y, const Float_t *exL, const Float_t *exH, const Float_t *eyL,
143 const Float_t *eyH, Int_t m)
144 : TGraphMultiErrors(np, x, y, exL, exH, eyL, eyH, m)
145{
146 SetNameTitle(name, title);
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// TGraphMultiErrors normal constructor with np points and a single y-error.
151///
152/// The signature of this constructor is equal to the corresponding constructor of TGraphAsymmErrors.
153/// If exL,H or eyL,H are NULL, the corresponding values are preset to zero.
154
156 const Double_t *exH, const Double_t *eyL, const Double_t *eyH, Int_t m)
157 : TGraph(np, x, y), fNYErrors(1), fSumErrorsMode(m)
158{
159 if (!CtorAllocate())
160 return;
161
162 Int_t n = fNpoints * sizeof(Double_t);
163
164 if (exL)
165 memcpy(fExL, exL, n);
166 else
167 memset(fExL, 0, n);
168 if (exH)
169 memcpy(fExH, exH, n);
170 else
171 memset(fExH, 0, n);
172
173 if (eyL)
174 fEyL[0].Set(fNpoints, eyL);
175 else
176 fEyL[0].Reset(0.);
177
178 if (eyH)
179 fEyH[0].Set(fNpoints, eyH);
180 else
181 fEyH[0].Reset(0.);
182
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// TGraphMultiErrors normal constructor with name, title, np points and a single y-error.
188///
189/// If exL,H or eyL,H are NULL, the corresponding values are preset to zero.
190
192 const Double_t *y, const Double_t *exL, const Double_t *exH, const Double_t *eyL,
193 const Double_t *eyH, Int_t m)
194 : TGraphMultiErrors(np, x, y, exL, exH, eyL, eyH, m)
195{
196 SetNameTitle(name, title);
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// TGraphMultiErrors normal constructor with np points and ne y-errors.
201///
202/// If exL,H are NULL, the corresponding values are preset to zero.
203/// The multiple y-errors are passed as std::vectors of std::vectors.
204
206 const Float_t *exH, std::vector<std::vector<Float_t>> eyL,
207 std::vector<std::vector<Float_t>> eyH, Int_t m)
208 : TGraph(np, x, y), fNYErrors(ne), fSumErrorsMode(m)
209{
210 if (!CtorAllocate())
211 return;
212
213 for (Int_t i = 0; i < fNpoints; i++) {
214 if (exL)
215 fExL[i] = exL[i];
216 else
217 fExL[i] = 0.;
218 if (exH)
219 fExH[i] = exH[i];
220 else
221 fExH[i] = 0.;
222
223 for (Int_t j = 0; j < fNYErrors; j++) {
224 if (Int_t(eyL.size()) > j && Int_t(eyL[j].size()) > i)
225 fEyL[j][i] = eyL[j][i];
226 else
227 fEyL[j][i] = 0.;
228 if (Int_t(eyH.size()) > j && Int_t(eyH[j].size()) > i)
229 fEyH[j][i] = eyH[j][i];
230 else
231 fEyH[j][i] = 0.;
232 }
233 }
234
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// TGraphMultiErrors normal constructor with name, title, np points and ne y-errors.
240///
241/// If exL,H are NULL, the corresponding values are preset to zero.
242/// The multiple y-errors are passed as std::vectors of std::vectors.
243
245 const Float_t *y, const Float_t *exL, const Float_t *exH,
246 std::vector<std::vector<Float_t>> eyL, std::vector<std::vector<Float_t>> eyH,
247 Int_t m)
248 : TGraphMultiErrors(np, ne, x, y, exL, exH, eyL, eyH, m)
249{
250 SetNameTitle(name, title);
251}
252
253////////////////////////////////////////////////////////////////////////////////
254/// TGraphMultiErrors normal constructor with np points and ne y-errors.
255///
256/// If exL,H are NULL, the corresponding values are preset to zero.
257/// The multiple y-errors are passed as std::vectors of std::vectors.
258
260 const Double_t *exH, std::vector<std::vector<Double_t>> eyL,
261 std::vector<std::vector<Double_t>> eyH, Int_t m)
262 : TGraph(np, x, y), fNYErrors(ne), fSumErrorsMode(m)
263{
264 if (!CtorAllocate())
265 return;
266
267 Int_t n = fNpoints * sizeof(Double_t);
268
269 if (exL)
270 memcpy(fExL, exL, n);
271 else
272 memset(fExL, 0, n);
273 if (exH)
274 memcpy(fExH, exH, n);
275 else
276 memset(fExH, 0, n);
277
278 for (Int_t i = 0; i < fNpoints; i++) {
279 for (Int_t j = 0; j < fNYErrors; j++) {
280 if (Int_t(eyL.size()) > j && Int_t(eyL[j].size()) > i)
281 fEyL[j][i] = eyL[j][i];
282 else
283 fEyL[j][i] = 0.;
284 if (Int_t(eyH.size()) > j && Int_t(eyH[j].size()) > i)
285 fEyH[j][i] = eyH[j][i];
286 else
287 fEyH[j][i] = 0.;
288 }
289 }
290
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// TGraphMultiErrors normal constructor with name, title, np points and ne y-errors.
296///
297/// If exL,H are NULL, the corresponding values are preset to zero.
298/// The multiple y-errors are passed as std::vectors of std::vectors.
299
301 const Double_t *y, const Double_t *exL, const Double_t *exH,
302 std::vector<std::vector<Double_t>> eyL, std::vector<std::vector<Double_t>> eyH,
303 Int_t m)
304 : TGraphMultiErrors(np, ne, x, y, exL, exH, eyL, eyH, m)
305{
306 SetNameTitle(name, title);
307}
308
309////////////////////////////////////////////////////////////////////////////////
310/// TGraphMultiErrors normal constructor with np points and ne y-errors.
311///
312/// If exL,H are NULL, the corresponding values are preset to zero.
313/// The multiple y-errors are passed as std::vectors of TArrayF objects.
314
316 const Float_t *exH, std::vector<TArrayF> eyL, std::vector<TArrayF> eyH, Int_t m)
317 : TGraph(np, x, y), fNYErrors(ne), fSumErrorsMode(m)
318{
319 if (!CtorAllocate())
320 return;
321
322 for (Int_t i = 0; i < fNpoints; i++) {
323 if (exL)
324 fExL[i] = exL[i];
325 else
326 fExL[i] = 0.;
327 if (exH)
328 fExH[i] = exH[i];
329 else
330 fExH[i] = 0.;
331
332 for (Int_t j = 0; j < fNYErrors; j++) {
333 if (Int_t(eyL.size()) > j && eyL[j].GetSize() > i)
334 fEyL[j][i] = eyL[j][i];
335 else
336 fEyL[j][i] = 0.;
337 if (Int_t(eyH.size()) > j && eyH[j].GetSize() > i)
338 fEyH[j][i] = eyH[j][i];
339 else
340 fEyH[j][i] = 0.;
341 }
342 }
343
345}
346
347////////////////////////////////////////////////////////////////////////////////
348/// TGraphMultiErrors normal constructor with name, title, np points and ne y-errors.
349///
350/// If exL,H are NULL, the corresponding values are preset to zero.
351/// The multiple y-errors are passed as std::vectors of TArrayF objects.
352
354 const Float_t *y, const Float_t *exL, const Float_t *exH, std::vector<TArrayF> eyL,
355 std::vector<TArrayF> eyH, Int_t m)
356 : TGraphMultiErrors(np, ne, x, y, exL, exH, eyL, eyH, m)
357{
358 SetNameTitle(name, title);
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// TGraphMultiErrors normal constructor with np points and ne y-errors.
363///
364/// If exL,H are NULL, the corresponding values are preset to zero.
365/// The multiple y-errors are passed as std::vectors of TArrayD objects.
366
368 const Double_t *exH, std::vector<TArrayD> eyL, std::vector<TArrayD> eyH, Int_t m)
369 : TGraph(np, x, y), fNYErrors(ne), fSumErrorsMode(m)
370{
371 if (!CtorAllocate())
372 return;
373
374 Int_t n = fNpoints * sizeof(Double_t);
375
376 if (exL)
377 memcpy(fExL, exL, n);
378 else
379 memset(fExL, 0, n);
380 if (exH)
381 memcpy(fExH, exH, n);
382 else
383 memset(fExH, 0, n);
384
385 for (Int_t i = 0; i < fNpoints; i++) {
386 for (Int_t j = 0; j < fNYErrors; j++) {
387 if (Int_t(eyL.size()) > j && eyL[j].GetSize() > i)
388 fEyL[j][i] = eyL[j][i];
389 else
390 fEyL[j][i] = 0.;
391 if (Int_t(eyH.size()) > j && eyH[j].GetSize() > i)
392 fEyH[j][i] = eyH[j][i];
393 else
394 fEyH[j][i] = 0.;
395 }
396 }
397
399}
400
401////////////////////////////////////////////////////////////////////////////////
402/// TGraphMultiErrors normal constructor with name, title, np points and ne y-errors.
403///
404/// If exL,H are NULL, the corresponding values are preset to zero.
405/// The multiple y-errors are passed as std::vectors of TArrayD objects.
406
408 const Double_t *y, const Double_t *exL, const Double_t *exH,
409 std::vector<TArrayD> eyL, std::vector<TArrayD> eyH, Int_t m)
410 : TGraphMultiErrors(np, ne, x, y, exL, exH, eyL, eyH, m)
411{
412 SetNameTitle(name, title);
413}
414
415////////////////////////////////////////////////////////////////////////////////
416/// Constructor with six vectors of floats in input and a single y error dimension
417/// The signature of this constructor is equal to the corresponding constructor of TGraphAsymmErrors.
418/// A grapherrors is built with the X coordinates taken from tvX and Y coord from tvY
419/// and the errors from vectors tvExL/H and tvEyL/H.
420/// The number of points in the graph is the minimum of number of points
421/// in tvX and tvY.
422
424 const TVectorF &tvExH, const TVectorF &tvEyL, const TVectorF &tvEyH, Int_t m)
425 : TGraph(), fNYErrors(1), fSumErrorsMode(m)
426{
427 fNpoints = TMath::Min(tvX.GetNrows(), tvY.GetNrows());
428
430 return;
431
432 if (!CtorAllocate())
433 return;
434
435 Int_t itvXL = tvX.GetLwb();
436 Int_t itvYL = tvY.GetLwb();
437 Int_t itvExLL = tvExL.GetLwb();
438 Int_t itvExHL = tvExH.GetLwb();
439 Int_t itvEyLL = tvEyL.GetLwb();
440 Int_t itvEyHL = tvEyH.GetLwb();
441
442 for (Int_t i = 0; i < fNpoints; i++) {
443 fX[i] = tvX(itvXL + i);
444 fY[i] = tvY(itvYL + i);
445 fExL[i] = tvExL(itvExLL + i);
446 fExH[i] = tvExH(itvExHL + i);
447 fEyL[0][i] = tvEyL(itvEyLL + i);
448 fEyH[0][i] = tvEyH(itvEyHL + i);
449 }
450
452}
453
454////////////////////////////////////////////////////////////////////////////////
455/// Constructor with six vectors of doubles in input and a single y error dimension
456/// The signature of this constructor is equal to the corresponding constructor of TGraphAsymmErrors.
457/// A grapherrors is built with the X coordinates taken from tvX and Y coord from tvY
458/// and the errors from vectors tvExL/H and tvEyL/H.
459/// The number of points in the graph is the minimum of number of points
460/// in tvX and tvY.
461
463 const TVectorD &tvExH, const TVectorD &tvEyL, const TVectorD &tvEyH, Int_t m)
464 : TGraph(), fNYErrors(1), fSumErrorsMode(m)
465{
466 fNpoints = TMath::Min(tvX.GetNrows(), tvY.GetNrows());
467
469 return;
470
471 if (!CtorAllocate())
472 return;
473
474 Int_t itvXL = tvX.GetLwb();
475 Int_t itvYL = tvY.GetLwb();
476 Int_t itvExLL = tvExL.GetLwb();
477 Int_t itvExHL = tvExH.GetLwb();
478 Int_t itvEyLL = tvEyL.GetLwb();
479 Int_t itvEyHL = tvEyH.GetLwb();
480
481 for (Int_t i = 0; i < fNpoints; i++) {
482 fX[i] = tvX(i + itvXL);
483 fY[i] = tvY(i + itvYL);
484 fExL[i] = tvExL(i + itvExLL);
485 fExH[i] = tvExH(i + itvExHL);
486 fEyL[0][i] = tvEyL(i + itvEyLL);
487 fEyH[0][i] = tvEyH(i + itvEyHL);
488 }
489
491}
492
493////////////////////////////////////////////////////////////////////////////////
494/// Constructor with multiple vectors of floats in input and multiple y error dimensions
495/// A grapherrors is built with the X coordinates taken from tvX and Y coord from tvY
496/// and the errors from vectors tvExL/H and tvEyL/H[yErrorDimension].
497/// The number of points in the graph is the minimum of number of points
498/// in tvX and tvY.
499
500TGraphMultiErrors::TGraphMultiErrors(Int_t ne, const TVectorF &tvX, const TVectorF &tvY, const TVectorF &tvExL,
501 const TVectorF &tvExH, const TVectorF *tvEyL, const TVectorF *tvEyH, Int_t m)
502 : TGraph(), fNYErrors(ne), fSumErrorsMode(m)
503{
504 fNpoints = TMath::Min(tvX.GetNrows(), tvY.GetNrows());
505
507 return;
508
509 if (!CtorAllocate())
510 return;
511
512 Int_t itvXL = tvX.GetLwb();
513 Int_t itvYL = tvY.GetLwb();
514 Int_t itvExLL = tvExL.GetLwb();
515 Int_t itvExHL = tvExH.GetLwb();
516
517 for (Int_t i = 0; i < fNpoints; i++) {
518 fX[i] = tvX(i + itvXL);
519 fY[i] = tvY(i + itvYL);
520 fExL[i] = tvExL(i + itvExLL);
521 fExH[i] = tvExH(i + itvExHL);
522
523 for (Int_t j = 0; j < ne; j++) {
524 fEyL[j][i] = tvEyL[j](i + tvEyL[j].GetLwb());
525 fEyH[j][i] = tvEyH[j](i + tvEyH[j].GetLwb());
526 }
527 }
528
530}
531
532////////////////////////////////////////////////////////////////////////////////
533/// Constructor with multiple vectors of doubles in input and multiple y error dimensions
534/// A grapherrors is built with the X coordinates taken from tvX and Y coord from tvY
535/// and the errors from vectors tvExL/H and tvEyL/H[yErrorDimension].
536/// The number of points in the graph is the minimum of number of points
537/// in tvX and tvY.
538
539TGraphMultiErrors::TGraphMultiErrors(Int_t ne, const TVectorD &tvX, const TVectorD &tvY, const TVectorD &tvExL,
540 const TVectorD &tvExH, const TVectorD *tvEyL, const TVectorD *tvEyH, Int_t m)
541 : TGraph(), fNYErrors(ne), fSumErrorsMode(m)
542{
543 fNpoints = TMath::Min(tvX.GetNrows(), tvY.GetNrows());
544
546 return;
547
548 if (!CtorAllocate())
549 return;
550
551 Int_t itvXL = tvX.GetLwb();
552 Int_t itvYL = tvY.GetLwb();
553 Int_t itvExLL = tvExL.GetLwb();
554 Int_t itvExHL = tvExH.GetLwb();
555
556 for (Int_t i = 0; i < fNpoints; i++) {
557 fX[i] = tvX(i + itvXL);
558 fY[i] = tvY(i + itvYL);
559 fExL[i] = tvExL(i + itvExLL);
560 fExH[i] = tvExH(i + itvExHL);
561
562 for (Int_t j = 0; j < ne; j++) {
563 fEyL[j][i] = tvEyL[j](i + tvEyL[j].GetLwb());
564 fEyH[j][i] = tvEyH[j](i + tvEyH[j].GetLwb());
565 }
566 }
567
569}
570
571////////////////////////////////////////////////////////////////////////////////
572/// TGraphMultiErrors copy constructor
573
575{
576 fNYErrors = tgme.fNYErrors;
578
579 if (!CtorAllocate())
580 return;
581
582 Int_t n = fNpoints * sizeof(Double_t);
583 memcpy(fExL, tgme.fExL, n);
584 memcpy(fExH, tgme.fExH, n);
585
586 for (Int_t j = 0; j < fNYErrors; j++) {
587 fEyL[j] = tgme.fEyL[j];
588 fEyH[j] = tgme.fEyH[j];
589 tgme.fAttFill[j].Copy(fAttFill[j]);
590 tgme.fAttLine[j].Copy(fAttLine[j]);
591 }
592
594}
595
596////////////////////////////////////////////////////////////////////////////////
597/// TGraphMultiErrors assignment operator
598
600{
601 if (this != &tgme) {
602 TGraph::operator=(tgme);
603 // delete arrays
604 if (fExL)
605 delete[] fExL;
606 if (fExH)
607 delete[] fExH;
608 if (fEyLSum)
609 delete[] fEyLSum;
610 if (fEyHSum)
611 delete[] fEyHSum;
612
613 fNYErrors = tgme.fNYErrors;
615
616 if (!CtorAllocate())
617 return *this;
618
619 Int_t n = fNpoints * sizeof(Double_t);
620 memcpy(fExL, tgme.fExL, n);
621 memcpy(fExH, tgme.fExH, n);
622 memcpy(fEyLSum, tgme.fEyLSum, n);
623 memcpy(fEyHSum, tgme.fEyHSum, n);
624
625 for (Int_t j = 0; j < fNYErrors; j++) {
626 fEyL[j] = tgme.fEyL[j];
627 fEyH[j] = tgme.fEyH[j];
628 tgme.fAttFill[j].Copy(fAttFill[j]);
629 tgme.fAttLine[j].Copy(fAttLine[j]);
630 }
631 }
632 return *this;
633}
634
635////////////////////////////////////////////////////////////////////////////////
636/// TGraphMultiErrors constructor importing its parameters from the TH1 object passed as argument
637/// the low and high errors are set to the bin error of the histogram.
638
640 : TGraph(h), fNYErrors(ne), fSumErrorsMode(TGraphMultiErrors::kOnlyFirst)
641{
642 if (!CtorAllocate())
643 return;
644
645 for (Int_t i = 0; i < fNpoints; i++) {
646 fExL[i] = h->GetBinWidth(i + 1) * gStyle->GetErrorX();
647 fExH[i] = h->GetBinWidth(i + 1) * gStyle->GetErrorX();
648 fEyL[0][i] = h->GetBinError(i + 1);
649 fEyH[0][i] = h->GetBinError(i + 1);
650
651 for (Int_t j = 1; j < fNYErrors; j++) {
652 fEyL[j][i] = 0.;
653 fEyH[j][i] = 0.;
654 }
655 }
656
658
661}
662
663////////////////////////////////////////////////////////////////////////////////
664/// Creates a TGraphMultiErrors by dividing two input TH1 histograms:
665/// pass/total. (see TGraphMultiErrors::Divide)
666
668 : TGraph(pass ? pass->GetNbinsX() : 0), fNYErrors(ne), fSumErrorsMode(TGraphMultiErrors::kOnlyFirst)
669{
670 if (!pass || !total) {
671 Error("TGraphMultiErrors", "Invalid histogram pointers");
672 return;
673 }
674
675 if (!CtorAllocate())
676 return;
677
678 std::string sname = "divide_" + std::string(pass->GetName()) + "_by_" + std::string(total->GetName());
679 SetName(sname.c_str());
680 SetTitle(pass->GetTitle());
681
682 // copy style from pass
683 pass->TAttLine::Copy(*this);
684 pass->TAttFill::Copy(*this);
685 pass->TAttMarker::Copy(*this);
686
687 Divide(pass, total, option);
689
692}
693
694////////////////////////////////////////////////////////////////////////////////
695/// TGraphMultiErrors default destructor.
696
698{
699 if (fExL)
700 delete[] fExL;
701 if (fExH)
702 delete[] fExH;
703 fEyL.resize(0);
704 fEyH.resize(0);
705 if (fEyLSum)
706 delete[] fEyLSum;
707 if (fEyHSum)
708 delete[] fEyHSum;
709 fAttFill.resize(0);
710 fAttLine.resize(0);
711}
712
713////////////////////////////////////////////////////////////////////////////////
714/// Should be called from ctors after fNpoints has been set
715/// Note: This function should be called only from the constructor
716/// since it does not delete previously existing arrays
717
719{
720 if (!fNpoints || !fNYErrors) {
721 fExL = fExH = nullptr;
722 fEyL.resize(0);
723 fEyH.resize(0);
724 return kFALSE;
725 }
726
727 fExL = new Double_t[fMaxSize];
728 fExH = new Double_t[fMaxSize];
729 fEyL.resize(fNYErrors, TArrayD(fMaxSize));
730 fEyH.resize(fNYErrors, TArrayD(fMaxSize));
733 fAttFill.resize(fNYErrors);
734 fAttLine.resize(fNYErrors);
735
736 Int_t n = fMaxSize * sizeof(Double_t);
737 memset(fExL, 0, n);
738 memset(fExH, 0, n);
739 memset(fEyLSum, 0, n);
740 memset(fEyHSum, 0, n);
741
742 return kTRUE;
743}
744
745////////////////////////////////////////////////////////////////////////////////
746/// Copy and release.
747
748void TGraphMultiErrors::CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
749{
750 CopyPoints(newarrays, ibegin, iend, obegin);
751 if (newarrays) {
752 delete[] fX;
753 fX = newarrays[0];
754 delete[] fY;
755 fY = newarrays[1];
756
757 delete[] fExL;
758 fExL = newarrays[2];
759 delete[] fExH;
760 fExH = newarrays[3];
761
762 if (fEyLSum)
763 delete[] fEyLSum;
764 fEyLSum = newarrays[4];
765 if (fEyHSum)
766 delete[] fEyHSum;
767 fEyHSum = newarrays[5];
768
769 delete[] newarrays;
770 }
771}
772
773////////////////////////////////////////////////////////////////////////////////
774/// Copy errors from fE*** to arrays[***]
775/// or to f*** Copy points.
776
778{
779 if (TGraph::CopyPoints(arrays, ibegin, iend, obegin)) {
780 Int_t n = (iend - ibegin) * sizeof(Double_t);
781
782 if (arrays) {
783 memmove(&arrays[2][obegin], &fExL[ibegin], n);
784 memmove(&arrays[3][obegin], &fExH[ibegin], n);
785 memmove(&arrays[4][obegin], &fEyLSum[ibegin], n);
786 memmove(&arrays[5][obegin], &fEyHSum[ibegin], n);
787 } else {
788 memmove(&fExL[obegin], &fExL[ibegin], n);
789 memmove(&fExH[obegin], &fExH[ibegin], n);
790 memmove(&fEyLSum[obegin], &fEyLSum[ibegin], n);
791 memmove(&fEyHSum[obegin], &fEyHSum[ibegin], n);
792 }
793
794 return kTRUE;
795 } else
796 return kFALSE;
797}
798
799////////////////////////////////////////////////////////////////////////////////
800/// Set zero values for point arrays in the range [begin, end)
801
803{
804 if (!from_ctor)
805 TGraph::FillZero(begin, end, from_ctor);
806
807 Int_t n = (end - begin) * sizeof(Double_t);
808 memset(fExL + begin, 0, n);
809 memset(fExH + begin, 0, n);
810 memset(fEyLSum + begin, 0, n);
811 memset(fEyHSum + begin, 0, n);
812
813 for (Int_t j = 0; j < fNYErrors; j++) {
814 memset(fEyL[j].GetArray() + begin, 0, n);
815 memset(fEyH[j].GetArray() + begin, 0, n);
816 }
817}
818
819////////////////////////////////////////////////////////////////////////////////
820/// Recalculates the summed y error arrays
821
823{
824 if (!fEyLSum)
826 if (!fEyHSum)
828
829 for (Int_t i = 0; i < fNpoints; i++) {
830 fEyLSum[i] = GetErrorYlow(i);
831 fEyHSum[i] = GetErrorYhigh(i);
832 }
833}
834
835////////////////////////////////////////////////////////////////////////////////
836/// protected function to perform the merge operation of a graph with multiple asymmetric errors
837
839{
840 if (tg->GetN() == 0)
841 return kFALSE;
842
843 if (tg->IsA() == TGraphMultiErrors::Class()) {
844 auto tgme = (TGraphMultiErrors *)tg;
845
846 for (Int_t i = 0; i < tgme->GetN(); i++) {
847 Int_t ipoint = GetN();
848 Double_t x, y;
849 tgme->GetPoint(i, x, y);
850 SetPoint(ipoint, x, y);
851 SetPointEX(ipoint, tgme->GetErrorXlow(i), tgme->GetErrorXhigh(i));
852 for (Int_t j = 0; j < tgme->GetNYErrors(); j++)
853 SetPointEY(ipoint, j, tgme->GetErrorYlow(i, j), tgme->GetErrorYhigh(i, j));
854 }
855
856 return kTRUE;
857 } else {
858 Warning("DoMerge", "Merging a %s is not compatible with a TGraphMultiErrors - Errors will be ignored",
859 tg->IsA()->GetName());
860 return TGraph::DoMerge(tg);
861 }
862
863 return kFALSE;
864}
865
866////////////////////////////////////////////////////////////////////////////////
867/// Swap points.
868
870{
871 SwapValues(fExL, pos1, pos2);
872 SwapValues(fExH, pos1, pos2);
873
874 for (Int_t j = 0; j <= fNYErrors; j++) {
875 SwapValues(fEyL[j].GetArray(), pos1, pos2);
876 SwapValues(fEyH[j].GetArray(), pos1, pos2);
877 }
878
879 TGraph::SwapPoints(pos1, pos2);
880}
881
882////////////////////////////////////////////////////////////////////////////////
883/// Add a new y error to the graph and fill it with the values from eyL and eyH
884
885void TGraphMultiErrors::AddYError(Int_t np, const Double_t *eyL, const Double_t *eyH)
886{
887 fEyL.emplace_back(np, eyL);
888 fEyH.emplace_back(np, eyH);
889 fEyL.back().Set(fNpoints);
890 fEyH.back().Set(fNpoints);
891 fAttFill.emplace_back();
892 fAttLine.emplace_back();
893
894 fNYErrors += 1;
895
897}
898
899////////////////////////////////////////////////////////////////////////////////
900/// Allocate internal data structures for `size` points.
902{
903 return AllocateArrays(6, size);
904}
905
906////////////////////////////////////////////////////////////////////////////////
907/// Apply a function to all data points `y = f(x,y)`
908///
909/// Errors are calculated as `eyh = f(x,y+eyh)-f(x,y)` and
910/// `eyl = f(x,y)-f(x,y-eyl)`
911/// Only the first error dimension is affected!!!
912///
913/// Special treatment has to be applied for the functions where the
914/// role of "up" and "down" is reversed.
915/// function suggested/implemented by Miroslav Helbich <helbich@mail.desy.de>
916
918{
919 Double_t x, y, eyL, eyH, eyLNew, eyHNew, fxy;
920
921 if (fHistogram) {
922 delete fHistogram;
923 fHistogram = nullptr;
924 }
925
926 for (Int_t i = 0; i < fNpoints; i++) {
927 GetPoint(i, x, y);
928 eyL = GetErrorYlow(i, 0);
929 eyH = GetErrorYhigh(i, 0);
930
931 fxy = f->Eval(x, y);
932 SetPoint(i, x, fxy);
933
934 if (f->Eval(x, y - eyL) < f->Eval(x, y + eyH)) {
935 eyLNew = TMath::Abs(fxy - f->Eval(x, y - eyL));
936 eyHNew = TMath::Abs(f->Eval(x, y + eyH) - fxy);
937 } else {
938 eyHNew = TMath::Abs(fxy - f->Eval(x, y - eyL));
939 eyLNew = TMath::Abs(f->Eval(x, y + eyH) - fxy);
940 }
941
942 // systematic errors and error on x doesn't change
943 SetPointEY(i, 0, eyLNew, eyHNew);
944 }
945
946 if (gPad)
947 gPad->Modified();
948}
949
950////////////////////////////////////////////////////////////////////////////////
951/// This function is only kept for backward compatibility.
952/// You should rather use the Divide method.
953/// It calls `Divide(pass,total,"cl=0.683 b(1,1) mode")` which is equivalent to the
954/// former BayesDivide method.
955
957{
958 Divide(pass, total, "cl=0.683 b(1,1) mode");
959}
960
961////////////////////////////////////////////////////////////////////////////////
962/// This function was adapted from the TGraphAsymmErrors class.
963/// See TGraphAsymmErrors::Divide for the documentation
964///
965/// Only the first error dimension is affected!!!
966
967void TGraphMultiErrors::Divide(const TH1 *pass, const TH1 *total, Option_t *opt)
968{
969 // check pointers
970 if (!pass || !total) {
971 Error("Divide", "one of the passed pointers is zero");
972 return;
973 }
974
975 // check dimension of histograms; only 1-dimensional ones are accepted
976 if ((pass->GetDimension() > 1) || (total->GetDimension() > 1)) {
977 Error("Divide", "passed histograms are not one-dimensional");
978 return;
979 }
980
981 // check whether histograms are filled with weights -> use number of effective
982 // entries
983 Bool_t bEffective = false;
984 // compare sum of weights with sum of squares of weights
985 // re-compute here to be sure to get the right values
986 Double_t psumw = 0;
987 Double_t psumw2 = 0;
988 if (pass->GetSumw2()->fN > 0) {
989 for (int i = 0; i < pass->GetNbinsX(); ++i) {
990 psumw += pass->GetBinContent(i);
991 psumw2 += pass->GetSumw2()->At(i);
992 }
993 } else {
994 psumw = pass->GetSumOfWeights();
995 psumw2 = psumw;
996 }
997 if (TMath::Abs(psumw - psumw2) > 1e-6)
998 bEffective = true;
999
1000 Double_t tsumw = 0;
1001 Double_t tsumw2 = 0;
1002 if (total->GetSumw2()->fN > 0) {
1003 for (int i = 0; i < total->GetNbinsX(); ++i) {
1004 tsumw += total->GetBinContent(i);
1005 tsumw2 += total->GetSumw2()->At(i);
1006 }
1007 } else {
1008 tsumw = total->GetSumOfWeights();
1009 tsumw2 = tsumw;
1010 }
1011 if (TMath::Abs(tsumw - tsumw2) > 1e-6)
1012 bEffective = true;
1013
1014 // we do not want to ignore the weights
1015 // if (bEffective && (pass->GetSumw2()->fN == 0 || total->GetSumw2()->fN == 0) ) {
1016 // Warning("Divide","histogram have been computed with weights but the sum of weight squares are not stored in the
1017 // histogram. Error calculation is performed ignoring the weights"); bEffective = false;
1018 // }
1019
1020 // parse option
1021 TString option = opt;
1022 option.ToLower();
1023
1024 Bool_t bVerbose = false;
1025 // pointer to function returning the boundaries of the confidence interval
1026 //(is only used in the frequentist cases.)
1027 // Double_t (*pBound)(Int_t,Int_t,Double_t,Bool_t) = &TEfficiency::ClopperPearson; // default method
1028 Double_t (*pBound)(Double_t, Double_t, Double_t, Bool_t) = &TEfficiency::ClopperPearson; // default method
1029 // confidence level
1030 Double_t conf = 0.682689492137;
1031 // values for bayesian statistics
1032 Bool_t bIsBayesian = false;
1033 Double_t alpha = 1;
1034 Double_t beta = 1;
1035
1036 // verbose mode
1037 if (option.Contains("v")) {
1038 option.ReplaceAll("v", "");
1039 bVerbose = true;
1040 if (bEffective)
1041 Info("Divide", "weight will be considered in the Histogram Ratio");
1042 }
1043
1044 // confidence level
1045 if (option.Contains("cl=")) {
1046 Double_t level = -1;
1047 // coverity [secure_coding : FALSE]
1048 sscanf(strstr(option.Data(), "cl="), "cl=%lf", &level);
1049 if ((level > 0) && (level < 1))
1050 conf = level;
1051 else
1052 Warning("Divide", "given confidence level %.3lf is invalid", level);
1053 option.ReplaceAll("cl=", "");
1054 }
1055
1056 // normal approximation
1057 if (option.Contains("n")) {
1058 option.ReplaceAll("n", "");
1059 pBound = &TEfficiency::Normal;
1060 }
1061
1062 // clopper pearson interval
1063 if (option.Contains("cp")) {
1064 option.ReplaceAll("cp", "");
1066 }
1067
1068 // wilson interval
1069 if (option.Contains("w")) {
1070 option.ReplaceAll("w", "");
1071 pBound = &TEfficiency::Wilson;
1072 }
1073
1074 // agresti coull interval
1075 if (option.Contains("ac")) {
1076 option.ReplaceAll("ac", "");
1077 pBound = &TEfficiency::AgrestiCoull;
1078 }
1079 // Feldman-Cousins interval
1080 if (option.Contains("fc")) {
1081 option.ReplaceAll("fc", "");
1083 }
1084 // mid-P Lancaster interval (In a later ROOT Version!)
1085 if (option.Contains("midp")) {
1086 option.ReplaceAll("midp", "");
1087 // pBound = &TEfficiency::MidPInterval;
1088 }
1089
1090 // bayesian with prior
1091 if (option.Contains("b(")) {
1092 Double_t a = 0;
1093 Double_t b = 0;
1094 sscanf(strstr(option.Data(), "b("), "b(%lf,%lf)", &a, &b);
1095 if (a > 0)
1096 alpha = a;
1097 else
1098 Warning("Divide", "given shape parameter for alpha %.2lf is invalid", a);
1099 if (b > 0)
1100 beta = b;
1101 else
1102 Warning("Divide", "given shape parameter for beta %.2lf is invalid", b);
1103 option.ReplaceAll("b(", "");
1104 bIsBayesian = true;
1105 }
1106
1107 // use posterior mode
1108 Bool_t usePosteriorMode = false;
1109 if (bIsBayesian && option.Contains("mode")) {
1110 usePosteriorMode = true;
1111 option.ReplaceAll("mode", "");
1112 }
1113
1114 Bool_t plot0Bins = false;
1115 if (option.Contains("e0")) {
1116 plot0Bins = true;
1117 option.ReplaceAll("e0", "");
1118 }
1119
1120 Bool_t useShortestInterval = false;
1121 if (bIsBayesian && (option.Contains("sh") || (usePosteriorMode && !option.Contains("cen")))) {
1122 useShortestInterval = true;
1123 }
1124
1125 // interpret as Poisson ratio
1126 Bool_t bPoissonRatio = false;
1127 if (option.Contains("pois")) {
1128 bPoissonRatio = true;
1129 option.ReplaceAll("pois", "");
1130 }
1131
1132 // weights works only in case of Normal approximation or Bayesian for binomial interval
1133 // in case of Poisson ratio we can use weights by rescaling the obtained results using the effective entries
1134 if ((bEffective && !bPoissonRatio) && !bIsBayesian && pBound != &TEfficiency::Normal) {
1135 Warning("Divide", "Histograms have weights: only Normal or Bayesian error calculation is supported");
1136 Info("Divide", "Using now the Normal approximation for weighted histograms");
1137 }
1138
1139 if (bPoissonRatio) {
1140 if (pass->GetDimension() != total->GetDimension()) {
1141 Error("Divide", "passed histograms are not of the same dimension");
1142 return;
1143 }
1144
1145 if (!TEfficiency::CheckBinning(*pass, *total)) {
1146 Error("Divide", "passed histograms are not consistent");
1147 return;
1148 }
1149 } else {
1150 // check consistency of histograms, allowing weights
1151 if (!TEfficiency::CheckConsistency(*pass, *total, "w")) {
1152 Error("Divide", "passed histograms are not consistent");
1153 return;
1154 }
1155 }
1156
1157 // Set the graph to have a number of points equal to the number of histogram
1158 // bins
1159 Int_t nbins = pass->GetNbinsX();
1160 Set(nbins);
1161
1162 // Ok, now set the points for each bin
1163 // (Note: the TH1 bin content is shifted to the right by one:
1164 // bin=0 is underflow, bin=nbins+1 is overflow.)
1165
1166 // this keeps track of the number of points added to the graph
1167 Int_t npoint = 0;
1168 // number of total and passed events
1169 Double_t t = 0, p = 0;
1170 Double_t tw = 0, tw2 = 0, pw = 0, pw2 = 0, wratio = 1; // for the case of weights
1171 // loop over all bins and fill the graph
1172 for (Int_t b = 1; b <= nbins; ++b) {
1173 // efficiency with lower and upper boundary of confidence interval default value when total =0;
1174 Double_t eff = 0., low = 0., upper = 0.;
1175
1176 // special case in case of weights we have to consider the sum of weights and the sum of weight squares
1177 if (bEffective) {
1178 tw = total->GetBinContent(b);
1179 tw2 = (total->GetSumw2()->fN > 0) ? total->GetSumw2()->At(b) : tw;
1180 pw = pass->GetBinContent(b);
1181 pw2 = (pass->GetSumw2()->fN > 0) ? pass->GetSumw2()->At(b) : pw;
1182
1183 if (bPoissonRatio) {
1184 // tw += pw;
1185 // tw2 += pw2;
1186 // compute ratio on the effective entries ( p and t)
1187 // special case is when (pw=0, pw2=0) in this case we cannot get the bin weight.
1188 // we use then the overall weight of the full histogram
1189 if (pw == 0 && pw2 == 0)
1190 p = 0;
1191 else
1192 p = (pw * pw) / pw2;
1193
1194 if (tw == 0 && tw2 == 0)
1195 t = 0;
1196 else
1197 t = (tw * tw) / tw2;
1198
1199 if (pw > 0 && tw > 0)
1200 // this is the ratio of the two bin weights ( pw/p / t/tw )
1201 wratio = (pw * t) / (p * tw);
1202 else if (pw == 0 && tw > 0)
1203 // case p histogram has zero compute the weights from all the histogram
1204 // weight of histogram - sumw2/sumw
1205 wratio = (psumw2 * t) / (psumw * tw);
1206 else if (tw == 0 && pw > 0)
1207 // case t histogram has zero compute the weights from all the histogram
1208 // weight of histogram - sumw2/sumw
1209 wratio = (pw * tsumw) / (p * tsumw2);
1210 else if (p > 0)
1211 wratio = pw / p; // not sure if needed
1212 else {
1213 // case both pw and tw are zero - we skip these bins
1214 if (!plot0Bins)
1215 continue; // skip bins with total <= 0
1216 }
1217
1218 t += p;
1219 // std::cout << p << " " << t << " " << wratio << std::endl;
1220 } else if (tw <= 0 && !plot0Bins)
1221 continue; // skip bins with total <= 0
1222
1223 // in the case of weights have the formula only for
1224 // the normal and bayesian statistics (see below)
1225
1226 }
1227
1228 // use bin contents
1229 else {
1230 t = TMath::Nint(total->GetBinContent(b));
1231 p = TMath::Nint(pass->GetBinContent(b));
1232
1233 if (bPoissonRatio)
1234 t += p;
1235
1236 if (t == 0. && !plot0Bins)
1237 continue; // skip bins with total = 0
1238 }
1239
1240 // using bayesian statistics
1241 if (bIsBayesian) {
1242 if ((bEffective && !bPoissonRatio) && tw2 <= 0) {
1243 // case of bins with zero errors
1244 eff = pw / tw;
1245 low = eff;
1246 upper = eff;
1247 } else {
1248 Double_t aa, bb;
1249
1250 if (bEffective && !bPoissonRatio) {
1251 // tw/tw2 re-normalize the weights
1252 double norm = tw / tw2; // case of tw2 = 0 is treated above
1253 aa = pw * norm + alpha;
1254 bb = (tw - pw) * norm + beta;
1255 } else {
1256 aa = double(p) + alpha;
1257 bb = double(t - p) + beta;
1258 }
1259 if (usePosteriorMode)
1260 eff = TEfficiency::BetaMode(aa, bb);
1261 else
1262 eff = TEfficiency::BetaMean(aa, bb);
1263
1264 if (useShortestInterval) {
1265 TEfficiency::BetaShortestInterval(conf, aa, bb, low, upper);
1266 } else {
1267 low = TEfficiency::BetaCentralInterval(conf, aa, bb, false);
1268 upper = TEfficiency::BetaCentralInterval(conf, aa, bb, true);
1269 }
1270 }
1271 }
1272 // case of non-bayesian statistics
1273 else {
1274 if (bEffective && !bPoissonRatio) {
1275
1276 if (tw > 0) {
1277
1278 eff = pw / tw;
1279
1280 // use normal error calculation using variance of MLE with weights (F.James 8.5.2)
1281 // this is the same formula used in ROOT for TH1::Divide("B")
1282
1283 double variance = (pw2 * (1. - 2 * eff) + tw2 * eff * eff) / (tw * tw);
1284 double sigma = sqrt(variance);
1285
1286 double prob = 0.5 * (1. - conf);
1287 double delta = ROOT::Math::normal_quantile_c(prob, sigma);
1288 low = eff - delta;
1289 upper = eff + delta;
1290 if (low < 0)
1291 low = 0;
1292 if (upper > 1)
1293 upper = 1.;
1294 }
1295 } else {
1296 // when not using weights (all cases) or in case of Poisson ratio with weights
1297 if (t != 0.)
1298 eff = ((Double_t)p) / t;
1299
1300 low = pBound(t, p, conf, false);
1301 upper = pBound(t, p, conf, true);
1302 }
1303 }
1304 // treat as Poisson ratio
1305 if (bPoissonRatio) {
1306 Double_t ratio = eff / (1 - eff);
1307 // take the intervals in eff as intervals in the Poisson ratio
1308 low = low / (1. - low);
1309 upper = upper / (1. - upper);
1310 eff = ratio;
1311 if (bEffective) {
1312 // scale result by the ratio of the weight
1313 eff *= wratio;
1314 low *= wratio;
1315 upper *= wratio;
1316 }
1317 }
1318 // Set the point center and its errors
1319 if (TMath::Finite(eff)) {
1320 SetPoint(npoint, pass->GetBinCenter(b), eff);
1321 SetPointEX(npoint, pass->GetBinCenter(b) - pass->GetBinLowEdge(b),
1322 pass->GetBinLowEdge(b) - pass->GetBinCenter(b) + pass->GetBinWidth(b));
1323 SetPointEY(npoint, 0, eff - low, upper - eff);
1324 npoint++; // we have added a point to the graph
1325 }
1326 }
1327
1328 Set(npoint); // tell the graph how many points we've really added
1329 if (npoint < nbins)
1330 Warning("Divide", "Number of graph points is different than histogram bins - %d points have been skipped",
1331 nbins - npoint);
1332
1333 if (bVerbose) {
1334 Info("Divide", "made a graph with %d points from %d bins", npoint, nbins);
1335 Info("Divide", "used confidence level: %.2lf\n", conf);
1336 if (bIsBayesian)
1337 Info("Divide", "used prior probability ~ beta(%.2lf,%.2lf)", alpha, beta);
1338 Print();
1339 }
1340}
1341
1342////////////////////////////////////////////////////////////////////////////////
1343/// Compute Range
1344
1346{
1348
1349 for (Int_t i = 0; i < fNpoints; i++) {
1350 if (fX[i] - fExL[i] < xmin) {
1351 if (gPad && gPad->GetLogx()) {
1352 if (fExL[i] < fX[i])
1353 xmin = fX[i] - fExL[i];
1354 else
1355 xmin = TMath::Min(xmin, fX[i] / 3.);
1356 } else
1357 xmin = fX[i] - fExL[i];
1358 }
1359
1360 if (fX[i] + fExH[i] > xmax)
1361 xmax = fX[i] + fExH[i];
1362
1363 Double_t eyLMax = 0., eyHMax = 0.;
1364 for (Int_t j = 0; j < fNYErrors; j++) {
1365 eyLMax = TMath::Max(eyLMax, fEyL[j][i]);
1366 eyHMax = TMath::Max(eyHMax, fEyH[j][i]);
1367 }
1368
1369 if (fY[i] - eyLMax < ymin) {
1370 if (gPad && gPad->GetLogy()) {
1371 if (eyLMax < fY[i])
1372 ymin = fY[i] - eyLMax;
1373 else
1374 ymin = TMath::Min(ymin, fY[i] / 3.);
1375 } else
1376 ymin = fY[i] - eyLMax;
1377 }
1378
1379 if (fY[i] + eyHMax > ymax)
1380 ymax = fY[i] + eyHMax;
1381 }
1382}
1383
1384////////////////////////////////////////////////////////////////////////////////
1385/// Deletes the y error with the index e
1386/// Note that you must keep at least 1 error
1387
1389{
1390 if (fNYErrors == 1 || e >= fNYErrors)
1391 return;
1392
1393 fEyL.erase(fEyL.begin() + e);
1394 fEyH.erase(fEyH.begin() + e);
1395 fAttFill.erase(fAttFill.begin() + e);
1396 fAttLine.erase(fAttLine.begin() + e);
1397
1398 fNYErrors -= 1;
1399}
1400
1401////////////////////////////////////////////////////////////////////////////////
1402/// Get error on x coordinate for point i
1403/// In case of asymmetric errors the mean of the square sum is returned
1404
1406{
1407 if (i < 0 || i >= fNpoints || (!fExL && !fExH))
1408 return -1.;
1409
1410 Double_t exL = fExL ? fExL[i] : 0.;
1411 Double_t exH = fExH ? fExH[i] : 0.;
1412 return TMath::Sqrt((exL * exL + exH * exH) / 2.);
1413}
1414
1415////////////////////////////////////////////////////////////////////////////////
1416/// Get error on y coordinate for point i
1417/// The multiple errors of the dimensions are summed according to fSumErrorsMode
1418/// In case of asymmetric errors the mean of the square sum is returned
1419
1421{
1422 if (i < 0 || i >= fNpoints || (fEyL.empty() && fEyH.empty()))
1423 return -1.;
1424
1425 Double_t eyL = GetErrorYlow(i);
1426 Double_t eyH = GetErrorYhigh(i);
1427 return TMath::Sqrt((eyL * eyL + eyH * eyH) / 2.);
1428}
1429
1430////////////////////////////////////////////////////////////////////////////////
1431/// Get error e on y coordinate for point i
1432/// In case of asymmetric errors the mean of the square sum is returned
1433
1435{
1436 if (i < 0 || i >= fNpoints || e >= fNYErrors || (fEyL.empty() && fEyH.empty()))
1437 return -1.;
1438
1439 Double_t eyL = fEyL.empty() ? 0. : fEyL[e][i];
1440 Double_t eyH = fEyH.empty() ? 0. : fEyH[e][i];
1441 return TMath::Sqrt((eyL * eyL + eyH * eyH) / 2.);
1442}
1443
1444////////////////////////////////////////////////////////////////////////////////
1445/// Get low error on x coordinate for point i
1446
1448{
1449 if (i < 0 || i >= fNpoints || !fExL)
1450 return -1.;
1451 else
1452 return fExL[i];
1453}
1454
1455////////////////////////////////////////////////////////////////////////////////
1456/// Get high error on x coordinate for point i
1457
1459{
1460 if (i < 0 || i >= fNpoints || !fExH)
1461 return -1.;
1462 else
1463 return fExH[i];
1464}
1465
1466////////////////////////////////////////////////////////////////////////////////
1467/// Get low error on y coordinate for point i
1468/// The multiple errors of the dimensions are summed according to fSumErrorsMode
1469
1471{
1472 if (i < 0 || i >= fNpoints || fEyL.empty())
1473 return -1.;
1474
1476 return fEyL[0][i];
1478 Double_t sum = 0.;
1479 for (Int_t j = 0; j < fNYErrors; j++)
1480 sum += fEyL[j][i] * fEyL[j][i];
1481 return TMath::Sqrt(sum);
1483 Double_t sum = 0.;
1484 for (Int_t j = 0; j < fNYErrors; j++)
1485 sum += fEyL[j][i];
1486 return sum;
1487 }
1488
1489 return -1.;
1490}
1491
1492////////////////////////////////////////////////////////////////////////////////
1493/// Get high error on y coordinate for point i
1494/// The multiple errors of the dimensions are summed according to fSumErrorsMode
1495
1497{
1498 if (i < 0 || i >= fNpoints || fEyH.empty())
1499 return -1.;
1500
1502 return fEyH[0][i];
1504 Double_t sum = 0.;
1505 for (Int_t j = 0; j < fNYErrors; j++)
1506 sum += fEyH[j][i] * fEyH[j][i];
1507 return TMath::Sqrt(sum);
1509 Double_t sum = 0.;
1510 for (Int_t j = 0; j < fNYErrors; j++)
1511 sum += fEyH[j][i];
1512 return sum;
1513 }
1514
1515 return -1.;
1516}
1517
1518////////////////////////////////////////////////////////////////////////////////
1519/// Get low error e on y coordinate for point i
1520
1522{
1523 if (i < 0 || i >= fNpoints || e >= fNYErrors || fEyL.empty())
1524 return -1.;
1525
1526 return fEyL[e][i];
1527}
1528
1529////////////////////////////////////////////////////////////////////////////////
1530/// Get high error e on y coordinate for point i
1531
1533{
1534 if (i < 0 || i >= fNpoints || e >= fNYErrors || fEyH.empty())
1535 return -1.;
1536
1537 return fEyH[e][i];
1538}
1539
1540////////////////////////////////////////////////////////////////////////////////
1541/// Get all low errors on y coordinates as an array summed according to fSumErrorsMode
1542
1544{
1545 if (!fEyLSum)
1547
1548 return fEyLSum;
1549}
1550
1551////////////////////////////////////////////////////////////////////////////////
1552/// Get all high errors on y coordinates as an array summed according to fSumErrorsMode
1553
1555{
1556 if (!fEyHSum)
1558
1559 return fEyHSum;
1560}
1561
1562////////////////////////////////////////////////////////////////////////////////
1563/// Get all low errors e on y coordinates as an array
1564
1566{
1567 if (e >= fNYErrors || fEyL.empty())
1568 return nullptr;
1569 else
1570 return fEyL[e].GetArray();
1571}
1572
1573////////////////////////////////////////////////////////////////////////////////
1574/// Get all high errors e on y coordinates as an array
1575
1577{
1578 if (e >= fNYErrors || fEyH.empty())
1579 return nullptr;
1580 else
1581 return fEyH[e].GetArray();
1582}
1583
1584////////////////////////////////////////////////////////////////////////////////
1585/// Get AttFill pointer for specified error dimension
1586
1588{
1589 if (e >= 0 && e < fNYErrors)
1590 return &fAttFill.at(e);
1591 else
1592 return nullptr;
1593}
1594
1595////////////////////////////////////////////////////////////////////////////////
1596/// Get AttLine pointer for specified error dimension
1597
1599{
1600 if (e >= 0 && e < fNYErrors)
1601 return &fAttLine.at(e);
1602 else
1603 return nullptr;
1604}
1605
1606////////////////////////////////////////////////////////////////////////////////
1607/// Get Fill Color for specified error e (-1 = Global and x errors)
1608
1610{
1611 if (e == -1)
1612 return GetFillColor();
1613 else if (e >= 0 && e < fNYErrors)
1614 return fAttFill[e].GetFillColor();
1615 else
1616 return 0;
1617}
1618
1619////////////////////////////////////////////////////////////////////////////////
1620/// Get Fill Style for specified error e (-1 = Global and x errors)
1621
1623{
1624 if (e == -1)
1625 return GetFillStyle();
1626 else if (e >= 0 && e < fNYErrors)
1627 return fAttFill[e].GetFillStyle();
1628 else
1629 return 0;
1630}
1631
1632////////////////////////////////////////////////////////////////////////////////
1633/// Get Line Color for specified error e (-1 = Global and x errors)
1634
1636{
1637 if (e == -1)
1638 return GetLineColor();
1639 else if (e >= 0 && e < fNYErrors)
1640 return fAttLine[e].GetLineColor();
1641 else
1642 return 0;
1643}
1644
1645////////////////////////////////////////////////////////////////////////////////
1646/// Get Line Style for specified error e (-1 = Global and x errors)
1647
1649{
1650 if (e == -1)
1651 return GetLineStyle();
1652 else if (e >= 0 && e < fNYErrors)
1653 return fAttLine[e].GetLineStyle();
1654 else
1655 return 0;
1656}
1657
1658////////////////////////////////////////////////////////////////////////////////
1659/// Get Line Width for specified error e (-1 = Global and x errors)
1660
1662{
1663 if (e == -1)
1664 return GetLineWidth();
1665 else if (e >= 0 && e < fNYErrors)
1666 return fAttLine[e].GetLineWidth();
1667 else
1668 return 0;
1669}
1670
1671////////////////////////////////////////////////////////////////////////////////
1672/// Print graph and errors values.
1673
1675{
1676 for (Int_t i = 0; i < fNpoints; i++) {
1677 printf("x[%d]=%g, y[%d]=%g", i, fX[i], i, fY[i]);
1678 if (fExL)
1679 printf(", exl[%d]=%g", i, fExL[i]);
1680 if (fExH)
1681 printf(", exh[%d]=%g", i, fExH[i]);
1682 if (!fEyL.empty())
1683 for (Int_t j = 0; j < fNYErrors; j++)
1684 printf(", eyl[%d][%d]=%g", j, i, fEyL[j][i]);
1685 if (!fEyH.empty())
1686 for (Int_t j = 0; j < fNYErrors; j++)
1687 printf(", eyh[%d][%d]=%g", j, i, fEyH[j][i]);
1688 printf("\n");
1689 }
1690}
1691
1692////////////////////////////////////////////////////////////////////////////////
1693/// Save primitive as a C++ statement(s) on output stream out
1694
1695void TGraphMultiErrors::SavePrimitive(std::ostream &out, Option_t *option)
1696{
1697 char quote = '"';
1698 out << " " << std::endl;
1699
1700 if (gROOT->ClassSaved(TGraphMultiErrors::Class()))
1701 out << " ";
1702 else
1703 out << " TGraphMultiErrors* ";
1704
1705 out << "tgme = new TGraphMultiErrors(" << fNpoints << ", " << fNYErrors << ");" << std::endl;
1706 out << " tgme->SetName(" << quote << GetName() << quote << ");" << std::endl;
1707 out << " tgme->SetTitle(" << quote << GetTitle() << quote << ");" << std::endl;
1708
1709 SaveFillAttributes(out, "tgme", 0, 1001);
1710 SaveLineAttributes(out, "tgme", 1, 1, 1);
1711 SaveMarkerAttributes(out, "tgme", 1, 1, 1);
1712
1713 for (Int_t j = 0; j < fNYErrors; j++) {
1714 fAttFill[j].SaveFillAttributes(out, Form("tgme->GetAttFill(%d)", j), 0, 1001);
1715 fAttLine[j].SaveLineAttributes(out, Form("tgme->GetAttLine(%d)", j), 1, 1, 1);
1716 }
1717
1718 for (Int_t i = 0; i < fNpoints; i++) {
1719 out << " tgme->SetPoint(" << i << ", " << fX[i] << ", " << fY[i] << ");" << std::endl;
1720 out << " tgme->SetPointEX(" << i << ", " << fExL[i] << ", " << fExH[i] << ");" << std::endl;
1721
1722 for (Int_t j = 0; j < fNYErrors; j++)
1723 out << " tgme->SetPointEY(" << i << ", " << j << ", " << fEyL[j][i] << ", " << fEyH[j][i] << ");"
1724 << std::endl;
1725 }
1726
1727 static Int_t frameNumber = 0;
1728 if (fHistogram) {
1729 frameNumber++;
1730 TString hname = fHistogram->GetName();
1731 hname += frameNumber;
1732 fHistogram->SetName(Form("Graph_%s", hname.Data()));
1733 fHistogram->SavePrimitive(out, "nodraw");
1734 out << " tgme->SetHistogram(" << fHistogram->GetName() << ");" << std::endl;
1735 out << " " << std::endl;
1736 }
1737
1738 // save list of functions
1739 TIter next(fFunctions);
1740 TObject *obj;
1741 while ((obj = next())) {
1742 obj->SavePrimitive(out, "nodraw");
1743 if (obj->InheritsFrom("TPaveStats")) {
1744 out << " tgme->GetListOfFunctions()->Add(ptstats);" << std::endl;
1745 out << " ptstats->SetParent(tgme->GetListOfFunctions());" << std::endl;
1746 } else
1747 out << " tgme->GetListOfFunctions()->Add(" << obj->GetName() << ");" << std::endl;
1748 }
1749
1750 const char *l = strstr(option, "multigraph");
1751 if (l)
1752 out << " multigraph->Add(tgme, " << quote << l + 10 << quote << ");" << std::endl;
1753 else
1754 out << " tgme->Draw(" << quote << option << quote << ");" << std::endl;
1755}
1756
1757////////////////////////////////////////////////////////////////////////////////
1758/// Set ex and ey values for point pointed by the mouse.
1759///
1760/// Up to 3 y error dimensions possible.
1761
1763 Double_t eyH2, Double_t eyL3, Double_t eyH3)
1764{
1765 Int_t px = gPad->GetEventX();
1766 Int_t py = gPad->GetEventY();
1767
1768 // localize point to be deleted
1769 Int_t ipoint = -2;
1770 Int_t i;
1771 // start with a small window (in case the mouse is very close to one point)
1772 for (i = 0; i < fNpoints; i++) {
1773 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
1774 Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
1775
1776 if (dpx * dpx + dpy * dpy < 25) {
1777 ipoint = i;
1778 break;
1779 }
1780 }
1781
1782 if (ipoint == -2)
1783 return;
1784
1785 SetPointEX(ipoint, exL, exH);
1786
1787 if (fNYErrors > 0)
1788 SetPointEY(ipoint, 0, eyL1, eyH1);
1789 if (fNYErrors > 1)
1790 SetPointEY(ipoint, 1, eyL2, eyH2);
1791 if (fNYErrors > 2)
1792 SetPointEY(ipoint, 2, eyL3, eyH3);
1793 gPad->Modified();
1794}
1795
1796////////////////////////////////////////////////////////////////////////////////
1797/// Set ex and ey values for point i.
1798
1800 const Double_t *eyH)
1801{
1802 SetPointEX(i, exL, exH);
1803 SetPointEY(i, ne, eyL, eyH);
1804}
1805
1806////////////////////////////////////////////////////////////////////////////////
1807/// Set ex values for point i.
1808
1810{
1811 SetPointEXlow(i, exL);
1812 SetPointEXhigh(i, exH);
1813}
1814
1815////////////////////////////////////////////////////////////////////////////////
1816/// Set exL value for point i.
1817
1819{
1820 if (i < 0)
1821 return;
1822
1823 if (i >= fNpoints) {
1824 // re-allocate the object
1825 TGraphMultiErrors::SetPoint(i, 0., 0.);
1826 }
1827
1828 fExL[i] = exL;
1829}
1830
1831////////////////////////////////////////////////////////////////////////////////
1832/// Set exH value for point i.
1833
1835{
1836 if (i < 0)
1837 return;
1838
1839 if (i >= fNpoints) {
1840 // re-allocate the object
1841 TGraphMultiErrors::SetPoint(i, 0., 0.);
1842 }
1843
1844 fExH[i] = exH;
1845}
1846
1847////////////////////////////////////////////////////////////////////////////////
1848/// Set ey values for point i.
1849
1850void TGraphMultiErrors::SetPointEY(Int_t i, Int_t ne, const Double_t *eyL, const Double_t *eyH)
1851{
1852 SetPointEYlow(i, ne, eyL);
1853 SetPointEYhigh(i, ne, eyH);
1854}
1855
1856////////////////////////////////////////////////////////////////////////////////
1857/// Set eyL values for point i.
1858
1860{
1861 for (Int_t j = 0; j < fNYErrors; j++) {
1862 if (j < ne)
1863 SetPointEYlow(i, j, eyL[j]);
1864 else
1865 SetPointEYlow(i, j, 0.);
1866 }
1867}
1868
1869////////////////////////////////////////////////////////////////////////////////
1870/// Set eyH values for point i.
1871
1873{
1874 for (Int_t j = 0; j < fNYErrors; j++) {
1875 if (j < ne)
1876 SetPointEYhigh(i, j, eyH[j]);
1877 else
1878 SetPointEYhigh(i, j, 0.);
1879 }
1880}
1881
1882////////////////////////////////////////////////////////////////////////////////
1883/// Set error e ey values for point i.
1884
1886{
1887 SetPointEYlow(i, e, eyL);
1888 SetPointEYhigh(i, e, eyH);
1889}
1890
1891////////////////////////////////////////////////////////////////////////////////
1892/// Set error e eyL value for point i.
1893
1895{
1896 if (i < 0 || e < 0)
1897 return;
1898
1899 if (i >= fNpoints)
1900 // re-allocate the object
1901 TGraphMultiErrors::SetPoint(i, 0., 0.);
1902
1903 while (e >= fNYErrors)
1905
1906 fEyL[e][i] = eyL;
1907 if (fEyLSum)
1908 fEyLSum[i] = GetErrorYlow(i);
1909 else
1911}
1912
1913////////////////////////////////////////////////////////////////////////////////
1914/// Set error e eyH value for point i.
1915
1917{
1918 if (i < 0 || e < 0)
1919 return;
1920
1921 if (i >= fNpoints)
1922 // re-allocate the object
1923 TGraphMultiErrors::SetPoint(i, 0., 0.);
1924
1925 while (e >= fNYErrors)
1927
1928 fEyH[e][i] = eyH;
1929 if (fEyHSum)
1930 fEyHSum[i] = GetErrorYhigh(i);
1931 else
1933}
1934
1935////////////////////////////////////////////////////////////////////////////////
1936/// Set error e ey values
1937
1938void TGraphMultiErrors::SetEY(Int_t e, Int_t np, const Double_t *eyL, const Double_t *eyH)
1939{
1940 SetEYlow(e, np, eyL);
1941 SetEYhigh(e, np, eyH);
1942}
1943
1944////////////////////////////////////////////////////////////////////////////////
1945/// Set error e eyL values
1946
1948{
1949 for (Int_t i = 0; i < fNpoints; i++) {
1950 if (i < np)
1951 SetPointEYlow(i, e, eyL[i]);
1952 else
1953 SetPointEYlow(i, e, 0.);
1954 }
1955}
1956
1957////////////////////////////////////////////////////////////////////////////////
1958/// Set error e eyH values
1959
1961{
1962 for (Int_t i = 0; i < fNpoints; i++) {
1963 if (i < np)
1964 SetPointEYhigh(i, e, eyH[i]);
1965 else
1966 SetPointEYhigh(i, e, 0.);
1967 }
1968}
1969
1970////////////////////////////////////////////////////////////////////////////////
1971/// Set the sum errors mode and recalculate summed errors
1973{
1974 if (fSumErrorsMode == m)
1975 return;
1976 fSumErrorsMode = m;
1978}
1979
1980////////////////////////////////////////////////////////////////////////////////
1981/// Set TAttFill parameters of error e by copying from another TAttFill (-1 = Global and x errors)
1982
1984{
1985 if (e == -1)
1986 taf->TAttFill::Copy(*this);
1987 else if (e >= 0 && e < fNYErrors)
1988 taf->TAttFill::Copy(fAttFill[e]);
1989}
1990
1991////////////////////////////////////////////////////////////////////////////////
1992/// Set TAttLine parameters of error e by copying from another TAttLine (-1 = Global and x errors)
1993
1995{
1996 if (e == -1)
1997 taf->TAttLine::Copy(*this);
1998 else if (e >= 0 && e < fNYErrors)
1999 taf->TAttLine::Copy(fAttLine[e]);
2000}
2001
2002////////////////////////////////////////////////////////////////////////////////
2003/// Set Fill Color of error e (-1 = Global and x errors)
2004
2006{
2007 if (e == -1)
2008 SetFillColor(fcolor);
2009 else if (e >= 0 && e < fNYErrors)
2010 fAttFill[e].SetFillColor(fcolor);
2011}
2012
2013////////////////////////////////////////////////////////////////////////////////
2014/// Set Fill Color and Alpha of error e (-1 = Global and x errors)
2015
2017{
2018 if (e == -1)
2019 SetFillColorAlpha(fcolor, falpha);
2020 else if (e >= 0 && e < fNYErrors)
2021 fAttFill[e].SetFillColorAlpha(fcolor, falpha);
2022}
2023
2024////////////////////////////////////////////////////////////////////////////////
2025/// Set Fill Style of error e (-1 = Global and x errors)
2026
2028{
2029 if (e == -1)
2030 SetFillStyle(fstyle);
2031 else if (e >= 0 && e < fNYErrors)
2032 fAttFill[e].SetFillStyle(fstyle);
2033}
2034
2035////////////////////////////////////////////////////////////////////////////////
2036/// Set Line Color of error e (-1 = Global and x errors)
2037
2039{
2040 if (e == -1)
2041 SetLineColor(lcolor);
2042 else if (e >= 0 && e < fNYErrors)
2043 fAttLine[e].SetLineColor(lcolor);
2044}
2045
2046////////////////////////////////////////////////////////////////////////////////
2047/// Set Line Color and Alpha of error e (-1 = Global and x errors)
2048
2050{
2051 if (e == -1)
2052 SetLineColorAlpha(lcolor, lalpha);
2053 else if (e >= 0 && e < fNYErrors)
2054 fAttLine[e].SetLineColorAlpha(lcolor, lalpha);
2055}
2056
2057////////////////////////////////////////////////////////////////////////////////
2058/// Set Line Style of error e (-1 = Global and x errors)
2059
2061{
2062 if (e == -1)
2063 SetLineStyle(lstyle);
2064 else if (e >= 0 && e < fNYErrors)
2065 fAttLine[e].SetLineStyle(lstyle);
2066}
2067
2068////////////////////////////////////////////////////////////////////////////////
2069/// Set Line Width of error e (-1 = Global and x errors)
2070
2072{
2073 if (e == -1)
2074 SetLineWidth(lwidth);
2075 else if (e >= 0 && e < fNYErrors)
2076 fAttLine[e].SetLineWidth(lwidth);
2077}
double
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
int Int_t
Definition RtypesCore.h:45
char Char_t
Definition RtypesCore.h:37
const Bool_t kFALSE
Definition RtypesCore.h:92
short Width_t
Definition RtypesCore.h:82
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
short Color_t
Definition RtypesCore.h:83
short Style_t
Definition RtypesCore.h:80
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
static unsigned int total
char name[80]
Definition TGX11.cxx:110
float xmin
float ymin
float xmax
float ymax
double sqrt(double)
#define gROOT
Definition TROOT.h:406
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
Definition TStyle.h:412
#define gPad
Array of doubles (64 bits per element).
Definition TArrayD.h:27
Double_t At(Int_t i) const
Definition TArrayD.h:79
Int_t fN
Definition TArray.h:38
Fill Area Attributes class.
Definition TAttFill.h:19
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:202
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:234
Line Attributes class.
Definition TAttLine.h:18
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition TAttLine.cxx:172
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:270
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.
static Double_t BetaMode(Double_t alpha, Double_t beta)
Compute the mode of the beta distribution.
static Bool_t BetaShortestInterval(Double_t level, Double_t alpha, Double_t beta, Double_t &lower, Double_t &upper)
Calculates the boundaries for a shortest confidence interval for a Beta distribution.
static Double_t BetaMean(Double_t alpha, Double_t beta)
Compute the mean (average) of the beta distribution.
static Double_t AgrestiCoull(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Agresti-Coull interval.
static Double_t FeldmanCousins(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Feldman-Cousins interval.
static Bool_t CheckBinning(const TH1 &pass, const TH1 &total)
Checks binning for each axis.
static Double_t BetaCentralInterval(Double_t level, Double_t alpha, Double_t beta, Bool_t bUpper)
Calculates the boundaries for a central confidence interval for a Beta distribution.
static Double_t Normal(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Returns the confidence limits for the efficiency supposing that the efficiency follows a normal distr...
static Double_t Wilson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Wilson interval.
static Bool_t CheckConsistency(const TH1 &pass, const TH1 &total, Option_t *opt="")
Checks the consistence of the given histograms.
static Double_t ClopperPearson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Clopper-Pearson interval.
1-Dim function class
Definition TF1.h:213
TGraph with asymmetric error bars and multiple y error dimensions.
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Compute Range.
virtual void Print(Option_t *chopt="") const
Print graph and errors values.
Double_t * fEyLSum
! array of summed Y low errors for fitting
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:30
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:31
virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE)
Set zero values for point arrays in the range [begin, end)
virtual void SetPointError(Double_t exL, Double_t exH, Double_t eyL1, Double_t eyH1, Double_t eyL2=0., Double_t eyH2=0., Double_t eyL3=0., Double_t eyH3=0.)
Set ex and ey values for point pointed by the mouse.
virtual TAttLine * GetAttLine(Int_t e)
Get AttLine pointer for specified error dimension.
virtual void SetFillColorAlpha(Int_t e, Color_t fcolor, Float_t falpha)
Set Fill Color and Alpha of error e (-1 = Global and x errors)
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:33
void Divide(const TH1 *pass, const TH1 *total, Option_t *opt="cp")
This function was adapted from the TGraphAsymmErrors class.
virtual void Apply(TF1 *f)
Apply a function to all data points y = f(x,y)
std::vector< TAttLine > fAttLine
the AttLine attributes of the different errors
virtual void AddYError(Int_t np, const Double_t *eyL=nullptr, const Double_t *eyH=nullptr)
Add a new y error to the graph and fill it with the values from eyL and eyH.
TGraphMultiErrors()
TGraphMultiErrors default constructor.
virtual void SetEY(Int_t e, Int_t np, const Double_t *eyL, const Double_t *eyH)
Set error e ey values.
virtual void SetSumErrorsMode(Int_t m)
Set the sum errors mode and recalculate summed errors.
virtual ~TGraphMultiErrors()
TGraphMultiErrors default destructor.
virtual void BayesDivide(const TH1 *pass, const TH1 *total, Option_t *opt="")
This function is only kept for backward compatibility.
TGraphMultiErrors & operator=(const TGraphMultiErrors &tgme)
TGraphMultiErrors assignment operator.
virtual Double_t GetErrorXhigh(Int_t i) const
Get high error on x coordinate for point i.
virtual Bool_t DoMerge(const TGraph *tg)
protected function to perform the merge operation of a graph with multiple asymmetric errors
Int_t fSumErrorsMode
How y errors are summed: kOnlyFirst = Only First; kSquareSum = Squared Sum; kSum = Absolute Addition.
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:35
virtual Bool_t CopyPoints(Double_t **arrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy errors from fE*** to arrays[] or to f Copy points.
virtual Double_t GetErrorY(Int_t i) const
Get error on y coordinate for point i The multiple errors of the dimensions are summed according to f...
@ kAbsSum
Calculate the absolute sum of all errors.
@ kSquareSum
Calculate the square sum of all errors.
@ kOnlyFirst
Only take errors from first dimension.
virtual Double_t GetErrorYlow(Int_t i) const
Get low error on y coordinate for point i The multiple errors of the dimensions are summed according ...
virtual Double_t * GetEYhigh() const
Get all high errors on y coordinates as an array summed according to fSumErrorsMode.
virtual TAttFill * GetAttFill(Int_t e)
Get AttFill pointer for specified error dimension.
virtual void SetLineStyle(Int_t e, Style_t lstyle)
Set Line Style of error e (-1 = Global and x errors)
virtual void SetPointEXhigh(Int_t i, Double_t exH)
Set exH value for point i.
Double_t * fExL
[fNpoints] array of X low errors
virtual Double_t ** Allocate(Int_t size)
Allocate internal data structures for size points.
virtual void SetLineWidth(Int_t e, Width_t lwidth)
Set Line Width of error e (-1 = Global and x errors)
std::vector< TArrayD > fEyH
two dimensional array of Y high errors
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:34
virtual void SetPointEX(Int_t i, Double_t exL, Double_t exH)
Set ex values for point i.
virtual void SetPointEYlow(Int_t i, Int_t ne, const Double_t *eyL)
Set eyL values for point i.
virtual void SetLineColorAlpha(Int_t e, Color_t lcolor, Float_t lalpha)
Set Line Color and Alpha of error e (-1 = Global and x errors)
virtual void SetFillColor(Int_t e, Color_t fcolor)
Set Fill Color of error e (-1 = Global and x errors)
void CalcYErrorsSum() const
Recalculates the summed y error arrays.
virtual void SetAttLine(Int_t e, TAttLine *tal)
Set TAttLine parameters of error e by copying from another TAttLine (-1 = Global and x errors)
Double_t * fEyHSum
! array of summed Y high errors for fitting
virtual void DeleteYError(Int_t e)
Deletes the y error with the index e Note that you must keep at least 1 error.
virtual Double_t * GetEYlow() const
Get all low errors on y coordinates as an array summed according to fSumErrorsMode.
virtual Double_t GetErrorX(Int_t i) const
Get error on x coordinate for point i In case of asymmetric errors the mean of the square sum is retu...
virtual void SetFillStyle(Int_t e, Style_t fstyle)
Set Fill Style of error e (-1 = Global and x errors)
virtual void SetEYhigh(Int_t e, Int_t np, const Double_t *eyH)
Set error e eyH values.
virtual Double_t GetErrorXlow(Int_t i) const
Get low error on x coordinate for point i.
virtual void SetAttFill(Int_t e, TAttFill *taf)
Set TAttFill parameters of error e by copying from another TAttFill (-1 = Global and x errors)
virtual void SetEYlow(Int_t e, Int_t np, const Double_t *eyL)
Set error e eyL values.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
std::vector< TAttFill > fAttFill
the AttFill attributes of the different errors
Bool_t CtorAllocate()
Should be called from ctors after fNpoints has been set Note: This function should be called only fro...
Double_t * fExH
[fNpoints] array of X high errors
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
virtual void SetPointEY(Int_t i, Int_t ne, const Double_t *eyL, const Double_t *eyH)
Set ey values for point i.
virtual void SetLineColor(Int_t e, Color_t lcolor)
Set Line Color of error e (-1 = Global and x errors)
virtual void SetPointEXlow(Int_t i, Double_t exL)
Set exL value for point i.
virtual void SetPointEYhigh(Int_t i, Int_t ne, const Double_t *eyH)
Set eyH values for point i.
Int_t fNYErrors
The amount of different y-errors.
std::vector< TArrayD > fEyL
two dimensional array of Y low errors
virtual void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy and release.
virtual Double_t GetErrorYhigh(Int_t i) const
Get high error on y coordinate for point i The multiple errors of the dimensions are summed according...
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
Int_t fNpoints
Number of points <= fMaxSize.
Definition TGraph.h:46
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition TGraph.cxx:2284
Int_t fMaxSize
!Current dimension of arrays fX and fY
Definition TGraph.h:45
TH1F * fHistogram
Pointer to histogram used for drawing axis.
Definition TGraph.h:50
virtual void SetName(const char *name="")
Set graph name.
Definition TGraph.cxx:2323
virtual void SetNameTitle(const char *name="", const char *title="")
Set graph name and title.
Definition TGraph.cxx:2359
Int_t GetN() const
Definition TGraph.h:124
virtual void SetTitle(const char *title="")
Change (i.e.
Definition TGraph.cxx:2339
Double_t * fY
[fNpoints] array of Y points
Definition TGraph.h:48
Bool_t CtorAllocate()
In constructors set fNpoints than call this method.
Definition TGraph.cxx:743
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:669
Double_t ** AllocateArrays(Int_t Narrays, Int_t arraySize)
Allocate arrays.
Definition TGraph.cxx:553
TList * fFunctions
Pointer to list of functions (fits and user)
Definition TGraph.h:49
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
Swap values.
Definition TGraph.cxx:2515
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
Definition TGraph.cxx:2580
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
Definition TGraph.cxx:2506
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:1037
Double_t * fX
[fNpoints] array of X points
Definition TGraph.h:47
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:2219
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:1607
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 !...
Definition TGraph.cxx:717
TGraph & operator=(const TGraph &)
Equal operator for this graph.
Definition TGraph.cxx:192
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition TH1.cxx:7122
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition TH1.cxx:8981
virtual Int_t GetDimension() const
Definition TH1.h:282
virtual Int_t GetNbinsX() const
Definition TH1.h:296
virtual Double_t GetBinLowEdge(Int_t bin) const
Return bin lower edge for 1D histogram.
Definition TH1.cxx:8992
virtual void SetName(const char *name)
Change the name of this histogram.
Definition TH1.cxx:8800
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:4993
virtual TArrayD * GetSumw2()
Definition TH1.h:312
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width for 1D histogram.
Definition TH1.cxx:9003
virtual Double_t GetSumOfWeights() const
Return the sum of weights excluding under/overflows.
Definition TH1.cxx:7810
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:359
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:879
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition TObject.cxx:666
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:893
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:867
Basic string class.
Definition TString.h:136
void ToLower()
Change string to lower-case.
Definition TString.cxx:1145
const char * Data() const
Definition TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:692
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
Float_t GetErrorX() const
Definition TStyle.h:178
TVectorT.
Definition TVectorT.h:27
Int_t GetNrows() const
Definition TVectorT.h:75
Int_t GetLwb() const
Definition TVectorT.h:73
double normal_quantile_c(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the upper tail of the normal (Gaussian) distri...
const Double_t sigma
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:713
Short_t Max(Short_t a, Short_t b)
Definition TMathBase.h:212
Int_t Finite(Double_t x)
Check if it is finite with a mask in order to be consistent in presence of fast math.
Definition TMath.h:771
Double_t Sqrt(Double_t x)
Definition TMath.h:691
Short_t Min(Short_t a, Short_t b)
Definition TMathBase.h:180
Short_t Abs(Short_t d)
Definition TMathBase.h:120
auto * m
Definition textangle.C:8
auto * l
Definition textangle.C:4
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345