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 "RooCategory.h"
00021 #include "TCanvas.h"
00022 #include "RooPlot.h"
00023 #include "TFile.h"
00024 using namespace RooFit ;
00025
00026
00027 class TestBasic402 : public RooFitTestUnit
00028 {
00029 public:
00030 TestBasic402(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Basic operations on datasets",refFile,writeRef,verbose) {} ;
00031 Bool_t testCode() {
00032
00033
00034
00035
00036
00037
00038 RooRealVar x("x","x",-10,10) ;
00039 RooRealVar y("y","y", 0, 40) ;
00040 RooCategory c("c","c") ;
00041 c.defineType("Plus",+1) ;
00042 c.defineType("Minus",-1) ;
00043
00044
00045
00046
00047
00048
00049
00050 RooDataSet d("d","d",RooArgSet(x,y,c)) ;
00051
00052
00053
00054
00055
00056
00057 Int_t i ;
00058 for (i=0 ; i<1000 ; i++) {
00059 x = i/50 - 10 ;
00060 y = sqrt(1.0*i) ;
00061 c.setLabel((i%2)?"Plus":"Minus") ;
00062
00063
00064
00065 d.add(RooArgSet(x,y,c)) ;
00066 }
00067
00068
00069
00070
00071
00072
00073 RooDataSet* d1 = (RooDataSet*) d.reduce(RooArgSet(x,c)) ;
00074 RooDataSet* d2 = (RooDataSet*) d.reduce(RooArgSet(y)) ;
00075 RooDataSet* d3 = (RooDataSet*) d.reduce("y>5.17") ;
00076 RooDataSet* d4 = (RooDataSet*) d.reduce(RooArgSet(x,c),"y>5.17") ;
00077
00078 regValue(d3->numEntries(),"rf403_nd3") ;
00079 regValue(d4->numEntries(),"rf403_nd4") ;
00080
00081
00082 d1->merge(d2) ;
00083
00084
00085 d1->append(*d3) ;
00086
00087 regValue(d1->numEntries(),"rf403_nd1") ;
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 x.setBins(10) ;
00102 y.setBins(10) ;
00103 RooDataHist dh("dh","binned version of d",RooArgSet(x,y),d) ;
00104
00105 RooPlot* yframe = y.frame(Bins(10),Title("Operations on binned datasets")) ;
00106 dh.plotOn(yframe) ;
00107
00108
00109
00110
00111
00112 RooDataHist* dh2 = (RooDataHist*) dh.reduce(y,"x>0") ;
00113
00114
00115 dh2->plotOn(yframe,LineColor(kRed),MarkerColor(kRed),Name("dh2")) ;
00116
00117 regPlot(yframe,"rf402_plot1") ;
00118
00119 delete d1 ;
00120 delete d2 ;
00121 delete d3 ;
00122 delete d4 ;
00123 delete dh2 ;
00124 return kTRUE ;
00125 }
00126 } ;