Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
111The Delaunay triangulation algorithm assumes that each (x, y) coordinate corresponds to a unique z value,
112meaning duplicate (x, y) points are not allowed. Consequently, when using drawing options that rely on this
113algorithm (e.g., TRI, SURF, etc.), a warning may appear instructing you to remove duplicates
114(see RemoveDuplicates()).
115
116A TGraph2D can be also drawn with any options valid to draw a 2D histogram
117(like `COL`, `SURF`, `LEGO`, `CONT` etc..).
118
119When a TGraph2D is drawn with one of the 2D histogram drawing option,
120an intermediate 2D histogram is filled using the Delaunay triangles
121to interpolate the data set. The 2D histogram has equidistant bins along the X
122and Y directions. The number of bins along each direction can be change using
123`SetNpx()` and `SetNpy()`. Each bin is filled with the Z
124value found via a linear interpolation on the plane defined by the triangle above
125the (X,Y) coordinates of the bin center.
126
127The existing (X,Y,Z) points can be randomly scattered.
128The Delaunay triangles are build in the (X,Y) plane. These 2D triangles are then
129used to define flat planes in (X,Y,Z) over which the interpolation is done to fill
130the 2D histogram. The 3D triangles int takes build a 3D surface in
131the form of tessellating triangles at various angles. The triangles found can be
132drawn in 3D with one of the TGraph2D specific drawing options.
133
134The histogram generated by the Delaunay interpolation can be accessed using the
135`GetHistogram()` method.
136
137The axis settings (title, ranges etc ...) can be changed accessing the axis via
138the GetXaxis GetYaxis and GetZaxis methods. They access the histogram axis created
139at drawing time only. Therefore they should called after the TGraph2D is drawn:
140
141~~~ {.cpp}
142 auto g = new TGraph2D();
143
144 [...]
145
146 g->Draw("tri1");
147 gPad->Update();
148 g->GetXaxis()->SetTitle("X axis title");
149~~~
150
151\anchor G2D02
152## Examples
153
154\anchor G2D021
155### SURF1 Example
156
157Begin_Macro(source)
158{
159 auto c = new TCanvas("c","Graph2D example",0,0,600,400);
160 Double_t x, y, z, P = 6.;
161 Int_t np = 200;
162 auto dt = new TGraph2D();
163 dt->SetTitle("Graph title; X axis title; Y axis title; Z axis title");
164 auto r = new TRandom();
165 for (Int_t N=0; N<np; N++) {
166 x = 2*P*(r->Rndm(N))-P;
167 y = 2*P*(r->Rndm(N))-P;
168 z = (sin(x)/x)*(sin(y)/y)+0.2;
169 dt->SetPoint(N,x,y,z);
170 }
171 gStyle->SetPalette(1);
172 dt->Draw("surf1");
173}
174End_Macro
175
176\anchor G2D022
177### Fitting Example
178
1792D graphs can be fitted as shown by the following example:
180
181Begin_Macro(source)
182../../../tutorials/math/fit/graph2dfit.C
183End_Macro
184
185\anchor G2D023
186### PCOL Example
187
188Example showing the PCOL option.
189
190Begin_Macro(source)
191{
192 auto c = new TCanvas("c","Graph2D example",0,0,600,400);
193 Double_t P = 5.;
194 Int_t npx = 20 ;
195 Int_t npy = 20 ;
196 Double_t x = -P;
197 Double_t y = -P;
198 Double_t z;
199 Int_t k = 0;
200 Double_t dx = (2*P)/npx;
201 Double_t dy = (2*P)/npy;
202 auto dt = new TGraph2D(npx*npy);
203 dt->SetNpy(41);
204 dt->SetNpx(40);
205 for (Int_t i=0; i<npx; i++) {
206 for (Int_t j=0; j<npy; j++) {
207 z = sin(sqrt(x*x+y*y))+1;
208 dt->SetPoint(k,x,y,z);
209 k++;
210 y = y+dy;
211 }
212 x = x+dx;
213 y = -P;
214 }
215 gStyle->SetPalette(1);
216 dt->SetMarkerStyle(20);
217 dt->Draw("pcol");
218}
219End_Macro
220
221\anchor G2D03
222## Definition of the Delaunay triangulation (After B. Delaunay)
223
224For a set S of points in the Euclidean plane, the unique triangulation DT(S)
225of S such that no point in S is inside the circumcircle of any triangle in
226DT(S). DT(S) is the dual of the Voronoi diagram of S.
227If n is the number of points in S, the Voronoi diagram of S is the partitioning
228of the plane containing S points into n convex polygons such that each polygon
229contains exactly one point and every point in a given polygon is closer to its
230central point than to any other. A Voronoi diagram is sometimes also known as
231a Dirichlet tessellation.
232
233\image html tgraph2d_delaunay.png
234
235[This applet](http://www.cs.cornell.edu/Info/People/chew/Delaunay.html)
236gives a nice practical view of Delaunay triangulation and Voronoi diagram.
237*/
238
239
240////////////////////////////////////////////////////////////////////////////////
241/// Graph2D default constructor
242
244 : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001), fNpoints(0)
245{
246 fSize = 0;
247 fMargin = 0.;
248 fNpx = 40;
249 fNpy = 40;
250 fDirectory = nullptr;
251 fHistogram = nullptr;
252 fDelaunay = nullptr;
253 fMaximum = -1111;
254 fMinimum = -1111;
255 fX = nullptr;
256 fY = nullptr;
257 fZ = nullptr;
258 fZout = 0;
259 fMaxIter = 100000;
260 fPainter = nullptr;
261 fFunctions = new TList;
263}
264
265
266////////////////////////////////////////////////////////////////////////////////
267/// Graph2D constructor with three vectors of ints as input.
268
270 : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001), fNpoints(n)
271{
272 Build(n);
273
274 // Copy the input vectors into local arrays
275 for (Int_t i = 0; i < fNpoints; ++i) {
276 fX[i] = (Double_t)x[i];
277 fY[i] = (Double_t)y[i];
278 fZ[i] = (Double_t)z[i];
279 }
280}
281
282
283////////////////////////////////////////////////////////////////////////////////
284/// Graph2D constructor with three vectors of floats as input.
285
287 : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001), 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), fNpoints(n)
305{
306 Build(n);
307
308 // Copy the input vectors into local arrays
309 for (Int_t i = 0; i < fNpoints; ++i) {
310 fX[i] = x[i];
311 fY[i] = y[i];
312 fZ[i] = z[i];
313 }
314}
315
316
317////////////////////////////////////////////////////////////////////////////////
318/// Graph2D constructor with a TH2 (h2) as input.
319/// Only the h2's bins within the X and Y axis ranges are used.
320/// Empty bins, recognized when both content and errors are zero, are excluded.
321
323 : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001), fNpoints(0)
324{
325 Build(h2->GetNbinsX()*h2->GetNbinsY());
326
327 TString gname = "Graph2D_from_" + TString(h2->GetName());
328 SetName(gname);
329 // need to call later because sets title in ref histogram
330 SetTitle(h2->GetTitle());
331
332 TAxis *xaxis = h2->GetXaxis();
333 TAxis *yaxis = h2->GetYaxis();
334 Int_t xfirst = xaxis->GetFirst();
335 Int_t xlast = xaxis->GetLast();
336 Int_t yfirst = yaxis->GetFirst();
337 Int_t ylast = yaxis->GetLast();
338
339 Double_t x, y, z;
340 Int_t k = 0;
341
342 for (Int_t i = xfirst; i <= xlast; i++) {
343 for (Int_t j = yfirst; j <= ylast; j++) {
344 x = xaxis->GetBinCenter(i);
345 y = yaxis->GetBinCenter(j);
346 z = h2->GetBinContent(i, j);
347 Double_t ez = h2->GetBinError(i, j);
348 if (z != 0. || ez != 0) {
349 SetPoint(k, x, y, z);
350 k++;
351 }
352 }
353 }
354}
355
356
357////////////////////////////////////////////////////////////////////////////////
358/// Graph2D constructor with name, title and three vectors of doubles as input.
359/// name : name of 2D graph (avoid blanks)
360/// title : 2D graph title
361/// if title is of the form "stringt;stringx;stringy;stringz"
362/// the 2D graph title is set to stringt, the x axis title to stringx,
363/// the y axis title to stringy,etc
364
365TGraph2D::TGraph2D(const char *name, const char *title,
367 : TNamed(name, title), TAttLine(1, 1, 1), TAttFill(0, 1001), fNpoints(n)
368{
369 Build(n);
370
371 // Copy the input vectors into local arrays
372 for (Int_t i = 0; i < fNpoints; ++i) {
373 fX[i] = x[i];
374 fY[i] = y[i];
375 fZ[i] = z[i];
376 }
377}
378
379
380////////////////////////////////////////////////////////////////////////////////
381/// Graph2D constructor. The arrays fX, fY and fZ should be filled via
382/// calls to SetPoint
383
385 : TNamed("Graph2D", "Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001), fNpoints(n)
386{
387 Build(n);
388 for (Int_t i = 0; i < fNpoints; i++) {
389 fX[i] = 0.;
390 fY[i] = 0.;
391 fZ[i] = 0.;
392 }
393}
394
395
396////////////////////////////////////////////////////////////////////////////////
397/// Graph2D constructor reading input from filename
398/// filename is assumed to contain at least three columns of numbers.
399/// For files separated by a specific delimiter different from ' ' and '\t' (e.g. ';' in csv files)
400/// you can avoid using %*s to bypass this delimiter by explicitly specify the "option" argument,
401/// e.g. option=" \t,;" for columns of figures separated by any of these characters (' ', '\t', ',', ';')
402/// used once (e.g. "1;1") or in a combined way (" 1;,;; 1").
403/// Note in that case, the instantiation is about 2 times slower.
404
406 : TNamed("Graph2D", filename), TAttLine(1, 1, 1), TAttFill(0, 1001), fNpoints(0)
407{
408 Double_t x, y, z;
411
412 std::ifstream infile(fname.Data());
413 if (!infile.good()) {
414 MakeZombie();
415 Error("TGraph2D", "Cannot open file: %s, TGraph2D is Zombie", filename);
416 return;
417 } else {
418 Build(100);
419 }
420 std::string line;
421 Int_t np = 0;
422
423 if (strcmp(option, "") == 0) { // No delimiters specified (standard constructor).
424
425 while (std::getline(infile, line, '\n')) {
426 if (3 != sscanf(line.c_str(), format, &x, &y, &z)) {
427 continue; // skip empty and ill-formed lines
428 }
429 SetPoint(np, x, y, z);
430 np++;
431 }
432
433 } else { // A delimiter has been specified in "option"
434
435 // Checking format and creating its boolean equivalent
437 format_.ReplaceAll(" ", "") ;
438 format_.ReplaceAll("\t", "") ;
439 format_.ReplaceAll("lg", "") ;
440 format_.ReplaceAll("s", "") ;
441 format_.ReplaceAll("%*", "0") ;
442 format_.ReplaceAll("%", "1") ;
443 if (!format_.IsDigit()) {
444 Error("TGraph2D", "Incorrect input format! Allowed format tags are {\"%%lg\",\"%%*lg\" or \"%%*s\"}");
445 return;
446 }
447 Int_t ntokens = format_.Length() ;
448 if (ntokens < 3) {
449 Error("TGraph2D", "Incorrect input format! Only %d tag(s) in format whereas 3 \"%%lg\" tags are expected!", ntokens);
450 return;
451 }
454 for (Int_t idx = 0; idx < ntokens; idx++) {
455 isTokenToBeSaved[idx] = TString::Format("%c", format_[idx]).Atoi() ; //atoi(&format_[idx]) does not work for some reason...
456 if (isTokenToBeSaved[idx] == 1) {
458 }
459 }
460 if (ntokens >= 3 && ntokensToBeSaved != 3) { //first condition not to repeat the previous error message
461 Error("TGraph2D", "Incorrect input format! There are %d \"%%lg\" tag(s) in format whereas 3 and only 3 are expected!", ntokensToBeSaved);
462 delete [] isTokenToBeSaved ;
463 return;
464 }
465
466 // Initializing loop variables
467 Bool_t isLineToBeSkipped = kFALSE ; //empty and ill-formed lines
468 char * token = nullptr ;
469 TString token_str = "" ;
470 Int_t token_idx = 0 ;
471 Double_t * value = new Double_t [3] ; //x,y,z buffers
472 Int_t value_idx = 0 ;
473
474 // Looping
475 char *rest;
476 while (std::getline(infile, line, '\n')) {
477 if (!line.empty()) {
478 if (line[line.size() - 1] == char(13)) { // removing DOS CR character
479 line.erase(line.end() - 1, line.end()) ;
480 }
481 token = R__STRTOK_R(const_cast<char*>(line.c_str()), option, &rest);
482 while (token != nullptr && value_idx < 3) {
485 token_str.ReplaceAll("\t", "") ;
486 if (!token_str.IsFloat()) {
488 break ;
489 } else {
490 value[value_idx] = token_str.Atof() ;
491 value_idx++ ;
492 }
493 }
494 token = R__STRTOK_R(nullptr, option, &rest); // next token
495 token_idx++ ;
496 }
497 if (!isLineToBeSkipped && value_idx == 3) {
498 x = value[0] ;
499 y = value[1] ;
500 z = value[2] ;
501 SetPoint(np, x, y, z) ;
502 np++ ;
503 }
504 }
506 token = nullptr ;
507 token_idx = 0 ;
508 value_idx = 0 ;
509 }
510
511 // Cleaning
512 delete [] isTokenToBeSaved ;
513 delete [] value ;
514 delete token ;
515 }
516 infile.close();
517}
518
519
520////////////////////////////////////////////////////////////////////////////////
521/// Graph2D copy constructor.
522/// copy everything apart from the list of contained functions
523
526 fX(nullptr), fY(nullptr), fZ(nullptr),
527 fHistogram(nullptr), fDirectory(nullptr), fPainter(nullptr)
528{
529 fFunctions = new TList(); // do not copy the functions
530
531 // use operator=
532 (*this) = g;
533
534 // append TGraph2D to gdirectory
537 if (fDirectory) {
538 // append without replacing existing objects
539 fDirectory->Append(this);
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 // copy the points
588 for (Int_t n = 0; n < fSize; n++) {
589 fX[n] = g.fX[n];
590 fY[n] = g.fY[n];
591 fZ[n] = g.fZ[n];
592 }
593
594 return *this;
595}
596
597////////////////////////////////////////////////////////////////////////////////
598/// Creates the 2D graph basic data structure
599
601{
602 if (n <= 0) {
603 Error("TGraph2D", "Invalid number of points (%d)", n);
604 return;
605 }
606
607 fSize = n;
608 fMargin = 0.;
609 fNpx = 40;
610 fNpy = 40;
611 fDirectory = nullptr;
612 fHistogram = nullptr;
613 fDelaunay = nullptr;
614 fMaximum = -1111;
615 fMinimum = -1111;
616 fX = new Double_t[fSize];
617 fY = new Double_t[fSize];
618 fZ = new Double_t[fSize];
619 fZout = 0;
620 fMaxIter = 100000;
621 fFunctions = new TList;
622 fPainter = nullptr;
624
627 if (fDirectory) {
628 fDirectory->Append(this, kTRUE);
629 }
630 }
631}
632
633////////////////////////////////////////////////////////////////////////////////
634/// Performs the operation: `z = z + c1*f(x,y,z)`
635/// Errors are not recalculated.
636///
637/// \param f may be a 2-D function TF2 or 3-d function TF3
638/// \param c1 a scaling factor, 1 by default
639
641{
642 //if (fHistogram) SetBit(kResetHisto);
643
644 for (Int_t i = 0; i < fNpoints; i++) {
645 fZ[i] += c1*f->Eval(fX[i], fY[i], fZ[i]);
646 }
647 if (gPad) gPad->Modified();
648}
649
650////////////////////////////////////////////////////////////////////////////////
651/// Apply function f to all the data points
652/// f may be a 2-D function TF2 or 3-d function TF3
653/// The Z values of the 2D graph are replaced by the new values computed
654/// using the function
655
657{
658 //if (fHistogram) SetBit(kResetHisto);
659
660 for (Int_t i = 0; i < fNpoints; i++) {
661 fZ[i] = f->Eval(fX[i], fY[i], fZ[i]);
662 }
663 if (gPad) gPad->Modified();
664}
665
666////////////////////////////////////////////////////////////////////////////////
667/// Browse
668
670{
671 Draw("p0");
672 gPad->Update();
673}
674
675
676////////////////////////////////////////////////////////////////////////////////
677/// Free all memory allocated by this object.
678
679void TGraph2D::Clear(Option_t * /*option = "" */)
680{
681 if (fX) delete [] fX;
682 fX = nullptr;
683 if (fY) delete [] fY;
684 fY = nullptr;
685 if (fZ) delete [] fZ;
686 fZ = nullptr;
687 fSize = fNpoints = 0;
688 if (fHistogram && !fUserHisto) {
689 delete fHistogram;
690 fHistogram = nullptr;
691 fDelaunay = nullptr;
692 }
693 if (fFunctions) {
696 delete fFunctions;
697 fFunctions = nullptr;
698 }
699 if (fDirectory) {
700 fDirectory->Remove(this);
701 fDirectory = nullptr;
702 }
703}
704
705
706////////////////////////////////////////////////////////////////////////////////
707/// Perform the automatic addition of the graph to the given directory
708///
709/// Note this function is called in place when the semantic requires
710/// this object to be added to a directory (I.e. when being read from
711/// a TKey or being Cloned)
712
714{
716 if (addStatus) {
717 SetDirectory(dir);
718 if (dir) {
720 }
721 }
722}
723
724
725////////////////////////////////////////////////////////////////////////////////
726/// Computes distance from point px,py to a graph
727
734
735
736////////////////////////////////////////////////////////////////////////////////
737/// Specific drawing options can be used to paint a TGraph2D:
738///
739/// - "TRI" : The Delaunay triangles are drawn using filled area.
740/// An hidden surface drawing technique is used. The surface is
741/// painted with the current fill area color. The edges of each
742/// triangles are painted with the current line color.
743/// - "TRIW" : The Delaunay triangles are drawn as wire frame
744/// - "TRI1" : The Delaunay triangles are painted with color levels. The edges
745/// of each triangles are painted with the current line color.
746/// - "TRI2" : the Delaunay triangles are painted with color levels.
747/// - "P" : Draw a marker at each vertex
748/// - "P0" : Draw a circle at each vertex. Each circle background is white.
749/// - "PCOL" : Draw a marker at each vertex. The color of each marker is
750/// defined according to its Z position.
751/// - "CONT" : Draw contours
752/// - "LINE" : Draw a 3D polyline
753///
754/// A TGraph2D can be also drawn with ANY options valid to draw a 2D histogram.
755///
756/// When a TGraph2D is drawn with one of the 2D histogram drawing option,
757/// a intermediate 2D histogram is filled using the Delaunay triangles
758/// technique to interpolate the data set.
759
761{
762 TString opt = option;
763 opt.ToLower();
764 if (gPad) {
765 if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
766 if (!opt.Contains("same")) {
767 //the following statement is necessary in case one attempts to draw
768 //a temporary histogram already in the current pad
769 if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
770 gPad->Clear();
771 }
772 }
773 AppendPad(opt.Data());
774}
775
776
777////////////////////////////////////////////////////////////////////////////////
778/// Executes action corresponding to one event
779
781{
782 if (fHistogram) fHistogram->ExecuteEvent(event, px, py);
783}
784
785
786////////////////////////////////////////////////////////////////////////////////
787/// search object named name in the list of functions
788
790{
791 return fFunctions ? fFunctions->FindObject(name) : nullptr;
792}
793
794
795////////////////////////////////////////////////////////////////////////////////
796/// search object obj in the list of functions
797
799{
800 return fFunctions ? fFunctions->FindObject(obj) : nullptr;
801}
802
803
804////////////////////////////////////////////////////////////////////////////////
805/// Fits this graph with function with name fname
806/// Predefined functions such as gaus, expo and poln are automatically
807/// created by ROOT.
808/// fname can also be a formula, accepted by the linear fitter (linear parts divided
809/// by "++" sign), for example "x++sin(y)" for fitting "[0]*x+[1]*sin(y)"
810
812{
813
814 char *linear;
815 linear = (char*)strstr(fname, "++");
816
817 if (linear) {
818 TF2 f2(fname, fname);
819 return Fit(&f2, option, "");
820 }
821 TF2 * f2 = (TF2*)gROOT->GetFunction(fname);
822 if (!f2) {
823 Printf("Unknown function: %s", fname);
824 return -1;
825 }
826 return Fit(f2, option, "");
827
828}
829
830
831////////////////////////////////////////////////////////////////////////////////
832/// Fits this 2D graph with function f2
833///
834/// f2 is an already predefined function created by TF2.
835///
836/// See TGraph::Fit for the available fitting options and fitting notes
837///
839{
840 // internal graph2D fitting methods
842 Option_t *goption = "";
844
845 // create range and minimizer options with default values
849}
850
851
852////////////////////////////////////////////////////////////////////////////////
853/// Display a GUI panel with all graph fit options.
854///
855/// See class TFitEditor for example
856
858{
859 if (!gPad)
860 gROOT->MakeDefCanvas();
861
862 if (!gPad) {
863 Error("FitPanel", "Unable to create a default canvas");
864 return;
865 }
866
867 // use plugin manager to create instance of TFitEditor
868 TPluginHandler *handler = gROOT->GetPluginManager()->FindHandler("TFitEditor");
869 if (handler && handler->LoadPlugin() != -1) {
870 if (handler->ExecPlugin(2, gPad, this) == 0)
871 Error("FitPanel", "Unable to crate the FitPanel");
872 } else
873 Error("FitPanel", "Unable to find the FitPanel plug-in");
874
875}
876
877
878////////////////////////////////////////////////////////////////////////////////
879/// Get x axis of the graph.
880
882{
883 TH1 *h = ((TGraph2D*)this)->GetHistogram("empty");
884 if (!h) return nullptr;
885 return h->GetXaxis();
886}
887
888
889////////////////////////////////////////////////////////////////////////////////
890/// Get y axis of the graph.
891
893{
894 TH1 *h = ((TGraph2D*)this)->GetHistogram("empty");
895 if (!h) return nullptr;
896 return h->GetYaxis();
897}
898
899
900////////////////////////////////////////////////////////////////////////////////
901/// Get z axis of the graph.
902
904{
905 TH1 *h = ((TGraph2D*)this)->GetHistogram("empty");
906 if (!h) return nullptr;
907 return h->GetZaxis();
908}
909
910
911////////////////////////////////////////////////////////////////////////////////
912/// Returns the X and Y graphs building a contour. A contour level may
913/// consist in several parts not connected to each other. This function
914/// returns them in a graphs' list.
915
917{
918 if (fNpoints <= 0) {
919 Error("GetContourList", "Empty TGraph2D");
920 return nullptr;
921 }
922
923 if (!fHistogram) GetHistogram("empty");
924
926
927 return fPainter->GetContourList(contour);
928}
929
930
931////////////////////////////////////////////////////////////////////////////////
932/// This function is called by Graph2DFitChisquare.
933/// It always returns a negative value. Real implementation in TGraph2DErrors
934
936{
937 return -1;
938}
939
940
941////////////////////////////////////////////////////////////////////////////////
942/// This function is called by Graph2DFitChisquare.
943/// It always returns a negative value. Real implementation in TGraph2DErrors
944
946{
947 return -1;
948}
949
950
951////////////////////////////////////////////////////////////////////////////////
952/// This function is called by Graph2DFitChisquare.
953/// It always returns a negative value. Real implementation in TGraph2DErrors
954
956{
957 return -1;
958}
959
960
961////////////////////////////////////////////////////////////////////////////////
962/// Add a TGraphDelaunay in the list of the fHistogram's functions
963
965{
966
968
969 if (oldInterp) {
970 TGraphDelaunay *dt = new TGraphDelaunay(this);
971 dt->SetMaxIter(fMaxIter);
972 dt->SetMarginBinsContent(fZout);
973 fDelaunay = dt;
975 if (!hl->FindObject("TGraphDelaunay")) hl->Add(fDelaunay);
976 } else {
978 dt->SetMarginBinsContent(fZout);
979 fDelaunay = dt;
981 if (!hl->FindObject("TGraphDelaunay2D")) hl->Add(fDelaunay);
982 }
983}
984
985////////////////////////////////////////////////////////////////////////////////
986/// Return pointer to function with name.
987///
988/// Functions such as TGraph2D::Fit store the fitted function in the list of
989/// functions of this graph.
990
991TF2 *TGraph2D::GetFunction(const char *name) const
992{
993 return dynamic_cast<TF2*>(FindObject(name));
994}
995
996////////////////////////////////////////////////////////////////////////////////
997/// By default returns a pointer to the Delaunay histogram. If fHistogram
998/// doesn't exist, books the 2D histogram fHistogram with a margin around
999/// the hull. Calls TGraphDelaunay::Interpolate at each bin centre to build up
1000/// an interpolated 2D histogram.
1001///
1002/// If the "empty" option is selected, returns an empty histogram booked with
1003/// the limits of fX, fY and fZ. This option is used when the data set is
1004/// drawn with markers only. In that particular case there is no need to
1005/// find the Delaunay triangles.
1006///
1007/// By default use the new interpolation routine based on Triangles
1008/// If the option "old" the old interpolation is used
1009
1011{
1012 // for an empty graph create histogram in [0,1][0,1]
1013 if (fNpoints <= 0) {
1014 if (!fHistogram) {
1015 // do not add the histogram to gDirectory
1016 TDirectory::TContext ctx(nullptr);
1017 fHistogram = new TH2D(GetName(), GetTitle(), fNpx , 0., 1., fNpy, 0., 1.);
1019 }
1020 return fHistogram;
1021 }
1022
1023 TString opt = option;
1024 opt.ToLower();
1025 Bool_t empty = opt.Contains("empty");
1026 Bool_t oldInterp = opt.Contains("old");
1027
1028 if (fHistogram) {
1029 if (!empty && fHistogram->GetEntries() == 0) {
1030 if (!fUserHisto) {
1031 delete fHistogram;
1032 fHistogram = nullptr;
1033 fDelaunay = nullptr;
1034 }
1035 } else if (fHistogram->GetEntries() == 0)
1036 {; }
1037 // check case if interpolation type has changed
1038 else if ( (TestBit(kOldInterpolation) && !oldInterp) || ( !TestBit(kOldInterpolation) && oldInterp ) ) {
1039 delete fHistogram;
1040 fHistogram = nullptr;
1041 fDelaunay = nullptr;
1042 }
1043 // normal case return existing histogram
1044 else {
1045 return fHistogram;
1046 }
1047 }
1048
1050
1051 // Book fHistogram if needed. It is not added in the current directory
1052 if (!fUserHisto) {
1057 hxmin = xmin - fMargin * (xmax - xmin);
1058 hymin = ymin - fMargin * (ymax - ymin);
1059 hxmax = xmax + fMargin * (xmax - xmin);
1060 hymax = ymax + fMargin * (ymax - ymin);
1061 Double_t epsilon = 1e-9;
1062 if (TMath::AreEqualRel(hxmax,hxmin,epsilon)) {
1063 if (TMath::Abs(hxmin) < epsilon) {
1064 hxmin = -0.001;
1065 hxmax = 0.001;
1066 } else {
1067 hxmin = hxmin-TMath::Abs(hxmin)*(epsilon/2.);
1068 hxmax = hxmax+TMath::Abs(hxmax)*(epsilon/2.);
1069 }
1070 }
1071 if (TMath::AreEqualRel(hymax, hymin, epsilon)) {
1072 if (TMath::Abs(hymin) < epsilon) {
1073 hymin = -0.001;
1074 hymax = 0.001;
1075 } else {
1076 hymin = hymin-TMath::Abs(hymin)*(epsilon/2.);
1077 hymax = hymax+TMath::Abs(hymax)*(epsilon/2.);
1078 }
1079 }
1080 if (fHistogram) {
1083 } else {
1084 TDirectory::TContext ctx(nullptr); // to avoid adding fHistogram to gDirectory
1085 fHistogram = new TH2D(GetName(), GetTitle(),
1086 fNpx , hxmin, hxmax,
1087 fNpy, hymin, hymax);
1089 }
1092 } else {
1097 }
1098
1099 // Option "empty" is selected. An empty histogram is returned.
1101 if (empty) {
1102 if (fMinimum != -1111) {
1103 hzmin = fMinimum;
1104 } else {
1105 hzmin = GetZminE();
1106 }
1107 if (fMaximum != -1111) {
1108 hzmax = fMaximum;
1109 } else {
1110 hzmax = GetZmaxE();
1111 }
1112 if (hzmin == hzmax) {
1113 Double_t hz = hzmin;
1114 if (hz==0) {
1115 hzmin = -0.01;
1116 hzmax = 0.01;
1117 } else {
1118 hzmin = hz - 0.01 * TMath::Abs(hz);
1119 hzmax = hz + 0.01 * TMath::Abs(hz);
1120 }
1121 }
1124 return fHistogram;
1125 }
1126
1127 Double_t dx = (hxmax - hxmin) / fNpx;
1128 Double_t dy = (hymax - hymin) / fNpy;
1129
1130 Double_t x, y, z;
1131
1132 for (Int_t ix = 1; ix <= fNpx; ix++) {
1133 x = hxmin + (ix - 0.5) * dx;
1134 for (Int_t iy = 1; iy <= fNpy; iy++) {
1135 y = hymin + (iy - 0.5) * dy;
1136 // do interpolation
1137 if (oldInterp)
1138 z = ((TGraphDelaunay*)fDelaunay)->ComputeZ(x, y);
1139 else
1140 z = ((TGraphDelaunay2D*)fDelaunay)->ComputeZ(x, y);
1141
1142 fHistogram->Fill(x, y, z);
1143 }
1144 }
1145
1146 hzmin = GetZminE();
1147 hzmax = GetZmaxE();
1150
1151 if (fMinimum != -1111) fHistogram->SetMinimum(fMinimum);
1152 if (fMaximum != -1111) fHistogram->SetMaximum(fMaximum);
1153
1154 return fHistogram;
1155}
1156
1157
1158////////////////////////////////////////////////////////////////////////////////
1159/// Returns the X maximum
1160
1162{
1163 Double_t v = fX[0];
1164 for (Int_t i = 1; i < fNpoints; i++) if (fX[i] > v) v = fX[i];
1165 return v;
1166}
1167
1168
1169////////////////////////////////////////////////////////////////////////////////
1170/// Returns the X minimum
1171
1173{
1174 Double_t v = fX[0];
1175 for (Int_t i = 1; i < fNpoints; i++) if (fX[i] < v) v = fX[i];
1176 return v;
1177}
1178
1179
1180////////////////////////////////////////////////////////////////////////////////
1181/// Returns the Y maximum
1182
1184{
1185 Double_t v = fY[0];
1186 for (Int_t i = 1; i < fNpoints; i++) if (fY[i] > v) v = fY[i];
1187 return v;
1188}
1189
1190
1191////////////////////////////////////////////////////////////////////////////////
1192/// Returns the Y minimum
1193
1195{
1196 Double_t v = fY[0];
1197 for (Int_t i = 1; i < fNpoints; i++) if (fY[i] < v) v = fY[i];
1198 return v;
1199}
1200
1201
1202////////////////////////////////////////////////////////////////////////////////
1203/// Returns the Z maximum
1204
1206{
1207 Double_t v = fZ[0];
1208 for (Int_t i = 1; i < fNpoints; i++) if (fZ[i] > v) v = fZ[i];
1209 return v;
1210}
1211
1212
1213////////////////////////////////////////////////////////////////////////////////
1214/// Returns the Z minimum
1215
1217{
1218 Double_t v = fZ[0];
1219 for (Int_t i = 1; i < fNpoints; i++) if (fZ[i] < v) v = fZ[i];
1220 return v;
1221}
1222
1223////////////////////////////////////////////////////////////////////////////////
1224/// Get x, y and z values for point number i.
1225/// The function returns -1 in case of an invalid request or the point number otherwise
1226
1228{
1229 if (i < 0 || i >= fNpoints) return -1;
1230 if (!fX || !fY || !fZ) return -1;
1231 x = fX[i];
1232 y = fY[i];
1233 z = fZ[i];
1234 return i;
1235}
1236
1237////////////////////////////////////////////////////////////////////////////////
1238/// Finds the z value at the position (x,y) thanks to
1239/// the Delaunay interpolation.
1240
1242{
1243 if (fNpoints <= 0) {
1244 Error("Interpolate", "Empty TGraph2D");
1245 return 0;
1246 }
1247
1248 if (!fHistogram) GetHistogram("empty");
1249 if (!fDelaunay) {
1251 if (!TestBit(kOldInterpolation) ) {
1252 fDelaunay = hl->FindObject("TGraphDelaunay2D");
1253 if (!fDelaunay) fDelaunay = hl->FindObject("TGraphDelaunay");
1254 }
1255 else {
1256 // if using old implementation
1257 fDelaunay = hl->FindObject("TGraphDelaunay");
1258 if (!fDelaunay) fDelaunay = hl->FindObject("TGraphDelaunay2D");
1259 }
1260 }
1261
1262 if (!fDelaunay) return TMath::QuietNaN();
1263
1265 return ((TGraphDelaunay2D*)fDelaunay)->ComputeZ(x, y);
1266 else if (fDelaunay->IsA() == TGraphDelaunay::Class() )
1267 return ((TGraphDelaunay*)fDelaunay)->ComputeZ(x, y);
1268
1269 // cannot be here
1270 assert(false);
1271 return TMath::QuietNaN();
1272}
1273
1274
1275////////////////////////////////////////////////////////////////////////////////
1276/// Paints this 2D graph with its current attributes
1277
1279{
1280 if (fNpoints <= 0) {
1281 Error("Paint", "Empty TGraph2D");
1282 return;
1283 }
1284
1285 TString opt = option;
1286 opt.ToLower();
1287 if (opt.Contains("p") && !opt.Contains("tri")) {
1288 if (!opt.Contains("pol") &&
1289 !opt.Contains("sph") &&
1290 !opt.Contains("psr")) opt.Append("tri0");
1291 }
1292
1293 if (opt.Contains("line") && !opt.Contains("tri")) opt.Append("tri0");
1294
1295 if (opt.Contains("err") && !opt.Contains("tri")) opt.Append("tri0");
1296
1297 if (opt.Contains("tri0")) {
1298 GetHistogram("empty");
1299 } else if (opt.Contains("old")) {
1300 GetHistogram("old");
1301 } else {
1302 GetHistogram();
1303 }
1304
1313 fHistogram->Paint(opt.Data());
1314}
1315
1316
1317////////////////////////////////////////////////////////////////////////////////
1318/// Print 2D graph values.
1319
1321{
1322 for (Int_t i = 0; i < fNpoints; i++) {
1323 printf("x[%d]=%g, y[%d]=%g, z[%d]=%g\n", i, fX[i], i, fY[i], i, fZ[i]);
1324 }
1325}
1326
1327
1328////////////////////////////////////////////////////////////////////////////////
1329/// Projects a 2-d graph into 1 or 2-d histograms depending on the option parameter.
1330/// option may contain a combination of the characters x,y,z:
1331///
1332/// - option = "x" return the x projection into a TH1D histogram
1333/// - option = "y" return the y projection into a TH1D histogram
1334/// - option = "xy" return the x versus y projection into a TH2D histogram
1335/// - option = "yx" return the y versus x projection into a TH2D histogram
1336
1338{
1339 if (fNpoints <= 0) {
1340 Error("Project", "Empty TGraph2D");
1341 return nullptr;
1342 }
1343
1344 TString opt = option;
1345 opt.ToLower();
1346
1347 Int_t pcase = 0;
1348 if (opt.Contains("x")) pcase = 1;
1349 if (opt.Contains("y")) pcase = 2;
1350 if (opt.Contains("xy")) pcase = 3;
1351 if (opt.Contains("yx")) pcase = 4;
1352
1353 // Create the projection histogram
1354 TH1D *h1 = nullptr;
1355 TH2D *h2 = nullptr;
1356 Int_t nch = strlen(GetName()) + opt.Length() + 2;
1357 char *name = new char[nch];
1358 snprintf(name, nch, "%s_%s", GetName(), option);
1359 nch = strlen(GetTitle()) + opt.Length() + 2;
1360 char *title = new char[nch];
1361 snprintf(title, nch, "%s_%s", GetTitle(), option);
1362
1367
1368 switch (pcase) {
1369 case 1:
1370 // "x"
1371 h1 = new TH1D(name, title, fNpx, hxmin, hxmax);
1372 break;
1373 case 2:
1374 // "y"
1375 h1 = new TH1D(name, title, fNpy, hymin, hymax);
1376 break;
1377 case 3:
1378 // "xy"
1379 h2 = new TH2D(name, title, fNpx, hxmin, hxmax, fNpy, hymin, hymax);
1380 break;
1381 case 4:
1382 // "yx"
1383 h2 = new TH2D(name, title, fNpy, hymin, hymax, fNpx, hxmin, hxmax);
1384 break;
1385 }
1386
1387 delete [] name;
1388 delete [] title;
1389 TH1 *h = h1;
1390 if (h2) h = h2;
1391 if (h == nullptr) return nullptr;
1392
1393 // Fill the projected histogram
1394 Double_t entries = 0;
1395 for (Int_t n = 0; n < fNpoints; n++) {
1396 switch (pcase) {
1397 case 1:
1398 // "x"
1399 h1->Fill(fX[n], fZ[n]);
1400 break;
1401 case 2:
1402 // "y"
1403 h1->Fill(fY[n], fZ[n]);
1404 break;
1405 case 3:
1406 // "xy"
1407 h2->Fill(fX[n], fY[n], fZ[n]);
1408 break;
1409 case 4:
1410 // "yx"
1411 h2->Fill(fY[n], fX[n], fZ[n]);
1412 break;
1413 }
1414 entries += fZ[n];
1415 }
1416 h->SetEntries(entries);
1417 return h;
1418}
1419
1420
1421////////////////////////////////////////////////////////////////////////////////
1422/// Deletes duplicated points.
1423///
1424/// The Delaunay triangulation algorithm assumes that each (x, y) coordinate corresponds to a unique z value,
1425/// meaning duplicate (x, y) points are not allowed. Consequently, when using drawing options that rely on this
1426/// algorithm (e.g., TRI, SURF, etc.), a warning may appear instructing you to remove duplicates.
1427/// This function provides a way to handle such duplicates.
1428///
1429/// Example:
1430/// ~~~ {.cpp}
1431/// g->RemoveDuplicates();
1432/// g->Draw("TRI1");
1433/// ~~~
1434
1436{
1437 for (int i = 0; i < fNpoints; i++) {
1438 double x = fX[i];
1439 double y = fY[i];
1440 for (int j = i + 1; j < fNpoints; j++) {
1441 if (x == fX[j] && y == fY[j]) {
1442 RemovePoint(j);
1443 j--;
1444 }
1445 }
1446 }
1447
1448 return fNpoints;
1449}
1450
1451
1452////////////////////////////////////////////////////////////////////////////////
1453/// Recursively remove object from the list of functions
1454
1456{
1457 if (fFunctions) {
1460 }
1461 if (fHistogram == obj)
1462 fHistogram = nullptr;
1463}
1464
1465
1466////////////////////////////////////////////////////////////////////////////////
1467/// Deletes point number ipoint
1468
1470{
1471 if (ipoint < 0) return -1;
1472 if (ipoint >= fNpoints) return -1;
1473 for (Int_t i = ipoint; i < fNpoints - 1; i++) {
1474 fX[i] = fX[i+1];
1475 fY[i] = fY[i+1];
1476 fZ[i] = fZ[i+1];
1477 }
1478 fNpoints--;
1479 if (fHistogram) {
1480 delete fHistogram;
1481 fHistogram = nullptr;
1482 fDelaunay = nullptr;
1483 }
1484 return ipoint;
1485}
1486
1487
1488////////////////////////////////////////////////////////////////////////////////
1489/// Saves primitive as a C++ statement(s) on output stream out
1490
1491void TGraph2D::SavePrimitive(std::ostream &out, Option_t *option)
1492{
1493 TString arrx = SavePrimitiveVector(out, "graph2d_x", fNpoints, fX, kTRUE);
1494 TString arry = SavePrimitiveVector(out, "graph2d_y", fNpoints, fY);
1495 TString arrz = SavePrimitiveVector(out, "graph2d_z", fNpoints, fZ);
1496
1497 SavePrimitiveConstructor(out, Class(), "graph2d",
1498 TString::Format("%d, %s.data(), %s.data(), %s.data()", fNpoints, arrx.Data(), arry.Data(), arrz.Data()), kFALSE);
1499
1500 if (strcmp(GetName(), "Graph2D"))
1501 out << " graph2d->SetName(\"" << TString(GetName()).ReplaceSpecialCppChars() << "\");\n";
1502
1503 TString title = GetTitle();
1504 if (fHistogram)
1505 title = TString(fHistogram->GetTitle()) + ";" + fHistogram->GetXaxis()->GetTitle() + ";" +
1507
1508 out << " graph2d->SetTitle(\"" << title.ReplaceSpecialCppChars() << "\");\n";
1509
1510 if (!fDirectory)
1511 out << " graph2d->SetDirectory(nullptr);\n";
1512
1513 SaveFillAttributes(out, "graph2d", 0, 1001);
1514 SaveLineAttributes(out, "graph2d", 1, 1, 1);
1515 SaveMarkerAttributes(out, "graph2d", 1, 1, 1);
1516
1517 TH1::SavePrimitiveFunctions(out, "graph2d", fFunctions);
1518
1519 SavePrimitiveDraw(out, "graph2d", option);
1520}
1521
1522////////////////////////////////////////////////////////////////////////////////
1523/// Multiply the values of a TGraph2D by a constant c1.
1524///
1525/// If option contains "x" the x values are scaled
1526/// If option contains "y" the y values are scaled
1527/// If option contains "z" the z values are scaled
1528/// If option contains "xyz" all three x, y and z values are scaled
1529
1531{
1532 TString opt = option; opt.ToLower();
1533 if (opt.Contains("x")) {
1534 for (Int_t i=0; i<GetN(); i++)
1535 GetX()[i] *= c1;
1536 }
1537 if (opt.Contains("y")) {
1538 for (Int_t i=0; i<GetN(); i++)
1539 GetY()[i] *= c1;
1540 }
1541 if (opt.Contains("z")) {
1542 for (Int_t i=0; i<GetN(); i++)
1543 GetZ()[i] *= c1;
1544 }
1545}
1546
1547////////////////////////////////////////////////////////////////////////////////
1548/// Set number of points in the 2D graph.
1549/// Existing coordinates are preserved.
1550/// New coordinates above fNpoints are preset to 0.
1551
1553{
1554 if (n < 0) n = 0;
1555 if (n == fNpoints) return;
1556 if (n > fNpoints) SetPoint(n, 0, 0, 0);
1557 fNpoints = n;
1558}
1559
1560
1561////////////////////////////////////////////////////////////////////////////////
1562/// By default when an 2D graph is created, it is added to the list
1563/// of 2D graph objects in the current directory in memory.
1564/// This method removes reference to this 2D graph from current directory and add
1565/// reference to new directory dir. dir can be 0 in which case the
1566/// 2D graph does not belong to any directory.
1567
1569{
1570 if (fDirectory == dir) return;
1571 if (fDirectory) fDirectory->Remove(this);
1572 fDirectory = dir;
1573 if (fDirectory) fDirectory->Append(this);
1574}
1575
1576
1577////////////////////////////////////////////////////////////////////////////////
1578/// Sets the histogram to be filled.
1579/// If the 2D graph needs to be save in a TFile the following set should be
1580/// followed to read it back:
1581/// 1. Create TGraph2D
1582/// 2. Call g->SetHistogram(h), and do whatever you need to do
1583/// 3. Save g and h to the TFile, exit
1584/// 4. Open the TFile, retrieve g and h
1585/// 5. Call h->SetDirectory(0)
1586/// 6. Call g->SetHistogram(h) again
1587/// 7. Carry on as normal
1588///
1589/// By default use the new interpolation routine based on Triangles
1590/// If the option "old" the old interpolation is used
1591
1593{
1594 TString opt = option;
1595 opt.ToLower();
1596 Bool_t oldInterp = opt.Contains("old");
1597
1598 fUserHisto = kTRUE;
1599 fHistogram = (TH2D*)h;
1600 fNpx = h->GetNbinsX();
1601 fNpy = h->GetNbinsY();
1603}
1604
1605
1606////////////////////////////////////////////////////////////////////////////////
1607/// Sets the extra space (in %) around interpolated area for the 2D histogram
1608
1610{
1611 if (m < 0 || m > 1) {
1612 Warning("SetMargin", "The margin must be >= 0 && <= 1, fMargin set to 0.1");
1613 fMargin = 0.1;
1614 } else {
1615 fMargin = m;
1616 }
1617 if (fHistogram) {
1618 delete fHistogram;
1619 fHistogram = nullptr;
1620 fDelaunay = nullptr;
1621 }
1622}
1623
1624
1625////////////////////////////////////////////////////////////////////////////////
1626/// Sets the histogram bin height for points lying outside the TGraphDelaunay
1627/// convex hull ie: the bins in the margin.
1628
1630{
1631 fZout = z;
1632 if (fHistogram) {
1633 delete fHistogram;
1634 fHistogram = nullptr;
1635 fDelaunay = nullptr;
1636 }
1637}
1638
1639
1640////////////////////////////////////////////////////////////////////////////////
1641/// Set maximum.
1642
1644{
1645 fMaximum = maximum;
1646 TH1 * h = GetHistogram();
1647 if (h) h->SetMaximum(maximum);
1648}
1649
1650
1651////////////////////////////////////////////////////////////////////////////////
1652/// Set minimum.
1653
1655{
1656 fMinimum = minimum;
1657 TH1 * h = GetHistogram();
1658 if (h) h->SetMinimum(minimum);
1659}
1660
1661
1662////////////////////////////////////////////////////////////////////////////////
1663/// Changes the name of this 2D graph
1664
1665void TGraph2D::SetName(const char *name)
1666{
1667 // 2D graphs are named objects in a THashList.
1668 // We must update the hashlist if we change the name
1669 if (fDirectory) fDirectory->Remove(this);
1670 fName = name;
1671 if (fDirectory) fDirectory->Append(this);
1672}
1673
1674
1675////////////////////////////////////////////////////////////////////////////////
1676/// Change the name and title of this 2D graph
1677///
1678
1679void TGraph2D::SetNameTitle(const char *name, const char *title)
1680{
1681 // 2D graphs are named objects in a THashList.
1682 // We must update the hashlist if we change the name
1683 if (fDirectory) fDirectory->Remove(this);
1684 fName = name;
1685 SetTitle(title);
1686 if (fDirectory) fDirectory->Append(this);
1687}
1688
1689
1690////////////////////////////////////////////////////////////////////////////////
1691/// Sets the number of bins along X used to draw the function
1692
1694{
1695 if (npx < 4) {
1696 Warning("SetNpx", "Number of points must be >4 && < 500, fNpx set to 4");
1697 fNpx = 4;
1698 } else if (npx > 500) {
1699 Warning("SetNpx", "Number of points must be >4 && < 500, fNpx set to 500");
1700 fNpx = 500;
1701 } else {
1702 fNpx = npx;
1703 }
1704 if (fHistogram) {
1705 delete fHistogram;
1706 fHistogram = nullptr;
1707 fDelaunay = nullptr;
1708 }
1709}
1710
1711
1712////////////////////////////////////////////////////////////////////////////////
1713/// Sets the number of bins along Y used to draw the function
1714
1716{
1717 if (npy < 4) {
1718 Warning("SetNpy", "Number of points must be >4 && < 500, fNpy set to 4");
1719 fNpy = 4;
1720 } else if (npy > 500) {
1721 Warning("SetNpy", "Number of points must be >4 && < 500, fNpy set to 500");
1722 fNpy = 500;
1723 } else {
1724 fNpy = npy;
1725 }
1726 if (fHistogram) {
1727 delete fHistogram;
1728 fHistogram = nullptr;
1729 fDelaunay = nullptr;
1730 }
1731}
1732
1733
1734////////////////////////////////////////////////////////////////////////////////
1735/// Sets point number n.
1736/// If n is greater than the current size, the arrays are automatically
1737/// extended.
1738
1740{
1741 if (n < 0) return;
1742
1743 if (!fX || !fY || !fZ || n >= fSize) {
1744 // re-allocate the object
1745 Int_t newN = TMath::Max(2 * fSize, n + 1);
1746 Double_t *savex = new Double_t [newN];
1747 Double_t *savey = new Double_t [newN];
1748 Double_t *savez = new Double_t [newN];
1749 if (fX && fSize) {
1750 memcpy(savex, fX, fSize * sizeof(Double_t));
1751 memset(&savex[fSize], 0, (newN - fSize)*sizeof(Double_t));
1752 delete [] fX;
1753 }
1754 if (fY && fSize) {
1755 memcpy(savey, fY, fSize * sizeof(Double_t));
1756 memset(&savey[fSize], 0, (newN - fSize)*sizeof(Double_t));
1757 delete [] fY;
1758 }
1759 if (fZ && fSize) {
1760 memcpy(savez, fZ, fSize * sizeof(Double_t));
1761 memset(&savez[fSize], 0, (newN - fSize)*sizeof(Double_t));
1762 delete [] fZ;
1763 }
1764 fX = savex;
1765 fY = savey;
1766 fZ = savez;
1767 fSize = newN;
1768 }
1769 fX[n] = x;
1770 fY[n] = y;
1771 fZ[n] = z;
1772 fNpoints = TMath::Max(fNpoints, n + 1);
1773}
1774
1775
1776////////////////////////////////////////////////////////////////////////////////
1777/// Sets the 2D graph title.
1778///
1779/// This method allows to change the global title and the axis' titles of a 2D
1780/// graph. If `g` is the 2D graph one can do:
1781///
1782/// ~~~ {.cpp}
1783/// g->SetTitle("Graph title; X axis title; Y axis title; Z axis title");
1784/// ~~~
1785
1786void TGraph2D::SetTitle(const char* title)
1787{
1788 fTitle = title;
1789 if (fHistogram) fHistogram->SetTitle(title);
1790}
1791
1792
1793////////////////////////////////////////////////////////////////////////////////
1794/// Stream a class object
1795
1797{
1798 if (b.IsReading()) {
1799 UInt_t R__s, R__c;
1800 Version_t R__v = b.ReadVersion(&R__s, &R__c);
1801 b.ReadClassBuffer(TGraph2D::Class(), this, R__v, R__s, R__c);
1802
1804 } else {
1805 b.WriteClassBuffer(TGraph2D::Class(), this);
1806 }
1807}
#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:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#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:572
#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:20
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:31
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:32
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:38
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:40
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:20
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:35
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:44
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:37
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:42
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:36
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:20
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:33
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:39
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:32
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition TAttMarker.h:34
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:41
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:46
Class to manage histogram axis.
Definition TAxis.h:32
const char * GetTitle() const override
Returns title of object.
Definition TAxis.h:137
Double_t GetXmax() const
Definition TAxis.h:142
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition TAxis.h:166
Double_t GetXmin() const
Definition TAxis.h:141
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
TF2 * GetFunction(const char *name) const
Return pointer to function with name.
Definition TGraph2D.cxx:991
TObject * FindObject(const char *name) const override
search object named name in the list of functions
Definition TGraph2D.cxx:789
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:143
TGraph2D()
Graph2D default constructor.
Definition TGraph2D.cxx:243
void Build(Int_t n)
Creates the 2D graph basic data structure.
Definition TGraph2D.cxx:600
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:145
virtual Double_t GetErrorZ(Int_t bin) const
This function is called by Graph2DFitChisquare.
Definition TGraph2D.cxx:955
Double_t GetMinimum() const
Definition TGraph2D.h:117
Double_t * GetY() const
Definition TGraph2D.h:123
virtual void FitPanel()
Display a GUI panel with all graph fit options.
Definition TGraph2D.cxx:857
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:656
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:142
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:669
Double_t * GetX() const
Definition TGraph2D.h:122
virtual Double_t GetZmaxE() const
Definition TGraph2D.h:144
void RecursiveRemove(TObject *obj) override
Recursively remove object from the list of functions.
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:935
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:811
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:903
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:141
TList * GetContourList(Double_t contour)
Returns the X and Y graphs building a contour.
Definition TGraph2D.cxx:916
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:892
virtual Double_t GetErrorY(Int_t bin) const
This function is called by Graph2DFitChisquare.
Definition TGraph2D.cxx:945
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:121
virtual Double_t GetXmaxE() const
Definition TGraph2D.h:140
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:640
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:728
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:679
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:713
void CreateInterpolator(Bool_t oldInterp)
Add a TGraphDelaunay in the list of the fHistogram's functions.
Definition TGraph2D.cxx:964
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:780
void Draw(Option_t *option="P0") override
Specific drawing options can be used to paint a TGraph2D:
Definition TGraph2D.cxx:760
Int_t fSize
!Real size of fX, fY and fZ
Definition TGraph2D.h:49
@ kOldInterpolation
Definition TGraph2D.h:70
Int_t RemoveDuplicates()
Deletes duplicated points.
TAxis * GetXaxis() const
Get x axis of the graph.
Definition TGraph2D.cxx:881
Double_t * GetZ() const
Definition TGraph2D.h:124
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()
TGraphDelaunay generates a Delaunay triangulation of a TGraph2D.
static TClass * Class()
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:698
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
TAxis * GetZaxis()
Definition TH1.h:346
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a line.
Definition TH1.cxx:2795
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6721
@ kNoStats
Don't draw stats box.
Definition TH1.h:176
TAxis * GetXaxis()
Definition TH1.h:344
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
Definition TH1.cxx:4489
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:8541
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:424
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3316
TAxis * GetYaxis()
Definition TH1.h:345
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:425
virtual Double_t GetEntries() const
Return the current number of entries.
Definition TH1.cxx:4401
TList * GetListOfFunctions() const
Definition TH1.h:261
void Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
Definition TH1.cxx:6209
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TH1.cxx:3212
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:9016
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
Definition TH1.cxx:742
static void SavePrimitiveFunctions(std::ostream &out, const char *varname, TList *lst)
Save list of functions Also can be used by TGraph classes.
Definition TH1.cxx:7426
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:356
Service class for 2-D histogram classes.
Definition TH2.h:30
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:357
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 RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition TList.cxx:762
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:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
TString fTitle
Definition TNamed.h:33
TString fName
Definition TNamed.h:32
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:205
static TString SavePrimitiveVector(std::ostream &out, const char *prefix, Int_t len, Double_t *arr, Bool_t empty_line=kFALSE)
Save array in the output stream "out" as vector.
Definition TObject.cxx:788
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual TClass * IsA() const
Definition TObject.h:249
void MakeZombie()
Definition TObject.h:53
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
Definition TObject.cxx:822
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:771
void ResetBit(UInt_t f)
Definition TObject.h:204
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
@ kInvalidObject
if object ctor succeeded but object should not be used
Definition TObject.h:78
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:70
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
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1114
const char * Data() const
Definition TString.h:376
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:1286
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:977
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