Logo ROOT  
Reference Guide
RooDataHist.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooDataHist.h,v 1.37 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_HIST
17#define ROO_DATA_HIST
18
19#include "RooAbsData.h"
20#include "RooDirItem.h"
21#include "RooArgSet.h"
22#include "RooNameSet.h"
23#include "RooCacheManager.h"
24
25#include <map>
26#include <vector>
27#include <string>
28#include <utility>
29
30class TObject ;
31class RooAbsArg;
32class RooAbsReal ;
33class RooAbsCategory ;
34class Roo1DTable ;
35class RooPlot;
36class RooArgSet ;
37class RooLinkedList ;
38class RooAbsLValue ;
39
40class RooDataHist : public RooAbsData, public RooDirItem {
41public:
42
43 // Constructors, factory methods etc.
44 RooDataHist() ;
45 RooDataHist(const char *name, const char *title, const RooArgSet& vars, const char* binningName=0) ;
46 RooDataHist(const char *name, const char *title, const RooArgSet& vars, const RooAbsData& data, Double_t initWgt=1.0) ;
47 RooDataHist(const char *name, const char *title, const RooArgList& vars, const TH1* hist, Double_t initWgt=1.0) ;
48 RooDataHist(const char *name, const char *title, const RooArgList& vars, RooCategory& indexCat, std::map<std::string,TH1*> histMap, Double_t initWgt=1.0) ;
49 RooDataHist(const char *name, const char *title, const RooArgList& vars, RooCategory& indexCat, std::map<std::string,RooDataHist*> dhistMap, Double_t wgt=1.0) ;
50 //RooDataHist(const char *name, const char *title, const RooArgList& vars, Double_t initWgt=1.0) ;
51 RooDataHist(const char *name, const char *title, const RooArgList& vars, const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg(), const RooCmdArg& arg3=RooCmdArg(),
52 const RooCmdArg& arg4=RooCmdArg(),const RooCmdArg& arg5=RooCmdArg(),const RooCmdArg& arg6=RooCmdArg(),const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg()) ;
54
55 RooDataHist(const RooDataHist& other, const char* newname = 0) ;
56 virtual TObject* Clone(const char* newname="") const {
57 return new RooDataHist(*this, newname && newname[0] != '\0' ? newname : GetName());
58 }
59 virtual ~RooDataHist() ;
60
61 virtual RooAbsData* emptyClone(const char* newName=0, const char* newTitle=0, const RooArgSet*vars=0, const char* /*wgtVarName*/=0) const {
62 // Return empty clone of this RooDataHist
63 return new RooDataHist(newName?newName:GetName(),newTitle?newTitle:GetTitle(),vars?*vars:*get()) ;
64 }
65
66 // Add one ore more rows of data
67 virtual void add(const RooArgSet& row, Double_t wgt=1.0) {
68 // Increment weight of bin enclosing coordinate stored in row by wgt
69 add(row,wgt,-1.) ;
70 }
71 virtual void add(const RooArgSet& row, Double_t weight, Double_t sumw2) ;
72 void set(Double_t weight, Double_t wgtErr=-1) ;
73 void set(const RooArgSet& row, Double_t weight, Double_t wgtErr=-1) ;
74 void set(const RooArgSet& row, Double_t weight, Double_t wgtErrLo, Double_t wgtErrHi) ;
75
76 void add(const RooAbsData& dset, const RooFormulaVar* cutVar=0, Double_t weight=1.0 ) ;
77 void add(const RooAbsData& dset, const char* cut, Double_t weight=1.0 ) ;
78
79 virtual const RooArgSet* get() const {
80 // Return set with coordinates of center of current bin
81 return &_vars ;
82 }
83 virtual const RooArgSet* get(Int_t masterIdx) const ;
84 virtual const RooArgSet* get(const RooArgSet& coord) const ;
85 virtual Int_t numEntries() const ;
86 virtual Double_t sumEntries() const ;
87 virtual Double_t sumEntries(const char* cutSpec, const char* cutRange=0) const ;
88 virtual Bool_t isWeighted() const {
89 // Return true as all histograms have in principle events weight != 1
90 return kTRUE ;
91 }
92 virtual Bool_t isNonPoissonWeighted() const ;
93
94 virtual RooSpan<const double> getWeightBatch(std::size_t, std::size_t) const {
95 //TODO
96 std::cerr << "Retrieving weights in batches not yet implemented for RooDataHist." << std::endl;
97 assert(false);
98
99 return {};
100 }
101
102 Double_t sum(Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) const ;
103 Double_t sum(const RooArgSet& sumSet, const RooArgSet& sliceSet, Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) ;
104 Double_t sum(const RooArgSet& sumSet, const RooArgSet& sliceSet, Bool_t correctForBinSize, Bool_t inverseCorr, const std::map<const RooAbsArg*, std::pair<Double_t, Double_t> >& ranges);
105
106 virtual Double_t weight() const {
107 // Return weight of current bin
108 return get_curWeight();
109 }
110 Double_t weightSquared() const ;
111 Double_t weight(const RooArgSet& bin, Int_t intOrder=1, Bool_t correctForBinSize=kFALSE, Bool_t cdfBoundaries=kFALSE, Bool_t oneSafe=kFALSE) ;
112 Double_t binVolume() const { return _curVolume ; }
113 Double_t binVolume(const RooArgSet& bin) ;
114 virtual Bool_t valid() const ;
115
116 TIterator* sliceIterator(RooAbsArg& sliceArg, const RooArgSet& otherArgs) ;
117
118 virtual void weightError(Double_t& lo, Double_t& hi, ErrorType etype=Poisson) const ;
119 virtual Double_t weightError(ErrorType etype=Poisson) const {
120 // Return symmetric error on current bin calculated either from Poisson statistics or from SumOfWeights
121 Double_t lo,hi ;
122 weightError(lo,hi,etype) ;
123 return (lo+hi)/2 ;
124 }
125
126 using RooAbsData::plotOn ;
127 virtual RooPlot *plotOn(RooPlot *frame, PlotOpt o) const;
128
129 virtual void reset() ;
130 void dump2() ;
131
132 virtual void printMultiline(std::ostream& os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const ;
133 virtual void printArgs(std::ostream& os) const ;
134 virtual void printValue(std::ostream& os) const ;
135
136 void SetName(const char *name) ;
137 void SetNameTitle(const char *name, const char* title) ;
138
139 Int_t getIndex(const RooArgSet& coord, Bool_t fast=kFALSE) ;
140
142
143protected:
144
145 friend class RooAbsCachedPdf ;
146 friend class RooAbsCachedReal ;
147 friend class RooDataHistSliceIter ;
149
150 Int_t calcTreeIndex() const ;
151 void cacheValidEntries() ;
152
153 void setAllWeights(Double_t value) ;
154
155 void initialize(const char* binningName=0,Bool_t fillTree=kTRUE) ;
156 RooDataHist(const char* name, const char* title, RooDataHist* h, const RooArgSet& varSubset,
157 const RooFormulaVar* cutVar, const char* cutRange, Int_t nStart, Int_t nStop, Bool_t copyCache) ;
158 RooAbsData* reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=0,
159 std::size_t nStart=0, std::size_t nStop=std::numeric_limits<std::size_t>::max(), Bool_t copyCache=kTRUE) ;
160 Double_t interpolateDim(RooRealVar& dim, const RooAbsBinning* binning, Double_t xval, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries) ;
161 void calculatePartialBinVolume(const RooArgSet& dimSet) const ;
162 void checkBinBounds() const;
163
164 void adjustBinning(const RooArgList& vars, const TH1& href, Int_t* offset=0) ;
165 void importTH1(const RooArgList& vars, const TH1& histo, Double_t initWgt, Bool_t doDensityCorrection) ;
166 void importTH1Set(const RooArgList& vars, RooCategory& indexCat, std::map<std::string,TH1*> hmap, Double_t initWgt, Bool_t doDensityCorrection) ;
167 void importDHistSet(const RooArgList& vars, RooCategory& indexCat, std::map<std::string,RooDataHist*> dmap, Double_t initWgt) ;
168
169 virtual RooAbsData* cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName=0) ;
170
171 Double_t get_wgt(const Int_t &idx) const { return _wgt[idx]; }
172 Double_t get_errLo(const Int_t &idx) const { return _errLo[idx]; }
173 Double_t get_errHi(const Int_t &idx) const { return _errHi[idx]; }
174 Double_t get_sumw2(const Int_t &idx) const { return _sumw2[idx]; }
175
179 Double_t get_curSumW2() const { return _curSumW2; }
180
181 Int_t get_curIndex() const { return _curIndex; }
182
183 Int_t _arrSize ; // Size of the weight array
184 std::vector<Int_t> _idxMult ; // Multiplier jump table for index calculation
185
186 Double_t* _wgt ; //[_arrSize] Weight array
187 Double_t* _errLo ; //[_arrSize] Low-side error on weight array
188 Double_t* _errHi ; //[_arrSize] High-side error on weight array
189 Double_t* _sumw2 ; //[_arrSize] Sum of weights^2
190 Double_t* _binv ; //[_arrSize] Bin volume array
191
192 RooArgSet _realVars ; // Real dimensions of the dataset
193 Bool_t* _binValid ; //! Valid bins with current range definition
194
195 mutable Double_t _curWeight{0.}; // Weight associated with the current coordinate
196 mutable Double_t _curWgtErrLo{0.}; // Error on weight associated with the current coordinate
197 mutable Double_t _curWgtErrHi{0.}; // Error on weight associated with the current coordinate
198 mutable Double_t _curSumW2{0.}; // Current sum of weights^2
199 mutable Double_t _curVolume{0.}; // Volume of bin enclosing current coordinate
200 mutable Int_t _curIndex{0}; // Current index
201
202 mutable std::vector<Double_t>* _pbinv ; //! Partial bin volume array
203 mutable RooCacheManager<std::vector<Double_t> > _pbinvCacheMgr ; //! Cache manager for arrays of partial bin volumes
204 std::vector<RooAbsLValue*> _lvvars ; //! List of observables casted as RooAbsLValue
205 std::vector<const RooAbsBinning*> _lvbins ; //! List of used binnings associated with lvalues
206 mutable std::vector<std::vector<Double_t> > _binbounds; //! list of bin bounds per dimension
207
208 mutable Int_t _cache_sum_valid{0}; //! Is cache sum valid
209 mutable Double_t _cache_sum{0.}; //! Cache for sum of entries ;
210
211
212private:
213 void _adjustBinning(RooRealVar &theirVar, const TAxis &axis, RooRealVar *ourVar, Int_t *offset);
214
215 ClassDef(RooDataHist,4) // Binned data set
216};
217
218#endif
219
#define h(i)
Definition: RSha256.hxx:106
const Bool_t kFALSE
Definition: RtypesCore.h:90
double Double_t
Definition: RtypesCore.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassDef(name, id)
Definition: Rtypes.h:322
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition: TGX11.cxx:109
float type_of_call hi(const int &, const int &)
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:23
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:73
RooAbsBinning is the abstract base class for RooRealVar binning definitions This class defines the in...
Definition: RooAbsBinning.h:26
RooAbsCachedPdf is the abstract base class for p.d.f.s that need or want to cache their evaluate() ou...
RooAbsCachedReal is the abstract base class for functions that need or want to cache their evaluate()...
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:44
RooArgSet _vars
Definition: RooAbsData.h:273
virtual RooPlot * plotOn(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
Calls RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;.
Definition: RooAbsData.cxx:546
Abstract base class for objects that are lvalues, i.e.
Definition: RooAbsLValue.h:26
RooAbsOptTestStatistic is the abstract base class for test statistics objects that evaluate a functio...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:60
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE)
Copy the cached value of another RooAbsArg to our cache.
virtual Double_t offset() const
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
Template class RooCacheManager manages the storage of any type of data indexed on the choice of norma...
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:23
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:28
RooDataHistSliceIter iterates over all bins in a RooDataHist that occur in a slice defined by the bin...
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
std::vector< Double_t > * _pbinv
Definition: RooDataHist.h:202
Double_t get_errLo(const Int_t &idx) const
Definition: RooDataHist.h:172
Double_t sum(Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) const
Return the sum of the weights of all hist bins.
virtual void printArgs(std::ostream &os) const
Print argument of dataset, i.e. the observable names.
virtual void reset()
Reset all bin weights to zero.
Int_t _curIndex
Definition: RooDataHist.h:200
void dump2()
Debug stuff, should go...
void initialize(const char *binningName=0, Bool_t fillTree=kTRUE)
Initialization procedure: allocate weights array, calculate multipliers needed for N-space to 1-dim a...
virtual Double_t weight() const
Definition: RooDataHist.h:106
virtual RooSpan< const double > getWeightBatch(std::size_t, std::size_t) const
Return event weights of all events in range [first, first+len).
Definition: RooDataHist.h:94
Int_t _cache_sum_valid
list of bin bounds per dimension
Definition: RooDataHist.h:208
void SetNameTitle(const char *name, const char *title)
Change the title of this RooDataHist.
Double_t _curWeight
Valid bins with current range definition.
Definition: RooDataHist.h:195
Double_t _curWgtErrLo
Definition: RooDataHist.h:196
void set(Double_t weight, Double_t wgtErr=-1)
Set the weight and weight error of the bin enclosing the current (i.e.
Double_t * _sumw2
Definition: RooDataHist.h:189
Double_t get_curWeight() const
Definition: RooDataHist.h:176
virtual Double_t sumEntries() const
Double_t weightSquared() const
RooCacheManager< std::vector< Double_t > > _pbinvCacheMgr
Partial bin volume array.
Definition: RooDataHist.h:203
void checkBinBounds() const
virtual void weightError(Double_t &lo, Double_t &hi, ErrorType etype=Poisson) const
Return the error on current weight.
virtual Int_t numEntries() const
Return the number of bins.
Double_t get_wgt(const Int_t &idx) const
Definition: RooDataHist.h:171
virtual RooAbsData * cacheClone(const RooAbsArg *newCacheOwner, const RooArgSet *newCacheVars, const char *newName=0)
Construct a clone of this dataset that contains only the cached variables.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: RooDataHist.h:56
virtual void add(const RooArgSet &row, Double_t wgt=1.0)
Definition: RooDataHist.h:67
std::vector< const RooAbsBinning * > _lvbins
List of observables casted as RooAbsLValue.
Definition: RooDataHist.h:205
Double_t get_sumw2(const Int_t &idx) const
Definition: RooDataHist.h:174
RooDataHist()
Default constructor.
Definition: RooDataHist.cxx:69
Double_t get_curWgtErrLo() const
Definition: RooDataHist.h:177
void removeSelfFromDir()
Definition: RooDataHist.h:141
Double_t get_errHi(const Int_t &idx) const
Definition: RooDataHist.h:173
Bool_t * _binValid
Definition: RooDataHist.h:193
void importTH1Set(const RooArgList &vars, RooCategory &indexCat, std::map< std::string, TH1 * > hmap, Double_t initWgt, Bool_t doDensityCorrection)
Import data from given set of TH1/2/3 into this RooDataHist.
virtual RooAbsData * emptyClone(const char *newName=0, const char *newTitle=0, const RooArgSet *vars=0, const char *=0) const
Definition: RooDataHist.h:61
Double_t _curWgtErrHi
Definition: RooDataHist.h:197
virtual void printValue(std::ostream &os) const
Print value of the dataset, i.e. the sum of weights contained in the dataset.
virtual Bool_t isNonPoissonWeighted() const
Returns true if datasets contains entries with a non-integer weight.
Double_t get_curSumW2() const
Definition: RooDataHist.h:179
Int_t getIndex(const RooArgSet &coord, Bool_t fast=kFALSE)
Double_t * _wgt
Definition: RooDataHist.h:186
Double_t * _errLo
Definition: RooDataHist.h:187
Double_t interpolateDim(RooRealVar &dim, const RooAbsBinning *binning, Double_t xval, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries)
Perform boundary safe 'intOrder'-th interpolation of weights in dimension 'dim' at current value 'xva...
void _adjustBinning(RooRealVar &theirVar, const TAxis &axis, RooRealVar *ourVar, Int_t *offset)
Cache for sum of entries ;.
virtual Bool_t isWeighted() const
Definition: RooDataHist.h:88
std::vector< std::vector< Double_t > > _binbounds
List of used binnings associated with lvalues.
Definition: RooDataHist.h:206
TIterator * sliceIterator(RooAbsArg &sliceArg, const RooArgSet &otherArgs)
Create an iterator over all bins in a slice defined by the subset of observables listed in sliceArg.
void importTH1(const RooArgList &vars, const TH1 &histo, Double_t initWgt, Bool_t doDensityCorrection)
Import data from given TH1/2/3 into this RooDataHist.
virtual const RooArgSet * get() const
Definition: RooDataHist.h:79
Double_t * _errHi
Definition: RooDataHist.h:188
Int_t calcTreeIndex() const
Calculate the index for the weights array corresponding to to the bin enclosing the current coordinat...
virtual void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print the details on the dataset contents.
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)
Implementation of RooAbsData virtual method that drives the RooAbsData::reduce() methods.
Double_t get_curWgtErrHi() const
Definition: RooDataHist.h:178
void setAllWeights(Double_t value)
Set all the event weight of all bins to the specified value.
RooDataHist & operator=(const RooDataHist &)=delete
virtual ~RooDataHist()
Destructor.
virtual RooPlot * plotOn(RooPlot *frame, PlotOpt o) const
Back end function to plotting functionality.
void importDHistSet(const RooArgList &vars, RooCategory &indexCat, std::map< std::string, RooDataHist * > dmap, Double_t initWgt)
Import data from given set of TH1/2/3 into this RooDataHist.
Int_t _arrSize
Definition: RooDataHist.h:183
std::vector< RooAbsLValue * > _lvvars
Cache manager for arrays of partial bin volumes.
Definition: RooDataHist.h:204
virtual Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
Double_t * _binv
Definition: RooDataHist.h:190
void cacheValidEntries()
Cache the datahist entries with bin centers that are inside/outside the current observable definitio.
RooArgSet _realVars
Definition: RooDataHist.h:192
Int_t get_curIndex() const
Definition: RooDataHist.h:181
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:184
void adjustBinning(const RooArgList &vars, const TH1 &href, Int_t *offset=0)
Adjust binning specification on first and optionally second and third observable to binning in given ...
virtual Double_t weightError(ErrorType etype=Poisson) const
Return error on current weight (dummy implementation returning zero)
Definition: RooDataHist.h:119
Double_t _curSumW2
Definition: RooDataHist.h:198
void SetName(const char *name)
Change the name of the RooDataHist.
Double_t _curVolume
Definition: RooDataHist.h:199
Double_t _cache_sum
Is cache sum valid.
Definition: RooDataHist.h:209
Double_t binVolume() const
Definition: RooDataHist.h:112
void calculatePartialBinVolume(const RooArgSet &dimSet) const
Fill the transient cache with partial bin volumes with up-to-date values for the partial volume speci...
RooDirItem is a utility base class for RooFit objects that are to be attached to ROOT directories.
Definition: RooDirItem.h:22
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
Definition: RooDirItem.cxx:44
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:29
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:35
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
A simple container to hold a batch of data values.
Definition: RooSpan.h:32
Class to manage histogram axis.
Definition: TAxis.h:30
The TH1 histogram class.
Definition: TH1.h:56
Iterator abstract base class.
Definition: TIterator.h:30
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
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:131