Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooTreeDataStore.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16#ifndef ROO_TREE_DATA_STORE
17#define ROO_TREE_DATA_STORE
18
19#include "RooAbsDataStore.h"
20
21#include "ROOT/RStringView.hxx"
22
23#include <vector>
24#include <list>
25#include <string>
26
27class RooAbsArg ;
28class RooArgList ;
29class TTree ;
30class RooFormulaVar ;
31class RooArgSet ;
32
33
35public:
36
38 RooTreeDataStore(TTree* t, const RooArgSet& vars, const char* wgtVarName=nullptr) ;
39
40 // Empty ctor
41 RooTreeDataStore(RooStringView name, RooStringView title, const RooArgSet& vars, const char* wgtVarName=nullptr) ;
42 RooAbsDataStore* clone(const char* newname=nullptr) const override { return new RooTreeDataStore(*this,newname) ; }
43 RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=nullptr) const override { return new RooTreeDataStore(*this,vars,newname) ; }
44
45 std::unique_ptr<RooAbsDataStore> reduce(RooStringView name, RooStringView title,
46 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
47 std::size_t nStart, std::size_t nStop) override;
48
49 // Constructor from TTree
50 RooTreeDataStore(RooStringView name, RooStringView title, const RooArgSet& vars, TTree& t, const char* selExpr=nullptr, const char* wgtVarName=nullptr) ;
51
52 // Constructor from DataStore
53 RooTreeDataStore(RooStringView name, RooStringView title, const RooArgSet& vars, const RooAbsDataStore& tds, const char* selExpr=nullptr, const char* wgtVarName=nullptr) ;
54
56 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
57 Int_t nStart, Int_t nStop, const char* wgtVarName=nullptr) ;
58
59 RooTreeDataStore(const RooTreeDataStore& other, const char* newname=nullptr) ;
60 RooTreeDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname=nullptr) ;
61 ~RooTreeDataStore() override ;
62
63
64 // Write current row
65 Int_t fill() override ;
66
67 // Retrieve a row
69 const RooArgSet* get(Int_t index) const override ;
71 double weight() const override ;
72 double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override ;
73 void weightError(double& lo, double& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const override ;
74 bool isWeighted() const override { return (_wgtVar!=nullptr||_extWgtArray!=nullptr) ; }
75
76 RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const override {
77 //TODO
78 std::cerr << "This functionality is not yet implemented for tree data stores." << std::endl;
79 throw std::logic_error("getBatches() not implemented in RooTreeDataStore.");
80 (void)first; (void)len;
81 return {};
82 }
83 std::span<const double> getWeightBatch(std::size_t first, std::size_t len) const override;
84
85 // Change observable name
86 bool changeObservableName(const char* from, const char* to) override ;
87
88 // Add one column
89 RooAbsArg* addColumn(RooAbsArg& var, bool adjustRange=true) override ;
90
91 // Merge column-wise
92 RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) override ;
93
94 // Add rows
95 void append(RooAbsDataStore& other) override ;
96
97 // General & bookkeeping methods
98 double sumEntries() const override ;
99 Int_t numEntries() const override ;
100 void reset() override ;
101
102 // Buffer redirection routines used in inside RooAbsOptTestStatistics
103 void attachBuffers(const RooArgSet& extObs) override ;
104 void resetBuffers() override ;
106
107 // Tree access
108 TTree& tree() { return *_tree ; }
109 const TTree* tree() const override { return _tree ; }
110
111 // Forwarded from TTree
112 Stat_t GetEntries() const;
113 void Reset(Option_t* option=nullptr);
114 Int_t Fill();
115 Int_t GetEntry(Int_t entry = 0, Int_t getall = 0);
116
117 void Draw(Option_t* option = "") override ;
118
119 // Constant term optimizer interface
120 void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=nullptr, bool skipZeroWeights=false) override ;
121 const RooAbsArg* cacheOwner() override { return _cacheOwner ; }
122 void setArgStatus(const RooArgSet& set, bool active) override ;
123 void resetCache() override ;
124
125 void loadValues(const TTree *t, const RooFormulaVar* select=nullptr, const char* rangeName=nullptr, Int_t nStart=0, Int_t nStop=2000000000) ;
126 void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=nullptr, const char* rangeName=nullptr,
127 std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max()) override;
128
129 void checkInit() const override;
130
131 void setExternalWeightArray(const double* arrayWgt, const double* arrayWgtErrLo,
132 const double* arrayWgtErrHi, const double* arraySumW2) override {
133 _extWgtArray = arrayWgt ;
134 _extWgtErrLoArray = arrayWgtErrLo ;
135 _extWgtErrHiArray = arrayWgtErrHi ;
136 _extSumW2Array = arraySumW2 ;
137 }
138
139 const RooArgSet& row() { return _varsww ; }
140
141 private:
142
143 friend class RooVectorDataStore ;
144
145 RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName=nullptr) ;
146 RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName=nullptr) ;
147
148 void initialize();
149 void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) override ;
150
151 // TTree Branch buffer size control
154
155 std::string makeTreeName() const;
156
158
160 TTree *_tree = nullptr; // TTree holding the data points
161 TTree *_cacheTree = nullptr; //! TTree holding the cached function values
162 const RooAbsArg* _cacheOwner = nullptr; //! Object owning cache contents
163 mutable bool _defCtor = false; //! Was object constructed with default ctor?
164
166 RooRealVar* _wgtVar = nullptr; // Pointer to weight variable (if set)
167
168 const double* _extWgtArray{nullptr}; ///<! External weight array
169 const double* _extWgtErrLoArray{nullptr}; ///<! External weight array - low error
170 const double* _extWgtErrHiArray{nullptr}; ///<! External weight array - high error
171 const double* _extSumW2Array{nullptr}; ///<! External sum of weights array
172 mutable std::unique_ptr<std::vector<double>> _weightBuffer; //! Buffer for weights in case a batch of values is requested.
173
174 mutable double _curWgt = 1.0; ///< Weight of current event
175 mutable double _curWgtErrLo = 0.0; ///< Weight of current event
176 mutable double _curWgtErrHi = 0.0; ///< Weight of current event
177 mutable double _curWgtErr = 0.0; ///< Weight of current event
178
179 RooArgSet _attachedBuffers ; ///<! Currently attached buffers (if different from _varsww)
180
181 ClassDefOverride(RooTreeDataStore, 2) // TTree-based Data Storage class
182};
183
184
185#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t option
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 name[80]
Definition TGX11.cxx:110
#define hi
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:79
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
const RooArgSet & cachedVars() const
virtual double weight() const =0
virtual const RooArgSet * get() const
std::map< RooFit::Detail::DataKey, std::span< const double > > RealSpans
Definition RooAbsData.h:131
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:37
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.
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
bool isWeighted() const override
void resetBuffers() override
RooAbsDataStore * clone(const char *newname=nullptr) const override
double _curWgt
Buffer for weights in case a batch of values is requested.
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.
RooAbsDataStore * clone(const RooArgSet &vars, const char *newname=nullptr) const override
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 setBranchBufferSize(Int_t size)
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.
void reset() 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
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 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
const RooAbsArg * cacheOwner() override
Int_t getBranchBufferSize() const
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
RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const override
Retrieve batches for all observables in this data store.
std::unique_ptr< std::vector< double > > _weightBuffer
Int_t Fill()
Interface function to TTree::Fill.
const double * _extSumW2Array
! External sum of weights array
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?
const TTree * tree() const override
void setExternalWeightArray(const double *arrayWgt, const double *arrayWgtErrLo, const double *arrayWgtErrHi, const double *arraySumW2) override
const RooArgSet & row()
RooVectorDataStore uses std::vectors to store data columns.
A TTree represents a columnar dataset.
Definition TTree.h:79
Definition first.py:1
th1 Draw()