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