GooFit  v2.1.3
Functions
exponential2.cpp File Reference
#include <goofit/Application.h>
#include <goofit/PDFs/basic/ExpPdf.h>
#include <goofit/UnbinnedDataSet.h>
#include <goofit/Variable.h>
#include <goofit/fitting/FCN.h>
#include <goofit/fitting/Params.h>
#include <Minuit2/FunctionMinimum.h>
#include <Minuit2/MnMigrad.h>
#include <Minuit2/MnPrint.h>
#include <Minuit2/MnUserParameters.h>
#include <iostream>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 18 of file exponential2.cpp.

References GooFit::UnbinnedDataSet::addEvent(), data, GOOFIT_PARSE, and GooFit::PdfBase::setData().

18  {
19  GooFit::Application app("Exponential example", argc, argv);
20 
21  GOOFIT_PARSE(app);
22 
23  Minuit2::MnPrint::SetLevel(3);
24 
25  // Independent variable.
26  Observable xvar{"xvar", 0, log(1 + RAND_MAX / 2)};
27 
28  // Data set
29  UnbinnedDataSet data(xvar);
30 
31  // Generate toy events.
32  for(int i = 0; i < 100000; ++i) {
33  try {
34  xvar.setValue(xvar.getUpperLimit() - log(1 + rand() / 2));
35  data.addEvent();
36  } catch(const GooFit::OutOfRange &) {
37  }
38  }
39 
40  // Fit parameter
41  Variable alpha{"alpha", -2, 0.1, -10, 10};
42  // GooPdf object
43  ExpPdf exppdf{"exppdf", xvar, alpha};
44  exppdf.setData(&data);
45 
46  GooFit::Params upar{exppdf};
47  GooFit::FCN fcn{upar};
48 
49  Minuit2::MnMigrad migrad{fcn, upar};
50 
51  Minuit2::FunctionMinimum min = migrad();
52  std::cout << "min= " << min << std::endl;
53 
54  return 0;
55 }
Special class for observables. Used in DataSets.
Definition: Variable.h:109
UnbinnedDataSet * data
__host__ void setData(DataSet *data)
#define GOOFIT_PARSE(app,...)
Definition: Application.h:11