Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
TVirtualFitter.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 31/08/99
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
13/** \class TVirtualFitter
14 \ingroup Hist
15 Abstract Base Class for Fitting
16*/
17
18#include "TROOT.h"
19#include "TVirtualFitter.h"
20#include "TPluginManager.h"
21#include "TEnv.h"
23#include "ThreadLocalStorage.h"
24
25
26// Implement a thread local static member as a replacement
27// for TVirtualFitter::fgFitter
28namespace {
29 struct FitterGlobals {
30 FitterGlobals() : fFitter(nullptr),fMaxPar(0) {}
31
32 TVirtualFitter *fFitter;
33 Int_t fMaxPar;
34 TString fDefault;
35 };
36 FitterGlobals &GetGlobals() {
37 TTHREAD_TLS_DECL(FitterGlobals,globals);
38 return globals;
39 }
41 return GetGlobals().fFitter;
42 }
44 return GetGlobals().fMaxPar;
45 }
47 return GetGlobals().fDefault;
48 }
49}
50//Int_t TVirtualFitter::fgMaxpar = 0;
51// Int_t TVirtualFitter::fgMaxiter = 5000;
52// Double_t TVirtualFitter::fgPrecision = 1e-6;
53// Double_t TVirtualFitter::fgErrorDef = 1;
54//TString TVirtualFitter::fgDefault = "";
55
57
58#ifdef R__COMPLETE_MEM_TERMINATION
59namespace {
63 }
64 };
66}
67#endif
68
69////////////////////////////////////////////////////////////////////////////////
70/// Default constructor.
71
73 fXfirst(0),
74 fXlast(0),
75 fYfirst(0),
76 fYlast(0),
77 fZfirst(0),
78 fZlast(0),
79 fNpoints(0),
80 fPointSize(0),
81 fCacheSize(0),
82 fCache(nullptr),
83 fObjectFit(nullptr),
84 fUserFunc(nullptr),
85 fMethodCall(nullptr),
86 fFCN(nullptr)
87{
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Cleanup virtual fitter.
92
94{
95 delete fMethodCall;
96 delete [] fCache;
97 if ( GetGlobalFitter() == this ) {
98 GetGlobalFitter() = nullptr;
99 GetGlobalMaxPar() = 0;
100 }
101 fMethodCall = nullptr;
102 fFCN = nullptr;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Static function returning a pointer to the current fitter.
107/// If the fitter does not exist, the default TFitter is created.
108/// Don't delete the returned fitter object, it will be re-used.
109
111{
113 delete GetGlobalFitter();
114 GetGlobalFitter() = nullptr;
115 }
116
117 if (!GetGlobalFitter()) {
119 if (GetGlobalDefault().Length() == 0) GetGlobalDefault() = gEnv->GetValue("Root.Fitter","Minuit");
120 if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualFitter",GetGlobalDefault()))) {
121 if (h->LoadPlugin() == -1)
122 return nullptr;
123 GetGlobalFitter() = (TVirtualFitter*) h->ExecPlugin(1, maxpar);
125 }
126 }
127
128 if (GetGlobalFitter()) GetGlobalFitter()->SetObjectFit(obj);
129 return GetGlobalFitter();
130}
131
132////////////////////////////////////////////////////////////////////////////////
133///return confidence intervals in array x of dimension ndim
134///implemented in TFitter and TLinearFitter
135
136void TVirtualFitter::GetConfidenceIntervals(Int_t /*n*/, Int_t /*ndim*/, const Double_t * /*x*/, Double_t * /*ci*/, Double_t /*cl*/)
137{
138}
139
140////////////////////////////////////////////////////////////////////////////////
141///return confidence intervals in TObject obj
142///implemented in TFitter and TLinearFitter
143
147
148////////////////////////////////////////////////////////////////////////////////
149/// static: return the name of the default fitter
150
152{
153 //return GetGlobalDefault().Data();
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// static: return the current Fitter
159
164
165////////////////////////////////////////////////////////////////////////////////
166/// static: Return the maximum number of iterations
167/// actually max number of function calls
168
174
175////////////////////////////////////////////////////////////////////////////////
176/// static: Return the Error Definition
177
183
184////////////////////////////////////////////////////////////////////////////////
185/// static: Return the fit relative precision
186
192
193////////////////////////////////////////////////////////////////////////////////
194/// static: set name of default fitter
195
197{
199 if (GetGlobalDefault() == name) return;
200 delete GetGlobalFitter();
201 GetGlobalFitter() = nullptr;
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Static function to set an alternative fitter
207
213
214////////////////////////////////////////////////////////////////////////////////
215/// To set the address of the minimization objective function
216/// called by the native compiler (see function below when called by CINT)
217
219{
220 fFCN = fcn;
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Initialize the cache array
225/// npoints is the number of points to be stored (or already stored) in the cache
226/// psize is the number of elements per point
227///
228/// if (npoints*psize > fCacheSize) the existing cache is deleted
229/// and a new array is created.
230/// The function returns a pointer to the cache
231
233{
234 if (npoints*psize > fCacheSize) {
235 delete [] fCache;
238 }
241 return fCache;
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// static: Set the maximum number of function calls for the minimization algorithm
246/// For example for MIGRAD this is the maxcalls value passed as first argument
247/// (see https://cern-tex.web.cern.ch/cern-tex/minuit/node18.html )
248
253
254////////////////////////////////////////////////////////////////////////////////
255/// static: Set the Error Definition (default=1)
256/// For Minuit this is the value passed with the "SET ERR" command
257/// (see https://cern-tex.web.cern.ch/cern-tex/minuit/node18.html)
258
260{
261// fgErrorDef = errdef;
263 if (!GetGlobalFitter()) return;
264 Double_t arglist[1];
265 arglist[0] = errdef;
266 GetGlobalFitter()->ExecuteCommand("SET ERRORDEF", arglist, 1);
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// static: Set the tolerance used in the minimization algorithm
271/// For example for MIGRAD this is tolerance value passed as second argument
272/// (see https://cern-tex.web.cern.ch/cern-tex/minuit/node18.html )
273
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
#define ClassImp(name)
Definition Rtypes.h:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:406
static void SetDefaultMaxFunctionCalls(int maxcall)
Set the maximum number of function calls.
static void SetDefaultErrorDef(double up)
Set the default level for computing the parameter errors.
static void SetDefaultMinimizer(const char *type, const char *algo=nullptr)
Set the default Minimizer type and corresponding algorithms.
static const std::string & DefaultMinimizerType()
static void SetDefaultTolerance(double tol)
Set the Minimization tolerance.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
Abstract Base Class for Fitting.
static void SetDefaultFitter(const char *name="")
static: set name of default fitter
static void SetPrecision(Double_t prec=1e-6)
static: Set the tolerance used in the minimization algorithm For example for MIGRAD this is tolerance...
Int_t fPointSize
Number of words per point in the cache.
virtual void GetConfidenceIntervals(Int_t n, Int_t ndim, const Double_t *x, Double_t *ci, Double_t cl=0.95)
return confidence intervals in array x of dimension ndim implemented in TFitter and TLinearFitter
TMethodCall * fMethodCall
Pointer to MethodCall in case of interpreted function.
static Int_t GetMaxIterations()
static: Return the maximum number of iterations actually max number of function calls
static Double_t GetPrecision()
static: Return the fit relative precision
virtual Double_t * SetCache(Int_t npoints, Int_t psize)
Initialize the cache array npoints is the number of points to be stored (or already stored) in the ca...
virtual void SetFCN(void(*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
To set the address of the minimization objective function called by the native compiler (see function...
TVirtualFitter()
Default constructor.
static const char * GetDefaultFitter()
static: return the name of the default fitter
Double_t * fCache
[fCacheSize] Array of points data (fNpoints*fPointSize < fCacheSize words)
static void SetMaxIterations(Int_t niter=5000)
static: Set the maximum number of function calls for the minimization algorithm For example for MIGRA...
void(* fFCN)(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag)
static Double_t GetErrorDef()
static: Return the Error Definition
Int_t fCacheSize
Size of the fCache array.
static void SetErrorDef(Double_t errdef=1)
static: Set the Error Definition (default=1) For Minuit this is the value passed with the "SET ERR" c...
static TVirtualFitter * GetFitter()
static: return the current Fitter
~TVirtualFitter() override
Cleanup virtual fitter.
Int_t fNpoints
Number of points to fit.
static TVirtualFitter * Fitter(TObject *obj, Int_t maxpar=25)
Static function returning a pointer to the current fitter.
static void SetFitter(TVirtualFitter *fitter, Int_t maxpar=25)
Static function to set an alternative fitter.