ROOT  6.06/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 //////////////////////////////////////////////////////////////////////////////
15 //
16 // BEGIN_HTML
17 // RooMultiBinomial is an efficiency function which makes all combinations of
18 // efficiencies given as input different effiency 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 // END_HTML
29 //
30 
31 #include "RooFit.h"
32 
33 #include "RooMultiBinomial.h"
34 #include "RooStreamParser.h"
35 #include "RooArgList.h"
36 #include "RooAbsCategory.h"
37 #include "RooMsgService.h"
38 #include <string>
39 #include <vector>
40 
41 using namespace std ;
42 
44  ;
45 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Construct the efficiency functions from a list of efficiency functions
49 /// and a list of categories cat with two states (0,1) that indicate if a given
50 /// event should be counted as rejected or accepted respectively
51 
52 RooMultiBinomial::RooMultiBinomial(const char *name, const char *title,
53  const RooArgList& effFuncList,
54  const RooArgList& catList,
55  Bool_t ignoreNonVisible) :
56  RooAbsReal(name,title),
57  _catList("catList","list of cats", this),
58  _effFuncList("effFuncList","list of eff funcs",this),
59  _ignoreNonVisible(ignoreNonVisible)
60 {
61  _catList.add(catList);
62  _effFuncList.add(effFuncList);
63 
64  if (_catList.getSize() != effFuncList.getSize()) {
65  coutE(InputArguments) << "RooMultiBinomial::ctor(" << GetName() << ") ERROR: Wrong input, should have equal number of categories and efficiencies." << endl;
66  throw string("RooMultiBinomial::ctor() ERROR: Wrong input, should have equal number of categories and efficiencies") ;
67  }
68 
69 }
70 
71 
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Copy constructor
75 
77  RooAbsReal(other, name),
78  _catList("catList",this,other._catList),
79  _effFuncList("effFuncList",this,other._effFuncList),
80  _ignoreNonVisible(other._ignoreNonVisible)
81 {
82 }
83 
84 
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// Destructor
88 
90 {
91 }
92 
93 
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Calculate the raw value of the function which is the effFunc
97 /// value if cat==1 and it is (1-effFunc) if cat==0
98 
100 {
101  Int_t effFuncListSize = _effFuncList.getSize();
102 
103  // Get efficiency function for category i
104 
105  vector<Double_t> effFuncVal(effFuncListSize);
106  for (int i=0; i<effFuncListSize; ++i) {
107  effFuncVal[i] = ((RooAbsReal&)_effFuncList[i]).getVal() ;
108  }
109 
110  // Truncate efficiency functions in range 0.0-1.0
111 
112  for (int i=0; i<effFuncListSize; ++i) {
113  if (effFuncVal[i]>1) {
114  coutW(Eval) << "WARNING: Efficency >1 (equal to " << effFuncVal[i]
115  << " ), for i = " << i << "...TRUNCATED" << endl;
116  effFuncVal[i] = 1.0 ;
117  } else if (effFuncVal[i]<0) {
118  effFuncVal[i] = 0.0 ;
119  coutW(Eval) << "WARNING: Efficency <0 (equal to " << effFuncVal[i]
120  << " ), for i = " << i << "...TRUNCATED" << endl;
121  }
122  }
123 
124  vector<Double_t> effValue(effFuncListSize);
125  Bool_t notVisible = true;
126 
127  // Calculate efficiency per accept/reject decision
128 
129  for (int i=0; i<effFuncListSize; ++i) {
130  if ( ((RooAbsCategory&)_catList[i]).getIndex() == 1) {
131  // Accept case
132  effValue[i] = effFuncVal[i] ;
133  notVisible = false;
134  } else if ( ((RooAbsCategory&)_catList[i]).getIndex() == 0){
135  // Reject case
136  effValue[i] = 1 - effFuncVal[i] ;
137  } else {
138  coutW(Eval) << "WARNING: WRONG CATEGORY NAMES GIVEN!, label = " << ((RooAbsCategory&)_catList[i]).getIndex() << endl;
139  effValue[i] = 0;
140  }
141  }
142 
143  Double_t _effVal = 1.;
144 
145  // Calculate efficiency for combination of accept/reject categories
146  // put equal to zero if combination of only zeros AND chosen to be invisible
147 
148  for (int i=0; i<effFuncListSize; ++i) {
149  _effVal=_effVal*effValue[i];
150  if (notVisible && _ignoreNonVisible){
151  _effVal=0;
152  }
153  }
154 
155  return _effVal;
156 
157 }
158 
159 
160 
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
STL namespace.
#define coutW(a)
Definition: RooMsgService.h:34
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
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
#define name(a, b)
Definition: linkTestLib0.cpp:5
ClassImp(RooMultiBinomial)
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