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 "RooConstVar.h" 00020 #include "RooCategory.h" 00021 #include "RooThresholdCategory.h" 00022 #include "RooBinningCategory.h" 00023 #include "Roo1DTable.h" 00024 #include "RooArgusBG.h" 00025 #include "TCanvas.h" 00026 #include "TAxis.h" 00027 #include "RooPlot.h" 00028 using namespace RooFit ; 00029 00030 00031 void rf405_realtocatfuncs() 00032 { 00033 00034 // 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 00035 // ------------------------------------------------------------------------ 00036 00037 00038 // Define a dummy PDF in x 00039 RooRealVar x("x","x",0,10) ; 00040 RooArgusBG a("a","argus(x)",x,RooConst(10),RooConst(-1)) ; 00041 00042 // Generate a dummy dataset 00043 RooDataSet *data = a.generate(x,10000) ; 00044 00045 00046 00047 // 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 00048 // -------------------------------------------------------------------------- 00049 00050 // A RooThresholdCategory is a category function that maps regions in a real-valued 00051 // input observable observables to state names. At construction time a 'default' 00052 // state name must be specified to which all values of x are mapped that are not 00053 // otherwise assigned 00054 RooThresholdCategory xRegion("xRegion","region of x",x,"Background") ; 00055 00056 // Specify thresholds and state assignments one-by-one. 00057 // Each statement specifies that all values _below_ the given value 00058 // (and above any lower specified threshold) are mapped to the 00059 // category state with the given name 00060 // 00061 // Background | SideBand | Signal | SideBand | Background 00062 // 4.23 5.23 8.23 9.23 00063 xRegion.addThreshold(4.23,"Background") ; 00064 xRegion.addThreshold(5.23,"SideBand") ; 00065 xRegion.addThreshold(8.23,"Signal") ; 00066 xRegion.addThreshold(9.23,"SideBand") ; 00067 00068 00069 00070 // 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 00071 // ------------------------------------------------------------------------------------- 00072 00073 // Add values of threshold function to dataset so that it can be used as observable 00074 data->addColumn(xRegion) ; 00075 00076 // Make plot of data in x 00077 RooPlot* xframe = x.frame(Title("Demo of threshold and binning mapping functions")) ; 00078 data->plotOn(xframe) ; 00079 00080 // Use calculated category to select sideband data 00081 data->plotOn(xframe,Cut("xRegion==xRegion::SideBand"),MarkerColor(kRed),LineColor(kRed)) ; 00082 00083 00084 00085 // 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 00086 // ---------------------------------------------------------------------- 00087 00088 // A RooBinningCategory is a category function that maps bins of a (named) binning definition 00089 // in a real-valued input observable observables to state names. The state names are automatically 00090 // constructed from the variable name, the binning name and the bin number. If no binning name 00091 // is specified the default binning is mapped 00092 00093 x.setBins(10,"coarse") ; 00094 RooBinningCategory xBins("xBins","coarse bins in x",x,"coarse") ; 00095 00096 00097 00098 // 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 00099 // ----------------------------------------------------------------------------------------------- 00100 00101 // Print table of xBins state multiplicity. Note that xBins does not need to be an observable in data 00102 // it can be a function of observables in data as well 00103 Roo1DTable* xbtable = data->table(xBins) ; 00104 xbtable->Print("v") ; 00105 00106 // Add values of xBins function to dataset so that it can be used as observable 00107 RooCategory* xb = (RooCategory*) data->addColumn(xBins) ; 00108 00109 // Define range "alt" as including bins 1,3,5,7,9 00110 xb->setRange("alt","x_coarse_bin1,x_coarse_bin3,x_coarse_bin5,x_coarse_bin7,x_coarse_bin9") ; 00111 00112 // Construct subset of data matching range "alt" but only for the first 5000 events and plot it on the frame 00113 RooDataSet* dataSel = (RooDataSet*) data->reduce(CutRange("alt"),EventRange(0,5000)) ; 00114 dataSel->plotOn(xframe,MarkerColor(kGreen),LineColor(kGreen)) ; 00115 00116 00117 00118 new TCanvas("rf405_realtocatfuncs","rf405_realtocatfuncs",600,600) ; 00119 xframe->SetMinimum(0.01) ; 00120 gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ; 00121 00122 00123 }