ROOT  6.06/09
Reference Guide
TGraph.cxx
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: Rene Brun, Olivier Couet 12/12/94
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 "TEnv.h"
17 #include "TGraph.h"
18 #include "TGaxis.h"
19 #include "TH1.h"
20 #include "TF1.h"
21 #include "TStyle.h"
22 #include "TMath.h"
23 #include "TFrame.h"
24 #include "TVector.h"
25 #include "TVectorD.h"
26 #include "Foption.h"
27 #include "TRandom.h"
28 #include "TSpline.h"
29 #include "TVirtualFitter.h"
30 #include "TVirtualPad.h"
31 #include "TVirtualGraphPainter.h"
32 #include "TBrowser.h"
33 #include "TClass.h"
34 #include "TSystem.h"
35 #include "TPluginManager.h"
36 #include <stdlib.h>
37 #include <string>
38 #include <cassert>
39 
40 #include "HFitInterface.h"
41 #include "Fit/DataRange.h"
42 #include "Math/MinimizerOptions.h"
43 
44 extern void H1LeastSquareSeqnd(Int_t n, Double_t *a, Int_t idim, Int_t &ifail, Int_t k, Double_t *b);
45 
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 
50 /** \class TGraph
51  \ingroup Hist
52 A Graph is a graphics object made of two arrays X and Y with npoints each.
53 The TGraph painting is performed thanks to the TGraphPainter
54 class. All details about the various painting options are given in this class.
55 
56 *Note:* Unlike histogram or tree (or even TGraph2D), TGraph objects
57  are not automatically attached to the current TFile, in order to keep the
58  management and size of the TGraph has small as possible.
59 
60 The picture below gives an example:
61 Begin_Macro(source)
62 {
63  TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);
64  Double_t x[100], y[100];
65  Int_t n = 20;
66  for (Int_t i=0;i<n;i++) {
67  x[i] = i*0.1;
68  y[i] = 10*sin(x[i]+0.2);
69  }
70  gr = new TGraph(n,x,y);
71  gr->Draw("AC*");
72  return c1;
73 }
74 End_Macro
75 */
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Graph default constructor.
79 
80 TGraph::TGraph(): TNamed(), TAttLine(), TAttFill(1, 1001), TAttMarker()
81 {
82  fNpoints = -1; //will be reset to 0 in CtorAllocate
83  if (!CtorAllocate()) return;
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// Constructor with only the number of points set
88 /// the arrays x and y will be set later
89 
91  : TNamed("Graph", "Graph"), TAttLine(), TAttFill(1, 1001), TAttMarker()
92 {
93  fNpoints = n;
94  if (!CtorAllocate()) return;
95  FillZero(0, fNpoints);
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Graph normal constructor with ints.
100 
101 TGraph::TGraph(Int_t n, const Int_t *x, const Int_t *y)
102  : TNamed("Graph", "Graph"), TAttLine(), TAttFill(1, 1001), TAttMarker()
103 {
104  if (!x || !y) {
105  fNpoints = 0;
106  } else {
107  fNpoints = n;
108  }
109  if (!CtorAllocate()) return;
110  for (Int_t i = 0; i < n; i++) {
111  fX[i] = (Double_t)x[i];
112  fY[i] = (Double_t)y[i];
113  }
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Graph normal constructor with floats.
118 
119 TGraph::TGraph(Int_t n, const Float_t *x, const Float_t *y)
120  : TNamed("Graph", "Graph"), TAttLine(), TAttFill(1, 1001), TAttMarker()
121 {
122  if (!x || !y) {
123  fNpoints = 0;
124  } else {
125  fNpoints = n;
126  }
127  if (!CtorAllocate()) return;
128  for (Int_t i = 0; i < n; i++) {
129  fX[i] = x[i];
130  fY[i] = y[i];
131  }
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// Graph normal constructor with doubles.
136 
137 TGraph::TGraph(Int_t n, const Double_t *x, const Double_t *y)
138  : TNamed("Graph", "Graph"), TAttLine(), TAttFill(1, 1001), TAttMarker()
139 {
140  if (!x || !y) {
141  fNpoints = 0;
142  } else {
143  fNpoints = n;
144  }
145  if (!CtorAllocate()) return;
146  n = fNpoints * sizeof(Double_t);
147  memcpy(fX, x, n);
148  memcpy(fY, y, n);
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// Copy constructor for this graph
153 
155  : TNamed(gr), TAttLine(gr), TAttFill(gr), TAttMarker(gr)
156 {
157  fNpoints = gr.fNpoints;
158  fMaxSize = gr.fMaxSize;
159  if (gr.fFunctions) fFunctions = (TList*)gr.fFunctions->Clone();
160  else fFunctions = new TList;
161  fHistogram = 0;
162  fMinimum = gr.fMinimum;
163  fMaximum = gr.fMaximum;
164  if (!fMaxSize) {
165  fX = fY = 0;
166  return;
167  } else {
168  fX = new Double_t[fMaxSize];
169  fY = new Double_t[fMaxSize];
170  }
171 
172  Int_t n = gr.GetN() * sizeof(Double_t);
173  memcpy(fX, gr.fX, n);
174  memcpy(fY, gr.fY, n);
175 }
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Equal operator for this graph
179 
181 {
182  if (this != &gr) {
183  TNamed::operator=(gr);
187 
188  fNpoints = gr.fNpoints;
189  fMaxSize = gr.fMaxSize;
190 
191  // delete list of functions and their contents before copying it
192  if (fFunctions) {
193  // delete previous lists of functions
194  if (!fFunctions->IsEmpty()) {
195  fFunctions->SetBit(kInvalidObject);
196  // use TList::Remove to take into account the case the same object is
197  // added multiple times in the list
198  TObject *obj;
199  while ((obj = fFunctions->First())) {
200  while (fFunctions->Remove(obj)) { }
201  delete obj;
202  }
203  }
204  delete fFunctions;
205  }
206 
207  if (gr.fFunctions) fFunctions = (TList*)gr.fFunctions->Clone();
208  else fFunctions = new TList;
209 
210  if (fHistogram) delete fHistogram;
211  if (gr.fHistogram) fHistogram = new TH1F(*(gr.fHistogram));
212  else fHistogram = 0;
213 
214  fMinimum = gr.fMinimum;
215  fMaximum = gr.fMaximum;
216  if (fX) delete [] fX;
217  if (fY) delete [] fY;
218  if (!fMaxSize) {
219  fX = fY = 0;
220  return *this;
221  } else {
222  fX = new Double_t[fMaxSize];
223  fY = new Double_t[fMaxSize];
224  }
225 
226  Int_t n = gr.GetN() * sizeof(Double_t);
227  if (n > 0) {
228  memcpy(fX, gr.fX, n);
229  memcpy(fY, gr.fY, n);
230  }
231  }
232  return *this;
233 }
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 /// Graph constructor with two vectors of floats in input
237 /// A graph is build with the X coordinates taken from vx and Y coord from vy
238 /// The number of points in the graph is the minimum of number of points
239 /// in vx and vy.
240 
241 TGraph::TGraph(const TVectorF &vx, const TVectorF &vy)
242  : TNamed("Graph", "Graph"), TAttLine(), TAttFill(1, 1001), TAttMarker()
243 {
244  fNpoints = TMath::Min(vx.GetNrows(), vy.GetNrows());
245  if (!CtorAllocate()) return;
246  Int_t ivxlow = vx.GetLwb();
247  Int_t ivylow = vy.GetLwb();
248  for (Int_t i = 0; i < fNpoints; i++) {
249  fX[i] = vx(i + ivxlow);
250  fY[i] = vy(i + ivylow);
251  }
252 }
253 
254 ////////////////////////////////////////////////////////////////////////////////
255 /// Graph constructor with two vectors of doubles in input
256 /// A graph is build with the X coordinates taken from vx and Y coord from vy
257 /// The number of points in the graph is the minimum of number of points
258 /// in vx and vy.
259 
260 TGraph::TGraph(const TVectorD &vx, const TVectorD &vy)
261  : TNamed("Graph", "Graph"), TAttLine(), TAttFill(1, 1001), TAttMarker()
262 {
263  fNpoints = TMath::Min(vx.GetNrows(), vy.GetNrows());
264  if (!CtorAllocate()) return;
265  Int_t ivxlow = vx.GetLwb();
266  Int_t ivylow = vy.GetLwb();
267  for (Int_t i = 0; i < fNpoints; i++) {
268  fX[i] = vx(i + ivxlow);
269  fY[i] = vy(i + ivylow);
270  }
271 }
272 
273 ////////////////////////////////////////////////////////////////////////////////
274 /// Graph constructor importing its parameters from the TH1 object passed as argument
275 
277  : TNamed("Graph", "Graph"), TAttLine(), TAttFill(1, 1001), TAttMarker()
278 {
279  if (!h) {
280  Error("TGraph", "Pointer to histogram is null");
281  fNpoints = 0;
282  return;
283  }
284  if (h->GetDimension() != 1) {
285  Error("TGraph", "Histogram must be 1-D; h %s is %d-D", h->GetName(), h->GetDimension());
286  fNpoints = 0;
287  } else {
288  fNpoints = ((TH1*)h)->GetXaxis()->GetNbins();
289  }
290 
291  if (!CtorAllocate()) return;
292 
293  TAxis *xaxis = ((TH1*)h)->GetXaxis();
294  for (Int_t i = 0; i < fNpoints; i++) {
295  fX[i] = xaxis->GetBinCenter(i + 1);
296  fY[i] = h->GetBinContent(i + 1);
297  }
298  h->TAttLine::Copy(*this);
299  h->TAttFill::Copy(*this);
300  h->TAttMarker::Copy(*this);
301 
302  std::string gname = "Graph_from_" + std::string(h->GetName());
303  SetName(gname.c_str());
304  SetTitle(h->GetTitle());
305 }
306 
307 ////////////////////////////////////////////////////////////////////////////////
308 /// Graph constructor importing its parameters from the TF1 object passed as argument
309 /// - if option =="" (default), a TGraph is created with points computed
310 /// at the fNpx points of f.
311 /// - if option =="d", a TGraph is created with points computed with the derivatives
312 /// at the fNpx points of f.
313 /// - if option =="i", a TGraph is created with points computed with the integral
314 /// at the fNpx points of f.
315 /// - if option =="I", a TGraph is created with points computed with the integral
316 /// at the fNpx+1 points of f and the integral is normalized to 1.
317 
318 TGraph::TGraph(const TF1 *f, Option_t *option)
319  : TNamed("Graph", "Graph"), TAttLine(), TAttFill(1, 1001), TAttMarker()
320 {
321  char coption = ' ';
322  if (!f) {
323  Error("TGraph", "Pointer to function is null");
324  fNpoints = 0;
325  } else {
326  fNpoints = f->GetNpx();
327  if (option) coption = *option;
328  if (coption == 'i' || coption == 'I') fNpoints++;
329  }
330  if (!CtorAllocate()) return;
331 
332  Double_t xmin = f->GetXmin();
333  Double_t xmax = f->GetXmax();
334  Double_t dx = (xmax - xmin) / fNpoints;
335  Double_t integ = 0;
336  Int_t i;
337  for (i = 0; i < fNpoints; i++) {
338  if (coption == 'i' || coption == 'I') {
339  fX[i] = xmin + i * dx;
340  if (i == 0) fY[i] = 0;
341  else fY[i] = integ + ((TF1*)f)->Integral(fX[i] - dx, fX[i]);
342  integ = fY[i];
343  } else if (coption == 'd' || coption == 'D') {
344  fX[i] = xmin + (i + 0.5) * dx;
345  fY[i] = ((TF1*)f)->Derivative(fX[i]);
346  } else {
347  fX[i] = xmin + (i + 0.5) * dx;
348  fY[i] = ((TF1*)f)->Eval(fX[i]);
349  }
350  }
351  if (integ != 0 && coption == 'I') {
352  for (i = 1; i < fNpoints; i++) fY[i] /= integ;
353  }
354 
355  f->TAttLine::Copy(*this);
356  f->TAttFill::Copy(*this);
357  f->TAttMarker::Copy(*this);
358 
359  SetName(f->GetName());
360  SetTitle(f->GetTitle());
361 }
362 
363 ////////////////////////////////////////////////////////////////////////////////
364 /// Graph constructor reading input from filename.
365 /// filename is assumed to contain at least two columns of numbers.
366 /// the string format is by default "%lg %lg".
367 /// this is a standard c formatting for scanf. If columns of numbers should be
368 /// skipped, a "%*lg" or "%*s" for each column can be added,
369 /// e.g. "%lg %*lg %lg" would read x-values from the first and y-values from
370 /// the third column.
371 /// For files separated by a specific delimiter different from ' ' and '\t' (e.g. ';' in csv files)
372 /// you can avoid using %*s to bypass this delimiter by explicitly specify the "option" argument,
373 /// e.g. option=" \t,;" for columns of figures separated by any of these characters (' ', '\t', ',', ';')
374 /// used once (e.g. "1;1") or in a combined way (" 1;,;; 1").
375 /// Note in that case, the instantiation is about 2 times slower.
376 
377 TGraph::TGraph(const char *filename, const char *format, Option_t *option)
378  : TNamed("Graph", filename), TAttLine(), TAttFill(1, 1001), TAttMarker()
379 {
380  Double_t x, y;
381  TString fname = filename;
382  gSystem->ExpandPathName(fname);
383 
384  std::ifstream infile(fname.Data());
385  if (!infile.good()) {
386  MakeZombie();
387  Error("TGraph", "Cannot open file: %s, TGraph is Zombie", filename);
388  fNpoints = 0;
389  return;
390  } else {
391  fNpoints = 100; //initial number of points
392  }
393  if (!CtorAllocate()) return;
394  std::string line;
395  Int_t np = 0;
396 
397  // No delimiters specified (standard constructor).
398  if (strcmp(option, "") == 0) {
399 
400  while (std::getline(infile, line, '\n')) {
401  if (2 != sscanf(line.c_str(), format, &x, &y)) {
402  continue; //skip empty and ill-formed lines
403  }
404  SetPoint(np, x, y);
405  np++;
406  }
407  Set(np);
408 
409  // A delimiter has been specified in "option"
410  } else {
411 
412  // Checking format and creating its boolean counterpart
413  TString format_ = TString(format) ;
414  format_.ReplaceAll(" ", "") ;
415  format_.ReplaceAll("\t", "") ;
416  format_.ReplaceAll("lg", "") ;
417  format_.ReplaceAll("s", "") ;
418  format_.ReplaceAll("%*", "0") ;
419  format_.ReplaceAll("%", "1") ;
420  if (!format_.IsDigit()) {
421  Error("TGraph", "Incorrect input format! Allowed formats are {\"%%lg\",\"%%*lg\" or \"%%*s\"}");
422  return;
423  }
424  Int_t ntokens = format_.Length() ;
425  if (ntokens < 2) {
426  Error("TGraph", "Incorrect input format! Only %d tag(s) in format whereas 2 \"%%lg\" tags are expected!", ntokens);
427  return;
428  }
429  Int_t ntokensToBeSaved = 0 ;
430  Bool_t * isTokenToBeSaved = new Bool_t [ntokens] ;
431  for (Int_t idx = 0; idx < ntokens; idx++) {
432  isTokenToBeSaved[idx] = TString::Format("%c", format_[idx]).Atoi() ; //atoi(&format_[idx]) does not work for some reason...
433  if (isTokenToBeSaved[idx] == 1) {
434  ntokensToBeSaved++ ;
435  }
436  }
437  if (ntokens >= 2 && ntokensToBeSaved != 2) { //first condition not to repeat the previous error message
438  Error("TGraph", "Incorrect input format! There are %d \"%%lg\" tag(s) in format whereas 2 and only 2 are expected!", ntokensToBeSaved);
439  delete [] isTokenToBeSaved ;
440  return;
441  }
442 
443  // Initializing loop variables
444  Bool_t isLineToBeSkipped = kFALSE ; //empty and ill-formed lines
445  char * token = NULL ;
446  TString token_str = "" ;
447  Int_t token_idx = 0 ;
448  Double_t * value = new Double_t [2] ; //x,y buffers
449  Int_t value_idx = 0 ;
450 
451  // Looping
452  while (std::getline(infile, line, '\n')) {
453  if (line != "") {
454  if (line[line.size() - 1] == char(13)) { // removing DOS CR character
455  line.erase(line.end() - 1, line.end()) ;
456  }
457  token = strtok(const_cast<char*>(line.c_str()), option) ;
458  while (token != NULL && value_idx < 2) {
459  if (isTokenToBeSaved[token_idx]) {
460  token_str = TString(token) ;
461  token_str.ReplaceAll("\t", "") ;
462  if (!token_str.IsFloat()) {
463  isLineToBeSkipped = kTRUE ;
464  break ;
465  } else {
466  value[value_idx] = token_str.Atof() ;
467  value_idx++ ;
468  }
469  }
470  token = strtok(NULL, option) ; //next token
471  token_idx++ ;
472  }
473  if (!isLineToBeSkipped && value_idx == 2) {
474  x = value[0] ;
475  y = value[1] ;
476  SetPoint(np, x, y) ;
477  np++ ;
478  }
479  }
480  isLineToBeSkipped = kFALSE ;
481  token = NULL ;
482  token_idx = 0 ;
483  value_idx = 0 ;
484  }
485  Set(np) ;
486 
487  // Cleaning
488  delete [] isTokenToBeSaved ;
489  delete [] value ;
490  delete token ;
491  }
492  infile.close();
493 }
494 
495 ////////////////////////////////////////////////////////////////////////////////
496 /// Graph default destructor.
497 
499 {
500  delete [] fX;
501  delete [] fY;
502  if (fFunctions) {
503  fFunctions->SetBit(kInvalidObject);
504  //special logic to support the case where the same object is
505  //added multiple times in fFunctions.
506  //This case happens when the same object is added with different
507  //drawing modes
508  TObject *obj;
509  while ((obj = fFunctions->First())) {
510  while (fFunctions->Remove(obj)) { }
511  delete obj;
512  }
513  delete fFunctions;
514  fFunctions = 0; //to avoid accessing a deleted object in RecursiveRemove
515  }
516  delete fHistogram;
517 }
518 
519 ////////////////////////////////////////////////////////////////////////////////
520 /// Allocate arrays.
521 
523 {
524  if (arraySize < 0) {
525  arraySize = 0;
526  }
527  Double_t **newarrays = new Double_t*[Narrays];
528  if (!arraySize) {
529  for (Int_t i = 0; i < Narrays; ++i)
530  newarrays[i] = 0;
531  } else {
532  for (Int_t i = 0; i < Narrays; ++i)
533  newarrays[i] = new Double_t[arraySize];
534  }
535  fMaxSize = arraySize;
536  return newarrays;
537 }
538 
539 ////////////////////////////////////////////////////////////////////////////////
540 /// Apply function f to all the data points
541 /// f may be a 1-D function TF1 or 2-d function TF2
542 /// The Y values of the graph are replaced by the new values computed
543 /// using the function
544 
546 {
547  if (fHistogram) {
548  delete fHistogram;
549  fHistogram = 0;
550  }
551  for (Int_t i = 0; i < fNpoints; i++) {
552  fY[i] = f->Eval(fX[i], fY[i]);
553  }
554  if (gPad) gPad->Modified();
555 }
556 
557 ////////////////////////////////////////////////////////////////////////////////
558 /// Browse
559 
561 {
562  TString opt = gEnv->GetValue("TGraph.BrowseOption", "");
563  if (opt.IsNull()) {
564  opt = b ? b->GetDrawOption() : "alp";
565  opt = (opt == "") ? "alp" : opt.Data();
566  }
567  Draw(opt.Data());
568  gPad->Update();
569 }
570 
571 ////////////////////////////////////////////////////////////////////////////////
572 /// Return the chisquare of this graph with respect to f1.
573 /// The chisquare is computed as the sum of the quantity below at each point:
574 /// \f[
575 /// \frac{(y-f1(x))^{2}}{ey^{2}+(\frac{1}{2}(exl+exh)f1'(x))^{2}}
576 /// \f]
577 /// where x and y are the graph point coordinates and f1'(x) is the derivative of function f1(x).
578 /// This method to approximate the uncertainty in y because of the errors in x, is called
579 /// "effective variance" method.
580 /// In case of a pure TGraph, the denominator is 1.
581 /// In case of a TGraphErrors or TGraphAsymmErrors the errors are taken
582 /// into account.
583 /// By default the range of the graph is used whatever function range.
584 /// Use option "R" to use the function range
585 
587 {
588  if (!func) {
589  Error("Chisquare","Function pointer is Null - return -1");
590  return -1;
591  }
592 
593  TString opt(option); opt.ToUpper();
594  bool useRange = opt.Contains("R");
595 
596  return ROOT::Fit::Chisquare(*this, *func,useRange);
597 }
598 
599 ////////////////////////////////////////////////////////////////////////////////
600 /// Return kTRUE if point number "left"'s argument (angle with respect to positive
601 /// x-axis) is bigger than that of point number "right". Can be used by Sort.
602 
604 {
605  Double_t xl, yl, xr, yr;
606  gr->GetPoint(left, xl, yl);
607  gr->GetPoint(right, xr, yr);
608  return (TMath::ATan2(yl, xl) > TMath::ATan2(yr, xr));
609 }
610 
611 ////////////////////////////////////////////////////////////////////////////////
612 /// Return kTRUE if fX[left] > fX[right]. Can be used by Sort.
613 
615 {
616  return gr->fX[left] > gr->fX[right];
617 }
618 
619 ////////////////////////////////////////////////////////////////////////////////
620 /// Return kTRUE if fY[left] > fY[right]. Can be used by Sort.
621 
623 {
624  return gr->fY[left] > gr->fY[right];
625 }
626 
627 ////////////////////////////////////////////////////////////////////////////////
628 /// Return kTRUE if point number "left"'s distance to origin is bigger than
629 /// that of point number "right". Can be used by Sort.
630 
632 {
633  return gr->fX[left] * gr->fX[left] + gr->fY[left] * gr->fY[left]
634  > gr->fX[right] * gr->fX[right] + gr->fY[right] * gr->fY[right];
635 }
636 
637 ////////////////////////////////////////////////////////////////////////////////
638 /// Compute the x/y range of the points in this graph
639 
641 {
642  if (fNpoints <= 0) {
643  xmin = xmax = ymin = ymax = 0;
644  return;
645  }
646  xmin = xmax = fX[0];
647  ymin = ymax = fY[0];
648 
649  Double_t xminl = 0; // Positive minimum. Used in case of log scale along X axis.
650  Double_t yminl = 0; // Positive minimum. Used in case of log scale along Y axis.
651 
652  for (Int_t i = 1; i < fNpoints; i++) {
653  if (fX[i] < xmin) xmin = fX[i];
654  if (fX[i] > xmax) xmax = fX[i];
655  if (fY[i] < ymin) ymin = fY[i];
656  if (fY[i] > ymax) ymax = fY[i];
657  if (ymin>0 && (yminl==0 || ymin<yminl)) yminl = ymin;
658  if (xmin>0 && (xminl==0 || xmin<xminl)) xminl = xmin;
659  }
660 
661  if (gPad && gPad->GetLogy() && yminl>0) ymin = yminl;
662  if (gPad && gPad->GetLogx() && xminl>0) xmin = xminl;
663 }
664 
665 ////////////////////////////////////////////////////////////////////////////////
666 /// Copy points from fX and fY to arrays[0] and arrays[1]
667 /// or to fX and fY if arrays == 0 and ibegin != iend.
668 /// If newarrays is non null, replace fX, fY with pointers from newarrays[0,1].
669 /// Delete newarrays, old fX and fY
670 
671 void TGraph::CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend,
672  Int_t obegin)
673 {
674  CopyPoints(newarrays, ibegin, iend, obegin);
675  if (newarrays) {
676  delete[] fX;
677  fX = newarrays[0];
678  delete[] fY;
679  fY = newarrays[1];
680  delete[] newarrays;
681  }
682 }
683 
684 ////////////////////////////////////////////////////////////////////////////////
685 /// Copy points from fX and fY to arrays[0] and arrays[1]
686 /// or to fX and fY if arrays == 0 and ibegin != iend.
687 
689  Int_t obegin)
690 {
691  if (ibegin < 0 || iend <= ibegin || obegin < 0) { // Error;
692  return kFALSE;
693  }
694  if (!arrays && ibegin == obegin) { // No copying is needed
695  return kFALSE;
696  }
697  Int_t n = (iend - ibegin) * sizeof(Double_t);
698  if (arrays) {
699  memmove(&arrays[0][obegin], &fX[ibegin], n);
700  memmove(&arrays[1][obegin], &fY[ibegin], n);
701  } else {
702  memmove(&fX[obegin], &fX[ibegin], n);
703  memmove(&fY[obegin], &fY[ibegin], n);
704  }
705  return kTRUE;
706 }
707 
708 ////////////////////////////////////////////////////////////////////////////////
709 /// In constructors set fNpoints than call this method.
710 /// Return kFALSE if the graph will contain no points.
711 ///Note: This function should be called only from the constructor
712 /// since it does not delete previously existing arrays
713 
715 {
716  fHistogram = 0;
717  fMaximum = -1111;
718  fMinimum = -1111;
720  fFunctions = new TList;
721  if (fNpoints <= 0) {
722  fNpoints = 0;
723  fMaxSize = 0;
724  fX = 0;
725  fY = 0;
726  return kFALSE;
727  } else {
728  fMaxSize = fNpoints;
729  fX = new Double_t[fMaxSize];
730  fY = new Double_t[fMaxSize];
731  }
732  return kTRUE;
733 }
734 
735 ////////////////////////////////////////////////////////////////////////////////
736 /// Draw this graph with its current attributes.
737 ///
738 /// The options to draw a graph are described in TGraphPainter class.
739 
740 void TGraph::Draw(Option_t *option)
741 {
742  TString opt = option;
743  opt.ToLower();
744 
745  if (opt.Contains("same")) {
746  opt.ReplaceAll("same", "");
747  }
748 
749  // in case of option *, set marker style to 3 (star) and replace
750  // * option by option P.
751  Ssiz_t pos;
752  if ((pos = opt.Index("*")) != kNPOS) {
753  SetMarkerStyle(3);
754  opt.Replace(pos, 1, "p");
755  }
756 
757  // If no option is specified, it is defined as "alp" in case there
758  // no current pad or if the current pad as no axis defined.
759  if (!strlen(option)) {
760  if (gPad) {
761  if (!gPad->GetListOfPrimitives()->FindObject("TFrame")) opt = "alp";
762  } else {
763  opt = "alp";
764  }
765  }
766 
767  if (gPad) {
768  if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
769  if (opt.Contains("a")) gPad->Clear();
770  }
771 
772  AppendPad(opt);
773 }
774 
775 ////////////////////////////////////////////////////////////////////////////////
776 /// Compute distance from point px,py to a graph.
777 ///
778 /// Compute the closest distance of approach from point px,py to this line.
779 /// The distance is computed in pixels units.
780 
782 {
784  if (painter) return painter->DistancetoPrimitiveHelper(this, px, py);
785  else return 0;
786 }
787 
788 ////////////////////////////////////////////////////////////////////////////////
789 /// Draw this graph with new attributes.
790 
791 void TGraph::DrawGraph(Int_t n, const Int_t *x, const Int_t *y, Option_t *option)
792 {
793  TGraph *newgraph = new TGraph(n, x, y);
794  TAttLine::Copy(*newgraph);
795  TAttFill::Copy(*newgraph);
796  TAttMarker::Copy(*newgraph);
797  newgraph->SetBit(kCanDelete);
798  newgraph->AppendPad(option);
799 }
800 
801 ////////////////////////////////////////////////////////////////////////////////
802 /// Draw this graph with new attributes.
803 
804 void TGraph::DrawGraph(Int_t n, const Float_t *x, const Float_t *y, Option_t *option)
805 {
806  TGraph *newgraph = new TGraph(n, x, y);
807  TAttLine::Copy(*newgraph);
808  TAttFill::Copy(*newgraph);
809  TAttMarker::Copy(*newgraph);
810  newgraph->SetBit(kCanDelete);
811  newgraph->AppendPad(option);
812 }
813 
814 ////////////////////////////////////////////////////////////////////////////////
815 /// Draw this graph with new attributes.
816 
817 void TGraph::DrawGraph(Int_t n, const Double_t *x, const Double_t *y, Option_t *option)
818 {
819  const Double_t *xx = x;
820  const Double_t *yy = y;
821  if (!xx) xx = fX;
822  if (!yy) yy = fY;
823  TGraph *newgraph = new TGraph(n, xx, yy);
824  TAttLine::Copy(*newgraph);
825  TAttFill::Copy(*newgraph);
826  TAttMarker::Copy(*newgraph);
827  newgraph->SetBit(kCanDelete);
828  newgraph->AppendPad(option);
829 }
830 
831 ////////////////////////////////////////////////////////////////////////////////
832 /// Display a panel with all graph drawing options.
833 
835 {
837  if (painter) painter->DrawPanelHelper(this);
838 }
839 
840 ////////////////////////////////////////////////////////////////////////////////
841 /// Interpolate points in this graph at x using a TSpline
842 /// -if spline==0 and option="" a linear interpolation between the two points
843 /// close to x is computed. If x is outside the graph range, a linear
844 /// extrapolation is computed.
845 /// -if spline==0 and option="S" a TSpline3 object is created using this graph
846 /// and the interpolated value from the spline is returned.
847 /// the internally created spline is deleted on return.
848 /// -if spline is specified, it is used to return the interpolated value.
849 
850 Double_t TGraph::Eval(Double_t x, TSpline *spline, Option_t *option) const
851 {
852 
853  if (!spline) {
854 
855  if (fNpoints == 0) return 0;
856  if (fNpoints == 1) return fY[0];
857 
858 
859  TString opt = option;
860  opt.ToLower();
861  if (opt.Contains("s")) {
862 
863  // points must be sorted before using a TSpline
864  std::vector<Double_t> xsort(fNpoints);
865  std::vector<Double_t> ysort(fNpoints);
866  std::vector<Int_t> indxsort(fNpoints);
867  TMath::Sort(fNpoints, fX, &indxsort[0], false);
868  for (Int_t i = 0; i < fNpoints; ++i) {
869  xsort[i] = fX[ indxsort[i] ];
870  ysort[i] = fY[ indxsort[i] ];
871  }
872 
873  // spline interpolation creating a new spline
874  TSpline3 *s = new TSpline3("", &xsort[0], &ysort[0], fNpoints);
875  Double_t result = s->Eval(x);
876  delete s;
877  return result;
878  }
879  //linear interpolation
880  //In case x is < fX[0] or > fX[fNpoints-1] return the extrapolated point
881 
882  //find points in graph around x assuming points are not sorted
883  // (if point are sorted could use binary search)
884 
885  // find neighbours simply looping all points
886  // and find also the 2 adjacent points: (low2 < low < x < up < up2 )
887  // needed in case x is outside the graph ascissa interval
888  Int_t low = -1;
889  Int_t up = -1;
890  Int_t low2 = -1;
891  Int_t up2 = -1;
892 
893  for (Int_t i = 0; i < fNpoints; ++i) {
894  if (fX[i] < x) {
895  if (low == -1 || fX[i] > fX[low]) {
896  low2 = low;
897  low = i;
898  } else if (low2 == -1) low2 = i;
899  } else if (fX[i] > x) {
900  if (up == -1 || fX[i] < fX[up]) {
901  up2 = up;
902  up = i;
903  } else if (up2 == -1) up2 = i;
904  } else // case x == fX[i]
905  return fY[i]; // no interpolation needed
906  }
907 
908  // treat cases when x is outside graph min max abscissa
909  if (up == -1) {
910  up = low;
911  low = low2;
912  }
913  if (low == -1) {
914  low = up;
915  up = up2;
916  }
917 
918  assert(low != -1 && up != -1);
919 
920  if (fX[low] == fX[up]) return fY[low];
921  Double_t yn = fY[up] + (x - fX[up]) * (fY[low] - fY[up]) / (fX[low] - fX[up]);
922  return yn;
923  } else {
924  //spline interpolation using the input spline
925  return spline->Eval(x);
926  }
927 }
928 
929 ////////////////////////////////////////////////////////////////////////////////
930 /// Execute action corresponding to one event.
931 ///
932 /// This member function is called when a graph is clicked with the locator
933 ///
934 /// If Left button clicked on one of the line end points, this point
935 /// follows the cursor until button is released.
936 ///
937 /// if Middle button clicked, the line is moved parallel to itself
938 /// until the button is released.
939 
941 {
943  if (painter) painter->ExecuteEventHelper(this, event, px, py);
944 }
945 
946 ////////////////////////////////////////////////////////////////////////////////
947 /// If array sizes <= newsize, expand storage to 2*newsize.
948 
949 void TGraph::Expand(Int_t newsize)
950 {
951  Double_t **ps = ExpandAndCopy(newsize, fNpoints);
952  CopyAndRelease(ps, 0, 0, 0);
953 }
954 
955 ////////////////////////////////////////////////////////////////////////////////
956 /// If graph capacity is less than newsize points then make array sizes
957 /// equal to least multiple of step to contain newsize points.
958 /// Returns kTRUE if size was altered
959 
960 void TGraph::Expand(Int_t newsize, Int_t step)
961 {
962  if (newsize <= fMaxSize) {
963  return;
964  }
965  Double_t **ps = Allocate(step * (newsize / step + (newsize % step ? 1 : 0)));
966  CopyAndRelease(ps, 0, fNpoints, 0);
967 }
968 
969 ////////////////////////////////////////////////////////////////////////////////
970 /// if size > fMaxSize allocate new arrays of 2*size points and copy iend first
971 /// points.
972 /// Return pointer to new arrays.
973 
975 {
976  if (size <= fMaxSize) {
977  return 0;
978  }
979  Double_t **newarrays = Allocate(2 * size);
980  CopyPoints(newarrays, 0, iend, 0);
981  return newarrays;
982 }
983 
984 ////////////////////////////////////////////////////////////////////////////////
985 /// Set zero values for point arrays in the range [begin, end)
986 /// Should be redefined in descendant classes
987 
989 {
990  memset(fX + begin, 0, (end - begin)*sizeof(Double_t));
991  memset(fY + begin, 0, (end - begin)*sizeof(Double_t));
992 }
993 
994 ////////////////////////////////////////////////////////////////////////////////
995 /// Search object named name in the list of functions
996 
997 TObject *TGraph::FindObject(const char *name) const
998 {
999  if (fFunctions) return fFunctions->FindObject(name);
1000  return 0;
1001 }
1002 
1003 ////////////////////////////////////////////////////////////////////////////////
1004 /// Search object obj in the list of functions
1005 
1007 {
1008  if (fFunctions) return fFunctions->FindObject(obj);
1009  return 0;
1010 }
1011 
1012 ////////////////////////////////////////////////////////////////////////////////
1013 /// Fit this graph with function with name fname.
1014 ///
1015 /// interface to TGraph::Fit(TF1 *f1...
1016 ///
1017 /// fname is the name of an already predefined function created by TF1 or TF2
1018 /// Predefined functions such as gaus, expo and poln are automatically
1019 /// created by ROOT.
1020 ///
1021 /// fname can also be a formula, accepted by the linear fitter (linear parts divided
1022 /// by "++" sign), for example "x++sin(x)" for fitting "[0]*x+[1]*sin(x)"
1023 
1025 {
1026  char *linear;
1027  linear = (char*) strstr(fname, "++");
1028  TF1 *f1 = 0;
1029  if (linear)
1030  f1 = new TF1(fname, fname, xmin, xmax);
1031  else {
1032  f1 = (TF1*)gROOT->GetFunction(fname);
1033  if (!f1) {
1034  Printf("Unknown function: %s", fname);
1035  return -1;
1036  }
1037  }
1038  return Fit(f1, option, "", xmin, xmax);
1039 }
1040 
1041 ////////////////////////////////////////////////////////////////////////////////
1042 /// Fit this graph with function f1.
1043 ///
1044 /// f1 is an already predefined function created by TF1.
1045 /// Predefined functions such as gaus, expo and poln are automatically
1046 /// created by ROOT.
1047 ///
1048 /// The list of fit options is given in parameter option.
1049 ///
1050 /// option | description
1051 /// -------|------------
1052 /// "W" | Set all weights to 1; ignore error bars
1053 /// "U" | Use a User specified fitting algorithm (via SetFCN)
1054 /// "Q" | Quiet mode (minimum printing)
1055 /// "V" | Verbose mode (default is between Q and V)
1056 /// "E" | Perform better Errors estimation using Minos technique
1057 /// "B" | User defined parameter settings are used for predefined functions like "gaus", "expo", "poln", "landau". Use this option when you want to fix one or more parameters for these functions.
1058 /// "M" | More. Improve fit results. It uses the IMPROVE command of TMinuit (see TMinuit::mnimpr). This algorithm attempts to improve the found local minimum by searching for a better one.
1059 /// "R" | Use the Range specified in the function range
1060 /// "N" | Do not store the graphics function, do not draw
1061 /// "0" | Do not plot the result of the fit. By default the fitted function is drawn unless the option "N" above is specified.
1062 /// "+" | Add this new fitted function to the list of fitted functions (by default, any previous function is deleted)
1063 /// "C" | In case of linear fitting, do not calculate the chisquare (saves time)
1064 /// "F" | If fitting a polN, use the minuit fitter
1065 /// "EX0" | When fitting a TGraphErrors or TGraphAsymErrors do not consider errors in the coordinate
1066 /// "ROB" | In case of linear fitting, compute the LTS regression coefficients (robust (resistant) regression), using the default fraction of good points "ROB=0.x" - compute the LTS regression coefficients, using 0.x as a fraction of good points
1067 /// "S" | The result of the fit is returned in the TFitResultPtr (see below Access to the Fit Result)
1068 ///
1069 /// When the fit is drawn (by default), the parameter goption may be used
1070 /// to specify a list of graphics options. See TGraphPainter for a complete
1071 /// list of these options.
1072 ///
1073 /// In order to use the Range option, one must first create a function
1074 /// with the expression to be fitted. For example, if your graph
1075 /// has a defined range between -4 and 4 and you want to fit a gaussian
1076 /// only in the interval 1 to 3, you can do:
1077 ///
1078 /// TF1 *f1 = new TF1("f1","gaus",1,3);
1079 /// graph->Fit("f1","R");
1080 ///
1081 /// Who is calling this function:
1082 ///
1083 /// Note that this function is called when calling TGraphErrors::Fit
1084 /// or TGraphAsymmErrors::Fit ot TGraphBentErrors::Fit
1085 /// See the discussion below on error calculation.
1086 ///
1087 /// ## Linear fitting:
1088 /// When the fitting function is linear (contains the "++" sign) or the fitting
1089 /// function is a polynomial, a linear fitter is initialised.
1090 /// To create a linear function, use the following syntax: linear parts
1091 /// separated by "++" sign.
1092 /// Example: to fit the parameters of "[0]*x + [1]*sin(x)", create a
1093 /// TF1 *f1=new TF1("f1", "x++sin(x)", xmin, xmax);
1094 /// For such a TF1 you don't have to set the initial conditions.
1095 /// Going via the linear fitter for functions, linear in parameters, gives a
1096 /// considerable advantage in speed.
1097 ///
1098 /// ## Setting initial conditions:
1099 ///
1100 /// Parameters must be initialized before invoking the Fit function.
1101 /// The setting of the parameter initial values is automatic for the
1102 /// predefined functions : poln, expo, gaus, landau. One can however disable
1103 /// this automatic computation by specifying the option "B".
1104 /// You can specify boundary limits for some or all parameters via
1105 ///
1106 /// f1->SetParLimits(p_number, parmin, parmax);
1107 /// If parmin>=parmax, the parameter is fixed
1108 /// Note that you are not forced to fix the limits for all parameters.
1109 /// For example, if you fit a function with 6 parameters, you can do:
1110 ///
1111 /// func->SetParameters(0,3.1,1.e-6,0.1,-8,100);
1112 /// func->SetParLimits(4,-10,-4);
1113 /// func->SetParLimits(5, 1,1);
1114 /// With this setup, parameters 0->3 can vary freely.
1115 /// Parameter 4 has boundaries [-10,-4] with initial value -8.
1116 /// Parameter 5 is fixed to 100.
1117 ///
1118 /// ## Fit range:
1119 ///
1120 /// The fit range can be specified in two ways:
1121 /// - specify rxmax > rxmin (default is rxmin=rxmax=0)
1122 /// - specify the option "R". In this case, the function will be taken
1123 /// instead of the full graph range.
1124 ///
1125 /// ## Changing the fitting function:
1126 ///
1127 /// By default a chi2 fitting function is used for fitting a TGraph.
1128 /// The function is implemented in FitUtil::EvaluateChi2.
1129 /// In case of TGraphErrors an effective chi2 is used (see below TGraphErrors fit)
1130 /// To specify a User defined fitting function, specify option "U" and
1131 /// call the following functions:
1132 ///
1133 /// TVirtualFitter::Fitter(mygraph)->SetFCN(MyFittingFunction)
1134 /// where MyFittingFunction is of type:
1135 /// extern void MyFittingFunction(Int_t &npar, Double_t *gin, Double_t &f,
1136 /// Double_t *u, Int_t flag);
1137 ///
1138 ///
1139 /// ## TGraphErrors fit:
1140 ///
1141 /// In case of a TGraphErrors object, when x errors are present, the error along x,
1142 /// is projected along the y-direction by calculating the function at the points x-exlow and
1143 /// x+exhigh. The chisquare is then computed as the sum of the quantity below at each point:
1144 ///
1145 /// \f[
1146 /// \frac{(y-f(x))^{2}}{ey^{2}+(\frac{1}{2}(exl+exh)f'(x))^{2}}
1147 /// \f]
1148 ///
1149 /// where x and y are the point coordinates, and f'(x) is the derivative of the
1150 /// function f(x).
1151 ///
1152 /// In case the function lies below (above) the data point, ey is ey_low (ey_high).
1153 ///
1154 /// thanks to Andy Haas (haas@yahoo.com) for adding the case with TGraphAsymmErrors
1155 /// University of Washington
1156 ///
1157 /// The approach used to approximate the uncertainty in y because of the
1158 /// errors in x is to make it equal the error in x times the slope of the line.
1159 /// The improvement, compared to the first method (f(x+ exhigh) - f(x-exlow))/2
1160 /// is of (error of x)**2 order. This approach is called "effective variance method".
1161 /// This improvement has been made in version 4.00/08 by Anna Kreshuk.
1162 /// The implementation is provided in the function FitUtil::EvaluateChi2Effective
1163 ///
1164 /// NOTE:
1165 /// 1. By using the "effective variance" method a simple linear regression
1166 /// becomes a non-linear case, which takes several iterations
1167 /// instead of 0 as in the linear case.
1168 /// 2. The effective variance technique assumes that there is no correlation
1169 /// between the x and y coordinate.
1170 /// 3. The standard chi2 (least square) method without error in the coordinates (x) can
1171 /// be forced by using option "EX0"
1172 /// 4. The linear fitter doesn't take into account the errors in x. When fitting a
1173 /// TGraphErrors with a linear functions the errors in x will not be considered.
1174 /// If errors in x are important, go through minuit (use option "F" for polynomial fitting).
1175 /// 5. When fitting a TGraph (i.e. no errors associated with each point),
1176 /// a correction is applied to the errors on the parameters with the following
1177 /// formula: errorp *= sqrt(chisquare/(ndf-1))
1178 ///
1179 /// ## Access to the fit result
1180 /// The function returns a TFitResultPtr which can hold a pointer to a TFitResult object.
1181 /// By default the TFitResultPtr contains only the status of the fit which is return by an
1182 /// automatic conversion of the TFitResultPtr to an integer. One can write in this case
1183 /// directly:
1184 ///
1185 /// Int_t fitStatus = h->Fit(myFunc)
1186 ///
1187 /// If the option "S" is instead used, TFitResultPtr contains the TFitResult and behaves
1188 /// as a smart pointer to it. For example one can do:
1189 ///
1190 /// TFitResultPtr r = h->Fit(myFunc,"S");
1191 /// TMatrixDSym cov = r->GetCovarianceMatrix(); // to access the covariance matrix
1192 /// Double_t chi2 = r->Chi2(); // to retrieve the fit chi2
1193 /// Double_t par0 = r->Value(0); // retrieve the value for the parameter 0
1194 /// Double_t err0 = r->ParError(0); // retrieve the error for the parameter 0
1195 /// r->Print("V"); // print full information of fit including covariance matrix
1196 /// r->Write(); // store the result in a file
1197 ///
1198 /// The fit parameters, error and chi2 (but not covariance matrix) can be retrieved also
1199 /// from the fitted function.
1200 /// If the histogram is made persistent, the list of
1201 /// associated functions is also persistent. Given a pointer (see above)
1202 /// to an associated function myfunc, one can retrieve the function/fit
1203 /// parameters with calls such as:
1204 ///
1205 /// Double_t chi2 = myfunc->GetChisquare();
1206 /// Double_t par0 = myfunc->GetParameter(0); //value of 1st parameter
1207 /// Double_t err0 = myfunc->GetParError(0); //error on first parameter
1208 ///
1209 ///
1210 /// ## Access to the fit status
1211 /// The status of the fit can be obtained converting the TFitResultPtr to an integer
1212 /// independently if the fit option "S" is used or not:
1213 ///
1214 /// TFitResultPtr r = h->Fit(myFunc,opt);
1215 /// Int_t fitStatus = r;
1216 ///
1217 /// The fitStatus is 0 if the fit is OK (i.e. no error occurred).
1218 /// The value of the fit status code is negative in case of an error not connected with the
1219 /// minimization procedure, for example when a wrong function is used.
1220 /// Otherwise the return value is the one returned from the minimization procedure.
1221 /// When TMinuit (default case) or Minuit2 are used as minimizer the status returned is :
1222 /// fitStatus = migradResult + 10*minosResult + 100*hesseResult + 1000*improveResult.
1223 /// TMinuit will return 0 (for migrad, minos, hesse or improve) in case of success and 4 in
1224 /// case of error (see the documentation of TMinuit::mnexcm). So for example, for an error
1225 /// only in Minos but not in Migrad a fitStatus of 40 will be returned.
1226 /// Minuit2 will return also 0 in case of success and different values in migrad, minos or
1227 /// hesse depending on the error. See in this case the documentation of
1228 /// Minuit2Minimizer::Minimize for the migradResult, Minuit2Minimizer::GetMinosError for the
1229 /// minosResult and Minuit2Minimizer::Hesse for the hesseResult.
1230 /// If other minimizers are used see their specific documentation for the status code
1231 /// returned. For example in the case of Fumili, for the status returned see TFumili::Minimize.
1232 ///
1233 /// ## Associated functions:
1234 /// One or more object (typically a TF1*) can be added to the list
1235 /// of functions (fFunctions) associated with each graph.
1236 /// When TGraph::Fit is invoked, the fitted function is added to this list.
1237 /// Given a graph gr, one can retrieve an associated function
1238 /// with: TF1 *myfunc = gr->GetFunction("myfunc");
1239 ///
1240 /// If the graph is made persistent, the list of associated functions is also
1241 /// persistent. Given a pointer (see above) to an associated function myfunc,
1242 /// one can retrieve the function/fit parameters with calls such as:
1243 ///
1244 /// Double_t chi2 = myfunc->GetChisquare();
1245 /// Double_t par0 = myfunc->GetParameter(0); //value of 1st parameter
1246 /// Double_t err0 = myfunc->GetParError(0); //error on first parameter
1247 ///
1248 /// ## Fit Statistics
1249 /// You can change the statistics box to display the fit parameters with
1250 /// the TStyle::SetOptFit(mode) method. This mode has four digits.
1251 /// mode = pcev (default = 0111)
1252 ///
1253 /// v = 1; print name/values of parameters
1254 /// e = 1; print errors (if e=1, v must be 1)
1255 /// c = 1; print Chisquare/Number of degrees of freedom
1256 /// p = 1; print Probability
1257 ///
1258 /// For example: gStyle->SetOptFit(1011);
1259 /// prints the fit probability, parameter names/values, and errors.
1260 /// You can change the position of the statistics box with these lines
1261 /// (where g is a pointer to the TGraph):
1262 ///
1263 /// Root > TPaveStats *st = (TPaveStats*)g->GetListOfFunctions()->FindObject("stats")
1264 /// Root > st->SetX1NDC(newx1); //new x start position
1265 /// Root > st->SetX2NDC(newx2); //new x end position
1266 ///
1267 
1268 TFitResultPtr TGraph::Fit(TF1 *f1, Option_t *option, Option_t *goption, Axis_t rxmin, Axis_t rxmax)
1269 {
1270  Foption_t fitOption;
1271  ROOT::Fit::FitOptionsMake(ROOT::Fit::kGraph, option, fitOption);
1272  // create range and minimizer options with default values
1273  ROOT::Fit::DataRange range(rxmin, rxmax);
1274  ROOT::Math::MinimizerOptions minOption;
1275  return ROOT::Fit::FitObject(this, f1 , fitOption , minOption, goption, range);
1276 }
1277 
1278 ////////////////////////////////////////////////////////////////////////////////
1279 /// Display a GUI panel with all graph fit options.
1280 ///
1281 /// See class TFitEditor for example
1282 
1284 {
1285  if (!gPad)
1286  gROOT->MakeDefCanvas();
1287 
1288  if (!gPad) {
1289  Error("FitPanel", "Unable to create a default canvas");
1290  return;
1291  }
1292 
1293  // use plugin manager to create instance of TFitEditor
1294  TPluginHandler *handler = gROOT->GetPluginManager()->FindHandler("TFitEditor");
1295  if (handler && handler->LoadPlugin() != -1) {
1296  if (handler->ExecPlugin(2, gPad, this) == 0)
1297  Error("FitPanel", "Unable to crate the FitPanel");
1298  } else
1299  Error("FitPanel", "Unable to find the FitPanel plug-in");
1300 }
1301 
1302 ////////////////////////////////////////////////////////////////////////////////
1303 /// Return graph correlation factor
1304 
1306 {
1307  Double_t rms1 = GetRMS(1);
1308  if (rms1 == 0) return 0;
1309  Double_t rms2 = GetRMS(2);
1310  if (rms2 == 0) return 0;
1311  return GetCovariance() / rms1 / rms2;
1312 }
1313 
1314 ////////////////////////////////////////////////////////////////////////////////
1315 /// Return covariance of vectors x,y
1316 
1318 {
1319  if (fNpoints <= 0) return 0;
1320  Double_t sum = fNpoints, sumx = 0, sumy = 0, sumxy = 0;
1321 
1322  for (Int_t i = 0; i < fNpoints; i++) {
1323  sumx += fX[i];
1324  sumy += fY[i];
1325  sumxy += fX[i] * fY[i];
1326  }
1327  return sumxy / sum - sumx / sum * sumy / sum;
1328 }
1329 
1330 ////////////////////////////////////////////////////////////////////////////////
1331 /// Return mean value of X (axis=1) or Y (axis=2)
1332 
1334 {
1335  if (axis < 1 || axis > 2) return 0;
1336  if (fNpoints <= 0) return 0;
1337  Double_t sumx = 0;
1338  for (Int_t i = 0; i < fNpoints; i++) {
1339  if (axis == 1) sumx += fX[i];
1340  else sumx += fY[i];
1341  }
1342  return sumx / fNpoints;
1343 }
1344 
1345 ////////////////////////////////////////////////////////////////////////////////
1346 /// Return RMS of X (axis=1) or Y (axis=2)
1347 
1349 {
1350  if (axis < 1 || axis > 2) return 0;
1351  if (fNpoints <= 0) return 0;
1352  Double_t sumx = 0, sumx2 = 0;
1353  for (Int_t i = 0; i < fNpoints; i++) {
1354  if (axis == 1) {
1355  sumx += fX[i];
1356  sumx2 += fX[i] * fX[i];
1357  } else {
1358  sumx += fY[i];
1359  sumx2 += fY[i] * fY[i];
1360  }
1361  }
1362  Double_t x = sumx / fNpoints;
1363  Double_t rms2 = TMath::Abs(sumx2 / fNpoints - x * x);
1364  return TMath::Sqrt(rms2);
1365 }
1366 
1367 ////////////////////////////////////////////////////////////////////////////////
1368 /// This function is called by GraphFitChisquare.
1369 /// It always returns a negative value. Real implementation in TGraphErrors
1370 
1372 {
1373  return -1;
1374 }
1375 
1376 ////////////////////////////////////////////////////////////////////////////////
1377 /// This function is called by GraphFitChisquare.
1378 /// It always returns a negative value. Real implementation in TGraphErrors
1379 
1381 {
1382  return -1;
1383 }
1384 
1385 ////////////////////////////////////////////////////////////////////////////////
1386 /// This function is called by GraphFitChisquare.
1387 /// It always returns a negative value. Real implementation in TGraphErrors
1388 /// and TGraphAsymmErrors
1389 
1391 {
1392  return -1;
1393 }
1394 
1395 ////////////////////////////////////////////////////////////////////////////////
1396 /// This function is called by GraphFitChisquare.
1397 /// It always returns a negative value. Real implementation in TGraphErrors
1398 /// and TGraphAsymmErrors
1399 
1401 {
1402  return -1;
1403 }
1404 
1405 ////////////////////////////////////////////////////////////////////////////////
1406 /// This function is called by GraphFitChisquare.
1407 /// It always returns a negative value. Real implementation in TGraphErrors
1408 /// and TGraphAsymmErrors
1409 
1411 {
1412  return -1;
1413 }
1414 
1415 ////////////////////////////////////////////////////////////////////////////////
1416 /// This function is called by GraphFitChisquare.
1417 /// It always returns a negative value. Real implementation in TGraphErrors
1418 /// and TGraphAsymmErrors
1419 
1421 {
1422  return -1;
1423 }
1424 
1425 ////////////////////////////////////////////////////////////////////////////////
1426 /// Return pointer to function with name.
1427 ///
1428 /// Functions such as TGraph::Fit store the fitted function in the list of
1429 /// functions of this graph.
1430 
1431 TF1 *TGraph::GetFunction(const char *name) const
1432 {
1433  if (!fFunctions) return 0;
1434  return (TF1*)fFunctions->FindObject(name);
1435 }
1436 
1437 ////////////////////////////////////////////////////////////////////////////////
1438 /// Returns a pointer to the histogram used to draw the axis
1439 /// Takes into account the two following cases.
1440 /// 1. option 'A' was specified in TGraph::Draw. Return fHistogram
1441 /// 2. user had called TPad::DrawFrame. return pointer to hframe histogram
1442 
1444 {
1445  Double_t rwxmin, rwxmax, rwymin, rwymax, maximum, minimum, dx, dy;
1446  Double_t uxmin, uxmax;
1447 
1448  ComputeRange(rwxmin, rwymin, rwxmax, rwymax); //this is redefined in TGraphErrors
1449 
1450  // (if fHistogram exist) && (if the log scale is on) &&
1451  // (if the computed range minimum is > 0) && (if the fHistogram minimum is zero)
1452  // then it means fHistogram limits have been computed in linear scale
1453  // therefore they might be too strict and cut some points. In that case the
1454  // fHistogram limits should be recomputed ie: the existing fHistogram
1455  // should not be returned.
1456  TH1F *historg = 0;
1457  if (fHistogram) {
1458  if (gPad && gPad->GetLogx()) {
1459  if (rwxmin <= 0 || fHistogram->GetXaxis()->GetXmin() != 0) return fHistogram;
1460  } else if (gPad && gPad->GetLogy()) {
1461  if (rwymin <= 0 || fHistogram->GetMinimum() != 0) return fHistogram;
1462  } else {
1463  return fHistogram;
1464  }
1465  historg = fHistogram;
1466  }
1467 
1468  if (rwxmin == rwxmax) rwxmax += 1.;
1469  if (rwymin == rwymax) rwymax += 1.;
1470  dx = 0.1 * (rwxmax - rwxmin);
1471  dy = 0.1 * (rwymax - rwymin);
1472  uxmin = rwxmin - dx;
1473  uxmax = rwxmax + dx;
1474  minimum = rwymin - dy;
1475  maximum = rwymax + dy;
1476 
1477  if (fMinimum != -1111) minimum = fMinimum;
1478  if (fMaximum != -1111) maximum = fMaximum;
1479 
1480  // the graph is created with at least as many channels as there are points
1481  // to permit zooming on the full range
1482  if (uxmin < 0 && rwxmin >= 0) {
1483  if (gPad && gPad->GetLogx()) uxmin = 0.9 * rwxmin;
1484  else uxmin = 0;
1485  }
1486  if (uxmax > 0 && rwxmax <= 0) {
1487  if (gPad && gPad->GetLogx()) uxmax = 1.1 * rwxmax;
1488  else uxmax = 0;
1489  }
1490  if (minimum < 0 && rwymin >= 0) {
1491  if (gPad && gPad->GetLogy()) minimum = 0.9 * rwymin;
1492  else minimum = 0;
1493  }
1494  if (minimum <= 0 && gPad && gPad->GetLogy()) minimum = 0.001 * maximum;
1495  if (uxmin <= 0 && gPad && gPad->GetLogx()) {
1496  if (uxmax > 1000) uxmin = 1;
1497  else uxmin = 0.001 * uxmax;
1498  }
1499 
1500  rwxmin = uxmin;
1501  rwxmax = uxmax;
1502  Int_t npt = 100;
1503  if (fNpoints > npt) npt = fNpoints;
1504  const char *gname = GetName();
1505  if (!gname[0]) gname = "Graph";
1506  ((TGraph*)this)->fHistogram = new TH1F(gname, GetTitle(), npt, rwxmin, rwxmax);
1507  if (!fHistogram) return 0;
1508  fHistogram->SetMinimum(minimum);
1509  fHistogram->SetBit(TH1::kNoStats);
1510  fHistogram->SetMaximum(maximum);
1511  fHistogram->GetYaxis()->SetLimits(minimum, maximum);
1512  fHistogram->SetDirectory(0);
1513  // Restore the axis attributes if needed
1514  if (historg) {
1515  fHistogram->GetXaxis()->SetTitle(historg->GetXaxis()->GetTitle());
1516  fHistogram->GetXaxis()->CenterTitle(historg->GetXaxis()->GetCenterTitle());
1517  fHistogram->GetXaxis()->RotateTitle(historg->GetXaxis()->GetRotateTitle());
1518  fHistogram->GetXaxis()->SetNoExponent(historg->GetXaxis()->GetNoExponent());
1519  fHistogram->GetXaxis()->SetNdivisions(historg->GetXaxis()->GetNdivisions());
1520  fHistogram->GetXaxis()->SetLabelFont(historg->GetXaxis()->GetLabelFont());
1521  fHistogram->GetXaxis()->SetLabelOffset(historg->GetXaxis()->GetLabelOffset());
1522  fHistogram->GetXaxis()->SetLabelSize(historg->GetXaxis()->GetLabelSize());
1523  fHistogram->GetXaxis()->SetTitleSize(historg->GetXaxis()->GetTitleSize());
1524  fHistogram->GetXaxis()->SetTitleOffset(historg->GetXaxis()->GetTitleOffset());
1525  fHistogram->GetXaxis()->SetTitleFont(historg->GetXaxis()->GetTitleFont());
1526  fHistogram->GetXaxis()->SetTimeDisplay(historg->GetXaxis()->GetTimeDisplay());
1527  fHistogram->GetXaxis()->SetTimeFormat(historg->GetXaxis()->GetTimeFormat());
1528 
1529  fHistogram->GetYaxis()->SetTitle(historg->GetYaxis()->GetTitle());
1530  fHistogram->GetYaxis()->CenterTitle(historg->GetYaxis()->GetCenterTitle());
1531  fHistogram->GetYaxis()->RotateTitle(historg->GetYaxis()->GetRotateTitle());
1532  fHistogram->GetYaxis()->SetNoExponent(historg->GetYaxis()->GetNoExponent());
1533  fHistogram->GetYaxis()->SetNdivisions(historg->GetYaxis()->GetNdivisions());
1534  fHistogram->GetYaxis()->SetLabelFont(historg->GetYaxis()->GetLabelFont());
1535  fHistogram->GetYaxis()->SetLabelOffset(historg->GetYaxis()->GetLabelOffset());
1536  fHistogram->GetYaxis()->SetLabelSize(historg->GetYaxis()->GetLabelSize());
1537  fHistogram->GetYaxis()->SetTitleSize(historg->GetYaxis()->GetTitleSize());
1538  fHistogram->GetYaxis()->SetTitleOffset(historg->GetYaxis()->GetTitleOffset());
1539  fHistogram->GetYaxis()->SetTitleFont(historg->GetYaxis()->GetTitleFont());
1540  fHistogram->GetYaxis()->SetTimeDisplay(historg->GetYaxis()->GetTimeDisplay());
1541  fHistogram->GetYaxis()->SetTimeFormat(historg->GetYaxis()->GetTimeFormat());
1542  delete historg;
1543  }
1544  return fHistogram;
1545 }
1546 
1547 ////////////////////////////////////////////////////////////////////////////////
1548 /// Get x and y values for point number i.
1549 /// The function returns -1 in case of an invalid request or the point number otherwise
1550 
1552 {
1553  if (i < 0 || i >= fNpoints) return -1;
1554  if (!fX || !fY) return -1;
1555  x = fX[i];
1556  y = fY[i];
1557  return i;
1558 }
1559 
1560 ////////////////////////////////////////////////////////////////////////////////
1561 /// Get x axis of the graph.
1562 
1564 {
1565  TH1 *h = GetHistogram();
1566  if (!h) return 0;
1567  return h->GetXaxis();
1568 }
1569 
1570 ////////////////////////////////////////////////////////////////////////////////
1571 /// Get y axis of the graph.
1572 
1574 {
1575  TH1 *h = GetHistogram();
1576  if (!h) return 0;
1577  return h->GetYaxis();
1578 }
1579 
1580 ////////////////////////////////////////////////////////////////////////////////
1581 /// Compute Initial values of parameters for a gaussian.
1582 
1584 {
1585  Double_t allcha, sumx, sumx2, x, val, rms, mean;
1586  Int_t bin;
1587  const Double_t sqrtpi = 2.506628;
1588 
1589  // Compute mean value and RMS of the graph in the given range
1590  if (xmax <= xmin) {
1591  xmin = fX[0];
1592  xmax = fX[fNpoints-1];
1593  }
1594  Int_t np = 0;
1595  allcha = sumx = sumx2 = 0;
1596  for (bin = 0; bin < fNpoints; bin++) {
1597  x = fX[bin];
1598  if (x < xmin || x > xmax) continue;
1599  np++;
1600  val = fY[bin];
1601  sumx += val * x;
1602  sumx2 += val * x * x;
1603  allcha += val;
1604  }
1605  if (np == 0 || allcha == 0) return;
1606  mean = sumx / allcha;
1607  rms = TMath::Sqrt(sumx2 / allcha - mean * mean);
1608  Double_t binwidx = TMath::Abs((xmax - xmin) / np);
1609  if (rms == 0) rms = 1;
1611  TF1 *f1 = (TF1*)grFitter->GetUserFunc();
1612  f1->SetParameter(0, binwidx * allcha / (sqrtpi * rms));
1613  f1->SetParameter(1, mean);
1614  f1->SetParameter(2, rms);
1615  f1->SetParLimits(2, 0, 10 * rms);
1616 }
1617 
1618 ////////////////////////////////////////////////////////////////////////////////
1619 /// Compute Initial values of parameters for an exponential.
1620 
1622 {
1623  Double_t constant, slope;
1624  Int_t ifail;
1625  if (xmax <= xmin) {
1626  xmin = fX[0];
1627  xmax = fX[fNpoints-1];
1628  }
1629  Int_t nchanx = fNpoints;
1630 
1631  LeastSquareLinearFit(-nchanx, constant, slope, ifail, xmin, xmax);
1632 
1634  TF1 *f1 = (TF1*)grFitter->GetUserFunc();
1635  f1->SetParameter(0, constant);
1636  f1->SetParameter(1, slope);
1637 }
1638 
1639 ////////////////////////////////////////////////////////////////////////////////
1640 /// Compute Initial values of parameters for a polynom.
1641 
1643 {
1644  Double_t fitpar[25];
1645 
1647  TF1 *f1 = (TF1*)grFitter->GetUserFunc();
1648  Int_t npar = f1->GetNpar();
1649  if (xmax <= xmin) {
1650  xmin = fX[0];
1651  xmax = fX[fNpoints-1];
1652  }
1653 
1654  LeastSquareFit(npar, fitpar, xmin, xmax);
1655 
1656  for (Int_t i = 0; i < npar; i++) f1->SetParameter(i, fitpar[i]);
1657 }
1658 
1659 ////////////////////////////////////////////////////////////////////////////////
1660 /// Insert a new point at the mouse position
1661 
1663 {
1664  Int_t px = gPad->GetEventX();
1665  Int_t py = gPad->GetEventY();
1666 
1667  //localize point where to insert
1668  Int_t ipoint = -2;
1669  Int_t i, d = 0;
1670  // start with a small window (in case the mouse is very close to one point)
1671  for (i = 0; i < fNpoints - 1; i++) {
1672  d = DistancetoLine(px, py, gPad->XtoPad(fX[i]), gPad->YtoPad(fY[i]), gPad->XtoPad(fX[i+1]), gPad->YtoPad(fY[i+1]));
1673  if (d < 5) {
1674  ipoint = i + 1;
1675  break;
1676  }
1677  }
1678  if (ipoint == -2) {
1679  //may be we are far from one point, try again with a larger window
1680  for (i = 0; i < fNpoints - 1; i++) {
1681  d = DistancetoLine(px, py, gPad->XtoPad(fX[i]), gPad->YtoPad(fY[i]), gPad->XtoPad(fX[i+1]), gPad->YtoPad(fY[i+1]));
1682  if (d < 10) {
1683  ipoint = i + 1;
1684  break;
1685  }
1686  }
1687  }
1688  if (ipoint == -2) {
1689  //distinguish between first and last point
1690  Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[0]));
1691  Int_t dpy = py - gPad->YtoAbsPixel(gPad->XtoPad(fY[0]));
1692  if (dpx * dpx + dpy * dpy < 25) ipoint = 0;
1693  else ipoint = fNpoints;
1694  }
1695  Double_t **ps = ExpandAndCopy(fNpoints + 1, ipoint);
1696  CopyAndRelease(ps, ipoint, fNpoints++, ipoint + 1);
1697 
1698  // To avoid redefinitions in descendant classes
1699  FillZero(ipoint, ipoint + 1);
1700 
1701  fX[ipoint] = gPad->PadtoX(gPad->AbsPixeltoX(px));
1702  fY[ipoint] = gPad->PadtoY(gPad->AbsPixeltoY(py));
1703  gPad->Modified();
1704  return ipoint;
1705 }
1706 
1707 ////////////////////////////////////////////////////////////////////////////////
1708 /// Integrate the TGraph data within a given (index) range.
1709 /// Note that this function computes the area of the polygon enclosed by the points of the TGraph.
1710 /// The polygon segments, which are defined by the points of the TGraph, do not need to form a closed polygon,
1711 /// since the last polygon segment, which closes the polygon, is taken as the line connecting the last TGraph point
1712 /// with the first one. It is clear that the order of the point is essential in defining the polygon.
1713 /// Also note that the segments should not intersect.
1714 ///
1715 /// NB:
1716 /// - if last=-1 (default) last is set to the last point.
1717 /// - if (first <0) the first point (0) is taken.
1718 ///
1719 /// ### Method:
1720 ///
1721 /// There are many ways to calculate the surface of a polygon. It all depends on what kind of data
1722 /// you have to deal with. The most evident solution would be to divide the polygon in triangles and
1723 /// calculate the surface of them. But this can quickly become complicated as you will have to test
1724 /// every segments of every triangles and check if they are intersecting with a current polygon's
1725 /// segment or if it goes outside the polygon. Many calculations that would lead to many problems...
1726 ///
1727 /// ### The solution (implemented by R.Brun)
1728 /// Fortunately for us, there is a simple way to solve this problem, as long as the polygon's
1729 /// segments don't intersect.
1730 /// It takes the x coordinate of the current vertex and multiply it by the y coordinate of the next
1731 /// vertex. Then it subtracts from it the result of the y coordinate of the current vertex multiplied
1732 /// by the x coordinate of the next vertex. Then divide the result by 2 to get the surface/area.
1733 ///
1734 /// ### Sources
1735 /// - http://forums.wolfram.com/mathgroup/archive/1998/Mar/msg00462.html
1736 /// - http://stackoverflow.com/questions/451426/how-do-i-calculate-the-surface-area-of-a-2d-polygon
1737 
1739 {
1740  if (first < 0) first = 0;
1741  if (last < 0) last = fNpoints - 1;
1742  if (last >= fNpoints) last = fNpoints - 1;
1743  if (first >= last) return 0;
1744  Int_t np = last - first + 1;
1745  Double_t sum = 0.0;
1746  //for(Int_t i=first;i<=last;i++) {
1747  // Int_t j = first + (i-first+1)%np;
1748  // sum += TMath::Abs(fX[i]*fY[j]);
1749  // sum -= TMath::Abs(fY[i]*fX[j]);
1750  //}
1751  for (Int_t i = first; i <= last; i++) {
1752  Int_t j = first + (i - first + 1) % np;
1753  sum += (fY[i] + fY[j]) * (fX[j] - fX[i]);
1754  }
1755  return 0.5 * TMath::Abs(sum);
1756 }
1757 
1758 ////////////////////////////////////////////////////////////////////////////////
1759 /// Return 1 if the point (x,y) is inside the polygon defined by
1760 /// the graph vertices 0 otherwise.
1761 ///
1762 /// Algorithm:
1763 ///
1764 /// The loop is executed with the end-point coordinates of a line segment
1765 /// (X1,Y1)-(X2,Y2) and the Y-coordinate of a horizontal line.
1766 /// The counter inter is incremented if the line (X1,Y1)-(X2,Y2) intersects
1767 /// the horizontal line. In this case XINT is set to the X-coordinate of the
1768 /// intersection point. If inter is an odd number, then the point x,y is within
1769 /// the polygon.
1770 
1772 {
1773  return (Int_t)TMath::IsInside(x, y, fNpoints, fX, fY);
1774 }
1775 
1776 ////////////////////////////////////////////////////////////////////////////////
1777 /// Least squares polynomial fitting without weights.
1778 ///
1779 /// \param [in] m number of parameters
1780 /// \param [in] ma array of parameters
1781 /// \param [in] mfirst 1st point number to fit (default =0)
1782 /// \param [in] mlast last point number to fit (default=fNpoints-1)
1783 ///
1784 /// based on CERNLIB routine LSQ: Translated to C++ by Rene Brun
1785 
1787 {
1788  const Double_t zero = 0.;
1789  const Double_t one = 1.;
1790  const Int_t idim = 20;
1791 
1792  Double_t b[400] /* was [20][20] */;
1793  Int_t i, k, l, ifail;
1794  Double_t power;
1795  Double_t da[20], xk, yk;
1796  Int_t n = fNpoints;
1797  if (xmax <= xmin) {
1798  xmin = fX[0];
1799  xmax = fX[fNpoints-1];
1800  }
1801 
1802  if (m <= 2) {
1803  LeastSquareLinearFit(n, a[0], a[1], ifail, xmin, xmax);
1804  return;
1805  }
1806  if (m > idim || m > n) return;
1807  da[0] = zero;
1808  for (l = 2; l <= m; ++l) {
1809  b[l-1] = zero;
1810  b[m + l*20 - 21] = zero;
1811  da[l-1] = zero;
1812  }
1813  Int_t np = 0;
1814  for (k = 0; k < fNpoints; ++k) {
1815  xk = fX[k];
1816  if (xk < xmin || xk > xmax) continue;
1817  np++;
1818  yk = fY[k];
1819  power = one;
1820  da[0] += yk;
1821  for (l = 2; l <= m; ++l) {
1822  power *= xk;
1823  b[l-1] += power;
1824  da[l-1] += power * yk;
1825  }
1826  for (l = 2; l <= m; ++l) {
1827  power *= xk;
1828  b[m + l*20 - 21] += power;
1829  }
1830  }
1831  b[0] = Double_t(np);
1832  for (i = 3; i <= m; ++i) {
1833  for (k = i; k <= m; ++k) {
1834  b[k - 1 + (i-1)*20 - 21] = b[k + (i-2)*20 - 21];
1835  }
1836  }
1837  H1LeastSquareSeqnd(m, b, idim, ifail, 1, da);
1838 
1839  if (ifail < 0) {
1840  a[0] = fY[0];
1841  for (i = 1; i < m; ++i) a[i] = 0;
1842  return;
1843  }
1844  for (i = 0; i < m; ++i) a[i] = da[i];
1845 }
1846 
1847 ////////////////////////////////////////////////////////////////////////////////
1848 /// Least square linear fit without weights.
1849 ///
1850 /// Fit a straight line (a0 + a1*x) to the data in this graph.
1851 ///
1852 /// \param [in] ndata if ndata<0, fits the logarithm of the graph (used in InitExpo() to set
1853 /// the initial parameter values for a fit with exponential function.
1854 /// \param [in] a0 constant
1855 /// \param [in] a1 slope
1856 /// \param [in] ifail return parameter indicating the status of the fit (ifail=0, fit is OK)
1857 /// \param [in] xmin, xmax fitting range
1858 ///
1859 /// extracted from CERNLIB LLSQ: Translated to C++ by Rene Brun
1860 
1862 {
1863  Double_t xbar, ybar, x2bar;
1864  Int_t i;
1865  Double_t xybar;
1866  Double_t fn, xk, yk;
1867  Double_t det;
1868  if (xmax <= xmin) {
1869  xmin = fX[0];
1870  xmax = fX[fNpoints-1];
1871  }
1872 
1873  ifail = -2;
1874  xbar = ybar = x2bar = xybar = 0;
1875  Int_t np = 0;
1876  for (i = 0; i < fNpoints; ++i) {
1877  xk = fX[i];
1878  if (xk < xmin || xk > xmax) continue;
1879  np++;
1880  yk = fY[i];
1881  if (ndata < 0) {
1882  if (yk <= 0) yk = 1e-9;
1883  yk = TMath::Log(yk);
1884  }
1885  xbar += xk;
1886  ybar += yk;
1887  x2bar += xk * xk;
1888  xybar += xk * yk;
1889  }
1890  fn = Double_t(np);
1891  det = fn * x2bar - xbar * xbar;
1892  ifail = -1;
1893  if (det <= 0) {
1894  if (fn > 0) a0 = ybar / fn;
1895  else a0 = 0;
1896  a1 = 0;
1897  return;
1898  }
1899  ifail = 0;
1900  a0 = (x2bar * ybar - xbar * xybar) / det;
1901  a1 = (fn * xybar - xbar * ybar) / det;
1902 }
1903 
1904 ////////////////////////////////////////////////////////////////////////////////
1905 /// Draw this graph with its current attributes.
1906 
1908 {
1910  if (painter) painter->PaintHelper(this, option);
1911 }
1912 
1913 ////////////////////////////////////////////////////////////////////////////////
1914 /// Draw the (x,y) as a graph.
1915 
1916 void TGraph::PaintGraph(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)
1917 {
1919  if (painter) painter->PaintGraph(this, npoints, x, y, chopt);
1920 }
1921 
1922 ////////////////////////////////////////////////////////////////////////////////
1923 /// Draw the (x,y) as a histogram.
1924 
1925 void TGraph::PaintGrapHist(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)
1926 {
1928  if (painter) painter->PaintGrapHist(this, npoints, x, y, chopt);
1929 }
1930 
1931 ////////////////////////////////////////////////////////////////////////////////
1932 /// Draw the stats
1933 
1935 {
1937  if (painter) painter->PaintStats(this, fit);
1938 }
1939 
1940 ////////////////////////////////////////////////////////////////////////////////
1941 /// Print graph values.
1942 
1944 {
1945  for (Int_t i = 0; i < fNpoints; i++) {
1946  printf("x[%d]=%g, y[%d]=%g\n", i, fX[i], i, fY[i]);
1947  }
1948 }
1949 
1950 ////////////////////////////////////////////////////////////////////////////////
1951 /// Recursively remove object from the list of functions
1952 
1954 {
1955  if (fFunctions) {
1956  if (!fFunctions->TestBit(kInvalidObject)) fFunctions->RecursiveRemove(obj);
1957  }
1958  if (fHistogram == obj) fHistogram = 0;
1959 }
1960 
1961 ////////////////////////////////////////////////////////////////////////////////
1962 /// Delete point close to the mouse position
1963 
1965 {
1966  Int_t px = gPad->GetEventX();
1967  Int_t py = gPad->GetEventY();
1968 
1969  //localize point to be deleted
1970  Int_t ipoint = -2;
1971  Int_t i;
1972  // start with a small window (in case the mouse is very close to one point)
1973  for (i = 0; i < fNpoints; i++) {
1974  Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
1975  Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
1976  if (dpx * dpx + dpy * dpy < 100) {
1977  ipoint = i;
1978  break;
1979  }
1980  }
1981  return RemovePoint(ipoint);
1982 }
1983 
1984 ////////////////////////////////////////////////////////////////////////////////
1985 /// Delete point number ipoint
1986 
1988 {
1989  if (ipoint < 0) return -1;
1990  if (ipoint >= fNpoints) return -1;
1991 
1992  Double_t **ps = ShrinkAndCopy(fNpoints - 1, ipoint);
1993  CopyAndRelease(ps, ipoint + 1, fNpoints--, ipoint);
1994  if (gPad) gPad->Modified();
1995  return ipoint;
1996 }
1997 
1998 ////////////////////////////////////////////////////////////////////////////////
1999 /// Save primitive as a C++ statement(s) on output stream out
2000 
2001 void TGraph::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2002 {
2003  char quote = '"';
2004  out << " " << std::endl;
2005  static Int_t frameNumber = 0;
2006  frameNumber++;
2007 
2008  if (fNpoints >= 1) {
2009  Int_t i;
2010  TString fXName = TString(GetName()) + Form("_fx%d",frameNumber);
2011  TString fYName = TString(GetName()) + Form("_fy%d",frameNumber);
2012  out << " Double_t " << fXName << "[" << fNpoints << "] = {" << std::endl;
2013  for (i = 0; i < fNpoints-1; i++) out << " " << fX[i] << "," << std::endl;
2014  out << " " << fX[fNpoints-1] << "};" << std::endl;
2015  out << " Double_t " << fYName << "[" << fNpoints << "] = {" << std::endl;
2016  for (i = 0; i < fNpoints-1; i++) out << " " << fY[i] << "," << std::endl;
2017  out << " " << fY[fNpoints-1] << "};" << std::endl;
2018  if (gROOT->ClassSaved(TGraph::Class())) out << " ";
2019  else out << " TGraph *";
2020  out << "graph = new TGraph(" << fNpoints << "," << fXName << "," << fYName << ");" << std::endl;
2021  } else {
2022  if (gROOT->ClassSaved(TGraph::Class())) out << " ";
2023  else out << " TGraph *";
2024  out << "graph = new TGraph();" << std::endl;
2025  }
2026 
2027  out << " graph->SetName(" << quote << GetName() << quote << ");" << std::endl;
2028  out << " graph->SetTitle(" << quote << GetTitle() << quote << ");" << std::endl;
2029 
2030  SaveFillAttributes(out, "graph", 0, 1001);
2031  SaveLineAttributes(out, "graph", 1, 1, 1);
2032  SaveMarkerAttributes(out, "graph", 1, 1, 1);
2033 
2034  if (fHistogram) {
2035  TString hname = fHistogram->GetName();
2036  hname += frameNumber;
2037  fHistogram->SetName(Form("Graph_%s", hname.Data()));
2038  fHistogram->SavePrimitive(out, "nodraw");
2039  out << " graph->SetHistogram(" << fHistogram->GetName() << ");" << std::endl;
2040  out << " " << std::endl;
2041  }
2042 
2043  // save list of functions
2044  TIter next(fFunctions);
2045  TObject *obj;
2046  while ((obj = next())) {
2047  obj->SavePrimitive(out, Form("nodraw #%d\n",++frameNumber));
2048  if (obj->InheritsFrom("TPaveStats")) {
2049  out << " graph->GetListOfFunctions()->Add(ptstats);" << std::endl;
2050  out << " ptstats->SetParent(graph->GetListOfFunctions());" << std::endl;
2051  } else {
2052  out << " graph->GetListOfFunctions()->Add("
2053  << Form("%s%d",obj->GetName(),frameNumber) << ");" << std::endl;
2054  }
2055  }
2056 
2057  const char *l;
2058  l = strstr(option, "multigraph");
2059  if (l) {
2060  out << " multigraph->Add(graph," << quote << l + 10 << quote << ");" << std::endl;
2061  return;
2062  }
2063  l = strstr(option, "th2poly");
2064  if (l) {
2065  out << " " << l + 7 << "->AddBin(graph);" << std::endl;
2066  return;
2067  }
2068  out << " graph->Draw(" << quote << option << quote << ");" << std::endl;
2069 }
2070 
2071 ////////////////////////////////////////////////////////////////////////////////
2072 /// Set number of points in the graph
2073 /// Existing coordinates are preserved
2074 /// New coordinates above fNpoints are preset to 0.
2075 
2077 {
2078  if (n < 0) n = 0;
2079  if (n == fNpoints) return;
2080  Double_t **ps = Allocate(n);
2081  CopyAndRelease(ps, 0, TMath::Min(fNpoints, n), 0);
2082  if (n > fNpoints) {
2083  FillZero(fNpoints, n, kFALSE);
2084  }
2085  fNpoints = n;
2086 }
2087 
2088 ////////////////////////////////////////////////////////////////////////////////
2089 /// Return kTRUE if kNotEditable bit is not set, kFALSE otherwise.
2090 
2092 {
2093  return TestBit(kNotEditable) ? kFALSE : kTRUE;
2094 }
2095 
2096 ////////////////////////////////////////////////////////////////////////////////
2097 /// if editable=kFALSE, the graph cannot be modified with the mouse
2098 /// by default a TGraph is editable
2099 
2101 {
2102  if (editable) ResetBit(kNotEditable);
2103  else SetBit(kNotEditable);
2104 }
2105 
2106 ////////////////////////////////////////////////////////////////////////////////
2107 /// Set the maximum of the graph.
2108 
2110 {
2111  fMaximum = maximum;
2112  GetHistogram()->SetMaximum(maximum);
2113 }
2114 
2115 ////////////////////////////////////////////////////////////////////////////////
2116 /// Set the minimum of the graph.
2117 
2119 {
2120  fMinimum = minimum;
2121  GetHistogram()->SetMinimum(minimum);
2122 }
2123 
2124 ////////////////////////////////////////////////////////////////////////////////
2125 /// Set x and y values for point number i.
2126 
2128 {
2129  if (i < 0) return;
2130  if (fHistogram) {
2131  delete fHistogram;
2132  fHistogram = 0;
2133  }
2134  if (i >= fMaxSize) {
2135  Double_t **ps = ExpandAndCopy(i + 1, fNpoints);
2136  CopyAndRelease(ps, 0, 0, 0);
2137  }
2138  if (i >= fNpoints) {
2139  // points above i can be not initialized
2140  // set zero up to i-th point to avoid redefinition
2141  // of this method in descendant classes
2142  FillZero(fNpoints, i + 1);
2143  fNpoints = i + 1;
2144  }
2145  fX[i] = x;
2146  fY[i] = y;
2147  if (gPad) gPad->Modified();
2148 }
2149 
2150 ////////////////////////////////////////////////////////////////////////////////
2151 /// Set graph title.
2152 
2153 void TGraph::SetTitle(const char* title)
2154 {
2155  fTitle = title;
2156  if (fHistogram) fHistogram->SetTitle(title);
2157 }
2158 
2159 ////////////////////////////////////////////////////////////////////////////////
2160 /// if size*2 <= fMaxSize allocate new arrays of size points,
2161 /// copy points [0,oend).
2162 /// Return newarray (passed or new instance if it was zero
2163 /// and allocations are needed)
2164 
2166 {
2167  if (size * 2 > fMaxSize || !fMaxSize) {
2168  return 0;
2169  }
2170  Double_t **newarrays = Allocate(size);
2171  CopyPoints(newarrays, 0, oend, 0);
2172  return newarrays;
2173 }
2174 
2175 ////////////////////////////////////////////////////////////////////////////////
2176 /// Sorts the points of this TGraph using in-place quicksort (see e.g. older glibc).
2177 /// To compare two points the function parameter greaterfunc is used (see TGraph::CompareX for an
2178 /// example of such a method, which is also the default comparison function for Sort). After
2179 /// the sort, greaterfunc(this, i, j) will return kTRUE for all i>j if ascending == kTRUE, and
2180 /// kFALSE otherwise.
2181 ///
2182 /// The last two parameters are used for the recursive quick sort, stating the range to be sorted
2183 ///
2184 /// Examples:
2185 /// ~~~ {.cpp}
2186 /// // sort points along x axis
2187 /// graph->Sort();
2188 /// // sort points along their distance to origin
2189 /// graph->Sort(&TGraph::CompareRadius);
2190 ///
2191 /// Bool_t CompareErrors(const TGraph* gr, Int_t i, Int_t j) {
2192 /// const TGraphErrors* ge=(const TGraphErrors*)gr;
2193 /// return (ge->GetEY()[i]>ge->GetEY()[j]); }
2194 /// // sort using the above comparison function, largest errors first
2195 /// graph->Sort(&CompareErrors, kFALSE);
2196 /// ~~~
2197 
2198 void TGraph::Sort(Bool_t (*greaterfunc)(const TGraph*, Int_t, Int_t) /*=TGraph::CompareX()*/,
2199  Bool_t ascending /*=kTRUE*/, Int_t low /* =0 */, Int_t high /* =-1111 */)
2200 {
2201  if (high == -1111) high = GetN() - 1;
2202  // Termination condition
2203  if (high <= low) return;
2204 
2205  int left, right;
2206  left = low; // low is the pivot element
2207  right = high;
2208  while (left < right) {
2209  // move left while item < pivot
2210  while (left <= high && greaterfunc(this, left, low) != ascending)
2211  left++;
2212  // move right while item > pivot
2213  while (right > low && greaterfunc(this, right, low) == ascending)
2214  right--;
2215  if (left < right && left < high && right > low)
2216  SwapPoints(left, right);
2217  }
2218  // right is final position for the pivot
2219  if (right > low)
2220  SwapPoints(low, right);
2221  Sort(greaterfunc, ascending, low, right - 1);
2222  Sort(greaterfunc, ascending, right + 1, high);
2223 }
2224 
2225 ////////////////////////////////////////////////////////////////////////////////
2226 /// Stream an object of class TGraph.
2227 
2228 void TGraph::Streamer(TBuffer &b)
2229 {
2230  if (b.IsReading()) {
2231  UInt_t R__s, R__c;
2232  Version_t R__v = b.ReadVersion(&R__s, &R__c);
2233  if (R__v > 2) {
2234  b.ReadClassBuffer(TGraph::Class(), this, R__v, R__s, R__c);
2235  if (fHistogram) fHistogram->SetDirectory(0);
2236  TIter next(fFunctions);
2237  TObject *obj;
2238  while ((obj = next())) {
2239  if (obj->InheritsFrom(TF1::Class())) {
2240  TF1 *f1 = (TF1*)obj;
2241  f1->SetParent(this);
2242  }
2243  }
2244  fMaxSize = fNpoints;
2245  return;
2246  }
2247  //====process old versions before automatic schema evolution
2248  TNamed::Streamer(b);
2249  TAttLine::Streamer(b);
2250  TAttFill::Streamer(b);
2251  TAttMarker::Streamer(b);
2252  b >> fNpoints;
2253  fMaxSize = fNpoints;
2254  fX = new Double_t[fNpoints];
2255  fY = new Double_t[fNpoints];
2256  if (R__v < 2) {
2257  Float_t *x = new Float_t[fNpoints];
2258  Float_t *y = new Float_t[fNpoints];
2259  b.ReadFastArray(x, fNpoints);
2260  b.ReadFastArray(y, fNpoints);
2261  for (Int_t i = 0; i < fNpoints; i++) {
2262  fX[i] = x[i];
2263  fY[i] = y[i];
2264  }
2265  delete [] y;
2266  delete [] x;
2267  } else {
2268  b.ReadFastArray(fX, fNpoints);
2269  b.ReadFastArray(fY, fNpoints);
2270  }
2271  b >> fFunctions;
2272  b >> fHistogram;
2273  if (fHistogram) fHistogram->SetDirectory(0);
2274  if (R__v < 2) {
2275  Float_t mi, ma;
2276  b >> mi;
2277  b >> ma;
2278  fMinimum = mi;
2279  fMaximum = ma;
2280  } else {
2281  b >> fMinimum;
2282  b >> fMaximum;
2283  }
2284  b.CheckByteCount(R__s, R__c, TGraph::IsA());
2285  //====end of old versions
2286 
2287  } else {
2288  b.WriteClassBuffer(TGraph::Class(), this);
2289  }
2290 }
2291 
2292 ////////////////////////////////////////////////////////////////////////////////
2293 /// Swap points.
2294 
2296 {
2297  SwapValues(fX, pos1, pos2);
2298  SwapValues(fY, pos1, pos2);
2299 }
2300 
2301 ////////////////////////////////////////////////////////////////////////////////
2302 /// Swap values.
2303 
2304 void TGraph::SwapValues(Double_t* arr, Int_t pos1, Int_t pos2)
2305 {
2306  Double_t tmp = arr[pos1];
2307  arr[pos1] = arr[pos2];
2308  arr[pos2] = tmp;
2309 }
2310 
2311 ////////////////////////////////////////////////////////////////////////////////
2312 /// Set current style settings in this graph
2313 /// This function is called when either TCanvas::UseCurrentStyle
2314 /// or TROOT::ForceStyle have been invoked.
2315 
2317 {
2318  if (gStyle->IsReading()) {
2327  } else {
2336  }
2337  if (fHistogram) fHistogram->UseCurrentStyle();
2338 
2340  TObject *obj;
2341 
2342  while ((obj = next())) {
2343  obj->UseCurrentStyle();
2344  }
2345 }
2346 
2347 ////////////////////////////////////////////////////////////////////////////////
2348 /// Adds all graphs from the collection to this graph.
2349 /// Returns the total number of poins in the result or -1 in case of an error.
2350 
2352 {
2353  TIter next(li);
2354  while (TObject* o = next()) {
2355  TGraph *g = dynamic_cast<TGraph*>(o);
2356  if (!g) {
2357  Error("Merge",
2358  "Cannot merge - an object which doesn't inherit from TGraph found in the list");
2359  return -1;
2360  }
2361  DoMerge(g);
2362  }
2363  return GetN();
2364 }
2365 ////////////////////////////////////////////////////////////////////////////////
2366 /// protected function to perform the merge operation of a graph
2367 
2369 {
2370  Double_t x, y;
2371  for (Int_t i = 0 ; i < g->GetN(); i++) {
2372  g->GetPoint(i, x, y);
2373  SetPoint(GetN(), x, y);
2374  }
2375  return kTRUE;
2376 }
2377 ////////////////////////////////////////////////////////////////////////////////
2378 /// Find zero of a continuous function.
2379 /// This function finds a real zero of the continuous real
2380 /// function Y(X) in a given interval (A,B). See accompanying
2381 /// notes for details of the argument list and calling sequence
2382 
2384  , Int_t maxiterations)
2385 {
2386  static Double_t a, b, ya, ytest, y1, x1, h;
2387  static Int_t j1, it, j3, j2;
2388  Double_t yb, x2;
2389  yb = 0;
2390 
2391  // Calculate Y(X) at X=AZ.
2392  if (k <= 0) {
2393  a = AZ;
2394  b = BZ;
2395  X = a;
2396  j1 = 1;
2397  it = 1;
2398  k = j1;
2399  return;
2400  }
2401 
2402  // Test whether Y(X) is sufficiently small.
2403 
2404  if (TMath::Abs(Y) <= E2) {
2405  k = 2;
2406  return;
2407  }
2408 
2409  // Calculate Y(X) at X=BZ.
2410 
2411  if (j1 == 1) {
2412  ya = Y;
2413  X = b;
2414  j1 = 2;
2415  return;
2416  }
2417  // Test whether the signs of Y(AZ) and Y(BZ) are different.
2418  // if not, begin the binary subdivision.
2419 
2420  if (j1 != 2) goto L100;
2421  if (ya * Y < 0) goto L120;
2422  x1 = a;
2423  y1 = ya;
2424  j1 = 3;
2425  h = b - a;
2426  j2 = 1;
2427  x2 = a + 0.5 * h;
2428  j3 = 1;
2429  it++; //*-*- Check whether (maxiterations) function values have been calculated.
2430  if (it >= maxiterations) k = j1;
2431  else X = x2;
2432  return;
2433 
2434  // Test whether a bracket has been found .
2435  // If not,continue the search
2436 
2437 L100:
2438  if (j1 > 3) goto L170;
2439  if (ya*Y >= 0) {
2440  if (j3 >= j2) {
2441  h = 0.5 * h;
2442  j2 = 2 * j2;
2443  a = x1;
2444  ya = y1;
2445  x2 = a + 0.5 * h;
2446  j3 = 1;
2447  } else {
2448  a = X;
2449  ya = Y;
2450  x2 = X + h;
2451  j3++;
2452  }
2453  it++;
2454  if (it >= maxiterations) k = j1;
2455  else X = x2;
2456  return;
2457  }
2458 
2459  // The first bracket has been found.calculate the next X by the
2460  // secant method based on the bracket.
2461 
2462 L120:
2463  b = X;
2464  yb = Y;
2465  j1 = 4;
2466 L130:
2467  if (TMath::Abs(ya) > TMath::Abs(yb)) {
2468  x1 = a;
2469  y1 = ya;
2470  X = b;
2471  Y = yb;
2472  } else {
2473  x1 = b;
2474  y1 = yb;
2475  X = a;
2476  Y = ya;
2477  }
2478 
2479  // Use the secant method based on the function values y1 and Y.
2480  // check that x2 is inside the interval (a,b).
2481 
2482 L150:
2483  x2 = X - Y * (X - x1) / (Y - y1);
2484  x1 = X;
2485  y1 = Y;
2486  ytest = 0.5 * TMath::Min(TMath::Abs(ya), TMath::Abs(yb));
2487  if ((x2 - a)*(x2 - b) < 0) {
2488  it++;
2489  if (it >= maxiterations) k = j1;
2490  else X = x2;
2491  return;
2492  }
2493 
2494  // Calculate the next value of X by bisection . Check whether
2495  // the maximum accuracy has been achieved.
2496 
2497 L160:
2498  x2 = 0.5 * (a + b);
2499  ytest = 0;
2500  if ((x2 - a)*(x2 - b) >= 0) {
2501  k = 2;
2502  return;
2503  }
2504  it++;
2505  if (it >= maxiterations) k = j1;
2506  else X = x2;
2507  return;
2508 
2509 
2510  // Revise the bracket (a,b).
2511 
2512 L170:
2513  if (j1 != 4) return;
2514  if (ya * Y < 0) {
2515  b = X;
2516  yb = Y;
2517  } else {
2518  a = X;
2519  ya = Y;
2520  }
2521 
2522  // Use ytest to decide the method for the next value of X.
2523 
2524  if (ytest <= 0) goto L130;
2525  if (TMath::Abs(Y) - ytest <= 0) goto L150;
2526  goto L160;
2527 }
const int ndata
TString fTitle
Definition: TNamed.h:37
virtual Double_t GetErrorX(Int_t bin) const
This function is called by GraphFitChisquare.
Definition: TGraph.cxx:1371
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0)
Fit this graph with function with name fname.
Definition: TGraph.cxx:1024
virtual TObject * FindObject(const char *name) const
Search object named name in the list of functions.
Definition: TGraph.cxx:997
void PaintGrapHist(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)
Draw the (x,y) as a histogram.
Definition: TGraph.cxx:1925
Int_t fNpoints
Current dimension of arrays fX and fY.
Definition: TGraph.h:58
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual void PaintHelper(TGraph *theGraph, Option_t *option)=0
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
Definition: TAttMarker.cxx:191
virtual Style_t GetLineStyle() const
Definition: TAttLine.h:48
virtual Style_t GetFillStyle() const
Definition: TAttFill.h:44
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
Abstract interface to a histogram painter.
float xmin
Definition: THbookFile.cxx:93
Double_t * fX
Definition: TGraph.h:59
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void FitPanel()
Display a GUI panel with all graph fit options.
Definition: TGraph.cxx:1283
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4629
virtual Double_t GetErrorYhigh(Int_t bin) const
This function is called by GraphFitChisquare.
Definition: TGraph.cxx:1410
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:394
static Bool_t CompareRadius(const TGraph *gr, Int_t left, Int_t right)
Return kTRUE if point number "left"'s distance to origin is bigger than that of point number "right"...
Definition: TGraph.cxx:631
Bool_t IsReading() const
Definition: TBuffer.h:81
Double_t Log(Double_t x)
Definition: TMath.h:526
Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TBrowser.h:108
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
virtual Double_t ** Allocate(Int_t newsize)
Definition: TGraph.h:191
short Version_t
Definition: RtypesCore.h:61
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
void PaintGraph(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)
Draw the (x,y) as a graph.
Definition: TGraph.cxx:1916
Ssiz_t Length() const
Definition: TString.h:390
TLine * line
float Float_t
Definition: RtypesCore.h:53
virtual void DrawPanelHelper(TGraph *theGraph)=0
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8266
Style_t GetHistLineStyle() const
Definition: TStyle.h:244
const char Option_t
Definition: RtypesCore.h:62
float ymin
Definition: THbookFile.cxx:93
virtual void InitPolynom(Double_t xmin=0, Double_t xmax=0)
Compute Initial values of parameters for a polynom.
Definition: TGraph.cxx:1642
double Axis_t
Definition: RtypesCore.h:72
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
#define assert(cond)
Definition: unittest.h:542
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum of the graph.
Definition: TGraph.cxx:2118
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
void SetHistLineWidth(Width_t width=1)
Definition: TStyle.h:378
virtual Int_t GetDimension() const
Definition: TH1.h:283
virtual Int_t IsInside(Double_t x, Double_t y) const
Return 1 if the point (x,y) is inside the polygon defined by the graph vertices 0 otherwise...
Definition: TGraph.cxx:1771
Int_t GetNrows() const
Definition: TVectorT.h:81
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
TH1 * h
Definition: legend2.C:5
static Bool_t CompareX(const TGraph *gr, Int_t left, Int_t right)
Return kTRUE if fX[left] > fX[right]. Can be used by Sort.
Definition: TGraph.cxx:614
Base class for spline implementation containing the Draw/Paint methods //.
Definition: TSpline.h:22
Double_t Atof() const
Return floating-point value contained in string.
Definition: TString.cxx:2030
void H1LeastSquareSeqnd(Int_t n, Double_t *a, Int_t idim, Int_t &ifail, Int_t k, Double_t *b)
Extracted from CERN Program library routine DSEQN.
Definition: TH1.cxx:4450
virtual Bool_t GetTimeDisplay() const
Definition: TAxis.h:130
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition: TAttLine.cxx:159
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1101
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
THist< 1, float > TH1F
Definition: THist.h:315
static const char * filename()
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
#define gROOT
Definition: TROOT.h:340
Int_t LoadPlugin()
Load the plugin library for this handler.
Basic string class.
Definition: TString.h:137
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
virtual TObject * GetUserFunc() const
virtual void DrawPanel()
Display a panel with all graph drawing options.
Definition: TGraph.cxx:834
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition: TAttFill.cxx:197
virtual void LeastSquareFit(Int_t m, Double_t *a, Double_t xmin=0, Double_t xmax=0)
Least squares polynomial fitting without weights.
Definition: TGraph.cxx:1786
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1088
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
TList * fFunctions
Definition: TGraph.h:61
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
virtual void SetTitle(const char *title="")
Set graph title.
Definition: TGraph.cxx:2153
virtual Style_t GetTitleFont() const
Definition: TAttAxis.h:60
virtual void UseCurrentStyle()
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyl...
Definition: TObject.cxx:753
virtual Double_t Chisquare(TF1 *f1, Option_t *option="") const
Return the chisquare of this graph with respect to f1.
Definition: TGraph.cxx:586
TH1F * GetHistogram() const
Returns a pointer to the histogram used to draw the axis Takes into account the two following cases...
Definition: TGraph.cxx:1443
TH1F * fHistogram
Definition: TGraph.h:62
static std::string format(double x, double y, int digits, int width)
virtual void RecursiveRemove(TObject *obj)
Recursively remove object from the list of functions.
Definition: TGraph.cxx:1953
Style_t GetHistFillStyle() const
Definition: TStyle.h:243
Int_t GetN() const
Definition: TGraph.h:132
Long_t ExecPlugin(int nargs, const T &...params)
virtual Float_t GetTitleSize() const
Definition: TAttAxis.h:57
virtual Double_t GetXmin() const
Definition: TF1.h:388
virtual void Apply(TF1 *f)
Apply function f to all the data points f may be a 1-D function TF1 or 2-d function TF2 The Y values ...
Definition: TGraph.cxx:545
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:740
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:625
virtual Double_t GetErrorXhigh(Int_t bin) const
This function is called by GraphFitChisquare.
Definition: TGraph.cxx:1390
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:164
virtual Int_t Merge(TCollection *list)
Adds all graphs from the collection to this graph.
Definition: TGraph.cxx:2351
virtual TObject * Clone(const char *newname="") const
Make a clone of an collection using the Streamer facility.
const char * Data() const
Definition: TString.h:349
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:688
Double_t ** ShrinkAndCopy(Int_t size, Int_t iend)
if size*2 <= fMaxSize allocate new arrays of size points, copy points [0,oend).
Definition: TGraph.cxx:2165
virtual void SetParent(TObject *p=0)
Definition: TF1.h:458
static const double x2[5]
Double_t x[n]
Definition: legend1.C:17
virtual void Paint(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:1907
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
void Class()
Definition: Class.C:29
TGraph & operator=(const TGraph &)
Equal operator for this graph.
Definition: TGraph.cxx:180
void SetHistFillColor(Color_t color=1)
Definition: TStyle.h:374
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:257
virtual void Sort(Bool_t(*greater)(const TGraph *, Int_t, Int_t)=&TGraph::CompareX, Bool_t ascending=kTRUE, Int_t low=0, Int_t high=-1111)
Sorts the points of this TGraph using in-place quicksort (see e.g.
Definition: TGraph.cxx:2198
TList * GetListOfFunctions() const
Definition: TGraph.h:126
Double_t Eval(Double_t x) const
Eval this spline at x.
Definition: TSpline.cxx:818
virtual void SetMaximum(Double_t maximum=-1111)
Set the maximum of the graph.
Definition: TGraph.cxx:2109
void Zero(Int_t &k, Double_t AZ, Double_t BZ, Double_t E2, Double_t &X, Double_t &Y, Int_t maxiterations)
Find zero of a continuous function.
Definition: TGraph.cxx:2383
Double_t fMinimum
Definition: TGraph.h:63
Double_t GetMinimum() const
Definition: TGraph.h:152
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
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:640
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition: TMath.h:1002
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1964
Double_t ATan2(Double_t, Double_t)
Definition: TMath.h:454
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:226
Bool_t IsInside(T xp, T yp, Int_t np, T *x, T *y)
Definition: TMath.h:1056
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual Int_t RemovePoint()
Delete point close to the mouse position.
Definition: TGraph.cxx:1964
Double_t GetXmin() const
Definition: TAxis.h:137
virtual Double_t GetXmax() const
Definition: TF1.h:389
virtual Float_t GetTitleOffset() const
Definition: TAttAxis.h:56
char * out
Definition: TBase64.cxx:29
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TGraph.cxx:940
A doubly linked list.
Definition: TList.h:47
virtual void Expand(Int_t newsize)
If array sizes <= newsize, expand storage to 2*newsize.
Definition: TGraph.cxx:949
Bool_t CtorAllocate()
In constructors set fNpoints than call this method.
Definition: TGraph.cxx:714
virtual const char * GetTimeFormat() const
Definition: TAxis.h:131
virtual Double_t GetErrorXlow(Int_t bin) const
This function is called by GraphFitChisquare.
Definition: TGraph.cxx:1400
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
Bool_t IsReading() const
Definition: TStyle.h:296
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TGraph.cxx:2001
virtual Size_t GetMarkerSize() const
Definition: TAttMarker.h:46
float ymax
Definition: THbookFile.cxx:93
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
Set limits for parameter ipar.
Definition: TF1.cxx:3206
Color_t GetHistFillColor() const
Definition: TStyle.h:241
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:40
Width_t GetHistLineWidth() const
Definition: TStyle.h:245
virtual void SwapPoints(Int_t pos1, Int_t pos2)
Swap points.
Definition: TGraph.cxx:2295
TAxis * GetXaxis() const
Get x axis of the graph.
Definition: TGraph.cxx:1563
void SetHistFillStyle(Style_t styl=0)
Definition: TStyle.h:376
Class to manage histogram axis.
Definition: TAxis.h:36
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
Definition: TFitResultPtr.h:33
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
Swap values.
Definition: TGraph.cxx:2304
virtual Int_t DistancetoPrimitiveHelper(TGraph *theGraph, Int_t px, Int_t py)=0
virtual Color_t GetFillColor() const
Definition: TAttFill.h:43
Collection abstract base class.
Definition: TCollection.h:48
TClass * IsA() const
virtual Bool_t DoMerge(const TGraph *g)
protected function to perform the merge operation of a graph
Definition: TGraph.cxx:2368
TF1 * GetFunction(const char *name) const
Return pointer to function with name.
Definition: TGraph.cxx:1431
unsigned int UInt_t
Definition: RtypesCore.h:42
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:229
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
TMarker * m
Definition: textangle.C:8
virtual Double_t GetRMS(Int_t axis=1) const
Return RMS of X (axis=1) or Y (axis=2)
Definition: TGraph.cxx:1348
char * Form(const char *fmt,...)
virtual Int_t InsertPoint()
Insert a new point at the mouse position.
Definition: TGraph.cxx:1662
static TVirtualFitter * GetFitter()
static: return the current Fitter
TLine * l
Definition: textangle.C:4
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
virtual Double_t Eval(Double_t x) const =0
double Chisquare(const TH1 &h1, TF1 &f1, bool useRange)
compute the chi2 value for an histogram given a function (see TH1::Chisquare for the documentation) ...
Definition: HFitImpl.cxx:989
TAxis * GetYaxis()
Definition: TH1.h:320
const char * GetTitle() const
Returns title of object.
Definition: TAxis.h:133
float xmax
Definition: THbookFile.cxx:93
Bool_t IsNull() const
Definition: TString.h:387
virtual Double_t Eval(Double_t x, TSpline *spline=0, Option_t *option="") const
Interpolate points in this graph at x using a TSpline -if spline==0 and option="" a linear interpolat...
Definition: TGraph.cxx:850
virtual Color_t GetLineColor() const
Definition: TAttLine.h:47
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
TGraphErrors * gr
Definition: legend1.C:25
Bool_t GetNoExponent() const
Definition: TAxis.h:126
#define Printf
Definition: TGeoToOCC.h:18
virtual Double_t GetCovariance() const
Return covariance of vectors x,y.
Definition: TGraph.cxx:1317
virtual Int_t GetNpx() const
Definition: TF1.h:352
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
int Ssiz_t
Definition: RtypesCore.h:63
virtual void Print(Option_t *chopt="") const
Print graph values.
Definition: TGraph.cxx:1943
virtual void InitGaus(Double_t xmin=0, Double_t xmax=0)
Compute Initial values of parameters for a gaussian.
Definition: TGraph.cxx:1583
virtual Double_t GetErrorYlow(Int_t bin) const
This function is called by GraphFitChisquare.
Definition: TGraph.cxx:1420
Bool_t GetCenterTitle() const
Definition: TAxis.h:120
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:279
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition: DataRange.h:34
double f(double x)
Int_t GetLwb() const
Definition: TVectorT.h:79
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
double Double_t
Definition: RtypesCore.h:55
void SetHistLineStyle(Style_t styl=0)
Definition: TStyle.h:377
virtual void PaintStats(TF1 *fit)
Draw the stats.
Definition: TGraph.cxx:1934
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a graph.
Definition: TGraph.cxx:781
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
virtual Style_t GetLabelFont() const
Definition: TAttAxis.h:53
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
Definition: TString.cxx:1834
Double_t y[n]
Definition: legend1.C:17
double func(double *x, double *p)
Definition: stressTF1.cxx:213
virtual Int_t GetNdivisions() const
Definition: TAttAxis.h:50
Int_t DistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, Double_t xp2, Double_t yp2)
Compute distance from point px,py to a line.
Definition: TAttLine.cxx:193
static TVirtualGraphPainter * GetPainter()
The TH1 histogram class.
Definition: TH1.h:80
virtual ~TGraph()
Graph default destructor.
Definition: TGraph.cxx:498
Double_t fMaximum
Definition: TGraph.h:64
Color_t GetHistLineColor() const
Definition: TStyle.h:242
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:1551
virtual void SetLineStyle(Style_t lstyle)
Definition: TAttLine.h:56
Double_t ** ExpandAndCopy(Int_t size, Int_t iend)
if size > fMaxSize allocate new arrays of 2*size points and copy iend first points.
Definition: TGraph.cxx:974
void FitOptionsMake(EFitObjectType type, const char *option, Foption_t &fitOption)
Decode list of options into fitOption.
Definition: HFitImpl.cxx:673
#define name(a, b)
Definition: linkTestLib0.cpp:5
Abstract Base Class for Fitting.
Binding & operator=(OUT(*fun)(void))
virtual Double_t Integral(Int_t first=0, Int_t last=-1) const
Integrate the TGraph data within a given (index) range.
Definition: TGraph.cxx:1738
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:449
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void UseCurrentStyle()
Set current style settings in this graph This function is called when either TCanvas::UseCurrentStyle...
Definition: TGraph.cxx:2316
TAxis * GetYaxis() const
Get y axis of the graph.
Definition: TGraph.cxx:1573
virtual void Browse(TBrowser *b)
Browse.
Definition: TGraph.cxx:560
virtual Float_t GetLabelSize() const
Definition: TAttAxis.h:55
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition: TString.cxx:1806
virtual Double_t GetErrorY(Int_t bin) const
This function is called by GraphFitChisquare.
Definition: TGraph.cxx:1380
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:988
virtual Color_t GetMarkerColor() const
Definition: TAttMarker.h:44
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition: TGraph.cxx:2127
Double_t * fY
Definition: TGraph.h:60
virtual void InitExpo(Double_t xmin=0, Double_t xmax=0)
Compute Initial values of parameters for an exponential.
Definition: TGraph.cxx:1621
const Ssiz_t kNPOS
Definition: Rtypes.h:115
virtual Double_t GetMean(Int_t axis=1) const
Return mean value of X (axis=1) or Y (axis=2)
Definition: TGraph.cxx:1333
virtual void LeastSquareLinearFit(Int_t n, Double_t &a0, Double_t &a1, Int_t &ifail, Double_t xmin=0, Double_t xmax=0)
Least square linear fit without weights.
Definition: TGraph.cxx:1861
static Bool_t CompareArg(const TGraph *gr, Int_t left, Int_t right)
Return kTRUE if point number "left"'s argument (angle with respect to positive x-axis) is bigger than...
Definition: TGraph.cxx:603
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
1-Dim function class
Definition: TF1.h:149
void MakeZombie()
Definition: TObject.h:68
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
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:1185
TF1 * f1
Definition: legend1.C:11
#define NULL
Definition: Rtypes.h:82
Bool_t GetEditable() const
Return kTRUE if kNotEditable bit is not set, kFALSE otherwise.
Definition: TGraph.cxx:2091
#define gPad
Definition: TVirtualPad.h:288
virtual void CopyAndRelease(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:671
virtual void DrawGraph(Int_t n, const Int_t *x, const Int_t *y, Option_t *option="")
Draw this graph with new attributes.
Definition: TGraph.cxx:791
double result[121]
void ResetBit(UInt_t f)
Definition: TObject.h:172
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:431
TFitResultPtr FitObject(TH1 *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
fitting function for a TH1 (called from TH1::Fit)
Definition: HFitImpl.cxx:935
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1243
Int_t fMaxSize
Definition: TGraph.h:57
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
virtual void ExecuteEventHelper(TGraph *theGraph, Int_t event, Int_t px, Int_t py)=0
virtual void PaintStats(TGraph *theGraph, TF1 *fit)=0
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
Definition: TGraph.cxx:2076
virtual Style_t GetMarkerStyle() const
Definition: TAttMarker.h:45
Bool_t GetRotateTitle() const
Definition: TAxis.h:128
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual Width_t GetLineWidth() const
Definition: TAttLine.h:49
void SetHistLineColor(Color_t color=1)
Definition: TStyle.h:375
TObject * obj
virtual void SetEditable(Bool_t editable=kTRUE)
if editable=kFALSE, the graph cannot be modified with the mouse by default a TGraph is editable ...
Definition: TGraph.cxx:2100
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:379
float value
Definition: math.cpp:443
Double_t ** AllocateArrays(Int_t Narrays, Int_t arraySize)
Allocate arrays.
Definition: TGraph.cxx:522
const Int_t n
Definition: legend1.C:16
virtual void PaintGrapHist(TGraph *theGraph, Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)=0
virtual Int_t GetNpar() const
Definition: TF1.h:349
virtual void PaintGraph(TGraph *theGraph, Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)=0
TAxis * GetXaxis()
Definition: TH1.h:319
virtual Double_t GetCorrelationFactor() const
Return graph correlation factor.
Definition: TGraph.cxx:1305
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
static Bool_t CompareY(const TGraph *gr, Int_t left, Int_t right)
Return kTRUE if fY[left] > fY[right]. Can be used by Sort.
Definition: TGraph.cxx:622
virtual Float_t GetLabelOffset() const
Definition: TAttAxis.h:54
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:702