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