rf107_plotstyles.C

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'BASIC FUNCTIONALITY' RooFit tutorial macro #107
00004 // 
00005 //  Demonstration of various plotting styles of data, functions
00006 //  in a RooPlot
00007 //
00008 // 07/2008 - Wouter Verkerke 
00009 // 
00010 /////////////////////////////////////////////////////////////////////////
00011 
00012 #ifndef __CINT__
00013 #include "RooGlobalFunc.h"
00014 #endif
00015 #include "RooRealVar.h"
00016 #include "RooDataSet.h"
00017 #include "RooGaussian.h"
00018 #include "TCanvas.h"
00019 #include "TAxis.h"
00020 #include "RooPlot.h"
00021 using namespace RooFit ;
00022 
00023 
00024 void rf107_plotstyles()
00025 {
00026 
00027   // S e t u p   m o d e l 
00028   // ---------------------
00029 
00030   // Create observables
00031   RooRealVar x("x","x",-10,10) ;
00032 
00033   // Create Gaussian
00034   RooRealVar sigma("sigma","sigma",3,0.1,10) ;
00035   RooRealVar mean("mean","mean",-3,-10,10) ;
00036   RooGaussian gauss("gauss","gauss",x,mean,sigma) ;
00037 
00038   // Generate a sample of 100 events with sigma=3
00039   RooDataSet* data = gauss.generate(x,100) ;
00040 
00041   // Fit pdf to data
00042   gauss.fitTo(*data) ;
00043 
00044 
00045 
00046   // M a k e   p l o t   f r a m e s
00047   // -------------------------------
00048 
00049   // Make four plot frames to demonstrate various plotting features
00050   RooPlot* frame1 = x.frame(Name("xframe"),Title("Red Curve / SumW2 Histo errors"),Bins(20)) ;
00051   RooPlot* frame2 = x.frame(Name("xframe"),Title("Dashed Curve / No XError bars"),Bins(20)) ;
00052   RooPlot* frame3 = x.frame(Name("xframe"),Title("Filled Curve / Blue Histo"),Bins(20)) ;
00053   RooPlot* frame4 = x.frame(Name("xframe"),Title("Partial Range / Filled Bar chart"),Bins(20)) ;
00054 
00055 
00056 
00057   // D a t a   p l o t t i n g   s t y l e s 
00058   // ---------------------------------------
00059 
00060   // Use sqrt(sum(weights^2)) error instead of Poisson errors
00061   data->plotOn(frame1,DataError(RooAbsData::SumW2)) ;
00062 
00063   // Remove horizontal error bars
00064   data->plotOn(frame2,XErrorSize(0)) ;
00065 
00066   // Blue markers and error bors
00067   data->plotOn(frame3,MarkerColor(kBlue),LineColor(kBlue)) ;
00068 
00069   // Filled bar chart
00070   data->plotOn(frame4,DrawOption("B"),DataError(RooAbsData::None),XErrorSize(0),FillColor(kGray)) ;
00071 
00072 
00073 
00074   // F u n c t i o n   p l o t t i n g   s t y l e s 
00075   // -----------------------------------------------
00076 
00077   // Change line color to red
00078   gauss.plotOn(frame1,LineColor(kRed)) ;
00079 
00080   // Change line style to dashed
00081   gauss.plotOn(frame2,LineStyle(kDashed)) ;
00082 
00083   // Filled shapes in green color
00084   gauss.plotOn(frame3,DrawOption("F"),FillColor(kOrange),MoveToBack()) ;
00085 
00086   //
00087   gauss.plotOn(frame4,Range(-8,3),LineColor(kMagenta)) ;
00088 
00089 
00090 
00091   TCanvas* c = new TCanvas("rf107_plotstyles","rf107_plotstyles",800,800) ;
00092   c->Divide(2,2) ;
00093   c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.6) ; frame1->Draw() ;
00094   c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.6) ; frame2->Draw() ;
00095   c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.6) ; frame3->Draw() ;
00096   c->cd(4) ; gPad->SetLeftMargin(0.15) ; frame4->GetYaxis()->SetTitleOffset(1.6) ; frame4->Draw() ;
00097 
00098   
00099 }

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