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