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