rf405_realtocatfuncs.cxx

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'DATA AND CATEGORIES' RooFit tutorial macro #405
00004 // 
00005 // Demonstration of real-->discrete mapping functions
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 "RooGaussian.h"
00019 #include "RooCategory.h"
00020 #include "RooThresholdCategory.h"
00021 #include "RooBinningCategory.h"
00022 #include "Roo1DTable.h"
00023 #include "RooArgusBG.h"
00024 #include "TCanvas.h"
00025 #include "RooPlot.h"
00026 using namespace RooFit ;
00027 
00028 
00029 class TestBasic405 : public RooFitTestUnit
00030 {
00031 public: 
00032   TestBasic405(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Real-to-category functions",refFile,writeRef,verbose) {} ;
00033   Bool_t testCode() {
00034 
00035 
00036   // D e f i n e   p d f   i n   x ,   s a m p l e   d a t a s e t   i n   x 
00037   // ------------------------------------------------------------------------
00038 
00039 
00040   // Define a dummy PDF in x 
00041   RooRealVar x("x","x",0,10) ;
00042   RooArgusBG a("a","argus(x)",x,RooRealConstant::value(10),RooRealConstant::value(-1)) ;
00043 
00044   // Generate a dummy dataset 
00045   RooDataSet *data = a.generate(x,10000) ;
00046 
00047 
00048 
00049   // C r e a t e   a   t h r e s h o l d   r e a l - > c a t   f u n c t i o n
00050   // --------------------------------------------------------------------------
00051 
00052   // A RooThresholdCategory is a category function that maps regions in a real-valued 
00053   // input observable observables to state names. At construction time a 'default'
00054   // state name must be specified to which all values of x are mapped that are not
00055   // otherwise assigned
00056   RooThresholdCategory xRegion("xRegion","region of x",x,"Background") ;
00057 
00058   // Specify thresholds and state assignments one-by-one. 
00059   // Each statement specifies that all values _below_ the given value 
00060   // (and above any lower specified threshold) are mapped to the
00061   // category state with the given name
00062   //
00063   // Background | SideBand | Signal | SideBand | Background
00064   //           4.23       5.23     8.23       9.23 
00065   xRegion.addThreshold(4.23,"Background") ;
00066   xRegion.addThreshold(5.23,"SideBand") ;
00067   xRegion.addThreshold(8.23,"Signal") ;
00068   xRegion.addThreshold(9.23,"SideBand") ; 
00069 
00070 
00071 
00072   // U s e   t h r e s h o l d   f u n c t i o n   t o   p l o t   d a t a   r e g i o n s
00073   // -------------------------------------------------------------------------------------
00074 
00075   // Add values of threshold function to dataset so that it can be used as observable
00076   data->addColumn(xRegion) ;
00077 
00078   // Make plot of data in x
00079   RooPlot* xframe = x.frame(Title("Demo of threshold and binning mapping functions")) ;
00080   data->plotOn(xframe) ;
00081 
00082   // Use calculated category to select sideband data
00083   data->plotOn(xframe,Cut("xRegion==xRegion::SideBand"),MarkerColor(kRed),LineColor(kRed),Name("data_cut")) ;
00084 
00085 
00086 
00087   // C r e a t e   a   b i n n i n g    r e a l - > c a t   f u n c t i o n
00088   // ----------------------------------------------------------------------
00089 
00090   // A RooBinningCategory is a category function that maps bins of a (named) binning definition 
00091   // in a real-valued input observable observables to state names. The state names are automatically
00092   // constructed from the variable name, the binning name and the bin number. If no binning name
00093   // is specified the default binning is mapped
00094 
00095   x.setBins(10,"coarse") ;
00096   RooBinningCategory xBins("xBins","coarse bins in x",x,"coarse") ;
00097 
00098 
00099 
00100   // U s e   b i n n i n g   f u n c t i o n   f o r   t a b u l a t i o n   a n d   p l o t t i n g
00101   // -----------------------------------------------------------------------------------------------
00102 
00103   // Print table of xBins state multiplicity. Note that xBins does not need to be an observable in data
00104   // it can be a function of observables in data as well
00105   Roo1DTable* xbtable = data->table(xBins) ;
00106 
00107   // Add values of xBins function to dataset so that it can be used as observable
00108   RooCategory* xb = (RooCategory*) data->addColumn(xBins) ;
00109 
00110   // Define range "alt" as including bins 1,3,5,7,9 
00111   xb->setRange("alt","x_coarse_bin1,x_coarse_bin3,x_coarse_bin5,x_coarse_bin7,x_coarse_bin9") ;
00112   
00113   // Construct subset of data matching range "alt" but only for the first 5000 events and plot it on the fram
00114   RooDataSet* dataSel = (RooDataSet*) data->reduce(CutRange("alt"),EventRange(0,5000)) ;
00115 //   dataSel->plotOn(xframe,MarkerColor(kGreen),LineColor(kGreen),Name("data_sel")) ;
00116 
00117 
00118   regTable(xbtable,"rf405_xbtable") ;
00119   regPlot(xframe,"rf405_plot1") ;
00120   
00121   delete data ;
00122   delete dataSel ;
00123 
00124   return kTRUE ;
00125 
00126   }
00127 
00128 } ;

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