Logo ROOT  
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 vars List with variables that are supposed to have their binning adjusted.
636 /// @param href 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 /// Calculate bin number of the given coordinates. If only a subset of the internal
957 /// coordinates are passed, the missing coordinates are taken at their current value.
958 /// \param[in] coord Variables that are representing the coordinates.
959 /// \param[in] fast If the variables in `coord` and the ones of the data hist have the
960 /// same size and layout, see RooAbsCollection::hasSameLayout(), fast can be set to skip
961 /// checking that all variables are present in `coord`.
963 {
964  checkInit() ;
965  if (fast) {
966  _vars.assignFast(coord,kFALSE) ;
967  } else {
968  _vars.assignValueOnly(coord) ;
969  }
970  return calcTreeIndex() ;
971 }
972 
973 
974 
975 
976 ////////////////////////////////////////////////////////////////////////////////
977 /// Calculate the index for the weights array corresponding to
978 /// to the bin enclosing the current coordinates of the internal argset
979 
981 {
982  int masterIdx(0);
983  for (unsigned int i=0; i < _lvvars.size(); ++i) {
984  const RooAbsLValue* lvvar = _lvvars[i];
985  const RooAbsBinning* binning = _lvbins[i];
986  masterIdx += _idxMult[i] * lvvar->getBin(binning);
987  }
988 
989  return masterIdx ;
990 }
991 
992 
993 
994 ////////////////////////////////////////////////////////////////////////////////
995 /// Debug stuff, should go...
996 
998 {
999  cout << "_arrSize = " << _arrSize << endl ;
1000  for (Int_t i=0 ; i<_arrSize ; i++) {
1001  cout << "wgt[" << i << "] = " << _wgt[i] << "sumw2[" << i << "] = " << _sumw2[i] << " vol[" << i << "] = " << _binv[i] << endl ;
1002  }
1003 }
1004 
1005 
1006 
1007 ////////////////////////////////////////////////////////////////////////////////
1008 /// Back end function to plotting functionality. Plot RooDataHist on given
1009 /// frame in mode specified by plot options 'o'. The main purpose of
1010 /// this function is to match the specified binning on 'o' to the
1011 /// internal binning of the plot observable in this RooDataHist.
1012 /// \see RooAbsData::plotOn() for plotting options.
1014 {
1015  checkInit() ;
1016  if (o.bins) return RooAbsData::plotOn(frame,o) ;
1017 
1018  if(0 == frame) {
1019  coutE(InputArguments) << ClassName() << "::" << GetName() << ":plotOn: frame is null" << endl;
1020  return 0;
1021  }
1022  RooAbsRealLValue *var= (RooAbsRealLValue*) frame->getPlotVar();
1023  if(0 == var) {
1024  coutE(InputArguments) << ClassName() << "::" << GetName()
1025  << ":plotOn: frame does not specify a plot variable" << endl;
1026  return 0;
1027  }
1028 
1029  RooRealVar* dataVar = (RooRealVar*) _vars.find(*var) ;
1030  if (!dataVar) {
1031  coutE(InputArguments) << ClassName() << "::" << GetName()
1032  << ":plotOn: dataset doesn't contain plot frame variable" << endl;
1033  return 0;
1034  }
1035 
1036  o.bins = &dataVar->getBinning() ;
1038  return RooAbsData::plotOn(frame,o) ;
1039 }
1040 
1041 
1042 
1043 
1044 ////////////////////////////////////////////////////////////////////////////////
1045 
1047  return _curSumW2 ;
1048 }
1049 
1050 
1051 
1052 ////////////////////////////////////////////////////////////////////////////////
1053 /// Return the weight at given coordinates with optional
1054 /// interpolation. If intOrder is zero, the weight
1055 /// for the bin enclosing the coordinates
1056 /// contained in 'bin' is returned. For higher values,
1057 /// the result is interpolated in the real dimensions
1058 /// of the dataset
1059 
1060 Double_t RooDataHist::weight(const RooArgSet& bin, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries, Bool_t oneSafe)
1061 {
1062  //cout << "RooDataHist::weight(" << bin << "," << intOrder << "," << correctForBinSize << "," << cdfBoundaries << "," << oneSafe << ")" << endl ;
1063 
1064  checkInit() ;
1065 
1066  // Handle illegal intOrder values
1067  if (intOrder<0) {
1068  coutE(InputArguments) << "RooDataHist::weight(" << GetName() << ") ERROR: interpolation order must be positive" << endl ;
1069  return 0 ;
1070  }
1071 
1072  // Handle no-interpolation case
1073  if (intOrder==0) {
1074  _vars.assignValueOnly(bin,oneSafe) ;
1075  Int_t idx = calcTreeIndex() ;
1076  //cout << "intOrder 0, idx = " << idx << endl ;
1077  if (correctForBinSize) {
1078  //calculatePartialBinVolume(*get()) ;
1079  //cout << "binw[" << idx << "] = " << _wgt[idx] << " / " << _binv[idx] << endl ;
1080  return get_wgt(idx) / _binv[idx];
1081  } else {
1082  //cout << "binw[" << idx << "] = " << _wgt[idx] << endl ;
1083  return get_wgt(idx);
1084  }
1085  }
1086 
1087  // Handle all interpolation cases
1088  _vars.assignValueOnly(bin) ;
1089 
1090  Double_t wInt(0) ;
1091  if (_realVars.getSize()==1) {
1092 
1093  // 1-dimensional interpolation
1094  const auto real = static_cast<RooRealVar*>(_realVars[static_cast<std::size_t>(0)]);
1095  const RooAbsBinning* binning = real->getBinningPtr(0) ;
1096  wInt = interpolateDim(*real,binning,((RooAbsReal*)bin.find(*real))->getVal(), intOrder, correctForBinSize, cdfBoundaries) ;
1097 
1098  } else if (_realVars.getSize()==2) {
1099 
1100  // 2-dimensional interpolation
1101  const auto realX = static_cast<RooRealVar*>(_realVars[static_cast<std::size_t>(0)]);
1102  const auto realY = static_cast<RooRealVar*>(_realVars[static_cast<std::size_t>(1)]);
1103  Double_t xval = ((RooAbsReal*)bin.find(*realX))->getVal() ;
1104  Double_t yval = ((RooAbsReal*)bin.find(*realY))->getVal() ;
1105 
1106  Int_t ybinC = realY->getBin() ;
1107  Int_t ybinLo = ybinC-intOrder/2 - ((yval<realY->getBinning().binCenter(ybinC))?1:0) ;
1108  Int_t ybinM = realY->numBins() ;
1109 
1110  Int_t i ;
1111  Double_t yarr[10] ;
1112  Double_t xarr[10] ;
1113  const RooAbsBinning* binning = realX->getBinningPtr(0) ;
1114  for (i=ybinLo ; i<=intOrder+ybinLo ; i++) {
1115  Int_t ibin ;
1116  if (i>=0 && i<ybinM) {
1117  // In range
1118  ibin = i ;
1119  realY->setBin(ibin) ;
1120  xarr[i-ybinLo] = realY->getVal() ;
1121  } else if (i>=ybinM) {
1122  // Overflow: mirror
1123  ibin = 2*ybinM-i-1 ;
1124  realY->setBin(ibin) ;
1125  xarr[i-ybinLo] = 2*realY->getMax()-realY->getVal() ;
1126  } else {
1127  // Underflow: mirror
1128  ibin = -i -1;
1129  realY->setBin(ibin) ;
1130  xarr[i-ybinLo] = 2*realY->getMin()-realY->getVal() ;
1131  }
1132  yarr[i-ybinLo] = interpolateDim(*realX,binning,xval,intOrder,correctForBinSize,kFALSE) ;
1133  }
1134 
1135  if (gDebug>7) {
1136  cout << "RooDataHist interpolating data is" << endl ;
1137  cout << "xarr = " ;
1138  for (int q=0; q<=intOrder ; q++) cout << xarr[q] << " " ;
1139  cout << " yarr = " ;
1140  for (int q=0; q<=intOrder ; q++) cout << yarr[q] << " " ;
1141  cout << endl ;
1142  }
1143  wInt = RooMath::interpolate(xarr,yarr,intOrder+1,yval) ;
1144 
1145  } else {
1146 
1147  // Higher dimensional scenarios not yet implemented
1148  coutE(InputArguments) << "RooDataHist::weight(" << GetName() << ") interpolation in "
1149  << _realVars.getSize() << " dimensions not yet implemented" << endl ;
1150  return weight(bin,0) ;
1151 
1152  }
1153 
1154  // Cut off negative values
1155 // if (wInt<=0) {
1156 // wInt=0 ;
1157 // }
1158 
1159  //cout << "RooDataHist wInt = " << wInt << endl ;
1160  return wInt ;
1161 }
1162 
1163 
1164 
1165 
1166 ////////////////////////////////////////////////////////////////////////////////
1167 /// Return the error on current weight
1168 
1170 {
1171  checkInit() ;
1172 
1173  switch (etype) {
1174 
1175  case Auto:
1176  throw string(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
1177  break ;
1178 
1179  case Expected:
1180  throw string(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
1181  break ;
1182 
1183  case Poisson:
1184  if (_curWgtErrLo>=0) {
1185  // Weight is preset or precalculated
1186  lo = _curWgtErrLo ;
1187  hi = _curWgtErrHi ;
1188  return ;
1189  }
1190 
1191  // Calculate poisson errors
1192  Double_t ym,yp ;
1194  _curWgtErrLo = weight()-ym ;
1195  _curWgtErrHi = yp-weight() ;
1198  lo = _curWgtErrLo ;
1199  hi = _curWgtErrHi ;
1200  return ;
1201 
1202  case SumW2:
1203  lo = sqrt(_curSumW2) ;
1204  hi = sqrt(_curSumW2) ;
1205  return ;
1206 
1207  case None:
1208  lo = 0 ;
1209  hi = 0 ;
1210  return ;
1211  }
1212 }
1213 
1214 
1215 // wve adjust for variable bin sizes
1216 
1217 ////////////////////////////////////////////////////////////////////////////////
1218 /// Perform boundary safe 'intOrder'-th interpolation of weights in dimension 'dim'
1219 /// at current value 'xval'
1220 
1221 Double_t RooDataHist::interpolateDim(RooRealVar& dim, const RooAbsBinning* binning, Double_t xval, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries)
1222 {
1223  // Fill workspace arrays spanning interpolation area
1224  Int_t fbinC = dim.getBin(*binning) ;
1225  Int_t fbinLo = fbinC-intOrder/2 - ((xval<binning->binCenter(fbinC))?1:0) ;
1226  Int_t fbinM = dim.numBins(*binning) ;
1227 
1228 
1229  Int_t i ;
1230  Double_t yarr[10] ;
1231  Double_t xarr[10] ;
1232  for (i=fbinLo ; i<=intOrder+fbinLo ; i++) {
1233  Int_t ibin ;
1234  if (i>=0 && i<fbinM) {
1235  // In range
1236  ibin = i ;
1237  dim.setBinFast(ibin,*binning) ;
1238  //cout << "INRANGE: dim.getVal(ibin=" << ibin << ") = " << dim.getVal() << endl ;
1239  xarr[i-fbinLo] = dim.getVal() ;
1240  Int_t idx = calcTreeIndex();
1241  yarr[i - fbinLo] = get_wgt(idx);
1242  if (correctForBinSize) yarr[i-fbinLo] /= _binv[idx] ;
1243  } else if (i>=fbinM) {
1244  // Overflow: mirror
1245  ibin = 2*fbinM-i-1 ;
1246  dim.setBinFast(ibin,*binning) ;
1247  //cout << "OVERFLOW: dim.getVal(ibin=" << ibin << ") = " << dim.getVal() << endl ;
1248  if (cdfBoundaries) {
1249  xarr[i-fbinLo] = dim.getMax()+1e-10*(i-fbinM+1) ;
1250  yarr[i-fbinLo] = 1.0 ;
1251  } else {
1252  Int_t idx = calcTreeIndex() ;
1253  xarr[i-fbinLo] = 2*dim.getMax()-dim.getVal() ;
1254  yarr[i - fbinLo] = get_wgt(idx);
1255  if (correctForBinSize)
1256  yarr[i - fbinLo] /= _binv[idx];
1257  }
1258  } else {
1259  // Underflow: mirror
1260  ibin = -i - 1 ;
1261  dim.setBinFast(ibin,*binning) ;
1262  //cout << "UNDERFLOW: dim.getVal(ibin=" << ibin << ") = " << dim.getVal() << endl ;
1263  if (cdfBoundaries) {
1264  xarr[i-fbinLo] = dim.getMin()-ibin*(1e-10) ; ;
1265  yarr[i-fbinLo] = 0.0 ;
1266  } else {
1267  Int_t idx = calcTreeIndex() ;
1268  xarr[i-fbinLo] = 2*dim.getMin()-dim.getVal() ;
1269  yarr[i - fbinLo] = get_wgt(idx);
1270  if (correctForBinSize)
1271  yarr[i - fbinLo] /= _binv[idx];
1272  }
1273  }
1274  //cout << "ibin = " << ibin << endl ;
1275  }
1276 // for (int k=0 ; k<=intOrder ; k++) {
1277 // cout << "k=" << k << " x = " << xarr[k] << " y = " << yarr[k] << endl ;
1278 // }
1279  dim.setBinFast(fbinC,*binning) ;
1280  Double_t ret = RooMath::interpolate(xarr,yarr,intOrder+1,xval) ;
1281  return ret ;
1282 }
1283 
1284 
1285 
1286 
1287 ////////////////////////////////////////////////////////////////////////////////
1288 /// Increment the weight of the bin enclosing the coordinates given
1289 /// by 'row' by the specified amount. Add the sum of weights squared
1290 /// for the bin by 'sumw2' rather than wgt^2
1291 
1292 void RooDataHist::add(const RooArgSet& row, Double_t wgt, Double_t sumw2)
1293 {
1294  checkInit() ;
1295 
1296 // cout << "RooDataHist::add() accepted coordinate is " << endl ;
1297 // _vars.Print("v") ;
1298 
1299  _vars = row ;
1300  Int_t idx = calcTreeIndex() ;
1301  _wgt[idx] += wgt ;
1302  _sumw2[idx] += (sumw2>0?sumw2:wgt*wgt) ;
1303  _errLo[idx] = -1 ;
1304  _errHi[idx] = -1 ;
1305 
1307 }
1308 
1309 
1310 
1311 ////////////////////////////////////////////////////////////////////////////////
1312 /// Set the weight and errors of the bin enclosing the coordinates
1313 /// given by `row`. Associate errors [wgtErrLo,wgtErrHi] with the event weight on this bin.
1314 void RooDataHist::set(const RooArgSet& row, Double_t wgt, Double_t wgtErrLo, Double_t wgtErrHi)
1315 {
1316  checkInit() ;
1317 
1318  _vars = row ;
1319  Int_t idx = calcTreeIndex() ;
1320  _wgt[idx] = wgt ;
1321  _errLo[idx] = wgtErrLo ;
1322  _errHi[idx] = wgtErrHi ;
1323 
1325 }
1326 
1327 
1328 
1329 ////////////////////////////////////////////////////////////////////////////////
1330 /// Set the weight and weight error of the bin enclosing the current (i.e. last-used)
1331 /// coordinates.
1333 {
1334  checkInit() ;
1335 
1336  if (_curIndex<0) {
1337  _curIndex = calcTreeIndex() ;
1338  }
1339 
1340  _wgt[_curIndex] = wgt ;
1341  _errLo[_curIndex] = wgtErr ;
1342  _errHi[_curIndex] = wgtErr ;
1343  _sumw2[_curIndex] = wgtErr*wgtErr ;
1344 
1346 }
1347 
1348 
1349 
1350 ////////////////////////////////////////////////////////////////////////////////
1351 /// Set the weight and weight error of the bin enclosing the coordinates
1352 /// given by `row`.
1353 void RooDataHist::set(const RooArgSet& row, Double_t wgt, Double_t wgtErr)
1354 {
1355  checkInit() ;
1356 
1357  _vars = row ;
1358  Int_t idx = calcTreeIndex() ;
1359  _wgt[idx] = wgt ;
1360  _errLo[idx] = wgtErr ;
1361  _errHi[idx] = wgtErr ;
1362  _sumw2[idx] = wgtErr*wgtErr ;
1363 
1365 }
1366 
1367 
1368 
1369 ////////////////////////////////////////////////////////////////////////////////
1370 /// Add all data points contained in 'dset' to this data set with given weight.
1371 /// Optional cut string expression selects the data points to be added and can
1372 /// reference any variable contained in this data set
1373 
1374 void RooDataHist::add(const RooAbsData& dset, const char* cut, Double_t wgt)
1375 {
1376  RooFormulaVar cutVar("select",cut,*dset.get()) ;
1377  add(dset,&cutVar,wgt) ;
1378 }
1379 
1380 
1381 
1382 ////////////////////////////////////////////////////////////////////////////////
1383 /// Add all data points contained in 'dset' to this data set with given weight.
1384 /// Optional RooFormulaVar pointer selects the data points to be added.
1385 
1386 void RooDataHist::add(const RooAbsData& dset, const RooFormulaVar* cutVar, Double_t wgt)
1387 {
1388  checkInit() ;
1389 
1390  RooFormulaVar* cloneVar = 0;
1391  RooArgSet* tmp(0) ;
1392  if (cutVar) {
1393  // Deep clone cutVar and attach clone to this dataset
1394  tmp = (RooArgSet*) RooArgSet(*cutVar).snapshot() ;
1395  if (!tmp) {
1396  coutE(DataHandling) << "RooDataHist::add(" << GetName() << ") Couldn't deep-clone cut variable, abort," << endl ;
1397  return ;
1398  }
1399 
1400  cloneVar = (RooFormulaVar*) tmp->find(*cutVar) ;
1401  cloneVar->attachDataSet(dset) ;
1402  }
1403 
1404 
1405  Int_t i ;
1406  for (i=0 ; i<dset.numEntries() ; i++) {
1407  const RooArgSet* row = dset.get(i) ;
1408  if (!cloneVar || cloneVar->getVal()) {
1409  add(*row,wgt*dset.weight(), wgt*wgt*dset.weightSquared()) ;
1410  }
1411  }
1412 
1413  if (cloneVar) {
1414  delete tmp ;
1415  }
1416 
1418 }
1419 
1420 
1421 
1422 ////////////////////////////////////////////////////////////////////////////////
1423 /// Return the sum of the weights of all hist bins.
1424 ///
1425 /// If correctForBinSize is specified, the sum of weights
1426 /// is multiplied by the N-dimensional bin volume,
1427 /// making the return value the integral over the function
1428 /// represented by this histogram
1429 
1430 Double_t RooDataHist::sum(Bool_t correctForBinSize, Bool_t inverseBinCor) const
1431 {
1432  checkInit() ;
1433 
1434  // Check if result was cached
1435  Int_t cache_code = 1 + (correctForBinSize?1:0) + ((correctForBinSize&&inverseBinCor)?1:0) ;
1436  if (_cache_sum_valid==cache_code) {
1437  return _cache_sum ;
1438  }
1439 
1440  Int_t i ;
1441  Double_t total(0), carry(0);
1442  for (i=0 ; i<_arrSize ; i++) {
1443 
1444  Double_t theBinVolume = correctForBinSize ? (inverseBinCor ? 1/_binv[i] : _binv[i]) : 1.0 ;
1445  // cout << "total += " << _wgt[i] << "*" << theBinVolume << endl ;
1446  // Double_t y = _wgt[i]*theBinVolume - carry;
1447  Double_t y = get_wgt(i) * theBinVolume - carry;
1448  Double_t t = total + y;
1449  carry = (t - total) - y;
1450  total = t;
1451  }
1452 
1453  // Store result in cache
1454  _cache_sum_valid=cache_code ;
1455  _cache_sum = total ;
1456 
1457  return total ;
1458 }
1459 
1460 
1461 
1462 ////////////////////////////////////////////////////////////////////////////////
1463 /// Return the sum of the weights of a multi-dimensional slice of the histogram
1464 /// by summing only over the dimensions specified in sumSet.
1465 ///
1466 /// The coordinates of all other dimensions are fixed to those given in sliceSet
1467 ///
1468 /// If correctForBinSize is specified, the sum of weights
1469 /// is multiplied by the M-dimensional bin volume, (M = N(sumSet)),
1470 /// making the return value the integral over the function
1471 /// represented by this histogram
1472 
1473 Double_t RooDataHist::sum(const RooArgSet& sumSet, const RooArgSet& sliceSet, Bool_t correctForBinSize, Bool_t inverseBinCor)
1474 {
1475  checkInit() ;
1476 
1477  RooArgSet varSave ;
1478  varSave.addClone(_vars) ;
1479 
1480  RooArgSet* sliceOnlySet = new RooArgSet(sliceSet) ;
1481  sliceOnlySet->remove(sumSet,kTRUE,kTRUE) ;
1482 
1483  _vars = *sliceOnlySet ;
1484  calculatePartialBinVolume(*sliceOnlySet) ;
1485  delete sliceOnlySet ;
1486 
1487  // Calculate mask and refence plot bins for non-iterating variables
1488  Bool_t* mask = new Bool_t[_vars.getSize()] ;
1489  Int_t* refBin = new Int_t[_vars.getSize()] ;
1490 
1491  for (unsigned int i = 0; i < _vars.size(); ++i) {
1492  const auto arg = _vars[i];
1493 
1494  if (sumSet.find(*arg)) {
1495  mask[i] = kFALSE ;
1496  } else {
1497  mask[i] = kTRUE ;
1498  refBin[i] = dynamic_cast<RooAbsLValue*>(arg)->getBin();
1499  }
1500  }
1501 
1502  // Loop over entire data set, skipping masked entries
1503  Double_t total(0), carry(0);
1504  Int_t ibin ;
1505  for (ibin=0 ; ibin<_arrSize ; ibin++) {
1506 
1507  Int_t idx(0), tmp(ibin), ivar(0) ;
1508  Bool_t skip(kFALSE) ;
1509 
1510  // Check if this bin belongs in selected slice
1511  for (unsigned int i = 0; !skip && i < _vars.size(); ++i) {
1512  idx = tmp / _idxMult[ivar] ;
1513  tmp -= idx*_idxMult[ivar] ;
1514  if (mask[ivar] && idx!=refBin[ivar]) skip=kTRUE ;
1515  ivar++ ;
1516  }
1517 
1518  if (!skip) {
1519  Double_t theBinVolume = correctForBinSize ? (inverseBinCor ? 1/(*_pbinv)[_vars.size()] : (*_pbinv)[_vars.size()] ) : 1.0 ;
1520  // cout << "adding bin[" << ibin << "] to sum wgt = " << _wgt[ibin] << " binv = " << theBinVolume << endl ;
1521  // Double_t y = _wgt[ibin]*theBinVolume - carry;
1522  Double_t y = get_wgt(ibin) * theBinVolume - carry;
1523  Double_t t = total + y;
1524  carry = (t - total) - y;
1525  total = t;
1526  }
1527  }
1528 
1529  delete[] mask ;
1530  delete[] refBin ;
1531 
1532  _vars = varSave ;
1533 
1534  return total ;
1535 }
1536 
1537 ////////////////////////////////////////////////////////////////////////////////
1538 /// Return the sum of the weights of a multi-dimensional slice of the histogram
1539 /// by summing only over the dimensions specified in sumSet.
1540 ///
1541 /// The coordinates of all other dimensions are fixed to those given in sliceSet
1542 ///
1543 /// If correctForBinSize is specified, the sum of weights
1544 /// is multiplied by the M-dimensional bin volume, (M = N(sumSet)),
1545 /// or the fraction of it that falls inside the range rangeName,
1546 /// making the return value the integral over the function
1547 /// represented by this histogram.
1548 ///
1549 /// If correctForBinSize is not specified, the weights are multiplied by the
1550 /// fraction of the bin volume that falls inside the range, i.e. a factor of
1551 /// binVolumeInRange/totalBinVolume.
1552 
1553 Double_t RooDataHist::sum(const RooArgSet& sumSet, const RooArgSet& sliceSet,
1554  Bool_t correctForBinSize, Bool_t inverseBinCor,
1555  const std::map<const RooAbsArg*, std::pair<Double_t, Double_t> >& ranges)
1556 {
1557  checkInit();
1558  checkBinBounds();
1559  RooArgSet varSave;
1560  varSave.addClone(_vars);
1561  {
1562  RooArgSet sliceOnlySet(sliceSet);
1563  sliceOnlySet.remove(sumSet,kTRUE,kTRUE);
1564  _vars = sliceOnlySet;
1565  }
1566 
1567  // Calculate mask and reference plot bins for non-iterating variables,
1568  // and get ranges for iterating variables
1569  std::vector<bool> mask(_vars.getSize());
1570  std::vector<Int_t> refBin(_vars.getSize());
1571  std::vector<Double_t> rangeLo(_vars.getSize(), -std::numeric_limits<Double_t>::infinity());
1572  std::vector<Double_t> rangeHi(_vars.getSize(), +std::numeric_limits<Double_t>::infinity());
1573 
1574  for (std::size_t i = 0; i < _vars.size(); ++i) {
1575  const auto arg = _vars[i];
1576  RooAbsArg* sumsetv = sumSet.find(*arg);
1577  RooAbsArg* slicesetv = sliceSet.find(*arg);
1578  mask[i] = !sumsetv;
1579  if (mask[i]) {
1580  auto argLV = dynamic_cast<const RooAbsLValue*>(arg);
1581  assert(argLV);
1582  refBin[i] = argLV->getBin();
1583  }
1584 
1585  auto it = ranges.find(sumsetv ? sumsetv : slicesetv);
1586  if (ranges.end() != it) {
1587  rangeLo[i] = it->second.first;
1588  rangeHi[i] = it->second.second;
1589  }
1590  }
1591 
1592  // Loop over entire data set, skipping masked entries
1593  Double_t total(0), carry(0);
1594  for (Int_t ibin = 0; ibin < _arrSize; ++ibin) {
1595  // Check if this bin belongs in selected slice
1596  Bool_t skip(kFALSE);
1597  for (int ivar = 0, tmp = ibin; !skip && ivar < int(_vars.size()); ++ivar) {
1598  const Int_t idx = tmp / _idxMult[ivar];
1599  tmp -= idx*_idxMult[ivar];
1600  if (mask[ivar] && idx!=refBin[ivar]) skip=kTRUE;
1601  }
1602 
1603  if (skip) continue;
1604 
1605  // work out bin volume
1606  Double_t theBinVolume = 1.;
1607  for (Int_t ivar = 0, tmp = ibin; ivar < (int)_vars.size(); ++ivar) {
1608  const Int_t idx = tmp / _idxMult[ivar];
1609  tmp -= idx*_idxMult[ivar];
1610  if (_binbounds[ivar].empty()) continue;
1611  const Double_t binLo = _binbounds[ivar][2 * idx];
1612  const Double_t binHi = _binbounds[ivar][2 * idx + 1];
1613  if (binHi < rangeLo[ivar] || binLo > rangeHi[ivar]) {
1614  // bin is outside of allowed range - effective bin volume is zero
1615  theBinVolume = 0.;
1616  break;
1617  }
1618  theBinVolume *=
1619  (std::min(rangeHi[ivar], binHi) - std::max(rangeLo[ivar], binLo));
1620  }
1621  const Double_t corrPartial = theBinVolume / _binv[ibin];
1622  if (0. == corrPartial) continue;
1623  const Double_t corr = correctForBinSize ? (inverseBinCor ? 1. / _binv[ibin] : _binv[ibin] ) : 1.0;
1624  //cout << "adding bin[" << ibin << "] to sum wgt = " << _wgt[ibin] << " binv = " << theBinVolume << " _binv[" << ibin << "] " << _binv[ibin] << endl;
1625  // const Double_t y = _wgt[ibin] * corr * corrPartial - carry;
1626  const Double_t y = get_wgt(ibin) * corr * corrPartial - carry;
1627  const Double_t t = total + y;
1628  carry = (t - total) - y;
1629  total = t;
1630  }
1631 
1632  _vars = varSave;
1633 
1634  return total;
1635 }
1636 
1637 
1638 
1639 ////////////////////////////////////////////////////////////////////////////////
1640 /// Fill the transient cache with partial bin volumes with up-to-date
1641 /// values for the partial volume specified by observables 'dimSet'
1642 
1644 {
1645  // Allocate cache if not yet existing
1646  vector<Double_t> *pbinv = _pbinvCacheMgr.getObj(&dimSet) ;
1647  if (pbinv) {
1648  _pbinv = pbinv ;
1649  return ;
1650  }
1651 
1652  pbinv = new vector<Double_t>(_arrSize) ;
1653 
1654  // Calculate plot bins of components from master index
1655  Bool_t* selDim = new Bool_t[_vars.getSize()] ;
1656  Int_t i(0) ;
1657  for (const auto v : _vars) {
1658  selDim[i++] = dimSet.find(*v) ? kTRUE : kFALSE ;
1659  }
1660 
1661  // Recalculate partial bin volume cache
1662  Int_t ibin ;
1663  for (ibin=0 ; ibin<_arrSize ; ibin++) {
1664  Int_t j(0), idx(0), tmp(ibin) ;
1665  Double_t theBinVolume(1) ;
1666  for (const auto absArg : _vars) {
1667  auto arg = dynamic_cast<const RooAbsLValue*>(absArg);
1668  if (!arg)
1669  break;
1670 
1671  idx = tmp / _idxMult[j] ;
1672  tmp -= idx*_idxMult[j++] ;
1673  if (selDim[j-1]) {
1674  theBinVolume *= arg->getBinWidth(idx) ;
1675  }
1676  }
1677  (*pbinv)[ibin] = theBinVolume ;
1678  }
1679 
1680  delete[] selDim ;
1681 
1682  // Put in cache (which takes ownership)
1683  _pbinvCacheMgr.setObj(&dimSet,pbinv) ;
1684 
1685  // Publicize the array
1686  _pbinv = pbinv ;
1687 }
1688 
1689 
1690 
1691 ////////////////////////////////////////////////////////////////////////////////
1692 /// Return the number of bins
1693 
1695 {
1696  return RooAbsData::numEntries() ;
1697 }
1698 
1699 
1700 
1701 ////////////////////////////////////////////////////////////////////////////////
1702 
1704 {
1705  Int_t i ;
1706  Double_t n(0), carry(0);
1707  for (i=0 ; i<_arrSize ; i++) {
1708  if (!_binValid || _binValid[i]) {
1709  // Double_t y = _wgt[i] - carry;
1710  Double_t y = get_wgt(i) - carry;
1711  Double_t t = n + y;
1712  carry = (t - n) - y;
1713  n = t;
1714  }
1715  }
1716  return n ;
1717 }
1718 
1719 
1720 
1721 ////////////////////////////////////////////////////////////////////////////////
1722 /// Return the sum of weights in all entries matching cutSpec (if specified)
1723 /// and in named range cutRange (if specified)
1724 /// Return the
1725 
1726 Double_t RooDataHist::sumEntries(const char* cutSpec, const char* cutRange) const
1727 {
1728  checkInit() ;
1729 
1730  if (cutSpec==0 && cutRange==0) {
1731  return sumEntries();
1732  } else {
1733 
1734  // Setup RooFormulaVar for cutSpec if it is present
1735  RooFormula* select = 0 ;
1736  if (cutSpec) {
1737  select = new RooFormula("select",cutSpec,*get()) ;
1738  }
1739 
1740  // Otherwise sum the weights in the event
1741  Double_t sumw(0), carry(0);
1742  Int_t i ;
1743  for (i=0 ; i<numEntries() ; i++) {
1744  get(i) ;
1745  if (select && select->eval()==0.) continue ;
1746  if (cutRange && !_vars.allInRange(cutRange)) continue ;
1747 
1748  if (!_binValid || _binValid[i]) {
1749  Double_t y = weight() - carry;
1750  Double_t t = sumw + y;
1751  carry = (t - sumw) - y;
1752  sumw = t;
1753  }
1754  }
1755 
1756  if (select) delete select ;
1757 
1758  return sumw ;
1759  }
1760 }
1761 
1762 
1763 
1764 ////////////////////////////////////////////////////////////////////////////////
1765 /// Reset all bin weights to zero
1766 
1768 {
1769  // WVE DO NOT CALL RooTreeData::reset() for binned
1770  // datasets as this will delete the bin definitions
1771 
1772  Int_t i ;
1773  for (i=0 ; i<_arrSize ; i++) {
1774  _wgt[i] = 0. ;
1775  _errLo[i] = -1 ;
1776  _errHi[i] = -1 ;
1777  }
1778  _curWeight = 0 ;
1779  _curWgtErrLo = -1 ;
1780  _curWgtErrHi = -1 ;
1781  _curVolume = 1 ;
1782 
1784 
1785 }
1786 
1787 
1788 
1789 ////////////////////////////////////////////////////////////////////////////////
1790 /// Return an argset with the bin center coordinates for
1791 /// bin sequential number 'masterIdx'. For iterative use.
1792 
1793 const RooArgSet* RooDataHist::get(Int_t masterIdx) const
1794 {
1795  checkInit() ;
1796  _curWeight = _wgt[masterIdx] ;
1797  _curWgtErrLo = _errLo[masterIdx] ;
1798  _curWgtErrHi = _errHi[masterIdx] ;
1799  _curSumW2 = _sumw2[masterIdx] ;
1800  _curVolume = _binv[masterIdx] ;
1801  _curIndex = masterIdx ;
1802  return RooAbsData::get(masterIdx) ;
1803 }
1804 
1805 
1806 
1807 ////////////////////////////////////////////////////////////////////////////////
1808 /// Return a RooArgSet with center coordinates of the bin
1809 /// enclosing the point 'coord'
1810 
1811 const RooArgSet* RooDataHist::get(const RooArgSet& coord) const
1812 {
1813  ((RooDataHist*)this)->_vars = coord ;
1814  return get(calcTreeIndex()) ;
1815 }
1816 
1817 
1818 
1819 ////////////////////////////////////////////////////////////////////////////////
1820 /// Return the volume of the bin enclosing coordinates 'coord'
1821 
1823 {
1824  checkInit() ;
1825  ((RooDataHist*)this)->_vars = coord ;
1826  return _binv[calcTreeIndex()] ;
1827 }
1828 
1829 
1830 ////////////////////////////////////////////////////////////////////////////////
1831 /// Set all the event weight of all bins to the specified value
1832 
1834 {
1835  for (Int_t i=0 ; i<_arrSize ; i++) {
1836  _wgt[i] = value ;
1837  }
1838 
1840 }
1841 
1842 
1843 
1844 ////////////////////////////////////////////////////////////////////////////////
1845 /// Create an iterator over all bins in a slice defined by the subset of observables
1846 /// listed in sliceArg. The position of the slice is given by otherArgs
1847 
1849 {
1850  // Update to current position
1851  _vars = otherArgs ;
1852  _curIndex = calcTreeIndex() ;
1853 
1854  RooAbsArg* intArg = _vars.find(sliceArg) ;
1855  if (!intArg) {
1856  coutE(InputArguments) << "RooDataHist::sliceIterator() variable " << sliceArg.GetName() << " is not part of this RooDataHist" << endl ;
1857  return 0 ;
1858  }
1859  return new RooDataHistSliceIter(*this,*intArg) ;
1860 }
1861 
1862 
1863 ////////////////////////////////////////////////////////////////////////////////
1864 /// Change the name of the RooDataHist
1865 
1866 void RooDataHist::SetName(const char *name)
1867 {
1868  if (_dir) _dir->GetList()->Remove(this);
1870  if (_dir) _dir->GetList()->Add(this);
1871 }
1872 
1873 
1874 ////////////////////////////////////////////////////////////////////////////////
1875 /// Change the title of this RooDataHist
1876 
1877 void RooDataHist::SetNameTitle(const char *name, const char* title)
1878 {
1879  if (_dir) _dir->GetList()->Remove(this);
1880  TNamed::SetNameTitle(name,title) ;
1881  if (_dir) _dir->GetList()->Add(this);
1882 }
1883 
1884 
1885 ////////////////////////////////////////////////////////////////////////////////
1886 /// Print value of the dataset, i.e. the sum of weights contained in the dataset
1887 
1888 void RooDataHist::printValue(ostream& os) const
1889 {
1890  os << numEntries() << " bins (" << sumEntries() << " weights)" ;
1891 }
1892 
1893 
1894 
1895 
1896 ////////////////////////////////////////////////////////////////////////////////
1897 /// Print argument of dataset, i.e. the observable names
1898 
1899 void RooDataHist::printArgs(ostream& os) const
1900 {
1901  os << "[" ;
1902  Bool_t first(kTRUE) ;
1903  for (const auto arg : _vars) {
1904  if (first) {
1905  first=kFALSE ;
1906  } else {
1907  os << "," ;
1908  }
1909  os << arg->GetName() ;
1910  }
1911  os << "]" ;
1912 }
1913 
1914 
1915 
1916 ////////////////////////////////////////////////////////////////////////////////
1917 /// Cache the datahist entries with bin centers that are inside/outside the
1918 /// current observable definitio
1919 
1921 {
1922  checkInit() ;
1923 
1924  if (!_binValid) {
1925  _binValid = new Bool_t[_arrSize] ;
1926  }
1927  TIterator* iter = _vars.createIterator() ;
1928  RooAbsArg* arg ;
1929  for (Int_t i=0 ; i<_arrSize ; i++) {
1930  get(i) ;
1931  _binValid[i] = kTRUE ;
1932  iter->Reset() ;
1933  while((arg=(RooAbsArg*)iter->Next())) {
1934  // coverity[CHECKED_RETURN]
1935  _binValid[i] &= arg->inRange(0) ;
1936  }
1937  }
1938  delete iter ;
1939 
1940 }
1941 
1942 
1943 ////////////////////////////////////////////////////////////////////////////////
1944 /// Return true if currently loaded coordinate is considered valid within
1945 /// the current range definitions of all observables
1946 
1948 {
1949  // If caching is enabled, use the precached result
1950  if (_binValid) {
1951  return _binValid[_curIndex] ;
1952  }
1953 
1954  return kTRUE ;
1955 }
1956 
1957 
1958 
1959 ////////////////////////////////////////////////////////////////////////////////
1960 /// Returns true if datasets contains entries with a non-integer weight
1961 
1963 {
1964  for (int i=0 ; i<numEntries() ; i++) {
1965  if (fabs(_wgt[i]-Int_t(_wgt[i]))>1e-10) return kTRUE ;
1966  }
1967  return kFALSE ;
1968 }
1969 
1970 
1971 
1972 
1973 ////////////////////////////////////////////////////////////////////////////////
1974 /// Print the details on the dataset contents
1975 
1976 void RooDataHist::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
1977 {
1979 
1980  os << indent << "Binned Dataset " << GetName() << " (" << GetTitle() << ")" << endl ;
1981  os << indent << " Contains " << numEntries() << " bins with a total weight of " << sumEntries() << endl;
1982 
1983  if (!verbose) {
1984  os << indent << " Observables " << _vars << endl ;
1985  } else {
1986  os << indent << " Observables: " ;
1988  }
1989 
1990  if(verbose) {
1991  if (_cachedVars.getSize()>0) {
1992  os << indent << " Caches " << _cachedVars << endl ;
1993  }
1994  }
1995 }
1996 
1997 
1998 
1999 ////////////////////////////////////////////////////////////////////////////////
2000 /// Stream an object of class RooDataHist.
2001 
2002 void RooDataHist::Streamer(TBuffer &R__b)
2003 {
2004  if (R__b.IsReading()) {
2005 
2006  UInt_t R__s, R__c;
2007  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
2008 
2009  if (R__v>2) {
2010 
2011  R__b.ReadClassBuffer(RooDataHist::Class(),this,R__v,R__s,R__c);
2012  initialize(0,kFALSE) ;
2013 
2014  } else {
2015 
2016  // Legacy dataset conversion happens here. Legacy RooDataHist inherits from RooTreeData
2017  // which in turn inherits from RooAbsData. Manually stream RooTreeData contents on
2018  // file here and convert it into a RooTreeDataStore which is installed in the
2019  // new-style RooAbsData base class
2020 
2021  // --- This is the contents of the streamer code of RooTreeData version 2 ---
2022  UInt_t R__s1, R__c1;
2023  Version_t R__v1 = R__b.ReadVersion(&R__s1, &R__c1); if (R__v1) { }
2024 
2025  RooAbsData::Streamer(R__b);
2026  TTree* X_tree(0) ; R__b >> X_tree;
2027  RooArgSet X_truth ; X_truth.Streamer(R__b);
2028  TString X_blindString ; X_blindString.Streamer(R__b);
2029  R__b.CheckByteCount(R__s1, R__c1, RooTreeData::Class());
2030  // --- End of RooTreeData-v1 streamer
2031 
2032  // Construct RooTreeDataStore from X_tree and complete initialization of new-style RooAbsData
2033  _dstore = new RooTreeDataStore(X_tree,_vars) ;
2034  _dstore->SetName(GetName()) ;
2035  _dstore->SetTitle(GetTitle()) ;
2036  _dstore->checkInit() ;
2037 
2038  RooDirItem::Streamer(R__b);
2039  R__b >> _arrSize;
2040  delete [] _wgt;
2041  _wgt = new Double_t[_arrSize];
2042  R__b.ReadFastArray(_wgt,_arrSize);
2043  delete [] _errLo;
2044  _errLo = new Double_t[_arrSize];
2046  delete [] _errHi;
2047  _errHi = new Double_t[_arrSize];
2049  delete [] _sumw2;
2050  _sumw2 = new Double_t[_arrSize];
2052  delete [] _binv;
2053  _binv = new Double_t[_arrSize];
2055  _realVars.Streamer(R__b);
2056  R__b >> _curWeight;
2057  R__b >> _curWgtErrLo;
2058  R__b >> _curWgtErrHi;
2059  R__b >> _curSumW2;
2060  R__b >> _curVolume;
2061  R__b >> _curIndex;
2062  R__b.CheckByteCount(R__s, R__c, RooDataHist::IsA());
2063 
2064  }
2065 
2066  } else {
2067 
2068  R__b.WriteClassBuffer(RooDataHist::Class(),this);
2069  }
2070 }
2071 
2072 
RooFormulaVar.h
RooDirItem::removeFromDir
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
Definition: RooDirItem.cxx:43
l
auto * l
Definition: textangle.C:4
RooAbsData::Tree
@ Tree
Definition: RooAbsData.h:237
RooDataHist::_binbounds
std::vector< std::vector< Double_t > > _binbounds
List of used binnings associated with lvalues.
Definition: RooDataHist.h:205
Util.h
RooAbsCategoryLValue::setBin
virtual void setBin(Int_t ibin, const char *rangeName=0)
Set category to i-th fit bin, which is the i-th registered state.
Definition: RooAbsCategoryLValue.cxx:177
RooFormula
Definition: RooFormula.h:28
RooDataHist::_curIndex
Int_t _curIndex
Definition: RooDataHist.h:199
RooDataHist::_pbinvCacheMgr
RooCacheManager< std::vector< Double_t > > _pbinvCacheMgr
Partial bin volume array.
Definition: RooDataHist.h:202
n
const Int_t n
Definition: legend1.C:16
TAxis
Class to manage histogram axis.
Definition: TAxis.h:30
RooBinning::averageBinWidth
virtual Double_t averageBinWidth() const
Definition: RooBinning.h:56
RooLinkedList::MakeIterator
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
Definition: RooLinkedList.cxx:747
RooTreeData.h
RooBinning::setRange
virtual void setRange(Double_t xlo, Double_t xhi)
Change the defined range associated with this binning.
Definition: RooBinning.cxx:233
RooCmdArg
Definition: RooCmdArg.h:27
RooDataHist::_curWeight
Double_t _curWeight
Valid bins with current range definition.
Definition: RooDataHist.h:194
first
Definition: first.py:1
RooHelpers.h
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooCmdConfig.h
RooPrintable::kVerbose
@ kVerbose
Definition: RooPrintable.h:34
e
#define e(i)
Definition: RSha256.hxx:121
TDirectory::GetList
virtual TList * GetList() const
Definition: TDirectory.h:167
RooLinkedListIter.h
RooAbsData::PlotOpt
Definition: RooAbsData.h:141
RooAbsBinning::numBins
Int_t numBins() const
Return number of bins.
Definition: RooAbsBinning.h:38
Version_t
short Version_t
Definition: RtypesCore.h:65
RooMsgService.h
RooDataHist::setAllWeights
void setAllWeights(Double_t value)
Set all the event weight of all bins to the specified value.
Definition: RooDataHist.cxx:1833
RooUniformBinning.h
TNamed::SetNameTitle
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition: TNamed.cxx:154
RooDataHist::~RooDataHist
virtual ~RooDataHist()
Destructor.
Definition: RooDataHist.cxx:934
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
RooDirItem::_dir
TDirectory * _dir
Definition: RooDirItem.h:33
RooAbsData
Definition: RooAbsData.h:46
RooAbsRealLValue::getMax
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
Definition: RooAbsRealLValue.h:89
RooAbsData::SumW2
@ SumW2
Definition: RooAbsData.h:96
RooFit.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:68
RooDataHist::set
void set(Double_t weight, Double_t wgtErr=-1)
Set the weight and weight error of the bin enclosing the current (i.e.
Definition: RooDataHist.cxx:1332
RooAbsData::printMultiline
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Interface for detailed printing of object.
Definition: RooAbsData.cxx:802
RooDataHist::_curWgtErrHi
Double_t _curWgtErrHi
Definition: RooDataHist.h:196
RooBinning
Definition: RooBinning.h:28
TBuffer::ReadFastArray
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:54
RooLinkedList::GetSize
Int_t GetSize() const
Definition: RooLinkedList.h:60
RooAbsCollection::assignValueOnly
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.
Definition: RooAbsCollection.cxx:330
TBuffer::ReadClassBuffer
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
RooAbsData::_dstore
RooAbsDataStore * _dstore
External variables cached with this data set.
Definition: RooAbsData.h:283
RooAbsData::fill
virtual void fill()
Definition: RooAbsData.cxx:300
coutE
#define coutE(a)
Definition: RooMsgService.h:33
RooDataHist::cacheClone
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.
Definition: RooDataHist.cxx:861
RooArgList
Definition: RooArgList.h:21
TTree
Definition: TTree.h:79
RooAbsData::Auto
@ Auto
Definition: RooAbsData.h:96
RooDirItem
Definition: RooDirItem.h:22
RooAbsData::weight
virtual Double_t weight() const =0
RooDataHist::importTH1Set
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.
Definition: RooDataHist.cxx:438
BatchHelpers::init
EvaluateInfo init(std::vector< RooRealProxy > parameters, std::vector< ArrayWrapper * > wrappers, std::vector< double * > arrays, size_t begin, size_t batchSize)
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooDataHist::get
virtual const RooArgSet * get() const
Definition: RooDataHist.h:78
RooDataHist::weightSquared
Double_t weightSquared() const
Definition: RooDataHist.cxx:1046
RooDataHist::importTH1
void importTH1(const RooArgList &vars, const TH1 &histo, Double_t initWgt, Bool_t doDensityCorrection)
Import data from given TH1/2/3 into this RooDataHist.
Definition: RooDataHist.cxx:371
Int_t
int Int_t
Definition: RtypesCore.h:45
TH1::GetBinError
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8518
RooAbsData::defaultStorageType
static StorageType defaultStorageType
Definition: RooAbsData.h:245
RooAbsCollection::remove
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
Definition: RooAbsCollection.cxx:584
RooAbsData::PlotOpt::correctForBinWidth
Bool_t correctForBinWidth
Definition: RooAbsData.h:157
RooAbsCollection::find
RooAbsArg * find(const char *name) const
Find object with given name in list.
Definition: RooAbsCollection.cxx:813
TGeant4Unit::pc
static constexpr double pc
Definition: TGeant4SystemOfUnits.h:136
RooDataHist::weight
virtual Double_t weight() const
Definition: RooDataHist.h:105
coutI
#define coutI(a)
Definition: RooMsgService.h:30
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
RooHistError::getPoissonInterval
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.
Definition: RooHistError.cxx:79
RooArgSet::add
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
RooFormula.h
RooAbsReal
Definition: RooAbsReal.h:61
RooArgList::at
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition: RooArgList.h:88
TBuffer
Definition: TBuffer.h:43
RooAbsData::checkInit
void checkInit() const
Definition: RooAbsData.cxx:2331
RooDataHist::_binValid
Bool_t * _binValid
Definition: RooDataHist.h:192
TTree.h
RooDataHist::getIndex
Int_t getIndex(const RooArgSet &coord, Bool_t fast=kFALSE)
Calculate bin number of the given coordinates.
Definition: RooDataHist.cxx:962
TBuffer::CheckByteCount
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
TString
Definition: TString.h:136
RooDataHist::importDHistSet
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.
Definition: RooDataHist.cxx:535
RooAbsLValue::getBin
virtual Int_t getBin(const char *rangeName=0) const =0
RooDataHistSliceIter.h
RooRealVar::setRange
void setRange(const char *name, Double_t min, Double_t max)
Set a fit or plotting range.
Definition: RooRealVar.cxx:485
TH1::GetZaxis
TAxis * GetZaxis()
Definition: TH1.h:319
RooAbsData::ErrorType
ErrorType
Definition: RooAbsData.h:96
RooAbsCategory::getCurrentLabel
virtual const char * getCurrentLabel() const
Return label string of current state.
Definition: RooAbsCategory.cxx:130
v
@ v
Definition: rootcling_impl.cxx:3635
RooTreeDataStore.h
RooCategory::defineType
bool defineType(const std::string &label)
Define a state with given name.
Definition: RooCategory.cxx:208
RooDataHist::_cache_sum
Double_t _cache_sum
Is cache sum valid.
Definition: RooDataHist.h:208
bool
TIterator
Definition: TIterator.h:30
RooAbsRealLValue::getMin
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
Definition: RooAbsRealLValue.h:86
RooDataHist::add
virtual void add(const RooArgSet &row, Double_t wgt=1.0)
Definition: RooDataHist.h:66
q
float * q
Definition: THbookFile.cxx:89
RooHistError::instance
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
Definition: RooHistError.cxx:49
TH1::GetDimension
virtual Int_t GetDimension() const
Definition: TH1.h:279
RooCmdConfig
Definition: RooCmdConfig.h:27
RooDataHist::weightError
virtual void weightError(Double_t &lo, Double_t &hi, ErrorType etype=Poisson) const
Return the error on current weight.
Definition: RooDataHist.cxx:1169
RooAbsBinning::binCenter
virtual Double_t binCenter(Int_t bin) const =0
RooDataHist::checkBinBounds
void checkBinBounds() const
Definition: RooDataHist.cxx:759
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:134
RooAbsLValue.h
RooDataHist::_idxMult
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:183
total
static unsigned int total
Definition: TGWin32ProxyDefs.h:40
RooDataHist::_arrSize
Int_t _arrSize
Definition: RooDataHist.h:182
RooDataHist::_realVars
RooArgSet _realVars
Definition: RooDataHist.h:191
RooTrace.h
hi
float type_of_call hi(const int &, const int &)
RooDataHist::binVolume
Double_t binVolume() const
Definition: RooDataHist.h:111
RooAbsData::Expected
@ Expected
Definition: RooAbsData.h:96
RooDataHist::interpolateDim
Double_t interpolateDim(RooRealVar &dim, const RooAbsBinning *binning, Double_t xval, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries)
Perform boundary safe 'intOrder'-th interpolation of weights in dimension 'dim' at current value 'xva...
Definition: RooDataHist.cxx:1221
RooFit::DataHandling
@ DataHandling
Definition: RooGlobalFunc.h:69
RooAbsData::_vars
RooArgSet _vars
Definition: RooAbsData.h:280
ROOT::Math::fabs
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Definition: UnaryOperators.h:131
RooDataHist::calcTreeIndex
Int_t calcTreeIndex() const
Calculate the index for the weights array corresponding to to the bin enclosing the current coordinat...
Definition: RooDataHist.cxx:980
RooAbsCategoryLValue::numBins
virtual Int_t numBins(const char *rangeName) const
Return the number of fit bins ( = number of types )
Definition: RooAbsCategoryLValue.cxx:203
RooDataHist
Definition: RooDataHist.h:39
RooPrintable::kName
@ kName
Definition: RooPrintable.h:33
RooCategory::setLabel
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Definition: RooCategory.cxx:185
TArrayD::GetArray
const Double_t * GetArray() const
Definition: TArrayD.h:49
RooFormulaVar
Definition: RooFormulaVar.h:30
RooDataHist::dump2
void dump2()
Debug stuff, should go...
Definition: RooDataHist.cxx:997
RooAbsRealLValue::numBins
virtual Int_t numBins(const char *rangeName=0) const
Definition: RooAbsRealLValue.h:54
TH1::GetBinContent
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4906
TBuffer.h
TAxis::GetXmin
Double_t GetXmin() const
Definition: TAxis.h:133
RooDataHist::_lvvars
std::vector< RooAbsLValue * > _lvvars
Cache manager for arrays of partial bin volumes.
Definition: RooDataHist.h:203
TRACE_DESTROY
#define TRACE_DESTROY
Definition: RooTrace.h:24
TH1::GetYaxis
TAxis * GetYaxis()
Definition: TH1.h:318
xmin
float xmin
Definition: THbookFile.cxx:95
h
#define h(i)
Definition: RSha256.hxx:124
RooDataHist::_adjustBinning
void _adjustBinning(RooRealVar &theirVar, const TAxis &axis, RooRealVar *ourVar, Int_t *offset)
Cache for sum of entries ;.
Definition: RooDataHist.cxx:573
RooDataHist::get_wgt
Double_t get_wgt(const Int_t &idx) const
Definition: RooDataHist.h:170
RooDataHist::initialize
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...
Definition: RooDataHist.cxx:667
RooMath::interpolate
static Double_t interpolate(Double_t yArr[], Int_t nOrder, Double_t x)
Definition: RooMath.cxx:605
RooAbsData::plotOn
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
Definition: RooAbsData.cxx:547
RooBinning::binLow
virtual Double_t binLow(Int_t bin) const
Return the lower bound of the requested bin.
Definition: RooBinning.cxx:304
RooDataHist::sumEntries
virtual Double_t sumEntries() const
Return effective number of entries in dataset, i.e., sum all weights.
Definition: RooDataHist.cxx:1703
RooDataHist::_pbinv
std::vector< Double_t > * _pbinv
Definition: RooDataHist.h:201
RooDataHist::printMultiline
virtual void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print the details on the dataset contents.
Definition: RooDataHist.cxx:1976
TBuffer::WriteClassBuffer
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooDataHist::_errHi
Double_t * _errHi
Definition: RooDataHist.h:187
RooDataHist.h
RooAbsData::get
virtual const RooArgSet * get() const
Definition: RooAbsData.h:89
gDebug
R__EXTERN Int_t gDebug
Definition: RtypesCore.h:119
RooAbsCollection::selectCommon
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
Definition: RooAbsCollection.cxx:700
RooLinkedList
Definition: RooLinkedList.h:35
RooPlot.h
RooAbsCollection::createIterator
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
Definition: RooAbsCollection.h:118
TMath::Power
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:735
RooAbsBinning
Definition: RooAbsBinning.h:26
RooUniformBinning
Definition: RooUniformBinning.h:23
RooAbsDataStore::setExternalWeightArray
virtual void setExternalWeightArray(const Double_t *, const Double_t *, const Double_t *, const Double_t *)
Definition: RooAbsDataStore.h:82
RooDataHist::_errLo
Double_t * _errLo
Definition: RooDataHist.h:186
RooPlot
Definition: RooPlot.h:44
RooDataHist::RooDataHist
RooDataHist()
Default constructor.
Definition: RooDataHist.cxx:66
TRACE_CREATE
#define TRACE_CREATE
Definition: RooTrace.h:23
RooAbsCollection::size
Storage_t::size_type size() const
Definition: RooAbsCollection.h:154
RooAbsCategory::lookupType
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.
Definition: RooAbsCategory.cxx:307
RooAbsData::numEntries
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Definition: RooAbsData.cxx:307
RooDataHist::adjustBinning
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 ...
Definition: RooDataHist.cxx:639
RooCategory.h
y
Double_t y[n]
Definition: legend1.C:17
RooPrintable::kValue
@ kValue
Definition: RooPrintable.h:33
sqrt
double sqrt(double)
RooDataHist::cacheValidEntries
void cacheValidEntries()
Cache the datahist entries with bin centers that are inside/outside the current observable definitio.
Definition: RooDataHist.cxx:1920
RooDataHist::printValue
virtual void printValue(std::ostream &os) const
Print value of the dataset, i.e. the sum of weights contained in the dataset.
Definition: RooDataHist.cxx:1888
RooAbsArg::attachDataSet
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
Definition: RooAbsArg.cxx:1469
RooRealVar.h
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
RooDataHist::SetName
void SetName(const char *name)
Change the name of the RooDataHist.
Definition: RooDataHist.cxx:1866
RooDirItem::appendToDir
void appendToDir(TObject *obj, Bool_t forceMemoryResident=kFALSE)
Append object to directory.
Definition: RooDirItem.cxx:55
TBuffer::ReadVersion
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
RooDataHist::RooDataHistSliceIter
friend class RooDataHistSliceIter
Definition: RooDataHist.h:146
RooDataHist::_binv
Double_t * _binv
Definition: RooDataHist.h:189
RooTreeDataStore
Definition: RooTreeDataStore.h:31
RooAbsData::Poisson
@ Poisson
Definition: RooAbsData.h:96
TIterator::Next
virtual TObject * Next()=0
RooAbsData::PlotOpt::bins
RooAbsBinning * bins
Definition: RooAbsData.h:147
unsigned int
ymin
float ymin
Definition: THbookFile.cxx:95
RooHelpers::tokenise
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:74
RooAbsLValue::setBin
virtual void setBin(Int_t ibin, const char *rangeName=0)=0
RooRealVar::getBinning
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
Definition: RooRealVar.cxx:277
RooDataHist::_curSumW2
Double_t _curSumW2
Definition: RooDataHist.h:197
TIterator::Reset
virtual void Reset()=0
RooAbsData::None
@ None
Definition: RooAbsData.h:96
RooDataHist::_curVolume
Double_t _curVolume
Definition: RooDataHist.h:198
RooAbsRealLValue::getBin
virtual Int_t getBin(const char *rangeName=0) const
Definition: RooAbsRealLValue.h:53
RooDataHist::calculatePartialBinVolume
void calculatePartialBinVolume(const RooArgSet &dimSet) const
Fill the transient cache with partial bin volumes with up-to-date values for the partial volume speci...
Definition: RooDataHist.cxx:1643
TBuffer::IsReading
Bool_t IsReading() const
Definition: TBuffer.h:86
RooDataHist::sliceIterator
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.
Definition: RooDataHist.cxx:1848
RooDataHist::sum
Double_t sum(Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) const
Return the sum of the weights of all hist bins.
Definition: RooDataHist.cxx:1430
RooAbsDataStore::checkInit
virtual void checkInit() const
Definition: RooAbsDataStore.h:112
RooDataHist::isNonPoissonWeighted
virtual Bool_t isNonPoissonWeighted() const
Returns true if datasets contains entries with a non-integer weight.
Definition: RooDataHist.cxx:1962
RooPrintable::kExtras
@ kExtras
Definition: RooPrintable.h:33
Double_t
double Double_t
Definition: RtypesCore.h:59
RooAbsRealLValue::setBinFast
virtual void setBinFast(Int_t ibin, const RooAbsBinning &binning)
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
Definition: RooAbsRealLValue.cxx:481
RooDataHist::SetNameTitle
void SetNameTitle(const char *name, const char *title)
Change the title of this RooDataHist.
Definition: RooDataHist.cxx:1877
TList::Remove
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:821
RooCategory
Definition: RooCategory.h:27
RooDataHist::numEntries
virtual Int_t numEntries() const
Return the number of bins.
Definition: RooDataHist.cxx:1694
RooRealVar::setBinning
void setBinning(const RooAbsBinning &binning, const char *name=0)
Add given binning under name 'name' with this variable.
Definition: RooRealVar.cxx:374
RooAbsData::weightSquared
virtual Double_t weightSquared() const =0
RooAbsBinning::clone
virtual RooAbsBinning * clone(const char *name=0) const =0
RooVectorDataStore
Definition: RooVectorDataStore.h:35
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TObject
Definition: TObject.h:37
RooDataHist::reset
virtual void reset()
Reset all bin weights to zero.
Definition: RooDataHist.cxx:1767
RooDataHist::printArgs
virtual void printArgs(std::ostream &os) const
Print argument of dataset, i.e. the observable names.
Definition: RooDataHist.cxx:1899
TH1
Definition: TH1.h:57
RooDataHist::_lvbins
std::vector< const RooAbsBinning * > _lvbins
List of observables casted as RooAbsLValue.
Definition: RooDataHist.h:204
name
char name[80]
Definition: TGX11.cxx:110
RooDataHist::_curWgtErrLo
Double_t _curWgtErrLo
Definition: RooDataHist.h:195
RooBinning::binHigh
virtual Double_t binHigh(Int_t bin) const
Return the upper bound of the requested bin.
Definition: RooBinning.cxx:314
RooPrintable::kTitle
@ kTitle
Definition: RooPrintable.h:33
RooPrintable::printStream
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,...
Definition: RooPrintable.cxx:75
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RooDataHist::_wgt
Double_t * _wgt
Definition: RooDataHist.h:185
RooBinning::addUniform
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
RooBinning.h
RooAbsArg
Definition: RooAbsArg.h:73
RooAbsRealLValue::getBins
virtual Int_t getBins(const char *name=0) const
Get number of bins of currently defined range.
Definition: RooAbsRealLValue.h:83
RooBinning::rawBinNumber
virtual Int_t rawBinNumber(Double_t x) const
Return sequential bin number that contains value x where bin zero is the first bin that is defined,...
Definition: RooBinning.cxx:196
RooArgSet::addClone
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
RooAbsLValue
Definition: RooAbsLValue.h:26
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
RooVectorDataStore.h
TAxis::GetXmax
Double_t GetXmax() const
Definition: TAxis.h:134
RooAbsDataStore
Definition: RooAbsDataStore.h:31
RooAbsData::attachCache
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:347
RooAbsCollection::allInRange
Bool_t allInRange(const char *rangeSpec) const
Return true if all contained object report to have their value inside the specified range.
Definition: RooAbsCollection.cxx:1197
RooBinning::binNumber
virtual Int_t binNumber(Double_t x) const
Return sequential bin number that contains value x where bin zero is the first bin with an upper boun...
Definition: RooBinning.cxx:186
Class
void Class()
Definition: Class.C:29
RooRealVar
Definition: RooRealVar.h:36
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:317
RooDataHist::plotOn
virtual RooPlot * plotOn(RooPlot *frame, PlotOpt o) const
Back end function to plotting functionality.
Definition: RooDataHist.cxx:1013
TAxis::GetXbins
const TArrayD * GetXbins() const
Definition: TAxis.h:130
Riostream.h
pow
double pow(double, double)
RooFormula::eval
Double_t eval(const RooArgSet *nset=0) const
Evalute all parameters/observables, and then evaluate formula.
Definition: RooFormula.cxx:340
RooHistError.h
RooAbsRealLValue
Definition: RooAbsRealLValue.h:31
RooArgList.h
TH1.h
TObject::ClassName
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
RooDataHist::_cache_sum_valid
Int_t _cache_sum_valid
list of bin bounds per dimension
Definition: RooDataHist.h:207
RooMath.h
RooDataHist::reduceEng
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.
Definition: RooDataHist.cxx:879
RooDataHist::_sumw2
Double_t * _sumw2
Definition: RooDataHist.h:188
RooPlot::getPlotVar
RooAbsRealLValue * getPlotVar() const
Definition: RooPlot.h:139
RooDataHist::valid
virtual Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
Definition: RooDataHist.cxx:1947
RooAbsArg::inRange
virtual Bool_t inRange(const char *) const
Definition: RooAbsArg.h:382
TAxis::GetNbins
Int_t GetNbins() const
Definition: TAxis.h:121
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
RooAbsData::_cachedVars
RooArgSet _cachedVars
Definition: RooAbsData.h:281
TMath.h
RooArgSet
Definition: RooArgSet.h:28
RooAbsCollection::assignFast
void assignFast(const RooAbsCollection &other, Bool_t setValDirty=kTRUE)
Functional equivalent of operator=() but assumes this and other collection have same layout.
Definition: RooAbsCollection.cxx:356
int
RooAbsRealLValue::setBin
virtual void setBin(Int_t ibin, const char *rangeName=0)
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
Definition: RooAbsRealLValue.cxx:433