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 fX = new Double_t[fSize];
616 fY = new Double_t[fSize];
617 fZ = new Double_t[fSize];
618 fZout = 0;
619 fMaxIter = 100000;
620 fFunctions = new TList;
621 fPainter = nullptr;
623
626 if (fDirectory) {
627 fDirectory->Append(this, kTRUE);
628 }
629 }
630}
631
632////////////////////////////////////////////////////////////////////////////////
633/// Performs the operation: `z = z + c1*f(x,y,z)`
634/// Errors are not recalculated.
635///
636/// \param f may be a 2-D function TF2 or 3-d function TF3
637/// \param c1 a scaling factor, 1 by default
638
640{
641 //if (fHistogram) SetBit(kResetHisto);
642
643 for (Int_t i = 0; i < fNpoints; i++) {
644 fZ[i] += c1*f->Eval(fX[i], fY[i], fZ[i]);
645 }
646 if (gPad) gPad->Modified();
647}
648
649////////////////////////////////////////////////////////////////////////////////
650/// Apply function f to all the data points
651/// f may be a 2-D function TF2 or 3-d function TF3
652/// The Z values of the 2D graph are replaced by the new values computed
653/// using the function
654
656{
657 //if (fHistogram) SetBit(kResetHisto);
658
659 for (Int_t i = 0; i < fNpoints; i++) {
660 fZ[i] = f->Eval(fX[i], fY[i], fZ[i]);
661 }
662 if (gPad) gPad->Modified();
663}
664
665////////////////////////////////////////////////////////////////////////////////
666/// Browse
667
669{
670 Draw("p0");
671 gPad->Update();
672}
673
674
675////////////////////////////////////////////////////////////////////////////////
676/// Free all memory allocated by this object.
677
678void TGraph2D::Clear(Option_t * /*option = "" */)
679{
680 if (fX) delete [] fX;
681 fX = nullptr;
682 if (fY) delete [] fY;
683 fY = nullptr;
684 if (fZ) delete [] fZ;
685 fZ = nullptr;
686 fSize = fNpoints = 0;
687 if (fHistogram && !fUserHisto) {
688 delete fHistogram;
689 fHistogram = nullptr;
690 fDelaunay = nullptr;
691 }
692 if (fFunctions) {
695 delete fFunctions;
696 fFunctions = nullptr;
697 }
698 if (fDirectory) {
699 fDirectory->Remove(this);
700 fDirectory = nullptr;
701 }
702}
703
704
705////////////////////////////////////////////////////////////////////////////////
706/// Perform the automatic addition of the graph to the given directory
707///
708/// Note this function is called in place when the semantic requires
709/// this object to be added to a directory (I.e. when being read from
710/// a TKey or being Cloned)
711
713{
715 if (addStatus) {
716 SetDirectory(dir);
717 if (dir) {
719 }
720 }
721}
722
723
724////////////////////////////////////////////////////////////////////////////////
725/// Computes distance from point px,py to a graph
726
733
734
735////////////////////////////////////////////////////////////////////////////////
736/// Specific drawing options can be used to paint a TGraph2D:
737///
738/// - "TRI" : The Delaunay triangles are drawn using filled area.
739/// An hidden surface drawing technique is used. The surface is
740/// painted with the current fill area color. The edges of each
741/// triangles are painted with the current line color.
742/// - "TRIW" : The Delaunay triangles are drawn as wire frame
743/// - "TRI1" : The Delaunay triangles are painted with color levels. The edges
744/// of each triangles are painted with the current line color.
745/// - "TRI2" : the Delaunay triangles are painted with color levels.
746/// - "P" : Draw a marker at each vertex
747/// - "P0" : Draw a circle at each vertex. Each circle background is white.
748/// - "PCOL" : Draw a marker at each vertex. The color of each marker is
749/// defined according to its Z position.
750/// - "CONT" : Draw contours
751/// - "LINE" : Draw a 3D polyline
752///
753/// A TGraph2D can be also drawn with ANY options valid to draw a 2D histogram.
754///
755/// When a TGraph2D is drawn with one of the 2D histogram drawing option,
756/// a intermediate 2D histogram is filled using the Delaunay triangles
757/// technique to interpolate the data set.
758
760{
761 TString opt = option;
762 opt.ToLower();
763 if (gPad) {
764 if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
765 if (!opt.Contains("same")) {
766 //the following statement is necessary in case one attempts to draw
767 //a temporary histogram already in the current pad
768 if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
769 gPad->Clear();
770 }
771 }
772 AppendPad(opt.Data());
773}
774
775
776////////////////////////////////////////////////////////////////////////////////
777/// Executes action corresponding to one event
778
780{
781 if (fHistogram) fHistogram->ExecuteEvent(event, px, py);
782}
783
784
785////////////////////////////////////////////////////////////////////////////////
786/// search object named name in the list of functions
787
789{
790 return fFunctions ? fFunctions->FindObject(name) : nullptr;
791}
792
793
794////////////////////////////////////////////////////////////////////////////////
795/// search object obj in the list of functions
796
798{
799 return fFunctions ? fFunctions->FindObject(obj) : nullptr;
800}
801
802////////////////////////////////////////////////////////////////////////////////
803/// Fit this graph with the global function named `fname`.
804///
805/// This will retrieve the function with name `fname` from ROOT's global list of functions, and use it to
806/// fit the data in the TGraph.
807/// TF1 or TF2 functions that have been created in the same ROOT session can be accessed using `fname`.
808/// Predefined functions such as gaus, expo and poln are automatically created by ROOT.
809///
810/// Note that using a global function is not thread safe. In this case, use the overload
811/// TGraph2D::Fit(TF2 *, Option_t *, Option_t *) with a locally created function.
812///
813/// For more details about fitting a TGraph, see TGraph::Fit().
814///
815/// fname can also be a formula, accepted by the linear fitter (linear parts divided
816/// by "++" sign), for example "x++sin(y)" for fitting "[0]*x+[1]*sin(y)"
817
819{
820
821 char *linear;
822 linear = (char*)strstr(fname, "++");
823
824 if (linear) {
825 TF2 f2(fname, fname);
826 return Fit(&f2, option, "");
827 }
828 TF2 * f2 = (TF2*)gROOT->GetFunction(fname);
829 if (!f2) {
830 Printf("Unknown function: %s", fname);
831 return -1;
832 }
833 return Fit(f2, option, "");
834
835}
836
837
838////////////////////////////////////////////////////////////////////////////////
839/// Fits this 2D graph with function f2
840///
841/// f2 is an already predefined function created by TF2.
842///
843/// See TGraph::Fit for the available fitting options and fitting notes
844///
846{
847 // internal graph2D fitting methods
849 Option_t *goption = "";
851
852 // create range and minimizer options with default values
856}
857
858
859////////////////////////////////////////////////////////////////////////////////
860/// Display a GUI panel with all graph fit options.
861///
862/// See class TFitEditor for example
863
865{
866 if (!gPad)
867 gROOT->MakeDefCanvas();
868
869 if (!gPad) {
870 Error("FitPanel", "Unable to create a default canvas");
871 return;
872 }
873
874 // use plugin manager to create instance of TFitEditor
875 TPluginHandler *handler = gROOT->GetPluginManager()->FindHandler("TFitEditor");
876 if (handler && handler->LoadPlugin() != -1) {
877 if (handler->ExecPlugin(2, gPad, this) == 0)
878 Error("FitPanel", "Unable to crate the FitPanel");
879 } else
880 Error("FitPanel", "Unable to find the FitPanel plug-in");
881
882}
883
884
885////////////////////////////////////////////////////////////////////////////////
886/// Get x axis of the graph.
887
889{
890 TH1 *h = ((TGraph2D*)this)->GetHistogram("empty");
891 if (!h) return nullptr;
892 return h->GetXaxis();
893}
894
895
896////////////////////////////////////////////////////////////////////////////////
897/// Get y axis of the graph.
898
900{
901 TH1 *h = ((TGraph2D*)this)->GetHistogram("empty");
902 if (!h) return nullptr;
903 return h->GetYaxis();
904}
905
906
907////////////////////////////////////////////////////////////////////////////////
908/// Get z axis of the graph.
909
911{
912 TH1 *h = ((TGraph2D*)this)->GetHistogram("empty");
913 if (!h) return nullptr;
914 return h->GetZaxis();
915}
916
917
918////////////////////////////////////////////////////////////////////////////////
919/// Returns the X and Y graphs building a contour. A contour level may
920/// consist in several parts not connected to each other. This function
921/// returns them in a graphs' list.
922
924{
925 if (fNpoints <= 0) {
926 Error("GetContourList", "Empty TGraph2D");
927 return nullptr;
928 }
929
930 if (!fHistogram) GetHistogram("empty");
931
933
934 return fPainter->GetContourList(contour);
935}
936
937
938////////////////////////////////////////////////////////////////////////////////
939/// This function is called by Graph2DFitChisquare.
940/// It always returns a negative value. Real implementation in TGraph2DErrors
941
943{
944 return -1;
945}
946
947
948////////////////////////////////////////////////////////////////////////////////
949/// This function is called by Graph2DFitChisquare.
950/// It always returns a negative value. Real implementation in TGraph2DErrors
951
953{
954 return -1;
955}
956
957
958////////////////////////////////////////////////////////////////////////////////
959/// This function is called by Graph2DFitChisquare.
960/// It always returns a negative value. Real implementation in TGraph2DErrors
961
963{
964 return -1;
965}
966
967
968////////////////////////////////////////////////////////////////////////////////
969/// Add a TGraphDelaunay in the list of the fHistogram's functions
970
972{
973
975
976 if (oldInterp) {
977 TGraphDelaunay *dt = new TGraphDelaunay(this);
978 dt->SetMaxIter(fMaxIter);
979 dt->SetMarginBinsContent(fZout);
980 fDelaunay = dt;
982 if (!hl->FindObject("TGraphDelaunay")) hl->Add(fDelaunay);
983 } else {
985 dt->SetMarginBinsContent(fZout);
986 fDelaunay = dt;
988 if (!hl->FindObject("TGraphDelaunay2D")) hl->Add(fDelaunay);
989 }
990}
991
992////////////////////////////////////////////////////////////////////////////////
993/// Return pointer to function with name.
994///
995/// Functions such as TGraph2D::Fit store the fitted function in the list of
996/// functions of this graph.
997
998TF2 *TGraph2D::GetFunction(const char *name) const
999{
1000 return dynamic_cast<TF2*>(FindObject(name));
1001}
1002
1003////////////////////////////////////////////////////////////////////////////////
1004/// By default returns a pointer to the Delaunay histogram. If fHistogram
1005/// doesn't exist, books the 2D histogram fHistogram with a margin around
1006/// the hull. Calls TGraphDelaunay::Interpolate at each bin centre to build up
1007/// an interpolated 2D histogram.
1008///
1009/// If the "empty" option is selected, returns an empty histogram booked with
1010/// the limits of fX, fY and fZ. This option is used when the data set is
1011/// drawn with markers only. In that particular case there is no need to
1012/// find the Delaunay triangles.
1013///
1014/// By default use the new interpolation routine based on Triangles
1015/// If the option "old" the old interpolation is used
1016
1018{
1019 // for an empty graph create histogram in [0,1][0,1]
1020 if (fNpoints <= 0) {
1021 if (!fHistogram) {
1022 // do not add the histogram to gDirectory
1023 TDirectory::TContext ctx(nullptr);
1024 fHistogram = new TH2D(GetName(), GetTitle(), fNpx , 0., 1., fNpy, 0., 1.);
1026 }
1027 return fHistogram;
1028 }
1029
1030 TString opt = option;
1031 opt.ToLower();
1032 Bool_t empty = opt.Contains("empty");
1033 Bool_t oldInterp = opt.Contains("old");
1034
1035 if (fHistogram) {
1036 if (!empty && fHistogram->GetEntries() == 0) {
1037 if (!fUserHisto) {
1038 delete fHistogram;
1039 fHistogram = nullptr;
1040 fDelaunay = nullptr;
1041 }
1042 } else if (fHistogram->GetEntries() == 0)
1043 {; }
1044 // check case if interpolation type has changed
1045 else if ( (TestBit(kOldInterpolation) && !oldInterp) || ( !TestBit(kOldInterpolation) && oldInterp ) ) {
1046 delete fHistogram;
1047 fHistogram = nullptr;
1048 fDelaunay = nullptr;
1049 }
1050 // normal case return existing histogram
1051 else {
1052 return fHistogram;
1053 }
1054 }
1055
1057
1058 // Book fHistogram if needed. It is not added in the current directory
1059 if (!fUserHisto) {
1064 hxmin = xmin - fMargin * (xmax - xmin);
1065 hymin = ymin - fMargin * (ymax - ymin);
1066 hxmax = xmax + fMargin * (xmax - xmin);
1067 hymax = ymax + fMargin * (ymax - ymin);
1068 Double_t epsilon = 1e-9;
1069 if (TMath::AreEqualRel(hxmax,hxmin,epsilon)) {
1070 if (TMath::Abs(hxmin) < epsilon) {
1071 hxmin = -0.001;
1072 hxmax = 0.001;
1073 } else {
1074 hxmin = hxmin-TMath::Abs(hxmin)*(epsilon/2.);
1075 hxmax = hxmax+TMath::Abs(hxmax)*(epsilon/2.);
1076 }
1077 }
1078 if (TMath::AreEqualRel(hymax, hymin, epsilon)) {
1079 if (TMath::Abs(hymin) < epsilon) {
1080 hymin = -0.001;
1081 hymax = 0.001;
1082 } else {
1083 hymin = hymin-TMath::Abs(hymin)*(epsilon/2.);
1084 hymax = hymax+TMath::Abs(hymax)*(epsilon/2.);
1085 }
1086 }
1087 if (fHistogram) {
1090 } else {
1091 TDirectory::TContext ctx(nullptr); // to avoid adding fHistogram to gDirectory
1092 fHistogram = new TH2D(GetName(), GetTitle(),
1093 fNpx , hxmin, hxmax,
1094 fNpy, hymin, hymax);
1096 }
1099 } else {
1104 }
1105
1106 // Option "empty" is selected. An empty histogram is returned.
1108 if (empty) {
1109 if (fMinimum != -1111) {
1110 hzmin = fMinimum;
1111 } else {
1112 hzmin = GetZminE();
1113 }
1114 if (fMaximum != -1111) {
1115 hzmax = fMaximum;
1116 } else {
1117 hzmax = GetZmaxE();
1118 }
1119 if (hzmin == hzmax) {
1120 Double_t hz = hzmin;
1121 if (hz==0) {
1122 hzmin = -0.01;
1123 hzmax = 0.01;
1124 } else {
1125 hzmin = hz - 0.01 * TMath::Abs(hz);
1126 hzmax = hz + 0.01 * TMath::Abs(hz);
1127 }
1128 }
1131 return fHistogram;
1132 }
1133
1134 Double_t dx = (hxmax - hxmin) / fNpx;
1135 Double_t dy = (hymax - hymin) / fNpy;
1136
1137 Double_t x, y, z;
1138
1139 for (Int_t ix = 1; ix <= fNpx; ix++) {
1140 x = hxmin + (ix - 0.5) * dx;
1141 for (Int_t iy = 1; iy <= fNpy; iy++) {
1142 y = hymin + (iy - 0.5) * dy;
1143 // do interpolation
1144 if (oldInterp)
1145 z = ((TGraphDelaunay*)fDelaunay)->ComputeZ(x, y);
1146 else
1147 z = ((TGraphDelaunay2D*)fDelaunay)->ComputeZ(x, y);
1148
1149 fHistogram->Fill(x, y, z);
1150 }
1151 }
1152
1153 hzmin = GetZminE();
1154 hzmax = GetZmaxE();
1157
1158 if (fMinimum != -1111) fHistogram->SetMinimum(fMinimum);
1159 if (fMaximum != -1111) fHistogram->SetMaximum(fMaximum);
1160
1161 return fHistogram;
1162}
1163
1164
1165////////////////////////////////////////////////////////////////////////////////
1166/// Returns the X maximum
1167
1169{
1170 Double_t v = fX[0];
1171 for (Int_t i = 1; i < fNpoints; i++) if (fX[i] > v) v = fX[i];
1172 return v;
1173}
1174
1175
1176////////////////////////////////////////////////////////////////////////////////
1177/// Returns the X minimum
1178
1180{
1181 Double_t v = fX[0];
1182 for (Int_t i = 1; i < fNpoints; i++) if (fX[i] < v) v = fX[i];
1183 return v;
1184}
1185
1186
1187////////////////////////////////////////////////////////////////////////////////
1188/// Returns the Y maximum
1189
1191{
1192 Double_t v = fY[0];
1193 for (Int_t i = 1; i < fNpoints; i++) if (fY[i] > v) v = fY[i];
1194 return v;
1195}
1196
1197
1198////////////////////////////////////////////////////////////////////////////////
1199/// Returns the Y minimum
1200
1202{
1203 Double_t v = fY[0];
1204 for (Int_t i = 1; i < fNpoints; i++) if (fY[i] < v) v = fY[i];
1205 return v;
1206}
1207
1208
1209////////////////////////////////////////////////////////////////////////////////
1210/// Returns the Z maximum
1211
1213{
1214 Double_t v = fZ[0];
1215 for (Int_t i = 1; i < fNpoints; i++) if (fZ[i] > v) v = fZ[i];
1216 return v;
1217}
1218
1219
1220////////////////////////////////////////////////////////////////////////////////
1221/// Returns the Z minimum
1222
1224{
1225 Double_t v = fZ[0];
1226 for (Int_t i = 1; i < fNpoints; i++) if (fZ[i] < v) v = fZ[i];
1227 return v;
1228}
1229
1230////////////////////////////////////////////////////////////////////////////////
1231/// Get x, y and z values for point number i.
1232/// The function returns -1 in case of an invalid request or the point number otherwise
1233
1235{
1236 if (i < 0 || i >= fNpoints) return -1;
1237 if (!fX || !fY || !fZ) return -1;
1238 x = fX[i];
1239 y = fY[i];
1240 z = fZ[i];
1241 return i;
1242}
1243
1244////////////////////////////////////////////////////////////////////////////////
1245/// Finds the z value at the position (x,y) thanks to
1246/// the Delaunay interpolation.
1247
1249{
1250 if (fNpoints <= 0) {
1251 Error("Interpolate", "Empty TGraph2D");
1252 return 0;
1253 }
1254
1255 if (!fHistogram) GetHistogram("empty");
1256 if (!fDelaunay) {
1258 if (!TestBit(kOldInterpolation) ) {
1259 fDelaunay = hl->FindObject("TGraphDelaunay2D");
1260 if (!fDelaunay) fDelaunay = hl->FindObject("TGraphDelaunay");
1261 }
1262 else {
1263 // if using old implementation
1264 fDelaunay = hl->FindObject("TGraphDelaunay");
1265 if (!fDelaunay) fDelaunay = hl->FindObject("TGraphDelaunay2D");
1266 }
1267 }
1268
1269 if (!fDelaunay) return TMath::QuietNaN();
1270
1272 return ((TGraphDelaunay2D*)fDelaunay)->ComputeZ(x, y);
1273 else if (fDelaunay->IsA() == TGraphDelaunay::Class() )
1274 return ((TGraphDelaunay*)fDelaunay)->ComputeZ(x, y);
1275
1276 // cannot be here
1277 assert(false);
1278 return TMath::QuietNaN();
1279}
1280
1281
1282////////////////////////////////////////////////////////////////////////////////
1283/// Paints this 2D graph with its current attributes
1284
1286{
1287 if (fNpoints <= 0) {
1288 Error("Paint", "Empty TGraph2D");
1289 return;
1290 }
1291
1292 TString opt = option;
1293 opt.ToLower();
1294 if (opt.Contains("p") && !opt.Contains("tri")) {
1295 if (!opt.Contains("pol") &&
1296 !opt.Contains("sph") &&
1297 !opt.Contains("psr")) opt.Append("tri0");
1298 }
1299
1300 if (opt.Contains("line") && !opt.Contains("tri")) opt.Append("tri0");
1301
1302 if (opt.Contains("err") && !opt.Contains("tri")) opt.Append("tri0");
1303
1304 if (opt.Contains("tri0")) {
1305 GetHistogram("empty");
1306 } else if (opt.Contains("old")) {
1307 GetHistogram("old");
1308 } else {
1309 GetHistogram();
1310 }
1311
1320 fHistogram->Paint(opt.Data());
1321}
1322
1323
1324////////////////////////////////////////////////////////////////////////////////
1325/// Print 2D graph values.
1326
1328{
1329 for (Int_t i = 0; i < fNpoints; i++) {
1330 printf("x[%d]=%g, y[%d]=%g, z[%d]=%g\n", i, fX[i], i, fY[i], i, fZ[i]);
1331 }
1332}
1333
1334
1335////////////////////////////////////////////////////////////////////////////////
1336/// Projects a 2-d graph into 1 or 2-d histograms depending on the option parameter.
1337/// option may contain a combination of the characters x,y,z:
1338///
1339/// - option = "x" return the x projection into a TH1D histogram
1340/// - option = "y" return the y projection into a TH1D histogram
1341/// - option = "xy" return the x versus y projection into a TH2D histogram
1342/// - option = "yx" return the y versus x projection into a TH2D histogram
1343
1345{
1346 if (fNpoints <= 0) {
1347 Error("Project", "Empty TGraph2D");
1348 return nullptr;
1349 }
1350
1351 TString opt = option;
1352 opt.ToLower();
1353
1354 Int_t pcase = 0;
1355 if (opt.Contains("x")) pcase = 1;
1356 if (opt.Contains("y")) pcase = 2;
1357 if (opt.Contains("xy")) pcase = 3;
1358 if (opt.Contains("yx")) pcase = 4;
1359
1360 // Create the projection histogram
1361 TH1D *h1 = nullptr;
1362 TH2D *h2 = nullptr;
1363 Int_t nch = strlen(GetName()) + opt.Length() + 2;
1364 char *name = new char[nch];
1365 snprintf(name, nch, "%s_%s", GetName(), option);
1366 nch = strlen(GetTitle()) + opt.Length() + 2;
1367 char *title = new char[nch];
1368 snprintf(title, nch, "%s_%s", GetTitle(), option);
1369
1374
1375 switch (pcase) {
1376 case 1:
1377 // "x"
1378 h1 = new TH1D(name, title, fNpx, hxmin, hxmax);
1379 break;
1380 case 2:
1381 // "y"
1382 h1 = new TH1D(name, title, fNpy, hymin, hymax);
1383 break;
1384 case 3:
1385 // "xy"
1386 h2 = new TH2D(name, title, fNpx, hxmin, hxmax, fNpy, hymin, hymax);
1387 break;
1388 case 4:
1389 // "yx"
1390 h2 = new TH2D(name, title, fNpy, hymin, hymax, fNpx, hxmin, hxmax);
1391 break;
1392 }
1393
1394 delete [] name;
1395 delete [] title;
1396 TH1 *h = h1;
1397 if (h2) h = h2;
1398 if (h == nullptr) return nullptr;
1399
1400 // Fill the projected histogram
1401 Double_t entries = 0;
1402 for (Int_t n = 0; n < fNpoints; n++) {
1403 switch (pcase) {
1404 case 1:
1405 // "x"
1406 h1->Fill(fX[n], fZ[n]);
1407 break;
1408 case 2:
1409 // "y"
1410 h1->Fill(fY[n], fZ[n]);
1411 break;
1412 case 3:
1413 // "xy"
1414 h2->Fill(fX[n], fY[n], fZ[n]);
1415 break;
1416 case 4:
1417 // "yx"
1418 h2->Fill(fY[n], fX[n], fZ[n]);
1419 break;
1420 }
1421 entries += fZ[n];
1422 }
1423 h->SetEntries(entries);
1424 return h;
1425}
1426
1427
1428////////////////////////////////////////////////////////////////////////////////
1429/// Deletes duplicated points.
1430///
1431/// The Delaunay triangulation algorithm assumes that each (x, y) coordinate corresponds to a unique z value,
1432/// meaning duplicate (x, y) points are not allowed. Consequently, when using drawing options that rely on this
1433/// algorithm (e.g., TRI, SURF, etc.), a warning may appear instructing you to remove duplicates.
1434/// This function provides a way to handle such duplicates.
1435///
1436/// Example:
1437/// ~~~ {.cpp}
1438/// g->RemoveDuplicates();
1439/// g->Draw("TRI1");
1440/// ~~~
1441
1443{
1444 for (int i = 0; i < fNpoints; i++) {
1445 double x = fX[i];
1446 double y = fY[i];
1447 for (int j = i + 1; j < fNpoints; j++) {
1448 if (x == fX[j] && y == fY[j]) {
1449 RemovePoint(j);
1450 j--;
1451 }
1452 }
1453 }
1454
1455 return fNpoints;
1456}
1457
1458
1459////////////////////////////////////////////////////////////////////////////////
1460/// Recursively remove object from the list of functions
1461
1463{
1464 if (fFunctions) {
1467 }
1468 if (fHistogram == obj)
1469 fHistogram = nullptr;
1470}
1471
1472
1473////////////////////////////////////////////////////////////////////////////////
1474/// Deletes point number ipoint
1475
1477{
1478 if (ipoint < 0) return -1;
1479 if (ipoint >= fNpoints) return -1;
1480 for (Int_t i = ipoint; i < fNpoints - 1; i++) {
1481 fX[i] = fX[i+1];
1482 fY[i] = fY[i+1];
1483 fZ[i] = fZ[i+1];
1484 }
1485 fNpoints--;
1486 if (fHistogram) {
1487 delete fHistogram;
1488 fHistogram = nullptr;
1489 fDelaunay = nullptr;
1490 }
1491 return ipoint;
1492}
1493
1494
1495////////////////////////////////////////////////////////////////////////////////
1496/// Saves primitive as a C++ statement(s) on output stream out
1497
1498void TGraph2D::SavePrimitive(std::ostream &out, Option_t *option)
1499{
1500 TString arrx = SavePrimitiveVector(out, "graph2d_x", fNpoints, fX, kTRUE);
1501 TString arry = SavePrimitiveVector(out, "graph2d_y", fNpoints, fY);
1502 TString arrz = SavePrimitiveVector(out, "graph2d_z", fNpoints, fZ);
1503
1504 SavePrimitiveConstructor(out, Class(), "graph2d",
1505 TString::Format("%d, %s.data(), %s.data(), %s.data()", fNpoints, arrx.Data(), arry.Data(), arrz.Data()), kFALSE);
1506
1507 if (strcmp(GetName(), "Graph2D"))
1508 out << " graph2d->SetName(\"" << TString(GetName()).ReplaceSpecialCppChars() << "\");\n";
1509
1510 TString title = GetTitle();
1511 if (fHistogram)
1512 title = TString(fHistogram->GetTitle()) + ";" + fHistogram->GetXaxis()->GetTitle() + ";" +
1514
1515 out << " graph2d->SetTitle(\"" << title.ReplaceSpecialCppChars() << "\");\n";
1516
1517 if (!fDirectory)
1518 out << " graph2d->SetDirectory(nullptr);\n";
1519
1520 SaveFillAttributes(out, "graph2d", 0, 1001);
1521 SaveLineAttributes(out, "graph2d", 1, 1, 1);
1522 SaveMarkerAttributes(out, "graph2d", 1, 1, 1);
1523
1524 TH1::SavePrimitiveFunctions(out, "graph2d", fFunctions);
1525
1526 SavePrimitiveDraw(out, "graph2d", option);
1527}
1528
1529////////////////////////////////////////////////////////////////////////////////
1530/// Multiply the values of a TGraph2D by a constant c1.
1531///
1532/// If option contains "x" the x values are scaled
1533/// If option contains "y" the y values are scaled
1534/// If option contains "z" the z values are scaled
1535/// If option contains "xyz" all three x, y and z values are scaled
1536
1538{
1539 TString opt = option; opt.ToLower();
1540 if (opt.Contains("x")) {
1541 for (Int_t i=0; i<GetN(); i++)
1542 GetX()[i] *= c1;
1543 }
1544 if (opt.Contains("y")) {
1545 for (Int_t i=0; i<GetN(); i++)
1546 GetY()[i] *= c1;
1547 }
1548 if (opt.Contains("z")) {
1549 for (Int_t i=0; i<GetN(); i++)
1550 GetZ()[i] *= c1;
1551 }
1552}
1553
1554////////////////////////////////////////////////////////////////////////////////
1555/// Set number of points in the 2D graph.
1556/// Existing coordinates are preserved.
1557/// New coordinates above fNpoints are preset to 0.
1558
1560{
1561 if (n < 0) n = 0;
1562 if (n == fNpoints) return;
1563 if (n > fNpoints) SetPoint(n, 0, 0, 0);
1564 fNpoints = n;
1565}
1566
1567
1568////////////////////////////////////////////////////////////////////////////////
1569/// By default when an 2D graph is created, it is added to the list
1570/// of 2D graph objects in the current directory in memory.
1571/// This method removes reference to this 2D graph from current directory and add
1572/// reference to new directory dir. dir can be 0 in which case the
1573/// 2D graph does not belong to any directory.
1574
1576{
1577 if (fDirectory == dir) return;
1578 if (fDirectory) fDirectory->Remove(this);
1579 fDirectory = dir;
1580 if (fDirectory) fDirectory->Append(this);
1581}
1582
1583
1584////////////////////////////////////////////////////////////////////////////////
1585/// Sets the histogram to be filled.
1586/// If the 2D graph needs to be save in a TFile the following set should be
1587/// followed to read it back:
1588/// 1. Create TGraph2D
1589/// 2. Call g->SetHistogram(h), and do whatever you need to do
1590/// 3. Save g and h to the TFile, exit
1591/// 4. Open the TFile, retrieve g and h
1592/// 5. Call h->SetDirectory(0)
1593/// 6. Call g->SetHistogram(h) again
1594/// 7. Carry on as normal
1595///
1596/// By default use the new interpolation routine based on Triangles
1597/// If the option "old" the old interpolation is used
1598
1600{
1601 TString opt = option;
1602 opt.ToLower();
1603 Bool_t oldInterp = opt.Contains("old");
1604
1605 fUserHisto = kTRUE;
1606 fHistogram = (TH2D*)h;
1607 fNpx = h->GetNbinsX();
1608 fNpy = h->GetNbinsY();
1610}
1611
1612
1613////////////////////////////////////////////////////////////////////////////////
1614/// Sets the extra space (in %) around interpolated area for the 2D histogram
1615
1617{
1618 if (m < 0 || m > 1) {
1619 Warning("SetMargin", "The margin must be >= 0 && <= 1, fMargin set to 0.1");
1620 fMargin = 0.1;
1621 } else {
1622 fMargin = m;
1623 }
1624 if (fHistogram) {
1625 delete fHistogram;
1626 fHistogram = nullptr;
1627 fDelaunay = nullptr;
1628 }
1629}
1630
1631
1632////////////////////////////////////////////////////////////////////////////////
1633/// Sets the histogram bin height for points lying outside the TGraphDelaunay
1634/// convex hull ie: the bins in the margin.
1635
1637{
1638 fZout = z;
1639 if (fHistogram) {
1640 delete fHistogram;
1641 fHistogram = nullptr;
1642 fDelaunay = nullptr;
1643 }
1644}
1645
1646
1647////////////////////////////////////////////////////////////////////////////////
1648/// Set maximum.
1649
1651{
1652 fMaximum = maximum;
1653 TH1 * h = GetHistogram();
1654 if (h) h->SetMaximum(maximum);
1655}
1656
1657
1658////////////////////////////////////////////////////////////////////////////////
1659/// Set minimum.
1660
1662{
1663 fMinimum = minimum;
1664 TH1 * h = GetHistogram();
1665 if (h) h->SetMinimum(minimum);
1666}
1667
1668
1669////////////////////////////////////////////////////////////////////////////////
1670/// Changes the name of this 2D graph
1671
1672void TGraph2D::SetName(const char *name)
1673{
1674 // 2D graphs are named objects in a THashList.
1675 // We must update the hashlist if we change the name
1676 if (fDirectory) fDirectory->Remove(this);
1677 fName = name;
1678 if (fDirectory) fDirectory->Append(this);
1679}
1680
1681
1682////////////////////////////////////////////////////////////////////////////////
1683/// Change the name and title of this 2D graph
1684///
1685
1686void TGraph2D::SetNameTitle(const char *name, const char *title)
1687{
1688 // 2D graphs are named objects in a THashList.
1689 // We must update the hashlist if we change the name
1690 if (fDirectory) fDirectory->Remove(this);
1691 fName = name;
1692 SetTitle(title);
1693 if (fDirectory) fDirectory->Append(this);
1694}
1695
1696
1697////////////////////////////////////////////////////////////////////////////////
1698/// Sets the number of bins along X used to draw the function
1699
1701{
1702 if (npx < 4) {
1703 Warning("SetNpx", "Number of points must be >4 && < 500, fNpx set to 4");
1704 fNpx = 4;
1705 } else if (npx > 500) {
1706 Warning("SetNpx", "Number of points must be >4 && < 500, fNpx set to 500");
1707 fNpx = 500;
1708 } else {
1709 fNpx = npx;
1710 }
1711 if (fHistogram) {
1712 delete fHistogram;
1713 fHistogram = nullptr;
1714 fDelaunay = nullptr;
1715 }
1716}
1717
1718
1719////////////////////////////////////////////////////////////////////////////////
1720/// Sets the number of bins along Y used to draw the function
1721
1723{
1724 if (npy < 4) {
1725 Warning("SetNpy", "Number of points must be >4 && < 500, fNpy set to 4");
1726 fNpy = 4;
1727 } else if (npy > 500) {
1728 Warning("SetNpy", "Number of points must be >4 && < 500, fNpy set to 500");
1729 fNpy = 500;
1730 } else {
1731 fNpy = npy;
1732 }
1733 if (fHistogram) {
1734 delete fHistogram;
1735 fHistogram = nullptr;
1736 fDelaunay = nullptr;
1737 }
1738}
1739
1740
1741////////////////////////////////////////////////////////////////////////////////
1742/// Sets point number n.
1743/// If n is greater than the current size, the arrays are automatically
1744/// extended.
1745
1747{
1748 if (n < 0) return;
1749
1750 if (!fX || !fY || !fZ || n >= fSize) {
1751 // re-allocate the object
1752 Int_t newN = TMath::Max(2 * fSize, n + 1);
1753 Double_t *savex = new Double_t [newN];
1754 Double_t *savey = new Double_t [newN];
1755 Double_t *savez = new Double_t [newN];
1756 if (fX && fSize) {
1757 memcpy(savex, fX, fSize * sizeof(Double_t));
1758 memset(&savex[fSize], 0, (newN - fSize)*sizeof(Double_t));
1759 delete [] fX;
1760 }
1761 if (fY && fSize) {
1762 memcpy(savey, fY, fSize * sizeof(Double_t));
1763 memset(&savey[fSize], 0, (newN - fSize)*sizeof(Double_t));
1764 delete [] fY;
1765 }
1766 if (fZ && fSize) {
1767 memcpy(savez, fZ, fSize * sizeof(Double_t));
1768 memset(&savez[fSize], 0, (newN - fSize)*sizeof(Double_t));
1769 delete [] fZ;
1770 }
1771 fX = savex;
1772 fY = savey;
1773 fZ = savez;
1774 fSize = newN;
1775 }
1776 fX[n] = x;
1777 fY[n] = y;
1778 fZ[n] = z;
1779 fNpoints = TMath::Max(fNpoints, n + 1);
1780}
1781
1782
1783////////////////////////////////////////////////////////////////////////////////
1784/// Sets the 2D graph title.
1785///
1786/// This method allows to change the global title and the axis' titles of a 2D
1787/// graph. If `g` is the 2D graph one can do:
1788///
1789/// ~~~ {.cpp}
1790/// g->SetTitle("Graph title; X axis title; Y axis title; Z axis title");
1791/// ~~~
1792
1793void TGraph2D::SetTitle(const char* title)
1794{
1795 fTitle = title;
1796 if (fHistogram) fHistogram->SetTitle(title);
1797}
1798
1799
1800////////////////////////////////////////////////////////////////////////////////
1801/// Stream a class object
1802
1804{
1805 if (b.IsReading()) {
1806 UInt_t R__s, R__c;
1807 Version_t R__v = b.ReadVersion(&R__s, &R__c);
1808 b.ReadClassBuffer(TGraph2D::Class(), this, R__v, R__s, R__c);
1809
1811 } else {
1812 b.WriteClassBuffer(TGraph2D::Class(), this);
1813 }
1814}
#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:414
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:998
TObject * FindObject(const char *name) const override
search object named name in the list of functions
Definition TGraph2D.cxx:788
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:962
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:864
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:655
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:668
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:942
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="")
Fit this graph with the global function named fname.
Definition TGraph2D.cxx:818
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:910
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:923
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:899
virtual Double_t GetErrorY(Int_t bin) const
This function is called by Graph2DFitChisquare.
Definition TGraph2D.cxx:952
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:639
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:727
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:678
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:712
void CreateInterpolator(Bool_t oldInterp)
Add a TGraphDelaunay in the list of the fHistogram's functions.
Definition TGraph2D.cxx:971
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:779
void Draw(Option_t *option="P0") override
Specific drawing options can be used to paint a TGraph2D:
Definition TGraph2D.cxx:759
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:888
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:2805
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6770
@ 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:4500
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:8597
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:3326
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:4412
TList * GetListOfFunctions() const
Definition TH1.h:488
void Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
Definition TH1.cxx:6255
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TH1.cxx:3222
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:9072
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:7482
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:363
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:708
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition TList.cxx:894
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:600
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
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1074
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:881
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1088
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:839
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
static TString SavePrimitiveVector(std::ostream &out, const char *prefix, Int_t len, Double_t *arr, Int_t flag=0)
Save array in the output stream "out" as vector.
Definition TObject.cxx:790
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:249
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:122
th1 Draw()
TMarker m
Definition textangle.C:8