// RooTreeDataStore is the abstract base class for data collection that
// use a TTree as internal storage mechanism
// END_HTML
#include "RooFit.h"
#include "RooMsgService.h"
#include "RooTreeDataStore.h"
#include "Riostream.h"
#include "TTree.h"
#include "TChain.h"
#include "TDirectory.h"
#include "TROOT.h"
#include "RooFormulaVar.h"
#include "RooRealVar.h"
#include "RooHistError.h"
#include <iomanip>
using namespace std ;
ClassImp(RooTreeDataStore)
;
Int_t RooTreeDataStore::_defTreeBufSize = 4096 ;
RooTreeDataStore::RooTreeDataStore() :
_tree(0),
_cacheTree(0),
_cacheOwner(0),
_defCtor(kTRUE),
_wgtVar(0),
_extWgtArray(0),
_extWgtErrLoArray(0),
_extWgtErrHiArray(0),
_extSumW2Array(0),
_curWgt(1),
_curWgtErrLo(0),
_curWgtErrHi(0),
_curWgtErr(0)
{
}
RooTreeDataStore::RooTreeDataStore(TTree* t, const RooArgSet& vars, const char* wgtVarName) :
RooAbsDataStore("blah","blah",varsNoWeight(vars,wgtVarName)),
_tree(t),
_cacheTree(0),
_cacheOwner(0),
_defCtor(kTRUE),
_varsww(vars),
_wgtVar(weightVar(vars,wgtVarName)),
_extWgtArray(0),
_extWgtErrLoArray(0),
_extWgtErrHiArray(0),
_extSumW2Array(0),
_curWgt(1)
{
}
RooTreeDataStore::RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const char* wgtVarName) :
RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
_tree(0),
_cacheTree(0),
_cacheOwner(0),
_defCtor(kFALSE),
_varsww(vars),
_wgtVar(weightVar(vars,wgtVarName)),
_extWgtArray(0),
_extWgtErrLoArray(0),
_extWgtErrHiArray(0),
_extSumW2Array(0),
_curWgt(1),
_curWgtErrLo(0),
_curWgtErrHi(0),
_curWgtErr(0)
{
initialize() ;
}
RooTreeDataStore::RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, TTree& t, const RooFormulaVar& select, const char* wgtVarName) :
RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
_tree(0),
_cacheTree(0),
_cacheOwner(0),
_defCtor(kFALSE),
_varsww(vars),
_wgtVar(weightVar(vars,wgtVarName)),
_extWgtArray(0),
_extWgtErrLoArray(0),
_extWgtErrHiArray(0),
_extSumW2Array(0),
_curWgt(1),
_curWgtErrLo(0),
_curWgtErrHi(0),
_curWgtErr(0)
{
initialize() ;
loadValues(&t,&select) ;
}
RooTreeDataStore::RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, TTree& t, const char* selExpr, const char* wgtVarName) :
RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
_tree(0),
_cacheTree(0),
_cacheOwner(0),
_defCtor(kFALSE),
_varsww(vars),
_wgtVar(weightVar(vars,wgtVarName)),
_extWgtArray(0),
_extWgtErrLoArray(0),
_extWgtErrHiArray(0),
_extSumW2Array(0),
_curWgt(1),
_curWgtErrLo(0),
_curWgtErrHi(0),
_curWgtErr(0)
{
initialize() ;
if (selExpr && *selExpr) {
RooFormulaVar select(selExpr,selExpr,_vars) ;
loadValues(&t,&select);
} else {
loadValues(&t);
}
}
RooTreeDataStore::RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const RooAbsDataStore& tds, const RooFormulaVar& select, const char* wgtVarName) :
RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
_tree(0),
_cacheTree(0),
_cacheOwner(0),
_defCtor(kFALSE),
_varsww(vars),
_wgtVar(weightVar(vars,wgtVarName)),
_extWgtArray(0),
_extWgtErrLoArray(0),
_extWgtErrHiArray(0),
_extSumW2Array(0),
_curWgt(1),
_curWgtErrLo(0),
_curWgtErrHi(0),
_curWgtErr(0)
{
initialize() ;
loadValues(&tds,&select) ;
}
RooTreeDataStore::RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const RooAbsDataStore& ads, const char* selExpr, const char* wgtVarName) :
RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
_tree(0),
_cacheTree(0),
_cacheOwner(0),
_defCtor(kFALSE),
_varsww(vars),
_wgtVar(weightVar(vars,wgtVarName)),
_extWgtArray(0),
_extWgtErrLoArray(0),
_extWgtErrHiArray(0),
_extSumW2Array(0),
_curWgt(1),
_curWgtErrLo(0),
_curWgtErrHi(0),
_curWgtErr(0)
{
initialize() ;
if (selExpr && *selExpr) {
RooFormulaVar select(selExpr,selExpr,_vars) ;
loadValues(&ads,&select);
} else {
loadValues(&ads);
}
}
RooTreeDataStore::RooTreeDataStore(const char *name, const char *title, RooAbsDataStore& tds,
const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
Int_t nStart, Int_t nStop, Bool_t , const char* wgtVarName) :
RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)), _defCtor(kFALSE),
_varsww(vars),
_wgtVar(weightVar(vars,wgtVarName)),
_extWgtArray(0),
_extWgtErrLoArray(0),
_extWgtErrHiArray(0),
_extSumW2Array(0),
_curWgt(1),
_curWgtErrLo(0),
_curWgtErrHi(0),
_curWgtErr(0)
{
_tree = 0 ;
_cacheTree = 0 ;
createTree(name,title) ;
RooFormulaVar* cloneVar = 0;
if (cutVar) {
cloneVar = (RooFormulaVar*) cutVar->cloneTree() ;
cloneVar->attachDataStore(tds) ;
}
initialize();
attachCache(0,((RooTreeDataStore&)tds)._cachedVars) ;
_cacheTree->CopyEntries(((RooTreeDataStore&)tds)._cacheTree) ;
_cacheOwner = 0 ;
loadValues(&tds,cloneVar,cutRange,nStart,nStop);
if (cloneVar) delete cloneVar ;
}
RooArgSet RooTreeDataStore::varsNoWeight(const RooArgSet& allVars, const char* wgtName)
{
RooArgSet ret(allVars) ;
if(wgtName) {
RooAbsArg* wgt = allVars.find(wgtName) ;
if (wgt) {
ret.remove(*wgt,kTRUE,kTRUE) ;
}
}
return ret ;
}
RooRealVar* RooTreeDataStore::weightVar(const RooArgSet& allVars, const char* wgtName)
{
if(wgtName) {
RooRealVar* wgt = dynamic_cast<RooRealVar*>(allVars.find(wgtName)) ;
return wgt ;
}
return 0 ;
}
void RooTreeDataStore::attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVarsIn)
{
_cachedVars.removeAll() ;
TIterator* iter = cachedVarsIn.createIterator() ;
RooAbsArg *var;
while((0 != (var= (RooAbsArg*)iter->Next()))) {
var->attachToTree(*_cacheTree,_defTreeBufSize) ;
_cachedVars.add(*var) ;
}
delete iter ;
_cacheOwner = newOwner ;
}
RooTreeDataStore::RooTreeDataStore(const RooTreeDataStore& other, const char* newname) :
RooAbsDataStore(other,newname),
_tree(0),
_cacheTree(0),
_defCtor(kFALSE),
_varsww(other._varsww),
_wgtVar(other._wgtVar),
_extWgtArray(other._extWgtArray),
_extWgtErrLoArray(other._extWgtErrLoArray),
_extWgtErrHiArray(other._extWgtErrHiArray),
_extSumW2Array(other._extSumW2Array),
_curWgt(other._curWgt),
_curWgtErrLo(other._curWgtErrLo),
_curWgtErrHi(other._curWgtErrHi),
_curWgtErr(other._curWgtErr)
{
initialize() ;
loadValues(&other) ;
}
RooTreeDataStore::RooTreeDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname) :
RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
_tree(0),
_cacheTree(0),
_defCtor(kFALSE),
_varsww(vars),
_wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):0),
_extWgtArray(other._extWgtArray),
_extWgtErrLoArray(other._extWgtErrLoArray),
_extWgtErrHiArray(other._extWgtErrHiArray),
_extSumW2Array(other._extSumW2Array),
_curWgt(other._curWgt),
_curWgtErrLo(other._curWgtErrLo),
_curWgtErrHi(other._curWgtErrHi),
_curWgtErr(other._curWgtErr)
{
initialize() ;
loadValues(&other) ;
}
RooTreeDataStore::~RooTreeDataStore()
{
if (_tree) {
delete _tree ;
}
if (_cacheTree) {
delete _cacheTree ;
}
}
void RooTreeDataStore::initialize()
{
createTree(GetName(),GetTitle()) ;
TIterator* iter = _varsww.createIterator() ;
RooAbsArg *var;
while((0 != (var= (RooAbsArg*)iter->Next()))) {
var->attachToTree(*_tree,_defTreeBufSize) ;
}
delete iter ;
}
void RooTreeDataStore::createTree(const char* name, const char* title)
{
TString pwd(gDirectory->GetPath()) ;
TString memDir(gROOT->GetName()) ;
memDir.Append(":/") ;
Bool_t notInMemNow= (pwd!=memDir) ;
if (notInMemNow) {
gDirectory->cd(memDir) ;
}
if (!_tree) {
_tree = new TTree(name,title) ;
_tree->SetDirectory(0) ;
gDirectory->RecursiveRemove(_tree) ;
}
if (!_cacheTree) {
_cacheTree = new TTree(name,title) ;
_cacheTree->SetDirectory(0) ;
gDirectory->RecursiveRemove(_cacheTree) ;
}
if (notInMemNow) {
gDirectory->cd(pwd) ;
}
}
void RooTreeDataStore::loadValues(const TTree *t, const RooFormulaVar* select, const char* , Int_t , Int_t )
{
TString pwd(gDirectory->GetPath()) ;
TString memDir(gROOT->GetName()) ;
memDir.Append(":/") ;
Bool_t notInMemNow= (pwd!=memDir) ;
if (notInMemNow) {
gDirectory->cd(memDir) ;
}
TTree* tClone ;
if (dynamic_cast<const TChain*>(t)) {
tClone = (TTree*) t->Clone() ;
} else {
tClone = ((TTree*)t)->CloneTree() ;
}
tClone->SetDirectory(0) ;
if (notInMemNow) {
gDirectory->cd(pwd) ;
}
RooArgSet *sourceArgSet = (RooArgSet*) _varsww.snapshot(kFALSE) ;
TIterator* sourceIter = sourceArgSet->createIterator() ;
RooAbsArg* sourceArg = 0;
while ((sourceArg=(RooAbsArg*)sourceIter->Next())) {
sourceArg->attachToTree(*tClone,_defTreeBufSize) ;
}
RooFormulaVar* selectClone(0) ;
if (select) {
selectClone = (RooFormulaVar*) select->cloneTree() ;
selectClone->recursiveRedirectServers(*sourceArgSet) ;
selectClone->setOperMode(RooAbsArg::ADirty,kTRUE) ;
}
RooAbsArg* destArg = 0;
TIterator* destIter = _varsww.createIterator() ;
Int_t numInvalid(0) ;
Int_t nevent= (Int_t)tClone->GetEntries();
for(Int_t i=0; i < nevent; ++i) {
Int_t entryNumber=tClone->GetEntryNumber(i);
if (entryNumber<0) break;
tClone->GetEntry(entryNumber,1);
destIter->Reset() ;
sourceIter->Reset() ;
Bool_t allOK(kTRUE) ;
while ((destArg = (RooAbsArg*)destIter->Next())) {
sourceArg = (RooAbsArg*) sourceIter->Next() ;
destArg->copyCache(sourceArg) ;
sourceArg->copyCache(destArg) ;
if (!destArg->isValid()) {
numInvalid++ ;
allOK=kFALSE ;
break ;
}
}
if (!allOK || (selectClone && selectClone->getVal()==0)) {
continue ;
}
fill() ;
}
delete destIter ;
if (numInvalid>0) {
coutI(Eval) << "RooTreeDataStore::loadValues(" << GetName() << ") Ignored " << numInvalid << " out of range events" << endl ;
}
SetTitle(t->GetTitle());
delete sourceIter ;
delete sourceArgSet ;
delete selectClone ;
delete tClone ;
}
void RooTreeDataStore::loadValues(const RooAbsDataStore *ads, const RooFormulaVar* select,
const char* rangeName, Int_t nStart, Int_t nStop)
{
RooFormulaVar* selectClone(0) ;
if (select) {
selectClone = (RooFormulaVar*) select->cloneTree() ;
selectClone->recursiveRedirectServers(*ads->get()) ;
selectClone->setOperMode(RooAbsArg::ADirty,kTRUE) ;
}
ads->get(0) ;
RooAbsArg* arg = 0;
TIterator* destIter = _varsww.createIterator() ;
Int_t nevent = nStop < ads->numEntries() ? nStop : ads->numEntries() ;
Bool_t allValid ;
Bool_t isTDS = dynamic_cast<const RooTreeDataStore*>(ads) ;
if (isTDS) {
((RooTreeDataStore*)(ads))->resetBuffers() ;
}
for(Int_t i=nStart; i < nevent ; ++i) {
ads->get(i) ;
if (selectClone && selectClone->getVal()==0) {
continue ;
}
if (isTDS) {
_varsww.assignValueOnly(((RooTreeDataStore*)ads)->_varsww) ;
} else {
_varsww.assignValueOnly(*ads->get()) ;
}
destIter->Reset() ;
allValid=kTRUE ;
while((arg=(RooAbsArg*)destIter->Next())) {
if (!arg->isValid() || (rangeName && !arg->inRange(rangeName))) {
allValid=kFALSE ;
break ;
}
}
if (!allValid) {
continue ;
}
_cachedVars = ((RooTreeDataStore*)ads)->_cachedVars ;
fill() ;
}
delete destIter ;
if (isTDS) {
((RooTreeDataStore*)(ads))->restoreAlternateBuffers() ;
}
delete selectClone ;
SetTitle(ads->GetTitle());
}
Bool_t RooTreeDataStore::valid() const
{
return kTRUE ;
}
Int_t RooTreeDataStore::fill()
{
return _tree->Fill() ;
}
const RooArgSet* RooTreeDataStore::get(Int_t index) const
{
checkInit() ;
Int_t ret = ((RooTreeDataStore*)this)->GetEntry(index, 1) ;
if(!ret) return 0;
if (_doDirtyProp) {
_iterator->Reset() ;
RooAbsArg* var = 0;
while ((var=(RooAbsArg*)_iterator->Next())) {
var->setValueDirty() ;
}
_cacheIter->Reset() ;
while ((var=(RooAbsArg*)_cacheIter->Next())) {
var->setValueDirty() ;
var->clearValueDirty() ;
}
}
if (_extWgtArray) {
_curWgt = _extWgtArray[index] ;
_curWgtErrLo = _extWgtErrLoArray[index] ;
_curWgtErrHi = _extWgtErrHiArray[index] ;
_curWgtErr = sqrt(_extSumW2Array[index]) ;
} else if (_wgtVar) {
_curWgt = _wgtVar->getVal() ;
_curWgtErrLo = _wgtVar->getAsymErrorLo() ;
_curWgtErrHi = _wgtVar->getAsymErrorHi() ;
_curWgtErr = _wgtVar->hasAsymError() ? ((_wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo())/2) : _wgtVar->getError() ;
} else {
_curWgt=1.0 ;
_curWgtErrLo = 0 ;
_curWgtErrHi = 0 ;
_curWgtErr = 0 ;
}
return &_vars;
}
Double_t RooTreeDataStore::weight(Int_t index) const
{
get(index) ;
return weight() ;
}
Double_t RooTreeDataStore::weight() const
{
return _curWgt ;
}
Double_t RooTreeDataStore::weightError(RooAbsData::ErrorType etype) const
{
if (_extWgtArray) {
Double_t lo,hi ;
weightError(lo,hi,etype) ;
return (lo+hi)/2 ;
} else if (_wgtVar) {
if (_wgtVar->hasAsymError()) {
return ( _wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo() ) / 2 ;
} else {
return _wgtVar->getError() ;
}
} else {
return 0 ;
}
}
void RooTreeDataStore::weightError(Double_t& lo, Double_t& hi, RooAbsData::ErrorType etype) const
{
if (_extWgtArray) {
switch (etype) {
case RooAbsData::Auto:
throw string(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
break ;
case RooAbsData::Expected:
throw string(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
break ;
case RooAbsData::Poisson:
if (_curWgtErrLo>=0) {
lo = _curWgtErrLo ;
hi = _curWgtErrHi ;
return ;
}
Double_t ym,yp ;
RooHistError::instance().getPoissonInterval(Int_t(weight()+0.5),ym,yp,1) ;
lo = weight()-ym ;
hi = yp-weight() ;
return ;
case RooAbsData::SumW2:
lo = _curWgtErr ;
hi = _curWgtErr ;
return ;
case RooAbsData::None:
lo = 0 ;
hi = 0 ;
return ;
}
} else if (_wgtVar) {
if (_wgtVar->hasAsymError()) {
hi = _wgtVar->getAsymErrorHi() ;
lo = _wgtVar->getAsymErrorLo() ;
} else {
hi = _wgtVar->getError() ;
lo = _wgtVar->getError() ;
}
} else {
lo=0 ;
hi=0 ;
}
}
Bool_t RooTreeDataStore::changeObservableName(const char* from, const char* to)
{
RooAbsArg* var = _vars.find(from) ;
if (!var) {
coutE(InputArguments) << "RooTreeDataStore::changeObservableName(" << GetName() << " no observable " << from << " in this dataset" << endl ;
return kTRUE ;
}
TString oldBranchName = var->cleanBranchName() ;
var->SetName(to) ;
if (_tree->GetBranch(oldBranchName.Data())) {
_tree->GetBranch(oldBranchName.Data())->SetName(var->cleanBranchName().Data()) ;
if (_tree->GetBranch(Form("%s_err",oldBranchName.Data()))) {
_tree->GetBranch(Form("%s_err",oldBranchName.Data()))->SetName(Form("%s_err",var->cleanBranchName().Data())) ;
}
if (_tree->GetBranch(Form("%s_aerr_lo",oldBranchName.Data()))) {
_tree->GetBranch(Form("%s_aerr_lo",oldBranchName.Data()))->SetName(Form("%s_aerr_lo",var->cleanBranchName().Data())) ;
}
if (_tree->GetBranch(Form("%s_aerr_hi",oldBranchName.Data()))) {
_tree->GetBranch(Form("%s_aerr_hi",oldBranchName.Data()))->SetName(Form("%s_aerr_hi",var->cleanBranchName().Data())) ;
}
} else {
if (_tree->GetBranch(Form("%s_idx",oldBranchName.Data()))) {
_tree->GetBranch(Form("%s_idx",oldBranchName.Data()))->SetName(Form("%s_idx",var->cleanBranchName().Data())) ;
}
if (_tree->GetBranch(Form("%s_lbl",oldBranchName.Data()))) {
_tree->GetBranch(Form("%s_lbl",oldBranchName.Data()))->SetName(Form("%s_lb",var->cleanBranchName().Data())) ;
}
}
return kFALSE ;
}
RooAbsArg* RooTreeDataStore::addColumn(RooAbsArg& newVar, Bool_t adjustRange)
{
checkInit() ;
RooAbsArg* valHolder= newVar.createFundamental();
if(!valHolder->isFundamental()) {
coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
<< valHolder->GetName() << "\"" << endl;
return 0;
}
resetBuffers() ;
RooAbsArg* newVarClone = newVar.cloneTree() ;
newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
((RooAbsArg*)valHolder)->attachToTree(*_tree,_defTreeBufSize) ;
_vars.add(*valHolder) ;
_varsww.add(*valHolder) ;
for (int i=0 ; i<GetEntries() ; i++) {
get(i) ;
newVarClone->syncCache(&_vars) ;
valHolder->copyCache(newVarClone) ;
valHolder->fillTreeBranch(*_tree) ;
}
restoreAlternateBuffers() ;
if (adjustRange) {
}
delete newVarClone ;
return valHolder ;
}
RooArgSet* RooTreeDataStore::addColumns(const RooArgList& varList)
{
TIterator* vIter = varList.createIterator() ;
RooAbsArg* var ;
checkInit() ;
TList cloneSetList ;
RooArgSet cloneSet ;
RooArgSet* holderSet = new RooArgSet ;
resetBuffers() ;
while((var=(RooAbsArg*)vIter->Next())) {
RooAbsArg* valHolder= var->createFundamental();
holderSet->add(*valHolder) ;
if(!valHolder->isFundamental()) {
coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
<< valHolder->GetName() << "\"" << endl;
return 0;
}
RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
if (!newVarCloneList) {
coutE(InputArguments) << "RooTreeDataStore::RooTreeData(" << GetName()
<< ") Couldn't deep-clone variable " << var->GetName() << ", abort." << endl ;
return 0 ;
}
RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
newVarClone->recursiveRedirectServers(*holderSet,kFALSE) ;
cloneSetList.Add(newVarCloneList) ;
cloneSet.add(*newVarClone) ;
((RooAbsArg*)valHolder)->attachToTree(*_tree,_defTreeBufSize) ;
_vars.addOwned(*valHolder) ;
}
delete vIter ;
TIterator* cIter = cloneSet.createIterator() ;
TIterator* hIter = holderSet->createIterator() ;
RooAbsArg *cloneArg, *holder ;
for (int i=0 ; i<GetEntries() ; i++) {
get(i) ;
cIter->Reset() ;
hIter->Reset() ;
while((cloneArg=(RooAbsArg*)cIter->Next())) {
holder = (RooAbsArg*)hIter->Next() ;
cloneArg->syncCache(&_vars) ;
holder->copyCache(cloneArg) ;
holder->fillTreeBranch(*_tree) ;
}
}
restoreAlternateBuffers() ;
delete cIter ;
delete hIter ;
cloneSetList.Delete() ;
return holderSet ;
}
RooAbsDataStore* RooTreeDataStore::merge(const RooArgSet& allVars, list<RooAbsDataStore*> dstoreList)
{
RooTreeDataStore* mergedStore = new RooTreeDataStore("merged","merged",allVars) ;
Int_t nevt = dstoreList.front()->numEntries() ;
for (int i=0 ; i<nevt ; i++) {
mergedStore->_vars = *get(i) ;
for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; iter++) {
const RooArgSet* partSet = (*iter)->get(i) ;
mergedStore->_vars = *partSet ;
}
mergedStore->fill() ;
}
return mergedStore ;
}
void RooTreeDataStore::append(RooAbsDataStore& other)
{
Int_t nevt = other.numEntries() ;
for (int i=0 ; i<nevt ; i++) {
_vars = *other.get(i) ;
if (_wgtVar) {
_wgtVar->setVal(other.weight()) ;
}
fill() ;
}
}
Double_t RooTreeDataStore::sumEntries() const
{
if (_wgtVar) {
Double_t sum(0), carry(0);
Int_t nevt = numEntries() ;
for (int i=0 ; i<nevt ; i++) {
get(i) ;
Double_t y = _wgtVar->getVal() - carry;
Double_t t = sum + y;
carry = (t - sum) - y;
sum = t;
}
return sum ;
} else if (_extWgtArray) {
Double_t sum(0) , carry(0);
Int_t nevt = numEntries() ;
for (int i=0 ; i<nevt ; i++) {
Double_t y = _extWgtArray[i] - carry;
Double_t t = sum + y;
carry = (t - sum) - y;
sum = t;
}
return sum ;
} else {
return numEntries() ;
}
}
Int_t RooTreeDataStore::numEntries() const
{
return _tree->GetEntries() ;
}
void RooTreeDataStore::reset()
{
Reset() ;
}
void RooTreeDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, const RooArgSet* nset)
{
checkInit() ;
_cacheOwner = owner ;
RooArgSet* constExprVarSet = (RooArgSet*) newVarSet.selectByAttrib("ConstantExpression",kTRUE) ;
TIterator *iter = constExprVarSet->createIterator() ;
RooAbsArg *arg ;
Bool_t doTreeFill = (_cachedVars.getSize()==0) ;
while ((arg=(RooAbsArg*)iter->Next())) {
arg->attachToTree(*_cacheTree,_defTreeBufSize) ;
_cachedVars.add(*arg) ;
}
for (int i=0 ; i<GetEntries() ; i++) {
get(i) ;
iter->Reset() ;
while ((arg=(RooAbsArg*)iter->Next())) {
arg->setValueDirty() ;
arg->syncCache(nset) ;
if (!doTreeFill) {
arg->fillTreeBranch(*_cacheTree) ;
}
}
if (doTreeFill) {
_cacheTree->Fill() ;
}
}
delete iter ;
delete constExprVarSet ;
}
void RooTreeDataStore::setArgStatus(const RooArgSet& set, Bool_t active)
{
TIterator* iter = set.createIterator() ;
RooAbsArg* arg ;
while ((arg=(RooAbsArg*)iter->Next())) {
RooAbsArg* depArg = _vars.find(arg->GetName()) ;
if (!depArg) {
coutE(InputArguments) << "RooTreeDataStore::setArgStatus(" << GetName()
<< ") dataset doesn't contain variable " << arg->GetName() << endl ;
continue ;
}
depArg->setTreeBranchStatus(*_tree,active) ;
}
delete iter ;
}
void RooTreeDataStore::resetCache()
{
_cachedVars.removeAll() ;
delete _cacheTree ;
_cacheTree = 0 ;
createTree(GetName(),GetTitle()) ;
return ;
}
void RooTreeDataStore::attachBuffers(const RooArgSet& extObs)
{
_attachedBuffers.removeAll() ;
RooFIter iter = _varsww.fwdIterator() ;
RooAbsArg* arg ;
while((arg=iter.next())) {
RooAbsArg* extArg = extObs.find(arg->GetName()) ;
if (extArg) {
if (arg->getAttribute("StoreError")) {
extArg->setAttribute("StoreError") ;
}
if (arg->getAttribute("StoreAsymError")) {
extArg->setAttribute("StoreAsymError") ;
}
extArg->attachToTree(*_tree) ;
_attachedBuffers.add(*extArg) ;
}
}
}
void RooTreeDataStore::resetBuffers()
{
RooFIter iter = _varsww.fwdIterator() ;
RooAbsArg* arg ;
while((arg=iter.next())) {
arg->attachToTree(*_tree) ;
}
}
void RooTreeDataStore::restoreAlternateBuffers()
{
RooFIter iter = _attachedBuffers.fwdIterator() ;
RooAbsArg* arg ;
while((arg=iter.next())) {
arg->attachToTree(*_tree) ;
}
}
void RooTreeDataStore::checkInit() const
{
if (_defCtor) {
const_cast<RooTreeDataStore*>(this)->initialize() ;
_defCtor = kFALSE ;
}
}
Stat_t RooTreeDataStore::GetEntries() const
{
return _tree->GetEntries() ;
}
void RooTreeDataStore::Reset(Option_t* option)
{
_tree->Reset(option) ;
}
Int_t RooTreeDataStore::Fill()
{
return _tree->Fill() ;
}
Int_t RooTreeDataStore::GetEntry(Int_t entry, Int_t getall)
{
Int_t ret1 = _tree->GetEntry(entry,getall) ;
if (!ret1) return 0 ;
_cacheTree->GetEntry(entry,getall) ;
return ret1 ;
}
void RooTreeDataStore::Draw(Option_t* option)
{
_tree->Draw(option) ;
}
void RooTreeDataStore::Streamer(TBuffer &R__b)
{
if (R__b.IsReading()) {
R__b.ReadClassBuffer(RooTreeDataStore::Class(),this);
initialize() ;
} else {
R__b.WriteClassBuffer(RooTreeDataStore::Class(),this);
}
}
RooTreeDataStore.cxx:1000 RooTreeDataStore.cxx:1001 RooTreeDataStore.cxx:1002 RooTreeDataStore.cxx:1003 RooTreeDataStore.cxx:1004 RooTreeDataStore.cxx:1005 RooTreeDataStore.cxx:1006 RooTreeDataStore.cxx:1007 RooTreeDataStore.cxx:1008 RooTreeDataStore.cxx:1009 RooTreeDataStore.cxx:1010 RooTreeDataStore.cxx:1011 RooTreeDataStore.cxx:1012 RooTreeDataStore.cxx:1013 RooTreeDataStore.cxx:1014 RooTreeDataStore.cxx:1015 RooTreeDataStore.cxx:1016 RooTreeDataStore.cxx:1017 RooTreeDataStore.cxx:1018 RooTreeDataStore.cxx:1019 RooTreeDataStore.cxx:1020 RooTreeDataStore.cxx:1021 RooTreeDataStore.cxx:1022 RooTreeDataStore.cxx:1023 RooTreeDataStore.cxx:1024 RooTreeDataStore.cxx:1025 RooTreeDataStore.cxx:1026 RooTreeDataStore.cxx:1027 RooTreeDataStore.cxx:1028 RooTreeDataStore.cxx:1029 RooTreeDataStore.cxx:1030 RooTreeDataStore.cxx:1031 RooTreeDataStore.cxx:1032 RooTreeDataStore.cxx:1033 RooTreeDataStore.cxx:1034 RooTreeDataStore.cxx:1035 RooTreeDataStore.cxx:1036 RooTreeDataStore.cxx:1037 RooTreeDataStore.cxx:1038 RooTreeDataStore.cxx:1039 RooTreeDataStore.cxx:1040 RooTreeDataStore.cxx:1041 RooTreeDataStore.cxx:1042 RooTreeDataStore.cxx:1043 RooTreeDataStore.cxx:1044 RooTreeDataStore.cxx:1045 RooTreeDataStore.cxx:1046 RooTreeDataStore.cxx:1047 RooTreeDataStore.cxx:1048 RooTreeDataStore.cxx:1049 RooTreeDataStore.cxx:1050 RooTreeDataStore.cxx:1051 RooTreeDataStore.cxx:1052 RooTreeDataStore.cxx:1053 RooTreeDataStore.cxx:1054 RooTreeDataStore.cxx:1055 RooTreeDataStore.cxx:1056 RooTreeDataStore.cxx:1057 RooTreeDataStore.cxx:1058 RooTreeDataStore.cxx:1059 RooTreeDataStore.cxx:1060 RooTreeDataStore.cxx:1061 RooTreeDataStore.cxx:1062 RooTreeDataStore.cxx:1063 RooTreeDataStore.cxx:1064 RooTreeDataStore.cxx:1065 RooTreeDataStore.cxx:1066 RooTreeDataStore.cxx:1067 RooTreeDataStore.cxx:1068 RooTreeDataStore.cxx:1069 RooTreeDataStore.cxx:1070 RooTreeDataStore.cxx:1071 RooTreeDataStore.cxx:1072 RooTreeDataStore.cxx:1073 RooTreeDataStore.cxx:1074 RooTreeDataStore.cxx:1075 RooTreeDataStore.cxx:1076 RooTreeDataStore.cxx:1077 RooTreeDataStore.cxx:1078 RooTreeDataStore.cxx:1079 RooTreeDataStore.cxx:1080 RooTreeDataStore.cxx:1081 RooTreeDataStore.cxx:1082 RooTreeDataStore.cxx:1083 RooTreeDataStore.cxx:1084 RooTreeDataStore.cxx:1085 RooTreeDataStore.cxx:1086 RooTreeDataStore.cxx:1087 RooTreeDataStore.cxx:1088 RooTreeDataStore.cxx:1089 RooTreeDataStore.cxx:1090 RooTreeDataStore.cxx:1091 RooTreeDataStore.cxx:1092 RooTreeDataStore.cxx:1093 RooTreeDataStore.cxx:1094 RooTreeDataStore.cxx:1095 RooTreeDataStore.cxx:1096 RooTreeDataStore.cxx:1097 RooTreeDataStore.cxx:1098 RooTreeDataStore.cxx:1099 RooTreeDataStore.cxx:1100 RooTreeDataStore.cxx:1101 RooTreeDataStore.cxx:1102 RooTreeDataStore.cxx:1103 RooTreeDataStore.cxx:1104 RooTreeDataStore.cxx:1105 RooTreeDataStore.cxx:1106 RooTreeDataStore.cxx:1107 RooTreeDataStore.cxx:1108 RooTreeDataStore.cxx:1109 RooTreeDataStore.cxx:1110 RooTreeDataStore.cxx:1111 RooTreeDataStore.cxx:1112 RooTreeDataStore.cxx:1113 RooTreeDataStore.cxx:1114 RooTreeDataStore.cxx:1115 RooTreeDataStore.cxx:1116 RooTreeDataStore.cxx:1117 RooTreeDataStore.cxx:1118 RooTreeDataStore.cxx:1119 RooTreeDataStore.cxx:1120 RooTreeDataStore.cxx:1121 RooTreeDataStore.cxx:1122 RooTreeDataStore.cxx:1123 RooTreeDataStore.cxx:1124 RooTreeDataStore.cxx:1125 RooTreeDataStore.cxx:1126 RooTreeDataStore.cxx:1127 RooTreeDataStore.cxx:1128 RooTreeDataStore.cxx:1129 RooTreeDataStore.cxx:1130 RooTreeDataStore.cxx:1131 RooTreeDataStore.cxx:1132 RooTreeDataStore.cxx:1133 RooTreeDataStore.cxx:1134 RooTreeDataStore.cxx:1135 RooTreeDataStore.cxx:1136 RooTreeDataStore.cxx:1137 RooTreeDataStore.cxx:1138 RooTreeDataStore.cxx:1139 RooTreeDataStore.cxx:1140 RooTreeDataStore.cxx:1141 RooTreeDataStore.cxx:1142 RooTreeDataStore.cxx:1143 RooTreeDataStore.cxx:1144 RooTreeDataStore.cxx:1145 RooTreeDataStore.cxx:1146 RooTreeDataStore.cxx:1147 RooTreeDataStore.cxx:1148 RooTreeDataStore.cxx:1149 RooTreeDataStore.cxx:1150 RooTreeDataStore.cxx:1151 RooTreeDataStore.cxx:1152 RooTreeDataStore.cxx:1153 RooTreeDataStore.cxx:1154 RooTreeDataStore.cxx:1155 RooTreeDataStore.cxx:1156 RooTreeDataStore.cxx:1157 RooTreeDataStore.cxx:1158 RooTreeDataStore.cxx:1159 RooTreeDataStore.cxx:1160 RooTreeDataStore.cxx:1161 RooTreeDataStore.cxx:1162 RooTreeDataStore.cxx:1163 RooTreeDataStore.cxx:1164 RooTreeDataStore.cxx:1165 RooTreeDataStore.cxx:1166 RooTreeDataStore.cxx:1167 RooTreeDataStore.cxx:1168 RooTreeDataStore.cxx:1169 RooTreeDataStore.cxx:1170 RooTreeDataStore.cxx:1171 RooTreeDataStore.cxx:1172 RooTreeDataStore.cxx:1173 RooTreeDataStore.cxx:1174 RooTreeDataStore.cxx:1175 RooTreeDataStore.cxx:1176 RooTreeDataStore.cxx:1177 RooTreeDataStore.cxx:1178 RooTreeDataStore.cxx:1179 RooTreeDataStore.cxx:1180 RooTreeDataStore.cxx:1181 RooTreeDataStore.cxx:1182 RooTreeDataStore.cxx:1183 RooTreeDataStore.cxx:1184 RooTreeDataStore.cxx:1185 RooTreeDataStore.cxx:1186 RooTreeDataStore.cxx:1187 RooTreeDataStore.cxx:1188 RooTreeDataStore.cxx:1189 RooTreeDataStore.cxx:1190 RooTreeDataStore.cxx:1191 RooTreeDataStore.cxx:1192 RooTreeDataStore.cxx:1193 RooTreeDataStore.cxx:1194 RooTreeDataStore.cxx:1195 RooTreeDataStore.cxx:1196 RooTreeDataStore.cxx:1197 RooTreeDataStore.cxx:1198 RooTreeDataStore.cxx:1199 RooTreeDataStore.cxx:1200 RooTreeDataStore.cxx:1201 RooTreeDataStore.cxx:1202 RooTreeDataStore.cxx:1203 RooTreeDataStore.cxx:1204 RooTreeDataStore.cxx:1205 RooTreeDataStore.cxx:1206 RooTreeDataStore.cxx:1207 RooTreeDataStore.cxx:1208 RooTreeDataStore.cxx:1209 RooTreeDataStore.cxx:1210 RooTreeDataStore.cxx:1211 RooTreeDataStore.cxx:1212 RooTreeDataStore.cxx:1213 RooTreeDataStore.cxx:1214 RooTreeDataStore.cxx:1215 RooTreeDataStore.cxx:1216 RooTreeDataStore.cxx:1217 RooTreeDataStore.cxx:1218 RooTreeDataStore.cxx:1219 RooTreeDataStore.cxx:1220 RooTreeDataStore.cxx:1221 RooTreeDataStore.cxx:1222 RooTreeDataStore.cxx:1223 RooTreeDataStore.cxx:1224 RooTreeDataStore.cxx:1225 RooTreeDataStore.cxx:1226 RooTreeDataStore.cxx:1227 RooTreeDataStore.cxx:1228 RooTreeDataStore.cxx:1229 RooTreeDataStore.cxx:1230 RooTreeDataStore.cxx:1231 RooTreeDataStore.cxx:1232 RooTreeDataStore.cxx:1233 RooTreeDataStore.cxx:1234 RooTreeDataStore.cxx:1235 RooTreeDataStore.cxx:1236 RooTreeDataStore.cxx:1237 RooTreeDataStore.cxx:1238 RooTreeDataStore.cxx:1239 RooTreeDataStore.cxx:1240 RooTreeDataStore.cxx:1241 RooTreeDataStore.cxx:1242 RooTreeDataStore.cxx:1243 RooTreeDataStore.cxx:1244 RooTreeDataStore.cxx:1245 RooTreeDataStore.cxx:1246 RooTreeDataStore.cxx:1247 RooTreeDataStore.cxx:1248 RooTreeDataStore.cxx:1249 RooTreeDataStore.cxx:1250 RooTreeDataStore.cxx:1251 RooTreeDataStore.cxx:1252 RooTreeDataStore.cxx:1253 RooTreeDataStore.cxx:1254 RooTreeDataStore.cxx:1255 RooTreeDataStore.cxx:1256 RooTreeDataStore.cxx:1257 RooTreeDataStore.cxx:1258 RooTreeDataStore.cxx:1259 RooTreeDataStore.cxx:1260 RooTreeDataStore.cxx:1261 RooTreeDataStore.cxx:1262 RooTreeDataStore.cxx:1263 RooTreeDataStore.cxx:1264 RooTreeDataStore.cxx:1265 RooTreeDataStore.cxx:1266 RooTreeDataStore.cxx:1267 RooTreeDataStore.cxx:1268 RooTreeDataStore.cxx:1269 RooTreeDataStore.cxx:1270 RooTreeDataStore.cxx:1271 RooTreeDataStore.cxx:1272 RooTreeDataStore.cxx:1273 RooTreeDataStore.cxx:1274 RooTreeDataStore.cxx:1275 RooTreeDataStore.cxx:1276 RooTreeDataStore.cxx:1277 RooTreeDataStore.cxx:1278 RooTreeDataStore.cxx:1279 RooTreeDataStore.cxx:1280 RooTreeDataStore.cxx:1281 RooTreeDataStore.cxx:1282 RooTreeDataStore.cxx:1283 RooTreeDataStore.cxx:1284 RooTreeDataStore.cxx:1285 RooTreeDataStore.cxx:1286 RooTreeDataStore.cxx:1287 RooTreeDataStore.cxx:1288 RooTreeDataStore.cxx:1289 RooTreeDataStore.cxx:1290 RooTreeDataStore.cxx:1291 RooTreeDataStore.cxx:1292 RooTreeDataStore.cxx:1293 RooTreeDataStore.cxx:1294 RooTreeDataStore.cxx:1295 RooTreeDataStore.cxx:1296 RooTreeDataStore.cxx:1297 RooTreeDataStore.cxx:1298 RooTreeDataStore.cxx:1299 RooTreeDataStore.cxx:1300 RooTreeDataStore.cxx:1301 RooTreeDataStore.cxx:1302 RooTreeDataStore.cxx:1303 RooTreeDataStore.cxx:1304 RooTreeDataStore.cxx:1305 RooTreeDataStore.cxx:1306 RooTreeDataStore.cxx:1307 RooTreeDataStore.cxx:1308 RooTreeDataStore.cxx:1309 RooTreeDataStore.cxx:1310 RooTreeDataStore.cxx:1311 RooTreeDataStore.cxx:1312 RooTreeDataStore.cxx:1313 RooTreeDataStore.cxx:1314 RooTreeDataStore.cxx:1315 RooTreeDataStore.cxx:1316 RooTreeDataStore.cxx:1317 RooTreeDataStore.cxx:1318 RooTreeDataStore.cxx:1319 RooTreeDataStore.cxx:1320 RooTreeDataStore.cxx:1321 RooTreeDataStore.cxx:1322 RooTreeDataStore.cxx:1323 RooTreeDataStore.cxx:1324 RooTreeDataStore.cxx:1325 RooTreeDataStore.cxx:1326 RooTreeDataStore.cxx:1327 RooTreeDataStore.cxx:1328 RooTreeDataStore.cxx:1329 RooTreeDataStore.cxx:1330 RooTreeDataStore.cxx:1331 RooTreeDataStore.cxx:1332 RooTreeDataStore.cxx:1333 RooTreeDataStore.cxx:1334 RooTreeDataStore.cxx:1335 RooTreeDataStore.cxx:1336 RooTreeDataStore.cxx:1337 RooTreeDataStore.cxx:1338 RooTreeDataStore.cxx:1339 RooTreeDataStore.cxx:1340 RooTreeDataStore.cxx:1341 RooTreeDataStore.cxx:1342 RooTreeDataStore.cxx:1343 RooTreeDataStore.cxx:1344 RooTreeDataStore.cxx:1345 RooTreeDataStore.cxx:1346 RooTreeDataStore.cxx:1347 RooTreeDataStore.cxx:1348