Logo ROOT  
Reference Guide
TGraph2D.cxx
Go to the documentation of this file.
1 // @(#)root/hist:$Id: TGraph2D.cxx,v 1.00
2 // Author: Olivier Couet
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 "TROOT.h"
13 #include "TBuffer.h"
14 #include "TMath.h"
15 #include "TH2.h"
16 #include "TF2.h"
17 #include "TList.h"
18 #include "TGraph2D.h"
19 #include "TGraphDelaunay.h"
20 #include "TGraphDelaunay2D.h"
21 #include "TVirtualPad.h"
22 #include "TVirtualFitter.h"
23 #include "TVirtualHistPainter.h"
24 #include "TPluginManager.h"
25 #include "TSystem.h"
26 #include "strtok.h"
27 #include "snprintf.h"
28 
29 #include <cstdlib>
30 #include <cassert>
31 #include <iostream>
32 #include <fstream>
33 
34 #include "HFitInterface.h"
35 #include "Fit/DataRange.h"
36 #include "Math/MinimizerOptions.h"
37 
39 
40 
41 /** \class TGraph2D
42  \ingroup Hist
43 Graphics object made of three arrays X, Y and Z with the same number of points each.
44 
45 This class has different constructors:
46 - With an array's dimension and three arrays x, y, and z:
47 ~~~ {.cpp}
48  TGraph2D *g = new TGraph2D(n, x, y, z);
49 ~~~
50  x, y, z arrays can be doubles, floats, or ints.
51 - With an array's dimension only:
52 ~~~ {.cpp}
53  TGraph2D *g = new TGraph2D(n);
54 ~~~
55  The internal arrays are then filled with `SetPoint()`. The following line
56  fills the internal arrays at the position `i` with the values
57  `x`, `y`, `z`.
58 ~~~ {.cpp}
59  g->SetPoint(i, x, y, z);
60 ~~~
61 - Without parameters:
62 ~~~ {.cpp}
63  TGraph2D *g = new TGraph2D();
64 ~~~
65  again `SetPoint()` must be used to fill the internal arrays.
66 - From a file:
67 ~~~ {.cpp}
68  TGraph2D *g = new TGraph2D("graph.dat");
69 ~~~
70  Arrays are read from the ASCII file "graph.dat" according to a specifies
71  format. The default format is `%%lg %%lg %%lg`
72 
73 Note that in any of these three cases, `SetPoint()` can be used to change a data
74 point or add a new one. If the data point index (`i`) is greater than the
75 current size of the internal arrays, they are automatically extended.
76 
77 Like TGraph the TGraph2D constructors do not have the TGraph2D title and name as parameters.
78 A TGraph2D has the default title and name "Graph2D". To change the default title
79 and name `SetTitle` and `SetName` should be called on the TGraph2D after its creation.
80 
81 Specific drawing options can be used to paint a TGraph2D:
82 
83 
84 | Option | Description |
85 |----------|-------------------------------------------------------------------|
86 | "TRI" | The Delaunay triangles are drawn using filled area. An hidden surface drawing technique is used. The surface is painted with the current fill area color. The edges of each triangles are painted with the current line color. |
87 | "TRIW" | The Delaunay triangles are drawn as wire frame. |
88 | "TRI1" | The Delaunay triangles are painted with color levels. The edges of each triangles are painted with the current line color. |
89 | "TRI2" | The Delaunay triangles are painted with color levels. |
90 | "P" | Draw a marker at each vertex. |
91 | "P0" | Draw a circle at each vertex. Each circle background is white. |
92 | "PCOL" | Draw a marker at each vertex. The color of each marker is defined according to its Z position. |
93 | "LINE" | Draw a 3D polyline. |
94 
95 A TGraph2D can be also drawn with any options valid to draw a 2D histogram
96 (like `COL`, `SURF`, `LEGO`, `CONT` etc..).
97 
98 When a TGraph2D is drawn with one of the 2D histogram drawing option,
99 an intermediate 2D histogram is filled using the Delaunay triangles
100 to interpolate the data set. The 2D histogram has equidistant bins along the X
101 and Y directions. The number of bins along each direction can be change using
102 `SetNpx()` and `SetNpy()`. Each bin is filled with the Z
103 value found via a linear interpolation on the plane defined by the triangle above
104 the (X,Y) coordinates of the bin center.
105 
106 The existing (X,Y,Z) points can be randomly scattered.
107 The Delaunay triangles are build in the (X,Y) plane. These 2D triangles are then
108 used to define flat planes in (X,Y,Z) over which the interpolation is done to fill
109 the 2D histogram. The 3D triangles int takes build a 3D surface in
110 the form of tessellating triangles at various angles. The triangles found can be
111 drawn in 3D with one of the TGraph2D specific drawing options.
112 
113 The histogram generated by the Delaunay interpolation can be accessed using the
114 `GetHistogram()` method.
115 
116 The axis settings (title, ranges etc ...) can be changed accessing the axis via
117 the GetXaxis GetYaxis and GetZaxis methods. They access the histogram axis created
118 at drawing time only. Therefore they should called after the TGraph2D is drawn:
119 
120 ~~~ {.cpp}
121  TGraph2D *g = new TGraph2D();
122 
123  [...]
124 
125  g->Draw("tri1");
126  gPad->Update();
127  g->GetXaxis()->SetTitle("X axis title");
128 ~~~
129 
130 Example:
131 
132 Begin_Macro(source)
133 {
134  TCanvas *c = new TCanvas("c","Graph2D example",0,0,600,400);
135  Double_t x, y, z, P = 6.;
136  Int_t np = 200;
137  TGraph2D *dt = new TGraph2D();
138  dt->SetTitle("Graph title; X axis title; Y axis title; Z axis title");
139  TRandom *r = new TRandom();
140  for (Int_t N=0; N<np; N++) {
141  x = 2*P*(r->Rndm(N))-P;
142  y = 2*P*(r->Rndm(N))-P;
143  z = (sin(x)/x)*(sin(y)/y)+0.2;
144  dt->SetPoint(N,x,y,z);
145  }
146  gStyle->SetPalette(1);
147  dt->Draw("surf1");
148  return c;
149 }
150 End_Macro
151 
152 2D graphs can be fitted as shown by the following example:
153 
154 Begin_Macro(source)
155 ../../../tutorials/fit/graph2dfit.C
156 End_Macro
157 
158 Example showing the PCOL option.
159 
160 Begin_Macro(source)
161 {
162  TCanvas *c1 = new TCanvas("c1","Graph2D example",0,0,600,400);
163  Double_t P = 5.;
164  Int_t npx = 20 ;
165  Int_t npy = 20 ;
166  Double_t x = -P;
167  Double_t y = -P;
168  Double_t z;
169  Int_t k = 0;
170  Double_t dx = (2*P)/npx;
171  Double_t dy = (2*P)/npy;
172  TGraph2D *dt = new TGraph2D(npx*npy);
173  dt->SetNpy(41);
174  dt->SetNpx(40);
175  for (Int_t i=0; i<npx; i++) {
176  for (Int_t j=0; j<npy; j++) {
177  z = sin(sqrt(x*x+y*y))+1;
178  dt->SetPoint(k,x,y,z);
179  k++;
180  y = y+dy;
181  }
182  x = x+dx;
183  y = -P;
184  }
185  gStyle->SetPalette(1);
186  dt->SetMarkerStyle(20);
187  dt->Draw("pcol");
188  return c1;
189 }
190 End_Macro
191 
192 ### Definition of Delaunay triangulation (After B. Delaunay)
193 For a set S of points in the Euclidean plane, the unique triangulation DT(S)
194 of S such that no point in S is inside the circumcircle of any triangle in
195 DT(S). DT(S) is the dual of the Voronoi diagram of S.
196 If n is the number of points in S, the Voronoi diagram of S is the partitioning
197 of the plane containing S points into n convex polygons such that each polygon
198 contains exactly one point and every point in a given polygon is closer to its
199 central point than to any other. A Voronoi diagram is sometimes also known as
200 a Dirichlet tessellation.
201 
202 \image html tgraph2d_delaunay.png
203 
204 [This applet](http://www.cs.cornell.edu/Info/People/chew/Delaunay.html)
205 gives a nice practical view of Delaunay triangulation and Voronoi diagram.
206 */
207 
208 
209 ////////////////////////////////////////////////////////////////////////////////
210 /// Graph2D default constructor
211 
213  : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
214  TAttMarker(), fNpoints(0)
215 {
216  fSize = 0;
217  fMargin = 0.;
218  fNpx = 40;
219  fNpy = 40;
220  fDirectory = 0;
221  fHistogram = 0;
222  fDelaunay = nullptr;
223  fMaximum = -1111;
224  fMinimum = -1111;
225  fX = 0;
226  fY = 0;
227  fZ = 0;
228  fZout = 0;
229  fMaxIter = 100000;
230  fPainter = 0;
231  fFunctions = new TList;
232  fUserHisto = kFALSE;
233 }
234 
235 
236 ////////////////////////////////////////////////////////////////////////////////
237 /// Graph2D constructor with three vectors of ints as input.
238 
240  : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
241  TAttMarker(), fNpoints(n)
242 {
243  Build(n);
244 
245  // Copy the input vectors into local arrays
246  for (Int_t i = 0; i < fNpoints; ++i) {
247  fX[i] = (Double_t)x[i];
248  fY[i] = (Double_t)y[i];
249  fZ[i] = (Double_t)z[i];
250  }
251 }
252 
253 
254 ////////////////////////////////////////////////////////////////////////////////
255 /// Graph2D constructor with three vectors of floats as input.
256 
258  : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
259  TAttMarker(), fNpoints(n)
260 {
261  Build(n);
262 
263  // Copy the input vectors into local arrays
264  for (Int_t i = 0; i < fNpoints; ++i) {
265  fX[i] = x[i];
266  fY[i] = y[i];
267  fZ[i] = z[i];
268  }
269 }
270 
271 
272 ////////////////////////////////////////////////////////////////////////////////
273 /// Graph2D constructor with three vectors of doubles as input.
274 
276  : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
277  TAttMarker(), fNpoints(n)
278 {
279  Build(n);
280 
281  // Copy the input vectors into local arrays
282  for (Int_t i = 0; i < fNpoints; ++i) {
283  fX[i] = x[i];
284  fY[i] = y[i];
285  fZ[i] = z[i];
286  }
287 }
288 
289 
290 ////////////////////////////////////////////////////////////////////////////////
291 /// Graph2D constructor with a TH2 (h2) as input.
292 /// Only the h2's bins within the X and Y axis ranges are used.
293 /// Empty bins, recognized when both content and errors are zero, are excluded.
294 
296  : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
297  TAttMarker(), fNpoints(0)
298 {
299  Build(h2->GetNbinsX()*h2->GetNbinsY());
300 
301  TString gname = "Graph2D_from_" + TString(h2->GetName());
302  SetName(gname);
303  // need to call later because sets title in ref histogram
304  SetTitle(h2->GetTitle());
305 
306 
307 
308  TAxis *xaxis = h2->GetXaxis();
309  TAxis *yaxis = h2->GetYaxis();
310  Int_t xfirst = xaxis->GetFirst();
311  Int_t xlast = xaxis->GetLast();
312  Int_t yfirst = yaxis->GetFirst();
313  Int_t ylast = yaxis->GetLast();
314 
315 
316  Double_t x, y, z;
317  Int_t k = 0;
318 
319  for (Int_t i = xfirst; i <= xlast; i++) {
320  for (Int_t j = yfirst; j <= ylast; j++) {
321  x = xaxis->GetBinCenter(i);
322  y = yaxis->GetBinCenter(j);
323  z = h2->GetBinContent(i, j);
324  Double_t ez = h2->GetBinError(i, j);
325  if (z != 0. || ez != 0) {
326  SetPoint(k, x, y, z);
327  k++;
328  }
329  }
330  }
331 }
332 
333 
334 ////////////////////////////////////////////////////////////////////////////////
335 /// Graph2D constructor with name, title and three vectors of doubles as input.
336 /// name : name of 2D graph (avoid blanks)
337 /// title : 2D graph title
338 /// if title is of the form "stringt;stringx;stringy;stringz"
339 /// the 2D graph title is set to stringt, the x axis title to stringx,
340 /// the y axis title to stringy,etc
341 
342 TGraph2D::TGraph2D(const char *name, const char *title,
343  Int_t n, Double_t *x, Double_t *y, Double_t *z)
344  : TNamed(name, title), TAttLine(1, 1, 1), TAttFill(0, 1001),
345  TAttMarker(), fNpoints(n)
346 {
347  Build(n);
348 
349  // Copy the input vectors into local arrays
350  for (Int_t i = 0; i < fNpoints; ++i) {
351  fX[i] = x[i];
352  fY[i] = y[i];
353  fZ[i] = z[i];
354  }
355 }
356 
357 
358 ////////////////////////////////////////////////////////////////////////////////
359 /// Graph2D constructor. The arrays fX, fY and fZ should be filled via
360 /// calls to SetPoint
361 
363  : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
364  TAttMarker(), fNpoints(n)
365 {
366  Build(n);
367  for (Int_t i = 0; i < fNpoints; i++) {
368  fX[i] = 0.;
369  fY[i] = 0.;
370  fZ[i] = 0.;
371  }
372 }
373 
374 
375 ////////////////////////////////////////////////////////////////////////////////
376 /// Graph2D constructor reading input from filename
377 /// filename is assumed to contain at least three columns of numbers.
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 TGraph2D::TGraph2D(const char *filename, const char *format, Option_t *option)
385  : TNamed("Graph2D", filename), TAttLine(1, 1, 1), TAttFill(0, 1001),
386  TAttMarker(), fNpoints(0)
387 {
388  Double_t x, y, z;
389  TString fname = filename;
390  gSystem->ExpandPathName(fname);
391 
392  std::ifstream infile(fname.Data());
393  if (!infile.good()) {
394  MakeZombie();
395  Error("TGraph2D", "Cannot open file: %s, TGraph2D is Zombie", filename);
396  return;
397  } else {
398  Build(100);
399  }
400  std::string line;
401  Int_t np = 0;
402 
403  if (strcmp(option, "") == 0) { // No delimiters specified (standard constructor).
404 
405  while (std::getline(infile, line, '\n')) {
406  if (3 != sscanf(line.c_str(), format, &x, &y, &z)) {
407  continue; // skip empty and ill-formed lines
408  }
409  SetPoint(np, x, y, z);
410  np++;
411  }
412 
413  } else { // A delimiter has been specified in "option"
414 
415  // Checking format and creating its boolean equivalent
416  TString format_ = TString(format) ;
417  format_.ReplaceAll(" ", "") ;
418  format_.ReplaceAll("\t", "") ;
419  format_.ReplaceAll("lg", "") ;
420  format_.ReplaceAll("s", "") ;
421  format_.ReplaceAll("%*", "0") ;
422  format_.ReplaceAll("%", "1") ;
423  if (!format_.IsDigit()) {
424  Error("TGraph2D", "Incorrect input format! Allowed format tags are {\"%%lg\",\"%%*lg\" or \"%%*s\"}");
425  return;
426  }
427  Int_t ntokens = format_.Length() ;
428  if (ntokens < 3) {
429  Error("TGraph2D", "Incorrect input format! Only %d tag(s) in format whereas 3 \"%%lg\" tags are expected!", ntokens);
430  return;
431  }
432  Int_t ntokensToBeSaved = 0 ;
433  Bool_t * isTokenToBeSaved = new Bool_t [ntokens] ;
434  for (Int_t idx = 0; idx < ntokens; idx++) {
435  isTokenToBeSaved[idx] = TString::Format("%c", format_[idx]).Atoi() ; //atoi(&format_[idx]) does not work for some reason...
436  if (isTokenToBeSaved[idx] == 1) {
437  ntokensToBeSaved++ ;
438  }
439  }
440  if (ntokens >= 3 && ntokensToBeSaved != 3) { //first condition not to repeat the previous error message
441  Error("TGraph2D", "Incorrect input format! There are %d \"%%lg\" tag(s) in format whereas 3 and only 3 are expected!", ntokensToBeSaved);
442  delete [] isTokenToBeSaved ;
443  return;
444  }
445 
446  // Initializing loop variables
447  Bool_t isLineToBeSkipped = kFALSE ; //empty and ill-formed lines
448  char * token = NULL ;
449  TString token_str = "" ;
450  Int_t token_idx = 0 ;
451  Double_t * value = new Double_t [3] ; //x,y,z buffers
452  Int_t value_idx = 0 ;
453 
454  // Looping
455  char *rest;
456  while (std::getline(infile, line, '\n')) {
457  if (line != "") {
458  if (line[line.size() - 1] == char(13)) { // removing DOS CR character
459  line.erase(line.end() - 1, line.end()) ;
460  }
461  token = R__STRTOK_R(const_cast<char*>(line.c_str()), option, &rest);
462  while (token != NULL && value_idx < 3) {
463  if (isTokenToBeSaved[token_idx]) {
464  token_str = TString(token) ;
465  token_str.ReplaceAll("\t", "") ;
466  if (!token_str.IsFloat()) {
467  isLineToBeSkipped = kTRUE ;
468  break ;
469  } else {
470  value[value_idx] = token_str.Atof() ;
471  value_idx++ ;
472  }
473  }
474  token = R__STRTOK_R(NULL, option, &rest); // next token
475  token_idx++ ;
476  }
477  if (!isLineToBeSkipped && value_idx == 3) {
478  x = value[0] ;
479  y = value[1] ;
480  z = value[2] ;
481  SetPoint(np, x, y, z) ;
482  np++ ;
483  }
484  }
485  isLineToBeSkipped = kFALSE ;
486  token = NULL ;
487  token_idx = 0 ;
488  value_idx = 0 ;
489  }
490 
491  // Cleaning
492  delete [] isTokenToBeSaved ;
493  delete [] value ;
494  delete token ;
495  }
496  infile.close();
497 }
498 
499 
500 ////////////////////////////////////////////////////////////////////////////////
501 /// Graph2D copy constructor.
502 /// copy everything apart from the list of contained functions
503 
506  fX(0), fY(0), fZ(0),
507  fHistogram(0), fDirectory(0), fPainter(0)
508 {
509  fFunctions = new TList(); // do not copy the functions
510 
511  // use operator=
512  (*this) = g;
513 
514  // append TGraph2D to gdirectory
515  if (TH1::AddDirectoryStatus()) {
517  if (fDirectory) {
518  // append without replacing existing objects
519  fDirectory->Append(this);
520  }
521  }
522 
523 
524 }
525 
526 
527 ////////////////////////////////////////////////////////////////////////////////
528 /// TGraph2D destructor.
529 
531 {
532  Clear();
533 }
534 
535 
536 ////////////////////////////////////////////////////////////////////////////////
537 /// Graph2D operator "="
538 
540 {
541  if (this == &g) return *this;
542 
543  // delete before existing contained objects
544  if (fX) delete [] fX;
545  if (fY) delete [] fY;
546  if (fZ) delete [] fZ;
547  if (fHistogram && !fUserHisto) {
548  delete fHistogram;
549  fHistogram = nullptr;
550  fDelaunay = nullptr;
551  }
552  // copy everything except the function list
553  fNpoints = g.fNpoints;
554  fNpx = g.fNpx;
555  fNpy = g.fNpy;
556  fMaxIter = g.fMaxIter;
557  fSize = fNpoints; // force size to be the same of npoints
558  fX = (fSize > 0) ? new Double_t[fSize] : 0;
559  fY = (fSize > 0) ? new Double_t[fSize] : 0;
560  fZ = (fSize > 0) ? new Double_t[fSize] : 0;
561  fMinimum = g.fMinimum;
562  fMaximum = g.fMaximum;
563  fMargin = g.fMargin;
564  fZout = g.fZout;
565  fUserHisto = g.fUserHisto;
566  if (g.fHistogram)
567  fHistogram = (fUserHisto ) ? g.fHistogram : new TH2D(*g.fHistogram);
568 
569 
570 
571  // copy the points
572  for (Int_t n = 0; n < fSize; n++) {
573  fX[n] = g.fX[n];
574  fY[n] = g.fY[n];
575  fZ[n] = g.fZ[n];
576  }
577 
578  return *this;
579 }
580 
581 ////////////////////////////////////////////////////////////////////////////////
582 /// Creates the 2D graph basic data structure
583 
585 {
586  if (n <= 0) {
587  Error("TGraph2D", "Invalid number of points (%d)", n);
588  return;
589  }
590 
591  fSize = n;
592  fMargin = 0.;
593  fNpx = 40;
594  fNpy = 40;
595  fDirectory = 0;
596  fHistogram = 0;
597  fDelaunay = nullptr;
598  fMaximum = -1111;
599  fMinimum = -1111;
600  fX = new Double_t[fSize];
601  fY = new Double_t[fSize];
602  fZ = new Double_t[fSize];
603  fZout = 0;
604  fMaxIter = 100000;
605  fFunctions = new TList;
606  fPainter = 0;
607  fUserHisto = kFALSE;
608 
609  if (TH1::AddDirectoryStatus()) {
611  if (fDirectory) {
612  fDirectory->Append(this, kTRUE);
613  }
614  }
615 }
616 
617 
618 ////////////////////////////////////////////////////////////////////////////////
619 /// Browse
620 
622 {
623  Draw("p0");
624  gPad->Update();
625 }
626 
627 
628 ////////////////////////////////////////////////////////////////////////////////
629 /// Free all memory allocated by this object.
630 
631 void TGraph2D::Clear(Option_t * /*option = "" */)
632 {
633  if (fX) delete [] fX;
634  fX = 0;
635  if (fY) delete [] fY;
636  fY = 0;
637  if (fZ) delete [] fZ;
638  fZ = 0;
639  fSize = fNpoints = 0;
640  if (fHistogram && !fUserHisto) {
641  delete fHistogram;
642  fHistogram = nullptr;
643  fDelaunay = nullptr;
644  }
645  if (fFunctions) {
647  fFunctions->Delete();
648  delete fFunctions;
649  fFunctions = 0;
650  }
651  if (fDirectory) {
652  fDirectory->Remove(this);
653  fDirectory = 0;
654  }
655 }
656 
657 
658 ////////////////////////////////////////////////////////////////////////////////
659 /// Perform the automatic addition of the graph to the given directory
660 ///
661 /// Note this function is called in place when the semantic requires
662 /// this object to be added to a directory (I.e. when being read from
663 /// a TKey or being Cloned)
664 
666 {
667  Bool_t addStatus = TH1::AddDirectoryStatus();
668  if (addStatus) {
669  SetDirectory(dir);
670  if (dir) {
672  }
673  }
674 }
675 
676 
677 ////////////////////////////////////////////////////////////////////////////////
678 /// Computes distance from point px,py to a graph
679 
681 {
682  Int_t distance = 9999;
683  if (fHistogram) distance = fHistogram->DistancetoPrimitive(px, py);
684  return distance;
685 }
686 
687 
688 ////////////////////////////////////////////////////////////////////////////////
689 /// Specific drawing options can be used to paint a TGraph2D:
690 ///
691 /// - "TRI" : The Delaunay triangles are drawn using filled area.
692 /// An hidden surface drawing technique is used. The surface is
693 /// painted with the current fill area color. The edges of each
694 /// triangles are painted with the current line color.
695 /// - "TRIW" : The Delaunay triangles are drawn as wire frame
696 /// - "TRI1" : The Delaunay triangles are painted with color levels. The edges
697 /// of each triangles are painted with the current line color.
698 /// - "TRI2" : the Delaunay triangles are painted with color levels.
699 /// - "P" : Draw a marker at each vertex
700 /// - "P0" : Draw a circle at each vertex. Each circle background is white.
701 /// - "PCOL" : Draw a marker at each vertex. The color of each marker is
702 /// defined according to its Z position.
703 /// - "CONT" : Draw contours
704 /// - "LINE" : Draw a 3D polyline
705 ///
706 /// A TGraph2D can be also drawn with ANY options valid to draw a 2D histogram.
707 ///
708 /// When a TGraph2D is drawn with one of the 2D histogram drawing option,
709 /// a intermediate 2D histogram is filled using the Delaunay triangles
710 /// technique to interpolate the data set.
711 
713 {
714  TString opt = option;
715  opt.ToLower();
716  if (gPad) {
717  if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
718  if (!opt.Contains("same")) {
719  //the following statement is necessary in case one attempts to draw
720  //a temporary histogram already in the current pad
721  if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
722  gPad->Clear();
723  }
724  }
725  AppendPad(opt.Data());
726 }
727 
728 
729 ////////////////////////////////////////////////////////////////////////////////
730 /// Executes action corresponding to one event
731 
733 {
734  if (fHistogram) fHistogram->ExecuteEvent(event, px, py);
735 }
736 
737 
738 ////////////////////////////////////////////////////////////////////////////////
739 /// search object named name in the list of functions
740 
741 TObject *TGraph2D::FindObject(const char *name) const
742 {
743  if (fFunctions) return fFunctions->FindObject(name);
744  return 0;
745 }
746 
747 
748 ////////////////////////////////////////////////////////////////////////////////
749 /// search object obj in the list of functions
750 
752 {
753  if (fFunctions) return fFunctions->FindObject(obj);
754  return 0;
755 }
756 
757 
758 ////////////////////////////////////////////////////////////////////////////////
759 /// Fits this graph with function with name fname
760 /// Predefined functions such as gaus, expo and poln are automatically
761 /// created by ROOT.
762 /// fname can also be a formula, accepted by the linear fitter (linear parts divided
763 /// by "++" sign), for example "x++sin(y)" for fitting "[0]*x+[1]*sin(y)"
764 
765 TFitResultPtr TGraph2D::Fit(const char *fname, Option_t *option, Option_t *)
766 {
767 
768  char *linear;
769  linear = (char*)strstr(fname, "++");
770 
771  if (linear) {
772  TF2 f2(fname, fname);
773  return Fit(&f2, option, "");
774  }
775  TF2 * f2 = (TF2*)gROOT->GetFunction(fname);
776  if (!f2) {
777  Printf("Unknown function: %s", fname);
778  return -1;
779  }
780  return Fit(f2, option, "");
781 
782 }
783 
784 
785 ////////////////////////////////////////////////////////////////////////////////
786 /// Fits this 2D graph with function f2
787 ///
788 /// f2 is an already predefined function created by TF2.
789 /// Predefined functions such as gaus, expo and poln are automatically
790 /// created by ROOT.
791 ///
792 /// The list of fit options is given in parameter option:
793 ///
794 /// | Option | Description |
795 /// |----------|-------------------------------------------------------------------|
796 /// | "W" | Ignore all point errors when fitting a TGraph2DErrors |
797 /// | "U" | Use a User specified fitting algorithm (via SetFCN) |
798 /// | "Q" | Quiet mode (minimum printing) |
799 /// | "V" | Verbose mode (default is between Q and V) |
800 /// | "R" | Use the Range specified in the function range |
801 /// | "N" | Do not store the graphics function, do not draw |
802 /// | "0" | Do not plot the result of the fit. By default the fitted function is drawn unless the option "N" above is specified. |
803 /// | "+" | Add this new fitted function to the list of fitted functions (by default, any previous function is deleted) |
804 /// | "C" | In case of linear fitting, not calculate the chisquare (saves time) |
805 /// | "EX0" | When fitting a TGraph2DErrors do not consider errors in the X,Y coordinates |
806 /// | "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 |
807 /// | "S" | The result of the fit is returned in the TFitResultPtr (see below Access to the Fit Result) |
808 ///
809 /// In order to use the Range option, one must first create a function
810 /// with the expression to be fitted. For example, if your graph2d
811 /// has a defined range between -4 and 4 and you want to fit a gaussian
812 /// only in the interval 1 to 3, you can do:
813 /// ~~~ {.cpp}
814 /// TF2 *f2 = new TF2("f2","gaus",1,3);
815 /// graph2d->Fit("f2","R");
816 /// ~~~
817 ///
818 /// ### Setting initial conditions
819 ///
820 /// Parameters must be initialized before invoking the Fit function.
821 /// The setting of the parameter initial values is automatic for the
822 /// predefined functions : poln, expo, gaus. One can however disable
823 /// this automatic computation by specifying the option "B".
824 /// You can specify boundary limits for some or all parameters via
825 /// ~~~ {.cpp}
826 /// f2->SetParLimits(p_number, parmin, parmax);
827 /// ~~~
828 /// if parmin>=parmax, the parameter is fixed
829 /// Note that you are not forced to fix the limits for all parameters.
830 /// For example, if you fit a function with 6 parameters, you can do:
831 /// ~~~ {.cpp}
832 /// func->SetParameters(0,3.1,1.e-6,0.1,-8,100);
833 /// func->SetParLimits(4,-10,-4);
834 /// func->SetParLimits(5, 1,1);
835 /// ~~~
836 /// With this setup, parameters 0->3 can vary freely
837 /// Parameter 4 has boundaries [-10,-4] with initial value -8
838 /// Parameter 5 is fixed to 100.
839 ///
840 /// ### Fit range
841 ///
842 /// The fit range can be specified in two ways:
843 /// - specify rxmax > rxmin (default is rxmin=rxmax=0)
844 /// - specify the option "R". In this case, the function will be taken
845 /// instead of the full graph range.
846 ///
847 /// ### Changing the fitting function
848 ///
849 /// By default a chi2 fitting function is used for fitting a TGraph.
850 /// The function is implemented in FitUtil::EvaluateChi2.
851 /// In case of TGraph2DErrors an effective chi2 is used
852 /// (see TGraphErrors fit in TGraph::Fit) and is implemented in
853 /// FitUtil::EvaluateChi2Effective
854 /// To specify a User defined fitting function, specify option "U" and
855 /// call the following functions:
856 /// ~~~ {.cpp}
857 /// TVirtualFitter::Fitter(mygraph)->SetFCN(MyFittingFunction)
858 /// ~~~
859 /// where MyFittingFunction is of type:
860 /// ~~~ {.cpp}
861 /// extern void MyFittingFunction(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag);
862 /// ~~~
863 ///
864 /// ### Associated functions
865 ///
866 /// One or more object (typically a TF2*) can be added to the list
867 /// of functions (fFunctions) associated to each graph.
868 /// When TGraph::Fit is invoked, the fitted function is added to this list.
869 /// Given a graph gr, one can retrieve an associated function
870 /// with: TF2 *myfunc = gr->GetFunction("myfunc");
871 ///
872 /// ### Access to the fit results
873 ///
874 /// The function returns a TFitResultPtr which can hold a pointer to a TFitResult object.
875 /// By default the TFitResultPtr contains only the status of the fit and it converts automatically to an
876 /// integer. If the option "S" is instead used, TFitResultPtr contains the TFitResult and behaves as a smart
877 /// pointer to it. For example one can do:
878 /// ~~~ {.cpp}
879 /// TFitResultPtr r = graph->Fit("myFunc","S");
880 /// TMatrixDSym cov = r->GetCovarianceMatrix(); // to access the covariance matrix
881 /// Double_t par0 = r->Value(0); // retrieve the value for the parameter 0
882 /// Double_t err0 = r->Error(0); // retrieve the error for the parameter 0
883 /// r->Print("V"); // print full information of fit including covariance matrix
884 /// r->Write(); // store the result in a file
885 /// ~~~
886 ///
887 /// The fit parameters, error and chi2 (but not covariance matrix) can be retrieved also
888 /// from the fitted function.
889 /// If the graph is made persistent, the list of
890 /// associated functions is also persistent. Given a pointer (see above)
891 /// to an associated function myfunc, one can retrieve the function/fit
892 /// parameters with calls such as:
893 /// ~~~ {.cpp}
894 /// Double_t chi2 = myfunc->GetChisquare();
895 /// Double_t par0 = myfunc->GetParameter(0); //value of 1st parameter
896 /// Double_t err0 = myfunc->GetParError(0); //error on first parameter
897 /// ~~~
898 ///
899 /// ### Fit Statistics
900 ///
901 /// You can change the statistics box to display the fit parameters with
902 /// the TStyle::SetOptFit(mode) method. This mode has four digits.
903 /// mode = pcev (default = 0111)
904 /// - v = 1; print name/values of parameters
905 /// - e = 1; print errors (if e=1, v must be 1)
906 /// - c = 1; print Chisquare/Number of degrees of freedom
907 /// - p = 1; print Probability
908 ///
909 /// For example: gStyle->SetOptFit(1011);
910 /// prints the fit probability, parameter names/values, and errors.
911 /// You can change the position of the statistics box with these lines
912 /// (where g is a pointer to the TGraph):
913 ///
914 /// ~~~ {.cpp}
915 /// Root > TPaveStats *st = (TPaveStats*)g->GetListOfFunctions()->FindObject("stats")
916 /// Root > st->SetX1NDC(newx1); //new x start position
917 /// Root > st->SetX2NDC(newx2); //new x end position
918 /// ~~~
919 
921 {
922  // internal graph2D fitting methods
923  Foption_t fitOption;
924  Option_t *goption = "";
925  ROOT::Fit::FitOptionsMake(ROOT::Fit::kGraph, option, fitOption);
926 
927  // create range and minimizer options with default values
928  ROOT::Fit::DataRange range(2);
930  return ROOT::Fit::FitObject(this, f2 , fitOption , minOption, goption, range);
931 }
932 
933 
934 ////////////////////////////////////////////////////////////////////////////////
935 /// Display a GUI panel with all graph fit options.
936 ///
937 /// See class TFitEditor for example
938 
940 {
941  if (!gPad)
942  gROOT->MakeDefCanvas();
943 
944  if (!gPad) {
945  Error("FitPanel", "Unable to create a default canvas");
946  return;
947  }
948 
949  // use plugin manager to create instance of TFitEditor
950  TPluginHandler *handler = gROOT->GetPluginManager()->FindHandler("TFitEditor");
951  if (handler && handler->LoadPlugin() != -1) {
952  if (handler->ExecPlugin(2, gPad, this) == 0)
953  Error("FitPanel", "Unable to crate the FitPanel");
954  } else
955  Error("FitPanel", "Unable to find the FitPanel plug-in");
956 
957 }
958 
959 
960 ////////////////////////////////////////////////////////////////////////////////
961 /// Get x axis of the graph.
962 
964 {
965  TH1 *h = ((TGraph2D*)this)->GetHistogram("empty");
966  if (!h) return 0;
967  return h->GetXaxis();
968 }
969 
970 
971 ////////////////////////////////////////////////////////////////////////////////
972 /// Get y axis of the graph.
973 
975 {
976  TH1 *h = ((TGraph2D*)this)->GetHistogram("empty");
977  if (!h) return 0;
978  return h->GetYaxis();
979 }
980 
981 
982 ////////////////////////////////////////////////////////////////////////////////
983 /// Get z axis of the graph.
984 
986 {
987  TH1 *h = ((TGraph2D*)this)->GetHistogram("empty");
988  if (!h) return 0;
989  return h->GetZaxis();
990 }
991 
992 
993 ////////////////////////////////////////////////////////////////////////////////
994 /// Returns the X and Y graphs building a contour. A contour level may
995 /// consist in several parts not connected to each other. This function
996 /// returns them in a graphs' list.
997 
999 {
1000  if (fNpoints <= 0) {
1001  Error("GetContourList", "Empty TGraph2D");
1002  return 0;
1003  }
1004 
1005  if (!fHistogram) GetHistogram("empty");
1006 
1008 
1009  return fPainter->GetContourList(contour);
1010 }
1011 
1012 
1013 ////////////////////////////////////////////////////////////////////////////////
1014 /// This function is called by Graph2DFitChisquare.
1015 /// It always returns a negative value. Real implementation in TGraph2DErrors
1016 
1018 {
1019  return -1;
1020 }
1021 
1022 
1023 ////////////////////////////////////////////////////////////////////////////////
1024 /// This function is called by Graph2DFitChisquare.
1025 /// It always returns a negative value. Real implementation in TGraph2DErrors
1026 
1028 {
1029  return -1;
1030 }
1031 
1032 
1033 ////////////////////////////////////////////////////////////////////////////////
1034 /// This function is called by Graph2DFitChisquare.
1035 /// It always returns a negative value. Real implementation in TGraph2DErrors
1036 
1038 {
1039  return -1;
1040 }
1041 
1042 
1043 ////////////////////////////////////////////////////////////////////////////////
1044 /// Add a TGraphDelaunay in the list of the fHistogram's functions
1045 
1047 {
1048 
1050 
1051  if (oldInterp) {
1052  TGraphDelaunay *dt = new TGraphDelaunay(this);
1053  dt->SetMaxIter(fMaxIter);
1055  fDelaunay = dt;
1057  if (!hl->FindObject("TGraphDelaunay")) hl->Add(fDelaunay);
1058  } else {
1059  TGraphDelaunay2D *dt = new TGraphDelaunay2D(this);
1061  fDelaunay = dt;
1063  if (!hl->FindObject("TGraphDelaunay2D")) hl->Add(fDelaunay);
1064  }
1065 }
1066 
1067 ////////////////////////////////////////////////////////////////////////////////
1068 /// By default returns a pointer to the Delaunay histogram. If fHistogram
1069 /// doesn't exist, books the 2D histogram fHistogram with a margin around
1070 /// the hull. Calls TGraphDelaunay::Interpolate at each bin centre to build up
1071 /// an interpolated 2D histogram.
1072 ///
1073 /// If the "empty" option is selected, returns an empty histogram booked with
1074 /// the limits of fX, fY and fZ. This option is used when the data set is
1075 /// drawn with markers only. In that particular case there is no need to
1076 /// find the Delaunay triangles.
1077 ///
1078 /// By default use the new interpolation routine based on Triangles
1079 /// If the option "old" the old interpolation is used
1080 
1082 {
1083  // for an empty graph create histogram in [0,1][0,1]
1084  if (fNpoints <= 0) {
1085  if (!fHistogram) {
1088  fHistogram = new TH2D(GetName(), GetTitle(), fNpx , 0., 1., fNpy, 0., 1.);
1089  TH1::AddDirectory(add);
1091  }
1092  return fHistogram;
1093  }
1094 
1095  TString opt = option;
1096  opt.ToLower();
1097  Bool_t empty = opt.Contains("empty");
1098  Bool_t oldInterp = opt.Contains("old");
1099 
1100  if (fHistogram) {
1101  if (!empty && fHistogram->GetEntries() == 0) {
1102  if (!fUserHisto) {
1103  delete fHistogram;
1104  fHistogram = nullptr;
1105  fDelaunay = nullptr;
1106  }
1107  } else if (fHistogram->GetEntries() == 0)
1108  {; }
1109  // check case if interpolation type has changed
1110  else if ( (TestBit(kOldInterpolation) && !oldInterp) || ( !TestBit(kOldInterpolation) && oldInterp ) ) {
1111  delete fHistogram;
1112  fHistogram = nullptr;
1113  fDelaunay = nullptr;
1114  }
1115  // normal case return existing histogram
1116  else {
1117  return fHistogram;
1118  }
1119  }
1120 
1121  Double_t hxmax, hymax, hxmin, hymin;
1122 
1123  // Book fHistogram if needed. It is not added in the current directory
1124  if (!fUserHisto) {
1127  Double_t xmax = GetXmaxE();
1128  Double_t ymax = GetYmaxE();
1129  Double_t xmin = GetXminE();
1130  Double_t ymin = GetYminE();
1131  hxmin = xmin - fMargin * (xmax - xmin);
1132  hymin = ymin - fMargin * (ymax - ymin);
1133  hxmax = xmax + fMargin * (xmax - xmin);
1134  hymax = ymax + fMargin * (ymax - ymin);
1135  if (TMath::Abs(hxmax - hxmin) < 0.0001) {
1136  if (TMath::Abs(hxmin) < 0.0001) {
1137  hxmin = -0.01;
1138  hxmax = 0.01;
1139  } else {
1140  hxmin = hxmin-TMath::Abs(hxmin)*0.01;
1141  hxmax = hxmax+TMath::Abs(hxmax)*0.01;
1142  }
1143  }
1144  if (TMath::Abs(hymax - hymin) < 0.0001) {
1145  if (TMath::Abs(hymin) < 0.0001) {
1146  hymin = -0.01;
1147  hymax = 0.01;
1148  } else {
1149  hymin = hymin-TMath::Abs(hymin)*0.01;
1150  hymax = hymax+TMath::Abs(hymax)*0.01;
1151  }
1152  }
1153  if (fHistogram) {
1154  fHistogram->GetXaxis()->SetLimits(hxmin, hxmax);
1155  fHistogram->GetYaxis()->SetLimits(hymin, hymax);
1156  } else {
1157  fHistogram = new TH2D(GetName(), GetTitle(),
1158  fNpx , hxmin, hxmax,
1159  fNpy, hymin, hymax);
1160  CreateInterpolator(oldInterp);
1161  }
1162  TH1::AddDirectory(add);
1164  } else {
1165  hxmin = fHistogram->GetXaxis()->GetXmin();
1166  hymin = fHistogram->GetYaxis()->GetXmin();
1167  hxmax = fHistogram->GetXaxis()->GetXmax();
1168  hymax = fHistogram->GetYaxis()->GetXmax();
1169  }
1170 
1171  // Option "empty" is selected. An empty histogram is returned.
1172  if (empty) {
1173  Double_t hzmax, hzmin;
1174  if (fMinimum != -1111) {
1175  hzmin = fMinimum;
1176  } else {
1177  hzmin = GetZminE();
1178  }
1179  if (fMaximum != -1111) {
1180  hzmax = fMaximum;
1181  } else {
1182  hzmax = GetZmaxE();
1183  }
1184  if (hzmin == hzmax) {
1185  Double_t hz = hzmin;
1186  if (hz==0) hz = 1.;
1187  hzmin = hz - 0.01 * hz;
1188  hzmax = hz + 0.01 * hz;
1189  }
1190  fHistogram->SetMinimum(hzmin);
1191  fHistogram->SetMaximum(hzmax);
1192  return fHistogram;
1193  }
1194 
1195  Double_t dx = (hxmax - hxmin) / fNpx;
1196  Double_t dy = (hymax - hymin) / fNpy;
1197 
1198  Double_t x, y, z;
1199 
1200  for (Int_t ix = 1; ix <= fNpx; ix++) {
1201  x = hxmin + (ix - 0.5) * dx;
1202  for (Int_t iy = 1; iy <= fNpy; iy++) {
1203  y = hymin + (iy - 0.5) * dy;
1204  // do interpolation
1205  if (oldInterp)
1206  z = ((TGraphDelaunay*)fDelaunay)->ComputeZ(x, y);
1207  else
1208  z = ((TGraphDelaunay2D*)fDelaunay)->ComputeZ(x, y);
1209 
1210  fHistogram->Fill(x, y, z);
1211  }
1212  }
1213 
1214 
1215  if (fMinimum != -1111) fHistogram->SetMinimum(fMinimum);
1216  if (fMaximum != -1111) fHistogram->SetMaximum(fMaximum);
1217 
1218  return fHistogram;
1219 }
1220 
1221 
1222 ////////////////////////////////////////////////////////////////////////////////
1223 /// Returns the X maximum
1224 
1226 {
1227  Double_t v = fX[0];
1228  for (Int_t i = 1; i < fNpoints; i++) if (fX[i] > v) v = fX[i];
1229  return v;
1230 }
1231 
1232 
1233 ////////////////////////////////////////////////////////////////////////////////
1234 /// Returns the X minimum
1235 
1237 {
1238  Double_t v = fX[0];
1239  for (Int_t i = 1; i < fNpoints; i++) if (fX[i] < v) v = fX[i];
1240  return v;
1241 }
1242 
1243 
1244 ////////////////////////////////////////////////////////////////////////////////
1245 /// Returns the Y maximum
1246 
1248 {
1249  Double_t v = fY[0];
1250  for (Int_t i = 1; i < fNpoints; i++) if (fY[i] > v) v = fY[i];
1251  return v;
1252 }
1253 
1254 
1255 ////////////////////////////////////////////////////////////////////////////////
1256 /// Returns the Y minimum
1257 
1259 {
1260  Double_t v = fY[0];
1261  for (Int_t i = 1; i < fNpoints; i++) if (fY[i] < v) v = fY[i];
1262  return v;
1263 }
1264 
1265 
1266 ////////////////////////////////////////////////////////////////////////////////
1267 /// Returns the Z maximum
1268 
1270 {
1271  Double_t v = fZ[0];
1272  for (Int_t i = 1; i < fNpoints; i++) if (fZ[i] > v) v = fZ[i];
1273  return v;
1274 }
1275 
1276 
1277 ////////////////////////////////////////////////////////////////////////////////
1278 /// Returns the Z minimum
1279 
1281 {
1282  Double_t v = fZ[0];
1283  for (Int_t i = 1; i < fNpoints; i++) if (fZ[i] < v) v = fZ[i];
1284  return v;
1285 }
1286 
1287 ////////////////////////////////////////////////////////////////////////////////
1288 /// Get x, y and z values for point number i.
1289 /// The function returns -1 in case of an invalid request or the point number otherwise
1290 
1292 {
1293  if (i < 0 || i >= fNpoints) return -1;
1294  if (!fX || !fY || !fZ) return -1;
1295  x = fX[i];
1296  y = fY[i];
1297  z = fZ[i];
1298  return i;
1299 }
1300 
1301 ////////////////////////////////////////////////////////////////////////////////
1302 /// Finds the z value at the position (x,y) thanks to
1303 /// the Delaunay interpolation.
1304 
1306 {
1307  if (fNpoints <= 0) {
1308  Error("Interpolate", "Empty TGraph2D");
1309  return 0;
1310  }
1311 
1312  if (!fHistogram) GetHistogram("empty");
1313  if (!fDelaunay) {
1315  if (!TestBit(kOldInterpolation) ) {
1316  fDelaunay = hl->FindObject("TGraphDelaunay2D");
1317  if (!fDelaunay) fDelaunay = hl->FindObject("TGraphDelaunay");
1318  }
1319  else {
1320  // if using old implementation
1321  fDelaunay = hl->FindObject("TGraphDelaunay");
1322  if (!fDelaunay) fDelaunay = hl->FindObject("TGraphDelaunay2D");
1323  }
1324  }
1325 
1326  if (!fDelaunay) return TMath::QuietNaN();
1327 
1328  if (fDelaunay->IsA() == TGraphDelaunay2D::Class() )
1329  return ((TGraphDelaunay2D*)fDelaunay)->ComputeZ(x, y);
1330  else if (fDelaunay->IsA() == TGraphDelaunay::Class() )
1331  return ((TGraphDelaunay*)fDelaunay)->ComputeZ(x, y);
1332 
1333  // cannot be here
1334  assert(false);
1335  return TMath::QuietNaN();
1336 }
1337 
1338 
1339 ////////////////////////////////////////////////////////////////////////////////
1340 /// Paints this 2D graph with its current attributes
1341 
1343 {
1344  if (fNpoints <= 0) {
1345  Error("Paint", "Empty TGraph2D");
1346  return;
1347  }
1348 
1349  TString opt = option;
1350  opt.ToLower();
1351  if (opt.Contains("p") && !opt.Contains("tri")) {
1352  if (!opt.Contains("pol") &&
1353  !opt.Contains("sph") &&
1354  !opt.Contains("psr")) opt.Append("tri0");
1355  }
1356 
1357  if (opt.Contains("line") && !opt.Contains("tri")) opt.Append("tri0");
1358 
1359  if (opt.Contains("err") && !opt.Contains("tri")) opt.Append("tri0");
1360 
1361  if (opt.Contains("tri0")) {
1362  GetHistogram("empty");
1363  } else if (opt.Contains("old")) {
1364  GetHistogram("old");
1365  } else {
1366  GetHistogram();
1367  }
1368 
1369  fHistogram->SetLineColor(GetLineColor());
1370  fHistogram->SetLineStyle(GetLineStyle());
1371  fHistogram->SetLineWidth(GetLineWidth());
1372  fHistogram->SetFillColor(GetFillColor());
1373  fHistogram->SetFillStyle(GetFillStyle());
1374  fHistogram->SetMarkerColor(GetMarkerColor());
1375  fHistogram->SetMarkerStyle(GetMarkerStyle());
1376  fHistogram->SetMarkerSize(GetMarkerSize());
1377  fHistogram->Paint(opt.Data());
1378 }
1379 
1380 
1381 ////////////////////////////////////////////////////////////////////////////////
1382 /// Print 2D graph values.
1383 
1385 {
1386  for (Int_t i = 0; i < fNpoints; i++) {
1387  printf("x[%d]=%g, y[%d]=%g, z[%d]=%g\n", i, fX[i], i, fY[i], i, fZ[i]);
1388  }
1389 }
1390 
1391 
1392 ////////////////////////////////////////////////////////////////////////////////
1393 /// Projects a 2-d graph into 1 or 2-d histograms depending on the option parameter.
1394 /// option may contain a combination of the characters x,y,z:
1395 ///
1396 /// - option = "x" return the x projection into a TH1D histogram
1397 /// - option = "y" return the y projection into a TH1D histogram
1398 /// - option = "xy" return the x versus y projection into a TH2D histogram
1399 /// - option = "yx" return the y versus x projection into a TH2D histogram
1400 
1402 {
1403  if (fNpoints <= 0) {
1404  Error("Project", "Empty TGraph2D");
1405  return 0;
1406  }
1407 
1408  TString opt = option;
1409  opt.ToLower();
1410 
1411  Int_t pcase = 0;
1412  if (opt.Contains("x")) pcase = 1;
1413  if (opt.Contains("y")) pcase = 2;
1414  if (opt.Contains("xy")) pcase = 3;
1415  if (opt.Contains("yx")) pcase = 4;
1416 
1417  // Create the projection histogram
1418  TH1D *h1 = 0;
1419  TH2D *h2 = 0;
1420  Int_t nch = strlen(GetName()) + opt.Length() + 2;
1421  char *name = new char[nch];
1422  snprintf(name, nch, "%s_%s", GetName(), option);
1423  nch = strlen(GetTitle()) + opt.Length() + 2;
1424  char *title = new char[nch];
1425  snprintf(title, nch, "%s_%s", GetTitle(), option);
1426 
1427  Double_t hxmin = GetXmin();
1428  Double_t hxmax = GetXmax();
1429  Double_t hymin = GetYmin();
1430  Double_t hymax = GetYmax();
1431 
1432  switch (pcase) {
1433  case 1:
1434  // "x"
1435  h1 = new TH1D(name, title, fNpx, hxmin, hxmax);
1436  break;
1437  case 2:
1438  // "y"
1439  h1 = new TH1D(name, title, fNpy, hymin, hymax);
1440  break;
1441  case 3:
1442  // "xy"
1443  h2 = new TH2D(name, title, fNpx, hxmin, hxmax, fNpy, hymin, hymax);
1444  break;
1445  case 4:
1446  // "yx"
1447  h2 = new TH2D(name, title, fNpy, hymin, hymax, fNpx, hxmin, hxmax);
1448  break;
1449  }
1450 
1451  delete [] name;
1452  delete [] title;
1453  TH1 *h = h1;
1454  if (h2) h = h2;
1455  if (h == 0) return 0;
1456 
1457  // Fill the projected histogram
1458  Double_t entries = 0;
1459  for (Int_t n = 0; n < fNpoints; n++) {
1460  switch (pcase) {
1461  case 1:
1462  // "x"
1463  h1->Fill(fX[n], fZ[n]);
1464  break;
1465  case 2:
1466  // "y"
1467  h1->Fill(fY[n], fZ[n]);
1468  break;
1469  case 3:
1470  // "xy"
1471  h2->Fill(fX[n], fY[n], fZ[n]);
1472  break;
1473  case 4:
1474  // "yx"
1475  h2->Fill(fY[n], fX[n], fZ[n]);
1476  break;
1477  }
1478  entries += fZ[n];
1479  }
1480  h->SetEntries(entries);
1481  return h;
1482 }
1483 
1484 
1485 ////////////////////////////////////////////////////////////////////////////////
1486 /// Deletes point number ipoint
1487 
1489 {
1490  if (ipoint < 0) return -1;
1491  if (ipoint >= fNpoints) return -1;
1492 
1493  fNpoints--;
1494  Double_t *newX = new Double_t[fNpoints];
1495  Double_t *newY = new Double_t[fNpoints];
1496  Double_t *newZ = new Double_t[fNpoints];
1497  Int_t j = -1;
1498  for (Int_t i = 0; i < fNpoints + 1; i++) {
1499  if (i == ipoint) continue;
1500  j++;
1501  newX[j] = fX[i];
1502  newY[j] = fY[i];
1503  newZ[j] = fZ[i];
1504  }
1505  delete [] fX;
1506  delete [] fY;
1507  delete [] fZ;
1508  fX = newX;
1509  fY = newY;
1510  fZ = newZ;
1511  fSize = fNpoints;
1512  if (fHistogram) {
1513  delete fHistogram;
1514  fHistogram = nullptr;
1515  fDelaunay = nullptr;
1516  }
1517  return ipoint;
1518 }
1519 
1520 
1521 ////////////////////////////////////////////////////////////////////////////////
1522 /// Saves primitive as a C++ statement(s) on output stream out
1523 
1524 void TGraph2D::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1525 {
1526  char quote = '"';
1527  out << " " << std::endl;
1528  if (gROOT->ClassSaved(TGraph2D::Class())) {
1529  out << " ";
1530  } else {
1531  out << " TGraph2D *";
1532  }
1533 
1534  out << "graph2d = new TGraph2D(" << fNpoints << ");" << std::endl;
1535  out << " graph2d->SetName(" << quote << GetName() << quote << ");" << std::endl;
1536  out << " graph2d->SetTitle(" << quote << GetTitle() << ";"
1537  << GetXaxis()->GetTitle() << ";"
1538  << GetYaxis()->GetTitle() << ";"
1539  << GetZaxis()->GetTitle() << quote << ");" << std::endl;
1540 
1541  if (fDirectory == 0) {
1542  out << " graph2d->SetDirectory(0);" << std::endl;
1543  }
1544 
1545  SaveFillAttributes(out, "graph2d", 0, 1001);
1546  SaveLineAttributes(out, "graph2d", 1, 1, 1);
1547  SaveMarkerAttributes(out, "graph2d", 1, 1, 1);
1548 
1549  for (Int_t i = 0; i < fNpoints; i++) {
1550  out << " graph2d->SetPoint(" << i << "," << fX[i] << "," << fY[i] << "," << fZ[i] << ");" << std::endl;
1551  }
1552 
1553  // save list of functions
1554  TIter next(fFunctions);
1555  TObject *obj;
1556  while ((obj = next())) {
1557  obj->SavePrimitive(out, "nodraw");
1558  out << " graph2d->GetListOfFunctions()->Add(" << obj->GetName() << ");" << std::endl;
1559  if (obj->InheritsFrom("TPaveStats")) {
1560  out << " ptstats->SetParent(graph2d->GetListOfFunctions());" << std::endl;
1561  } else if (obj->InheritsFrom("TF1")) {
1562  out << " " << obj->GetName() << "->SetParent(graph);\n";
1563  }
1564 
1565  }
1566 
1567  out << " graph2d->Draw(" << quote << option << quote << ");" << std::endl;
1568 }
1569 
1570 
1571 ////////////////////////////////////////////////////////////////////////////////
1572 /// Set number of points in the 2D graph.
1573 /// Existing coordinates are preserved.
1574 /// New coordinates above fNpoints are preset to 0.
1575 
1577 {
1578  if (n < 0) n = 0;
1579  if (n == fNpoints) return;
1580  if (n > fNpoints) SetPoint(n, 0, 0, 0);
1581  fNpoints = n;
1582 }
1583 
1584 
1585 ////////////////////////////////////////////////////////////////////////////////
1586 /// By default when an 2D graph is created, it is added to the list
1587 /// of 2D graph objects in the current directory in memory.
1588 /// This method removes reference to this 2D graph from current directory and add
1589 /// reference to new directory dir. dir can be 0 in which case the
1590 /// 2D graph does not belong to any directory.
1591 
1593 {
1594  if (fDirectory == dir) return;
1595  if (fDirectory) fDirectory->Remove(this);
1596  fDirectory = dir;
1597  if (fDirectory) fDirectory->Append(this);
1598 }
1599 
1600 
1601 ////////////////////////////////////////////////////////////////////////////////
1602 /// Sets the histogram to be filled.
1603 /// If the 2D graph needs to be save in a TFile the following set should be
1604 /// followed to read it back:
1605 /// 1. Create TGraph2D
1606 /// 2. Call g->SetHistogram(h), and do whatever you need to do
1607 /// 3. Save g and h to the TFile, exit
1608 /// 4. Open the TFile, retrieve g and h
1609 /// 5. Call h->SetDirectory(0)
1610 /// 6. Call g->SetHistogram(h) again
1611 /// 7. Carry on as normal
1612 
1614 {
1615  fUserHisto = kTRUE;
1616  fHistogram = (TH2D*)h;
1617  fNpx = h->GetNbinsX();
1618  fNpy = h->GetNbinsY();
1620 }
1621 
1622 
1623 ////////////////////////////////////////////////////////////////////////////////
1624 /// Sets the extra space (in %) around interpolated area for the 2D histogram
1625 
1627 {
1628  if (m < 0 || m > 1) {
1629  Warning("SetMargin", "The margin must be >= 0 && <= 1, fMargin set to 0.1");
1630  fMargin = 0.1;
1631  } else {
1632  fMargin = m;
1633  }
1634  if (fHistogram) {
1635  delete fHistogram;
1636  fHistogram = nullptr;
1637  fDelaunay = nullptr;
1638  }
1639 }
1640 
1641 
1642 ////////////////////////////////////////////////////////////////////////////////
1643 /// Sets the histogram bin height for points lying outside the TGraphDelaunay
1644 /// convex hull ie: the bins in the margin.
1645 
1647 {
1648  fZout = z;
1649  if (fHistogram) {
1650  delete fHistogram;
1651  fHistogram = nullptr;
1652  fDelaunay = nullptr;
1653  }
1654 }
1655 
1656 
1657 ////////////////////////////////////////////////////////////////////////////////
1658 /// Set maximum.
1659 
1661 {
1662  fMaximum = maximum;
1663  TH1 * h = GetHistogram();
1664  if (h) h->SetMaximum(maximum);
1665 }
1666 
1667 
1668 ////////////////////////////////////////////////////////////////////////////////
1669 /// Set minimum.
1670 
1672 {
1673  fMinimum = minimum;
1674  TH1 * h = GetHistogram();
1675  if (h) h->SetMinimum(minimum);
1676 }
1677 
1678 
1679 ////////////////////////////////////////////////////////////////////////////////
1680 /// Changes the name of this 2D graph
1681 
1682 void TGraph2D::SetName(const char *name)
1683 {
1684  // 2D graphs are named objects in a THashList.
1685  // We must update the hashlist if we change the name
1686  if (fDirectory) fDirectory->Remove(this);
1687  fName = name;
1688  if (fDirectory) fDirectory->Append(this);
1689 }
1690 
1691 
1692 ////////////////////////////////////////////////////////////////////////////////
1693 /// Change the name and title of this 2D graph
1694 ///
1695 
1696 void TGraph2D::SetNameTitle(const char *name, const char *title)
1697 {
1698  // 2D graphs are named objects in a THashList.
1699  // We must update the hashlist if we change the name
1700  if (fDirectory) fDirectory->Remove(this);
1701  fName = name;
1702  SetTitle(title);
1703  if (fDirectory) fDirectory->Append(this);
1704 }
1705 
1706 
1707 ////////////////////////////////////////////////////////////////////////////////
1708 /// Sets the number of bins along X used to draw the function
1709 
1711 {
1712  if (npx < 4) {
1713  Warning("SetNpx", "Number of points must be >4 && < 500, fNpx set to 4");
1714  fNpx = 4;
1715  } else if (npx > 500) {
1716  Warning("SetNpx", "Number of points must be >4 && < 500, fNpx set to 500");
1717  fNpx = 500;
1718  } else {
1719  fNpx = npx;
1720  }
1721  if (fHistogram) {
1722  delete fHistogram;
1723  fHistogram = nullptr;
1724  fDelaunay = nullptr;
1725  }
1726 }
1727 
1728 
1729 ////////////////////////////////////////////////////////////////////////////////
1730 /// Sets the number of bins along Y used to draw the function
1731 
1733 {
1734  if (npy < 4) {
1735  Warning("SetNpy", "Number of points must be >4 && < 500, fNpy set to 4");
1736  fNpy = 4;
1737  } else if (npy > 500) {
1738  Warning("SetNpy", "Number of points must be >4 && < 500, fNpy set to 500");
1739  fNpy = 500;
1740  } else {
1741  fNpy = npy;
1742  }
1743  if (fHistogram) {
1744  delete fHistogram;
1745  fHistogram = nullptr;
1746  fDelaunay = nullptr;
1747  }
1748 }
1749 
1750 
1751 ////////////////////////////////////////////////////////////////////////////////
1752 /// Sets point number n.
1753 /// If n is greater than the current size, the arrays are automatically
1754 /// extended.
1755 
1757 {
1758  if (n < 0) return;
1759 
1760  if (!fX || !fY || !fZ || n >= fSize) {
1761  // re-allocate the object
1762  Int_t newN = TMath::Max(2 * fSize, n + 1);
1763  Double_t *savex = new Double_t [newN];
1764  Double_t *savey = new Double_t [newN];
1765  Double_t *savez = new Double_t [newN];
1766  if (fX && fSize) {
1767  memcpy(savex, fX, fSize * sizeof(Double_t));
1768  memset(&savex[fSize], 0, (newN - fSize)*sizeof(Double_t));
1769  delete [] fX;
1770  }
1771  if (fY && fSize) {
1772  memcpy(savey, fY, fSize * sizeof(Double_t));
1773  memset(&savey[fSize], 0, (newN - fSize)*sizeof(Double_t));
1774  delete [] fY;
1775  }
1776  if (fZ && fSize) {
1777  memcpy(savez, fZ, fSize * sizeof(Double_t));
1778  memset(&savez[fSize], 0, (newN - fSize)*sizeof(Double_t));
1779  delete [] fZ;
1780  }
1781  fX = savex;
1782  fY = savey;
1783  fZ = savez;
1784  fSize = newN;
1785  }
1786  fX[n] = x;
1787  fY[n] = y;
1788  fZ[n] = z;
1789  fNpoints = TMath::Max(fNpoints, n + 1);
1790 }
1791 
1792 
1793 ////////////////////////////////////////////////////////////////////////////////
1794 /// Sets the 2D graph title.
1795 ///
1796 /// This method allows to change the global title and the axis' titles of a 2D
1797 /// graph. If `g` is the 2D graph one can do:
1798 ///
1799 /// ~~~ {.cpp}
1800 /// g->SetTitle("Graph title; X axis title; Y axis title; Z axis title");
1801 /// ~~~
1802 
1803 void TGraph2D::SetTitle(const char* title)
1804 {
1805  fTitle = title;
1806  if (fHistogram) fHistogram->SetTitle(title);
1807 }
1808 
1809 
1810 ////////////////////////////////////////////////////////////////////////////////
1811 /// Stream a class object
1812 
1813 void TGraph2D::Streamer(TBuffer &b)
1814 {
1815  if (b.IsReading()) {
1816  UInt_t R__s, R__c;
1817  Version_t R__v = b.ReadVersion(&R__s, &R__c);
1818  b.ReadClassBuffer(TGraph2D::Class(), this, R__v, R__s, R__c);
1819 
1821  } else {
1822  b.WriteClassBuffer(TGraph2D::Class(), this);
1823  }
1824 }
TObject::kMustCleanup
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition: TObject.h:60
TGraph2D::GetXmin
Double_t GetXmin() const
Returns the X minimum.
Definition: TGraph2D.cxx:1236
m
auto * m
Definition: textangle.C:8
n
const Int_t n
Definition: legend1.C:16
TAxis
Class to manage histogram axis.
Definition: TAxis.h:30
TGraph2D::fSize
Int_t fSize
!Real size of fX, fY and fZ
Definition: TGraph2D.h:49
TGraph2D::fY
Double_t * fY
[fNpoints] Data set to be plotted
Definition: TGraph2D.h:51
TObject::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:666
TGraph2D::GetErrorZ
virtual Double_t GetErrorZ(Int_t bin) const
This function is called by Graph2DFitChisquare.
Definition: TGraph2D.cxx:1037
TDirectory::Remove
virtual TObject * Remove(TObject *)
Remove an object from the in-memory list.
Definition: TDirectory.cxx:1155
TBrowser
Definition: TBrowser.h:37
ymax
float ymax
Definition: THbookFile.cxx:95
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TObject::TestBit
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
Version_t
short Version_t
Definition: RtypesCore.h:65
snprintf
#define snprintf
Definition: civetweb.c:1540
TGraph2D::fZ
Double_t * fZ
[fNpoints]
Definition: TGraph2D.h:52
TGraph2D::GetXaxis
TAxis * GetXaxis() const
Get x axis of the graph.
Definition: TGraph2D.cxx:963
Foption_t
Definition: Foption.h:24
TMath::Max
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
TString::Atoi
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1921
TMath::QuietNaN
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754
Definition: TMath.h:890
TGraphDelaunay::SetMarginBinsContent
void SetMarginBinsContent(Double_t z=0.)
Sets the histogram bin height for points lying outside the convex hull ie: the bins in the margin.
Definition: TGraphDelaunay.cxx:943
TH1::SetMinimum
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:396
TGraphDelaunay2D::SetMarginBinsContent
void SetMarginBinsContent(Double_t z=0.)
Definition: TGraphDelaunay2D.h:63
TH2::GetBinContent
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH2.h:88
TGraph2D::Draw
virtual void Draw(Option_t *option="P0")
Specific drawing options can be used to paint a TGraph2D:
Definition: TGraph2D.cxx:712
TList::FindObject
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:577
TAxis::SetLimits
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition: TAxis.h:154
TGraph2D::SetNameTitle
virtual void SetNameTitle(const char *name, const char *title)
Change the name and title of this 2D graph.
Definition: TGraph2D.cxx:1696
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:469
TString::Data
const char * Data() const
Definition: TString.h:369
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:54
TGraph2D.h
TH1::GetPainter
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
Definition: TH1.cxx:4367
TPluginHandler::ExecPlugin
Long_t ExecPlugin(int nargs, const T &... params)
Definition: TPluginManager.h:165
ROOT::Fit::FitOptionsMake
void FitOptionsMake(EFitObjectType type, const char *option, Foption_t &fitOption)
Decode list of options into fitOption.
Definition: HFitImpl.cxx:684
TGraph2D::Fit
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="")
Fits this graph with function with name fname Predefined functions such as gaus, expo and poln are au...
Definition: TGraph2D.cxx:765
xmax
float xmax
Definition: THbookFile.cxx:95
TGraph2D::operator=
TGraph2D & operator=(const TGraph2D &)
Graph2D operator "=".
Definition: TGraph2D.cxx:539
HFitInterface.h
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TGraph2D::ExecuteEvent
void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Executes action corresponding to one event.
Definition: TGraph2D.cxx:732
TString::Atof
Double_t Atof() const
Return floating-point value contained in string.
Definition: TString.cxx:1987
TH1D
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:615
TGraph2D::GetContourList
TList * GetContourList(Double_t contour)
Returns the X and Y graphs building a contour.
Definition: TGraph2D.cxx:998
TGraphDelaunay2D
Definition: TGraphDelaunay2D.h:32
DataRange.h
TAxis::GetFirst
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:458
TVirtualHistPainter.h
Float_t
float Float_t
Definition: RtypesCore.h:57
TGraph2D::GetZmin
Double_t GetZmin() const
Returns the Z minimum.
Definition: TGraph2D.cxx:1280
TGraph2D::fMaxIter
Int_t fMaxIter
Maximum number of iterations to find Delaunay triangles.
Definition: TGraph2D.h:48
TGraph2D::GetXmaxE
virtual Double_t GetXmaxE() const
Definition: TGraph2D.h:132
TAxis::GetBinCenter
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:478
TH1::GetBinError
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8518
TVirtualHistPainter::GetContourList
virtual TList * GetContourList(Double_t contour) const =0
ROOT::Fit::FitObject
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:971
TNamed::fName
TString fName
Definition: TNamed.h:38
TObject::AppendPad
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:107
TH1::GetEntries
virtual Double_t GetEntries() const
Return the current number of entries.
Definition: TH1.cxx:4301
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
TAttLine::SaveLineAttributes
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:270
x
Double_t x[n]
Definition: legend1.C:17
TGraph2D::Set
virtual void Set(Int_t n)
Set number of points in the 2D graph.
Definition: TGraph2D.cxx:1576
TGraph2D::fNpy
Int_t fNpy
Number of bins along Y in fHistogram.
Definition: TGraph2D.h:47
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
TGraph2D::Paint
void Paint(Option_t *option="")
Paints this 2D graph with its current attributes.
Definition: TGraph2D.cxx:1342
TGraph2D::SetMinimum
void SetMinimum(Double_t minimum=-1111)
Set minimum.
Definition: TGraph2D.cxx:1671
TList.h
TGraph2D::DirectoryAutoAdd
virtual void DirectoryAutoAdd(TDirectory *)
Perform the automatic addition of the graph to the given directory.
Definition: TGraph2D.cxx:665
TH1::GetListOfFunctions
TList * GetListOfFunctions() const
Definition: TH1.h:240
TMath::Abs
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
TBuffer
Definition: TBuffer.h:43
TString::IsFloat
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
Definition: TString.cxx:1791
TString::Format
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:2311
TGraph2D::GetZmax
Double_t GetZmax() const
Returns the Z maximum.
Definition: TGraph2D.cxx:1269
TGraph2D::GetXmax
Double_t GetXmax() const
Returns the X maximum.
Definition: TGraph2D.cxx:1225
TGraph2D::GetZminE
virtual Double_t GetZminE() const
Definition: TGraph2D.h:137
TString
Definition: TString.h:136
TVirtualFitter.h
TAttFill::SaveFillAttributes
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:234
MinimizerOptions.h
TGraph2D::fZout
Double_t fZout
fHistogram bin height for points lying outside the interpolated area
Definition: TGraph2D.h:56
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
v
@ v
Definition: rootcling_impl.cxx:3635
TGraph2D::fX
Double_t * fX
[fNpoints]
Definition: TGraph2D.h:50
TGraph2D::CreateInterpolator
void CreateInterpolator(Bool_t oldInterp)
Add a TGraphDelaunay in the list of the fHistogram's functions.
Definition: TGraph2D.cxx:1046
b
#define b(i)
Definition: RSha256.hxx:118
h1
TH1F * h1
Definition: legend1.C:5
bool
TString::ReplaceAll
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
TGraph2D::Interpolate
Double_t Interpolate(Double_t x, Double_t y)
Finds the z value at the position (x,y) thanks to the Delaunay interpolation.
Definition: TGraph2D.cxx:1305
TGraph2D::kOldInterpolation
@ kOldInterpolation
Definition: TGraph2D.h:70
TAxis::GetTitle
const char * GetTitle() const
Returns title of object.
Definition: TAxis.h:129
TNamed::fTitle
TString fTitle
Definition: TNamed.h:39
TROOT.h
TH1::SetTitle
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6344
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
TPluginHandler
Definition: TPluginManager.h:101
TGraph2D::fPainter
TVirtualHistPainter * fPainter
!Pointer to histogram painter
Definition: TGraph2D.h:61
TGraph2D::SetDirectory
virtual void SetDirectory(TDirectory *dir)
By default when an 2D graph is created, it is added to the list of 2D graph objects in the current di...
Definition: TGraph2D.cxx:1592
TAttMarker::SaveMarkerAttributes
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:339
TGraphDelaunay.h
TGraph2D::fMinimum
Double_t fMinimum
Minimum value for plotting along z.
Definition: TGraph2D.h:53
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TDirectory::Append
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
Definition: TDirectory.cxx:191
TF2.h
TGraph2D::SetName
virtual void SetName(const char *name)
Changes the name of this 2D graph.
Definition: TGraph2D.cxx:1682
TGraph2D
Definition: TGraph2D.h:41
TBuffer.h
TGraph2D::fDirectory
TDirectory * fDirectory
!Pointer to directory holding this 2D graph
Definition: TGraph2D.h:60
TAttLine
Definition: TAttLine.h:18
TAxis::GetXmin
Double_t GetXmin() const
Definition: TAxis.h:133
TObject::ResetBit
void ResetBit(UInt_t f)
Definition: TObject.h:171
TGraph2D::fNpx
Int_t fNpx
Number of bins along X in fHistogram.
Definition: TGraph2D.h:46
TSystem.h
TFitResultPtr
Definition: TFitResultPtr.h:32
TH1::GetYaxis
TAxis * GetYaxis()
Definition: TH1.h:318
TGraph2D::GetZmaxE
virtual Double_t GetZmaxE() const
Definition: TGraph2D.h:136
TGraph2D::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Saves primitive as a C++ statement(s) on output stream out.
Definition: TGraph2D.cxx:1524
xmin
float xmin
Definition: THbookFile.cxx:95
TGraph2D::fDelaunay
TObject * fDelaunay
! Pointer to Delaunay interpolator object
Definition: TGraph2D.h:59
TGraph2D::fMaximum
Double_t fMaximum
Maximum value for plotting along z.
Definition: TGraph2D.h:54
h
#define h(i)
Definition: RSha256.hxx:124
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
TGraphDelaunay
Definition: TGraphDelaunay.h:30
TGraph2D::GetErrorY
virtual Double_t GetErrorY(Int_t bin) const
This function is called by Graph2DFitChisquare.
Definition: TGraph2D.cxx:1027
TNamed
Definition: TNamed.h:29
TGraph2D::SetMaximum
void SetMaximum(Double_t maximum=-1111)
Set maximum.
Definition: TGraph2D.cxx:1660
TGraph2D::Clear
virtual void Clear(Option_t *option="")
Free all memory allocated by this object.
Definition: TGraph2D.cxx:631
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
TH1::AddDirectory
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition: TH1.cxx:1225
TH2D
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:292
TH1::DistancetoPrimitive
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a line.
Definition: TH1.cxx:2735
TH1::ExecuteEvent
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TH1.cxx:3170
TH1::SetMaximum
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:395
TGraphDelaunay::SetMaxIter
void SetMaxIter(Int_t n=100000)
Defines the number of triangles tested for a Delaunay triangle (number of iterations) before abandoni...
Definition: TGraphDelaunay.cxx:932
TGraph2D::Project
TH1 * Project(Option_t *option="x") const
Projects a 2-d graph into 1 or 2-d histograms depending on the option parameter.
Definition: TGraph2D.cxx:1401
gDirectory
#define gDirectory
Definition: TDirectory.h:236
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3274
TAttMarker
Definition: TAttMarker.h:19
TH2
Definition: TH2.h:30
ROOT::Fit::DataRange
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition: DataRange.h:45
TAxis::GetLast
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:469
ROOT::Math::MinimizerOptions
Minimizer options.
Definition: MinimizerOptions.h:42
TVirtualPad.h
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TGraph2D::TGraph2D
TGraph2D()
Graph2D default constructor.
Definition: TGraph2D.cxx:212
TGraph2D::SetTitle
virtual void SetTitle(const char *title="")
Sets the 2D graph title.
Definition: TGraph2D.cxx:1803
TGraph2D::FitPanel
virtual void FitPanel()
Display a GUI panel with all graph fit options.
Definition: TGraph2D.cxx:939
y
Double_t y[n]
Definition: legend1.C:17
TObject::MakeZombie
void MakeZombie()
Definition: TObject.h:49
TGraph2D::fNpoints
Int_t fNpoints
Number of points in the data set.
Definition: TGraph2D.h:45
TGraph2D::GetYminE
virtual Double_t GetYminE() const
Definition: TGraph2D.h:135
TSystem::ExpandPathName
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1272
TGraph2D::GetErrorX
virtual Double_t GetErrorX(Int_t bin) const
This function is called by Graph2DFitChisquare.
Definition: TGraph2D.cxx:1017
line
TLine * line
Definition: entrylistblock_figure1.C:235
TH2.h
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:876
TGraph2D::Browse
virtual void Browse(TBrowser *)
Browse.
Definition: TGraph2D.cxx:621
TString::IsDigit
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition: TString.cxx:1763
TObject::kCanDelete
@ kCanDelete
if object in a list can be deleted
Definition: TObject.h:58
TObject::kInvalidObject
@ kInvalidObject
if object ctor succeeded but object should not be used
Definition: TObject.h:68
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
ymin
float ymin
Definition: THbookFile.cxx:95
TF2
Definition: TF2.h:29
Printf
void Printf(const char *fmt,...)
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
TGraph2D::SetPoint
virtual void SetPoint(Int_t point, Double_t x, Double_t y, Double_t z)
Sets point number n.
Definition: TGraph2D.cxx:1756
TGraph2D::GetXminE
virtual Double_t GetXminE() const
Definition: TGraph2D.h:133
TPluginHandler::LoadPlugin
Int_t LoadPlugin()
Load the plugin library for this handler.
Definition: TPluginManager.cxx:254
Double_t
double Double_t
Definition: RtypesCore.h:59
TPluginManager.h
ROOT::Fit::kGraph
@ kGraph
Definition: HFitInterface.h:50
TGraphDelaunay2D.h
TGraph2D::GetYmaxE
virtual Double_t GetYmaxE() const
Definition: TGraph2D.h:134
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TObject
Definition: TObject.h:37
TGraph2D::FindObject
virtual TObject * FindObject(const char *name) const
search object named name in the list of functions
Definition: TGraph2D.cxx:741
TGraph2D::SetNpy
void SetNpy(Int_t npx=40)
Sets the number of bins along Y used to draw the function.
Definition: TGraph2D.cxx:1732
TGraph2D::~TGraph2D
virtual ~TGraph2D()
TGraph2D destructor.
Definition: TGraph2D.cxx:530
TH1
Definition: TH1.h:57
TGraph2D::Build
void Build(Int_t n)
Creates the 2D graph basic data structure.
Definition: TGraph2D.cxx:584
name
char name[80]
Definition: TGX11.cxx:110
TDirectory
Definition: TDirectory.h:40
TGraph2D::GetPoint
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y, Double_t &z) const
Get x, y and z values for point number i.
Definition: TGraph2D.cxx:1291
gPad
#define gPad
Definition: TVirtualPad.h:287
TIter
Definition: TCollection.h:233
TGraph2D::SetMarginBinsContent
void SetMarginBinsContent(Double_t z=0.)
Sets the histogram bin height for points lying outside the TGraphDelaunay convex hull ie: the bins in...
Definition: TGraph2D.cxx:1646
TH1::kNoStats
@ kNoStats
don't draw stats box
Definition: TH1.h:161
TH1::GetNbinsY
virtual Int_t GetNbinsY() const
Definition: TH1.h:294
TAttFill
Definition: TAttFill.h:19
TGraph2D::GetYmin
Double_t GetYmin() const
Returns the Y minimum.
Definition: TGraph2D.cxx:1258
TGraph2D::RemovePoint
Int_t RemovePoint(Int_t ipoint)
Deletes point number ipoint.
Definition: TGraph2D.cxx:1488
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
TAxis::GetXmax
Double_t GetXmax() const
Definition: TAxis.h:134
TH1::AddDirectoryStatus
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
Definition: TH1.cxx:705
Class
void Class()
Definition: Class.C:29
TString::ToLower
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
TGraph2D::SetMargin
void SetMargin(Double_t m=0.1)
Sets the extra space (in %) around interpolated area for the 2D histogram.
Definition: TGraph2D.cxx:1626
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:317
TGraph2D::fHistogram
TH2D * fHistogram
!2D histogram of z values linearly interpolated on the triangles
Definition: TGraph2D.h:58
TGraph2D::SetNpx
void SetNpx(Int_t npx=40)
Sets the number of bins along X used to draw the function.
Definition: TGraph2D.cxx:1710
TGraph2D::fUserHisto
Bool_t fUserHisto
Definition: TGraph2D.h:67
TGraph2D::GetHistogram
TH2D * GetHistogram(Option_t *option="")
By default returns a pointer to the Delaunay histogram.
Definition: TGraph2D.cxx:1081
TGraph2D::GetZaxis
TAxis * GetZaxis() const
Get z axis of the graph.
Definition: TGraph2D.cxx:985
TGraph2D::fFunctions
TList * fFunctions
Pointer to list of functions (fits and user)
Definition: TGraph2D.h:57
TGraph2D::SetHistogram
virtual void SetHistogram(TH2 *h)
Sets the histogram to be filled.
Definition: TGraph2D.cxx:1613
TGraph2D::DistancetoPrimitive
Int_t DistancetoPrimitive(Int_t px, Int_t py)
Computes distance from point px,py to a graph.
Definition: TGraph2D.cxx:680
TH1::Paint
virtual void Paint(Option_t *option="")
Control routine to paint any kind of histograms.
Definition: TH1.cxx:5836
TList
Definition: TList.h:44
TGraph2D::GetYaxis
TAxis * GetYaxis() const
Get y axis of the graph.
Definition: TGraph2D.cxx:974
TMath.h
TGraph2D::fMargin
Double_t fMargin
Extra space (in %) around interpolated area for fHistogram.
Definition: TGraph2D.h:55
TH1::GetNbinsX
virtual Int_t GetNbinsX() const
Definition: TH1.h:293
gROOT
#define gROOT
Definition: TROOT.h:406
int
TGraph2D::Print
virtual void Print(Option_t *chopt="") const
Print 2D graph values.
Definition: TGraph2D.cxx:1384
TGraph2D::GetYmax
Double_t GetYmax() const
Returns the Y maximum.
Definition: TGraph2D.cxx:1247
g
#define g(i)
Definition: RSha256.hxx:123