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
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
41 // Empty ctor
42 RooTreeDataStore(RooStringView name, RooStringView title, const RooArgSet& vars, const char* wgtVarName=0) ;
43 RooAbsDataStore* clone(const char* newname=0) const override { return new RooTreeDataStore(*this,newname) ; }
44 RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=0) const override { return new RooTreeDataStore(*this,vars,newname) ; }
45
47 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
48 std::size_t nStart, std::size_t nStop) override;
49
50 // Constructor from TTree
51 RooTreeDataStore(RooStringView name, RooStringView title, const RooArgSet& vars, TTree& t, const char* selExpr=0, const char* wgtVarName=0) ;
52
53 // Constructor from DataStore
54 RooTreeDataStore(RooStringView name, RooStringView title, const RooArgSet& vars, const RooAbsDataStore& tds, const char* selExpr=0, const char* wgtVarName=0) ;
55
57 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
58 Int_t nStart, Int_t nStop, 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 ~RooTreeDataStore() override ;
63
64
65 // Write current row
66 Int_t fill() override ;
67
68 // Retrieve a row
70 const RooArgSet* get(Int_t index) const override ;
72 double weight() const override ;
73 double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override ;
74 void weightError(double& lo, double& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const override ;
75 bool isWeighted() const override { return (_wgtVar!=0||_extWgtArray!=0) ; }
76
77 RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const override {
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 RooSpan<const double> getWeightBatch(std::size_t first, std::size_t len) const override;
85
86 // Change observable name
87 bool changeObservableName(const char* from, const char* to) override ;
88
89 // Add one column
90 RooAbsArg* addColumn(RooAbsArg& var, bool adjustRange=true) override ;
91
92 // Merge column-wise
93 RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) override ;
94
95 // Add rows
96 void append(RooAbsDataStore& other) override ;
97
98 // General & bookkeeping methods
99 double sumEntries() const override ;
100 Int_t numEntries() const override ;
101 void reset() override ;
102
103 // Buffer redirection routines used in inside RooAbsOptTestStatistics
104 void attachBuffers(const RooArgSet& extObs) override ;
105 void resetBuffers() override ;
107
108 // Tree access
109 TTree& tree() { return *_tree ; }
110 const TTree* tree() const override { return _tree ; }
111
112 // Forwarded from TTree
113 Stat_t GetEntries() const;
114 void Reset(Option_t* option=0);
115 Int_t Fill();
116 Int_t GetEntry(Int_t entry = 0, Int_t getall = 0);
117
118 void Draw(Option_t* option = "") override ;
119
120 // Constant term optimizer interface
121 void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=0, bool skipZeroWeights=false) override ;
122 const RooAbsArg* cacheOwner() override { return _cacheOwner ; }
123 void setArgStatus(const RooArgSet& set, bool active) override ;
124 void resetCache() override ;
125
126 void loadValues(const TTree *t, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000) ;
127 void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=0, const char* rangeName=0,
128 std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max()) override;
129
130 void checkInit() const override;
131
132 void setExternalWeightArray(const double* arrayWgt, const double* arrayWgtErrLo,
133 const double* arrayWgtErrHi, const double* arraySumW2) override {
134 _extWgtArray = arrayWgt ;
135 _extWgtErrLoArray = arrayWgtErrLo ;
136 _extWgtErrHiArray = arrayWgtErrHi ;
137 _extSumW2Array = arraySumW2 ;
138 }
139
140 const RooArgSet& row() { return _varsww ; }
141
142 private:
143
144 friend class RooVectorDataStore ;
145
146 RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName=0) ;
147 RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName=0) ;
148
149 void initialize();
150 void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) override ;
151
152 // TTree Branch buffer size control
155
156 std::string makeTreeName() const;
157
159
161 TTree *_tree = nullptr; // TTree holding the data points
162 TTree *_cacheTree = nullptr; //! TTree holding the cached function values
163 const RooAbsArg* _cacheOwner = nullptr; //! Object owning cache contents
164 mutable bool _defCtor = false; //! Was object constructed with default ctor?
165
167 RooRealVar* _wgtVar = nullptr; // Pointer to weight variable (if set)
168
169 const double* _extWgtArray{nullptr}; ///<! External weight array
170 const double* _extWgtErrLoArray{nullptr}; ///<! External weight array - low error
171 const double* _extWgtErrHiArray{nullptr}; ///<! External weight array - high error
172 const double* _extSumW2Array{nullptr}; ///<! External sum of weights array
173 mutable std::unique_ptr<std::vector<double>> _weightBuffer; //! Buffer for weights in case a batch of values is requested.
174
175 mutable double _curWgt = 1.0; ///< Weight of current event
176 mutable double _curWgtErrLo = 0.0; ///< Weight of current event
177 mutable double _curWgtErrHi = 0.0; ///< Weight of current event
178 mutable double _curWgtErr = 0.0; ///< Weight of current event
179
180 RooArgSet _attachedBuffers ; ///<! Currently attached buffers (if different from _varsww)
181
182 ClassDefOverride(RooTreeDataStore, 2) // TTree-based Data Storage class
183};
184
185
186#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:339
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
Definition: THbookFile.cxx:128
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
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, RooSpan< const double > > RealSpans
Definition: RooAbsData.h:136
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:57
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
The RooStringView is a wrapper around a C-syle string that can also be constructed from a std::string...
Definition: RooStringView.h:27
RooTreeDataStore is a TTree-backed data storage.
void initialize()
One-time initialization common to all constructor forms.
void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=0, bool skipZeroWeights=false) override
Cache given RooAbsArgs with this tree: The tree is given direct write access of the args internal cac...
double _curWgtErr
Weight of current event.
double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override
bool isWeighted() const override
void resetBuffers() override
double _curWgt
Buffer for weights in case a batch of values is requested.
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
void Draw(Option_t *option="") override
Default Draw method for all objects.
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.
~RooTreeDataStore() override
Destructor.
void createTree(RooStringView name, RooStringView title)
Create TTree object that lives in memory, independent of current location of gDirectory.
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return pointer to weight variable if it is defined.
const double * _extWgtErrHiArray
! External weight array - high error
RooAbsDataStore * clone(const char *newname=0) const override
RooAbsDataStore * clone(const RooArgSet &vars, const char *newname=0) const override
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
RooSpan< 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).
RooArgSet _attachedBuffers
! Currently attached buffers (if different from _varsww)
Int_t fill() override
Interface function to TTree::Fill.
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...
double sumEntries() const 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 append(RooAbsDataStore &other) override
const RooAbsArg * cacheOwner() override
Int_t getBranchBufferSize() const
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.
RooAbsDataStore * reduce(RooStringView name, RooStringView title, const RooArgSet &vars, const RooFormulaVar *cutVar, const char *cutRange, std::size_t nStart, std::size_t nStop) override
const double * _extSumW2Array
! External sum of weights array
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'.
RooRealVar * _wgtVar
void Reset(Option_t *option=0)
Interface function to TTree::Reset.
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...
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
void(off) SmallVectorTemplateBase< T
Definition: first.py:1