Logo ROOT  
Reference Guide
rf405_realtocatfuncs.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// Data and categories: demonstration of real-->discrete mapping functions
5///
6/// \macro_image
7/// \macro_output
8/// \macro_code
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooConstVar.h"
17#include "RooCategory.h"
19#include "RooBinningCategory.h"
20#include "Roo1DTable.h"
21#include "RooArgusBG.h"
22#include "TCanvas.h"
23#include "TAxis.h"
24#include "RooPlot.h"
25using namespace RooFit;
26
28{
29
30 // 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
31 // ------------------------------------------------------------------------
32
33 // Define a dummy PDF in x
34 RooRealVar x("x", "x", 0, 10);
35 RooArgusBG a("a", "argus(x)", x, RooConst(10), RooConst(-1));
36
37 // Generate a dummy dataset
38 RooDataSet *data = a.generate(x, 10000);
39
40 // 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
41 // --------------------------------------------------------------------------
42
43 // A RooThresholdCategory is a category function that maps regions in a real-valued
44 // input observable observables to state names. At construction time a 'default'
45 // state name must be specified to which all values of x are mapped that are not
46 // otherwise assigned
47 RooThresholdCategory xRegion("xRegion", "region of x", x, "Background");
48
49 // Specify thresholds and state assignments one-by-one.
50 // Each statement specifies that all values _below_ the given value
51 // (and above any lower specified threshold) are mapped to the
52 // category state with the given name
53 //
54 // Background | SideBand | Signal | SideBand | Background
55 // 4.23 5.23 8.23 9.23
56 xRegion.addThreshold(4.23, "Background");
57 xRegion.addThreshold(5.23, "SideBand");
58 xRegion.addThreshold(8.23, "Signal");
59 xRegion.addThreshold(9.23, "SideBand");
60
61 // 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
62 // -------------------------------------------------------------------------------------
63
64 // Add values of threshold function to dataset so that it can be used as observable
65 data->addColumn(xRegion);
66
67 // Make plot of data in x
68 RooPlot *xframe = x.frame(Title("Demo of threshold and binning mapping functions"));
69 data->plotOn(xframe);
70
71 // Use calculated category to select sideband data
72 data->plotOn(xframe, Cut("xRegion==xRegion::SideBand"), MarkerColor(kRed), LineColor(kRed));
73
74 // 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
75 // ----------------------------------------------------------------------
76
77 // A RooBinningCategory is a category function that maps bins of a (named) binning definition
78 // in a real-valued input observable observables to state names. The state names are automatically
79 // constructed from the variable name, the binning name and the bin number. If no binning name
80 // is specified the default binning is mapped
81
82 x.setBins(10, "coarse");
83 RooBinningCategory xBins("xBins", "coarse bins in x", x, "coarse");
84
85 // 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
86 // -----------------------------------------------------------------------------------------------
87
88 // Print table of xBins state multiplicity. Note that xBins does not need to be an observable in data
89 // it can be a function of observables in data as well
90 Roo1DTable *xbtable = data->table(xBins);
91 xbtable->Print("v");
92
93 // Add values of xBins function to dataset so that it can be used as observable
94 RooCategory *xb = (RooCategory *)data->addColumn(xBins);
95
96 // Define range "alt" as including bins 1,3,5,7,9
97 xb->setRange("alt", "x_coarse_bin1,x_coarse_bin3,x_coarse_bin5,x_coarse_bin7,x_coarse_bin9");
98
99 // Construct subset of data matching range "alt" but only for the first 5000 events and plot it on the frame
100 RooDataSet *dataSel = (RooDataSet *)data->reduce(CutRange("alt"), EventRange(0, 5000));
101 dataSel->plotOn(xframe, MarkerColor(kGreen), LineColor(kGreen));
102
103 new TCanvas("rf405_realtocatfuncs", "rf405_realtocatfuncs", 600, 600);
104 xframe->SetMinimum(0.01);
105 gPad->SetLeftMargin(0.15);
106 xframe->GetYaxis()->SetTitleOffset(1.4);
107 xframe->Draw();
108}
@ kRed
Definition: Rtypes.h:66
@ kGreen
Definition: Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
Definition: TVirtualPad.h:288
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:23
void Print(Option_t *options=nullptr) const override
Print TNamed name and title.
Definition: Roo1DTable.h:50
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
Definition: RooAbsData.cxx:598
RooArgusBG is a RooAbsPdf implementation describing the ARGUS background shape.
Definition: RooArgusBG.h:22
Class RooBinningCategory provides a real-to-category mapping defined by a series of thresholds.
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:28
void setRange(const char *rangeName, const char *stateNameList)
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:43
virtual void SetMinimum(double minimum=-1111)
Set minimum value of Y axis.
Definition: RooPlot.cxx:1059
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1276
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:649
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
The RooThresholdCategory provides a real-to-category mapping defined by a series of thresholds.
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:301
The Canvas class.
Definition: TCanvas.h:23
RooConstVar & RooConst(double val)
RooCmdArg EventRange(Int_t nStart, Int_t nStop)
RooCmdArg MarkerColor(Color_t color)
RooCmdArg CutRange(const char *rangeName)
RooCmdArg Cut(const char *cutSpec)
RooCmdArg LineColor(Color_t color)
Double_t x[n]
Definition: legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18
const char * Title
Definition: TXMLSetup.cxx:68
TArc a
Definition: textangle.C:12