Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "RooDataHist.h"
28
29#include "RooFit.h"
30#include "Riostream.h"
31#include "RooMsgService.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 "RooHelpers.h"
47#include "RooFormulaVar.h"
48#include "RooFormula.h"
49#include "RooUniformBinning.h"
50#include "RooSpan.h"
51
52#include "TAxis.h"
53#include "TH1.h"
54#include "TTree.h"
55#include "TBuffer.h"
56#include "TMath.h"
57#include "Math/Util.h"
58
59using namespace std;
60
62
63
64////////////////////////////////////////////////////////////////////////////////
65/// Default constructor
66
68{
70}
71
72
73
74////////////////////////////////////////////////////////////////////////////////
75/// Constructor of an empty data hist from a RooArgSet defining the dimensions
76/// of the data space. The range and number of bins in each dimensions are taken
77/// from getMin()getMax(),getBins() of each RooAbsArg representing that
78/// dimension.
79///
80/// For real dimensions, the fit range and number of bins can be set independently
81/// of the plot range and number of bins, but it is advisable to keep the
82/// ratio of the plot bin width and the fit bin width an integer value.
83/// For category dimensions, the fit ranges always comprises all defined states
84/// and each state is always has its individual bin
85///
86/// To effectively bin real dimensions with variable bin sizes,
87/// construct a RooThresholdCategory of the real dimension to be binned variably.
88/// Set the thresholds at the desired bin boundaries, and construct the
89/// data hist as a function of the threshold category instead of the real variable.
90RooDataHist::RooDataHist(const char *name, const char *title, const RooArgSet& vars, const char* binningName) :
91 RooAbsData(name,title,vars)
92{
93 // Initialize datastore
96
97 initialize(binningName) ;
98
100
101 appendToDir(this,kTRUE) ;
103}
104
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// Constructor of a data hist from an existing data collection (binned or unbinned)
109/// The RooArgSet 'vars' defines the dimensions of the histogram.
110/// The range and number of bins in each dimensions are taken
111/// from getMin(), getMax(), getBins() of each argument passed.
112///
113/// For real dimensions, the fit range and number of bins can be set independently
114/// of the plot range and number of bins, but it is advisable to keep the
115/// ratio of the plot bin width and the fit bin width an integer value.
116/// For category dimensions, the fit ranges always comprises all defined states
117/// and each state is always has its individual bin
118///
119/// To effectively bin real dimensions with variable bin sizes,
120/// construct a RooThresholdCategory of the real dimension to be binned variably.
121/// Set the thresholds at the desired bin boundaries, and construct the
122/// data hist as a function of the threshold category instead of the real variable.
123///
124/// If the constructed data hist has less dimensions that in source data collection,
125/// all missing dimensions will be projected.
126
127RooDataHist::RooDataHist(const char *name, const char *title, const RooArgSet& vars, const RooAbsData& data, Double_t wgt) :
128 RooAbsData(name,title,vars)
129{
130 // Initialize datastore
133
134 initialize() ;
136
137 add(data,(const RooFormulaVar*)0,wgt) ;
138 appendToDir(this,kTRUE) ;
140}
141
142
143
144////////////////////////////////////////////////////////////////////////////////
145/// Constructor of a data hist from a map of TH1,TH2 or TH3 that are collated into a x+1 dimensional
146/// RooDataHist where the added dimension is a category that labels the input source as defined
147/// in the histMap argument. The state names used in histMap must correspond to predefined states
148/// 'indexCat'
149///
150/// The RooArgList 'vars' defines the dimensions of the histogram.
151/// The ranges and number of bins are taken from the input histogram and must be the same in all histograms
152
153RooDataHist::RooDataHist(const char *name, const char *title, const RooArgList& vars, RooCategory& indexCat,
154 map<string,TH1*> histMap, Double_t wgt) :
155 RooAbsData(name,title,RooArgSet(vars,&indexCat))
156{
157 // Initialize datastore
160
161 importTH1Set(vars, indexCat, histMap, wgt, kFALSE) ;
162
165}
166
167
168
169////////////////////////////////////////////////////////////////////////////////
170/// Constructor of a data hist from a map of RooDataHists that are collated into a x+1 dimensional
171/// RooDataHist where the added dimension is a category that labels the input source as defined
172/// in the histMap argument. The state names used in histMap must correspond to predefined states
173/// 'indexCat'
174///
175/// The RooArgList 'vars' defines the dimensions of the histogram.
176/// The ranges and number of bins are taken from the input histogram and must be the same in all histograms
177
178RooDataHist::RooDataHist(const char *name, const char *title, const RooArgList& vars, RooCategory& indexCat,
179 map<string,RooDataHist*> dhistMap, Double_t wgt) :
180 RooAbsData(name,title,RooArgSet(vars,&indexCat))
181{
182 // Initialize datastore
185
186 importDHistSet(vars, indexCat, dhistMap, wgt) ;
187
190}
191
192
193
194////////////////////////////////////////////////////////////////////////////////
195/// Constructor of a data hist from an TH1,TH2 or TH3
196/// The RooArgSet 'vars' defines the dimensions of the histogram. The ranges
197/// and number of bins are taken from the input histogram, and the corresponding
198/// values are set accordingly on the arguments in 'vars'
199
200RooDataHist::RooDataHist(const char *name, const char *title, const RooArgList& vars, const TH1* hist, Double_t wgt) :
201 RooAbsData(name,title,vars)
202{
203 // Initialize datastore
206
207 // Check consistency in number of dimensions
208 if (vars.getSize() != hist->GetDimension()) {
209 coutE(InputArguments) << "RooDataHist::ctor(" << GetName() << ") ERROR: dimension of input histogram must match "
210 << "number of dimension variables" << endl ;
211 assert(0) ;
212 }
213
214 importTH1(vars,*hist,wgt, kFALSE) ;
215
218}
219
220
221
222////////////////////////////////////////////////////////////////////////////////
223/// Constructor of a binned dataset from a RooArgSet defining the dimensions
224/// of the data space. The range and number of bins in each dimensions are taken
225/// from getMin() getMax(),getBins() of each RooAbsArg representing that
226/// dimension.
227///
228/// <table>
229/// <tr><th> Optional Argument <th> Effect
230/// <tr><td> Import(TH1&, Bool_t impDens) <td> Import contents of the given TH1/2/3 into this binned dataset. The
231/// ranges and binning of the binned dataset are automatically adjusted to
232/// match those of the imported histogram.
233///
234/// Please note: for TH1& with unequal binning _only_,
235/// you should decide if you want to import the absolute bin content,
236/// or the bin content expressed as density. The latter is default and will
237/// result in the same histogram as the original TH1. For certain types of
238/// bin contents (containing efficiencies, asymmetries, or ratio is general)
239/// you should import the absolute value and set impDens to kFALSE
240///
241///
242/// <tr><td> Weight(Double_t) <td> Apply given weight factor when importing histograms
243///
244/// <tr><td> Index(RooCategory&) <td> Prepare import of multiple TH1/1/2/3 into a N+1 dimensional RooDataHist
245/// where the extra discrete dimension labels the source of the imported histogram
246/// If the index category defines states for which no histogram is be imported
247/// the corresponding bins will be left empty.
248///
249/// <tr><td> Import(const char*, TH1&) <td> Import a THx to be associated with the given state name of the index category
250/// specified in Index(). If the given state name is not yet defined in the index
251/// category it will be added on the fly. The import command can be specified
252/// multiple times.
253/// <tr><td> Import(map<string,TH1*>&) <td> As above, but allows specification of many imports in a single operation
254///
255
256RooDataHist::RooDataHist(const char *name, const char *title, const RooArgList& vars, const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3,
257 const RooCmdArg& arg4,const RooCmdArg& arg5,const RooCmdArg& arg6,const RooCmdArg& arg7,const RooCmdArg& arg8) :
258 RooAbsData(name,title,RooArgSet(vars,(RooAbsArg*)RooCmdConfig::decodeObjOnTheFly("RooDataHist::RooDataHist", "IndexCat",0,0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)))
259{
260 // Initialize datastore
263
264 // Define configuration for this method
265 RooCmdConfig pc(Form("RooDataHist::ctor(%s)",GetName())) ;
266 pc.defineObject("impHist","ImportHisto",0) ;
267 pc.defineInt("impDens","ImportHisto",0) ;
268 pc.defineObject("indexCat","IndexCat",0) ;
269 pc.defineObject("impSliceHist","ImportHistoSlice",0,0,kTRUE) ; // array
270 pc.defineString("impSliceState","ImportHistoSlice",0,"",kTRUE) ; // array
271 pc.defineObject("impSliceDHist","ImportDataHistSlice",0,0,kTRUE) ; // array
272 pc.defineString("impSliceDState","ImportDataHistSlice",0,"",kTRUE) ; // array
273 pc.defineDouble("weight","Weight",0,1) ;
274 pc.defineObject("dummy1","ImportDataHistSliceMany",0) ;
275 pc.defineObject("dummy2","ImportHistoSliceMany",0) ;
276 pc.defineMutex("ImportHisto","ImportHistoSlice","ImportDataHistSlice") ;
277 pc.defineDependency("ImportHistoSlice","IndexCat") ;
278 pc.defineDependency("ImportDataHistSlice","IndexCat") ;
279
281 l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
282 l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
283 l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
284 l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
285
286 // Process & check varargs
287 pc.process(l) ;
288 if (!pc.ok(kTRUE)) {
289 assert(0) ;
290 return ;
291 }
292
293 TH1* impHist = static_cast<TH1*>(pc.getObject("impHist")) ;
294 Bool_t impDens = pc.getInt("impDens") ;
295 Double_t initWgt = pc.getDouble("weight") ;
296 const char* impSliceNames = pc.getString("impSliceState","",kTRUE) ;
297 const RooLinkedList& impSliceHistos = pc.getObjectList("impSliceHist") ;
298 RooCategory* indexCat = static_cast<RooCategory*>(pc.getObject("indexCat")) ;
299 const char* impSliceDNames = pc.getString("impSliceDState","",kTRUE) ;
300 const RooLinkedList& impSliceDHistos = pc.getObjectList("impSliceDHist") ;
301
302
303 if (impHist) {
304
305 // Initialize importing contents from TH1
306 importTH1(vars,*impHist,initWgt, impDens) ;
307
308 } else if (indexCat) {
309
310
311 if (impSliceHistos.GetSize()>0) {
312
313 // Initialize importing mapped set of TH1s
314 map<string,TH1*> hmap ;
315 TIterator* hiter = impSliceHistos.MakeIterator() ;
316 for (const auto& token : RooHelpers::tokenise(impSliceNames, ",")) {
317 auto histo = static_cast<TH1*>(hiter->Next());
318 assert(histo);
319 hmap[token] = histo;
320 }
321 importTH1Set(vars,*indexCat,hmap,initWgt,kFALSE) ;
322 } else {
323
324 // Initialize importing mapped set of RooDataHists
325 map<string,RooDataHist*> dmap ;
326 TIterator* hiter = impSliceDHistos.MakeIterator() ;
327 for (const auto& token : RooHelpers::tokenise(impSliceDNames, ",")) {
328 dmap[token] = (RooDataHist*) hiter->Next() ;
329 }
330 importDHistSet(vars,*indexCat,dmap,initWgt) ;
331 }
332
333
334 } else {
335
336 // Initialize empty
337 initialize() ;
338 appendToDir(this,kTRUE) ;
339
340 }
341
344
345}
346
347
348
349
350////////////////////////////////////////////////////////////////////////////////
351/// Import data from given TH1/2/3 into this RooDataHist
352
353void RooDataHist::importTH1(const RooArgList& vars, const TH1& histo, Double_t wgt, Bool_t doDensityCorrection)
354{
355 // Adjust binning of internal observables to match that of input THx
356 Int_t offset[3]{0, 0, 0};
357 adjustBinning(vars, histo, offset) ;
358
359 // Initialize internal data structure
360 initialize() ;
361 appendToDir(this,kTRUE) ;
362
363 // Define x,y,z as 1st, 2nd and 3rd observable
364 RooRealVar* xvar = (RooRealVar*) _vars.find(vars.at(0)->GetName()) ;
365 RooRealVar* yvar = (RooRealVar*) (vars.at(1) ? _vars.find(vars.at(1)->GetName()) : 0 ) ;
366 RooRealVar* zvar = (RooRealVar*) (vars.at(2) ? _vars.find(vars.at(2)->GetName()) : 0 ) ;
367
368 // Transfer contents
369 Int_t xmin(0),ymin(0),zmin(0) ;
370 RooArgSet vset(*xvar) ;
371 Double_t volume = xvar->getMax()-xvar->getMin() ;
372 xmin = offset[0] ;
373 if (yvar) {
374 vset.add(*yvar) ;
375 ymin = offset[1] ;
376 volume *= (yvar->getMax()-yvar->getMin()) ;
377 }
378 if (zvar) {
379 vset.add(*zvar) ;
380 zmin = offset[2] ;
381 volume *= (zvar->getMax()-zvar->getMin()) ;
382 }
383 //Double_t avgBV = volume / numEntries() ;
384// cout << "average bin volume = " << avgBV << endl ;
385
386 Int_t ix(0),iy(0),iz(0) ;
387 for (ix=0 ; ix < xvar->getBins() ; ix++) {
388 xvar->setBin(ix) ;
389 if (yvar) {
390 for (iy=0 ; iy < yvar->getBins() ; iy++) {
391 yvar->setBin(iy) ;
392 if (zvar) {
393 for (iz=0 ; iz < zvar->getBins() ; iz++) {
394 zvar->setBin(iz) ;
395 Double_t bv = doDensityCorrection ? binVolume(vset) : 1;
396 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)) ;
397 }
398 } else {
399 Double_t bv = doDensityCorrection ? binVolume(vset) : 1;
400 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)) ;
401 }
402 }
403 } else {
404 Double_t bv = doDensityCorrection ? binVolume(vset) : 1 ;
405 add(vset,bv*histo.GetBinContent(ix+1+xmin)*wgt,bv*TMath::Power(histo.GetBinError(ix+1+xmin)*wgt,2)) ;
406 }
407 }
408
409}
410
411namespace {
412bool checkConsistentAxes(const TH1* first, const TH1* second) {
413 return first->GetDimension() == second->GetDimension()
414 && first->GetNbinsX() == second->GetNbinsX()
415 && first->GetNbinsY() == second->GetNbinsY()
416 && first->GetNbinsZ() == second->GetNbinsZ()
417 && first->GetXaxis()->GetXmin() == second->GetXaxis()->GetXmin()
418 && first->GetXaxis()->GetXmax() == second->GetXaxis()->GetXmax()
419 && (first->GetNbinsY() == 1 || (first->GetYaxis()->GetXmin() == second->GetYaxis()->GetXmin()
420 && first->GetYaxis()->GetXmax() == second->GetYaxis()->GetXmax() ) )
421 && (first->GetNbinsZ() == 1 || (first->GetZaxis()->GetXmin() == second->GetZaxis()->GetXmin()
422 && first->GetZaxis()->GetXmax() == second->GetZaxis()->GetXmax() ) );
423}
424}
425
426
427////////////////////////////////////////////////////////////////////////////////
428/// Import data from given set of TH1/2/3 into this RooDataHist. The category indexCat labels the sources
429/// in the constructed RooDataHist. The stl map provides the mapping between the indexCat state labels
430/// and the import source
431
432void RooDataHist::importTH1Set(const RooArgList& vars, RooCategory& indexCat, map<string,TH1*> hmap, Double_t wgt, Bool_t doDensityCorrection)
433{
434 RooCategory* icat = (RooCategory*) _vars.find(indexCat.GetName()) ;
435
436 TH1* histo(0) ;
437 Bool_t init(kFALSE) ;
438 for (const auto& hiter : hmap) {
439 // Store pointer to first histogram from which binning specification will be taken
440 if (!histo) {
441 histo = hiter.second;
442 } else {
443 if (!checkConsistentAxes(histo, hiter.second)) {
444 coutE(InputArguments) << "Axes of histogram " << hiter.second->GetName() << " are not consistent with first processed "
445 << "histogram " << histo->GetName() << std::endl;
446 throw std::invalid_argument("Axes of inputs for RooDataHist are inconsistent");
447 }
448 }
449 // Define state labels in index category (both in provided indexCat and in internal copy in dataset)
450 if (!indexCat.hasLabel(hiter.first)) {
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->hasLabel(hiter.first)) {
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::importTH1Set(" << GetName() << "): dimension of input histogram must match "
462 << "number of continuous variables" << endl ;
463 throw std::invalid_argument("Inputs histograms for RooDataHist are not compatible with dimensions of variables.");
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
535void 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 (const auto& diter : dmap) {
540
541 // Define state labels in index category (both in provided indexCat and in internal copy in dataset)
542 if (!indexCat.hasLabel(diter.first)) {
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->hasLabel(diter.first)) {
547 icat->defineType(diter.first) ;
548 }
549 }
550
551 initialize() ;
552 appendToDir(this,kTRUE) ;
553
554
555 for (const auto& diter : dmap) {
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
573void 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
639void 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
659namespace {
660/// Clone external weight arrays, unless the external array is nullptr.
661void cloneArray(double*& ours, const double* theirs, std::size_t n) {
662 if (ours) delete[] ours;
663 ours = nullptr;
664 if (!theirs) return;
665 ours = new double[n];
666 std::copy(theirs, theirs+n, ours);
667}
668
669/// Allocate and initialise an array with desired size and values.
670void initArray(double*& arr, std::size_t n, double val) {
671 if (arr) delete[] arr;
672 arr = nullptr;
673 if (n == 0) return;
674 arr = new double[n];
675 std::fill(arr, arr+n, val);
676}
677}
678
679
680////////////////////////////////////////////////////////////////////////////////
681/// Initialization procedure: allocate weights array, calculate
682/// multipliers needed for N-space to 1-dim array jump table,
683/// and fill the internal tree with all bin center coordinates
684
685void RooDataHist::initialize(const char* binningName, Bool_t fillTree)
686{
687
688 // Save real dimensions of dataset separately
689 for (const auto real : _vars) {
690 if (dynamic_cast<RooAbsReal*>(real)) _realVars.add(*real);
691 }
692
693 _lvvars.clear();
694 _lvbins.clear();
695
696 // Fill array of LValue pointers to variables
697 for (unsigned int i = 0; i < _vars.size(); ++i) {
698 if (binningName) {
699 RooRealVar* rrv = dynamic_cast<RooRealVar*>(_vars[i]);
700 if (rrv) {
701 rrv->setBinning(rrv->getBinning(binningName));
702 }
703 }
704
705 auto lvarg = dynamic_cast<RooAbsLValue*>(_vars[i]);
706 assert(lvarg);
707 _lvvars.push_back(lvarg);
708
709 const RooAbsBinning* binning = lvarg->getBinningPtr(0);
710 _lvbins.emplace_back(binning ? binning->clone() : nullptr);
711 }
712
713
714 // Allocate coefficients array
715 _idxMult.resize(_vars.getSize()) ;
716
717 _arrSize = 1 ;
718 unsigned int n = 0u;
719 for (const auto var : _vars) {
720 auto arg = dynamic_cast<const RooAbsLValue*>(var);
721 assert(arg);
722
723 // Calculate sub-index multipliers for master index
724 for (unsigned int i = 0u; i<n; i++) {
725 _idxMult[i] *= arg->numBins() ;
726 }
727 _idxMult[n++] = 1 ;
728
729 // Calculate dimension of weight array
730 _arrSize *= arg->numBins() ;
731 }
732
733 // Allocate and initialize weight array if necessary
734 if (!_wgt) {
735 initArray(_wgt, _arrSize, 0.);
736 delete[] _errLo; _errLo = nullptr;
737 delete[] _errHi; _errHi = nullptr;
738 delete[] _sumw2; _sumw2 = nullptr;
739 initArray(_binv, _arrSize, 0.);
740
741 // Refill array pointers in data store when reading
742 // from Streamer
743 if (!fillTree) {
745 }
746 }
747
748 if (!fillTree) return ;
749
750 // Fill TTree with bin center coordinates
751 // Calculate plot bins of components from master index
752
753 for (Int_t ibin=0 ; ibin < _arrSize ; ibin++) {
754 Int_t j(0), idx(0), tmp(ibin) ;
755 Double_t theBinVolume(1) ;
756 for (auto arg2 : _lvvars) {
757 idx = tmp / _idxMult[j] ;
758 tmp -= idx*_idxMult[j++] ;
759 arg2->setBin(idx) ;
760 theBinVolume *= arg2->getBinWidth(idx) ;
761 }
762 _binv[ibin] = theBinVolume ;
763
764 fill() ;
765 }
766
767
768}
769
770
771////////////////////////////////////////////////////////////////////////////////
772
774{
775 if (!_binbounds.empty()) return;
776 for (auto& it : _lvbins) {
777 _binbounds.push_back(std::vector<Double_t>());
778 if (it) {
779 std::vector<Double_t>& bounds = _binbounds.back();
780 bounds.reserve(2 * it->numBins());
781 for (Int_t i = 0; i < it->numBins(); ++i) {
782 bounds.push_back(it->binLow(i));
783 bounds.push_back(it->binHigh(i));
784 }
785 }
786 }
787}
788
789
790////////////////////////////////////////////////////////////////////////////////
791/// Copy constructor
792
793RooDataHist::RooDataHist(const RooDataHist& other, const char* newname) :
794 RooAbsData(other,newname), RooDirItem(), _arrSize(other._arrSize), _idxMult(other._idxMult), _pbinvCache(other._pbinvCache)
795{
796 // Allocate and initialize weight array
797 assert(_arrSize == other._arrSize);
798 cloneArray(_wgt, other._wgt, other._arrSize);
799 cloneArray(_errLo, other._errLo, other._arrSize);
800 cloneArray(_errHi, other._errHi, other._arrSize);
801 cloneArray(_binv, other._binv, other._arrSize);
802 cloneArray(_sumw2, other._sumw2, other._arrSize);
803
804 // Save real dimensions of dataset separately
805 for (const auto arg : _vars) {
806 if (dynamic_cast<RooAbsReal*>(arg) != nullptr) _realVars.add(*arg) ;
807 }
808
809 // Fill array of LValue pointers to variables
810 for (const auto rvarg : _vars) {
811 auto lvarg = dynamic_cast<RooAbsLValue*>(rvarg);
812 assert(lvarg);
813 _lvvars.push_back(lvarg);
814 const RooAbsBinning* binning = lvarg->getBinningPtr(0);
815 _lvbins.emplace_back(binning ? binning->clone() : 0) ;
816 }
817
819
820 appendToDir(this,kTRUE) ;
821}
822
823
824
825////////////////////////////////////////////////////////////////////////////////
826/// Constructor of a data hist from (part of) an existing data hist. The dimensions
827/// of the data set are defined by the 'vars' RooArgSet, which can be identical
828/// to 'dset' dimensions, or a subset thereof. Reduced dimensions will be projected
829/// in the output data hist. The optional 'cutVar' formula variable can used to
830/// select the subset of bins to be copied.
831///
832/// For most uses the RooAbsData::reduce() wrapper function, which uses this constructor,
833/// is the most convenient way to create a subset of an existing data
834
835RooDataHist::RooDataHist(const char* name, const char* title, RooDataHist* h, const RooArgSet& varSubset,
836 const RooFormulaVar* cutVar, const char* cutRange, Int_t nStart, Int_t nStop, Bool_t copyCache) :
837 RooAbsData(name,title,varSubset)
838{
839 // Initialize datastore
840 _dstore = new RooTreeDataStore(name,title,*h->_dstore,_vars,cutVar,cutRange,nStart,nStop,copyCache) ;
841
842 initialize(0,kFALSE) ;
843
844 // Copy weight array etc
845 assert(_arrSize == h->_arrSize);
846 cloneArray(_wgt, h->_wgt, _arrSize);
847 cloneArray(_errLo, h->_errLo, _arrSize);
848 cloneArray(_errHi, h->_errHi, _arrSize);
849 cloneArray(_binv, h->_binv, _arrSize);
850 cloneArray(_sumw2, h->_sumw2, _arrSize);
851
853
854 appendToDir(this,kTRUE) ;
856}
857
858
859////////////////////////////////////////////////////////////////////////////////
860/// Construct a clone of this dataset that contains only the cached variables
861
862RooAbsData* RooDataHist::cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName)
863{
864 checkInit() ;
865
866 RooDataHist* dhist = new RooDataHist(newName?newName:GetName(),GetTitle(),this,*get(),0,0,0,2000000000,kTRUE) ;
867
868 RooArgSet* selCacheVars = (RooArgSet*) newCacheVars->selectCommon(dhist->_cachedVars) ;
869 dhist->attachCache(newCacheOwner, *selCacheVars) ;
870 delete selCacheVars ;
871
872 return dhist ;
873}
874
875
876
877////////////////////////////////////////////////////////////////////////////////
878/// Implementation of RooAbsData virtual method that drives the RooAbsData::reduce() methods
879
880RooAbsData* RooDataHist::reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange,
881 std::size_t nStart, std::size_t nStop, Bool_t /*copyCache*/)
882{
883 checkInit() ;
884 RooArgSet* myVarSubset = (RooArgSet*) _vars.selectCommon(varSubset) ;
885 RooDataHist *rdh = new RooDataHist(GetName(), GetTitle(), *myVarSubset) ;
886 delete myVarSubset ;
887
888 RooFormulaVar* cloneVar = 0;
889 RooArgSet* tmp(0) ;
890 if (cutVar) {
891 // Deep clone cutVar and attach clone to this dataset
892 tmp = (RooArgSet*) RooArgSet(*cutVar).snapshot() ;
893 if (!tmp) {
894 coutE(DataHandling) << "RooDataHist::reduceEng(" << GetName() << ") Couldn't deep-clone cut variable, abort," << endl ;
895 return 0 ;
896 }
897 cloneVar = (RooFormulaVar*) tmp->find(*cutVar) ;
898 cloneVar->attachDataSet(*this) ;
899 }
900
901 Double_t lo,hi ;
902 const std::size_t nevt = nStop < static_cast<std::size_t>(numEntries()) ? nStop : static_cast<std::size_t>(numEntries());
903 for (auto i=nStart; i<nevt ; i++) {
904 const RooArgSet* row = get(i) ;
905
906 Bool_t doSelect(kTRUE) ;
907 if (cutRange) {
908 for (const auto arg : *row) {
909 if (!arg->inRange(cutRange)) {
910 doSelect = kFALSE ;
911 break ;
912 }
913 }
914 }
915 if (!doSelect) continue ;
916
917 if (!cloneVar || cloneVar->getVal()) {
918 weightError(lo,hi,SumW2) ;
919 rdh->add(*row,weight(),lo*lo) ;
920 }
921 }
922
923 if (cloneVar) {
924 delete tmp ;
925 }
926
927 return rdh ;
928}
929
930
931
932////////////////////////////////////////////////////////////////////////////////
933/// Destructor
934
936{
937 delete[] _wgt;
938 delete[] _errLo;
939 delete[] _errHi;
940 delete[] _sumw2;
941 delete[] _binv;
942
943 removeFromDir(this) ;
945}
946
947
948
949
950////////////////////////////////////////////////////////////////////////////////
951/// Calculate bin number of the given coordinates. If only a subset of the internal
952/// coordinates are passed, the missing coordinates are taken at their current value.
953/// \param[in] coord Variables that are representing the coordinates.
954/// \param[in] fast If the variables in `coord` and the ones of the data hist have the
955/// same size and layout, `fast` can be set to skip checking that all variables are
956/// present in `coord`.
957Int_t RooDataHist::getIndex(const RooArgSet& coord, Bool_t fast) const {
958 checkInit() ;
959 return calcTreeIndex(coord, fast);
960}
961
962
963
964
965////////////////////////////////////////////////////////////////////////////////
966/// Calculate the bin index corresponding to the coordinates passed as argument.
967/// \param[in] coords Coordinates. Is `fast == false`, these can be partial.
968/// \param[in] fast Promise that the coordinates in `coords` have the same order
969/// as the internal coordinates. In this case, values are looked up only by index.
970std::size_t RooDataHist::calcTreeIndex(const RooArgSet& coords, bool fast) const
971{
972 // With fast, caller promises that layout of "coords" is identical to our internal "vars"
973 assert(!fast || _vars.size() == coords.size());
974
975 if (&_vars == &coords)
976 fast = true;
977
978 std::size_t masterIdx = 0;
979
980 for (unsigned int i=0; i < _vars.size(); ++i) {
981 const RooAbsArg* internalVar = _vars[i];
982 const RooAbsBinning* binning = _lvbins[i].get();
983
984 // Find the variable that we need values from.
985 // That's either the variable directly from the external coordinates
986 // or we find the external one that has the same name as "internalVar".
987 const RooAbsArg* theVar = fast ? coords[i] : coords.find(*internalVar);
988 if (!theVar) {
989 // Variable is not in external coordinates. Use current internal value.
990 theVar = internalVar;
991 }
992
993 if (binning) {
994 assert(dynamic_cast<const RooAbsReal*>(theVar));
995 const double val = static_cast<const RooAbsReal*>(theVar)->getVal();
996 masterIdx += _idxMult[i] * binning->binNumber(val);
997 } else {
998 // We are a category. No binning.
999 assert(dynamic_cast<const RooAbsCategoryLValue*>(theVar));
1000 auto cat = static_cast<const RooAbsCategoryLValue*>(theVar);
1001 masterIdx += _idxMult[i] * cat->getBin(static_cast<const char*>(nullptr));
1002 }
1003 }
1004
1005 return masterIdx ;
1006}
1007
1008
1009
1010////////////////////////////////////////////////////////////////////////////////
1011/// Debug stuff, should go...
1012
1014{
1015 cout << "_arrSize = " << _arrSize << endl ;
1016 for (Int_t i=0 ; i < _arrSize ; i++) {
1017 cout << "wgt[" << i << "] = " << _wgt[i]
1018 << "\tsumw2[" << i << "] = " << (_sumw2 ? _sumw2[i] : -1.)
1019 << "\tvol[" << i << "] = " << _binv[i] << endl ;
1020 }
1021}
1022
1023
1024
1025////////////////////////////////////////////////////////////////////////////////
1026/// Back end function to plotting functionality. Plot RooDataHist on given
1027/// frame in mode specified by plot options 'o'. The main purpose of
1028/// this function is to match the specified binning on 'o' to the
1029/// internal binning of the plot observable in this RooDataHist.
1030/// \see RooAbsData::plotOn() for plotting options.
1032{
1033 checkInit() ;
1034 if (o.bins) return RooAbsData::plotOn(frame,o) ;
1035
1036 if(0 == frame) {
1037 coutE(InputArguments) << ClassName() << "::" << GetName() << ":plotOn: frame is null" << endl;
1038 return 0;
1039 }
1041 if(0 == var) {
1042 coutE(InputArguments) << ClassName() << "::" << GetName()
1043 << ":plotOn: frame does not specify a plot variable" << endl;
1044 return 0;
1045 }
1046
1047 RooRealVar* dataVar = (RooRealVar*) _vars.find(*var) ;
1048 if (!dataVar) {
1049 coutE(InputArguments) << ClassName() << "::" << GetName()
1050 << ":plotOn: dataset doesn't contain plot frame variable" << endl;
1051 return 0;
1052 }
1053
1054 o.bins = &dataVar->getBinning() ;
1056 return RooAbsData::plotOn(frame,o) ;
1057}
1058
1059
1060////////////////////////////////////////////////////////////////////////////////
1061/// Return the weight at given coordinates with optional interpolation.
1062/// \param[in] bin Coordinates for which the weight should be calculated.
1063/// \param[in] intOrder If zero, the bare weight for the bin enclosing the coordinatesis returned.
1064/// For higher values, the result is interpolated in the real dimensions of the dataset.
1065/// \param[in] correctForBinSize
1066/// \param[in] cdfBoundaries
1067/// \param[in] oneSafe Ignored.
1068
1069Double_t RooDataHist::weight(const RooArgSet& bin, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries, Bool_t /*oneSafe*/)
1070{
1071 checkInit() ;
1072
1073 // Handle illegal intOrder values
1074 if (intOrder<0) {
1075 coutE(InputArguments) << "RooDataHist::weight(" << GetName() << ") ERROR: interpolation order must be positive" << endl ;
1076 return 0 ;
1077 }
1078
1079 // Handle no-interpolation case
1080 if (intOrder==0) {
1081 const auto idx = calcTreeIndex(bin, false);
1082 if (correctForBinSize) {
1083 return get_wgt(idx) / _binv[idx];
1084 } else {
1085 return get_wgt(idx);
1086 }
1087 }
1088
1089 // Handle all interpolation cases
1090 _vars.assignValueOnly(bin) ;
1091
1092 Double_t wInt(0) ;
1093 if (_realVars.getSize()==1) {
1094
1095 // 1-dimensional interpolation
1096 const auto real = static_cast<RooRealVar*>(_realVars[static_cast<std::size_t>(0)]);
1097 const RooAbsBinning* binning = real->getBinningPtr(0) ;
1098 wInt = interpolateDim(*real,binning,((RooAbsReal*)bin.find(*real))->getVal(), intOrder, correctForBinSize, cdfBoundaries) ;
1099
1100 } else if (_realVars.getSize()==2) {
1101
1102 // 2-dimensional interpolation
1103 const auto realX = static_cast<RooRealVar*>(_realVars[static_cast<std::size_t>(0)]);
1104 const auto realY = static_cast<RooRealVar*>(_realVars[static_cast<std::size_t>(1)]);
1105 Double_t xval = ((RooAbsReal*)bin.find(*realX))->getVal() ;
1106 Double_t yval = ((RooAbsReal*)bin.find(*realY))->getVal() ;
1107
1108 Int_t ybinC = realY->getBin() ;
1109 Int_t ybinLo = ybinC-intOrder/2 - ((yval<realY->getBinning().binCenter(ybinC))?1:0) ;
1110 Int_t ybinM = realY->numBins() ;
1111
1112 Int_t i ;
1113 Double_t yarr[10] ;
1114 Double_t xarr[10] ;
1115 const RooAbsBinning* binning = realX->getBinningPtr(0) ;
1116 for (i=ybinLo ; i<=intOrder+ybinLo ; i++) {
1117 Int_t ibin ;
1118 if (i>=0 && i<ybinM) {
1119 // In range
1120 ibin = i ;
1121 realY->setBin(ibin) ;
1122 xarr[i-ybinLo] = realY->getVal() ;
1123 } else if (i>=ybinM) {
1124 // Overflow: mirror
1125 ibin = 2*ybinM-i-1 ;
1126 realY->setBin(ibin) ;
1127 xarr[i-ybinLo] = 2*realY->getMax()-realY->getVal() ;
1128 } else {
1129 // Underflow: mirror
1130 ibin = -i -1;
1131 realY->setBin(ibin) ;
1132 xarr[i-ybinLo] = 2*realY->getMin()-realY->getVal() ;
1133 }
1134 yarr[i-ybinLo] = interpolateDim(*realX,binning,xval,intOrder,correctForBinSize,kFALSE) ;
1135 }
1136
1137 if (gDebug>7) {
1138 cout << "RooDataHist interpolating data is" << endl ;
1139 cout << "xarr = " ;
1140 for (int q=0; q<=intOrder ; q++) cout << xarr[q] << " " ;
1141 cout << " yarr = " ;
1142 for (int q=0; q<=intOrder ; q++) cout << yarr[q] << " " ;
1143 cout << endl ;
1144 }
1145 wInt = RooMath::interpolate(xarr,yarr,intOrder+1,yval) ;
1146
1147 } else {
1148
1149 // Higher dimensional scenarios not yet implemented
1150 coutE(InputArguments) << "RooDataHist::weight(" << GetName() << ") interpolation in "
1151 << _realVars.getSize() << " dimensions not yet implemented" << endl ;
1152 return weight(bin,0) ;
1153
1154 }
1155
1156 return wInt ;
1157}
1158
1159
1160
1161
1162////////////////////////////////////////////////////////////////////////////////
1163/// Return the error of current weight.
1164/// \param[out] lo Low error.
1165/// \param[out] hi High error.
1166/// \param[in] etype Type of error to compute. May throw if not supported.
1167/// Supported errors are
1168/// - `Poisson` Default. Asymmetric Poisson errors (68% CL).
1169/// - `SumW2` The square root of the sum of weights. (Symmetric).
1170/// - `None` Return zero.
1172{
1173 checkInit() ;
1174
1175 switch (etype) {
1176
1177 case Auto:
1178 throw std::invalid_argument(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
1179 break ;
1180
1181 case Expected:
1182 throw std::invalid_argument(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
1183 break ;
1184
1185 case Poisson:
1186 if (get_curWgtErrLo() >= 0) {
1187 // Weight is preset or precalculated
1188 lo = get_curWgtErrLo();
1189 hi = get_curWgtErrHi();
1190 return ;
1191 }
1192
1193 if (!_errLo || !_errHi) {
1194 // We didn't track asymmetric errors so far, so now we need to allocate
1195 initArray(_errLo, _arrSize, -1.);
1196 initArray(_errHi, _arrSize, -1.);
1198 }
1199
1200 // Calculate poisson errors
1201 Double_t ym,yp ;
1203 _errLo[_curIndex] = weight()-ym;
1204 _errHi[_curIndex] = yp-weight();
1205 lo = _errLo[_curIndex];
1206 hi = _errHi[_curIndex];
1207 return ;
1208
1209 case SumW2:
1210 lo = sqrt(get_curSumW2());
1211 hi = lo;
1212 return ;
1213
1214 case None:
1215 lo = 0 ;
1216 hi = 0 ;
1217 return ;
1218 }
1219}
1220
1221
1222// wve adjust for variable bin sizes
1223
1224////////////////////////////////////////////////////////////////////////////////
1225/// Perform boundary safe 'intOrder'-th interpolation of weights in dimension 'dim'
1226/// at current value 'xval'
1227
1228Double_t RooDataHist::interpolateDim(RooRealVar& dim, const RooAbsBinning* binning, Double_t xval, Int_t intOrder, Bool_t correctForBinSize, Bool_t cdfBoundaries)
1229{
1230 // Fill workspace arrays spanning interpolation area
1231 Int_t fbinC = dim.getBin(*binning) ;
1232 Int_t fbinLo = fbinC-intOrder/2 - ((xval<binning->binCenter(fbinC))?1:0) ;
1233 Int_t fbinM = dim.numBins(*binning) ;
1234
1235
1236 Int_t i ;
1237 Double_t yarr[10] ;
1238 Double_t xarr[10] ;
1239 for (i=fbinLo ; i<=intOrder+fbinLo ; i++) {
1240 Int_t ibin ;
1241 if (i>=0 && i<fbinM) {
1242 // In range
1243 ibin = i ;
1244 dim.setBinFast(ibin,*binning) ;
1245 //cout << "INRANGE: dim.getVal(ibin=" << ibin << ") = " << dim.getVal() << endl ;
1246 xarr[i-fbinLo] = dim.getVal() ;
1247 Int_t idx = calcTreeIndex(_vars, true);
1248 yarr[i - fbinLo] = get_wgt(idx);
1249 if (correctForBinSize) yarr[i-fbinLo] /= _binv[idx] ;
1250 } else if (i>=fbinM) {
1251 // Overflow: mirror
1252 ibin = 2*fbinM-i-1 ;
1253 dim.setBinFast(ibin,*binning) ;
1254 //cout << "OVERFLOW: dim.getVal(ibin=" << ibin << ") = " << dim.getVal() << endl ;
1255 if (cdfBoundaries) {
1256 xarr[i-fbinLo] = dim.getMax()+1e-10*(i-fbinM+1) ;
1257 yarr[i-fbinLo] = 1.0 ;
1258 } else {
1259 Int_t idx = calcTreeIndex(_vars, true) ;
1260 xarr[i-fbinLo] = 2*dim.getMax()-dim.getVal() ;
1261 yarr[i - fbinLo] = get_wgt(idx);
1262 if (correctForBinSize)
1263 yarr[i - fbinLo] /= _binv[idx];
1264 }
1265 } else {
1266 // Underflow: mirror
1267 ibin = -i - 1 ;
1268 dim.setBinFast(ibin,*binning) ;
1269 //cout << "UNDERFLOW: dim.getVal(ibin=" << ibin << ") = " << dim.getVal() << endl ;
1270 if (cdfBoundaries) {
1271 xarr[i-fbinLo] = dim.getMin()-ibin*(1e-10) ; ;
1272 yarr[i-fbinLo] = 0.0 ;
1273 } else {
1274 Int_t idx = calcTreeIndex(_vars, true) ;
1275 xarr[i-fbinLo] = 2*dim.getMin()-dim.getVal() ;
1276 yarr[i - fbinLo] = get_wgt(idx);
1277 if (correctForBinSize)
1278 yarr[i - fbinLo] /= _binv[idx];
1279 }
1280 }
1281 //cout << "ibin = " << ibin << endl ;
1282 }
1283// for (int k=0 ; k<=intOrder ; k++) {
1284// cout << "k=" << k << " x = " << xarr[k] << " y = " << yarr[k] << endl ;
1285// }
1286 dim.setBinFast(fbinC,*binning) ;
1287 Double_t ret = RooMath::interpolate(xarr,yarr,intOrder+1,xval) ;
1288 return ret ;
1289}
1290
1291
1292
1293
1294////////////////////////////////////////////////////////////////////////////////
1295/// Increment the bin content of the bin enclosing the given coordinates.
1296///
1297/// \param[in] row Coordinates of the bin.
1298/// \param[in] wgt Increment by this weight.
1299/// \param[in] sumw2 Optionally, track the sum of squared weights. If a value > 0 or
1300/// a weight != 1. is passed for the first time, a vector for the squared weights will be allocated.
1301void RooDataHist::add(const RooArgSet& row, Double_t wgt, Double_t sumw2)
1302{
1303 checkInit() ;
1304
1305 if ((sumw2 > 0. || wgt != 1.) && !_sumw2) {
1306 // Receiving a weighted entry. SumW2 != sumw from now on.
1307 _sumw2 = new double[_arrSize];
1308 std::copy(_wgt, _wgt+_arrSize, _sumw2);
1309
1311 }
1312
1313 const auto idx = calcTreeIndex(row, false);
1314
1315 _wgt[idx] += wgt ;
1316 if (_sumw2) _sumw2[idx] += (sumw2 > 0 ? sumw2 : wgt*wgt);
1317
1318 _cache_sum_valid = false;
1319}
1320
1321
1322
1323////////////////////////////////////////////////////////////////////////////////
1324/// Set a bin content.
1325/// \param[in] row Coordinates of the bin to be set.
1326/// \param[in] wgt New bin content.
1327/// \param[in] wgtErrLo Low error of the bin content.
1328/// \param[in] wgtErrHi High error of the bin content.
1329void RooDataHist::set(const RooArgSet& row, Double_t wgt, Double_t wgtErrLo, Double_t wgtErrHi)
1330{
1331 checkInit() ;
1332
1333 if (!_errLo || !_errHi) {
1334 initArray(_errLo, _arrSize, -1.);
1335 initArray(_errHi, _arrSize, -1.);
1337 }
1338
1339 const auto idx = calcTreeIndex(row, false);
1340
1341 _wgt[idx] = wgt ;
1342 _errLo[idx] = wgtErrLo ;
1343 _errHi[idx] = wgtErrHi ;
1344
1345 _cache_sum_valid = false;
1346}
1347
1348
1349
1350////////////////////////////////////////////////////////////////////////////////
1351/// Set bin content of bin that was last loaded with get(std::size_t).
1352/// \param[in] binNumber Optional bin number to set. If empty, currently active bin is set.
1353/// \param[in] wgt New bin content.
1354/// \param[in] wgtErr Error of the new bin content. If the weight need not have an error, use 0. or a negative number.
1355void RooDataHist::set(std::size_t binNumber, double wgt, double wgtErr) {
1356 checkInit() ;
1357
1358 if (wgtErr > 0. && !_sumw2) {
1359 // Receiving a weighted entry. Need to track sumw2 from now on:
1360 cloneArray(_sumw2, _wgt, _arrSize);
1361
1363 }
1364
1365 _wgt[binNumber] = wgt ;
1366 if (_errLo) _errLo[binNumber] = wgtErr;
1367 if (_errHi) _errHi[binNumber] = wgtErr;
1368 if (_sumw2) _sumw2[binNumber] = wgtErr*wgtErr;
1369
1371}
1372
1373
1374////////////////////////////////////////////////////////////////////////////////
1375/// Set bin content of bin that was last loaded with get(std::size_t).
1376/// \deprecated Prefer set(std::size_t, double, double).
1377/// \param[in] wgt New bin content.
1378/// \param[in] wgtErr Optional error of the bin content.
1379void RooDataHist::set(double wgt, double wgtErr) {
1380 if (_curIndex == std::numeric_limits<std::size_t>::max()) {
1381 _curIndex = calcTreeIndex(_vars, true) ;
1382 }
1383
1384 set(_curIndex, wgt, wgtErr);
1385}
1386
1387
1388////////////////////////////////////////////////////////////////////////////////
1389/// Set a bin content.
1390/// \param[in] row Coordinates to compute the bin from.
1391/// \param[in] wgt New bin content.
1392/// \param[in] wgtErr Optional error of the bin content.
1393void RooDataHist::set(const RooArgSet& row, Double_t wgt, Double_t wgtErr) {
1394 set(calcTreeIndex(row, false), wgt, wgtErr);
1395}
1396
1397
1398
1399////////////////////////////////////////////////////////////////////////////////
1400/// Add all data points contained in 'dset' to this data set with given weight.
1401/// Optional cut string expression selects the data points to be added and can
1402/// reference any variable contained in this data set
1403
1404void RooDataHist::add(const RooAbsData& dset, const char* cut, Double_t wgt)
1405{
1406 RooFormulaVar cutVar("select",cut,*dset.get()) ;
1407 add(dset,&cutVar,wgt) ;
1408}
1409
1410
1411
1412////////////////////////////////////////////////////////////////////////////////
1413/// Add all data points contained in 'dset' to this data set with given weight.
1414/// Optional RooFormulaVar pointer selects the data points to be added.
1415
1416void RooDataHist::add(const RooAbsData& dset, const RooFormulaVar* cutVar, Double_t wgt)
1417{
1418 checkInit() ;
1419
1420 RooFormulaVar* cloneVar = 0;
1421 RooArgSet* tmp(0) ;
1422 if (cutVar) {
1423 // Deep clone cutVar and attach clone to this dataset
1424 tmp = (RooArgSet*) RooArgSet(*cutVar).snapshot() ;
1425 if (!tmp) {
1426 coutE(DataHandling) << "RooDataHist::add(" << GetName() << ") Couldn't deep-clone cut variable, abort," << endl ;
1427 return ;
1428 }
1429
1430 cloneVar = (RooFormulaVar*) tmp->find(*cutVar) ;
1431 cloneVar->attachDataSet(dset) ;
1432 }
1433
1434
1435 Int_t i ;
1436 for (i=0 ; i<dset.numEntries() ; i++) {
1437 const RooArgSet* row = dset.get(i) ;
1438 if (!cloneVar || cloneVar->getVal()) {
1439 add(*row,wgt*dset.weight(), wgt*wgt*dset.weightSquared()) ;
1440 }
1441 }
1442
1443 if (cloneVar) {
1444 delete tmp ;
1445 }
1446
1448}
1449
1450
1451
1452////////////////////////////////////////////////////////////////////////////////
1453/// Return the sum of the weights of all bins in the histogram.
1454///
1455/// \param[in] correctForBinSize Multiply the sum of weights in each bin
1456/// with the N-dimensional bin volume, making the return value
1457/// the integral over the function represented by this histogram.
1458/// \param[in] inverseBinCor Divide by the N-dimensional bin volume.
1459Double_t RooDataHist::sum(bool correctForBinSize, bool inverseBinCor) const
1460{
1461 checkInit() ;
1462
1463 // Check if result was cached
1464 const CacheSumState_t cache_code = !correctForBinSize ? kNoBinCorrection : (inverseBinCor ? kInverseBinCorr : kCorrectForBinSize);
1465 if (_cache_sum_valid == static_cast<Int_t>(cache_code)) {
1466 return _cache_sum ;
1467 }
1468
1470 for (Int_t i=0; i < _arrSize; i++) {
1471 const double theBinVolume = correctForBinSize ? (inverseBinCor ? 1/_binv[i] : _binv[i]) : 1.0 ;
1472 kahanSum += get_wgt(i) * theBinVolume;
1473 }
1474
1475 // Store result in cache
1476 _cache_sum_valid = cache_code;
1477 _cache_sum = kahanSum;
1478
1479 return kahanSum;
1480}
1481
1482
1483
1484////////////////////////////////////////////////////////////////////////////////
1485/// Return the sum of the weights of a multi-dimensional slice of the histogram
1486/// by summing only over the dimensions specified in sumSet.
1487///
1488/// The coordinates of all other dimensions are fixed to those given in sliceSet
1489///
1490/// If correctForBinSize is specified, the sum of weights
1491/// is multiplied by the M-dimensional bin volume, (M = N(sumSet)),
1492/// making the return value the integral over the function
1493/// represented by this histogram
1494
1495Double_t RooDataHist::sum(const RooArgSet& sumSet, const RooArgSet& sliceSet, bool correctForBinSize, bool inverseBinCor)
1496{
1497 checkInit() ;
1498
1499 RooArgSet varSave ;
1500 varSave.addClone(_vars) ;
1501
1502 RooArgSet sliceOnlySet(sliceSet);
1503 sliceOnlySet.remove(sumSet,true,true) ;
1504
1505 _vars = sliceOnlySet;
1506 std::vector<double> const * pbinv = nullptr;
1507
1508 if(correctForBinSize && inverseBinCor) {
1509 pbinv = &calculatePartialBinVolume(sliceOnlySet);
1510 } else if(correctForBinSize && !inverseBinCor) {
1511 pbinv = &calculatePartialBinVolume(sumSet);
1512 }
1513
1514 // Calculate mask and refence plot bins for non-iterating variables
1515 std::vector<bool> mask(_vars.getSize());
1516 std::vector<int> refBin(_vars.getSize());
1517
1518 for (unsigned int i = 0; i < _vars.size(); ++i) {
1519 const RooAbsArg* arg = _vars[i];
1520 const RooAbsLValue* argLv = _lvvars[i]; // Same as above, but cross-cast
1521
1522 if (sumSet.find(*arg)) {
1523 mask[i] = false ;
1524 } else {
1525 mask[i] = true ;
1526 refBin[i] = argLv->getBin();
1527 }
1528 }
1529
1530 // Loop over entire data set, skipping masked entries
1532 for (Int_t ibin=0; ibin < _arrSize; ++ibin) {
1533
1534 std::size_t tmpibin = ibin;
1535 Bool_t skip(false) ;
1536
1537 // Check if this bin belongs in selected slice
1538 for (unsigned int ivar = 0; !skip && ivar < _vars.size(); ++ivar) {
1539 const Int_t idx = tmpibin / _idxMult[ivar] ;
1540 tmpibin -= idx*_idxMult[ivar] ;
1541 if (mask[ivar] && idx!=refBin[ivar])
1542 skip = true ;
1543 }
1544
1545 if (!skip) {
1546 const double theBinVolume = correctForBinSize ? (inverseBinCor ? 1/(*pbinv)[ibin] : (*pbinv)[ibin] ) : 1.0 ;
1547 total += get_wgt(ibin) * theBinVolume;
1548 }
1549 }
1550
1551 _vars = varSave ;
1552
1553 return total;
1554}
1555
1556////////////////////////////////////////////////////////////////////////////////
1557/// Return the sum of the weights of a multi-dimensional slice of the histogram
1558/// by summing only over the dimensions specified in sumSet.
1559///
1560/// The coordinates of all other dimensions are fixed to those given in sliceSet
1561///
1562/// If correctForBinSize is specified, the sum of weights
1563/// is multiplied by the M-dimensional bin volume, (M = N(sumSet)),
1564/// or the fraction of it that falls inside the range rangeName,
1565/// making the return value the integral over the function
1566/// represented by this histogram.
1567///
1568/// If correctForBinSize is not specified, the weights are multiplied by the
1569/// fraction of the bin volume that falls inside the range, i.e. a factor of
1570/// binVolumeInRange/totalBinVolume.
1571
1572Double_t RooDataHist::sum(const RooArgSet& sumSet, const RooArgSet& sliceSet,
1573 bool correctForBinSize, bool inverseBinCor,
1574 const std::map<const RooAbsArg*, std::pair<double, double> >& ranges,
1575 std::function<double(int)> getBinScale)
1576{
1577 checkInit();
1579 RooArgSet varSave;
1580 varSave.addClone(_vars);
1581 {
1582 RooArgSet sliceOnlySet(sliceSet);
1583 sliceOnlySet.remove(sumSet, true, true);
1584 _vars = sliceOnlySet;
1585 }
1586
1587 // Calculate mask and reference plot bins for non-iterating variables,
1588 // and get ranges for iterating variables
1589 std::vector<bool> mask(_vars.getSize());
1590 std::vector<int> refBin(_vars.getSize());
1591 std::vector<double> rangeLo(_vars.getSize(), -std::numeric_limits<Double_t>::infinity());
1592 std::vector<double> rangeHi(_vars.getSize(), +std::numeric_limits<Double_t>::infinity());
1593
1594 for (std::size_t i = 0; i < _vars.size(); ++i) {
1595 const RooAbsArg* arg = _vars[i];
1596 const RooAbsLValue* argLV = _lvvars[i]; // Same object as above, but cross cast
1597
1598 RooAbsArg* sumsetv = sumSet.find(*arg);
1599 RooAbsArg* slicesetv = sliceSet.find(*arg);
1600 mask[i] = !sumsetv;
1601 if (mask[i]) {
1602 assert(argLV);
1603 refBin[i] = argLV->getBin();
1604 }
1605
1606 auto it = ranges.find(sumsetv ? sumsetv : slicesetv);
1607 if (ranges.end() != it) {
1608 rangeLo[i] = it->second.first;
1609 rangeHi[i] = it->second.second;
1610 }
1611 }
1612
1613 // Loop over entire data set, skipping masked entries
1615 for (Int_t ibin = 0; ibin < _arrSize; ++ibin) {
1616 // Check if this bin belongs in selected slice
1617 bool skip{false};
1618 for (int ivar = 0, tmp = ibin; !skip && ivar < int(_vars.size()); ++ivar) {
1619 const Int_t idx = tmp / _idxMult[ivar];
1620 tmp -= idx*_idxMult[ivar];
1621 if (mask[ivar] && idx!=refBin[ivar]) skip = true;
1622 }
1623
1624 if (skip) continue;
1625
1626 // Work out bin volume
1627 // It's not necessary to figure out the bin volume for the slice-only set explicitely here.
1628 // We need to loop over the sumSet anyway to get the partial bin containment correction,
1629 // so we can get the slice-only set volume later by dividing _binv[ibin] / binVolumeSumSetFull.
1630 Double_t binVolumeSumSetFull = 1.;
1631 Double_t binVolumeSumSetInRange = 1.;
1632 for (Int_t ivar = 0, tmp = ibin; ivar < (int)_vars.size(); ++ivar) {
1633 const Int_t idx = tmp / _idxMult[ivar];
1634 tmp -= idx*_idxMult[ivar];
1635
1636 // If the current variable is not in the sumSet, it should not be considered for the bin volume
1637 const auto arg = _vars[ivar];
1638 if (!sumSet.find(*arg)) {
1639 continue;
1640 }
1641
1642 if (_binbounds[ivar].empty()) continue;
1643 const Double_t binLo = _binbounds[ivar][2 * idx];
1644 const Double_t binHi = _binbounds[ivar][2 * idx + 1];
1645 if (binHi < rangeLo[ivar] || binLo > rangeHi[ivar]) {
1646 // bin is outside of allowed range - effective bin volume is zero
1647 binVolumeSumSetInRange = 0.;
1648 break;
1649 }
1650
1651 binVolumeSumSetFull *= binHi - binLo;
1652 binVolumeSumSetInRange *= std::min(rangeHi[ivar], binHi) - std::max(rangeLo[ivar], binLo);
1653 }
1654 const Double_t corrPartial = binVolumeSumSetInRange / binVolumeSumSetFull;
1655 if (0. == corrPartial) continue;
1656 const Double_t corr = correctForBinSize ? (inverseBinCor ? binVolumeSumSetFull / _binv[ibin] : binVolumeSumSetFull ) : 1.0;
1657 total += getBinScale(ibin)*(get_wgt(ibin) * corr * corrPartial);
1658 }
1659
1660 _vars = varSave;
1661
1662 return total;
1663}
1664
1665
1666
1667////////////////////////////////////////////////////////////////////////////////
1668/// Fill the transient cache with partial bin volumes with up-to-date
1669/// values for the partial volume specified by observables 'dimSet'
1670
1671const std::vector<double>& RooDataHist::calculatePartialBinVolume(const RooArgSet& dimSet) const
1672{
1673 // The code bitset has all bits set to one whose position corresponds to arguments in dimSet.
1674 // It is used as the key for the bin volume caching hash map.
1675 int code{0};
1676 {
1677 int i{0} ;
1678 for (auto const& v : _vars) {
1679 code += ((dimSet.find(*v) ? 1 : 0) << i) ;
1680 ++i;
1681 }
1682 }
1683
1684 auto& pbinv = _pbinvCache[code];
1685 if(!pbinv.empty()) {
1686 return pbinv;
1687 }
1688 pbinv.resize(_arrSize);
1689
1690 // Calculate plot bins of components from master index
1691 std::vector<bool> selDim(_vars.getSize());
1692 for (std::size_t i = 0; i < selDim.size(); ++i) {
1693 selDim[i] = (code >> i) & 1 ;
1694 }
1695
1696 // Recalculate partial bin volume cache
1697 for (Int_t ibin=0; ibin < _arrSize ;ibin++) {
1698 Int_t idx(0), tmp(ibin) ;
1699 Double_t theBinVolume(1) ;
1700 for (unsigned int j=0; j < _lvvars.size(); ++j) {
1701 const RooAbsLValue* arg = _lvvars[j];
1702 assert(arg);
1703
1704 idx = tmp / _idxMult[j];
1705 tmp -= idx*_idxMult[j];
1706 if (selDim[j]) {
1707 theBinVolume *= arg->getBinWidth(idx) ;
1708 }
1709 }
1710 pbinv[ibin] = theBinVolume ;
1711 }
1712
1713 return pbinv;
1714}
1715
1716
1717
1718////////////////////////////////////////////////////////////////////////////////
1719/// Return the number of bins
1720
1722{
1723 return RooAbsData::numEntries() ;
1724}
1725
1726
1727
1728////////////////////////////////////////////////////////////////////////////////
1729/// Sum the weights of all bins.
1731
1732 if (_maskedWeights.empty()) {
1734 } else {
1736 }
1737}
1738
1739
1740
1741////////////////////////////////////////////////////////////////////////////////
1742/// Return the sum of weights in all entries matching cutSpec (if specified)
1743/// and in named range cutRange (if specified)
1744/// Return the
1745
1746Double_t RooDataHist::sumEntries(const char* cutSpec, const char* cutRange) const
1747{
1748 checkInit() ;
1749
1750 if (cutSpec==0 && cutRange==0) {
1751 return sumEntries();
1752 } else {
1753
1754 // Setup RooFormulaVar for cutSpec if it is present
1755 RooFormula* select = 0 ;
1756 if (cutSpec) {
1757 select = new RooFormula("select",cutSpec,*get()) ;
1758 }
1759
1760 // Otherwise sum the weights in the event
1761 ROOT::Math::KahanSum<> kahanSum;
1762 for (Int_t i=0; i < _arrSize; i++) {
1763 get(i) ;
1764 if ((!_maskedWeights.empty() && _maskedWeights[i] == 0.)
1765 || (select && select->eval() == 0.)
1766 || (cutRange && !_vars.allInRange(cutRange)))
1767 continue;
1768
1769 kahanSum += weight(i);
1770 }
1771
1772 if (select) delete select ;
1773
1774 return kahanSum;
1775 }
1776}
1777
1778
1779
1780////////////////////////////////////////////////////////////////////////////////
1781/// Reset all bin weights to zero
1782
1784{
1785 // WVE DO NOT CALL RooTreeData::reset() for binned
1786 // datasets as this will delete the bin definitions
1787
1788 std::fill(_wgt, _wgt + _arrSize, 0.);
1789 delete[] _errLo; _errLo = nullptr;
1790 delete[] _errHi; _errHi = nullptr;
1791 delete[] _sumw2; _sumw2 = nullptr;
1792
1794
1795 _cache_sum_valid = false;
1796}
1797
1798
1799
1800////////////////////////////////////////////////////////////////////////////////
1801/// Load bin `binNumber`, and return an argset with the coordinates of the bin centre.
1802/// \note The argset is owned by this data hist, and this function has a side effect, because
1803/// it alters the currently active bin.
1804const RooArgSet* RooDataHist::get(Int_t binNumber) const
1805{
1806 checkInit() ;
1807 _curIndex = binNumber;
1808
1809 return RooAbsData::get(_curIndex);
1810}
1811
1812
1813
1814////////////////////////////////////////////////////////////////////////////////
1815/// Return a RooArgSet with whose coordinates denote the bin centre of the bin
1816/// enclosing the point in `coord`.
1817/// \note The argset is owned by this data hist, and this function has a side effect, because
1818/// it alters the currently active bin.
1819const RooArgSet* RooDataHist::get(const RooArgSet& coord) const {
1820 return get(calcTreeIndex(coord, false));
1821}
1822
1823
1824
1825////////////////////////////////////////////////////////////////////////////////
1826/// Return the volume of the bin enclosing coordinates 'coord'.
1828 checkInit() ;
1829 return _binv[calcTreeIndex(coord, false)] ;
1830}
1831
1832
1833////////////////////////////////////////////////////////////////////////////////
1834/// Set all the event weight of all bins to the specified value
1835
1837{
1838 for (Int_t i=0 ; i<_arrSize ; i++) {
1839 _wgt[i] = value ;
1840 }
1841
1843}
1844
1845
1846
1847////////////////////////////////////////////////////////////////////////////////
1848/// Create an iterator over all bins in a slice defined by the subset of observables
1849/// listed in sliceArg. The position of the slice is given by otherArgs
1850
1852{
1853 // Update to current position
1854 _vars = otherArgs ;
1855 _curIndex = calcTreeIndex(_vars, true);
1856
1857 RooAbsArg* intArg = _vars.find(sliceArg) ;
1858 if (!intArg) {
1859 coutE(InputArguments) << "RooDataHist::sliceIterator() variable " << sliceArg.GetName() << " is not part of this RooDataHist" << endl ;
1860 return 0 ;
1861 }
1862 return new RooDataHistSliceIter(*this,*intArg) ;
1863}
1864
1865
1866////////////////////////////////////////////////////////////////////////////////
1867/// Change the name of the RooDataHist
1868
1869void RooDataHist::SetName(const char *name)
1870{
1871 if (_dir) _dir->GetList()->Remove(this);
1873 if (_dir) _dir->GetList()->Add(this);
1874}
1875
1876
1877////////////////////////////////////////////////////////////////////////////////
1878/// Change the title of this RooDataHist
1879
1880void RooDataHist::SetNameTitle(const char *name, const char* title)
1881{
1882 if (_dir) _dir->GetList()->Remove(this);
1883 TNamed::SetNameTitle(name,title) ;
1884 if (_dir) _dir->GetList()->Add(this);
1885}
1886
1887
1888////////////////////////////////////////////////////////////////////////////////
1889/// Print value of the dataset, i.e. the sum of weights contained in the dataset
1890
1891void RooDataHist::printValue(ostream& os) const
1892{
1893 os << numEntries() << " bins (" << sumEntries() << " weights)" ;
1894}
1895
1896
1897
1898
1899////////////////////////////////////////////////////////////////////////////////
1900/// Print argument of dataset, i.e. the observable names
1901
1902void RooDataHist::printArgs(ostream& os) const
1903{
1904 os << "[" ;
1905 Bool_t first(kTRUE) ;
1906 for (const auto arg : _vars) {
1907 if (first) {
1908 first=kFALSE ;
1909 } else {
1910 os << "," ;
1911 }
1912 os << arg->GetName() ;
1913 }
1914 os << "]" ;
1915}
1916
1917
1918
1919////////////////////////////////////////////////////////////////////////////////
1920/// Compute which bins of the dataset are part of the currently set fit range.
1922{
1923 checkInit() ;
1924
1925 _maskedWeights.assign(_wgt, _wgt + _arrSize);
1926
1927 for (Int_t i=0; i < _arrSize; ++i) {
1928 get(i) ;
1929
1930 for (const auto arg : _vars) {
1931 if (!arg->inRange(nullptr)) {
1932 _maskedWeights[i] = 0.;
1933 break;
1934 }
1935 }
1936 }
1937
1938}
1939
1940
1941
1942////////////////////////////////////////////////////////////////////////////////
1943/// Returns true if dataset contains entries with a non-integer weight.
1944
1946{
1947 for (Int_t i=0; i < _arrSize; ++i) {
1948 const double wgt = _wgt[i];
1949 double intpart;
1950 if (fabs(std::modf(wgt, &intpart)) > 1.E-10)
1951 return true;
1952 }
1953
1954 return false;
1955}
1956
1957
1958////////////////////////////////////////////////////////////////////////////////
1959/// Print the details on the dataset contents
1960
1961void RooDataHist::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
1962{
1963 RooAbsData::printMultiline(os,content,verbose,indent) ;
1964
1965 os << indent << "Binned Dataset " << GetName() << " (" << GetTitle() << ")" << endl ;
1966 os << indent << " Contains " << numEntries() << " bins with a total weight of " << sumEntries() << endl;
1967
1968 if (!verbose) {
1969 os << indent << " Observables " << _vars << endl ;
1970 } else {
1971 os << indent << " Observables: " ;
1973 }
1974
1975 if(verbose) {
1976 if (_cachedVars.getSize()>0) {
1977 os << indent << " Caches " << _cachedVars << endl ;
1978 }
1979 }
1980}
1981
1982
1983
1984////////////////////////////////////////////////////////////////////////////////
1985/// Stream an object of class RooDataHist.
1986void RooDataHist::Streamer(TBuffer &R__b) {
1987 if (R__b.IsReading()) {
1988
1989 UInt_t R__s, R__c;
1990 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1991
1992 if (R__v > 2) {
1993 R__b.ReadClassBuffer(RooDataHist::Class(),this,R__v,R__s,R__c);
1994 R__b.CheckByteCount(R__s, R__c, RooDataHist::IsA());
1995 initialize(0, false);
1996 } else {
1997
1998 // Legacy dataset conversion happens here. Legacy RooDataHist inherits from RooTreeData
1999 // which in turn inherits from RooAbsData. Manually stream RooTreeData contents on
2000 // file here and convert it into a RooTreeDataStore which is installed in the
2001 // new-style RooAbsData base class
2002
2003 // --- This is the contents of the streamer code of RooTreeData version 2 ---
2004 UInt_t R__s1, R__c1;
2005 Version_t R__v1 = R__b.ReadVersion(&R__s1, &R__c1); if (R__v1) { }
2006
2007 RooAbsData::Streamer(R__b);
2008 TTree* X_tree(0) ; R__b >> X_tree;
2009 RooArgSet X_truth ; X_truth.Streamer(R__b);
2010 TString X_blindString ; X_blindString.Streamer(R__b);
2011 R__b.CheckByteCount(R__s1, R__c1, TClass::GetClass("RooTreeData"));
2012 // --- End of RooTreeData-v1 streamer
2013
2014 // Construct RooTreeDataStore from X_tree and complete initialization of new-style RooAbsData
2015 _dstore = new RooTreeDataStore(X_tree,_vars) ;
2016 _dstore->SetName(GetName()) ;
2018 _dstore->checkInit() ;
2019
2020 RooDirItem::Streamer(R__b);
2021 R__b >> _arrSize;
2022 delete [] _wgt;
2023 _wgt = new Double_t[_arrSize];
2025 delete [] _errLo;
2026 _errLo = new Double_t[_arrSize];
2028 delete [] _errHi;
2029 _errHi = new Double_t[_arrSize];
2031 delete [] _sumw2;
2032 _sumw2 = new Double_t[_arrSize];
2034 delete [] _binv;
2035 _binv = new Double_t[_arrSize];
2036 _realVars.Streamer(R__b);
2037 double tmp;
2038 R__b >> tmp; //_curWeight;
2039 R__b >> tmp; //_curWgtErrLo;
2040 R__b >> tmp; //_curWgtErrHi;
2041 R__b >> tmp; //_curSumW2;
2042 R__b >> tmp; //_curVolume;
2043 R__b >> _curIndex;
2044 R__b.CheckByteCount(R__s, R__c, RooDataHist::IsA());
2045 }
2046
2047 } else {
2048
2049 R__b.WriteClassBuffer(RooDataHist::Class(),this);
2050 }
2051}
2052
2053
2054////////////////////////////////////////////////////////////////////////////////
2055/// Return event weights of all events in range [first, first+len).
2056/// If no contiguous structure of weights is stored, an empty batch is be returned.
2057/// In this case, the single-value weight() needs to be used to retrieve it.
2058RooSpan<const double> RooDataHist::getWeightBatch(std::size_t first, std::size_t len) const {
2059 return _maskedWeights.empty() ?
2062}
2063
2064
2065////////////////////////////////////////////////////////////////////////////////
2066/// Write information to retrieve data columns into `evalData.spans`.
2067/// All spans belonging to variables of this dataset are overwritten. Spans to other
2068/// variables remain intact.
2069/// \param[out] evalData Store references to all data batches in this struct's `spans`.
2070/// The key to retrieve an item is the pointer of the variable that owns the data.
2071/// \param first Index of first event that ends up in the batch.
2072/// \param len Number of events in each batch.
2073void RooDataHist::getBatches(RooBatchCompute::RunContext& evalData, std::size_t begin, std::size_t len) const {
2074 for (auto&& batch : store()->getBatches(begin, len).spans) {
2075 evalData.spans[batch.first] = std::move(batch.second);
2076 }
2077}
2078
2079////////////////////////////////////////////////////////////////////////////////
2080/// Hand over pointers to our weight arrays to the data store implementation.
2083}
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
#define coutI(a)
#define coutE(a)
#define TRACE_DESTROY
Definition RooTrace.h:24
#define TRACE_CREATE
Definition RooTrace.h:23
int Int_t
Definition RtypesCore.h:45
short Version_t
Definition RtypesCore.h:65
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
static void indent(ostringstream &buf, int indent_level)
static unsigned int total
char name[80]
Definition TGX11.cxx:110
float xmin
#define hi
float * q
float ymin
double pow(double, double)
double sqrt(double)
Int_t gDebug
Definition TROOT.cxx:590
char * Form(const char *fmt,...)
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:122
static KahanSum< T, N > Accumulate(Iterator begin, Iterator end, T initialValue=T{})
Iterate over a range and return an instance of a KahanSum.
Definition Util.h:179
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:72
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
virtual RooAbsBinning * clone(const char *name=0) const =0
virtual Double_t binCenter(Int_t bin) const =0
virtual Int_t binNumber(Double_t x) const =0
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual Int_t getBin(const char *) const
Get index of plot bin for current value this category.
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
Return the number of fit bins ( = number of types )
bool hasLabel(const std::string &label) const
Check if a state with name label exists.
virtual const char * getCurrentLabel() const
Return label string of current state.
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
Bool_t allInRange(const char *rangeSpec) const
Return true if all contained object report to have their value inside the specified range.
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 RooBatchCompute::RunContext getBatches(std::size_t first, std::size_t len) const =0
Retrieve batches for all observables in this data store.
virtual void checkInit() const
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:49
virtual const RooArgSet * get() const
Definition RooAbsData.h:92
RooAbsDataStore * store()
Definition RooAbsData.h:68
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Interface for detailed printing of object.
void checkInit() const
virtual Double_t weight() const =0
static StorageType defaultStorageType
Definition RooAbsData.h:256
virtual Double_t weightSquared() const =0
virtual void fill()
RooArgSet _vars
Definition RooAbsData.h:291
virtual void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)
Internal method – Attach dataset copied with cache contents to copied instances of functions.
RooArgSet _cachedVars
Definition RooAbsData.h:292
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
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
RooAbsDataStore * _dstore
External variables cached with this data set.
Definition RooAbsData.h:294
Abstract base class for objects that are lvalues, i.e.
virtual Double_t getBinWidth(Int_t i, const char *rangeName=0) const =0
virtual Int_t getBin(const char *rangeName=0) const =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:61
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
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:70
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:118
Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to non-owning set.
RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add clone of specified element to an owning set.
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values,...
Definition RooBinning.h:28
RooCategory is an object to represent discrete states.
Definition RooCategory.h:27
bool defineType(const std::string &label)
Define a state with given name.
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition RooCmdArg.h:27
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
TObject * getObject(const char *name, TObject *obj=0)
Return TObject property registered with name 'name'.
Bool_t defineInt(const char *name, const char *argName, Int_t intNum, Int_t defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
void defineMutex(const char *argName1, const char *argName2)
Define arguments named argName1 and argName2 mutually exclusive.
Bool_t defineObject(const char *name, const char *argName, Int_t setNum, const TObject *obj=0, Bool_t isArray=kFALSE)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
const char * getString(const char *name, const char *defaultValue="", Bool_t convEmptyToNull=kFALSE)
Return string property registered with name 'name'.
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
const RooLinkedList & getObjectList(const char *name)
Return list of objects registered with name 'name'.
Bool_t defineDouble(const char *name, const char *argName, Int_t doubleNum, Double_t defValue=0.)
Define Double_t property name 'name' mapped to Double_t in slot 'doubleNum' in RooCmdArg with name ar...
void defineDependency(const char *refArgName, const char *neededArgName)
Define that processing argument name refArgName requires processing of argument named neededArgName t...
Double_t getDouble(const char *name, Double_t defaultValue=0)
Return Double_t property registered with name 'name'.
Bool_t defineString(const char *name, const char *argName, Int_t stringNum, const char *defValue="", Bool_t appendMode=kFALSE)
Define Double_t property name 'name' mapped to Double_t in slot 'stringNum' in RooCmdArg with name ar...
Bool_t ok(Bool_t verbose) const
Return true of parsing was successful.
Bool_t process(const RooCmdArg &arg)
Process given RooCmdArg.
The RooDataHist is a container class to hold N-dimensional binned data.
Definition RooDataHist.h:37
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...
Int_t _cache_sum_valid
friend class RooDataHistSliceIter
void getBatches(RooBatchCompute::RunContext &evalData, std::size_t begin, std::size_t len) const override
Write information to retrieve data columns into evalData.spans.
void SetNameTitle(const char *name, const char *title) override
Change the title of this RooDataHist.
std::vector< double > _maskedWeights
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) override
Implementation of RooAbsData virtual method that drives the RooAbsData::reduce() methods.
const std::vector< double > & calculatePartialBinVolume(const RooArgSet &dimSet) const
Fill the transient cache with partial bin volumes with up-to-date values for the partial volume speci...
Double_t weight() const override
Return weight of last bin that was requested with get().
RooAbsData * cacheClone(const RooAbsArg *newCacheOwner, const RooArgSet *newCacheVars, const char *newName=0) override
Construct a clone of this dataset that contains only the cached variables.
std::unordered_map< int, std::vector< double > > _pbinvCache
void checkBinBounds() const
double weight(std::size_t i) const
Return weight of i-th bin.
Definition RooDataHist.h:98
void set(std::size_t binNumber, double weight, double wgtErr)
Set bin content of bin that was last loaded with get(std::size_t).
Double_t sumEntries() const override
Sum the weights of all bins.
RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len) const override
Return event weights of all events in range [first, first+len).
virtual void add(const RooArgSet &row, Double_t wgt=1.0)
Add wgt to the bin content enclosed by the coordinates passed in row.
Definition RooDataHist.h:64
double * _errHi
double * _binv
RooDataHist()
Default constructor.
Double_t get_curWgtErrLo() const
virtual void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const override
Print the details on the dataset contents.
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.
Int_t getIndex(const RooArgSet &coord, Bool_t fast=false) const
Calculate bin number of the given coordinates.
RooPlot * plotOn(RooPlot *frame, PlotOpt o) const override
Back end function to plotting functionality.
Double_t get_curSumW2() const
Bool_t isNonPoissonWeighted() const override
Returns true if dataset contains entries with a non-integer weight.
virtual void printArgs(std::ostream &os) const override
Print argument of dataset, i.e. the observable names.
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.
double * _sumw2
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.
std::size_t _curIndex
Copy of _wgtVec, but masked events have a weight of zero.
Int_t calcTreeIndex() const
Legacy overload to calculate the tree index from the current value of _vars.
Double_t get_curWgtErrHi() const
~RooDataHist() override
Destructor.
void setAllWeights(Double_t value)
Set all the event weight of all bins to the specified value.
Double_t get_wgt(std::size_t idx) const
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.
std::vector< RooAbsLValue * > _lvvars
Cache for arrays of partial bin volumes.
Int_t numEntries() const override
Return the number of bins.
void cacheValidEntries()
Compute which bins of the dataset are part of the currently set fit range.
void SetName(const char *name) override
Change the name of the RooDataHist.
std::vector< std::unique_ptr< const RooAbsBinning > > _lvbins
List of observables casted as RooAbsLValue.
RooArgSet _realVars
std::vector< Int_t > _idxMult
void registerWeightArraysToDataStore() const
Hand over pointers to our weight arrays to the data store implementation.
void reset() override
Reset all bin weights to zero.
double * _errLo
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 * _wgt
CacheSumState_t
list of bin bounds per dimension
virtual void printValue(std::ostream &os) const override
Print value of the dataset, i.e. the sum of weights contained in the dataset.
Double_t _cache_sum
Is cache sum valid? Needs to be Int_t instead of CacheSumState_t for subclasses.
Double_t binVolume() const
Return volume of current bin.
const RooArgSet * get() const override
Get bin centre of current bin.
Definition RooDataHist.h:74
void weightError(Double_t &lo, Double_t &hi, ErrorType etype=Poisson) const override
Return the error of current weight.
Double_t sum(bool correctForBinSize, bool inverseCorr=false) const
Return the sum of the weights of all bins in the histogram.
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.
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
TDirectory * _dir
Definition RooDirItem.h:33
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
RooFormula internally uses ROOT's TFormula to compute user-defined expressions of RooAbsArgs.
Definition RooFormula.h:34
Double_t eval(const RooArgSet *nset=0) const
Evalute all parameters/observables, and then evaluate formula.
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 ...
Int_t GetSize() const
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
virtual void Add(TObject *arg)
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:39
void setRange(const char *name, Double_t min, Double_t max)
Set a fit or plotting range.
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
void setBinning(const RooAbsBinning &binning, const char *name=0)
Add given binning under name 'name' with this variable.
A simple container to hold a batch of data values.
Definition RooSpan.h:34
constexpr std::span< T >::pointer data() const
Definition RooSpan.h:106
constexpr bool empty() const noexcept
Definition RooSpan.h:125
RooTreeDataStore is a TTree-backed data storage.
RooUniformBinning is an implementation of RooAbsBinning that provides a uniform binning in 'n' bins b...
RooVectorDataStore uses std::vectors to store data columns.
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:43
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:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2957
virtual TList * GetList() const
Definition TDirectory.h:176
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
TAxis * GetZaxis()
Definition TH1.h:322
virtual Int_t GetNbinsY() const
Definition TH1.h:297
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition TH1.cxx:8903
virtual Int_t GetNbinsZ() const
Definition TH1.h:298
virtual Int_t GetDimension() const
Definition TH1.h:282
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition TH1.h:320
virtual Int_t GetNbinsX() const
Definition TH1.h:296
TAxis * GetYaxis()
Definition TH1.h:321
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:4993
Iterator abstract base class.
Definition TIterator.h:30
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:822
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:130
Basic string class.
Definition TString.h:136
A TTree represents a columnar dataset.
Definition TTree.h:79
const Int_t n
Definition legend1.C:16
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.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition TMath.h:735
Definition first.py:1
RooAbsBinning * bins
Definition RooAbsData.h:158
This struct enables passing computation data around between elements of a computation graph.
Definition RunContext.h:31
std::unordered_map< const RooAbsReal *, RooSpan< const double > > spans
Once an object has computed its value(s), the span pointing to the results is registered here.
Definition RunContext.h:52
auto * l
Definition textangle.C:4