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