21 using namespace RooFit;
25 void rf402_datahandling()
33 RooRealVar x(
"x",
"x", -10, 10);
34 RooRealVar y(
"y",
"y", 0, 40);
35 RooCategory c(
"c",
"c");
36 c.defineType(
"Plus", +1);
37 c.defineType(
"Minus", -1);
43 RooDataSet d(
"d",
"d", RooArgSet(x, y, c));
51 for (i = 0; i < 1000; i++) {
54 c.setLabel((i % 2) ?
"Plus" :
"Minus");
58 d.add(RooArgSet(x, y, c));
65 const RooArgSet *row = d.get();
72 d.get(900)->Print(
"v");
79 cout << endl <<
">> d1 has only columns x,c" << endl;
80 RooDataSet *d1 = (RooDataSet *)d.reduce(RooArgSet(x, c));
83 cout << endl <<
">> d2 has only column y" << endl;
84 RooDataSet *d2 = (RooDataSet *)d.reduce(RooArgSet(y));
87 cout << endl <<
">> d3 has only the points with y>5.17" << endl;
88 RooDataSet *d3 = (RooDataSet *)d.reduce(
"y>5.17");
91 cout << endl <<
">> d4 has only columns x,c for data points with y>5.17" << endl;
92 RooDataSet *d4 = (RooDataSet *)d.reduce(RooArgSet(x, c),
"y>5.17");
96 cout << endl <<
">> merge d2(y) with d1(x,c) to form d1(x,c,y)" << endl;
101 cout << endl <<
">> append data points of d3 to d1" << endl;
111 cout <<
">> construct dh (binned) from d(unbinned) but only take the x and y dimensions," << endl
112 <<
">> the category 'c' will be projected in the filling process" << endl;
119 RooDataHist dh(
"dh",
"binned version of d", RooArgSet(x, y), d);
122 RooPlot *yframe = y.frame(Bins(10), Title(
"Operations on binned datasets"));
126 cout <<
">> number of bins in dh : " << dh.numEntries() << endl;
127 cout <<
">> sum of weights in dh : " << dh.sum(kFALSE) << endl;
128 cout <<
">> integral over histogram: " << dh.sum(kTRUE) << endl;
133 cout <<
">> retrieving the properties of the bin enclosing coordinate (x,y) = (0.3,20.5) " << endl;
134 cout <<
" bin center:" << endl;
135 dh.get(RooArgSet(x, y))->Print(
"v");
136 cout <<
" weight = " << dh.weight() << endl;
142 cout <<
">> Creating 1-dimensional projection on y of dh for bins with x>0" << endl;
143 RooDataHist *dh2 = (RooDataHist *)dh.reduce(y,
"x>0");
147 dh2->plotOn(yframe, LineColor(kRed), MarkerColor(kRed));
153 cout << endl <<
">> Persisting d via ROOT I/O" << endl;
154 TFile f(
"rf402_datahandling.root",
"RECREATE");
162 new TCanvas(
"rf402_datahandling",
"rf402_datahandling", 600, 600);
163 gPad->SetLeftMargin(0.15);
164 yframe->GetYaxis()->SetTitleOffset(1.4);