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 "TCanvas.h"
00021 #include "RooPlot.h"
00022 #include "TTree.h"
00023 #include "TH1D.h"
00024 #include "TRandom.h"
00025 using namespace RooFit ;
00026
00027 TH1* makeTH1() ;
00028 TTree* makeTTree() ;
00029
00030
00031 void rf102_dataimport()
00032 {
00033
00034
00035
00036
00037
00038
00039
00040
00041 TH1* hh = makeTH1() ;
00042
00043
00044 RooRealVar x("x","x",-10,10) ;
00045
00046
00047 RooDataHist dh("dh","dh",x,Import(*hh)) ;
00048
00049
00050
00051
00052
00053
00054 RooPlot* frame = x.frame(Title("Imported TH1 with Poisson error bars")) ;
00055 dh.plotOn(frame) ;
00056
00057
00058 RooRealVar mean("mean","mean",0,-10,10) ;
00059 RooRealVar sigma("sigma","sigma",3,0.1,10) ;
00060 RooGaussian gauss("gauss","gauss",x,mean,sigma) ;
00061 gauss.fitTo(dh) ;
00062 gauss.plotOn(frame) ;
00063
00064
00065
00066
00067
00068
00069
00070 RooPlot* frame2 = x.frame(Title("Imported TH1 with internal errors")) ;
00071 dh.plotOn(frame2,DataError(RooAbsData::SumW2)) ;
00072 gauss.plotOn(frame2) ;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 TTree* tree = makeTTree() ;
00091
00092
00093 RooRealVar y("y","y",-10,10) ;
00094
00095
00096
00097
00098
00099
00100
00101
00102 RooDataSet ds("ds","ds",RooArgSet(x,y),Import(*tree)) ;
00103
00104
00105
00106
00107
00108
00109 ds.Print() ;
00110
00111
00112 RooPlot* frame3 = y.frame(Title("Unbinned data shown in default frame binning")) ;
00113 ds.plotOn(frame3) ;
00114
00115
00116 RooPlot* frame4 = y.frame(Title("Unbinned data shown with custom binning")) ;
00117 ds.plotOn(frame4,Binning(20)) ;
00118
00119
00120 TCanvas* c = new TCanvas("rf102_dataimport","rf102_dataimport",800,800) ;
00121 c->Divide(2,2) ;
00122 c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
00123 c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
00124 c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.4) ; frame3->Draw() ;
00125 c->cd(4) ; gPad->SetLeftMargin(0.15) ; frame4->GetYaxis()->SetTitleOffset(1.4) ; frame4->Draw() ;
00126
00127 }
00128
00129
00130
00131
00132 TH1* makeTH1()
00133 {
00134
00135
00136 TH1D* hh = new TH1D("hh","hh",25,-10,10) ;
00137 for (int i=0 ; i<100 ; i++) {
00138 hh->Fill(gRandom->Gaus(0,3)) ;
00139 }
00140 return hh ;
00141 }
00142
00143
00144 TTree* makeTTree()
00145 {
00146
00147
00148 TTree* tree = new TTree("tree","tree") ;
00149 Double_t* px = new Double_t ;
00150 Double_t* py = new Double_t ;
00151 tree->Branch("x",px,"x/D") ;
00152 tree->Branch("y",py,"y/D") ;
00153 for (int i=0 ; i<100 ; i++) {
00154 *px = gRandom->Gaus(0,3) ;
00155 *py = gRandom->Uniform()*30 - 15 ;
00156 tree->Fill() ;
00157 }
00158 return tree ;
00159 }
00160
00161