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