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 "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{
56 _catList.add(catList);
57 _effFuncList.add(effFuncList);
58
59 if (_catList.getSize() != effFuncList.getSize()) {
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/// Destructor
79
81{
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Calculate the raw value of the function which is the effFunc
86/// value if cat==1 and it is (1-effFunc) if cat==0
87
89{
90 Int_t effFuncListSize = _effFuncList.getSize();
91
92 // Get efficiency function for category i
93
94 vector<double> effFuncVal(effFuncListSize);
95 for (int i=0; i<effFuncListSize; ++i) {
96 effFuncVal[i] = ((RooAbsReal&)_effFuncList[i]).getVal() ;
97 }
98
99 // Truncate efficiency functions in range 0.0-1.0
100
101 for (int i=0; i<effFuncListSize; ++i) {
102 if (effFuncVal[i]>1) {
103 coutW(Eval) << "WARNING: Efficiency >1 (equal to " << effFuncVal[i]
104 << " ), for i = " << i << "...TRUNCATED" << endl;
105 effFuncVal[i] = 1.0 ;
106 } else if (effFuncVal[i]<0) {
107 effFuncVal[i] = 0.0 ;
108 coutW(Eval) << "WARNING: Efficiency <0 (equal to " << effFuncVal[i]
109 << " ), for i = " << i << "...TRUNCATED" << endl;
110 }
111 }
112
113 vector<double> effValue(effFuncListSize);
114 bool notVisible = true;
115
116 // Calculate efficiency per accept/reject decision
117
118 for (int i=0; i<effFuncListSize; ++i) {
119 if ( ((RooAbsCategory&)_catList[i]).getCurrentIndex() == 1) {
120 // Accept case
121 effValue[i] = effFuncVal[i] ;
122 notVisible = false;
123 } else if ( ((RooAbsCategory&)_catList[i]).getCurrentIndex() == 0){
124 // Reject case
125 effValue[i] = 1 - effFuncVal[i] ;
126 } else {
127 coutW(Eval) << "WARNING: WRONG CATEGORY NAMES GIVEN!, label = " << ((RooAbsCategory&)_catList[i]).getCurrentIndex() << endl;
128 effValue[i] = 0;
129 }
130 }
131
132 double _effVal = 1.;
133
134 // Calculate efficiency for combination of accept/reject categories
135 // put equal to zero if combination of only zeros AND chosen to be invisible
136
137 for (int i=0; i<effFuncListSize; ++i) {
138 _effVal=_effVal*effValue[i];
139 if (notVisible && _ignoreNonVisible){
140 _effVal=0;
141 }
142 }
143
144 return _effVal;
145
146}
#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.
Int_t getSize() const
Return the number of elements in the collection.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
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
~RooMultiBinomial() override
Destructor.
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