Logo ROOT   6.10/09
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]).getIndex() == 1) {
122  // Accept case
123  effValue[i] = effFuncVal[i] ;
124  notVisible = false;
125  } else if ( ((RooAbsCategory&)_catList[i]).getIndex() == 0){
126  // Reject case
127  effValue[i] = 1 - effFuncVal[i] ;
128  } else {
129  coutW(Eval) << "WARNING: WRONG CATEGORY NAMES GIVEN!, label = " << ((RooAbsCategory&)_catList[i]).getIndex() << 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 }
RooListProxy _effFuncList
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:145
#define coutE(a)
Definition: RooMsgService.h:34
virtual ~RooMultiBinomial()
Destructor.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
#define coutW(a)
Definition: RooMsgService.h:33
Int_t getSize() const
RooListProxy _catList
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
RooMultiBinomial is an efficiency function which makes all combinations of efficiencies given as inpu...
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
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...