54 for (
int j = 0; j <
N; ++j) {
57 t2.
Branch(xname.c_str(),&x[j],xname2.c_str());
59 t2.
Branch(
"ev",&ev,
"ev/I");
63 for (
int j = 0; j <
N; ++j) {
64 double mu = double(j)/10.;
65 double s = 1.0 + double(j)/10.;
84 std::cout <<
"number of unbin data is " << n <<
" of dim " <<
N << std::endl;
88 for (
int j = 0; j <
N; ++j) {
94 std::vector<double>
m(N);
95 for (
int unsigned i = 0; i <
n; ++i) {
98 for (
int j = 0; j <
N; ++j)
103 std::cout <<
"average values of means :\n";
104 for (
int j = 0; j <
N; ++j)
105 std::cout << m[j]/n <<
" ";
118 class MultiGaussRooPdf {
123 MultiGaussRooPdf(
unsigned int n) :
124 x(n),
m(n), s(n), g(n), pdf(n)
129 for (
unsigned int j = 0; j <
n; ++j) {
132 x[j] =
new RooRealVar(xname.c_str(),xname.c_str(),-10000,10000) ;
144 g[j] =
new RooGaussian(gname.c_str(),
"gauss(x,mean,sigma)",*
x[j],*
m[j],*s[j]);
160 RooAbsPdf & getPdf() {
return *pdf.back(); }
162 std::unique_ptr<RooArgSet> getVars() {
163 std::unique_ptr<RooArgSet> vars(
new RooArgSet() );
164 for (
unsigned int i = 0; i <
x.size(); ++i)
169 ~MultiGaussRooPdf() {
172 for (
int j = 0; j <
n; ++j) {
177 if (j> 0)
delete pdf[j];
183 std::vector<RooRealVar *>
x;
184 std::vector<RooRealVar *>
m;
185 std::vector<RooRealVar *> s;
187 std::vector<RooAbsPdf *> g;
188 std::vector<RooAbsPdf *> pdf;
197 std::cout <<
"\n************************************************************\n";
198 std::cout <<
"\tFit using RooFit (Likelihood Fit) on " << pdf.
GetName() << std::endl;
205 for (
int i = 0; i <
nfit; ++i) {
213 std::cout <<
"num entries = " << data.
numEntries() << std::endl;
216 std::cout <<
"\n\nDo the fit now \n\n";
222 #ifndef _WIN32 // until a bug 30762 is fixed 230 std::cout <<
" Roofit status " << result->
status() << std::endl;
233 iret |= (result == 0);
239 std::cout <<
"RooFit result " << std::endl;
245 std::cout <<
"\nTime: \t" << w.
RealTime() <<
" , " << w.
CpuTime() << std::endl;
246 std::cout <<
"\n************************************************************\n";
252 template <
class MinType>
276 bool ret = fitter.
Fit(d);
278 std::cout <<
" Fit Failed " << std::endl;
286 template <
class MinType,
class FitObj>
289 std::cout <<
"\n************************************************************\n";
290 std::cout <<
"\tFit using new Fit::Fitter\n";
291 std::cout <<
"\tMinimizer is " <<
MinType::name() <<
" " << MinType::name2() << std::endl;
298 iret |= DoFit<MinType>(fitobj,
func,
true, useGrad);
301 for (
int i = 0; i <
nfit; ++i) {
302 func.SetParameters(
iniPar);
303 iret = DoFit<MinType>(fitobj,
func,
false, useGrad);
304 if (iret != 0)
break;
308 std::cout <<
"\nTime: \t" << w.
RealTime() <<
" , " << w.
CpuTime() << std::endl;
309 std::cout <<
"\n************************************************************\n";
316 static double F(
const double *
x,
const double *p) {
323 static double F(
const double *
x,
const double *p) {
342 TTree tree(
"t",
"a large Tree with many gaussian variables");
346 for (
int i = 0; i <
N; ++i) {
352 MultiGaussRooPdf multipdf(N);
355 std::unique_ptr<RooArgSet> xvars(multipdf.getVars());
360 std::cout <<
"ndim " << wpdf.NDim() << std::endl;
361 std::cout <<
"npar " << wpdf.NPar() << std::endl;
362 for (
unsigned int i = 0; i < wpdf.NPar(); ++i)
363 std::cout <<
" par " << i <<
" is " << wpdf.ParameterName(i) <<
" value " << wpdf.Parameters()[i] << std::endl;
366 FitUsingNewFitter<TMINUIT>(&
tree,wpdf);
369 wpdf.SetParameters(
iniPar);
377 FitUsingNewFitter<TMINUIT>(&
tree,gausn);
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
virtual const char * GetName() const
Returns name of object.
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.
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
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...
RooCmdArg PrintLevel(Int_t code)
RooProdPdf is an efficient implementation of a product of PDFs of the form.
RooCmdArg Minos(Bool_t flag=kTRUE)
int FitUsingNewFitter(FitObj *fitobj, Func &func, bool useGrad=false)
virtual Int_t Fill()
Fill all branches.
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
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)
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
double normal_pdf(double x, double sigma=1, double x0=0)
Probability density function of the normal (Gaussian) distribution.
const FitResult & Result() const
get fit result
void Stop()
Stop the stopwatch.
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
ROOT::Math::IParamMultiFunction Func
const FitConfig & Config() const
access to the fit configuration (const method)
RooRealVar represents a fundamental (non-derived) real valued object.
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 ...
Fitter class, entry point for performing all type of fits.
RooDataSet is a container class to hold unbinned data.
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.
RooCmdArg Hesse(Bool_t flag=kTRUE)
int FitUsingRooFit(TTree &tree, RooAbsPdf &pdf, RooArgSet &xvars)
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
void Add(double x)
add one dim coordinate data (unweighted)
virtual void ResetBranchAddresses()
Tell all of our branches to drop their current objects and allocate new ones.
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.
RooCmdArg Save(Bool_t flag=kTRUE)
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
void Print(std::ostream &os, bool covmat=false) const
print the result and optionaly covariance matrix and correlations
std::string ToString(const T &val)
Utility function for conversion to strings.
virtual RooFitResult * fitTo(RooAbsData &data, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Fit PDF to given dataset.
int DoFit(TTree *tree, Func &func, bool debug=false, bool=false)
A TTree object has a header with a name and a title.
A TTree is a list of TBranches.
void FillUnBinData(ROOT::Fit::UnBinData &d, TTree *tree)
virtual Int_t numEntries() const
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...