72 _wgtVar(weightVar(vars,wgtVarName))
75 arg->attachToVStore(*
this) ;
89 realVec->setNativeBuffer();
93 fullVec->setNativeBuffer();
97 catVec->setNativeBuffer();
114 ret.
remove(*wgt,
true,
true) ;
143 _varsww(other._varsww),
144 _wgtVar(other._wgtVar),
145 _sumWeight(other._sumWeight),
146 _sumWeightCarry(other._sumWeightCarry),
147 _extWgtArray(other._extWgtArray),
148 _extWgtErrLoArray(other._extWgtErrLoArray),
149 _extWgtErrHiArray(other._extWgtErrHiArray),
150 _extSumW2Array(other._extSumW2Array),
151 _currentWeightIndex(other._currentWeightIndex)
174 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
176 _wgtVar(weightVar(vars,other._wgtVar?other._wgtVar->GetName():0))
178 for (
const auto arg :
_varsww) {
179 arg->attachToVStore(*
this) ;
200 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
202 _wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):0),
203 _sumWeight(other._sumWeight),
204 _sumWeightCarry(other._sumWeightCarry),
205 _extWgtArray(other._extWgtArray),
206 _extWgtErrLoArray(other._extWgtErrLoArray),
207 _extWgtErrHiArray(other._extWgtErrHiArray),
208 _extSumW2Array(other._extSumW2Array),
209 _currentWeightIndex(other._currentWeightIndex)
212 auto real =
static_cast<RooAbsReal*
>(vars.
find(realVec->bufArg()->GetName()));
217 real->attachToVStore(*
this) ;
221 vector<RealFullVector*>::const_iterator fiter = other.
_realfStoreList.begin() ;
232 vector<CatVector*>::const_iterator citer = other.
_catStoreList.begin() ;
252 std::size_t nStart, std::size_t nStop) {
267 std::size_t nStart, std::size_t nStop,
const char* wgtVarName) :
271 _wgtVar(weightVar(vars,wgtVarName))
273 for (
const auto arg :
_varsww) {
274 arg->attachToVStore(*
this) ;
291 loadValues(&tds,cloneVar,cutRange,nStart,nStop);
356 if (
index < 0 ||
static_cast<std::size_t
>(
index) >=
size())
return 0;
372 for (
auto var :
_vars) {
373 var->setValueDirty();
393 if (
index < 0 ||
static_cast<std::size_t
>(
index) >=
size())
return 0;
396 realV->loadToNative(
index) ;
400 fullRealP->loadToNative(
index);
404 catP->loadToNative(
index);
409 for (
auto var :
_vars) {
410 var->setValueDirty() ;
436 double lo = 0,
hi = 0 ;
472 throw string(
Form(
"RooDataHist::weightError(%s) error type Auto not allowed here",
GetName())) ;
476 throw string(
Form(
"RooDataHist::weightError(%s) error type Expected not allowed here",
GetName())) ;
538 std::unique_ptr<RooFormulaVar> selectClone;
541 selectClone->recursiveRedirectServers(*ads->
get()) ;
549 const auto numEntr =
static_cast<std::size_t
>(ads->
numEntries());
550 const std::size_t nevent = nStop < numEntr ? nStop : numEntr;
556 bool weightRename(
false) ;
570 std::vector<std::string> ranges;
576 for(
auto i=nStart; i < nevent ; ++i) {
580 if (selectClone && selectClone->getVal()==0) {
599 bool allValid =
true;
600 for (
const auto arg :
_varsww) {
601 allValid &= arg->isValid();
602 if (allValid && !ranges.empty()) {
605 allValid &= std::any_of(ranges.begin(), ranges.end(), [arg](
const std::string& range){
606 return arg->inRange(range.c_str());});
663 << valHolder->
GetName() <<
"\"" << endl;
668 const std::size_t numEvt =
size();
691 for (std::size_t i=0; i < numEvt; i++) {
697 if (rv) rv->
write(i) ;
698 if (cv) cv->
write(i) ;
718 const auto nevt = dstoreList.front()->numEntries();
720 for (
int i=0 ; i<nevt ; i++) {
726 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
731 mergedStore->
fill() ;
759 for (
int i=0 ; i<nevt ; i++) {
810 vector<RooAbsArg*> trackArgs;
811 for (
const auto arg : newVarSetCopy) {
812 if (arg->getAttribute(
"ConstantExpression") && !arg->getAttribute(
"NOCacheAndTrack")) {
813 orderedArgs.
add(*arg) ;
820 if (arg->dependsOn(
_vars) && !arg->getAttribute(
"NOCacheAndTrack")) {
821 trackArgs.push_back(arg) ;
831 if (left == right) return false;
832 return right->dependsOn(*left);
836 for (
const auto trackedArg : trackArgs) {
837 orderedArgs.
add(*trackedArg);
847 std::vector<RooArgSet*> vlist;
850 for (
const auto var : orderedArgs) {
854 RooAbsArg* newVarClone = newVarCloneList->
find(var->GetName()) ;
857 vlist.push_back(newVarCloneList) ;
858 cloneSet.
add(*newVarClone) ;
867 std::vector<RooArgSet*> nsetList ;
868 std::vector<RooArgSet*> argObsList ;
871 for (
const auto arg : cloneSet) {
872 arg->attachToVStore(*newCache) ;
874 RooArgSet* argObs = nset ? arg->getObservables(*nset) : arg->getVariables() ;
875 argObsList.push_back(argObs) ;
878 const char* catNset = arg->getStringAttribute(
"CATNormSet") ;
886 const char* catCset = arg->getStringAttribute(
"CATCondSet") ;
891 argObs->
remove(acset,
true,
true) ;
899 nsetList.push_back(normSet) ;
904 const std::size_t numEvt =
size();
906 for (std::size_t i=0; i < numEvt; i++) {
908 if (
weight()!=0 || !skipZeroWeights) {
909 for (
unsigned int j = 0; j < cloneSet.
size(); ++j) {
910 auto& cloneArg = cloneSet[j];
911 auto argNSet = nsetList[j];
913 cloneArg.syncCache(argNSet ? argNSet : nset) ;
923 for (
const auto arg : orderedArgs) {
924 arg->attachToVStore(*newCache) ;
927 if (!arg->getAttribute(
"ConstantExpression") &&
dynamic_cast<RooAbsReal*
>(arg)) {
936 coutI(
Optimization) <<
"RooVectorDataStore::cacheArg() element " << arg->
GetName() <<
" has change tracking enabled on parameters " << *deps << endl ;
944 for (
auto set : vlist) {
947 for (
auto set : argObsList) {
969 std::vector<RooVectorDataStore::RealVector *> tv;
975 tv.push_back(realVec);
991 if (projectedArgs && projectedArgs->
getSize()>0) {
993 ownedNset->
remove(*projectedArgs,
false,
true);
994 usedNset = ownedNset ;
1000 for (
int i=firstEvent ; i<lastEvent ; i+=stepSize) {
1002 bool zeroWeight = (
weight()==0) ;
1003 if (!zeroWeight || !skipZeroWeights) {
1004 for (
auto realVector : tv) {
1005 realVector->_nativeReal->_valueDirty =
true;
1006 realVector->_nativeReal->getValV(realVector->_nset ? realVector->_nset : usedNset);
1007 realVector->write(i);
1012 for (
auto realVector : tv) {
1034 for (
const auto elm : cacheElements) {
1035 auto real =
static_cast<RooAbsReal*
>(cachedVarsIn.
find(elm->bufArg()->GetName()));
1043 auto cat =
static_cast<RooAbsCategory*
>(cachedVarsIn.
find(catVec->bufArg()->GetName()));
1101 arg->attachToVStore(*
this);
1111 cout <<
"RooVectorDataStor::dump()" << endl ;
1114 cout <<
"realVector list is" << endl ;
1117 cout <<
"RealVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName() <<
" bufptr = " << elm->_buf << endl ;
1118 cout <<
" values : " ;
1119 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1120 for (
Int_t i=0 ; i<imax ; i++) {
1121 cout << elm->_vec[i] <<
" " ;
1127 cout <<
"RealFullVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName()
1128 <<
" bufptr = " << elm->_buf <<
" errbufptr = " << elm->_bufE << endl ;
1130 cout <<
" values : " ;
1131 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1132 for (
Int_t i=0 ; i<imax ; i++) {
1133 cout << elm->_vec[i] <<
" " ;
1137 cout <<
" errors : " ;
1138 for (
Int_t i=0 ; i<imax ; i++) {
1139 cout << (*elm->_vecE)[i] <<
" " ;
1206 auto result = evalData.
spans.emplace(realVec->_nativeReal, span);
1209 coutE(
DataHandling) <<
"A batch of data for '" << realVec->_nativeReal->GetName()
1211 <<
", but only the events [" <<
first <<
", " <<
first +
size <<
") are available." << std::endl;
1213 if (realVec->_real) {
1216 evalData.
spans.emplace(realVec->_real, std::move(span));
1241 std::map<const std::string, RooSpan<const RooAbsCategory::value_type>> evalData;
1245 auto result = evalData.emplace(catVec->_cat->GetName(), span);
1250 <<
", but only the events [" <<
first <<
", " <<
first +
size <<
") are available." << std::endl;
1274 auto findWeightVar = [
this](
const RealVector* realVec) {
1286 throw std::logic_error(
"RooVectorDataStore::getWeightBatch(): Could not retrieve data for _wgtVar.");
1296 if (std::string(catVec->bufArg()->GetName())==cat->
GetName()) {
1312 if (realVec->bufArg()->namePtr()==real->
namePtr()) {
1319 if (fullVec->bufArg()->namePtr()==real->
namePtr()) {
1336 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1348 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1349 return fullVec->_vecE ? true : false ;
1360 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1361 return fullVec->_vecEL ? true : false ;
1372 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1379 if (std::string(realVec->bufArg()->GetName())==real->
GetName()) {
1403 double const* arr =
nullptr;
1410 if(wgtName == real->_nativeReal->GetName())
1411 arr = real->_vec.data();
1414 if(wgtName == real->_nativeReal->GetName())
1415 arr = real->_vec.data();
1418 if(arr ==
nullptr) {
1435 out.
reals.emplace_back(real->_nativeReal->GetName(), real->_vec.data());
1438 std::string
name = realf->_nativeReal->GetName();
1439 out.
reals.emplace_back(
name, realf->_vec.data());
1440 if(realf->_vecE) out.
reals.emplace_back(
name +
"Err", realf->_vecE->data());
1441 if(realf->_vecEL) out.
reals.emplace_back(
name +
"ErrLo", realf->_vecEL->data());
1442 if(realf->_vecEH) out.
reals.emplace_back(
name +
"ErrHi", realf->_vecEH->data());
1445 out.
cats.emplace_back(cat->_cat->GetName(), cat->_vec.data());
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.
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.
virtual void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDirty=true)=0
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.
void attachDataStore(const RooAbsDataStore &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
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 void syncCache(const RooArgSet *nset=0)=0
virtual void attachToVStore(RooVectorDataStore &vstore)=0
virtual RooAbsArg * createFundamental(const char *newname=0) const =0
Create a fundamental-type object that stores our type of value.
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
RooArgSet * getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
A space to attach TBranches.
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.
RooAbsCollection & assignValueOnly(const RooAbsCollection &other, bool forceIfSizeOne=false)
Sets the value of any argument in our set that also appears in the other set.
bool contains(const RooAbsArg &var) const
Check if collection contains an argument with the same name as var.
void Print(Option_t *options=0) const override
This method must be overridden when a class wants to print itself.
Int_t getSize() const
Return the number of elements in the collection.
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.
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
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
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
A simple container to hold a batch of data values.
The RooStringView is a wrapper around a C-syle string that can also be constructed from a std::string...
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)
std::vector< double > * _vecE
void Streamer(TBuffer &) override
Stream an object of class RooVectorDataStore::RealFullVector.
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.
RooAbsDataStore * reduce(RooStringView name, RooStringView title, const RooArgSet &vars, const RooFormulaVar *cutVar, const char *cutRange, std::size_t nStart, std::size_t nStop) override
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
~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.
RooRealVar * _wgtVar
Pointer to weight variable (if set)
std::vector< RealVector * > _realStoreList
CatVector * addCategory(RooAbsCategory *cat)
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
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)
std::map< const std::string, RooSpan< const RooAbsCategory::value_type > > getCategoryBatches(std::size_t, std::size_t len) const override
double weight() const override
Return the weight of the last-retrieved data point.
ULong64_t _currentWeightIndex
bool isFullReal(RooAbsReal *real)
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 ...
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()
RooBatchCompute::RunContext getBatches(std::size_t first, std::size_t len) const override
Return batches of the data columns for the requested events.
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...
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
void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=0, bool skipZeroWeights=true) override
Cache given RooAbsArgs: The tree is given direct write access of the args internal cache the args val...
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.
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
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=0)=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.
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
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.
This struct enables passing computation data around between elements of a computation graph.
std::map< const RooAbsArg *, RooSpan< const double > > spans
Once an object has computed its value(s), the span pointing to the results is registered here.
Output struct for the RooVectorDataStore::getArrays() helper function.
std::vector< ArrayInfo< double > > reals
std::vector< ArrayInfo< RooAbsCategory::value_type > > cats