Logo ROOT  
Reference Guide
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 #include "RunContext.h"
21 #include <vector>
22 #include <list>
23 #include <string>
24 
25 class RooAbsArg ;
26 class RooArgList ;
27 class TTree ;
28 class RooFormulaVar ;
29 class RooArgSet ;
30 
31 
33 public:
34 
35  RooTreeDataStore() ;
36  RooTreeDataStore(TTree* t, const RooArgSet& vars, const char* wgtVarName=0) ;
37 
38  // Empty ctor
39  RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const char* wgtVarName=0) ;
40  virtual RooAbsDataStore* clone(const char* newname=0) const { return new RooTreeDataStore(*this,newname) ; }
41  virtual RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=0) const { return new RooTreeDataStore(*this,vars,newname) ; }
42 
43  // Ctors from TTree
44  RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, TTree& t, const RooFormulaVar& select, const char* wgtVarName=0) ;
45  RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, TTree& t, const char* selExpr=0, const char* wgtVarName=0) ;
46 
47  // Ctors from DataStore
48  RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const RooAbsDataStore& tds, const RooFormulaVar& select, const char* wgtVarName=0) ;
49  RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const RooAbsDataStore& tds, const char* selExpr=0, const char* wgtVarName=0) ;
50 
51  RooTreeDataStore(const char *name, const char *title, RooAbsDataStore& tds,
52  const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
53  Int_t nStart, Int_t nStop, Bool_t /*copyCache*/, const char* wgtVarName=0) ;
54 
55  RooTreeDataStore(const RooTreeDataStore& other, const char* newname=0) ;
56  RooTreeDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname=0) ;
57  virtual ~RooTreeDataStore() ;
58 
59 
60  // Write current row
61  virtual Int_t fill() ;
62 
63  // Retrieve a row
64  using RooAbsDataStore::get ;
65  virtual const RooArgSet* get(Int_t index) const ;
66  virtual Double_t weight() const ;
68  virtual void weightError(Double_t& lo, Double_t& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const ;
69  virtual Double_t weight(Int_t index) const ;
70  virtual Bool_t isWeighted() const { return (_wgtVar!=0||_extWgtArray!=0) ; }
71 
72  virtual RooBatchCompute::RunContext getBatches(std::size_t first, std::size_t len) const {
73  //TODO
74  std::cerr << "This functionality is not yet implemented for tree data stores." << std::endl;
75  throw std::logic_error("getBatches() not implemented in RooTreeDataStore.");
76  (void)first; (void)len;
77  return {};
78  }
79  virtual RooSpan<const double> getWeightBatch(std::size_t first, std::size_t len) const;
80 
81  // Change observable name
82  virtual Bool_t changeObservableName(const char* from, const char* to) ;
83 
84  // Add one or more columns
85  virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
86  virtual RooArgSet* addColumns(const RooArgList& varList) ;
87 
88  // Merge column-wise
89  RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) ;
90 
91  // Add rows
92  virtual void append(RooAbsDataStore& other) ;
93 
94  // General & bookkeeping methods
95  virtual Bool_t valid() const ;
96  virtual Double_t sumEntries() const ;
97  virtual Int_t numEntries() const ;
98  virtual void reset() ;
99 
100  // Buffer redirection routines used in inside RooAbsOptTestStatistics
101  virtual void attachBuffers(const RooArgSet& extObs) ;
102  virtual void resetBuffers() ;
103  void restoreAlternateBuffers() ;
104 
105  // Tree access
106  TTree& tree() { return *_tree ; }
107  virtual const TTree* tree() const { return _tree ; }
108 
109  // Forwarded from TTree
110  Stat_t GetEntries() const;
111  void Reset(Option_t* option=0);
112  Int_t Fill();
113  Int_t GetEntry(Int_t entry = 0, Int_t getall = 0);
114 
115  void Draw(Option_t* option = "") ;
116 
117  // Constant term optimizer interface
118  virtual void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=0, Bool_t skipZeroWeights=kFALSE) ;
119  virtual const RooAbsArg* cacheOwner() { return _cacheOwner ; }
120  virtual void setArgStatus(const RooArgSet& set, Bool_t active) ;
121  virtual void resetCache() ;
122 
123  void loadValues(const TTree *t, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000) ;
124  void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=0, const char* rangeName=0,
125  std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max());
126 
127  virtual void checkInit() const;
128 
129  void setExternalWeightArray(const Double_t* arrayWgt, const Double_t* arrayWgtErrLo,
130  const Double_t* arrayWgtErrHi, const Double_t* arraySumW2) {
131  _extWgtArray = arrayWgt ;
132  _extWgtErrLoArray = arrayWgtErrLo ;
133  _extWgtErrHiArray = arrayWgtErrHi ;
134  _extSumW2Array = arraySumW2 ;
135  }
136 
137  const RooArgSet& row() { return _varsww ; }
138 
139  private:
140 
141  friend class RooVectorDataStore ;
142 
143  RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName=0) ;
144  RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName=0) ;
145 
146  void initialize();
147  void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) ;
148 
149  // TTree Branch buffer size control
152 
153  std::string makeTreeName() const;
154 
156 
157  void createTree(const char* name, const char* title) ;
158  TTree *_tree ; // TTree holding the data points
159  TTree *_cacheTree ; //! TTree holding the cached function values
160  const RooAbsArg* _cacheOwner ; //! Object owning cache contents
161  mutable Bool_t _defCtor ;//! Was object constructed with default ctor?
162 
164  RooRealVar* _wgtVar ; // Pointer to weight variable (if set)
165 
166  const Double_t* _extWgtArray{nullptr}; //! External weight array
167  const Double_t* _extWgtErrLoArray{nullptr}; //! External weight array - low error
168  const Double_t* _extWgtErrHiArray{nullptr}; //! External weight array - high error
169  const Double_t* _extSumW2Array{nullptr}; //! External sum of weights array
170  mutable std::unique_ptr<std::vector<double>> _weightBuffer; //! Buffer for weights in case a batch of values is requested.
171 
172  mutable Double_t _curWgt ; // Weight of current event
173  mutable Double_t _curWgtErrLo ; // Weight of current event
174  mutable Double_t _curWgtErrHi ; // Weight of current event
175  mutable Double_t _curWgtErr ; // Weight of current event
176 
177  RooArgSet _attachedBuffers ; //! Currently attached buffers (if different from _varsww)
178 
179  ClassDef(RooTreeDataStore, 2) // TTree-based Data Storage class
180 };
181 
182 
183 #endif
RooTreeDataStore::resetCache
virtual void resetCache()
Remove tree with values of cached observables and clear list of cached observables.
Definition: RooTreeDataStore.cxx:1217
RooTreeDataStore::setExternalWeightArray
void setExternalWeightArray(const Double_t *arrayWgt, const Double_t *arrayWgtErrLo, const Double_t *arrayWgtErrHi, const Double_t *arraySumW2)
Definition: RooTreeDataStore.h:129
first
Definition: first.py:1
RooAbsDataStore::cachedVars
const RooArgSet & cachedVars() const
Definition: RooAbsDataStore.h:109
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
RooAbsDataStore::get
virtual const RooArgSet * get() const
Definition: RooAbsDataStore.h:50
RooTreeDataStore::GetEntry
Int_t GetEntry(Int_t entry=0, Int_t getall=0)
Interface function to TTree::GetEntry.
Definition: RooTreeDataStore.cxx:1325
Option_t
const char Option_t
Definition: RtypesCore.h:66
RooTreeDataStore::tree
TTree & tree()
Definition: RooTreeDataStore.h:106
RooTreeDataStore::cacheArgs
virtual void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=0, Bool_t skipZeroWeights=kFALSE)
Cache given RooAbsArgs with this tree: The tree is given direct write access of the args internal cac...
Definition: RooTreeDataStore.cxx:1140
RooTreeDataStore::RooTreeDataStore
RooTreeDataStore()
Definition: RooTreeDataStore.cxx:74
RooTreeDataStore::Reset
void Reset(Option_t *option=0)
Interface function to TTree::Reset.
Definition: RooTreeDataStore.cxx:1307
RooTreeDataStore::_extWgtErrHiArray
const Double_t * _extWgtErrHiArray
External weight array - low error.
Definition: RooTreeDataStore.h:168
RooTreeDataStore::reset
virtual void reset()
Definition: RooTreeDataStore.cxx:1125
RooTreeDataStore::addColumn
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a new column to the data set which holds the pre-calculated values of 'newVar'.
Definition: RooTreeDataStore.cxx:887
RooTreeDataStore::clone
virtual RooAbsDataStore * clone(const char *newname=0) const
Definition: RooTreeDataStore.h:40
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
TTree
A TTree represents a columnar dataset.
Definition: TTree.h:79
RooTreeDataStore::addColumns
virtual RooArgSet * addColumns(const RooArgList &varList)
Utility function to add multiple columns in one call See addColumn() for details.
Definition: RooTreeDataStore.cxx:947
RooTreeDataStore::_defCtor
Bool_t _defCtor
Object owning cache contents.
Definition: RooTreeDataStore.h:161
RooTreeDataStore::cacheOwner
virtual const RooAbsArg * cacheOwner()
Definition: RooTreeDataStore.h:119
RooTreeDataStore::setBranchBufferSize
void setBranchBufferSize(Int_t size)
Definition: RooTreeDataStore.h:150
RooTreeDataStore::valid
virtual Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
Definition: RooTreeDataStore.cxx:623
RooTreeDataStore::_defTreeBufSize
static Int_t _defTreeBufSize
Definition: RooTreeDataStore.h:155
RooAbsData::ErrorType
ErrorType
Definition: RooAbsData.h:99
bool
RooTreeDataStore::_extWgtErrLoArray
const Double_t * _extWgtErrLoArray
External weight array.
Definition: RooTreeDataStore.h:167
RooTreeDataStore::append
virtual void append(RooAbsDataStore &other)
Definition: RooTreeDataStore.cxx:1059
RooTreeDataStore::GetEntries
Stat_t GetEntries() const
Interface function to TTree::GetEntries.
Definition: RooTreeDataStore.cxx:1298
hi
float type_of_call hi(const int &, const int &)
RooTreeDataStore::restoreAlternateBuffers
void restoreAlternateBuffers()
Definition: RooTreeDataStore.cxx:1270
RooTreeDataStore::checkInit
virtual void checkInit() const
Definition: RooTreeDataStore.cxx:1283
RooTreeDataStore::tree
virtual const TTree * tree() const
Definition: RooTreeDataStore.h:107
RooTreeDataStore::_tree
TTree * _tree
Definition: RooTreeDataStore.h:158
RooTreeDataStore::isWeighted
virtual Bool_t isWeighted() const
Definition: RooTreeDataStore.h:70
RooFormulaVar
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
size
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
RooTreeDataStore::_extWgtArray
const Double_t * _extWgtArray
Definition: RooTreeDataStore.h:166
RooTreeDataStore::Fill
Int_t Fill()
Interface function to TTree::Fill.
Definition: RooTreeDataStore.cxx:1316
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
RooTreeDataStore::weight
virtual Double_t weight() const
Return the weight of the n-th data point (n='index') in memory.
Definition: RooTreeDataStore.cxx:712
RooTreeDataStore::_extSumW2Array
const Double_t * _extSumW2Array
External weight array - high error.
Definition: RooTreeDataStore.h:169
RooTreeDataStore::get
virtual const RooArgSet * get(Int_t index) const=0
RooTreeDataStore::fill
virtual Int_t fill()
Interface function to TTree::Fill.
Definition: RooTreeDataStore.cxx:634
RooTreeDataStore::makeTreeName
std::string makeTreeName() const
Generate a name for the storage tree from the name and title of this instance.
Definition: RooTreeDataStore.cxx:1387
RooTreeDataStore::setArgStatus
virtual void setArgStatus(const RooArgSet &set, Bool_t active)
Activate or deactivate the branch status of the TTree branch associated with the given set of dataset...
Definition: RooTreeDataStore.cxx:1195
RooTreeDataStore::getWeightBatch
virtual RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len) const
Get the weights of the events in the range [first, first+len).
Definition: RooTreeDataStore.cxx:1399
RooTreeDataStore::weightError
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const
Definition: RooTreeDataStore.cxx:720
RooTreeDataStore::Draw
void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: RooTreeDataStore.cxx:1336
void
typedef void((*Func_t)())
RooTreeDataStore::numEntries
virtual Int_t numEntries() const
Definition: RooTreeDataStore.cxx:1116
RooTreeDataStore
RooTreeDataStore is a TTree-backed data storage.
Definition: RooTreeDataStore.h:32
RooAbsDataStore.h
RooAbsData::Poisson
@ Poisson
Definition: RooAbsData.h:99
RooTreeDataStore::_curWgtErrLo
Double_t _curWgtErrLo
Definition: RooTreeDataStore.h:173
RooTreeDataStore::weightVar
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return pointer to weight variable if it is defined.
Definition: RooTreeDataStore.cxx:292
RooTreeDataStore::createTree
void createTree(const char *name, const char *title)
Create TTree object that lives in memory, independent of current location of gDirectory.
Definition: RooTreeDataStore.cxx:414
RooTreeDataStore::_cacheOwner
const RooAbsArg * _cacheOwner
TTree holding the cached function values.
Definition: RooTreeDataStore.h:160
RooTreeDataStore::~RooTreeDataStore
virtual ~RooTreeDataStore()
Destructor.
Definition: RooTreeDataStore.cxx:379
RooTreeDataStore::merge
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList)
Merge columns of supplied data set(s) with this data set.
Definition: RooTreeDataStore.cxx:1032
RooTreeDataStore::row
const RooArgSet & row()
Definition: RooTreeDataStore.h:137
RooTreeDataStore::sumEntries
virtual Double_t sumEntries() const
Definition: RooTreeDataStore.cxx:1075
RooTreeDataStore::varsNoWeight
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
Definition: RooTreeDataStore.cxx:274
RooTreeDataStore::_curWgt
Double_t _curWgt
Buffer for weights in case a batch of values is requested.
Definition: RooTreeDataStore.h:172
Double_t
double Double_t
Definition: RtypesCore.h:59
RooTreeDataStore::_cacheTree
TTree * _cacheTree
Definition: RooTreeDataStore.h:159
RooVectorDataStore
RooVectorDataStore uses std::vectors to store data columns.
Definition: RooVectorDataStore.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
RooTreeDataStore::initialize
void initialize()
One-time initialization common to all constructor forms.
Definition: RooTreeDataStore.cxx:395
name
char name[80]
Definition: TGX11.cxx:110
RooTreeDataStore::_weightBuffer
std::unique_ptr< std::vector< double > > _weightBuffer
External sum of weights array.
Definition: RooTreeDataStore.h:170
RooTreeDataStore::attachCache
void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
Definition: RooTreeDataStore.cxx:308
RunContext.h
RooTreeDataStore::_curWgtErrHi
Double_t _curWgtErrHi
Definition: RooTreeDataStore.h:174
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooTreeDataStore::loadValues
void loadValues(const TTree *t, const RooFormulaVar *select=0, const char *rangeName=0, Int_t nStart=0, Int_t nStop=2000000000)
Load values from tree 't' into this data collection, optionally selecting events using the RooFormula...
Definition: RooTreeDataStore.cxx:455
RooTreeDataStore::getBatches
virtual RooBatchCompute::RunContext getBatches(std::size_t first, std::size_t len) const
Retrieve batches for all observables in this data store.
Definition: RooTreeDataStore.h:72
RooTreeDataStore::_curWgtErr
Double_t _curWgtErr
Definition: RooTreeDataStore.h:175
RooTreeDataStore::resetBuffers
virtual void resetBuffers()
Definition: RooTreeDataStore.cxx:1257
RooAbsDataStore
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
Definition: RooAbsDataStore.h:34
Stat_t
double Stat_t
Definition: RtypesCore.h:86
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
RooTreeDataStore::_attachedBuffers
RooArgSet _attachedBuffers
Definition: RooTreeDataStore.h:177
RooTreeDataStore::attachBuffers
virtual void attachBuffers(const RooArgSet &extObs)
Definition: RooTreeDataStore.cxx:1235
RooTreeDataStore::_wgtVar
RooRealVar * _wgtVar
Definition: RooTreeDataStore.h:164
RooTreeDataStore::clone
virtual RooAbsDataStore * clone(const RooArgSet &vars, const char *newname=0) const
Definition: RooTreeDataStore.h:41
RooTreeDataStore::getBranchBufferSize
Int_t getBranchBufferSize() const
Definition: RooTreeDataStore.h:151
RooTreeDataStore::_varsww
RooArgSet _varsww
Was object constructed with default ctor?
Definition: RooTreeDataStore.h:163
RooBatchCompute::RunContext
This struct enables passing computation data around between elements of a computation graph.
Definition: RunContext.h:31
RooSpan
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
int
RooTreeDataStore::changeObservableName
virtual Bool_t changeObservableName(const char *from, const char *to)
Change name of internal observable named 'from' into 'to'.
Definition: RooTreeDataStore.cxx:817