63using std::endl, std::list, std::string;
113 if (selExpr && *selExpr) {
132 if (selExpr && *selExpr) {
148 const char *wgtVarName)
160 std::unique_ptr<RooFormulaVar> cloneVar;
163 cloneVar->attachDataStore(tds) ;
175 loadValues(&tds,cloneVar.get(),cutRange,nStart,nStop);
181 std::size_t nStart, std::size_t nStop) {
187 return std::make_unique<RooTreeDataStore>(
name, title, *
this, tmp, cutVar, cutRange, nStart, nStop, wgtVarName);
201 ret.
remove(*wgt,
true,
true) ;
332 _tree->SetDirectory(
nullptr);
338 bool notInMemNow= (pwd!=memDir) ;
373 std::unique_ptr<
TTree,
decltype(deleter)> tClone(
static_cast<TTree*
>(t->
Clone()), deleter);
378 _varsww.snapshot(sourceArgSet,
false);
381 bool missingBranches =
false;
382 for (
const auto var : sourceArgSet) {
383 if (!tClone->GetBranch(var->GetName())) {
384 missingBranches =
true;
385 coutE(InputArguments) <<
"Didn't find a branch in Tree '" << tClone->GetName() <<
"' to read variable '"
386 << var->GetName() <<
"' from."
387 <<
"\n\tNote: Name the RooFit variable the same as the branch." << std::endl;
390 if (missingBranches) {
391 coutE(InputArguments) <<
"Cannot import data from TTree '" << tClone->GetName()
392 <<
"' because some branches are missing !" << std::endl;
397 for (
const auto sourceArg : sourceArgSet) {
402 std::unique_ptr<RooFormulaVar> selectClone;
405 selectClone->recursiveRedirectServers(sourceArgSet) ;
410 Int_t numInvalid(0) ;
411 const Long64_t nevent = tClone->GetEntries();
413 const auto entryNumber = tClone->GetEntryNumber(
i);
414 if (entryNumber<0)
break;
415 tClone->GetEntry(entryNumber,1);
419 for (
unsigned int j=0; j < sourceArgSet.
size(); ++j) {
421 const auto sourceArg = sourceArgSet[j];
423 destArg->copyCache(sourceArg) ;
424 sourceArg->copyCache(destArg) ;
425 if (!destArg->isValid()) {
428 if (numInvalid < 5) {
429 auto& log =
coutI(DataHandling);
430 log <<
"RooTreeDataStore::loadValues(" <<
GetName() <<
") Skipping event #" <<
i <<
" because " << destArg->GetName()
431 <<
" cannot accommodate the value ";
432 if(sourceArg->isCategory()) {
433 log << static_cast<RooAbsCategory*>(sourceArg)->getCurrentIndex();
435 log << static_cast<RooAbsReal*>(sourceArg)->getVal();
438 }
else if (numInvalid == 5) {
439 coutI(DataHandling) <<
"RooTreeDataStore::loadValues(" <<
GetName() <<
") Skipping ..." << std::endl;
446 if (!allOK || (selectClone && selectClone->getVal()==0)) {
454 coutW(DataHandling) <<
"RooTreeDataStore::loadValues(" <<
GetName() <<
") Ignored " << numInvalid <<
" out-of-range events" << endl ;
471 const char* rangeName, std::size_t nStart, std::size_t nStop)
474 std::unique_ptr<RooFormulaVar> selectClone;
477 selectClone->recursiveRedirectServers(*ads->
get()) ;
485 const auto numEntr =
static_cast<std::size_t
>(ads->
numEntries());
486 std::size_t nevent = nStop < numEntr ? nStop : numEntr;
493 std::vector<std::string> ranges;
498 for (
auto i=nStart;
i < nevent ; ++
i) {
502 if (selectClone && selectClone->getVal()==0) {
508 _varsww.assignValueOnly(TDS->_varsww) ;
514 bool allValid =
true;
515 for (
const auto arg :
_varsww) {
516 allValid = arg->isValid() && (ranges.empty() || std::any_of(ranges.begin(), ranges.end(),
517 [arg](
const std::string& range){return arg->inRange(range.c_str());}) );
543 return _tree->Fill() ;
559 if(!ret)
return nullptr;
563 for (
auto var :
_vars) {
564 var->setValueDirty();
568 var->setValueDirty();
569 var->clearValueDirty();
631 return (
_wgtVar->getAsymErrorHi() -
_wgtVar->getAsymErrorLo() ) / 2 ;
656 throw string(
Form(
"RooDataHist::weightError(%s) error type Auto not allowed here",
GetName())) ;
660 throw string(
Form(
"RooDataHist::weightError(%s) error type Expected not allowed here",
GetName())) ;
695 lo =
_wgtVar->getAsymErrorLo() ;
721 coutE(InputArguments) <<
"RooTreeDataStore::changeObservableName(" <<
GetName() <<
" no observable " << from <<
" in this dataset" << endl ;
730 if (
_tree->GetBranch(oldBranchName.
Data())) {
739 if (
_tree->GetBranch(
Form(
"%s_aerr_lo",oldBranchName.
Data()))) {
742 if (
_tree->GetBranch(
Form(
"%s_aerr_hi",oldBranchName.
Data()))) {
789 auto valHolder = std::unique_ptr<RooAbsArg>{newVar.
createFundamental()}.release();
791 if(!valHolder->isFundamental()) {
792 coutE(InputArguments) <<
GetName() <<
"::addColumn: holder argument is not fundamental: \""
793 << valHolder->GetName() <<
"\"" << endl;
806 _vars.add(*valHolder) ;
815 valHolder->copyCache(newVarClone) ;
816 valHolder->fillTreeBranch(*
_tree) ;
849 Int_t nevt = dstoreList.front()->numEntries() ;
850 for (
int i=0 ;
i<nevt ;
i++) {
856 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
861 mergedStore->
fill() ;
875 for (
int i=0 ;
i<nevt ;
i++) {
895 for (
int i=0 ;
i<nevt ;
i++) {
898 double y =
_wgtVar->getVal() - carry;
900 carry = (t -
sum) -
y;
910 for (
int i=0 ;
i<nevt ;
i++) {
914 carry = (t -
sum) -
y;
933 return _tree->GetEntries() ;
961 std::unique_ptr<RooArgSet> constExprVarSet{
static_cast<RooArgSet*
>(newVarSet.
selectByAttrib(
"ConstantExpression",
true))};
965 for (
RooAbsArg * arg : *constExprVarSet) {
980 for (
RooAbsArg * arg : *constExprVarSet) {
981 arg->setValueDirty() ;
982 arg->syncCache(nset) ;
1009 coutE(InputArguments) <<
"RooTreeDataStore::setArgStatus(" <<
GetName()
1010 <<
") dataset doesn't contain variable " << arg->GetName() << endl ;
1044 for (
const auto arg :
_varsww) {
1047 if (arg->getAttribute(
"StoreError")) {
1050 if (arg->getAttribute(
"StoreAsymError")) {
1066 arg->attachToTree(*
_tree) ;
1077 arg->attachToTree(*
_tree) ;
1102 return _tree->GetEntries() ;
1120 return _tree->Fill() ;
1130 if (!ret1)
return 0 ;
1169 if (
_tree && parent) {
1173 auto tmpDir =
_tree->GetDirectory();
1175 _tree->SetDirectory(parent);
1176 _tree->FlushBaskets(
false);
1178 _tree->SetDirectory(tmpDir);
1192 std::replace(title.begin(), title.end(),
' ',
'_');
1193 std::replace(title.begin(), title.end(),
'-',
'_');
1194 return std::string(
"RooTreeDataStore_") +
GetName() +
"_" + title;
true
Register systematic variations for multiple existing columns using auto-generated tags.
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 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 &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
virtual void syncCache(const RooArgSet *nset=nullptr)=0
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 void setTreeBranchStatus(TTree &t, bool active)=0
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.
RooAbsCollection * selectByAttrib(const char *name, bool value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
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.
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
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
RooArgSet is a container object that can hold multiple RooAbsArg objects.
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.
Variable that can be changed from the outside.
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
Buffer for weights in case a batch of values is requested.
void Draw(Option_t *option="") override
Default Draw method for all objects.
void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars) override
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
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
Stat_t GetEntries() const
Interface function to TTree::GetEntries.
void attachBuffers(const RooArgSet &extObs) override
Int_t GetEntry(Int_t entry=0, Int_t getall=0)
Interface function to TTree::GetEntry.
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
Object owning cache contents.
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 Reset(Option_t *option=nullptr)
Interface function to TTree::Reset.
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
Int_t Fill()
Interface function to TTree::Fill.
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'.
void resetCache() override
Remove tree with values of cached observables and clear list of cached observables.
void setArgStatus(const RooArgSet &set, bool active) override
Activate or deactivate the branch status of the TTree branch associated with the given set of dataset...
void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=nullptr, bool skipZeroWeights=false) override
Cache given RooAbsArgs with this tree: The tree is given direct write access of the args internal cac...
virtual const RooArgSet * get() const
const RooAbsArg * _cacheOwner
TTree holding the cached function values.
RooArgSet _varsww
Was object constructed with default ctor?
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.
@ 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.
TDirectory * GetDirectory() const
virtual void SetDirectory(TDirectory *dir)
Change the tree's directory.
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)