File indexing completed on 2025-01-18 10:11:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROO_TREE_DATA_STORE
0017 #define ROO_TREE_DATA_STORE
0018
0019 #include "RooAbsDataStore.h"
0020
0021 #include <string_view>
0022
0023 #include <vector>
0024 #include <list>
0025 #include <string>
0026
0027 class RooAbsArg ;
0028 class RooArgList ;
0029 class TTree ;
0030 class RooFormulaVar ;
0031 class RooArgSet ;
0032
0033
0034 class RooTreeDataStore : public RooAbsDataStore {
0035 public:
0036
0037 RooTreeDataStore() ;
0038 RooTreeDataStore(TTree* t, const RooArgSet& vars, const char* wgtVarName=nullptr) ;
0039
0040
0041 RooTreeDataStore(RooStringView name, RooStringView title, const RooArgSet& vars, const char* wgtVarName=nullptr) ;
0042 RooAbsDataStore* clone(const char* newname=nullptr) const override { return new RooTreeDataStore(*this,newname) ; }
0043 RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=nullptr) const override { return new RooTreeDataStore(*this,vars,newname) ; }
0044
0045 std::unique_ptr<RooAbsDataStore> reduce(RooStringView name, RooStringView title,
0046 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
0047 std::size_t nStart, std::size_t nStop) override;
0048
0049
0050 RooTreeDataStore(RooStringView name, RooStringView title, const RooArgSet& vars, TTree& t, const char* selExpr=nullptr, const char* wgtVarName=nullptr) ;
0051
0052
0053 RooTreeDataStore(RooStringView name, RooStringView title, const RooArgSet& vars, const RooAbsDataStore& tds, const char* selExpr=nullptr, const char* wgtVarName=nullptr) ;
0054
0055 RooTreeDataStore(RooStringView name, RooStringView title, RooAbsDataStore& tds,
0056 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
0057 Int_t nStart, Int_t nStop, const char* wgtVarName=nullptr) ;
0058
0059 RooTreeDataStore(const RooTreeDataStore& other, const char* newname=nullptr) ;
0060 RooTreeDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname=nullptr) ;
0061 ~RooTreeDataStore() override ;
0062
0063
0064
0065 Int_t fill() override ;
0066
0067
0068 using RooAbsDataStore::get ;
0069 const RooArgSet* get(Int_t index) const override ;
0070 using RooAbsDataStore::weight ;
0071 double weight() const override ;
0072 double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override ;
0073 void weightError(double& lo, double& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const override ;
0074 bool isWeighted() const override { return (_wgtVar!=nullptr||_extWgtArray!=nullptr) ; }
0075
0076 RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const override {
0077
0078 std::cerr << "This functionality is not yet implemented for tree data stores." << std::endl;
0079 throw std::logic_error("getBatches() not implemented in RooTreeDataStore.");
0080 (void)first; (void)len;
0081 return {};
0082 }
0083 std::span<const double> getWeightBatch(std::size_t first, std::size_t len) const override;
0084
0085
0086 bool changeObservableName(const char* from, const char* to) override ;
0087
0088
0089 RooAbsArg* addColumn(RooAbsArg& var, bool adjustRange=true) override ;
0090
0091
0092 RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) override ;
0093
0094
0095 void append(RooAbsDataStore& other) override ;
0096
0097
0098 double sumEntries() const override ;
0099 Int_t numEntries() const override ;
0100 void reset() override ;
0101
0102
0103 void attachBuffers(const RooArgSet& extObs) override ;
0104 void resetBuffers() override ;
0105 void restoreAlternateBuffers() ;
0106
0107
0108 TTree& tree() { return *_tree ; }
0109 const TTree* tree() const override { return _tree ; }
0110
0111
0112 Stat_t GetEntries() const;
0113 void Reset(Option_t* option=nullptr);
0114 Int_t Fill();
0115 Int_t GetEntry(Int_t entry = 0, Int_t getall = 0);
0116
0117 void Draw(Option_t* option = "") override ;
0118
0119
0120 void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=nullptr, bool skipZeroWeights=false) override ;
0121 const RooAbsArg* cacheOwner() override { return _cacheOwner ; }
0122 void setArgStatus(const RooArgSet& set, bool active) override ;
0123 void resetCache() override ;
0124
0125 void loadValues(const TTree *t, const RooFormulaVar* select=nullptr, const char* rangeName=nullptr, Int_t nStart=0, Int_t nStop=2000000000) ;
0126 void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=nullptr, const char* rangeName=nullptr,
0127 std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max()) override;
0128
0129 void checkInit() const override;
0130
0131 void setExternalWeightArray(const double* arrayWgt, const double* arrayWgtErrLo,
0132 const double* arrayWgtErrHi, const double* arraySumW2) override {
0133 _extWgtArray = arrayWgt ;
0134 _extWgtErrLoArray = arrayWgtErrLo ;
0135 _extWgtErrHiArray = arrayWgtErrHi ;
0136 _extSumW2Array = arraySumW2 ;
0137 }
0138
0139 const RooArgSet& row() { return _varsww ; }
0140
0141 private:
0142
0143 friend class RooVectorDataStore ;
0144
0145 RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName=nullptr) ;
0146 RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName=nullptr) ;
0147
0148 void initialize();
0149 void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) override ;
0150
0151
0152 void setBranchBufferSize(Int_t size) { _defTreeBufSize = size ; }
0153 Int_t getBranchBufferSize() const { return _defTreeBufSize ; }
0154
0155 std::string makeTreeName() const;
0156
0157 static Int_t _defTreeBufSize ;
0158
0159 void createTree(RooStringView name, RooStringView title) ;
0160 TTree *_tree = nullptr;
0161 TTree *_cacheTree = nullptr;
0162 const RooAbsArg* _cacheOwner = nullptr;
0163 mutable bool _defCtor = false;
0164
0165 RooArgSet _varsww ;
0166 RooRealVar* _wgtVar = nullptr;
0167
0168 const double* _extWgtArray{nullptr};
0169 const double* _extWgtErrLoArray{nullptr};
0170 const double* _extWgtErrHiArray{nullptr};
0171 const double* _extSumW2Array{nullptr};
0172 mutable std::unique_ptr<std::vector<double>> _weightBuffer;
0173
0174 mutable double _curWgt = 1.0;
0175 mutable double _curWgtErrLo = 0.0;
0176 mutable double _curWgtErrHi = 0.0;
0177 mutable double _curWgtErr = 0.0;
0178
0179 RooArgSet _attachedBuffers ;
0180
0181 ClassDefOverride(RooTreeDataStore, 2)
0182 };
0183
0184
0185 #endif