50using std::string, std::vector, std::list;
71 arg->attachToVStore(*
this) ;
85 realVec->setNativeBuffer();
89 fullVec->setNativeBuffer();
93 catVec->setNativeBuffer();
110 ret.
remove(*wgt,
true,
true) ;
150 _realStoreList.push_back(new RealVector(*realVec, static_cast<RooAbsReal*>(_varsww.find(realVec->_nativeReal->GetName())))) ;
154 _realfStoreList.push_back(new RealFullVector(*realFullVec, static_cast<RooAbsReal*>(_varsww.find(realFullVec->_nativeReal->GetName())))) ;
158 _catStoreList.push_back(new CatVector(*catVec, static_cast<RooAbsCategory*>(_varsww.find(catVec->_cat->GetName())))) ;
174 for (
const auto arg :
_varsww) {
175 arg->attachToVStore(*
this) ;
208 auto real = static_cast<RooAbsReal*>(vars.find(realVec->bufArg()->GetName()));
211 _realStoreList.push_back(new RealVector(*realVec, real)) ;
213 real->attachToVStore(*this) ;
217 auto forwardIter = other._realfStoreList.begin() ;
218 for (; forwardIter!=other._realfStoreList.end() ; ++forwardIter) {
222 _realfStoreList.push_back(
new RealFullVector(**forwardIter,real)) ;
229 for (; citer!=other._catStoreList.end() ; ++citer) {
233 _catStoreList.push_back(
new CatVector(**citer,cat)) ;
239 setAllBuffersNative() ;
248 std::size_t nStart, std::size_t nStop) {
254 return std::make_unique<RooVectorDataStore>(
name, title, *
this, tmp, cutVar, cutRange, nStart, nStop, wgtVarName);
263 std::size_t nStart, std::size_t nStop,
const char* wgtVarName) :
269 for (
const auto arg :
_varsww) {
270 arg->attachToVStore(*
this) ;
276 std::unique_ptr<RooFormulaVar> cloneVar;
279 cloneVar->attachDataStore(tds) ;
287 loadValues(&tds,cloneVar.get(),cutRange,nStart,nStop);
351 if (
index < 0 ||
static_cast<std::size_t
>(
index) >=
size())
return nullptr;
358 fullRealP->load(
index);
367 for (
auto var :
_vars) {
368 var->setValueDirty();
403 return (
_wgtVar->getAsymErrorHi() -
_wgtVar->getAsymErrorLo() ) / 2 ;
404 }
else if (
_wgtVar->hasError(
false)) {
431 throw string(
Form(
"RooDataHist::weightError(%s) error type Auto not allowed here",
GetName())) ;
435 throw string(
Form(
"RooDataHist::weightError(%s) error type Expected not allowed here",
GetName())) ;
471 lo =
_wgtVar->getAsymErrorLo() ;
498 std::unique_ptr<RooFormulaVar> selectClone;
500 selectClone.reset(
static_cast<RooFormulaVar*
>(select->cloneTree()) );
501 selectClone->recursiveRedirectServers(*ads->
get()) ;
509 const auto numEntr =
static_cast<std::size_t
>(ads->
numEntries());
510 const std::size_t nevent = nStop < numEntr ? nStop : numEntr;
516 bool weightRename(
false) ;
517 const bool newWeightVar =
_wgtVar ?
_wgtVar->getAttribute(
"NewWeight") : false ;
519 if (
_wgtVar && vectorDS && vectorDS->_wgtVar) {
520 if (std::string(
_wgtVar->GetName()) != vectorDS->_wgtVar->GetName() && !newWeightVar) {
524 if (
_wgtVar && treeDS && treeDS->_wgtVar) {
525 if (std::string(
_wgtVar->GetName()) != treeDS->_wgtVar->GetName() && !newWeightVar) {
530 std::vector<std::string> ranges;
536 for(
auto i=nStart; i < nevent ; ++i) {
540 if (selectClone && selectClone->getVal()==0) {
547 otherVarsww = &treeDS->_varsww;
549 _wgtVar->setVal(treeDS->_wgtVar->getVal()) ;
551 }
else if (vectorDS) {
552 otherVarsww = &vectorDS->_varsww;
554 _wgtVar->setVal(vectorDS->_wgtVar->getVal()) ;
557 otherVarsww = ads->
get();
561 bool allValid =
true;
562 for (
const auto arg : *otherVarsww) {
563 allValid &= arg->isValid();
564 if (allValid && !ranges.empty()) {
567 allValid &= std::any_of(ranges.begin(), ranges.end(), [arg](
const std::string& range){
568 return arg->inRange(range.c_str());});
623 auto valHolder = std::unique_ptr<RooAbsArg>{newVar.
createFundamental()}.release();
625 if(!valHolder->isFundamental()) {
626 coutE(InputArguments) <<
GetName() <<
"::addColumn: holder argument is not fundamental: \""
627 << valHolder->GetName() <<
"\"" << std::endl;
632 const std::size_t numEvt =
size();
635 std::unique_ptr<RooAbsArg> newVarClone{newVar.
cloneTree()};
636 newVarClone->recursiveRedirectServers(
_vars,
false) ;
639 valHolder->attachToVStore(*
this) ;
640 _vars.add(*valHolder) ;
655 for (std::size_t i=0; i < numEvt; i++) {
658 newVarClone->syncCache(&
_vars) ;
659 valHolder->copyCache(newVarClone.get()) ;
661 if (rv) rv->
write(i) ;
662 if (cv) cv->
write(i) ;
680 const auto nevt = dstoreList.front()->numEntries();
682 for (
int i=0 ; i<nevt ; i++) {
688 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
693 mergedStore->
fill() ;
721 for (
int i=0 ; i<nevt ; i++) {
772 vector<RooAbsArg*> trackArgs;
773 for (
const auto arg : newVarSetCopy) {
774 if (arg->getAttribute(
"ConstantExpression") && !arg->getAttribute(
"NOCacheAndTrack")) {
775 orderedArgs.
add(*arg) ;
782 if (arg->dependsOn(
_vars) && !arg->getAttribute(
"NOCacheAndTrack")) {
783 trackArgs.push_back(arg) ;
793 if (left == right) return false;
794 return right->dependsOn(*left);
798 for (
const auto trackedArg : trackArgs) {
799 orderedArgs.
add(*trackedArg);
809 std::vector<std::unique_ptr<RooArgSet>> vlist;
812 for (
const auto var : orderedArgs) {
815 auto newVarCloneList = std::make_unique<RooArgSet>();
817 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
820 vlist.emplace_back(std::move(newVarCloneList));
821 cloneSet.
add(*newVarClone) ;
830 std::vector<RooArgSet*> nsetList ;
831 std::vector<std::unique_ptr<RooArgSet>> argObsList ;
832 std::vector<std::unique_ptr<RooArgSet>> ownedNsets;
835 for (
const auto arg : cloneSet) {
836 arg->attachToVStore(*newCache) ;
838 if(nset) argObsList.emplace_back(arg->getObservables(*nset));
839 else argObsList.emplace_back(arg->getVariables());
840 RooArgSet* argObs = argObsList.back().get();
843 const char* catNset = arg->getStringAttribute(
"CATNormSet") ;
849 normSet = ownedNsets.back().get();
851 const char* catCset = arg->getStringAttribute(
"CATCondSet") ;
856 argObs->
remove(acset,
true,
true) ;
864 nsetList.push_back(normSet) ;
869 const std::size_t numEvt =
size();
871 for (std::size_t i=0; i < numEvt; i++) {
873 if (
weight()!=0 || !skipZeroWeights) {
874 for (
unsigned int j = 0; j < cloneSet.
size(); ++j) {
875 auto& cloneArg = cloneSet[j];
876 auto argNSet = nsetList[j];
878 cloneArg.syncCache(argNSet ? argNSet : nset) ;
888 for (
const auto arg : orderedArgs) {
889 arg->attachToVStore(*newCache) ;
892 if (!arg->getAttribute(
"ConstantExpression") &&
dynamic_cast<RooAbsReal*
>(arg)) {
895 arg->getParameters(&
_vars, deps);
902 coutI(Optimization) <<
"RooVectorDataStore::cacheArg() element " << arg->GetName() <<
" has change tracking enabled on parameters " << deps << std::endl ;
926 std::vector<RooVectorDataStore::RealVector *> tv;
927 tv.reserve(
static_cast<std::size_t
>(
_cache->_realStoreList.size() * 0.7));
930 for (
const auto realVec :
_cache->_realStoreList) {
932 tv.push_back(realVec);
946 std::unique_ptr<RooArgSet> ownedNset;
948 if (projectedArgs && !projectedArgs->
empty()) {
949 ownedNset = std::make_unique<RooArgSet>();
950 _vars.snapshot(*ownedNset,
false) ;
951 ownedNset->remove(*projectedArgs,
false,
true);
952 usedNset = ownedNset.get();
958 for (
int i=firstEvent ; i<lastEvent ; i+=stepSize) {
960 bool zeroWeight = (
weight()==0) ;
961 if (!zeroWeight || !skipZeroWeights) {
962 for (
auto realVector : tv) {
963 realVector->_nativeReal->_valueDirty =
true;
964 realVector->_nativeReal->getValV(realVector->_nset ? realVector->_nset : usedNset);
965 realVector->write(i);
970 for (
auto realVector : tv) {
986 std::vector<RealVector*> cacheElements(
_cache->realStoreList());
987 cacheElements.insert(cacheElements.end(),
_cache->_realfStoreList.begin(),
_cache->_realfStoreList.end());
989 for (
const auto elm : cacheElements) {
990 auto real =
static_cast<RooAbsReal*
>(cachedVarsIn.
find(elm->bufArg()->GetName()));
997 for (
const auto catVec :
_cache->_catStoreList) {
998 auto cat =
static_cast<RooAbsCategory*
>(cachedVarsIn.
find(catVec->bufArg()->GetName()));
1056 arg->attachToVStore(*
this);
1066 std::cout <<
"RooVectorDataStor::dump()" << std::endl ;
1068 std::cout <<
"_varsww = " << std::endl ;
_varsww.Print(
"v") ;
1069 std::cout <<
"realVector list is" << std::endl ;
1072 std::cout <<
"RealVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName() <<
" bufptr = " << elm->_buf << std::endl ;
1073 std::cout <<
" values : " ;
1074 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1075 for (
Int_t i=0 ; i<imax ; i++) {
1076 std::cout << elm->_vec[i] <<
" " ;
1078 std::cout << std::endl ;
1082 std::cout <<
"RealFullVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName()
1083 <<
" bufptr = " << elm->_buf <<
" errbufptr = " << elm->bufE() << std::endl ;
1085 std::cout <<
" values : " ;
1086 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1087 for (
Int_t i=0 ; i<imax ; i++) {
1088 std::cout << elm->_vec[i] <<
" " ;
1090 std::cout << std::endl ;
1092 std::cout <<
" errors : " ;
1093 for (
Int_t i=0 ; i<imax ; i++) {
1094 std::cout << elm->dataE()[i] <<
" " ;
1096 std::cout << std::endl ;
1138 auto emplace = [
this,&evalData,first,
len](
const RealVector* realVec) {
1139 auto span = realVec->getRange(first, first +
len);
1140 auto result = evalData.emplace(realVec->_nativeReal, span);
1143 coutE(DataHandling) <<
"A batch of data for '" << realVec->_nativeReal->GetName()
1144 <<
"' was requested from " << first <<
" to " << first+
len
1145 <<
", but only the events [" << first <<
", " << first +
size <<
") are available." << std::endl;
1147 if (realVec->_real) {
1150 evalData.emplace(realVec->_real, span);
1162 for (
const auto realVec :
_cache->_realStoreList) {
1165 for (
const auto realVec :
_cache->_realfStoreList) {
1177 auto emplace = [
this,&evalData,first,
len](
const CatVector* catVec) {
1178 auto span = catVec->getRange(first, first +
len);
1179 auto result = evalData.emplace(catVec->_cat, span);
1182 coutE(DataHandling) <<
"A batch of data for '" << catVec->_cat->GetName()
1183 <<
"' was requested from " << first <<
" to " << first+
len
1184 <<
", but only the events [" << first <<
", " << first +
size <<
") are available." << std::endl;
1208 auto findWeightVar = [
this](
const RealVector* realVec) {
1209 return realVec->_nativeReal ==
_wgtVar || realVec->_nativeReal->GetName() ==
_wgtVar->GetName();
1214 return (*storageIter)->getRange(first, first +
len);
1218 return (*fstorageIter)->getRange(first, first +
len);
1220 throw std::logic_error(
"RooVectorDataStore::getWeightBatch(): Could not retrieve data for _wgtVar.");
1230 if (std::string(catVec->bufArg()->GetName())==cat->
GetName()) {
1246 if (realVec->bufArg()->namePtr()==real->
namePtr()) {
1253 if (fullVec->bufArg()->namePtr()==real->
namePtr()) {
1270 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1282 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1283 return fullVec->bufE();
1294 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1295 return fullVec->bufEL();
1306 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1313 if (std::string(realVec->bufArg()->GetName())==real->
GetName()) {
1337 double const* arr =
nullptr;
1342 const std::string wgtName =
_wgtVar->GetName();
1344 if(wgtName == real->_nativeReal->
GetName())
1345 arr = real->_vec.data();
1348 if(wgtName == real->_nativeReal->
GetName())
1349 arr = real->_vec.data();
1352 if(arr ==
nullptr) {
1369 out.
reals.emplace_back(real->_nativeReal->
GetName(), real->_vec.data());
1372 std::string
name = realf->_nativeReal->GetName();
1373 out.
reals.emplace_back(
name, realf->_vec.data());
1374 if(realf->bufE()) out.
reals.emplace_back(
name +
"Err", realf->dataE().data());
1375 if(realf->bufEL()) out.
reals.emplace_back(
name +
"ErrLo", realf->dataEL().data());
1376 if(realf->bufEH()) out.
reals.emplace_back(
name +
"ErrHi", realf->dataEH().data());
1379 out.
cats.emplace_back(cat->_cat->
GetName(), cat->_vec.data());
true
Register systematic variations for multiple existing columns using auto-generated tags.
int Int_t
Signed integer 4 bytes (int)
return
Invalidate stored TCling state for declarations included in transaction âTâ.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
static KahanSum< T, N > Accumulate(Iterator begin, Iterator end, T initialValue=T{})
Iterate over a range and return an instance of a KahanSum.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
bool recursiveRedirectServers(const RooAbsCollection &newSet, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
virtual RooFit::OwningPtr< RooAbsArg > createFundamental(const char *newname=nullptr) const =0
Create a fundamental-type object that stores our type of value.
static void setDirtyInhibit(bool flag)
Control global dirty inhibit mode.
virtual RooAbsArg * cloneTree(const char *newname=nullptr) const
Clone tree expression of objects.
virtual void attachToVStore(RooVectorDataStore &vstore)=0
A space to attach TBranches.
void attachToVStore(RooVectorDataStore &vstore) override
Attach the category index and label to as branches to the given vector store.
bool contains(const char *name) const
Check if collection contains an argument with a specific name.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
Storage_t const & get() const
Const access to the underlying stl container.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
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
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual const RooArgSet * get(Int_t index) const =0
virtual void checkInit() const
bool _doDirtyProp
Switch do (de)activate dirty state propagation when loading a data point.
virtual double weight() const =0
virtual Int_t numEntries() const =0
std::map< RooFit::Detail::DataKey, std::span< const double > > RealSpans
std::map< RooFit::Detail::DataKey, std::span< const RooAbsCategory::value_type > > CategorySpans
Abstract base class for objects that represent a real value and implements functionality common to al...
void attachToVStore(RooVectorDataStore &vstore) override
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.
RooArgSet * selectCommon(const RooAbsCollection &refColl) const
Use RooAbsCollection::selecCommon(), but return as RooArgSet.
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
bool getPoissonInterval(Int_t n, double &mu1, double &mu2, double nSigma=1) const
Calculate a confidence interval for the expected number of events given n observed (unweighted) event...
The RooStringView is a wrapper around a C-style string that can also be constructed from a std::strin...
TTree-backed data storage.
const RooArgSet * get(Int_t index) const override
Load the n-th data point (n='index') in memory and return a pointer to the internal RooArgSet holding...
Int_t numEntries() const override
void write(std::size_t i)
void resize(Int_t newSize)
void setNset(RooArgSet *newNset)
void setDependents(const RooArgSet &deps)
void resize(Int_t newSize)
void resetCache() override
void recalculateCache(const RooArgSet *, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, bool skipZeroWeights) override
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
Int_t numEntries() const override
RooAbsArg * addColumn(RooAbsArg &var, bool adjustRange=true) override
Add a new column to the data set which holds the pre-calculated values of 'newVar'.
RooVectorDataStore * _cache
! Optimization cache
const double * _extWgtErrHiArray
! External weight array - high error
std::span< 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).
~RooVectorDataStore() override
Destructor.
void resetBuffers() override
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return pointer to weight variable if it is defined.
void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=nullptr, bool skipZeroWeights=true) override
Cache given RooAbsArgs: The tree is given direct write access of the args internal cache the args val...
RooRealVar * _wgtVar
Pointer to weight variable (if set)
std::vector< RealVector * > _realStoreList
CatVector * addCategory(RooAbsCategory *cat)
void loadValues(const RooAbsDataStore *tds, const RooFormulaVar *select=nullptr, const char *rangeName=nullptr, std::size_t nStart=0, std::size_t nStop=std::numeric_limits< std::size_t >::max()) override
RealFullVector * addRealFull(RooAbsReal *real)
double weight() const override
Return the weight of the last-retrieved data point.
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
bool isFullReal(RooAbsReal *real)
Int_t fill() override
Interface function to TTree::Fill.
const double * _extWgtErrLoArray
! External weight array - low error
bool _forcedUpdate
! Request for forced cache update
void append(RooAbsDataStore &other) override
bool hasError(RooAbsReal *real)
std::vector< CatVector * > _catStoreList
void setArgStatus(const RooArgSet &set, bool active) override
Disabling of branches is (intentionally) not implemented in vector data stores (as the doesn't result...
void setAllBuffersNative()
double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override
Return the error of the current weight.
void attachBuffers(const RooArgSet &extObs) override
friend class RooAbsCategory
ArraysStruct getArrays() const
Exports all arrays in this RooVectorDataStore into a simple datastructure to be used by RooFit intern...
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.
RealVector * addReal(RooAbsReal *real)
bool hasAsymError(RooAbsReal *real)
bool changeObservableName(const char *from, const char *to) override
void forceCacheUpdate() override
const double * _extSumW2Array
! External sum of weights array
void recomputeSumWeight()
Trigger a recomputation of the cached weight sums.
std::size_t size() const
Get size of stored dataset.
std::unique_ptr< RooAbsDataStore > reduce(RooStringView name, RooStringView title, const RooArgSet &vars, const RooFormulaVar *cutVar, const char *cutRange, std::size_t nStart, std::size_t nStop) override
virtual const RooArgSet * get() const
const double * _extWgtArray
! External weight array
void Streamer(TBuffer &) override
Stream an object of class RooVectorDataStore.
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
RooAbsArg * _cacheOwner
! Cache owner
Buffer base class used for serializing objects.
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title 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)
Output struct for the RooVectorDataStore::getArrays() helper function.
std::vector< ArrayInfo< double > > reals
std::vector< ArrayInfo< RooAbsCategory::value_type > > cats