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