Logo ROOT   6.10/09
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 
30 class TObject ;
31 class RooAbsArg;
32 class RooAbsReal ;
33 class RooAbsCategory ;
34 class Roo1DTable ;
35 class RooPlot;
36 class RooArgSet ;
37 class RooLinkedList ;
38 class RooAbsLValue ;
39 
40 class RooDataHist : public RooAbsData, public RooDirItem {
41 public:
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()) ;
53 
54 
55  RooDataHist(const RooDataHist& other, const char* newname = 0) ;
56  virtual TObject* Clone(const char* newname=0) const { return new RooDataHist(*this,newname?newname:GetName()) ; }
57  virtual ~RooDataHist() ;
58 
59  virtual RooAbsData* emptyClone(const char* newName=0, const char* newTitle=0, const RooArgSet*vars=0, const char* /*wgtVarName*/=0) const {
60  // Return empty clone of this RooDataHist
61  return new RooDataHist(newName?newName:GetName(),newTitle?newTitle:GetTitle(),vars?*vars:*get()) ;
62  }
63 
64  // Add one ore more rows of data
65  virtual void add(const RooArgSet& row, Double_t wgt=1.0) {
66  // Increment weight of bin enclosing coordinate stored in row by wgt
67  add(row,wgt,-1.) ;
68  }
69  virtual void add(const RooArgSet& row, Double_t weight, Double_t sumw2) ;
70  void set(Double_t weight, Double_t wgtErr=-1) ;
71  void set(const RooArgSet& row, Double_t weight, Double_t wgtErr=-1) ;
72  void set(const RooArgSet& row, Double_t weight, Double_t wgtErrLo, Double_t wgtErrHi) ;
73 
74  void add(const RooAbsData& dset, const RooFormulaVar* cutVar=0, Double_t weight=1.0 ) ;
75  void add(const RooAbsData& dset, const char* cut, Double_t weight=1.0 ) ;
76 
77  virtual const RooArgSet* get() const {
78  // Return set with coordinates of center of current bin
79  return &_vars ;
80  }
81  virtual const RooArgSet* get(Int_t masterIdx) const ;
82  virtual const RooArgSet* get(const RooArgSet& coord) const ;
83  virtual Int_t numEntries() const ;
84  virtual Double_t sumEntries() const ;
85  virtual Double_t sumEntries(const char* cutSpec, const char* cutRange=0) const ;
86  virtual Bool_t isWeighted() const {
87  // Return true as all histograms have in principle events weight != 1
88  return kTRUE ;
89  }
90  virtual Bool_t isNonPoissonWeighted() const ;
91 
92  Double_t sum(Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) const ;
93  Double_t sum(const RooArgSet& sumSet, const RooArgSet& sliceSet, Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) ;
94  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);
95 
96  virtual Double_t weight() const {
97  // Return weight of current bin
98  return _curWeight ;
99  }
100  Double_t weightSquared() const ;
101  Double_t weight(const RooArgSet& bin, Int_t intOrder=1, Bool_t correctForBinSize=kFALSE, Bool_t cdfBoundaries=kFALSE, Bool_t oneSafe=kFALSE) ;
102  Double_t binVolume() const { return _curVolume ; }
103  Double_t binVolume(const RooArgSet& bin) ;
104  virtual Bool_t valid() const ;
105 
106  TIterator* sliceIterator(RooAbsArg& sliceArg, const RooArgSet& otherArgs) ;
107 
108  virtual void weightError(Double_t& lo, Double_t& hi, ErrorType etype=Poisson) const ;
109  virtual Double_t weightError(ErrorType etype=Poisson) const {
110  // Return symmetric error on current bin calculated either from Poisson statistics or from SumOfWeights
111  Double_t lo,hi ;
112  weightError(lo,hi,etype) ;
113  return (lo+hi)/2 ;
114  }
115 
116  using RooAbsData::plotOn ;
117  virtual RooPlot *plotOn(RooPlot *frame, PlotOpt o) const;
118 
119  virtual void reset() ;
120  void dump2() ;
121 
122  virtual void printMultiline(std::ostream& os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const ;
123  virtual void printArgs(std::ostream& os) const ;
124  virtual void printValue(std::ostream& os) const ;
125 
126  void SetName(const char *name) ;
127  void SetNameTitle(const char *name, const char* title) ;
128 
129  Int_t getIndex(const RooArgSet& coord, Bool_t fast=kFALSE) ;
130 
131  void removeSelfFromDir() { removeFromDir(this) ; }
132 
133 protected:
134 
135  friend class RooAbsCachedPdf ;
136  friend class RooAbsCachedReal ;
137  friend class RooDataHistSliceIter ;
138  friend class RooAbsOptTestStatistic ;
139 
140  Int_t calcTreeIndex() const ;
141  void cacheValidEntries() ;
142 
143  void setAllWeights(Double_t value) ;
144 
145  void initialize(const char* binningName=0,Bool_t fillTree=kTRUE) ;
146  RooDataHist(const char* name, const char* title, RooDataHist* h, const RooArgSet& varSubset,
147  const RooFormulaVar* cutVar, const char* cutRange, Int_t nStart, Int_t nStop, Bool_t copyCache) ;
148  RooAbsData* reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=0,
149  Int_t nStart=0, Int_t nStop=2000000000, Bool_t copyCache=kTRUE) ;
150  Double_t interpolateDim(RooRealVar& dim, const RooAbsBinning* binning, Double_t xval, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries) ;
151  void calculatePartialBinVolume(const RooArgSet& dimSet) const ;
152  void checkBinBounds() const;
153 
154  void adjustBinning(const RooArgList& vars, const TH1& href, Int_t* offset=0) ;
155  void importTH1(const RooArgList& vars, const TH1& histo, Double_t initWgt, Bool_t doDensityCorrection) ;
156  void importTH1Set(const RooArgList& vars, RooCategory& indexCat, std::map<std::string,TH1*> hmap, Double_t initWgt, Bool_t doDensityCorrection) ;
157  void importDHistSet(const RooArgList& vars, RooCategory& indexCat, std::map<std::string,RooDataHist*> dmap, Double_t initWgt) ;
158 
159  virtual RooAbsData* cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName=0) ;
160 
161 
162  Int_t _arrSize ; // Size of the weight array
163  std::vector<Int_t> _idxMult ; // Multiplier jump table for index calculation
164 
165  Double_t* _wgt ; //[_arrSize] Weight array
166  Double_t* _errLo ; //[_arrSize] Low-side error on weight array
167  Double_t* _errHi ; //[_arrSize] High-side error on weight array
168  Double_t* _sumw2 ; //[_arrSize] Sum of weights^2
169  Double_t* _binv ; //[_arrSize] Bin volume array
170 
171  RooArgSet _realVars ; // Real dimensions of the dataset
172  TIterator* _realIter ; //! Iterator over realVars
173  Bool_t* _binValid ; //! Valid bins with current range definition
174 
175  mutable Double_t _curWeight ; // Weight associated with the current coordinate
176  mutable Double_t _curWgtErrLo ; // Error on weight associated with the current coordinate
177  mutable Double_t _curWgtErrHi ; // Error on weight associated with the current coordinate
178  mutable Double_t _curSumW2 ; // Current sum of weights^2
179  mutable Double_t _curVolume ; // Volume of bin enclosing current coordinate
180  mutable Int_t _curIndex ; // Current index
181 
182  mutable std::vector<Double_t>* _pbinv ; //! Partial bin volume array
183  mutable RooCacheManager<std::vector<Double_t> > _pbinvCacheMgr ; //! Cache manager for arrays of partial bin volumes
184  std::vector<RooAbsLValue*> _lvvars ; //! List of observables casted as RooAbsLValue
185  std::vector<const RooAbsBinning*> _lvbins ; //! List of used binnings associated with lvalues
186  mutable std::vector<std::vector<Double_t> > _binbounds; //! list of bin bounds per dimension
187 
188  mutable Int_t _cache_sum_valid ; //! Is cache sum valid
189  mutable Double_t _cache_sum ; //! Cache for sum of entries ;
190 
191 
192 private:
193 
194  ClassDef(RooDataHist,4) // Binned data set
195 };
196 
197 #endif
198 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Double_t weightSquared() const
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
Plot dataset on specified frame.
Definition: RooAbsData.cxx:552
virtual Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
virtual RooAbsData * emptyClone(const char *newName=0, const char *newTitle=0, const RooArgSet *vars=0, const char *=0) const
Definition: RooDataHist.h:59
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 ~RooDataHist()
Destructor.
TH1 * h
Definition: legend2.C:5
Int_t getIndex(const RooArgSet &coord, Bool_t fast=kFALSE)
Double_t _curWgtErrHi
Definition: RooDataHist.h:177
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.
Basic string class.
Definition: TString.h:129
Double_t _cache_sum
Is cache sum valid.
Definition: RooDataHist.h:189
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Double_t offset() const
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 void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE)
Copy the cached value of another RooAbsArg to our cache.
Iterator abstract base class.
Definition: TIterator.h:30
void importTH1(const RooArgList &vars, const TH1 &histo, Double_t initWgt, Bool_t doDensityCorrection)
Import data from given TH1/2/3 into this RooDataHist.
void dump2()
Debug stuff, should go...
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.
std::vector< RooAbsLValue * > _lvvars
Cache manager for arrays of partial bin volumes.
Definition: RooDataHist.h:184
RooDataSet is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
#define ClassDef(name, id)
Definition: Rtypes.h:297
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...
void checkBinBounds() const
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:163
TIterator * _realIter
Definition: RooDataHist.h:172
Double_t binVolume() const
Definition: RooDataHist.h:102
Double_t * _errHi
Definition: RooDataHist.h:167
Double_t interpolateDim(RooRealVar &dim, const RooAbsBinning *binning, Double_t xval, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries)
Perform boundary safe &#39;intOrder&#39;-th interpolation of weights in dimension &#39;dim&#39; at current value &#39;xva...
Int_t calcTreeIndex() const
Calculate the index for the weights array corresponding to to the bin enclosing the current coordinat...
virtual Double_t weight() const
Definition: RooDataHist.h:96
Double_t * _errLo
Definition: RooDataHist.h:166
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 void weightError(Double_t &lo, Double_t &hi, ErrorType etype=Poisson) const
Return the error on current weight.
Bool_t * _binValid
Iterator over realVars.
Definition: RooDataHist.h:173
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooArgSet _realVars
Definition: RooDataHist.h:171
virtual Bool_t isWeighted() const
Definition: RooDataHist.h:86
void SetName(const char *name)
Change the name of the RooDataHist.
RooAbsCachedReal is the abstract base class for functions that need or want to cache their evaluate()...
virtual void add(const RooArgSet &row, Double_t wgt=1.0)
Definition: RooDataHist.h:65
RooDataHist()
Default constructor.
Definition: RooDataHist.cxx:63
Int_t _arrSize
Definition: RooDataHist.h:162
virtual void printValue(std::ostream &os) const
Print value of the dataset, i.e. the sum of weights contained in the dataset.
void fillTree(TTree &t2)
Definition: testRooFit.cxx:49
bool verbose
virtual void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print the details on the dataset contents.
void SetNameTitle(const char *name, const char *title)
Change the title of this RooDataHist.
Double_t * _binv
Definition: RooDataHist.h:169
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
void removeSelfFromDir()
Definition: RooDataHist.h:131
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
Definition: RooDirItem.cxx:71
Double_t _curSumW2
Definition: RooDataHist.h:178
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:24
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:92
Double_t sum(Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) const
Return the sum of the weights of all hist bins.
Double_t * _wgt
Definition: RooDataHist.h:165
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:35
RooAbsBinning is the abstract base class for RooRealVar binning definitions This class defines the in...
Definition: RooAbsBinning.h:26
virtual Double_t sumEntries() const
std::vector< Double_t > * _pbinv
Definition: RooDataHist.h:182
RooAbsCachedPdf is the abstract base class for p.d.f.s that need or want to cache their evaluate() ou...
virtual Int_t numEntries() const
Return the number of bins.
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
RooDirItem is a utility base class for RooFit objects that are to be attached to ROOT directories...
Definition: RooDirItem.h:22
The TH1 histogram class.
Definition: TH1.h:56
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...
Double_t _curWgtErrLo
Definition: RooDataHist.h:176
void cacheValidEntries()
Cache the datahist entries with bin centers that are inside/outside the current observable definitio...
Double_t * _sumw2
Definition: RooDataHist.h:168
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Double_t weightError(ErrorType etype=Poisson) const
Return error on current weight (dummy implementation returning zero)
Definition: RooDataHist.h:109
RooDataHistSliceIter iterates over all bins in a RooDataHist that occur in a slice defined by the bin...
virtual void reset()
Reset all bin weights to zero.
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
virtual void printArgs(std::ostream &os) const
Print argument of dataset, i.e. the observable names.
std::vector< const RooAbsBinning * > _lvbins
List of observables casted as RooAbsLValue.
Definition: RooDataHist.h:185
Double_t _curVolume
Definition: RooDataHist.h:179
void calculatePartialBinVolume(const RooArgSet &dimSet) const
Fill the transient cache with partial bin volumes with up-to-date values for the partial volume speci...
RooCacheManager< std::vector< Double_t > > _pbinvCacheMgr
Partial bin volume array.
Definition: RooDataHist.h:183
virtual Bool_t isNonPoissonWeighted() const
Returns true if datasets contains entries with a non-integer weight.
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooDataHist.h:56
float type_of_call hi(const int &, const int &)
Abstract base class for objects that are lvalues, i.e.
Definition: RooAbsLValue.h:26
Template class RooCacheManager manages the storage of any type of data indexed on the choice of norma...
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
RooArgSet _vars
Definition: RooAbsData.h:253
void setAllWeights(Double_t value)
Set all the event weight of all bins to the specified value.
const Bool_t kTRUE
Definition: RtypesCore.h:91
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:24
virtual RooPlot * plotOn(RooPlot *frame, PlotOpt o) const
Back end function to plotting functionality.
std::vector< std::vector< Double_t > > _binbounds
List of used binnings associated with lvalues.
Definition: RooDataHist.h:186
Int_t _curIndex
Definition: RooDataHist.h:180
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
Int_t _cache_sum_valid
list of bin bounds per dimension
Definition: RooDataHist.h:188
RooAbsOptTestStatistic is the abstract base class for test statistics objects that evaluate a functio...
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27
Double_t _curWeight
Valid bins with current range definition.
Definition: RooDataHist.h:175