ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 /**
15 \file RooMultiBinomial.cxx
16 \class RooMultiBinomial
17 \ingroup Roofit
18 
19 RooMultiBinomial is an efficiency function which makes all combinations of
20 efficiencies given as input different effiency functions for different categories.
21 
22 Given a dataset with a category C that determines if a given
23 event is accepted (1) or rejected (0) for the efficiency to be measured,
24 this class evaluates as F if C is 'accept' and as (1-F) if
25 C is 'reject'. Values of F below 0 and above 1 are clipped.
26 F may have an arbitrary number of dependents and parameters
27 
28 The combination only 'reject' can be chosen to be visible or not visible
29 (and hence this efficiency is then equal to zero).
30 **/
31 
32 #include "RooFit.h"
33 
34 #include "RooMultiBinomial.h"
35 #include "RooStreamParser.h"
36 #include "RooArgList.h"
37 #include "RooAbsCategory.h"
38 #include "RooMsgService.h"
39 #include <string>
40 #include <vector>
41 
42 using namespace std ;
43 
45  ;
46 
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Construct the efficiency functions from a list of efficiency functions
50 /// and a list of categories cat with two states (0,1) that indicate if a given
51 /// event should be counted as rejected or accepted respectively
52 
53 RooMultiBinomial::RooMultiBinomial(const char *name, const char *title,
54  const RooArgList& effFuncList,
55  const RooArgList& catList,
56  Bool_t ignoreNonVisible) :
57  RooAbsReal(name,title),
58  _catList("catList","list of cats", this),
59  _effFuncList("effFuncList","list of eff funcs",this),
60  _ignoreNonVisible(ignoreNonVisible)
61 {
62  _catList.add(catList);
63  _effFuncList.add(effFuncList);
64 
65  if (_catList.getSize() != effFuncList.getSize()) {
66  coutE(InputArguments) << "RooMultiBinomial::ctor(" << GetName() << ") ERROR: Wrong input, should have equal number of categories and efficiencies." << endl;
67  throw string("RooMultiBinomial::ctor() ERROR: Wrong input, should have equal number of categories and efficiencies") ;
68  }
69 
70 }
71 
72 
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Copy constructor
76 
78  RooAbsReal(other, name),
79  _catList("catList",this,other._catList),
80  _effFuncList("effFuncList",this,other._effFuncList),
81  _ignoreNonVisible(other._ignoreNonVisible)
82 {
83 }
84 
85 
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 /// Destructor
89 
91 {
92 }
93 
94 
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// Calculate the raw value of the function which is the effFunc
98 /// value if cat==1 and it is (1-effFunc) if cat==0
99 
101 {
102  Int_t effFuncListSize = _effFuncList.getSize();
103 
104  // Get efficiency function for category i
105 
106  vector<Double_t> effFuncVal(effFuncListSize);
107  for (int i=0; i<effFuncListSize; ++i) {
108  effFuncVal[i] = ((RooAbsReal&)_effFuncList[i]).getVal() ;
109  }
110 
111  // Truncate efficiency functions in range 0.0-1.0
112 
113  for (int i=0; i<effFuncListSize; ++i) {
114  if (effFuncVal[i]>1) {
115  coutW(Eval) << "WARNING: Efficency >1 (equal to " << effFuncVal[i]
116  << " ), for i = " << i << "...TRUNCATED" << endl;
117  effFuncVal[i] = 1.0 ;
118  } else if (effFuncVal[i]<0) {
119  effFuncVal[i] = 0.0 ;
120  coutW(Eval) << "WARNING: Efficency <0 (equal to " << effFuncVal[i]
121  << " ), for i = " << i << "...TRUNCATED" << endl;
122  }
123  }
124 
125  vector<Double_t> effValue(effFuncListSize);
126  Bool_t notVisible = true;
127 
128  // Calculate efficiency per accept/reject decision
129 
130  for (int i=0; i<effFuncListSize; ++i) {
131  if ( ((RooAbsCategory&)_catList[i]).getIndex() == 1) {
132  // Accept case
133  effValue[i] = effFuncVal[i] ;
134  notVisible = false;
135  } else if ( ((RooAbsCategory&)_catList[i]).getIndex() == 0){
136  // Reject case
137  effValue[i] = 1 - effFuncVal[i] ;
138  } else {
139  coutW(Eval) << "WARNING: WRONG CATEGORY NAMES GIVEN!, label = " << ((RooAbsCategory&)_catList[i]).getIndex() << endl;
140  effValue[i] = 0;
141  }
142  }
143 
144  Double_t _effVal = 1.;
145 
146  // Calculate efficiency for combination of accept/reject categories
147  // put equal to zero if combination of only zeros AND chosen to be invisible
148 
149  for (int i=0; i<effFuncListSize; ++i) {
150  _effVal=_effVal*effValue[i];
151  if (notVisible && _ignoreNonVisible){
152  _effVal=0;
153  }
154  }
155 
156  return _effVal;
157 
158 }
159 
160 
161 
RooListProxy _effFuncList
#define coutE(a)
Definition: RooMsgService.h:35
virtual ~RooMultiBinomial()
Destructor.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
#define coutW(a)
Definition: RooMsgService.h:34
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
RooListProxy _catList
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
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...
#define name(a, b)
Definition: linkTestLib0.cpp:5
ClassImp(RooMultiBinomial)
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...
Int_t getSize() const