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