ROOT   Reference Guide
Searching...
No Matches
RooMultiBinomial.cxx
Go to the documentation of this file.
1
2/*****************************************************************************
3 * Project: RooFit *
4 * Package: RooFitCore *
5 * @(#)root/roofitcore:$Id$
6 * Author: *
7 * Tristan du Pree, Nikhef, Amsterdam, tdupree@nikhef.nl *
8 * *
9 * Redistribution and use in source and binary forms, *
10 * with or without modification, are permitted according to the terms *
11 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
12 *****************************************************************************/
13
14/** \class RooMultiBinomial
15 \ingroup Roofit
16
17RooMultiBinomial is an efficiency function which makes all combinations of
18efficiencies given as input different efficiency functions for different categories.
19
20Given a dataset with a category C that determines if a given
21event is accepted (1) or rejected (0) for the efficiency to be measured,
22this class evaluates as F if C is 'accept' and as (1-F) if
23C is 'reject'. Values of F below 0 and above 1 are clipped.
24F may have an arbitrary number of dependents and parameters
25
26The combination only 'reject' can be chosen to be visible or not visible
27(and hence this efficiency is then equal to zero).
28**/
29
30#include "RooMultiBinomial.h"
31#include "RooStreamParser.h"
32#include "RooArgList.h"
33#include "RooAbsCategory.h"
34#include "RooMsgService.h"
35#include <string>
36#include <vector>
37
38using namespace std ;
39
41
42////////////////////////////////////////////////////////////////////////////////
43/// Construct the efficiency functions from a list of efficiency functions
44/// and a list of categories cat with two states (0,1) that indicate if a given
45/// event should be counted as rejected or accepted respectively
46
47RooMultiBinomial::RooMultiBinomial(const char *name, const char *title,
48 const RooArgList& effFuncList,
49 const RooArgList& catList,
50 bool ignoreNonVisible) :
51 RooAbsReal(name,title),
52 _catList("catList","list of cats", this),
53 _effFuncList("effFuncList","list of eff funcs",this),
54 _ignoreNonVisible(ignoreNonVisible)
55{
58
59 if (_catList.size() != effFuncList.size()) {
60 coutE(InputArguments) << "RooMultiBinomial::ctor(" << GetName() << ") ERROR: Wrong input, should have equal number of categories and efficiencies." << endl;
61 throw string("RooMultiBinomial::ctor() ERROR: Wrong input, should have equal number of categories and efficiencies") ;
62 }
63
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Copy constructor
68
70 RooAbsReal(other, name),
71 _catList("catList",this,other._catList),
72 _effFuncList("effFuncList",this,other._effFuncList),
73 _ignoreNonVisible(other._ignoreNonVisible)
74{
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Calculate the raw value of the function which is the effFunc
79/// value if cat==1 and it is (1-effFunc) if cat==0
80
82{
83 Int_t effFuncListSize = _effFuncList.size();
84
85 // Get efficiency function for category i
86
87 vector<double> effFuncVal(effFuncListSize);
88 for (int i=0; i<effFuncListSize; ++i) {
89 effFuncVal[i] = (static_cast<RooAbsReal&>(_effFuncList[i])).getVal() ;
90 }
91
92 // Truncate efficiency functions in range 0.0-1.0
93
94 for (int i=0; i<effFuncListSize; ++i) {
95 if (effFuncVal[i]>1) {
96 coutW(Eval) << "WARNING: Efficiency >1 (equal to " << effFuncVal[i]
97 << " ), for i = " << i << "...TRUNCATED" << endl;
98 effFuncVal[i] = 1.0 ;
99 } else if (effFuncVal[i]<0) {
100 effFuncVal[i] = 0.0 ;
101 coutW(Eval) << "WARNING: Efficiency <0 (equal to " << effFuncVal[i]
102 << " ), for i = " << i << "...TRUNCATED" << endl;
103 }
104 }
105
106 vector<double> effValue(effFuncListSize);
107 bool notVisible = true;
108
109 // Calculate efficiency per accept/reject decision
110
111 for (int i=0; i<effFuncListSize; ++i) {
112 if ( (static_cast<RooAbsCategory&>(_catList[i])).getCurrentIndex() == 1) {
113 // Accept case
114 effValue[i] = effFuncVal[i] ;
115 notVisible = false;
116 } else if ( (static_cast<RooAbsCategory&>(_catList[i])).getCurrentIndex() == 0){
117 // Reject case
118 effValue[i] = 1 - effFuncVal[i] ;
119 } else {
120 coutW(Eval) << "WARNING: WRONG CATEGORY NAMES GIVEN!, label = " << (static_cast<RooAbsCategory&>(_catList[i])).getCurrentIndex() << endl;
121 effValue[i] = 0;
122 }
123 }
124
125 double _effVal = 1.;
126
127 // Calculate efficiency for combination of accept/reject categories
128 // put equal to zero if combination of only zeros AND chosen to be invisible
129
130 for (int i=0; i<effFuncListSize; ++i) {
131 _effVal=_effVal*effValue[i];
132 if (notVisible && _ignoreNonVisible){
133 _effVal=0;
134 }
135 }
136
137 return _effVal;
138
139}
#define coutW(a)
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:377
char name[80]
Definition TGX11.cxx:110
A space to attach TBranches.
Storage_t::size_type size() const
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
RooMultiBinomial is an efficiency function which makes all combinations of efficiencies given as inpu...
RooListProxy _effFuncList
double evaluate() const override
Calculate the raw value of the function which is the effFunc value if cat==1 and it is (1-effFunc) if...
RooListProxy _catList
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47