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