RooDataHist.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  *    File: $Id: RooDataHist.h,v 1.37 2007/05/11 09:11:30 verkerke Exp $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 #ifndef ROO_DATA_HIST
00017 #define ROO_DATA_HIST
00018 
00019 #include "RooAbsData.h"
00020 #include "RooDirItem.h"
00021 #include "RooArgSet.h"
00022 #include "RooNameSet.h"
00023 #include "RooCacheManager.h"
00024 #include <vector>
00025 #include <list>
00026 #include <map>
00027 #include <string>
00028 
00029 class TObject ;
00030 class RooAbsArg;
00031 class RooAbsReal ;
00032 class RooAbsCategory ;
00033 class Roo1DTable ;
00034 class RooPlot;
00035 class RooArgSet ;
00036 class RooLinkedList ;
00037 class RooAbsLValue ;
00038 
00039 class RooDataHist : public RooAbsData, public RooDirItem {
00040 public:
00041 
00042   // Constructors, factory methods etc.
00043   RooDataHist() ; 
00044   RooDataHist(const char *name, const char *title, const RooArgSet& vars, const char* binningName=0) ;
00045   RooDataHist(const char *name, const char *title, const RooArgSet& vars, const RooAbsData& data, Double_t initWgt=1.0) ;
00046   RooDataHist(const char *name, const char *title, const RooArgList& vars, const TH1* hist, Double_t initWgt=1.0) ;
00047   RooDataHist(const char *name, const char *title, const RooArgList& vars, RooCategory& indexCat, std::map<std::string,TH1*> histMap, Double_t initWgt=1.0) ;
00048   RooDataHist(const char *name, const char *title, const RooArgList& vars, RooCategory& indexCat, std::map<std::string,RooDataHist*> dhistMap, Double_t wgt=1.0) ;
00049   //RooDataHist(const char *name, const char *title, const RooArgList& vars, Double_t initWgt=1.0) ;
00050   RooDataHist(const char *name, const char *title, const RooArgList& vars, const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg(), const RooCmdArg& arg3=RooCmdArg(),
00051               const RooCmdArg& arg4=RooCmdArg(),const RooCmdArg& arg5=RooCmdArg(),const RooCmdArg& arg6=RooCmdArg(),const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg()) ;
00052 
00053 
00054   RooDataHist(const RooDataHist& other, const char* newname = 0) ;
00055   virtual TObject* Clone(const char* newname=0) const { return new RooDataHist(*this,newname?newname:GetName()) ; }
00056   virtual ~RooDataHist() ;
00057 
00058   virtual RooAbsData* emptyClone(const char* newName=0, const char* newTitle=0, const RooArgSet*vars=0) const {
00059     // Return empty clone of this RooDataHist
00060     return new RooDataHist(newName?newName:GetName(),newTitle?newTitle:GetTitle(),vars?*vars:*get()) ; 
00061   }
00062 
00063   // Add one ore more rows of data
00064   virtual void add(const RooArgSet& row, Double_t wgt=1.0) { 
00065     // Increment weight of bin enclosing coordinate stored in row by wgt
00066     add(row,wgt,-1.) ; 
00067   }
00068   virtual void add(const RooArgSet& row, Double_t weight, Double_t sumw2) ;
00069   void set(Double_t weight, Double_t wgtErr=-1) ;
00070   void set(const RooArgSet& row, Double_t weight, Double_t wgtErr=-1) ;
00071   void set(const RooArgSet& row, Double_t weight, Double_t wgtErrLo, Double_t wgtErrHi) ;
00072 
00073   void add(const RooAbsData& dset, const RooFormulaVar* cutVar=0, Double_t weight=1.0 ) ;
00074   void add(const RooAbsData& dset, const char* cut, Double_t weight=1.0 ) ;
00075 
00076   virtual const RooArgSet* get() const { 
00077     // Return set with coordinates of center of current bin
00078     return &_vars ; 
00079   } 
00080   virtual const RooArgSet* get(Int_t masterIdx) const ;
00081   virtual const RooArgSet* get(const RooArgSet& coord) const ;
00082   virtual Int_t numEntries() const ; 
00083   virtual Double_t sumEntries(const char* cutSpec=0, const char* cutRange=0) const ;
00084   virtual Bool_t isWeighted() const { 
00085     // Return true as all histograms have in principle events weight != 1
00086     return kTRUE ;     
00087   }
00088   virtual Bool_t isNonPoissonWeighted() const ;
00089 
00090   Double_t sum(Bool_t correctForBinSize) const ;
00091   Double_t sum(const RooArgSet& sumSet, const RooArgSet& sliceSet, Bool_t correctForBinSize) ;
00092 
00093   virtual Double_t weight() const { 
00094     // Return weight of current bin
00095     return _curWeight ; 
00096   }
00097   Double_t weight(const RooArgSet& bin, Int_t intOrder=1, Bool_t correctForBinSize=kFALSE, Bool_t cdfBoundaries=kFALSE) ;   
00098   Double_t binVolume() const { return _curVolume ; }
00099   Double_t binVolume(const RooArgSet& bin) ; 
00100   virtual Bool_t valid() const ;
00101 
00102   TIterator* sliceIterator(RooAbsArg& sliceArg, const RooArgSet& otherArgs) ;
00103   
00104   virtual void weightError(Double_t& lo, Double_t& hi, ErrorType etype=Poisson) const ;
00105   virtual Double_t weightError(ErrorType etype=Poisson) const { 
00106     // Return symmetric error on current bin calculated either from Poisson statistics or from SumOfWeights
00107     Double_t lo,hi ;
00108     weightError(lo,hi,etype) ;
00109     return (lo+hi)/2 ;
00110   }
00111 
00112   using RooAbsData::plotOn ;
00113   virtual RooPlot *plotOn(RooPlot *frame, PlotOpt o) const;
00114   
00115   virtual void reset() ;
00116   void dump2() ;
00117 
00118   virtual void printMultiline(ostream& os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const ;
00119   virtual void printArgs(ostream& os) const ;
00120   virtual void printValue(ostream& os) const ;
00121 
00122   void SetName(const char *name) ;
00123   void SetNameTitle(const char *name, const char* title) ;
00124 
00125   Int_t getIndex(const RooArgSet& coord) ;
00126 
00127   void removeSelfFromDir() { removeFromDir(this) ; }
00128   
00129 protected:
00130 
00131   friend class RooAbsCachedPdf ;
00132   friend class RooAbsCachedReal ;
00133   friend class RooDataHistSliceIter ;
00134   friend class RooAbsOptTestStatistic ;
00135 
00136   Int_t calcTreeIndex() const ;
00137   void cacheValidEntries() ;
00138 
00139   void setAllWeights(Double_t value) ;
00140  
00141   void initialize(const char* binningName=0,Bool_t fillTree=kTRUE) ;
00142   RooDataHist(const char* name, const char* title, RooDataHist* h, const RooArgSet& varSubset, 
00143               const RooFormulaVar* cutVar, const char* cutRange, Int_t nStart, Int_t nStop, Bool_t copyCache) ;
00144   RooAbsData* reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=0, 
00145                         Int_t nStart=0, Int_t nStop=2000000000, Bool_t copyCache=kTRUE) ;
00146   Double_t interpolateDim(RooRealVar& dim, const RooAbsBinning* binning, Double_t xval, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries) ;
00147   void calculatePartialBinVolume(const RooArgSet& dimSet) const ;
00148 
00149   void adjustBinning(const RooArgList& vars, TH1& href, Int_t* offset=0) ;
00150   void importTH1(const RooArgList& vars, TH1& histo, Double_t initWgt, Bool_t doDensityCorrection) ;
00151   void importTH1Set(const RooArgList& vars, RooCategory& indexCat, std::map<std::string,TH1*> hmap, Double_t initWgt, Bool_t doDensityCorrection) ;
00152   void importDHistSet(const RooArgList& vars, RooCategory& indexCat, std::map<std::string,RooDataHist*> dmap, Double_t initWgt) ;
00153 
00154   virtual RooAbsData* cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName=0) ;
00155 
00156 
00157   Int_t       _arrSize ; //  Size of the weight array
00158   std::vector<Int_t> _idxMult ; // Multiplier jump table for index calculation
00159 
00160   Double_t*       _wgt ; //[_arrSize] Weight array
00161   Double_t*     _errLo ; //[_arrSize] Low-side error on weight array
00162   Double_t*     _errHi ; //[_arrSize] High-side error on weight array
00163   Double_t*     _sumw2 ; //[_arrSize] Sum of weights^2
00164   Double_t*      _binv ; //[_arrSize] Bin volume array  
00165 
00166   RooArgSet  _realVars ; // Real dimensions of the dataset 
00167   TIterator* _realIter ; //! Iterator over realVars
00168   Bool_t*    _binValid ; //! Valid bins with current range definition
00169  
00170   mutable Double_t _curWeight ; // Weight associated with the current coordinate
00171   mutable Double_t _curWgtErrLo ; // Error on weight associated with the current coordinate
00172   mutable Double_t _curWgtErrHi ; // Error on weight associated with the current coordinate
00173   mutable Double_t _curSumW2 ; // Current sum of weights^2
00174   mutable Double_t _curVolume ; // Volume of bin enclosing current coordinate
00175   mutable Int_t    _curIndex ; // Current index
00176 
00177   mutable std::vector<Double_t>* _pbinv ; //! Partial bin volume array
00178   mutable RooCacheManager<std::vector<Double_t> > _pbinvCacheMgr ; //! Cache manager for arrays of partial bin volumes
00179   std::list<RooAbsLValue*> _lvvars ; //! List of observables casted as RooAbsLValue
00180   std::list<const RooAbsBinning*> _lvbins ; //! List of used binnings associated with lvalues
00181 
00182 private:
00183 
00184   ClassDef(RooDataHist,4) // Binned data set
00185 };
00186 
00187 #endif
00188 

Generated on Tue Jul 5 14:26:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1