Logo ROOT  
Reference Guide
TF1.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 18/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 <iostream>
13#include "strlcpy.h"
14#include "snprintf.h"
15#include "TROOT.h"
16#include "TBuffer.h"
17#include "TMath.h"
18#include "TF1.h"
19#include "TH1.h"
20#include "TGraph.h"
21#include "TVirtualPad.h"
22#include "TStyle.h"
23#include "TRandom.h"
24#include "TObjString.h"
25#include "TInterpreter.h"
26#include "TPluginManager.h"
27#include "TBrowser.h"
28#include "TColor.h"
29#include "TMethodCall.h"
30#include "TF1Helper.h"
31#include "TF1NormSum.h"
32#include "TF1Convolution.h"
33#include "TVirtualMutex.h"
35#include "Math/WrappedTF1.h"
38#include "Math/BrentMethods.h"
39#include "Math/Integrator.h"
46#include "Math/Functor.h"
47#include "Math/Minimizer.h"
49#include "Math/Factory.h"
50#include "Math/ChebyshevPol.h"
51#include "Fit/FitResult.h"
52// for I/O backward compatibility
53#include "v5/TF1Data.h"
54
55#include "AnalyticalIntegrals.h"
56
57std::atomic<Bool_t> TF1::fgAbsValue(kFALSE);
59std::atomic<Bool_t> TF1::fgAddToGlobList(kTRUE);
61
62using TF1Updater_t = void (*)(Int_t nobjects, TObject **from, TObject **to);
64
65
66namespace {
67struct TF1v5Convert : public TF1 {
68public:
69 void Convert(ROOT::v5::TF1Data &from)
70 {
71 // convert old TF1 to new one
72 fNpar = from.GetNpar();
73 fNdim = from.GetNdim();
74 if (from.fType == 0) {
75 // formula functions
76 // if ndim is not 1 set xmin max to zero to avoid error in ctor
77 double xmin = from.fXmin;
78 double xmax = from.fXmax;
79 if (fNdim > 1) {
80 xmin = 0;
81 xmax = 0;
82 }
83 TF1 fnew(from.GetName(), from.GetExpFormula(), xmin, xmax);
84 if (fNdim > 1) {
85 fnew.SetRange(from.fXmin, from.fXmax);
86 }
87 fnew.Copy(*this);
88 // need to set parameter values
89 if (from.GetParameters())
90 fFormula->SetParameters(from.GetParameters());
91 } else {
92 // case of a function pointers
93 fParams.reset(new TF1Parameters(fNpar));
94 fName = from.GetName();
95 fTitle = from.GetTitle();
96 // need to set parameter values
97 if (from.GetParameters())
98 fParams->SetParameters(from.GetParameters());
99 }
100 // copy the other data members
101 fNpx = from.fNpx;
102 fType = (EFType)from.fType;
103 fNpfits = from.fNpfits;
104 fNDF = from.fNDF;
105 fChisquare = from.fChisquare;
106 fMaximum = from.fMaximum;
107 fMinimum = from.fMinimum;
108 fXmin = from.fXmin;
109 fXmax = from.fXmax;
110
111 if (from.fParErrors)
112 fParErrors = std::vector<Double_t>(from.fParErrors, from.fParErrors + fNpar);
113 if (from.fParMin)
114 fParMin = std::vector<Double_t>(from.fParMin, from.fParMin + fNpar);
115 if (from.fParMax)
116 fParMax = std::vector<Double_t>(from.fParMax, from.fParMax + fNpar);
117 if (from.fNsave > 0) {
118 assert(from.fSave);
119 fSave = std::vector<Double_t>(from.fSave, from.fSave + from.fNsave);
120 }
121 // set the bits
122 for (int ibit = 0; ibit < 24; ++ibit)
123 if (from.TestBit(BIT(ibit)))
124 SetBit(BIT(ibit));
125
126 // copy the graph attributes
127 auto &fromLine = static_cast<TAttLine &>(from);
128 fromLine.Copy(*this);
129 auto &fromFill = static_cast<TAttFill &>(from);
130 fromFill.Copy(*this);
131 auto &fromMarker = static_cast<TAttMarker &>(from);
132 fromMarker.Copy(*this);
133 }
134};
135} // unnamed namespace
136
137static void R__v5TF1Updater(Int_t nobjects, TObject **from, TObject **to)
138{
139 auto **fromv5 = (ROOT::v5::TF1Data **)from;
140 auto **target = (TF1v5Convert **)to;
141
142 for (int i = 0; i < nobjects; ++i) {
143 if (fromv5[i] && target[i])
144 target[i]->Convert(*fromv5[i]);
145 }
146}
147
149
151
152// class wrapping evaluation of TF1(x) - y0
153class GFunc {
155 const double fY0;
156public:
157 GFunc(const TF1 *function , double y): fFunction(function), fY0(y) {}
158 double operator()(double x) const
159 {
160 return fFunction->Eval(x) - fY0;
161 }
162};
163
164// class wrapping evaluation of -TF1(x)
167public:
169
170 double operator()(double x) const
171 {
172 return - fFunction->Eval(x);
173 }
174};
175// class wrapping evaluation of -TF1(x) for multi-dimension
178public:
180
181 double operator()(const double *x) const
182 {
183 return - fFunction->EvalPar(x, (Double_t *)0);
184 }
185};
186
187// class wrapping function evaluation directly in 1D interface (used for integration)
188// and implementing the methods for the momentum calculations
189
191public:
192 TF1_EvalWrapper(TF1 *f, const Double_t *par, bool useAbsVal, Double_t n = 1, Double_t x0 = 0) :
193 fFunc(f),
194 fPar(((par) ? par : f->GetParameters())),
195 fAbsVal(useAbsVal),
196 fN(n),
197 fX0(x0)
198 {
200 if (par) fFunc->SetParameters(par);
201 }
202
204 {
205 // use default copy constructor
206 TF1_EvalWrapper *f = new TF1_EvalWrapper(*this);
207 f->fFunc->InitArgs(f->fX, f->fPar);
208 return f;
209 }
210 // evaluate |f(x)|
212 {
213 // use evaluation with stored parameters (i.e. pass zero)
214 fX[0] = x;
215 Double_t fval = fFunc->EvalPar(fX, 0);
216 if (fAbsVal && fval < 0) return -fval;
217 return fval;
218 }
219 // evaluate x * |f(x)|
221 {
222 fX[0] = x;
223 return fX[0] * TMath::Abs(fFunc->EvalPar(fX, 0));
224 }
225 // evaluate (x - x0) ^n * f(x)
227 {
228 fX[0] = x;
229 return TMath::Power(fX[0] - fX0, fN) * TMath::Abs(fFunc->EvalPar(fX, 0));
230 }
231
233 mutable Double_t fX[1];
234 const double *fPar;
238};
239
240////////////////////////////////////////////////////////////////////////////////
241/** \class TF1
242 \ingroup Functions
243 \brief 1-Dim function class
244
245
246## TF1: 1-Dim function class
247
248A TF1 object is a 1-Dim function defined between a lower and upper limit.
249The function may be a simple function based on a TFormula expression or a precompiled user function.
250The function may have associated parameters.
251TF1 graphics function is via the TH1 and TGraph drawing functions.
252
253The following types of functions can be created:
254
2551. [Expression using variable x and no parameters](\ref F1)
2562. [Expression using variable x with parameters](\ref F2)
2573. [Lambda Expression with variable x and parameters](\ref F3)
2584. [A general C function with parameters](\ref F4)
2595. [A general C++ function object (functor) with parameters](\ref F5)
2606. [A member function with parameters of a general C++ class](\ref F6)
261
262
263
264\anchor F1
265### 1 - Expression using variable x and no parameters
266
267#### Case 1: inline expression using standard C++ functions/operators
268
269Begin_Macro(source)
270{
271 TF1 *fa1 = new TF1("fa1","sin(x)/x",0,10);
272 fa1->Draw();
273}
274End_Macro
275
276#### Case 2: inline expression using a ROOT function (e.g. from TMath) without parameters
277
278
279Begin_Macro(source)
280{
281 TF1 *fa2 = new TF1("fa2","TMath::DiLog(x)",0,10);
282 fa2->Draw();
283}
284End_Macro
285
286#### Case 3: inline expression using a user defined CLING function by name
287
288~~~~{.cpp}
289Double_t myFunc(double x) { return x+sin(x); }
290....
291TF1 *fa3 = new TF1("fa3","myFunc(x)",-3,5);
292fa3->Draw();
293~~~~
294
295\anchor F2
296### 2 - Expression using variable x with parameters
297
298#### Case 1: inline expression using standard C++ functions/operators
299
300* Example a:
301
302
303~~~~{.cpp}
304TF1 *fa = new TF1("fa","[0]*x*sin([1]*x)",-3,3);
305~~~~
306
307This creates a function of variable x with 2 parameters. The parameters must be initialized via:
308
309~~~~{.cpp}
310 fa->SetParameter(0,value_first_parameter);
311 fa->SetParameter(1,value_second_parameter);
312~~~~
313
314
315Parameters may be given a name:
316
317~~~~{.cpp}
318 fa->SetParName(0,"Constant");
319~~~~
320
321* Example b:
322
323~~~~{.cpp}
324 TF1 *fb = new TF1("fb","gaus(0)*expo(3)",0,10);
325~~~~
326
327
328``gaus(0)`` is a substitute for ``[0]*exp(-0.5*((x-[1])/[2])**2)`` and ``(0)`` means start numbering parameters at ``0``. ``expo(3)`` is a substitute for ``exp([3]+[4]*x)``.
329
330#### Case 2: inline expression using TMath functions with parameters
331
332~~~~{.cpp}
333 TF1 *fb2 = new TF1("fa3","TMath::Landau(x,[0],[1],0)",-5,10);
334 fb2->SetParameters(0.2,1.3);
335 fb2->Draw();
336~~~~
337
338
339
340Begin_Macro
341{
342 TCanvas *c = new TCanvas("c","c",0,0,500,300);
343 TF1 *fb2 = new TF1("fa3","TMath::Landau(x,[0],[1],0)",-5,10);
344 fb2->SetParameters(0.2,1.3); fb2->Draw();
345 return c;
346}
347End_Macro
348
349\anchor F3
350### 3 - A lambda expression with variables and parameters
351
352\since **6.00/00:**
353TF1 supports using lambda expressions in the formula. This allows, by using a full C++ syntax the full power of lambda
354functions and still maintain the capability of storing the function in a file which cannot be done with
355function pointer or lambda written not as expression, but as code (see items below).
356
357Example on how using lambda to define a sum of two functions.
358Note that is necessary to provide the number of parameters
359
360~~~~{.cpp}
361TF1 f1("f1","sin(x)",0,10);
362TF1 f2("f2","cos(x)",0,10);
363TF1 fsum("f1","[&](double *x, double *p){ return p[0]*f1(x) + p[1]*f2(x); }",0,10,2);
364~~~~
365
366\anchor F4
367### 4 - A general C function with parameters
368
369Consider the macro myfunc.C below:
370
371~~~~{.cpp}
372 // Macro myfunc.C
373 Double_t myfunction(Double_t *x, Double_t *par)
374 {
375 Float_t xx =x[0];
376 Double_t f = TMath::Abs(par[0]*sin(par[1]*xx)/xx);
377 return f;
378 }
379 void myfunc()
380 {
381 TF1 *f1 = new TF1("myfunc",myfunction,0,10,2);
382 f1->SetParameters(2,1);
383 f1->SetParNames("constant","coefficient");
384 f1->Draw();
385 }
386 void myfit()
387 {
388 TH1F *h1=new TH1F("h1","test",100,0,10);
389 h1->FillRandom("myfunc",20000);
390 TF1 *f1 = (TF1 *)gROOT->GetFunction("myfunc");
391 f1->SetParameters(800,1);
392 h1->Fit("myfunc");
393 }
394~~~~
395
396
397
398In an interactive session you can do:
399
400~~~~
401 Root > .L myfunc.C
402 Root > myfunc();
403 Root > myfit();
404~~~~
405
406
407
408TF1 objects can reference other TF1 objects of type A or B defined above. This excludes CLing or compiled functions. However, there is a restriction. A function cannot reference a basic function if the basic function is a polynomial polN.
409
410Example:
411
412~~~~{.cpp}
413{
414 TF1 *fcos = new TF1 ("fcos", "[0]*cos(x)", 0., 10.);
415 fcos->SetParNames( "cos");
416 fcos->SetParameter( 0, 1.1);
417
418 TF1 *fsin = new TF1 ("fsin", "[0]*sin(x)", 0., 10.);
419 fsin->SetParNames( "sin");
420 fsin->SetParameter( 0, 2.1);
421
422 TF1 *fsincos = new TF1 ("fsc", "fcos+fsin");
423
424 TF1 *fs2 = new TF1 ("fs2", "fsc+fsc");
425}
426~~~~
427
428
429\anchor F5
430### 5 - A general C++ function object (functor) with parameters
431
432A TF1 can be created from any C++ class implementing the operator()(double *x, double *p). The advantage of the function object is that he can have a state and reference therefore what-ever other object. In this way the user can customize his function.
433
434Example:
435
436
437~~~~{.cpp}
438class MyFunctionObject {
439 public:
440 // use constructor to customize your function object
441
442 double operator() (double *x, double *p) {
443 // function implementation using class data members
444 }
445};
446{
447 ....
448 MyFunctionObject fobj;
449 TF1 * f = new TF1("f",fobj,0,1,npar); // create TF1 class.
450 .....
451}
452~~~~
453
454#### Using a lambda function as a general C++ functor object
455
456From C++11 we can use both std::function or even better lambda functions to create the TF1.
457As above the lambda must have the right signature but can capture whatever we want. For example we can make
458a TF1 from the TGraph::Eval function as shown below where we use as function parameter the graph normalization.
459
460~~~~{.cpp}
461TGraph * g = new TGraph(npointx, xvec, yvec);
462TF1 * f = new TF1("f",[&](double*x, double *p){ return p[0]*g->Eval(x[0]); }, xmin, xmax, 1);
463~~~~
464
465
466\anchor F6
467### 6 - A member function with parameters of a general C++ class
468
469A TF1 can be created in this case from any member function of a class which has the signature of (double * , double *) and returning a double.
470
471Example:
472
473~~~~{.cpp}
474class MyFunction {
475 public:
476 ...
477 double Evaluate() (double *x, double *p) {
478 // function implementation
479 }
480};
481{
482 ....
483 MyFunction * fptr = new MyFunction(....); // create the user function class
484 TF1 * f = new TF1("f",fptr,&MyFunction::Evaluate,0,1,npar,"MyFunction","Evaluate"); // create TF1 class.
485
486 .....
487}
488~~~~
489
490See also the tutorial __math/exampleFunctor.C__ for a running example.
491*/
492////////////////////////////////////////////////////////////////////////////
493
495
496
497////////////////////////////////////////////////////////////////////////////////
498/// TF1 default constructor.
499
502 fXmin(0), fXmax(0), fNpar(0), fNdim(0), fType(EFType::kFormula)
503{
504 SetFillStyle(0);
505}
506
507
508////////////////////////////////////////////////////////////////////////////////
509/// F1 constructor using a formula definition
510///
511/// See TFormula constructor for explanation of the formula syntax.
512///
513/// See tutorials: fillrandom, first, fit1, formula1, multifit
514/// for real examples.
515///
516/// Creates a function of type A or B between xmin and xmax
517///
518/// if formula has the form "fffffff;xxxx;yyyy", it is assumed that
519/// the formula string is "fffffff" and "xxxx" and "yyyy" are the
520/// titles for the X and Y axis respectively.
521
522TF1::TF1(const char *name, const char *formula, Double_t xmin, Double_t xmax, EAddToList addToGlobList, bool vectorize) :
523 TNamed(name, formula), TAttLine(), TAttFill(), TAttMarker(), fType(EFType::kFormula)
524{
525 if (xmin < xmax) {
526 fXmin = xmin;
527 fXmax = xmax;
528 } else {
529 fXmin = xmax; //when called from TF2,TF3
530 fXmax = xmin;
531 }
532 // Create rep formula (no need to add to gROOT list since we will add the TF1 object)
533 const auto formulaLength = strlen(formula);
534 // First check if we are making a convolution
535 if (strncmp(formula, "CONV(", 5) == 0 && formula[formulaLength - 1] == ')') {
536 // Look for single ',' delimiter
537 int delimPosition = -1;
538 int parenCount = 0;
539 for (unsigned int i = 5; i < formulaLength - 1; i++) {
540 if (formula[i] == '(')
541 parenCount++;
542 else if (formula[i] == ')')
543 parenCount--;
544 else if (formula[i] == ',' && parenCount == 0) {
545 if (delimPosition == -1)
546 delimPosition = i;
547 else
548 Error("TF1", "CONV takes 2 arguments. Too many arguments found in : %s", formula);
549 }
550 }
551 if (delimPosition == -1)
552 Error("TF1", "CONV takes 2 arguments. Only one argument found in : %s", formula);
554 // Having found the delimiter, define the first and second formulas
555 TString formula1 = TString(TString(formula)(5, delimPosition - 5));
556 TString formula2 = TString(TString(formula)(delimPosition + 1, formulaLength - 1 - (delimPosition + 1)));
557 // remove spaces from these formulas
558 formula1.ReplaceAll(' ', "");
559 formula2.ReplaceAll(' ', "");
560
561 TF1 *function1 = (TF1 *)(gROOT->GetListOfFunctions()->FindObject(formula1));
562 if (function1 == nullptr)
563 function1 = new TF1((const char *)formula1, (const char *)formula1, xmin, xmax);
564 TF1 *function2 = (TF1 *)(gROOT->GetListOfFunctions()->FindObject(formula2));
565 if (function2 == nullptr)
566 function2 = new TF1((const char *)formula2, (const char *)formula2, xmin, xmax);
567
568 // std::cout << "functions have been defined" << std::endl;
569
570 TF1Convolution *conv = new TF1Convolution(function1, function2,xmin,xmax);
571
572 // (note: currently ignoring `useFFT` option)
573 fNpar = conv->GetNpar();
574 fNdim = 1; // (note: may want to extend this in the future?)
575
576 fType = EFType::kCompositionFcn;
577 fComposition = std::unique_ptr<TF1AbsComposition>(conv);
578
579 fParams = std::unique_ptr<TF1Parameters>(new TF1Parameters(fNpar)); // default to zeros (TF1Convolution has no GetParameters())
580 // set parameter names
581 for (int i = 0; i < fNpar; i++)
582 this->SetParName(i, conv->GetParName(i));
583 // set parameters to default values
584 int f1Npar = function1->GetNpar();
585 int f2Npar = function2->GetNpar();
586 // first, copy parameters from function1
587 for (int i = 0; i < f1Npar; i++)
588 this->SetParameter(i, function1->GetParameter(i));
589 // then, check if the "Constant" parameters were combined
590 // (this code assumes function2 has at most one parameter named "Constant")
591 if (conv->GetNpar() == f1Npar + f2Npar - 1) {
592 int cst1 = function1->GetParNumber("Constant");
593 int cst2 = function2->GetParNumber("Constant");
594 this->SetParameter(cst1, function1->GetParameter(cst1) * function2->GetParameter(cst2));
595 // and copy parameters from function2
596 for (int i = 0; i < f2Npar; i++)
597 if (i < cst2)
598 this->SetParameter(f1Npar + i, function2->GetParameter(i));
599 else if (i > cst2)
600 this->SetParameter(f1Npar + i - 1, function2->GetParameter(i));
601 } else {
602 // or if no constant, simply copy parameters from function2
603 for (int i = 0; i < f2Npar; i++)
604 this->SetParameter(i + f1Npar, function2->GetParameter(i));
605 }
606
607 // Then check if we need NSUM syntax:
608 } else if (strncmp(formula, "NSUM(", 5) == 0 && formula[formulaLength - 1] == ')') {
609 // using comma as delimiter
610 char delimiter = ',';
611 // first, remove "NSUM(" and ")" and spaces
612 TString formDense = TString(formula)(5,formulaLength-5-1);
613 formDense.ReplaceAll(' ', "");
614
615 // make sure standard functions are defined (e.g. gaus, expo)
617
618 // Go char-by-char to split terms and define the relevant functions
619 int parenCount = 0;
620 int termStart = 0;
621 TObjArray *newFuncs = new TObjArray();
622 newFuncs->SetOwner(kTRUE);
623 TObjArray *coeffNames = new TObjArray();
624 coeffNames->SetOwner(kTRUE);
625 TString fullFormula("");
626 for (int i = 0; i < formDense.Length(); ++i) {
627 if (formDense[i] == '(')
628 parenCount++;
629 else if (formDense[i] == ')')
630 parenCount--;
631 else if (formDense[i] == delimiter && parenCount == 0) {
632 // term goes from termStart to i
633 DefineNSUMTerm(newFuncs, coeffNames, fullFormula, formDense, termStart, i, xmin, xmax);
634 termStart = i + 1;
635 }
636 }
637 DefineNSUMTerm(newFuncs, coeffNames, fullFormula, formDense, termStart, formDense.Length(), xmin, xmax);
638
639 TF1NormSum *normSum = new TF1NormSum(fullFormula, xmin, xmax);
640
641 if (xmin == 0 && xmax == 1.) Info("TF1","Created TF1NormSum object using the default [0,1] range");
642
643 fNpar = normSum->GetNpar();
644 fNdim = 1; // (note: may want to extend functionality in the future)
645
646 fType = EFType::kCompositionFcn;
647 fComposition = std::unique_ptr<TF1AbsComposition>(normSum);
648
649 fParams = std::unique_ptr<TF1Parameters>(new TF1Parameters(fNpar));
650 fParams->SetParameters(&(normSum->GetParameters())[0]); // inherit default parameters from normSum
651
652 // Parameter names
653 for (int i = 0; i < fNpar; i++) {
654 if (coeffNames->At(i) != nullptr) {
655 TString coeffName = ((TObjString *)coeffNames->At(i))->GetString();
656 this->SetParName(i, (const char *)coeffName);
657 } else {
658 this->SetParName(i, normSum->GetParName(i));
659 }
660 }
661
662 } else { // regular TFormula
663 fFormula = std::unique_ptr<TFormula>(new TFormula(name, formula, false, vectorize));
664 fNpar = fFormula->GetNpar();
665 // TFormula can have dimension zero, but since this is a TF1 minimal dim is 1
666 fNdim = fFormula->GetNdim() == 0 ? 1 : fFormula->GetNdim();
667 }
668 if (fNpar) {
669 fParErrors.resize(fNpar);
670 fParMin.resize(fNpar);
671 fParMax.resize(fNpar);
672 }
673 // do we want really to have this un-documented feature where we accept cases where dim > 1
674 // by setting xmin >= xmax ??
675 if (fNdim > 1 && xmin < xmax) {
676 Error("TF1", "function: %s/%s has dimension %d instead of 1", name, formula, fNdim);
677 MakeZombie();
678 }
679
680 DoInitialize(addToGlobList);
681}
683 if (opt == nullptr) return TF1::EAddToList::kDefault;
684 TString option(opt);
685 option.ToUpper();
686 if (option.Contains("NL")) return TF1::EAddToList::kNo;
687 if (option.Contains("GL")) return TF1::EAddToList::kAdd;
689}
691 if (opt == nullptr) return false;
692 TString option(opt);
693 option.ToUpper();
694 if (option.Contains("VEC")) return true;
695 return false;
696}
697TF1::TF1(const char *name, const char *formula, Double_t xmin, Double_t xmax, Option_t * opt) :
698////////////////////////////////////////////////////////////////////////////////
699/// Same constructor as above (for TFormula based function) but passing an option strings
700/// available options
701/// VEC - vectorize the formula expressions (not possible for lambda based expressions)
702/// NL - function is not stores in the global list of functions
703/// GL - function will be always stored in the global list of functions ,
704/// independently of the global setting of TF1::DefaultAddToGlobalList
705///////////////////////////////////////////////////////////////////////////////////
707{}
708////////////////////////////////////////////////////////////////////////////////
709/// F1 constructor using name of an interpreted function.
710///
711/// Creates a function of type C between xmin and xmax.
712/// name is the name of an interpreted C++ function.
713/// The function is defined with npar parameters
714/// fcn must be a function of type:
715///
716/// Double_t fcn(Double_t *x, Double_t *params)
717///
718/// This constructor is called for functions of type C by the C++ interpreter.
719///
720/// \warning A function created with this constructor cannot be Cloned.
721
722TF1::TF1(const char *name, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim, EAddToList addToGlobList) :
723 TF1(EFType::kInterpreted, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar))
724{
725 if (fName.Data()[0] == '*') { // case TF1 name starts with a *
726 Info("TF1", "TF1 has a name starting with a \'*\' - it is for saved TF1 objects in a .C file");
727 return; //case happens via SavePrimitive
728 } else if (fName.IsNull()) {
729 Error("TF1", "requires a proper function name!");
730 return;
731 }
732
733 fMethodCall = std::unique_ptr<TMethodCall>(new TMethodCall());
734 fMethodCall->InitWithPrototype(fName, "Double_t*,Double_t*");
735
736 if (! fMethodCall->IsValid()) {
737 Error("TF1", "No function found with the signature %s(Double_t*,Double_t*)", name);
738 return;
739 }
740}
741
742
743////////////////////////////////////////////////////////////////////////////////
744/// Constructor using a pointer to a real function.
745///
746/// \param[in] name object name
747/// \param[in] fcn pointer to function
748/// \param[in] xmin,xmax x axis limits
749/// \param[in] npar is the number of free parameters used by the function
750/// \param[in] ndim number of dimensions
751/// \param[in] addToGlobList boolean marking if it should be added to global list
752///
753/// This constructor creates a function of type C when invoked
754/// with the normal C++ compiler.
755///
756/// see test program test/stress.cxx (function stress1) for an example.
757/// note the interface with an intermediate pointer.
758///
759/// \warning A function created with this constructor cannot be Cloned.
760
761TF1::TF1(const char *name, Double_t (*fcn)(Double_t *, Double_t *), Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim, EAddToList addToGlobList) :
762 TF1(EFType::kPtrScalarFreeFcn, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<double>(ROOT::Math::ParamFunctor(fcn)))
763{}
764
765////////////////////////////////////////////////////////////////////////////////
766/// Constructor using a pointer to (const) real function.
767///
768/// \param[in] name object name
769/// \param[in] fcn pointer to function
770/// \param[in] xmin,xmax x axis limits
771/// \param[in] npar is the number of free parameters used by the function
772/// \param[in] ndim number of dimensions
773/// \param[in] addToGlobList boolean marking if it should be added to global list
774///
775/// This constructor creates a function of type C when invoked
776/// with the normal C++ compiler.
777///
778/// see test program test/stress.cxx (function stress1) for an example.
779/// note the interface with an intermediate pointer.
780///
781/// \warning A function created with this constructor cannot be Cloned.
782
783TF1::TF1(const char *name, Double_t (*fcn)(const Double_t *, const Double_t *), Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim, EAddToList addToGlobList) :
784 TF1(EFType::kPtrScalarFreeFcn, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<double>(ROOT::Math::ParamFunctor(fcn)))
785{}
786
787////////////////////////////////////////////////////////////////////////////////
788/// Constructor using the Functor class.
789///
790/// \param[in] name object name
791/// \param f parameterized functor
792/// \param xmin and
793/// \param xmax define the plotting range of the function
794/// \param[in] npar is the number of free parameters used by the function
795/// \param[in] ndim number of dimensions
796/// \param[in] addToGlobList boolean marking if it should be added to global list
797///
798/// This constructor can be used only in compiled code
799///
800/// WARNING! A function created with this constructor cannot be Cloned.
801
803 TF1(EFType::kPtrScalarFreeFcn, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<double>(ROOT::Math::ParamFunctor(f)))
804{}
805
806////////////////////////////////////////////////////////////////////////////////
807/// Common initialization of the TF1. Add to the global list and
808/// set the default style
809
810void TF1::DoInitialize(EAddToList addToGlobalList)
811{
812 // add to global list of functions if default adding is on OR if bit is set
813 bool doAdd = ((addToGlobalList == EAddToList::kDefault && fgAddToGlobList)
814 || addToGlobalList == EAddToList::kAdd);
815 if (doAdd && gROOT) {
818 // Store formula in linked list of formula in ROOT
819 TF1 *f1old = (TF1 *)gROOT->GetListOfFunctions()->FindObject(fName);
820 if (f1old) {
821 gROOT->GetListOfFunctions()->Remove(f1old);
822 // We removed f1old from the list, it is not longer global.
823 // (See TF1::AddToGlobalList which requires this flag to be correct).
824 f1old->SetBit(kNotGlobal, kTRUE);
825 }
826 gROOT->GetListOfFunctions()->Add(this);
827 } else
829
830 if (gStyle) {
834 }
835 SetFillStyle(0);
836}
837
838////////////////////////////////////////////////////////////////////////////////
839/// Static method to add/avoid to add automatically functions to the global list (gROOT->GetListOfFunctions() )
840/// After having called this static method, all the functions created afterwards will follow the
841/// desired behaviour.
842///
843/// By default the functions are added automatically
844/// It returns the previous status (true if the functions are added automatically)
845
847{
848 return fgAddToGlobList.exchange(on);
849}
850
851////////////////////////////////////////////////////////////////////////////////
852/// Add to global list of functions (gROOT->GetListOfFunctions() )
853/// return previous status (true if the function was already in the list false if not)
854
856{
857 if (!gROOT) return false;
858
859 bool prevStatus = !TestBit(kNotGlobal);
860 if (on) {
861 if (prevStatus) {
863 assert(gROOT->GetListOfFunctions()->FindObject(this) != nullptr);
864 return on; // do nothing
865 }
866 // do I need to delete previous one with the same name ???
867 //TF1 * old = dynamic_cast<TF1*>( gROOT->GetListOfFunctions()->FindObject(GetName()) );
868 //if (old) { gROOT->GetListOfFunctions()->Remove(old); old->SetBit(kNotGlobal, kTRUE); }
870 gROOT->GetListOfFunctions()->Add(this);
872 } else if (prevStatus) {
873 // if previous status was on and now is off we need to remove the function
876 TF1 *old = dynamic_cast<TF1 *>(gROOT->GetListOfFunctions()->FindObject(GetName()));
877 if (!old) {
878 Warning("AddToGlobalList", "Function is supposed to be in the global list but it is not present");
879 return kFALSE;
880 }
881 gROOT->GetListOfFunctions()->Remove(this);
882 }
883 return prevStatus;
884}
885
886////////////////////////////////////////////////////////////////////////////////
887/// Helper functions for NSUM parsing
888
889// Defines the formula that a given term uses, if not already defined,
890// and appends "sanitized" formula to `fullFormula` string
891void TF1::DefineNSUMTerm(TObjArray *newFuncs, TObjArray *coeffNames, TString &fullFormula, TString &formula,
892 int termStart, int termEnd, Double_t xmin, Double_t xmax)
893{
894 TString originalTerm = formula(termStart, termEnd-termStart);
895 int coeffLength = TermCoeffLength(originalTerm);
896 if (coeffLength != -1)
897 termStart += coeffLength + 1;
898
899 // `originalFunc` is the real formula and `cleanedFunc` is the
900 // sanitized version that will not confuse the TF1NormSum
901 // constructor
902 TString originalFunc = formula(termStart, termEnd-termStart);
903 TString cleanedFunc = TString(formula(termStart, termEnd-termStart))
904 .ReplaceAll('+', "<plus>")
905 .ReplaceAll('*',"<times>");
906
907 // define function (if necessary)
908 if (!gROOT->GetListOfFunctions()->FindObject(cleanedFunc))
909 newFuncs->Add(new TF1(cleanedFunc, originalFunc, xmin, xmax));
910
911 // append sanitized term to `fullFormula`
912 if (fullFormula.Length() != 0)
913 fullFormula.Append('+');
914
915 // include numerical coefficient
916 if (coeffLength != -1 && originalTerm[0] != '[')
917 fullFormula.Append(originalTerm(0, coeffLength+1));
918
919 // add coefficient name
920 if (coeffLength != -1 && originalTerm[0] == '[')
921 coeffNames->Add(new TObjString(TString(originalTerm(1,coeffLength-2))));
922 else
923 coeffNames->Add(nullptr);
924
925 fullFormula.Append(cleanedFunc);
926}
927
928
929// Returns length of coeff at beginning of a given term, not counting the '*'
930// Returns -1 if no coeff found
931// Coeff can be either a number or parameter name
933 int firstAsterisk = term.First('*');
934 if (firstAsterisk == -1) // no asterisk found
935 return -1;
936
937 if (TString(term(0,firstAsterisk)).IsFloat())
938 return firstAsterisk;
939
940 if (term[0] == '[' && term[firstAsterisk-1] == ']'
941 && TString(term(1,firstAsterisk-2)).IsAlnum())
942 return firstAsterisk;
943
944 return -1;
945}
946
947////////////////////////////////////////////////////////////////////////////////
948/// Operator =
949
951{
952 if (this != &rhs) {
953 rhs.Copy(*this);
954 }
955 return *this;
956}
957
958
959////////////////////////////////////////////////////////////////////////////////
960/// TF1 default destructor.
961
963{
964 if (fHistogram) delete fHistogram;
965
966 // this was before in TFormula destructor
967 {
969 if (gROOT) gROOT->GetListOfFunctions()->Remove(this);
970 }
971
972 if (fParent) fParent->RecursiveRemove(this);
973
974}
975
976
977////////////////////////////////////////////////////////////////////////////////
978
979TF1::TF1(const TF1 &f1) :
981 fXmin(0), fXmax(0), fNpar(0), fNdim(0), fType(EFType::kFormula)
982{
983 ((TF1 &)f1).Copy(*this);
984}
985
986
987////////////////////////////////////////////////////////////////////////////////
988/// Static function: set the fgAbsValue flag.
989/// By default TF1::Integral uses the original function value to compute the integral
990/// However, TF1::Moment, CentralMoment require to compute the integral
991/// using the absolute value of the function.
992
994{
995 fgAbsValue = flag;
996}
997
998
999////////////////////////////////////////////////////////////////////////////////
1000/// Browse.
1001
1003{
1004 Draw(b ? b->GetDrawOption() : "");
1005 gPad->Update();
1006}
1007
1008
1009////////////////////////////////////////////////////////////////////////////////
1010/// Copy this F1 to a new F1.
1011/// Note that the cached integral with its related arrays are not copied
1012/// (they are also set as transient data members)
1013
1014void TF1::Copy(TObject &obj) const
1015{
1016 delete((TF1 &)obj).fHistogram;
1017
1018 TNamed::Copy((TF1 &)obj);
1019 TAttLine::Copy((TF1 &)obj);
1020 TAttFill::Copy((TF1 &)obj);
1021 TAttMarker::Copy((TF1 &)obj);
1022 ((TF1 &)obj).fXmin = fXmin;
1023 ((TF1 &)obj).fXmax = fXmax;
1024 ((TF1 &)obj).fNpx = fNpx;
1025 ((TF1 &)obj).fNpar = fNpar;
1026 ((TF1 &)obj).fNdim = fNdim;
1027 ((TF1 &)obj).fType = fType;
1028 ((TF1 &)obj).fChisquare = fChisquare;
1029 ((TF1 &)obj).fNpfits = fNpfits;
1030 ((TF1 &)obj).fNDF = fNDF;
1031 ((TF1 &)obj).fMinimum = fMinimum;
1032 ((TF1 &)obj).fMaximum = fMaximum;
1033
1034 ((TF1 &)obj).fParErrors = fParErrors;
1035 ((TF1 &)obj).fParMin = fParMin;
1036 ((TF1 &)obj).fParMax = fParMax;
1037 ((TF1 &)obj).fParent = fParent;
1038 ((TF1 &)obj).fSave = fSave;
1039 ((TF1 &)obj).fHistogram = 0;
1040 ((TF1 &)obj).fMethodCall = 0;
1041 ((TF1 &)obj).fNormalized = fNormalized;
1042 ((TF1 &)obj).fNormIntegral = fNormIntegral;
1043 ((TF1 &)obj).fFormula = 0;
1044
1045 if (fFormula) assert(fFormula->GetNpar() == fNpar);
1046
1047 // use copy-constructor of TMethodCall
1048 TMethodCall *m = (fMethodCall) ? new TMethodCall(*fMethodCall) : nullptr;
1049 ((TF1 &)obj).fMethodCall.reset(m);
1050
1051 TFormula *formulaToCopy = (fFormula) ? new TFormula(*fFormula) : nullptr;
1052 ((TF1 &)obj).fFormula.reset(formulaToCopy);
1053
1054 TF1Parameters *paramsToCopy = (fParams) ? new TF1Parameters(*fParams) : nullptr;
1055 ((TF1 &)obj).fParams.reset(paramsToCopy);
1056
1057 TF1FunctorPointer *functorToCopy = (fFunctor) ? fFunctor->Clone() : nullptr;
1058 ((TF1 &)obj).fFunctor.reset(functorToCopy);
1059
1060 TF1AbsComposition *comp = nullptr;
1061 if (fComposition) {
1062 comp = (TF1AbsComposition *)fComposition->IsA()->New();
1063 fComposition->Copy(*comp);
1064 }
1065 ((TF1 &)obj).fComposition.reset(comp);
1066}
1067
1068
1069////////////////////////////////////////////////////////////////////////////////
1070/// Make a complete copy of the underlying object. If 'newname' is set,
1071/// the copy's name will be set to that name.
1072
1073TObject* TF1::Clone(const char* newname) const
1074{
1075
1076 TF1* obj = (TF1*) TNamed::Clone(newname);
1077
1078 if (fHistogram) {
1079 obj->fHistogram = (TH1*)fHistogram->Clone();
1080 obj->fHistogram->SetDirectory(0);
1081 }
1082
1083 return obj;
1084}
1085
1086
1087////////////////////////////////////////////////////////////////////////////////
1088/// Returns the first derivative of the function at point x,
1089/// computed by Richardson's extrapolation method (use 2 derivative estimates
1090/// to compute a third, more accurate estimation)
1091/// first, derivatives with steps h and h/2 are computed by central difference formulas
1092/// \f[
1093/// D(h) = \frac{f(x+h) - f(x-h)}{2h}
1094/// \f]
1095/// the final estimate
1096/// \f[
1097/// D = \frac{4D(h/2) - D(h)}{3}
1098/// \f]
1099/// "Numerical Methods for Scientists and Engineers", H.M.Antia, 2nd edition"
1100///
1101/// if the argument params is null, the current function parameters are used,
1102/// otherwise the parameters in params are used.
1103///
1104/// the argument eps may be specified to control the step size (precision).
1105/// the step size is taken as eps*(xmax-xmin).
1106/// the default value (0.001) should be good enough for the vast majority
1107/// of functions. Give a smaller value if your function has many changes
1108/// of the second derivative in the function range.
1109///
1110/// Getting the error via TF1::DerivativeError:
1111/// (total error = roundoff error + interpolation error)
1112/// the estimate of the roundoff error is taken as follows:
1113/// \f[
1114/// err = k\sqrt{f(x)^{2} + x^{2}deriv^{2}}\sqrt{\sum ai^{2}},
1115/// \f]
1116/// where k is the double precision, ai are coefficients used in
1117/// central difference formulas
1118/// interpolation error is decreased by making the step size h smaller.
1119///
1120/// \author Anna Kreshuk
1121
1123{
1124 if (GetNdim() > 1) {
1125 Warning("Derivative", "Function dimension is larger than one");
1126 }
1127
1129 double xmin, xmax;
1130 GetRange(xmin, xmax);
1131 // this is not optimal (should be used the average x instead of the range)
1132 double h = eps * std::abs(xmax - xmin);
1133 if (h <= 0) h = 0.001;
1134 double der = 0;
1135 if (params) {
1136 ROOT::Math::WrappedTF1 wtf(*(const_cast<TF1 *>(this)));
1137 wtf.SetParameters(params);
1138 der = rd.Derivative1(wtf, x, h);
1139 } else {
1140 // no need to set parameters used a non-parametric wrapper to avoid allocating
1141 // an array with parameter values
1143 der = rd.Derivative1(wf, x, h);
1144 }
1145
1146 gErrorTF1 = rd.Error();
1147 return der;
1148
1149}
1150
1151
1152////////////////////////////////////////////////////////////////////////////////
1153/// Returns the second derivative of the function at point x,
1154/// computed by Richardson's extrapolation method (use 2 derivative estimates
1155/// to compute a third, more accurate estimation)
1156/// first, derivatives with steps h and h/2 are computed by central difference formulas
1157/// \f[
1158/// D(h) = \frac{f(x+h) - 2f(x) + f(x-h)}{h^{2}}
1159/// \f]
1160/// the final estimate
1161/// \f[
1162/// D = \frac{4D(h/2) - D(h)}{3}
1163/// \f]
1164/// "Numerical Methods for Scientists and Engineers", H.M.Antia, 2nd edition"
1165///
1166/// if the argument params is null, the current function parameters are used,
1167/// otherwise the parameters in params are used.
1168///
1169/// the argument eps may be specified to control the step size (precision).
1170/// the step size is taken as eps*(xmax-xmin).
1171/// the default value (0.001) should be good enough for the vast majority
1172/// of functions. Give a smaller value if your function has many changes
1173/// of the second derivative in the function range.
1174///
1175/// Getting the error via TF1::DerivativeError:
1176/// (total error = roundoff error + interpolation error)
1177/// the estimate of the roundoff error is taken as follows:
1178/// \f[
1179/// err = k\sqrt{f(x)^{2} + x^{2}deriv^{2}}\sqrt{\sum ai^{2}},
1180/// \f]
1181/// where k is the double precision, ai are coefficients used in
1182/// central difference formulas
1183/// interpolation error is decreased by making the step size h smaller.
1184///
1185/// \author Anna Kreshuk
1186
1188{
1189 if (GetNdim() > 1) {
1190 Warning("Derivative2", "Function dimension is larger than one");
1191 }
1192
1194 double xmin, xmax;
1195 GetRange(xmin, xmax);
1196 // this is not optimal (should be used the average x instead of the range)
1197 double h = eps * std::abs(xmax - xmin);
1198 if (h <= 0) h = 0.001;
1199 double der = 0;
1200 if (params) {
1201 ROOT::Math::WrappedTF1 wtf(*(const_cast<TF1 *>(this)));
1202 wtf.SetParameters(params);
1203 der = rd.Derivative2(wtf, x, h);
1204 } else {
1205 // no need to set parameters used a non-parametric wrapper to avoid allocating
1206 // an array with parameter values
1208 der = rd.Derivative2(wf, x, h);
1209 }
1210
1211 gErrorTF1 = rd.Error();
1212
1213 return der;
1214}
1215
1216
1217////////////////////////////////////////////////////////////////////////////////
1218/// Returns the third derivative of the function at point x,
1219/// computed by Richardson's extrapolation method (use 2 derivative estimates
1220/// to compute a third, more accurate estimation)
1221/// first, derivatives with steps h and h/2 are computed by central difference formulas
1222/// \f[
1223/// D(h) = \frac{f(x+2h) - 2f(x+h) + 2f(x-h) - f(x-2h)}{2h^{3}}
1224/// \f]
1225/// the final estimate
1226/// \f[
1227/// D = \frac{4D(h/2) - D(h)}{3}
1228/// \f]
1229/// "Numerical Methods for Scientists and Engineers", H.M.Antia, 2nd edition"
1230///
1231/// if the argument params is null, the current function parameters are used,
1232/// otherwise the parameters in params are used.
1233///
1234/// the argument eps may be specified to control the step size (precision).
1235/// the step size is taken as eps*(xmax-xmin).
1236/// the default value (0.001) should be good enough for the vast majority
1237/// of functions. Give a smaller value if your function has many changes
1238/// of the second derivative in the function range.
1239///
1240/// Getting the error via TF1::DerivativeError:
1241/// (total error = roundoff error + interpolation error)
1242/// the estimate of the roundoff error is taken as follows:
1243/// \f[
1244/// err = k\sqrt{f(x)^{2} + x^{2}deriv^{2}}\sqrt{\sum ai^{2}},
1245/// \f]
1246/// where k is the double precision, ai are coefficients used in
1247/// central difference formulas
1248/// interpolation error is decreased by making the step size h smaller.
1249///
1250/// \author Anna Kreshuk
1251
1253{
1254 if (GetNdim() > 1) {
1255 Warning("Derivative3", "Function dimension is larger than one");
1256 }
1257
1259 double xmin, xmax;
1260 GetRange(xmin, xmax);
1261 // this is not optimal (should be used the average x instead of the range)
1262 double h = eps * std::abs(xmax - xmin);
1263 if (h <= 0) h = 0.001;
1264 double der = 0;
1265 if (params) {
1266 ROOT::Math::WrappedTF1 wtf(*(const_cast<TF1 *>(this)));
1267 wtf.SetParameters(params);
1268 der = rd.Derivative3(wtf, x, h);
1269 } else {
1270 // no need to set parameters used a non-parametric wrapper to avoid allocating
1271 // an array with parameter values
1273 der = rd.Derivative3(wf, x, h);
1274 }
1275
1276 gErrorTF1 = rd.Error();
1277 return der;
1278
1279}
1280
1281
1282////////////////////////////////////////////////////////////////////////////////
1283/// Static function returning the error of the last call to the of Derivative's
1284/// functions
1285
1287{
1288 return gErrorTF1;
1289}
1290
1291
1292////////////////////////////////////////////////////////////////////////////////
1293/// Compute distance from point px,py to a function.
1294///
1295/// Compute the closest distance of approach from point px,py to this
1296/// function. The distance is computed in pixels units.
1297///
1298/// Note that px is called with a negative value when the TF1 is in
1299/// TGraph or TH1 list of functions. In this case there is no point
1300/// looking at the histogram axis.
1301
1303{
1304 if (!fHistogram) return 9999;
1305 Int_t distance = 9999;
1306 if (px >= 0) {
1307 distance = fHistogram->DistancetoPrimitive(px, py);
1308 if (distance <= 1) return distance;
1309 } else {
1310 px = -px;
1311 }
1312
1313 Double_t xx[1];
1314 Double_t x = gPad->AbsPixeltoX(px);
1315 xx[0] = gPad->PadtoX(x);
1316 if (xx[0] < fXmin || xx[0] > fXmax) return distance;
1317 Double_t fval = Eval(xx[0]);
1318 Double_t y = gPad->YtoPad(fval);
1319 Int_t pybin = gPad->YtoAbsPixel(y);
1320 return TMath::Abs(py - pybin);
1321}
1322
1323
1324////////////////////////////////////////////////////////////////////////////////
1325/// Draw this function with its current attributes.
1326///
1327/// Possible option values are:
1328///
1329/// option | description
1330/// -------|----------------------------------------
1331/// "SAME" | superimpose on top of existing picture
1332/// "L" | connect all computed points with a straight line
1333/// "C" | connect all computed points with a smooth curve
1334/// "FC" | draw a fill area below a smooth curve
1335///
1336/// Note that the default value is "L". Therefore to draw on top
1337/// of an existing picture, specify option "LSAME"
1338///
1339/// NB. You must use DrawCopy if you want to draw several times the same
1340/// function in the current canvas.
1341
1342void TF1::Draw(Option_t *option)
1343{
1344 TString opt = option;
1345 opt.ToLower();
1346 if (gPad && !opt.Contains("same")) gPad->Clear();
1347
1348 AppendPad(option);
1349
1350 gPad->IncrementPaletteColor(1, opt);
1351}
1352
1353
1354////////////////////////////////////////////////////////////////////////////////
1355/// Draw a copy of this function with its current attributes.
1356///
1357/// This function MUST be used instead of Draw when you want to draw
1358/// the same function with different parameters settings in the same canvas.
1359///
1360/// Possible option values are:
1361///
1362/// option | description
1363/// -------|----------------------------------------
1364/// "SAME" | superimpose on top of existing picture
1365/// "L" | connect all computed points with a straight line
1366/// "C" | connect all computed points with a smooth curve
1367/// "FC" | draw a fill area below a smooth curve
1368///
1369/// Note that the default value is "L". Therefore to draw on top
1370/// of an existing picture, specify option "LSAME"
1371
1373{
1374 TF1 *newf1 = (TF1 *)this->IsA()->New();
1375 Copy(*newf1);
1376 newf1->AppendPad(option);
1377 newf1->SetBit(kCanDelete);
1378 return newf1;
1379}
1380
1381
1382////////////////////////////////////////////////////////////////////////////////
1383/// Draw derivative of this function
1384///
1385/// An intermediate TGraph object is built and drawn with option.
1386/// The function returns a pointer to the TGraph object. Do:
1387///
1388/// TGraph *g = (TGraph*)myfunc.DrawDerivative(option);
1389///
1390/// The resulting graph will be drawn into the current pad.
1391/// If this function is used via the context menu, it recommended
1392/// to create a new canvas/pad before invoking this function.
1393
1395{
1396 TVirtualPad *pad = gROOT->GetSelectedPad();
1397 TVirtualPad *padsav = gPad;
1398 if (pad) pad->cd();
1399
1400 TGraph *gr = new TGraph(this, "d");
1401 gr->Draw(option);
1402 if (padsav) padsav->cd();
1403 return gr;
1404}
1405
1406
1407////////////////////////////////////////////////////////////////////////////////
1408/// Draw integral of this function
1409///
1410/// An intermediate TGraph object is built and drawn with option.
1411/// The function returns a pointer to the TGraph object. Do:
1412///
1413/// TGraph *g = (TGraph*)myfunc.DrawIntegral(option);
1414///
1415/// The resulting graph will be drawn into the current pad.
1416/// If this function is used via the context menu, it recommended
1417/// to create a new canvas/pad before invoking this function.
1418
1420{
1421 TVirtualPad *pad = gROOT->GetSelectedPad();
1422 TVirtualPad *padsav = gPad;
1423 if (pad) pad->cd();
1424
1425 TGraph *gr = new TGraph(this, "i");
1426 gr->Draw(option);
1427 if (padsav) padsav->cd();
1428 return gr;
1429}
1430
1431
1432////////////////////////////////////////////////////////////////////////////////
1433/// Draw function between xmin and xmax.
1434
1436{
1437// //if(Compile(formula)) return ;
1438 SetRange(xmin, xmax);
1439
1440 Draw(option);
1441}
1442
1443
1444////////////////////////////////////////////////////////////////////////////////
1445/// Evaluate this function.
1446///
1447/// Computes the value of this function (general case for a 3-d function)
1448/// at point x,y,z.
1449/// For a 1-d function give y=0 and z=0
1450/// The current value of variables x,y,z is passed through x, y and z.
1451/// The parameters used will be the ones in the array params if params is given
1452/// otherwise parameters will be taken from the stored data members fParams
1453
1455{
1456 if (fType == EFType::kFormula) return fFormula->Eval(x, y, z, t);
1457
1458 Double_t xx[4] = {x, y, z, t};
1459 Double_t *pp = (Double_t *)fParams->GetParameters();
1460 // if (fType == EFType::kInterpreted)((TF1 *)this)->InitArgs(xx, pp);
1461 return ((TF1 *)this)->EvalPar(xx, pp);
1462}
1463
1464
1465////////////////////////////////////////////////////////////////////////////////
1466/// Evaluate function with given coordinates and parameters.
1467///
1468/// Compute the value of this function at point defined by array x
1469/// and current values of parameters in array params.
1470/// If argument params is omitted or equal 0, the internal values
1471/// of parameters (array fParams) will be used instead.
1472/// For a 1-D function only x[0] must be given.
1473/// In case of a multi-dimensional function, the arrays x must be
1474/// filled with the corresponding number of dimensions.
1475///
1476/// WARNING. In case of an interpreted function (fType=2), it is the
1477/// user's responsibility to initialize the parameters via InitArgs
1478/// before calling this function.
1479/// InitArgs should be called at least once to specify the addresses
1480/// of the arguments x and params.
1481/// InitArgs should be called every time these addresses change.
1482
1484{
1485 //fgCurrent = this;
1486
1487 if (fType == EFType::kFormula) {
1488 assert(fFormula);
1489
1490 if (fNormalized && fNormIntegral != 0)
1491 return fFormula->EvalPar(x, params) / fNormIntegral;
1492 else
1493 return fFormula->EvalPar(x, params);
1494 }
1495 Double_t result = 0;
1496 if (fType == EFType::kPtrScalarFreeFcn || fType == EFType::kTemplScalar) {
1497 if (fFunctor) {
1498 assert(fParams);
1499 if (params) result = ((TF1FunctorPointerImpl<Double_t> *)fFunctor.get())->fImpl((Double_t *)x, (Double_t *)params);
1500 else result = ((TF1FunctorPointerImpl<Double_t> *)fFunctor.get())->fImpl((Double_t *)x, (Double_t *)fParams->GetParameters());
1501
1502 } else result = GetSave(x);
1503
1504 if (fNormalized && fNormIntegral != 0)
1505 result = result / fNormIntegral;
1506
1507 return result;
1508 }
1509 if (fType == EFType::kInterpreted) {
1510 if (fMethodCall) fMethodCall->Execute(result);
1511 else result = GetSave(x);
1512
1513 if (fNormalized && fNormIntegral != 0)
1514 result = result / fNormIntegral;
1515
1516 return result;
1517 }
1518
1519#ifdef R__HAS_VECCORE
1520 if (fType == EFType::kTemplVec) {
1521 if (fFunctor) {
1522 if (params) result = EvalParVec(x, params);
1523 else result = EvalParVec(x, (Double_t *) fParams->GetParameters());
1524 }
1525 else {
1526 result = GetSave(x);
1527 }
1528
1529 if (fNormalized && fNormIntegral != 0)
1530 result = result / fNormIntegral;
1531
1532 return result;
1533 }
1534#endif
1535
1536 if (fType == EFType::kCompositionFcn) {
1537 if (!fComposition)
1538 Error("EvalPar", "Composition function not found");
1539
1540 result = (*fComposition)(x, params);
1541 }
1542
1543 return result;
1544}
1545
1546////////////////////////////////////////////////////////////////////////////////
1547/// Execute action corresponding to one event.
1548///
1549/// This member function is called when a F1 is clicked with the locator
1550
1552{
1553 if (!gPad) return;
1554
1555 if (fHistogram) fHistogram->ExecuteEvent(event, px, py);
1556
1557 if (!gPad->GetView()) {
1558 if (event == kMouseMotion) gPad->SetCursor(kHand);
1559 }
1560}
1561
1562
1563////////////////////////////////////////////////////////////////////////////////
1564/// Fix the value of a parameter
1565/// The specified value will be used in a fit operation
1566
1568{
1569 if (ipar < 0 || ipar > GetNpar() - 1) return;
1570 SetParameter(ipar, value);
1571 if (value != 0) SetParLimits(ipar, value, value);
1572 else SetParLimits(ipar, 1, 1);
1573}
1574
1575
1576////////////////////////////////////////////////////////////////////////////////
1577/// Static function returning the current function being processed
1578
1580{
1581 ::Warning("TF1::GetCurrent", "This function is obsolete and is working only for the current painted functions");
1582 return fgCurrent;
1583}
1584
1585
1586////////////////////////////////////////////////////////////////////////////////
1587/// Return a pointer to the histogram used to visualise the function
1588/// Note that this histogram is managed by the function and
1589/// in same case it is automatically deleted when some TF1 functions are called
1590/// such as TF1::SetParameters, TF1::SetNpx, TF1::SetRange
1591/// It is then reccomended either to clone the return object or calling again teh GetHistogram
1592/// function whenever is needed
1593
1595{
1596 if (fHistogram) return fHistogram;
1597
1598 // histogram has not been yet created - create it
1599 // should not we make this function not const ??
1600 const_cast<TF1 *>(this)->fHistogram = const_cast<TF1 *>(this)->CreateHistogram();
1601 if (!fHistogram) Error("GetHistogram", "Error creating histogram for function %s of type %s", GetName(), IsA()->GetName());
1602 return fHistogram;
1603}
1604
1605
1606////////////////////////////////////////////////////////////////////////////////
1607/// Returns the maximum value of the function
1608///
1609/// Method:
1610/// First, the grid search is used to bracket the maximum
1611/// with the step size = (xmax-xmin)/fNpx.
1612/// This way, the step size can be controlled via the SetNpx() function.
1613/// If the function is unimodal or if its extrema are far apart, setting
1614/// the fNpx to a small value speeds the algorithm up many times.
1615/// Then, Brent's method is applied on the bracketed interval
1616/// epsilon (default = 1.E-10) controls the relative accuracy (if |x| > 1 )
1617/// and absolute (if |x| < 1) and maxiter (default = 100) controls the maximum number
1618/// of iteration of the Brent algorithm
1619/// If the flag logx is set the grid search is done in log step size
1620/// This is done automatically if the log scale is set in the current Pad
1621///
1622/// NOTE: see also TF1::GetMaximumX and TF1::GetX
1623
1625{
1626 if (xmin >= xmax) {
1627 xmin = fXmin;
1628 xmax = fXmax;
1629 }
1630
1631 if (!logx && gPad != 0) logx = gPad->GetLogx();
1632
1634 GInverseFunc g(this);
1636 bm.SetFunction(wf1, xmin, xmax);
1637 bm.SetNpx(fNpx);
1638 bm.SetLogScan(logx);
1639 bm.Minimize(maxiter, epsilon, epsilon);
1640 Double_t x;
1641 x = - bm.FValMinimum();
1642
1643 return x;
1644}
1645
1646
1647////////////////////////////////////////////////////////////////////////////////
1648/// Returns the X value corresponding to the maximum value of the function
1649///
1650/// Method:
1651/// First, the grid search is used to bracket the maximum
1652/// with the step size = (xmax-xmin)/fNpx.
1653/// This way, the step size can be controlled via the SetNpx() function.
1654/// If the function is unimodal or if its extrema are far apart, setting
1655/// the fNpx to a small value speeds the algorithm up many times.
1656/// Then, Brent's method is applied on the bracketed interval
1657/// epsilon (default = 1.E-10) controls the relative accuracy (if |x| > 1 )
1658/// and absolute (if |x| < 1) and maxiter (default = 100) controls the maximum number
1659/// of iteration of the Brent algorithm
1660/// If the flag logx is set the grid search is done in log step size
1661/// This is done automatically if the log scale is set in the current Pad
1662///
1663/// NOTE: see also TF1::GetX
1664
1666{
1667 if (xmin >= xmax) {
1668 xmin = fXmin;
1669 xmax = fXmax;
1670 }
1671
1672 if (!logx && gPad != 0) logx = gPad->GetLogx();
1673
1675 GInverseFunc g(this);
1677 bm.SetFunction(wf1, xmin, xmax);
1678 bm.SetNpx(fNpx);
1679 bm.SetLogScan(logx);
1680 bm.Minimize(maxiter, epsilon, epsilon);
1681 Double_t x;
1682 x = bm.XMinimum();
1683
1684 return x;
1685}
1686
1687
1688////////////////////////////////////////////////////////////////////////////////
1689/// Returns the minimum value of the function on the (xmin, xmax) interval
1690///
1691/// Method:
1692/// First, the grid search is used to bracket the maximum
1693/// with the step size = (xmax-xmin)/fNpx. This way, the step size
1694/// can be controlled via the SetNpx() function. If the function is
1695/// unimodal or if its extrema are far apart, setting the fNpx to
1696/// a small value speeds the algorithm up many times.
1697/// Then, Brent's method is applied on the bracketed interval
1698/// epsilon (default = 1.E-10) controls the relative accuracy (if |x| > 1 )
1699/// and absolute (if |x| < 1) and maxiter (default = 100) controls the maximum number
1700/// of iteration of the Brent algorithm
1701/// If the flag logx is set the grid search is done in log step size
1702/// This is done automatically if the log scale is set in the current Pad
1703///
1704/// NOTE: see also TF1::GetMaximumX and TF1::GetX
1705
1707{
1708 if (xmin >= xmax) {
1709 xmin = fXmin;
1710 xmax = fXmax;
1711 }
1712
1713 if (!logx && gPad != 0) logx = gPad->GetLogx();
1714
1717 bm.SetFunction(wf1, xmin, xmax);
1718 bm.SetNpx(fNpx);
1719 bm.SetLogScan(logx);
1720 bm.Minimize(maxiter, epsilon, epsilon);
1721 Double_t x;
1722 x = bm.FValMinimum();
1723
1724 return x;
1725}
1726
1727////////////////////////////////////////////////////////////////////////////////
1728/// Find the minimum of a function of whatever dimension.
1729/// While GetMinimum works only for 1D function , GetMinimumNDim works for all dimensions
1730/// since it uses the minimizer interface
1731/// vector x at beginning will contained the initial point, on exit will contain the result
1732
1734{
1735 R__ASSERT(x != 0);
1736
1737 int ndim = GetNdim();
1738 if (ndim == 0) {
1739 Error("GetMinimumNDim", "Function of dimension 0 - return Eval(x)");
1740 return (const_cast<TF1 &>(*this))(x);
1741 }
1742
1743 // create minimizer class
1744 const char *minimName = ROOT::Math::MinimizerOptions::DefaultMinimizerType().c_str();
1745 const char *minimAlgo = ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo().c_str();
1747
1748 if (min == 0) {
1749 Error("GetMinimumNDim", "Error creating minimizer %s", minimName);
1750 return 0;
1751 }
1752
1753 // minimizer will be set using default values
1754 if (epsilon > 0) min->SetTolerance(epsilon);
1755 if (maxiter > 0) min->SetMaxFunctionCalls(maxiter);
1756
1757 // create wrapper class from TF1 (cannot use Functor, t.b.i.)
1758 ROOT::Math::WrappedMultiFunction<TF1 &> objFunc(const_cast<TF1 &>(*this), ndim);
1759 // create -f(x) when searching for the maximum
1760 GInverseFuncNdim invFunc(const_cast<TF1 *>(this));
1762 if (!findmax)
1763 min->SetFunction(objFunc);
1764 else
1765 min->SetFunction(objFuncInv);
1766
1767 std::vector<double> rmin(ndim);
1768 std::vector<double> rmax(ndim);
1769 GetRange(&rmin[0], &rmax[0]);
1770 for (int i = 0; i < ndim; ++i) {
1771 const char *xname = 0;
1772 double stepSize = 0.1;
1773 // use range for step size or give some value depending on x if range is not defined
1774 if (rmax[i] > rmin[i])
1775 stepSize = (rmax[i] - rmin[i]) / 100;
1776 else if (std::abs(x[i]) > 1.)
1777 stepSize = 0.1 * x[i];
1778
1779 // set variable names
1780 if (ndim <= 3) {
1781 if (i == 0) {
1782 xname = "x";
1783 } else if (i == 1) {
1784 xname = "y";
1785 } else {
1786 xname = "z";
1787 }
1788 } else {
1789 xname = TString::Format("x_%d", i);
1790 // arbitrary step sie (should be computed from range)
1791 }
1792
1793 if (rmin[i] < rmax[i]) {
1794 //Info("GetMinMax","setting limits on %s - [ %f , %f ]",xname,rmin[i],rmax[i]);
1795 min->SetLimitedVariable(i, xname, x[i], stepSize, rmin[i], rmax[i]);
1796 } else {
1797 min->SetVariable(i, xname, x[i], stepSize);
1798 }
1799 }
1800
1801 bool ret = min->Minimize();
1802 if (!ret) {
1803 Error("GetMinimumNDim", "Error minimizing function %s", GetName());
1804 }
1805 if (min->X()) std::copy(min->X(), min->X() + ndim, x);
1806 double fmin = min->MinValue();
1807 delete min;
1808 // need to revert sign in case looking for maximum
1809 return (findmax) ? -fmin : fmin;
1810
1811}
1812
1813
1814////////////////////////////////////////////////////////////////////////////////
1815/// Returns the X value corresponding to the minimum value of the function
1816/// on the (xmin, xmax) interval
1817///
1818/// Method:
1819/// First, the grid search is used to bracket the maximum
1820/// with the step size = (xmax-xmin)/fNpx. This way, the step size
1821/// can be controlled via the SetNpx() function. If the function is
1822/// unimodal or if its extrema are far apart, setting the fNpx to
1823/// a small value speeds the algorithm up many times.
1824/// Then, Brent's method is applied on the bracketed interval
1825/// epsilon (default = 1.E-10) controls the relative accuracy (if |x| > 1 )
1826/// and absolute (if |x| < 1) and maxiter (default = 100) controls the maximum number
1827/// of iteration of the Brent algorithm
1828/// If the flag logx is set the grid search is done in log step size
1829/// This is done automatically if the log scale is set in the current Pad
1830///
1831/// NOTE: see also TF1::GetX
1832
1834{
1835 if (xmin >= xmax) {
1836 xmin = fXmin;
1837 xmax = fXmax;
1838 }
1839
1842 bm.SetFunction(wf1, xmin, xmax);
1843 bm.SetNpx(fNpx);
1844 bm.SetLogScan(logx);
1845 bm.Minimize(maxiter, epsilon, epsilon);
1846 Double_t x;
1847 x = bm.XMinimum();
1848
1849 return x;
1850}
1851
1852
1853////////////////////////////////////////////////////////////////////////////////
1854/// Returns the X value corresponding to the function value fy for (xmin<x<xmax).
1855/// in other words it can find the roots of the function when fy=0 and successive calls
1856/// by changing the next call to [xmin+eps,xmax] where xmin is the previous root.
1857///
1858/// Method:
1859/// First, the grid search is used to bracket the maximum
1860/// with the step size = (xmax-xmin)/fNpx. This way, the step size
1861/// can be controlled via the SetNpx() function. If the function is
1862/// unimodal or if its extrema are far apart, setting the fNpx to
1863/// a small value speeds the algorithm up many times.
1864/// Then, Brent's method is applied on the bracketed interval
1865/// epsilon (default = 1.E-10) controls the relative accuracy (if |x| > 1 )
1866/// and absolute (if |x| < 1) and maxiter (default = 100) controls the maximum number
1867/// of iteration of the Brent algorithm
1868/// If the flag logx is set the grid search is done in log step size
1869/// This is done automatically if the log scale is set in the current Pad
1870///
1871/// NOTE: see also TF1::GetMaximumX, TF1::GetMinimumX
1872
1874{
1875 if (xmin >= xmax) {
1876 xmin = fXmin;
1877 xmax = fXmax;
1878 }
1879
1880 if (!logx && gPad != 0) logx = gPad->GetLogx();
1881
1882 GFunc g(this, fy);
1885 brf.SetFunction(wf1, xmin, xmax);
1886 brf.SetNpx(fNpx);
1887 brf.SetLogScan(logx);
1888 bool ret = brf.Solve(maxiter, epsilon, epsilon);
1889 if (!ret) Error("GetX","[%f,%f] is not a valid interval",xmin,xmax);
1890 return (ret) ? brf.Root() : TMath::QuietNaN();
1891}
1892
1893////////////////////////////////////////////////////////////////////////////////
1894/// Return the number of degrees of freedom in the fit
1895/// the fNDF parameter has been previously computed during a fit.
1896/// The number of degrees of freedom corresponds to the number of points
1897/// used in the fit minus the number of free parameters.
1898
1900{
1901 Int_t npar = GetNpar();
1902 if (fNDF == 0 && (fNpfits > npar)) return fNpfits - npar;
1903 return fNDF;
1904}
1905
1906
1907////////////////////////////////////////////////////////////////////////////////
1908/// Return the number of free parameters
1909
1911{
1912 Int_t ntot = GetNpar();
1913 Int_t nfree = ntot;
1914 Double_t al, bl;
1915 for (Int_t i = 0; i < ntot; i++) {
1916 ((TF1 *)this)->GetParLimits(i, al, bl);
1917 if (al * bl != 0 && al >= bl) nfree--;
1918 }
1919 return nfree;
1920}
1921
1922
1923////////////////////////////////////////////////////////////////////////////////
1924/// Redefines TObject::GetObjectInfo.
1925/// Displays the function info (x, function value)
1926/// corresponding to cursor position px,py
1927
1928char *TF1::GetObjectInfo(Int_t px, Int_t /* py */) const
1929{
1930 static char info[64];
1931 Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px));
1932 snprintf(info, 64, "(x=%g, f=%g)", x, ((TF1 *)this)->Eval(x));
1933 return info;
1934}
1935
1936
1937////////////////////////////////////////////////////////////////////////////////
1938/// Return value of parameter number ipar
1939
1941{
1942 if (ipar < 0 || ipar > GetNpar() - 1) return 0;
1943 return fParErrors[ipar];
1944}
1945
1946
1947////////////////////////////////////////////////////////////////////////////////
1948/// Return limits for parameter ipar.
1949
1950void TF1::GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
1951{
1952 parmin = 0;
1953 parmax = 0;
1954 int n = fParMin.size();
1955 assert(n == int(fParMax.size()) && n <= fNpar);
1956 if (ipar < 0 || ipar > n - 1) return;
1957 parmin = fParMin[ipar];
1958 parmax = fParMax[ipar];
1959}
1960
1961
1962////////////////////////////////////////////////////////////////////////////////
1963/// Return the fit probability
1964
1966{
1967 if (fNDF <= 0) return 0;
1968 return TMath::Prob(fChisquare, fNDF);
1969}
1970
1971
1972////////////////////////////////////////////////////////////////////////////////
1973/// Compute Quantiles for density distribution of this function
1974///
1975/// Quantile x_q of a probability distribution Function F is defined as
1976/// \f[
1977/// F(x_{q}) = \int_{xmin}^{x_{q}} f dx = q with 0 <= q <= 1.
1978/// \f]
1979/// For instance the median \f$ x_{\frac{1}{2}} \f$ of a distribution is defined as that value
1980/// of the random variable for which the distribution function equals 0.5:
1981/// \f[
1982/// F(x_{\frac{1}{2}}) = \prod(x < x_{\frac{1}{2}}) = \frac{1}{2}
1983/// \f]
1984///
1985/// \param[in] nprobSum maximum size of array q and size of array probSum
1986/// \param[out] q array filled with nq quantiles
1987/// \param[in] probSum array of positions where quantiles will be computed.
1988/// It is assumed to contain at least nprobSum values.
1989/// \return value nq (<=nprobSum) with the number of quantiles computed
1990///
1991/// Getting quantiles from two histograms and storing results in a TGraph,
1992/// a so-called QQ-plot
1993///
1994/// TGraph *gr = new TGraph(nprob);
1995/// f1->GetQuantiles(nprob,gr->GetX());
1996/// f2->GetQuantiles(nprob,gr->GetY());
1997/// gr->Draw("alp");
1998///
1999/// \author Eddy Offermann
2000
2001
2002Int_t TF1::GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum)
2003{
2004 // LM: change to use fNpx
2005 // should we change code to use a root finder ?
2006 // It should be more precise and more efficient
2007 const Int_t npx = TMath::Max(fNpx, 2 * nprobSum);
2008 const Double_t xMin = GetXmin();
2009 const Double_t xMax = GetXmax();
2010 const Double_t dx = (xMax - xMin) / npx;
2011
2012 TArrayD integral(npx + 1);
2013 TArrayD alpha(npx);
2014 TArrayD beta(npx);
2015 TArrayD gamma(npx);
2016
2017 integral[0] = 0;
2018 Int_t intNegative = 0;
2019 Int_t i;
2020 for (i = 0; i < npx; i++) {
2021 Double_t integ = Integral(Double_t(xMin + i * dx), Double_t(xMin + i * dx + dx), 0.0);
2022 if (integ < 0) {
2023 intNegative++;
2024 integ = -integ;
2025 }
2026 integral[i + 1] = integral[i] + integ;
2027 }
2028
2029 if (intNegative > 0)
2030 Warning("GetQuantiles", "function:%s has %d negative values: abs assumed",
2031 GetName(), intNegative);
2032 if (integral[npx] == 0) {
2033 Error("GetQuantiles", "Integral of function is zero");
2034 return 0;
2035 }
2036
2037 const Double_t total = integral[npx];
2038 for (i = 1; i <= npx; i++) integral[i] /= total;
2039 //the integral r for each bin is approximated by a parabola
2040 // x = alpha + beta*r +gamma*r**2
2041 // compute the coefficients alpha, beta, gamma for each bin
2042 for (i = 0; i < npx; i++) {
2043 const Double_t x0 = xMin + dx * i;
2044 const Double_t r2 = integral[i + 1] - integral[i];
2045 const Double_t r1 = Integral(x0, x0 + 0.5 * dx, 0.0) / total;
2046 gamma[i] = (2 * r2 - 4 * r1) / (dx * dx);
2047 beta[i] = r2 / dx - gamma[i] * dx;
2048 alpha[i] = x0;
2049 gamma[i] *= 2;
2050 }
2051
2052 // Be careful because of finite precision in the integral; Use the fact that the integral
2053 // is monotone increasing
2054 for (i = 0; i < nprobSum; i++) {
2055 const Double_t r = probSum[i];
2056 Int_t bin = TMath::Max(TMath::BinarySearch(npx + 1, integral.GetArray(), r), (Long64_t)0);
2057 // in case the prob is 1
2058 if (bin == npx) {
2059 q[i] = xMax;
2060 continue;
2061 }
2062 // LM use a tolerance 1.E-12 (integral precision)
2063 while (bin < npx - 1 && TMath::AreEqualRel(integral[bin + 1], r, 1E-12)) {
2064 if (TMath::AreEqualRel(integral[bin + 2], r, 1E-12)) bin++;
2065 else break;
2066 }
2067
2068 const Double_t rr = r - integral[bin];
2069 if (rr != 0.0) {
2070 Double_t xx = 0.0;
2071 const Double_t fac = -2.*gamma[bin] * rr / beta[bin] / beta[bin];
2072 if (fac != 0 && fac <= 1)
2073 xx = (-beta[bin] + TMath::Sqrt(beta[bin] * beta[bin] + 2 * gamma[bin] * rr)) / gamma[bin];
2074 else if (beta[bin] != 0.)
2075 xx = rr / beta[bin];
2076 q[i] = alpha[bin] + xx;
2077 } else {
2078 q[i] = alpha[bin];
2079 if (integral[bin + 1] == r) q[i] += dx;
2080 }
2081 }
2082
2083 return nprobSum;
2084}
2085////////////////////////////////////////////////////////////////////////////////
2086///
2087/// Compute the cumulative function at fNpx points between fXmin and fXmax.
2088/// Option can be used to force a log scale (option = "log"), linear (option = "lin") or automatic if empty.
2090
2091 fIntegral.resize(fNpx + 1);
2092 fAlpha.resize(fNpx + 1);
2093 fBeta.resize(fNpx);
2094 fGamma.resize(fNpx);
2095 fIntegral[0] = 0;
2096 fAlpha[fNpx] = 0;
2097 Double_t integ;
2098 Int_t intNegative = 0;
2099 Int_t i;
2100 Bool_t logbin = kFALSE;
2101 Double_t dx;
2104 TString opt(option);
2105 opt.ToUpper();
2106 // perform a log binning if specified by user (option="Log") or if some conditions are met
2107 // and the user explicitly does not specify a Linear binning option
2108 if (opt.Contains("LOG") || ((xmin > 0 && xmax / xmin > fNpx) && !opt.Contains("LIN"))) {
2109 logbin = kTRUE;
2110 fAlpha[fNpx] = 1;
2113 if (gDebug)
2114 Info("GetRandom", "Use log scale for tabulating the integral in [%f,%f] with %d points", fXmin, fXmax, fNpx);
2115 }
2116 dx = (xmax - xmin) / fNpx;
2117
2118 std::vector<Double_t> xx(fNpx + 1);
2119 for (i = 0; i < fNpx; i++) {
2120 xx[i] = xmin + i * dx;
2121 }
2122 xx[fNpx] = xmax;
2123 for (i = 0; i < fNpx; i++) {
2124 if (logbin) {
2125 integ = Integral(TMath::Power(10, xx[i]), TMath::Power(10, xx[i + 1]), 0.0);
2126 } else {
2127 integ = Integral(xx[i], xx[i + 1], 0.0);
2128 }
2129 if (integ < 0) {
2130 intNegative++;
2131 integ = -integ;
2132 }
2133 fIntegral[i + 1] = fIntegral[i] + integ;
2134 }
2135 if (intNegative > 0) {
2136 Warning("GetRandom", "function:%s has %d negative values: abs assumed", GetName(), intNegative);
2137 }
2138 if (fIntegral[fNpx] == 0) {
2139 Error("GetRandom", "Integral of function is zero");
2140 return kFALSE;
2141 }
2143 for (i = 1; i <= fNpx; i++) { // normalize integral to 1
2144 fIntegral[i] /= total;
2145 }
2146 // the integral r for each bin is approximated by a parabola
2147 // x = alpha + beta*r +gamma*r**2
2148 // compute the coefficients alpha, beta, gamma for each bin
2149 Double_t x0, r1, r2, r3;
2150 for (i = 0; i < fNpx; i++) {
2151 x0 = xx[i];
2152 r2 = fIntegral[i + 1] - fIntegral[i];
2153 if (logbin)
2154 r1 = Integral(TMath::Power(10, x0), TMath::Power(10, x0 + 0.5 * dx), 0.0) / total;
2155 else
2156 r1 = Integral(x0, x0 + 0.5 * dx, 0.0) / total;
2157 r3 = 2 * r2 - 4 * r1;
2158 if (TMath::Abs(r3) > 1e-8)
2159 fGamma[i] = r3 / (dx * dx);
2160 else
2161 fGamma[i] = 0;
2162 fBeta[i] = r2 / dx - fGamma[i] * dx;
2163 fAlpha[i] = x0;
2164 fGamma[i] *= 2;
2165 }
2166 return kTRUE;
2167}
2168
2169////////////////////////////////////////////////////////////////////////////////
2170/// Return a random number following this function shape.
2171///
2172/// @param rng Random number generator. By default (or when passing a nullptr) the global gRandom is used
2173/// @param option Option string which controls the binning used to compute the integral. Default mode is automatic depending of
2174/// xmax, xmin and Npx (function points).
2175/// Possible values are:
2176/// - "LOG" to force usage of log scale for tabulating the integral
2177/// - "LIN" to force usage of linear scale when tabulating the integral
2178///
2179/// The distribution contained in the function fname (TF1) is integrated
2180/// over the channel contents.
2181/// It is normalized to 1.
2182/// For each bin the integral is approximated by a parabola.
2183/// The parabola coefficients are stored as non persistent data members
2184/// Getting one random number implies:
2185/// - Generating a random number between 0 and 1 (say r1)
2186/// - Look in which bin in the normalized integral r1 corresponds to
2187/// - Evaluate the parabolic curve in the selected bin to find the corresponding X value.
2188///
2189/// The user can provide as optional parameter a Random number generator.
2190/// By default gRandom is used
2191///
2192/// If the ratio fXmax/fXmin > fNpx the integral is tabulated in log scale in x
2193/// A log scale for the intergral is also always used if a user specifies the "LOG" option
2194/// Instead if a user requestes a "LIN" option the integral binning is never done in log scale
2195/// whatever the fXmax/fXmin ratio is
2196///
2197/// Note that the parabolic approximation is very good as soon as the number of bins is greater than 50.
2198
2199
2201{
2202 // Check if integral array must be built
2203 if (fIntegral.size() == 0) {
2204 Bool_t ret = ComputeCdfTable(option);
2205 if (!ret) return TMath::QuietNaN();
2206 }
2207
2208
2209 // return random number
2210 Double_t r = (rng) ? rng->Rndm() : gRandom->Rndm();
2211 Int_t bin = TMath::BinarySearch(fNpx, fIntegral.data(), r);
2212 Double_t rr = r - fIntegral[bin];
2213
2214 Double_t yy;
2215 if (fGamma[bin] != 0)
2216 yy = (-fBeta[bin] + TMath::Sqrt(fBeta[bin] * fBeta[bin] + 2 * fGamma[bin] * rr)) / fGamma[bin];
2217 else
2218 yy = rr / fBeta[bin];
2219 Double_t x = fAlpha[bin] + yy;
2220 if (fAlpha[fNpx] > 0) return TMath::Power(10, x);
2221 return x;
2222}
2223
2224
2225////////////////////////////////////////////////////////////////////////////////
2226/// Return a random number following this function shape in [xmin,xmax]
2227///
2228/// The distribution contained in the function fname (TF1) is integrated
2229/// over the channel contents.
2230/// It is normalized to 1.
2231/// For each bin the integral is approximated by a parabola.
2232/// The parabola coefficients are stored as non persistent data members
2233/// Getting one random number implies:
2234/// - Generating a random number between 0 and 1 (say r1)
2235/// - Look in which bin in the normalized integral r1 corresponds to
2236/// - Evaluate the parabolic curve in the selected bin to find
2237/// the corresponding X value.
2238///
2239/// The parabolic approximation is very good as soon as the number
2240/// of bins is greater than 50.
2241///
2242/// @param xmin minimum value for generated random numbers
2243/// @param xmax maximum value for generated random numbers
2244/// @param rng (optional) random number generator pointer
2245/// @param option (optional) : `LOG` or `LIN` to force the usage of a log or linear scale for computing the cumulative integral table
2246///
2247/// IMPORTANT NOTE
2248///
2249/// The integral of the function is computed at fNpx points. If the function
2250/// has sharp peaks, you should increase the number of points (SetNpx)
2251/// such that the peak is correctly tabulated at several points.
2252
2254{
2255 // Check if integral array must be built
2256 if (fIntegral.size() == 0) {
2257 Bool_t ret = ComputeCdfTable(option);
2258 if (!ret) return TMath::QuietNaN();
2259 }
2260
2261 // return random number
2262 Double_t dx = (fXmax - fXmin) / fNpx;
2263 Int_t nbinmin = (Int_t)((xmin - fXmin) / dx);
2264 Int_t nbinmax = (Int_t)((xmax - fXmin) / dx) + 2;
2265 if (nbinmax > fNpx) nbinmax = fNpx;
2266
2267 Double_t pmin = fIntegral[nbinmin];
2268 Double_t pmax = fIntegral[nbinmax];
2269
2270 Double_t r, x, xx, rr;
2271 do {
2272 r = (rng) ? rng->Uniform(pmin, pmax) : gRandom->Uniform(pmin, pmax);
2273
2274 Int_t bin = TMath::BinarySearch(fNpx, fIntegral.data(), r);
2275 rr = r - fIntegral[bin];
2276
2277 if (fGamma[bin] != 0)
2278 xx = (-fBeta[bin] + TMath::Sqrt(fBeta[bin] * fBeta[bin] + 2 * fGamma[bin] * rr)) / fGamma[bin];
2279 else
2280 xx = rr / fBeta[bin];
2281 x = fAlpha[bin] + xx;
2282 } while (x < xmin || x > xmax);
2283 return x;
2284}
2285
2286////////////////////////////////////////////////////////////////////////////////
2287/// Return range of a generic N-D function.
2288
2289void TF1::GetRange(Double_t *rmin, Double_t *rmax) const
2290{
2291 int ndim = GetNdim();
2292
2293 double xmin = 0, ymin = 0, zmin = 0, xmax = 0, ymax = 0, zmax = 0;
2294 GetRange(xmin, ymin, zmin, xmax, ymax, zmax);
2295 for (int i = 0; i < ndim; ++i) {
2296 if (i == 0) {
2297 rmin[0] = xmin;
2298 rmax[0] = xmax;
2299 } else if (i == 1) {
2300 rmin[1] = ymin;
2301 rmax[1] = ymax;
2302 } else if (i == 2) {
2303 rmin[2] = zmin;
2304 rmax[2] = zmax;
2305 } else {
2306 rmin[i] = 0;
2307 rmax[i] = 0;
2308 }
2309 }
2310}
2311
2312
2313////////////////////////////////////////////////////////////////////////////////
2314/// Return range of a 1-D function.
2315
2317{
2318 xmin = fXmin;
2319 xmax = fXmax;
2320}
2321
2322
2323////////////////////////////////////////////////////////////////////////////////
2324/// Return range of a 2-D function.
2325
2327{
2328 xmin = fXmin;
2329 xmax = fXmax;
2330 ymin = 0;
2331 ymax = 0;
2332}
2333
2334
2335////////////////////////////////////////////////////////////////////////////////
2336/// Return range of function.
2337
2339{
2340 xmin = fXmin;
2341 xmax = fXmax;
2342 ymin = 0;
2343 ymax = 0;
2344 zmin = 0;
2345 zmax = 0;
2346}
2347
2348
2349////////////////////////////////////////////////////////////////////////////////
2350/// Get value corresponding to X in array of fSave values
2351
2353{
2354 if (fSave.size() == 0) return 0;
2355 //if (fSave == 0) return 0;
2356 int fNsave = fSave.size();
2357 Double_t x = Double_t(xx[0]);
2358 Double_t y, dx, xmin, xmax, xlow, xup, ylow, yup;
2360 //if parent is a histogram the function had been saved at the center of the bins
2361 //we make a linear interpolation between the saved values
2362 xmin = fSave[fNsave - 3];
2363 xmax = fSave[fNsave - 2];
2364 if (fSave[fNsave - 1] == xmax) {
2365 TH1 *h = (TH1 *)fParent;
2366 TAxis *xaxis = h->GetXaxis();
2367 Int_t bin1 = xaxis->FindBin(xmin);
2368 Int_t binup = xaxis->FindBin(xmax);
2369 Int_t bin = xaxis->FindBin(x);
2370 if (bin < binup) {
2371 xlow = xaxis->GetBinCenter(bin);
2372 xup = xaxis->GetBinCenter(bin + 1);
2373 ylow = fSave[bin - bin1];
2374 yup = fSave[bin - bin1 + 1];
2375 } else {
2376 xlow = xaxis->GetBinCenter(bin - 1);
2377 xup = xaxis->GetBinCenter(bin);
2378 ylow = fSave[bin - bin1 - 1];
2379 yup = fSave[bin - bin1];
2380 }
2381 dx = xup - xlow;
2382 y = ((xup * ylow - xlow * yup) + x * (yup - ylow)) / dx;
2383 return y;
2384 }
2385 }
2386 Int_t np = fNsave - 3;
2387 xmin = Double_t(fSave[np + 1]);
2388 xmax = Double_t(fSave[np + 2]);
2389 dx = (xmax - xmin) / np;
2390 if (x < xmin || x > xmax) return 0;
2391 // return a Nan in case of x=nan, otherwise will crash later
2392 if (TMath::IsNaN(x)) return x;
2393 if (dx <= 0) return 0;
2394
2395 Int_t bin = Int_t((x - xmin) / dx);
2396 xlow = xmin + bin * dx;
2397 xup = xlow + dx;
2398 ylow = fSave[bin];
2399 yup = fSave[bin + 1];
2400 y = ((xup * ylow - xlow * yup) + x * (yup - ylow)) / dx;
2401 return y;
2402}
2403
2404
2405////////////////////////////////////////////////////////////////////////////////
2406/// Get x axis of the function.
2407
2409{
2410 TH1 *h = GetHistogram();
2411 if (!h) return 0;
2412 return h->GetXaxis();
2413}
2414
2415
2416////////////////////////////////////////////////////////////////////////////////
2417/// Get y axis of the function.
2418
2420{
2421 TH1 *h = GetHistogram();
2422 if (!h) return 0;
2423 return h->GetYaxis();
2424}
2425
2426
2427////////////////////////////////////////////////////////////////////////////////
2428/// Get z axis of the function. (In case this object is a TF2 or TF3)
2429
2431{
2432 TH1 *h = GetHistogram();
2433 if (!h) return 0;
2434 return h->GetZaxis();
2435}
2436
2437
2438
2439////////////////////////////////////////////////////////////////////////////////
2440/// Compute the gradient (derivative) wrt a parameter ipar
2441///
2442/// \param ipar index of parameter for which the derivative is computed
2443/// \param x point, where the derivative is computed
2444/// \param eps - if the errors of parameters have been computed, the step used in
2445/// numerical differentiation is eps*parameter_error.
2446///
2447/// if the errors have not been computed, step=eps is used
2448/// default value of eps = 0.01
2449/// Method is the same as in Derivative() function
2450///
2451/// If a parameter is fixed, the gradient on this parameter = 0
2452
2454{
2455 return GradientParTempl<Double_t>(ipar, x, eps);
2456}
2457
2458////////////////////////////////////////////////////////////////////////////////
2459/// Compute the gradient wrt parameters
2460/// If the TF1 object is based on a formula expression (TFormula)
2461/// and TFormula::GenerateGradientPar() has been successfully called
2462/// automatic differentiation using CLAD is used instead of the default
2463/// numerical differentiation
2464///
2465/// \param x point, were the gradient is computed
2466/// \param grad used to return the computed gradient, assumed to be of at least fNpar size
2467/// \param eps if the errors of parameters have been computed, the step used in
2468/// numerical differentiation is eps*parameter_error.
2469///
2470/// if the errors have not been computed, step=eps is used
2471/// default value of eps = 0.01
2472/// Method is the same as in Derivative() function
2473///
2474/// If a parameter is fixed, the gradient on this parameter = 0
2475
2477{
2478 if (fFormula && fFormula->HasGeneratedGradient())
2479 fFormula->GradientPar(x,grad);
2480 else
2481 GradientParTempl<Double_t>(x, grad, eps);
2482}
2483
2484////////////////////////////////////////////////////////////////////////////////
2485/// Initialize parameters addresses.
2486
2487void TF1::InitArgs(const Double_t *x, const Double_t *params)
2488{
2489 if (fMethodCall) {
2490 Longptr_t args[2];
2491 args[0] = (Longptr_t)x;
2492 if (params) args[1] = (Longptr_t)params;
2493 else args[1] = (Longptr_t)GetParameters();
2494 fMethodCall->SetParamPtrs(args);
2495 }
2496}
2497
2498
2499////////////////////////////////////////////////////////////////////////////////
2500/// Create the basic function objects
2501
2503{
2504 TF1 *f1;
2506 if (!gROOT->GetListOfFunctions()->FindObject("gaus")) {
2507 f1 = new TF1("gaus", "gaus", -1, 1);
2508 f1->SetParameters(1, 0, 1);
2509 f1 = new TF1("gausn", "gausn", -1, 1);
2510 f1->SetParameters(1, 0, 1);
2511 f1 = new TF1("landau", "landau", -1, 1);
2512 f1->SetParameters(1, 0, 1);
2513 f1 = new TF1("landaun", "landaun", -1, 1);
2514 f1->SetParameters(1, 0, 1);
2515 f1 = new TF1("expo", "expo", -1, 1);
2516 f1->SetParameters(1, 1);
2517 for (Int_t i = 0; i < 10; i++) {
2518 f1 = new TF1(Form("pol%d", i), Form("pol%d", i), -1, 1);
2519 f1->SetParameters(1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
2520 // create also chebyshev polynomial
2521 // (note polynomial object will not be deleted)
2522 // note that these functions cannot be stored
2524 Double_t min = -1;
2525 Double_t max = 1;
2526 f1 = new TF1(TString::Format("chebyshev%d", i), pol, min, max, i + 1, 1);
2527 f1->SetParameters(1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
2528 }
2529
2530 }
2531}
2532////////////////////////////////////////////////////////////////////////////////
2533/// IntegralOneDim or analytical integral
2534
2536{
2537 Double_t error = 0;
2538 if (GetNumber() > 0) {
2539 Double_t result = 0.;
2540 if (gDebug) {
2541 Info("computing analytical integral for function %s with number %d", GetName(), GetNumber());
2542 }
2543 result = AnalyticalIntegral(this, a, b);
2544 // if it is a formula that havent been implemented in analytical integral a NaN is return
2545 if (!TMath::IsNaN(result)) return result;
2546 if (gDebug)
2547 Warning("analytical integral not available for %s - with number %d compute numerical integral", GetName(), GetNumber());
2548 }
2549 return IntegralOneDim(a, b, epsrel, epsrel, error);
2550}
2551
2552////////////////////////////////////////////////////////////////////////////////
2553/// Return Integral of function between a and b using the given parameter values and
2554/// relative and absolute tolerance.
2555///
2556/// The default integrator defined in ROOT::Math::IntegratorOneDimOptions::DefaultIntegrator() is used
2557/// If ROOT contains the MathMore library the default integrator is set to be
2558/// the adaptive ROOT::Math::GSLIntegrator (based on QUADPACK) or otherwise the
2559/// ROOT::Math::GaussIntegrator is used
2560/// See the reference documentation of these classes for more information about the
2561/// integration algorithms
2562/// To change integration algorithm just do :
2563/// ROOT::Math::IntegratorOneDimOptions::SetDefaultIntegrator(IntegratorName);
2564/// Valid integrator names are:
2565/// - Gauss : for ROOT::Math::GaussIntegrator
2566/// - GaussLegendre : for ROOT::Math::GaussLegendreIntegrator
2567/// - Adaptive : for ROOT::Math::GSLIntegrator adaptive method (QAG)
2568/// - AdaptiveSingular : for ROOT::Math::GSLIntegrator adaptive singular method (QAGS)
2569/// - NonAdaptive : for ROOT::Math::GSLIntegrator non adaptive (QNG)
2570///
2571/// In order to use the GSL integrators one needs to have the MathMore library installed
2572///
2573/// Note 1:
2574///
2575/// Values of the function f(x) at the interval end-points A and B are not
2576/// required. The subprogram may therefore be used when these values are
2577/// undefined.
2578///
2579/// Note 2:
2580///
2581/// Instead of TF1::Integral, you may want to use the combination of
2582/// TF1::CalcGaussLegendreSamplingPoints and TF1::IntegralFast.
2583/// See an example with the following script:
2584///
2585/// ~~~ {.cpp}
2586/// void gint() {
2587/// TF1 *g = new TF1("g","gaus",-5,5);
2588/// g->SetParameters(1,0,1);
2589/// //default gaus integration method uses 6 points
2590/// //not suitable to integrate on a large domain
2591/// double r1 = g->Integral(0,5);
2592/// double r2 = g->Integral(0,1000);
2593///
2594/// //try with user directives computing more points
2595/// Int_t np = 1000;
2596/// double *x=new double[np];
2597/// double *w=new double[np];
2598/// g->CalcGaussLegendreSamplingPoints(np,x,w,1e-15);
2599/// double r3 = g->IntegralFast(np,x,w,0,5);
2600/// double r4 = g->IntegralFast(np,x,w,0,1000);
2601/// double r5 = g->IntegralFast(np,x,w,0,10000);
2602/// double r6 = g->IntegralFast(np,x,w,0,100000);
2603/// printf("g->Integral(0,5) = %g\n",r1);
2604/// printf("g->Integral(0,1000) = %g\n",r2);
2605/// printf("g->IntegralFast(n,x,w,0,5) = %g\n",r3);
2606/// printf("g->IntegralFast(n,x,w,0,1000) = %g\n",r4);
2607/// printf("g->IntegralFast(n,x,w,0,10000) = %g\n",r5);
2608/// printf("g->IntegralFast(n,x,w,0,100000)= %g\n",r6);
2609/// delete [] x;
2610/// delete [] w;
2611/// }
2612/// ~~~
2613///
2614/// This example produces the following results:
2615///
2616/// ~~~ {.cpp}
2617/// g->Integral(0,5) = 1.25331
2618/// g->Integral(0,1000) = 1.25319
2619/// g->IntegralFast(n,x,w,0,5) = 1.25331
2620/// g->IntegralFast(n,x,w,0,1000) = 1.25331
2621/// g->IntegralFast(n,x,w,0,10000) = 1.25331
2622/// g->IntegralFast(n,x,w,0,100000)= 1.253
2623/// ~~~
2624
2626{
2627 //Double_t *parameters = GetParameters();
2628 TF1_EvalWrapper wf1(this, 0, fgAbsValue);
2629 Double_t result = 0;
2630 Int_t status = 0;
2634 ROOT::Math::GaussIntegrator iod(epsabs, epsrel);
2635 iod.SetFunction(wf1);
2636 if (a != - TMath::Infinity() && b != TMath::Infinity())
2637 result = iod.Integral(a, b);
2638 else if (a == - TMath::Infinity() && b != TMath::Infinity())
2639 result = iod.IntegralLow(b);
2640 else if (a != - TMath::Infinity() && b == TMath::Infinity())
2641 result = iod.IntegralUp(a);
2642 else if (a == - TMath::Infinity() && b == TMath::Infinity())
2643 result = iod.Integral();
2644 error = iod.Error();
2645 status = iod.Status();
2646 } else {
2648 if (a != - TMath::Infinity() && b != TMath::Infinity())
2649 result = iod.Integral(a, b);
2650 else if (a == - TMath::Infinity() && b != TMath::Infinity())
2651 result = iod.IntegralLow(b);
2652 else if (a != - TMath::Infinity() && b == TMath::Infinity())
2653 result = iod.IntegralUp(a);
2654 else if (a == - TMath::Infinity() && b == TMath::Infinity())
2655 result = iod.Integral();
2656 error = iod.Error();
2657 status = iod.Status();
2658 }
2659 if (status != 0) {
2661 Warning("IntegralOneDim", "Error found in integrating function %s in [%f,%f] using %s. Result = %f +/- %f - status = %d", GetName(), a, b, igName.c_str(), result, error, status);
2662 TString msg("\t\tFunction Parameters = {");
2663 for (int ipar = 0; ipar < GetNpar(); ++ipar) {
2664 msg += TString::Format(" %s = %f ", GetParName(ipar), GetParameter(ipar));
2665 if (ipar < GetNpar() - 1) msg += TString(",");
2666 else msg += TString("}");
2667 }
2668 Info("IntegralOneDim", "%s", msg.Data());
2669 }
2670 return result;
2671}
2672
2673////////////////////////////////////////////////////////////////////////////////
2674/// Return Error on Integral of a parametric function between a and b
2675/// due to the parameter uncertainties and their covariance matrix from the fit.
2676/// In addition to the integral limits, this method takes as input a pointer to the fitted parameter values
2677/// and a pointer the covariance matrix from the fit. These pointers should be retrieved from the
2678/// previously performed fit using the TFitResult class.
2679/// Note that to get the TFitResult, te fit should be done using the fit option `S`.
2680/// Example:
2681/// ~~~~{.cpp}
2682/// TFitResultPtr r = histo->Fit(func, "S");
2683/// func->IntegralError(x1,x2,r->GetParams(), r->GetCovarianceMatrix()->GetMatrixArray() );
2684/// ~~~~
2685///
2686/// IMPORTANT NOTE1:
2687///
2688/// A null pointer to the parameter values vector and to the covariance matrix can be passed.
2689/// In this case, when the parameter values pointer is null, the parameter values stored in this
2690/// TF1 function object are used in the integral error computation.
2691/// When the poassed pointer to the covariance matrix is null, a covariance matrix from the last fit is retrieved
2692/// from a global fitter instance when it exists. Note that the global fitter instance
2693/// esists only when ROOT is not running with multi-threading enabled (ROOT::IsImplicitMTEnabled() == True).
2694/// When the ovariance matrix from the last fit cannot be retrieved, an error message is printed and a a zero value is
2695/// returned.
2696///
2697///
2698/// IMPORTANT NOTE2:
2699///
2700/// When no covariance matrix is passed and in the meantime a fit is done
2701/// using another function, the routine will signal an error and it will return zero only
2702/// when the number of fit parameter is different than the values stored in TF1 (TF1::GetNpar() ).
2703/// In the case that npar is the same, an incorrect result is returned.
2704///
2705/// IMPORTANT NOTE3:
2706///
2707/// The user must pass a pointer to the elements of the full covariance matrix
2708/// dimensioned with the right size (npar*npar), where npar is the total number of parameters (TF1::GetNpar()),
2709/// including also the fixed parameters. The covariance matrix must be retrieved from the TFitResult class as
2710/// shown above and not from TVirtualFitter::GetCovarianceMatrix() function.
2711
2713{
2714 Double_t x1[1];
2715 Double_t x2[1];
2716 x1[0] = a, x2[0] = b;
2717 return ROOT::TF1Helper::IntegralError(this, 1, x1, x2, params, covmat, epsilon);
2718}
2719
2720////////////////////////////////////////////////////////////////////////////////
2721/// Return Error on Integral of a parametric function with dimension larger than one
2722/// between a[] and b[] due to the parameters uncertainties.
2723/// For a TF1 with dimension larger than 1 (for example a TF2 or TF3)
2724/// TF1::IntegralMultiple is used for the integral calculation
2725///
2726/// In addition to the integral limits, this method takes as input a pointer to the fitted parameter values
2727/// and a pointer the covariance matrix from the fit. These pointers should be retrieved from the
2728/// previously performed fit using the TFitResult class.
2729/// Note that to get the TFitResult, te fit should be done using the fit option `S`.
2730/// Example:
2731/// ~~~~{.cpp}
2732/// TFitResultPtr r = histo2d->Fit(func2, "S");
2733/// func2->IntegralError(a,b,r->GetParams(), r->GetCovarianceMatrix()->GetMatrixArray() );
2734/// ~~~~
2735///
2736/// IMPORTANT NOTE1:
2737///
2738/// A null pointer to the parameter values vector and to the covariance matrix can be passed.
2739/// In this case, when the parameter values pointer is null, the parameter values stored in this
2740/// TF1 function object are used in the integral error computation.
2741/// When the poassed pointer to the covariance matrix is null, a covariance matrix from the last fit is retrieved
2742/// from a global fitter instance when it exists. Note that the global fitter instance
2743/// esists only when ROOT is not running with multi-threading enabled (ROOT::IsImplicitMTEnabled() == True).
2744/// When the ovariance matrix from the last fit cannot be retrieved, an error message is printed and a a zero value is
2745/// returned.
2746///
2747///
2748/// IMPORTANT NOTE2:
2749///
2750/// When no covariance matrix is passed and in the meantime a fit is done
2751/// using another function, the routine will signal an error and it will return zero only
2752/// when the number of fit parameter is different than the values stored in TF1 (TF1::GetNpar() ).
2753/// In the case that npar is the same, an incorrect result is returned.
2754///
2755/// IMPORTANT NOTE3:
2756///
2757/// The user must pass a pointer to the elements of the full covariance matrix
2758/// dimensioned with the right size (npar*npar), where npar is the total number of parameters (TF1::GetNpar()),
2759/// including also the fixed parameters. The covariance matrix must be retrieved from the TFitResult class as
2760/// shown above and not from TVirtualFitter::GetCovarianceMatrix() function.
2761
2762Double_t TF1::IntegralError(Int_t n, const Double_t *a, const Double_t *b, const Double_t *params, const Double_t *covmat, Double_t epsilon)
2763{
2764 return ROOT::TF1Helper::IntegralError(this, n, a, b, params, covmat, epsilon);
2765}
2766
2767#ifdef INTHEFUTURE
2768////////////////////////////////////////////////////////////////////////////////
2769/// Gauss-Legendre integral, see CalcGaussLegendreSamplingPoints
2770
2772{
2773 if (!g) return 0;
2774 return IntegralFast(g->GetN(), g->GetX(), g->GetY(), a, b, params);
2775}
2776#endif
2777
2778
2779////////////////////////////////////////////////////////////////////////////////
2780/// Gauss-Legendre integral, see CalcGaussLegendreSamplingPoints
2781
2783{
2784 // Now x and w are not used!
2785
2786 ROOT::Math::WrappedTF1 wf1(*this);
2787 if (params)
2788 wf1.SetParameters(params);
2790 gli.SetFunction(wf1);
2791 return gli.Integral(a, b);
2792
2793}
2794
2795
2796////////////////////////////////////////////////////////////////////////////////
2797/// See more general prototype below.
2798/// This interface kept for back compatibility
2799/// It is recommended to use the other interface where one can specify also epsabs and the maximum number of
2800/// points
2801
2803{
2804 Int_t nfnevl, ifail;
2806 Double_t result = IntegralMultiple(n, a, b, maxpts, epsrel, epsrel, relerr, nfnevl, ifail);
2807 if (ifail > 0) {
2808 Warning("IntegralMultiple", "failed code=%d, ", ifail);
2809 }
2810 return result;
2811}
2812
2813
2814////////////////////////////////////////////////////////////////////////////////
2815/// This function computes, to an attempted specified accuracy, the value of
2816/// the integral
2817///
2818/// \param[in] n Number of dimensions [2,15]
2819/// \param[in] a,b One-dimensional arrays of length >= N . On entry A[i], and B[i],
2820/// contain the lower and upper limits of integration, respectively.
2821/// \param[in] maxpts Maximum number of function evaluations to be allowed.
2822/// maxpts >= 2^n +2*n*(n+1) +1
2823/// if maxpts<minpts, maxpts is set to 10*minpts
2824/// \param[in] epsrel Specified relative accuracy.
2825/// \param[in] epsabs Specified absolute accuracy.
2826/// The integration algorithm will attempt to reach either the relative or the absolute accuracy.
2827/// In case the maximum function called is reached the algorithm will stop earlier without having reached
2828/// the desired accuracy
2829///
2830/// \param[out] relerr Contains, on exit, an estimation of the relative accuracy of the result.
2831/// \param[out] nfnevl number of function evaluations performed.
2832/// \param[out] ifail
2833/// \parblock
2834/// 0 Normal exit. At least minpts and at most maxpts calls to the function were performed.
2835///
2836/// 1 maxpts is too small for the specified accuracy eps. The result and relerr contain the values obtainable for the
2837/// specified value of maxpts.
2838///
2839/// 3 n<2 or n>15
2840/// \endparblock
2841///
2842/// Method:
2843///
2844/// The default method used is the Genz-Mallik adaptive multidimensional algorithm
2845/// using the class ROOT::Math::AdaptiveIntegratorMultiDim (see the reference documentation of the class)
2846///
2847/// Other methods can be used by setting ROOT::Math::IntegratorMultiDimOptions::SetDefaultIntegrator()
2848/// to different integrators.
2849/// Other possible integrators are MC integrators based on the ROOT::Math::GSLMCIntegrator class
2850/// Possible methods are : Vegas, Miser or Plain
2851/// IN case of MC integration the accuracy is determined by the number of function calls, one should be
2852/// careful not to use a too large value of maxpts
2853///
2854
2855Double_t TF1::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)
2856{
2858
2859 double result = 0;
2863 ROOT::Math::AdaptiveIntegratorMultiDim aimd(wf1, epsabs, epsrel, maxpts);
2864 //aimd.SetMinPts(minpts); // use default minpts ( n^2 + 2 * n * (n+1) +1 )
2865 result = aimd.Integral(a, b);
2866 relerr = aimd.RelError();
2867 nfnevl = aimd.NEval();
2868 ifail = aimd.Status();
2869 } else {
2870 // use default abs tolerance = relative tolerance
2872 result = imd.Integral(a, b);
2873 relerr = (result != 0) ? imd.Error() / std::abs(result) : imd.Error();
2874 nfnevl = 0;
2875 ifail = imd.Status();
2876 }
2877
2878
2879 return result;
2880}
2881
2882
2883////////////////////////////////////////////////////////////////////////////////
2884/// Return kTRUE if the function is valid
2885
2887{
2888 if (fFormula) return fFormula->IsValid();
2889 if (fMethodCall) return fMethodCall->IsValid();
2890 // function built on compiled functors are always valid by definition
2891 // (checked at compiled time)
2892 // invalid is a TF1 where the functor is null pointer and has not been saved
2893 if (!fFunctor && fSave.empty()) return kFALSE;
2894 return kTRUE;
2895}
2896
2897
2898//______________________________________________________________________________
2899
2900
2901void TF1::Print(Option_t *option) const
2902{
2903 if (fType == EFType::kFormula) {
2904 printf("Formula based function: %s \n", GetName());
2905 assert(fFormula);
2906 fFormula->Print(option);
2907 } else if (fType > 0) {
2908 if (fType == EFType::kInterpreted)
2909 printf("Interpreted based function: %s(double *x, double *p). Ndim = %d, Npar = %d \n", GetName(), GetNdim(),
2910 GetNpar());
2911 else if (fType == EFType::kCompositionFcn) {
2912 printf("Composition based function: %s. Ndim = %d, Npar = %d \n", GetName(), GetNdim(), GetNpar());
2913 if (!fComposition)
2914 printf("fComposition not found!\n"); // this would be bad
2915 } else {
2916 if (fFunctor)
2917 printf("Compiled based function: %s based on a functor object. Ndim = %d, Npar = %d\n", GetName(),
2918 GetNdim(), GetNpar());
2919 else {
2920 printf("Function based on a list of points from a compiled based function: %s. Ndim = %d, Npar = %d, Npx "
2921 "= %zu\n",
2922 GetName(), GetNdim(), GetNpar(), fSave.size());
2923 if (fSave.empty())
2924 Warning("Print", "Function %s is based on a list of points but list is empty", GetName());
2925 }
2926 }
2927 TString opt(option);
2928 opt.ToUpper();
2929 if (opt.Contains("V")) {
2930 // print list of parameters
2931 if (fNpar > 0) {
2932 printf("List of Parameters: \n");
2933 for (int i = 0; i < fNpar; ++i)
2934 printf(" %20s = %10f \n", GetParName(i), GetParameter(i));
2935 }
2936 if (!fSave.empty()) {
2937 // print list of saved points
2938 printf("List of Saved points (N=%d): \n", int(fSave.size()));
2939 for (auto &x : fSave)
2940 printf("( %10f ) ", x);
2941 printf("\n");
2942 }
2943 }
2944 }
2945 if (fHistogram) {
2946 printf("Contained histogram\n");
2947 fHistogram->Print(option);
2948 }
2949}
2950
2951////////////////////////////////////////////////////////////////////////////////
2952/// Paint this function with its current attributes.
2953/// The function is going to be converted in an histogram and the corresponding
2954/// histogram is painted.
2955/// The painted histogram can be retrieved calling afterwards the method TF1::GetHistogram()
2956
2957void TF1::Paint(Option_t *choptin)
2958{
2959 fgCurrent = this;
2960
2961 char option[32];
2962 strlcpy(option,choptin,32);
2963
2964 TString opt = option;
2965 opt.ToLower();
2966
2967 Bool_t optSAME = kFALSE;
2968 if (opt.Contains("same")) {
2969 opt.ReplaceAll("same","");
2970 optSAME = kTRUE;
2971 }
2972 opt.ReplaceAll(' ', "");
2973
2974 Double_t xmin = fXmin, xmax = fXmax, pmin = fXmin, pmax = fXmax;
2975 if (gPad) {
2976 pmin = gPad->PadtoX(gPad->GetUxmin());
2977 pmax = gPad->PadtoX(gPad->GetUxmax());
2978 }
2979 if (optSAME) {
2980 if (xmax < pmin) return; // Completely outside.
2981 if (xmin > pmax) return;
2982 if (xmin < pmin) xmin = pmin;
2983 if (xmax > pmax) xmax = pmax;
2984 }
2985
2986 // create an histogram using the function content (re-use it if already existing)
2988
2989 char *l1 = strstr(option,"PFC"); // Automatic Fill Color
2990 char *l2 = strstr(option,"PLC"); // Automatic Line Color
2991 char *l3 = strstr(option,"PMC"); // Automatic Marker Color
2992 if (l1 || l2 || l3) {
2993 Int_t i = gPad->NextPaletteColor();
2994 if (l1) {memcpy(l1," ",3); fHistogram->SetFillColor(i);}
2995 if (l2) {memcpy(l2," ",3); fHistogram->SetLineColor(i);}
2996 if (l3) {memcpy(l3," ",3); fHistogram->SetMarkerColor(i);}
2997 }
2998
2999 // set the optimal minimum and maximum
3002 if (minimum <= 0 && gPad && gPad->GetLogy()) minimum = -1111; // This can happen when switching from lin to log scale.
3003 if (gPad && gPad->GetUymin() < fHistogram->GetMinimum() &&
3004 !fHistogram->TestBit(TH1::kIsZoomed)) minimum = -1111; // This can happen after unzooming a fit.
3005 if (minimum == -1111) { // This can happen after unzooming.
3007 minimum = fHistogram->GetYaxis()->GetXmin();
3008 } else {
3009 minimum = fMinimum;
3010 // Optimize the computation of the scale in Y in case the min/max of the
3011 // function oscillate around a constant value
3012 if (minimum == -1111) {
3013 Double_t hmin;
3014 if (optSAME && gPad) hmin = gPad->GetUymin();
3015 else hmin = fHistogram->GetMinimum();
3016 if (hmin > 0) {
3017 Double_t hmax;
3018 Double_t hminpos = hmin;
3019 if (optSAME && gPad) hmax = gPad->GetUymax();
3020 else hmax = fHistogram->GetMaximum();
3021 hmin -= 0.05 * (hmax - hmin);
3022 if (hmin < 0) hmin = 0;
3023 if (hmin <= 0 && gPad && gPad->GetLogy()) hmin = hminpos;
3024 minimum = hmin;
3025 }
3026 }
3027 }
3028 fHistogram->SetMinimum(minimum);
3029 }
3030 if (maximum == -1111) {
3032 maximum = fHistogram->GetYaxis()->GetXmax();
3033 } else {
3034 maximum = fMaximum;
3035 }
3036 fHistogram->SetMaximum(maximum);
3037 }
3038
3039
3040 // Draw the histogram.
3041 if (!gPad) return;
3042 if (opt.Length() == 0) {
3043 if (optSAME) fHistogram->Paint("lfsame");
3044 else fHistogram->Paint("lf");
3045 } else {
3046 fHistogram->Paint(option);
3047 }
3048}
3049
3050////////////////////////////////////////////////////////////////////////////////
3051/// Create histogram with bin content equal to function value
3052/// computed at the bin center
3053/// This histogram will be used to paint the function
3054/// A re-creation is forced and a new histogram is done if recreate=true
3055
3057{
3058 Int_t i;
3059 Double_t xv[1];
3060
3061 TH1 *histogram = 0;
3062
3063
3064 // Create a temporary histogram and fill each channel with the function value
3065 // Preserve axis titles
3066 TString xtitle = "";
3067 TString ytitle = "";
3068 char *semicol = (char *)strstr(GetTitle(), ";");
3069 if (semicol) {
3070 Int_t nxt = strlen(semicol);
3071 char *ctemp = new char[nxt];
3072 strlcpy(ctemp, semicol + 1, nxt);
3073 semicol = (char *)strstr(ctemp, ";");
3074 if (semicol) {
3075 *semicol = 0;
3076 ytitle = semicol + 1;
3077 }
3078 xtitle = ctemp;
3079 delete [] ctemp;
3080 }
3081 if (fHistogram) {
3082 // delete previous histograms if were done if done in different mode
3083 xtitle = fHistogram->GetXaxis()->GetTitle();
3084 ytitle = fHistogram->GetYaxis()->GetTitle();
3085 Bool_t test_logx = fHistogram->TestBit(TH1::kLogX);
3086 if (!gPad->GetLogx() && test_logx) {
3087 delete fHistogram;
3088 fHistogram = nullptr;
3089 recreate = kTRUE;
3090 }
3091 if (gPad->GetLogx() && !test_logx) {
3092 delete fHistogram;
3093 fHistogram = nullptr;
3094 recreate = kTRUE;
3095 }
3096 }
3097
3098 if (fHistogram && !recreate) {
3099 histogram = fHistogram;
3101 } else {
3102 // If logx, we must bin in logx and not in x
3103 // otherwise in case of several decades, one gets wrong results.
3104 if (xmin > 0 && gPad && gPad->GetLogx()) {
3105 Double_t *xbins = new Double_t[fNpx + 1];
3106 Double_t xlogmin = TMath::Log10(xmin);
3107 Double_t xlogmax = TMath::Log10(xmax);
3108 Double_t dlogx = (xlogmax - xlogmin) / ((Double_t)fNpx);
3109 for (i = 0; i <= fNpx; i++) {
3110 xbins[i] = gPad->PadtoX(xlogmin + i * dlogx);
3111 }
3112 histogram = new TH1D("Func", GetTitle(), fNpx, xbins);
3113 histogram->SetBit(TH1::kLogX);
3114 delete [] xbins;
3115 } else {
3116 histogram = new TH1D("Func", GetTitle(), fNpx, xmin, xmax);
3117 }
3118 if (fMinimum != -1111) histogram->SetMinimum(fMinimum);
3119 if (fMaximum != -1111) histogram->SetMaximum(fMaximum);
3120 histogram->SetDirectory(0);
3121 }
3122 R__ASSERT(histogram);
3123
3124 // Restore axis titles.
3125 histogram->GetXaxis()->SetTitle(xtitle.Data());
3126 histogram->GetYaxis()->SetTitle(ytitle.Data());
3127 Double_t *parameters = GetParameters();
3128
3129 InitArgs(xv, parameters);
3130 for (i = 1; i <= fNpx; i++) {
3131 xv[0] = histogram->GetBinCenter(i);
3132 histogram->SetBinContent(i, EvalPar(xv, parameters));
3133 }
3134
3135 // Copy Function attributes to histogram attributes.
3136 histogram->SetBit(TH1::kNoStats);
3137 histogram->SetLineColor(GetLineColor());
3138 histogram->SetLineStyle(GetLineStyle());
3139 histogram->SetLineWidth(GetLineWidth());
3140 histogram->SetFillColor(GetFillColor());
3141 histogram->SetFillStyle(GetFillStyle());
3142 histogram->SetMarkerColor(GetMarkerColor());
3143 histogram->SetMarkerStyle(GetMarkerStyle());
3144 histogram->SetMarkerSize(GetMarkerSize());
3145
3146 // update saved histogram in case it was deleted or if it is the first time the method is called
3147 // for example when called from TF1::GetHistogram()
3148 if (!fHistogram) fHistogram = histogram;
3149 return histogram;
3150
3151}
3152
3153
3154////////////////////////////////////////////////////////////////////////////////
3155/// Release parameter number ipar If used in a fit, the parameter
3156/// can vary freely. The parameter limits are reset to 0,0.
3157
3159{
3160 if (ipar < 0 || ipar > GetNpar() - 1) return;
3161 SetParLimits(ipar, 0, 0);
3162}
3163
3164
3165////////////////////////////////////////////////////////////////////////////////
3166/// Save values of function in array fSave
3167
3169{
3170 Double_t *parameters = GetParameters();
3171 //if (fSave != 0) {delete [] fSave; fSave = 0;}
3173 //if parent is a histogram save the function at the center of the bins
3174 if ((xmin > 0 && xmax > 0) && TMath::Abs(TMath::Log10(xmax / xmin) > TMath::Log10(fNpx))) {
3175 TH1 *h = (TH1 *)fParent;
3176 Int_t bin1 = h->GetXaxis()->FindBin(xmin);
3177 Int_t bin2 = h->GetXaxis()->FindBin(xmax);
3178 int fNsave = bin2 - bin1 + 4;
3179 //fSave = new Double_t[fNsave];
3180 fSave.resize(fNsave);
3181 Double_t xv[1];
3182
3183 InitArgs(xv, parameters);
3184 for (Int_t i = bin1; i <= bin2; i++) {
3185 xv[0] = h->GetXaxis()->GetBinCenter(i);
3186 fSave[i - bin1] = EvalPar(xv, parameters);
3187 }
3188 fSave[fNsave - 3] = xmin;
3189 fSave[fNsave - 2] = xmax;
3190 fSave[fNsave - 1] = xmax;
3191 return;
3192 }
3193 }
3194 int fNsave = fNpx + 3;
3195 if (fNsave <= 3) {
3196 return;
3197 }
3198 //fSave = new Double_t[fNsave];
3199 fSave.resize(fNsave);
3200 Double_t dx = (xmax - xmin) / fNpx;
3201 if (dx <= 0) {
3202 dx = (fXmax - fXmin) / fNpx;
3203 fNsave--;
3204 xmin = fXmin + 0.5 * dx;
3205 xmax = fXmax - 0.5 * dx;
3206 }
3207 Double_t xv[1];
3208 InitArgs(xv, parameters);
3209 for (Int_t i = 0; i <= fNpx; i++) {
3210 xv[0] = xmin + dx * i;
3211 fSave[i] = EvalPar(xv, parameters);
3212 }
3213 fSave[fNpx + 1] = xmin;
3214 fSave[fNpx + 2] = xmax;
3215}
3216
3217
3218////////////////////////////////////////////////////////////////////////////////
3219/// Save primitive as a C++ statement(s) on output stream out
3220
3221void TF1::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
3222{
3223 Int_t i;
3224 char quote = '"';
3225
3226 // Save the function as C code independant from ROOT.
3227 if (strstr(option, "cc")) {
3228 out << "double " << GetName() << "(double xv) {" << std::endl;
3229 Double_t dx = (fXmax - fXmin) / (fNpx - 1);
3230 out << " double x[" << fNpx << "] = {" << std::endl;
3231 out << " ";
3232 Int_t n = 0;
3233 for (i = 0; i < fNpx; i++) {
3234 out << fXmin + dx *i ;
3235 if (i < fNpx - 1) out << ", ";
3236 if (n++ == 10) {
3237 out << std::endl;
3238 out << " ";
3239 n = 0;
3240 }
3241 }
3242 out << std::endl;
3243 out << " };" << std::endl;
3244 out << " double y[" << fNpx << "] = {" << std::endl;
3245 out << " ";
3246 n = 0;
3247 for (i = 0; i < fNpx; i++) {
3248 out << Eval(fXmin + dx * i);
3249 if (i < fNpx - 1) out << ", ";
3250 if (n++ == 10) {
3251 out << std::endl;
3252 out << " ";
3253 n = 0;
3254 }
3255 }
3256 out << std::endl;
3257 out << " };" << std::endl;
3258 out << " if (xv<x[0]) return y[0];" << std::endl;
3259 out << " if (xv>x[" << fNpx - 1 << "]) return y[" << fNpx - 1 << "];" << std::endl;
3260 out << " int i, j=0;" << std::endl;
3261 out << " for (i=1; i<" << fNpx << "; i++) { if (xv < x[i]) break; j++; }" << std::endl;
3262 out << " return y[j] + (y[j + 1] - y[j]) / (x[j + 1] - x[j]) * (xv - x[j]);" << std::endl;
3263 out << "}" << std::endl;
3264 return;
3265 }
3266
3267 out << " " << std::endl;
3268
3269 // Either f1Number is computed locally or set from outside
3270 static Int_t f1Number = 0;
3271 TString f1Name(GetName());
3272 const char *l = strstr(option, "#");
3273 if (l != 0) {
3274 sscanf(&l[1], "%d", &f1Number);
3275 } else {
3276 ++f1Number;
3277 }
3278 f1Name += f1Number;
3279
3280 const char *addToGlobList = fParent ? ", TF1::EAddToList::kNo" : ", TF1::EAddToList::kDefault";
3281
3282 if (!fType) {
3283 out << " TF1 *" << f1Name.Data() << " = new TF1(" << quote << GetName() << quote << "," << quote << GetTitle() << quote << "," << fXmin << "," << fXmax << addToGlobList << ");" << std::endl;
3284 if (fNpx != 100) {
3285 out << " " << f1Name.Data() << "->SetNpx(" << fNpx << ");" << std::endl;
3286 }
3287 } else {
3288 out << " TF1 *" << f1Name.Data() << " = new TF1(" << quote << "*" << GetName() << quote << "," << fXmin << "," << fXmax << "," << GetNpar() << ");" << std::endl;
3289 out << " //The original function : " << GetTitle() << " had originally been created by:" << std::endl;
3290 out << " //TF1 *" << GetName() << " = new TF1(" << quote << GetName() << quote << "," << GetTitle() << "," << fXmin << "," << fXmax << "," << GetNpar();
3291 out << ", 1" << addToGlobList << ");" << std::endl;
3292 out << " " << f1Name.Data() << "->SetRange(" << fXmin << "," << fXmax << ");" << std::endl;
3293 out << " " << f1Name.Data() << "->SetName(" << quote << GetName() << quote << ");" << std::endl;
3294 out << " " << f1Name.Data() << "->SetTitle(" << quote << GetTitle() << quote << ");" << std::endl;
3295 if (fNpx != 100) {
3296 out << " " << f1Name.Data() << "->SetNpx(" << fNpx << ");" << std::endl;
3297 }
3298 Double_t dx = (fXmax - fXmin) / fNpx;
3299 Double_t xv[1];
3300 Double_t *parameters = GetParameters();
3301 InitArgs(xv, parameters);
3302 for (i = 0; i <= fNpx; i++) {
3303 xv[0] = fXmin + dx * i;
3304 Double_t save = EvalPar(xv, parameters);
3305 out << " " << f1Name.Data() << "->SetSavedPoint(" << i << "," << save << ");" << std::endl;
3306 }
3307 out << " " << f1Name.Data() << "->SetSavedPoint(" << fNpx + 1 << "," << fXmin << ");" << std::endl;
3308 out << " " << f1Name.Data() << "->SetSavedPoint(" << fNpx + 2 << "," << fXmax << ");" << std::endl;
3309 }
3310
3311 if (TestBit(kNotDraw)) {
3312 out << " " << f1Name.Data() << "->SetBit(TF1::kNotDraw);" << std::endl;
3313 }
3314 if (GetFillColor() != 0) {
3315 if (GetFillColor() > 228) {
3317 out << " " << f1Name.Data() << "->SetFillColor(ci);" << std::endl;
3318 } else
3319 out << " " << f1Name.Data() << "->SetFillColor(" << GetFillColor() << ");" << std::endl;
3320 }
3321 if (GetFillStyle() != 1001) {
3322 out << " " << f1Name.Data() << "->SetFillStyle(" << GetFillStyle() << ");" << std::endl;
3323 }
3324 if (GetMarkerColor() != 1) {
3325 if (GetMarkerColor() > 228) {
3327 out << " " << f1Name.Data() << "->SetMarkerColor(ci);" << std::endl;
3328 } else
3329 out << " " << f1Name.Data() << "->SetMarkerColor(" << GetMarkerColor() << ");" << std::endl;
3330 }
3331 if (GetMarkerStyle() != 1) {
3332 out << " " << f1Name.Data() << "->SetMarkerStyle(" << GetMarkerStyle() << ");" << std::endl;
3333 }
3334 if (GetMarkerSize() != 1) {
3335 out << " " << f1Name.Data() << "->SetMarkerSize(" << GetMarkerSize() << ");" << std::endl;
3336 }
3337 if (GetLineColor() != 1) {
3338 if (GetLineColor() > 228) {
3340 out << " " << f1Name.Data() << "->SetLineColor(ci);" << std::endl;
3341 } else
3342 out << " " << f1Name.Data() << "->SetLineColor(" << GetLineColor() << ");" << std::endl;
3343 }
3344 if (GetLineWidth() != 4) {
3345 out << " " << f1Name.Data() << "->SetLineWidth(" << GetLineWidth() << ");" << std::endl;
3346 }
3347 if (GetLineStyle() != 1) {
3348 out << " " << f1Name.Data() << "->SetLineStyle(" << GetLineStyle() << ");" << std::endl;
3349 }
3350 if (GetChisquare() != 0) {
3351 out << " " << f1Name.Data() << "->SetChisquare(" << GetChisquare() << ");" << std::endl;
3352 out << " " << f1Name.Data() << "->SetNDF(" << GetNDF() << ");" << std::endl;
3353 }
3354
3355 if (GetXaxis()) GetXaxis()->SaveAttributes(out, f1Name.Data(), "->GetXaxis()");
3356 if (GetYaxis()) GetYaxis()->SaveAttributes(out, f1Name.Data(), "->GetYaxis()");
3357
3358 Double_t parmin, parmax;
3359 for (i = 0; i < GetNpar(); i++) {
3360 out << " " << f1Name.Data() << "->SetParameter(" << i << "," << GetParameter(i) << ");" << std::endl;
3361 out << " " << f1Name.Data() << "->SetParError(" << i << "," << GetParError(i) << ");" << std::endl;
3362 GetParLimits(i, parmin, parmax);
3363 out << " " << f1Name.Data() << "->SetParLimits(" << i << "," << parmin << "," << parmax << ");" << std::endl;
3364 }
3365 if (!strstr(option, "nodraw")) {
3366 out << " " << f1Name.Data() << "->Draw("
3367 << quote << option << quote << ");" << std::endl;
3368 }
3369}
3370
3371
3372////////////////////////////////////////////////////////////////////////////////
3373/// Static function setting the current function.
3374/// the current function may be accessed in static C-like functions
3375/// when fitting or painting a function.
3376
3378{
3379 fgCurrent = f1;
3380}
3381
3382////////////////////////////////////////////////////////////////////////////////
3383/// Set the result from the fit
3384/// parameter values, errors, chi2, etc...
3385/// Optionally a pointer to a vector (with size fNpar) of the parameter indices in the FitResult can be passed
3386/// This is useful in the case of a combined fit with different functions, and the FitResult contains the global result
3387/// By default it is assume that indpar = {0,1,2,....,fNpar-1}.
3388
3389void TF1::SetFitResult(const ROOT::Fit::FitResult &result, const Int_t *indpar)
3390{
3391 Int_t npar = GetNpar();
3392 if (result.IsEmpty()) {
3393 Warning("SetFitResult", "Empty Fit result - nothing is set in TF1");
3394 return;
3395 }
3396 if (indpar == 0 && npar != (int) result.NPar()) {
3397 Error("SetFitResult", "Invalid Fit result passed - number of parameter is %d , different than TF1::GetNpar() = %d", npar, result.NPar());
3398 return;
3399 }
3400 if (result.Chi2() > 0)
3401 SetChisquare(result.Chi2());
3402 else
3403 SetChisquare(result.MinFcnValue());
3404
3405 SetNDF(result.Ndf());
3406 SetNumberFitPoints(result.Ndf() + result.NFreeParameters());
3407
3408
3409 for (Int_t i = 0; i < npar; ++i) {
3410 Int_t ipar = (indpar != 0) ? indpar[i] : i;
3411 if (ipar < 0) continue;
3412 GetParameters()[i] = result.Parameter(ipar);
3413 // in case errors are not present do not set them
3414 if (ipar < (int) result.Errors().size())
3415 fParErrors[i] = result.Error(ipar);
3416 }
3417 //invalidate cached integral since parameters have changed
3418 Update();
3419
3420}
3421
3422
3423////////////////////////////////////////////////////////////////////////////////
3424/// Set the maximum value along Y for this function
3425/// In case the function is already drawn, set also the maximum in the
3426/// helper histogram
3427
3429{
3430 fMaximum = maximum;
3431 if (fHistogram) fHistogram->SetMaximum(maximum);
3432 if (gPad) gPad->Modified();
3433}
3434
3435
3436////////////////////////////////////////////////////////////////////////////////
3437/// Set the minimum value along Y for this function
3438/// In case the function is already drawn, set also the minimum in the
3439/// helper histogram
3440
3442{
3443 fMinimum = minimum;
3444 if (fHistogram) fHistogram->SetMinimum(minimum);
3445 if (gPad) gPad->Modified();
3446}
3447
3448
3449////////////////////////////////////////////////////////////////////////////////
3450/// Set the number of degrees of freedom
3451/// ndf should be the number of points used in a fit - the number of free parameters
3452
3454{
3455 fNDF = ndf;
3456}
3457
3458
3459////////////////////////////////////////////////////////////////////////////////
3460/// Set the number of points used to draw the function
3461///
3462/// The default number of points along x is 100 for 1-d functions and 30 for 2-d/3-d functions
3463/// You can increase this value to get a better resolution when drawing
3464/// pictures with sharp peaks or to get a better result when using TF1::GetRandom
3465/// the minimum number of points is 4, the maximum is 10000000 for 1-d and 10000 for 2-d/3-d functions
3466
3468{
3469 const Int_t minPx = 4;
3470 Int_t maxPx = 10000000;
3471 if (GetNdim() > 1) maxPx = 10000;
3472 if (npx >= minPx && npx <= maxPx) {
3473 fNpx = npx;
3474 } else {
3475 if (npx < minPx) fNpx = minPx;
3476 if (npx > maxPx) fNpx = maxPx;
3477 Warning("SetNpx", "Number of points must be >=%d && <= %d, fNpx set to %d", minPx, maxPx, fNpx);
3478 }
3479 Update();
3480}
3481////////////////////////////////////////////////////////////////////////////////
3482/// Set name of parameter number ipar
3483
3484void TF1::SetParName(Int_t ipar, const char *name)
3485{
3486 if (fFormula) {
3487 if (ipar < 0 || ipar >= GetNpar()) return;
3488 fFormula->SetParName(ipar, name);
3489 } else
3490 fParams->SetParName(ipar, name);
3491}
3492
3493////////////////////////////////////////////////////////////////////////////////
3494/// Set up to 10 parameter names
3495
3496void TF1::SetParNames(const char *name0, const char *name1, const char *name2, const char *name3, const char *name4,
3497 const char *name5, const char *name6, const char *name7, const char *name8, const char *name9, const char *name10)
3498{
3499 if (fFormula)
3500 fFormula->SetParNames(name0, name1, name2, name3, name4, name5, name6, name7, name8, name9, name10);
3501 else
3502 fParams->SetParNames(name0, name1, name2, name3, name4, name5, name6, name7, name8, name9, name10);
3503}
3504////////////////////////////////////////////////////////////////////////////////
3505/// Set error for parameter number ipar
3506
3508{
3509 if (ipar < 0 || ipar > GetNpar() - 1) return;
3510 fParErrors[ipar] = error;
3511}
3512
3513
3514////////////////////////////////////////////////////////////////////////////////
3515/// Set errors for all active parameters
3516/// when calling this function, the array errors must have at least fNpar values
3517
3518void TF1::SetParErrors(const Double_t *errors)
3519{
3520 if (!errors) return;
3521 for (Int_t i = 0; i < GetNpar(); i++) fParErrors[i] = errors[i];
3522}
3523
3524
3525////////////////////////////////////////////////////////////////////////////////
3526/// Set limits for parameter ipar.
3527///
3528/// The specified limits will be used in a fit operation
3529/// when the option "B" is specified (Bounds).
3530/// To fix a parameter, use TF1::FixParameter
3531
3532void TF1::SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
3533{
3534 Int_t npar = GetNpar();
3535 if (ipar < 0 || ipar > npar - 1) return;
3536 if (int(fParMin.size()) != npar) {
3537 fParMin.resize(npar);
3538 }
3539 if (int(fParMax.size()) != npar) {
3540 fParMax.resize(npar);
3541 }
3542 fParMin[ipar] = parmin;
3543 fParMax[ipar] = parmax;
3544}
3545
3546
3547////////////////////////////////////////////////////////////////////////////////
3548/// Initialize the upper and lower bounds to draw the function.
3549///
3550/// The function range is also used in an histogram fit operation
3551/// when the option "R" is specified.
3552
3554{
3555 fXmin = xmin;
3556 fXmax = xmax;
3557 if (fType == EFType::kCompositionFcn && fComposition) {
3558 fComposition->SetRange(xmin, xmax); // automatically updates sub-functions
3559 }
3560 Update();
3561}
3562
3563
3564////////////////////////////////////////////////////////////////////////////////
3565/// Restore value of function saved at point
3566
3568{
3569 if (fSave.size() == 0) {
3570 fSave.resize(fNpx + 3);
3571 }
3572 if (point < 0 || point >= int(fSave.size())) return;
3573 fSave[point] = value;
3574}
3575
3576
3577////////////////////////////////////////////////////////////////////////////////
3578/// Set function title
3579/// if title has the form "fffffff;xxxx;yyyy", it is assumed that
3580/// the function title is "fffffff" and "xxxx" and "yyyy" are the
3581/// titles for the X and Y axis respectively.
3582
3583void TF1::SetTitle(const char *title)
3584{
3585 if (!title) return;
3586 fTitle = title;
3587 if (!fHistogram) return;
3588 fHistogram->SetTitle(title);
3589 if (gPad) gPad->Modified();
3590}
3591
3592
3593////////////////////////////////////////////////////////////////////////////////
3594/// Stream a class object.
3595
3596void TF1::Streamer(TBuffer &b)
3597{
3598 if (b.IsReading()) {
3599 UInt_t R__s, R__c;
3600 Version_t v = b.ReadVersion(&R__s, &R__c);
3601 // process new version with new TFormula class which is contained in TF1
3602 //printf("reading TF1....- version %d..\n",v);
3603
3604 if (v > 7) {
3605 // new classes with new TFormula
3606 // need to register the objects
3607 b.ReadClassBuffer(TF1::Class(), this, v, R__s, R__c);
3608 if (!TestBit(kNotGlobal)) {
3610 gROOT->GetListOfFunctions()->Add(this);
3611 }
3612 return;
3613 } else {
3614 ROOT::v5::TF1Data fold;
3615 //printf("Reading TF1 as v5::TF1Data- version %d \n",v);
3616 fold.Streamer(b, v, R__s, R__c, TF1::Class());
3617 // convert old TF1 to new one
3618 ((TF1v5Convert *)this)->Convert(fold);
3619 }
3620 }
3621
3622 // Writing
3623 else {
3624 Int_t saved = 0;
3625 // save not-formula functions as array of points
3626 if (fType > 0 && fSave.empty() && fType != EFType::kCompositionFcn) {
3627 saved = 1;
3628 Save(fXmin, fXmax, 0, 0, 0, 0);
3629 }
3630 b.WriteClassBuffer(TF1::Class(), this);
3631
3632 // clear vector contents
3633 if (saved) {
3634 fSave.clear();
3635 }
3636 }
3637}
3638
3639
3640////////////////////////////////////////////////////////////////////////////////
3641/// Called by functions such as SetRange, SetNpx, SetParameters
3642/// to force the deletion of the associated histogram or Integral
3643
3645{
3646 delete fHistogram;
3647 fHistogram = 0;
3648 if (!fIntegral.empty()) {
3649 fIntegral.clear();
3650 fAlpha.clear();
3651 fBeta.clear();
3652 fGamma.clear();
3653 }
3654 if (fNormalized) {
3655 // need to compute the integral of the not-normalized function
3656 fNormalized = false;
3658 fNormalized = true;
3659 } else
3660 fNormIntegral = 0;
3661
3662 // std::vector<double>x(fNdim);
3663 // if ((fType == 1) && !fFunctor->Empty()) (*fFunctor)x.data(), (Double_t*)fParams);
3664 if (fType == EFType::kCompositionFcn && fComposition) {
3665 // double-check that the parameters are correct
3666 fComposition->SetParameters(GetParameters());
3667
3668 fComposition->Update(); // should not be necessary, but just to be safe
3669 }
3670}
3671
3672////////////////////////////////////////////////////////////////////////////////
3673/// Static function to set the global flag to reject points
3674/// the fgRejectPoint global flag is tested by all fit functions
3675/// if TRUE the point is not included in the fit.
3676/// This flag can be set by a user in a fitting function.
3677/// The fgRejectPoint flag is reset by the TH1 and TGraph fitting functions.
3678
3680{
3681 fgRejectPoint = reject;
3682}
3683
3684
3685////////////////////////////////////////////////////////////////////////////////
3686/// See TF1::RejectPoint above
3687
3689{
3690 return fgRejectPoint;
3691}
3692
3693////////////////////////////////////////////////////////////////////////////////
3694/// Return nth moment of function between a and b
3695///
3696/// See TF1::Integral() for parameter definitions
3697
3699{
3700 // wrapped function in interface for integral calculation
3701 // using abs value of integral
3702
3703 TF1_EvalWrapper func(this, params, kTRUE, n);
3704
3706
3707 giod.SetFunction(func);
3709
3710 Double_t norm = giod.Integral(a, b);
3711 if (norm == 0) {
3712 Error("Moment", "Integral zero over range");
3713 return 0;
3714 }
3715
3716 // calculate now integral of x^n f(x)
3717 // wrapped the member function EvalNum in interface required by integrator using the functor class
3719 giod.SetFunction(xnfunc);
3720
3721 Double_t res = giod.Integral(a, b) / norm;
3722
3723 return res;
3724}
3725
3726
3727////////////////////////////////////////////////////////////////////////////////
3728/// Return nth central moment of function between a and b
3729/// (i.e the n-th moment around the mean value)
3730///
3731/// See TF1::Integral() for parameter definitions
3732///
3733/// \author Gene Van Buren <gene@bnl.gov>
3734
3736{
3737 TF1_EvalWrapper func(this, params, kTRUE, n);
3738
3740
3741 giod.SetFunction(func);
3743
3744 Double_t norm = giod.Integral(a, b);
3745 if (norm == 0) {
3746 Error("Moment", "Integral zero over range");
3747 return 0;
3748 }
3749
3750 // calculate now integral of xf(x)
3751 // wrapped the member function EvalFirstMom in interface required by integrator using the functor class
3753 giod.SetFunction(xfunc);
3754
3755 // estimate of mean value
3756 Double_t xbar = giod.Integral(a, b) / norm;
3757
3758 // use different mean value in function wrapper
3759 func.fX0 = xbar;
3761 giod.SetFunction(xnfunc);
3762
3763 Double_t res = giod.Integral(a, b) / norm;
3764 return res;
3765}
3766
3767
3768//______________________________________________________________________________
3769// some useful static utility functions to compute sampling points for IntegralFast
3770////////////////////////////////////////////////////////////////////////////////
3771/// Type safe interface (static method)
3772/// The number of sampling points are taken from the TGraph
3773
3774#ifdef INTHEFUTURE
3776{
3777 if (!g) return;
3778 CalcGaussLegendreSamplingPoints(g->GetN(), g->GetX(), g->GetY(), eps);
3779}
3780
3781
3782////////////////////////////////////////////////////////////////////////////////
3783/// Type safe interface (static method)
3784/// A TGraph is created with new with num points and the pointer to the
3785/// graph is returned by the function. It is the responsibility of the
3786/// user to delete the object.
3787/// if num is invalid (<=0) NULL is returned
3788
3790{
3791 if (num <= 0)
3792 return 0;
3793
3794 TGraph *g = new TGraph(num);
3795 CalcGaussLegendreSamplingPoints(g->GetN(), g->GetX(), g->GetY(), eps);
3796 return g;
3797}
3798#endif
3799
3800
3801////////////////////////////////////////////////////////////////////////////////
3802/// Type: unsafe but fast interface filling the arrays x and w (static method)
3803///
3804/// Given the number of sampling points this routine fills the arrays x and w
3805/// of length num, containing the abscissa and weight of the Gauss-Legendre
3806/// n-point quadrature formula.
3807///
3808/// Gauss-Legendre:
3809/** \f[
3810 W(x)=1 -1<x<1 \\
3811 (j+1)P_{j+1} = (2j+1)xP_j-jP_{j-1}
3812 \f]
3813**/
3814/// num is the number of sampling points (>0)
3815/// x and w are arrays of size num
3816/// eps is the relative precision
3817///
3818/// If num<=0 or eps<=0 no action is done.
3819///
3820/// Reference: Numerical Recipes in C, Second Edition
3821
3823{
3824 // This function is just kept like this for backward compatibility!
3825
3827 gli.GetWeightVectors(x, w);
3828
3829
3830}
3831
3832
3833/** \class TF1Parameters
3834TF1 Parameters class
3835*/
3836
3837////////////////////////////////////////////////////////////////////////////////
3838/// Returns the parameter number given a name
3839/// not very efficient but list of parameters is typically small
3840/// could use a map if needed
3841
3843{
3844 for (unsigned int i = 0; i < fParNames.size(); ++i) {
3845 if (fParNames[i] == std::string(name)) return i;
3846 }
3847 return -1;
3848}
3849
3850////////////////////////////////////////////////////////////////////////////////
3851/// Set parameter values
3852
3854 Double_t p5, Double_t p6, Double_t p7, Double_t p8,
3855 Double_t p9, Double_t p10)
3856{
3857 unsigned int npar = fParameters.size();
3858 if (npar > 0) fParameters[0] = p0;
3859 if (npar > 1) fParameters[1] = p1;
3860 if (npar > 2) fParameters[2] = p2;
3861 if (npar > 3) fParameters[3] = p3;
3862 if (npar > 4) fParameters[4] = p4;
3863 if (npar > 5) fParameters[5] = p5;
3864 if (npar > 6) fParameters[6] = p6;
3865 if (npar > 7) fParameters[7] = p7;
3866 if (npar > 8) fParameters[8] = p8;
3867 if (npar > 9) fParameters[9] = p9;
3868 if (npar > 10) fParameters[10] = p10;
3869}
3870
3871////////////////////////////////////////////////////////////////////////////////
3872/// Set parameter names
3873
3874void TF1Parameters::SetParNames(const char *name0, const char *name1, const char *name2, const char *name3,
3875 const char *name4, const char *name5, const char *name6, const char *name7,
3876 const char *name8, const char *name9, const char *name10)
3877{
3878 unsigned int npar = fParNames.size();
3879 if (npar > 0) fParNames[0] = name0;
3880 if (npar > 1) fParNames[1] = name1;
3881 if (npar > 2) fParNames[2] = name2;
3882 if (npar > 3) fParNames[3] = name3;
3883 if (npar > 4) fParNames[4] = name4;
3884 if (npar > 5) fParNames[5] = name5;
3885 if (npar > 6) fParNames[6] = name6;
3886 if (npar > 7) fParNames[7] = name7;
3887 if (npar > 8) fParNames[8] = name8;
3888 if (npar > 9) fParNames[9] = name9;
3889 if (npar > 10) fParNames[10] = name10;
3890}
Double_t AnalyticalIntegral(TF1 *f, Double_t a, Double_t b)
@ kMouseMotion
Definition: Buttons.h:23
void Class()
Definition: Class.C:29
double
Definition: Converters.cxx:939
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
@ kHand
Definition: GuiTypes.h:374
ROOT::R::TRInterface & r
Definition: Object.C:4
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
#define g(i)
Definition: RSha256.hxx:105
#define h(i)
Definition: RSha256.hxx:106
#define e(i)
Definition: RSha256.hxx:103
static const double x2[5]
static const double x1[5]
int Int_t
Definition: RtypesCore.h:45
long Longptr_t
Definition: RtypesCore.h:82
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
long long Long64_t
Definition: RtypesCore.h:80
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define BIT(n)
Definition: Rtypes.h:85
#define ClassImp(name)
Definition: Rtypes.h:364
#define R__ASSERT(e)
Definition: TError.h:118
bool R__SetClonesArrayTF1Updater(TF1Updater_t func)
TF1::EAddToList GetGlobalListOption(Option_t *opt)
Definition: TF1.cxx:682
int R__RegisterTF1UpdaterTrigger
Definition: TF1.cxx:148
void(*)(Int_t nobjects, TObject **from, TObject **to) TF1Updater_t
Definition: TF1.cxx:62
static Double_t gErrorTF1
Definition: TF1.cxx:60
static void R__v5TF1Updater(Int_t nobjects, TObject **from, TObject **to)
Definition: TF1.cxx:137
bool GetVectorizedOption(Option_t *opt)
Definition: TF1.cxx:690
void GetParameters(TFitEditor::FuncParams_t &pars, TF1 *func)
Stores the parameters of the given function into pars.
Definition: TFitEditor.cxx:256
static unsigned int total
char name[80]
Definition: TGX11.cxx:110
float xmin
Definition: THbookFile.cxx:95
float * q
Definition: THbookFile.cxx:89
float ymin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
float ymax
Definition: THbookFile.cxx:95
Int_t gDebug
Definition: TROOT.cxx:592
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:61
#define gROOT
Definition: TROOT.h:404
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
Definition: TStyle.h:413
#define R__LOCKGUARD(mutex)
#define gPad
Definition: TVirtualPad.h:288
#define snprintf
Definition: civetweb.c:1540
Definition: TF1.cxx:153
double operator()(double x) const
Definition: TF1.cxx:158
const TF1 * fFunction
Definition: TF1.cxx:154
const double fY0
Definition: TF1.cxx:155
GFunc(const TF1 *function, double y)
Definition: TF1.cxx:157
GInverseFuncNdim(TF1 *function)
Definition: TF1.cxx:179
TF1 * fFunction
Definition: TF1.cxx:177
double operator()(const double *x) const
Definition: TF1.cxx:181
double operator()(double x) const
Definition: TF1.cxx:170
const TF1 * fFunction
Definition: TF1.cxx:166
GInverseFunc(const TF1 *function)
Definition: TF1.cxx:168
class containg the result of the fit and all the related information (fitted parameter values,...
Definition: FitResult.h:47
bool IsEmpty() const
True if a fit result does not exist (even invalid) with parameter values.
Definition: FitResult.h:117
const std::vector< double > & Errors() const
parameter errors (return st::vector)
Definition: FitResult.h:169
double Error(unsigned int i) const
parameter error by index
Definition: FitResult.h:186
unsigned int Ndf() const
Number of degree of freedom.
Definition: FitResult.h:163
double Chi2() const
Chi2 fit value in case of likelihood must be computed ?
Definition: FitResult.h:160
double MinFcnValue() const
Return value of the objective function (chi2 or likelihood) used in the fit.
Definition: FitResult.h:120
unsigned int NPar() const
total number of parameters (abbreviation)
Definition: FitResult.h:131
unsigned int NFreeParameters() const
get total number of free parameters
Definition: FitResult.h:134
double Parameter(unsigned int i) const
parameter value by index
Definition: FitResult.h:181
Class for adaptive quadrature integration in multi-dimensions using rectangular regions.
int Status() const
return status of integration
int NEval() const
return number of function evaluations in calculating the integral
double RelError() const
return relative error
double Integral(const double *xmin, const double *xmax)
evaluate the integral with the previously given function between xmin[] and xmax[]
User class for performing function minimization.
virtual bool Minimize(int maxIter, double absTol=1.E-8, double relTol=1.E-10)
Find minimum position iterating until convergence specified by the absolute and relative tolerance or...
virtual double XMinimum() const
Return current estimate of the position of the minimum.
void SetFunction(const ROOT::Math::IGenFunction &f, double xlow, double xup)
Sets function to be minimized.
void SetNpx(int npx)
Set the number of point used to bracket root using a grid.
void SetLogScan(bool on)
Set a log grid scan (default is equidistant bins) will work only if xlow > 0.
virtual double FValMinimum() const
Return function value at current estimate of the minimum.
Class for finding the root of a one dimensional function using the Brent algorithm.
double Root() const
Returns root value.
bool Solve(int maxIter=100, double absTol=1E-8, double relTol=1E-10)
Returns the X value corresponding to the function value fy for (xmin<x<xmax).
void SetNpx(int npx)
Set the number of point used to bracket root using a grid.
bool SetFunction(const ROOT::Math::IGenFunction &f, double xlow, double xup)
Sets the function for the rest of the algorithms.
void SetLogScan(bool on)
Set a log grid scan (default is equidistant bins) will work only if xlow > 0.
static ROOT::Math::Minimizer * CreateMinimizer(const std::string &minimizerType="", const std::string &algoType="")
static method to create the corresponding Minimizer given the string Supported Minimizers types are: ...
Definition: Factory.cxx:63
Functor1D class for one-dimensional functions.
Definition: Functor.h:506
User class for performing function integration.
double IntegralLow(double b)
Returns Integral of function on a lower semi-infinite interval.
double Integral(double a, double b)
Returns Integral of function between a and b.
double Error() const
Return the estimate of the absolute Error of the last Integral calculation.
void SetFunction(const IGenFunction &)
Set integration function (flag control if function must be copied inside).
virtual void SetRelTolerance(double eps)
Set the desired relative Error.
int Status() const
return the status of the last integration - 0 in case of success
double IntegralUp(double a)
Returns Integral of function on an upper semi-infinite interval.
User class for performing function integration.
void GetWeightVectors(double *x, double *w) const
Returns the arrays x and w containing the abscissa and weight of the Gauss-Legendre n-point quadratur...
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
static IntegrationMultiDim::Type DefaultIntegratorType()
User class for performing multidimensional integration.
double Integral(const double *xmin, const double *xmax)
evaluate the integral with the previously given function between xmin[] and xmax[]
int Status() const
return the Error Status of the last Integral calculation
double Error() const
return integration error
static IntegrationOneDim::Type DefaultIntegratorType()
User Class for performing numerical integration of a function in one dimension.
Definition: Integrator.h:98
static std::string GetName(IntegrationOneDim::Type)
static function to get a string from the enumeration
Definition: Integrator.cxx:66
int Status() const
return the Error Status of the last Integral calculation
Definition: Integrator.h:421
double IntegralUp(const IGenFunction &f, double a)
evaluate the Integral of a function f over the semi-infinite interval (a,+inf)
Definition: Integrator.h:278
double Integral(Function &f, double a, double b)
evaluate the Integral of a function f over the defined interval (a,b)
Definition: Integrator.h:500
double Error() const
return the estimate of the absolute Error of the last Integral calculation
Definition: Integrator.h:416
double IntegralLow(const IGenFunction &f, double b)
evaluate the Integral of a function f over the over the semi-infinite interval (-inf,...
Definition: Integrator.h:296
static const std::string & DefaultMinimizerType()
static const std::string & DefaultMinimizerAlgo()
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition: Minimizer.h:75
virtual const double * X() const =0
return pointer to X values at the minimum
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)=0
set the function to minimize
void SetTolerance(double tol)
set the tolerance
Definition: Minimizer.h:453
virtual bool Minimize()=0
method to perform the minimization
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)=0
set a new free variable
void SetMaxFunctionCalls(unsigned int maxfcn)
set maximum of function calls
Definition: Minimizer.h:447
virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower, double upper)
set a new upper/lower limited variable (override if minimizer supports them ) otherwise as default se...
Definition: Minimizer.h:160
virtual double MinValue() const =0
return minimum function value
Param Functor class for Multidimensional functions.
Definition: ParamFunctor.h:273
User class for calculating the derivatives of a function.
double Derivative2(double x)
Returns the second derivative of the function at point x, computed by Richardson's extrapolation meth...
double Error() const
Returns the estimate of the absolute Error of the last derivative calculation.
double Derivative3(double x)
Returns the third derivative of the function at point x, computed by Richardson's extrapolation metho...
double Derivative1(double x)
Returns the first derivative of the function at point x, computed by Richardson's extrapolation metho...
Template class to wrap any C++ callable object which takes one argument i.e.
Template class to wrap any C++ callable object implementing operator() (const double * x) in a multi-...
Class to Wrap a ROOT Function class (like TF1) in a IParamFunction interface of one dimensions to be ...
Definition: WrappedTF1.h:39
void SetParameters(const double *p)
set parameter values need to call also SetParameters in TF1 in ace some other operations (re-normaliz...
Definition: WrappedTF1.h:90
virtual Double_t * GetParameters() const
Definition: TFormula.h:243
virtual Int_t GetNdim() const
Definition: TFormula.h:237
virtual Int_t GetNpar() const
Definition: TFormula.h:238
virtual TString GetExpFormula(Option_t *option="") const
Reconstruct the formula expression from the internal TFormula member variables.
Array of doubles (64 bits per element).
Definition: TArrayD.h:27
const Double_t * GetArray() const
Definition: TArrayD.h:43
Fill Area Attributes class.
Definition: TAttFill.h:19
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition: TAttFill.cxx:204
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
Line Attributes class.
Definition: TAttLine.h:18
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
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition: TAttLine.cxx:175
Marker Attributes class.
Definition: TAttMarker.h:19
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
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
Definition: TAttMarker.cxx:241
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:41
Class to manage histogram axis.
Definition: TAxis.h:30
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:478
Double_t GetXmax() const
Definition: TAxis.h:134
virtual void SaveAttributes(std::ostream &out, const char *name, const char *subname)
Save axis attributes as C++ statement(s) on output stream out.
Definition: TAxis.cxx:661
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:293
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition: TAxis.h:154
Double_t GetXmin() const
Definition: TAxis.h:133
const char * GetTitle() const
Returns title of object.
Definition: TAxis.h:129
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:2174
Class wrapping convolution of two functions.
Int_t GetNpar() const
const char * GetParName(Int_t ipar) const
Class adding two functions: c1*f1+c2*f2.
Definition: TF1NormSum.h:19
const char * GetParName(Int_t ipar) const
Definition: TF1NormSum.h:66
std::vector< double > GetParameters() const
Return array of parameters.
Definition: TF1NormSum.cxx:291
Int_t GetNpar() const
Return the number of (non constant) parameters including the coefficients: for 2 functions: c1,...
Definition: TF1NormSum.cxx:363
TF1 Parameters class.
Definition: TF1.h:50
std::vector< Double_t > fParameters
Definition: TF1.h:140
void SetParNames(const char *name0="p0", const char *name1="p1", const char *name2="p2", const char *name3="p3", const char *name4="p4", const char *name5="p5", const char *name6="p6", const char *name7="p7", const char *name8="p8", const char *name9="p9", const char *name10="p10")
Set parameter names.
Definition: TF1.cxx:3874
std::vector< std::string > fParNames
Definition: TF1.h:141
void SetParameters(const Double_t *params)
Definition: TF1.h:108
Int_t GetParNumber(const char *name) const
Returns the parameter number given a name not very efficient but list of parameters is typically smal...
Definition: TF1.cxx:3842
const double * fPar
Definition: TF1.cxx:234
Double_t fX0
Definition: TF1.cxx:237
Double_t fN
Definition: TF1.cxx:236
Double_t DoEval(Double_t x) const
implementation of the evaluation function. Must be implemented by derived classes
Definition: TF1.cxx:211
Double_t fX[1]
Definition: TF1.cxx:233
Double_t EvalFirstMom(Double_t x)
Definition: TF1.cxx:220
TF1 * fFunc
Definition: TF1.cxx:232
Double_t EvalNMom(Double_t x) const
Definition: TF1.cxx:226
TF1_EvalWrapper(TF1 *f, const Double_t *par, bool useAbsVal, Double_t n=1, Double_t x0=0)
Definition: TF1.cxx:192
Bool_t fAbsVal
Definition: TF1.cxx:235
ROOT::Math::IGenFunction * Clone() const
Clone a function.
Definition: TF1.cxx:203
1-Dim function class
Definition: TF1.h:213
std::unique_ptr< TF1FunctorPointer > fFunctor
! Functor object to wrap any C++ callable object
Definition: TF1.h:267
virtual Double_t GetMinimumX(Double_t xmin=0, Double_t xmax=0, Double_t epsilon=1.E-10, Int_t maxiter=100, Bool_t logx=false) const
Returns the X value corresponding to the minimum value of the function on the (xmin,...
Definition: TF1.cxx:1833
virtual Double_t GetMinimum(Double_t xmin=0, Double_t xmax=0, Double_t epsilon=1.E-10, Int_t maxiter=100, Bool_t logx=false) const
Returns the minimum value of the function on the (xmin, xmax) interval.
Definition: TF1.cxx:1706
virtual Double_t GetXmax() const
Definition: TF1.h:561
virtual void ReleaseParameter(Int_t ipar)
Release parameter number ipar If used in a fit, the parameter can vary freely.
Definition: TF1.cxx:3158
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Redefines TObject::GetObjectInfo.
Definition: TF1.cxx:1928
virtual void SetParError(Int_t ipar, Double_t error)
Set error for parameter number ipar.
Definition: TF1.cxx:3507
static void RejectPoint(Bool_t reject=kTRUE)
Static function to set the global flag to reject points the fgRejectPoint global flag is tested by al...
Definition: TF1.cxx:3679
EAddToList
Add to list behavior.
Definition: TF1.h:220
virtual Int_t GetNumber() const
Definition: TF1.h:503
virtual Int_t GetNDF() const
Return the number of degrees of freedom in the fit the fNDF parameter has been previously computed du...
Definition: TF1.cxx:1899
std::vector< Double_t > fParErrors
Array of errors of the fNpar parameters.
Definition: TF1.h:254
Int_t fNdim
Function dimension.
Definition: TF1.h:246
static void CalcGaussLegendreSamplingPoints(Int_t num, Double_t *x, Double_t *w, Double_t eps=3.0e-11)
Type safe interface (static method) The number of sampling points are taken from the TGraph.
Definition: TF1.cxx:3822
static void AbsValue(Bool_t reject=kTRUE)
Static function: set the fgAbsValue flag.
Definition: TF1.cxx:993
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to visualise the function Note that this histogram is managed ...
Definition: TF1.cxx:1594
virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
Return limits for parameter ipar.
Definition: TF1.cxx:1950
virtual Double_t Derivative2(Double_t x, Double_t *params=0, Double_t epsilon=0.001) const
Returns the second derivative of the function at point x, computed by Richardson's extrapolation meth...
Definition: TF1.cxx:1187
Int_t fNpar
Number of parameters.
Definition: TF1.h:245
TAxis * GetYaxis() const
Get y axis of the function.
Definition: TF1.cxx:2419
virtual void SetNDF(Int_t ndf)
Set the number of degrees of freedom ndf should be the number of points used in a fit - the number of...
Definition: TF1.cxx:3453
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition: TF1.cxx:1940
static std::atomic< Bool_t > fgAddToGlobList
Definition: TF1.h:306
virtual Double_t Moment(Double_t n, Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001)
Return nth moment of function between a and b.
Definition: TF1.cxx:3698
virtual void SetChisquare(Double_t chi2)
Definition: TF1.h:617
Double_t fNormIntegral
Integral of the function before being normalized.
Definition: TF1.h:266
Double_t GetChisquare() const
Definition: TF1.h:449
virtual void SetMaximum(Double_t maximum=-1111)
Set the maximum value along Y for this function In case the function is already drawn,...
Definition: TF1.cxx:3428
virtual TH1 * CreateHistogram()
Definition: TF1.h:454
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:1014
virtual void Update()
Called by functions such as SetRange, SetNpx, SetParameters to force the deletion of the associated h...
Definition: TF1.cxx:3644
virtual Double_t GetProb() const
Return the fit probability.
Definition: TF1.cxx:1965
virtual void SetTitle(const char *title="")
Set function title if title has the form "fffffff;xxxx;yyyy", it is assumed that the function title i...
Definition: TF1.cxx:3583
virtual void SetFitResult(const ROOT::Fit::FitResult &result, const Int_t *indpar=0)
Set the result from the fit parameter values, errors, chi2, etc... Optionally a pointer to a vector (...
Definition: TF1.cxx:3389
virtual Double_t GradientPar(Int_t ipar, const Double_t *x, Double_t eps=0.01)
Compute the gradient (derivative) wrt a parameter ipar.
Definition: TF1.cxx:2453
TAxis * GetZaxis() const
Get z axis of the function. (In case this object is a TF2 or TF3)
Definition: TF1.cxx:2430
virtual Double_t GetRandom(TRandom *rng=nullptr, Option_t *opt=nullptr)
Return a random number following this function shape.
Definition: TF1.cxx:2200
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF1.cxx:3553
virtual Int_t GetNpar() const
Definition: TF1.h:486
std::vector< Double_t > fBeta
! Array beta. is approximated by x = alpha +beta*r *gamma*r**2
Definition: TF1.h:260
Int_t fNDF
Number of degrees of freedom in the fit.
Definition: TF1.h:250
TH1 * fHistogram
! Pointer to histogram used for visualisation
Definition: TF1.h:263
std::unique_ptr< TF1AbsComposition > fComposition
Pointer to composition (NSUM or CONV)
Definition: TF1.h:270
virtual void SetParErrors(const Double_t *errors)
Set errors for all active parameters when calling this function, the array errors must have at least ...
Definition: TF1.cxx:3518
virtual TH1 * DoCreateHistogram(Double_t xmin, Double_t xmax, Bool_t recreate=kFALSE)
Create histogram with bin content equal to function value computed at the bin center This histogram w...
Definition: TF1.cxx:3056
virtual Double_t CentralMoment(Double_t n, Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001)
Return nth central moment of function between a and b (i.e the n-th moment around the mean value)
Definition: TF1.cxx:3735
Int_t fNpfits
Number of points used in the fit.
Definition: TF1.h:249
static void SetCurrent(TF1 *f1)
Static function setting the current function.
Definition: TF1.cxx:3377
std::vector< Double_t > fAlpha
! Array alpha. for each bin in x the deconvolution r of fIntegral
Definition: TF1.h:259
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
Definition: TF1.cxx:2535
virtual Double_t Derivative(Double_t x, Double_t *params=0, Double_t epsilon=0.001) const
Returns the first derivative of the function at point x, computed by Richardson's extrapolation metho...
Definition: TF1.cxx:1122
std::unique_ptr< TFormula > fFormula
Pointer to TFormula in case when user define formula.
Definition: TF1.h:268
static Double_t DerivativeError()
Static function returning the error of the last call to the of Derivative's functions.
Definition: TF1.cxx:1286
virtual void Paint(Option_t *option="")
Paint this function with its current attributes.
Definition: TF1.cxx:2957
std::vector< Double_t > fParMin
Array of lower limits of the fNpar parameters.
Definition: TF1.h:255
static void InitStandardFunctions()
Create the basic function objects.
Definition: TF1.cxx:2502
Double_t fMaximum
Maximum value for plotting.
Definition: TF1.h:253
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3467
virtual Double_t * GetParameters() const
Definition: TF1.h:525
Double_t fMinimum
Minimum value for plotting.
Definition: TF1.h:252
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a function.
Definition: TF1.cxx:1302
int TermCoeffLength(TString &term)
Definition: TF1.cxx:932
static Bool_t fgRejectPoint
Definition: TF1.h:305
virtual ~TF1()
TF1 default destructor.
Definition: TF1.cxx:962
virtual void SetNumberFitPoints(Int_t npfits)
Definition: TF1.h:629
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0)
Evaluate function with given coordinates and parameters.
Definition: TF1.cxx:1483
TF1 & operator=(const TF1 &rhs)
Operator =.
Definition: TF1.cxx:950
virtual Int_t GetNumberFreeParameters() const
Return the number of free parameters.
Definition: TF1.cxx:1910
Double_t fChisquare
Function fit chisquare.
Definition: TF1.h:251
@ kNotGlobal
Definition: TF1.h:325
@ kNotDraw
Definition: TF1.h:326
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TF1.cxx:3221
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition: TF1.cxx:2487
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:2855
EFType fType
Definition: TF1.h:248
Bool_t fNormalized
Normalization option (false by default)
Definition: TF1.h:265
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum value along Y for this function In case the function is already drawn,...
Definition: TF1.cxx:3441
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition: TF1.cxx:2289
virtual void Print(Option_t *option="") const
Print TNamed name and title.
Definition: TF1.cxx:2901
virtual Double_t IntegralFast(Int_t num, Double_t *x, Double_t *w, Double_t a, Double_t b, Double_t *params=0, Double_t epsilon=1e-12)
Gauss-Legendre integral, see CalcGaussLegendreSamplingPoints.
Definition: TF1.cxx:2782
virtual const char * GetParName(Int_t ipar) const
Definition: TF1.h:534
static TF1 * fgCurrent
Definition: TF1.h:307
Int_t fNpx
Number of points used for the graphical representation.
Definition: TF1.h:247
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
Set limits for parameter ipar.
Definition: TF1.cxx:3532
void DoInitialize(EAddToList addToGlobList)
Common initialization of the TF1.
Definition: TF1.cxx:810
virtual Double_t GetX(Double_t y, Double_t xmin=0, Double_t xmax=0, Double_t epsilon=1.E-10, Int_t maxiter=100, Bool_t logx=false) const
Returns the X value corresponding to the function value fy for (xmin<x<xmax).
Definition: TF1.cxx:1873
static TF1 * GetCurrent()
Static function returning the current function being processed.
Definition: TF1.cxx:1579
virtual Int_t GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum)
Compute Quantiles for density distribution of this function.
Definition: TF1.cxx:2002
virtual void SetParName(Int_t ipar, const char *name)
Set name of parameter number ipar.
Definition: TF1.cxx:3484
virtual Double_t GetSave(const Double_t *x)
Get value corresponding to X in array of fSave values.
Definition: TF1.cxx:2352
static std::atomic< Bool_t > fgAbsValue
Definition: TF1.h:304
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1342
TF1()
TF1 default constructor.
Definition: TF1.cxx:500
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition: TF1.cxx:1372
std::vector< Double_t > fParMax
Array of upper limits of the fNpar parameters.
Definition: TF1.h:256
virtual Bool_t IsValid() const
Return kTRUE if the function is valid.
Definition: TF1.cxx:2886
static Bool_t DefaultAddToGlobalList(Bool_t on=kTRUE)
Static method to add/avoid to add automatically functions to the global list (gROOT->GetListOfFunctio...
Definition: TF1.cxx:846
std::vector< Double_t > fSave
Array of fNsave function values.
Definition: TF1.h:257
static Bool_t RejectedPoint()
See TF1::RejectPoint above.
Definition: TF1.cxx:3688
void DefineNSUMTerm(TObjArray *newFuncs, TObjArray *coeffNames, TString &fullFormula, TString &formula, int termStart, int termEnd, Double_t xmin, Double_t xmax)
Helper functions for NSUM parsing.
Definition: TF1.cxx:891
std::vector< Double_t > fGamma
! Array gamma.
Definition: TF1.h:261
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
Definition: TF1.cxx:1073
TObject * fParent
! Parent object hooking this function (if one)
Definition: TF1.h:262
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:1733
virtual void DrawF1(Double_t xmin, Double_t xmax, Option_t *option="")
Draw function between xmin and xmax.
Definition: TF1.cxx:1435
Bool_t ComputeCdfTable(Option_t *opt)
Compute the cumulative function at fNpx points between fXmin and fXmax.
Definition: TF1.cxx:2089
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:649
virtual TObject * DrawIntegral(Option_t *option="al")
Draw integral of this function.
Definition: TF1.cxx:1419
std::vector< Double_t > fIntegral
! Integral of function binned on fNpx bins
Definition: TF1.h:258
virtual void SetParNames(const char *name0="p0", const char *name1="p1", const char *name2="p2", const char *name3="p3", const char *name4="p4", const char *name5="p5", const char *name6="p6", const char *name7="p7", const char *name8="p8", const char *name9="p9", const char *name10="p10")
Set up to 10 parameter names.
Definition: TF1.cxx:3496
virtual TObject * DrawDerivative(Option_t *option="al")
Draw derivative of this function.
Definition: TF1.cxx:1394
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:1454
virtual Double_t GetMaximum(Double_t xmin=0, Double_t xmax=0, Double_t epsilon=1.E-10, Int_t maxiter=100, Bool_t logx=false) const
Returns the maximum value of the function.
Definition: TF1.cxx:1624
std::unique_ptr< TF1Parameters > fParams
Pointer to Function parameters object (exists only for not-formula functions)
Definition: TF1.h:269
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:639
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: TF1.cxx:3168
EFType
Definition: TF1.h:234
virtual void SetSavedPoint(Int_t point, Double_t value)
Restore value of function saved at point.
Definition: TF1.cxx:3567
virtual void FixParameter(Int_t ipar, Double_t value)
Fix the value of a parameter The specified value will be used in a fit operation.
Definition: TF1.cxx:1567
Double_t fXmax
Upper bounds for the range.
Definition: TF1.h:244
virtual Double_t GetMaximumX(Double_t xmin=0, Double_t xmax=0, Double_t epsilon=1.E-10, Int_t maxiter=100, Bool_t logx=false) const
Returns the X value corresponding to the maximum value of the function.
Definition: TF1.cxx:1665
virtual Int_t GetNdim() const
Definition: TF1.h:490
virtual Double_t GetXmin() const
Definition: TF1.h:557
virtual Double_t Derivative3(Double_t x, Double_t *params=0, Double_t epsilon=0.001) const
Returns the third derivative of the function at point x, computed by Richardson's extrapolation metho...
Definition: TF1.cxx:1252
virtual Bool_t AddToGlobalList(Bool_t on=kTRUE)
Add to global list of functions (gROOT->GetListOfFunctions() ) return previous status (true if the fu...
Definition: TF1.cxx:855
virtual Double_t IntegralOneDim(Double_t a, Double_t b, Double_t epsrel, Double_t epsabs, Double_t &err)
Return Integral of function between a and b using the given parameter values and relative and absolut...
Definition: TF1.cxx:2625
virtual void Browse(TBrowser *b)
Browse.
Definition: TF1.cxx:1002
virtual Double_t GetParameter(Int_t ipar) const
Definition: TF1.h:517
virtual Double_t IntegralError(Double_t a, Double_t b, const Double_t *params=0, const Double_t *covmat=0, Double_t epsilon=1.E-2)
Return Error on Integral of a parametric function between a and b due to the parameter uncertainties ...
Definition: TF1.cxx:2712
virtual Int_t GetParNumber(const char *name) const
Definition: TF1.h:538
TAxis * GetXaxis() const
Get x axis of the function.
Definition: TF1.cxx:2408
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TF1.cxx:1551
The Formula class.
Definition: TFormula.h:87
TString fFormula
String representing the formula expression.
Definition: TFormula.h:148
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:769
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:618
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8816
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6715
virtual void Print(Option_t *option="") const
Print some global quantities for this histogram.
Definition: TH1.cxx:7012
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition: TH1.cxx:9020
virtual Double_t GetMinimumStored() const
Definition: TH1.h:292
@ kLogX
X-axis in log scale.
Definition: TH1.h:167
@ kNoStats
Don't draw stats box.
Definition: TH1.h:164
@ kIsZoomed
Bit set when zooming on Y axis.
Definition: TH1.h:168
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:320
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
Definition: TH1.cxx:2735
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition: TH1.cxx:8424
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:398
TAxis * GetYaxis()
Definition: TH1.h:321
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:9101
virtual Double_t GetMaximumStored() const
Definition: TH1.h:288
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TH1.cxx:3241
virtual void Paint(Option_t *option="")
Control routine to paint any kind of histograms.
Definition: TH1.cxx:6192
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
Definition: TH1.cxx:8514
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a line.
Definition: TH1.cxx:2806
Method or function calling interface.
Definition: TMethodCall.h:37
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void Copy(TObject &named) const
Copy this to obj.
Definition: TNamed.cxx:94
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TString fTitle
Definition: TNamed.h:33
TString fName
Definition: TNamed.h:32
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:74
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
An array of TObjects.
Definition: TObjArray.h:37
void Add(TObject *obj)
Definition: TObjArray.h:74
TObject * At(Int_t idx) const
Definition: TObjArray.h:166
Collectable string class.
Definition: TObjString.h:28
Mother of all ROOT objects.
Definition: TObject.h:37
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
virtual void RecursiveRemove(TObject *obj)
Recursively remove this object from a list.
Definition: TObject.cxx:574
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 Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
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 Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:672
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
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:523
const char * Data() const
Definition: TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1163
Bool_t IsNull() const
Definition: TString.h:407
TString & Append(const char *cs)
Definition: TString.h:564
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2336
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
Color_t GetFuncColor() const
Definition: TStyle.h:210
Width_t GetFuncWidth() const
Definition: TStyle.h:212
Style_t GetFuncStyle() const
Definition: TStyle.h:211
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:51
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
@ kGAUSS
simple Gauss integration method with fixed rule
@ kADAPTIVE
adaptive multi-dimensional integration
double beta(double x, double y)
Calculates the beta function.
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
TGraphErrors * gr
Definition: legend1.C:25
TF1 * f1
Definition: legend1.C:11
Namespace for new Math classes and functions.
double gamma(double x)
ParamFunctorTempl< double > ParamFunctor
Definition: ParamFunctor.h:387
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:150
double IntegralError(TF1 *func, Int_t ndim, const double *a, const double *b, const double *params, const double *covmat, double epsilon)
Definition: TF1Helper.cxx:39
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Bool_t IsNaN(Double_t x)
Definition: TMath.h:842
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:208
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
Definition: TMath.cxx:614
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754
Definition: TMath.h:851
constexpr Double_t E()
Base of natural log:
Definition: TMath.h:96
Double_t Sqrt(Double_t x)
Definition: TMath.h:641
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:685
Bool_t AreEqualRel(Double_t af, Double_t bf, Double_t relPrec)
Definition: TMath.h:430
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Definition: TMathBase.h:274
Double_t Log10(Double_t x)
Definition: TMath.h:714
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
Double_t Infinity()
Returns an infinity as defined by the IEEE standard.
Definition: TMath.h:864
const double xbins[xbins_n]
Double_t * fParMin
Definition: TF1Data.h:48
void Streamer(TBuffer &b, Int_t version, UInt_t start, UInt_t count, const TClass *onfile_class=0)
Stream a class object.
Definition: TF1Data_v5.cxx:59
Double_t * fSave
Definition: TF1Data.h:50
Double_t fXmin
Definition: TF1Data.h:39
Double_t * fParMax
Definition: TF1Data.h:49
Double_t fMaximum
Definition: TF1Data.h:51
Double_t fChisquare
Definition: TF1Data.h:46
Double_t fMinimum
Definition: TF1Data.h:52
Double_t * fParErrors
Definition: TF1Data.h:47
Double_t fXmax
Definition: TF1Data.h:40
auto * m
Definition: textangle.C:8
auto * l
Definition: textangle.C:4
auto * a
Definition: textangle.C:12
REAL epsilon
Definition: triangle.c:618