Logo ROOT  
Reference Guide
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 <string.h>
13
14#include "Riostream.h"
15#include "TROOT.h"
16#include "TGraphBentErrors.h"
17#include "TStyle.h"
18#include "TMath.h"
19#include "TVirtualPad.h"
20#include "TH1.h"
21#include "TF1.h"
22
24
25
26////////////////////////////////////////////////////////////////////////////////
27
28/** \class TGraphBentErrors
29 \ingroup Hist
30A TGraphBentErrors is a TGraph with bent, asymmetric error bars.
31
32The TGraphBentErrors painting is performed thanks to the TGraphPainter
33class. All details about the various painting options are given in this class.
34
35The picture below gives an example:
36Begin_Macro(source)
37{
38 auto c1 = new TCanvas("c1","A Simple Graph with bent error bars",200,10,700,500);
39 const Int_t n = 10;
40 Double_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
41 Double_t y[n] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
42 Double_t exl[n] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
43 Double_t eyl[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
44 Double_t exh[n] = {.02,.08,.05,.05,.03,.03,.04,.05,.06,.03};
45 Double_t eyh[n] = {.6,.5,.4,.3,.2,.2,.3,.4,.5,.6};
46 Double_t exld[n] = {.0,.0,.0,.0,.0,.0,.0,.0,.0,.0};
47 Double_t eyld[n] = {.0,.0,.05,.0,.0,.0,.0,.0,.0,.0};
48 Double_t exhd[n] = {.0,.0,.0,.0,.0,.0,.0,.0,.0,.0};
49 Double_t eyhd[n] = {.0,.0,.0,.0,.0,.0,.0,.0,.05,.0};
50 auto gr = new TGraphBentErrors(n,x,y,exl,exh,eyl,eyh,exld,exhd,eyld,eyhd);
51 gr->SetTitle("TGraphBentErrors Example");
52 gr->SetMarkerColor(4);
53 gr->SetMarkerStyle(21);
54 gr->Draw("ALP");
55}
56End_Macro
57*/
58
59
60////////////////////////////////////////////////////////////////////////////////
61/// TGraphBentErrors default constructor.
62
64{
65 if (!CtorAllocate()) return;
66}
67
68
69////////////////////////////////////////////////////////////////////////////////
70/// TGraphBentErrors copy constructor
71
73 : TGraph(gr)
74{
75 if (!CtorAllocate()) return;
76 Int_t n = fNpoints*sizeof(Double_t);
77 memcpy(fEXlow, gr.fEXlow, n);
78 memcpy(fEYlow, gr.fEYlow, n);
79 memcpy(fEXhigh, gr.fEXhigh, n);
80 memcpy(fEYhigh, gr.fEYhigh, n);
81 memcpy(fEXlowd, gr.fEXlowd, n);
82 memcpy(fEYlowd, gr.fEYlowd, n);
83 memcpy(fEXhighd, gr.fEXhighd, n);
84 memcpy(fEYhighd, gr.fEYhighd, n);
85}
86
87
88////////////////////////////////////////////////////////////////////////////////
89/// TGraphBentErrors normal constructor.
90///
91/// the arrays are preset to zero
92
94 : TGraph(n)
95{
96 if (!CtorAllocate()) return;
98}
99
100
101////////////////////////////////////////////////////////////////////////////////
102/// TGraphBentErrors normal constructor.
103///
104/// if exl,h or eyl,h are null, the corresponding arrays are preset to zero
105
107 const Float_t *x, const Float_t *y,
108 const Float_t *exl, const Float_t *exh,
109 const Float_t *eyl, const Float_t *eyh,
110 const Float_t *exld, const Float_t *exhd,
111 const Float_t *eyld, const Float_t *eyhd)
112 : TGraph(n,x,y)
113{
114 if (!CtorAllocate()) return;
115
116 for (Int_t i=0;i<n;i++) {
117 if (exl) fEXlow[i] = exl[i];
118 else fEXlow[i] = 0;
119 if (exh) fEXhigh[i] = exh[i];
120 else fEXhigh[i] = 0;
121 if (eyl) fEYlow[i] = eyl[i];
122 else fEYlow[i] = 0;
123 if (eyh) fEYhigh[i] = eyh[i];
124 else fEYhigh[i] = 0;
125
126 if (exld) fEXlowd[i] = exld[i];
127 else fEXlowd[i] = 0;
128 if (exhd) fEXhighd[i] = exhd[i];
129 else fEXhighd[i] = 0;
130 if (eyld) fEYlowd[i] = eyld[i];
131 else fEYlowd[i] = 0;
132 if (eyhd) fEYhighd[i] = eyhd[i];
133 else fEYhighd[i] = 0;
134 }
135}
136
137
138////////////////////////////////////////////////////////////////////////////////
139/// TGraphBentErrors normal constructor.
140///
141/// if exl,h or eyl,h are null, the corresponding arrays are preset to zero
142
144 const Double_t *x, const Double_t *y,
145 const Double_t *exl, const Double_t *exh,
146 const Double_t *eyl, const Double_t *eyh,
147 const Double_t *exld, const Double_t *exhd,
148 const Double_t *eyld, const Double_t *eyhd)
149 : TGraph(n,x,y)
150{
151 if (!CtorAllocate()) return;
152 n = sizeof(Double_t)*fNpoints;
153
154 if (exl) memcpy(fEXlow, exl, n);
155 else memset(fEXlow, 0, n);
156 if (exh) memcpy(fEXhigh, exh, n);
157 else memset(fEXhigh, 0, n);
158 if (eyl) memcpy(fEYlow, eyl, n);
159 else memset(fEYlow, 0, n);
160 if (eyh) memcpy(fEYhigh, eyh, n);
161 else memset(fEYhigh, 0, n);
162
163 if (exld) memcpy(fEXlowd, exld, n);
164 else memset(fEXlowd, 0, n);
165 if (exhd) memcpy(fEXhighd, exhd, n);
166 else memset(fEXhighd, 0, n);
167 if (eyld) memcpy(fEYlowd, eyld, n);
168 else memset(fEYlowd, 0, n);
169 if (eyhd) memcpy(fEYhighd, eyhd, n);
170 else memset(fEYhighd, 0, n);
171}
172
173
174////////////////////////////////////////////////////////////////////////////////
175/// TGraphBentErrors default destructor.
176
178{
179 delete [] fEXlow;
180 delete [] fEXhigh;
181 delete [] fEYlow;
182 delete [] fEYhigh;
183
184 delete [] fEXlowd;
185 delete [] fEXhighd;
186 delete [] fEYlowd;
187 delete [] fEYhighd;
188}
189
190
191////////////////////////////////////////////////////////////////////////////////
192/// apply a function to all data points
193/// y = f(x,y)
194///
195/// Errors are calculated as eyh = f(x,y+eyh)-f(x,y) and
196/// eyl = f(x,y)-f(x,y-eyl)
197///
198/// Special treatment has to be applied for the functions where the
199/// role of "up" and "down" is reversed.
200/// function suggested/implemented by Miroslav Helbich <helbich@mail.desy.de>
201
203{
204 Double_t x,y,exl,exh,eyl,eyh,eyl_new,eyh_new,fxy;
205
206 if (fHistogram) {
207 delete fHistogram;
208 fHistogram = 0;
209 }
210 for (Int_t i=0;i<GetN();i++) {
211 GetPoint(i,x,y);
212 exl=GetErrorXlow(i);
213 exh=GetErrorXhigh(i);
214 eyl=GetErrorYlow(i);
215 eyh=GetErrorYhigh(i);
216
217 fxy = f->Eval(x,y);
218 SetPoint(i,x,fxy);
219
220 // in the case of the functions like y-> -1*y the roles of the
221 // upper and lower error bars is reversed
222 if (f->Eval(x,y-eyl)<f->Eval(x,y+eyh)) {
223 eyl_new = TMath::Abs(fxy - f->Eval(x,y-eyl));
224 eyh_new = TMath::Abs(f->Eval(x,y+eyh) - fxy);
225 }
226 else {
227 eyh_new = TMath::Abs(fxy - f->Eval(x,y-eyl));
228 eyl_new = TMath::Abs(f->Eval(x,y+eyh) - fxy);
229 }
230
231 //error on x doesn't change
232 SetPointError(i,exl,exh,eyl_new,eyh_new);
233 }
234 if (gPad) gPad->Modified();
235}
236
237
238////////////////////////////////////////////////////////////////////////////////
239/// Compute range.
240
242{
244
245 for (Int_t i=0;i<fNpoints;i++) {
246 if (fX[i] -fEXlow[i] < xmin) {
247 if (gPad && gPad->GetLogx()) {
248 if (fEXlow[i] < fX[i]) xmin = fX[i]-fEXlow[i];
249 else xmin = TMath::Min(xmin,fX[i]/3);
250 } else {
251 xmin = fX[i]-fEXlow[i];
252 }
253 }
254 if (fX[i] +fEXhigh[i] > xmax) xmax = fX[i]+fEXhigh[i];
255 if (fY[i] -fEYlow[i] < ymin) {
256 if (gPad && gPad->GetLogy()) {
257 if (fEYlow[i] < fY[i]) ymin = fY[i]-fEYlow[i];
258 else ymin = TMath::Min(ymin,fY[i]/3);
259 } else {
260 ymin = fY[i]-fEYlow[i];
261 }
262 }
263 if (fY[i] +fEYhigh[i] > ymax) ymax = fY[i]+fEYhigh[i];
264 }
265}
266
267
268////////////////////////////////////////////////////////////////////////////////
269/// Copy and release.
270
272 Int_t ibegin, Int_t iend, Int_t obegin)
273{
274 CopyPoints(newarrays, ibegin, iend, obegin);
275 if (newarrays) {
276 delete[] fEXlow;
277 fEXlow = newarrays[0];
278 delete[] fEXhigh;
279 fEXhigh = newarrays[1];
280 delete[] fEYlow;
281 fEYlow = newarrays[2];
282 delete[] fEYhigh;
283 fEYhigh = newarrays[3];
284 delete[] fEXlowd;
285 fEXlowd = newarrays[4];
286 delete[] fEXhighd;
287 fEXhighd = newarrays[5];
288 delete[] fEYlowd;
289 fEYlowd = newarrays[6];
290 delete[] fEYhighd;
291 fEYhighd = newarrays[7];
292 delete[] fX;
293 fX = newarrays[8];
294 delete[] fY;
295 fY = newarrays[9];
296 delete[] newarrays;
297 }
298}
299
300
301////////////////////////////////////////////////////////////////////////////////
302/// Copy errors from fE*** to arrays[***]
303/// or to f*** Copy points.
304
306 Int_t ibegin, Int_t iend, Int_t obegin)
307{
308 if (TGraph::CopyPoints(arrays ? arrays+8 : 0, ibegin, iend, obegin)) {
309 Int_t n = (iend - ibegin)*sizeof(Double_t);
310 if (arrays) {
311 memmove(&arrays[0][obegin], &fEXlow[ibegin], n);
312 memmove(&arrays[1][obegin], &fEXhigh[ibegin], n);
313 memmove(&arrays[2][obegin], &fEYlow[ibegin], n);
314 memmove(&arrays[3][obegin], &fEYhigh[ibegin], n);
315 memmove(&arrays[4][obegin], &fEXlowd[ibegin], n);
316 memmove(&arrays[5][obegin], &fEXhighd[ibegin], n);
317 memmove(&arrays[6][obegin], &fEYlowd[ibegin], n);
318 memmove(&arrays[7][obegin], &fEYhighd[ibegin], n);
319 } else {
320 memmove(&fEXlow[obegin], &fEXlow[ibegin], n);
321 memmove(&fEXhigh[obegin], &fEXhigh[ibegin], n);
322 memmove(&fEYlow[obegin], &fEYlow[ibegin], n);
323 memmove(&fEYhigh[obegin], &fEYhigh[ibegin], n);
324 memmove(&fEXlowd[obegin], &fEXlowd[ibegin], n);
325 memmove(&fEXhighd[obegin], &fEXhighd[ibegin], n);
326 memmove(&fEYlowd[obegin], &fEYlowd[ibegin], n);
327 memmove(&fEYhighd[obegin], &fEYhighd[ibegin], n);
328 }
329 return kTRUE;
330 } else {
331 return kFALSE;
332 }
333}
334
335
336////////////////////////////////////////////////////////////////////////////////
337/// Should be called from ctors after fNpoints has been set
338
340{
341 if (!fNpoints) {
342 fEXlow = fEYlow = fEXhigh = fEYhigh = 0;
344 return kFALSE;
345 }
346 fEXlow = new Double_t[fMaxSize];
347 fEYlow = new Double_t[fMaxSize];
354 return kTRUE;
355}
356
357////////////////////////////////////////////////////////////////////////////////
358/// protected function to perform the merge operation of a graph with asymmetric errors
359
361{
362 if (g->GetN() == 0) return kFALSE;
363
364 Double_t * exl = g->GetEXlow();
365 Double_t * exh = g->GetEXhigh();
366 Double_t * eyl = g->GetEYlow();
367 Double_t * eyh = g->GetEYhigh();
368
369 Double_t * exld = g->GetEXlowd();
370 Double_t * exhd = g->GetEXhighd();
371 Double_t * eyld = g->GetEYlowd();
372 Double_t * eyhd = g->GetEYhighd();
373
374 if (exl == 0 || exh == 0 || eyl == 0 || eyh == 0 ||
375 exld == 0 || exhd == 0 || eyld == 0 || eyhd == 0) {
376 if (g->IsA() != TGraph::Class() )
377 Warning("DoMerge","Merging a %s is not compatible with a TGraphBentErrors - errors will be ignored",g->IsA()->GetName());
378 return TGraph::DoMerge(g);
379 }
380 for (Int_t i = 0 ; i < g->GetN(); i++) {
381 Int_t ipoint = GetN();
382 Double_t x = g->GetX()[i];
383 Double_t y = g->GetY()[i];
384 SetPoint(ipoint, x, y);
385 SetPointError(ipoint, exl[i], exh[i], eyl[i], eyh[i],
386 exld[i], exhd[i], eyld[i], eyhd[i] );
387 }
388
389 return kTRUE;
390
391}
392////////////////////////////////////////////////////////////////////////////////
393/// This function is called by GraphFitChisquare.
394/// It returns the error along X at point i.
395
397{
398 if (i < 0 || i >= fNpoints) return -1;
399 if (!fEXlow && !fEXhigh) return -1;
400 Double_t elow=0, ehigh=0;
401 if (fEXlow) elow = fEXlow[i];
402 if (fEXhigh) ehigh = fEXhigh[i];
403 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
404}
405
406
407////////////////////////////////////////////////////////////////////////////////
408/// This function is called by GraphFitChisquare.
409/// It returns the error along Y at point i.
410
412{
413 if (i < 0 || i >= fNpoints) return -1;
414 if (!fEYlow && !fEYhigh) return -1;
415 Double_t elow=0, ehigh=0;
416 if (fEYlow) elow = fEYlow[i];
417 if (fEYhigh) ehigh = fEYhigh[i];
418 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
419}
420
421
422////////////////////////////////////////////////////////////////////////////////
423/// Get high error on X[i].
424
426{
427 if (i<0 || i>fNpoints) return -1;
428 if (fEXhigh) return fEXhigh[i];
429 return -1;
430}
431
432
433////////////////////////////////////////////////////////////////////////////////
434/// Get low error on X[i].
435
437{
438 if (i<0 || i>fNpoints) return -1;
439 if (fEXlow) return fEXlow[i];
440 return -1;
441}
442
443
444////////////////////////////////////////////////////////////////////////////////
445/// Get high error on Y[i].
446
448{
449 if (i<0 || i>fNpoints) return -1;
450 if (fEYhigh) return fEYhigh[i];
451 return -1;
452}
453
454
455////////////////////////////////////////////////////////////////////////////////
456/// Get low error on Y[i].
457
459{
460 if (i<0 || i>fNpoints) return -1;
461 if (fEYlow) return fEYlow[i];
462 return -1;
463}
464
465
466////////////////////////////////////////////////////////////////////////////////
467/// Set zero values for point arrays in the range [begin, end)
468
470 Bool_t from_ctor)
471{
472 if (!from_ctor) {
473 TGraph::FillZero(begin, end, from_ctor);
474 }
475 Int_t n = (end - begin)*sizeof(Double_t);
476 memset(fEXlow + begin, 0, n);
477 memset(fEXhigh + begin, 0, n);
478 memset(fEYlow + begin, 0, n);
479 memset(fEYhigh + begin, 0, n);
480 memset(fEXlowd + begin, 0, n);
481 memset(fEXhighd + begin, 0, n);
482 memset(fEYlowd + begin, 0, n);
483 memset(fEYhighd + begin, 0, n);
484}
485
486
487////////////////////////////////////////////////////////////////////////////////
488/// Print graph and errors values.
489
491{
492 for (Int_t i=0;i<fNpoints;i++) {
493 printf("x[%d]=%g, y[%d]=%g, exl[%d]=%g, exh[%d]=%g, eyl[%d]=%g, eyh[%d]=%g\n"
494 ,i,fX[i],i,fY[i],i,fEXlow[i],i,fEXhigh[i],i,fEYlow[i],i,fEYhigh[i]);
495 }
496}
497
498
499////////////////////////////////////////////////////////////////////////////////
500/// Save primitive as a C++ statement(s) on output stream out
501
502void TGraphBentErrors::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
503{
504 char quote = '"';
505 out << " " << std::endl;
506 static Int_t frameNumber = 2000;
507 frameNumber++;
508
509 Int_t i;
510 TString fXName = TString(GetName()) + Form("_fx%d",frameNumber);
511 TString fYName = TString(GetName()) + Form("_fy%d",frameNumber);
512 TString fElXName = TString(GetName()) + Form("_felx%d",frameNumber);
513 TString fElYName = TString(GetName()) + Form("_fely%d",frameNumber);
514 TString fEhXName = TString(GetName()) + Form("_fehx%d",frameNumber);
515 TString fEhYName = TString(GetName()) + Form("_fehy%d",frameNumber);
516 TString fEldXName = TString(GetName()) + Form("_feldx%d",frameNumber);
517 TString fEldYName = TString(GetName()) + Form("_feldy%d",frameNumber);
518 TString fEhdXName = TString(GetName()) + Form("_fehdx%d",frameNumber);
519 TString fEhdYName = TString(GetName()) + Form("_fehdy%d",frameNumber);
520 out << " Double_t " << fXName << "[" << fNpoints << "] = {" << std::endl;
521 for (i = 0; i < fNpoints-1; i++) out << " " << fX[i] << "," << std::endl;
522 out << " " << fX[fNpoints-1] << "};" << std::endl;
523 out << " Double_t " << fYName << "[" << fNpoints << "] = {" << std::endl;
524 for (i = 0; i < fNpoints-1; i++) out << " " << fY[i] << "," << std::endl;
525 out << " " << fY[fNpoints-1] << "};" << std::endl;
526 out << " Double_t " << fElXName << "[" << fNpoints << "] = {" << std::endl;
527 for (i = 0; i < fNpoints-1; i++) out << " " << fEXlow[i] << "," << std::endl;
528 out << " " << fEXlow[fNpoints-1] << "};" << std::endl;
529 out << " Double_t " << fElYName << "[" << fNpoints << "] = {" << std::endl;
530 for (i = 0; i < fNpoints-1; i++) out << " " << fEYlow[i] << "," << std::endl;
531 out << " " << fEYlow[fNpoints-1] << "};" << std::endl;
532 out << " Double_t " << fEhXName << "[" << fNpoints << "] = {" << std::endl;
533 for (i = 0; i < fNpoints-1; i++) out << " " << fEXhigh[i] << "," << std::endl;
534 out << " " << fEXhigh[fNpoints-1] << "};" << std::endl;
535 out << " Double_t " << fEhYName << "[" << fNpoints << "] = {" << std::endl;
536 for (i = 0; i < fNpoints-1; i++) out << " " << fEYhigh[i] << "," << std::endl;
537 out << " " << fEYhigh[fNpoints-1] << "};" << std::endl;
538 out << " Double_t " << fEldXName << "[" << fNpoints << "] = {" << std::endl;
539 for (i = 0; i < fNpoints-1; i++) out << " " << fEXlowd[i] << "," << std::endl;
540 out << " " << fEXlowd[fNpoints-1] << "};" << std::endl;
541 out << " Double_t " << fEldYName << "[" << fNpoints << "] = {" << std::endl;
542 for (i = 0; i < fNpoints-1; i++) out << " " << fEYlowd[i] << "," << std::endl;
543 out << " " << fEYlowd[fNpoints-1] << "};" << std::endl;
544 out << " Double_t " << fEhdXName << "[" << fNpoints << "] = {" << std::endl;
545 for (i = 0; i < fNpoints-1; i++) out << " " << fEXhighd[i] << "," << std::endl;
546 out << " " << fEXhighd[fNpoints-1] << "};" << std::endl;
547 out << " Double_t " << fEhdYName << "[" << fNpoints << "] = {" << std::endl;
548 for (i = 0; i < fNpoints-1; i++) out << " " << fEYhighd[i] << "," << std::endl;
549 out << " " << fEYhighd[fNpoints-1] << "};" << std::endl;
550
551 if (gROOT->ClassSaved(TGraphBentErrors::Class())) out << " ";
552 else out << " TGraphBentErrors *";
553 out << "grbe = new TGraphBentErrors("<< fNpoints << ","
554 << fXName << "," << fYName << ","
555 << fElXName << "," << fEhXName << ","
556 << fElYName << "," << fEhYName << ","
557 << fEldXName << "," << fEhdXName << ","
558 << fEldYName << "," << fEhdYName << ");"
559 << std::endl;
560
561 out << " grbe->SetName(" << quote << GetName() << quote << ");" << std::endl;
562 out << " grbe->SetTitle(" << quote << GetTitle() << quote << ");" << std::endl;
563
564 SaveFillAttributes(out,"grbe",0,1001);
565 SaveLineAttributes(out,"grbe",1,1,1);
566 SaveMarkerAttributes(out,"grbe",1,1,1);
567
568 if (fHistogram) {
569 TString hname = fHistogram->GetName();
570 hname += frameNumber;
571 fHistogram->SetName(Form("Graph_%s",hname.Data()));
572 fHistogram->SavePrimitive(out,"nodraw");
573 out<<" grbe->SetHistogram("<<fHistogram->GetName()<<");"<<std::endl;
574 out<<" "<<std::endl;
575 }
576
577 // save list of functions
578 TIter next(fFunctions);
579 TObject *obj;
580 while ((obj = next())) {
581 obj->SavePrimitive(out, Form("nodraw #%d\n",++frameNumber));
582 if (obj->InheritsFrom("TPaveStats")) {
583 out << " grbe->GetListOfFunctions()->Add(ptstats);" << std::endl;
584 out << " ptstats->SetParent(grbe->GetListOfFunctions());" << std::endl;
585 } else {
586 TString objname;
587 objname.Form("%s%d",obj->GetName(),frameNumber);
588 if (obj->InheritsFrom("TF1")) {
589 out << " " << objname << "->SetParent(grbe);\n";
590 }
591 out << " grbe->GetListOfFunctions()->Add("
592 << objname << ");" << std::endl;
593 }
594 }
595
596 const char *l = strstr(option,"multigraph");
597 if (l) {
598 out<<" multigraph->Add(grbe,"<<quote<<l+10<<quote<<");"<<std::endl;
599 } else {
600 out<<" grbe->Draw("<<quote<<option<<quote<<");"<<std::endl;
601 }
602}
603
604
605////////////////////////////////////////////////////////////////////////////////
606/// Set ex and ey values for point pointed by the mouse.
607
609 Double_t exld, Double_t exhd, Double_t eyld, Double_t eyhd)
610{
611 Int_t px = gPad->GetEventX();
612 Int_t py = gPad->GetEventY();
613
614 //localize point to be deleted
615 Int_t ipoint = -2;
616 Int_t i;
617 // start with a small window (in case the mouse is very close to one point)
618 for (i=0;i<fNpoints;i++) {
619 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
620 Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
621 if (dpx*dpx+dpy*dpy < 25) {ipoint = i; break;}
622 }
623 if (ipoint == -2) return;
624
625 fEXlow[ipoint] = exl;
626 fEYlow[ipoint] = eyl;
627 fEXhigh[ipoint] = exh;
628 fEYhigh[ipoint] = eyh;
629 fEXlowd[ipoint] = exld;
630 fEXhighd[ipoint] = exhd;
631 fEYlowd[ipoint] = eyld;
632 fEYhighd[ipoint] = eyhd;
633 gPad->Modified();
634}
635
636
637////////////////////////////////////////////////////////////////////////////////
638/// Set ex and ey values for point number i.
639
641 Double_t exld, Double_t exhd, Double_t eyld, Double_t eyhd)
642{
643 if (i < 0) return;
644 if (i >= fNpoints) {
645 // re-allocate the object
647 }
648 fEXlow[i] = exl;
649 fEYlow[i] = eyl;
650 fEXhigh[i] = exh;
651 fEYhigh[i] = eyh;
652 fEXlowd[i] = exld;
653 fEXhighd[i] = exhd;
654 fEYlowd[i] = eyld;
655 fEYhighd[i] = eyhd;
656}
657
658
659////////////////////////////////////////////////////////////////////////////////
660/// Swap points.
661
663{
664 SwapValues(fEXlow, pos1, pos2);
665 SwapValues(fEXhigh, pos1, pos2);
666 SwapValues(fEYlow, pos1, pos2);
667 SwapValues(fEYhigh, pos1, pos2);
668
669 SwapValues(fEXlowd, pos1, pos2);
670 SwapValues(fEXhighd, pos1, pos2);
671 SwapValues(fEYlowd, pos1, pos2);
672 SwapValues(fEYhighd, pos1, pos2);
673
674 TGraph::SwapPoints(pos1, pos2);
675}
void Class()
Definition: Class.C:29
#define f(i)
Definition: RSha256.hxx:104
#define g(i)
Definition: RSha256.hxx:105
const Bool_t kFALSE
Definition: RtypesCore.h:90
double Double_t
Definition: RtypesCore.h:57
float Float_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
float xmin
Definition: THbookFile.cxx:93
float ymin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
float ymax
Definition: THbookFile.cxx:93
#define gROOT
Definition: TROOT.h:406
char * Form(const char *fmt,...)
#define gPad
Definition: TVirtualPad.h:287
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition: TAttFill.cxx:234
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttLine.cxx:270
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttMarker.cxx:339
1-Dim function class
Definition: TF1.h:210
A TGraphBentErrors is a TGraph with bent, asymmetric error bars.
Double_t GetErrorXhigh(Int_t bin) const
Get high error on X[i].
TGraphBentErrors()
TGraphBentErrors default constructor.
Double_t * fEYhigh
[fNpoints] array of Y high errors
virtual ~TGraphBentErrors()
TGraphBentErrors default destructor.
Double_t * fEXlowd
[fNpoints] array of X low displacements
Double_t * fEYlowd
[fNpoints] array of Y low displacements
Double_t GetErrorXlow(Int_t bin) const
Get low error on X[i].
virtual Bool_t CopyPoints(Double_t **arrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy errors from fE*** to arrays[] or to f Copy points.
Bool_t CtorAllocate()
Should be called from ctors after fNpoints has been set.
virtual void Apply(TF1 *f)
apply a function to all data points y = f(x,y)
Double_t * fEXhighd
[fNpoints] array of X high displacements
Double_t GetErrorYhigh(Int_t bin) const
Get high error on Y[i].
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
virtual void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
Copy and release.
Double_t GetErrorX(Int_t bin) const
This function is called by GraphFitChisquare.
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
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
Double_t GetErrorY(Int_t bin) const
This function is called by GraphFitChisquare.
virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE)
Set zero values for point arrays in the range [begin, end)
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph with asymmetric errors
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Compute range.
Double_t * fEYlow
[fNpoints] array of Y low errors
Double_t GetErrorYlow(Int_t bin) const
Get low error on Y[i].
Double_t * fEYhighd
[fNpoints] array of Y high displacements
virtual void Print(Option_t *chopt="") const
Print graph and errors values.
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:2269
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
Int_t GetN() const
Definition: TGraph.h:123
Double_t * fY
[fNpoints] array of Y points
Definition: TGraph.h:48
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:660
TList * fFunctions
Pointer to list of functions (fits and user)
Definition: TGraph.h:49
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
Swap values.
Definition: TGraph.cxx:2500
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
Definition: TGraph.cxx:2565
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
Definition: TGraph.cxx:2491
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:1028
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:1593
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:708
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TH1.cxx:6789
virtual void SetName(const char *name)
Change the name of this histogram.
Definition: TH1.cxx:8416
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:877
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:664
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2289
Double_t y[n]
Definition: legend1.C:17
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)
Definition: TMath.h:681
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
auto * l
Definition: textangle.C:4