ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rf405_realtocatfuncs.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// 'DATA AND CATEGORIES' RooFit tutorial macro #405
4 ///
5 /// Demonstration of real-->discrete mapping functions
6 ///
7 ///
8 ///
9 /// \macro_code
10 /// \author 07/2008 - Wouter Verkerke
11 
12 
13 #ifndef __CINT__
14 #include "RooGlobalFunc.h"
15 #endif
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooGaussian.h"
19 #include "RooConstVar.h"
20 #include "RooCategory.h"
21 #include "RooThresholdCategory.h"
22 #include "RooBinningCategory.h"
23 #include "Roo1DTable.h"
24 #include "RooArgusBG.h"
25 #include "TCanvas.h"
26 #include "TAxis.h"
27 #include "RooPlot.h"
28 using namespace RooFit ;
29 
30 
31 void rf405_realtocatfuncs()
32 {
33 
34  // 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
35  // ------------------------------------------------------------------------
36 
37 
38  // Define a dummy PDF in x
39  RooRealVar x("x","x",0,10) ;
40  RooArgusBG a("a","argus(x)",x,RooConst(10),RooConst(-1)) ;
41 
42  // Generate a dummy dataset
43  RooDataSet *data = a.generate(x,10000) ;
44 
45 
46 
47  // 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
48  // --------------------------------------------------------------------------
49 
50  // A RooThresholdCategory is a category function that maps regions in a real-valued
51  // input observable observables to state names. At construction time a 'default'
52  // state name must be specified to which all values of x are mapped that are not
53  // otherwise assigned
54  RooThresholdCategory xRegion("xRegion","region of x",x,"Background") ;
55 
56  // Specify thresholds and state assignments one-by-one.
57  // Each statement specifies that all values _below_ the given value
58  // (and above any lower specified threshold) are mapped to the
59  // category state with the given name
60  //
61  // Background | SideBand | Signal | SideBand | Background
62  // 4.23 5.23 8.23 9.23
63  xRegion.addThreshold(4.23,"Background") ;
64  xRegion.addThreshold(5.23,"SideBand") ;
65  xRegion.addThreshold(8.23,"Signal") ;
66  xRegion.addThreshold(9.23,"SideBand") ;
67 
68 
69 
70  // 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
71  // -------------------------------------------------------------------------------------
72 
73  // Add values of threshold function to dataset so that it can be used as observable
74  data->addColumn(xRegion) ;
75 
76  // Make plot of data in x
77  RooPlot* xframe = x.frame(Title("Demo of threshold and binning mapping functions")) ;
78  data->plotOn(xframe) ;
79 
80  // Use calculated category to select sideband data
81  data->plotOn(xframe,Cut("xRegion==xRegion::SideBand"),MarkerColor(kRed),LineColor(kRed)) ;
82 
83 
84 
85  // 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
86  // ----------------------------------------------------------------------
87 
88  // A RooBinningCategory is a category function that maps bins of a (named) binning definition
89  // in a real-valued input observable observables to state names. The state names are automatically
90  // constructed from the variable name, the binning name and the bin number. If no binning name
91  // is specified the default binning is mapped
92 
93  x.setBins(10,"coarse") ;
94  RooBinningCategory xBins("xBins","coarse bins in x",x,"coarse") ;
95 
96 
97 
98  // 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
99  // -----------------------------------------------------------------------------------------------
100 
101  // Print table of xBins state multiplicity. Note that xBins does not need to be an observable in data
102  // it can be a function of observables in data as well
103  Roo1DTable* xbtable = data->table(xBins) ;
104  xbtable->Print("v") ;
105 
106  // Add values of xBins function to dataset so that it can be used as observable
107  RooCategory* xb = (RooCategory*) data->addColumn(xBins) ;
108 
109  // Define range "alt" as including bins 1,3,5,7,9
110  xb->setRange("alt","x_coarse_bin1,x_coarse_bin3,x_coarse_bin5,x_coarse_bin7,x_coarse_bin9") ;
111 
112  // Construct subset of data matching range "alt" but only for the first 5000 events and plot it on the frame
113  RooDataSet* dataSel = (RooDataSet*) data->reduce(CutRange("alt"),EventRange(0,5000)) ;
114  dataSel->plotOn(xframe,MarkerColor(kGreen),LineColor(kGreen)) ;
115 
116 
117 
118  new TCanvas("rf405_realtocatfuncs","rf405_realtocatfuncs",600,600) ;
119  xframe->SetMinimum(0.01) ;
120  gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ;
121 
122 
123 }
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:245
RooCmdArg Cut(const char *cutSpec)
virtual Roo1DTable * table(const RooArgSet &catSet, const char *cuts="", const char *opts="") const
Construct table for product of categories in catSet.
Definition: RooAbsData.cxx:835
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:61
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1118
TArc * a
Definition: textangle.C:12
RooAbsData * reduce(const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg())
Create a reduced copy of this dataset.
Definition: RooAbsData.cxx:399
Definition: Rtypes.h:61
RooCmdArg Title(const char *name)
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum value of Y axis.
Definition: RooPlot.cxx:959
RooArgusBG is a RooAbsPdf implementation describing the ARGUS background shape.
Definition: RooArgusBG.h:25
Double_t x[n]
Definition: legend1.C:17
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a column with the values of the given (function) argument to this dataset.
Class RooThresholdCategory provides a real-to-category mapping defined by a series of thresholds...
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Plot dataset on specified frame.
Definition: RooAbsData.cxx:626
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
Class RooBinningCategory provides a real-to-category mapping defined by a series of thresholds...
RooCmdArg CutRange(const char *rangeName)
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: Roo1DTable.h:52
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:25
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
RooCmdArg EventRange(Int_t nStart, Int_t nStop)
RooConstVar & RooConst(Double_t val)
#define gPad
Definition: TVirtualPad.h:288
RooCmdArg MarkerColor(Color_t color)
void setRange(const char *rangeName, const char *stateNameList)
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:25
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559