Logo ROOT   6.14/05
Reference Guide
RooDataHist.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
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 
17 /**
18 \file RooDataHist.cxx
19 \class RooDataHist
20 \ingroup Roofitcore
21 
22 RooDataSet is a container class to hold N-dimensional binned data. Each bins central
23 coordinates in N-dimensional space are represented by a RooArgSet of RooRealVar, RooCategory
24 or RooStringVar objects, thus data can be binned in real and/or discrete dimensions
25 **/
26 
27 #include "RooFit.h"
28 #include "Riostream.h"
29 
30 #include "TH1.h"
31 #include "TH1.h"
32 #include "TDirectory.h"
33 #include "TMath.h"
34 #include "RooMsgService.h"
35 #include "RooDataHist.h"
36 #include "RooDataHistSliceIter.h"
37 #include "RooAbsLValue.h"
38 #include "RooArgList.h"
39 #include "RooRealVar.h"
40 #include "RooMath.h"
41 #include "RooBinning.h"
42 #include "RooPlot.h"
43 #include "RooHistError.h"
44 #include "RooCategory.h"
45 #include "RooCmdConfig.h"
46 #include "RooLinkedListIter.h"
47 #include "RooTreeDataStore.h"
48 #include "RooVectorDataStore.h"
49 #include "TTree.h"
50 #include "RooTrace.h"
51 #include "RooTreeData.h"
52 
53 using namespace std ;
54 
56 ;
57 
58 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Default constructor
62 
63 RooDataHist::RooDataHist() : _pbinvCacheMgr(0,10)
64 {
65  _arrSize = 0 ;
66  _wgt = 0 ;
67  _errLo = 0 ;
68  _errHi = 0 ;
69  _sumw2 = 0 ;
70  _binv = 0 ;
71  _pbinv = 0 ;
72  _curWeight = 0 ;
73  _curIndex = -1 ;
75  _binValid = 0 ;
76  _curSumW2 = 0 ;
77  _curVolume = 1 ;
78  _curWgtErrHi = 0 ;
79  _curWgtErrLo = 0 ;
80  _cache_sum_valid = 0 ;
82 }
83 
84 
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// Constructor of an empty data hist from a RooArgSet defining the dimensions
88 /// of the data space. The range and number of bins in each dimensions are taken
89 /// from getMin()getMax(),getBins() of each RooAbsArg representing that
90 /// dimension.
91 ///
92 /// For real dimensions, the fit range and number of bins can be set independently
93 /// of the plot range and number of bins, but it is advisable to keep the
94 /// ratio of the plot bin width and the fit bin width an integer value.
95 /// For category dimensions, the fit ranges always comprises all defined states
96 /// and each state is always has its individual bin
97 ///
98 /// To effective achive binning of real dimensions with variable bins sizes,
99 /// construct a RooThresholdCategory of the real dimension to be binned variably.
100 /// Set the thresholds at the desired bin boundaries, and construct the
101 /// data hist as function of the threshold category instead of the real variable.
102 
103 RooDataHist::RooDataHist(const char *name, const char *title, const RooArgSet& vars, const char* binningName) :
104  RooAbsData(name,title,vars), _wgt(0), _binValid(0), _curWeight(0), _curVolume(1), _pbinv(0), _pbinvCacheMgr(0,10), _cache_sum_valid(0)
105 {
106  // Initialize datastore
108  ((RooAbsDataStore*) new RooVectorDataStore(name,title,_vars)) ;
109 
110  initialize(binningName) ;
111 
113 
114  appendToDir(this,kTRUE) ;
116 }
117 
118 
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Constructor of a data hist from an existing data collection (binned or unbinned)
122 /// The RooArgSet 'vars' defines the dimensions of the histogram.
123 /// The range and number of bins in each dimensions are taken
124 /// from getMin()getMax(),getBins() of each RooAbsArg representing that
125 /// dimension.
126 ///
127 /// For real dimensions, the fit range and number of bins can be set independently
128 /// of the plot range and number of bins, but it is advisable to keep the
129 /// ratio of the plot bin width and the fit bin width an integer value.
130 /// For category dimensions, the fit ranges always comprises all defined states
131 /// and each state is always has its individual bin
132 ///
133 /// To effective achive binning of real dimensions with variable bins sizes,
134 /// construct a RooThresholdCategory of the real dimension to be binned variably.
135 /// Set the thresholds at the desired bin boundaries, and construct the
136 /// data hist as function of the threshold category instead of the real variable.
137 ///
138 /// If the constructed data hist has less dimensions that in source data collection,
139 /// all missing dimensions will be projected.
140 
141 RooDataHist::RooDataHist(const char *name, const char *title, const RooArgSet& vars, const RooAbsData& data, Double_t wgt) :
142  RooAbsData(name,title,vars), _wgt(0), _binValid(0), _curWeight(0), _curVolume(1), _pbinv(0), _pbinvCacheMgr(0,10), _cache_sum_valid(0)
143 {
144  // Initialize datastore
146  ((RooAbsDataStore*) new RooVectorDataStore(name,title,_vars)) ;
147 
148  initialize() ;
150 
151  add(data,(const RooFormulaVar*)0,wgt) ;
152  appendToDir(this,kTRUE) ;
154 }
155 
156 
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// Constructor of a data hist from a map of TH1,TH2 or TH3 that are collated into a x+1 dimensional
160 /// RooDataHist where the added dimension is a category that labels the input source as defined
161 /// in the histMap argument. The state names used in histMap must correspond to predefined states
162 /// 'indexCat'
163 ///
164 /// The RooArgList 'vars' defines the dimensions of the histogram.
165 /// The ranges and number of bins are taken from the input histogram and must be the same in all histograms
166 
167 RooDataHist::RooDataHist(const char *name, const char *title, const RooArgList& vars, RooCategory& indexCat,
168  map<string,TH1*> histMap, Double_t wgt) :
169  RooAbsData(name,title,RooArgSet(vars,&indexCat)),
171 {
172  // Initialize datastore
174  ((RooAbsDataStore*) new RooVectorDataStore(name,title,_vars)) ;
175 
176  importTH1Set(vars, indexCat, histMap, wgt, kFALSE) ;
177 
180 }
181 
182 
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Constructor of a data hist from a map of RooDataHists that are collated into a x+1 dimensional
186 /// RooDataHist where the added dimension is a category that labels the input source as defined
187 /// in the histMap argument. The state names used in histMap must correspond to predefined states
188 /// 'indexCat'
189 ///
190 /// The RooArgList 'vars' defines the dimensions of the histogram.
191 /// The ranges and number of bins are taken from the input histogram and must be the same in all histograms
192 
193 RooDataHist::RooDataHist(const char *name, const char *title, const RooArgList& vars, RooCategory& indexCat,
194  map<string,RooDataHist*> dhistMap, Double_t wgt) :
195  RooAbsData(name,title,RooArgSet(vars,&indexCat)),
197 {
198  // Initialize datastore
200  ((RooAbsDataStore*) new RooVectorDataStore(name,title,_vars)) ;
201 
202  importDHistSet(vars, indexCat, dhistMap, wgt) ;
203 
206 }
207 
208 
209 
210 ////////////////////////////////////////////////////////////////////////////////
211 /// Constructor of a data hist from an TH1,TH2 or TH3
212 /// The RooArgSet 'vars' defines the dimensions of the histogram. The ranges
213 /// and number of bins are taken from the input histogram, and the corresponding
214 /// values are set accordingly on the arguments in 'vars'
215 
216 RooDataHist::RooDataHist(const char *name, const char *title, const RooArgList& vars, const TH1* hist, Double_t wgt) :
217  RooAbsData(name,title,vars), _wgt(0), _binValid(0), _curWeight(0), _curVolume(1), _pbinv(0), _pbinvCacheMgr(0,10), _cache_sum_valid(0)
218 {
219  // Initialize datastore
221  ((RooAbsDataStore*) new RooVectorDataStore(name,title,_vars)) ;
222 
223  // Check consistency in number of dimensions
224  if (vars.getSize() != hist->GetDimension()) {
225  coutE(InputArguments) << "RooDataHist::ctor(" << GetName() << ") ERROR: dimension of input histogram must match "
226  << "number of dimension variables" << endl ;
227  assert(0) ;
228  }
229 
230  importTH1(vars,*hist,wgt, kFALSE) ;
231 
234 }
235 
236 
237 
238 ////////////////////////////////////////////////////////////////////////////////
239 /// Constructor of a binned dataset from a RooArgSet defining the dimensions
240 /// of the data space. The range and number of bins in each dimensions are taken
241 /// from getMin() getMax(),getBins() of each RooAbsArg representing that
242 /// dimension.
243 ///
244 /// This constructor takes the following optional arguments
245 ///
246 /// Import(TH1&, Bool_t impDens) -- Import contents of the given TH1/2/3 into this binned dataset. The
247 /// ranges and binning of the binned dataset are automatically adjusted to
248 /// match those of the imported histogram.
249 ///
250 /// Please note: for TH1& with unequal binning _only_,
251 /// you should decide if you want to import the absolute bin content,
252 /// or the bin content expressed as density. The latter is default and will
253 /// result in the same histogram as the original TH1. For certain type of
254 /// bin contents (containing efficiencies, asymmetries, or ratio is general)
255 /// you should import the absolute value and set impDens to kFALSE
256 ///
257 ///
258 /// Weight(Double_t) -- Apply given weight factor when importing histograms
259 ///
260 /// Index(RooCategory&) -- Prepare import of multiple TH1/1/2/3 into a N+1 dimensional RooDataHist
261 /// where the extra discrete dimension labels the source of the imported histogram
262 /// If the index category defines states for which no histogram is be imported
263 /// the corresponding bins will be left empty.
264 ///
265 /// Import(const char*, TH1&) -- Import a THx to be associated with the given state name of the index category
266 /// specified in Index(). If the given state name is not yet defined in the index
267 /// category it will be added on the fly. The import command can be specified
268 /// multiple times.
269 /// Import(map<string,TH1*>&) -- As above, but allows specification of many imports in a single operation
270 ///
271 
272 RooDataHist::RooDataHist(const char *name, const char *title, const RooArgList& vars, const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3,
273  const RooCmdArg& arg4,const RooCmdArg& arg5,const RooCmdArg& arg6,const RooCmdArg& arg7,const RooCmdArg& arg8) :
274  RooAbsData(name,title,RooArgSet(vars,(RooAbsArg*)RooCmdConfig::decodeObjOnTheFly("RooDataHist::RooDataHist", "IndexCat",0,0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8))),
276 {
277  // Initialize datastore
279  ((RooAbsDataStore*) new RooVectorDataStore(name,title,_vars)) ;
280 
281  // Define configuration for this method
282  RooCmdConfig pc(Form("RooDataHist::ctor(%s)",GetName())) ;
283  pc.defineObject("impHist","ImportHisto",0) ;
284  pc.defineInt("impDens","ImportHisto",0) ;
285  pc.defineObject("indexCat","IndexCat",0) ;
286  pc.defineObject("impSliceHist","ImportHistoSlice",0,0,kTRUE) ; // array
287  pc.defineString("impSliceState","ImportHistoSlice",0,"",kTRUE) ; // array
288  pc.defineObject("impSliceDHist","ImportDataHistSlice",0,0,kTRUE) ; // array
289  pc.defineString("impSliceDState","ImportDataHistSlice",0,"",kTRUE) ; // array
290  pc.defineDouble("weight","Weight",0,1) ;
291  pc.defineObject("dummy1","ImportDataHistSliceMany",0) ;
292  pc.defineObject("dummy2","ImportHistoSliceMany",0) ;
293  pc.defineMutex("ImportHisto","ImportHistoSlice","ImportDataHistSlice") ;
294  pc.defineDependency("ImportHistoSlice","IndexCat") ;
295  pc.defineDependency("ImportDataHistSlice","IndexCat") ;
296 
297  RooLinkedList l ;
298  l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
299  l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
300  l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
301  l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
302 
303  // Process & check varargs
304  pc.process(l) ;
305  if (!pc.ok(kTRUE)) {
306  assert(0) ;
307  return ;
308  }
309 
310  TH1* impHist = static_cast<TH1*>(pc.getObject("impHist")) ;
311  Bool_t impDens = pc.getInt("impDens") ;
312  Double_t initWgt = pc.getDouble("weight") ;
313  const char* impSliceNames = pc.getString("impSliceState","",kTRUE) ;
314  const RooLinkedList& impSliceHistos = pc.getObjectList("impSliceHist") ;
315  RooCategory* indexCat = static_cast<RooCategory*>(pc.getObject("indexCat")) ;
316  const char* impSliceDNames = pc.getString("impSliceDState","",kTRUE) ;
317  const RooLinkedList& impSliceDHistos = pc.getObjectList("impSliceDHist") ;
318 
319 
320  if (impHist) {
321 
322  // Initialize importing contents from TH1
323  importTH1(vars,*impHist,initWgt, impDens) ;
324 
325  } else if (indexCat) {
326 
327 
328  if (impSliceHistos.GetSize()>0) {
329 
330  // Initialize importing mapped set of TH1s
331  map<string,TH1*> hmap ;
332  char tmp[1024] ;
333  strlcpy(tmp,impSliceNames,1024) ;
334  char* token = strtok(tmp,",") ;
335  TIterator* hiter = impSliceHistos.MakeIterator() ;
336  while(token) {
337  hmap[token] = (TH1*) hiter->Next() ;
338  token = strtok(0,",") ;
339  }
340  importTH1Set(vars,*indexCat,hmap,initWgt,kFALSE) ;
341  } else {
342 
343  // Initialize importing mapped set of RooDataHists
344  map<string,RooDataHist*> dmap ;
345  char tmp[1024] ;
346  strlcpy(tmp,impSliceDNames,1024) ;
347  char* token = strtok(tmp,",") ;
348  TIterator* hiter = impSliceDHistos.MakeIterator() ;
349  while(token) {
350  dmap[token] = (RooDataHist*) hiter->Next() ;
351  token = strtok(0,",") ;
352  }
353  importDHistSet(vars,*indexCat,dmap,initWgt) ;
354 
355  }
356 
357 
358  } else {
359 
360  // Initialize empty
361  initialize() ;
362  appendToDir(this,kTRUE) ;
363 
364  }
365 
368 
369 }
370 
371 
372 
373 
374 ////////////////////////////////////////////////////////////////////////////////
375 /// Import data from given TH1/2/3 into this RooDataHist
376 
377 void RooDataHist::importTH1(const RooArgList& vars, const TH1& histo, Double_t wgt, Bool_t doDensityCorrection)
378 {
379  // Adjust binning of internal observables to match that of input THx
380  Int_t offset[3] ;
381  adjustBinning(vars,histo,offset) ;
382 
383  // Initialize internal data structure
384  initialize() ;
385  appendToDir(this,kTRUE) ;
386 
387  // Define x,y,z as 1st, 2nd and 3rd observable
388  RooRealVar* xvar = (RooRealVar*) _vars.find(vars.at(0)->GetName()) ;
389  RooRealVar* yvar = (RooRealVar*) (vars.at(1) ? _vars.find(vars.at(1)->GetName()) : 0 ) ;
390  RooRealVar* zvar = (RooRealVar*) (vars.at(2) ? _vars.find(vars.at(2)->GetName()) : 0 ) ;
391 
392  // Transfer contents
393  Int_t xmin(0),ymin(0),zmin(0) ;
394  RooArgSet vset(*xvar) ;
395  Double_t volume = xvar->getMax()-xvar->getMin() ;
396  xmin = offset[0] ;
397  if (yvar) {
398  vset.add(*yvar) ;
399  ymin = offset[1] ;
400  volume *= (yvar->getMax()-yvar->getMin()) ;
401  }
402  if (zvar) {
403  vset.add(*zvar) ;
404  zmin = offset[2] ;
405  volume *= (zvar->getMax()-zvar->getMin()) ;
406  }
407  //Double_t avgBV = volume / numEntries() ;
408 // cout << "average bin volume = " << avgBV << endl ;
409 
410  Int_t ix(0),iy(0),iz(0) ;
411  for (ix=0 ; ix < xvar->getBins() ; ix++) {
412  xvar->setBin(ix) ;
413  if (yvar) {
414  for (iy=0 ; iy < yvar->getBins() ; iy++) {
415  yvar->setBin(iy) ;
416  if (zvar) {
417  for (iz=0 ; iz < zvar->getBins() ; iz++) {
418  zvar->setBin(iz) ;
419  Double_t bv = doDensityCorrection ? binVolume(vset) : 1;
420  add(vset,bv*histo.GetBinContent(ix+1+xmin,iy+1+ymin,iz+1+zmin)*wgt,bv*TMath::Power(histo.GetBinError(ix+1+xmin,iy+1+ymin,iz+1+zmin)*wgt,2)) ;
421  }
422  } else {
423  Double_t bv = doDensityCorrection ? binVolume(vset) : 1;
424  add(vset,bv*histo.GetBinContent(ix+1+xmin,iy+1+ymin)*wgt,bv*TMath::Power(histo.GetBinError(ix+1+xmin,iy+1+ymin)*wgt,2)) ;
425  }
426  }
427  } else {
428  Double_t bv = doDensityCorrection ? binVolume(vset) : 1 ;
429  add(vset,bv*histo.GetBinContent(ix+1+xmin)*wgt,bv*TMath::Power(histo.GetBinError(ix+1+xmin)*wgt,2)) ;
430  }
431  }
432 
433 }
434 
435 
436 
437 
438 
439 ////////////////////////////////////////////////////////////////////////////////
440 /// Import data from given set of TH1/2/3 into this RooDataHist. The category indexCat labels the sources
441 /// in the constructed RooDataHist. The stl map provides the mapping between the indexCat state labels
442 /// and the import source
443 
444 void RooDataHist::importTH1Set(const RooArgList& vars, RooCategory& indexCat, map<string,TH1*> hmap, Double_t wgt, Bool_t doDensityCorrection)
445 {
446  RooCategory* icat = (RooCategory*) _vars.find(indexCat.GetName()) ;
447 
448  TH1* histo(0) ;
449  Bool_t init(kFALSE) ;
450  for (map<string,TH1*>::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) {
451  // Store pointer to first histogram from which binning specification will be taken
452  if (!histo) {
453  histo = hiter->second ;
454  }
455  // Define state labels in index category (both in provided indexCat and in internal copy in dataset)
456  if (!indexCat.lookupType(hiter->first.c_str())) {
457  indexCat.defineType(hiter->first.c_str()) ;
458  coutI(InputArguments) << "RooDataHist::importTH1Set(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat.GetName() << endl ;
459  }
460  if (!icat->lookupType(hiter->first.c_str())) {
461  icat->defineType(hiter->first.c_str()) ;
462  }
463  }
464 
465  // Check consistency in number of dimensions
466  if (histo && (vars.getSize() != histo->GetDimension())) {
467  coutE(InputArguments) << "RooDataHist::ctor(" << GetName() << ") ERROR: dimension of input histogram must match "
468  << "number of continuous variables" << endl ;
469  assert(0) ;
470  }
471 
472  // Copy bins and ranges from THx to dimension observables
473  Int_t offset[3] ;
474  adjustBinning(vars,*histo,offset) ;
475 
476  // Initialize internal data structure
477  if (!init) {
478  initialize() ;
479  appendToDir(this,kTRUE) ;
480  init = kTRUE ;
481  }
482 
483  // Define x,y,z as 1st, 2nd and 3rd observable
484  RooRealVar* xvar = (RooRealVar*) _vars.find(vars.at(0)->GetName()) ;
485  RooRealVar* yvar = (RooRealVar*) (vars.at(1) ? _vars.find(vars.at(1)->GetName()) : 0 ) ;
486  RooRealVar* zvar = (RooRealVar*) (vars.at(2) ? _vars.find(vars.at(2)->GetName()) : 0 ) ;
487 
488  // Transfer contents
489  Int_t xmin(0),ymin(0),zmin(0) ;
490  RooArgSet vset(*xvar) ;
491  Double_t volume = xvar->getMax()-xvar->getMin() ;
492  xmin = offset[0] ;
493  if (yvar) {
494  vset.add(*yvar) ;
495  ymin = offset[1] ;
496  volume *= (yvar->getMax()-yvar->getMin()) ;
497  }
498  if (zvar) {
499  vset.add(*zvar) ;
500  zmin = offset[2] ;
501  volume *= (zvar->getMax()-zvar->getMin()) ;
502  }
503  Double_t avgBV = volume / numEntries() ;
504 
505  Int_t ic(0),ix(0),iy(0),iz(0) ;
506  for (ic=0 ; ic < icat->numBins(0) ; ic++) {
507  icat->setBin(ic) ;
508  histo = hmap[icat->getLabel()] ;
509  for (ix=0 ; ix < xvar->getBins() ; ix++) {
510  xvar->setBin(ix) ;
511  if (yvar) {
512  for (iy=0 ; iy < yvar->getBins() ; iy++) {
513  yvar->setBin(iy) ;
514  if (zvar) {
515  for (iz=0 ; iz < zvar->getBins() ; iz++) {
516  zvar->setBin(iz) ;
517  Double_t bv = doDensityCorrection ? binVolume(vset)/avgBV : 1;
518  add(vset,bv*histo->GetBinContent(ix+1+xmin,iy+1+ymin,iz+1+zmin)*wgt,bv*TMath::Power(histo->GetBinError(ix+1+xmin,iy+1+ymin,iz+1+zmin)*wgt,2)) ;
519  }
520  } else {
521  Double_t bv = doDensityCorrection ? binVolume(vset)/avgBV : 1;
522  add(vset,bv*histo->GetBinContent(ix+1+xmin,iy+1+ymin)*wgt,bv*TMath::Power(histo->GetBinError(ix+1+xmin,iy+1+ymin)*wgt,2)) ;
523  }
524  }
525  } else {
526  Double_t bv = doDensityCorrection ? binVolume(vset)/avgBV : 1;
527  add(vset,bv*histo->GetBinContent(ix+1+xmin)*wgt,bv*TMath::Power(histo->GetBinError(ix+1+xmin)*wgt,2)) ;
528  }
529  }
530  }
531 
532 }
533 
534 
535 
536 ////////////////////////////////////////////////////////////////////////////////
537 /// Import data from given set of TH1/2/3 into this RooDataHist. The category indexCat labels the sources
538 /// in the constructed RooDataHist. The stl map provides the mapping between the indexCat state labels
539 /// and the import source
540 
541 void RooDataHist::importDHistSet(const RooArgList& /*vars*/, RooCategory& indexCat, std::map<std::string,RooDataHist*> dmap, Double_t initWgt)
542 {
543  RooCategory* icat = (RooCategory*) _vars.find(indexCat.GetName()) ;
544 
545  for (map<string,RooDataHist*>::iterator diter = dmap.begin() ; diter!=dmap.end() ; ++diter) {
546 
547  // Define state labels in index category (both in provided indexCat and in internal copy in dataset)
548  if (!indexCat.lookupType(diter->first.c_str())) {
549  indexCat.defineType(diter->first.c_str()) ;
550  coutI(InputArguments) << "RooDataHist::importDHistSet(" << GetName() << ") defining state \"" << diter->first << "\" in index category " << indexCat.GetName() << endl ;
551  }
552  if (!icat->lookupType(diter->first.c_str())) {
553  icat->defineType(diter->first.c_str()) ;
554  }
555  }
556 
557  initialize() ;
558  appendToDir(this,kTRUE) ;
559 
560 
561  for (map<string,RooDataHist*>::iterator diter = dmap.begin() ; diter!=dmap.end() ; ++diter) {
562 
563  RooDataHist* dhist = diter->second ;
564 
565  icat->setLabel(diter->first.c_str()) ;
566 
567  // Transfer contents
568  for (Int_t i=0 ; i<dhist->numEntries() ; i++) {
569  _vars = *dhist->get(i) ;
570  add(_vars,dhist->weight()*initWgt, pow(dhist->weightError(SumW2),2) ) ;
571  }
572 
573  }
574 }
575 
576 ////////////////////////////////////////////////////////////////////////////////
577 /// Adjust binning specification on first and optionally second and third
578 /// observable to binning in given reference TH1. Used by constructors
579 /// that import data from an external TH1
580 
581 void RooDataHist::adjustBinning(const RooArgList& vars, const TH1& href, Int_t* offset)
582 {
583  // X
584  RooRealVar* xvar = (RooRealVar*) _vars.find(*vars.at(0)) ;
585  if (!dynamic_cast<RooRealVar*>(xvar)) {
586  coutE(InputArguments) << "RooDataHist::adjustBinning(" << GetName() << ") ERROR: dimension " << xvar->GetName() << " must be real" << endl ;
587  assert(0) ;
588  }
589 
590  Double_t xlo = ((RooRealVar*)vars.at(0))->getMin() ;
591  Double_t xhi = ((RooRealVar*)vars.at(0))->getMax() ;
592  Int_t xmin(0) ;
593  if (href.GetXaxis()->GetXbins()->GetArray()) {
594 
595  RooBinning xbins(href.GetNbinsX(),href.GetXaxis()->GetXbins()->GetArray()) ;
596 
597  Double_t tolerance = 1e-6*xbins.averageBinWidth() ;
598 
599  // Adjust xlo/xhi to nearest boundary
600  Double_t xloAdj = xbins.binLow(xbins.binNumber(xlo+tolerance)) ;
601  Double_t xhiAdj = xbins.binHigh(xbins.binNumber(xhi-tolerance)) ;
602  xbins.setRange(xloAdj,xhiAdj) ;
603 
604  ((RooRealVar*)vars.at(0))->setBinning(xbins) ;
605  if (fabs(xloAdj-xlo)>tolerance||fabs(xhiAdj-xhi)<tolerance) {
606  coutI(DataHandling) << "RooDataHist::adjustBinning(" << GetName() << "): fit range of variable " << xvar->GetName() << " expanded to nearest bin boundaries: ["
607  << xlo << "," << xhi << "] --> [" << xloAdj << "," << xhiAdj << "]" << endl ;
608  }
609 
610  xvar->setBinning(xbins) ;
611  xmin = xbins.rawBinNumber(xloAdj+tolerance) ;
612  if (offset) {
613  offset[0] = xmin ;
614  }
615 
616  } else {
617 
618  RooBinning xbins(href.GetXaxis()->GetXmin(),href.GetXaxis()->GetXmax()) ;
619  xbins.addUniform(href.GetNbinsX(),href.GetXaxis()->GetXmin(),href.GetXaxis()->GetXmax()) ;
620 
621  Double_t tolerance = 1e-6*xbins.averageBinWidth() ;
622 
623  // Adjust xlo/xhi to nearest boundary
624  Double_t xloAdj = xbins.binLow(xbins.binNumber(xlo+tolerance)) ;
625  Double_t xhiAdj = xbins.binHigh(xbins.binNumber(xhi-tolerance)) ;
626  xbins.setRange(xloAdj,xhiAdj) ;
627  ((RooRealVar*)vars.at(0))->setRange(xloAdj,xhiAdj) ;
628  if (fabs(xloAdj-xlo)>tolerance||fabs(xhiAdj-xhi)<tolerance) {
629  coutI(DataHandling) << "RooDataHist::adjustBinning(" << GetName() << "): fit range of variable " << xvar->GetName() << " expanded to nearest bin boundaries: ["
630  << xlo << "," << xhi << "] --> [" << xloAdj << "," << xhiAdj << "]" << endl ;
631  }
632 
633 
634  RooUniformBinning xbins2(xloAdj,xhiAdj,xbins.numBins()) ;
635  xvar->setBinning(xbins2) ;
636  xmin = xbins.rawBinNumber(xloAdj+tolerance) ;
637  if (offset) {
638  offset[0] = xmin ;
639  }
640  }
641 
642 
643 
644  // Y
645  RooRealVar* yvar = (RooRealVar*) (vars.at(1) ? _vars.find(*vars.at(1)) : 0 ) ;
646  Int_t ymin(0) ;
647  if (yvar) {
648  Double_t ylo = ((RooRealVar*)vars.at(1))->getMin() ;
649  Double_t yhi = ((RooRealVar*)vars.at(1))->getMax() ;
650 
651  if (!dynamic_cast<RooRealVar*>(yvar)) {
652  coutE(InputArguments) << "RooDataHist::adjustBinning(" << GetName() << ") ERROR: dimension " << yvar->GetName() << " must be real" << endl ;
653  assert(0) ;
654  }
655 
656  if (href.GetYaxis()->GetXbins()->GetArray()) {
657 
658  RooBinning ybins(href.GetNbinsY(),href.GetYaxis()->GetXbins()->GetArray()) ;
659 
660  Double_t tolerance = 1e-6*ybins.averageBinWidth() ;
661 
662  // Adjust ylo/yhi to nearest boundary
663  Double_t yloAdj = ybins.binLow(ybins.binNumber(ylo+tolerance)) ;
664  Double_t yhiAdj = ybins.binHigh(ybins.binNumber(yhi-tolerance)) ;
665  ybins.setRange(yloAdj,yhiAdj) ;
666  ((RooRealVar*)vars.at(1))->setBinning(ybins) ;
667  if (fabs(yloAdj-ylo)>tolerance||fabs(yhiAdj-yhi)<tolerance) {
668  coutI(DataHandling) << "RooDataHist::adjustBinning(" << GetName() << "): fit range of variable " << yvar->GetName() << " expanded to nearest bin boundaries: ["
669  << ylo << "," << yhi << "] --> [" << yloAdj << "," << yhiAdj << "]" << endl ;
670  }
671 
672  yvar->setBinning(ybins) ;
673  ymin = ybins.rawBinNumber(yloAdj+tolerance) ;
674  if (offset) {
675  offset[1] = ymin ;
676  }
677 
678  } else {
679 
680  RooBinning ybins(href.GetYaxis()->GetXmin(),href.GetYaxis()->GetXmax()) ;
681  ybins.addUniform(href.GetNbinsY(),href.GetYaxis()->GetXmin(),href.GetYaxis()->GetXmax()) ;
682 
683  Double_t tolerance = 1e-6*ybins.averageBinWidth() ;
684 
685  // Adjust ylo/yhi to nearest boundary
686  Double_t yloAdj = ybins.binLow(ybins.binNumber(ylo+tolerance)) ;
687  Double_t yhiAdj = ybins.binHigh(ybins.binNumber(yhi-tolerance)) ;
688  ybins.setRange(yloAdj,yhiAdj) ;
689  ((RooRealVar*)vars.at(1))->setRange(yloAdj,yhiAdj) ;
690  if (fabs(yloAdj-ylo)>tolerance||fabs(yhiAdj-yhi)<tolerance) {
691  coutI(DataHandling) << "RooDataHist::adjustBinning(" << GetName() << "): fit range of variable " << yvar->GetName() << " expanded to nearest bin boundaries: ["
692  << ylo << "," << yhi << "] --> [" << yloAdj << "," << yhiAdj << "]" << endl ;
693  }
694 
695  RooUniformBinning ybins2(yloAdj,yhiAdj,ybins.numBins()) ;
696  yvar->setBinning(ybins2) ;
697  ymin = ybins.rawBinNumber(yloAdj+tolerance) ;
698  if (offset) {
699  offset[1] = ymin ;
700  }
701 
702  }
703  }
704 
705  // Z
706  RooRealVar* zvar = (RooRealVar*) (vars.at(2) ? _vars.find(*vars.at(2)) : 0 ) ;
707  Int_t zmin(0) ;
708  if (zvar) {
709  Double_t zlo = ((RooRealVar*)vars.at(2))->getMin() ;
710  Double_t zhi = ((RooRealVar*)vars.at(2))->getMax() ;
711 
712  if (!dynamic_cast<RooRealVar*>(zvar)) {
713  coutE(InputArguments) << "RooDataHist::adjustBinning(" << GetName() << ") ERROR: dimension " << zvar->GetName() << " must be real" << endl ;
714  assert(0) ;
715  }
716 
717  if (href.GetZaxis()->GetXbins()->GetArray()) {
718 
719  RooBinning zbins(href.GetNbinsZ(),href.GetZaxis()->GetXbins()->GetArray()) ;
720 
721  Double_t tolerance = 1e-6*zbins.averageBinWidth() ;
722 
723  // Adjust zlo/zhi to nearest boundary
724  Double_t zloAdj = zbins.binLow(zbins.binNumber(zlo+tolerance)) ;
725  Double_t zhiAdj = zbins.binHigh(zbins.binNumber(zhi-tolerance)) ;
726  zbins.setRange(zloAdj,zhiAdj) ;
727  ((RooRealVar*)vars.at(2))->setBinning(zbins) ;
728  if (fabs(zloAdj-zlo)>tolerance||fabs(zhiAdj-zhi)<tolerance) {
729  coutI(DataHandling) << "RooDataHist::adjustBinning(" << GetName() << "): fit range of variable " << zvar->GetName() << " expanded to nearest bin boundaries: ["
730  << zlo << "," << zhi << "] --> [" << zloAdj << "," << zhiAdj << "]" << endl ;
731  }
732 
733  zvar->setBinning(zbins) ;
734  zmin = zbins.rawBinNumber(zloAdj+tolerance) ;
735  if (offset) {
736  offset[2] = zmin ;
737  }
738 
739  } else {
740 
741  RooBinning zbins(href.GetZaxis()->GetXmin(),href.GetZaxis()->GetXmax()) ;
742  zbins.addUniform(href.GetNbinsZ(),href.GetZaxis()->GetXmin(),href.GetZaxis()->GetXmax()) ;
743 
744  Double_t tolerance = 1e-6*zbins.averageBinWidth() ;
745 
746  // Adjust zlo/zhi to nearest boundary
747  Double_t zloAdj = zbins.binLow(zbins.binNumber(zlo+tolerance)) ;
748  Double_t zhiAdj = zbins.binHigh(zbins.binNumber(zhi-tolerance)) ;
749  zbins.setRange(zloAdj,zhiAdj) ;
750  ((RooRealVar*)vars.at(2))->setRange(zloAdj,zhiAdj) ;
751  if (fabs(zloAdj-zlo)>tolerance||fabs(zhiAdj-zhi)<tolerance) {
752  coutI(DataHandling) << "RooDataHist::adjustBinning(" << GetName() << "): fit range of variable " << zvar->GetName() << " expanded to nearest bin boundaries: ["
753  << zlo << "," << zhi << "] --> [" << zloAdj << "," << zhiAdj << "]" << endl ;
754  }
755 
756  RooUniformBinning zbins2(zloAdj,zhiAdj,zbins.numBins()) ;
757  zvar->setBinning(zbins2) ;
758  zmin = zbins.rawBinNumber(zloAdj+tolerance) ;
759  if (offset) {
760  offset[2] = zmin ;
761  }
762  }
763  }
764 
765 }
766 
767 
768 
769 
770 
771 ////////////////////////////////////////////////////////////////////////////////
772 /// Initialization procedure: allocate weights array, calculate
773 /// multipliers needed for N-space to 1-dim array jump table,
774 /// and fill the internal tree with all bin center coordinates
775 
776 void RooDataHist::initialize(const char* binningName, Bool_t fillTree)
777 {
778 
779  // Save real dimensions of dataset separately
780  RooAbsArg* real ;
781  _iterator->Reset() ;
782  while((real=(RooAbsArg*)_iterator->Next())) {
783  if (dynamic_cast<RooAbsReal*>(real)) _realVars.add(*real);
784  }
786 
787  // Fill array of LValue pointers to variables
788  _iterator->Reset();
789  RooAbsArg* rvarg;
790  while((rvarg=(RooAbsArg*)_iterator->Next())) {
791  if (binningName) {
792  RooRealVar* rrv = dynamic_cast<RooRealVar*>(rvarg);
793  if (rrv) {
794  rrv->setBinning(rrv->getBinning(binningName));
795  }
796  }
797  // coverity[FORWARD_NULL]
798  _lvvars.push_back(dynamic_cast<RooAbsLValue*>(rvarg));
799  // coverity[FORWARD_NULL]
800  const RooAbsBinning* binning = dynamic_cast<RooAbsLValue*>(rvarg)->getBinningPtr(0);
801  _lvbins.push_back(binning ? binning->clone() : 0);
802  }
803 
804 
805  // Allocate coefficients array
806  _idxMult.resize(_vars.getSize()) ;
807 
808  _arrSize = 1 ;
809  _iterator->Reset() ;
810  RooAbsLValue* arg ;
811  Int_t n(0), i ;
812  while((arg=dynamic_cast<RooAbsLValue*>(_iterator->Next()))) {
813 
814  // Calculate sub-index multipliers for master index
815  for (i=0 ; i<n ; i++) {
816  _idxMult[i] *= arg->numBins() ;
817  }
818  _idxMult[n++] = 1 ;
819 
820  // Calculate dimension of weight array
821  _arrSize *= arg->numBins() ;
822  }
823 
824  // Allocate and initialize weight array if necessary
825  if (!_wgt) {
826  _wgt = new Double_t[_arrSize] ;
827  _errLo = new Double_t[_arrSize] ;
828  _errHi = new Double_t[_arrSize] ;
829  _sumw2 = new Double_t[_arrSize] ;
830  _binv = new Double_t[_arrSize] ;
831 
832  // Refill array pointers in data store when reading
833  // from Streamer
834  if (fillTree==kFALSE) {
836  }
837 
838  for (i=0 ; i<_arrSize ; i++) {
839  _wgt[i] = 0 ;
840  _errLo[i] = -1 ;
841  _errHi[i] = -1 ;
842  _sumw2[i] = 0 ;
843  }
844  }
845 
846  if (!fillTree) return ;
847 
848  // Fill TTree with bin center coordinates
849  // Calculate plot bins of components from master index
850 
851  Int_t ibin ;
852  for (ibin=0 ; ibin<_arrSize ; ibin++) {
853  _iterator->Reset() ;
854  RooAbsLValue* arg2 ;
855  Int_t j(0), idx(0), tmp(ibin) ;
856  Double_t theBinVolume(1) ;
857  while((arg2=dynamic_cast<RooAbsLValue*>(_iterator->Next()))) {
858  idx = tmp / _idxMult[j] ;
859  tmp -= idx*_idxMult[j++] ;
860  RooAbsLValue* arglv = dynamic_cast<RooAbsLValue*>(arg2) ;
861  arglv->setBin(idx) ;
862  theBinVolume *= arglv->getBinWidth(idx) ;
863 // cout << "init: bin width at idx=" << idx << " = " << arglv->getBinWidth(idx) << " binv[" << idx << "] = " << theBinVolume << endl ;
864  }
865  _binv[ibin] = theBinVolume ;
866 // cout << "binv[" << ibin << "] = " << theBinVolume << endl ;
867  fill() ;
868  }
869 
870 
871 }
872 
873 
874 ////////////////////////////////////////////////////////////////////////////////
875 
877 {
878  if (!_binbounds.empty()) return;
879  for (std::vector<const RooAbsBinning*>::const_iterator it = _lvbins.begin();
880  _lvbins.end() != it; ++it) {
881  _binbounds.push_back(std::vector<Double_t>());
882  if (*it) {
883  std::vector<Double_t>& bounds = _binbounds.back();
884  bounds.reserve(2 * (*it)->numBins());
885  for (Int_t i = 0; i < (*it)->numBins(); ++i) {
886  bounds.push_back((*it)->binLow(i));
887  bounds.push_back((*it)->binHigh(i));
888  }
889  }
890  }
891 }
892 
893 ////////////////////////////////////////////////////////////////////////////////
894 /// Copy constructor
895 
896 RooDataHist::RooDataHist(const RooDataHist& other, const char* newname) :
898 {
899  Int_t i ;
900 
901  // Allocate and initialize weight array
902  _arrSize = other._arrSize ;
903  _wgt = new Double_t[_arrSize] ;
904  _errLo = new Double_t[_arrSize] ;
905  _errHi = new Double_t[_arrSize] ;
906  _binv = new Double_t[_arrSize] ;
907  _sumw2 = new Double_t[_arrSize] ;
908  for (i=0 ; i<_arrSize ; i++) {
909  _wgt[i] = other._wgt[i] ;
910  _errLo[i] = other._errLo[i] ;
911  _errHi[i] = other._errHi[i] ;
912  _sumw2[i] = other._sumw2[i] ;
913  _binv[i] = other._binv[i] ;
914  }
915 
916  // Save real dimensions of dataset separately
917  RooAbsArg* arg ;
918  _iterator->Reset() ;
919  while((arg=(RooAbsArg*)_iterator->Next())) {
920  if (dynamic_cast<RooAbsReal*>(arg)) _realVars.add(*arg) ;
921  }
923 
924  // Fill array of LValue pointers to variables
925  _iterator->Reset() ;
926  RooAbsArg* rvarg ;
927  while((rvarg=(RooAbsArg*)_iterator->Next())) {
928  // coverity[FORWARD_NULL]
929  _lvvars.push_back(dynamic_cast<RooAbsLValue*>(rvarg)) ;
930  // coverity[FORWARD_NULL]
931  const RooAbsBinning* binning = dynamic_cast<RooAbsLValue*>(rvarg)->getBinningPtr(0) ;
932  _lvbins.push_back(binning ? binning->clone() : 0) ;
933  }
934 
936 
937  appendToDir(this,kTRUE) ;
938 }
939 
940 
941 
942 ////////////////////////////////////////////////////////////////////////////////
943 /// Constructor of a data hist from (part of) an existing data hist. The dimensions
944 /// of the data set are defined by the 'vars' RooArgSet, which can be identical
945 /// to 'dset' dimensions, or a subset thereof. Reduced dimensions will be projected
946 /// in the output data hist. The optional 'cutVar' formula variable can used to
947 /// select the subset of bins to be copied.
948 ///
949 /// For most uses the RooAbsData::reduce() wrapper function, which uses this constructor,
950 /// is the most convenient way to create a subset of an existing data
951 
952 RooDataHist::RooDataHist(const char* name, const char* title, RooDataHist* h, const RooArgSet& varSubset,
953  const RooFormulaVar* cutVar, const char* cutRange, Int_t nStart, Int_t nStop, Bool_t copyCache) :
954  RooAbsData(name,title,varSubset),
956 {
957  // Initialize datastore
958  _dstore = new RooTreeDataStore(name,title,*h->_dstore,_vars,cutVar,cutRange,nStart,nStop,copyCache) ;
959 
960  initialize(0,kFALSE) ;
961 
963 
964  // Copy weight array etc
965  Int_t i ;
966  for (i=0 ; i<_arrSize ; i++) {
967  _wgt[i] = h->_wgt[i] ;
968  _errLo[i] = h->_errLo[i] ;
969  _errHi[i] = h->_errHi[i] ;
970  _sumw2[i] = h->_sumw2[i] ;
971  _binv[i] = h->_binv[i] ;
972  }
973 
974 
975  appendToDir(this,kTRUE) ;
977 }
978 
979 
980 ////////////////////////////////////////////////////////////////////////////////
981 /// Construct a clone of this dataset that contains only the cached variables
982 
983 RooAbsData* RooDataHist::cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName)
984 {
985  checkInit() ;
986 
987  RooDataHist* dhist = new RooDataHist(newName?newName:GetName(),GetTitle(),this,*get(),0,0,0,2000000000,kTRUE) ;
988 
989  RooArgSet* selCacheVars = (RooArgSet*) newCacheVars->selectCommon(dhist->_cachedVars) ;
990  dhist->attachCache(newCacheOwner, *selCacheVars) ;
991  delete selCacheVars ;
992 
993  return dhist ;
994 }
995 
996 
997 
998 ////////////////////////////////////////////////////////////////////////////////
999 /// Implementation of RooAbsData virtual method that drives the RooAbsData::reduce() methods
1000 
1001 RooAbsData* RooDataHist::reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange,
1002  Int_t nStart, Int_t nStop, Bool_t /*copyCache*/)
1003 {
1004  checkInit() ;
1005  RooArgSet* myVarSubset = (RooArgSet*) _vars.selectCommon(varSubset) ;
1006  RooDataHist *rdh = new RooDataHist(GetName(), GetTitle(), *myVarSubset) ;
1007  delete myVarSubset ;
1008 
1009  RooFormulaVar* cloneVar = 0;
1010  RooArgSet* tmp(0) ;
1011  if (cutVar) {
1012  // Deep clone cutVar and attach clone to this dataset
1013  tmp = (RooArgSet*) RooArgSet(*cutVar).snapshot() ;
1014  if (!tmp) {
1015  coutE(DataHandling) << "RooDataHist::reduceEng(" << GetName() << ") Couldn't deep-clone cut variable, abort," << endl ;
1016  return 0 ;
1017  }
1018  cloneVar = (RooFormulaVar*) tmp->find(*cutVar) ;
1019  cloneVar->attachDataSet(*this) ;
1020  }
1021 
1022  Int_t i ;
1023  Double_t lo,hi ;
1024  Int_t nevt = nStop < numEntries() ? nStop : numEntries() ;
1025  TIterator* vIter = get()->createIterator() ;
1026  for (i=nStart ; i<nevt ; i++) {
1027  const RooArgSet* row = get(i) ;
1028 
1029  Bool_t doSelect(kTRUE) ;
1030  if (cutRange) {
1031  RooAbsArg* arg ;
1032  vIter->Reset() ;
1033  while((arg=(RooAbsArg*)vIter->Next())) {
1034  if (!arg->inRange(cutRange)) {
1035  doSelect = kFALSE ;
1036  break ;
1037  }
1038  }
1039  }
1040  if (!doSelect) continue ;
1041 
1042  if (!cloneVar || cloneVar->getVal()) {
1043  weightError(lo,hi,SumW2) ;
1044  rdh->add(*row,weight(),lo*lo) ;
1045  }
1046  }
1047  delete vIter ;
1048 
1049  if (cloneVar) {
1050  delete tmp ;
1051  }
1052 
1053  return rdh ;
1054  }
1055 
1056 
1057 
1058 ////////////////////////////////////////////////////////////////////////////////
1059 /// Destructor
1060 
1062 {
1063  if (_wgt) delete[] _wgt ;
1064  if (_errLo) delete[] _errLo ;
1065  if (_errHi) delete[] _errHi ;
1066  if (_sumw2) delete[] _sumw2 ;
1067  if (_binv) delete[] _binv ;
1068  if (_realIter) delete _realIter ;
1069  if (_binValid) delete[] _binValid ;
1070  vector<const RooAbsBinning*>::iterator iter = _lvbins.begin() ;
1071  while(iter!=_lvbins.end()) {
1072  delete *iter ;
1073  ++iter ;
1074  }
1075 
1076  removeFromDir(this) ;
1078 }
1079 
1080 
1081 
1082 
1083 ////////////////////////////////////////////////////////////////////////////////
1084 
1086 {
1087  checkInit() ;
1088  if (fast) {
1089  _vars.assignFast(coord,kFALSE) ;
1090  } else {
1091  _vars.assignValueOnly(coord) ;
1092  }
1093  return calcTreeIndex() ;
1094 }
1095 
1096 
1097 
1098 
1099 ////////////////////////////////////////////////////////////////////////////////
1100 /// Calculate the index for the weights array corresponding to
1101 /// to the bin enclosing the current coordinates of the internal argset
1102 
1104 {
1105  Int_t masterIdx(0), i(0) ;
1106  vector<RooAbsLValue*>::const_iterator iter = _lvvars.begin() ;
1107  vector<const RooAbsBinning*>::const_iterator biter = _lvbins.begin() ;
1108  for (;iter!=_lvvars.end() ; ++iter) {
1109  const RooAbsBinning* binning = (*biter) ;
1110  masterIdx += _idxMult[i++]*(*iter)->getBin(binning) ;
1111  ++biter ;
1112  }
1113  return masterIdx ;
1114 }
1115 
1116 
1117 
1118 ////////////////////////////////////////////////////////////////////////////////
1119 /// Debug stuff, should go...
1120 
1122 {
1123  cout << "_arrSize = " << _arrSize << endl ;
1124  for (Int_t i=0 ; i<_arrSize ; i++) {
1125  cout << "wgt[" << i << "] = " << _wgt[i] << "sumw2[" << i << "] = " << _sumw2[i] << " vol[" << i << "] = " << _binv[i] << endl ;
1126  }
1127 }
1128 
1129 
1130 
1131 ////////////////////////////////////////////////////////////////////////////////
1132 /// Back end function to plotting functionality. Plot RooDataHist on given
1133 /// frame in mode specified by plot options 'o'. The main purpose of
1134 /// this function is to match the specified binning on 'o' to the
1135 /// internal binning of the plot observable in this RooDataHist.
1136 
1138 {
1139  checkInit() ;
1140  if (o.bins) return RooAbsData::plotOn(frame,o) ;
1141 
1142  if(0 == frame) {
1143  coutE(InputArguments) << ClassName() << "::" << GetName() << ":plotOn: frame is null" << endl;
1144  return 0;
1145  }
1146  RooAbsRealLValue *var= (RooAbsRealLValue*) frame->getPlotVar();
1147  if(0 == var) {
1148  coutE(InputArguments) << ClassName() << "::" << GetName()
1149  << ":plotOn: frame does not specify a plot variable" << endl;
1150  return 0;
1151  }
1152 
1153  RooRealVar* dataVar = (RooRealVar*) _vars.find(*var) ;
1154  if (!dataVar) {
1155  coutE(InputArguments) << ClassName() << "::" << GetName()
1156  << ":plotOn: dataset doesn't contain plot frame variable" << endl;
1157  return 0;
1158  }
1159 
1160  o.bins = &dataVar->getBinning() ;
1162  return RooAbsData::plotOn(frame,o) ;
1163 }
1164 
1165 
1166 
1167 
1168 ////////////////////////////////////////////////////////////////////////////////
1169 
1171  return _curSumW2 ;
1172 }
1173 
1174 
1175 
1176 ////////////////////////////////////////////////////////////////////////////////
1177 /// Return the weight at given coordinates with optional
1178 /// interpolation. If intOrder is zero, the weight
1179 /// for the bin enclosing the coordinates
1180 /// contained in 'bin' is returned. For higher values,
1181 /// the result is interpolated in the real dimensions
1182 /// of the dataset
1183 
1184 Double_t RooDataHist::weight(const RooArgSet& bin, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries, Bool_t oneSafe)
1185 {
1186  //cout << "RooDataHist::weight(" << bin << "," << intOrder << "," << correctForBinSize << "," << cdfBoundaries << "," << oneSafe << ")" << endl ;
1187 
1188  checkInit() ;
1189 
1190  // Handle illegal intOrder values
1191  if (intOrder<0) {
1192  coutE(InputArguments) << "RooDataHist::weight(" << GetName() << ") ERROR: interpolation order must be positive" << endl ;
1193  return 0 ;
1194  }
1195 
1196  // Handle no-interpolation case
1197  if (intOrder==0) {
1198  _vars.assignValueOnly(bin,oneSafe) ;
1199  Int_t idx = calcTreeIndex() ;
1200  //cout << "intOrder 0, idx = " << idx << endl ;
1201  if (correctForBinSize) {
1202  //calculatePartialBinVolume(*get()) ;
1203  //cout << "binw[" << idx << "] = " << _wgt[idx] << " / " << _binv[idx] << endl ;
1204  return get_wgt(idx) / _binv[idx];
1205  } else {
1206  //cout << "binw[" << idx << "] = " << _wgt[idx] << endl ;
1207  return get_wgt(idx);
1208  }
1209  }
1210 
1211  // Handle all interpolation cases
1212  _vars.assignValueOnly(bin) ;
1213 
1214  Double_t wInt(0) ;
1215  if (_realVars.getSize()==1) {
1216 
1217  // 1-dimensional interpolation
1218  RooFIter realIter = _realVars.fwdIterator() ;
1219  RooRealVar* real=(RooRealVar*)realIter.next() ;
1220  const RooAbsBinning* binning = real->getBinningPtr(0) ;
1221  wInt = interpolateDim(*real,binning,((RooAbsReal*)bin.find(*real))->getVal(), intOrder, correctForBinSize, cdfBoundaries) ;
1222 
1223  } else if (_realVars.getSize()==2) {
1224 
1225  // 2-dimensional interpolation
1226  RooFIter realIter = _realVars.fwdIterator() ;
1227  RooRealVar* realX=(RooRealVar*)realIter.next() ;
1228  RooRealVar* realY=(RooRealVar*)realIter.next() ;
1229  Double_t xval = ((RooAbsReal*)bin.find(*realX))->getVal() ;
1230  Double_t yval = ((RooAbsReal*)bin.find(*realY))->getVal() ;
1231 
1232  Int_t ybinC = realY->getBin() ;
1233  Int_t ybinLo = ybinC-intOrder/2 - ((yval<realY->getBinning().binCenter(ybinC))?1:0) ;
1234  Int_t ybinM = realY->numBins() ;
1235 
1236  Int_t i ;
1237  Double_t yarr[10] ;
1238  Double_t xarr[10] ;
1239  const RooAbsBinning* binning = realX->getBinningPtr(0) ;
1240  for (i=ybinLo ; i<=intOrder+ybinLo ; i++) {
1241  Int_t ibin ;
1242  if (i>=0 && i<ybinM) {
1243  // In range
1244  ibin = i ;
1245  realY->setBin(ibin) ;
1246  xarr[i-ybinLo] = realY->getVal() ;
1247  } else if (i>=ybinM) {
1248  // Overflow: mirror
1249  ibin = 2*ybinM-i-1 ;
1250  realY->setBin(ibin) ;
1251  xarr[i-ybinLo] = 2*realY->getMax()-realY->getVal() ;
1252  } else {
1253  // Underflow: mirror
1254  ibin = -i -1;
1255  realY->setBin(ibin) ;
1256  xarr[i-ybinLo] = 2*realY->getMin()-realY->getVal() ;
1257  }
1258  yarr[i-ybinLo] = interpolateDim(*realX,binning,xval,intOrder,correctForBinSize,kFALSE) ;
1259  }
1260 
1261  if (gDebug>7) {
1262  cout << "RooDataHist interpolating data is" << endl ;
1263  cout << "xarr = " ;
1264  for (int q=0; q<=intOrder ; q++) cout << xarr[q] << " " ;
1265  cout << " yarr = " ;
1266  for (int q=0; q<=intOrder ; q++) cout << yarr[q] << " " ;
1267  cout << endl ;
1268  }
1269  wInt = RooMath::interpolate(xarr,yarr,intOrder+1,yval) ;
1270 
1271  } else {
1272 
1273  // Higher dimensional scenarios not yet implemented
1274  coutE(InputArguments) << "RooDataHist::weight(" << GetName() << ") interpolation in "
1275  << _realVars.getSize() << " dimensions not yet implemented" << endl ;
1276  return weight(bin,0) ;
1277 
1278  }
1279 
1280  // Cut off negative values
1281 // if (wInt<=0) {
1282 // wInt=0 ;
1283 // }
1284 
1285  //cout << "RooDataHist wInt = " << wInt << endl ;
1286  return wInt ;
1287 }
1288 
1289 
1290 
1291 
1292 ////////////////////////////////////////////////////////////////////////////////
1293 /// Return the error on current weight
1294 
1296 {
1297  checkInit() ;
1298 
1299  switch (etype) {
1300 
1301  case Auto:
1302  throw string(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
1303  break ;
1304 
1305  case Expected:
1306  throw string(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
1307  break ;
1308 
1309  case Poisson:
1310  if (_curWgtErrLo>=0) {
1311  // Weight is preset or precalculated
1312  lo = _curWgtErrLo ;
1313  hi = _curWgtErrHi ;
1314  return ;
1315  }
1316 
1317  // Calculate poisson errors
1318  Double_t ym,yp ;
1320  _curWgtErrLo = weight()-ym ;
1321  _curWgtErrHi = yp-weight() ;
1324  lo = _curWgtErrLo ;
1325  hi = _curWgtErrHi ;
1326  return ;
1327 
1328  case SumW2:
1329  lo = sqrt(_curSumW2) ;
1330  hi = sqrt(_curSumW2) ;
1331  return ;
1332 
1333  case None:
1334  lo = 0 ;
1335  hi = 0 ;
1336  return ;
1337  }
1338 }
1339 
1340 
1341 // wve adjust for variable bin sizes
1342 
1343 ////////////////////////////////////////////////////////////////////////////////
1344 /// Perform boundary safe 'intOrder'-th interpolation of weights in dimension 'dim'
1345 /// at current value 'xval'
1346 
1347 Double_t RooDataHist::interpolateDim(RooRealVar& dim, const RooAbsBinning* binning, Double_t xval, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries)
1348 {
1349  // Fill workspace arrays spanning interpolation area
1350  Int_t fbinC = dim.getBin(*binning) ;
1351  Int_t fbinLo = fbinC-intOrder/2 - ((xval<binning->binCenter(fbinC))?1:0) ;
1352  Int_t fbinM = dim.numBins(*binning) ;
1353 
1354 
1355  Int_t i ;
1356  Double_t yarr[10] ;
1357  Double_t xarr[10] ;
1358  for (i=fbinLo ; i<=intOrder+fbinLo ; i++) {
1359  Int_t ibin ;
1360  if (i>=0 && i<fbinM) {
1361  // In range
1362  ibin = i ;
1363  dim.setBinFast(ibin,*binning) ;
1364  //cout << "INRANGE: dim.getVal(ibin=" << ibin << ") = " << dim.getVal() << endl ;
1365  xarr[i-fbinLo] = dim.getVal() ;
1366  Int_t idx = calcTreeIndex();
1367  yarr[i - fbinLo] = get_wgt(idx);
1368  if (correctForBinSize) yarr[i-fbinLo] /= _binv[idx] ;
1369  } else if (i>=fbinM) {
1370  // Overflow: mirror
1371  ibin = 2*fbinM-i-1 ;
1372  dim.setBinFast(ibin,*binning) ;
1373  //cout << "OVERFLOW: dim.getVal(ibin=" << ibin << ") = " << dim.getVal() << endl ;
1374  if (cdfBoundaries) {
1375  xarr[i-fbinLo] = dim.getMax()+1e-10*(i-fbinM+1) ;
1376  yarr[i-fbinLo] = 1.0 ;
1377  } else {
1378  Int_t idx = calcTreeIndex() ;
1379  xarr[i-fbinLo] = 2*dim.getMax()-dim.getVal() ;
1380  yarr[i - fbinLo] = get_wgt(idx);
1381  if (correctForBinSize)
1382  yarr[i - fbinLo] /= _binv[idx];
1383  }
1384  } else {
1385  // Underflow: mirror
1386  ibin = -i - 1 ;
1387  dim.setBinFast(ibin,*binning) ;
1388  //cout << "UNDERFLOW: dim.getVal(ibin=" << ibin << ") = " << dim.getVal() << endl ;
1389  if (cdfBoundaries) {
1390  xarr[i-fbinLo] = dim.getMin()-ibin*(1e-10) ; ;
1391  yarr[i-fbinLo] = 0.0 ;
1392  } else {
1393  Int_t idx = calcTreeIndex() ;
1394  xarr[i-fbinLo] = 2*dim.getMin()-dim.getVal() ;
1395  yarr[i - fbinLo] = get_wgt(idx);
1396  if (correctForBinSize)
1397  yarr[i - fbinLo] /= _binv[idx];
1398  }
1399  }
1400  //cout << "ibin = " << ibin << endl ;
1401  }
1402 // for (int k=0 ; k<=intOrder ; k++) {
1403 // cout << "k=" << k << " x = " << xarr[k] << " y = " << yarr[k] << endl ;
1404 // }
1405  dim.setBinFast(fbinC,*binning) ;
1406  Double_t ret = RooMath::interpolate(xarr,yarr,intOrder+1,xval) ;
1407  return ret ;
1408 }
1409 
1410 
1411 
1412 
1413 ////////////////////////////////////////////////////////////////////////////////
1414 /// Increment the weight of the bin enclosing the coordinates given
1415 /// by 'row' by the specified amount. Add the sum of weights squared
1416 /// for the bin by 'sumw2' rather than wgt^2
1417 
1418 void RooDataHist::add(const RooArgSet& row, Double_t wgt, Double_t sumw2)
1419 {
1420  checkInit() ;
1421 
1422 // cout << "RooDataHist::add() accepted coordinate is " << endl ;
1423 // _vars.Print("v") ;
1424 
1425  _vars = row ;
1426  Int_t idx = calcTreeIndex() ;
1427  _wgt[idx] += wgt ;
1428  _sumw2[idx] += (sumw2>0?sumw2:wgt*wgt) ;
1429  _errLo[idx] = -1 ;
1430  _errHi[idx] = -1 ;
1431 
1433 }
1434 
1435 
1436 
1437 ////////////////////////////////////////////////////////////////////////////////
1438 /// Increment the weight of the bin enclosing the coordinates
1439 /// given by 'row' by the specified amount. Associate errors
1440 /// [wgtErrLo,wgtErrHi] with the event weight on this bin.
1441 
1442 void RooDataHist::set(const RooArgSet& row, Double_t wgt, Double_t wgtErrLo, Double_t wgtErrHi)
1443 {
1444  checkInit() ;
1445 
1446  _vars = row ;
1447  Int_t idx = calcTreeIndex() ;
1448  _wgt[idx] = wgt ;
1449  _errLo[idx] = wgtErrLo ;
1450  _errHi[idx] = wgtErrHi ;
1451 
1453 }
1454 
1455 
1456 
1457 ////////////////////////////////////////////////////////////////////////////////
1458 /// Increment the weight of the bin enclosing the coordinates
1459 /// given by 'row' by the specified amount. Associate errors
1460 /// [wgtErrLo,wgtErrHi] with the event weight on this bin.
1461 
1463 {
1464  checkInit() ;
1465 
1466  if (_curIndex<0) {
1467  _curIndex = calcTreeIndex() ;
1468  }
1469 
1470  _wgt[_curIndex] = wgt ;
1471  _errLo[_curIndex] = wgtErr ;
1472  _errHi[_curIndex] = wgtErr ;
1473  _sumw2[_curIndex] = wgtErr*wgtErr ;
1474 
1476 }
1477 
1478 
1479 
1480 ////////////////////////////////////////////////////////////////////////////////
1481 /// Increment the weight of the bin enclosing the coordinates
1482 /// given by 'row' by the specified amount. Associate errors
1483 /// [wgtErrLo,wgtErrHi] with the event weight on this bin.
1484 
1485 void RooDataHist::set(const RooArgSet& row, Double_t wgt, Double_t wgtErr)
1486 {
1487  checkInit() ;
1488 
1489  _vars = row ;
1490  Int_t idx = calcTreeIndex() ;
1491  _wgt[idx] = wgt ;
1492  _errLo[idx] = wgtErr ;
1493  _errHi[idx] = wgtErr ;
1494  _sumw2[idx] = wgtErr*wgtErr ;
1495 
1497 }
1498 
1499 
1500 
1501 ////////////////////////////////////////////////////////////////////////////////
1502 /// Add all data points contained in 'dset' to this data set with given weight.
1503 /// Optional cut string expression selects the data points to be added and can
1504 /// reference any variable contained in this data set
1505 
1506 void RooDataHist::add(const RooAbsData& dset, const char* cut, Double_t wgt)
1507 {
1508  RooFormulaVar cutVar("select",cut,*dset.get()) ;
1509  add(dset,&cutVar,wgt) ;
1510 }
1511 
1512 
1513 
1514 ////////////////////////////////////////////////////////////////////////////////
1515 /// Add all data points contained in 'dset' to this data set with given weight.
1516 /// Optional RooFormulaVar pointer selects the data points to be added.
1517 
1518 void RooDataHist::add(const RooAbsData& dset, const RooFormulaVar* cutVar, Double_t wgt)
1519 {
1520  checkInit() ;
1521 
1522  RooFormulaVar* cloneVar = 0;
1523  RooArgSet* tmp(0) ;
1524  if (cutVar) {
1525  // Deep clone cutVar and attach clone to this dataset
1526  tmp = (RooArgSet*) RooArgSet(*cutVar).snapshot() ;
1527  if (!tmp) {
1528  coutE(DataHandling) << "RooDataHist::add(" << GetName() << ") Couldn't deep-clone cut variable, abort," << endl ;
1529  return ;
1530  }
1531 
1532  cloneVar = (RooFormulaVar*) tmp->find(*cutVar) ;
1533  cloneVar->attachDataSet(dset) ;
1534  }
1535 
1536 
1537  Int_t i ;
1538  for (i=0 ; i<dset.numEntries() ; i++) {
1539  const RooArgSet* row = dset.get(i) ;
1540  if (!cloneVar || cloneVar->getVal()) {
1541  add(*row,wgt*dset.weight(), wgt*wgt*dset.weightSquared()) ;
1542  }
1543  }
1544 
1545  if (cloneVar) {
1546  delete tmp ;
1547  }
1548 
1550 }
1551 
1552 
1553 
1554 ////////////////////////////////////////////////////////////////////////////////
1555 /// Return the sum of the weights of all hist bins.
1556 ///
1557 /// If correctForBinSize is specified, the sum of weights
1558 /// is multiplied by the N-dimensional bin volume,
1559 /// making the return value the integral over the function
1560 /// represented by this histogram
1561 
1562 Double_t RooDataHist::sum(Bool_t correctForBinSize, Bool_t inverseBinCor) const
1563 {
1564  checkInit() ;
1565 
1566  // Check if result was cached
1567  Int_t cache_code = 1 + (correctForBinSize?1:0) + ((correctForBinSize&&inverseBinCor)?1:0) ;
1568  if (_cache_sum_valid==cache_code) {
1569  return _cache_sum ;
1570  }
1571 
1572  Int_t i ;
1573  Double_t total(0), carry(0);
1574  for (i=0 ; i<_arrSize ; i++) {
1575 
1576  Double_t theBinVolume = correctForBinSize ? (inverseBinCor ? 1/_binv[i] : _binv[i]) : 1.0 ;
1577  // cout << "total += " << _wgt[i] << "*" << theBinVolume << endl ;
1578  // Double_t y = _wgt[i]*theBinVolume - carry;
1579  Double_t y = get_wgt(i) * theBinVolume - carry;
1580  Double_t t = total + y;
1581  carry = (t - total) - y;
1582  total = t;
1583  }
1584 
1585  // Store result in cache
1586  _cache_sum_valid=cache_code ;
1587  _cache_sum = total ;
1588 
1589  return total ;
1590 }
1591 
1592 
1593 
1594 ////////////////////////////////////////////////////////////////////////////////
1595 /// Return the sum of the weights of a multi-dimensional slice of the histogram
1596 /// by summing only over the dimensions specified in sumSet.
1597 ///
1598 /// The coordinates of all other dimensions are fixed to those given in sliceSet
1599 ///
1600 /// If correctForBinSize is specified, the sum of weights
1601 /// is multiplied by the M-dimensional bin volume, (M = N(sumSet)),
1602 /// making the return value the integral over the function
1603 /// represented by this histogram
1604 
1605 Double_t RooDataHist::sum(const RooArgSet& sumSet, const RooArgSet& sliceSet, Bool_t correctForBinSize, Bool_t inverseBinCor)
1606 {
1607  checkInit() ;
1608 
1609  RooArgSet varSave ;
1610  varSave.addClone(_vars) ;
1611 
1612  RooArgSet* sliceOnlySet = new RooArgSet(sliceSet) ;
1613  sliceOnlySet->remove(sumSet,kTRUE,kTRUE) ;
1614 
1615  _vars = *sliceOnlySet ;
1616  calculatePartialBinVolume(*sliceOnlySet) ;
1617  delete sliceOnlySet ;
1618 
1619  TIterator* ssIter = sumSet.createIterator() ;
1620 
1621  // Calculate mask and refence plot bins for non-iterating variables
1622  RooAbsArg* arg ;
1623  Bool_t* mask = new Bool_t[_vars.getSize()] ;
1624  Int_t* refBin = new Int_t[_vars.getSize()] ;
1625 
1626  Int_t i(0) ;
1627  _iterator->Reset() ;
1628  while((arg=(RooAbsArg*)_iterator->Next())) {
1629  if (sumSet.find(*arg)) {
1630  mask[i] = kFALSE ;
1631  } else {
1632  mask[i] = kTRUE ;
1633  // coverity[FORWARD_NULL]
1634  refBin[i] = (dynamic_cast<RooAbsLValue*>(arg))->getBin() ;
1635  }
1636  i++ ;
1637  }
1638 
1639  // Loop over entire data set, skipping masked entries
1640  Double_t total(0), carry(0);
1641  Int_t ibin ;
1642  for (ibin=0 ; ibin<_arrSize ; ibin++) {
1643 
1644  Int_t idx(0), tmp(ibin), ivar(0) ;
1645  Bool_t skip(kFALSE) ;
1646 
1647  // Check if this bin belongs in selected slice
1648  _iterator->Reset() ;
1649  // coverity[UNUSED_VALUE]
1650  while((!skip && (arg=(RooAbsArg*)_iterator->Next()))) {
1651  idx = tmp / _idxMult[ivar] ;
1652  tmp -= idx*_idxMult[ivar] ;
1653  if (mask[ivar] && idx!=refBin[ivar]) skip=kTRUE ;
1654  ivar++ ;
1655  }
1656 
1657  if (!skip) {
1658  Double_t theBinVolume = correctForBinSize ? (inverseBinCor ? 1/(*_pbinv)[i] : (*_pbinv)[i] ) : 1.0 ;
1659  // cout << "adding bin[" << ibin << "] to sum wgt = " << _wgt[ibin] << " binv = " << theBinVolume << endl ;
1660  // Double_t y = _wgt[ibin]*theBinVolume - carry;
1661  Double_t y = get_wgt(ibin) * theBinVolume - carry;
1662  Double_t t = total + y;
1663  carry = (t - total) - y;
1664  total = t;
1665  }
1666  }
1667  delete ssIter ;
1668 
1669  delete[] mask ;
1670  delete[] refBin ;
1671 
1672  _vars = varSave ;
1673 
1674  return total ;
1675 }
1676 
1677 ////////////////////////////////////////////////////////////////////////////////
1678 /// Return the sum of the weights of a multi-dimensional slice of the histogram
1679 /// by summing only over the dimensions specified in sumSet.
1680 ///
1681 /// The coordinates of all other dimensions are fixed to those given in sliceSet
1682 ///
1683 /// If correctForBinSize is specified, the sum of weights
1684 /// is multiplied by the M-dimensional bin volume, (M = N(sumSet)),
1685 /// or the fraction of it that falls inside the range rangeName,
1686 /// making the return value the integral over the function
1687 /// represented by this histogram
1688 ///
1689 /// If correctForBinSize is not specified, the weights are multiplied by the
1690 /// fraction of the bin volume that falls inside the range, i.e. a factor or
1691 /// binVolumeInRange/totalBinVolume.
1692 
1693 Double_t RooDataHist::sum(const RooArgSet& sumSet, const RooArgSet& sliceSet,
1694  Bool_t correctForBinSize, Bool_t inverseBinCor,
1695  const std::map<const RooAbsArg*, std::pair<Double_t, Double_t> >& ranges)
1696 {
1697  checkInit();
1698  checkBinBounds();
1699  RooArgSet varSave;
1700  varSave.addClone(_vars);
1701  {
1702  RooArgSet sliceOnlySet(sliceSet);
1703  sliceOnlySet.remove(sumSet,kTRUE,kTRUE);
1704  _vars = sliceOnlySet;
1705  }
1706 
1707  // Calculate mask and refence plot bins for non-iterating variables,
1708  // and get ranges for iterating variables
1709  std::vector<bool> mask(_vars.getSize());
1710  std::vector<Int_t> refBin(_vars.getSize());
1711  std::vector<Double_t> rangeLo(_vars.getSize(), -std::numeric_limits<Double_t>::infinity());
1712  std::vector<Double_t> rangeHi(_vars.getSize(), +std::numeric_limits<Double_t>::infinity());
1713 
1714  _iterator->Reset();
1715  RooAbsArg* arg;
1716  for (Int_t i = 0; (arg=(RooAbsArg*)_iterator->Next()); ++i) {
1717  RooAbsArg* sumsetv = sumSet.find(*arg);
1718  RooAbsArg* slicesetv = sliceSet.find(*arg);
1719  mask[i] = !sumsetv;
1720  if (mask[i]) {
1721  // coverity[FORWARD_NULL]
1722  refBin[i] = (dynamic_cast<RooAbsLValue*>(arg))->getBin();
1723  }
1724  std::map<const RooAbsArg*, std::pair<Double_t, Double_t> >::const_iterator
1725  it = ranges.find(sumsetv ? sumsetv : slicesetv);
1726  if (ranges.end() != it) {
1727  rangeLo[i] = it->second.first;
1728  rangeHi[i] = it->second.second;
1729  }
1730  }
1731 
1732  // Loop over entire data set, skipping masked entries
1733  Double_t total(0), carry(0);
1734  for (Int_t ibin = 0; ibin < _arrSize; ++ibin) {
1735  // Check if this bin belongs in selected slice
1736  _iterator->Reset();
1737  Bool_t skip(kFALSE);
1738  // coverity[UNUSED_VALUE]
1739  for (Int_t ivar = 0, tmp = ibin;
1740  (!skip && (arg=(RooAbsArg*)_iterator->Next())); ++ivar) {
1741  const Int_t idx = tmp / _idxMult[ivar];
1742  tmp -= idx*_idxMult[ivar];
1743  if (mask[ivar] && idx!=refBin[ivar]) skip=kTRUE;
1744  }
1745  if (skip) continue;
1746  _iterator->Reset();
1747  // work out bin volume
1748  Double_t theBinVolume = 1.;
1749  for (Int_t ivar = 0, tmp = ibin;
1750  (arg=(RooAbsArg*)_iterator->Next()); ++ivar) {
1751  const Int_t idx = tmp / _idxMult[ivar];
1752  tmp -= idx*_idxMult[ivar];
1753  if (_binbounds[ivar].empty()) continue;
1754  const Double_t binLo = _binbounds[ivar][2 * idx];
1755  const Double_t binHi = _binbounds[ivar][2 * idx + 1];
1756  if (binHi < rangeLo[ivar] || binLo > rangeHi[ivar]) {
1757  // bin is outside of allowed range - effective bin volume is zero
1758  theBinVolume = 0.;
1759  break;
1760  }
1761  theBinVolume *=
1762  (std::min(rangeHi[ivar], binHi) - std::max(rangeLo[ivar], binLo));
1763  }
1764  const Double_t corrPartial = theBinVolume / _binv[ibin];
1765  if (0. == corrPartial) continue;
1766  const Double_t corr = correctForBinSize ? (inverseBinCor ? 1. / _binv[ibin] : _binv[ibin] ) : 1.0;
1767  //cout << "adding bin[" << ibin << "] to sum wgt = " << _wgt[ibin] << " binv = " << theBinVolume << " _binv[" << ibin << "] " << _binv[ibin] << endl;
1768  // const Double_t y = _wgt[ibin] * corr * corrPartial - carry;
1769  const Double_t y = get_wgt(ibin) * corr * corrPartial - carry;
1770  const Double_t t = total + y;
1771  carry = (t - total) - y;
1772  total = t;
1773  }
1774 
1775  _vars = varSave;
1776 
1777  return total;
1778 }
1779 
1780 
1781 
1782 ////////////////////////////////////////////////////////////////////////////////
1783 /// Fill the transient cache with partial bin volumes with up-to-date
1784 /// values for the partial volume specified by observables 'dimSet'
1785 
1787 {
1788  // Allocate cache if not yet existing
1789  vector<Double_t> *pbinv = _pbinvCacheMgr.getObj(&dimSet) ;
1790  if (pbinv) {
1791  _pbinv = pbinv ;
1792  return ;
1793  }
1794 
1795  pbinv = new vector<Double_t>(_arrSize) ;
1796 
1797  // Calculate plot bins of components from master index
1798  Bool_t* selDim = new Bool_t[_vars.getSize()] ;
1799  _iterator->Reset() ;
1800  RooAbsArg* v ;
1801  Int_t i(0) ;
1802  while((v=(RooAbsArg*)_iterator->Next())) {
1803  selDim[i++] = dimSet.find(*v) ? kTRUE : kFALSE ;
1804  }
1805 
1806  // Recalculate partial bin volume cache
1807  Int_t ibin ;
1808  for (ibin=0 ; ibin<_arrSize ; ibin++) {
1809  _iterator->Reset() ;
1810  RooAbsLValue* arg ;
1811  Int_t j(0), idx(0), tmp(ibin) ;
1812  Double_t theBinVolume(1) ;
1813  while((arg=dynamic_cast<RooAbsLValue*>(_iterator->Next()))) {
1814  idx = tmp / _idxMult[j] ;
1815  tmp -= idx*_idxMult[j++] ;
1816  if (selDim[j-1]) {
1817  RooAbsLValue* arglv = dynamic_cast<RooAbsLValue*>(arg) ;
1818  theBinVolume *= arglv->getBinWidth(idx) ;
1819  }
1820  }
1821  (*pbinv)[ibin] = theBinVolume ;
1822  }
1823 
1824  delete[] selDim ;
1825 
1826  // Put in cache (which takes ownership)
1827  _pbinvCacheMgr.setObj(&dimSet,pbinv) ;
1828 
1829  // Publicize the array
1830  _pbinv = pbinv ;
1831 }
1832 
1833 
1834 
1835 ////////////////////////////////////////////////////////////////////////////////
1836 /// Return the number of bins
1837 
1839 {
1840  return RooAbsData::numEntries() ;
1841 }
1842 
1843 
1844 
1845 ////////////////////////////////////////////////////////////////////////////////
1846 
1848 {
1849  Int_t i ;
1850  Double_t n(0), carry(0);
1851  for (i=0 ; i<_arrSize ; i++) {
1852  if (!_binValid || _binValid[i]) {
1853  // Double_t y = _wgt[i] - carry;
1854  Double_t y = get_wgt(i) - carry;
1855  Double_t t = n + y;
1856  carry = (t - n) - y;
1857  n = t;
1858  }
1859  }
1860  return n ;
1861 }
1862 
1863 
1864 
1865 ////////////////////////////////////////////////////////////////////////////////
1866 /// Return the sum of weights in all entries matching cutSpec (if specified)
1867 /// and in named range cutRange (if specified)
1868 /// Return the
1869 
1870 Double_t RooDataHist::sumEntries(const char* cutSpec, const char* cutRange) const
1871 {
1872  checkInit() ;
1873 
1874  if (cutSpec==0 && cutRange==0) {
1875  return sumEntries();
1876  } else {
1877 
1878  // Setup RooFormulaVar for cutSpec if it is present
1879  RooFormula* select = 0 ;
1880  if (cutSpec) {
1881  select = new RooFormula("select",cutSpec,*get()) ;
1882  }
1883 
1884  // Otherwise sum the weights in the event
1885  Double_t sumw(0), carry(0);
1886  Int_t i ;
1887  for (i=0 ; i<numEntries() ; i++) {
1888  get(i) ;
1889  if (select && select->eval()==0.) continue ;
1890  if (cutRange && !_vars.allInRange(cutRange)) continue ;
1891 
1892  if (!_binValid || _binValid[i]) {
1893  Double_t y = weight() - carry;
1894  Double_t t = sumw + y;
1895  carry = (t - sumw) - y;
1896  sumw = t;
1897  }
1898  }
1899 
1900  if (select) delete select ;
1901 
1902  return sumw ;
1903  }
1904 }
1905 
1906 
1907 
1908 ////////////////////////////////////////////////////////////////////////////////
1909 /// Reset all bin weights to zero
1910 
1912 {
1913  // WVE DO NOT CALL RooTreeData::reset() for binned
1914  // datasets as this will delete the bin definitions
1915 
1916  Int_t i ;
1917  for (i=0 ; i<_arrSize ; i++) {
1918  _wgt[i] = 0. ;
1919  _errLo[i] = -1 ;
1920  _errHi[i] = -1 ;
1921  }
1922  _curWeight = 0 ;
1923  _curWgtErrLo = -1 ;
1924  _curWgtErrHi = -1 ;
1925  _curVolume = 1 ;
1926 
1928 
1929 }
1930 
1931 
1932 
1933 ////////////////////////////////////////////////////////////////////////////////
1934 /// Return an argset with the bin center coordinates for
1935 /// bin sequential number 'masterIdx'. For iterative use.
1936 
1937 const RooArgSet* RooDataHist::get(Int_t masterIdx) const
1938 {
1939  checkInit() ;
1940  _curWeight = _wgt[masterIdx] ;
1941  _curWgtErrLo = _errLo[masterIdx] ;
1942  _curWgtErrHi = _errHi[masterIdx] ;
1943  _curSumW2 = _sumw2[masterIdx] ;
1944  _curVolume = _binv[masterIdx] ;
1945  _curIndex = masterIdx ;
1946  return RooAbsData::get(masterIdx) ;
1947 }
1948 
1949 
1950 
1951 ////////////////////////////////////////////////////////////////////////////////
1952 /// Return a RooArgSet with center coordinates of the bin
1953 /// enclosing the point 'coord'
1954 
1955 const RooArgSet* RooDataHist::get(const RooArgSet& coord) const
1956 {
1957  ((RooDataHist*)this)->_vars = coord ;
1958  return get(calcTreeIndex()) ;
1959 }
1960 
1961 
1962 
1963 ////////////////////////////////////////////////////////////////////////////////
1964 /// Return the volume of the bin enclosing coordinates 'coord'
1965 
1967 {
1968  checkInit() ;
1969  ((RooDataHist*)this)->_vars = coord ;
1970  return _binv[calcTreeIndex()] ;
1971 }
1972 
1973 
1974 ////////////////////////////////////////////////////////////////////////////////
1975 /// Set all the event weight of all bins to the specified value
1976 
1978 {
1979  for (Int_t i=0 ; i<_arrSize ; i++) {
1980  _wgt[i] = value ;
1981  }
1982 
1984 }
1985 
1986 
1987 
1988 ////////////////////////////////////////////////////////////////////////////////
1989 /// Create an iterator over all bins in a slice defined by the subset of observables
1990 /// listed in sliceArg. The position of the slice is given by otherArgs
1991 
1993 {
1994  // Update to current position
1995  _vars = otherArgs ;
1996  _curIndex = calcTreeIndex() ;
1997 
1998  RooAbsArg* intArg = _vars.find(sliceArg) ;
1999  if (!intArg) {
2000  coutE(InputArguments) << "RooDataHist::sliceIterator() variable " << sliceArg.GetName() << " is not part of this RooDataHist" << endl ;
2001  return 0 ;
2002  }
2003  return new RooDataHistSliceIter(*this,*intArg) ;
2004 }
2005 
2006 
2007 ////////////////////////////////////////////////////////////////////////////////
2008 /// Change the name of the RooDataHist
2009 
2010 void RooDataHist::SetName(const char *name)
2011 {
2012  if (_dir) _dir->GetList()->Remove(this);
2013  TNamed::SetName(name) ;
2014  if (_dir) _dir->GetList()->Add(this);
2015 }
2016 
2017 
2018 ////////////////////////////////////////////////////////////////////////////////
2019 /// Change the title of this RooDataHist
2020 
2021 void RooDataHist::SetNameTitle(const char *name, const char* title)
2022 {
2023  if (_dir) _dir->GetList()->Remove(this);
2024  TNamed::SetNameTitle(name,title) ;
2025  if (_dir) _dir->GetList()->Add(this);
2026 }
2027 
2028 
2029 ////////////////////////////////////////////////////////////////////////////////
2030 /// Print value of the dataset, i.e. the sum of weights contained in the dataset
2031 
2032 void RooDataHist::printValue(ostream& os) const
2033 {
2034  os << numEntries() << " bins (" << sumEntries() << " weights)" ;
2035 }
2036 
2037 
2038 
2039 
2040 ////////////////////////////////////////////////////////////////////////////////
2041 /// Print argument of dataset, i.e. the observable names
2042 
2043 void RooDataHist::printArgs(ostream& os) const
2044 {
2045  os << "[" ;
2046  _iterator->Reset() ;
2047  RooAbsArg* arg ;
2048  Bool_t first(kTRUE) ;
2049  while((arg=(RooAbsArg*)_iterator->Next())) {
2050  if (first) {
2051  first=kFALSE ;
2052  } else {
2053  os << "," ;
2054  }
2055  os << arg->GetName() ;
2056  }
2057  os << "]" ;
2058 }
2059 
2060 
2061 
2062 ////////////////////////////////////////////////////////////////////////////////
2063 /// Cache the datahist entries with bin centers that are inside/outside the
2064 /// current observable definitio
2065 
2067 {
2068  checkInit() ;
2069 
2070  if (!_binValid) {
2071  _binValid = new Bool_t[_arrSize] ;
2072  }
2073  TIterator* iter = _vars.createIterator() ;
2074  RooAbsArg* arg ;
2075  for (Int_t i=0 ; i<_arrSize ; i++) {
2076  get(i) ;
2077  _binValid[i] = kTRUE ;
2078  iter->Reset() ;
2079  while((arg=(RooAbsArg*)iter->Next())) {
2080  // coverity[CHECKED_RETURN]
2081  _binValid[i] &= arg->inRange(0) ;
2082  }
2083  }
2084  delete iter ;
2085 
2086 }
2087 
2088 
2089 ////////////////////////////////////////////////////////////////////////////////
2090 /// Return true if currently loaded coordinate is considered valid within
2091 /// the current range definitions of all observables
2092 
2094 {
2095  // If caching is enabled, use the precached result
2096  if (_binValid) {
2097  return _binValid[_curIndex] ;
2098  }
2099 
2100  return kTRUE ;
2101 }
2102 
2103 
2104 
2105 ////////////////////////////////////////////////////////////////////////////////
2106 /// Returns true if datasets contains entries with a non-integer weight
2107 
2109 {
2110  for (int i=0 ; i<numEntries() ; i++) {
2111  if (fabs(_wgt[i]-Int_t(_wgt[i]))>1e-10) return kTRUE ;
2112  }
2113  return kFALSE ;
2114 }
2115 
2116 
2117 
2118 
2119 ////////////////////////////////////////////////////////////////////////////////
2120 /// Print the details on the dataset contents
2121 
2122 void RooDataHist::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
2123 {
2124  RooAbsData::printMultiline(os,content,verbose,indent) ;
2125 
2126  os << indent << "Binned Dataset " << GetName() << " (" << GetTitle() << ")" << endl ;
2127  os << indent << " Contains " << numEntries() << " bins with a total weight of " << sumEntries() << endl;
2128 
2129  if (!verbose) {
2130  os << indent << " Observables " << _vars << endl ;
2131  } else {
2132  os << indent << " Observables: " ;
2134  }
2135 
2136  if(verbose) {
2137  if (_cachedVars.getSize()>0) {
2138  os << indent << " Caches " << _cachedVars << endl ;
2139  }
2140  }
2141 }
2142 
2143 
2144 
2145 ////////////////////////////////////////////////////////////////////////////////
2146 /// Stream an object of class RooDataHist.
2147 
2148 void RooDataHist::Streamer(TBuffer &R__b)
2149 {
2150  if (R__b.IsReading()) {
2151 
2152  UInt_t R__s, R__c;
2153  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
2154 
2155  if (R__v>2) {
2156 
2157  R__b.ReadClassBuffer(RooDataHist::Class(),this,R__v,R__s,R__c);
2158  initialize(0,kFALSE) ;
2159 
2160  } else {
2161 
2162  // Legacy dataset conversion happens here. Legacy RooDataHist inherits from RooTreeData
2163  // which in turn inherits from RooAbsData. Manually stream RooTreeData contents on
2164  // file here and convert it into a RooTreeDataStore which is installed in the
2165  // new-style RooAbsData base class
2166 
2167  // --- This is the contents of the streamer code of RooTreeData version 2 ---
2168  UInt_t R__s1, R__c1;
2169  Version_t R__v1 = R__b.ReadVersion(&R__s1, &R__c1); if (R__v1) { }
2170 
2171  RooAbsData::Streamer(R__b);
2172  TTree* X_tree(0) ; R__b >> X_tree;
2173  RooArgSet X_truth ; X_truth.Streamer(R__b);
2174  TString X_blindString ; X_blindString.Streamer(R__b);
2175  R__b.CheckByteCount(R__s1, R__c1, RooTreeData::Class());
2176  // --- End of RooTreeData-v1 streamer
2177 
2178  // Construct RooTreeDataStore from X_tree and complete initialization of new-style RooAbsData
2179  _dstore = new RooTreeDataStore(X_tree,_vars) ;
2180  _dstore->SetName(GetName()) ;
2181  _dstore->SetTitle(GetTitle()) ;
2182  _dstore->checkInit() ;
2183 
2184  RooDirItem::Streamer(R__b);
2185  R__b >> _arrSize;
2186  delete [] _wgt;
2187  _wgt = new Double_t[_arrSize];
2188  R__b.ReadFastArray(_wgt,_arrSize);
2189  delete [] _errLo;
2190  _errLo = new Double_t[_arrSize];
2191  R__b.ReadFastArray(_errLo,_arrSize);
2192  delete [] _errHi;
2193  _errHi = new Double_t[_arrSize];
2194  R__b.ReadFastArray(_errHi,_arrSize);
2195  delete [] _sumw2;
2196  _sumw2 = new Double_t[_arrSize];
2197  R__b.ReadFastArray(_sumw2,_arrSize);
2198  delete [] _binv;
2199  _binv = new Double_t[_arrSize];
2200  R__b.ReadFastArray(_binv,_arrSize);
2201  _realVars.Streamer(R__b);
2202  R__b >> _curWeight;
2203  R__b >> _curWgtErrLo;
2204  R__b >> _curWgtErrHi;
2205  R__b >> _curSumW2;
2206  R__b >> _curVolume;
2207  R__b >> _curIndex;
2208  R__b.CheckByteCount(R__s, R__c, RooDataHist::IsA());
2209 
2210  }
2211 
2212  } else {
2213 
2214  R__b.WriteClassBuffer(RooDataHist::Class(),this);
2215  }
2216 }
2217 
2218 
virtual Double_t getMin(const char *name=0) const
static Double_t interpolate(Double_t yArr[], Int_t nOrder, Double_t x)
Definition: RooMath.cxx:605
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void setBin(Int_t ibin, const char *rangeName=0)
Set value to center of bin &#39;ibin&#39; of binning &#39;rangeName&#39; (or of default binning if no range is specif...
Bool_t IsReading() const
Definition: TBuffer.h:83
TIterator * createIterator(Bool_t dir=kIterForward) const
#define coutE(a)
Definition: RooMsgService.h:34
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer, which is interpreted as an OR of &#39;enum ContentsOptions&#39; values and in the style given by &#39;enum StyleOption&#39;.
float xmin
Definition: THbookFile.cxx:93
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual Double_t getBinWidth(Int_t i, const char *rangeName=0) const =0
virtual Double_t getMax(const char *name=0) const
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:86
Double_t weightSquared() const
virtual const RooArgSet * get() const
Definition: RooDataHist.h:77
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:568
virtual void Reset()=0
short Version_t
Definition: RtypesCore.h:61
Bool_t defineDouble(const char *name, const char *argName, Int_t doubleNum, Double_t defValue=0.)
Define Double_t property name &#39;name&#39; mapped to Double_t in slot &#39;doubleNum&#39; in RooCmdArg with name ar...
virtual Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
virtual const RooArgSet * get() const
Definition: RooAbsData.h:79
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
#define coutI(a)
Definition: RooMsgService.h:31
float ymin
Definition: THbookFile.cxx:93
virtual Int_t numBins(const char *rangeName=0) const
const char * getString(const char *name, const char *defaultValue="", Bool_t convEmptyToNull=kFALSE)
Return string property registered with name &#39;name&#39;.
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
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.
const Double_t * GetArray() const
Definition: TArrayD.h:43
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
Definition: RooRealVar.cxx:266
Int_t getIndex(const RooArgSet &coord, Bool_t fast=kFALSE)
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4770
void set(Double_t weight, Double_t wgtErr=-1)
Increment the weight of the bin enclosing the coordinates given by &#39;row&#39; by the specified amount...
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
virtual Double_t get_wgt(const Int_t &idx) const
Definition: RooDataHist.h:161
Double_t _curWgtErrHi
Definition: RooDataHist.h:188
virtual Int_t GetNbinsZ() const
Definition: TH1.h:293
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.
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
void addUniform(Int_t nBins, Double_t xlo, Double_t xhi)
Add array of nbins uniformly sized bins in range [xlo,xhi].
Definition: RooBinning.cxx:173
Double_t _cache_sum
Is cache sum valid.
Definition: RooDataHist.h:200
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
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.
RooTreeDataStore is the abstract base class for data collection that use a TTree as internal storage ...
TObject * getObject(const char *name, TObject *obj=0)
Return TObject property registered with name &#39;name&#39;.
TIterator * _iterator
External variables cached with this data set.
Definition: RooAbsData.h:260
virtual RooAbsBinning * clone(const char *name=0) const =0
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition: TNamed.cxx:154
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables...
Definition: RooAbsArg.cxx:1488
Int_t GetSize() const
Definition: RooLinkedList.h:60
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.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:734
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)
Set value by specifying the name of the desired state If printError is set, a message will be printed...
RooAbsBinning * bins
Definition: RooAbsData.h:125
virtual Bool_t inRange(const char *) const
Definition: RooAbsArg.h:289
virtual Double_t weightSquared() const =0
void dump2()
Debug stuff, should go...
Bool_t process(const RooCmdArg &arg)
Process given RooCmdArg.
virtual Int_t GetDimension() const
Definition: TH1.h:277
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.
double sqrt(double)
void setBinning(const RooAbsBinning &binning, const char *name=0)
Add given binning under name &#39;name&#39; with this variable.
Definition: RooRealVar.cxx:345
std::vector< RooAbsLValue * > _lvvars
Cache manager for arrays of partial bin volumes.
Definition: RooDataHist.h:195
void appendToDir(TObject *obj, Bool_t forceMemoryResident=kFALSE)
Append object to directory.
Definition: RooDirItem.cxx:86
Double_t GetXmin() const
Definition: TAxis.h:133
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
virtual Int_t numBins(const char *rangeName) const
Returm the number of fit bins ( = number of types )
#define TRACE_CREATE
Definition: RooTrace.h:22
RooDataSet is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
virtual void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)
Internal method – Attach dataset copied with cache contents to copied instances of functions...
Definition: RooAbsData.cxx:325
void Class()
Definition: Class.C:29
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...
Bool_t allInRange(const char *rangeSpec) const
Return true if all contained object report to have their value inside the specified range...
void checkBinBounds() const
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:174
TIterator * _realIter
Definition: RooDataHist.h:183
RooVectorDataStore is the abstract base class for data collection that use a TTree as internal storag...
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=0, const TNamed *isetRangeName=0)
double pow(double, double)
Double_t binVolume() const
Definition: RooDataHist.h:102
Double_t * _errHi
Definition: RooDataHist.h:178
virtual void setBinFast(Int_t ibin, const RooAbsBinning &binning)
Set value to center of bin &#39;ibin&#39; of binning &#39;rangeName&#39; (or of default binning if no range is specif...
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...
Bool_t defineString(const char *name, const char *argName, Int_t stringNum, const char *defValue="", Bool_t appendMode=kFALSE)
Define Double_t property name &#39;name&#39; mapped to Double_t in slot &#39;stringNum&#39; in RooCmdArg with name ar...
Int_t calcTreeIndex() const
Calculate the index for the weights array corresponding to to the bin enclosing the current coordinat...
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values, posing no constraints on the choice of binning, thus allowing variable bin sizes.
Definition: RooBinning.h:29
virtual Double_t weight() const
Definition: RooDataHist.h:96
void assignFast(const RooAbsCollection &other, Bool_t setValDirty=kTRUE)
Functional equivalent of operator=() but assumes this and other collection have same layout...
virtual TList * GetList() const
Definition: TDirectory.h:149
Double_t * _errLo
Definition: RooDataHist.h:177
void defineDependency(const char *refArgName, const char *neededArgName)
Define that processing argument name refArgName requires processing of argument named neededArgName t...
RooFormula an implementation of ROOT::v5::TFormula that interfaces it to RooAbsArg value objects...
Definition: RooFormula.h:27
Double_t eval(const RooArgSet *nset=0)
Evaluate ROOT::v5::TFormula using given normalization set to be used as observables definition passed...
Definition: RooFormula.cxx:234
Bool_t defineInt(const char *name, const char *argName, Int_t intNum, Int_t defValue=0)
Define integer property name &#39;name&#39; mapped to integer in slot &#39;intNum&#39; in RooCmdArg with name argName...
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:184
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooArgSet _realVars
Definition: RooDataHist.h:182
virtual void addClone(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling addOwned() for each element in the source...
Definition: RooArgSet.h:94
virtual void setBin(Int_t ibin, const char *rangeName=0)=0
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Interface for detailed printing of object.
Definition: RooAbsData.cxx:821
void SetName(const char *name)
Change the name of the RooDataHist.
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
Int_t getSize() const
virtual const RooAbsBinning * getBinningPtr(const char *rangeName) const
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
virtual void checkInit() const
RooArgSet _cachedVars
Definition: RooAbsData.h:258
void defineMutex(const char *argName1, const char *argName2)
Define arguments named argName1 and argName2 mutually exclusive.
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name &#39;name&#39;.
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
virtual void add(const RooArgSet &row, Double_t wgt=1.0)
Definition: RooDataHist.h:65
RooDataHist()
Default constructor.
Definition: RooDataHist.cxx:63
SVector< double, 2 > v
Definition: Dict.h:5
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
Bool_t ok(Bool_t verbose) const
Return true of parsing was successful.
const RooCatType * lookupType(Int_t index, Bool_t printError=kFALSE) const
Find our type corresponding to the specified index, or return 0 for no match.
Int_t _arrSize
Definition: RooDataHist.h:173
virtual void printValue(std::ostream &os) const
Print value of the dataset, i.e. the sum of weights contained in the dataset.
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
virtual void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print the details on the dataset contents.
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called...
void SetNameTitle(const char *name, const char *title)
Change the title of this RooDataHist.
Double_t * _binv
Definition: RooDataHist.h:180
TAxis * GetYaxis()
Definition: TH1.h:316
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
Definition: RooCmdConfig.h:27
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
virtual void fill()
Definition: RooAbsData.cxx:278
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
Definition: RooDirItem.cxx:71
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
Double_t _curSumW2
Definition: RooDataHist.h:189
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:24
#define h(i)
Definition: RSha256.hxx:106
TDirectory * _dir
Definition: RooDirItem.h:33
RooAbsArg * next()
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:88
void checkInit() const
Double_t sum(Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) const
Return the sum of the weights of all hist bins.
static unsigned int total
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
Double_t * _wgt
Definition: RooDataHist.h:176
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
RooUniformBinning is an implementation of RooAbsBinning that provides a uniform binning in &#39;n&#39; bins b...
virtual Double_t sumEntries() const
std::vector< Double_t > * _pbinv
Definition: RooDataHist.h:193
#define ClassImp(name)
Definition: Rtypes.h:359
static Int_t init()
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual Int_t numEntries() const
Return the number of bins.
RooAbsCollection & assignValueOnly(const RooAbsCollection &other, Bool_t oneSafe=kFALSE)
The assignment operator sets the value of any argument in our set that also appears in the other set...
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
RooFIter fwdIterator() const
RooDirItem is a utility base class for RooFit objects that are to be attached to ROOT directories...
Definition: RooDirItem.h:22
virtual Double_t binCenter(Int_t bin) const =0
RooAbsDataStore * _dstore
Iterator over cached variables.
Definition: RooAbsData.h:263
Double_t getDouble(const char *name, Double_t defaultValue=0)
Return Double_t property registered with name &#39;name&#39;.
virtual void setExternalWeightArray(Double_t *, Double_t *, Double_t *, Double_t *)
virtual Int_t getBin(const char *rangeName=0) const
Double_t y[n]
Definition: legend1.C:17
#define TRACE_DESTROY
Definition: RooTrace.h:23
The TH1 histogram class.
Definition: TH1.h:56
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
Bool_t getPoissonInterval(Int_t n, Double_t &mu1, Double_t &mu2, Double_t nSigma=1) const
Return a confidence interval for the expected number of events given n observed (unweighted) events...
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...
virtual const char * getLabel() const
Return label string of current state.
Definition: RooCategory.h:39
Double_t _curWgtErrLo
Definition: RooDataHist.h:187
const RooLinkedList & getObjectList(const char *name)
Return list of objects registered with name &#39;name&#39;.
void cacheValidEntries()
Cache the datahist entries with bin centers that are inside/outside the current observable definitio...
TAxis * GetZaxis()
Definition: TH1.h:317
Double_t * _sumw2
Definition: RooDataHist.h:179
static StorageType defaultStorageType
Definition: RooAbsData.h:222
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
friend class RooDataHistSliceIter
Definition: RooDataHist.h:137
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual void Add(TObject *obj)
Definition: TList.h:87
auto * l
Definition: textangle.C:4
RooAbsRealLValue * getPlotVar() const
Definition: RooPlot.h:132
TIterator * MakeIterator(Bool_t dir=kTRUE) const
Return an iterator over this list.
virtual void setBin(Int_t ibin, const char *rangeName=0)
Set category to i-th fit bin, which is the i-th registered state.
virtual void reset()
Reset all bin weights to zero.
virtual TObject * Next()=0
virtual void printArgs(std::ostream &os) const
Print argument of dataset, i.e. the observable names.
virtual Double_t weight() const =0
std::vector< const RooAbsBinning * > _lvbins
List of observables casted as RooAbsLValue.
Definition: RooDataHist.h:196
Double_t _curVolume
Definition: RooDataHist.h:190
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:194
R__EXTERN Int_t gDebug
Definition: Rtypes.h:86
Bool_t defineType(const char *label)
Define a state with given name, the lowest available positive integer is assigned as index...
virtual Bool_t isNonPoissonWeighted() const
Returns true if datasets contains entries with a non-integer weight.
static constexpr double pc
float type_of_call hi(const int &, const int &)
Bool_t defineObject(const char *name, const char *argName, Int_t setNum, const TObject *obj=0, Bool_t isArray=kFALSE)
Define TObject property name &#39;name&#39; mapped to object in slot &#39;setNum&#39; in RooCmdArg with name argName ...
virtual Int_t getBins(const char *name=0) const
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=0)
Abstract base class for objects that are lvalues, i.e.
Definition: RooAbsLValue.h:26
Definition: first.py:1
virtual Int_t GetNbinsX() const
Definition: TH1.h:291
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:257
float * q
Definition: THbookFile.cxx:87
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
void setAllWeights(Double_t value)
Set all the event weight of all bins to the specified value.
const Bool_t kTRUE
Definition: RtypesCore.h:87
Double_t GetXmax() const
Definition: TAxis.h:134
const Int_t n
Definition: legend1.C:16
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:197
char name[80]
Definition: TGX11.cxx:109
const TArrayD * GetXbins() const
Definition: TAxis.h:130
Int_t _curIndex
Definition: RooDataHist.h:191
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:315
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:285
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual Int_t numBins(const char *rangeName=0) const =0
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual Int_t GetNbinsY() const
Definition: TH1.h:292
Int_t _cache_sum_valid
list of bin bounds per dimension
Definition: RooDataHist.h:199
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8356
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:186
Bool_t correctForBinWidth
Definition: RooAbsData.h:135