Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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_code
8/// \macro_output
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooCategory.h"
18#include "RooBinningCategory.h"
19#include "Roo1DTable.h"
20#include "RooArgusBG.h"
21#include "TCanvas.h"
22#include "TAxis.h"
23#include "RooPlot.h"
24using namespace RooFit;
25
27{
28
29 // 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
30 // ------------------------------------------------------------------------
31
32 // Define a dummy PDF in x
33 RooRealVar x("x", "x", 0, 10);
34 RooArgusBG a("a", "argus(x)", x, 10.0, -1.0);
35
36 // Generate a dummy dataset
37 std::unique_ptr<RooDataSet> data{a.generate(x, 10000)};
38
39 // 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
40 // --------------------------------------------------------------------------
41
42 // A RooThresholdCategory is a category function that maps regions in a real-valued
43 // input observable observables to state names. At construction time a 'default'
44 // state name must be specified to which all values of x are mapped that are not
45 // otherwise assigned
46 RooThresholdCategory xRegion("xRegion", "region of x", x, "Background");
47
48 // Specify thresholds and state assignments one-by-one.
49 // Each statement specifies that all values _below_ the given value
50 // (and above any lower specified threshold) are mapped to the
51 // category state with the given name
52 //
53 // Background | SideBand | Signal | SideBand | Background
54 // 4.23 5.23 8.23 9.23
55 xRegion.addThreshold(4.23, "Background");
56 xRegion.addThreshold(5.23, "SideBand");
57 xRegion.addThreshold(8.23, "Signal");
58 xRegion.addThreshold(9.23, "SideBand");
59
60 // 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
61 // -------------------------------------------------------------------------------------
62
63 // Add values of threshold function to dataset so that it can be used as observable
64 data->addColumn(xRegion);
65
66 // Make plot of data in x
67 RooPlot *xframe = x.frame(Title("Demo of threshold and binning mapping functions"));
68 data->plotOn(xframe);
69
70 // Use calculated category to select sideband data
71 data->plotOn(xframe, Cut("xRegion==xRegion::SideBand"), MarkerColor(kRed), LineColor(kRed));
72
73 // 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
74 // ----------------------------------------------------------------------
75
76 // A RooBinningCategory is a category function that maps bins of a (named) binning definition
77 // in a real-valued input observable observables to state names. The state names are automatically
78 // constructed from the variable name, the binning name and the bin number. If no binning name
79 // is specified the default binning is mapped
80
81 x.setBins(10, "coarse");
82 RooBinningCategory xBins("xBins", "coarse bins in x", x, "coarse");
83
84 // 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
85 // -----------------------------------------------------------------------------------------------
86
87 // Print table of xBins state multiplicity. Note that xBins does not need to be an observable in data
88 // it can be a function of observables in data as well
89 Roo1DTable *xbtable = data->table(xBins);
90 xbtable->Print("v");
91
92 // Add values of xBins function to dataset so that it can be used as observable
93 RooCategory *xb = (RooCategory *)data->addColumn(xBins);
94
95 // Define range "alt" as including bins 1,3,5,7,9
96 xb->setRange("alt", "x_coarse_bin1,x_coarse_bin3,x_coarse_bin5,x_coarse_bin7,x_coarse_bin9");
97
98 // Construct subset of data matching range "alt" but only for the first 5000 events and plot it on the frame
99 std::unique_ptr<RooAbsData> dataSel{data->reduce(CutRange("alt"), EventRange(0, 5000))};
100 dataSel->plotOn(xframe, MarkerColor(kGreen), LineColor(kGreen));
101
102 new TCanvas("rf405_realtocatfuncs", "rf405_realtocatfuncs", 600, 600);
103 xframe->SetMinimum(0.01);
104 gPad->SetLeftMargin(0.15);
105 xframe->GetYaxis()->SetTitleOffset(1.4);
106 xframe->Draw();
107}
#define a(i)
Definition RSha256.hxx:99
@ 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
One-dimensional table.
Definition Roo1DTable.h:23
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
Definition Roo1DTable.h:50
RooArgusBG is a RooAbsPdf implementation describing the ARGUS background shape.
Definition RooArgusBG.h:22
Provides a real-to-category mapping defined by a series of thresholds.
Object to represent discrete states.
Definition RooCategory.h:28
void setRange(const char *rangeName, const char *stateNameList)
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:185
virtual void SetMinimum(double minimum=-1111)
Set minimum value of Y axis.
Definition RooPlot.cxx:1007
TAxis * GetYaxis() const
Definition RooPlot.cxx:1224
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:597
Variable that can be changed from the outside.
Definition RooRealVar.h:37
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:298
The Canvas class.
Definition TCanvas.h:23
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 JSONIO.h:26
const char * Title
Definition TXMLSetup.cxx:68