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
19class TDirectory;
21class RooRealVar;
22class RooDataHist;
23
24#include "RooAbsData.h"
25#include "RooDirItem.h"
26
27#include "ROOT/RStringView.hxx"
28
29#include <list>
30
31
32#define USEMEMPOOLFORDATASET
33template <class RooSet_t, size_t>
35
36class RooDataSet : public RooAbsData, public RooDirItem {
37public:
38
39#ifdef USEMEMPOOLFORDATASET
40 void* operator new (size_t bytes);
41 void operator delete (void *ptr);
42#endif
43
44
45 // Constructors, factory methods etc.
46 RooDataSet() ;
47
48 // Empty constructor
49 RooDataSet(std::string_view name, std::string_view title, const RooArgSet& vars, const char* wgtVarName=0) ;
50
51 // Universal constructor
52 RooDataSet(std::string_view name, std::string_view title, const RooArgSet& vars, const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg(),
53 const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),const RooCmdArg& arg5=RooCmdArg(),
54 const RooCmdArg& arg6=RooCmdArg(),const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg()) ;
55
56 // Constructor for subset of existing dataset
58 const char *cuts=0, const char* wgtVarName=0);
60 const RooFormulaVar& cutVar, const char* wgtVarName=0) ;
61
62
63 // Constructor importing data from external ROOT Tree
65 const char *cuts=0, const char* wgtVarName=0);
67 const RooFormulaVar& cutVar, const char* wgtVarName=0) ;
68
70
71 RooDataSet(RooDataSet const & other, const char* newname=0) ;
72 virtual TObject* Clone(const char* newname = "") const override {
73 return new RooDataSet(*this, newname && newname[0] != '\0' ? newname : GetName());
74 }
75 virtual ~RooDataSet() ;
76
77 virtual RooAbsData* emptyClone(const char* newName=0, const char* newTitle=0, const RooArgSet* vars=0, const char* wgtVarName=0) const override;
78
79 RooDataHist* binnedClone(const char* newName=0, const char* newTitle=0) const ;
80
81 virtual Double_t sumEntries() const override;
82 virtual Double_t sumEntries(const char* cutSpec, const char* cutRange=0) const override;
83
84 virtual RooPlot* plotOnXY(RooPlot* frame,
85 const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
86 const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
87 const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
88 const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) const ;
89
90
91 // Read data from a text file and create a dataset from it.
92 // The possible options are: (D)ebug, (Q)uiet.
93 static RooDataSet *read(const char *filename, const RooArgList &variables,
94 const char *opts= "", const char* commonPath="",
95 const char *indexCatName=0) ;
96 Bool_t write(const char* filename) const;
97 Bool_t write(std::ostream & ofs) const;
98
99/* void setWeightVar(const char* name=0) ; */
100/* void setWeightVar(const RooAbsArg& arg) { */
101/* // Interpret given argument as event weight */
102/* setWeightVar(arg.GetName()) ; */
103/* } */
104 virtual Bool_t isWeighted() const override;
105 virtual Bool_t isNonPoissonWeighted() const override;
106
107 virtual Double_t weight() const override;
108 virtual Double_t weightSquared() const override;
109 virtual void weightError(double& lo, double& hi,ErrorType etype=SumW2) const override;
110 double weightError(ErrorType etype=SumW2) const override;
111
112 virtual const RooArgSet* get(Int_t index) const override;
113 virtual const RooArgSet* get() const override;
114
116 std::size_t first = 0, std::size_t len = std::numeric_limits<std::size_t>::max()) const override;
117 virtual RooSpan<const double> getWeightBatch(std::size_t first, std::size_t len) const override;
118
119 // Add one ore more rows of data
120 virtual void add(const RooArgSet& row, Double_t weight=1.0, Double_t weightError=0) override;
121 virtual void add(const RooArgSet& row, Double_t weight, Double_t weightErrorLo, Double_t weightErrorHi);
122
123 virtual void addFast(const RooArgSet& row, Double_t weight=1.0, Double_t weightError=0);
124
125 void append(RooDataSet& data) ;
126 Bool_t merge(RooDataSet* data1, RooDataSet* data2=0, RooDataSet* data3=0,
127 RooDataSet* data4=0, RooDataSet* data5=0, RooDataSet* data6=0) ;
128 Bool_t merge(std::list<RooDataSet*> dsetList) ;
129
130 virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
131 virtual RooArgSet* addColumns(const RooArgList& varList) ;
132
133 // Plot the distribution of a real valued arg
135 TH2F* createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, const char* cuts="",
136 const char *name= "hist") const;
137 TH2F* createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, Int_t nx, Int_t ny,
138 const char* cuts="", const char *name="hist") const;
139
140 void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const override;
141 virtual void printArgs(std::ostream& os) const override;
142 virtual void printValue(std::ostream& os) const override;
143
144 void SetName(const char *name) override;
145 void SetNameTitle(const char *name, const char* title) override;
146
147 static void cleanup();
148
149 void convertToTreeStore() override;
150
151protected:
152
153 virtual RooAbsData* cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName=0) override;
154
155 friend class RooProdGenContext ;
156
157 void initialize(const char* wgtVarName) ;
158
159 // Cache copy feature is not publicly accessible
160 RooAbsData* reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=0,
161 std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max(), Bool_t copyCache=kTRUE) override;
163 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange, std::size_t nStart, std::size_t nStop, Bool_t copyCache, const char* wgtVarName=0);
164
165 RooArgSet addWgtVar(const RooArgSet& origVars, const RooAbsArg* wgtVar) ;
166
167 RooArgSet _varsNoWgt ; // Vars without weight variable
168 RooRealVar* _wgtVar ; // Pointer to weight variable (if set)
169
170private:
171#ifdef USEMEMPOOLFORDATASET
172 typedef MemPoolForRooSets<RooDataSet, 5*150> MemPool; // 150 = about 100kb
173 static MemPool * memPool();
174#endif
175 unsigned short _errorMsgCount{0}; //! Counter to silence error messages when filling dataset.
176 bool _doWeightErrorCheck{true}; //! When adding events with weights, check that weights can actually be stored.
177
178 ClassDefOverride(RooDataSet,2) // Unbinned data set
179};
180
181#endif
#define WRITE_TSTRING_COMPATIBLE_CONSTRUCTOR(Class_t)
Definition: RooAbsData.h:66
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassDefOverride(name, id)
Definition: Rtypes.h:329
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition: TGX11.cxx:110
float type_of_call hi(const int &, const int &)
Memory pool for RooArgSet and RooDataSet.
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:79
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:682
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
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
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27
static const RooCmdArg & none()
Return reference to null argument.
Definition: RooCmdArg.cxx:52
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:44
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:36
virtual TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
Definition: RooDataSet.h:72
virtual Bool_t isNonPoissonWeighted() const override
Returns true if histogram contains bins with entries with a non-integer weight.
virtual Bool_t isWeighted() const override
Return true if dataset contains weighted events.
RooRealVar * _wgtVar
Definition: RooDataSet.h:168
bool _doWeightErrorCheck
Counter to silence error messages when filling dataset.
Definition: RooDataSet.h:176
static void cleanup()
Definition: RooDataSet.cxx:116
RooArgSet _varsNoWgt
Definition: RooDataSet.h:167
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:888
virtual void weightError(double &lo, double &hi, ErrorType etype=SumW2) const override
Return the asymmetric errors on the current weight.
virtual const RooArgSet * get() const override
Return a RooArgSet with the coordinates of the current event.
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a column with the values of the given (function) argument to this dataset.
virtual Double_t sumEntries() const override
Return effective number of entries in dataset, i.e., sum all weights.
Bool_t write(const char *filename) const
Write the contents of this dataset to an ASCII file with the specified name.
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:944
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:858
void initialize(const char *wgtVarName)
Initialize the dataset.
Definition: RooDataSet.cxx:917
MemPoolForRooSets< RooDataSet, 5 *150 > MemPool
Definition: RooDataSet.h:172
virtual void printArgs(std::ostream &os) const override
Print argument of dataset, i.e. the observable names.
void SetName(const char *name) override
Change the name of this dataset into the given name.
virtual Double_t weightSquared() const override
Return squared event weight of current event.
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...
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.
virtual RooArgSet * addColumns(const RooArgList &varList)
Add a column with the values of the given list of (function) argument to this dataset.
void SetNameTitle(const char *name, const char *title) override
Change the title of this dataset into the given name.
virtual void printValue(std::ostream &os) const override
Print value of the dataset, i.e. the sum of weights contained in the dataset.
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.
void append(RooDataSet &data)
Add all data points of given data set to this data set.
RooDataSet()
Default constructor for persistence.
Definition: RooDataSet.cxx:175
Bool_t merge(RooDataSet *data1, RooDataSet *data2=0, RooDataSet *data3=0, RooDataSet *data4=0, RooDataSet *data5=0, RooDataSet *data6=0)
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.
virtual ~RooDataSet()
Destructor.
Definition: RooDataSet.cxx:970
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.
void getBatches(RooBatchCompute::RunContext &evalData, std::size_t first=0, std::size_t len=std::numeric_limits< std::size_t >::max()) const override
Write information to retrieve data columns into evalData.spans.
unsigned short _errorMsgCount
Definition: RooDataSet.h:175
RooDataHist * binnedClone(const char *newName=0, const char *newTitle=0) const
Return binned clone of this dataset.
Definition: RooDataSet.cxx:981
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.
static MemPool * memPool()
void convertToTreeStore() override
Convert vector-based storage to tree-based storage.
virtual RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len) const override
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:870
virtual Double_t weight() const override
Return event weight of current event.
RooDirItem is a utility base class for RooFit objects that are to be attached to ROOT directories.
Definition: RooDirItem.h:22
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
RooProdGenContext is an efficient implementation of the generator context specific for RooProdPdf PDF...
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
Describe directory structure in memory.
Definition: TDirectory.h:45
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:136
A TTree represents a columnar dataset.
Definition: TTree.h:79
basic_string_view< char > string_view
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)
Definition: first.py:1
Definition: tree.py:1
This struct enables passing computation data around between elements of a computation graph.
Definition: RunContext.h:31