ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooDataSet.h,v 1.59 2007/05/11 09:11:30 verkerke 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_DATA_SET
#define ROO_DATA_SET

class TDirectory ;
class RooAbsRealLValue ;
class RooRealVar ;
class RooDataHist ;
#include "RooAbsData.h"
#include "RooDirItem.h"


class RooDataSet : public RooAbsData, public RooDirItem {
public:

  // Constructors, factory methods etc.
  RooDataSet() ; 

  // Empty constructor 
  RooDataSet(const char *name, const char *title, const RooArgSet& vars, const char* wgtVarName=0) ;

  // Universal constructor
  RooDataSet(const char* name, const char* title, const RooArgSet& vars, RooCmdArg arg1, RooCmdArg arg2=RooCmdArg(), 
	     RooCmdArg arg3=RooCmdArg(), RooCmdArg arg4=RooCmdArg(),RooCmdArg arg5=RooCmdArg(),
	     RooCmdArg arg6=RooCmdArg(),RooCmdArg arg7=RooCmdArg(),RooCmdArg arg8=RooCmdArg()) ; 

    // Constructor for subset of existing dataset
  RooDataSet(const char *name, const char *title, RooDataSet *data, const RooArgSet& vars, 
             const char *cuts=0, const char* wgtVarName=0);
  RooDataSet(const char *name, const char *title, RooDataSet *data, const RooArgSet& vars,  
	     const RooFormulaVar& cutVar, const char* wgtVarName=0) ;  


  // Constructor importing data from external ROOT Tree
  RooDataSet(const char *name, const char *title, TTree *ntuple, const RooArgSet& vars, 
	     const char *cuts=0, const char* wgtVarName=0); 
  RooDataSet(const char *name, const char *title, TTree *t, const RooArgSet& vars, 
	     const RooFormulaVar& cutVar, const char* wgtVarName=0) ;  
  

  RooDataSet(RooDataSet const & other, const char* newname=0) ;
  virtual TObject* Clone(const char* newname=0) const { return new RooDataSet(*this,newname?newname:GetName()) ; }
  virtual ~RooDataSet() ;

  virtual RooAbsData* emptyClone(const char* newName=0, const char* newTitle=0, const RooArgSet* vars=0) const ;

  RooDataHist* binnedClone(const char* newName=0, const char* newTitle=0) const ;

  virtual Double_t sumEntries(const char* cutSpec=0, const char* cutRange=0) const ;

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


  // Read data from a text file and create a dataset from it.
  // The possible options are: (D)ebug, (Q)uiet.
  static RooDataSet *read(const char *filename, const RooArgList &variables,
			  const char *opts= "", const char* commonPath="",
			  const char *indexCatName=0) ;
  Bool_t write(const char* filename) ;

  void setWeightVar(const char* name=0) ;
  void setWeightVar(const RooAbsArg& arg) { 
    // Interpret given argument as event weight
    setWeightVar(arg.GetName()) ; 
  }

  virtual Bool_t isWeighted() const ;
  virtual Bool_t isNonPoissonWeighted() const ;

  virtual Double_t weight() const ; 
  virtual void weightError(Double_t& lo, Double_t& hi,ErrorType etype=SumW2) const ;
  Double_t weightError(ErrorType etype=SumW2) const ;

  virtual const RooArgSet* get(Int_t index) const;
  virtual const RooArgSet* get() const ; 

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

  virtual void addFast(const RooArgSet& row, Double_t weight=1.0, Double_t weightError=0);

  void append(RooDataSet& data) ;
  Bool_t merge(RooDataSet* data1, RooDataSet* data2=0, RooDataSet* data3=0,  
 	       RooDataSet* data4=0, RooDataSet* data5=0, RooDataSet* data6=0) ; 
  Bool_t merge(std::list<RooDataSet*> dsetList) ;

  virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
  virtual RooArgSet* addColumns(const RooArgList& varList) ;

  // Plot the distribution of a real valued arg
  using RooAbsData::createHistogram ;
  TH2F* createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, const char* cuts="", 
			const char *name= "hist") const;	 
  TH2F* createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, Int_t nx, Int_t ny,
                        const char* cuts="", const char *name="hist") const;

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

  void SetName(const char *name) ;
  void SetNameTitle(const char *name, const char* title) ;

protected:

  virtual RooAbsData* cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName=0) ;

  friend class RooProdGenContext ;

  void initialize(const char* wgtVarName) ;
  
  // Cache copy feature is not publicly accessible
  RooAbsData* reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=0, 
	                Int_t nStart=0, Int_t nStop=2000000000, Bool_t copyCache=kTRUE) ;
  RooDataSet(const char *name, const char *title, RooDataSet *ntuple, 
	     const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange, int nStart, int nStop, Bool_t copyCache, const char* wgtVarName=0);
  
  RooArgSet addWgtVar(const RooArgSet& origVars, const RooAbsArg* wgtVar) ; 
  
  RooArgSet _varsNoWgt ;   // Vars without weight variable 
  RooRealVar* _wgtVar ;    // Pointer to weight variable (if set) 

  ClassDef(RooDataSet,2) // Unbinned data set
};

