ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
22 class RooAbsArg ;
23 class RooArgList ;
24 class TTree ;
25 class RooFormulaVar ;
26 class RooArgSet ;
27 
28 
30 public:
31 
32  RooTreeDataStore() ;
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
61  using RooAbsDataStore::get ;
62  virtual const RooArgSet* get(Int_t index) const ;
63  virtual Double_t weight() const ;
65  virtual void weightError(Double_t& lo, Double_t& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const ;
66  virtual Double_t weight(Int_t index) const ;
67  virtual Bool_t isWeighted() const { return (_wgtVar!=0||_extWgtArray!=0) ; }
68 
69  // Change observable name
70  virtual Bool_t changeObservableName(const char* from, const char* to) ;
71 
72  // Add one or more columns
73  virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
74  virtual RooArgSet* addColumns(const RooArgList& varList) ;
75 
76  // Merge column-wise
77  RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) ;
78 
79  // Add rows
80  virtual void append(RooAbsDataStore& other) ;
81 
82  // General & bookkeeping methods
83  virtual Bool_t valid() const ;
84  virtual Double_t sumEntries() const ;
85  virtual Int_t numEntries() const ;
86  virtual void reset() ;
87 
88  // Buffer redirection routines used in inside RooAbsOptTestStatistics
89  virtual void attachBuffers(const RooArgSet& extObs) ;
90  virtual void resetBuffers() ;
92 
93  // Tree access
94  TTree& tree() { return *_tree ; }
95  virtual const TTree* tree() const { return _tree ; }
96 
97  // Forwarded from TTree
98  Stat_t GetEntries() const;
99  void Reset(Option_t* option=0);
100  Int_t Fill();
101  Int_t GetEntry(Int_t entry = 0, Int_t getall = 0);
102 
103  void Draw(Option_t* option = "") ;
104 
105  // Constant term optimizer interface
106  virtual void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=0, Bool_t skipZeroWeights=kFALSE) ;
107  virtual const RooAbsArg* cacheOwner() { return _cacheOwner ; }
108  virtual void setArgStatus(const RooArgSet& set, Bool_t active) ;
109  virtual void resetCache() ;
110 
111  void loadValues(const TTree *t, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000) ;
112  void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000) ;
113 
114  virtual void checkInit() const;
115 
116  void setExternalWeightArray(Double_t* arrayWgt, Double_t* arrayWgtErrLo, Double_t* arrayWgtErrHi, Double_t* arraySumW2) {
117  _extWgtArray = arrayWgt ;
118  _extWgtErrLoArray = arrayWgtErrLo ;
119  _extWgtErrHiArray = arrayWgtErrHi ;
120  _extSumW2Array = arraySumW2 ;
121  }
122 
123  const RooArgSet& row() { return _varsww ; }
124 
125  protected:
126 
127  friend class RooVectorDataStore ;
128 
129  RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName=0) ;
130  RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName=0) ;
131 
132  void initialize();
133  void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) ;
134 
135  // TTree Branch buffer size control
136  void setBranchBufferSize(Int_t size) { _defTreeBufSize = size ; }
138 
140 
141  void createTree(const char* name, const char* title) ;
142  TTree *_tree ; // TTree holding the data points
143  TTree *_cacheTree ; //! TTree holding the cached function values
144  const RooAbsArg* _cacheOwner ; //! Object owning cache contents
145  mutable Bool_t _defCtor ;//! Was object constructed with default ctor?
146 
148  RooRealVar* _wgtVar ; // Pointer to weight variable (if set)
149 
150  Double_t* _extWgtArray ; //! External weight array
151  Double_t* _extWgtErrLoArray ; //! External weight array - low error
152  Double_t* _extWgtErrHiArray ; //! External weight array - high error
153  Double_t* _extSumW2Array ; //! External sum of weights array
154 
155  mutable Double_t _curWgt ; // Weight of current event
156  mutable Double_t _curWgtErrLo ; // Weight of current event
157  mutable Double_t _curWgtErrHi ; // Weight of current event
158  mutable Double_t _curWgtErr ; // Weight of current event
159 
160  RooArgSet _attachedBuffers ; //! Currently attached buffers (if different from _varsww)
161 
162  ClassDef(RooTreeDataStore,2) // TTree-based Data Storage class
163 };
164 
165 
166 #endif
virtual Bool_t changeObservableName(const char *from, const char *to)
Change name of internal observable named 'from' into 'to'.
virtual RooArgSet * addColumns(const RooArgList &varList)
Utility function to add multiple columns in one call See addColumn() for details. ...
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
virtual void attachBuffers(const RooArgSet &extObs)
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 'select' RooFo...
const char Option_t
Definition: RtypesCore.h:62
virtual const RooArgSet * get() const
virtual RooAbsDataStore * clone(const RooArgSet &vars, const char *newname=0) const
void Reset(Option_t *option=0)
Interface function to TTree::Reset.
Bool_t _defCtor
Object owning cache contents.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Int_t GetEntry(Int_t entry=0, Int_t getall=0)
Interface function to TTree::GetEntry.
void setBranchBufferSize(Int_t size)
RooTreeDataStore is the abstract base class for data collection that use a TTree as internal storage ...
virtual RooAbsDataStore * clone(const char *newname=0) const
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'.
#define ClassDef(name, id)
Definition: Rtypes.h:254
Double_t * _extWgtErrLoArray
External weight array.
virtual Double_t sumEntries() const
RooVectorDataStore is the abstract base class for data collection that use a TTree as internal storag...
Double_t * _extWgtArray
virtual Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
Double_t * _extWgtErrHiArray
External weight array - low error.
const RooAbsArg * _cacheOwner
TTree holding the cached function values.
virtual ~RooTreeDataStore()
Destructor.
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) 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 & cachedVars() const
virtual void append(RooAbsDataStore &other)
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
TThread * t[5]
Definition: threadsh1.C:13
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
virtual Int_t fill()
Interface function to TTree::Fill.
static Int_t _defTreeBufSize
Int_t getBranchBufferSize() const
void setExternalWeightArray(Double_t *arrayWgt, Double_t *arrayWgtErrLo, Double_t *arrayWgtErrHi, Double_t *arraySumW2)
Int_t Fill()
Interface function to TTree::Fill.
Long64_t entry
virtual Int_t numEntries() const
Double_t * _extSumW2Array
External weight array - high error.
double Double_t
Definition: RtypesCore.h:55
void select(Int_t replica=1, Int_t color=kGreen)
Definition: runplugin.C:24
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
RooArgSet _attachedBuffers
void initialize()
One-time initialization common to all constructor forms.
RooRealVar * _wgtVar
RooArgSet _varsww
Was object constructed with default ctor?
Double_t _curWgt
External sum of weights array.
double Stat_t
Definition: RtypesCore.h:73
#define name(a, b)
Definition: linkTestLib0.cpp:5
void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches...
Stat_t GetEntries() const
Interface function to TTree::GetEntries.
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList)
Merge columns of supplied data set(s) with this data set.
virtual void resetCache()
Remove tree with values of cached observables and clear list of cached observables.
const RooArgSet & row()
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 const TTree * tree() const
A TTree object has a header with a name and a title.
Definition: TTree.h:98
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:66
virtual void checkInit() const
void createTree(const char *name, const char *title)
Create TTree object that lives in memory, independent of current location of gDirectory.
void Draw(Option_t *option="")
Default Draw method for all objects.
virtual Double_t weight() const
Return the weight of the n-th data point (n='index') in memory.
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void reset()
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return pointer to weight variable if it is defined.
virtual void resetBuffers()
virtual const RooAbsArg * cacheOwner()
virtual Bool_t isWeighted() const