Logo ROOT  
Reference Guide
 
Loading...
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 "RooFit.h"
31
32#include "RooMultiBinomial.h"
33#include "RooStreamParser.h"
34#include "RooArgList.h"
35#include "RooAbsCategory.h"
36#include "RooMsgService.h"
37#include <string>
38#include <vector>
39
40using namespace std ;
41
43
44////////////////////////////////////////////////////////////////////////////////
45/// Construct the efficiency functions from a list of efficiency functions
46/// and a list of categories cat with two states (0,1) that indicate if a given
47/// event should be counted as rejected or accepted respectively
48
49RooMultiBinomial::RooMultiBinomial(const char *name, const char *title,
50 const RooArgList& effFuncList,
51 const RooArgList& catList,
52 Bool_t ignoreNonVisible) :
53 RooAbsReal(name,title),
54 _catList("catList","list of cats", this),
55 _effFuncList("effFuncList","list of eff funcs",this),
56 _ignoreNonVisible(ignoreNonVisible)
57{
58 _catList.add(catList);
59 _effFuncList.add(effFuncList);
60
61 if (_catList.getSize() != effFuncList.getSize()) {
62 coutE(InputArguments) << "RooMultiBinomial::ctor(" << GetName() << ") ERROR: Wrong input, should have equal number of categories and efficiencies." << endl;
63 throw string("RooMultiBinomial::ctor() ERROR: Wrong input, should have equal number of categories and efficiencies") ;
64 }
65
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Copy constructor
70
72 RooAbsReal(other, name),
73 _catList("catList",this,other._catList),
74 _effFuncList("effFuncList",this,other._effFuncList),
75 _ignoreNonVisible(other._ignoreNonVisible)
76{
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// Destructor
81
83{
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Calculate the raw value of the function which is the effFunc
88/// value if cat==1 and it is (1-effFunc) if cat==0
89
91{
92 Int_t effFuncListSize = _effFuncList.getSize();
93
94 // Get efficiency function for category i
95
96 vector<Double_t> effFuncVal(effFuncListSize);
97 for (int i=0; i<effFuncListSize; ++i) {
98 effFuncVal[i] = ((RooAbsReal&)_effFuncList[i]).getVal() ;
99 }
100
101 // Truncate efficiency functions in range 0.0-1.0
102
103 for (int i=0; i<effFuncListSize; ++i) {
104 if (effFuncVal[i]>1) {
105 coutW(Eval) << "WARNING: Efficiency >1 (equal to " << effFuncVal[i]
106 << " ), for i = " << i << "...TRUNCATED" << endl;
107 effFuncVal[i] = 1.0 ;
108 } else if (effFuncVal[i]<0) {
109 effFuncVal[i] = 0.0 ;
110 coutW(Eval) << "WARNING: Efficiency <0 (equal to " << effFuncVal[i]
111 << " ), for i = " << i << "...TRUNCATED" << endl;
112 }
113 }
114
115 vector<Double_t> effValue(effFuncListSize);
116 Bool_t notVisible = true;
117
118 // Calculate efficiency per accept/reject decision
119
120 for (int i=0; i<effFuncListSize; ++i) {
121 if ( ((RooAbsCategory&)_catList[i]).getCurrentIndex() == 1) {
122 // Accept case
123 effValue[i] = effFuncVal[i] ;
124 notVisible = false;
125 } else if ( ((RooAbsCategory&)_catList[i]).getCurrentIndex() == 0){
126 // Reject case
127 effValue[i] = 1 - effFuncVal[i] ;
128 } else {
129 coutW(Eval) << "WARNING: WRONG CATEGORY NAMES GIVEN!, label = " << ((RooAbsCategory&)_catList[i]).getCurrentIndex() << endl;
130 effValue[i] = 0;
131 }
132 }
133
134 Double_t _effVal = 1.;
135
136 // Calculate efficiency for combination of accept/reject categories
137 // put equal to zero if combination of only zeros AND chosen to be invisible
138
139 for (int i=0; i<effFuncListSize; ++i) {
140 _effVal=_effVal*effValue[i];
141 if (notVisible && _ignoreNonVisible){
142 _effVal=0;
143 }
144 }
145
146 return _effVal;
147
148}
#define coutW(a)
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
Int_t getSize() const
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:61
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:21
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Reimplementation of standard RooArgList::add()
RooMultiBinomial is an efficiency function which makes all combinations of efficiencies given as inpu...
virtual Double_t evaluate() const
Calculate the raw value of the function which is the effFunc value if cat==1 and it is (1-effFunc) if...
virtual ~RooMultiBinomial()
Destructor.
RooListProxy _effFuncList
RooListProxy _catList
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47