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 "TString.h"
21
22class RooAbsArg ;
23class RooArgList ;
24class TTree ;
25class RooFormulaVar ;
26class RooArgSet ;
27
28
30public:
31
33 RooTreeDataStore(TTree* t, const RooArgSet& vars, const char* wgtVarName=0) ;
34
35 // Empty ctor
36 RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const char* wgtVarName=0) ;
37 virtual RooAbsDataStore* clone(const char* newname=0) const { return new RooTreeDataStore(*this,newname) ; }
38 virtual RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=0) const { return new RooTreeDataStore(*this,vars,newname) ; }
39
40 // Ctors from TTree
41 RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, TTree& t, const RooFormulaVar& select, const char* wgtVarName=0) ;
42 RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, TTree& t, const char* selExpr=0, const char* wgtVarName=0) ;
43
44 // Ctors from DataStore
45 RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const RooAbsDataStore& tds, const RooFormulaVar& select, const char* wgtVarName=0) ;
46 RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const RooAbsDataStore& tds, const char* selExpr=0, const char* wgtVarName=0) ;
47
48 RooTreeDataStore(const char *name, const char *title, RooAbsDataStore& tds,
49 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
50 Int_t nStart, Int_t nStop, Bool_t /*copyCache*/, const char* wgtVarName=0) ;
51
52 RooTreeDataStore(const RooTreeDataStore& other, const char* newname=0) ;
53 RooTreeDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname=0) ;
54 virtual ~RooTreeDataStore() ;
55
56
57 // Write current row
58 virtual Int_t fill() ;
59
60 // Retrieve a row
62 virtual const RooArgSet* get(Int_t index) const ;
63 virtual Double_t weight() const ;
66 virtual Double_t weight(Int_t index) const ;
67 virtual Bool_t isWeighted() const { return (_wgtVar!=0||_extWgtArray!=0) ; }
68
69 virtual std::vector<RooSpan<const double>> getBatch(std::size_t first, std::size_t last) const {
70 //TODO
71 std::cerr << "This functionality is not yet implemented for tree data stores." << std::endl;
72 assert(false);
73
74 std::vector<double> vec(first, last);
75 return {RooSpan<const double>(vec)};
76 }
77
78 // Change observable name
79 virtual Bool_t changeObservableName(const char* from, const char* to) ;
80
81 // Add one or more columns
82 virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
83 virtual RooArgSet* addColumns(const RooArgList& varList) ;
84
85 // Merge column-wise
86 RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) ;
87
88 // Add rows
89 virtual void append(RooAbsDataStore& other) ;
90
91 // General & bookkeeping methods
92 virtual Bool_t valid() const ;
93 virtual Double_t sumEntries() const ;
94 virtual Int_t numEntries() const ;
95 virtual void reset() ;
96
97 // Buffer redirection routines used in inside RooAbsOptTestStatistics
98 virtual void attachBuffers(const RooArgSet& extObs) ;
99 virtual void resetBuffers() ;
101
102 // Tree access
103 TTree& tree() { return *_tree ; }
104 virtual const TTree* tree() const { return _tree ; }
105
106 // Forwarded from TTree
107 Stat_t GetEntries() const;
108 void Reset(Option_t* option=0);
109 Int_t Fill();
110 Int_t GetEntry(Int_t entry = 0, Int_t getall = 0);
111
112 void Draw(Option_t* option = "") ;
113
114 // Constant term optimizer interface
115 virtual void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=0, Bool_t skipZeroWeights=kFALSE) ;
116 virtual const RooAbsArg* cacheOwner() { return _cacheOwner ; }
117 virtual void setArgStatus(const RooArgSet& set, Bool_t active) ;
118 virtual void resetCache() ;
119
120 void loadValues(const TTree *t, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000) ;
121 void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=0, const char* rangeName=0,
122 std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max());
123
124 virtual void checkInit() const;
125
126 void setExternalWeightArray(const Double_t* arrayWgt, const Double_t* arrayWgtErrLo,
127 const Double_t* arrayWgtErrHi, const Double_t* arraySumW2) {
128 _extWgtArray = arrayWgt ;
129 _extWgtErrLoArray = arrayWgtErrLo ;
130 _extWgtErrHiArray = arrayWgtErrHi ;
131 _extSumW2Array = arraySumW2 ;
132 }
133
134 const RooArgSet& row() { return _varsww ; }
135
136 private:
137
138 friend class RooVectorDataStore ;
139
140 RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName=0) ;
141 RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName=0) ;
142
143 void initialize();
144 void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) ;
145
146 // TTree Branch buffer size control
149
150 std::string makeTreeName() const;
151
153
154 void createTree(const char* name, const char* title) ;
155 TTree *_tree ; // TTree holding the data points
156 TTree *_cacheTree ; //! TTree holding the cached function values
157 const RooAbsArg* _cacheOwner ; //! Object owning cache contents
158 mutable Bool_t _defCtor ;//! Was object constructed with default ctor?
159
161 RooRealVar* _wgtVar ; // Pointer to weight variable (if set)
162
163 const Double_t* _extWgtArray{nullptr}; //! External weight array
164 const Double_t* _extWgtErrLoArray{nullptr}; //! External weight array - low error
165 const Double_t* _extWgtErrHiArray{nullptr}; //! External weight array - high error
166 const Double_t* _extSumW2Array{nullptr}; //! External sum of weights array
167
168 mutable Double_t _curWgt ; // Weight of current event
169 mutable Double_t _curWgtErrLo ; // Weight of current event
170 mutable Double_t _curWgtErrHi ; // Weight of current event
171 mutable Double_t _curWgtErr ; // Weight of current event
172
173 RooArgSet _attachedBuffers ; //! Currently attached buffers (if different from _varsww)
174
175 ClassDef(RooTreeDataStore, 2) // TTree-based Data Storage class
176};
177
178
179#endif
int Int_t
Definition: RtypesCore.h:43
const Bool_t kFALSE
Definition: RtypesCore.h:90
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
double Stat_t
Definition: RtypesCore.h:75
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassDef(name, id)
Definition: Rtypes.h:322
char name[80]
Definition: TGX11.cxx:109
float type_of_call hi(const int &, const int &)
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:73
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
const RooArgSet & cachedVars() const
virtual const RooArgSet * get() const
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:29
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
A simple container to hold a batch of data values.
Definition: RooSpan.h:32
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 Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
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
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.
void createTree(const char *name, const char *title)
Create TTree object that lives in memory, independent of current location of gDirectory.
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
External sum of weights array.
virtual std::vector< RooSpan< const double > > getBatch(std::size_t first, std::size_t last) const
virtual void reset()
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
RooArgSet _attachedBuffers
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.
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.
Int_t Fill()
Interface function to TTree::Fill.
RooRealVar * _wgtVar
virtual ~RooTreeDataStore()
Destructor.
void Reset(Option_t *option=0)
Interface function to TTree::Reset.
virtual Double_t sumEntries() const
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()
void Draw(Option_t *option="")
Default Draw method for all objects.
RooVectorDataStore is the abstract base class for data collection that use a TTree as internal storag...
std::size_t size() const
Get size of stored dataset.
A TTree represents a columnar dataset.
Definition: TTree.h:78
Definition: first.py:1