Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TF2.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 23/08/95
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 "TF2.h"
14#include "TMath.h"
15#include "TRandom.h"
16#include "TBuffer.h"
17#include "TH2.h"
18#include "TVirtualPad.h"
19#include <iostream>
20#include "TColor.h"
21#include "TVirtualFitter.h"
23#include "snprintf.h"
24
26
27/** \class TF2
28 \ingroup Functions
29 \brief A 2-Dim function with parameters.
30
31The following types of functions can be created:
32
331. [Expression using variables x and y](\ref TF2a)
342. [Expression using a user defined function](\ref TF2b)
353. [Lambda Expression with x and y variables and parameters](\ref TF2c)
36
37\anchor TF2a
38### Expression using variables x and y
39
40Begin_Macro (source)
41{
42 auto f2 = new TF2("f2","sin(x)*sin(y)/(x*y)",0,5,0,5);
43 f2->Draw();
44}
45End_Macro
46
47\anchor TF2b
48### Expression using a user defined function
49
50~~~~{.cpp}
51Double_t func(Double_t *val, Double_t *par)
52{
53 Float_t x = val[0];
54 Float_t y = val[1];
55 Double_t f = x*x-y*y;
56 return f;
57}
58
59void fplot()
60{
61 auto f = new TF2("f",func,-1,1,-1,1);
62 f->Draw("surf1");
63}
64~~~~
65
66\anchor TF2c
67### Lambda Expression with x and y variables and parameters
68
69~~~~{.cpp}
70root [0] TF2 f2("f2", [](double* x, double*p) { return x[0] + x[1] * p[0]; }, 0., 1., 0., 1., 1)
71(TF2 &) Name: f2 Title: f2
72root [1] f2.SetParameter(0, 1.)
73root [2] f2.Eval(1., 2.)
74(double) 3.0000000
75~~~~
76
77See TF1 class for the list of functions formats
78*/
79
80////////////////////////////////////////////////////////////////////////////////
81/// TF2 default constructor
82
83TF2::TF2(): fYmin(0),fYmax(0),fNpy(100)
84{
85}
86
87
88////////////////////////////////////////////////////////////////////////////////
89/// F2 constructor using a formula definition
90///
91/// See TFormula constructor for explanation of the formula syntax.
92///
93/// If formula has the form "fffffff;xxxx;yyyy", it is assumed that
94/// the formula string is "fffffff" and "xxxx" and "yyyy" are the
95/// titles for the X and Y axis respectively.
96
97TF2::TF2(const char *name,const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Option_t * opt)
98 :TF1(name,formula,xmax,xmin,opt)
99{
100 if (ymin < ymax) {
101 fYmin = ymin;
102 fYmax = ymax;
103 } else {
104 fYmin = ymax;
105 fYmax = ymin;
106 }
107 fNpx = 30;
108 fNpy = 30;
109 fContour.Set(0);
110 // accept 1-d formula
111 if (GetNdim() < 2) fNdim = 2;
112 // dimension is obtained by TFormula
113 // accept cases where formula dim is less than 2
114 if (GetNdim() > 2 && xmin < xmax && ymin < ymax) {
115 Error("TF2","function: %s/%s has dimension %d instead of 2",name,formula,GetNdim());
116 MakeZombie();
117 }
118}
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// F2 constructor using a pointer to a compiled function
123///
124/// npar is the number of free parameters used by the function
125///
126/// This constructor creates a function of type C when invoked
127/// with the normal C++ compiler.
128///
129/// WARNING! A function created with this constructor cannot be Cloned.
130
132 : TF1(name, fcn, xmin, xmax, npar,ndim)
133{
134 fYmin = ymin;
135 fYmax = ymax;
136 fNpx = 30;
137 fNpy = 30;
138 fContour.Set(0);
139
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// F2 constructor using a pointer to a compiled function
144///
145/// npar is the number of free parameters used by the function
146///
147/// This constructor creates a function of type C when invoked
148/// with the normal C++ compiler.
149///
150/// WARNING! A function created with this constructor cannot be Cloned.
151
152TF2::TF2(const char *name, Double_t (*fcn)(const Double_t *, const Double_t *), Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar, Int_t ndim)
153 : TF1(name, fcn, xmin, xmax, npar,ndim)
154{
155 fYmin = ymin;
156 fYmax = ymax;
157 fNpx = 30;
158 fNpy = 30;
159 fContour.Set(0);
160
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// F2 constructor using a ParamFunctor,
165/// a functor class implementing operator() (double *, double *)
166///
167/// npar is the number of free parameters used by the function
168///
169/// WARNING! A function created with this constructor cannot be Cloned.
170
172 : TF1(name, f, xmin, xmax, npar,ndim)
173{
174 fYmin = ymin;
175 fYmax = ymax;
176 fNpx = 30;
177 fNpy = 30;
178 fContour.Set(0);
179
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Operator =
184
186{
187 if (this != &rhs)
188 rhs.TF2::Copy(*this);
189 return *this;
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// F2 default destructor
194
196{
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Copy constructor.
201
202TF2::TF2(const TF2 &f2) : TF1()
203{
204 f2.TF2::Copy(*this);
205}
206
207////////////////////////////////////////////////////////////////////////////////
208/// Copy this F2 to a new F2
209
210void TF2::Copy(TObject &obj) const
211{
212 TF1::Copy(obj);
213 ((TF2&)obj).fYmin = fYmin;
214 ((TF2&)obj).fYmax = fYmax;
215 ((TF2&)obj).fNpy = fNpy;
216 fContour.Copy(((TF2&)obj).fContour);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Compute distance from point px,py to a function
221///
222/// \param[in] px x position
223/// \param[in] py y position
224///
225/// Compute the closest distance of approach from point px,py to this function.
226/// The distance is computed in pixels units.
227
229{
230 if (!fHistogram) return 9999;
231 Int_t distance = fHistogram->DistancetoPrimitive(px,py);
232 if (distance <= 1) return distance;
233
234 Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px));
235 Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py));
236 const char *drawOption = GetDrawOption();
237 Double_t uxmin,uxmax;
238 Double_t uymin,uymax;
239 if (gPad->GetView() || strncmp(drawOption,"cont",4) == 0
240 || strncmp(drawOption,"CONT",4) == 0) {
241 uxmin=gPad->GetUxmin();
242 uxmax=gPad->GetUxmax();
243 x = fXmin +(fXmax-fXmin)*(x-uxmin)/(uxmax-uxmin);
244 uymin=gPad->GetUymin();
245 uymax=gPad->GetUymax();
246 y = fYmin +(fYmax-fYmin)*(y-uymin)/(uymax-uymin);
247 }
248 if (x < fXmin || x > fXmax) return distance;
249 if (y < fYmin || y > fYmax) return distance;
250 return 0;
251}
252
253////////////////////////////////////////////////////////////////////////////////
254/// Draw this function with its current attributes
255///
256/// NB. You must use DrawCopy if you want to draw several times the same
257/// function in the current canvas.
258
260{
261 TString opt = option;
262 opt.ToLower();
263 if (gPad && !opt.Contains("same")) gPad->Clear();
264
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Draw a copy of this function with its current attributes-*
270///
271/// This function MUST be used instead of Draw when you want to draw
272/// the same function with different parameters settings in the same canvas.
273///
274/// Possible option values are:
275///
276/// option | description
277/// ---------|------------
278/// "SAME" | superimpose on top of existing picture
279/// "L" | connect all computed points with a straight line
280/// "C" | connect all computed points with a smooth curve.
281///
282/// Note that the default value is "F". Therefore to draw on top
283/// of an existing picture, specify option "SL"
284
285
287{
288 TF2 *newf2 = new TF2();
289 Copy(*newf2);
290 newf2->AppendPad(option);
291 newf2->SetBit(kCanDelete);
292 return newf2;
293}
294
295// remove this function
296//______________________________________________________________________________
297// void TF2::DrawF2(const char *formula, Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax, Option_t *option)
298// {
299// //----Draw formula between xmin,ymin and xmax,ymax---
300// // ============================================
301// //
302
303// //if (Compile((char*)formula)) return;
304
305// SetRange(xmin, ymin, xmax, ymax);
306
307// Draw(option);
308
309// }
310
311////////////////////////////////////////////////////////////////////////////////
312/// Execute action corresponding to one event
313///
314/// This member function is called when a F2 is clicked with the locator
315
317{
318 TF1::ExecuteEvent(event, px, py);
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Return contour values into array levels
323///
324/// The number of contour levels can be returned by getContourLevel
325
327{
328 Int_t nlevels = fContour.fN;
329 if (levels) {
330 for (Int_t level=0; level<nlevels; level++) levels[level] = GetContourLevel(level);
331 }
332 return nlevels;
333}
334
335////////////////////////////////////////////////////////////////////////////////
336/// Return the number of contour levels
337
339{
340 if (level <0 || level >= fContour.fN) return 0;
341 if (fContour.fArray[0] != -9999) return fContour.fArray[level];
342 if (fHistogram == nullptr) return 0;
343 return fHistogram->GetContourLevel(level);
344}
345
346////////////////////////////////////////////////////////////////////////////////
347/// Return minimum/maximum value of the function
348///
349/// To find the minimum on a range, first set this range via the SetRange function.
350/// If a vector x of coordinate is passed it will be used as starting point for the minimum.
351/// In addition on exit x will contain the coordinate values at the minimuma
352///
353/// If x is NULL or x is infinity or NaN, first, a grid search is performed to find the initial estimate of the
354/// minimum location. The range of the function is divided into fNpx and fNpy
355/// sub-ranges. If the function is "good" (or "bad"), these values can be changed
356/// by SetNpx and SetNpy functions
357///
358/// Then, a minimization is used with starting values found by the grid search
359/// The minimizer algorithm used (by default Minuit) can be changed by callinga
360/// ROOT::Math::Minimizer::SetDefaultMinimizerType("..")
361/// Other option for the minimizer can be set using the static method of the MinimizerOptions class
362
364{
365 //First do a grid search with step size fNpx and fNpy
366
367 Double_t xx[2];
368 Double_t rsign = (findmax) ? -1. : 1.;
369 TF2 & function = const_cast<TF2&>(*this); // needed since EvalPar is not const
370 Double_t xxmin = 0, yymin = 0, zzmin = 0;
371 if (x == nullptr || ( (x!= nullptr) && ( !TMath::Finite(x[0]) || !TMath::Finite(x[1]) ) ) ){
372 Double_t dx = (fXmax - fXmin)/fNpx;
373 Double_t dy = (fYmax - fYmin)/fNpy;
374 xxmin = fXmin;
375 yymin = fYmin;
376 zzmin = rsign * TMath::Infinity();
377 for (Int_t i=0; i<fNpx; i++){
378 xx[0]=fXmin + (i+0.5)*dx;
379 for (Int_t j=0; j<fNpy; j++){
380 xx[1]=fYmin+(j+0.5)*dy;
381 Double_t zz = function(xx);
382 if (rsign*zz < rsign*zzmin) {xxmin = xx[0], yymin = xx[1]; zzmin = zz;}
383 }
384 }
385
386 xxmin = TMath::Min(fXmax, xxmin);
387 yymin = TMath::Min(fYmax, yymin);
388 }
389 else {
390 xxmin = x[0];
391 yymin = x[1];
392 zzmin = function(x);
393 }
394 xx[0] = xxmin;
395 xx[1] = yymin;
396
397 double fmin = GetMinMaxNDim(xx,findmax);
398 if (rsign*fmin < rsign*zzmin) {
399 if (x) {x[0] = xx[0]; x[1] = xx[1]; }
400 return fmin;
401 }
402 // here if minimization failed
403 if (x) { x[0] = xxmin; x[1] = yymin; }
404 return zzmin;
405}
406
407////////////////////////////////////////////////////////////////////////////////
408/// Compute the X and Y values corresponding to the minimum value of the function
409///
410/// Return the minimum value of the function
411/// To find the minimum on a range, first set this range via the SetRange function
412///
413/// Method:
414/// First, a grid search is performed to find the initial estimate of the
415/// minimum location. The range of the function is divided into fNpx and fNpy
416/// sub-ranges. If the function is "good" (or "bad"), these values can be changed
417/// by SetNpx and SetNpy functions
418/// Then, a minimization is used with starting values found by the grid search
419/// The minimizer algorithm used (by default Minuit) can be changed by callinga
420/// ROOT::Math::Minimizer::SetDefaultMinimizerType("..")
421/// Other option for the minimizer can be set using the static method of the MinimizerOptions class
422///
423/// Note that this method will always do first a grid search in contrast to GetMinimum
424
426{
427 double xx[2] = { 0,0 };
428 xx[0] = TMath::QuietNaN(); // to force to do grid search in TF2::FindMinMax
429 double fmin = FindMinMax(xx, false);
430 x = xx[0]; y = xx[1];
431 return fmin;
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// Compute the X and Y values corresponding to the maximum value of the function
436///
437/// Return the maximum value of the function
438/// See TF2::GetMinimumXY
439
441{
442 double xx[2] = { 0,0 };
443 xx[0] = TMath::QuietNaN(); // to force to do grid search in TF2::FindMinMax
444 double fmax = FindMinMax(xx, true);
445 x = xx[0]; y = xx[1];
446 return fmax;
447}
448
449
450////////////////////////////////////////////////////////////////////////////////
451/// Return minimum/maximum value of the function
452///
453/// To find the minimum on a range, first set this range via the SetRange function
454/// If a vector x of coordinate is passed it will be used as starting point for the minimum.
455/// In addition on exit x will contain the coordinate values at the minimuma
456/// If x is NULL or x is infinity or NaN, first, a grid search is performed to find the initial estimate of the
457/// minimum location. The range of the function is divided into fNpx and fNpy
458/// sub-ranges. If the function is "good" (or "bad"), these values can be changed
459/// by SetNpx and SetNpy functions
460/// Then, a minimization is used with starting values found by the grid search
461/// The minimizer algorithm used (by default Minuit) can be changed by callinga
462/// ROOT::Math::Minimizer::SetDefaultMinimizerType("..")
463/// Other option for the minimizer can be set using the static method of the MinimizerOptions class
464
466{
467 return FindMinMax(x, false);
468}
469
470////////////////////////////////////////////////////////////////////////////////
471/// Return maximum value of the function
472/// See TF2::GetMinimum
473
475{
476 return FindMinMax(x, true);
477}
478
479
480////////////////////////////////////////////////////////////////////////////////
481/// Redefines TObject::GetObjectInfo.
482///
483/// Displays the function value
484/// corresponding to cursor position px,py
485
486char *TF2::GetObjectInfo(Int_t px, Int_t py) const
487{
488 const char *snull = "";
489 if (!gPad) return (char*)snull;
490 static char info[64];
491 Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px));
492 Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py));
493 const char *drawOption = GetDrawOption();
494 Double_t uxmin,uxmax;
495 Double_t uymin,uymax;
496 if (gPad->GetView() || strncmp(drawOption,"cont",4) == 0
497 || strncmp(drawOption,"CONT",4) == 0) {
498 uxmin=gPad->GetUxmin();
499 uxmax=gPad->GetUxmax();
500 x = fXmin +(fXmax-fXmin)*(x-uxmin)/(uxmax-uxmin);
501 uymin=gPad->GetUymin();
502 uymax=gPad->GetUymax();
503 y = fYmin +(fYmax-fYmin)*(y-uymin)/(uymax-uymin);
504 }
505 snprintf(info,64,"(x=%g, y=%g, f=%.18g)",x,y,((TF2*)this)->Eval(x,y));
506 return info;
507}
508
509////////////////////////////////////////////////////////////////////////////////
510/// Return a random number following this function shape
511
513{
514 Error("GetRandom","cannot be called for TF2/3, use GetRandom2/3 instead");
515 return 0; // not yet implemented
516}
517
518////////////////////////////////////////////////////////////////////////////////
519/// Return a random number following this function shape
520
521
523{
524 Error("GetRandom","cannot be called for TF2/3, use GetRandom2/3 instead");
525 return 0; // not yet implemented
526}
527
528////////////////////////////////////////////////////////////////////////////////
529/// Return 2 random numbers following this function shape
530///
531/// The distribution contained in this TF2 function is integrated
532/// over the cell contents.
533/// It is normalized to 1.
534/// Getting the two random numbers implies:
535/// - Generating a random number between 0 and 1 (say r1)
536/// - Look in which cell in the normalized integral r1 corresponds to
537/// - make a linear interpolation in the returned cell
538///
539///
540/// IMPORTANT NOTE
541///
542/// The integral of the function is computed at fNpx * fNpy points.
543/// If the function has sharp peaks, you should increase the number of
544/// points (SetNpx, SetNpy) such that the peak is correctly tabulated
545/// at several points.
546
547void TF2::GetRandom2(Double_t &xrandom, Double_t &yrandom, TRandom * rng)
548{
549 // Check if integral array must be built
550 Int_t i,j,cell;
551 Double_t dx = (fXmax-fXmin)/fNpx;
552 Double_t dy = (fYmax-fYmin)/fNpy;
553 Int_t ncells = fNpx*fNpy;
554 if (fIntegral.empty()) {
555 fIntegral.resize(ncells+1);
556 fIntegral[0] = 0;
557 Double_t integ;
558 Int_t intNegative = 0;
559 cell = 0;
560 for (j=0;j<fNpy;j++) {
561 for (i=0;i<fNpx;i++) {
562 integ = Integral(fXmin+i*dx,fXmin+i*dx+dx,fYmin+j*dy,fYmin+j*dy+dy);
563 if (integ < 0) {intNegative++; integ = -integ;}
564 fIntegral[cell+1] = fIntegral[cell] + integ;
565 cell++;
566 }
567 }
568 if (intNegative > 0) {
569 Warning("GetRandom2","function:%s has %d negative values: abs assumed",GetName(),intNegative);
570 }
571 if (fIntegral[ncells] == 0) {
572 Error("GetRandom2","Integral of function is zero");
573 return;
574 }
575 for (i=1;i<=ncells;i++) { // normalize integral to 1
576 fIntegral[i] /= fIntegral[ncells];
577 }
578 }
579
580// return random numbers
581 Double_t r,ddx,ddy,dxint;
582 if (!rng) rng = gRandom;
583 r = rng->Rndm();
584 cell = TMath::BinarySearch(ncells,fIntegral.data(),r);
585 dxint = fIntegral[cell+1] - fIntegral[cell];
586 if (dxint > 0) ddx = dx*(r - fIntegral[cell])/dxint;
587 else ddx = 0;
588 ddy = dy*rng->Rndm();
589 j = cell/fNpx;
590 i = cell%fNpx;
591 xrandom = fXmin +dx*i +ddx;
592 yrandom = fYmin +dy*j +ddy;
593}
594
595////////////////////////////////////////////////////////////////////////////////
596/// Return range of a 2-D function
597
599{
600 xmin = fXmin;
601 xmax = fXmax;
602 ymin = fYmin;
603 ymax = fYmax;
604}
605
606////////////////////////////////////////////////////////////////////////////////
607/// Return range of function
608
610{
611 xmin = fXmin;
612 xmax = fXmax;
613 ymin = fYmin;
614 ymax = fYmax;
615 zmin = 0;
616 zmax = 0;
617}
618
619
620////////////////////////////////////////////////////////////////////////////////
621/// Get value corresponding to X in array of fSave values
622
624{
625 if (fSave.size() < 6) return 0;
626 Int_t nsave = fSave.size() - 6;
627 Double_t xmin = fSave[nsave+0];
628 Double_t xmax = fSave[nsave+1];
629 Double_t ymin = fSave[nsave+2];
630 Double_t ymax = fSave[nsave+3];
631 Int_t npx = Int_t(fSave[nsave+4]);
632 Int_t npy = Int_t(fSave[nsave+5]);
633 Double_t x = Double_t(xx[0]);
634 Double_t dx = (xmax-xmin)/npx;
635 if (x < xmin || x > xmax) return 0;
636 if (dx <= 0) return 0;
637 Double_t y = Double_t(xx[1]);
638 Double_t dy = (ymax-ymin)/npy;
639 if (y < ymin || y > ymax) return 0;
640 if (dy <= 0) return 0;
641
642 //we make a bilinear interpolation using the 4 points surrounding x,y
643 Int_t ibin = TMath::Min(npx-1, Int_t((x-xmin)/dx));
644 Int_t jbin = TMath::Min(npy-1, Int_t((y-ymin)/dy));
645 Double_t xlow = xmin + ibin*dx;
646 Double_t ylow = ymin + jbin*dy;
647 Double_t t = (x-xlow)/dx;
648 Double_t u = (y-ylow)/dy;
649 Int_t k1 = jbin*(npx+1) + ibin;
650 Int_t k2 = jbin*(npx+1) + ibin +1;
651 Int_t k3 = (jbin+1)*(npx+1) + ibin +1;
652 Int_t k4 = (jbin+1)*(npx+1) + ibin;
653 Double_t z = (1-t)*(1-u)*fSave[k1] +t*(1-u)*fSave[k2] +t*u*fSave[k3] + (1-t)*u*fSave[k4];
654 return z;
655}
656
657////////////////////////////////////////////////////////////////////////////////
658/// Return Integral of a 2d function in range [ax,bx],[ay,by]
659/// with desired relative accuracy (defined by eps)
660
662{
663 Double_t a[2], b[2];
664 a[0] = ax;
665 b[0] = bx;
666 a[1] = ay;
667 b[1] = by;
668 Double_t relerr = 0;
669 Int_t n = 2;
671 Int_t nfnevl,ifail;
672 Double_t result = IntegralMultiple(n,a,b,maxpts,epsrel,epsrel,relerr,nfnevl,ifail);
673 if (ifail > 0) {
674 Warning("Integral","failed for %s code=%d, maxpts=%d, epsrel=%g, nfnevl=%d, relerr=%g ",GetName(),ifail,maxpts,epsrel,nfnevl,relerr);
675 }
676 if (gDebug) {
677 Info("Integral", "Integral of %s using %d and tol=%f is %f , relerr=%f nfcn=%d", GetName(), maxpts,epsrel,result,relerr,nfnevl);
678 }
679 return result;
680}
681
682////////////////////////////////////////////////////////////////////////////////
683/// Return kTRUE is the point is inside the function range
684
686{
687 if (x[0] < fXmin || x[0] > fXmax) return kFALSE;
688 if (x[1] < fYmin || x[1] > fYmax) return kFALSE;
689 return kTRUE;
690}
691
692////////////////////////////////////////////////////////////////////////////////
693/// Create a histogram from function.
694///
695/// always created it, even if it is already existing
696
698{
699 Int_t i,j,bin;
700 Double_t dx, dy;
701 Double_t xv[2];
702
703
704 Double_t *parameters = GetParameters();
705 TH2F* h = new TH2F("Func",(char*)GetTitle(),fNpx,fXmin,fXmax,fNpy,fYmin,fYmax);
706 h->SetDirectory(nullptr);
707
708 InitArgs(xv,parameters);
709 dx = (fXmax - fXmin)/Double_t(fNpx);
710 dy = (fYmax - fYmin)/Double_t(fNpy);
711 for (i=1;i<=fNpx;i++) {
712 xv[0] = fXmin + (Double_t(i) - 0.5)*dx;
713 for (j=1;j<=fNpy;j++) {
714 xv[1] = fYmin + (Double_t(j) - 0.5)*dy;
715 bin = j*(fNpx + 2) + i;
716 h->SetBinContent(bin,EvalPar(xv,parameters));
717 }
718 }
719 h->Fill(fXmin-1,fYmin-1,0); //This call to force fNentries non zero
720
721 Double_t *levels = fContour.GetArray();
722 if (levels && levels[0] == -9999) levels = nullptr;
723 h->SetMinimum(fMinimum);
724 h->SetMaximum(fMaximum);
725 h->SetContour(fContour.fN, levels);
726 h->SetLineColor(GetLineColor());
727 h->SetLineStyle(GetLineStyle());
728 h->SetLineWidth(GetLineWidth());
729 h->SetFillColor(GetFillColor());
730 h->SetFillStyle(GetFillStyle());
731 h->SetMarkerColor(GetMarkerColor());
732 h->SetMarkerStyle(GetMarkerStyle());
733 h->SetMarkerSize(GetMarkerSize());
734 h->SetStats(false);
735
736 return h;
737}
738
739////////////////////////////////////////////////////////////////////////////////
740/// Paint this 2-D function with its current attributes
741
743{
744 Int_t i,j,bin;
745 Double_t dx, dy;
746 Double_t xv[2];
747 Double_t *parameters = GetParameters();
748 TString opt = option;
749 opt.ToLower();
750
751//- Create a temporary histogram and fill each channel with the function value
752 if (!fHistogram) {
753 fHistogram = new TH2F("Func",(char*)GetTitle(),fNpx,fXmin,fXmax,fNpy,fYmin,fYmax);
754 if (!fHistogram) return;
755 fHistogram->SetDirectory(nullptr);
756 }
757 InitArgs(xv,parameters);
758 dx = (fXmax - fXmin)/Double_t(fNpx);
759 dy = (fYmax - fYmin)/Double_t(fNpy);
760 for (i=1;i<=fNpx;i++) {
761 xv[0] = fXmin + (Double_t(i) - 0.5)*dx;
762 for (j=1;j<=fNpy;j++) {
763 xv[1] = fYmin + (Double_t(j) - 0.5)*dy;
764 bin = j*(fNpx + 2) + i;
765 fHistogram->SetBinContent(bin,EvalPar(xv,parameters));
766 }
767 }
768 ((TH2F*)fHistogram)->Fill(fXmin-1,fYmin-1,0); //This call to force fNentries non zero
769
770//- Copy Function attributes to histogram attributes
771 Double_t *levels = fContour.GetArray();
772 if (levels && levels[0] == -9999) levels = nullptr;
784 fHistogram->SetStats(false);
785
786//- Draw the histogram
787 if (!gPad) return;
788 if (opt.Length() == 0) fHistogram->Paint("cont3");
789 else if (opt == "same") fHistogram->Paint("cont2same");
790 else fHistogram->Paint(option);
791}
792
793////////////////////////////////////////////////////////////////////////////////
794/// Save values of function in array fSave
795
797{
798 if (!fSave.empty())
799 fSave.clear();
800 Int_t npx = fNpx, npy = fNpy;
801 if ((npx < 2) || (npy < 2))
802 return;
803 Double_t dx = (xmax-xmin)/fNpx;
804 Double_t dy = (ymax-ymin)/fNpy;
805 if (dx <= 0) {
806 dx = (fXmax-fXmin)/fNpx;
807 npx--;
808 xmin = fXmin + 0.5*dx;
809 xmax = fXmax - 0.5*dx;
810 }
811 if (dy <= 0) {
812 dy = (fYmax-fYmin)/fNpy;
813 npy--;
814 ymin = fYmin + 0.5*dy;
815 ymax = fYmax - 0.5*dy;
816 }
817
818 Int_t nsave = (npx + 1) * (npy + 1);
819 fSave.resize(nsave + 6);
820 Double_t xv[2];
821 Double_t *parameters = GetParameters();
822 InitArgs(xv, parameters);
823 for (Int_t j = 0, k = 0; j <= npy; j++) {
824 xv[1] = ymin + dy*j;
825 for (Int_t i = 0; i <= npx; i++) {
826 xv[0] = xmin + dx*i;
827 fSave[k++] = EvalPar(xv, parameters);
828 }
829 }
830 fSave[nsave+0] = xmin;
831 fSave[nsave+1] = xmax;
832 fSave[nsave+2] = ymin;
833 fSave[nsave+3] = ymax;
834 fSave[nsave+4] = npx;
835 fSave[nsave+5] = npy;
836}
837
838////////////////////////////////////////////////////////////////////////////////
839/// Save primitive as a C++ statement(s) on output stream out
840
841void TF2::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
842{
843 char quote = '"';
844 TString f2Name(GetName());
845 out<<" "<<std::endl;
846 if (gROOT->ClassSaved(TF2::Class())) {
847 out<<" ";
848 } else {
849 out<<" TF2 *";
850 }
851 if (!fMethodCall) {
852 out<<f2Name.Data()<<" = new TF2("<<quote<<f2Name.Data()<<quote<<","<<quote<<GetTitle()<<quote<<","<<fXmin<<","<<fXmax<<","<<fYmin<<","<<fYmax<<");"<<std::endl;
853 } else {
854 out<<f2Name.Data()<<" = new TF2("<<quote<<f2Name.Data()<<quote<<","<<GetTitle()<<","<<fXmin<<","<<fXmax<<","<<fYmin<<","<<fYmax<<","<<GetNpar()<<");"<<std::endl;
855 }
856
857 SaveFillAttributes(out, f2Name.Data(), 0, 1001);
858 SaveMarkerAttributes(out, f2Name.Data(), 1, 1, 1);
859 SaveLineAttributes(out, f2Name.Data(), 1, 1, 4);
860
861 if (GetNpx() != 30)
862 out<<" "<<f2Name.Data()<<"->SetNpx("<<GetNpx()<<");"<<std::endl;
863 if (GetNpy() != 30)
864 out<<" "<<f2Name.Data()<<"->SetNpy("<<GetNpy()<<");"<<std::endl;
865
866 if (GetChisquare() != 0)
867 out<<" "<<f2Name.Data()<<"->SetChisquare("<<GetChisquare()<<");"<<std::endl;
868
869 Double_t parmin, parmax;
870 for (Int_t i=0;i<GetNpar();i++) {
871 out<<" "<<f2Name.Data()<<"->SetParameter("<<i<<","<<GetParameter(i)<<");"<<std::endl;
872 out<<" "<<f2Name.Data()<<"->SetParError("<<i<<","<<GetParError(i)<<");"<<std::endl;
873 GetParLimits(i,parmin,parmax);
874 out<<" "<<f2Name.Data()<<"->SetParLimits("<<i<<","<<parmin<<","<<parmax<<");"<<std::endl;
875 }
876 out<<" "<<f2Name.Data()<<"->Draw("<<quote<<option<<quote<<");"<<std::endl;
877
878 if (GetXaxis()) GetXaxis()->SaveAttributes(out, f2Name.Data(), "->GetXaxis()");
879 if (GetYaxis()) GetYaxis()->SaveAttributes(out, f2Name.Data(), "->GetYaxis()");
880 if (GetZaxis()) GetZaxis()->SaveAttributes(out, f2Name.Data(), "->GetZaxis()");
881}
882
883
884
885////////////////////////////////////////////////////////////////////////////////
886/// Set the number and values of contour levels
887///
888/// By default the number of contour levels is set to 20.
889///
890/// if argument levels = 0 or missing, equidistant contours are computed
891
892void TF2::SetContour(Int_t nlevels, const Double_t *levels)
893{
894 Int_t level;
895 if (nlevels <=0 ) {
896 fContour.Set(0);
897 return;
898 }
899 fContour.Set(nlevels);
900
901 //- Contour levels are specified
902 if (levels) {
903 for (level=0; level<nlevels; level++) fContour.fArray[level] = levels[level];
904 } else {
905 fContour.fArray[0] = -9999; // means not defined at this point
906 }
907}
908
909
910////////////////////////////////////////////////////////////////////////////////
911/// Set value for one contour level
912
914{
915 if (level <0 || level >= fContour.fN) return;
916 fContour.fArray[level] = value;
917}
918
919////////////////////////////////////////////////////////////////////////////////
920/// Set the number of points used to draw the function
921///
922/// The default number of points along x is 30 for 2-d/3-d functions.
923/// You can increase this value to get a better resolution when drawing
924/// pictures with sharp peaks or to get a better result when using TF2::GetRandom2
925/// the minimum number of points is 4, the maximum is 10000 for 2-d/3-d functions
926
928{
929 if (npy < 4) {
930 Warning("SetNpy","Number of points must be >=4 && <= 10000, fNpy set to 4");
931 fNpy = 4;
932 } else if(npy > 10000) {
933 Warning("SetNpy","Number of points must be >=4 && <= 10000, fNpy set to 10000");
934 fNpy = 10000;
935 } else {
936 fNpy = npy;
937 }
938 Update();
939}
940
941////////////////////////////////////////////////////////////////////////////////
942/// Initialize the upper and lower bounds to draw the function-
943
945{
946 fXmin = xmin;
947 fXmax = xmax;
948 fYmin = ymin;
949 fYmax = ymax;
950 Update();
951}
952
953////////////////////////////////////////////////////////////////////////////////
954/// Stream an object of class TF2.
955
957{
958 if (R__b.IsReading()) {
959 UInt_t R__s, R__c;
960 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
961 if (R__v > 3) {
962 R__b.ReadClassBuffer(TF2::Class(), this, R__v, R__s, R__c);
963 return;
964 }
965 //====process old versions before automatic schema evolution
966 Int_t nlevels;
967 TF1::Streamer(R__b);
968 if (R__v < 3) {
970 R__b >> ymin; fYmin = ymin;
971 R__b >> ymax; fYmax = ymax;
972 } else {
973 R__b >> fYmin;
974 R__b >> fYmax;
975 }
976 R__b >> fNpy;
977 R__b >> nlevels;
978 if (R__v < 3) {
979 Float_t *contour = nullptr;
980 Int_t n = R__b.ReadArray(contour);
981 fContour.Set(n);
982 for (Int_t i=0;i<n;i++) fContour.fArray[i] = contour[i];
983 delete [] contour;
984 } else {
985 fContour.Streamer(R__b);
986 }
987 R__b.CheckByteCount(R__s, R__c, TF2::IsA());
988 //====end of old versions
989
990 } else {
991 Int_t saved = 0;
992 if (fType != EFType::kFormula && fSave.empty()) { saved = 1; Save(fXmin,fXmax,fYmin,fYmax,0,0);}
993
994 R__b.WriteClassBuffer(TF2::Class(),this);
995
996 if (saved) {fSave.clear(); }
997 }
998}
999
1000////////////////////////////////////////////////////////////////////////////////
1001/// Return x^nx * y^ny moment of a 2d function in range [ax,bx],[ay,by]
1002/// \author Gene Van Buren <gene@bnl.gov>
1003
1005{
1006 Double_t norm = Integral(ax,bx,ay,by,epsilon);
1007 if (norm == 0) {
1008 Error("Moment2", "Integral zero over range");
1009 return 0;
1010 }
1011
1012 // define integrand function as a lambda : g(x,y)= x^(nx) * y^(ny) * f(x,y)
1013 auto integrand = [&](double *x, double *) {
1014 return std::pow(x[0], nx) * std::pow(x[1], ny) * this->EvalPar(x, nullptr);
1015 };
1016 // compute integral of g(x,y)
1017 TF2 fnc("TF2_ExpValHelper",integrand,ax,bx,ay,by,0);
1018 // set same points as current function to get correct max points when computing the integral
1019 fnc.fNpx = fNpx;
1020 fnc.fNpy = fNpy;
1021 return fnc.Integral(ax,bx,ay,by,epsilon)/norm;
1022}
1023
1024////////////////////////////////////////////////////////////////////////////////
1025/// Return x^nx * y^ny central moment of a 2d function in range [ax,bx],[ay,by]
1026/// \author Gene Van Buren <gene@bnl.gov>
1027
1029{
1030 Double_t norm = Integral(ax,bx,ay,by,epsilon);
1031 if (norm == 0) {
1032 Error("CentralMoment2", "Integral zero over range");
1033 return 0;
1034 }
1035
1036 Double_t xbar = 0;
1037 Double_t ybar = 0;
1038 if (nx!=0) {
1039 // compute first momentum in x
1040 auto integrandX = [&](double *x, double *) { return x[0] * this->EvalPar(x, nullptr); };
1041 TF2 fncx("TF2_ExpValHelperx",integrandX, ax, bx, ay, by, 0);
1042 fncx.fNpx = fNpx;
1043 fncx.fNpy = fNpy;
1044 xbar = fncx.Integral(ax,bx,ay,by,epsilon)/norm;
1045 }
1046 if (ny!=0) {
1047 // compute first momentum in y
1048 auto integrandY = [&](double *x, double *) { return x[1] * this->EvalPar(x, nullptr); };
1049 TF2 fncy("TF2_ExpValHelperx", integrandY, ax, bx, ay, by, 0);
1050 fncy.fNpx = fNpx;
1051 fncy.fNpy = fNpy;
1052 ybar = fncy.Integral(ax,bx,ay,by,epsilon)/norm;
1053 }
1054 // define integrand function as a lambda : g(x,y)= (x-xbar)^(nx) * (y-ybar)^(ny) * f(x,y)
1055 auto integrand = [&](double *x, double *) {
1056 double xxx = (nx != 0) ? std::pow(x[0] - xbar, nx) : 1.;
1057 double yyy = (ny != 0) ? std::pow(x[1] - ybar, ny) : 1.;
1058 return xxx * yyy * this->EvalPar(x, nullptr);
1059 };
1060 // compute integral of g(x,y)
1061 TF2 fnc("TF2_ExpValHelper", integrand, ax, bx, ay, by, 0);
1062 fnc.fNpx = fNpx;
1063 fnc.fNpy = fNpy;
1064 return fnc.Integral(ax, bx, ay, by, epsilon) / norm;
1065}
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
short Version_t
Definition RtypesCore.h:65
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
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 r
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 result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110
float xmin
float ymin
float xmax
float ymax
Int_t gDebug
Definition TROOT.cxx:597
#define gROOT
Definition TROOT.h:406
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
#define gPad
#define snprintf
Definition civetweb.c:1540
Param Functor class for Multidimensional functions.
Double_t * fArray
Definition TArrayD.h:30
void Streamer(TBuffer &) override
Stream a TArrayD object.
Definition TArrayD.cxx:149
void Copy(TArrayD &array) const
Definition TArrayD.h:42
void Set(Int_t n) override
Set size of this array to n doubles.
Definition TArrayD.cxx:106
const Double_t * GetArray() const
Definition TArrayD.h:43
Int_t fN
Definition TArray.h:38
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:30
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:31
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:39
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition TAttFill.cxx:239
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:33
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:42
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:35
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:34
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:275
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition TAttMarker.h:32
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:31
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition TAttMarker.h:33
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:45
void SaveAttributes(std::ostream &out, const char *name, const char *subname) override
Save axis attributes as C++ statement(s) on output stream out.
Definition TAxis.cxx:711
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t ReadArray(Bool_t *&b)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
1-Dim function class
Definition TF1.h:233
Int_t fNdim
Function dimension.
Definition TF1.h:266
virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
Return limits for parameter ipar.
Definition TF1.cxx:1940
TAxis * GetYaxis() const
Get y axis of the function.
Definition TF1.cxx:2411
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition TF1.cxx:1930
Double_t GetChisquare() const
Return the Chisquare after fitting. See ROOT::Fit::FitResult::Chi2()
Definition TF1.h:472
Double_t fXmin
Lower bounds for the range.
Definition TF1.h:263
std::unique_ptr< TMethodCall > fMethodCall
! Pointer to MethodCall in case of interpreted function
Definition TF1.h:284
virtual void Update()
Called by functions such as SetRange, SetNpx, SetParameters to force the deletion of the associated h...
Definition TF1.cxx:3619
TAxis * GetZaxis() const
Get z axis of the function. (In case this object is a TF2 or TF3)
Definition TF1.cxx:2422
virtual Int_t GetNpar() const
Definition TF1.h:509
TH1 * fHistogram
! Pointer to histogram used for visualisation
Definition TF1.h:283
Double_t fMaximum
Maximum value for plotting.
Definition TF1.h:273
virtual Double_t * GetParameters() const
Definition TF1.h:548
Double_t fMinimum
Minimum value for plotting.
Definition TF1.h:272
void Copy(TObject &f1) const override
Copy this F1 to a new F1.
Definition TF1.cxx:1005
void Streamer(TBuffer &) override
Stream a class object.
Definition TF1.cxx:3571
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition TF1.cxx:2482
virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Int_t maxpts, Double_t epsrel, Double_t epsabs, Double_t &relerr, Int_t &nfnevl, Int_t &ifail)
This function computes, to an attempted specified accuracy, the value of the integral.
Definition TF1.cxx:2851
EFType fType
Definition TF1.h:268
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=nullptr)
Evaluate function with given coordinates and parameters.
Definition TF1.cxx:1468
Int_t fNpx
Number of points used for the graphical representation.
Definition TF1.h:267
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TF1.cxx:1536
std::vector< Double_t > fSave
Array of fNsave function values.
Definition TF1.h:277
virtual Double_t GetMinMaxNDim(Double_t *x, Bool_t findmax, Double_t epsilon=0, Int_t maxiter=0) const
Find the minimum of a function of whatever dimension.
Definition TF1.cxx:1723
std::vector< Double_t > fIntegral
! Integral of function binned on fNpx bins
Definition TF1.h:278
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Definition TF1.cxx:1439
@ kFormula
Formula functions which can be stored,.
Definition TF1.h:255
virtual Int_t GetNpx() const
Definition TF1.h:518
Double_t fXmax
Upper bounds for the range.
Definition TF1.h:264
virtual Int_t GetNdim() const
Definition TF1.h:513
virtual Double_t GetParameter(Int_t ipar) const
Definition TF1.h:540
TAxis * GetXaxis() const
Get x axis of the function.
Definition TF1.cxx:2400
A 2-Dim function with parameters.
Definition TF2.h:29
virtual Double_t GetMaximumXY(Double_t &x, Double_t &y) const
Compute the X and Y values corresponding to the maximum value of the function.
Definition TF2.cxx:440
void Streamer(TBuffer &) override
Stream an object of class TF2.
Definition TF2.cxx:956
virtual Double_t FindMinMax(Double_t *x, bool findmax) const
Return minimum/maximum value of the function.
Definition TF2.cxx:363
~TF2() override
F2 default destructor.
Definition TF2.cxx:195
virtual Double_t GetMinimum(Double_t *x) const
Return minimum/maximum value of the function.
Definition TF2.cxx:465
void Copy(TObject &f2) const override
Copy this F2 to a new F2.
Definition TF2.cxx:210
virtual void GetRandom2(Double_t &xrandom, Double_t &yrandom, TRandom *rng=nullptr)
Return 2 random numbers following this function shape.
Definition TF2.cxx:547
Double_t GetSave(const Double_t *x) override
Get value corresponding to X in array of fSave values.
Definition TF2.cxx:623
TClass * IsA() const override
Definition TF2.h:143
void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax) override
Save values of function in array fSave.
Definition TF2.cxx:796
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a function.
Definition TF2.cxx:228
virtual void SetContour(Int_t nlevels=20, const Double_t *levels=nullptr)
Set the number and values of contour levels.
Definition TF2.cxx:892
TH1 * CreateHistogram() override
Create a histogram from function.
Definition TF2.cxx:697
void GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const override
Return range of a 2-D function.
Definition TF2.cxx:598
virtual Int_t GetContour(Double_t *levels=nullptr)
Return contour values into array levels.
Definition TF2.cxx:326
Bool_t IsInside(const Double_t *x) const override
Return kTRUE is the point is inside the function range.
Definition TF2.cxx:685
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition TF2.cxx:927
virtual Double_t Moment2(Double_t nx, Double_t ax, Double_t bx, Double_t ny, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Return x^nx * y^ny moment of a 2d function in range [ax,bx],[ay,by].
Definition TF2.cxx:1004
TF1 * DrawCopy(Option_t *option="") const override
Draw a copy of this function with its current attributes-*.
Definition TF2.cxx:286
virtual Double_t GetMinimumXY(Double_t &x, Double_t &y) const
Compute the X and Y values corresponding to the minimum value of the function.
Definition TF2.cxx:425
Int_t fNpy
Number of points along y used for the graphical representation.
Definition TF2.h:34
void Paint(Option_t *option="") override
Paint this 2-D function with its current attributes.
Definition TF2.cxx:742
TArrayD fContour
Array to display contour levels.
Definition TF2.h:35
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition TF2.cxx:259
Double_t fYmax
Upper bound for the range in y.
Definition TF2.h:33
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TF2.cxx:841
TF2 & operator=(const TF2 &rhs)
Operator =.
Definition TF2.cxx:185
char * GetObjectInfo(Int_t px, Int_t py) const override
Redefines TObject::GetObjectInfo.
Definition TF2.cxx:486
virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsrel=1.e-6)
Return Integral of a 2d function in range [ax,bx],[ay,by] with desired relative accuracy (defined by ...
Definition TF2.cxx:661
Double_t fYmin
Lower bound for the range in y.
Definition TF2.h:32
Int_t GetNpy() const
Definition TF2.h:96
virtual Double_t GetContourLevel(Int_t level) const
Return the number of contour levels.
Definition TF2.cxx:338
virtual Double_t CentralMoment2(Double_t nx, Double_t ax, Double_t bx, Double_t ny, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Return x^nx * y^ny central moment of a 2d function in range [ax,bx],[ay,by].
Definition TF2.cxx:1028
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TF2.cxx:316
virtual void SetContourLevel(Int_t level, Double_t value)
Set value for one contour level.
Definition TF2.cxx:913
TF2()
TF2 default constructor.
Definition TF2.cxx:83
virtual Double_t GetMaximum(Double_t *x) const
Return maximum value of the function See TF2::GetMinimum.
Definition TF2.cxx:474
Double_t GetRandom(TRandom *rng=nullptr, Option_t *opt=nullptr) override
Return a random number following this function shape.
Definition TF2.cxx:512
void SetRange(Double_t xmin, Double_t xmax) override
Initialize the upper and lower bounds to draw the function.
Definition TF2.h:146
static TClass * Class()
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8964
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a line.
Definition TH1.cxx:2825
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:404
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:405
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition TH1.cxx:9249
void Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
Definition TH1.cxx:6229
virtual Double_t GetContourLevel(Int_t level) const
Return value of contour number level.
Definition TH1.cxx:8457
virtual void SetContour(Int_t nlevels, const Double_t *levels=nullptr)
Set the number and values of contour levels.
Definition TH1.cxx:8510
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:9017
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
Mother of all ROOT objects.
Definition TObject.h:41
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition TObject.cxx:440
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:991
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:202
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:798
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1005
void MakeZombie()
Definition TObject.h:53
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:62
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:979
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:559
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
const char * Data() const
Definition TString.h:376
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754.
Definition TMath.h:906
Int_t Finite(Double_t x)
Check if it is finite with a mask in order to be consistent in presence of fast math.
Definition TMath.h:774
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Definition TMathBase.h:347
Double_t Infinity()
Returns an infinity as defined by the IEEE standard.
Definition TMath.h:921