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(): TF1(),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());
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 == 0) 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 == NULL || ( (x!= NULL) && ( !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 (fNsave <= 0) return 0;
626 if (fSave.empty()) return 0;
627 Int_t fNsave = fSave.size();
628 Int_t np = fNsave - 6;
633 Int_t npx = Int_t(fSave[np+4]);
634 Int_t npy = Int_t(fSave[np+5]);
635 Double_t x = Double_t(xx[0]);
636 Double_t dx = (xmax-xmin)/npx;
637 if (x < xmin || x > xmax) return 0;
638 if (dx <= 0) return 0;
639 Double_t y = Double_t(xx[1]);
640 Double_t dy = (ymax-ymin)/npy;
641 if (y < ymin || y > ymax) return 0;
642 if (dy <= 0) return 0;
643
644 //we make a bilinear interpolation using the 4 points surrounding x,y
645 Int_t ibin = Int_t((x-xmin)/dx);
646 Int_t jbin = Int_t((y-ymin)/dy);
647 Double_t xlow = xmin + ibin*dx;
648 Double_t ylow = ymin + jbin*dy;
649 Double_t t = (x-xlow)/dx;
650 Double_t u = (y-ylow)/dy;
651 Int_t k1 = jbin*(npx+1) + ibin;
652 Int_t k2 = jbin*(npx+1) + ibin +1;
653 Int_t k3 = (jbin+1)*(npx+1) + ibin +1;
654 Int_t k4 = (jbin+1)*(npx+1) + ibin;
655 Double_t z = (1-t)*(1-u)*fSave[k1] +t*(1-u)*fSave[k2] +t*u*fSave[k3] + (1-t)*u*fSave[k4];
656 return z;
657}
658
659////////////////////////////////////////////////////////////////////////////////
660/// Return Integral of a 2d function in range [ax,bx],[ay,by]
661/// with desired relative accuracy (default value of eps is 1.e-9)
662
664{
665 Double_t a[2], b[2];
666 a[0] = ax;
667 b[0] = bx;
668 a[1] = ay;
669 b[1] = by;
670 Double_t relerr = 0;
671 Int_t n = 2;
673 Int_t nfnevl,ifail;
674 Double_t result = IntegralMultiple(n,a,b,maxpts,epsrel,epsrel,relerr,nfnevl,ifail);
675 if (ifail > 0) {
676 Warning("Integral","failed for %s code=%d, maxpts=%d, epsrel=%g, nfnevl=%d, relerr=%g ",GetName(),ifail,maxpts,epsrel,nfnevl,relerr);
677 }
678 if (gDebug) {
679 Info("Integral", "Integral of %s using %d and tol=%f is %f , relerr=%f nfcn=%d", GetName(), maxpts,epsrel,result,relerr,nfnevl);
680 }
681 return result;
682}
683
684////////////////////////////////////////////////////////////////////////////////
685/// Return kTRUE is the point is inside the function range
686
688{
689 if (x[0] < fXmin || x[0] > fXmax) return kFALSE;
690 if (x[1] < fYmin || x[1] > fYmax) return kFALSE;
691 return kTRUE;
692}
693
694////////////////////////////////////////////////////////////////////////////////
695/// Create a histogram from function.
696///
697/// always created it, even if it is already existing
698
700{
701 Int_t i,j,bin;
702 Double_t dx, dy;
703 Double_t xv[2];
704
705
706 Double_t *parameters = GetParameters();
707 TH2F* h = new TH2F("Func",(char*)GetTitle(),fNpx,fXmin,fXmax,fNpy,fYmin,fYmax);
708 h->SetDirectory(0);
709
710 InitArgs(xv,parameters);
711 dx = (fXmax - fXmin)/Double_t(fNpx);
712 dy = (fYmax - fYmin)/Double_t(fNpy);
713 for (i=1;i<=fNpx;i++) {
714 xv[0] = fXmin + (Double_t(i) - 0.5)*dx;
715 for (j=1;j<=fNpy;j++) {
716 xv[1] = fYmin + (Double_t(j) - 0.5)*dy;
717 bin = j*(fNpx + 2) + i;
718 h->SetBinContent(bin,EvalPar(xv,parameters));
719 }
720 }
721 h->Fill(fXmin-1,fYmin-1,0); //This call to force fNentries non zero
722
723 Double_t *levels = fContour.GetArray();
724 if (levels && levels[0] == -9999) levels = 0;
725 h->SetMinimum(fMinimum);
726 h->SetMaximum(fMaximum);
727 h->SetContour(fContour.fN, levels);
728 h->SetLineColor(GetLineColor());
729 h->SetLineStyle(GetLineStyle());
730 h->SetLineWidth(GetLineWidth());
731 h->SetFillColor(GetFillColor());
732 h->SetFillStyle(GetFillStyle());
733 h->SetMarkerColor(GetMarkerColor());
734 h->SetMarkerStyle(GetMarkerStyle());
735 h->SetMarkerSize(GetMarkerSize());
736 h->SetStats(0);
737
738 return h;
739}
740
741////////////////////////////////////////////////////////////////////////////////
742/// Paint this 2-D function with its current attributes
743
745{
746 Int_t i,j,bin;
747 Double_t dx, dy;
748 Double_t xv[2];
749 Double_t *parameters = GetParameters();
750 TString opt = option;
751 opt.ToLower();
752
753//- Create a temporary histogram and fill each channel with the function value
754 if (!fHistogram) {
755 fHistogram = new TH2F("Func",(char*)GetTitle(),fNpx,fXmin,fXmax,fNpy,fYmin,fYmax);
756 if (!fHistogram) return;
758 }
759 InitArgs(xv,parameters);
760 dx = (fXmax - fXmin)/Double_t(fNpx);
761 dy = (fYmax - fYmin)/Double_t(fNpy);
762 for (i=1;i<=fNpx;i++) {
763 xv[0] = fXmin + (Double_t(i) - 0.5)*dx;
764 for (j=1;j<=fNpy;j++) {
765 xv[1] = fYmin + (Double_t(j) - 0.5)*dy;
766 bin = j*(fNpx + 2) + i;
767 fHistogram->SetBinContent(bin,EvalPar(xv,parameters));
768 }
769 }
770 ((TH2F*)fHistogram)->Fill(fXmin-1,fYmin-1,0); //This call to force fNentries non zero
771
772//- Copy Function attributes to histogram attributes
773 Double_t *levels = fContour.GetArray();
774 if (levels && levels[0] == -9999) levels = 0;
787
788//- Draw the histogram
789 if (!gPad) return;
790 if (opt.Length() == 0) fHistogram->Paint("cont3");
791 else if (opt == "same") fHistogram->Paint("cont2same");
792 else fHistogram->Paint(option);
793}
794
795////////////////////////////////////////////////////////////////////////////////
796/// Save values of function in array fSave
797
799{
800 if (!fSave.empty()) fSave.clear();
801 //if (fSave != 0) {delete [] fSave; fSave = 0;}
802 Int_t nsave = (fNpx+1)*(fNpy+1);
803 Int_t fNsave = nsave+6;
804 if (fNsave <= 6) {fNsave=0; return;}
805 //fSave = new Double_t[fNsave];
806 fSave.resize(fNsave);
807 Int_t i,j,k=0;
808 Double_t dx = (xmax-xmin)/fNpx;
809 Double_t dy = (ymax-ymin)/fNpy;
810 if (dx <= 0) {
811 dx = (fXmax-fXmin)/fNpx;
812 xmin = fXmin +0.5*dx;
813 xmax = fXmax -0.5*dx;
814 }
815 if (dy <= 0) {
816 dy = (fYmax-fYmin)/fNpy;
817 ymin = fYmin +0.5*dy;
818 ymax = fYmax -0.5*dy;
819 }
820 Double_t xv[2];
821 Double_t *parameters = GetParameters();
822 InitArgs(xv,parameters);
823 for (j=0;j<=fNpy;j++) {
824 xv[1] = ymin + dy*j;
825 for (i=0;i<=fNpx;i++) {
826 xv[0] = xmin + dx*i;
827 fSave[k] = EvalPar(xv,parameters);
828 k++;
829 }
830 }
831 fSave[nsave+0] = xmin;
832 fSave[nsave+1] = xmax;
833 fSave[nsave+2] = ymin;
834 fSave[nsave+3] = ymax;
835 fSave[nsave+4] = fNpx;
836 fSave[nsave+5] = fNpy;
837}
838
839////////////////////////////////////////////////////////////////////////////////
840/// Save primitive as a C++ statement(s) on output stream out
841
842void TF2::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
843{
844 char quote = '"';
845 out<<" "<<std::endl;
846 if (gROOT->ClassSaved(TF2::Class())) {
847 out<<" ";
848 } else {
849 out<<" TF2 *";
850 }
851 if (!fMethodCall) {
852 out<<GetName()<<" = new TF2("<<quote<<GetName()<<quote<<","<<quote<<GetTitle()<<quote<<","<<fXmin<<","<<fXmax<<","<<fYmin<<","<<fYmax<<");"<<std::endl;
853 } else {
854 out<<GetName()<<" = new TF2("<<quote<<GetName()<<quote<<","<<GetTitle()<<","<<fXmin<<","<<fXmax<<","<<fYmin<<","<<fYmax<<","<<GetNpar()<<");"<<std::endl;
855 }
856
857 SaveFillAttributes(out, GetName(), 0, 1001);
858 SaveMarkerAttributes(out, GetName(), 1, 1, 1);
859 SaveLineAttributes(out, GetName(), 1, 1, 4);
860
861 if (GetNpx() != 100)
862 out<<" "<<GetName()<<"->SetNpx("<<GetNpx()<<");"<<std::endl;
863 if (GetChisquare() != 0)
864 out<<" "<<GetName()<<"->SetChisquare("<<GetChisquare()<<");"<<std::endl;
865
866 Double_t parmin, parmax;
867 for (Int_t i=0;i<GetNpar();i++) {
868 out<<" "<<GetName()<<"->SetParameter("<<i<<","<<GetParameter(i)<<");"<<std::endl;
869 out<<" "<<GetName()<<"->SetParError("<<i<<","<<GetParError(i)<<");"<<std::endl;
870 GetParLimits(i,parmin,parmax);
871 out<<" "<<GetName()<<"->SetParLimits("<<i<<","<<parmin<<","<<parmax<<");"<<std::endl;
872 }
873 out<<" "<<GetName()<<"->Draw("<<quote<<option<<quote<<");"<<std::endl;
874}
875
876
877
878////////////////////////////////////////////////////////////////////////////////
879/// Set the number and values of contour levels
880///
881/// By default the number of contour levels is set to 20.
882///
883/// if argument levels = 0 or missing, equidistant contours are computed
884
885void TF2::SetContour(Int_t nlevels, const Double_t *levels)
886{
887 Int_t level;
888 if (nlevels <=0 ) {
889 fContour.Set(0);
890 return;
891 }
892 fContour.Set(nlevels);
893
894 //- Contour levels are specified
895 if (levels) {
896 for (level=0; level<nlevels; level++) fContour.fArray[level] = levels[level];
897 } else {
898 fContour.fArray[0] = -9999; // means not defined at this point
899 }
900}
901
902
903////////////////////////////////////////////////////////////////////////////////
904/// Set value for one contour level
905
907{
908 if (level <0 || level >= fContour.fN) return;
909 fContour.fArray[level] = value;
910}
911
912////////////////////////////////////////////////////////////////////////////////
913/// Set the number of points used to draw the function
914///
915/// The default number of points along x is 30 for 2-d/3-d functions.
916/// You can increase this value to get a better resolution when drawing
917/// pictures with sharp peaks or to get a better result when using TF2::GetRandom2
918/// the minimum number of points is 4, the maximum is 10000 for 2-d/3-d functions
919
921{
922 if (npy < 4) {
923 Warning("SetNpy","Number of points must be >=4 && <= 10000, fNpy set to 4");
924 fNpy = 4;
925 } else if(npy > 10000) {
926 Warning("SetNpy","Number of points must be >=4 && <= 10000, fNpy set to 10000");
927 fNpy = 10000;
928 } else {
929 fNpy = npy;
930 }
931 Update();
932}
933
934////////////////////////////////////////////////////////////////////////////////
935/// Initialize the upper and lower bounds to draw the function-
936
938{
939 fXmin = xmin;
940 fXmax = xmax;
941 fYmin = ymin;
942 fYmax = ymax;
943 Update();
944}
945
946////////////////////////////////////////////////////////////////////////////////
947/// Stream an object of class TF2.
948
950{
951 if (R__b.IsReading()) {
952 UInt_t R__s, R__c;
953 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
954 if (R__v > 3) {
955 R__b.ReadClassBuffer(TF2::Class(), this, R__v, R__s, R__c);
956 return;
957 }
958 //====process old versions before automatic schema evolution
959 Int_t nlevels;
960 TF1::Streamer(R__b);
961 if (R__v < 3) {
963 R__b >> ymin; fYmin = ymin;
964 R__b >> ymax; fYmax = ymax;
965 } else {
966 R__b >> fYmin;
967 R__b >> fYmax;
968 }
969 R__b >> fNpy;
970 R__b >> nlevels;
971 if (R__v < 3) {
972 Float_t *contour = 0;
973 Int_t n = R__b.ReadArray(contour);
974 fContour.Set(n);
975 for (Int_t i=0;i<n;i++) fContour.fArray[i] = contour[i];
976 delete [] contour;
977 } else {
978 fContour.Streamer(R__b);
979 }
980 R__b.CheckByteCount(R__s, R__c, TF2::IsA());
981 //====end of old versions
982
983 } else {
984 Int_t saved = 0;
985 if (fType != EFType::kFormula && fSave.empty()) { saved = 1; Save(fXmin,fXmax,fYmin,fYmax,0,0);}
986
987 R__b.WriteClassBuffer(TF2::Class(),this);
988
989 if (saved) {fSave.clear(); }
990 }
991}
992
993////////////////////////////////////////////////////////////////////////////////
994/// Return x^nx * y^ny moment of a 2d function in range [ax,bx],[ay,by]
995/// \author Gene Van Buren <gene@bnl.gov>
996
998{
999 Double_t norm = Integral(ax,bx,ay,by,epsilon);
1000 if (norm == 0) {
1001 Error("Moment2", "Integral zero over range");
1002 return 0;
1003 }
1004
1005 // define integrand function as a lambda : g(x,y)= x^(nx) * y^(ny) * f(x,y)
1006 auto integrand = [&](double *x, double *) {
1007 return std::pow(x[0], nx) * std::pow(x[1], ny) * this->EvalPar(x, nullptr);
1008 };
1009 // compute integral of g(x,y)
1010 TF2 fnc("TF2_ExpValHelper",integrand,ax,bx,ay,by,0);
1011 // set same points as current function to get correct max points when computing the integral
1012 fnc.fNpx = fNpx;
1013 fnc.fNpy = fNpy;
1014 return fnc.Integral(ax,bx,ay,by,epsilon)/norm;
1015}
1016
1017////////////////////////////////////////////////////////////////////////////////
1018/// Return x^nx * y^ny central moment of a 2d function in range [ax,bx],[ay,by]
1019/// \author Gene Van Buren <gene@bnl.gov>
1020
1022{
1023 Double_t norm = Integral(ax,bx,ay,by,epsilon);
1024 if (norm == 0) {
1025 Error("CentralMoment2", "Integral zero over range");
1026 return 0;
1027 }
1028
1029 Double_t xbar = 0;
1030 Double_t ybar = 0;
1031 if (nx!=0) {
1032 // compute first momentum in x
1033 auto integrandX = [&](double *x, double *) { return x[0] * this->EvalPar(x, nullptr); };
1034 TF2 fncx("TF2_ExpValHelperx",integrandX, ax, bx, ay, by, 0);
1035 fncx.fNpx = fNpx;
1036 fncx.fNpy = fNpy;
1037 xbar = fncx.Integral(ax,bx,ay,by,epsilon)/norm;
1038 }
1039 if (ny!=0) {
1040 // compute first momentum in y
1041 auto integrandY = [&](double *x, double *) { return x[1] * this->EvalPar(x, nullptr); };
1042 TF2 fncy("TF2_ExpValHelperx", integrandY, ax, bx, ay, by, 0);
1043 fncy.fNpx = fNpx;
1044 fncy.fNpy = fNpy;
1045 ybar = fncy.Integral(ax,bx,ay,by,epsilon)/norm;
1046 }
1047 // define integrand function as a lambda : g(x,y)= (x-xbar)^(nx) * (y-ybar)^(ny) * f(x,y)
1048 auto integrand = [&](double *x, double *) {
1049 double xxx = (nx != 0) ? std::pow(x[0] - xbar, nx) : 1.;
1050 double yyy = (ny != 0) ? std::pow(x[1] - ybar, ny) : 1.;
1051 return xxx * yyy * this->EvalPar(x, nullptr);
1052 };
1053 // compute integral of g(x,y)
1054 TF2 fnc("TF2_ExpValHelper", integrand, ax, bx, ay, by, 0);
1055 fnc.fNpx = fNpx;
1056 fnc.fNpy = fNpy;
1057 return fnc.Integral(ax, bx, ay, by, epsilon) / norm;
1058}
#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
RooPlot * contour(RooRealVar &var1, RooRealVar &var2, double n1=1, double n2=2, double n3=0.0, double n4=0.0, double n5=0.0, double n6=0.0)
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:101
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
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:585
#define gROOT
Definition TROOT.h:405
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:236
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
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
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:213
Int_t fNdim
Function dimension.
Definition TF1.h:246
virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
Return limits for parameter ipar.
Definition TF1.cxx:1941
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition TF1.cxx:1931
Double_t GetChisquare() const
Definition TF1.h:449
Double_t fXmin
Lower bounds for the range.
Definition TF1.h:243
std::unique_ptr< TMethodCall > fMethodCall
! Pointer to MethodCall in case of interpreted function
Definition TF1.h:264
virtual void Update()
Called by functions such as SetRange, SetNpx, SetParameters to force the deletion of the associated h...
Definition TF1.cxx:3611
virtual Int_t GetNpar() const
Definition TF1.h:486
TH1 * fHistogram
! Pointer to histogram used for visualisation
Definition TF1.h:263
Double_t fMaximum
Maximum value for plotting.
Definition TF1.h:253
virtual Double_t * GetParameters() const
Definition TF1.h:525
Double_t fMinimum
Minimum value for plotting.
Definition TF1.h:252
void Copy(TObject &f1) const override
Copy this F1 to a new F1.
Definition TF1.cxx:1006
void Streamer(TBuffer &) override
Stream a class object.
Definition TF1.cxx:3563
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition TF1.cxx:2481
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:2849
EFType fType
Definition TF1.h:248
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=nullptr)
Evaluate function with given coordinates and parameters.
Definition TF1.cxx:1469
Int_t fNpx
Number of points used for the graphical representation.
Definition TF1.h:247
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TF1.cxx:1537
std::vector< Double_t > fSave
Array of fNsave function values.
Definition TF1.h:257
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:1724
std::vector< Double_t > fIntegral
! Integral of function binned on fNpx bins
Definition TF1.h:258
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:1440
@ kFormula
Formula functions which can be stored,.
Definition TF1.h:235
virtual Int_t GetNpx() const
Definition TF1.h:495
Double_t fXmax
Upper bounds for the range.
Definition TF1.h:244
virtual Int_t GetNdim() const
Definition TF1.h:490
virtual Double_t GetParameter(Int_t ipar) const
Definition TF1.h:517
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:949
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:145
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:798
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:885
TH1 * CreateHistogram() override
Create a histogram from function.
Definition TF2.cxx:699
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:687
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition TF2.cxx:920
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:997
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:744
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:842
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 (default val...
Definition TF2.cxx:663
Double_t fYmin
Lower bound for the range in y.
Definition TF2.h:32
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:1021
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:906
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:148
static TClass * Class()
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
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:8803
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a line.
Definition TH1.cxx:2798
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:400
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:401
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:9088
void Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
Definition TH1.cxx:6188
virtual Double_t GetContourLevel(Int_t level) const
Return value of contour number level.
Definition TH1.cxx:8296
virtual void SetContour(Int_t nlevels, const Double_t *levels=nullptr)
Set the number and values of contour levels.
Definition TH1.cxx:8349
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8856
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:257
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:423
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:956
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:184
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:774
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:970
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:944
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:552
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:421
void ToLower()
Change string to lower-case.
Definition TString.cxx:1170
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
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:900
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:768
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:915
double epsilon
Definition triangle.c:618