GooFit  v2.1.3
exponential2.cpp
Go to the documentation of this file.
1 #include <goofit/Application.h>
4 #include <goofit/Variable.h>
5 #include <goofit/fitting/FCN.h>
7 
8 #include <Minuit2/FunctionMinimum.h>
9 #include <Minuit2/MnMigrad.h>
10 #include <Minuit2/MnPrint.h>
11 #include <Minuit2/MnUserParameters.h>
12 
13 #include <iostream>
14 
15 using namespace std;
16 using namespace GooFit;
17 
18 int main(int argc, char **argv) {
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
int main(int argc, char **argv)