Logo ROOT  
Reference Guide
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 }
40 TVirtualFitter *&GetGlobalFitter() {
41 return GetGlobals().fFitter;
42 }
43 Int_t &GetGlobalMaxPar() {
44 return GetGlobals().fMaxPar;
45 }
46 TString &GetGlobalDefault() {
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
56
57#ifdef R__COMPLETE_MEM_TERMINATION
58namespace {
59 struct TVirtualFitterCleanup {
60 ~TVirtualFitterCleanup() {
62 }
63 };
64 TVirtualFitterCleanup cleanup;
65}
66#endif
67
68////////////////////////////////////////////////////////////////////////////////
69/// Default constructor.
70
72 fXfirst(0),
73 fXlast(0),
74 fYfirst(0),
75 fYlast(0),
76 fZfirst(0),
77 fZlast(0),
78 fNpoints(0),
79 fPointSize(0),
80 fCacheSize(0),
81 fCache(nullptr),
82 fObjectFit(nullptr),
83 fUserFunc(nullptr),
84 fMethodCall(nullptr),
85 fFCN(nullptr)
86{
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Cleanup virtual fitter.
91
93{
94 delete fMethodCall;
95 delete [] fCache;
96 if ( GetGlobalFitter() == this ) {
97 GetGlobalFitter() = nullptr;
98 GetGlobalMaxPar() = 0;
99 }
100 fMethodCall = nullptr;
101 fFCN = nullptr;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Static function returning a pointer to the current fitter.
106/// If the fitter does not exist, the default TFitter is created.
107/// Don't delete the returned fitter object, it will be re-used.
108
110{
111 if (GetGlobalFitter() && maxpar > GetGlobalMaxPar()) {
112 delete GetGlobalFitter();
113 GetGlobalFitter() = nullptr;
114 }
115
116 if (!GetGlobalFitter()) {
118 if (GetGlobalDefault().Length() == 0) GetGlobalDefault() = gEnv->GetValue("Root.Fitter","Minuit");
119 if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualFitter",GetGlobalDefault()))) {
120 if (h->LoadPlugin() == -1)
121 return nullptr;
122 GetGlobalFitter() = (TVirtualFitter*) h->ExecPlugin(1, maxpar);
123 GetGlobalMaxPar() = maxpar;
124 }
125 }
126
127 if (GetGlobalFitter()) GetGlobalFitter()->SetObjectFit(obj);
128 return GetGlobalFitter();
129}
130
131////////////////////////////////////////////////////////////////////////////////
132///return confidence intervals in array x of dimension ndim
133///implemented in TFitter and TLinearFitter
134
135void TVirtualFitter::GetConfidenceIntervals(Int_t /*n*/, Int_t /*ndim*/, const Double_t * /*x*/, Double_t * /*ci*/, Double_t /*cl*/)
136{
137}
138
139////////////////////////////////////////////////////////////////////////////////
140///return confidence intervals in TObject obj
141///implemented in TFitter and TLinearFitter
142
146
147////////////////////////////////////////////////////////////////////////////////
148/// static: return the name of the default fitter
149
151{
152 //return GetGlobalDefault().Data();
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// static: return the current Fitter
158
160{
161 return GetGlobalFitter();
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// static: Return the maximum number of iterations
166/// actually max number of function calls
167
173
174////////////////////////////////////////////////////////////////////////////////
175/// static: Return the Error Definition
176
182
183////////////////////////////////////////////////////////////////////////////////
184/// static: Return the fit relative precision
185
191
192////////////////////////////////////////////////////////////////////////////////
193/// static: set name of default fitter
194
196{
198 if (GetGlobalDefault() == name) return;
199 delete GetGlobalFitter();
200 GetGlobalFitter() = nullptr;
201 GetGlobalDefault() = name;
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Static function to set an alternative fitter
206
208{
209 GetGlobalFitter() = fitter;
210 GetGlobalMaxPar() = maxpar;
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// To set the address of the minimization objective function
215/// called by the native compiler (see function below when called by Cling)
216
218{
219 fFCN = fcn;
220}
221
222////////////////////////////////////////////////////////////////////////////////
223/// Initialize the cache array
224/// npoints is the number of points to be stored (or already stored) in the cache
225/// psize is the number of elements per point
226///
227/// if (npoints*psize > fCacheSize) the existing cache is deleted
228/// and a new array is created.
229/// The function returns a pointer to the cache
230
232{
233 if (npoints*psize > fCacheSize) {
234 delete [] fCache;
235 fCacheSize = npoints*psize;
237 }
238 fNpoints = npoints;
239 fPointSize = psize;
240 return fCache;
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// static: Set the maximum number of function calls for the minimization algorithm
245/// For example for MIGRAD this is the maxcalls value passed as first argument
246/// (see https://cern-tex.web.cern.ch/cern-tex/minuit/node18.html )
247
252
253////////////////////////////////////////////////////////////////////////////////
254/// static: Set the Error Definition (default=1)
255/// For Minuit this is the value passed with the "SET ERR" command
256/// (see https://cern-tex.web.cern.ch/cern-tex/minuit/node18.html)
257
259{
260// fgErrorDef = errdef;
262 if (!GetGlobalFitter()) return;
263 Double_t arglist[1];
264 arglist[0] = errdef;
265 GetGlobalFitter()->ExecuteCommand("SET ERRORDEF", arglist, 1);
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// static: Set the tolerance used in the minimization algorithm
270/// For example for MIGRAD this is tolerance value passed as second argument
271/// (see https://cern-tex.web.cern.ch/cern-tex/minuit/node18.html )
272
274{
275 //fgPrecision = prec;
277}
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
externTEnv * gEnv
Definition TEnv.h:170
char name[80]
Definition TGX11.cxx:148
#define gROOT
Definition TROOT.h:417
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.
TObject()
TObject constructor.
Definition TObject.h:259
Basic string class.
Definition TString.h:138
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 SetObjectFit(TObject *obj)
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
TObject * fUserFunc
Pointer to user theoretical function (a TF1*).
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
TVirtualFitter(const TVirtualFitter &)=delete
static Double_t GetPrecision()
static: Return the fit relative precision
Int_t fYlast
Last bin on Y axis.
Int_t fXfirst
First bin on X axis.
Int_t fZfirst
First bin on Z axis.
Int_t fXlast
Last bin on X axis.
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
TObject * fObjectFit
Pointer to object being fitted.
Int_t fCacheSize
Size of the fCache array.
Int_t fYfirst
First bin on Y axis.
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 fZlast
Last bin on Z axis.
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.