Logo ROOT   6.18/05
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 <map>
20#include <vector>
21#include <string>
22#include <utility>
23
24#include "RooAbsData.h"
25#include "RooDirItem.h"
26#include "RooArgSet.h"
27#include "RooNameSet.h"
28#include "RooCacheManager.h"
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 Double_t sum(Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) const ;
95 Double_t sum(const RooArgSet& sumSet, const RooArgSet& sliceSet, Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) ;
96 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);
97
98 virtual Double_t weight() const {
99 // Return weight of current bin
100 return get_curWeight();
101 }
102 Double_t weightSquared() const ;
103 Double_t weight(const RooArgSet& bin, Int_t intOrder=1, Bool_t correctForBinSize=kFALSE, Bool_t cdfBoundaries=kFALSE, Bool_t oneSafe=kFALSE) ;
104 Double_t binVolume() const { return _curVolume ; }
105 Double_t binVolume(const RooArgSet& bin) ;
106 virtual Bool_t valid() const ;
107
108 TIterator* sliceIterator(RooAbsArg& sliceArg, const RooArgSet& otherArgs) ;
109
110 virtual void weightError(Double_t& lo, Double_t& hi, ErrorType etype=Poisson) const ;
111 virtual Double_t weightError(ErrorType etype=Poisson) const {
112 // Return symmetric error on current bin calculated either from Poisson statistics or from SumOfWeights
113 Double_t lo,hi ;
114 weightError(lo,hi,etype) ;
115 return (lo+hi)/2 ;
116 }
117
118 using RooAbsData::plotOn ;
119 virtual RooPlot *plotOn(RooPlot *frame, PlotOpt o) const;
120
121 virtual void reset() ;
122 void dump2() ;
123
124 virtual void printMultiline(std::ostream& os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const ;
125 virtual void printArgs(std::ostream& os) const ;
126 virtual void printValue(std::ostream& os) const ;
127
128 void SetName(const char *name) ;
129 void SetNameTitle(const char *name, const char* title) ;
130
131 Int_t getIndex(const RooArgSet& coord, Bool_t fast=kFALSE) ;
132
134
135protected:
136
137 friend class RooAbsCachedPdf ;
138 friend class RooAbsCachedReal ;
139 friend class RooDataHistSliceIter ;
141
142 Int_t calcTreeIndex() const ;
143 void cacheValidEntries() ;
144
145 void setAllWeights(Double_t value) ;
146
147 void initialize(const char* binningName=0,Bool_t fillTree=kTRUE) ;
148 RooDataHist(const char* name, const char* title, RooDataHist* h, const RooArgSet& varSubset,
149 const RooFormulaVar* cutVar, const char* cutRange, Int_t nStart, Int_t nStop, Bool_t copyCache) ;
150 RooAbsData* reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=0,
151 Int_t nStart=0, Int_t nStop=2000000000, Bool_t copyCache=kTRUE) ;
152 Double_t interpolateDim(RooRealVar& dim, const RooAbsBinning* binning, Double_t xval, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries) ;
153 void calculatePartialBinVolume(const RooArgSet& dimSet) const ;
154 void checkBinBounds() const;
155
156 void adjustBinning(const RooArgList& vars, const TH1& href, Int_t* offset=0) ;
157 void importTH1(const RooArgList& vars, const TH1& histo, Double_t initWgt, Bool_t doDensityCorrection) ;
158 void importTH1Set(const RooArgList& vars, RooCategory& indexCat, std::map<std::string,TH1*> hmap, Double_t initWgt, Bool_t doDensityCorrection) ;
159 void importDHistSet(const RooArgList& vars, RooCategory& indexCat, std::map<std::string,RooDataHist*> dmap, Double_t initWgt) ;
160
161 virtual RooAbsData* cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName=0) ;
162
163 virtual Double_t get_wgt(const Int_t &idx) const { return _wgt[idx]; }
164 virtual Double_t get_errLo(const Int_t &idx) const { return _errLo[idx]; }
165 virtual Double_t get_errHi(const Int_t &idx) const { return _errHi[idx]; }
166 virtual Double_t get_sumw2(const Int_t &idx) const { return _sumw2[idx]; }
167
168 virtual Double_t get_curWeight() const { return _curWeight; }
169 virtual Double_t get_curWgtErrLo() const { return _curWgtErrLo; }
170 virtual Double_t get_curWgtErrHi() const { return _curWgtErrHi; }
171 virtual Double_t get_curSumW2() const { return _curSumW2; }
172
173 virtual Int_t get_curIndex() const { return _curIndex; }
174
175 Int_t _arrSize ; // Size of the weight array
176 std::vector<Int_t> _idxMult ; // Multiplier jump table for index calculation
177
178 Double_t* _wgt ; //[_arrSize] Weight array
179 Double_t* _errLo ; //[_arrSize] Low-side error on weight array
180 Double_t* _errHi ; //[_arrSize] High-side error on weight array
181 Double_t* _sumw2 ; //[_arrSize] Sum of weights^2
182 Double_t* _binv ; //[_arrSize] Bin volume array
183
184 RooArgSet _realVars ; // Real dimensions of the dataset
185 TIterator* _realIter ; //! Iterator over realVars
186 Bool_t* _binValid ; //! Valid bins with current range definition
187
188 mutable Double_t _curWeight{0.}; // Weight associated with the current coordinate
189 mutable Double_t _curWgtErrLo{0.}; // Error on weight associated with the current coordinate
190 mutable Double_t _curWgtErrHi{0.}; // Error on weight associated with the current coordinate
191 mutable Double_t _curSumW2{0.}; // Current sum of weights^2
192 mutable Double_t _curVolume{0.}; // Volume of bin enclosing current coordinate
193 mutable Int_t _curIndex{0}; // Current index
194
195 mutable std::vector<Double_t>* _pbinv ; //! Partial bin volume array
196 mutable RooCacheManager<std::vector<Double_t> > _pbinvCacheMgr ; //! Cache manager for arrays of partial bin volumes
197 std::vector<RooAbsLValue*> _lvvars ; //! List of observables casted as RooAbsLValue
198 std::vector<const RooAbsBinning*> _lvbins ; //! List of used binnings associated with lvalues
199 mutable std::vector<std::vector<Double_t> > _binbounds; //! list of bin bounds per dimension
200
201 mutable Int_t _cache_sum_valid{0}; //! Is cache sum valid
202 mutable Double_t _cache_sum{0.}; //! Cache for sum of entries ;
203
204
205private:
206 void _adjustBinning(RooRealVar &theirVar, const TAxis &axis, RooRealVar *ourVar, Int_t *offset);
207
208 ClassDef(RooDataHist,4) // Binned data set
209};
210
211#endif
212
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassDef(name, id)
Definition: Rtypes.h:326
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:24
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:70
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 common abstract base class for objects that represent a discrete value with a f...
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
RooArgSet _vars
Definition: RooAbsData.h:260
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:552
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:53
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 represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:24
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27
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:195
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:193
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:98
Int_t _cache_sum_valid
list of bin bounds per dimension
Definition: RooDataHist.h:201
void SetNameTitle(const char *name, const char *title)
Change the title of this RooDataHist.
virtual Double_t get_errLo(const Int_t &idx) const
Definition: RooDataHist.h:164
Double_t _curWeight
Valid bins with current range definition.
Definition: RooDataHist.h:188
virtual Double_t get_curWgtErrHi() const
Definition: RooDataHist.h:170
Double_t _curWgtErrLo
Definition: RooDataHist.h:189
RooAbsData * reduceEng(const RooArgSet &varSubset, const RooFormulaVar *cutVar, const char *cutRange=0, Int_t nStart=0, Int_t nStop=2000000000, Bool_t copyCache=kTRUE)
Implementation of RooAbsData virtual method that drives the RooAbsData::reduce() methods.
void set(Double_t weight, Double_t wgtErr=-1)
Increment the weight of the bin enclosing the coordinates given by 'row' by the specified amount.
Double_t * _sumw2
Definition: RooDataHist.h:181
virtual Double_t sumEntries() const
Double_t weightSquared() const
RooCacheManager< std::vector< Double_t > > _pbinvCacheMgr
Partial bin volume array.
Definition: RooDataHist.h:196
virtual Double_t get_errHi(const Int_t &idx) const
Definition: RooDataHist.h:165
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.
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 Int_t get_curIndex() const
Definition: RooDataHist.h:173
virtual Double_t get_wgt(const Int_t &idx) const
Definition: RooDataHist.h:163
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:198
RooDataHist()
Default constructor.
Definition: RooDataHist.cxx:63
void removeSelfFromDir()
Definition: RooDataHist.h:133
Bool_t * _binValid
Iterator over realVars.
Definition: RooDataHist.h:186
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:190
virtual Double_t get_curWeight() const
Definition: RooDataHist.h:168
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.
Int_t getIndex(const RooArgSet &coord, Bool_t fast=kFALSE)
Double_t * _wgt
Definition: RooDataHist.h:178
Double_t * _errLo
Definition: RooDataHist.h:179
TIterator * _realIter
Definition: RooDataHist.h:185
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...
virtual Double_t get_curWgtErrLo() const
Definition: RooDataHist.h:169
virtual TObject * Clone(const char *newname) const
Make a clone of an object using the Streamer facility.
Definition: RooDataHist.h:56
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:199
virtual Double_t get_curSumW2() const
Definition: RooDataHist.h:171
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:180
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.
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:175
std::vector< RooAbsLValue * > _lvvars
Cache manager for arrays of partial bin volumes.
Definition: RooDataHist.h:197
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:182
void cacheValidEntries()
Cache the datahist entries with bin centers that are inside/outside the current observable definitio.
RooArgSet _realVars
Definition: RooDataHist.h:184
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:176
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:111
Double_t _curSumW2
Definition: RooDataHist.h:191
virtual Double_t get_sumw2(const Int_t &idx) const
Definition: RooDataHist.h:166
void SetName(const char *name)
Change the name of the RooDataHist.
Double_t _curVolume
Definition: RooDataHist.h:192
Double_t _cache_sum
Is cache sum valid.
Definition: RooDataHist.h:202
Double_t binVolume() const
Definition: RooDataHist.h:104
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:71
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:27
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:36
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:41
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
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