rf309_ndimplot.C

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #308
00004 // 
00005 // Making 2/3 dimensional plots of p.d.f.s and datasets
00006 //
00007 //
00008 //
00009 // 07/2008 - Wouter Verkerke 
00010 // 
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef __CINT__
00014 #include "RooGlobalFunc.h"
00015 #endif
00016 #include "RooRealVar.h"
00017 #include "RooDataSet.h"
00018 #include "RooConstVar.h"
00019 #include "RooGaussian.h"
00020 #include "RooProdPdf.h"
00021 #include "TCanvas.h"
00022 #include "TAxis.h"
00023 #include "TH1.h"
00024 #include "RooPlot.h"
00025 using namespace RooFit ;
00026 
00027 
00028 void rf309_ndimplot()
00029 {
00030 
00031   // C r e a t e   2 D   m o d e l   a n d   d a t a s e t
00032   // -----------------------------------------------------
00033 
00034   // Create observables
00035   RooRealVar x("x","x",-5,5) ;
00036   RooRealVar y("y","y",-5,5) ;
00037 
00038   // Create parameters
00039   RooRealVar a0("a0","a0",-3.5,-5,5) ;
00040   RooRealVar a1("a1","a1",-1.5,-1,1) ;
00041   RooRealVar sigma("sigma","width of gaussian",1.5) ;
00042 
00043   // Create interpreted function f(y) = a0 - a1*sqrt(10*abs(y))
00044   RooFormulaVar fy("fy","a0-a1*sqrt(10*abs(y))",RooArgSet(y,a0,a1)) ;
00045 
00046   // Create gauss(x,f(y),s)
00047   RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;
00048 
00049   // Sample dataset from gauss(x,y)
00050   RooDataSet* data = model.generate(RooArgSet(x,y),10000) ;
00051 
00052 
00053   // M a k e   2 D   p l o t s   o f   d a t a   a n d   m o d e l
00054   // -------------------------------------------------------------
00055 
00056   // Create and fill ROOT 2D histogram (20x20 bins) with contents of dataset
00057   //TH2D* hh_data = data->createHistogram("hh_data",x,Binning(20),YVar(y,Binning(20))) ;
00058   TH1* hh_data = data->createHistogram("x,y",20,20) ;
00059 
00060   // Create and fill ROOT 2D histogram (50x50 bins) with sampling of pdf
00061   //TH2D* hh_pdf = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
00062   TH1* hh_pdf = model.createHistogram("x,y",50,50) ;
00063   hh_pdf->SetLineColor(kBlue) ;
00064 
00065 
00066   // C r e a t e   3 D   m o d e l   a n d   d a t a s e t
00067   // -----------------------------------------------------
00068 
00069   // Create observables
00070   RooRealVar z("z","z",-5,5) ;
00071 
00072   RooGaussian gz("gz","gz",z,RooConst(0),RooConst(2)) ;
00073   RooProdPdf model3("model3","model3",RooArgSet(model,gz)) ;
00074 
00075   RooDataSet* data3 = model3.generate(RooArgSet(x,y,z),10000) ;
00076 
00077   
00078   // M a k e   3 D   p l o t s   o f   d a t a   a n d   m o d e l
00079   // -------------------------------------------------------------
00080 
00081   // Create and fill ROOT 2D histogram (8x8x8 bins) with contents of dataset
00082   TH1* hh_data3 = data3->createHistogram("hh_data3",x,Binning(8),YVar(y,Binning(8)),ZVar(z,Binning(8))) ;
00083 
00084   // Create and fill ROOT 2D histogram (20x20x20 bins) with sampling of pdf
00085   TH1* hh_pdf3 = model3.createHistogram("hh_model3",x,Binning(20),YVar(y,Binning(20)),ZVar(z,Binning(20))) ;
00086   hh_pdf3->SetFillColor(kBlue) ;
00087 
00088 
00089 
00090   TCanvas* c1 = new TCanvas("rf309_2dimplot","rf309_2dimplot",800,800) ;
00091   c1->Divide(2,2) ;
00092   c1->cd(1) ; gPad->SetLeftMargin(0.15) ; hh_data->GetZaxis()->SetTitleOffset(1.4) ; hh_data->Draw("lego") ; 
00093   c1->cd(2) ; gPad->SetLeftMargin(0.20) ; hh_pdf->GetZaxis()->SetTitleOffset(2.5) ; hh_pdf->Draw("surf") ;
00094   c1->cd(3) ; gPad->SetLeftMargin(0.15) ; hh_data->GetZaxis()->SetTitleOffset(1.4) ; hh_data->Draw("box") ; 
00095   c1->cd(4) ; gPad->SetLeftMargin(0.15) ; hh_pdf->GetZaxis()->SetTitleOffset(2.5) ; hh_pdf->Draw("cont3") ;
00096   
00097   TCanvas* c2 = new TCanvas("rf309_3dimplot","rf309_3dimplot",800,400) ;
00098   c2->Divide(2) ;
00099   c2->cd(1) ; gPad->SetLeftMargin(0.15) ; hh_data3->GetZaxis()->SetTitleOffset(1.4) ; hh_data3->Draw("lego") ;
00100   c2->cd(2) ; gPad->SetLeftMargin(0.15) ; hh_pdf3->GetZaxis()->SetTitleOffset(1.4) ; hh_pdf3->Draw("iso") ;
00101   
00102 }

Generated on Tue Jul 5 15:45:05 2011 for ROOT_528-00b_version by  doxygen 1.5.1