50 double invsig = 1./p[1];
51 double tmp = (x[0]-p[0]) * invsig;
52 const double sqrt_2pi = 1./
std::sqrt(2.* 3.14159 );
53 return std::exp(-0.5 * tmp*tmp ) * sqrt_2pi * invsig;
58 for (
int i = 0; i <
N; ++i)
65 static std::string
name() {
return "Minuit2"; }
66 static std::string
name2() {
return ""; }
80 std::cout <<
"number of unbin data is " << n <<
" of dim " <<
N << std::endl;
86 std::vector<double>
m(
N);
87 for (
int unsigned i = 0; i <
n; ++i) {
90 for (
int j = 0; j <
N; ++j)
95 std::cout <<
"average values of means :\n";
96 for (
int j = 0; j <
N; ++j)
97 std::cout << m[j]/n <<
" ";
111 template <
class MinType,
class T>
119 std::cout <<
"Fit data size = " << d->
Size() <<
" dimension = " << d->
NDim() << std::endl;
149 bool ret = fitter.
Fit(*d);
151 std::cout <<
" Fit Failed " << std::endl;
159 for (
int i = 0; i <
N; ++i) {
164 int iret = (prob < 1.0E-6) ? -1 : 0;
166 std::cout <<
"Found difference in fitted values - prob = " << prob << std::endl;
168 for (
int i = 0; i <
N; ++i) {
170 std::cout <<
"par_" << i <<
" = " << fitter.
Result().
Value(i) <<
" true = " <<
truePar[i] <<
" pull = " << d << std::endl;
182 template <
class MinType>
184 return DoUnBinFit<MinType, TTree>(tree,
func,
debug);
195 template <
class MinType,
class FitObj>
198 std::cout <<
"\n************************************************************\n";
199 std::cout <<
"\tFit using new Fit::Fitter " <<
typeid(*fitobj).name() << std::endl;
200 std::cout <<
"\tMinimizer is " <<
MinType::name() <<
" " << MinType::name2() <<
" func dim = " << func.
NDim() << std::endl;
206 std::cout <<
"initial Parameters " <<
iniPar <<
" " << *
iniPar <<
" " << *(
iniPar+1) << std::endl;
208 iret |= DoFit<MinType>(fitobj,
func,true );
211 for (
int i = 0; i <
nfit; ++i) {
212 func.SetParameters(
iniPar);
213 iret = DoFit<MinType>(fitobj,
func,
false);
215 std::cout <<
"Fit failed " << std::endl;
221 std::cout <<
"\nTime: \t" << w.
RealTime() <<
" , " << w.
CpuTime() << std::endl;
222 std::cout <<
"\n************************************************************\n";
231 std::cout <<
"\n\n************************************************************\n";
232 std::cout <<
"\t UNBINNED TREE (GAUSSIAN MULTI-DIM) FIT\n";
233 std::cout <<
"************************************************************\n";
235 TTree *
t1 =
new TTree(
"t2",
"a large Tree with gaussian variables");
239 t1->
Branch(
"ev",&ev,
"ev/I");
242 for (
int j = 0; j <
N; ++j) {
243 double mu =
double(j)/10.;
244 double s = 1.0 +
double(j)/10.;
253 for (
int j = 0; j <
N; ++j) {
266 for (
int i = 0; i <
N; ++i) {
276 iret |= FitUsingNewFitter<MINUIT2>(
t1,
f2);
const FitConfig & Config() const
access to the fit configuration (const method)
int DoUnBinFit(T *tree, Func &func, bool debug=false)
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 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.
unsigned int NDim() const
return coordinate data dimension
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)
ROOT::Fit::UnBinData * FillUnBinData(TTree *tree)
void Stop()
Stop the stopwatch.
const std::string branchType
const FitResult & Result() const
get fit result
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
double Value(unsigned int i) const
parameter value by index
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
Fitter class, entry point for performing all type of fits.
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
double gausnorm(const double *x, const double *p)
double gausnormN(const double *x, const double *p)
int FitUsingNewFitter(FitObj *fitobj, Func &func)
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.
int DoFit(TTree *tree, Func &func, bool debug=false)
virtual void SetParameters(const double *p)=0
Set the parameter values.
ROOT::Math::IParamMultiFunction Func
void Add(double x)
add one dim coordinate data (unweighted)
double Error(unsigned int i) const
parameter error by index
double func(double *x, double *p)
void Print(std::ostream &os, bool covmat=false) const
print the result and optionaly covariance matrix and correlations
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.
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)
unsigned int Size() const
return number of contained points
virtual Long64_t GetEntries() const
A TTree object has a header with a name and a title.
A TTree is a list of TBranches.
WrappedParamFunction class to wrap any multi-dimensional function pbject implementing the operator()(...
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...