00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __CINT__
00014 #include "RooGlobalFunc.h"
00015 #endif
00016 #include "RooRealVar.h"
00017 #include "RooDataSet.h"
00018 #include "RooDataHist.h"
00019 #include "RooGaussian.h"
00020 #include "RooConstVar.h"
00021 #include "RooCategory.h"
00022 #include "TCanvas.h"
00023 #include "TAxis.h"
00024 #include "RooPlot.h"
00025 #include "TFile.h"
00026 using namespace RooFit ;
00027
00028
00029
00030
00031 void rf402_datahandling()
00032 {
00033
00034
00035
00036
00037
00038
00039 RooRealVar x("x","x",-10,10) ;
00040 RooRealVar y("y","y", 0, 40) ;
00041 RooCategory c("c","c") ;
00042 c.defineType("Plus",+1) ;
00043 c.defineType("Minus",-1) ;
00044
00045
00046
00047
00048
00049
00050
00051 RooDataSet d("d","d",RooArgSet(x,y,c)) ;
00052
00053
00054
00055
00056
00057
00058 Int_t i ;
00059 for (i=0 ; i<1000 ; i++) {
00060 x = i/50 - 10 ;
00061 y = sqrt(1.0*i) ;
00062 c.setLabel((i%2)?"Plus":"Minus") ;
00063
00064
00065
00066 d.add(RooArgSet(x,y,c)) ;
00067 }
00068 d.Print("v") ;
00069 cout << endl ;
00070
00071
00072
00073 const RooArgSet* row = d.get() ;
00074 row->Print("v") ;
00075 cout << endl ;
00076
00077
00078
00079
00080 d.get(900)->Print("v") ;
00081 cout << endl ;
00082
00083
00084
00085
00086
00087
00088
00089 cout << endl << ">> d1 has only columns x,c" << endl ;
00090 RooDataSet* d1 = (RooDataSet*) d.reduce(RooArgSet(x,c)) ;
00091 d1->Print("v") ;
00092
00093 cout << endl << ">> d2 has only column y" << endl ;
00094 RooDataSet* d2 = (RooDataSet*) d.reduce(RooArgSet(y)) ;
00095 d2->Print("v") ;
00096
00097 cout << endl << ">> d3 has only the points with y>5.17" << endl ;
00098 RooDataSet* d3 = (RooDataSet*) d.reduce("y>5.17") ;
00099 d3->Print("v") ;
00100
00101 cout << endl << ">> d4 has only columns x,c for data points with y>5.17" << endl ;
00102 RooDataSet* d4 = (RooDataSet*) d.reduce(RooArgSet(x,c),"y>5.17") ;
00103 d4->Print("v") ;
00104
00105
00106 cout << endl << ">> merge d2(y) with d1(x,c) to form d1(x,c,y)" << endl ;
00107 d1->merge(d2) ;
00108 d1->Print("v") ;
00109
00110
00111 cout << endl << ">> append data points of d3 to d1" << endl ;
00112 d1->append(*d3) ;
00113 d1->Print("v") ;
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 cout << ">> construct dh (binned) from d(unbinned) but only take the x and y dimensions," << endl
00124 << ">> the category 'c' will be projected in the filling process" << endl ;
00125
00126
00127
00128
00129 x.setBins(10) ;
00130 y.setBins(10) ;
00131 RooDataHist dh("dh","binned version of d",RooArgSet(x,y),d) ;
00132 dh.Print("v") ;
00133
00134 RooPlot* yframe = y.frame(Bins(10),Title("Operations on binned datasets")) ;
00135 dh.plotOn(yframe) ;
00136
00137
00138 cout << ">> number of bins in dh : " << dh.numEntries() << endl ;
00139 cout << ">> sum of weights in dh : " << dh.sum(kFALSE) << endl ;
00140 cout << ">> integral over histogram: " << dh.sum(kTRUE) << endl ;
00141
00142
00143 x = 0.3 ; y = 20.5 ;
00144 cout << ">> retrieving the properties of the bin enclosing coordinate (x,y) = (0.3,20.5) " << endl ;
00145 cout << " bin center:" << endl ;
00146 dh.get(RooArgSet(x,y))->Print("v") ;
00147 cout << " weight = " << dh.weight() << endl ;
00148
00149
00150
00151
00152
00153 cout << ">> Creating 1-dimensional projection on y of dh for bins with x>0" << endl ;
00154 RooDataHist* dh2 = (RooDataHist*) dh.reduce(y,"x>0") ;
00155 dh2->Print("v") ;
00156
00157
00158 dh2->plotOn(yframe,LineColor(kRed),MarkerColor(kRed)) ;
00159
00160
00161
00162
00163
00164
00165
00166 cout << endl << ">> Persisting d via ROOT I/O" << endl ;
00167 TFile f("rf402_datahandling.root","RECREATE") ;
00168 d.Write() ;
00169 f.ls() ;
00170
00171
00172
00173
00174
00175
00176
00177 new TCanvas("rf402_datahandling","rf402_datahandling",600,600) ;
00178 gPad->SetLeftMargin(0.15) ; yframe->GetYaxis()->SetTitleOffset(1.4) ; yframe->Draw() ;
00179
00180 }