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