Logo ROOT  
Reference Guide
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 
17 RooMultiBinomial is an efficiency function which makes all combinations of
18 efficiencies given as input different efficiency functions for different categories.
19 
20 Given a dataset with a category C that determines if a given
21 event is accepted (1) or rejected (0) for the efficiency to be measured,
22 this class evaluates as F if C is 'accept' and as (1-F) if
23 C is 'reject'. Values of F below 0 and above 1 are clipped.
24 F may have an arbitrary number of dependents and parameters
25 
26 The 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 
40 using 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 
49 RooMultiBinomial::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 }
RooStreamParser.h
RooMultiBinomial::~RooMultiBinomial
virtual ~RooMultiBinomial()
Destructor.
Definition: RooMultiBinomial.cxx:82
RooMultiBinomial::RooMultiBinomial
RooMultiBinomial()
Definition: RooMultiBinomial.h:27
RooMsgService.h
RooFit.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:68
RooMultiBinomial.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
coutE
#define coutE(a)
Definition: RooMsgService.h:33
coutW
#define coutW(a)
Definition: RooMsgService.h:32
RooArgList
Definition: RooArgList.h:21
RooAbsReal
Definition: RooAbsReal.h:61
RooMultiBinomial::_ignoreNonVisible
Bool_t _ignoreNonVisible
Definition: RooMultiBinomial.h:44
bool
RooAbsCategory
Definition: RooAbsCategory.h:38
RooMultiBinomial
Definition: RooMultiBinomial.h:24
RooListProxy::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
Definition: RooListProxy.cxx:104
Double_t
double Double_t
Definition: RtypesCore.h:59
RooAbsCategory.h
RooMultiBinomial::evaluate
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...
Definition: RooMultiBinomial.cxx:90
RooMultiBinomial::_catList
RooListProxy _catList
Definition: RooMultiBinomial.h:42
name
char name[80]
Definition: TGX11.cxx:110
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
RooFit::Eval
@ Eval
Definition: RooGlobalFunc.h:68
RooArgList.h
RooMultiBinomial::_effFuncList
RooListProxy _effFuncList
Definition: RooMultiBinomial.h:43
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
int