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