ROOT logo

From $ROOTSYS/tutorials/roofit/rf406_cattocatfuncs.C

//////////////////////////////////////////////////////////////////////////
//
// 'DATA AND CATEGORIES' RooFit tutorial macro #406
// 
// Demonstration of discrete-->discrete (invertable) functions
//
//
//
// 07/2008 - Wouter Verkerke 
// 
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooPolynomial.h"
#include "RooCategory.h"
#include "RooMappedCategory.h"
#include "RooMultiCategory.h"
#include "RooSuperCategory.h"
#include "Roo1DTable.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit ;


void rf406_cattocatfuncs()
{
  // C o n s t r u c t  t w o   c a t e g o r i e 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() ;

  // Define a category with explicitly numbered states
  RooCategory b0flav("b0flav","B0 flavour eigenstate") ;
  b0flav.defineType("B0",-1) ;
  b0flav.defineType("B0bar",1) ;
  b0flav.Print() ;

  // Construct a dummy dataset with random values of tagCat and b0flav
  RooRealVar x("x","x",0,10) ;
  RooPolynomial p("p","p",x) ;
  RooDataSet* data = p.generate(RooArgSet(x,b0flav,tagCat),10000) ;



  // 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 
  // ---------------------------------------------------------------------

  // A RooMappedCategory is category->category mapping function based on string expression
  // The constructor takes an input category an a default state name to which unassigned
  // states are mapped
  RooMappedCategory tcatType("tcatType","tagCat type",tagCat,"Cut based") ;

  // Enter fully specified state mappings
  tcatType.map("Lepton","Cut based") ;
  tcatType.map("Kaon","Cut based") ;

  // Enter a wilcard expression mapping
  tcatType.map("NetTagger*","Neural Network") ;

  // Make a table of the mapped category state multiplicit in data
  Roo1DTable* mtable = data->table(tcatType) ;
  mtable->Print("v") ;



  // 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 
  // ----------------------------------------------------------------------

  // A SUPER-category is 'product' of _lvalue_ categories. The state names of a super
  // category is a composite of the state labels of the input categories
  RooSuperCategory b0Xtcat("b0Xtcat","b0flav X tagCat",RooArgSet(b0flav,tagCat)) ;

  // Make a table of the product category state multiplicity in data
  Roo1DTable* stable = data->table(b0Xtcat) ;
  stable->Print("v") ;

  // Since the super category is an lvalue, assignment is explicitly possible
  b0Xtcat.setLabel("{B0bar;Lepton}") ;



  // A MULTI-category is a 'product' of any category (function). The state names of a super
  // category is a composite of the state labels of the input categories
  RooMultiCategory b0Xttype("b0Xttype","b0flav X tagType",RooArgSet(b0flav,tcatType)) ;
  
  // Make a table of the product category state multiplicity in data
  Roo1DTable* xtable = data->table(b0Xttype) ;
  xtable->Print("v") ;


}
 rf406_cattocatfuncs.C:1
 rf406_cattocatfuncs.C:2
 rf406_cattocatfuncs.C:3
 rf406_cattocatfuncs.C:4
 rf406_cattocatfuncs.C:5
 rf406_cattocatfuncs.C:6
 rf406_cattocatfuncs.C:7
 rf406_cattocatfuncs.C:8
 rf406_cattocatfuncs.C:9
 rf406_cattocatfuncs.C:10
 rf406_cattocatfuncs.C:11
 rf406_cattocatfuncs.C:12
 rf406_cattocatfuncs.C:13
 rf406_cattocatfuncs.C:14
 rf406_cattocatfuncs.C:15
 rf406_cattocatfuncs.C:16
 rf406_cattocatfuncs.C:17
 rf406_cattocatfuncs.C:18
 rf406_cattocatfuncs.C:19
 rf406_cattocatfuncs.C:20
 rf406_cattocatfuncs.C:21
 rf406_cattocatfuncs.C:22
 rf406_cattocatfuncs.C:23
 rf406_cattocatfuncs.C:24
 rf406_cattocatfuncs.C:25
 rf406_cattocatfuncs.C:26
 rf406_cattocatfuncs.C:27
 rf406_cattocatfuncs.C:28
 rf406_cattocatfuncs.C:29
 rf406_cattocatfuncs.C:30
 rf406_cattocatfuncs.C:31
 rf406_cattocatfuncs.C:32
 rf406_cattocatfuncs.C:33
 rf406_cattocatfuncs.C:34
 rf406_cattocatfuncs.C:35
 rf406_cattocatfuncs.C:36
 rf406_cattocatfuncs.C:37
 rf406_cattocatfuncs.C:38
 rf406_cattocatfuncs.C:39
 rf406_cattocatfuncs.C:40
 rf406_cattocatfuncs.C:41
 rf406_cattocatfuncs.C:42
 rf406_cattocatfuncs.C:43
 rf406_cattocatfuncs.C:44
 rf406_cattocatfuncs.C:45
 rf406_cattocatfuncs.C:46
 rf406_cattocatfuncs.C:47
 rf406_cattocatfuncs.C:48
 rf406_cattocatfuncs.C:49
 rf406_cattocatfuncs.C:50
 rf406_cattocatfuncs.C:51
 rf406_cattocatfuncs.C:52
 rf406_cattocatfuncs.C:53
 rf406_cattocatfuncs.C:54
 rf406_cattocatfuncs.C:55
 rf406_cattocatfuncs.C:56
 rf406_cattocatfuncs.C:57
 rf406_cattocatfuncs.C:58
 rf406_cattocatfuncs.C:59
 rf406_cattocatfuncs.C:60
 rf406_cattocatfuncs.C:61
 rf406_cattocatfuncs.C:62
 rf406_cattocatfuncs.C:63
 rf406_cattocatfuncs.C:64
 rf406_cattocatfuncs.C:65
 rf406_cattocatfuncs.C:66
 rf406_cattocatfuncs.C:67
 rf406_cattocatfuncs.C:68
 rf406_cattocatfuncs.C:69
 rf406_cattocatfuncs.C:70
 rf406_cattocatfuncs.C:71
 rf406_cattocatfuncs.C:72
 rf406_cattocatfuncs.C:73
 rf406_cattocatfuncs.C:74
 rf406_cattocatfuncs.C:75
 rf406_cattocatfuncs.C:76
 rf406_cattocatfuncs.C:77
 rf406_cattocatfuncs.C:78
 rf406_cattocatfuncs.C:79
 rf406_cattocatfuncs.C:80
 rf406_cattocatfuncs.C:81
 rf406_cattocatfuncs.C:82
 rf406_cattocatfuncs.C:83
 rf406_cattocatfuncs.C:84
 rf406_cattocatfuncs.C:85
 rf406_cattocatfuncs.C:86
 rf406_cattocatfuncs.C:87
 rf406_cattocatfuncs.C:88
 rf406_cattocatfuncs.C:89
 rf406_cattocatfuncs.C:90
 rf406_cattocatfuncs.C:91
 rf406_cattocatfuncs.C:92
 rf406_cattocatfuncs.C:93
 rf406_cattocatfuncs.C:94
 rf406_cattocatfuncs.C:95
 rf406_cattocatfuncs.C:96
 rf406_cattocatfuncs.C:97
 rf406_cattocatfuncs.C:98
 rf406_cattocatfuncs.C:99
 rf406_cattocatfuncs.C:100
 rf406_cattocatfuncs.C:101
 rf406_cattocatfuncs.C:102
 rf406_cattocatfuncs.C:103