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 <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 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 \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 = 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/// It returns the error along X at point `i`.
393
395{
396 if (i < 0 || i >= fNpoints) return -1;
397 if (!fEXlow && !fEXhigh) return -1;
398 Double_t elow=0, ehigh=0;
399 if (fEXlow) elow = fEXlow[i];
400 if (fEXhigh) ehigh = fEXhigh[i];
401 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
402}
403
404
405////////////////////////////////////////////////////////////////////////////////
406/// It returns the error along Y at point `i`.
407
409{
410 if (i < 0 || i >= fNpoints) return -1;
411 if (!fEYlow && !fEYhigh) return -1;
412 Double_t elow=0, ehigh=0;
413 if (fEYlow) elow = fEYlow[i];
414 if (fEYhigh) ehigh = fEYhigh[i];
415 return TMath::Sqrt(0.5*(elow*elow + ehigh*ehigh));
416}
417
418
419////////////////////////////////////////////////////////////////////////////////
420/// Get high error on X[i].
421
423{
424 if (i<0 || i>fNpoints) return -1;
425 if (fEXhigh) return fEXhigh[i];
426 return -1;
427}
428
429
430////////////////////////////////////////////////////////////////////////////////
431/// Get low error on X[i].
432
434{
435 if (i<0 || i>fNpoints) return -1;
436 if (fEXlow) return fEXlow[i];
437 return -1;
438}
439
440
441////////////////////////////////////////////////////////////////////////////////
442/// Get high error on Y[i].
443
445{
446 if (i<0 || i>fNpoints) return -1;
447 if (fEYhigh) return fEYhigh[i];
448 return -1;
449}
450
451
452////////////////////////////////////////////////////////////////////////////////
453/// Get low error on Y[i].
454
456{
457 if (i<0 || i>fNpoints) return -1;
458 if (fEYlow) return fEYlow[i];
459 return -1;
460}
461
462
463////////////////////////////////////////////////////////////////////////////////
464/// Set zero values for point arrays in the range `[begin, end]`
465
467 Bool_t from_ctor)
468{
469 if (!from_ctor) {
470 TGraph::FillZero(begin, end, from_ctor);
471 }
472 Int_t n = (end - begin)*sizeof(Double_t);
473 memset(fEXlow + begin, 0, n);
474 memset(fEXhigh + begin, 0, n);
475 memset(fEYlow + begin, 0, n);
476 memset(fEYhigh + begin, 0, n);
477 memset(fEXlowd + begin, 0, n);
478 memset(fEXhighd + begin, 0, n);
479 memset(fEYlowd + begin, 0, n);
480 memset(fEYhighd + begin, 0, n);
481}
482
483
484////////////////////////////////////////////////////////////////////////////////
485/// Print graph and errors values.
486
488{
489 for (Int_t i=0;i<fNpoints;i++) {
490 printf("x[%d]=%g, y[%d]=%g, exl[%d]=%g, exh[%d]=%g, eyl[%d]=%g, eyh[%d]=%g\n"
491 ,i,fX[i],i,fY[i],i,fEXlow[i],i,fEXhigh[i],i,fEYlow[i],i,fEYhigh[i]);
492 }
493}
494
495////////////////////////////////////////////////////////////////////////////////
496/// Multiply the values and errors of a TGraphBentErrors by a constant c1.
497///
498/// If option contains "x" the x values and errors are scaled
499/// If option contains "y" the y values and errors are scaled
500/// If option contains "xy" both x and y values and errors are scaled
501
503{
505 TString opt = option; opt.ToLower();
506 if (opt.Contains("x") && GetEXlow()) {
507 for (Int_t i=0; i<GetN(); i++)
508 GetEXlow()[i] *= c1;
509 }
510 if (opt.Contains("x") && GetEXhigh()) {
511 for (Int_t i=0; i<GetN(); i++)
512 GetEXhigh()[i] *= c1;
513 }
514 if (opt.Contains("y") && GetEYlow()) {
515 for (Int_t i=0; i<GetN(); i++)
516 GetEYlow()[i] *= c1;
517 }
518 if (opt.Contains("y") && GetEYhigh()) {
519 for (Int_t i=0; i<GetN(); i++)
520 GetEYhigh()[i] *= c1;
521 }
522 if (opt.Contains("x") && GetEXlowd()) {
523 for (Int_t i=0; i<GetN(); i++)
524 GetEXlowd()[i] *= c1;
525 }
526 if (opt.Contains("x") && GetEXhighd()) {
527 for (Int_t i=0; i<GetN(); i++)
528 GetEXhighd()[i] *= c1;
529 }
530 if (opt.Contains("y") && GetEYlowd()) {
531 for (Int_t i=0; i<GetN(); i++)
532 GetEYlowd()[i] *= c1;
533 }
534 if (opt.Contains("y") && GetEYhighd()) {
535 for (Int_t i=0; i<GetN(); i++)
536 GetEYhighd()[i] *= c1;
537 }
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Save primitive as a C++ statement(s) on output stream out.
542
543void TGraphBentErrors::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
544{
545 char quote = '"';
546 out << " " << std::endl;
547 static Int_t frameNumber = 2000;
548 frameNumber++;
549
550 Int_t i;
551 TString fXName = TString(GetName()) + Form("_fx%d",frameNumber);
552 TString fYName = TString(GetName()) + Form("_fy%d",frameNumber);
553 TString fElXName = TString(GetName()) + Form("_felx%d",frameNumber);
554 TString fElYName = TString(GetName()) + Form("_fely%d",frameNumber);
555 TString fEhXName = TString(GetName()) + Form("_fehx%d",frameNumber);
556 TString fEhYName = TString(GetName()) + Form("_fehy%d",frameNumber);
557 TString fEldXName = TString(GetName()) + Form("_feldx%d",frameNumber);
558 TString fEldYName = TString(GetName()) + Form("_feldy%d",frameNumber);
559 TString fEhdXName = TString(GetName()) + Form("_fehdx%d",frameNumber);
560 TString fEhdYName = TString(GetName()) + Form("_fehdy%d",frameNumber);
561 out << " Double_t " << fXName << "[" << fNpoints << "] = {" << std::endl;
562 for (i = 0; i < fNpoints-1; i++) out << " " << fX[i] << "," << std::endl;
563 out << " " << fX[fNpoints-1] << "};" << std::endl;
564 out << " Double_t " << fYName << "[" << fNpoints << "] = {" << std::endl;
565 for (i = 0; i < fNpoints-1; i++) out << " " << fY[i] << "," << std::endl;
566 out << " " << fY[fNpoints-1] << "};" << std::endl;
567 out << " Double_t " << fElXName << "[" << fNpoints << "] = {" << std::endl;
568 for (i = 0; i < fNpoints-1; i++) out << " " << fEXlow[i] << "," << std::endl;
569 out << " " << fEXlow[fNpoints-1] << "};" << std::endl;
570 out << " Double_t " << fElYName << "[" << fNpoints << "] = {" << std::endl;
571 for (i = 0; i < fNpoints-1; i++) out << " " << fEYlow[i] << "," << std::endl;
572 out << " " << fEYlow[fNpoints-1] << "};" << std::endl;
573 out << " Double_t " << fEhXName << "[" << fNpoints << "] = {" << std::endl;
574 for (i = 0; i < fNpoints-1; i++) out << " " << fEXhigh[i] << "," << std::endl;
575 out << " " << fEXhigh[fNpoints-1] << "};" << std::endl;
576 out << " Double_t " << fEhYName << "[" << fNpoints << "] = {" << std::endl;
577 for (i = 0; i < fNpoints-1; i++) out << " " << fEYhigh[i] << "," << std::endl;
578 out << " " << fEYhigh[fNpoints-1] << "};" << std::endl;
579 out << " Double_t " << fEldXName << "[" << fNpoints << "] = {" << std::endl;
580 for (i = 0; i < fNpoints-1; i++) out << " " << fEXlowd[i] << "," << std::endl;
581 out << " " << fEXlowd[fNpoints-1] << "};" << std::endl;
582 out << " Double_t " << fEldYName << "[" << fNpoints << "] = {" << std::endl;
583 for (i = 0; i < fNpoints-1; i++) out << " " << fEYlowd[i] << "," << std::endl;
584 out << " " << fEYlowd[fNpoints-1] << "};" << std::endl;
585 out << " Double_t " << fEhdXName << "[" << fNpoints << "] = {" << std::endl;
586 for (i = 0; i < fNpoints-1; i++) out << " " << fEXhighd[i] << "," << std::endl;
587 out << " " << fEXhighd[fNpoints-1] << "};" << std::endl;
588 out << " Double_t " << fEhdYName << "[" << fNpoints << "] = {" << std::endl;
589 for (i = 0; i < fNpoints-1; i++) out << " " << fEYhighd[i] << "," << std::endl;
590 out << " " << fEYhighd[fNpoints-1] << "};" << std::endl;
591
592 if (gROOT->ClassSaved(TGraphBentErrors::Class())) out << " ";
593 else out << " TGraphBentErrors *";
594 out << "grbe = new TGraphBentErrors("<< fNpoints << ","
595 << fXName << "," << fYName << ","
596 << fElXName << "," << fEhXName << ","
597 << fElYName << "," << fEhYName << ","
598 << fEldXName << "," << fEhdXName << ","
599 << fEldYName << "," << fEhdYName << ");"
600 << std::endl;
601
602 out << " grbe->SetName(" << quote << GetName() << quote << ");" << std::endl;
603 out << " grbe->SetTitle(" << quote << GetTitle() << quote << ");" << std::endl;
604
605 SaveFillAttributes(out,"grbe",0,1001);
606 SaveLineAttributes(out,"grbe",1,1,1);
607 SaveMarkerAttributes(out,"grbe",1,1,1);
608
609 if (fHistogram) {
610 TString hname = fHistogram->GetName();
611 hname += frameNumber;
612 fHistogram->SetName(Form("Graph_%s",hname.Data()));
613 fHistogram->SavePrimitive(out,"nodraw");
614 out<<" grbe->SetHistogram("<<fHistogram->GetName()<<");"<<std::endl;
615 out<<" "<<std::endl;
616 }
617
618 // save list of functions
619 TIter next(fFunctions);
620 TObject *obj;
621 while ((obj = next())) {
622 obj->SavePrimitive(out, Form("nodraw #%d\n",++frameNumber));
623 if (obj->InheritsFrom("TPaveStats")) {
624 out << " grbe->GetListOfFunctions()->Add(ptstats);" << std::endl;
625 out << " ptstats->SetParent(grbe->GetListOfFunctions());" << std::endl;
626 } else {
627 TString objname;
628 objname.Form("%s%d",obj->GetName(),frameNumber);
629 if (obj->InheritsFrom("TF1")) {
630 out << " " << objname << "->SetParent(grbe);\n";
631 }
632 out << " grbe->GetListOfFunctions()->Add("
633 << objname << ");" << std::endl;
634 }
635 }
636
637 const char *l = strstr(option,"multigraph");
638 if (l) {
639 out<<" multigraph->Add(grbe,"<<quote<<l+10<<quote<<");"<<std::endl;
640 } else {
641 out<<" grbe->Draw("<<quote<<option<<quote<<");"<<std::endl;
642 }
643}
644
645
646////////////////////////////////////////////////////////////////////////////////
647/// Set ex and ey values for point pointed by the mouse.
648
650 Double_t exld, Double_t exhd, Double_t eyld, Double_t eyhd)
651{
652 Int_t px = gPad->GetEventX();
653 Int_t py = gPad->GetEventY();
654
655 //localize point to be deleted
656 Int_t ipoint = -2;
657 Int_t i;
658 // start with a small window (in case the mouse is very close to one point)
659 for (i=0;i<fNpoints;i++) {
660 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
661 Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
662 if (dpx*dpx+dpy*dpy < 25) {ipoint = i; break;}
663 }
664 if (ipoint == -2) return;
665
666 fEXlow[ipoint] = exl;
667 fEYlow[ipoint] = eyl;
668 fEXhigh[ipoint] = exh;
669 fEYhigh[ipoint] = eyh;
670 fEXlowd[ipoint] = exld;
671 fEXhighd[ipoint] = exhd;
672 fEYlowd[ipoint] = eyld;
673 fEYhighd[ipoint] = eyhd;
674 gPad->Modified();
675}
676
677
678////////////////////////////////////////////////////////////////////////////////
679/// Set ex and ey values for point number `i`.
680
682 Double_t exld, Double_t exhd, Double_t eyld, Double_t eyhd)
683{
684 if (i < 0) return;
685 if (i >= fNpoints) {
686 // re-allocate the object
688 }
689 fEXlow[i] = exl;
690 fEYlow[i] = eyl;
691 fEXhigh[i] = exh;
692 fEYhigh[i] = eyh;
693 fEXlowd[i] = exld;
694 fEXhighd[i] = exhd;
695 fEYlowd[i] = eyld;
696 fEYhighd[i] = eyhd;
697}
698
699
700////////////////////////////////////////////////////////////////////////////////
701/// Swap points.
702
704{
705 SwapValues(fEXlow, pos1, pos2);
706 SwapValues(fEXhigh, pos1, pos2);
707 SwapValues(fEYlow, pos1, pos2);
708 SwapValues(fEYhigh, pos1, pos2);
709
710 SwapValues(fEXlowd, pos1, pos2);
711 SwapValues(fEXhighd, pos1, pos2);
712 SwapValues(fEYlowd, pos1, pos2);
713 SwapValues(fEYhighd, pos1, pos2);
714
715 TGraph::SwapPoints(pos1, pos2);
716}
#define f(i)
Definition: RSha256.hxx:104
const Bool_t kFALSE
Definition: RtypesCore.h:101
float Float_t
Definition: RtypesCore.h:57
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:375
Option_t Option_t option
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 g
float xmin
Definition: THbookFile.cxx:95
float ymin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
float ymax
Definition: THbookFile.cxx:95
#define gROOT
Definition: TROOT.h:404
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2456
#define gPad
Definition: TVirtualPad.h:288
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:236
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:273
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:345
1-Dim function class
Definition: TF1.h:213
A TGraphBentErrors is a TGraph with bent, asymmetric error bars.
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:2283
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:126
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:708
virtual void Scale(Double_t c1=1., Option_t *option="y")
Multiply the values of a TGraph by a constant c1.
Definition: TGraph.cxx:2200
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:2538
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
Definition: TGraph.cxx:2603
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
Definition: TGraph.cxx:2529
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:1076
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:1520
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:756
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition: TH1.cxx:7147
void SetName(const char *name) override
Change the name of this histogram.
Definition: TH1.cxx:8827
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
Mother of all ROOT objects.
Definition: TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:440
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:956
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:746
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:526
SCoord_t GetY() const
Definition: TPoint.h:47
SCoord_t GetX() const
Definition: TPoint.h:46
Basic string class.
Definition: TString.h:136
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1159
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:2323
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
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:660
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
TLine l
Definition: textangle.C:4