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 Graphs
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
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`,`exH` or `eyL`,`exH` 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`,`exH` or `eyL`,`eyH` 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`,`exH` or `eyL`,`exH` 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`,`exH` or `eyL`,`exH` 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`,`exH` 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`,`exH` 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`,`exH` 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`,`exH` 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`,`exH` 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`,`exH` 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`,`exH` 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`,`exH` 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` the Y coordinates from `tvY`
419/// and the errors from vectors `tvExL`, `tvExH` and `tvEyL`, `tvEyH`.
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` the Y coordinates from `tvY`
458/// and the errors from vectors `tvExL`, `tvExH` and `tvEyL`, `tvEyH`.
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 dimension.
495/// A grapherrors is built with the X coordinates taken from `tvX` the Y coordinates from `tvY`
496/// and the errors from vectors `tvExL`, `tvExH` 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` the Y coordinates from `tvY`
535/// and the errors from vectors `tvExL`, `tvExH` 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/// Update the fX, fY, fExL, fExH, fEyL and fEyH arrays with the sorted values.
884
885void TGraphMultiErrors::UpdateArrays(const std::vector<Int_t> &sorting_indices, Int_t numSortedPoints, Int_t low)
886{
887 std::vector<Double_t> fExLSorted(numSortedPoints);
888 std::vector<Double_t> fExHSorted(numSortedPoints);
889
890 std::generate(fExLSorted.begin(), fExLSorted.end(),
891 [begin = low, &sorting_indices, this]() mutable { return fExL[sorting_indices[begin++]]; });
892 std::generate(fExHSorted.begin(), fExHSorted.end(),
893 [begin = low, &sorting_indices, this]() mutable { return fExH[sorting_indices[begin++]]; });
894
895 std::copy(fExLSorted.begin(), fExLSorted.end(), fExL + low);
896 std::copy(fExHSorted.begin(), fExHSorted.end(), fExH + low);
897
898 for (Int_t j = 0; j < fNYErrors; j++) {
899 std::vector<Double_t> fEyLSorted(numSortedPoints);
900 std::vector<Double_t> fEyHSorted(numSortedPoints);
901
902 std::generate(fEyLSorted.begin(), fEyLSorted.end(),
903 [begin = low, &sorting_indices, &j, this]() mutable { return fEyL[j].GetArray()[sorting_indices[begin++]]; });
904 std::generate(fEyHSorted.begin(), fEyHSorted.end(),
905 [begin = low, &sorting_indices, &j, this]() mutable { return fEyL[j].GetArray()[sorting_indices[begin++]]; });
906
907 std::copy(fEyLSorted.begin(), fEyLSorted.end(), fEyL[j].GetArray() + low);
908 std::copy(fEyHSorted.begin(), fEyHSorted.end(), fEyL[j].GetArray() + low);
909 }
910
911 TGraph::UpdateArrays(sorting_indices, numSortedPoints, low);
912}
913
914////////////////////////////////////////////////////////////////////////////////
915/// Add a new y error to the graph and fill it with the values from `eyL` and `eyH`
916
918{
919 fEyL.emplace_back(np, eyL);
920 fEyH.emplace_back(np, eyH);
921 fEyL.back().Set(fNpoints);
922 fEyH.back().Set(fNpoints);
923 fAttFill.emplace_back();
924 fAttLine.emplace_back();
925
926 fNYErrors += 1;
927
929}
930
931////////////////////////////////////////////////////////////////////////////////
932/// Allocate internal data structures for `size` points.
934{
935 return AllocateArrays(6, size);
936}
937
938////////////////////////////////////////////////////////////////////////////////
939/// Apply a function to all data points \f$ y = f(x,y) \f$.
940///
941/// Errors are calculated as \f$ eyh = f(x,y+eyh)-f(x,y) \f$ and
942/// \f$ eyl = f(x,y)-f(x,y-eyl) \f$
943///
944/// Only the first error dimension is affected.
945///
946/// Special treatment has to be applied for the functions where the
947/// role of "up" and "down" is reversed.
948///
949/// Function suggested/implemented by Miroslav Helbich <helbich@mail.desy.de>
950
952{
953 Double_t x, y, eyL, eyH, eyLNew, eyHNew, fxy;
954
955 if (fHistogram) {
956 delete fHistogram;
957 fHistogram = nullptr;
958 }
959
960 for (Int_t i = 0; i < fNpoints; i++) {
961 GetPoint(i, x, y);
962 eyL = GetErrorYlow(i, 0);
963 eyH = GetErrorYhigh(i, 0);
964
965 fxy = f->Eval(x, y);
966 SetPoint(i, x, fxy);
967
968 if (f->Eval(x, y - eyL) < f->Eval(x, y + eyH)) {
969 eyLNew = TMath::Abs(fxy - f->Eval(x, y - eyL));
970 eyHNew = TMath::Abs(f->Eval(x, y + eyH) - fxy);
971 } else {
972 eyHNew = TMath::Abs(fxy - f->Eval(x, y - eyL));
973 eyLNew = TMath::Abs(f->Eval(x, y + eyH) - fxy);
974 }
975
976 // systematic errors and error on x doesn't change
977 SetPointEY(i, 0, eyLNew, eyHNew);
978 }
979
980 if (gPad)
981 gPad->Modified();
982}
983
984////////////////////////////////////////////////////////////////////////////////
985/// This function is only kept for backward compatibility.
986/// You should rather use the Divide method.
987/// It calls `Divide(pass,total,"cl=0.683 b(1,1) mode")` which is equivalent to the
988/// former BayesDivide method.
989
991{
992 Divide(pass, total, "cl=0.683 b(1,1) mode");
993}
994
995////////////////////////////////////////////////////////////////////////////////
996/// This function was adapted from the TGraphAsymmErrors class.
997/// See TGraphAsymmErrors::Divide for the documentation
998///
999/// Only the first error dimension is affected.
1000
1001void TGraphMultiErrors::Divide(const TH1 *pass, const TH1 *total, Option_t *opt)
1002{
1003 // check pointers
1004 if (!pass || !total) {
1005 Error("Divide", "one of the passed pointers is zero");
1006 return;
1007 }
1008
1009 // check dimension of histograms; only 1-dimensional ones are accepted
1010 if ((pass->GetDimension() > 1) || (total->GetDimension() > 1)) {
1011 Error("Divide", "passed histograms are not one-dimensional");
1012 return;
1013 }
1014
1015 // check whether histograms are filled with weights -> use number of effective
1016 // entries
1017 Bool_t bEffective = false;
1018 // compare sum of weights with sum of squares of weights
1019 // re-compute here to be sure to get the right values
1020 Double_t psumw = 0;
1021 Double_t psumw2 = 0;
1022 if (pass->GetSumw2()->fN > 0) {
1023 for (int i = 0; i < pass->GetNbinsX(); ++i) {
1024 psumw += pass->GetBinContent(i);
1025 psumw2 += pass->GetSumw2()->At(i);
1026 }
1027 } else {
1028 psumw = pass->GetSumOfWeights();
1029 psumw2 = psumw;
1030 }
1031 if (TMath::Abs(psumw - psumw2) > 1e-6)
1032 bEffective = true;
1033
1034 Double_t tsumw = 0;
1035 Double_t tsumw2 = 0;
1036 if (total->GetSumw2()->fN > 0) {
1037 for (int i = 0; i < total->GetNbinsX(); ++i) {
1038 tsumw += total->GetBinContent(i);
1039 tsumw2 += total->GetSumw2()->At(i);
1040 }
1041 } else {
1042 tsumw = total->GetSumOfWeights();
1043 tsumw2 = tsumw;
1044 }
1045 if (TMath::Abs(tsumw - tsumw2) > 1e-6)
1046 bEffective = true;
1047
1048 // we do not want to ignore the weights
1049 // if (bEffective && (pass->GetSumw2()->fN == 0 || total->GetSumw2()->fN == 0) ) {
1050 // Warning("Divide","histogram have been computed with weights but the sum of weight squares are not stored in the
1051 // histogram. Error calculation is performed ignoring the weights"); bEffective = false;
1052 // }
1053
1054 // parse option
1055 TString option = opt;
1056 option.ToLower();
1057
1058 Bool_t bVerbose = false;
1059 // pointer to function returning the boundaries of the confidence interval
1060 //(is only used in the frequentist cases.)
1061 // Double_t (*pBound)(Int_t,Int_t,Double_t,Bool_t) = &TEfficiency::ClopperPearson; // default method
1062 Double_t (*pBound)(Double_t, Double_t, Double_t, Bool_t) = &TEfficiency::ClopperPearson; // default method
1063 // confidence level
1064 Double_t conf = 0.682689492137;
1065 // values for bayesian statistics
1066 Bool_t bIsBayesian = false;
1067 Double_t alpha = 1;
1068 Double_t beta = 1;
1069
1070 // verbose mode
1071 if (option.Contains("v")) {
1072 option.ReplaceAll("v", "");
1073 bVerbose = true;
1074 if (bEffective)
1075 Info("Divide", "weight will be considered in the Histogram Ratio");
1076 }
1077
1078 // confidence level
1079 if (option.Contains("cl=")) {
1080 Double_t level = -1;
1081 // coverity [secure_coding : FALSE]
1082 sscanf(strstr(option.Data(), "cl="), "cl=%lf", &level);
1083 if ((level > 0) && (level < 1))
1084 conf = level;
1085 else
1086 Warning("Divide", "given confidence level %.3lf is invalid", level);
1087 option.ReplaceAll("cl=", "");
1088 }
1089
1090 // normal approximation
1091 if (option.Contains("n")) {
1092 option.ReplaceAll("n", "");
1093 pBound = &TEfficiency::Normal;
1094 }
1095
1096 // clopper pearson interval
1097 if (option.Contains("cp")) {
1098 option.ReplaceAll("cp", "");
1100 }
1101
1102 // wilson interval
1103 if (option.Contains("w")) {
1104 option.ReplaceAll("w", "");
1105 pBound = &TEfficiency::Wilson;
1106 }
1107
1108 // agresti coull interval
1109 if (option.Contains("ac")) {
1110 option.ReplaceAll("ac", "");
1111 pBound = &TEfficiency::AgrestiCoull;
1112 }
1113 // Feldman-Cousins interval
1114 if (option.Contains("fc")) {
1115 option.ReplaceAll("fc", "");
1117 }
1118 // mid-P Lancaster interval (In a later ROOT Version!)
1119 if (option.Contains("midp")) {
1120 option.ReplaceAll("midp", "");
1121 // pBound = &TEfficiency::MidPInterval;
1122 }
1123
1124 // bayesian with prior
1125 if (option.Contains("b(")) {
1126 Double_t a = 0;
1127 Double_t b = 0;
1128 sscanf(strstr(option.Data(), "b("), "b(%lf,%lf)", &a, &b);
1129 if (a > 0)
1130 alpha = a;
1131 else
1132 Warning("Divide", "given shape parameter for alpha %.2lf is invalid", a);
1133 if (b > 0)
1134 beta = b;
1135 else
1136 Warning("Divide", "given shape parameter for beta %.2lf is invalid", b);
1137 option.ReplaceAll("b(", "");
1138 bIsBayesian = true;
1139 }
1140
1141 // use posterior mode
1142 Bool_t usePosteriorMode = false;
1143 if (bIsBayesian && option.Contains("mode")) {
1144 usePosteriorMode = true;
1145 option.ReplaceAll("mode", "");
1146 }
1147
1148 Bool_t plot0Bins = false;
1149 if (option.Contains("e0")) {
1150 plot0Bins = true;
1151 option.ReplaceAll("e0", "");
1152 }
1153
1154 Bool_t useShortestInterval = false;
1155 if (bIsBayesian && (option.Contains("sh") || (usePosteriorMode && !option.Contains("cen")))) {
1156 useShortestInterval = true;
1157 }
1158
1159 // interpret as Poisson ratio
1160 Bool_t bPoissonRatio = false;
1161 if (option.Contains("pois")) {
1162 bPoissonRatio = true;
1163 option.ReplaceAll("pois", "");
1164 }
1165
1166 // weights works only in case of Normal approximation or Bayesian for binomial interval
1167 // in case of Poisson ratio we can use weights by rescaling the obtained results using the effective entries
1168 if ((bEffective && !bPoissonRatio) && !bIsBayesian && pBound != &TEfficiency::Normal) {
1169 Warning("Divide", "Histograms have weights: only Normal or Bayesian error calculation is supported");
1170 Info("Divide", "Using now the Normal approximation for weighted histograms");
1171 }
1172
1173 if (bPoissonRatio) {
1174 if (pass->GetDimension() != total->GetDimension()) {
1175 Error("Divide", "passed histograms are not of the same dimension");
1176 return;
1177 }
1178
1179 if (!TEfficiency::CheckBinning(*pass, *total)) {
1180 Error("Divide", "passed histograms are not consistent");
1181 return;
1182 }
1183 } else {
1184 // check consistency of histograms, allowing weights
1185 if (!TEfficiency::CheckConsistency(*pass, *total, "w")) {
1186 Error("Divide", "passed histograms are not consistent");
1187 return;
1188 }
1189 }
1190
1191 // Set the graph to have a number of points equal to the number of histogram
1192 // bins
1193 Int_t nbins = pass->GetNbinsX();
1194 Set(nbins);
1195
1196 // Ok, now set the points for each bin
1197 // (Note: the TH1 bin content is shifted to the right by one:
1198 // bin=0 is underflow, bin=nbins+1 is overflow.)
1199
1200 // this keeps track of the number of points added to the graph
1201 Int_t npoint = 0;
1202 // number of total and passed events
1203 Double_t t = 0, p = 0;
1204 Double_t tw = 0, tw2 = 0, pw = 0, pw2 = 0, wratio = 1; // for the case of weights
1205 // loop over all bins and fill the graph
1206 for (Int_t b = 1; b <= nbins; ++b) {
1207 // efficiency with lower and upper boundary of confidence interval default value when total =0;
1208 Double_t eff = 0., low = 0., upper = 0.;
1209
1210 // special case in case of weights we have to consider the sum of weights and the sum of weight squares
1211 if (bEffective) {
1212 tw = total->GetBinContent(b);
1213 tw2 = (total->GetSumw2()->fN > 0) ? total->GetSumw2()->At(b) : tw;
1214 pw = pass->GetBinContent(b);
1215 pw2 = (pass->GetSumw2()->fN > 0) ? pass->GetSumw2()->At(b) : pw;
1216
1217 if (bPoissonRatio) {
1218 // tw += pw;
1219 // tw2 += pw2;
1220 // compute ratio on the effective entries ( p and t)
1221 // special case is when (pw=0, pw2=0) in this case we cannot get the bin weight.
1222 // we use then the overall weight of the full histogram
1223 if (pw == 0 && pw2 == 0)
1224 p = 0;
1225 else
1226 p = (pw * pw) / pw2;
1227
1228 if (tw == 0 && tw2 == 0)
1229 t = 0;
1230 else
1231 t = (tw * tw) / tw2;
1232
1233 if (pw > 0 && tw > 0)
1234 // this is the ratio of the two bin weights ( pw/p / t/tw )
1235 wratio = (pw * t) / (p * tw);
1236 else if (pw == 0 && tw > 0)
1237 // case p histogram has zero compute the weights from all the histogram
1238 // weight of histogram - sumw2/sumw
1239 wratio = (psumw2 * t) / (psumw * tw);
1240 else if (tw == 0 && pw > 0)
1241 // case t histogram has zero compute the weights from all the histogram
1242 // weight of histogram - sumw2/sumw
1243 wratio = (pw * tsumw) / (p * tsumw2);
1244 else if (p > 0)
1245 wratio = pw / p; // not sure if needed
1246 else {
1247 // case both pw and tw are zero - we skip these bins
1248 if (!plot0Bins)
1249 continue; // skip bins with total <= 0
1250 }
1251
1252 t += p;
1253 // std::cout << p << " " << t << " " << wratio << std::endl;
1254 } else if (tw <= 0 && !plot0Bins)
1255 continue; // skip bins with total <= 0
1256
1257 // in the case of weights have the formula only for
1258 // the normal and bayesian statistics (see below)
1259
1260 }
1261
1262 // use bin contents
1263 else {
1264 t = TMath::Nint(total->GetBinContent(b));
1265 p = TMath::Nint(pass->GetBinContent(b));
1266
1267 if (bPoissonRatio)
1268 t += p;
1269
1270 if (t == 0. && !plot0Bins)
1271 continue; // skip bins with total = 0
1272 }
1273
1274 // using bayesian statistics
1275 if (bIsBayesian) {
1276 if ((bEffective && !bPoissonRatio) && tw2 <= 0) {
1277 // case of bins with zero errors
1278 eff = pw / tw;
1279 low = eff;
1280 upper = eff;
1281 } else {
1282 Double_t aa, bb;
1283
1284 if (bEffective && !bPoissonRatio) {
1285 // tw/tw2 re-normalize the weights
1286 double norm = tw / tw2; // case of tw2 = 0 is treated above
1287 aa = pw * norm + alpha;
1288 bb = (tw - pw) * norm + beta;
1289 } else {
1290 aa = double(p) + alpha;
1291 bb = double(t - p) + beta;
1292 }
1293 if (usePosteriorMode)
1294 eff = TEfficiency::BetaMode(aa, bb);
1295 else
1296 eff = TEfficiency::BetaMean(aa, bb);
1297
1298 if (useShortestInterval) {
1299 TEfficiency::BetaShortestInterval(conf, aa, bb, low, upper);
1300 } else {
1301 low = TEfficiency::BetaCentralInterval(conf, aa, bb, false);
1302 upper = TEfficiency::BetaCentralInterval(conf, aa, bb, true);
1303 }
1304 }
1305 }
1306 // case of non-bayesian statistics
1307 else {
1308 if (bEffective && !bPoissonRatio) {
1309
1310 if (tw > 0) {
1311
1312 eff = pw / tw;
1313
1314 // use normal error calculation using variance of MLE with weights (F.James 8.5.2)
1315 // this is the same formula used in ROOT for TH1::Divide("B")
1316
1317 double variance = (pw2 * (1. - 2 * eff) + tw2 * eff * eff) / (tw * tw);
1318 double sigma = sqrt(variance);
1319
1320 double prob = 0.5 * (1. - conf);
1321 double delta = ROOT::Math::normal_quantile_c(prob, sigma);
1322 low = eff - delta;
1323 upper = eff + delta;
1324 if (low < 0)
1325 low = 0;
1326 if (upper > 1)
1327 upper = 1.;
1328 }
1329 } else {
1330 // when not using weights (all cases) or in case of Poisson ratio with weights
1331 if (t != 0.)
1332 eff = ((Double_t)p) / t;
1333
1334 low = pBound(t, p, conf, false);
1335 upper = pBound(t, p, conf, true);
1336 }
1337 }
1338 // treat as Poisson ratio
1339 if (bPoissonRatio) {
1340 Double_t ratio = eff / (1 - eff);
1341 // take the intervals in eff as intervals in the Poisson ratio
1342 low = low / (1. - low);
1343 upper = upper / (1. - upper);
1344 eff = ratio;
1345 if (bEffective) {
1346 // scale result by the ratio of the weight
1347 eff *= wratio;
1348 low *= wratio;
1349 upper *= wratio;
1350 }
1351 }
1352 // Set the point center and its errors
1353 if (TMath::Finite(eff)) {
1354 SetPoint(npoint, pass->GetBinCenter(b), eff);
1355 SetPointEX(npoint, pass->GetBinCenter(b) - pass->GetBinLowEdge(b),
1356 pass->GetBinLowEdge(b) - pass->GetBinCenter(b) + pass->GetBinWidth(b));
1357 SetPointEY(npoint, 0, eff - low, upper - eff);
1358 npoint++; // we have added a point to the graph
1359 }
1360 }
1361
1362 Set(npoint); // tell the graph how many points we've really added
1363 if (npoint < nbins)
1364 Warning("Divide", "Number of graph points is different than histogram bins - %d points have been skipped",
1365 nbins - npoint);
1366
1367 if (bVerbose) {
1368 Info("Divide", "made a graph with %d points from %d bins", npoint, nbins);
1369 Info("Divide", "used confidence level: %.2lf\n", conf);
1370 if (bIsBayesian)
1371 Info("Divide", "used prior probability ~ beta(%.2lf,%.2lf)", alpha, beta);
1372 Print();
1373 }
1374}
1375
1376////////////////////////////////////////////////////////////////////////////////
1377/// Compute Range.
1378
1380{
1382
1383 for (Int_t i = 0; i < fNpoints; i++) {
1384 if (fX[i] - fExL[i] < xmin) {
1385 if (gPad && gPad->GetLogx()) {
1386 if (fExL[i] < fX[i])
1387 xmin = fX[i] - fExL[i];
1388 else
1389 xmin = TMath::Min(xmin, fX[i] / 3.);
1390 } else
1391 xmin = fX[i] - fExL[i];
1392 }
1393
1394 if (fX[i] + fExH[i] > xmax)
1395 xmax = fX[i] + fExH[i];
1396
1397 Double_t eyLMax = 0., eyHMax = 0.;
1398 for (Int_t j = 0; j < fNYErrors; j++) {
1399 eyLMax = TMath::Max(eyLMax, fEyL[j][i]);
1400 eyHMax = TMath::Max(eyHMax, fEyH[j][i]);
1401 }
1402
1403 if (fY[i] - eyLMax < ymin) {
1404 if (gPad && gPad->GetLogy()) {
1405 if (eyLMax < fY[i])
1406 ymin = fY[i] - eyLMax;
1407 else
1408 ymin = TMath::Min(ymin, fY[i] / 3.);
1409 } else
1410 ymin = fY[i] - eyLMax;
1411 }
1412
1413 if (fY[i] + eyHMax > ymax)
1414 ymax = fY[i] + eyHMax;
1415 }
1416}
1417
1418////////////////////////////////////////////////////////////////////////////////
1419/// Deletes the y error with the index `e`.
1420/// Note that you must keep at least 1 error
1421
1423{
1424 if (fNYErrors == 1 || e >= fNYErrors)
1425 return;
1426
1427 fEyL.erase(fEyL.begin() + e);
1428 fEyH.erase(fEyH.begin() + e);
1429 fAttFill.erase(fAttFill.begin() + e);
1430 fAttLine.erase(fAttLine.begin() + e);
1431
1432 fNYErrors -= 1;
1433}
1434
1435////////////////////////////////////////////////////////////////////////////////
1436/// Get error on x coordinate for point `i`.
1437/// In case of asymmetric errors the mean of the square sum is returned
1438
1440{
1441 if (i < 0 || i >= fNpoints || (!fExL && !fExH))
1442 return -1.;
1443
1444 Double_t exL = fExL ? fExL[i] : 0.;
1445 Double_t exH = fExH ? fExH[i] : 0.;
1446 return TMath::Sqrt((exL * exL + exH * exH) / 2.);
1447}
1448
1449////////////////////////////////////////////////////////////////////////////////
1450/// Get error on y coordinate for point `i`.
1451/// The multiple errors of the dimensions are summed according to `fSumErrorsMode`.
1452/// In case of asymmetric errors the mean of the square sum is returned
1453
1455{
1456 if (i < 0 || i >= fNpoints || (fEyL.empty() && fEyH.empty()))
1457 return -1.;
1458
1459 Double_t eyL = GetErrorYlow(i);
1460 Double_t eyH = GetErrorYhigh(i);
1461 return TMath::Sqrt((eyL * eyL + eyH * eyH) / 2.);
1462}
1463
1464////////////////////////////////////////////////////////////////////////////////
1465/// Get error e on y coordinate for point `i`.
1466/// In case of asymmetric errors the mean of the square sum is returned
1467
1469{
1470 if (i < 0 || i >= fNpoints || e >= fNYErrors || (fEyL.empty() && fEyH.empty()))
1471 return -1.;
1472
1473 Double_t eyL = fEyL.empty() ? 0. : fEyL[e][i];
1474 Double_t eyH = fEyH.empty() ? 0. : fEyH[e][i];
1475 return TMath::Sqrt((eyL * eyL + eyH * eyH) / 2.);
1476}
1477
1478////////////////////////////////////////////////////////////////////////////////
1479/// Get low error on x coordinate for point `i`.
1480
1482{
1483 if (i < 0 || i >= fNpoints || !fExL)
1484 return -1.;
1485 else
1486 return fExL[i];
1487}
1488
1489////////////////////////////////////////////////////////////////////////////////
1490/// Get high error on x coordinate for point `i`.
1491
1493{
1494 if (i < 0 || i >= fNpoints || !fExH)
1495 return -1.;
1496 else
1497 return fExH[i];
1498}
1499
1500////////////////////////////////////////////////////////////////////////////////
1501/// Get low error on y coordinate for point `i`.
1502/// The multiple errors of the dimensions are summed according to `fSumErrorsMode`.
1503
1505{
1506 if (i < 0 || i >= fNpoints || fEyL.empty())
1507 return -1.;
1508
1510 return fEyL[0][i];
1512 Double_t sum = 0.;
1513 for (Int_t j = 0; j < fNYErrors; j++)
1514 sum += fEyL[j][i] * fEyL[j][i];
1515 return TMath::Sqrt(sum);
1517 Double_t sum = 0.;
1518 for (Int_t j = 0; j < fNYErrors; j++)
1519 sum += fEyL[j][i];
1520 return sum;
1521 }
1522
1523 return -1.;
1524}
1525
1526////////////////////////////////////////////////////////////////////////////////
1527/// Get high error on y coordinate for point `i`.
1528/// The multiple errors of the dimensions are summed according to `fSumErrorsMode`.
1529
1531{
1532 if (i < 0 || i >= fNpoints || fEyH.empty())
1533 return -1.;
1534
1536 return fEyH[0][i];
1538 Double_t sum = 0.;
1539 for (Int_t j = 0; j < fNYErrors; j++)
1540 sum += fEyH[j][i] * fEyH[j][i];
1541 return TMath::Sqrt(sum);
1543 Double_t sum = 0.;
1544 for (Int_t j = 0; j < fNYErrors; j++)
1545 sum += fEyH[j][i];
1546 return sum;
1547 }
1548
1549 return -1.;
1550}
1551
1552////////////////////////////////////////////////////////////////////////////////
1553/// Get low error e on y coordinate for point `i`.
1554
1556{
1557 if (i < 0 || i >= fNpoints || e >= fNYErrors || fEyL.empty())
1558 return -1.;
1559
1560 return fEyL[e][i];
1561}
1562
1563////////////////////////////////////////////////////////////////////////////////
1564/// Get high error e on y coordinate for point `i`.
1565
1567{
1568 if (i < 0 || i >= fNpoints || e >= fNYErrors || fEyH.empty())
1569 return -1.;
1570
1571 return fEyH[e][i];
1572}
1573
1574////////////////////////////////////////////////////////////////////////////////
1575/// Get all low errors on y coordinates as an array summed according to `fSumErrorsMode`.
1576
1578{
1579 if (!fEyLSum)
1581
1582 return fEyLSum;
1583}
1584
1585////////////////////////////////////////////////////////////////////////////////
1586/// Get all high errors on y coordinates as an array summed according to `fSumErrorsMode`.
1587
1589{
1590 if (!fEyHSum)
1592
1593 return fEyHSum;
1594}
1595
1596////////////////////////////////////////////////////////////////////////////////
1597/// Get all low errors `e` on y coordinates as an array.
1598
1600{
1601 if (e >= fNYErrors || fEyL.empty())
1602 return nullptr;
1603 else
1604 return fEyL[e].GetArray();
1605}
1606
1607////////////////////////////////////////////////////////////////////////////////
1608/// Get all high errors `e` on y coordinates as an array.
1609
1611{
1612 if (e >= fNYErrors || fEyH.empty())
1613 return nullptr;
1614 else
1615 return fEyH[e].GetArray();
1616}
1617
1618////////////////////////////////////////////////////////////////////////////////
1619/// Get AttFill pointer for specified error dimension.
1620
1622{
1623 if (e >= 0 && e < fNYErrors)
1624 return &fAttFill.at(e);
1625 else
1626 return nullptr;
1627}
1628
1629////////////////////////////////////////////////////////////////////////////////
1630/// Get AttLine pointer for specified error dimension.
1631
1633{
1634 if (e >= 0 && e < fNYErrors)
1635 return &fAttLine.at(e);
1636 else
1637 return nullptr;
1638}
1639
1640////////////////////////////////////////////////////////////////////////////////
1641/// Get Fill Color for specified error e (-1 = Global and x errors).
1642
1644{
1645 if (e == -1)
1646 return GetFillColor();
1647 else if (e >= 0 && e < fNYErrors)
1648 return fAttFill[e].GetFillColor();
1649 else
1650 return 0;
1651}
1652
1653////////////////////////////////////////////////////////////////////////////////
1654/// Get Fill Style for specified error e (-1 = Global and x errors).
1655
1657{
1658 if (e == -1)
1659 return GetFillStyle();
1660 else if (e >= 0 && e < fNYErrors)
1661 return fAttFill[e].GetFillStyle();
1662 else
1663 return 0;
1664}
1665
1666////////////////////////////////////////////////////////////////////////////////
1667/// Get Line Color for specified error e (-1 = Global and x errors).
1668
1670{
1671 if (e == -1)
1672 return GetLineColor();
1673 else if (e >= 0 && e < fNYErrors)
1674 return fAttLine[e].GetLineColor();
1675 else
1676 return 0;
1677}
1678
1679////////////////////////////////////////////////////////////////////////////////
1680/// Get Line Style for specified error e (-1 = Global and x errors).
1681
1683{
1684 if (e == -1)
1685 return GetLineStyle();
1686 else if (e >= 0 && e < fNYErrors)
1687 return fAttLine[e].GetLineStyle();
1688 else
1689 return 0;
1690}
1691
1692////////////////////////////////////////////////////////////////////////////////
1693/// Get Line Width for specified error e (-1 = Global and x errors).
1694
1696{
1697 if (e == -1)
1698 return GetLineWidth();
1699 else if (e >= 0 && e < fNYErrors)
1700 return fAttLine[e].GetLineWidth();
1701 else
1702 return 0;
1703}
1704
1705////////////////////////////////////////////////////////////////////////////////
1706/// Print graph and errors values.
1707
1709{
1710 for (Int_t i = 0; i < fNpoints; i++) {
1711 printf("x[%d]=%g, y[%d]=%g", i, fX[i], i, fY[i]);
1712 if (fExL)
1713 printf(", exl[%d]=%g", i, fExL[i]);
1714 if (fExH)
1715 printf(", exh[%d]=%g", i, fExH[i]);
1716 if (!fEyL.empty())
1717 for (Int_t j = 0; j < fNYErrors; j++)
1718 printf(", eyl[%d][%d]=%g", j, i, fEyL[j][i]);
1719 if (!fEyH.empty())
1720 for (Int_t j = 0; j < fNYErrors; j++)
1721 printf(", eyh[%d][%d]=%g", j, i, fEyH[j][i]);
1722 printf("\n");
1723 }
1724}
1725
1726////////////////////////////////////////////////////////////////////////////////
1727/// Save primitive as a C++ statement(s) on output stream out
1728
1730{
1731 out << " " << std::endl;
1732 static Int_t frameNumber = 5000;
1733 frameNumber++;
1734
1735 if (gROOT->ClassSaved(TGraphMultiErrors::Class()))
1736 out << " ";
1737 else
1738 out << " TGraphMultiErrors* ";
1739
1740 out << "tgme = new TGraphMultiErrors(" << fNpoints << ", " << fNYErrors << ");" << std::endl;
1741
1742 for (Int_t j = 0; j < fNYErrors; j++) {
1743 fAttFill[j].SaveFillAttributes(out, TString::Format("tgme->GetAttFill(%d)", j).Data(), 0, 1001);
1744 fAttLine[j].SaveLineAttributes(out, TString::Format("tgme->GetAttLine(%d)", j).Data(), 1, 1, 1);
1745 }
1746
1747 for (Int_t i = 0; i < fNpoints; i++) {
1748 out << " tgme->SetPoint(" << i << ", " << fX[i] << ", " << fY[i] << ");" << std::endl;
1749 out << " tgme->SetPointEX(" << i << ", " << fExL[i] << ", " << fExH[i] << ");" << std::endl;
1750
1751 for (Int_t j = 0; j < fNYErrors; j++)
1752 out << " tgme->SetPointEY(" << i << ", " << j << ", " << fEyL[j][i] << ", " << fEyH[j][i] << ");"
1753 << std::endl;
1754 }
1755
1756 SaveHistogramAndFunctions(out, "tgme", frameNumber, option);
1757}
1758
1759////////////////////////////////////////////////////////////////////////////////
1760/// Multiply the values and errors of a TGraphMultiErrors by a constant c1.
1761///
1762/// If option contains "x" the x values and errors are scaled
1763/// If option contains "y" the y values and (multiple) errors are scaled
1764/// If option contains "xy" both x and y values and (multiple) errors are scaled
1765
1767{
1769 TString opt = option; opt.ToLower();
1770 if (opt.Contains("x") && GetEXlow()) {
1771 for (Int_t i=0; i<GetN(); i++)
1772 GetEXlow()[i] *= c1;
1773 }
1774 if (opt.Contains("x") && GetEXhigh()) {
1775 for (Int_t i=0; i<GetN(); i++)
1776 GetEXhigh()[i] *= c1;
1777 }
1778 if (opt.Contains("y")) {
1779 for (size_t d=0; d<fEyL.size(); d++)
1780 for (Int_t i=0; i<fEyL[d].GetSize(); i++)
1781 fEyL[d][i] *= c1;
1782 for (size_t d=0; d<fEyH.size(); d++)
1783 for (Int_t i=0; i<fEyH[d].GetSize(); i++)
1784 fEyH[d][i] *= c1;
1785 }
1786}
1787
1788////////////////////////////////////////////////////////////////////////////////
1789/// Set ex and ey values for point pointed by the mouse.
1790///
1791/// Up to 3 y error dimensions possible.
1792
1794 Double_t eyH2, Double_t eyL3, Double_t eyH3)
1795{
1796 if (!gPad) {
1797 Error("SetPointError", "Cannot be used without gPad, requires last mouse position");
1798 return;
1799 }
1800
1801 Int_t px = gPad->GetEventX();
1802 Int_t py = gPad->GetEventY();
1803
1804 // localize point to be deleted
1805 Int_t ipoint = -2;
1806 // start with a small window (in case the mouse is very close to one point)
1807 for (Int_t i = 0; i < fNpoints; i++) {
1808 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
1809 Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
1810
1811 if (dpx * dpx + dpy * dpy < 25) {
1812 ipoint = i;
1813 break;
1814 }
1815 }
1816
1817 if (ipoint == -2)
1818 return;
1819
1820 SetPointEX(ipoint, exL, exH);
1821
1822 if (fNYErrors > 0)
1823 SetPointEY(ipoint, 0, eyL1, eyH1);
1824 if (fNYErrors > 1)
1825 SetPointEY(ipoint, 1, eyL2, eyH2);
1826 if (fNYErrors > 2)
1827 SetPointEY(ipoint, 2, eyL3, eyH3);
1828 gPad->Modified();
1829}
1830
1831////////////////////////////////////////////////////////////////////////////////
1832/// Set ex and ey values for point `i`.
1833
1835 const Double_t *eyH)
1836{
1837 SetPointEX(i, exL, exH);
1838 SetPointEY(i, ne, eyL, eyH);
1839}
1840
1841////////////////////////////////////////////////////////////////////////////////
1842/// Set ex values for point `i`.
1843
1845{
1846 SetPointEXlow(i, exL);
1847 SetPointEXhigh(i, exH);
1848}
1849
1850////////////////////////////////////////////////////////////////////////////////
1851/// Set exL value for point `i`.
1852
1854{
1855 if (i < 0)
1856 return;
1857
1858 if (i >= fNpoints) {
1859 // re-allocate the object
1860 TGraphMultiErrors::SetPoint(i, 0., 0.);
1861 }
1862
1863 fExL[i] = exL;
1864}
1865
1866////////////////////////////////////////////////////////////////////////////////
1867/// Set exH value for point `i`.
1868
1870{
1871 if (i < 0)
1872 return;
1873
1874 if (i >= fNpoints) {
1875 // re-allocate the object
1876 TGraphMultiErrors::SetPoint(i, 0., 0.);
1877 }
1878
1879 fExH[i] = exH;
1880}
1881
1882////////////////////////////////////////////////////////////////////////////////
1883/// Set ey values for point `i`.
1884
1885void TGraphMultiErrors::SetPointEY(Int_t i, Int_t ne, const Double_t *eyL, const Double_t *eyH)
1886{
1887 SetPointEYlow(i, ne, eyL);
1888 SetPointEYhigh(i, ne, eyH);
1889}
1890
1891////////////////////////////////////////////////////////////////////////////////
1892/// Set eyL values for point `i`.
1893
1895{
1896 for (Int_t j = 0; j < fNYErrors; j++) {
1897 if (j < ne)
1898 SetPointEYlow(i, j, eyL[j]);
1899 else
1900 SetPointEYlow(i, j, 0.);
1901 }
1902}
1903
1904////////////////////////////////////////////////////////////////////////////////
1905/// Set eyH values for point `i`.
1906
1908{
1909 for (Int_t j = 0; j < fNYErrors; j++) {
1910 if (j < ne)
1911 SetPointEYhigh(i, j, eyH[j]);
1912 else
1913 SetPointEYhigh(i, j, 0.);
1914 }
1915}
1916
1917////////////////////////////////////////////////////////////////////////////////
1918/// Set error e ey values for point `i`.
1919
1921{
1922 SetPointEYlow(i, e, eyL);
1923 SetPointEYhigh(i, e, eyH);
1924}
1925
1926////////////////////////////////////////////////////////////////////////////////
1927/// Set error e eyL value for point `i`.
1928
1930{
1931 if (i < 0 || e < 0)
1932 return;
1933
1934 if (i >= fNpoints)
1935 // re-allocate the object
1936 TGraphMultiErrors::SetPoint(i, 0., 0.);
1937
1938 while (e >= fNYErrors)
1940
1941 fEyL[e][i] = eyL;
1942 if (fEyLSum)
1943 fEyLSum[i] = GetErrorYlow(i);
1944 else
1946}
1947
1948////////////////////////////////////////////////////////////////////////////////
1949/// Set error e eyH value for point `i`.
1950
1952{
1953 if (i < 0 || e < 0)
1954 return;
1955
1956 if (i >= fNpoints)
1957 // re-allocate the object
1958 TGraphMultiErrors::SetPoint(i, 0., 0.);
1959
1960 while (e >= fNYErrors)
1962
1963 fEyH[e][i] = eyH;
1964 if (fEyHSum)
1965 fEyHSum[i] = GetErrorYhigh(i);
1966 else
1968}
1969
1970////////////////////////////////////////////////////////////////////////////////
1971/// Set error e ey values.
1972
1974{
1975 SetEYlow(e, np, eyL);
1976 SetEYhigh(e, np, eyH);
1977}
1978
1979////////////////////////////////////////////////////////////////////////////////
1980/// Set error e eyL values.
1981
1983{
1984 for (Int_t i = 0; i < fNpoints; i++) {
1985 if (i < np)
1986 SetPointEYlow(i, e, eyL[i]);
1987 else
1988 SetPointEYlow(i, e, 0.);
1989 }
1990}
1991
1992////////////////////////////////////////////////////////////////////////////////
1993/// Set error e eyH values.
1994
1996{
1997 for (Int_t i = 0; i < fNpoints; i++) {
1998 if (i < np)
1999 SetPointEYhigh(i, e, eyH[i]);
2000 else
2001 SetPointEYhigh(i, e, 0.);
2002 }
2003}
2004
2005////////////////////////////////////////////////////////////////////////////////
2006/// Set the sum errors mode and recalculate summed errors.
2008{
2009 if (fSumErrorsMode == m)
2010 return;
2011 fSumErrorsMode = m;
2013}
2014
2015////////////////////////////////////////////////////////////////////////////////
2016/// Set TAttFill parameters of error e by copying from another TAttFill (-1 = Global and x errors).
2017
2019{
2020 if (e == -1)
2021 taf->TAttFill::Copy(*this);
2022 else if (e >= 0 && e < fNYErrors)
2023 taf->TAttFill::Copy(fAttFill[e]);
2024}
2025
2026////////////////////////////////////////////////////////////////////////////////
2027/// Set TAttLine parameters of error e by copying from another TAttLine (-1 = Global and x errors).
2028
2030{
2031 if (e == -1)
2032 taf->TAttLine::Copy(*this);
2033 else if (e >= 0 && e < fNYErrors)
2034 taf->TAttLine::Copy(fAttLine[e]);
2035}
2036
2037////////////////////////////////////////////////////////////////////////////////
2038/// Set Fill Color of error e (-1 = Global and x errors).
2039
2041{
2042 if (e == -1)
2043 SetFillColor(fcolor);
2044 else if (e >= 0 && e < fNYErrors)
2045 fAttFill[e].SetFillColor(fcolor);
2046}
2047
2048////////////////////////////////////////////////////////////////////////////////
2049/// Set Fill Color and Alpha of error e (-1 = Global and x errors).
2050
2052{
2053 if (e == -1)
2054 SetFillColorAlpha(fcolor, falpha);
2055 else if (e >= 0 && e < fNYErrors)
2056 fAttFill[e].SetFillColorAlpha(fcolor, falpha);
2057}
2058
2059////////////////////////////////////////////////////////////////////////////////
2060/// Set Fill Style of error e (-1 = Global and x errors).
2061
2063{
2064 if (e == -1)
2065 SetFillStyle(fstyle);
2066 else if (e >= 0 && e < fNYErrors)
2067 fAttFill[e].SetFillStyle(fstyle);
2068}
2069
2070////////////////////////////////////////////////////////////////////////////////
2071/// Set Line Color of error e (-1 = Global and x errors).
2072
2074{
2075 if (e == -1)
2076 SetLineColor(lcolor);
2077 else if (e >= 0 && e < fNYErrors)
2078 fAttLine[e].SetLineColor(lcolor);
2079}
2080
2081////////////////////////////////////////////////////////////////////////////////
2082/// Set Line Color and Alpha of error e (-1 = Global and x errors).
2083
2085{
2086 if (e == -1)
2087 SetLineColorAlpha(lcolor, lalpha);
2088 else if (e >= 0 && e < fNYErrors)
2089 fAttLine[e].SetLineColorAlpha(lcolor, lalpha);
2090}
2091
2092////////////////////////////////////////////////////////////////////////////////
2093/// Set Line Style of error e (-1 = Global and x errors).
2094
2096{
2097 if (e == -1)
2098 SetLineStyle(lstyle);
2099 else if (e >= 0 && e < fNYErrors)
2100 fAttLine[e].SetLineStyle(lstyle);
2101}
2102
2103////////////////////////////////////////////////////////////////////////////////
2104/// Set Line Width of error e (-1 = Global and x errors).
2105
2107{
2108 if (e == -1)
2109 SetLineWidth(lwidth);
2110 else if (e >= 0 && e < fNYErrors)
2111 fAttLine[e].SetLineWidth(lwidth);
2112}
#define d(i)
Definition RSha256.hxx:102
#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
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Style_t
Definition RtypesCore.h:89
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:92
char Char_t
Definition RtypesCore.h:37
short Width_t
Definition RtypesCore.h:91
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
static unsigned int total
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t SetLineWidth
Option_t Option_t SetFillStyle
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t SetLineColor
Option_t Option_t SetFillColor
char name[80]
Definition TGX11.cxx:110
float xmin
float ymin
float xmax
float ymax
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
#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:207
Line Attributes class.
Definition TAttLine.h:18
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition TAttLine.cxx:177
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:233
TGraph with asymmetric error bars and multiple y error dimensions.
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
Double_t * GetEYhigh() const override
Get all high errors on y coordinates as an array summed according to fSumErrorsMode.
Double_t GetErrorX(Int_t i) const override
Get error on x coordinate for point i.
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:31
Double_t GetErrorXhigh(Int_t i) const override
Get high error on x coordinate for point i.
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
Double_t GetErrorYlow(Int_t i) const override
Get low error on y coordinate for point i.
void Divide(const TH1 *pass, const TH1 *total, Option_t *opt="cp")
This function was adapted from the TGraphAsymmErrors class.
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
Double_t GetErrorXlow(Int_t i) const override
Get low error on x coordinate for point i.
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 void BayesDivide(const TH1 *pass, const TH1 *total, Option_t *opt="")
This function is only kept for backward compatibility.
void Print(Option_t *chopt="") const override
Print graph and errors values.
TGraphMultiErrors & operator=(const TGraphMultiErrors &tgme)
TGraphMultiErrors assignment operator.
void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin) override
Copy and release.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
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
Double_t * GetEXhigh() const override
@ kAbsSum
Calculate the absolute sum of all errors.
@ kSquareSum
Calculate the square sum of all errors.
@ kOnlyFirst
Only take errors from first dimension.
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).
Bool_t CopyPoints(Double_t **arrays, Int_t ibegin, Int_t iend, Int_t obegin) override
Copy errors from fE*** to arrays[***] or to f*** Copy points.
virtual void SetPointEXhigh(Int_t i, Double_t exH)
Set exH value for point i.
Double_t * fExL
[fNpoints] array of X low errors
void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE) override
Set zero values for point arrays in the range [begin, end].
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.
void Scale(Double_t c1=1., Option_t *option="y") override
Multiply the values and errors of a TGraphMultiErrors by a constant c1.
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).
Double_t * GetEXlow() const override
void CalcYErrorsSum() const
Recalculates the summed y error arrays.
~TGraphMultiErrors() override
TGraphMultiErrors default destructor.
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
Double_t * GetEYlow() const override
Get all low errors on y coordinates as an array summed according to fSumErrorsMode.
virtual void DeleteYError(Int_t e)
Deletes the y error with the index e.
void Apply(TF1 *f) override
Apply a function to all data points .
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.
void SwapPoints(Int_t pos1, Int_t pos2) override
Swap points.
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.
std::vector< TAttFill > fAttFill
The AttFill attributes of the different errors.
void UpdateArrays(const std::vector< Int_t > &sorting_indices, Int_t numSortedPoints, Int_t low) override
Update the fX, fY, fExL, fExH, fEyL and fEyH arrays with the sorted values.
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 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.
void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const override
Compute Range.
Int_t fNYErrors
The amount of different y-errors.
std::vector< TArrayD > fEyL
Two dimensional array of Y low errors.
Double_t GetErrorY(Int_t i) const override
Get error on y coordinate for point i.
Double_t ** Allocate(Int_t size) override
Allocate internal data structures for size points.
Bool_t DoMerge(const TGraph *tg) override
Protected function to perform the merge operation of a graph with multiple asymmetric errors.
static TClass * Class()
Double_t GetErrorYhigh(Int_t i) const override
Get high error on y coordinate for point i.
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:2319
Int_t fMaxSize
!Current dimension of arrays fX and fY
Definition TGraph.h:45
void SaveHistogramAndFunctions(std::ostream &out, const char *varname, Int_t &frameNumber, Option_t *option)
Save histogram and list of functions of TGraph as C++ statement Used in all TGraph-derived classes.
Definition TGraph.cxx:2177
TH1F * fHistogram
Pointer to histogram used for drawing axis.
Definition TGraph.h:50
virtual void UpdateArrays(const std::vector< Int_t > &sorting_indices, Int_t numSortedPoints, Int_t low)
Update the fX and fY arrays with the sorted values.
Definition TGraph.cxx:2569
TClass * IsA() const override
Definition TGraph.h:202
Int_t GetN() const
Definition TGraph.h:131
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:783
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:709
Double_t ** AllocateArrays(Int_t Narrays, Int_t arraySize)
Allocate arrays.
Definition TGraph.cxx:593
virtual void Scale(Double_t c1=1., Option_t *option="y")
Multiply the values of a TGraph by a constant c1.
Definition TGraph.cxx:2236
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
Swap values.
Definition TGraph.cxx:2588
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
Definition TGraph.cxx:2653
void SetName(const char *name="") override
Set graph name.
Definition TGraph.cxx:2358
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
Definition TGraph.cxx:2560
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:1080
Double_t * fX
[fNpoints] array of X points
Definition TGraph.h:47
void SetTitle(const char *title="") override
Change (i.e.
Definition TGraph.cxx:2374
void SetNameTitle(const char *name="", const char *title="") override
Set graph name and title.
Definition TGraph.cxx:2394
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:2254
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:1511
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:757
TGraph & operator=(const TGraph &)
Equal operator for this graph.
Definition TGraph.cxx:232
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition TH1.cxx:9109
virtual Int_t GetDimension() const
Definition TH1.h:283
virtual Int_t GetNbinsX() const
Definition TH1.h:297
virtual Double_t GetBinLowEdge(Int_t bin) const
Return bin lower edge for 1D histogram.
Definition TH1.cxx:9120
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5029
virtual TArrayD * GetSumw2()
Definition TH1.h:313
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width for 1D histogram.
Definition TH1.cxx:9131
virtual Double_t GetSumOfWeights() const
Return the sum of weights excluding under/overflows.
Definition TH1.cxx:7885
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:961
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Float_t GetErrorX() const
Definition TStyle.h:185
TVectorT.
Definition TVectorT.h:27
Int_t GetNrows() const
Definition TVectorT.h:73
Int_t GetLwb() const
Definition TVectorT.h:71
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
return c1
Definition legend1.C:41
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:693
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
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:770
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
TMarker m
Definition textangle.C:8
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345