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