47 double invsig = 1./std::abs(p[1]);
48 double tmp = (x[0]-p[0]) * invsig;
49 const double sqrt_2pi = 1./
std::sqrt(2.* 3.14159 );
50 return std::exp(-0.5 * tmp*tmp ) * sqrt_2pi * invsig;
53 double gausSum(
const double *
x,
const double *p) {
59 double norm = 1. + p[0] + p[1];
64 static std::string
name() {
return "Minuit2"; }
65 static std::string
name2() {
return ""; }
79 std::cout <<
"number of unbin data is " << n <<
" of dim " <<
N << std::endl;
85 std::vector<double>
m(
N);
86 for (
int unsigned i = 0; i <
n; ++i) {
89 for (
int j = 0; j <
N; ++j)
94 std::cout <<
"average values of means :\n";
95 for (
int j = 0; j <
N; ++j)
96 std::cout << m[j]/n <<
" ";
107 template <
class MinType,
class T>
114 std::cout <<
"Filled the fit data " << std::endl;
118 std::cout <<
"data size type and size is " <<
typeid(*d).name() <<
" " << d->
Size() << std::endl;
150 std::cout <<
"do fitting... " << std::endl;
152 bool ret = fitter.
Fit(*d);
154 std::cout <<
" Fit Failed " << std::endl;
163 for (
int i = 0; i <
NPar; ++i) {
181 int iret = (prob < 1.0E-6) ? -1 : 0;
183 std::cout <<
"Found difference in fitted values - chi2 = " << chi2
184 <<
" prob = " << prob << std::endl;
195 template <
class MinType>
208 template <
class MinType,
class FitObj>
211 std::cout <<
"\n************************************************************\n";
212 std::cout <<
"\tFit using new Fit::Fitter " <<
typeid(*fitobj).name() << std::endl;
213 std::cout <<
"\tMinimizer is " <<
MinType::name() <<
" " << MinType::name2() <<
" func dim = " << func.
NDim() << std::endl;
219 std::cout <<
"initial Parameters " <<
iniPar <<
" " << *
iniPar <<
" " << *(
iniPar+1) << std::endl;
221 iret |= DoFit<MinType>(fitobj,
func,true );
223 std::cout <<
"Test failed " << std::endl;
227 for (
int i = 0; i <
nfit; ++i) {
228 func.SetParameters(
iniPar);
229 iret = DoFit<MinType>(fitobj,
func,
false);
231 std::cout <<
"Test failed " << std::endl;
237 std::cout <<
"\nTime: \t" << w.
RealTime() <<
" , " << w.
CpuTime() << std::endl;
238 std::cout <<
"\n************************************************************\n";
247 std::cout <<
"\n\n************************************************************\n";
248 std::cout <<
"\t UNBINNED TREE (GAUSSIAN MULTI-DIM) FIT\n";
249 std::cout <<
"************************************************************\n";
251 TTree t1(
"t2",
"a large Tree with gaussian variables");
255 t1.
Branch(
"ev",&ev,
"ev/I");
285 std::cout <<
" True amplitude gaussians " << a <<
" " << b <<
" " << c << std::endl;
287 for (
int j = 0; j <
N; ++j) {
293 else if (r.
Rndm() <
b ) {
313 for (
int i = 0; i <
NGaus; ++i) {
316 std::cout <<
"inipar " << i <<
" = " <<
iniPar[2*i+2] <<
" " <<
iniPar[2*i+3] << std::endl;
324 iret |= FitUsingNewFitter<MINUIT2>(&
t1,
f2);
int FitUsingNewFitter(FitObj *fitobj, Func &func)
void SetPrintLevel(int level)
set print level
Random number generator class based on M.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
virtual void SetAddress(void *add)
Set address of this branch.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void SetTolerance(double tol)
set the tolerance
virtual Double_t Rndm()
Machine independent random number generator.
double Error(unsigned int i) const
parameter error by index
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
static std::string name()
virtual Int_t Fill()
Fill all branches.
double Value(unsigned int i) const
parameter value by index
double gausnorm(const double *x, const double *p)
static std::string name2()
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
Class describing the unbinned data sets (just x coordinates values) of any dimensions.
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
const FitResult & Result() const
get fit result
void Stop()
Stop the stopwatch.
double gausSum(const double *x, const double *p)
const FitConfig & Config() const
access to the fit configuration (const method)
void SetLowerLimit(double low)
set a single lower limit
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
bool Fit(const Data &data, const Function &func)
fit a data set using any generic model function If data set is binned a least square fit is performed...
void SetMinimizer(const char *type, const char *algo=0)
set minimizer type
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
ROOT::Math::IParamMultiFunction Func
Fitter class, entry point for performing all type of fits.
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all leaves of entry and return total number of bytes read.
void SetFunction(const IModelFunction &func, bool useGradient=false)
Set the fitted function (model function) from a parametric function interface.
virtual void SetParameters(const double *p)=0
Set the parameter values.
void Add(double x)
add one dim coordinate data (unweighted)
double func(double *x, double *p)
virtual Long64_t GetEntries() const
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Create one branch for each element in the collection.
int DoUnBinFit(T *tree, Func &func, bool debug=false)
void Print(std::ostream &os, bool covmat=false) const
print the result and optionaly covariance matrix and correlations
double chisquared_cdf_c(double x, double r, double x0=0)
Complement of the cumulative distribution function of the distribution with degrees of freedom (upp...
void SetStrategy(int stra)
set the strategy
double f2(const double *x)
ROOT::Fit::UnBinData * FillUnBinData(TTree *tree)
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
A TTree object has a header with a name and a title.
const std::string branchType
A TTree is a list of TBranches.
double norm(double *x, double *p)
unsigned int Size() const
return number of contained points
WrappedParamFunction class to wrap any multi-dimensional function pbject implementing the operator()(...
int DoFit(TTree *tree, Func &func, bool debug=false)
void Initialize(unsigned int maxpoints, unsigned int dim=1, bool isWeighted=false)
preallocate a data set given size and dimension of the coordinates if a vector already exists with co...