GooFit  v2.1.3
exponential.cpp
Go to the documentation of this file.
1 #include <CLI/Timer.hpp>
2 #include <goofit/Application.h>
3 #include <goofit/FitManager.h>
6 #include <goofit/Variable.h>
7 #include <iostream>
8 
9 int main(int argc, char **argv) {
10  GooFit::Application app("Exponential example", argc, argv);
11 
12  GOOFIT_PARSE(app);
13 
14  // Independent variable.
15  GooFit::Observable xvar{"xvar", 0, log(1 + RAND_MAX / 2)};
16 
17  // Data set
19 
20  // Generate toy events
21  CLI::Timer gen_timer{"Generating took"};
22  for(int i = 0; i < 100000; ++i) {
23  try {
24  xvar.setValue(xvar.getUpperLimit() - log(1 + rand() / 2));
25  data.addEvent();
26  } catch(const GooFit::OutOfRange &) {
27  }
28  }
29 
30  std::cout << GooFit::magenta << gen_timer << GooFit::reset << std::endl;
31 
32  // Fit parameter
33  GooFit::Variable alpha{"alpha", -2, 0.1, -10, 10};
34  // GooPdf object
35  GooFit::ExpPdf exppdf{"exppdf", xvar, alpha};
36  exppdf.setData(&data);
37 
38  GooFit::FitManager fitter{&exppdf};
39  fitter.fit();
40 
41  if(alpha.getValue() < -1.01 || alpha.getValue() > -0.99)
42  return 1;
43 
44  return fitter;
45 }
int main(int argc, char **argv)
Definition: exponential.cpp:9
Special class for observables. Used in DataSets.
Definition: Variable.h:109
UnbinnedDataSet * data
__host__ void setData(DataSet *data)
constexpr rang::style const reset
Definition: Color.h:16
constexpr rang::fg const magenta
Definition: Color.h:13
ROOT::Minuit2::FunctionMinimum fit()
This runs the fit.
#define GOOFIT_PARSE(app,...)
Definition: Application.h:11