Logo ROOT   6.16/01
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' RooFit tutorial macro #404
5///
6/// Working with RooCategory objects to describe discrete variables
7///
8/// \macro_output
9/// \macro_code
10/// \author 07/2008 - Wouter Verkerke
11
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooPolynomial.h"
16#include "RooCategory.h"
17#include "Roo1DTable.h"
18#include "RooGaussian.h"
19#include "RooConstVar.h"
20#include "TCanvas.h"
21#include "TAxis.h"
22#include "RooPlot.h"
23using namespace RooFit ;
24
25
27{
28
29 // 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
30 // ----------------------------------------------------------------
31
32 // Define a category with labels only
33 RooCategory tagCat("tagCat","Tagging category") ;
34 tagCat.defineType("Lepton") ;
35 tagCat.defineType("Kaon") ;
36 tagCat.defineType("NetTagger-1") ;
37 tagCat.defineType("NetTagger-2") ;
38 tagCat.Print() ;
39
40
41
42 // 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
43 // ----------------------------------------------------------------------------------------
44
45 // Define a category with explicitly numbered states
46 RooCategory b0flav("b0flav","B0 flavour eigenstate") ;
47 b0flav.defineType("B0",-1) ;
48 b0flav.defineType("B0bar",1) ;
49 b0flav.Print() ;
50
51
52
53 // 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
54 // ----------------------------------------------------------------------------
55
56 // Generate a dummy dataset
57 RooRealVar x("x","x",0,10) ;
58 RooDataSet *data = RooPolynomial("p","p",x).generate(RooArgSet(x,b0flav,tagCat),10000) ;
59
60
61
62 // 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
63 // ------------------------------------------------------------------------------------------
64
65 // Tables are equivalent of plots for categories
66 Roo1DTable* btable = data->table(b0flav) ;
67 btable->Print() ;
68 btable->Print("v") ;
69
70 // Create table for subset of events matching cut expression
71 Roo1DTable* ttable = data->table(tagCat,"x>8.23") ;
72 ttable->Print() ;
73 ttable->Print("v") ;
74
75 // Create table for all (tagCat x b0flav) state combinations
76 Roo1DTable* bttable = data->table(RooArgSet(tagCat,b0flav)) ;
77 bttable->Print("v") ;
78
79 // Retrieve number of events from table
80 // Number can be non-integer if source dataset has weighed events
81 Double_t nb0 = btable->get("B0") ;
82 cout << "Number of events with B0 flavor is " << nb0 << endl ;
83
84 // Retrieve fraction of events with "Lepton" tag
85 Double_t fracLep = ttable->getFrac("Lepton") ;
86 cout << "Fraction of events tagged with Lepton tag is " << fracLep << endl ;
87
88
89
90 // 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
91 // ------------------------------------------------------------------------------------------------------
92
93 // Define named range as comma separated list of labels
94 tagCat.setRange("good","Lepton,Kaon") ;
95
96 // Or add state names one by one
97 tagCat.addToRange("soso","NetTagger-1") ;
98 tagCat.addToRange("soso","NetTagger-2") ;
99
100 // Use category range in dataset reduction specification
101 RooDataSet* goodData = (RooDataSet*) data->reduce(CutRange("good")) ;
102 goodData->table(tagCat)->Print("v") ;
103
104
105}
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:733
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
RooCmdArg CutRange(const char *rangeName)