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 (invertable) functions
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 "RooMappedCategory.h"
15#include "RooMultiCategory.h"
16#include "RooSuperCategory.h"
17#include "Roo1DTable.h"
18#include "TCanvas.h"
19#include "TAxis.h"
20#include "RooPlot.h"
21using namespace RooFit;
22
24{
25 // C o n s t r u c t t w o c a t e g o r i e 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 // Define a category with explicitly numbered states
37 RooCategory b0flav("b0flav", "B0 flavour eigenstate");
38 b0flav.defineType("B0", -1);
39 b0flav.defineType("B0bar", 1);
40 b0flav.Print();
41
42 // Construct a dummy dataset with random values of tagCat and b0flav
43 RooRealVar x("x", "x", 0, 10);
44 RooPolynomial p("p", "p", x);
45 RooDataSet *data = p.generate(RooArgSet(x, b0flav, tagCat), 10000);
46
47 // 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
48 // ---------------------------------------------------------------------
49
50 // A RooMappedCategory is category->category mapping function based on string expression
51 // The constructor takes an input category an a default state name to which unassigned
52 // states are mapped
53 RooMappedCategory tcatType("tcatType", "tagCat type", tagCat, "Cut based");
54
55 // Enter fully specified state mappings
56 tcatType.map("Lepton", "Cut based");
57 tcatType.map("Kaon", "Cut based");
58
59 // Enter a wilcard expression mapping
60 tcatType.map("NetTagger*", "Neural Network");
61
62 // Make a table of the mapped category state multiplicity in data
63 Roo1DTable *mtable = data->table(tcatType);
64 mtable->Print("v");
65
66 // 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
67 // ----------------------------------------------------------------------
68
69 // A SUPER-category is 'product' of _lvalue_ categories. The state names of a super
70 // category is a composite of the state labels of the input categories
71 RooSuperCategory b0Xtcat("b0Xtcat", "b0flav X tagCat", RooArgSet(b0flav, tagCat));
72
73 // Make a table of the product category state multiplicity in data
74 Roo1DTable *stable = data->table(b0Xtcat);
75 stable->Print("v");
76
77 // Since the super category is an lvalue, assignment is explicitly possible
78 b0Xtcat.setLabel("{B0bar;Lepton}");
79
80 // A MULTI-category is a 'product' of any category (function). The state names of a super
81 // category is a composite of the state labels of the input categories
82 RooMultiCategory b0Xttype("b0Xttype", "b0flav X tagType", RooArgSet(b0flav, tcatType));
83
84 // Make a table of the product category state multiplicity in data
85 Roo1DTable *xtable = data->table(b0Xttype);
86 xtable->Print("v");
87}
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:24
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:752
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
RooMultiCategory consolidates 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
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...