Logo ROOT  
Reference Guide
rf406_cattocatfuncs.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -nodraw
4 /// Data and categories: demonstration of discrete-->discrete (invertible) functions
5 ///
6 /// \macro_output
7 /// \macro_code
8 ///
9 /// \date July 2008
10 /// \author Wouter Verkerke
11 
12 #include "RooRealVar.h"
13 #include "RooDataSet.h"
14 #include "RooPolynomial.h"
15 #include "RooCategory.h"
16 #include "RooMappedCategory.h"
17 #include "RooMultiCategory.h"
18 #include "RooSuperCategory.h"
19 #include "Roo1DTable.h"
20 #include "TCanvas.h"
21 #include "TAxis.h"
22 #include "RooPlot.h"
23 using namespace RooFit;
24 
26 {
27  // C o n s t r u c t t w o c a t e g o r i e s
28  // ----------------------------------------------
29 
30  // Define a category with labels only
31  RooCategory tagCat("tagCat", "Tagging category");
32  tagCat.defineType("Lepton");
33  tagCat.defineType("Kaon");
34  tagCat.defineType("NetTagger-1");
35  tagCat.defineType("NetTagger-2");
36  tagCat.Print();
37 
38  // Define a category with explicitly numbered states
39  RooCategory b0flav("b0flav", "B0 flavour eigenstate");
40  b0flav.defineType("B0", -1);
41  b0flav.defineType("B0bar", 1);
42  b0flav.Print();
43 
44  // Construct a dummy dataset with random values of tagCat and b0flav
45  RooRealVar x("x", "x", 0, 10);
46  RooPolynomial p("p", "p", x);
47  RooDataSet *data = p.generate(RooArgSet(x, b0flav, tagCat), 10000);
48 
49  // C r e a t e a c a t - > c a t m a p p i n g c a t e g o r y
50  // ---------------------------------------------------------------------
51 
52  // A RooMappedCategory is category->category mapping function based on string expression
53  // The constructor takes an input category an a default state name to which unassigned
54  // states are mapped
55  RooMappedCategory tcatType("tcatType", "tagCat type", tagCat, "Cut based");
56 
57  // Enter fully specified state mappings
58  tcatType.map("Lepton", "Cut based");
59  tcatType.map("Kaon", "Cut based");
60 
61  // Enter a wilcard expression mapping
62  tcatType.map("NetTagger*", "Neural Network");
63 
64  // Make a table of the mapped category state multiplicity in data
65  Roo1DTable *mtable = data->table(tcatType);
66  mtable->Print("v");
67 
68  // C r e a t e a c a t X c a t p r o d u c t c a t e g o r y
69  // ----------------------------------------------------------------------
70 
71  // A SUPER-category is 'product' of _lvalue_ categories. The state names of a super
72  // category is a composite of the state labels of the input categories
73  RooSuperCategory b0Xtcat("b0Xtcat", "b0flav X tagCat", RooArgSet(b0flav, tagCat));
74 
75  // Make a table of the product category state multiplicity in data
76  Roo1DTable *stable = data->table(b0Xtcat);
77  stable->Print("v");
78 
79  // Since the super category is an lvalue, assignment is explicitly possible
80  b0Xtcat.setLabel("{B0bar;Lepton}");
81 
82  // A MULTI-category is a 'product' of any category (function). The state names of a super
83  // category is a composite of the state labels of the input categories
84  RooMultiCategory b0Xttype("b0Xttype", "b0flav X tagType", RooArgSet(b0flav, tcatType));
85 
86  // Make a table of the product category state multiplicity in data
87  Roo1DTable *xtable = data->table(b0Xttype);
88  xtable->Print("v");
89 }
RooSuperCategory.h
Roo1DTable
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:23
Roo1DTable::Print
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: Roo1DTable.h:50
x
Double_t x[n]
Definition: legend1.C:17
TCanvas.h
RooDataSet.h
RooPolynomial.h
RooMappedCategory
RooMappedCategory provides a category-to-category mapping defined by pattern matching on their state ...
Definition: RooMappedCategory.h:27
RooAbsData::table
virtual Roo1DTable * table(const RooArgSet &catSet, const char *cuts="", const char *opts="") const
Construct table for product of categories in catSet.
Definition: RooAbsData.cxx:749
RooMultiCategory
RooMultiCategory connects several RooAbsCategory objects into a single category.
Definition: RooMultiCategory.h:28
RooMultiCategory.h
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooPolynomial
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooPlot.h
RooCategory.h
RooRealVar.h
rf406_cattocatfuncs
Definition: rf406_cattocatfuncs.py:1
Roo1DTable.h
RooCategory
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:27
RooSuperCategory
The RooSuperCategory can join several RooAbsCategoryLValue objects into a single category.
Definition: RooSuperCategory.h:27
TAxis.h
RooDataSet
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooMappedCategory.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29