Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
20class RooCategory;
21class RooDataHist;
22class RooRealVar;
23
24class TDirectory;
25
26#include "RooAbsData.h"
27#include "RooDirItem.h"
28
29#include <string_view>
30
31#include <list>
32
33
34//#define USEMEMPOOLFORDATASET
35
36// In the past, a custom memory pool was used for RooDataSet objects on the
37// heap. This memoy pool guaranteed that no memory addresses were reused for
38// different RooDataSets, making it possible to uniquely identify manually
39// allocated RooDataSets by their memory address.
40//
41// However, the memoy pool for RooArgSets caused unexpected memory usage
42// increases, even if no memory leaks were present [1]. It was suspected that
43// the memory allocation pattern with the memory pool might cause some heap
44// fragmentation, which did not happen when the standard allocator was used.
45//
46// To solve that problem, the memory pool was disabled. It is not clear what
47// RooFit code actually relied on the unique memory addresses, but an
48// alternative mechanism to uniquely identify RooDataSet objects was
49// implemented for these usecases (see RooAbsData::uniqueId()) [2].
50//
51// [1] https://github.com/root-project/root/issues/8323
52// [2] https://github.com/root-project/root/pull/8324
53
54template <class RooSet_t, size_t>
56
57class RooDataSet : public RooAbsData, public RooDirItem {
58public:
59
60#ifdef USEMEMPOOLFORDATASET
61 void* operator new (size_t bytes);
62 void operator delete (void *ptr);
63#endif
64
65
66 // Constructors, factory methods etc.
67 RooDataSet() ;
68
69 RooDataSet(RooStringView name, RooStringView title, const RooArgSet& vars, const char* wgtVarName)
70 R__DEPRECATED(6,34, "Use RooDataSet(name, title, vars, RooFit::WeightVar(wgtVarName)).");
71
72 // Universal constructor
73 RooDataSet(RooStringView name, RooStringView title, const RooArgSet& vars, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
74 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},const RooCmdArg& arg5={},
75 const RooCmdArg& arg6={},const RooCmdArg& arg7={},const RooCmdArg& arg8={}) ;
76
77 // Constructor for subset of existing dataset
79 const char *cuts=nullptr, const char* wgtVarName=nullptr);
81 const RooFormulaVar& cutVar, const char* wgtVarName=nullptr) ;
82
83
84 // Constructor importing data from external ROOT Tree
86 const char *cuts=nullptr, const char* wgtVarName=nullptr)
87#ifndef ROOFIT_BUILDS_ITSELF // need to guard because this is used in the implementation of other deprecated constructors
88 R__DEPRECATED(6,34, "Use RooDataSet(name, title, vars, Import(*tree), Cut(cuts), WeightVar(wgtVarName)).")
89#endif
90 ;
92 const RooFormulaVar& cutVar, const char* wgtVarName=nullptr)
93 R__DEPRECATED(6,34, "Use RooDataSet(name, title, vars, Import(*tree), Cut(cutVar), WeightVar(wgtVarName)).");
94
95 RooDataSet(RooDataSet const & other, const char* newname=nullptr) ;
96 TObject* Clone(const char* newname = "") const override {
97 return new RooDataSet(*this, newname && newname[0] != '\0' ? newname : GetName());
98 }
99 ~RooDataSet() override ;
100
101 RooFit::OwningPtr<RooAbsData> emptyClone(const char* newName=nullptr, const char* newTitle=nullptr, const RooArgSet* vars=nullptr, const char* wgtVarName=nullptr) const override;
102
103 RooFit::OwningPtr<RooDataHist> binnedClone(const char* newName=nullptr, const char* newTitle=nullptr) const ;
104
105 double sumEntries() const override;
106 double sumEntries(const char* cutSpec, const char* cutRange=nullptr) const override;
107
108 virtual RooPlot* plotOnXY(RooPlot* frame,
109 const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
110 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
111 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
112 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) const ;
113
114
115 /// Read data from a text file and create a dataset from it.
116 /// The possible options are: (D)ebug, (Q)uiet.
117 static RooDataSet *read(const char *filename, const RooArgList &variables,
118 const char *opts= "", const char* commonPath="",
119 const char *indexCatName=nullptr) ;
120 bool write(const char* filename) const;
121 bool write(std::ostream & ofs) const;
122
123
124 bool isWeighted() const override;
125 bool isNonPoissonWeighted() const override;
126
127 double weight() const override;
128 /// Returns a pointer to the weight variable (if set).
129 RooRealVar* weightVar() const { return _wgtVar; }
130 double weightSquared() const override;
131 void weightError(double& lo, double& hi,ErrorType etype=SumW2) const override;
132 double weightError(ErrorType etype=SumW2) const override;
133
134 const RooArgSet* get(Int_t index) const override;
135 const RooArgSet* get() const override;
136
137 std::span<const double> getWeightBatch(std::size_t first, std::size_t len, bool sumW2) const override;
138
139 /// Add one ore more rows of data
140 void add(const RooArgSet& row, double weight, double weightError);
141 void add(const RooArgSet& row, double weight=1.0) override { add(row, weight, 0.0); }
142 virtual void add(const RooArgSet& row, double weight, double weightErrorLo, double weightErrorHi);
143
144 virtual void addFast(const RooArgSet& row, double weight=1.0, double weightError=0.0);
145
146 void append(RooDataSet& data) ;
147 bool merge(RooDataSet* data1, RooDataSet* data2=nullptr, RooDataSet* data3=nullptr,
148 RooDataSet* data4=nullptr, RooDataSet* data5=nullptr, RooDataSet* data6=nullptr) ;
149 bool merge(std::list<RooDataSet*> dsetList) ;
150
151 virtual RooAbsArg* addColumn(RooAbsArg& var, bool adjustRange=true) ;
152 virtual RooArgSet* addColumns(const RooArgList& varList) ;
153
154 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override;
155 void printArgs(std::ostream& os) const override;
156 void printValue(std::ostream& os) const override;
157
158 void SetName(const char *name) override;
159 void SetNameTitle(const char *name, const char* title) override;
160
161 static void cleanup();
162
163 void convertToTreeStore() override;
164
165protected:
166
167 friend class RooProdGenContext ;
168
169 void initialize(const char* wgtVarName) ;
170
171 // Cache copy feature is not publicly accessible
172 std::unique_ptr<RooAbsData> reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=nullptr,
173 std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max()) override;
174
175 RooArgSet _varsNoWgt; ///< Vars without weight variable
176 RooRealVar *_wgtVar = nullptr; ///< Pointer to weight variable (if set)
177
178private:
179
180 void loadValuesFromSlices(RooCategory &indexCat, std::map<std::string, RooAbsData *> const &slices,
181 const char *rangeName, RooFormulaVar const *cutVar, const char *cutSpec);
182
183#ifdef USEMEMPOOLFORDATASET
184 typedef MemPoolForRooSets<RooDataSet, 5*150> MemPool; ///< 150 = about 100kb
185 static MemPool * memPool();
186#endif
187 unsigned short _errorMsgCount{0}; ///<! Counter to silence error messages when filling dataset.
188 bool _doWeightErrorCheck{true}; ///<! When adding events with weights, check that weights can actually be stored.
189
190 mutable std::unique_ptr<std::vector<double>> _sumW2Buffer; ///<! Buffer for sumW2 in case a batch of values is requested.
191
192 ClassDefOverride(RooDataSet,2) // Unbinned data set
193};
194
195#endif
#define R__DEPRECATED(MAJOR, MINOR, REASON)
Definition RConfig.hxx:521
bool initialize()
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
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 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 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 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
Memory pool for RooArgSet and RooDataSet.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
const TTree * tree() const
Return a pointer to the TTree which stores the data.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
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:55
Object to represent discrete states.
Definition RooCategory.h:28
Named container for two doubles, two integers two object points and three string pointers that can be...
Definition RooCmdArg.h:26
Container class to hold N-dimensional binned data.
Definition RooDataHist.h:39
Container class to hold unbinned data.
Definition RooDataSet.h:57
RooFit::OwningPtr< RooAbsData > emptyClone(const char *newName=nullptr, const char *newTitle=nullptr, const RooArgSet *vars=nullptr, const char *wgtVarName=nullptr) const override
Return an empty clone of this dataset.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
Definition RooDataSet.h:96
RooRealVar * _wgtVar
Pointer to weight variable (if set)
Definition RooDataSet.h:176
bool _doWeightErrorCheck
! When adding events with weights, check that weights can actually be stored.
Definition RooDataSet.h:188
static void cleanup()
RooArgSet _varsNoWgt
Vars without weight variable.
Definition RooDataSet.h:175
void loadValuesFromSlices(RooCategory &indexCat, std::map< std::string, RooAbsData * > const &slices, const char *rangeName, RooFormulaVar const *cutVar, const char *cutSpec)
RooFit::OwningPtr< RooDataHist > binnedClone(const char *newName=nullptr, const char *newTitle=nullptr) const
Return binned clone of this dataset.
void weightError(double &lo, double &hi, ErrorType etype=SumW2) const override
Return the asymmetric errors on the current weight.
const RooArgSet * get() const override
Return a RooArgSet with the coordinates of the current event.
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 void addFast(const RooArgSet &row, double weight=1.0, double weightError=0.0)
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
bool merge(RooDataSet *data1, RooDataSet *data2=nullptr, RooDataSet *data3=nullptr, RooDataSet *data4=nullptr, RooDataSet *data5=nullptr, RooDataSet *data6=nullptr)
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.
std::span< const double > getWeightBatch(std::size_t first, std::size_t len, bool sumW2) const override
std::unique_ptr< RooAbsData > reduceEng(const RooArgSet &varSubset, const RooFormulaVar *cutVar, const char *cutRange=nullptr, 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.
RooRealVar * weightVar() const
Returns a pointer to the weight variable (if set).
Definition RooDataSet.h:129
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.
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.
void append(RooDataSet &data)
Add all data points of given data set to this data set.
RooDataSet()
Default constructor for persistence.
std::unique_ptr< std::vector< double > > _sumW2Buffer
! Buffer for sumW2 in case a batch of values is requested.
Definition RooDataSet.h:190
void add(const RooArgSet &row, double weight, double weightError)
Add one ore more rows of data.
unsigned short _errorMsgCount
! Counter to silence error messages when filling dataset.
Definition RooDataSet.h:187
void convertToTreeStore() override
Convert vector-based storage to tree-based storage.
virtual RooPlot * plotOnXY(RooPlot *frame, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Special plot method for 'X-Y' datasets used in fitting.
void add(const RooArgSet &row, double weight=1.0) override
Definition RooDataSet.h:141
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 the current event.
double weight() const override
Return event weight of current event.
static RooDataSet * read(const char *filename, const RooArgList &variables, const char *opts="", const char *commonPath="", const char *indexCatName=nullptr)
Read data from a text file and create a dataset from it.
bool isWeighted() const override
Return true if dataset contains weighted events.
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...
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
Efficient implementation of the generator context specific for RooProdPdf PDFs.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
The RooStringView is a wrapper around a C-style string that can also be constructed from a std::strin...
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:41
Basic string class.
Definition TString.h:139
A TTree represents a columnar dataset.
Definition TTree.h:79
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:35