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