63using std::endl, std::list, std::string;
85 _wgtVar(weightVar(vars,wgtVarName))
97 _wgtVar(weightVar(vars,wgtVarName))
108 _wgtVar(weightVar(vars,wgtVarName))
112 if (selExpr && *selExpr) {
127 _wgtVar(weightVar(vars,wgtVarName))
131 if (selExpr && *selExpr) {
147 const char *wgtVarName)
150 _wgtVar(weightVar(vars, wgtVarName))
159 std::unique_ptr<RooFormulaVar> cloneVar;
162 cloneVar->attachDataStore(tds) ;
168 loadValues(&tds,cloneVar.get(),cutRange,nStart,nStop);
174 std::size_t nStart, std::size_t nStop) {
180 return std::make_unique<RooTreeDataStore>(
name, title, *
this, tmp, cutVar, cutRange, nStart, nStop, wgtVarName);
194 ret.
remove(*wgt,
true,
true) ;
220 _varsww(other._varsww),
221 _wgtVar(other._wgtVar),
222 _extWgtArray(other._extWgtArray),
223 _extWgtErrLoArray(other._extWgtErrLoArray),
224 _extWgtErrHiArray(other._extWgtErrHiArray),
225 _extSumW2Array(other._extSumW2Array),
226 _curWgt(other._curWgt),
227 _curWgtErrLo(other._curWgtErrLo),
228 _curWgtErrHi(other._curWgtErrHi),
229 _curWgtErr(other._curWgtErr)
239 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():nullptr),newname),
241 _wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):nullptr),
242 _extWgtArray(other._extWgtArray),
243 _extWgtErrLoArray(other._extWgtErrLoArray),
244 _extWgtErrHiArray(other._extWgtErrHiArray),
245 _extSumW2Array(other._extSumW2Array),
246 _curWgt(other._curWgt),
247 _curWgtErrLo(other._curWgtErrLo),
248 _curWgtErrHi(other._curWgtErrHi),
249 _curWgtErr(other._curWgtErr)
305 bool notInMemNow= (pwd!=memDir) ;
334 std::unique_ptr<
TTree,
decltype(deleter)> tClone(
static_cast<TTree*
>(t->
Clone()), deleter);
342 bool missingBranches =
false;
343 for (
const auto var : sourceArgSet) {
344 if (!tClone->GetBranch(var->GetName())) {
345 missingBranches =
true;
346 coutE(InputArguments) <<
"Didn't find a branch in Tree '" << tClone->GetName() <<
"' to read variable '"
347 << var->GetName() <<
"' from."
348 <<
"\n\tNote: Name the RooFit variable the same as the branch." << std::endl;
351 if (missingBranches) {
352 coutE(InputArguments) <<
"Cannot import data from TTree '" << tClone->GetName()
353 <<
"' because some branches are missing !" << std::endl;
358 for (
const auto sourceArg : sourceArgSet) {
363 std::unique_ptr<RooFormulaVar> selectClone;
365 selectClone.reset(
static_cast<RooFormulaVar*
>(select->cloneTree()) );
366 selectClone->recursiveRedirectServers(sourceArgSet) ;
371 Int_t numInvalid(0) ;
372 const Long64_t nevent = tClone->GetEntries();
373 for(
Long64_t i=0; i < nevent; ++i) {
374 const auto entryNumber = tClone->GetEntryNumber(i);
375 if (entryNumber<0)
break;
376 tClone->GetEntry(entryNumber,1);
380 for (
unsigned int j=0; j < sourceArgSet.
size(); ++j) {
382 const auto sourceArg = sourceArgSet[j];
384 destArg->copyCache(sourceArg) ;
385 sourceArg->copyCache(destArg) ;
386 if (!destArg->isValid()) {
389 if (numInvalid < 5) {
390 auto& log =
coutI(DataHandling);
391 log <<
"RooTreeDataStore::loadValues(" <<
GetName() <<
") Skipping event #" << i <<
" because " << destArg->GetName()
392 <<
" cannot accommodate the value ";
393 if(sourceArg->isCategory()) {
394 log << static_cast<RooAbsCategory*>(sourceArg)->getCurrentIndex();
396 log << static_cast<RooAbsReal*>(sourceArg)->getVal();
399 }
else if (numInvalid == 5) {
400 coutI(DataHandling) <<
"RooTreeDataStore::loadValues(" <<
GetName() <<
") Skipping ..." << std::endl;
407 if (!allOK || (selectClone && selectClone->getVal()==0)) {
415 coutW(DataHandling) <<
"RooTreeDataStore::loadValues(" <<
GetName() <<
") Ignored " << numInvalid <<
" out-of-range events" << std::endl ;
432 const char* rangeName, std::size_t nStart, std::size_t nStop)
435 std::unique_ptr<RooFormulaVar> selectClone;
437 selectClone.reset(
static_cast<RooFormulaVar*
>(select->cloneTree()) );
438 selectClone->recursiveRedirectServers(*ads->
get()) ;
446 const auto numEntr =
static_cast<std::size_t
>(ads->
numEntries());
447 std::size_t nevent = nStop < numEntr ? nStop : numEntr;
454 std::vector<std::string> ranges;
459 for (
auto i=nStart; i < nevent ; ++i) {
463 if (selectClone && selectClone->getVal()==0) {
475 bool allValid =
true;
476 for (
const auto arg :
_varsww) {
477 allValid = arg->isValid() && (ranges.empty() || std::any_of(ranges.begin(), ranges.end(),
478 [arg](
const std::string& range){return arg->inRange(range.c_str());}) );
519 if(!ret)
return nullptr;
523 for (
auto var :
_vars) {
524 var->setValueDirty();
609 throw string(
Form(
"RooDataHist::weightError(%s) error type Auto not allowed here",
GetName())) ;
613 throw string(
Form(
"RooDataHist::weightError(%s) error type Expected not allowed here",
GetName())) ;
674 coutE(InputArguments) <<
"RooTreeDataStore::changeObservableName(" <<
GetName() <<
" no observable " << from <<
" in this dataset" << std::endl ;
742 auto valHolder = std::unique_ptr<RooAbsArg>{newVar.
createFundamental()}.release();
744 if(!valHolder->isFundamental()) {
745 coutE(InputArguments) <<
GetName() <<
"::addColumn: holder argument is not fundamental: \""
746 << valHolder->GetName() <<
"\"" << std::endl;
754 std::unique_ptr<RooAbsArg> newVarClone{newVar.
cloneTree()};
767 newVarClone->syncCache(&
_vars) ;
768 valHolder->copyCache(newVarClone.get());
769 valHolder->fillTreeBranch(*
_tree) ;
799 Int_t nevt = dstoreList.front()->numEntries() ;
800 for (
int i=0 ; i<nevt ; i++) {
806 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
811 mergedStore->
fill() ;
825 for (
int i=0 ; i<nevt ; i++) {
845 for (
int i=0 ; i<nevt ; i++) {
850 carry = (t -
sum) -
y;
860 for (
int i=0 ; i<nevt ; i++) {
864 carry = (t -
sum) -
y;
902 for (
const auto arg :
_varsww) {
905 if (arg->getAttribute(
"StoreError")) {
908 if (arg->getAttribute(
"StoreAsymError")) {
924 arg->attachToTree(*
_tree) ;
935 arg->attachToTree(*
_tree) ;
977 if (
_tree && parent) {
1000 std::replace(title.begin(), title.end(),
' ',
'_');
1001 std::replace(title.begin(), title.end(),
'-',
'_');
1002 return std::string(
"RooTreeDataStore_") +
GetName() +
"_" + title;
int Int_t
Signed integer 4 bytes (int)
short Version_t
Class version identifier (short)
long long Long64_t
Portable signed long integer 8 bytes.
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.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool recursiveRedirectServers(const RooAbsCollection &newSet, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
void SetName(const char *name) override
Set the name of the TNamed.
virtual RooFit::OwningPtr< RooAbsArg > createFundamental(const char *newname=nullptr) const =0
Create a fundamental-type object that stores our type of value.
virtual void attachToTree(TTree &t, Int_t bufSize=32000)=0
Overloadable function for derived classes to implement attachment as branch to a TTree.
virtual RooAbsArg * cloneTree(const char *newname=nullptr) const
Clone tree expression of objects.
TString cleanBranchName() const
Construct a mangled name from the actual name that is free of any math symbols that might be interpre...
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
bool contains(const char *name) const
Check if collection contains an argument with a specific name.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
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.
virtual bool add(const RooAbsArg &var, bool silent=false)
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
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for a data collection.
virtual const RooArgSet * get(Int_t index) const =0
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
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
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
Calculate a confidence interval for the expected number of events given n observed (unweighted) event...
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
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...
const char * c_str() const
TTree-backed data storage.
void initialize()
One-time initialization common to all constructor forms.
double _curWgtErr
Weight of current event.
double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override
void resetBuffers() override
double _curWgt
Weight of current event.
double _curWgtErrHi
Weight of current event.
Int_t numEntries() const override
std::string makeTreeName() const
Generate a name for the storage tree from the name and title of this instance.
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName=nullptr)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
~RooTreeDataStore() override
Destructor.
void createTree(RooStringView name, RooStringView title)
Create TTree object that lives in memory, independent of current location of gDirectory.
const double * _extWgtErrHiArray
! External weight array - high error
void attachBuffers(const RooArgSet &extObs) override
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList) override
Merge columns of supplied data set(s) with this data set.
static Int_t _defTreeBufSize
RooArgSet _attachedBuffers
! Currently attached buffers (if different from _varsww)
Int_t fill() override
Interface function to TTree::Fill.
double sumEntries() const override
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
bool _defCtor
! Was object constructed with default ctor?
RooAbsArg * addColumn(RooAbsArg &var, bool adjustRange=true) override
Add a new column to the data set which holds the pre-calculated values of 'newVar'.
double weight() const override
Return the weight of the n-th data point (n='index') in memory.
void restoreAlternateBuffers()
void loadValues(const TTree *t, const RooFormulaVar *select=nullptr, const char *rangeName=nullptr, Int_t nStart=0, Int_t nStop=2000000000)
Load values from tree 't' into this data collection, optionally selecting events using the RooFormula...
void append(RooAbsDataStore &other) override
std::span< const double > getWeightBatch(std::size_t first, std::size_t len) const override
Get the weights of the events in the range [first, first+len).
const double * _extWgtErrLoArray
! External weight array - low error
void checkInit() const override
std::unique_ptr< std::vector< double > > _weightBuffer
! Buffer for weights in case a batch of values is requested.
const double * _extSumW2Array
! External sum of weights array
void Streamer(TBuffer &) override
Stream an object of class RooTreeDataStore.
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName=nullptr)
Utility function for constructors Return pointer to weight variable if it is defined.
const double * _extWgtArray
! External weight array
double _curWgtErrLo
Weight of current event.
bool changeObservableName(const char *from, const char *to) override
Change name of internal observable named 'from' into 'to'.
virtual const RooArgSet * get() const
Buffer base class used for serializing objects.
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
TObject * GetParent() const
Return pointer to parent of this buffer.
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
Describe directory structure in memory.
void GetObject(const char *namecycle, T *&ptr)
Get an object with proper type checking.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
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.
virtual void SetName(const char *name)
Set the name of the TNamed.
@ kCanDelete
if object in a list can be deleted
@ kMustCleanup
if object destructor must call RecursiveRemove()
const char * Data() const
TString & Append(const char *cs)
A TTree represents a columnar dataset.
virtual Int_t Fill()
Fill all branches.
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
virtual Int_t FlushBaskets(bool create_cluster=true) const
Write to disk all the basket that have not yet been individually written and create an event cluster ...
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
TDirectory * GetDirectory() const
virtual void SetDirectory(TDirectory *dir)
Change the tree's directory.
virtual Long64_t GetEntries() const
virtual void Reset(Option_t *option="")
Reset baskets, buffers and entries count in all branches and leaves.
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
static uint64_t sum(uint64_t i)