Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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_code
7/// \macro_output
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"
23using 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 std::unique_ptr<RooDataSet> data{p.generate({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 wildcard 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}
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
One-dimensional table.
Definition Roo1DTable.h:23
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
Definition Roo1DTable.h:50
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Object to represent discrete states.
Definition RooCategory.h:28
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.
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:37
Joins 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...
Definition JSONIO.h:26