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