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