Logo ROOT  
Reference Guide
RooDataSet.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooDataSet.h,v 1.59 2007/05/11 09:11:30 verkerke Exp $
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_DATA_SET
17 #define ROO_DATA_SET
18 
19 class TDirectory;
20 class RooAbsRealLValue;
21 class RooRealVar;
22 class RooDataHist;
23 
24 #include "RooAbsData.h"
25 #include "RooDirItem.h"
26 #include <list>
27 
28 
29 #define USEMEMPOOLFORDATASET
30 template <class RooSet_t, size_t>
31 class MemPoolForRooSets;
32 
33 class RooDataSet : public RooAbsData, public RooDirItem {
34 public:
35 
36 #ifdef USEMEMPOOLFORDATASET
37  void* operator new (size_t bytes);
38  void operator delete (void *ptr);
39 #endif
40 
41 
42  // Constructors, factory methods etc.
43  RooDataSet() ;
44 
45  // Empty constructor
46  RooDataSet(const char *name, const char *title, const RooArgSet& vars, const char* wgtVarName=0) ;
47 
48  // Universal constructor
49  RooDataSet(const char* name, const char* title, const RooArgSet& vars, const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg(),
50  const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),const RooCmdArg& arg5=RooCmdArg(),
51  const RooCmdArg& arg6=RooCmdArg(),const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg()) ;
52 
53  // Constructor for subset of existing dataset
54  RooDataSet(const char *name, const char *title, RooDataSet *data, const RooArgSet& vars,
55  const char *cuts=0, const char* wgtVarName=0);
56  RooDataSet(const char *name, const char *title, RooDataSet *data, const RooArgSet& vars,
57  const RooFormulaVar& cutVar, const char* wgtVarName=0) ;
58 
59 
60  // Constructor importing data from external ROOT Tree
61  RooDataSet(const char *name, const char *title, TTree *tree, const RooArgSet& vars,
62  const char *cuts=0, const char* wgtVarName=0);
63  RooDataSet(const char *name, const char *title, TTree *tree, const RooArgSet& vars,
64  const RooFormulaVar& cutVar, const char* wgtVarName=0) ;
65 
66 
67  RooDataSet(RooDataSet const & other, const char* newname=0) ;
68  virtual TObject* Clone(const char* newname = "") const override {
69  return new RooDataSet(*this, newname && newname[0] != '\0' ? newname : GetName());
70  }
71  virtual ~RooDataSet() ;
72 
73  virtual RooAbsData* emptyClone(const char* newName=0, const char* newTitle=0, const RooArgSet* vars=0, const char* wgtVarName=0) const override;
74 
75  RooDataHist* binnedClone(const char* newName=0, const char* newTitle=0) const ;
76 
77  virtual Double_t sumEntries() const override;
78  virtual Double_t sumEntries(const char* cutSpec, const char* cutRange=0) const override;
79 
80  virtual RooPlot* plotOnXY(RooPlot* frame,
81  const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
82  const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
83  const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
84  const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) const ;
85 
86 
87  // Read data from a text file and create a dataset from it.
88  // The possible options are: (D)ebug, (Q)uiet.
89  static RooDataSet *read(const char *filename, const RooArgList &variables,
90  const char *opts= "", const char* commonPath="",
91  const char *indexCatName=0) ;
92  Bool_t write(const char* filename) const;
93  Bool_t write(std::ostream & ofs) const;
94 
95 /* void setWeightVar(const char* name=0) ; */
96 /* void setWeightVar(const RooAbsArg& arg) { */
97 /* // Interpret given argument as event weight */
98 /* setWeightVar(arg.GetName()) ; */
99 /* } */
100  virtual Bool_t isWeighted() const override;
101  virtual Bool_t isNonPoissonWeighted() const override;
102 
103  virtual Double_t weight() const override;
104  virtual Double_t weightSquared() const override;
105  virtual void weightError(Double_t& lo, Double_t& hi,ErrorType etype=SumW2) const override;
106  Double_t weightError(ErrorType etype=SumW2) const override;
107 
108  virtual const RooArgSet* get(Int_t index) const override;
109  virtual const RooArgSet* get() const override;
110 
111  virtual RooSpan<const double> getWeightBatch(std::size_t first, std::size_t len) const override;
112 
113  // Add one ore more rows of data
114  virtual void add(const RooArgSet& row, Double_t weight=1.0, Double_t weightError=0) override;
115  virtual void add(const RooArgSet& row, Double_t weight, Double_t weightErrorLo, Double_t weightErrorHi);
116 
117  virtual void addFast(const RooArgSet& row, Double_t weight=1.0, Double_t weightError=0);
118 
119  void append(RooDataSet& data) ;
120  Bool_t merge(RooDataSet* data1, RooDataSet* data2=0, RooDataSet* data3=0,
121  RooDataSet* data4=0, RooDataSet* data5=0, RooDataSet* data6=0) ;
122  Bool_t merge(std::list<RooDataSet*> dsetList) ;
123 
124  virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
125  virtual RooArgSet* addColumns(const RooArgList& varList) ;
126 
127  // Plot the distribution of a real valued arg
129  TH2F* createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, const char* cuts="",
130  const char *name= "hist") const;
131  TH2F* createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, Int_t nx, Int_t ny,
132  const char* cuts="", const char *name="hist") const;
133 
134  void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const override;
135  virtual void printArgs(std::ostream& os) const override;
136  virtual void printValue(std::ostream& os) const override;
137 
138  void SetName(const char *name) override;
139  void SetNameTitle(const char *name, const char* title) override;
140 
141  static void cleanup();
142 
143  void convertToTreeStore() override;
144 
145 protected:
146 
147  virtual RooAbsData* cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName=0) override;
148 
149  friend class RooProdGenContext ;
150 
151  void initialize(const char* wgtVarName) ;
152 
153  // Cache copy feature is not publicly accessible
154  RooAbsData* reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=0,
155  std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max(), Bool_t copyCache=kTRUE) override;
156  RooDataSet(const char *name, const char *title, RooDataSet *ntuple,
157  const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange, std::size_t nStart, std::size_t nStop, Bool_t copyCache, const char* wgtVarName=0);
158 
159  RooArgSet addWgtVar(const RooArgSet& origVars, const RooAbsArg* wgtVar) ;
160 
161  RooArgSet _varsNoWgt ; // Vars without weight variable
162  RooRealVar* _wgtVar ; // Pointer to weight variable (if set)
163 
164 private:
165 #ifdef USEMEMPOOLFORDATASET
166  typedef MemPoolForRooSets<RooDataSet, 5*150> MemPool; // 150 = about 100kb
167  static MemPool * memPool();
168 #endif
169  unsigned short _errorMsgCount{0}; //! Counter to silence error messages when filling dataset.
170  bool _doWeightErrorCheck{true}; //! When adding events with weights, check that weights can actually be stored.
171 
172  ClassDefOverride(RooDataSet,2) // Unbinned data set
173 };
174 
175 #endif
RooDataSet::createHistogram
TH2F * createHistogram(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2, const char *cuts="", const char *name="hist") const
Create a TH2F histogram of the distribution of the specified variable using this dataset.
Definition: RooDataSet.cxx:1419
RooCmdArg
Definition: RooCmdArg.h:27
first
Definition: first.py:1
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooDataSet::cacheClone
virtual RooAbsData * cacheClone(const RooAbsArg *newCacheOwner, const RooArgSet *newCacheVars, const char *newName=0) override
Return a clone of this dataset containing only the cached variables.
Definition: RooDataSet.cxx:863
RooDataSet::convertToTreeStore
void convertToTreeStore() override
Convert vector-based storage to tree-based storage.
Definition: RooDataSet.cxx:2066
RooAbsData
Definition: RooAbsData.h:46
RooAbsData::SumW2
@ SumW2
Definition: RooAbsData.h:96
RooDataSet::MemPool
MemPoolForRooSets< RooDataSet, 5 *150 > MemPool
Definition: RooDataSet.h:166
TH2F
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
RooProdGenContext
Definition: RooProdGenContext.h:31
RooDataSet::initialize
void initialize(const char *wgtVarName)
Initialize the dataset.
Definition: RooDataSet.cxx:910
tree
Definition: tree.py:1
RooArgList
Definition: RooArgList.h:21
TTree
Definition: TTree.h:79
RooDirItem
Definition: RooDirItem.h:22
RooDataSet::printValue
virtual void printValue(std::ostream &os) const override
Print value of the dataset, i.e. the sum of weights contained in the dataset.
Definition: RooDataSet.cxx:1951
RooDataSet::printArgs
virtual void printArgs(std::ostream &os) const override
Print argument of dataset, i.e. the observable names.
Definition: RooDataSet.cxx:1964
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
RooDataSet::merge
Bool_t merge(RooDataSet *data1, RooDataSet *data2=0, RooDataSet *data3=0, RooDataSet *data4=0, RooDataSet *data5=0, RooDataSet *data6=0)
Definition: RooDataSet.cxx:1308
RooDataSet::append
void append(RooDataSet &data)
Add all data points of given data set to this data set.
Definition: RooDataSet.cxx:1368
RooDataSet::SetName
void SetName(const char *name) override
Change the name of this dataset into the given name.
Definition: RooDataSet.cxx:1990
RooDataSet::addFast
virtual void addFast(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0)
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
Definition: RooDataSet.cxx:1266
RooDataSet::_wgtVar
RooRealVar * _wgtVar
Definition: RooDataSet.h:162
TString
Definition: TString.h:136
ClassDefOverride
#define ClassDefOverride(name, id)
Definition: Rtypes.h:329
RooDataSet::cleanup
static void cleanup()
Definition: RooDataSet.cxx:114
RooDataSet::addWgtVar
RooArgSet addWgtVar(const RooArgSet &origVars, const RooAbsArg *wgtVar)
Helper function for constructor that adds optional weight variable to construct total set of observab...
Definition: RooDataSet.cxx:851
RooCmdArg::none
static const RooCmdArg & none()
Return reference to null argument.
Definition: RooCmdArg.cxx:52
RooAbsData::ErrorType
ErrorType
Definition: RooAbsData.h:96
bool
hi
float type_of_call hi(const int &, const int &)
RooDataSet::_errorMsgCount
unsigned short _errorMsgCount
Definition: RooDataSet.h:169
RooDataSet::add
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0) override
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
Definition: RooDataSet.cxx:1164
RooDataSet::addColumns
virtual RooArgSet * addColumns(const RooArgList &varList)
Add a column with the values of the given list of (function) argument to this dataset.
Definition: RooDataSet.cxx:1400
RooDataHist
Definition: RooDataHist.h:39
RooFormulaVar
Definition: RooFormulaVar.h:30
RooDataSet::get
virtual const RooArgSet * get() const override
Return a RooArgSet with the coordinates of the current event.
Definition: RooDataSet.cxx:1146
RooDataSet::~RooDataSet
virtual ~RooDataSet()
Destructor.
Definition: RooDataSet.cxx:961
RooDataSet::isNonPoissonWeighted
virtual Bool_t isNonPoissonWeighted() const override
Returns true if histogram contains bins with entries with a non-integer weight.
Definition: RooDataSet.cxx:1124
TMVA::variables
void variables(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooDataSet::SetNameTitle
void SetNameTitle(const char *name, const char *title) override
Change the title of this dataset into the given name.
Definition: RooDataSet.cxx:2001
RooAbsData::createHistogram
TH1 * createHistogram(const char *name, const RooAbsRealLValue &xvar, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Calls createHistogram(const char *name, const RooAbsRealLValue& xvar, const RooLinkedList& argList) c...
Definition: RooAbsData.cxx:629
RooDirItem.h
RooPlot
Definition: RooPlot.h:44
RooDataSet::printMultiline
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const override
Print info about this dataset to the specified output stream.
Definition: RooDataSet.cxx:1938
RooDataSet::_varsNoWgt
RooArgSet _varsNoWgt
Definition: RooDataSet.h:161
RooDataSet::_doWeightErrorCheck
bool _doWeightErrorCheck
Counter to silence error messages when filling dataset.
Definition: RooDataSet.h:170
RooDataSet::sumEntries
virtual Double_t sumEntries() const override
Return effective number of entries in dataset, i.e., sum all weights.
Definition: RooDataSet.cxx:1047
RooDataSet::RooDataSet
RooDataSet()
Default constructor for persistence.
Definition: RooDataSet.cxx:173
MemPoolForRooSets
Memory pool for RooArgSet and RooDataSet.
Definition: RooArgSet.h:26
RooDataSet::isWeighted
virtual Bool_t isWeighted() const override
Return true if dataset contains weighted events.
Definition: RooDataSet.cxx:1114
RooDataSet::read
static RooDataSet * read(const char *filename, const RooArgList &variables, const char *opts="", const char *commonPath="", const char *indexCatName=0)
Read given list of ascii files, and construct a data set, using the given ArgList as structure defini...
Definition: RooDataSet.cxx:1710
RooDataSet::weightSquared
virtual Double_t weightSquared() const override
Return squared event weight of current event.
Definition: RooDataSet.cxx:1004
RooAbsData.h
Double_t
double Double_t
Definition: RtypesCore.h:59
RooDataSet::plotOnXY
virtual RooPlot * plotOnXY(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Special plot method for 'X-Y' datasets used in fitting.
Definition: RooDataSet.cxx:1548
RooDataSet::memPool
static MemPool * memPool()
TObject
Definition: TObject.h:37
RooDataSet::binnedClone
RooDataHist * binnedClone(const char *newName=0, const char *newTitle=0) const
Return binned clone of this dataset.
Definition: RooDataSet.cxx:972
name
char name[80]
Definition: TGX11.cxx:110
RooDataSet::emptyClone
virtual RooAbsData * emptyClone(const char *newName=0, const char *newTitle=0, const RooArgSet *vars=0, const char *wgtVarName=0) const override
Return an empty clone of this dataset.
Definition: RooDataSet.cxx:881
TDirectory
Definition: TDirectory.h:40
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RooDataSet
Definition: RooDataSet.h:33
RooDataSet::Clone
virtual TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
Definition: RooDataSet.h:68
RooAbsArg
Definition: RooAbsArg.h:73
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
RooDataSet::reduceEng
RooAbsData * reduceEng(const RooArgSet &varSubset, const RooFormulaVar *cutVar, const char *cutRange=0, std::size_t nStart=0, std::size_t nStop=std::numeric_limits< std::size_t >::max(), Bool_t copyCache=kTRUE) override
Implementation of RooAbsData virtual method that drives the RooAbsData::reduce() methods.
Definition: RooDataSet.cxx:935
RooRealVar
Definition: RooRealVar.h:36
RooAbsRealLValue
Definition: RooAbsRealLValue.h:31
RooSpan
A simple container to hold a batch of data values.
Definition: RooSpan.h:33
RooDataSet::weightError
virtual void weightError(Double_t &lo, Double_t &hi, ErrorType etype=SumW2) const override
Return asymmetric error on weight. (Dummy implementation returning zero)
Definition: RooDataSet.cxx:1019
RooDataSet::getWeightBatch
virtual RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len) const override
Return event weights of all events in range [first, first+len).
Definition: RooDataSet.cxx:1012
RooArgSet
Definition: RooArgSet.h:28
RooDataSet::weight
virtual Double_t weight() const override
Return event weight of current event.
Definition: RooDataSet.cxx:994
RooDataSet::addColumn
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a column with the values of the given (function) argument to this dataset.
Definition: RooDataSet.cxx:1383
int
RooDataSet::write
Bool_t write(const char *filename) const
Write the contents of this dataset to an ASCII file with the specified name.
Definition: RooDataSet.cxx:1897