71 _wgtVar(weightVar(vars,wgtVarName))
74 arg->attachToVStore(*
this) ;
88 realVec->setNativeBuffer();
92 fullVec->setNativeBuffer();
96 catVec->setNativeBuffer();
113 ret.
remove(*wgt,
true,
true) ;
142 _varsww(other._varsww),
143 _wgtVar(other._wgtVar),
145 _sumWeightCarry(other._sumWeightCarry),
146 _extWgtArray(other._extWgtArray),
147 _extWgtErrLoArray(other._extWgtErrLoArray),
148 _extWgtErrHiArray(other._extWgtErrHiArray),
149 _extSumW2Array(other._extSumW2Array),
150 _currentWeightIndex(other._currentWeightIndex)
173 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():nullptr),newname),
175 _wgtVar(weightVar(vars,other._wgtVar?other._wgtVar->GetName():nullptr))
177 for (
const auto arg :
_varsww) {
178 arg->attachToVStore(*
this) ;
199 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():nullptr),newname),
201 _wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):nullptr),
203 _sumWeightCarry(other._sumWeightCarry),
204 _extWgtArray(other._extWgtArray),
205 _extWgtErrLoArray(other._extWgtErrLoArray),
206 _extWgtErrHiArray(other._extWgtErrHiArray),
207 _extSumW2Array(other._extSumW2Array),
208 _currentWeightIndex(other._currentWeightIndex)
211 auto real =
static_cast<RooAbsReal*
>(vars.
find(realVec->bufArg()->GetName()));
231 vector<CatVector*>::const_iterator citer = other.
_catStoreList.begin() ;
251 std::size_t nStart, std::size_t nStop) {
257 return std::make_unique<RooVectorDataStore>(
name, title, *
this, tmp, cutVar, cutRange, nStart, nStop, wgtVarName);
266 std::size_t nStart, std::size_t nStop,
const char* wgtVarName) :
270 _wgtVar(weightVar(vars,wgtVarName))
272 for (
const auto arg :
_varsww) {
273 arg->attachToVStore(*
this) ;
279 std::unique_ptr<RooFormulaVar> cloneVar;
282 cloneVar->attachDataStore(tds) ;
354 if (
index < 0 ||
static_cast<std::size_t
>(
index) >=
size())
return nullptr;
361 fullRealP->load(
index);
370 for (
auto var :
_vars) {
371 var->setValueDirty();
397 double lo = 0,
hi = 0 ;
433 throw string(
Form(
"RooDataHist::weightError(%s) error type Auto not allowed here",
GetName())) ;
437 throw string(
Form(
"RooDataHist::weightError(%s) error type Expected not allowed here",
GetName())) ;
499 std::unique_ptr<RooFormulaVar> selectClone;
502 selectClone->recursiveRedirectServers(*ads->
get()) ;
510 const auto numEntr =
static_cast<std::size_t
>(ads->
numEntries());
511 const std::size_t nevent = nStop < numEntr ? nStop : numEntr;
517 bool weightRename(
false) ;
520 if (
_wgtVar && vectorDS && vectorDS->_wgtVar) {
521 if (std::string(
_wgtVar->
GetName()) != vectorDS->_wgtVar->GetName() && !newWeightVar) {
525 if (
_wgtVar && treeDS && treeDS->_wgtVar) {
526 if (std::string(
_wgtVar->
GetName()) != treeDS->_wgtVar->GetName() && !newWeightVar) {
531 std::vector<std::string> ranges;
537 for(
auto i=nStart; i < nevent ; ++i) {
541 if (selectClone && selectClone->getVal()==0) {
548 otherVarsww = &treeDS->_varsww;
552 }
else if (vectorDS) {
553 otherVarsww = &vectorDS->_varsww;
558 otherVarsww = ads->
get();
562 bool allValid =
true;
563 for (
const auto arg : *otherVarsww) {
564 allValid &= arg->isValid();
565 if (allValid && !ranges.empty()) {
568 allValid &= std::any_of(ranges.begin(), ranges.end(), [arg](
const std::string& range){
569 return arg->inRange(range.c_str());});
624 auto valHolder = std::unique_ptr<RooAbsArg>{newVar.
createFundamental()}.release();
626 if(!valHolder->isFundamental()) {
627 coutE(InputArguments) <<
GetName() <<
"::addColumn: holder argument is not fundamental: \""
628 << valHolder->GetName() <<
"\"" << endl;
633 const std::size_t numEvt =
size();
636 std::unique_ptr<RooAbsArg> newVarClone{newVar.
cloneTree()};
640 valHolder->attachToVStore(*
this) ;
656 for (std::size_t i=0; i < numEvt; i++) {
659 newVarClone->syncCache(&
_vars) ;
660 valHolder->
copyCache(newVarClone.get()) ;
662 if (rv) rv->
write(i) ;
663 if (cv) cv->
write(i) ;
681 const auto nevt = dstoreList.front()->numEntries();
683 for (
int i=0 ; i<nevt ; i++) {
689 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
694 mergedStore->
fill() ;
722 for (
int i=0 ; i<nevt ; i++) {
773 vector<RooAbsArg*> trackArgs;
774 for (
const auto arg : newVarSetCopy) {
775 if (arg->getAttribute(
"ConstantExpression") && !arg->getAttribute(
"NOCacheAndTrack")) {
776 orderedArgs.
add(*arg) ;
783 if (arg->dependsOn(
_vars) && !arg->getAttribute(
"NOCacheAndTrack")) {
784 trackArgs.push_back(arg) ;
794 if (left == right) return false;
795 return right->dependsOn(*left);
799 for (
const auto trackedArg : trackArgs) {
800 orderedArgs.
add(*trackedArg);
810 std::vector<std::unique_ptr<RooArgSet>> vlist;
813 for (
const auto var : orderedArgs) {
816 auto newVarCloneList = std::make_unique<RooArgSet>();
818 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
821 vlist.emplace_back(std::move(newVarCloneList));
822 cloneSet.
add(*newVarClone) ;
831 std::vector<RooArgSet*> nsetList ;
832 std::vector<std::unique_ptr<RooArgSet>> argObsList ;
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());
843 const char* catNset = arg->getStringAttribute(
"CATNormSet") ;
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 << endl ;
926 std::vector<RooVectorDataStore::RealVector *> tv;
932 tv.push_back(realVec);
946 std::unique_ptr<RooArgSet> ownedNset;
948 if (projectedArgs && !projectedArgs->
empty()) {
949 ownedNset = std::make_unique<RooArgSet>();
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) {
989 for (
const auto elm : cacheElements) {
990 auto real =
static_cast<RooAbsReal*
>(cachedVarsIn.
find(elm->bufArg()->GetName()));
998 auto cat =
static_cast<RooAbsCategory*
>(cachedVarsIn.
find(catVec->bufArg()->GetName()));
1056 arg->attachToVStore(*
this);
1066 cout <<
"RooVectorDataStor::dump()" << endl ;
1069 cout <<
"realVector list is" << endl ;
1072 cout <<
"RealVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName() <<
" bufptr = " << elm->_buf << endl ;
1073 cout <<
" values : " ;
1074 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1075 for (
Int_t i=0 ; i<imax ; i++) {
1076 cout << elm->_vec[i] <<
" " ;
1082 cout <<
"RealFullVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName()
1083 <<
" bufptr = " << elm->_buf <<
" errbufptr = " << elm->bufE() << endl ;
1085 cout <<
" values : " ;
1086 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1087 for (
Int_t i=0 ; i<imax ; i++) {
1088 cout << elm->_vec[i] <<
" " ;
1092 cout <<
" errors : " ;
1093 for (
Int_t i=0 ; i<imax ; i++) {
1094 cout << elm->dataE()[i] <<
" " ;
1140 auto result = evalData.emplace(realVec->_nativeReal, span);
1143 coutE(DataHandling) <<
"A batch of data for '" << realVec->_nativeReal->GetName()
1145 <<
", but only the events [" <<
first <<
", " <<
first +
size <<
") are available." << std::endl;
1147 if (realVec->_real) {
1150 evalData.emplace(realVec->_real, std::move(span));
1179 auto result = evalData.emplace(catVec->_cat, span);
1182 coutE(DataHandling) <<
"A batch of data for '" << catVec->_cat->GetName()
1184 <<
", but only the events [" <<
first <<
", " <<
first +
size <<
") are available." << std::endl;
1208 auto findWeightVar = [
this](
const RealVector* realVec) {
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;
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());
double _sumWeight
Global sum of weights needed for normalization.
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.
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
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.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
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 copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValueDirty=true) override
Copy the cached value from given source and raise dirty flag.
void attachToVStore(RooVectorDataStore &vstore) override
Attach the category index and label to as branches to the given vector store.
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.
bool contains(const RooAbsArg &var) const
Check if collection contains an argument with the same name as var.
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
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...
RooAbsArg * find(const char *name) const
Find object with given name in list.
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
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
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...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
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.
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
Return a confidence interval for the expected number of events given n observed (unweighted) events.
RooRealVar represents a variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
bool hasError(bool allowZero=true) const
bool hasAsymError(bool allowZero=true) const
double getAsymErrorHi() const
double getAsymErrorLo() const
The RooStringView is a wrapper around a C-style string that can also be constructed from a std::strin...
RooTreeDataStore is a 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
RooArgSet _varsww
Was object constructed with default ctor?
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)
RooVectorDataStore uses std::vectors to store data columns.
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
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 ...
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
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.
void setDirtyProp(bool flag) override
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::vector< RealVector * > & realStoreList()
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.