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 Hist
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 n = sizeof(Double_t)*fNpoints;
152
153 if (exl) memcpy(fEXlow, exl, n);
154 else memset(fEXlow, 0, n);
155 if (exh) memcpy(fEXhigh, exh, n);
156 else memset(fEXhigh, 0, n);
157 if (eyl) memcpy(fEYlow, eyl, n);
158 else memset(fEYlow, 0, n);
159 if (eyh) memcpy(fEYhigh, eyh, n);
160 else memset(fEYhigh, 0, n);
161
162 if (exld) memcpy(fEXlowd, exld, n);
163 else memset(fEXlowd, 0, n);
164 if (exhd) memcpy(fEXhighd, exhd, n);
165 else memset(fEXhighd, 0, n);
166 if (eyld) memcpy(fEYlowd, eyld, n);
167 else memset(fEYlowd, 0, n);
168 if (eyhd) memcpy(fEYhighd, eyhd, n);
169 else memset(fEYhighd, 0, n);
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
192/// y = f(x,y)
193///
194/// Errors are calculated as eyh = f(x,y+eyh)-f(x,y) and
195/// eyl = f(x,y)-f(x,y-eyl)
196///
197/// Special treatment has to be applied for the functions where the
198/// role of "up" and "down" is reversed.
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 = 0;
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 }
225 else {
226 eyh_new = TMath::Abs(fxy - f->Eval(x,y-eyl));
227 eyl_new = TMath::Abs(f->Eval(x,y+eyh) - fxy);
228 }
229
230 //error on x doesn't change
231 SetPointError(i,exl,exh,eyl_new,eyh_new);
232 }
233 if (gPad) gPad->Modified();
234}
235
236
237////////////////////////////////////////////////////////////////////////////////
238/// Compute range.
239
241{
243
244 for (Int_t i=0;i<fNpoints;i++) {
245 if (fX[i] -fEXlow[i] < xmin) {
246 if (gPad && gPad->GetLogx()) {
247 if (fEXlow[i] < fX[i]) xmin = fX[i]-fEXlow[i];
248 else xmin = TMath::Min(xmin,fX[i]/3);
249 } else {
250 xmin = fX[i]-fEXlow[i];
251 }
252 }
253 if (fX[i] +fEXhigh[i] > xmax) xmax = fX[i]+fEXhigh[i];
254 if (fY[i] -fEYlow[i] < ymin) {
255 if (gPad && gPad->GetLogy()) {
256 if (fEYlow[i] < fY[i]) ymin = fY[i]-fEYlow[i];
257 else ymin = TMath::Min(ymin,fY[i]/3);
258 } else {
259 ymin = fY[i]-fEYlow[i];
260 }
261 }
262 if (fY[i] +fEYhigh[i] > ymax) ymax = fY[i]+fEYhigh[i];
263 }
264}
265
266
267////////////////////////////////////////////////////////////////////////////////
268/// Copy and release.
269
271 Int_t ibegin, Int_t iend, Int_t obegin)
272{
273 CopyPoints(newarrays, ibegin, iend, obegin);
274 if (newarrays) {
275 delete[] fEXlow;
276 fEXlow = newarrays[0];
277 delete[] fEXhigh;
278 fEXhigh = newarrays[1];
279 delete[] fEYlow;
280 fEYlow = newarrays[2];
281 delete[] fEYhigh;
282 fEYhigh = newarrays[3];
283 delete[] fEXlowd;
284 fEXlowd = newarrays[4];
285 delete[] fEXhighd;
286 fEXhighd = newarrays[5];
287 delete[] fEYlowd;
288 fEYlowd = newarrays[6];
289 delete[] fEYhighd;
290 fEYhighd = newarrays[7];
291 delete[] fX;
292 fX = newarrays[8];
293 delete[] fY;
294 fY = newarrays[9];
295 delete[] newarrays;
296 }
297}
298
299
300////////////////////////////////////////////////////////////////////////////////
301/// Copy errors from fE*** to arrays[***]
302/// or to f*** Copy points.
303
305 Int_t ibegin, Int_t iend, Int_t obegin)
306{
307 if (TGraph::CopyPoints(arrays ? arrays+8 : 0, ibegin, iend, obegin)) {
308 Int_t n = (iend - ibegin)*sizeof(Double_t);
309 if (arrays) {
310 memmove(&arrays[0][obegin], &fEXlow[ibegin], n);
311 memmove(&arrays[1][obegin], &fEXhigh[ibegin], n);
312 memmove(&arrays[2][obegin], &fEYlow[ibegin], n);
313 memmove(&arrays[3][obegin], &fEYhigh[ibegin], n);
314 memmove(&arrays[4][obegin], &fEXlowd[ibegin], n);
315 memmove(&arrays[5][obegin], &fEXhighd[ibegin], n);
316 memmove(&arrays[6][obegin], &fEYlowd[ibegin], n);
317 memmove(&arrays[7][obegin], &fEYhighd[ibegin], n);
318 } else {
319 memmove(&fEXlow[obegin], &fEXlow[ibegin], n);
320 memmove(&fEXhigh[obegin], &fEXhigh[ibegin], n);
321 memmove(&fEYlow[obegin], &fEYlow[ibegin], n);
322 memmove(&fEYhigh[obegin], &fEYhigh[ibegin], n);
323 memmove(&fEXlowd[obegin], &fEXlowd[ibegin], n);
324 memmove(&fEXhighd[obegin], &fEXhighd[ibegin], n);
325 memmove(&fEYlowd[obegin], &fEYlowd[ibegin], n);
326 memmove(&fEYhighd[obegin], &fEYhighd[ibegin], n);
327 }
328 return kTRUE;
329 } else {
330 return kFALSE;
331 }
332}
333
334
335////////////////////////////////////////////////////////////////////////////////
336/// Should be called from ctors after fNpoints has been set
337
339{
340 if (!fNpoints) {
341 fEXlow = fEYlow = fEXhigh = fEYhigh = 0;
343 return kFALSE;
344 }
345 fEXlow = new Double_t[fMaxSize];
346 fEYlow = new Double_t[fMaxSize];
353 return kTRUE;
354}
355
356////////////////////////////////////////////////////////////////////////////////
357/// protected function to perform the merge operation of a graph with asymmetric errors
358
360{
361 if (g->GetN() == 0) return kFALSE;
362
363 Double_t * exl = g->GetEXlow();
364 Double_t * exh = g->GetEXhigh();
365 Double_t * eyl = g->GetEYlow();
366 Double_t * eyh = g->GetEYhigh();
367
368 Double_t * exld = g->GetEXlowd();
369 Double_t * exhd = g->GetEXhighd();
370 Double_t * eyld = g->GetEYlowd();
371 Double_t * eyhd = g->GetEYhighd();
372
373 if (exl == 0 || exh == 0 || eyl == 0 || eyh == 0 ||
374 exld == 0 || exhd == 0 || eyld == 0 || eyhd == 0) {
375 if (g->IsA() != TGraph::Class() )
376 Warning("DoMerge","Merging a %s is not compatible with a TGraphBentErrors - errors will be ignored",g->IsA()->GetName());
377 return TGraph::DoMerge(g);
378 }
379 for (Int_t i = 0 ; i < g->GetN(); i++) {
380 Int_t ipoint = GetN();
381 Double_t x = g->GetX()[i];
382 Double_t y = g->GetY()[i];
383 SetPoint(ipoint, x, y);
384 SetPointError(ipoint, exl[i], exh[i], eyl[i], eyh[i],
385 exld[i], exhd[i], eyld[i], eyhd[i] );
386 }
387
388 return kTRUE;
389
390}
391////////////////////////////////////////////////////////////////////////////////
392/// This function is called by GraphFitChisquare.
393/// It returns the error along X at point i.
394
396{
397 if (i < 0 || i >= fNpoints) return -1;
398 if (!fEXlow && !fEXhigh) return -1;
399 Double_t elow=0, ehigh=0;
400 if (fEXlow) elow = fEXlow[i];
401 if (fEXhigh) ehigh = fEXhigh[i];
402 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
403}
404
405
406////////////////////////////////////////////////////////////////////////////////
407/// This function is called by GraphFitChisquare.
408/// It returns the error along Y at point i.
409
411{
412 if (i < 0 || i >= fNpoints) return -1;
413 if (!fEYlow && !fEYhigh) return -1;
414 Double_t elow=0, ehigh=0;
415 if (fEYlow) elow = fEYlow[i];
416 if (fEYhigh) ehigh = fEYhigh[i];
417 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
418}
419
420
421////////////////////////////////////////////////////////////////////////////////
422/// Get high error on X[i].
423
425{
426 if (i<0 || i>fNpoints) return -1;
427 if (fEXhigh) return fEXhigh[i];
428 return -1;
429}
430
431
432////////////////////////////////////////////////////////////////////////////////
433/// Get low error on X[i].
434
436{
437 if (i<0 || i>fNpoints) return -1;
438 if (fEXlow) return fEXlow[i];
439 return -1;
440}
441
442
443////////////////////////////////////////////////////////////////////////////////
444/// Get high error on Y[i].
445
447{
448 if (i<0 || i>fNpoints) return -1;
449 if (fEYhigh) return fEYhigh[i];
450 return -1;
451}
452
453
454////////////////////////////////////////////////////////////////////////////////
455/// Get low error on Y[i].
456
458{
459 if (i<0 || i>fNpoints) return -1;
460 if (fEYlow) return fEYlow[i];
461 return -1;
462}
463
464
465////////////////////////////////////////////////////////////////////////////////
466/// Set zero values for point arrays in the range [begin, end)
467
469 Bool_t from_ctor)
470{
471 if (!from_ctor) {
472 TGraph::FillZero(begin, end, from_ctor);
473 }
474 Int_t n = (end - begin)*sizeof(Double_t);
475 memset(fEXlow + begin, 0, n);
476 memset(fEXhigh + begin, 0, n);
477 memset(fEYlow + begin, 0, n);
478 memset(fEYhigh + begin, 0, n);
479 memset(fEXlowd + begin, 0, n);
480 memset(fEXhighd + begin, 0, n);
481 memset(fEYlowd + begin, 0, n);
482 memset(fEYhighd + begin, 0, n);
483}
484
485
486////////////////////////////////////////////////////////////////////////////////
487/// Print graph and errors values.
488
490{
491 for (Int_t i=0;i<fNpoints;i++) {
492 printf("x[%d]=%g, y[%d]=%g, exl[%d]=%g, exh[%d]=%g, eyl[%d]=%g, eyh[%d]=%g\n"
493 ,i,fX[i],i,fY[i],i,fEXlow[i],i,fEXhigh[i],i,fEYlow[i],i,fEYhigh[i]);
494 }
495}
496
497
498////////////////////////////////////////////////////////////////////////////////
499/// Save primitive as a C++ statement(s) on output stream out
500
501void TGraphBentErrors::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
502{
503 char quote = '"';
504 out << " " << std::endl;
505 static Int_t frameNumber = 2000;
506 frameNumber++;
507
508 Int_t i;
509 TString fXName = TString(GetName()) + Form("_fx%d",frameNumber);
510 TString fYName = TString(GetName()) + Form("_fy%d",frameNumber);
511 TString fElXName = TString(GetName()) + Form("_felx%d",frameNumber);
512 TString fElYName = TString(GetName()) + Form("_fely%d",frameNumber);
513 TString fEhXName = TString(GetName()) + Form("_fehx%d",frameNumber);
514 TString fEhYName = TString(GetName()) + Form("_fehy%d",frameNumber);
515 TString fEldXName = TString(GetName()) + Form("_feldx%d",frameNumber);
516 TString fEldYName = TString(GetName()) + Form("_feldy%d",frameNumber);
517 TString fEhdXName = TString(GetName()) + Form("_fehdx%d",frameNumber);
518 TString fEhdYName = TString(GetName()) + Form("_fehdy%d",frameNumber);
519 out << " Double_t " << fXName << "[" << fNpoints << "] = {" << std::endl;
520 for (i = 0; i < fNpoints-1; i++) out << " " << fX[i] << "," << std::endl;
521 out << " " << fX[fNpoints-1] << "};" << std::endl;
522 out << " Double_t " << fYName << "[" << fNpoints << "] = {" << std::endl;
523 for (i = 0; i < fNpoints-1; i++) out << " " << fY[i] << "," << std::endl;
524 out << " " << fY[fNpoints-1] << "};" << std::endl;
525 out << " Double_t " << fElXName << "[" << fNpoints << "] = {" << std::endl;
526 for (i = 0; i < fNpoints-1; i++) out << " " << fEXlow[i] << "," << std::endl;
527 out << " " << fEXlow[fNpoints-1] << "};" << std::endl;
528 out << " Double_t " << fElYName << "[" << fNpoints << "] = {" << std::endl;
529 for (i = 0; i < fNpoints-1; i++) out << " " << fEYlow[i] << "," << std::endl;
530 out << " " << fEYlow[fNpoints-1] << "};" << std::endl;
531 out << " Double_t " << fEhXName << "[" << fNpoints << "] = {" << std::endl;
532 for (i = 0; i < fNpoints-1; i++) out << " " << fEXhigh[i] << "," << std::endl;
533 out << " " << fEXhigh[fNpoints-1] << "};" << std::endl;
534 out << " Double_t " << fEhYName << "[" << fNpoints << "] = {" << std::endl;
535 for (i = 0; i < fNpoints-1; i++) out << " " << fEYhigh[i] << "," << std::endl;
536 out << " " << fEYhigh[fNpoints-1] << "};" << std::endl;
537 out << " Double_t " << fEldXName << "[" << fNpoints << "] = {" << std::endl;
538 for (i = 0; i < fNpoints-1; i++) out << " " << fEXlowd[i] << "," << std::endl;
539 out << " " << fEXlowd[fNpoints-1] << "};" << std::endl;
540 out << " Double_t " << fEldYName << "[" << fNpoints << "] = {" << std::endl;
541 for (i = 0; i < fNpoints-1; i++) out << " " << fEYlowd[i] << "," << std::endl;
542 out << " " << fEYlowd[fNpoints-1] << "};" << std::endl;
543 out << " Double_t " << fEhdXName << "[" << fNpoints << "] = {" << std::endl;
544 for (i = 0; i < fNpoints-1; i++) out << " " << fEXhighd[i] << "," << std::endl;
545 out << " " << fEXhighd[fNpoints-1] << "};" << std::endl;
546 out << " Double_t " << fEhdYName << "[" << fNpoints << "] = {" << std::endl;
547 for (i = 0; i < fNpoints-1; i++) out << " " << fEYhighd[i] << "," << std::endl;
548 out << " " << fEYhighd[fNpoints-1] << "};" << std::endl;
549
550 if (gROOT->ClassSaved(TGraphBentErrors::Class())) out << " ";
551 else out << " TGraphBentErrors *";
552 out << "grbe = new TGraphBentErrors("<< fNpoints << ","
553 << fXName << "," << fYName << ","
554 << fElXName << "," << fEhXName << ","
555 << fElYName << "," << fEhYName << ","
556 << fEldXName << "," << fEhdXName << ","
557 << fEldYName << "," << fEhdYName << ");"
558 << std::endl;
559
560 out << " grbe->SetName(" << quote << GetName() << quote << ");" << std::endl;
561 out << " grbe->SetTitle(" << quote << GetTitle() << quote << ");" << std::endl;
562
563 SaveFillAttributes(out,"grbe",0,1001);
564 SaveLineAttributes(out,"grbe",1,1,1);
565 SaveMarkerAttributes(out,"grbe",1,1,1);
566
567 if (fHistogram) {
568 TString hname = fHistogram->GetName();
569 hname += frameNumber;
570 fHistogram->SetName(Form("Graph_%s",hname.Data()));
571 fHistogram->SavePrimitive(out,"nodraw");
572 out<<" grbe->SetHistogram("<<fHistogram->GetName()<<");"<<std::endl;
573 out<<" "<<std::endl;
574 }
575
576 // save list of functions
577 TIter next(fFunctions);
578 TObject *obj;
579 while ((obj = next())) {
580 obj->SavePrimitive(out, Form("nodraw #%d\n",++frameNumber));
581 if (obj->InheritsFrom("TPaveStats")) {
582 out << " grbe->GetListOfFunctions()->Add(ptstats);" << std::endl;
583 out << " ptstats->SetParent(grbe->GetListOfFunctions());" << std::endl;
584 } else {
585 TString objname;
586 objname.Form("%s%d",obj->GetName(),frameNumber);
587 if (obj->InheritsFrom("TF1")) {
588 out << " " << objname << "->SetParent(grbe);\n";
589 }
590 out << " grbe->GetListOfFunctions()->Add("
591 << objname << ");" << std::endl;
592 }
593 }
594
595 const char *l = strstr(option,"multigraph");
596 if (l) {
597 out<<" multigraph->Add(grbe,"<<quote<<l+10<<quote<<");"<<std::endl;
598 } else {
599 out<<" grbe->Draw("<<quote<<option<<quote<<");"<<std::endl;
600 }
601}
602
603
604////////////////////////////////////////////////////////////////////////////////
605/// Set ex and ey values for point pointed by the mouse.
606
608 Double_t exld, Double_t exhd, Double_t eyld, Double_t eyhd)
609{
610 Int_t px = gPad->GetEventX();
611 Int_t py = gPad->GetEventY();
612
613 //localize point to be deleted
614 Int_t ipoint = -2;
615 Int_t i;
616 // start with a small window (in case the mouse is very close to one point)
617 for (i=0;i<fNpoints;i++) {
618 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
619 Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
620 if (dpx*dpx+dpy*dpy < 25) {ipoint = i; break;}
621 }
622 if (ipoint == -2) return;
623
624 fEXlow[ipoint] = exl;
625 fEYlow[ipoint] = eyl;
626 fEXhigh[ipoint] = exh;
627 fEYhigh[ipoint] = eyh;
628 fEXlowd[ipoint] = exld;
629 fEXhighd[ipoint] = exhd;
630 fEYlowd[ipoint] = eyld;
631 fEYhighd[ipoint] = eyhd;
632 gPad->Modified();
633}
634
635
636////////////////////////////////////////////////////////////////////////////////
637/// Set ex and ey values for point number i.
638
640 Double_t exld, Double_t exhd, Double_t eyld, Double_t eyhd)
641{
642 if (i < 0) return;
643 if (i >= fNpoints) {
644 // re-allocate the object
646 }
647 fEXlow[i] = exl;
648 fEYlow[i] = eyl;
649 fEXhigh[i] = exh;
650 fEYhigh[i] = eyh;
651 fEXlowd[i] = exld;
652 fEXhighd[i] = exhd;
653 fEYlowd[i] = eyld;
654 fEYhighd[i] = eyhd;
655}
656
657
658////////////////////////////////////////////////////////////////////////////////
659/// Swap points.
660
662{
663 SwapValues(fEXlow, pos1, pos2);
664 SwapValues(fEXhigh, pos1, pos2);
665 SwapValues(fEYlow, pos1, pos2);
666 SwapValues(fEYhigh, pos1, pos2);
667
668 SwapValues(fEXlowd, pos1, pos2);
669 SwapValues(fEXhighd, pos1, pos2);
670 SwapValues(fEYlowd, pos1, pos2);
671 SwapValues(fEYhighd, pos1, pos2);
672
673 TGraph::SwapPoints(pos1, pos2);
674}
#define f(i)
Definition RSha256.hxx:104
#define g(i)
Definition RSha256.hxx:105
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
float xmin
float ymin
float xmax
float ymax
#define gROOT
Definition TROOT.h:406
char * Form(const char *fmt,...)
#define gPad
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.
1-Dim function class
Definition TF1.h:213
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:2284
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:124
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:669
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:2515
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
Definition TGraph.cxx:2580
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
Definition TGraph.cxx:2506
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:1037
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:1607
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:717
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition TH1.cxx:7122
virtual void SetName(const char *name)
Change the name of this histogram.
Definition TH1.cxx:8800
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:359
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:879
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition TObject.cxx:666
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2309
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:691
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