FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RooDataGenerator.h
Go to the documentation of this file.
1 /*
2  * File: RooDataGenerator.h
3  * Author: winckler
4  *
5  * Created on December 11, 2014, 1:16 PM
6  */
7 
8 #ifndef ROODATAGENERATOR_H
9 #define ROODATAGENERATOR_H
10 
11 // root
12 #include <TDatime.h>
13 
14 // roofit
15 #include "RooArgSet.h"
16 #include "RooConstVar.h"
17 #include "RooDataSet.h"
18 #include "RooGaussian.h"
19 #include "RooGlobalFunc.h"
20 #include "RooProdPdf.h"
21 #include "RooRandom.h"
22 #include "RooRealVar.h"
23 
25 {
26  RdmVarParameters(double min, double max, double mean, double sigma)
27  : fMin(min)
28  , fMax(max)
29  , fMean(mean)
30  , fSigma(sigma)
31  {}
32 
33  RdmVarParameters(double mean, double sigma)
34  : fMin(mean - 6 * sigma)
35  , fMax(mean + 6 * sigma)
36  , fMean(mean)
37  , fSigma(sigma)
38  {}
39 
40  double fMin;
41  double fMax;
42  double fMean;
43  double fSigma;
44 };
45 
46 struct PDFConfig
47 {
49  : fX(-10, 3)
50  , fY(10, 2)
51  , fZ(0, 0.5)
52  , fTErr(0.005, 0.001)
53  {}
54 
55  void Set(const RdmVarParameters& x,
56  const RdmVarParameters& y,
57  const RdmVarParameters& z,
58  const RdmVarParameters& terr)
59  {
60  fX = x;
61  fY = y;
62  fZ = z;
63  fTErr = terr;
64  }
65 
70 };
71 
73 {
74  public:
75  MultiVariatePDF(unsigned int tStart = 0)
76  : MultiVariatePDF(PDFConfig(), tStart)
77  {}
78 
79  MultiVariatePDF(const PDFConfig& opt, unsigned int tStart = 0)
80  : fOpt(opt)
81  , fX("x", "x", fOpt.fX.fMin, fOpt.fX.fMax)
82  , fY("y", "y", fOpt.fY.fMin, fOpt.fY.fMax)
83  , fZ("z", "z", fOpt.fZ.fMin, fOpt.fZ.fMax)
84  , fT("t", "t", static_cast<double>(tStart), static_cast<double>(tStart + 1))
85  , fTErr("tErr", "tErr", fOpt.fTErr.fMin, fOpt.fTErr.fMax)
86  , fMeanT("mu_t", "mean of t-distribution", (static_cast<double>(tStart) + static_cast<double>(tStart + 1)) / 2)
87  , fSigmaT("fSigmaT", "width of t-distribution", 0.1)
88  , fGaussX("fGaussX", "gaussian PDF", fX, RooFit::RooConst(fOpt.fX.fMean), RooFit::RooConst(fOpt.fX.fSigma))
89  , fGaussY("fGaussY", "gaussian PDF", fY, RooFit::RooConst(fOpt.fY.fMean), RooFit::RooConst(fOpt.fY.fSigma))
90  , fGaussZ("fGaussZ", "gaussian PDF", fZ, RooFit::RooConst(fOpt.fZ.fMean), RooFit::RooConst(fOpt.fZ.fSigma))
91  , fGaussT("fGaussT", "gaussian PDF", fT, fMeanT, fSigmaT)
92  , fGaussTErr("fGaussTErr",
93  "gaussian PDF",
94  fTErr,
95  RooFit::RooConst((fTErr.getMin() + fTErr.getMax()) / 2),
96  RooFit::RooConst(fOpt.fTErr.fSigma))
97  , fModel("fGaussXyzt_ter",
98  "fGaussX*fGaussY*fGaussZ*fGaussT*fGaussTErr",
99  RooArgList(fGaussX, fGaussY, fGaussZ, fGaussT, fGaussTErr))
100  {
101  RooMsgService::instance().setGlobalKillBelow(RooFit::MsgLevel::ERROR);
102  RooRandom::randomGenerator()->SetSeed(TDatime().GetTime());
103  }
104 
105  MultiVariatePDF(const MultiVariatePDF&) = delete;
106  MultiVariatePDF operator=(const MultiVariatePDF&) = delete;
107 
109 
110  RooDataSet* GetGeneratedData(unsigned int n, unsigned int ti)
111  {
112  fT.setRange(static_cast<double>(ti), static_cast<double>(ti + 1));
113  fMeanT.setVal(static_cast<double>(ti + 0.5));
114  return fModel.generate(RooArgSet(fX, fY, fZ, fT, fTErr), n);
115  }
116 
117  private:
118  PDFConfig fOpt;
119 
120  RooRealVar fX;
121  RooRealVar fY;
122  RooRealVar fZ;
123  RooRealVar fT;
124  RooRealVar fTErr;
125 
126  RooRealVar fMeanT;
127  RooRealVar fSigmaT;
128 
129  RooGaussian fGaussX;
130  RooGaussian fGaussY;
131  RooGaussian fGaussZ;
132  RooGaussian fGaussT;
133  RooGaussian fGaussTErr;
134 
135  RooProdPdf fModel;
136 };
137 
138 #endif /* ROODATAGENERATOR_H */
MultiVariatePDF(const PDFConfig &opt, unsigned int tStart=0)
void Set(const RdmVarParameters &x, const RdmVarParameters &y, const RdmVarParameters &z, const RdmVarParameters &terr)
RdmVarParameters fY
RooDataSet * GetGeneratedData(unsigned int n, unsigned int ti)
RdmVarParameters(double mean, double sigma)
RdmVarParameters fZ
MultiVariatePDF operator=(const MultiVariatePDF &)=delete
RdmVarParameters(double min, double max, double mean, double sigma)
MultiVariatePDF(unsigned int tStart=0)
RdmVarParameters fTErr
RdmVarParameters fX