GooFit  v2.1.3
Functions
convolution.cpp File Reference
#include <goofit/Application.h>
#include <goofit/FitManager.h>
#include <goofit/PDFs/basic/BWPdf.h>
#include <goofit/PDFs/basic/GaussianPdf.h>
#include <goofit/PDFs/combine/ConvolutionPdf.h>
#include <goofit/UnbinnedDataSet.h>
#include <goofit/Variable.h>
#include <TCanvas.h>
#include <TFile.h>
#include <TH1.h>
#include <TRandom.h>

Go to the source code of this file.

Functions

double cpu_bw (double x, double x0, double gamma)
 
int main (int argc, char **argv)
 

Function Documentation

◆ cpu_bw()

double cpu_bw ( double  x,
double  x0,
double  gamma 
)

Definition at line 17 of file convolution.cpp.

Referenced by main().

17  {
18  double ret = gamma;
19  ret /= (2 * sqrt(M_PI));
20  ret /= ((x - x0) * (x - x0) + 0.25 * gamma * gamma);
21  return ret;
22 }

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 24 of file convolution.cpp.

References GooFit::UnbinnedDataSet::addEvent(), cpu_bw(), data, GooFit::FitManagerMinuit2::fit(), GooFit::Indexable::getValue(), GOOFIT_PARSE, GooFit::PdfBase::setData(), and sigma.

24  {
25  GooFit::Application app("Convolution example", argc, argv);
26 
27  GOOFIT_PARSE(app);
28 
29  // Independent variable.
30  Observable xvar{"xvar", -10, 10};
31 
32  Variable gamma{"gamma", 2, 0.1, 0.1, 5};
33  Variable sigma{"sigma", 1.5, 0.1, 0.1, 5};
34  Variable x0{"x0", 0.2, 0.05, -1, 1};
35  Variable zero{"zero", 0};
36 
37  TRandom donram(42);
38  // Data set
39  UnbinnedDataSet data(xvar);
40 
41  // Generate toy events.
42  for(int i = 0; i < 100000; ++i) {
43  xvar.setValue(donram.Uniform(20) - 10);
44 
45  double bwvalue = cpu_bw(xvar.getValue(), x0.getValue(), gamma.getValue());
46  double roll = donram.Uniform() * (2.0 / (sqrt(M_PI) * gamma.getValue()));
47 
48  if(roll > bwvalue) {
49  --i;
50  continue;
51  }
52 
53  xvar.setValue(xvar.getValue() + donram.Gaus(0, sigma.getValue()));
54 
55  if((xvar.getValue() < xvar.getLowerLimit()) || (xvar.getValue() > xvar.getUpperLimit())) {
56  --i;
57  continue;
58  }
59 
60  data.addEvent();
61  }
62 
63  BWPdf breit{"breit", xvar, x0, gamma};
64  GaussianPdf gauss{"gauss", xvar, zero, sigma};
65  ConvolutionPdf convolution{"convolution", xvar, &breit, &gauss};
66  convolution.setData(&data);
67 
68  FitManager fitter(&convolution);
69  fitter.fit();
70 
71  TFile f("output.root", "RECREATE");
72  auto toroot = convolution.plotToROOT(xvar);
73  toroot->Write();
74  f.Write();
75 
76  return fitter;
77 }
Special class for observables. Used in DataSets.
Definition: Variable.h:109
UnbinnedDataSet * data
__host__ void setData(DataSet *data)
Observable * sigma
fptype getValue() const
Get the value.
Definition: Variable.h:68
#define GOOFIT_PARSE(app,...)
Definition: Application.h:11
double cpu_bw(double x, double x0, double gamma)
Definition: convolution.cpp:17