Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RooDataSet.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooDataSet.h,v 1.59 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_SET
17 #define ROO_DATA_SET
18 
19 class TDirectory ;
20 class RooAbsRealLValue ;
21 class RooRealVar ;
22 class RooDataHist ;
23 #include "RooAbsData.h"
24 #include "RooDirItem.h"
25 
26 
27 #define USEMEMPOOLFORDATASET
28 template <class RooSet_t, size_t>
29 class MemPoolForRooSets;
30 
31 class RooDataSet : public RooAbsData, public RooDirItem {
32 public:
33 
34 #ifdef USEMEMPOOLFORDATASET
35  void* operator new (size_t bytes);
36  void operator delete (void *ptr);
37 #endif
38 
39 
40  // Constructors, factory methods etc.
41  RooDataSet() ;
42 
43  // Empty constructor
44  RooDataSet(const char *name, const char *title, const RooArgSet& vars, const char* wgtVarName=0) ;
45 
46  // Universal constructor
47  RooDataSet(const char* name, const char* title, const RooArgSet& vars, const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg(),
48  const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),const RooCmdArg& arg5=RooCmdArg(),
49  const RooCmdArg& arg6=RooCmdArg(),const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg()) ;
50 
51  // Constructor for subset of existing dataset
52  RooDataSet(const char *name, const char *title, RooDataSet *data, const RooArgSet& vars,
53  const char *cuts=0, const char* wgtVarName=0);
54  RooDataSet(const char *name, const char *title, RooDataSet *data, const RooArgSet& vars,
55  const RooFormulaVar& cutVar, const char* wgtVarName=0) ;
56 
57 
58  // Constructor importing data from external ROOT Tree
59  RooDataSet(const char *name, const char *title, TTree *ntuple, const RooArgSet& vars,
60  const char *cuts=0, const char* wgtVarName=0);
61  RooDataSet(const char *name, const char *title, TTree *t, const RooArgSet& vars,
62  const RooFormulaVar& cutVar, const char* wgtVarName=0) ;
63 
64 
65  RooDataSet(RooDataSet const & other, const char* newname=0) ;
66  virtual TObject* Clone(const char* newname = "") const override {
67  return new RooDataSet(*this, newname && newname[0] != '\0' ? newname : GetName());
68  }
69  virtual ~RooDataSet() ;
70 
71  virtual RooAbsData* emptyClone(const char* newName=0, const char* newTitle=0, const RooArgSet* vars=0, const char* wgtVarName=0) const override;
72 
73  RooDataHist* binnedClone(const char* newName=0, const char* newTitle=0) const ;
74 
75  virtual Double_t sumEntries() const override;
76  virtual Double_t sumEntries(const char* cutSpec, const char* cutRange=0) const override;
77 
78  virtual RooPlot* plotOnXY(RooPlot* frame,
79  const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
80  const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
81  const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
82  const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) const ;
83 
84 
85  // Read data from a text file and create a dataset from it.
86  // The possible options are: (D)ebug, (Q)uiet.
87  static RooDataSet *read(const char *filename, const RooArgList &variables,
88  const char *opts= "", const char* commonPath="",
89  const char *indexCatName=0) ;
90  Bool_t write(const char* filename) const;
91  Bool_t write(std::ostream & ofs) const;
92 
93 /* void setWeightVar(const char* name=0) ; */
94 /* void setWeightVar(const RooAbsArg& arg) { */
95 /* // Interpret given argument as event weight */
96 /* setWeightVar(arg.GetName()) ; */
97 /* } */
98  virtual Bool_t isWeighted() const override;
99  virtual Bool_t isNonPoissonWeighted() const override;
100 
101  virtual Double_t weight() const override;
102  virtual Double_t weightSquared() const override;
103  virtual void weightError(Double_t& lo, Double_t& hi,ErrorType etype=SumW2) const override;
104  Double_t weightError(ErrorType etype=SumW2) const override;
105 
106  virtual const RooArgSet* get(Int_t index) const override;
107  virtual const RooArgSet* get() const override;
108 
109  virtual RooSpan<const double> getWeightBatch(std::size_t first, std::size_t last) const override;
110 
111  // Add one ore more rows of data
112  virtual void add(const RooArgSet& row, Double_t weight=1.0, Double_t weightError=0) override;
113  virtual void add(const RooArgSet& row, Double_t weight, Double_t weightErrorLo, Double_t weightErrorHi);
114 
115  virtual void addFast(const RooArgSet& row, Double_t weight=1.0, Double_t weightError=0);
116 
117  void append(RooDataSet& data) ;
118  Bool_t merge(RooDataSet* data1, RooDataSet* data2=0, RooDataSet* data3=0,
119  RooDataSet* data4=0, RooDataSet* data5=0, RooDataSet* data6=0) ;
120  Bool_t merge(std::list<RooDataSet*> dsetList) ;
121 
122  virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
123  virtual RooArgSet* addColumns(const RooArgList& varList) ;
124 
125  // Plot the distribution of a real valued arg
126  using RooAbsData::createHistogram ;
127  TH2F* createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, const char* cuts="",
128  const char *name= "hist") const;
129  TH2F* createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, Int_t nx, Int_t ny,
130  const char* cuts="", const char *name="hist") const;
131 
132  void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const override;
133  virtual void printArgs(std::ostream& os) const override;
134  virtual void printValue(std::ostream& os) const override;
135 
136  void SetName(const char *name) override;
137  void SetNameTitle(const char *name, const char* title) override;
138 
139  static void cleanup();
140 
141  void convertToTreeStore() override;
142 
143 protected:
144 
145  virtual RooAbsData* cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName=0) override;
146 
147  friend class RooProdGenContext ;
148 
149  void initialize(const char* wgtVarName) ;
150 
151  // Cache copy feature is not publicly accessible
152  RooAbsData* reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange=0,
153  Int_t nStart=0, Int_t nStop=2000000000, Bool_t copyCache=kTRUE) override;
154  RooDataSet(const char *name, const char *title, RooDataSet *ntuple,
155  const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange, int nStart, int nStop, Bool_t copyCache, const char* wgtVarName=0);
156 
157  RooArgSet addWgtVar(const RooArgSet& origVars, const RooAbsArg* wgtVar) ;
158 
159  RooArgSet _varsNoWgt ; // Vars without weight variable
160  RooRealVar* _wgtVar ; // Pointer to weight variable (if set)
161 
162 private:
163 #ifdef USEMEMPOOLFORDATASET
164  typedef MemPoolForRooSets<RooDataSet, 5*150> MemPool; // 150 = about 100kb
165  static MemPool * memPool();
166 #endif
167  unsigned short _errorMsgCount{0}; //! Counter to silence error messages when filling dataset.
168  bool _doWeightErrorCheck{true}; //! When adding events with weights, check that weights can actually be stored.
169 
170  ClassDefOverride(RooDataSet,2) // Unbinned data set
171 };
172 
173 #endif