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