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