ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooAbsData.h,v 1.33 2007/07/16 21:04:28 wouter Exp $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/
#ifndef ROO_ABS_DATA
#define ROO_ABS_DATA

#include "TNamed.h"
#include "RooPrintable.h"
#include "RooArgSet.h"
#include "RooFormulaVar.h"
#include <math.h>
#include "TMatrixDSym.h"

class RooAbsArg;
class RooAbsReal ;
class RooAbsCategory ;
class Roo1DTable ;
class RooPlot;
class RooArgList;
class TH1;
class RooAbsBinning ;
class Roo1DTable ;
class RooAbsDataStore ;

class RooAbsData : public TNamed, public RooPrintable {
public:

  // Constructors, factory methods etc.
  RooAbsData() ; 
  RooAbsData(const char *name, const char *title, const RooArgSet& vars, RooAbsDataStore* store=0) ;
  RooAbsData(const RooAbsData& other, const char* newname = 0) ;
  virtual ~RooAbsData() ;
  virtual RooAbsData* emptyClone(const char* newName=0, const char* newTitle=0, const RooArgSet* vars=0) const = 0 ;

  // Reduction methods
  RooAbsData* reduce(const RooCmdArg& arg1,const RooCmdArg& arg2=RooCmdArg(),const RooCmdArg& arg3=RooCmdArg(),const RooCmdArg& arg4=RooCmdArg(),
                     const RooCmdArg& arg5=RooCmdArg(),const RooCmdArg& arg6=RooCmdArg(),const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg()) ;
  RooAbsData* reduce(const char* cut) ;
  RooAbsData* reduce(const RooFormulaVar& cutVar) ;
  RooAbsData* reduce(const RooArgSet& varSubset, const char* cut=0) ;
  RooAbsData* reduce(const RooArgSet& varSubset, const RooFormulaVar& cutVar) ;

  RooAbsDataStore* store() { return _dstore ; }
  const RooAbsDataStore* store() const { return _dstore ; }
  const TTree* tree() const ;
  
  virtual void Draw(Option_t* option = "") ;

  void checkInit() const ; 

  // Change name of observable
  virtual Bool_t changeObservableName(const char* from, const char* to) ;

  // Add one ore more rows of data
  virtual void add(const RooArgSet& row, Double_t weight=1, Double_t weightError=0) = 0 ; // DERIVED
  virtual void fill() ; 

  // Load a given row of data
  virtual inline const RooArgSet* get() const { 
    // Return current row of dataset
    return &_vars ; 
  } 
  virtual Double_t weight() const = 0 ; // DERIVED
  virtual Bool_t valid() const { return kTRUE ; }
  enum ErrorType { Poisson, SumW2, None, Auto } ;
  virtual Double_t weightError(ErrorType etype=Poisson) const ;
  virtual void weightError(Double_t& lo, Double_t& hi, ErrorType etype=Poisson) const ; 
  virtual const RooArgSet* get(Int_t index) const ;

  virtual Int_t numEntries() const ;
  virtual Double_t sumEntries(const char* cutSpec=0, const char* cutRange=0) const = 0 ; // DERIVED
  virtual Bool_t isWeighted() const { 
    // Do events in dataset have weights?
    return kFALSE ; 
  }
  virtual Bool_t isNonPoissonWeighted() const { 
    // Do events in dataset have non-integer weights?
    return kFALSE ; 
  }
  virtual void reset() ;


  Bool_t getRange(RooRealVar& var, Double_t& lowest, Double_t& highest, Double_t marginFrac=0, Bool_t symMode=kFALSE) const ;

  // Plot the distribution of a real valued arg
  virtual Roo1DTable* table(const RooArgSet& catSet, const char* cuts="", const char* opts="") const ;
  virtual Roo1DTable* table(const RooAbsCategory& cat, const char* cuts="", const char* opts="") 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 ;

  virtual RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;

  // WVE --- This needs to be public to avoid CINT problems
  struct PlotOpt {
   PlotOpt() : cuts(""), drawOptions("P"), bins(0), etype(RooAbsData::Poisson), cutRange(0), histName(0), histInvisible(kFALSE),
              addToHistName(0),addToWgtSelf(1.),addToWgtOther(1.),xErrorSize(1),refreshFrameNorm(kFALSE),correctForBinWidth(kTRUE),
              scaleFactor(1.) {} ;
   const char* cuts ;
   Option_t* drawOptions ;
   RooAbsBinning* bins ;
   RooAbsData::ErrorType etype ;
   const char* cutRange ;
   const char* histName ;
   Bool_t histInvisible ;
   const char* addToHistName ;
   Double_t addToWgtSelf ;
   Double_t addToWgtOther ;
   Double_t xErrorSize ;
   Bool_t refreshFrameNorm ;
   Bool_t correctForBinWidth ;
   Double_t scaleFactor ;
  } ;
	
