Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf404_categories.py File Reference

Detailed Description

View in nbviewer Open in SWAN
Data and categories: working with ROOT.RooCategory objects to describe discrete variables

from __future__ import print_function
import ROOT
# Construct a category with labels
# --------------------------------------------
# Define a category with labels only
tagCat = ROOT.RooCategory("tagCat", "Tagging category")
tagCat.defineType("Lepton")
tagCat.defineType("Kaon")
tagCat.defineType("NetTagger-1")
tagCat.defineType("NetTagger-2")
tagCat.Print()
# Construct a category with labels and indices
# ------------------------------------------------
# Define a category with explicitly numbered states
b0flav = ROOT.RooCategory("b0flav", "B0 flavour eigenstate", {"B0": -1, "B0bar": 1})
b0flav.Print()
# Generate dummy data for tabulation demo
# ------------------------------------------------
# Generate a dummy dataset
x = ROOT.RooRealVar("x", "x", 0, 10)
data = ROOT.RooPolynomial("p", "p", x).generate({x, b0flav, tagCat}, 10000)
# Print tables of category contents of datasets
# --------------------------------------------------
# Tables are equivalent of plots for categories
btable = data.table(b0flav)
btable.Print()
btable.Print("v")
# Create table for subset of events matching cut expression
ttable = data.table(tagCat, "x>8.23")
ttable.Print()
ttable.Print("v")
# Create table for all (tagCat x b0flav) state combinations
bttable = data.table({tagCat, b0flav})
bttable.Print("v")
# Retrieve number of events from table
# Number can be non-integer if source dataset has weighed events
nb0 = btable.get("B0")
print("Number of events with B0 flavor is ", nb0)
# Retrieve fraction of events with "Lepton" tag
fracLep = ttable.getFrac("Lepton")
print("Fraction of events tagged with Lepton tag is ", fracLep)
# Defining ranges for plotting, fitting on categories
# ------------------------------------------------------------------------------------------------------
# Define named range as comma separated list of labels
tagCat.setRange("good", "Lepton,Kaon")
# Or add state names one by one
tagCat.addToRange("soso", "NetTagger-1")
tagCat.addToRange("soso", "NetTagger-2")
# Use category range in dataset reduction specification
goodData = data.reduce(CutRange="good")
goodData.table(tagCat).Print("v")
void Print(GNN_Data &d, std::string txt="")
RooCategory::tagCat = Lepton(idx = 0)
RooCategory::b0flav = B0(idx = -1)
Roo1DTable::b0flav = (B0=5040,B0bar=4960)
Table b0flav : pData
+-------+------+
| B0 | 5040 |
| B0bar | 4960 |
+-------+------+
[#1] INFO:InputArguments -- The formula cutVar claims to use the variables (x,tagCat,b0flav) but only (x) seem to be in use.
inputs: x>8.23
Roo1DTable::tagCat = (Lepton=487,Kaon=433,NetTagger-1=439,NetTagger-2=406)
Table tagCat : pData(x>8.23)
+-------------+-----+
| Lepton | 487 |
| Kaon | 433 |
| NetTagger-1 | 439 |
| NetTagger-2 | 406 |
+-------------+-----+
Table (b0flav x tagCat) : pData
+---------------------+------+
| {B0;Lepton} | 1281 |
| {B0bar;Lepton} | 1269 |
| {B0;Kaon} | 1253 |
| {B0bar;Kaon} | 1255 |
| {B0;NetTagger-1} | 1234 |
| {B0bar;NetTagger-1} | 1219 |
| {B0;NetTagger-2} | 1272 |
| {B0bar;NetTagger-2} | 1217 |
+---------------------+------+
Table tagCat : pData
+-------------+------+
| Lepton | 2550 |
| Kaon | 2508 |
| NetTagger-1 | 0 |
| NetTagger-2 | 0 |
+-------------+------+
Number of events with B0 flavor is 5040.0
Fraction of events tagged with Lepton tag is 0.27592067988668556
Date
February 2018
Authors
Clemens Lange, Wouter Verkerke (C++ version)

Definition in file rf404_categories.py.