#endif
 RooDataSet.h:1
 RooDataSet.h:2
 RooDataSet.h:3
 RooDataSet.h:4
 RooDataSet.h:5
 RooDataSet.h:6
 RooDataSet.h:7
 RooDataSet.h:8
 RooDataSet.h:9
 RooDataSet.h:10
 RooDataSet.h:11
 RooDataSet.h:12
 RooDataSet.h:13
 RooDataSet.h:14
 RooDataSet.h:15
 RooDataSet.h:16
 RooDataSet.h:17
 RooDataSet.h:18
 RooDataSet.h:19
 RooDataSet.h:20
 RooDataSet.h:21
 RooDataSet.h:22
 RooDataSet.h:23
 RooDataSet.h:24
 RooDataSet.h:25
 RooDataSet.h:26
 RooDataSet.h:27
 RooDataSet.h:28
 RooDataSet.h:29
 RooDataSet.h:30
 RooDataSet.h:31
 RooDataSet.h:32
 RooDataSet.h:33
 RooDataSet.h:34
 RooDataSet.h:35
 RooDataSet.h:36
 RooDataSet.h:37
 RooDataSet.h:38
 RooDataSet.h:39
 RooDataSet.h:40
 RooDataSet.h:41
 RooDataSet.h:42
 RooDataSet.h:43
 RooDataSet.h:44
 RooDataSet.h:45
 RooDataSet.h:46
 RooDataSet.h:47
 RooDataSet.h:48
 RooDataSet.h:49
 RooDataSet.h:50
 RooDataSet.h:51
 RooDataSet.h:52
 RooDataSet.h:53
 RooDataSet.h:54
 RooDataSet.h:55
 RooDataSet.h:56
 RooDataSet.h:57
 RooDataSet.h:58
 RooDataSet.h:59
 RooDataSet.h:60
 RooDataSet.h:61
 RooDataSet.h:62
 RooDataSet.h:63
 RooDataSet.h:64
 RooDataSet.h:65
 RooDataSet.h:66
 RooDataSet.h:67
 RooDataSet.h:68
 RooDataSet.h:69
 RooDataSet.h:70
 RooDataSet.h:71
 RooDataSet.h:72
 RooDataSet.h:73
 RooDataSet.h:74
 RooDataSet.h:75
 RooDataSet.h:76
 RooDataSet.h:77
 RooDataSet.h:78
 RooDataSet.h:79
 RooDataSet.h:80
 RooDataSet.h:81
 RooDataSet.h:82
 RooDataSet.h:83
 RooDataSet.h:84
 RooDataSet.h:85
 RooDataSet.h:86
 RooDataSet.h:87
 RooDataSet.h:88
 RooDataSet.h:89
 RooDataSet.h:90
 RooDataSet.h:91
 RooDataSet.h:92
 RooDataSet.h:93
 RooDataSet.h:94
 RooDataSet.h:95
 RooDataSet.h:96
 RooDataSet.h:97
 RooDataSet.h:98
 RooDataSet.h:99
 RooDataSet.h:100
 RooDataSet.h:101
 RooDataSet.h:102
 RooDataSet.h:103
 RooDataSet.h:104
 RooDataSet.h:105
 RooDataSet.h:106
 RooDataSet.h:107
 RooDataSet.h:108
 RooDataSet.h:109
 RooDataSet.h:110
 RooDataSet.h:111
 RooDataSet.h:112
 RooDataSet.h:113
 RooDataSet.h:114
 RooDataSet.h:115
 RooDataSet.h:116
 RooDataSet.h:117
 RooDataSet.h:118
 RooDataSet.h:119
 RooDataSet.h:120
 RooDataSet.h:121
 RooDataSet.h:122
 RooDataSet.h:123
 RooDataSet.h:124
 RooDataSet.h:125
 RooDataSet.h:126
 RooDataSet.h:127
 RooDataSet.h:128
 RooDataSet.h:129
 RooDataSet.h:130
 RooDataSet.h:131
 RooDataSet.h:132
 RooDataSet.h:133
 RooDataSet.h:134
 RooDataSet.h:135
 RooDataSet.h:136
 RooDataSet.h:137
 RooDataSet.h:138
 RooDataSet.h:139
 RooDataSet.h:140
 RooDataSet.h:141
 RooDataSet.h:142
 RooDataSet.h:143
 RooDataSet.h:144
 RooDataSet.h:145