rf314_paramfitrange.cxx

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #314
00004 // 
00005 // Working with parameterized ranges in a fit. This an example of a
00006 // fit with an acceptance that changes per-event 
00007 //
00008 //  pdf = exp(-t/tau) with t[tmin,5]
00009 //
00010 //  where t and tmin are both observables in the dataset
00011 //
00012 // 07/2008 - Wouter Verkerke 
00013 // 
00014 /////////////////////////////////////////////////////////////////////////
00015 
00016 #ifndef __CINT__
00017 #include "RooGlobalFunc.h"
00018 #endif
00019 #include "RooRealVar.h"
00020 #include "RooDataSet.h"
00021 #include "RooGaussian.h"
00022 #include "RooExponential.h"
00023 #include "TCanvas.h"
00024 #include "RooPlot.h"
00025 #include "RooFitResult.h"
00026 
00027 using namespace RooFit ;
00028 
00029 
00030 class TestBasic314 : public RooFitTestUnit
00031 {
00032 public: 
00033   TestBasic314(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Fit with non-rectangular observable boundaries",refFile,writeRef,verbose) {} ;
00034   Bool_t testCode() {
00035 
00036   // D e f i n e   o b s e r v a b l e s   a n d   d e c a y   p d f 
00037   // ---------------------------------------------------------------
00038 
00039   // Declare observables
00040   RooRealVar t("t","t",0,5) ;
00041   RooRealVar tmin("tmin","tmin",0,0,5) ;
00042 
00043   // Make parameterized range in t : [tmin,5]
00044   t.setRange(tmin,RooConst(t.getMax())) ;
00045 
00046   // Make pdf
00047   RooRealVar tau("tau","tau",-1.54,-10,-0.1) ;
00048   RooExponential model("model","model",t,tau) ;
00049 
00050 
00051 
00052   // C r e a t e   i n p u t   d a t a 
00053   // ------------------------------------
00054 
00055   // Generate complete dataset without acceptance cuts (for reference)  
00056   RooDataSet* dall = model.generate(t,10000) ;
00057 
00058   // Generate a (fake) prototype dataset for acceptance limit values
00059   RooDataSet* tmp = RooGaussian("gmin","gmin",tmin,RooConst(0),RooConst(0.5)).generate(tmin,5000) ;
00060 
00061   // Generate dataset with t values that observe (t>tmin)
00062   RooDataSet* dacc = model.generate(t,ProtoData(*tmp)) ;
00063 
00064 
00065 
00066   // F i t   p d f   t o   d a t a   i n   a c c e p t a n c e   r e g i o n
00067   // -----------------------------------------------------------------------
00068 
00069   RooFitResult* r = model.fitTo(*dacc,Save()) ;
00070 
00071 
00072  
00073   // P l o t   f i t t e d   p d f   o n   f u l l   a n d   a c c e p t e d   d a t a 
00074   // ---------------------------------------------------------------------------------
00075 
00076   // Make plot frame, add datasets and overlay model
00077   RooPlot* frame = t.frame(Title("Fit to data with per-event acceptance")) ;
00078   dall->plotOn(frame,MarkerColor(kRed),LineColor(kRed)) ;
00079   model.plotOn(frame) ;
00080   dacc->plotOn(frame,Name("dacc")) ;
00081 
00082   // Print fit results to demonstrate absence of bias
00083   regResult(r,"rf314_fit") ;
00084   regPlot(frame,"rf314_plot1") ;
00085 
00086   delete tmp ;
00087   delete dacc ;
00088   delete dall ;
00089 
00090   return kTRUE;
00091   }
00092 } ;

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