  // Split a dataset by a category
  virtual TList* split(const RooAbsCategory& splitCat, Bool_t createEmptyDataSets=kFALSE) const ;

  // Fast splitting for SimMaster setData
  Bool_t canSplitFast() const ; 
  RooAbsData* getSimData(const char* idxstate) ;
			
  // Create 1,2, and 3D histograms from and fill it
  TH1 *createHistogram(const char *name, const RooAbsRealLValue& xvar,
                       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 ;
  TH1* createHistogram(const char *name, const RooAbsRealLValue& xvar, const RooLinkedList& argList) const ;
  TH1 *createHistogram(const char* varNameList, Int_t xbins=0, Int_t ybins=0, Int_t zbins=0) const ;

  // Fill an existing histogram
  virtual TH1 *fillHistogram(TH1 *hist, const RooArgList &plotVars, const char *cuts= "", const char* cutRange=0) const;

  // Printing interface (human readable)
  inline virtual void Print(Option_t *options= 0) const {
    // Print contents on stdout
    printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
  }

  virtual void printName(ostream& os) const ;
  virtual void printTitle(ostream& os) const ;
  virtual void printClassName(ostream& os) const ;
  void printMultiline(ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;

  virtual Int_t defaultPrintContents(Option_t* opt) const ;

  void setDirtyProp(Bool_t flag) ;
  
  Double_t moment(RooRealVar &var, Double_t order, const char* cutSpec=0, const char* cutRange=0) const ;
  Double_t moment(RooRealVar &var, Double_t order, Double_t offset, const char* cutSpec=0, const char* cutRange=0) const ;
  Double_t standMoment(RooRealVar &var, Double_t order, const char* cutSpec=0, const char* cutRange=0) const ;

  Double_t mean(RooRealVar& var, const char* cutSpec=0, const char* cutRange=0) const { return moment(var,1,0,cutSpec,cutRange) ; }
  Double_t sigma(RooRealVar& var, const char* cutSpec=0, const char* cutRange=0) const { return sqrt(moment(var,2,cutSpec,cutRange)) ; }
  Double_t skewness(RooRealVar& var, const char* cutSpec=0, const char* cutRange=0) const { return standMoment(var,3,cutSpec,cutRange) ; }
  Double_t kurtosis(RooRealVar& var, const char* cutSpec=0, const char* cutRange=0) const { return standMoment(var,4,cutSpec,cutRange) ; }

  Double_t covariance(RooRealVar &x,RooRealVar &y, const char* cutSpec=0, const char* cutRange=0) const { return corrcov(x,y,cutSpec,cutRange,kFALSE) ; }
  Double_t correlation(RooRealVar &x,RooRealVar &y, const char* cutSpec=0, const char* cutRange=0) const { return corrcov(x,y,cutSpec,cutRange,kTRUE) ; }

  TMatrixDSym* covarianceMatrix(const char* cutSpec=0, const char* cutRange=0) const { return covarianceMatrix(*get(),cutSpec,cutRange) ; }
  TMatrixDSym* correlationMatrix(const char* cutSpec=0, const char* cutRange=0) const { return correlationMatrix(*get(),cutSpec,cutRange) ; }
  TMatrixDSym* covarianceMatrix(const RooArgList& vars, const char* cutSpec=0, const char* cutRange=0) const { return corrcovMatrix(vars,cutSpec,cutRange,kFALSE) ; }
  TMatrixDSym* correlationMatrix(const RooArgList& vars, const char* cutSpec=0, const char* cutRange=0) const { return corrcovMatrix(vars,cutSpec,cutRange,kTRUE) ; }
  
  RooRealVar* meanVar(RooRealVar &var, const char* cutSpec=0, const char* cutRange=0) const ;
  RooRealVar* rmsVar(RooRealVar &var, const char* cutSpec=0, const char* cutRange=0) const ;

  virtual RooPlot* statOn(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()) ;

  virtual RooPlot* statOn(RooPlot* frame, const char *what, 
			  const char *label= "", Int_t sigDigits= 2,
			  Option_t *options= "NELU", Double_t xmin=0.15, 
			  Double_t xmax= 0.65,Double_t ymax=0.85, 
                          const char* cutSpec=0, const char* cutRange=0, 
                          const RooCmdArg* formatCmd=0);



  Bool_t hasFilledCache() const ; 

  void addOwnedComponent(const char* idxlabel, RooAbsData& data) ;
  static void claimVars(RooAbsData*) ;
  static Bool_t releaseVars(RooAbsData*) ;

protected:

  Double_t corrcov(RooRealVar &x,RooRealVar &y, const char* cutSpec, const char* cutRange, Bool_t corr) const  ;
  TMatrixDSym* corrcovMatrix(const RooArgList& vars, const char* cutSpec, const char* cutRange, Bool_t corr) const  ;

  virtual void optimizeReadingWithCaching(RooAbsArg& arg, const RooArgSet& cacheList, const RooArgSet& keepObsList) ;
  Bool_t allClientsCached(RooAbsArg*, const RooArgSet&) ;


 // PlotOn implementation
  virtual RooPlot *plotOn(RooPlot *frame, PlotOpt o) const ;
  virtual RooPlot *plotAsymOn(RooPlot* frame, const RooAbsCategoryLValue& asymCat, PlotOpt o) const ;
  virtual RooPlot *plotEffOn(RooPlot* frame, const RooAbsCategoryLValue& effCat, PlotOpt o) const ;
 
 
  // Constant term optimizer interface
  friend class RooAbsArg ;
  friend class RooAbsReal ;
  friend class RooAbsOptTestStatistic ;
  friend class RooAbsCachedPdf ;

  virtual void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=0) ;
  virtual void resetCache() ;
  virtual void setArgStatus(const RooArgSet& set, Bool_t active) ;
  virtual void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) ;

