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
33
34// In the past, a custom memory pool was used for RooDataSet objects on the
35// heap. This memoy pool guaranteed that no memory addresses were reused for
36// different RooDataSets, making it possible to uniquely identify manually
37// allocated RooDataSets by their memory address.
38//
39// However, the memoy pool for RooArgSets caused unexpected memory usage
40// increases, even if no memory leaks were present [1]. It was suspected that
41// the memory allocation pattern with the memory pool might cause some heap
42// fragmentation, which did not happen when the standard allocator was used.
43//
44// To solve that problem, the memory pool was disabled. It is not clear what
45// RooFit code actually relied on the unique memory addresses, but an
46// alternative mechanism to uniquely identify RooDataSet objects was
47// implemented for these usecases (see RooAbsData::uniqueId()) [2].
48//
49// [1] https://github.com/root-project/root/issues/8323
50// [2] https://github.com/root-project/root/pull/8324
51
52template <class RooSet_t, size_t>
54
55class RooDataSet : public RooAbsData, public RooDirItem {
56public:
57
58#ifdef USEMEMPOOLFORDATASET
59 void* operator new (size_t bytes);
60 void operator delete (void *ptr);
61#endif
62
63
64 // Constructors, factory methods etc.
65 RooDataSet() ;
66
67 // Empty constructor
68 RooDataSet(RooStringView name, RooStringView title, const RooArgSet& vars, const char* wgtVarName=0) ;
69
70 // Universal constructor
71 RooDataSet(RooStringView name, RooStringView title, const RooArgSet& vars, const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg(),
72 const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),const RooCmdArg& arg5=RooCmdArg(),
73 const RooCmdArg& arg6=RooCmdArg(),const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg()) ;
74
75 // Constructor for subset of existing dataset
77 const char *cuts=0, const char* wgtVarName=0);
79 const RooFormulaVar& cutVar, const char* wgtVarName=0) ;
80
81
82 // Constructor importing data from external ROOT Tree
84 const char *cuts=0, const char* wgtVarName=0);
86 const RooFormulaVar& cutVar, const char* wgtVarName=0) ;
87
88 RooDataSet(RooDataSet const & other, const char* newname=0) ;
89 TObject* Clone(const char* newname = "") const override {
90 return new RooDataSet(*this, newname && newname[0] != '\0' ? newname : GetName());
91 }
92 ~RooDataSet() override ;
93
94 RooAbsData* emptyClone(const char* newName=0, const char* newTitle=0, const RooArgSet* vars=0, const char* wgtVarName=0) const override;
95
96 RooDataHist* binnedClone(const char* newName=0, const char* newTitle=0) const ;
97
98 double sumEntries() const override;
99 double sumEntries(const char* cutSpec, const char* cutRange=0) const override;
100
101 virtual RooPlot* plotOnXY(RooPlot* frame,
102 const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
103 const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
104 const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
105 const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) const ;
106
107
108 /// Read data from a text file and create a dataset from it.
109 /// The possible options are: (D)ebug, (Q)uiet.
110 static RooDataSet *read(const char *filename, const RooArgList &variables,
111 const char *opts= "", const char* commonPath="",
112 const char *indexCatName=0) ;
113 bool write(const char* filename) const;
114 bool write(std::ostream & ofs) const;
115
116
117 bool isWeighted() const override;
118 bool isNonPoissonWeighted() const override;
119
120 double weight() const override;
121 /// Returns a pointer to the weight variable (if set).
122 RooRealVar* weightVar() const { return _wgtVar; }
123 double weightSquared() const override;
124 void weightError(double& lo, double& hi,ErrorType etype=SumW2) const override;
125 double weightError(ErrorType etype=SumW2) const override;
126
127 const RooArgSet* get(Int_t index) const override;
128 const RooArgSet* get() const override;
129
130 RooSpan<const double> getWeightBatch(std::size_t first, std::size_t len, bool sumW2) const override;
131
132 /// Add one ore more rows of data
133 void add(const RooArgSet& row, double weight=1.0, double weightError=0) override;
134 virtual void add(const RooArgSet& row, double weight, double weightErrorLo, double weightErrorHi);
135
136 virtual void addFast(const RooArgSet& row, double weight=1.0, double weightError=0);
137
138 void append(RooDataSet& data) ;
139 bool merge(RooDataSet* data1, RooDataSet* data2=0, RooDataSet* data3=0,
140 RooDataSet* data4=0, RooDataSet* data5=0, RooDataSet* data6=0) ;
141 bool merge(std::list<RooDataSet*> dsetList) ;
142
143 virtual RooAbsArg* addColumn(RooAbsArg& var, bool adjustRange=true) ;
144 virtual RooArgSet* addColumns(const RooArgList& varList) ;
145
146 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override;
147 void printArgs(std::ostream& os) const override;
148 void printValue(std::ostream& os) const override;
149
150 void SetName(const char *name) override;
151 void SetNameTitle(const char *name, const char* title) override;
152
153 static void cleanup();
154
155 void convertToTreeStore() override;
156
157protected:
158
159 friend class RooProdGenContext ;
160
161 void initialize(const char* wgtVarName) ;
162
163 // Cache copy feature is not publicly accessible
164 RooAbsData* reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=0,
165 std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max()) override;
167 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
168 std::size_t nStart, std::size_t nStop);
169
170 RooArgSet addWgtVar(const RooArgSet& origVars, const RooAbsArg* wgtVar) ;
171
172 RooArgSet _varsNoWgt ; ///< Vars without weight variable
173 RooRealVar* _wgtVar ; ///< Pointer to weight variable (if set)
174
175private:
176#ifdef USEMEMPOOLFORDATASET
177 typedef MemPoolForRooSets<RooDataSet, 5*150> MemPool; ///< 150 = about 100kb
178 static MemPool * memPool();
179#endif
180 unsigned short _errorMsgCount{0}; ///<! Counter to silence error messages when filling dataset.
181 bool _doWeightErrorCheck{true}; ///<! When adding events with weights, check that weights can actually be stored.
182
183 mutable std::unique_ptr<std::vector<double>> _sumW2Buffer; ///<! Buffer for sumW2 in case a batch of values is requested.
184
185 ClassDefOverride(RooDataSet,2) // Unbinned data set
186};
187
188#endif
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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 filename
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
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 bytes
char name[80]
Definition: TGX11.cxx:110
#define hi
Definition: THbookFile.cxx:128
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:62
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:57
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:26
static const RooCmdArg & none()
Return reference to null argument.
Definition: RooCmdArg.cxx:51
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:45
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len, bool sumW2) const override
Definition: RooDataSet.cxx:949
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
Definition: RooDataSet.h:89
RooRealVar * _wgtVar
Pointer to weight variable (if set)
Definition: RooDataSet.h:173
bool _doWeightErrorCheck
! When adding events with weights, check that weights can actually be stored.
Definition: RooDataSet.h:181
static void cleanup()
Definition: RooDataSet.cxx:125
RooArgSet _varsNoWgt
Vars without weight variable.
Definition: RooDataSet.h:172
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:825
void weightError(double &lo, double &hi, ErrorType etype=SumW2) const override
Return the asymmetric errors on the current weight.
Definition: RooDataSet.cxx:984
const RooArgSet * get() const override
Return a RooArgSet with the coordinates of the current event.
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()) override
Implementation of RooAbsData virtual method that drives the RooAbsData::reduce() methods.
Definition: RooDataSet.cxx:881
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:813
void initialize(const char *wgtVarName)
Initialize the dataset.
Definition: RooDataSet.cxx:854
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 RooAbsArg * addColumn(RooAbsArg &var, bool adjustRange=true)
Add a column with the values of the given (function) argument to this dataset.
bool write(const char *filename) const
Write the contents of this dataset to an ASCII file with the specified name.
double sumEntries() const override
Return effective number of entries in dataset, i.e., sum all weights.
static RooDataSet * read(const char *filename, const RooArgList &variables, const char *opts="", const char *commonPath="", const char *indexCatName=0)
Read data from a text file and create a dataset from it.
RooRealVar * weightVar() const
Returns a pointer to the weight variable (if set).
Definition: RooDataSet.h:122
virtual RooArgSet * addColumns(const RooArgList &varList)
Add a column with the values of the given list of (function) argument to this dataset.
~RooDataSet() override
Destructor.
Definition: RooDataSet.cxx:897
bool isNonPoissonWeighted() const override
Returns true if histogram contains bins with entries with a non-integer weight.
void SetNameTitle(const char *name, const char *title) override
Change the title of this dataset into the given name.
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.
bool merge(RooDataSet *data1, RooDataSet *data2=0, RooDataSet *data3=0, RooDataSet *data4=0, RooDataSet *data5=0, RooDataSet *data6=0)
RooDataSet()
Default constructor for persistence.
Definition: RooDataSet.cxx:184
void add(const RooArgSet &row, double weight=1.0, double weightError=0) override
Add one ore more rows of data.
virtual void addFast(const RooArgSet &row, double weight=1.0, double weightError=0)
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
std::unique_ptr< std::vector< double > > _sumW2Buffer
! Buffer for sumW2 in case a batch of values is requested.
Definition: RooDataSet.h:183
unsigned short _errorMsgCount
! Counter to silence error messages when filling dataset.
Definition: RooDataSet.h:180
RooDataHist * binnedClone(const char *newName=0, const char *newTitle=0) const
Return binned clone of this dataset.
Definition: RooDataSet.cxx:908
void convertToTreeStore() override
Convert vector-based storage to tree-based storage.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print info about this dataset to the specified output stream.
double weightSquared() const override
Return squared event weight of current event.
Definition: RooDataSet.cxx:941
double weight() const override
Return event weight of current event.
Definition: RooDataSet.cxx:931
bool isWeighted() const override
Return true if dataset contains weighted events.
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:43
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: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
Describe directory structure in memory.
Definition: TDirectory.h:45
const char * GetName() const override
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
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