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