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 <vector>
21 #include <list>
22 #include <string>
23 
24 class RooAbsArg ;
25 class RooArgList ;
26 class TTree ;
27 class RooFormulaVar ;
28 class RooArgSet ;
29 
30 
32 public:
33 
34  RooTreeDataStore() ;
35  RooTreeDataStore(TTree* t, const RooArgSet& vars, const char* wgtVarName=0) ;
36 
37  // Empty ctor
38  RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const char* wgtVarName=0) ;
39  virtual RooAbsDataStore* clone(const char* newname=0) const { return new RooTreeDataStore(*this,newname) ; }
40  virtual RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=0) const { return new RooTreeDataStore(*this,vars,newname) ; }
41 
42  // Ctors from TTree
43  RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, TTree& t, const RooFormulaVar& select, const char* wgtVarName=0) ;
44  RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, TTree& t, const char* selExpr=0, const char* wgtVarName=0) ;
45 
46  // Ctors from DataStore
47  RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const RooAbsDataStore& tds, const RooFormulaVar& select, const char* wgtVarName=0) ;
48  RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const RooAbsDataStore& tds, const char* selExpr=0, const char* wgtVarName=0) ;
49 
50  RooTreeDataStore(const char *name, const char *title, RooAbsDataStore& tds,
51  const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
52  Int_t nStart, Int_t nStop, Bool_t /*copyCache*/, const char* wgtVarName=0) ;
53 
54  RooTreeDataStore(const RooTreeDataStore& other, const char* newname=0) ;
55  RooTreeDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname=0) ;
56  virtual ~RooTreeDataStore() ;
57 
58 
59  // Write current row
60  virtual Int_t fill() ;
61 
62  // Retrieve a row
63  using RooAbsDataStore::get ;
64  virtual const RooArgSet* get(Int_t index) const ;
65  virtual Double_t weight() const ;
67  virtual void weightError(Double_t& lo, Double_t& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const ;
68  virtual Double_t weight(Int_t index) const ;
69  virtual Bool_t isWeighted() const { return (_wgtVar!=0||_extWgtArray!=0) ; }
70 
71  virtual BatchHelpers::RunContext getBatches(std::size_t first, std::size_t len) const {
72  //TODO
73  std::cerr << "This functionality is not yet implemented for tree data stores." << std::endl;
74  throw std::logic_error("getBatches() not implemented in RooTreeDataStore.");
75  (void)first; (void)len;
76  return {};
77  }
78  virtual RooSpan<const double> getWeightBatch(std::size_t first, std::size_t len) const;
79 
80  // Change observable name
81  virtual Bool_t changeObservableName(const char* from, const char* to) ;
82 
83  // Add one or more columns
84  virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
85  virtual RooArgSet* addColumns(const RooArgList& varList) ;
86 
87  // Merge column-wise
88  RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) ;
89 
90  // Add rows
91  virtual void append(RooAbsDataStore& other) ;
92 
93  // General & bookkeeping methods
94  virtual Bool_t valid() const ;
95  virtual Double_t sumEntries() const ;
96  virtual Int_t numEntries() const ;
97  virtual void reset() ;
98 
99  // Buffer redirection routines used in inside RooAbsOptTestStatistics
100  virtual void attachBuffers(const RooArgSet& extObs) ;
101  virtual void resetBuffers() ;
102  void restoreAlternateBuffers() ;
103 
104  // Tree access
105  TTree& tree() { return *_tree ; }
106  virtual const TTree* tree() const { return _tree ; }
107 
108  // Forwarded from TTree
109  Stat_t GetEntries() const;
110  void Reset(Option_t* option=0);
111  Int_t Fill();
112  Int_t GetEntry(Int_t entry = 0, Int_t getall = 0);
113 
114  void Draw(Option_t* option = "") ;
115 
116  // Constant term optimizer interface
117  virtual void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=0, Bool_t skipZeroWeights=kFALSE) ;
118  virtual const RooAbsArg* cacheOwner() { return _cacheOwner ; }
119  virtual void setArgStatus(const RooArgSet& set, Bool_t active) ;
120  virtual void resetCache() ;
121 
122  void loadValues(const TTree *t, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000) ;
123  void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=0, const char* rangeName=0,
124  std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max());
125 
126  virtual void checkInit() const;
127 
128  void setExternalWeightArray(const Double_t* arrayWgt, const Double_t* arrayWgtErrLo,
129  const Double_t* arrayWgtErrHi, const Double_t* arraySumW2) {
130  _extWgtArray = arrayWgt ;
131  _extWgtErrLoArray = arrayWgtErrLo ;
132  _extWgtErrHiArray = arrayWgtErrHi ;
133  _extSumW2Array = arraySumW2 ;
134  }
135 
136  const RooArgSet& row() { return _varsww ; }
137 
138  private:
139 
140  friend class RooVectorDataStore ;
141 
142  RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName=0) ;
143  RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName=0) ;
144 
145  void initialize();
146  void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) ;
147 
148  // TTree Branch buffer size control
151 
152  std::string makeTreeName() const;
153 
155 
156  void createTree(const char* name, const char* title) ;
157  TTree *_tree ; // TTree holding the data points
158  TTree *_cacheTree ; //! TTree holding the cached function values
159  const RooAbsArg* _cacheOwner ; //! Object owning cache contents
160  mutable Bool_t _defCtor ;//! Was object constructed with default ctor?
161 
163  RooRealVar* _wgtVar ; // Pointer to weight variable (if set)
164 
165  const Double_t* _extWgtArray{nullptr}; //! External weight array
166  const Double_t* _extWgtErrLoArray{nullptr}; //! External weight array - low error
167  const Double_t* _extWgtErrHiArray{nullptr}; //! External weight array - high error
168  const Double_t* _extSumW2Array{nullptr}; //! External sum of weights array
169  mutable std::unique_ptr<std::vector<double>> _weightBuffer; //! Buffer for weights in case a batch of values is requested.
170 
171  mutable Double_t _curWgt ; // Weight of current event
172  mutable Double_t _curWgtErrLo ; // Weight of current event
173  mutable Double_t _curWgtErrHi ; // Weight of current event
174  mutable Double_t _curWgtErr ; // Weight of current event
175 
176  RooArgSet _attachedBuffers ; //! Currently attached buffers (if different from _varsww)
177 
178  ClassDef(RooTreeDataStore, 2) // TTree-based Data Storage class
179 };
180 
181 
182 #endif
RooTreeDataStore::resetCache
virtual void resetCache()
Remove tree with values of cached observables and clear list of cached observables.
Definition: RooTreeDataStore.cxx:1210
RooTreeDataStore::setExternalWeightArray
void setExternalWeightArray(const Double_t *arrayWgt, const Double_t *arrayWgtErrLo, const Double_t *arrayWgtErrHi, const Double_t *arraySumW2)
Definition: RooTreeDataStore.h:128
first
Definition: first.py:1
RooAbsDataStore::cachedVars
const RooArgSet & cachedVars() const
Definition: RooAbsDataStore.h:109
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
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:1318
Option_t
const char Option_t
Definition: RtypesCore.h:66
RooTreeDataStore::tree
TTree & tree()
Definition: RooTreeDataStore.h:105
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:1133
RooTreeDataStore::RooTreeDataStore
RooTreeDataStore()
Definition: RooTreeDataStore.cxx:74
RooTreeDataStore::Reset
void Reset(Option_t *option=0)
Interface function to TTree::Reset.
Definition: RooTreeDataStore.cxx:1300
RooTreeDataStore::_extWgtErrHiArray
const Double_t * _extWgtErrHiArray
External weight array - low error.
Definition: RooTreeDataStore.h:167
RooTreeDataStore::reset
virtual void reset()
Definition: RooTreeDataStore.cxx:1118
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:880
RooTreeDataStore::clone
virtual RooAbsDataStore * clone(const char *newname=0) const
Definition: RooTreeDataStore.h:39
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:940
RooTreeDataStore::_defCtor
Bool_t _defCtor
Object owning cache contents.
Definition: RooTreeDataStore.h:160
RooTreeDataStore::cacheOwner
virtual const RooAbsArg * cacheOwner()
Definition: RooTreeDataStore.h:118
RooTreeDataStore::setBranchBufferSize
void setBranchBufferSize(Int_t size)
Definition: RooTreeDataStore.h:149
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:616
RooVectorDataStore::size
std::size_t size() const
Get size of stored dataset.
Definition: RooVectorDataStore.h:101
RooTreeDataStore::_defTreeBufSize
static Int_t _defTreeBufSize
Definition: RooTreeDataStore.h:154
RooAbsData::ErrorType
ErrorType
Definition: RooAbsData.h:97
bool
BatchHelpers::RunContext
Data that has to be passed around when evaluating functions / PDFs.
Definition: RunContext.h:32
RooTreeDataStore::_extWgtErrLoArray
const Double_t * _extWgtErrLoArray
External weight array.
Definition: RooTreeDataStore.h:166
RooTreeDataStore::append
virtual void append(RooAbsDataStore &other)
Definition: RooTreeDataStore.cxx:1052
RooTreeDataStore::GetEntries
Stat_t GetEntries() const
Interface function to TTree::GetEntries.
Definition: RooTreeDataStore.cxx:1291
hi
float type_of_call hi(const int &, const int &)
RooTreeDataStore::restoreAlternateBuffers
void restoreAlternateBuffers()
Definition: RooTreeDataStore.cxx:1263
RooTreeDataStore::checkInit
virtual void checkInit() const
Definition: RooTreeDataStore.cxx:1276
RooTreeDataStore::tree
virtual const TTree * tree() const
Definition: RooTreeDataStore.h:106
RooTreeDataStore::_tree
TTree * _tree
Definition: RooTreeDataStore.h:157
RooTreeDataStore::isWeighted
virtual Bool_t isWeighted() const
Definition: RooTreeDataStore.h:69
RooFormulaVar
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooTreeDataStore::_extWgtArray
const Double_t * _extWgtArray
Definition: RooTreeDataStore.h:165
RooTreeDataStore::Fill
Int_t Fill()
Interface function to TTree::Fill.
Definition: RooTreeDataStore.cxx:1309
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooTreeDataStore::weight
virtual Double_t weight() const
Return the weight of the n-th data point (n='index') in memory.
Definition: RooTreeDataStore.cxx:705
RooTreeDataStore::_extSumW2Array
const Double_t * _extSumW2Array
External weight array - high error.
Definition: RooTreeDataStore.h:168
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:627
RooTreeDataStore::makeTreeName
std::string makeTreeName() const
Generate a name for the storage tree from the name and title of this instance.
Definition: RooTreeDataStore.cxx:1380
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:1188
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:1392
RooTreeDataStore::weightError
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const
Definition: RooTreeDataStore.cxx:713
RooTreeDataStore::Draw
void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: RooTreeDataStore.cxx:1329
void
typedef void((*Func_t)())
RooTreeDataStore::numEntries
virtual Int_t numEntries() const
Definition: RooTreeDataStore.cxx:1109
RooTreeDataStore
RooTreeDataStore is a TTree-backed data storage.
Definition: RooTreeDataStore.h:31
RooAbsDataStore.h
RooAbsData::Poisson
@ Poisson
Definition: RooAbsData.h:97
RooTreeDataStore::_curWgtErrLo
Double_t _curWgtErrLo
Definition: RooTreeDataStore.h:172
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:159
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:1025
RooTreeDataStore::row
const RooArgSet & row()
Definition: RooTreeDataStore.h:136
RooTreeDataStore::sumEntries
virtual Double_t sumEntries() const
Definition: RooTreeDataStore.cxx:1068
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:171
Double_t
double Double_t
Definition: RtypesCore.h:59
RooTreeDataStore::_cacheTree
TTree * _cacheTree
Definition: RooTreeDataStore.h:158
RooVectorDataStore
RooVectorDataStore uses std::vectors to store data columns.
Definition: RooVectorDataStore.h:36
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:169
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
RooTreeDataStore::_curWgtErrHi
Double_t _curWgtErrHi
Definition: RooTreeDataStore.h:173
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 BatchHelpers::RunContext getBatches(std::size_t first, std::size_t len) const
Retrieve batches for all observables in this data store.
Definition: RooTreeDataStore.h:71
RooTreeDataStore::_curWgtErr
Double_t _curWgtErr
Definition: RooTreeDataStore.h:174
RooTreeDataStore::resetBuffers
virtual void resetBuffers()
Definition: RooTreeDataStore.cxx:1250
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:77
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooTreeDataStore::_attachedBuffers
RooArgSet _attachedBuffers
Definition: RooTreeDataStore.h:176
RooTreeDataStore::attachBuffers
virtual void attachBuffers(const RooArgSet &extObs)
Definition: RooTreeDataStore.cxx:1228
RooTreeDataStore::_wgtVar
RooRealVar * _wgtVar
Definition: RooTreeDataStore.h:163
RooTreeDataStore::clone
virtual RooAbsDataStore * clone(const RooArgSet &vars, const char *newname=0) const
Definition: RooTreeDataStore.h:40
RooTreeDataStore::getBranchBufferSize
Int_t getBranchBufferSize() const
Definition: RooTreeDataStore.h:150
RooTreeDataStore::_varsww
RooArgSet _varsww
Was object constructed with default ctor?
Definition: RooTreeDataStore.h:162
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:810