17 #include <sys/times.h> 22 int main(
int argc,
char **argv) {
28 std::mt19937 gen(137);
29 std::normal_distribution<> dx(0.2, 1.1);
30 std::normal_distribution<> dy(0.5, 0.3);
32 GooFit::setROOTStyle();
38 TH2F dataHist(
"dataHist",
45 yvar.getUpperLimit());
46 TH1F xvarHist(
"xvarHist",
"", xvar.getNumBins(), xvar.getLowerLimit(), xvar.getUpperLimit());
47 TH1F yvarHist(
"yvarHist",
"", yvar.getNumBins(), yvar.getLowerLimit(), yvar.getUpperLimit());
49 dataHist.SetStats(
false);
50 xvarHist.SetStats(
false);
51 yvarHist.SetStats(
false);
55 while(totalData < 100000) {
56 xvar.setValue(dx(gen));
57 yvar.setValue(dy(gen));
59 if(fabs(xvar.getValue()) < 5 && fabs(yvar.getValue()) < 5) {
61 dataHist.Fill(xvar.getValue(), yvar.getValue());
62 xvarHist.Fill(xvar.getValue());
63 yvarHist.Fill(yvar.getValue());
68 Variable xmean{
"xmean", 0, 1, -10, 10};
69 Variable xsigm{
"xsigm", 1, 0.5, 1.5};
72 Variable ymean{
"ymean", 0, 1, -10, 10};
73 Variable ysigm{
"ysigm", 0.4, 0.1, 0.6};
76 ProdPdf total(
"total", {&xgauss, &ygauss});
82 TH2F pdfHist(
"pdfHist",
89 yvar.getUpperLimit());
90 TH1F xpdfHist(
"xpdfHist",
"", xvar.getNumBins(), xvar.getLowerLimit(), xvar.getUpperLimit());
91 TH1F ypdfHist(
"ypdfHist",
"", yvar.getNumBins(), yvar.getLowerLimit(), yvar.getUpperLimit());
93 pdfHist.SetStats(
false);
94 xpdfHist.SetStats(
false);
95 ypdfHist.SetStats(
false);
99 std::vector<std::vector<double>> pdfVals = total.getCompProbsAtDataPoints();
102 dataHist.Draw(
"colz");
103 foo.SaveAs(
"data.png");
109 pdfHist.Fill(xvar.getValue(), yvar.getValue(), pdfVals[0][i]);
110 xpdfHist.Fill(xvar.getValue(), pdfVals[0][i]);
111 ypdfHist.Fill(yvar.getValue(), pdfVals[0][i]);
112 totalPdf += pdfVals[0][i];
115 for(
int i = 0; i < xvar.getNumBins(); ++i) {
116 double val = xpdfHist.GetBinContent(i + 1);
119 xpdfHist.SetBinContent(i + 1, val);
122 for(
int i = 0; i < yvar.getNumBins(); ++i) {
123 double val = ypdfHist.GetBinContent(i + 1);
126 ypdfHist.SetBinContent(i + 1, val);
128 for(
int j = 0; j < xvar.getNumBins(); ++j) {
129 val = pdfHist.GetBinContent(j + 1, i + 1);
132 pdfHist.SetBinContent(j + 1, i + 1, val);
136 pdfHist.Draw(
"colz");
137 foo.SaveAs(
"pdf.png");
139 for(
int i = 0; i < yvar.getNumBins(); ++i) {
140 for(
int j = 0; j < xvar.getNumBins(); ++j) {
141 double pval = pdfHist.GetBinContent(j + 1, i + 1);
142 double dval = dataHist.GetBinContent(j + 1, i + 1);
144 pval /= std::max(1.0, sqrt(dval));
145 pdfHist.SetBinContent(j + 1, i + 1, pval);
149 pdfHist.GetZaxis()->SetRangeUser(-5, 5);
150 pdfHist.Draw(
"colz");
151 foo.SaveAs(
"pull.png");
153 xvarHist.SetMarkerStyle(8);
154 xvarHist.SetMarkerSize(0.5);
156 xpdfHist.SetLineColor(kBlue);
157 xpdfHist.SetLineWidth(3);
158 xpdfHist.Draw(
"lsame");
159 foo.SaveAs(
"xhist.png");
161 yvarHist.SetMarkerStyle(8);
162 yvarHist.SetMarkerSize(0.5);
164 ypdfHist.SetLineColor(kBlue);
165 ypdfHist.SetLineWidth(3);
166 ypdfHist.Draw(
"lsame");
167 foo.SaveAs(
"yhist.png");
size_t getNumEvents() const
int main(int argc, char **argv)
Special class for observables. Used in DataSets.
__host__ void setData(DataSet *data)
ROOT::Minuit2::FunctionMinimum fit()
This runs the fit.
#define GOOFIT_PARSE(app,...)
void loadEvent(size_t idx)
Set all the variables to the current event values.