  virtual RooAbsData* cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName=0) = 0 ; // DERIVED
  virtual RooAbsData* reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=0, 
	                        Int_t nStart=0, Int_t nStop=2000000000, Bool_t copyCache=kTRUE) = 0 ; // DERIVED

  RooRealVar* dataRealVar(const char* methodname, RooRealVar& extVar) const ;

  // Column structure definition
  RooArgSet _vars;         // Dimensions of this data set
  RooArgSet _cachedVars ;  //! External variables cached with this data set

  TIterator *_iterator;    //! Iterator over dimension variables
  TIterator *_cacheIter ;  //! Iterator over cached variables

  RooAbsDataStore* _dstore ; // Data storage implementation

  std::map<std::string,RooAbsData*> _ownedComponents ; // Owned external components

private:

  ClassDef(RooAbsData,4) // Abstract data collection
};

#endif
 RooAbsData.h:1
 RooAbsData.h:2
 RooAbsData.h:3
 RooAbsData.h:4
 RooAbsData.h:5
 RooAbsData.h:6
 RooAbsData.h:7
 RooAbsData.h:8
 RooAbsData.h:9
 RooAbsData.h:10
 RooAbsData.h:11
 RooAbsData.h:12
 RooAbsData.h:13
 RooAbsData.h:14
 RooAbsData.h:15
 RooAbsData.h:16
 RooAbsData.h:17
 RooAbsData.h:18
 RooAbsData.h:19
 RooAbsData.h:20
 RooAbsData.h:21
 RooAbsData.h:22
 RooAbsData.h:23
 RooAbsData.h:24
 RooAbsData.h:25
 RooAbsData.h:26
 RooAbsData.h:27
 RooAbsData.h:28
 RooAbsData.h:29
 RooAbsData.h:30
 RooAbsData.h:31
 RooAbsData.h:32
 RooAbsData.h:33
 RooAbsData.h:34
 RooAbsData.h:35
 RooAbsData.h:36
 RooAbsData.h:37
 RooAbsData.h:38
 RooAbsData.h:39
 RooAbsData.h:40
 RooAbsData.h:41
 RooAbsData.h:42
 RooAbsData.h:43
 RooAbsData.h:44
 RooAbsData.h:45
 RooAbsData.h:46
 RooAbsData.h:47
 RooAbsData.h:48
 RooAbsData.h:49
 RooAbsData.h:50
 RooAbsData.h:51
 RooAbsData.h:52
 RooAbsData.h:53
 RooAbsData.h:54
 RooAbsData.h:55
 RooAbsData.h:56
 RooAbsData.h:57
 RooAbsData.h:58
 RooAbsData.h:59
 RooAbsData.h:60
 RooAbsData.h:61
 RooAbsData.h:62
 RooAbsData.h:63
 RooAbsData.h:64
 RooAbsData.h:65
 RooAbsData.h:66
 RooAbsData.h:67
 RooAbsData.h:68
 RooAbsData.h:69
 RooAbsData.h:70
 RooAbsData.h:71
 RooAbsData.h:72
 RooAbsData.h:73
 RooAbsData.h:74
 RooAbsData.h:75
 RooAbsData.h:76
 RooAbsData.h:77
 RooAbsData.h:78
 RooAbsData.h:79
 RooAbsData.h:80
 RooAbsData.h:81
 RooAbsData.h:82
 RooAbsData.h:83
 RooAbsData.h:84
 RooAbsData.h:85
 RooAbsData.h:86
 RooAbsData.h:87
 RooAbsData.h:88
 RooAbsData.h:89
 RooAbsData.h:90
 RooAbsData.h:91
 RooAbsData.h:92
 RooAbsData.h:93
 RooAbsData.h:94
 RooAbsData.h:95
 RooAbsData.h:96
 RooAbsData.h:97
 RooAbsData.h:98
 RooAbsData.h:99
 RooAbsData.h:100
 RooAbsData.h:101
 RooAbsData.h:102
 RooAbsData.h:103
 RooAbsData.h:104
 RooAbsData.h:105
 RooAbsData.h:106
 RooAbsData.h:107
 RooAbsData.h:108
 RooAbsData.h:109
 RooAbsData.h:110
 RooAbsData.h:111
 RooAbsData.h:112
 RooAbsData.h:113
 RooAbsData.h:114
 RooAbsData.h:115
 RooAbsData.h:116
 RooAbsData.h:117
 RooAbsData.h:118
 RooAbsData.h:119
 RooAbsData.h:120
 RooAbsData.h:121
 RooAbsData.h:122
 RooAbsData.h:123
 RooAbsData.h:124
 RooAbsData.h:125
 RooAbsData.h:126
 RooAbsData.h:127
 RooAbsData.h:128
 RooAbsData.h:129
 RooAbsData.h:130
 RooAbsData.h:131
 RooAbsData.h:132
 RooAbsData.h:133
 RooAbsData.h:134
 RooAbsData.h:135
 RooAbsData.h:136
 RooAbsData.h:137
 RooAbsData.h:138
 RooAbsData.h:139
 RooAbsData.h:140
 RooAbsData.h:141
 RooAbsData.h:142
 RooAbsData.h:143
 RooAbsData.h:144
 RooAbsData.h:145
 RooAbsData.h:146
 RooAbsData.h:147
 RooAbsData.h:148
 RooAbsData.h:149
 RooAbsData.h:150
 RooAbsData.h:151
 RooAbsData.h:152
 RooAbsData.h:153
 RooAbsData.h:154
 RooAbsData.h:155
 RooAbsData.h:156
 RooAbsData.h:157
 RooAbsData.h:158
 RooAbsData.h:159
 RooAbsData.h:160
 RooAbsData.h:161
 RooAbsData.h:162
 RooAbsData.h:163
 RooAbsData.h:164
 RooAbsData.h:165
 RooAbsData.h:166
 RooAbsData.h:167
 RooAbsData.h:168
 RooAbsData.h:169
 RooAbsData.h:170
 RooAbsData.h:171
 RooAbsData.h:172
 RooAbsData.h:173
 RooAbsData.h:174
 RooAbsData.h:175
 RooAbsData.h:176
 RooAbsData.h:177
 RooAbsData.h:178
 RooAbsData.h:179
 RooAbsData.h:180
 RooAbsData.h:181
 RooAbsData.h:182
 RooAbsData.h:183
 RooAbsData.h:184
 RooAbsData.h:185
 RooAbsData.h:186
 RooAbsData.h:187
 RooAbsData.h:188
 RooAbsData.h:189
 RooAbsData.h:190
 RooAbsData.h:191
 RooAbsData.h:192
 RooAbsData.h:193
 RooAbsData.h:194
 RooAbsData.h:195
 RooAbsData.h:196
 RooAbsData.h:197
 RooAbsData.h:198
 RooAbsData.h:199
 RooAbsData.h:200
 RooAbsData.h:201
 RooAbsData.h:202
 RooAbsData.h:203
 RooAbsData.h:204
 RooAbsData.h:205
 RooAbsData.h:206
 RooAbsData.h:207
 RooAbsData.h:208
 RooAbsData.h:209
 RooAbsData.h:210
 RooAbsData.h:211
 RooAbsData.h:212
 RooAbsData.h:213
 RooAbsData.h:214
 RooAbsData.h:215
 RooAbsData.h:216
 RooAbsData.h:217
 RooAbsData.h:218
 RooAbsData.h:219
 RooAbsData.h:220
 RooAbsData.h:221
 RooAbsData.h:222
 RooAbsData.h:223
 RooAbsData.h:224
 RooAbsData.h:225
 RooAbsData.h:226
 RooAbsData.h:227
 RooAbsData.h:228
 RooAbsData.h:229
 RooAbsData.h:230
 RooAbsData.h:231
 RooAbsData.h:232
 RooAbsData.h:233
 RooAbsData.h:234
 RooAbsData.h:235
 RooAbsData.h:236
 RooAbsData.h:237
 RooAbsData.h:238
 RooAbsData.h:239
 RooAbsData.h:240
 RooAbsData.h:241
 RooAbsData.h:242
 RooAbsData.h:243
 RooAbsData.h:244
 RooAbsData.h:245
 RooAbsData.h:246
 RooAbsData.h:247
 RooAbsData.h:248
 RooAbsData.h:249
 RooAbsData.h:250
 RooAbsData.h:251
 RooAbsData.h:252