ROOT
Version master
v6.34
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
rf404_categories.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_roofit_main
3
## \notebook -nodraw
4
## Data and categories: working with ROOT.RooCategory objects to describe discrete variables
5
##
6
## \macro_code
7
## \macro_output
8
##
9
## \date February 2018
10
## \authors Clemens Lange, Wouter Verkerke (C++ version)
11
12
import
ROOT
13
14
15
# Construct a category with labels
16
# --------------------------------------------
17
18
# Define a category with labels only
19
tagCat =
ROOT.RooCategory
(
"tagCat"
,
"Tagging category"
)
20
tagCat.defineType
(
"Lepton"
)
21
tagCat.defineType
(
"Kaon"
)
22
tagCat.defineType
(
"NetTagger-1"
)
23
tagCat.defineType
(
"NetTagger-2"
)
24
tagCat.Print
()
25
26
# Construct a category with labels and indices
27
# ------------------------------------------------
28
29
# Define a category with explicitly numbered states
30
b0flav =
ROOT.RooCategory
(
"b0flav"
,
"B0 flavour eigenstate"
, {
"B0"
: -1,
"B0bar"
: 1})
31
b0flav.Print
()
32
33
# Generate dummy data for tabulation demo
34
# ------------------------------------------------
35
36
# Generate a dummy dataset
37
x =
ROOT.RooRealVar
(
"x"
,
"x"
, 0, 10)
38
data =
ROOT.RooPolynomial
(
"p"
,
"p"
, x).generate({x, b0flav, tagCat}, 10000)
39
40
# Print tables of category contents of datasets
41
# --------------------------------------------------
42
43
# Tables are equivalent of plots for categories
44
btable =
data.table
(b0flav)
45
btable.Print
()
46
btable.Print
(
"v"
)
47
48
# Create table for subset of events matching cut expression
49
ttable =
data.table
(tagCat,
"x>8.23"
)
50
ttable.Print
()
51
ttable.Print
(
"v"
)
52
53
# Create table for all (tagCat x b0flav) state combinations
54
bttable =
data.table
({tagCat, b0flav})
55
bttable.Print
(
"v"
)
56
57
# Retrieve number of events from table
58
# Number can be non-integer if source dataset has weighed events
59
nb0 =
btable.get
(
"B0"
)
60
print(
"Number of events with B0 flavor is "
, nb0)
61
62
# Retrieve fraction of events with "Lepton" tag
63
fracLep =
ttable.getFrac
(
"Lepton"
)
64
print(
"Fraction of events tagged with Lepton tag is "
, fracLep)
65
66
# Defining ranges for plotting, fitting on categories
67
# ------------------------------------------------------------------------------------------------------
68
69
# Define named range as comma separated list of labels
70
tagCat.setRange
(
"good"
,
"Lepton,Kaon"
)
71
72
# Or add state names one by one
73
tagCat.addToRange
(
"soso"
,
"NetTagger-1"
)
74
tagCat.addToRange
(
"soso"
,
"NetTagger-2"
)
75
76
# Use category range in dataset reduction specification
77
goodData =
data.reduce
(CutRange=
"good"
)
78
goodData.table
(tagCat).
Print
(
"v"
)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
Print
void Print(GNN_Data &d, std::string txt="")
Definition
TMVA_SOFIE_GNN_Application.C:59
tutorials
roofit
roofit
rf404_categories.py
ROOT master - Reference Guide Generated on Sun Apr 6 2025 05:38:01 (GVA Time) using Doxygen 1.10.0