Logo ROOT   6.18/05
Reference Guide
rf404_categories.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -nodraw
4/// Data and categories: working with RooCategory objects to describe discrete variables
5///
6/// \macro_output
7/// \macro_code
8/// \author 07/2008 - Wouter Verkerke
9
10#include "RooRealVar.h"
11#include "RooDataSet.h"
12#include "RooPolynomial.h"
13#include "RooCategory.h"
14#include "Roo1DTable.h"
15#include "RooGaussian.h"
16#include "RooConstVar.h"
17#include "TCanvas.h"
18#include "TAxis.h"
19#include "RooPlot.h"
20using namespace RooFit;
21
23{
24
25 // C o n s t r u c t a c a t e g o r y w i t h l a b e l s
26 // ----------------------------------------------------------------
27
28 // Define a category with labels only
29 RooCategory tagCat("tagCat", "Tagging category");
30 tagCat.defineType("Lepton");
31 tagCat.defineType("Kaon");
32 tagCat.defineType("NetTagger-1");
33 tagCat.defineType("NetTagger-2");
34 tagCat.Print();
35
36 // C o n s t r u c t a c a t e g o r y w i t h l a b e l s a n d i n d e c e s
37 // ----------------------------------------------------------------------------------------
38
39 // Define a category with explicitly numbered states
40 RooCategory b0flav("b0flav", "B0 flavour eigenstate");
41 b0flav.defineType("B0", -1);
42 b0flav.defineType("B0bar", 1);
43 b0flav.Print();
44
45 // G e n e r a t e d u m m y d a t a f o r t a b u l a t i o n d e m o
46 // ----------------------------------------------------------------------------
47
48 // Generate a dummy dataset
49 RooRealVar x("x", "x", 0, 10);
50 RooDataSet *data = RooPolynomial("p", "p", x).generate(RooArgSet(x, b0flav, tagCat), 10000);
51
52 // P r i n t t a b l e s o f c a t e g o r y c o n t e n t s o f d a t a s e t s
53 // ------------------------------------------------------------------------------------------
54
55 // Tables are equivalent of plots for categories
56 Roo1DTable *btable = data->table(b0flav);
57 btable->Print();
58 btable->Print("v");
59
60 // Create table for subset of events matching cut expression
61 Roo1DTable *ttable = data->table(tagCat, "x>8.23");
62 ttable->Print();
63 ttable->Print("v");
64
65 // Create table for all (tagCat x b0flav) state combinations
66 Roo1DTable *bttable = data->table(RooArgSet(tagCat, b0flav));
67 bttable->Print("v");
68
69 // Retrieve number of events from table
70 // Number can be non-integer if source dataset has weighed events
71 Double_t nb0 = btable->get("B0");
72 cout << "Number of events with B0 flavor is " << nb0 << endl;
73
74 // Retrieve fraction of events with "Lepton" tag
75 Double_t fracLep = ttable->getFrac("Lepton");
76 cout << "Fraction of events tagged with Lepton tag is " << fracLep << endl;
77
78 // D e f i n i n g r a n g e s f o r p l o t t i n g , f i t t i n g o n c a t e g o r i e s
79 // ------------------------------------------------------------------------------------------------------
80
81 // Define named range as comma separated list of labels
82 tagCat.setRange("good", "Lepton,Kaon");
83
84 // Or add state names one by one
85 tagCat.addToRange("soso", "NetTagger-1");
86 tagCat.addToRange("soso", "NetTagger-2");
87
88 // Use category range in dataset reduction specification
89 RooDataSet *goodData = (RooDataSet *)data->reduce(CutRange("good"));
90 goodData->table(tagCat)->Print("v");
91}
double Double_t
Definition: RtypesCore.h:55
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:24
Double_t get(const char *label, Bool_t silent=kFALSE) const
Return the table entry named 'label'.
Definition: Roo1DTable.cxx:244
Double_t getFrac(const char *label, Bool_t silent=kFALSE) const
Return the fraction of entries in the table contained in the slot named 'label'.
Definition: Roo1DTable.cxx:301
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: Roo1DTable.h:51
virtual Roo1DTable * table(const RooArgSet &catSet, const char *cuts="", const char *opts="") const
Construct table for product of categories in catSet.
Definition: RooAbsData.cxx:754
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:381
RooDataSet * generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none())
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
Definition: RooAbsPdf.h:56
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:24
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
Double_t x[n]
Definition: legend1.C:17
Template specialisation used in RooAbsArg:
RooCmdArg CutRange(const char *rangeName)