Logo ROOT   6.18/05
Reference Guide
rf404_categories.C File Reference

Detailed Description

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

␛[1mRooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby␛[0m
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt
RooCategory::tagCat = Lepton(idx = 0)
RooCategory::b0flav = B0(idx = -1)
Roo1DTable::b0flav = (B0=5058,B0bar=4942)
Table b0flav : pData
+-------+------+
| B0 | 5058 |
| B0bar | 4942 |
+-------+------+
Roo1DTable::tagCat = (Lepton=454,Kaon=450,NetTagger-1=432,NetTagger-2=429)
Table tagCat : pData(x>8.23)
+-------------+-----+
| Lepton | 454 |
| Kaon | 450 |
| NetTagger-1 | 432 |
| NetTagger-2 | 429 |
+-------------+-----+
Table (tagCat x b0flav) : pData
+---------------------+------+
| {Lepton;B0} | 1302 |
| {Kaon;B0} | 1232 |
| {NetTagger-1;B0} | 1242 |
| {NetTagger-2;B0} | 1282 |
| {Lepton;B0bar} | 1192 |
| {Kaon;B0bar} | 1314 |
| {NetTagger-1;B0bar} | 1208 |
| {NetTagger-2;B0bar} | 1228 |
+---------------------+------+
Number of events with B0 flavor is 5058
Fraction of events tagged with Lepton tag is 0.257224
Table tagCat : pData
+-------------+------+
| Lepton | 2494 |
| Kaon | 2546 |
| NetTagger-1 | 0 |
| NetTagger-2 | 0 |
+-------------+------+
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooPolynomial.h"
#include "RooCategory.h"
#include "Roo1DTable.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit;
{
// C o n s t r u c t a c a t e g o r y w i t h l a b e l s
// ----------------------------------------------------------------
// Define a category with labels only
RooCategory tagCat("tagCat", "Tagging category");
tagCat.defineType("Lepton");
tagCat.defineType("Kaon");
tagCat.defineType("NetTagger-1");
tagCat.defineType("NetTagger-2");
tagCat.Print();
// C o n s t r u c t a c a t e g o r y w i t h l a b e l s a n d i n d e c e s
// ----------------------------------------------------------------------------------------
// Define a category with explicitly numbered states
RooCategory b0flav("b0flav", "B0 flavour eigenstate");
b0flav.defineType("B0", -1);
b0flav.defineType("B0bar", 1);
b0flav.Print();
// G e n e r a t e d u m m y d a t a f o r t a b u l a t i o n d e m o
// ----------------------------------------------------------------------------
// Generate a dummy dataset
RooRealVar x("x", "x", 0, 10);
RooDataSet *data = RooPolynomial("p", "p", x).generate(RooArgSet(x, b0flav, tagCat), 10000);
// P r i n t t a b l e s o f c a t e g o r y c o n t e n t s o f d a t a s e t s
// ------------------------------------------------------------------------------------------
// Tables are equivalent of plots for categories
Roo1DTable *btable = data->table(b0flav);
btable->Print();
btable->Print("v");
// Create table for subset of events matching cut expression
Roo1DTable *ttable = data->table(tagCat, "x>8.23");
ttable->Print();
ttable->Print("v");
// Create table for all (tagCat x b0flav) state combinations
Roo1DTable *bttable = data->table(RooArgSet(tagCat, b0flav));
bttable->Print("v");
// Retrieve number of events from table
// Number can be non-integer if source dataset has weighed events
Double_t nb0 = btable->get("B0");
cout << "Number of events with B0 flavor is " << nb0 << endl;
// Retrieve fraction of events with "Lepton" tag
Double_t fracLep = ttable->getFrac("Lepton");
cout << "Fraction of events tagged with Lepton tag is " << fracLep << endl;
// D e f i n i n g r a n g e s f o r p l o t t i n g , f i t t i n g o n c a t e g o r i e s
// ------------------------------------------------------------------------------------------------------
// 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
RooDataSet *goodData = (RooDataSet *)data->reduce(CutRange("good"));
goodData->table(tagCat)->Print("v");
}
double Double_t
Definition: RtypesCore.h:55
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:24
Double_t get(const char *label, Bool_t silent=kFALSE) const
Return the table entry named 'label'.
Definition: Roo1DTable.cxx:244
Double_t getFrac(const char *label, Bool_t silent=kFALSE) const
Return the fraction of entries in the table contained in the slot named 'label'.
Definition: Roo1DTable.cxx:301
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:754
RooAbsData * reduce(const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg())
Create a reduced copy of this dataset.
Definition: RooAbsData.cxx:381
RooDataSet * generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none())
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
Definition: RooAbsPdf.h:56
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
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
Double_t x[n]
Definition: legend1.C:17
Template specialisation used in RooAbsArg:
RooCmdArg CutRange(const char *rangeName)
Author
07/2008 - Wouter Verkerke

Definition in file rf404_categories.C.