82 _wgtVar(weightVar(vars,wgtVarName)),
94 arg->attachToVStore(*
this) ;
108 realVec->setNativeBuffer();
112 fullVec->setNativeBuffer();
116 catVec->setNativeBuffer();
162 _varsww(other._varsww),
163 _wgtVar(other._wgtVar),
164 _sumWeight(other._sumWeight),
165 _sumWeightCarry(other._sumWeightCarry),
166 _extWgtArray(other._extWgtArray),
167 _extWgtErrLoArray(other._extWgtErrLoArray),
168 _extWgtErrHiArray(other._extWgtErrHiArray),
169 _extSumW2Array(other._extSumW2Array),
170 _currentWeightIndex(other._currentWeightIndex),
196 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
198 _wgtVar(weightVar(vars,other._wgtVar?other._wgtVar->GetName():0)),
202 _extWgtErrLoArray(0),
203 _extWgtErrHiArray(0),
205 _currentWeightIndex(0),
210 for (
const auto arg :
_varsww) {
211 arg->attachToVStore(*
this) ;
232 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
234 _wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):0),
235 _sumWeight(other._sumWeight),
236 _sumWeightCarry(other._sumWeightCarry),
237 _extWgtArray(other._extWgtArray),
238 _extWgtErrLoArray(other._extWgtErrLoArray),
239 _extWgtErrHiArray(other._extWgtErrHiArray),
240 _extSumW2Array(other._extSumW2Array),
241 _currentWeightIndex(other._currentWeightIndex),
246 auto real =
static_cast<RooAbsReal*
>(vars.
find(realVec->bufArg()->GetName()));
255 vector<RealFullVector*>::const_iterator fiter = other.
_realfStoreList.begin() ;
266 vector<CatVector*>::const_iterator citer = other.
_catStoreList.begin() ;
291 std::size_t nStart, std::size_t nStop,
Bool_t ,
const char* wgtVarName) :
295 _wgtVar(weightVar(vars,wgtVarName)),
299 _extWgtErrLoArray(0),
300 _extWgtErrHiArray(0),
305 for (
const auto arg :
_varsww) {
306 arg->attachToVStore(*
this) ;
323 loadValues(&tds,cloneVar,cutRange,nStart,nStop);
388 if (index < 0 ||
static_cast<std::size_t
>(index) >=
size())
return 0;
395 fullRealP->
get(index);
404 for (
auto var :
_vars) {
405 var->setValueDirty();
425 if (index < 0 ||
static_cast<std::size_t
>(index) >=
size())
return 0;
428 realV->loadToNative(index) ;
432 fullRealP->loadToNative(index);
436 catP->loadToNative(index);
441 for (
auto var :
_vars) {
442 var->setValueDirty() ;
504 throw string(
Form(
"RooDataHist::weightError(%s) error type Auto not allowed here",
GetName())) ;
508 throw string(
Form(
"RooDataHist::weightError(%s) error type Expected not allowed here",
GetName())) ;
570 std::unique_ptr<RooFormulaVar> selectClone;
573 selectClone->recursiveRedirectServers(*ads->
get()) ;
581 const auto numEntr =
static_cast<std::size_t
>(ads->
numEntries());
582 const std::size_t nevent = nStop < numEntr ? nStop : numEntr;
602 std::vector<std::string> ranges;
608 for(
auto i=nStart; i < nevent ; ++i) {
612 if (selectClone && selectClone->getVal()==0) {
631 bool allValid =
true;
632 for (
const auto arg :
_varsww) {
633 allValid &= arg->isValid();
634 if (allValid && !ranges.empty()) {
637 allValid &= std::any_of(ranges.begin(), ranges.end(), [arg](
const std::string& range){
638 return arg->inRange(range.c_str());});
694 coutE(InputArguments) <<
GetName() <<
"::addColumn: holder argument is not fundamental: \""
695 << valHolder->
GetName() <<
"\"" << endl;
700 const std::size_t numEvt =
size();
723 for (std::size_t i=0; i < numEvt; i++) {
729 if (rv) rv->
write(i) ;
730 if (cv) cv->
write(i) ;
753 const std::size_t numEvt =
size();
755 for (
const auto var : varList) {
758 holderSet->
add(*valHolder) ;
762 coutE(InputArguments) <<
GetName() <<
"::addColumn: holder argument is not fundamental: \""
763 << valHolder->
GetName() <<
"\"" << endl;
769 if (!newVarCloneList) {
770 coutE(InputArguments) <<
"RooTreeDataStore::RooTreeData(" <<
GetName()
771 <<
") Couldn't deep-clone variable " << var->
GetName() <<
", abort." << endl ;
774 RooAbsArg* newVarClone = newVarCloneList->
find(var->GetName()) ;
778 cloneSetList.
Add(newVarCloneList) ;
779 cloneSet.
add(*newVarClone) ;
787 for (
const auto holder : *holderSet) {
796 for (std::size_t i=0; i < numEvt; i++) {
799 for (
unsigned int j=0; j < holderSet->
size(); ++j) {
800 const auto holder = (*holderSet)[j];
801 const auto cloneArg = cloneSet[j];
803 cloneArg->syncCache(&
_vars) ;
805 holder->copyCache(cloneArg) ;
832 const auto nevt = dstoreList.front()->numEntries();
834 for (
int i=0 ; i<nevt ; i++) {
840 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
845 mergedStore->
fill() ;
873 for (
int i=0 ; i<nevt ; i++) {
924 vector<RooAbsArg*> trackArgs;
925 for (
const auto arg : newVarSetCopy) {
926 if (arg->getAttribute(
"ConstantExpression") && !arg->getAttribute(
"NOCacheAndTrack")) {
927 orderedArgs.
add(*arg) ;
934 if (arg->dependsOn(
_vars) && !arg->getAttribute(
"NOCacheAndTrack")) {
935 trackArgs.push_back(arg) ;
945 if (left == right) return false;
946 return right->dependsOn(*left);
950 for (
const auto trackedArg : trackArgs) {
951 orderedArgs.
add(*trackedArg);
961 std::vector<RooArgSet*> vlist;
964 for (
const auto var : orderedArgs) {
968 RooAbsArg* newVarClone = newVarCloneList->
find(var->GetName()) ;
971 vlist.push_back(newVarCloneList) ;
972 cloneSet.
add(*newVarClone) ;
981 std::vector<RooArgSet*> nsetList ;
982 std::vector<RooArgSet*> argObsList ;
985 for (
const auto arg : cloneSet) {
986 arg->attachToVStore(*newCache) ;
988 RooArgSet* argObs = nset ? arg->getObservables(*nset) : arg->getVariables() ;
989 argObsList.push_back(argObs) ;
992 const char* catNset = arg->getStringAttribute(
"CATNormSet") ;
1000 const char* catCset = arg->getStringAttribute(
"CATCondSet") ;
1013 nsetList.push_back(normSet) ;
1018 const std::size_t numEvt =
size();
1020 for (std::size_t i=0; i < numEvt; i++) {
1022 if (
weight()!=0 || !skipZeroWeights) {
1023 for (
unsigned int j = 0; j < cloneSet.
size(); ++j) {
1024 auto& cloneArg = cloneSet[j];
1025 auto argNSet = nsetList[j];
1027 cloneArg.syncCache(argNSet ? argNSet : nset) ;
1037 for (
const auto arg : orderedArgs) {
1038 arg->attachToVStore(*newCache) ;
1041 if (!arg->getAttribute(
"ConstantExpression") &&
dynamic_cast<RooAbsReal*
>(arg)) {
1050 coutI(Optimization) <<
"RooVectorDataStore::cacheArg() element " << arg->GetName() <<
" has change tracking enabled on parameters " << *deps << endl ;
1058 for (
auto set : vlist) {
1061 for (
auto set : argObsList) {
1083 std::vector<RooVectorDataStore::RealVector *> tv;
1089 tv.push_back(realVec);
1105 if (projectedArgs && projectedArgs->
getSize()>0) {
1108 usedNset = ownedNset ;
1114 for (
int i=firstEvent ; i<lastEvent ; i+=stepSize) {
1117 if (!zeroWeight || !skipZeroWeights) {
1118 for (
auto realVector : tv) {
1119 realVector->_nativeReal->_valueDirty =
kTRUE;
1120 realVector->_nativeReal->getValV(realVector->_nset ? realVector->_nset : usedNset);
1121 realVector->write(i);
1126 for (
auto realVector : tv) {
1148 for (
const auto elm : cacheElements) {
1149 auto real =
static_cast<RooAbsReal*
>(cachedVarsIn.
find(elm->bufArg()->GetName()));
1157 auto cat =
static_cast<RooAbsCategory*
>(cachedVarsIn.
find(catVec->bufArg()->GetName()));
1215 arg->attachToVStore(*
this);
1225 cout <<
"RooVectorDataStor::dump()" << endl ;
1228 cout <<
"realVector list is" << endl ;
1231 cout <<
"RealVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName() <<
" bufptr = " << elm->_buf << endl ;
1232 cout <<
" values : " ;
1233 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1234 for (
Int_t i=0 ; i<imax ; i++) {
1235 cout << elm->_vec[i] <<
" " ;
1241 cout <<
"RealFullVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName()
1242 <<
" bufptr = " << elm->_buf <<
" errbufptr = " << elm->_bufE << endl ;
1244 cout <<
" values : " ;
1245 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1246 for (
Int_t i=0 ; i<imax ; i++) {
1247 cout << elm->_vec[i] <<
" " ;
1251 cout <<
" errors : " ;
1252 for (
Int_t i=0 ; i<imax ; i++) {
1253 cout << (*elm->_vecE)[i] <<
" " ;
1265void RooVectorDataStore::Streamer(
TBuffer &R__b)
1292void RooVectorDataStore::RealFullVector::Streamer(
TBuffer &R__b)
1295 R__b.
ReadClassBuffer(RooVectorDataStore::RealFullVector::Class(),
this);
1317 auto emplace = [
this,&evalData,
first,len](
const RealVector* realVec) {
1318 auto span = realVec->getRange(
first,
first + len);
1319 auto result = evalData.emplace(realVec->_nativeReal, span);
1320 if (result.second ==
false || result.first->second.size() != len) {
1321 const auto size = result.second ? result.first->second.size() : 0;
1322 coutE(DataHandling) <<
"A batch of data for '" << realVec->_nativeReal->GetName()
1323 <<
"' was requested from " <<
first <<
" to " <<
first+len
1324 <<
", but only the events [" <<
first <<
", " <<
first +
size <<
") are available." << std::endl;
1326 if (realVec->_real) {
1329 evalData.emplace(realVec->_real, std::move(span));
1356 auto emplace = [
this,&evalData,
first,len](
const CatVector* catVec) {
1357 auto span = catVec->getRange(
first,
first + len);
1358 auto result = evalData.emplace(catVec->_cat, span);
1359 if (result.second ==
false || result.first->second.size() != len) {
1360 const auto size = result.second ? result.first->second.size() : 0;
1361 coutE(DataHandling) <<
"A batch of data for '" << catVec->_cat->GetName()
1362 <<
"' was requested from " <<
first <<
" to " <<
first+len
1363 <<
", but only the events [" <<
first <<
", " <<
first +
size <<
") are available." << std::endl;
1387 auto findWeightVar = [
this](
const RealVector* realVec) {
1393 return (*storageIter)->getRange(
first,
first + len);
1397 return (*fstorageIter)->getRange(
first,
first + len);
1399 throw std::logic_error(
"RooVectorDataStore::getWeightBatch(): Could not retrieve data for _wgtVar.");
1409 if (std::string(catVec->bufArg()->GetName())==cat->
GetName()) {
1425 if (realVec->bufArg()->namePtr()==real->
namePtr()) {
1432 if (fullVec->bufArg()->namePtr()==real->
namePtr()) {
1449 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1461 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1473 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1485 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1492 if (std::string(realVec->bufArg()->GetName())==real->
GetName()) {
1516 double const* arr =
nullptr;
1523 if(wgtName == real->_nativeReal->GetName())
1524 arr = real->_vec.data();
1527 if(wgtName == real->_nativeReal->GetName())
1528 arr = real->_vec.data();
1531 if(arr ==
nullptr) {
1548 out.
reals.emplace_back(real->_nativeReal->GetName(), real->_vec.data());
1551 std::string
name = realf->_nativeReal->GetName();
1552 out.
reals.emplace_back(
name, realf->_vec.data());
1553 if(realf->_vecE) out.
reals.emplace_back(
name +
"Err", realf->_vecE->data());
1554 if(realf->_vecEL) out.
reals.emplace_back(
name +
"ErrLo", realf->_vecEL->data());
1555 if(realf->_vecEH) out.
reals.emplace_back(
name +
"ErrHi", realf->_vecEH->data());
1558 out.
cats.emplace_back(cat->_cat->GetName(), cat->_vec.data());
char * Form(const char *fmt,...)
static KahanSum< T, N > Accumulate(Iterator begin, Iterator end, T initialValue=T{})
Iterate over a range and return an instance of a KahanSum.
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
virtual RooAbsArg * cloneTree(const char *newname=0) const
Clone tree expression of objects.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
void attachDataStore(const RooAbsDataStore &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE)=0
static void setDirtyInhibit(Bool_t flag)
Control global dirty inhibit mode.
virtual Bool_t isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
virtual void syncCache(const RooArgSet *nset=0)=0
virtual void attachToVStore(RooVectorDataStore &vstore)=0
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
virtual RooAbsArg * createFundamental(const char *newname=0) const =0
Create a fundamental-type object that stores our type of value.
Bool_t recursiveRedirectServers(const RooAbsCollection &newServerList, Bool_t mustReplaceAll=kFALSE, Bool_t nameChange=kFALSE, Bool_t recurseInNewSet=kTRUE)
Recursively replace all servers with the new servers in newSet.
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
virtual void attachToVStore(RooVectorDataStore &vstore)
Attach the category index and label to as branches to the given vector store.
Storage_t const & get() const
Const access to the underlying stl container.
RooAbsCollection & assignValueOnly(const RooAbsCollection &other, bool forceIfSizeOne=false)
Sets the value of any argument in our set that also appears in the other set.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
Storage_t::size_type size() const
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
const char * GetName() const
Returns name of object.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
virtual const RooArgSet * get(Int_t index) const =0
virtual void checkInit() const
virtual Double_t weight() const =0
virtual Int_t numEntries() const =0
std::map< RooFit::Detail::DataKey, RooSpan< const double > > RealSpans
std::map< RooFit::Detail::DataKey, RooSpan< const RooAbsCategory::value_type > > CategorySpans
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
virtual void attachToVStore(RooVectorDataStore &vstore)
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Bool_t getPoissonInterval(Int_t n, Double_t &mu1, Double_t &mu2, Double_t nSigma=1) const
Return a confidence interval for the expected number of events given n observed (unweighted) events.
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
RooRealVar represents a variable that can be changed from the outside.
Double_t getAsymErrorLo() const
Bool_t hasAsymError(Bool_t allowZero=kTRUE) const
Double_t getAsymErrorHi() const
Bool_t hasError(Bool_t allowZero=kTRUE) const
Double_t getError() const
virtual void setVal(Double_t value)
Set value of variable to 'value'.
A simple container to hold a batch of data values.
RooTreeDataStore is a TTree-backed data storage.
virtual const RooArgSet * get(Int_t index) const
Load the n-th data point (n='index') in memory and return a pointer to the internal RooArgSet holding...
RooArgSet _varsww
Was object constructed with default ctor?
virtual Int_t numEntries() const
void write(std::size_t i)
std::vector< double > * _vecE
std::vector< double > * _vecEL
std::vector< double > * _vecEH
void setNset(RooArgSet *newNset)
void setDependents(const RooArgSet &deps)
RooVectorDataStore uses std::vectors to store data columns.
const Double_t * _extWgtErrHiArray
External weight array - low error.
Bool_t hasAsymError(RooAbsReal *real)
virtual void resetCache() override
virtual Int_t numEntries() const override
virtual void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars) override
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
std::vector< RealFullVector * > _realfStoreList
Bool_t isFullReal(RooAbsReal *real)
RooVectorDataStore * _cache
virtual void resetBuffers() override
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return pointer to weight variable if it is defined.
std::vector< RealVector * > _realStoreList
CatVector * addCategory(RooAbsCategory *cat)
virtual RooArgSet * addColumns(const RooArgList &varList) override
Utility function to add multiple columns in one call See addColumn() for details.
void loadValues(const RooAbsDataStore *tds, const RooFormulaVar *select=0, const char *rangeName=0, std::size_t nStart=0, std::size_t nStop=std::numeric_limits< std::size_t >::max()) override
virtual const RooArgSet * get(Int_t index) const override
Load the n-th data point (n='index') into the variables of this dataset, and return a pointer to the ...
virtual Bool_t changeObservableName(const char *from, const char *to) override
RealFullVector * addRealFull(RooAbsReal *real)
const Double_t * _extWgtErrLoArray
External weight array.
RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const override
Return batches of the data columns for the requested events.
ULong64_t _currentWeightIndex
External sum of weights array.
virtual const RooArgSet * getNative(Int_t index) const
Load the n-th data point (n='index') into the variables of this dataset, and return a pointer to the ...
Double_t weight() const override
Return the weight of the last-retrieved data point.
virtual Int_t fill() override
Interface function to TTree::Fill.
virtual void append(RooAbsDataStore &other) override
std::vector< CatVector * > _catStoreList
Bool_t _forcedUpdate
Cache owner.
void setAllBuffersNative()
const Double_t * _extSumW2Array
External weight array - high error.
virtual void reset() override
virtual void attachBuffers(const RooArgSet &extObs) override
ArraysStruct getArrays() const
Exports all arrays in this RooVectorDataStore into a simple datastructure to be used by RooFit intern...
virtual void setDirtyProp(Bool_t flag) override
RooAbsData::CategorySpans getCategoryBatches(std::size_t, std::size_t len) const override
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList) override
Merge columns of supplied data set(s) with this data set.
virtual void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=0, Bool_t skipZeroWeights=kTRUE) override
Cache given RooAbsArgs: The tree is given direct write access of the args internal cache the args val...
RealVector * addReal(RooAbsReal *real)
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override
Return the error of the current weight.
void forceCacheUpdate() override
void recomputeSumWeight()
Trigger a recomputation of the cached weight sums.
std::vector< RealVector * > & realStoreList()
virtual void recalculateCache(const RooArgSet *, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, Bool_t skipZeroWeights) override
std::size_t size() const
Get size of stored dataset.
Bool_t hasError(RooAbsReal *real)
RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len) const override
Return the weights of all events in the range [first, first+len).
virtual const RooArgSet * get() const
virtual ~RooVectorDataStore()
Destructor.
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
const Double_t * _extWgtArray
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE) override
Add a new column to the data set which holds the pre-calculated values of 'newVar'.
virtual void setArgStatus(const RooArgSet &set, Bool_t active) override
Disabling of branches is (intentionally) not implemented in vector data stores (as the doesn't result...
RooAbsArg * _cacheOwner
Optimization cache.
Buffer base class used for serializing objects.
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void Add(TObject *obj)
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
RooArgSet selectFromArgSet(RooArgSet const &, std::string const &names)
Construct a RooArgSet of objects in a RooArgSet whose names match to those in the names string.
Output struct for the RooVectorDataStore::getArrays() helper function.
std::vector< ArrayInfo< double > > reals
std::vector< ArrayInfo< RooAbsCategory::value_type > > cats