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#include "RunContext.h"
21
22#include "ROOT/RStringView.hxx"
23
24#include <vector>
25#include <list>
26#include <string>
27
28class RooAbsArg ;
29class RooArgList ;
30class TTree ;
31class RooFormulaVar ;
32class RooArgSet ;
33
34
36public:
37
39 RooTreeDataStore(TTree* t, const RooArgSet& vars, const char* wgtVarName=0) ;
40
42
43 // Empty ctor
44 RooTreeDataStore(std::string_view name, std::string_view title, const RooArgSet& vars, const char* wgtVarName=0) ;
45 virtual RooAbsDataStore* clone(const char* newname=0) const { return new RooTreeDataStore(*this,newname) ; }
46 virtual RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=0) const { return new RooTreeDataStore(*this,vars,newname) ; }
47
48 // Ctors from TTree
49 RooTreeDataStore(std::string_view name, std::string_view title, const RooArgSet& vars, TTree& t, const RooFormulaVar& select, const char* wgtVarName=0) ;
50 RooTreeDataStore(std::string_view name, std::string_view title, const RooArgSet& vars, TTree& t, const char* selExpr=0, const char* wgtVarName=0) ;
51
52 // Ctors from DataStore
53 RooTreeDataStore(std::string_view name, std::string_view title, const RooArgSet& vars, const RooAbsDataStore& tds, const RooFormulaVar& select, const char* wgtVarName=0) ;
54 RooTreeDataStore(std::string_view name, std::string_view title, const RooArgSet& vars, const RooAbsDataStore& tds, const char* selExpr=0, const char* wgtVarName=0) ;
55
56 RooTreeDataStore(std::string_view name, std::string_view title, RooAbsDataStore& tds,
57 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
58 Int_t nStart, Int_t nStop, Bool_t /*copyCache*/, const char* wgtVarName=0) ;
59
60 RooTreeDataStore(const RooTreeDataStore& other, const char* newname=0) ;
61 RooTreeDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname=0) ;
62 virtual ~RooTreeDataStore() ;
63
64
65 // Write current row
66 virtual Int_t fill() ;
67
68 // Retrieve a row
70 virtual const RooArgSet* get(Int_t index) const ;
72 virtual Double_t weight() const ;
75 virtual Bool_t isWeighted() const { return (_wgtVar!=0||_extWgtArray!=0) ; }
76
77 RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const {
78 //TODO
79 std::cerr << "This functionality is not yet implemented for tree data stores." << std::endl;
80 throw std::logic_error("getBatches() not implemented in RooTreeDataStore.");
81 (void)first; (void)len;
82 return {};
83 }
84 virtual RooSpan<const double> getWeightBatch(std::size_t first, std::size_t len) const;
85
86 // Change observable name
87 virtual Bool_t changeObservableName(const char* from, const char* to) ;
88
89 // Add one or more columns
90 virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
91 virtual RooArgSet* addColumns(const RooArgList& varList) ;
92
93 // Merge column-wise
94 RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) ;
95
96 // Add rows
97 virtual void append(RooAbsDataStore& other) ;
98
99 // General & bookkeeping methods
100 virtual Double_t sumEntries() const ;
101 virtual Int_t numEntries() const ;
102 virtual void reset() ;
103
104 // Buffer redirection routines used in inside RooAbsOptTestStatistics
105 virtual void attachBuffers(const RooArgSet& extObs) ;
106 virtual void resetBuffers() ;
108
109 // Tree access
110 TTree& tree() { return *_tree ; }
111 virtual const TTree* tree() const { return _tree ; }
112
113 // Forwarded from TTree
114 Stat_t GetEntries() const;
115 void Reset(Option_t* option=0);
116 Int_t Fill();
117 Int_t GetEntry(Int_t entry = 0, Int_t getall = 0);
118
119 void Draw(Option_t* option = "") ;
120
121 // Constant term optimizer interface
122 virtual void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=0, Bool_t skipZeroWeights=kFALSE) ;
123 virtual const RooAbsArg* cacheOwner() { return _cacheOwner ; }
124 virtual void setArgStatus(const RooArgSet& set, Bool_t active) ;
125 virtual void resetCache() ;
126
127 void loadValues(const TTree *t, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000) ;
128 void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=0, const char* rangeName=0,
129 std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max());
130
131 virtual void checkInit() const;
132
133 void setExternalWeightArray(const Double_t* arrayWgt, const Double_t* arrayWgtErrLo,
134 const Double_t* arrayWgtErrHi, const Double_t* arraySumW2) {
135 _extWgtArray = arrayWgt ;
136 _extWgtErrLoArray = arrayWgtErrLo ;
137 _extWgtErrHiArray = arrayWgtErrHi ;
138 _extSumW2Array = arraySumW2 ;
139 }
140
141 const RooArgSet& row() { return _varsww ; }
142
143 private:
144
145 friend class RooVectorDataStore ;
146
147 RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName=0) ;
148 RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName=0) ;
149
150 void initialize();
151 void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) ;
152
153 // TTree Branch buffer size control
156
157 std::string makeTreeName() const;
158
160
161 void createTree(std::string_view name, std::string_view title) ;
162 TTree *_tree ; // TTree holding the data points
163 TTree *_cacheTree ; //! TTree holding the cached function values
164 const RooAbsArg* _cacheOwner ; //! Object owning cache contents
165 mutable Bool_t _defCtor ;//! Was object constructed with default ctor?
166
168 RooRealVar* _wgtVar ; // Pointer to weight variable (if set)
169
170 const Double_t* _extWgtArray{nullptr}; //! External weight array
171 const Double_t* _extWgtErrLoArray{nullptr}; //! External weight array - low error
172 const Double_t* _extWgtErrHiArray{nullptr}; //! External weight array - high error
173 const Double_t* _extSumW2Array{nullptr}; //! External sum of weights array
174 mutable std::unique_ptr<std::vector<double>> _weightBuffer; //! Buffer for weights in case a batch of values is requested.
175
176 mutable Double_t _curWgt ; // Weight of current event
177 mutable Double_t _curWgtErrLo ; // Weight of current event
178 mutable Double_t _curWgtErrHi ; // Weight of current event
179 mutable Double_t _curWgtErr ; // Weight of current event
180
181 RooArgSet _attachedBuffers ; //! Currently attached buffers (if different from _varsww)
182
183 ClassDef(RooTreeDataStore, 2) // TTree-based Data Storage class
184};
185
186
187#endif
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
#define WRITE_TSTRING_COMPATIBLE_CONSTRUCTOR(Class_t)
Definition RooAbsData.h:69
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
const Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
double Stat_t
Definition RtypesCore.h:86
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
char name[80]
Definition TGX11.cxx:110
#define hi
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:69
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
const RooArgSet & cachedVars() const
virtual Double_t weight() const =0
virtual const RooArgSet * get() const
std::map< RooFit::Detail::DataKey, RooSpan< const double > > RealSpans
Definition RooAbsData.h:159
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:35
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:39
A simple container to hold a batch of data values.
Definition RooSpan.h:34
RooTreeDataStore is a TTree-backed data storage.
const Double_t * _extSumW2Array
External weight array - high error.
const Double_t * _extWgtArray
virtual Double_t weight() const
Return the weight of the n-th data point (n='index') in memory.
void initialize()
One-time initialization common to all constructor forms.
virtual void append(RooAbsDataStore &other)
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
virtual Bool_t changeObservableName(const char *from, const char *to)
Change name of internal observable named 'from' into 'to'.
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...
virtual void attachBuffers(const RooArgSet &extObs)
std::string makeTreeName() const
Generate a name for the storage tree from the name and title of this instance.
virtual const TTree * tree() const
RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const
Retrieve batches for all observables in this data store.
virtual Bool_t isWeighted() const
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return pointer to weight variable if it is defined.
void setBranchBufferSize(Int_t size)
const Double_t * _extWgtErrLoArray
External weight array.
virtual Int_t fill()
Interface function to TTree::Fill.
Stat_t GetEntries() const
Interface function to TTree::GetEntries.
virtual RooAbsDataStore * clone(const RooArgSet &vars, const char *newname=0) const
Int_t GetEntry(Int_t entry=0, Int_t getall=0)
Interface function to TTree::GetEntry.
Double_t _curWgt
Buffer for weights in case a batch of values is requested.
void setExternalWeightArray(const Double_t *arrayWgt, const Double_t *arrayWgtErrLo, const Double_t *arrayWgtErrHi, const Double_t *arraySumW2)
virtual void checkInit() const
static Int_t _defTreeBufSize
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...
const Double_t * _extWgtErrHiArray
External weight array - low error.
void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
virtual void resetCache()
Remove tree with values of cached observables and clear list of cached observables.
Bool_t _defCtor
Object owning cache contents.
virtual RooAbsDataStore * clone(const char *newname=0) const
Int_t getBranchBufferSize() const
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList)
Merge columns of supplied data set(s) with this data set.
void createTree(std::string_view name, std::string_view title)
Create TTree object that lives in memory, independent of current location of gDirectory.
virtual const RooAbsArg * cacheOwner()
virtual void resetBuffers()
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'.
virtual RooArgSet * addColumns(const RooArgList &varList)
Utility function to add multiple columns in one call See addColumn() for details.
std::unique_ptr< std::vector< double > > _weightBuffer
External sum of weights array.
Int_t Fill()
Interface function to TTree::Fill.
virtual ~RooTreeDataStore()
Destructor.
void Reset(Option_t *option=0)
Interface function to TTree::Reset.
virtual Double_t sumEntries() const
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).
virtual const RooArgSet * get() const
const RooAbsArg * _cacheOwner
TTree holding the cached function values.
RooArgSet _varsww
Was object constructed with default ctor?
virtual Int_t numEntries() const
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...
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()