// adaptor that projects a real function via summation of states
// provided in a dataset. The real function must be attached to the
// dataset before creating this binding object.
//
// If the dataset only contains category variables, the summation is optimized
// performing a weighted sum over the states of a RooSuperCategory that is
// constructed from all the categories in the dataset
//
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "RooDataProjBinding.h"
#include "RooAbsReal.h"
#include "RooAbsData.h"
#include "Roo1DTable.h"
#include "RooSuperCategory.h"
#include "RooCategory.h"
#include "RooAbsPdf.h"
#include "RooMsgService.h"
#include <assert.h>
using namespace std;
ClassImp(RooDataProjBinding)
;
RooDataProjBinding::RooDataProjBinding(const RooAbsReal &real, const RooAbsData& data,
const RooArgSet &vars, const RooArgSet* nset) :
RooRealBinding(real,vars,0), _first(kTRUE), _real(&real), _data(&data), _nset(nset),
_superCat(0), _catTable(0)
{
TIterator* iter = data.get()->createIterator() ;
Bool_t allCat(kTRUE) ;
RooAbsArg* arg ;
while((arg=(RooAbsArg*)iter->Next())) {
if (!dynamic_cast<RooCategory*>(arg)) allCat = kFALSE ;
}
delete iter ;
if (allCat) {
_superCat = new RooSuperCategory("superCat","superCat",*data.get()) ;
_catTable = data.table(*_superCat) ;
}
}
RooDataProjBinding::~RooDataProjBinding()
{
if (_superCat) delete _superCat ;
if (_catTable) delete _catTable ;
}
Double_t RooDataProjBinding::operator()(const Double_t xvector[]) const
{
assert(isValid());
loadValues(xvector);
Double_t result(0) ;
Double_t wgtSum(0) ;
if (_catTable) {
TIterator* iter = _superCat->typeIterator() ;
RooCatType* type ;
while((type=(RooCatType*)iter->Next())) {
_superCat->setIndex(type->getVal()) ;
Double_t wgt = _catTable->get(type->GetName()) ;
if (wgt) {
result += wgt * _real->getVal(_nset) ;
wgtSum += wgt ;
}
}
delete iter ;
} else {
Int_t i ;
Int_t nEvt = _data->numEntries() ;
if (_first) {
oocoutW(_real,Eval) << "RooDataProjBinding::operator() projecting over " << nEvt << " events" << endl ;
_first = kFALSE ;
} else {
if (oodologW(_real,Eval)) {
ooccoutW(_real,Eval) << "." ; cout.flush() ;
}
}
for (i=0 ; i<nEvt ; i++) {
_data->get(i) ;
Double_t wgt = _data->weight() ;
Double_t ret ;
if (wgt) {
ret = _real->getVal(_nset) ;
result += wgt * ret ;
wgtSum += wgt ;
}
}
}
if (wgtSum==0) return 0 ;
return result / wgtSum ;
}
RooDataProjBinding.cxx:10 RooDataProjBinding.cxx:11 RooDataProjBinding.cxx:12 RooDataProjBinding.cxx:13 RooDataProjBinding.cxx:14 RooDataProjBinding.cxx:15 RooDataProjBinding.cxx:16 RooDataProjBinding.cxx:17 RooDataProjBinding.cxx:18 RooDataProjBinding.cxx:19 RooDataProjBinding.cxx:20 RooDataProjBinding.cxx:21 RooDataProjBinding.cxx:22 RooDataProjBinding.cxx:23 RooDataProjBinding.cxx:24 RooDataProjBinding.cxx:25 RooDataProjBinding.cxx:26 RooDataProjBinding.cxx:27 RooDataProjBinding.cxx:28 RooDataProjBinding.cxx:29 RooDataProjBinding.cxx:30 RooDataProjBinding.cxx:31 RooDataProjBinding.cxx:32 RooDataProjBinding.cxx:33 RooDataProjBinding.cxx:34 RooDataProjBinding.cxx:35 RooDataProjBinding.cxx:36 RooDataProjBinding.cxx:37 RooDataProjBinding.cxx:38 RooDataProjBinding.cxx:39 RooDataProjBinding.cxx:40 RooDataProjBinding.cxx:41 RooDataProjBinding.cxx:42 RooDataProjBinding.cxx:43 RooDataProjBinding.cxx:44 RooDataProjBinding.cxx:45 RooDataProjBinding.cxx:46 RooDataProjBinding.cxx:47 RooDataProjBinding.cxx:48 RooDataProjBinding.cxx:49 RooDataProjBinding.cxx:50 RooDataProjBinding.cxx:51 RooDataProjBinding.cxx:52 RooDataProjBinding.cxx:53 RooDataProjBinding.cxx:54 RooDataProjBinding.cxx:55 RooDataProjBinding.cxx:56 RooDataProjBinding.cxx:57 RooDataProjBinding.cxx:58 RooDataProjBinding.cxx:59 RooDataProjBinding.cxx:60 RooDataProjBinding.cxx:61 RooDataProjBinding.cxx:62 RooDataProjBinding.cxx:63 RooDataProjBinding.cxx:64 RooDataProjBinding.cxx:65 RooDataProjBinding.cxx:66 RooDataProjBinding.cxx:67 RooDataProjBinding.cxx:68 RooDataProjBinding.cxx:69 RooDataProjBinding.cxx:70 RooDataProjBinding.cxx:71 RooDataProjBinding.cxx:72 RooDataProjBinding.cxx:73 RooDataProjBinding.cxx:74 RooDataProjBinding.cxx:75 RooDataProjBinding.cxx:76 RooDataProjBinding.cxx:77 RooDataProjBinding.cxx:78 RooDataProjBinding.cxx:79 RooDataProjBinding.cxx:80 RooDataProjBinding.cxx:81 RooDataProjBinding.cxx:82 RooDataProjBinding.cxx:83 RooDataProjBinding.cxx:84 RooDataProjBinding.cxx:85 RooDataProjBinding.cxx:86 RooDataProjBinding.cxx:87 RooDataProjBinding.cxx:88 RooDataProjBinding.cxx:89 RooDataProjBinding.cxx:90 RooDataProjBinding.cxx:91 RooDataProjBinding.cxx:92 RooDataProjBinding.cxx:93 RooDataProjBinding.cxx:94 RooDataProjBinding.cxx:95 RooDataProjBinding.cxx:96 RooDataProjBinding.cxx:97 RooDataProjBinding.cxx:98 RooDataProjBinding.cxx:99 RooDataProjBinding.cxx:100 RooDataProjBinding.cxx:101 RooDataProjBinding.cxx:102 RooDataProjBinding.cxx:103 RooDataProjBinding.cxx:104 RooDataProjBinding.cxx:105 RooDataProjBinding.cxx:106 RooDataProjBinding.cxx:107 RooDataProjBinding.cxx:108 RooDataProjBinding.cxx:109 RooDataProjBinding.cxx:110 RooDataProjBinding.cxx:111 RooDataProjBinding.cxx:112 RooDataProjBinding.cxx:113 RooDataProjBinding.cxx:114 RooDataProjBinding.cxx:115 RooDataProjBinding.cxx:116 RooDataProjBinding.cxx:117 RooDataProjBinding.cxx:118 RooDataProjBinding.cxx:119 RooDataProjBinding.cxx:120 RooDataProjBinding.cxx:121 RooDataProjBinding.cxx:122 RooDataProjBinding.cxx:123 RooDataProjBinding.cxx:124 RooDataProjBinding.cxx:125 RooDataProjBinding.cxx:126 RooDataProjBinding.cxx:127 RooDataProjBinding.cxx:128 RooDataProjBinding.cxx:129 RooDataProjBinding.cxx:130 RooDataProjBinding.cxx:131 RooDataProjBinding.cxx:132 RooDataProjBinding.cxx:133 RooDataProjBinding.cxx:134 RooDataProjBinding.cxx:135 RooDataProjBinding.cxx:136 RooDataProjBinding.cxx:137 RooDataProjBinding.cxx:138 RooDataProjBinding.cxx:139 RooDataProjBinding.cxx:140 RooDataProjBinding.cxx:141 RooDataProjBinding.cxx:142 RooDataProjBinding.cxx:143 RooDataProjBinding.cxx:144 RooDataProjBinding.cxx:145 RooDataProjBinding.cxx:146 RooDataProjBinding.cxx:147 RooDataProjBinding.cxx:148 RooDataProjBinding.cxx:149 RooDataProjBinding.cxx:150 RooDataProjBinding.cxx:151 RooDataProjBinding.cxx:152 RooDataProjBinding.cxx:153 RooDataProjBinding.cxx:154 RooDataProjBinding.cxx:155 RooDataProjBinding.cxx:156 RooDataProjBinding.cxx:157 RooDataProjBinding.cxx:158 RooDataProjBinding.cxx:159 RooDataProjBinding.cxx:160 RooDataProjBinding.cxx:161 RooDataProjBinding.cxx:162 RooDataProjBinding.cxx:163