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