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