00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "RooFit.h"
00032 #include "Riostream.h"
00033
00034 #include "RooDataProjBinding.h"
00035 #include "RooAbsReal.h"
00036 #include "RooAbsData.h"
00037 #include "Roo1DTable.h"
00038 #include "RooSuperCategory.h"
00039 #include "RooCategory.h"
00040 #include "RooAbsPdf.h"
00041 #include "RooMsgService.h"
00042
00043 #include <assert.h>
00044
00045
00046
00047 ClassImp(RooDataProjBinding)
00048 ;
00049
00050
00051
00052 RooDataProjBinding::RooDataProjBinding(const RooAbsReal &real, const RooAbsData& data,
00053 const RooArgSet &vars, const RooArgSet* nset) :
00054 RooRealBinding(real,vars,0), _first(kTRUE), _real(&real), _data(&data), _nset(nset),
00055 _superCat(0), _catTable(0)
00056 {
00057
00058
00059
00060
00061
00062 TIterator* iter = data.get()->createIterator() ;
00063 Bool_t allCat(kTRUE) ;
00064 RooAbsArg* arg ;
00065 while((arg=(RooAbsArg*)iter->Next())) {
00066 if (!dynamic_cast<RooCategory*>(arg)) allCat = kFALSE ;
00067 }
00068 delete iter ;
00069
00070
00071 if (allCat) {
00072 _superCat = new RooSuperCategory("superCat","superCat",*data.get()) ;
00073 _catTable = data.table(*_superCat) ;
00074 }
00075 }
00076
00077
00078
00079
00080 RooDataProjBinding::~RooDataProjBinding()
00081 {
00082
00083 if (_superCat) delete _superCat ;
00084 if (_catTable) delete _catTable ;
00085 }
00086
00087
00088
00089
00090 Double_t RooDataProjBinding::operator()(const Double_t xvector[]) const
00091 {
00092
00093
00094 assert(isValid());
00095 loadValues(xvector);
00096
00097
00098
00099 Double_t result(0) ;
00100 Double_t wgtSum(0) ;
00101
00102 if (_catTable) {
00103
00104
00105 TIterator* iter = _superCat->typeIterator() ;
00106 RooCatType* type ;
00107 while((type=(RooCatType*)iter->Next())) {
00108
00109 _superCat->setIndex(type->getVal()) ;
00110
00111
00112 Double_t wgt = _catTable->get(type->GetName()) ;
00113 if (wgt) {
00114 result += wgt * _real->getVal(_nset) ;
00115 wgtSum += wgt ;
00116 }
00117 }
00118 delete iter ;
00119
00120 } else {
00121
00122
00123 Int_t i ;
00124 Int_t nEvt = _data->numEntries() ;
00125
00126
00127 if (_first) {
00128 oocoutW(_real,Eval) << "RooDataProjBinding::operator() projecting over " << nEvt << " events" << endl ;
00129 _first = kFALSE ;
00130 } else {
00131 if (oodologW(_real,Eval)) {
00132 ooccoutW(_real,Eval) << "." ; cout.flush() ;
00133 }
00134 }
00135
00136
00137
00138
00139
00140
00141 for (i=0 ; i<nEvt ; i++) {
00142 _data->get(i) ;
00143
00144 Double_t wgt = _data->weight() ;
00145 Double_t ret ;
00146 if (wgt) {
00147 ret = _real->getVal(_nset) ;
00148 result += wgt * ret ;
00149
00150
00151
00152 wgtSum += wgt ;
00153 }
00154 }
00155 }
00156
00157
00158
00159 if (wgtSum==0) return 0 ;
00160 return result / wgtSum ;
00161 }