Logo ROOT   6.08/07
Reference Guide
rf406_cattocatfuncs.cxx
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // 'DATA AND CATEGORIES' RooFit tutorial macro #406
4 //
5 // Demonstration of discrete-->discrete (invertable) functions
6 //
7 //
8 //
9 // 07/2008 - Wouter Verkerke
10 //
11 /////////////////////////////////////////////////////////////////////////
12 
13 #ifndef __CINT__
14 #include "RooGlobalFunc.h"
15 #endif
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooPolynomial.h"
19 #include "RooCategory.h"
20 #include "RooMappedCategory.h"
21 #include "RooMultiCategory.h"
22 #include "RooSuperCategory.h"
23 #include "Roo1DTable.h"
24 #include "TCanvas.h"
25 #include "RooPlot.h"
26 using namespace RooFit ;
27 
28 
29 class TestBasic406 : public RooFitTestUnit
30 {
31 public:
32  TestBasic406(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Category-to-category functions",refFile,writeRef,verbose) {} ;
33  Bool_t testCode() {
34 
35  // C o n s t r u c t t w o c a t e g o r i e s
36  // ----------------------------------------------
37 
38  // Define a category with labels only
39  RooCategory tagCat("tagCat","Tagging category") ;
40  tagCat.defineType("Lepton") ;
41  tagCat.defineType("Kaon") ;
42  tagCat.defineType("NetTagger-1") ;
43  tagCat.defineType("NetTagger-2") ;
44 
45  // Define a category with explicitly numbered states
46  RooCategory b0flav("b0flav","B0 flavour eigenstate") ;
47  b0flav.defineType("B0",-1) ;
48  b0flav.defineType("B0bar",1) ;
49 
50  // Construct a dummy dataset with random values of tagCat and b0flav
51  RooRealVar x("x","x",0,10) ;
52  RooPolynomial p("p","p",x) ;
53  RooDataSet* data = p.generate(RooArgSet(x,b0flav,tagCat),10000) ;
54 
55 
56 
57  // 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
58  // ---------------------------------------------------------------------
59 
60  // A RooMappedCategory is category->category mapping function based on string expression
61  // The constructor takes an input category an a default state name to which unassigned
62  // states are mapped
63  RooMappedCategory tcatType("tcatType","tagCat type",tagCat,"Cut based") ;
64 
65  // Enter fully specified state mappings
66  tcatType.map("Lepton","Cut based") ;
67  tcatType.map("Kaon","Cut based") ;
68 
69  // Enter a wilcard expression mapping
70  tcatType.map("NetTagger*","Neural Network") ;
71 
72  // Make a table of the mapped category state multiplicit in data
73  Roo1DTable* mtable = data->table(tcatType) ;
74 
75 
76 
77  // 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
78  // ----------------------------------------------------------------------
79 
80  // A SUPER-category is 'product' of _lvalue_ categories. The state names of a super
81  // category is a composite of the state labels of the input categories
82  RooSuperCategory b0Xtcat("b0Xtcat","b0flav X tagCat",RooArgSet(b0flav,tagCat)) ;
83 
84  // Make a table of the product category state multiplicity in data
85  Roo1DTable* stable = data->table(b0Xtcat) ;
86 
87  // Since the super category is an lvalue, assignment is explicitly possible
88  b0Xtcat.setLabel("{B0bar;Lepton}") ;
89 
90 
91 
92  // A MULTI-category is a 'product' of any category (function). The state names of a super
93  // category is a composite of the state labels of the input categories
94  RooMultiCategory b0Xttype("b0Xttype","b0flav X tagType",RooArgSet(b0flav,tcatType)) ;
95 
96  // Make a table of the product category state multiplicity in data
97  Roo1DTable* xtable = data->table(b0Xttype) ;
98 
99  regTable(mtable,"rf406_mtable") ;
100  regTable(stable,"rf406_stable") ;
101  regTable(xtable,"rf406_xtable") ;
102 
103  delete data ;
104 
105  return kTRUE ;
106  }
107 
108 } ;
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t x[n]
Definition: legend1.C:17
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
bool verbose
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:25
RooMultiCategory consolidates several RooAbsCategory objects into a single category.
RooPolynomial implements a polynomial p.d.f of the form By default coefficient a_0 is chosen to be 1...
Definition: RooPolynomial.h:28
RooSuperCategory consolidates several RooAbsCategoryLValue objects into a single category.
const Bool_t kTRUE
Definition: Rtypes.h:91
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:25
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