Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGraphBentErrors.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Dave Morrison 30/06/2003
3
4/*************************************************************************
5 * Copyright (C) 1995-2003, 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 <cstring>
13#include <iostream>
14
15#include "TROOT.h"
16#include "TGraphBentErrors.h"
17#include "TMath.h"
18#include "TVirtualPad.h"
19#include "TH1.h"
20#include "TF1.h"
21
23
24
25////////////////////////////////////////////////////////////////////////////////
26
27/** \class TGraphBentErrors
28 \ingroup Graphs
29A TGraphBentErrors is a TGraph with bent, asymmetric error bars.
30
31The TGraphBentErrors painting is performed thanks to the TGraphPainter
32class. All details about the various painting options are given in this class.
33
34The picture below gives an example:
35Begin_Macro(source)
36{
37 auto c1 = new TCanvas("c1","A Simple Graph with bent error bars",200,10,700,500);
38 const Int_t n = 10;
39 Double_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
40 Double_t y[n] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
41 Double_t exl[n] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
42 Double_t eyl[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
43 Double_t exh[n] = {.02,.08,.05,.05,.03,.03,.04,.05,.06,.03};
44 Double_t eyh[n] = {.6,.5,.4,.3,.2,.2,.3,.4,.5,.6};
45 Double_t exld[n] = {.0,.0,.0,.0,.0,.0,.0,.0,.0,.0};
46 Double_t eyld[n] = {.0,.0,.05,.0,.0,.0,.0,.0,.0,.0};
47 Double_t exhd[n] = {.0,.0,.0,.0,.0,.0,.0,.0,.0,.0};
48 Double_t eyhd[n] = {.0,.0,.0,.0,.0,.0,.0,.0,.05,.0};
49 auto gr = new TGraphBentErrors(n,x,y,exl,exh,eyl,eyh,exld,exhd,eyld,eyhd);
50 gr->SetTitle("TGraphBentErrors Example");
51 gr->SetMarkerColor(4);
52 gr->SetMarkerStyle(21);
53 gr->Draw("ALP");
54}
55End_Macro
56*/
57
58
59////////////////////////////////////////////////////////////////////////////////
60/// TGraphBentErrors default constructor.
61
63{
64 if (!CtorAllocate()) return;
65}
66
67
68////////////////////////////////////////////////////////////////////////////////
69/// TGraphBentErrors copy constructor
70
72 : TGraph(gr)
73{
74 if (!CtorAllocate()) return;
75 Int_t n = fNpoints*sizeof(Double_t);
76 memcpy(fEXlow, gr.fEXlow, n);
77 memcpy(fEYlow, gr.fEYlow, n);
78 memcpy(fEXhigh, gr.fEXhigh, n);
79 memcpy(fEYhigh, gr.fEYhigh, n);
80 memcpy(fEXlowd, gr.fEXlowd, n);
81 memcpy(fEYlowd, gr.fEYlowd, n);
82 memcpy(fEXhighd, gr.fEXhighd, n);
83 memcpy(fEYhighd, gr.fEYhighd, n);
84}
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// TGraphBentErrors normal constructor.
89///
90/// the arrays are preset to zero
91
93 : TGraph(n)
94{
95 if (!CtorAllocate()) return;
97}
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// TGraphBentErrors normal constructor.
102///
103/// if exl,h or eyl,h are null, the corresponding arrays are preset to zero
104
106 const Float_t *x, const Float_t *y,
107 const Float_t *exl, const Float_t *exh,
108 const Float_t *eyl, const Float_t *eyh,
109 const Float_t *exld, const Float_t *exhd,
110 const Float_t *eyld, const Float_t *eyhd)
111 : TGraph(n,x,y)
112{
113 if (!CtorAllocate()) return;
114
115 for (Int_t i=0;i<n;i++) {
116 if (exl) fEXlow[i] = exl[i];
117 else fEXlow[i] = 0;
118 if (exh) fEXhigh[i] = exh[i];
119 else fEXhigh[i] = 0;
120 if (eyl) fEYlow[i] = eyl[i];
121 else fEYlow[i] = 0;
122 if (eyh) fEYhigh[i] = eyh[i];
123 else fEYhigh[i] = 0;
124
125 if (exld) fEXlowd[i] = exld[i];
126 else fEXlowd[i] = 0;
127 if (exhd) fEXhighd[i] = exhd[i];
128 else fEXhighd[i] = 0;
129 if (eyld) fEYlowd[i] = eyld[i];
130 else fEYlowd[i] = 0;
131 if (eyhd) fEYhighd[i] = eyhd[i];
132 else fEYhighd[i] = 0;
133 }
134}
135
136
137////////////////////////////////////////////////////////////////////////////////
138/// TGraphBentErrors normal constructor.
139///
140/// if exl,h or eyl,h are null, the corresponding arrays are preset to zero
141
143 const Double_t *x, const Double_t *y,
144 const Double_t *exl, const Double_t *exh,
145 const Double_t *eyl, const Double_t *eyh,
146 const Double_t *exld, const Double_t *exhd,
147 const Double_t *eyld, const Double_t *eyhd)
148 : TGraph(n,x,y)
149{
150 if (!CtorAllocate()) return;
151 auto memsz = sizeof(Double_t)*fNpoints;
152
153 if (exl) memcpy(fEXlow, exl, memsz);
154 else memset(fEXlow, 0, memsz);
155 if (exh) memcpy(fEXhigh, exh, memsz);
156 else memset(fEXhigh, 0, memsz);
157 if (eyl) memcpy(fEYlow, eyl, memsz);
158 else memset(fEYlow, 0, memsz);
159 if (eyh) memcpy(fEYhigh, eyh, memsz);
160 else memset(fEYhigh, 0, memsz);
161
162 if (exld) memcpy(fEXlowd, exld, memsz);
163 else memset(fEXlowd, 0, memsz);
164 if (exhd) memcpy(fEXhighd, exhd, memsz);
165 else memset(fEXhighd, 0, memsz);
166 if (eyld) memcpy(fEYlowd, eyld, memsz);
167 else memset(fEYlowd, 0, memsz);
168 if (eyhd) memcpy(fEYhighd, eyhd, memsz);
169 else memset(fEYhighd, 0, memsz);
170}
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// TGraphBentErrors default destructor.
175
177{
178 delete [] fEXlow;
179 delete [] fEXhigh;
180 delete [] fEYlow;
181 delete [] fEYhigh;
182
183 delete [] fEXlowd;
184 delete [] fEXhighd;
185 delete [] fEYlowd;
186 delete [] fEYhighd;
187}
188
189
190////////////////////////////////////////////////////////////////////////////////
191/// Apply a function to all data points \f$ y = f(x,y) \f$.
192///
193/// Errors are calculated as \f$ eyh = f(x,y+eyh)-f(x,y) \f$ and
194/// \f$ eyl = f(x,y)-f(x,y-eyl) \f$.
195///
196/// Special treatment has to be applied for the functions where the
197/// role of "up" and "down" is reversed.
198///
199/// Function suggested/implemented by Miroslav Helbich <helbich@mail.desy.de>
200
202{
203 Double_t x,y,exl,exh,eyl,eyh,eyl_new,eyh_new,fxy;
204
205 if (fHistogram) {
206 delete fHistogram;
207 fHistogram = nullptr;
208 }
209 for (Int_t i = 0; i < GetN(); i++) {
210 GetPoint(i, x, y);
211 exl = GetErrorXlow(i);
212 exh = GetErrorXhigh(i);
213 eyl = GetErrorYlow(i);
214 eyh = GetErrorYhigh(i);
215
216 fxy = f->Eval(x, y);
217 SetPoint(i, x, fxy);
218
219 // in the case of the functions like y-> -1*y the roles of the
220 // upper and lower error bars is reversed
221 if (f->Eval(x,y-eyl) < f->Eval(x,y+eyh)) {
222 eyl_new = TMath::Abs(fxy - f->Eval(x,y-eyl));
223 eyh_new = TMath::Abs(f->Eval(x,y+eyh) - fxy);
224 } else {
225 eyh_new = TMath::Abs(fxy - f->Eval(x,y-eyl));
226 eyl_new = TMath::Abs(f->Eval(x,y+eyh) - fxy);
227 }
228
229 //error on x doesn't change
230 SetPointError(i,exl,exh,eyl_new,eyh_new);
231 }
232 if (gPad) gPad->Modified();
233}
234
235
236////////////////////////////////////////////////////////////////////////////////
237/// Compute range.
238
240{
242
243 for (Int_t i=0;i<fNpoints;i++) {
244 if (fX[i] -fEXlow[i] < xmin) {
245 if (gPad && gPad->GetLogx()) {
246 if (fEXlow[i] < fX[i]) xmin = fX[i]-fEXlow[i];
247 else xmin = TMath::Min(xmin,fX[i]/3);
248 } else {
249 xmin = fX[i]-fEXlow[i];
250 }
251 }
252 if (fX[i] +fEXhigh[i] > xmax) xmax = fX[i]+fEXhigh[i];
253 if (fY[i] -fEYlow[i] < ymin) {
254 if (gPad && gPad->GetLogy()) {
255 if (fEYlow[i] < fY[i]) ymin = fY[i]-fEYlow[i];
256 else ymin = TMath::Min(ymin,fY[i]/3);
257 } else {
258 ymin = fY[i]-fEYlow[i];
259 }
260 }
261 if (fY[i] +fEYhigh[i] > ymax) ymax = fY[i]+fEYhigh[i];
262 }
263}
264
265
266////////////////////////////////////////////////////////////////////////////////
267/// Copy and release.
268
270 Int_t ibegin, Int_t iend, Int_t obegin)
271{
272 CopyPoints(newarrays, ibegin, iend, obegin);
273 if (newarrays) {
274 delete[] fEXlow;
275 fEXlow = newarrays[0];
276 delete[] fEXhigh;
277 fEXhigh = newarrays[1];
278 delete[] fEYlow;
279 fEYlow = newarrays[2];
280 delete[] fEYhigh;
281 fEYhigh = newarrays[3];
282 delete[] fEXlowd;
283 fEXlowd = newarrays[4];
284 delete[] fEXhighd;
285 fEXhighd = newarrays[5];
286 delete[] fEYlowd;
287 fEYlowd = newarrays[6];
288 delete[] fEYhighd;
289 fEYhighd = newarrays[7];
290 delete[] fX;
291 fX = newarrays[8];
292 delete[] fY;
293 fY = newarrays[9];
294 delete[] newarrays;
295 }
296}
297
298
299////////////////////////////////////////////////////////////////////////////////
300/// Copy errors from `fE*** `to `arrays[***]`
301/// or to `f***` Copy points.
302
304 Int_t ibegin, Int_t iend, Int_t obegin)
305{
306 if (TGraph::CopyPoints(arrays ? arrays+8 : nullptr, ibegin, iend, obegin)) {
307 Int_t n = (iend - ibegin)*sizeof(Double_t);
308 if (arrays) {
309 memmove(&arrays[0][obegin], &fEXlow[ibegin], n);
310 memmove(&arrays[1][obegin], &fEXhigh[ibegin], n);
311 memmove(&arrays[2][obegin], &fEYlow[ibegin], n);
312 memmove(&arrays[3][obegin], &fEYhigh[ibegin], n);
313 memmove(&arrays[4][obegin], &fEXlowd[ibegin], n);
314 memmove(&arrays[5][obegin], &fEXhighd[ibegin], n);
315 memmove(&arrays[6][obegin], &fEYlowd[ibegin], n);
316 memmove(&arrays[7][obegin], &fEYhighd[ibegin], n);
317 } else {
318 memmove(&fEXlow[obegin], &fEXlow[ibegin], n);
319 memmove(&fEXhigh[obegin], &fEXhigh[ibegin], n);
320 memmove(&fEYlow[obegin], &fEYlow[ibegin], n);
321 memmove(&fEYhigh[obegin], &fEYhigh[ibegin], n);
322 memmove(&fEXlowd[obegin], &fEXlowd[ibegin], n);
323 memmove(&fEXhighd[obegin], &fEXhighd[ibegin], n);
324 memmove(&fEYlowd[obegin], &fEYlowd[ibegin], n);
325 memmove(&fEYhighd[obegin], &fEYhighd[ibegin], n);
326 }
327 return kTRUE;
328 } else {
329 return kFALSE;
330 }
331}
332
333
334////////////////////////////////////////////////////////////////////////////////
335/// Should be called from ctors after `fNpoints` has been set.
336
338{
339 if (!fNpoints) {
340 fEXlow = fEYlow = fEXhigh = fEYhigh = nullptr;
341 fEXlowd = fEYlowd = fEXhighd = fEYhighd = nullptr;
342 return kFALSE;
343 }
344 fEXlow = new Double_t[fMaxSize];
345 fEYlow = new Double_t[fMaxSize];
352 return kTRUE;
353}
354
355////////////////////////////////////////////////////////////////////////////////
356/// Protected function to perform the merge operation of a graph with asymmetric errors.
357
359{
360 if (g->GetN() == 0) return kFALSE;
361
362 Double_t *exl = g->GetEXlow();
363 Double_t *exh = g->GetEXhigh();
364 Double_t *eyl = g->GetEYlow();
365 Double_t *eyh = g->GetEYhigh();
366
367 Double_t *exld = g->GetEXlowd();
368 Double_t *exhd = g->GetEXhighd();
369 Double_t *eyld = g->GetEYlowd();
370 Double_t *eyhd = g->GetEYhighd();
371
372 if (!exl || !exh || !eyl || !eyh ||
373 !exld || !exhd || !eyld || !eyhd) {
374 if (g->IsA() != TGraph::Class() )
375 Warning("DoMerge", "Merging a %s is not compatible with a TGraphBentErrors - errors will be ignored", g->IsA()->GetName());
376 return TGraph::DoMerge(g);
377 }
378 for (Int_t i = 0 ; i < g->GetN(); i++) {
379 Int_t ipoint = GetN();
380 Double_t x = g->GetX()[i];
381 Double_t y = g->GetY()[i];
382 SetPoint(ipoint, x, y);
383 SetPointError(ipoint, exl[i], exh[i], eyl[i], eyh[i],
384 exld[i], exhd[i], eyld[i], eyhd[i]);
385 }
386
387 return kTRUE;
388
389}
390////////////////////////////////////////////////////////////////////////////////
391/// It returns the error along X at point `i`.
392
394{
395 if (i < 0 || i >= fNpoints) return -1;
396 if (!fEXlow && !fEXhigh) return -1;
397 Double_t elow = 0, ehigh = 0;
398 if (fEXlow) elow = fEXlow[i];
399 if (fEXhigh) ehigh = fEXhigh[i];
400 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
401}
402
403
404////////////////////////////////////////////////////////////////////////////////
405/// It returns the error along Y at point `i`.
406
408{
409 if (i < 0 || i >= fNpoints) return -1;
410 if (!fEYlow && !fEYhigh) return -1;
411 Double_t elow=0, ehigh=0;
412 if (fEYlow) elow = fEYlow[i];
413 if (fEYhigh) ehigh = fEYhigh[i];
414 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
415}
416
417
418////////////////////////////////////////////////////////////////////////////////
419/// Get high error on X[i].
420
422{
423 if (i<0 || i>fNpoints) return -1;
424 if (fEXhigh) return fEXhigh[i];
425 return -1;
426}
427
428
429////////////////////////////////////////////////////////////////////////////////
430/// Get low error on X[i].
431
433{
434 if (i<0 || i>fNpoints) return -1;
435 if (fEXlow) return fEXlow[i];
436 return -1;
437}
438
439
440////////////////////////////////////////////////////////////////////////////////
441/// Get high error on Y[i].
442
444{
445 if (i<0 || i>fNpoints) return -1;
446 if (fEYhigh) return fEYhigh[i];
447 return -1;
448}
449
450
451////////////////////////////////////////////////////////////////////////////////
452/// Get low error on Y[i].
453
455{
456 if (i<0 || i>fNpoints) return -1;
457 if (fEYlow) return fEYlow[i];
458 return -1;
459}
460
461
462////////////////////////////////////////////////////////////////////////////////
463/// Set zero values for point arrays in the range `[begin, end]`
464
466 Bool_t from_ctor)
467{
468 if (!from_ctor) {
469 TGraph::FillZero(begin, end, from_ctor);
470 }
471 Int_t n = (end - begin)*sizeof(Double_t);
472 memset(fEXlow + begin, 0, n);
473 memset(fEXhigh + begin, 0, n);
474 memset(fEYlow + begin, 0, n);
475 memset(fEYhigh + begin, 0, n);
476 memset(fEXlowd + begin, 0, n);
477 memset(fEXhighd + begin, 0, n);
478 memset(fEYlowd + begin, 0, n);
479 memset(fEYhighd + begin, 0, n);
480}
481
482
483////////////////////////////////////////////////////////////////////////////////
484/// Print graph and errors values.
485
487{
488 for (Int_t i=0;i<fNpoints;i++) {
489 printf("x[%d]=%g, y[%d]=%g, exl[%d]=%g, exh[%d]=%g, eyl[%d]=%g, eyh[%d]=%g\n"
490 ,i,fX[i],i,fY[i],i,fEXlow[i],i,fEXhigh[i],i,fEYlow[i],i,fEYhigh[i]);
491 }
492}
493
494////////////////////////////////////////////////////////////////////////////////
495/// Multiply the values and errors of a TGraphBentErrors by a constant c1.
496///
497/// If option contains "x" the x values and errors are scaled
498/// If option contains "y" the y values and errors are scaled
499/// If option contains "xy" both x and y values and errors are scaled
500
502{
504 TString opt = option; opt.ToLower();
505 if (opt.Contains("x") && GetEXlow()) {
506 for (Int_t i=0; i<GetN(); i++)
507 GetEXlow()[i] *= c1;
508 }
509 if (opt.Contains("x") && GetEXhigh()) {
510 for (Int_t i=0; i<GetN(); i++)
511 GetEXhigh()[i] *= c1;
512 }
513 if (opt.Contains("y") && GetEYlow()) {
514 for (Int_t i=0; i<GetN(); i++)
515 GetEYlow()[i] *= c1;
516 }
517 if (opt.Contains("y") && GetEYhigh()) {
518 for (Int_t i=0; i<GetN(); i++)
519 GetEYhigh()[i] *= c1;
520 }
521 if (opt.Contains("x") && GetEXlowd()) {
522 for (Int_t i=0; i<GetN(); i++)
523 GetEXlowd()[i] *= c1;
524 }
525 if (opt.Contains("x") && GetEXhighd()) {
526 for (Int_t i=0; i<GetN(); i++)
527 GetEXhighd()[i] *= c1;
528 }
529 if (opt.Contains("y") && GetEYlowd()) {
530 for (Int_t i=0; i<GetN(); i++)
531 GetEYlowd()[i] *= c1;
532 }
533 if (opt.Contains("y") && GetEYhighd()) {
534 for (Int_t i=0; i<GetN(); i++)
535 GetEYhighd()[i] *= c1;
536 }
537}
538
539////////////////////////////////////////////////////////////////////////////////
540/// Save primitive as a C++ statement(s) on output stream out.
541
542void TGraphBentErrors::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
543{
544 out << " " << std::endl;
545 static Int_t frameNumber = 2000;
546 frameNumber++;
547
548 auto fXName = SaveArray(out, "fx", frameNumber, fX);
549 auto fYName = SaveArray(out, "fy", frameNumber, fY);
550 auto fElXName = SaveArray(out, "felx", frameNumber, fEXlow);
551 auto fElYName = SaveArray(out, "fely", frameNumber, fEYlow);
552 auto fEhXName = SaveArray(out, "fehx", frameNumber, fEXhigh);
553 auto fEhYName = SaveArray(out, "fehy", frameNumber, fEYhigh);
554 auto fEldXName = SaveArray(out, "feldx", frameNumber, fEXlowd);
555 auto fEldYName = SaveArray(out, "feldy", frameNumber, fEYlowd);
556 auto fEhdXName = SaveArray(out, "fehdx", frameNumber, fEXhighd);
557 auto fEhdYName = SaveArray(out, "fehdy", frameNumber, fEYhighd);
558
559 if (gROOT->ClassSaved(TGraphBentErrors::Class()))
560 out << " ";
561 else
562 out << " TGraphBentErrors *";
563 out << "grbe = new TGraphBentErrors("<< fNpoints << ","
564 << fXName << "," << fYName << ","
565 << fElXName << "," << fEhXName << ","
566 << fElYName << "," << fEhYName << ","
567 << fEldXName << "," << fEhdXName << ","
568 << fEldYName << "," << fEhdYName << ");"
569 << std::endl;
570
571 SaveHistogramAndFunctions(out, "grbe", frameNumber, option);
572}
573
574
575////////////////////////////////////////////////////////////////////////////////
576/// Set ex and ey values for point pointed by the mouse.
577
579 Double_t exld, Double_t exhd, Double_t eyld, Double_t eyhd)
580{
581 if (!gPad) {
582 Error("SetPointError", "Cannot be used without gPad, requires last mouse position");
583 return;
584 }
585
586 Int_t px = gPad->GetEventX();
587 Int_t py = gPad->GetEventY();
588
589 //localize point to be deleted
590 Int_t ipoint = -2;
591 // start with a small window (in case the mouse is very close to one point)
592 for (Int_t i = 0; i < fNpoints; i++) {
593 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
594 Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
595 if (dpx*dpx+dpy*dpy < 25) {ipoint = i; break;}
596 }
597 if (ipoint == -2) return;
598
599 fEXlow[ipoint] = exl;
600 fEYlow[ipoint] = eyl;
601 fEXhigh[ipoint] = exh;
602 fEYhigh[ipoint] = eyh;
603 fEXlowd[ipoint] = exld;
604 fEXhighd[ipoint] = exhd;
605 fEYlowd[ipoint] = eyld;
606 fEYhighd[ipoint] = eyhd;
607
608 gPad->Modified();
609}
610
611
612////////////////////////////////////////////////////////////////////////////////
613/// Set ex and ey values for point number `i`.
614
616 Double_t exld, Double_t exhd, Double_t eyld, Double_t eyhd)
617{
618 if (i < 0) return;
619 if (i >= fNpoints) {
620 // re-allocate the object
622 }
623 fEXlow[i] = exl;
624 fEYlow[i] = eyl;
625 fEXhigh[i] = exh;
626 fEYhigh[i] = eyh;
627 fEXlowd[i] = exld;
628 fEXhighd[i] = exhd;
629 fEYlowd[i] = eyld;
630 fEYhighd[i] = eyhd;
631}
632
633
634////////////////////////////////////////////////////////////////////////////////
635/// Swap points.
636
638{
639 SwapValues(fEXlow, pos1, pos2);
640 SwapValues(fEXhigh, pos1, pos2);
641 SwapValues(fEYlow, pos1, pos2);
642 SwapValues(fEYhigh, pos1, pos2);
643
644 SwapValues(fEXlowd, pos1, pos2);
645 SwapValues(fEXhighd, pos1, pos2);
646 SwapValues(fEYlowd, pos1, pos2);
647 SwapValues(fEYhighd, pos1, pos2);
648
649 TGraph::SwapPoints(pos1, pos2);
650}
651
652////////////////////////////////////////////////////////////////////////////////
653/// Update the fX, fY, fEXlow, fEXhigh, fEXlowd, fEXhighd, fEYlow, fEYhigh, fEYlowd,
654/// and fEYhighd arrays with the sorted values.
655
656void TGraphBentErrors::UpdateArrays(const std::vector<Int_t> &sorting_indices, Int_t numSortedPoints, Int_t low)
657{
658 std::vector<Double_t> fEXlowSorted(numSortedPoints);
659 std::vector<Double_t> fEXhighSorted(numSortedPoints);
660 std::vector<Double_t> fEXlowdSorted(numSortedPoints);
661 std::vector<Double_t> fEXhighdSorted(numSortedPoints);
662
663 std::vector<Double_t> fEYlowSorted(numSortedPoints);
664 std::vector<Double_t> fEYhighSorted(numSortedPoints);
665 std::vector<Double_t> fEYlowdSorted(numSortedPoints);
666 std::vector<Double_t> fEYhighdSorted(numSortedPoints);
667
668 // Fill the sorted X and Y error values based on the sorted indices
669 std::generate(fEXlowSorted.begin(), fEXlowSorted.end(),
670 [begin = low, &sorting_indices, this]() mutable { return fEXlow[sorting_indices[begin++]]; });
671 std::generate(fEXhighSorted.begin(), fEXhighSorted.end(),
672 [begin = low, &sorting_indices, this]() mutable { return fEXhigh[sorting_indices[begin++]]; });
673 std::generate(fEXlowdSorted.begin(), fEXlowdSorted.end(),
674 [begin = low, &sorting_indices, this]() mutable { return fEXlowd[sorting_indices[begin++]]; });
675 std::generate(fEXhighdSorted.begin(), fEXhighdSorted.end(),
676 [begin = low, &sorting_indices, this]() mutable { return fEXhighd[sorting_indices[begin++]]; });
677
678 std::generate(fEYlowSorted.begin(), fEYlowSorted.end(),
679 [begin = low, &sorting_indices, this]() mutable { return fEYlow[sorting_indices[begin++]]; });
680 std::generate(fEYhighSorted.begin(), fEYhighSorted.end(),
681 [begin = low, &sorting_indices, this]() mutable { return fEYhigh[sorting_indices[begin++]]; });
682 std::generate(fEYlowdSorted.begin(), fEYlowdSorted.end(),
683 [begin = low, &sorting_indices, this]() mutable { return fEYlowd[sorting_indices[begin++]]; });
684 std::generate(fEYhighdSorted.begin(), fEYhighdSorted.end(),
685 [begin = low, &sorting_indices, this]() mutable { return fEYhighd[sorting_indices[begin++]]; });
686
687 // Copy the sorted X and Y error values back to the original arrays
688 std::copy(fEXlowSorted.begin(), fEXlowSorted.end(), fEXlow + low);
689 std::copy(fEXhighSorted.begin(), fEXhighSorted.end(), fEXhigh + low);
690 std::copy(fEXlowdSorted.begin(), fEXlowdSorted.end(), fEXlowd + low);
691 std::copy(fEXhighdSorted.begin(), fEXhighdSorted.end(), fEXhighd + low);
692
693 std::copy(fEYlowSorted.begin(), fEYlowSorted.end(), fEYlow + low);
694 std::copy(fEYhighSorted.begin(), fEYhighSorted.end(), fEYhigh + low);
695 std::copy(fEYlowdSorted.begin(), fEYlowdSorted.end(), fEYlowd + low);
696 std::copy(fEYhighdSorted.begin(), fEYhighdSorted.end(), fEYhighd + low);
697
698 TGraph::UpdateArrays(sorting_indices, numSortedPoints, low);
699}
#define f(i)
Definition RSha256.hxx:104
#define g(i)
Definition RSha256.hxx:105
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t option
float xmin
float ymin
float xmax
float ymax
#define gROOT
Definition TROOT.h:406
#define gPad
1-Dim function class
Definition TF1.h:233
A TGraphBentErrors is a TGraph with bent, asymmetric error bars.
void UpdateArrays(const std::vector< Int_t > &sorting_indices, Int_t numSortedPoints, Int_t low) override
Update the fX, fY, fEXlow, fEXhigh, fEXlowd, fEXhighd, fEYlow, fEYhigh, fEYlowd, and fEYhighd array...
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
TGraphBentErrors()
TGraphBentErrors default constructor.
Double_t * GetEXlow() const override
Double_t * fEYhigh
[fNpoints] array of Y high errors
Double_t * fEXlowd
[fNpoints] array of X low displacements
Double_t * fEYlowd
[fNpoints] array of Y low displacements
Bool_t CtorAllocate()
Should be called from ctors after fNpoints has been set.
Bool_t DoMerge(const TGraph *g) override
Protected function to perform the merge operation of a graph with asymmetric errors.
Double_t * GetEYhigh() const override
Double_t GetErrorXlow(Int_t bin) const override
Get low error on X[i].
Double_t * GetEYlow() const override
Double_t * GetEYhighd() const override
void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const override
Compute range.
Double_t * GetEXhigh() const override
static TClass * Class()
Double_t * GetEYlowd() const override
Double_t * fEXhighd
[fNpoints] array of X high displacements
Double_t * GetEXhighd() const override
Double_t GetErrorXhigh(Int_t bin) const override
Get high error on X[i].
virtual void SetPointError(Double_t exl, Double_t exh, Double_t eyl, Double_t eyh, Double_t exld=0, Double_t exhd=0, Double_t eyld=0, Double_t eyhd=0)
Set ex and ey values for point pointed by the mouse.
Double_t * fEXlow
[fNpoints] array of X low errors
Double_t * fEXhigh
[fNpoints] array of X high errors
~TGraphBentErrors() override
TGraphBentErrors default destructor.
void Print(Option_t *chopt="") const override
Print graph and errors values.
void Scale(Double_t c1=1., Option_t *option="y") override
Multiply the values and errors of a TGraphBentErrors by a constant c1.
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]
Double_t * GetEXlowd() const override
Double_t GetErrorY(Int_t bin) const override
It returns the error along Y at point i.
Double_t * fEYlow
[fNpoints] array of Y low errors
Double_t * fEYhighd
[fNpoints] array of Y high displacements
void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin) override
Copy and release.
void SwapPoints(Int_t pos1, Int_t pos2) override
Swap points.
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.
Double_t GetErrorYlow(Int_t bin) const override
Get low error on Y[i].
Double_t GetErrorX(Int_t bin) const override
It returns the error along X at point i.
Double_t GetErrorYhigh(Int_t bin) const override
Get high error on Y[i].
void Apply(TF1 *f) override
Apply a function to all data points .
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
static TClass * Class()
Int_t fNpoints
Number of points <= fMaxSize.
Definition TGraph.h:46
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition TGraph.cxx:2319
Int_t fMaxSize
!Current dimension of arrays fX and fY
Definition TGraph.h:45
void SaveHistogramAndFunctions(std::ostream &out, const char *varname, Int_t &frameNumber, Option_t *option)
Save histogram and list of functions of TGraph as C++ statement Used in all TGraph-derived classes.
Definition TGraph.cxx:2177
TH1F * fHistogram
Pointer to histogram used for drawing axis.
Definition TGraph.h:50
virtual void UpdateArrays(const std::vector< Int_t > &sorting_indices, Int_t numSortedPoints, Int_t low)
Update the fX and fY arrays with the sorted values.
Definition TGraph.cxx:2569
Int_t GetN() const
Definition TGraph.h:131
Double_t * fY
[fNpoints] array of Y points
Definition TGraph.h:48
TString SaveArray(std::ostream &out, const char *suffix, Int_t frameNumber, Double_t *arr)
Save array as C++ code Returns name of created array.
Definition TGraph.cxx:2153
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Compute the x/y range of the points in this graph.
Definition TGraph.cxx:709
virtual void Scale(Double_t c1=1., Option_t *option="y")
Multiply the values of a TGraph by a constant c1.
Definition TGraph.cxx:2236
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
Swap values.
Definition TGraph.cxx:2588
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
Definition TGraph.cxx:2653
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
Definition TGraph.cxx:2560
virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE)
Set zero values for point arrays in the range [begin, end) Should be redefined in descendant classes.
Definition TGraph.cxx:1080
Double_t * fX
[fNpoints] array of X points
Definition TGraph.h:47
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
Get x and y values for point number i.
Definition TGraph.cxx:1511
virtual Bool_t CopyPoints(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy points from fX and fY to arrays[0] and arrays[1] or to fX and fY if arrays == 0 and ibegin !...
Definition TGraph.cxx:757
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
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
TGraphErrors * gr
Definition legend1.C:25
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123