Logo ROOT  
Reference Guide
RooAbsData.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 RooAbsData.cxx
19\class RooAbsData
20\ingroup Roofitcore
21
22RooAbsData is the common abstract base class for binned and unbinned
23datasets. The abstract interface defines plotting and tabulating entry
24points for its contents and provides an iterator over its elements
25(bins for binned data sets, data points for unbinned datasets).
26
27### Storing global observables in RooFit datasets
28
29RooFit groups model variables into *observables* and *parameters*, depending on
30if their values are stored in the dataset. For fits with parameter
31constraints, there is a third kind of variables, called *global observables*.
32These represent the results of auxiliary measurements that constrain the
33nuisance parameters. In the RooFit implementation, a likelihood is generally
34the sum of two terms:
35- the likelihood of the data given the parameters, where the normalization set
36 is the set of observables (implemented by RooNLLVar)
37- the constraint term, where the normalization set is the set of *global
38observables* (implemented by RooConstraintSum)
39
40Before this release, the global observable values were always taken from the
41model/pdf. With this release, a mechanism is added to store a snapshot of
42global observables in any RooDataSet or RooDataHist. For toy studies where the
43global observables assume a different values for each toy, the bookkeeping of
44the set of global observables and in particular their values is much easier
45with this change.
46
47Usage example for a model with global observables `g1` and `g2`:
48```
49auto data = model.generate(x, 1000); // data has only the single observables x
50data->setGlobalObservables(g1, g2); // now, data also stores a snapshot of g1 and g2
51
52// If you fit the model to the data, the global observables and their values
53// are taken from the dataset:
54model.fitTo(*data);
55
56// You can still define the set of global observables yourself, but the values
57// will be takes from the dataset if available:
58model.fitTo(*data, GlobalObservables(g1, g2));
59
60// To force `fitTo` to take the global observable values from the model even
61// though they are in the dataset, you can use the new `GlobalObservablesSource`
62// command argument:
63model.fitTo(*data, GlobalObservables(g1, g2), GlobalObservablesSource("model"));
64// The only other allowed value for `GlobalObservablesSource` is "data", which
65// corresponds to the new default behavior explained above.
66```
67
68In case you create a RooFit dataset directly by calling its constructor, you
69can also pass the global observables in a command argument instead of calling
70RooAbsData::setGlobalObservables() later:
71```
72RooDataSet data{"dataset", "dataset", x, RooFit::GlobalObservables(g1, g2)};
73```
74
75To access the set of global observables stored in a RooAbsData, call
76RooAbsData::getGlobalObservables(). It returns a `nullptr` if no global
77observable snapshots are stored in the dataset.
78**/
79
80#include "RooAbsData.h"
81
82#include "TBuffer.h"
83#include "TClass.h"
84#include "TMath.h"
85#include "TTree.h"
86
87#include "RooFormulaVar.h"
88#include "RooCmdConfig.h"
89#include "RooAbsRealLValue.h"
90#include "RooMsgService.h"
91#include "RooMultiCategory.h"
92#include "Roo1DTable.h"
93#include "RooAbsDataStore.h"
94#include "RooVectorDataStore.h"
95#include "RooTreeDataStore.h"
96#include "RooDataHist.h"
98#include "RooCategory.h"
99#include "RooTrace.h"
100#include "RooUniformBinning.h"
101#include "RooSimultaneous.h"
102
103#include "RooRealVar.h"
104#include "RooGlobalFunc.h"
105#include "RooPlot.h"
106#include "RooCurve.h"
107#include "RooHist.h"
108#include "RooHelpers.h"
109
110#include "ROOT/StringUtils.hxx"
111#include "TMatrixDSym.h"
112#include "TPaveText.h"
113#include "TH1.h"
114#include "TH2.h"
115#include "TH3.h"
116#include "Math/Util.h"
117
118#include <iostream>
119#include <memory>
120
121
122using namespace std;
123
125;
126
127static std::map<RooAbsData*,int> _dcc ;
128
130
131////////////////////////////////////////////////////////////////////////////////
132
134{
135 if (RooAbsData::Composite == s) {
136 cout << "Composite storage is not a valid *default* storage type." << endl;
137 } else {
139 }
140}
141
142////////////////////////////////////////////////////////////////////////////////
143
145{
146 return defaultStorageType;
147}
148
149////////////////////////////////////////////////////////////////////////////////
150
152{
153 _dcc[data]++ ;
154 //cout << "RooAbsData(" << data << ") claim incremented to " << _dcc[data] << endl ;
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// If return value is true variables can be deleted
159
161{
162 if (_dcc[data]>0) {
163 _dcc[data]-- ;
164 }
165
166 //cout << "RooAbsData(" << data << ") claim decremented to " << _dcc[data] << endl ;
167 return (_dcc[data]==0) ;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Default constructor
172
174{
175 claimVars(this) ;
176 _dstore = 0 ;
178
179 RooTrace::create(this) ;
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Constructor from a set of variables. Only fundamental elements of vars
184/// (RooRealVar,RooCategory etc) are stored as part of the dataset
185
187 TNamed(name,title),
188 _vars("Dataset Variables"),
189 _cachedVars("Cached Variables"),
190 _dstore(dstore),
191 _namePtr(nullptr)
192{
193 if (dynamic_cast<RooTreeDataStore *>(dstore)) {
195 } else if (dynamic_cast<RooVectorDataStore *>(dstore)) {
197 } else {
199 }
200 // cout << "created dataset " << this << endl ;
201 claimVars(this);
202
203 // clone the fundamentals of the given data set into internal buffer
204 for (const auto var : vars) {
205 if (!var->isFundamental()) {
206 coutE(InputArguments) << "RooAbsDataStore::initialize(" << GetName()
207 << "): Data set cannot contain non-fundamental types, ignoring " << var->GetName()
208 << endl;
209 throw std::invalid_argument(std::string("Only fundamental variables can be placed into datasets. This is violated for ") + var->GetName());
210 } else {
211 _vars.addClone(*var);
212 }
213 }
214
215 // reconnect any parameterized ranges to internal dataset observables
216 for (auto var : _vars) {
217 var->attachArgs(_vars);
218 }
219
221
222 RooTrace::create(this);
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Copy constructor
227
228RooAbsData::RooAbsData(const RooAbsData& other, const char* newname) :
229 TNamed(newname ? newname : other.GetName(),other.GetTitle()),
230 RooPrintable(other), _vars(),
231 _cachedVars("Cached Variables"),
232 _namePtr(newname ? RooNameReg::instance().constPtr(newname) : other._namePtr)
233{
234 //cout << "created dataset " << this << endl ;
235 claimVars(this) ;
236 _vars.addClone(other._vars) ;
237
238 // reconnect any parameterized ranges to internal dataset observables
239 for (auto var : _vars) {
240 var->attachArgs(_vars);
241 }
242
243
244 if (other._ownedComponents.size()>0) {
245
246 // copy owned components here
247
248 map<string,RooAbsDataStore*> smap ;
249 for (auto& itero : other._ownedComponents) {
250 RooAbsData* dclone = (RooAbsData*) itero.second->Clone();
251 _ownedComponents[itero.first] = dclone;
252 smap[itero.first] = dclone->store();
253 }
254
256 _dstore = new RooCompositeDataStore(newname?newname:other.GetName(),other.GetTitle(),_vars,*idx,smap) ;
258
259 } else {
260
261 // Convert to vector store if default is vector
262 _dstore = other._dstore->clone(_vars,newname?newname:other.GetName()) ;
263 storageType = other.storageType;
264 }
265
267
268 RooTrace::create(this) ;
269}
270
272 TNamed::operator=(other);
274
275 claimVars(this);
276 _vars.Clear();
277 _vars.addClone(other._vars);
278 _namePtr = other._namePtr;
279
280 // reconnect any parameterized ranges to internal dataset observables
281 for (const auto var : _vars) {
282 var->attachDataSet(*this) ;
283 }
284
285
286 if (other._ownedComponents.size()>0) {
287
288 // copy owned components here
289
290 map<string,RooAbsDataStore*> smap ;
291 for (auto& itero : other._ownedComponents) {
292 RooAbsData* dclone = (RooAbsData*) itero.second->Clone();
293 _ownedComponents[itero.first] = dclone;
294 smap[itero.first] = dclone->store();
295 }
296
298 _dstore = new RooCompositeDataStore(GetName(), GetTitle(), _vars, *idx, smap);
300
301 } else {
302
303 // Convert to vector store if default is vector
304 _dstore = other._dstore->clone(_vars);
305 storageType = other.storageType;
306 }
307
309
310 return *this;
311}
312
313
315 if (other._globalObservables) {
316 if(_globalObservables == nullptr) _globalObservables = std::make_unique<RooArgSet>();
317 else _globalObservables->clear();
318 other._globalObservables->snapshot(*_globalObservables);
319 } else {
320 _globalObservables.reset(nullptr);
321 }
322}
323
324
325////////////////////////////////////////////////////////////////////////////////
326/// Destructor
327
329{
330 if (releaseVars(this)) {
331 // will cause content to be deleted subsequently in dtor
332 } else {
334 }
335
336 // delete owned contents.
337 delete _dstore ;
338
339 // Delete owned dataset components
340 for(map<std::string,RooAbsData*>::iterator iter = _ownedComponents.begin() ; iter!= _ownedComponents.end() ; ++iter) {
341 delete iter->second ;
342 }
343
344 RooTrace::destroy(this) ;
345}
346
347////////////////////////////////////////////////////////////////////////////////
348/// Convert tree-based storage to vector-based storage
349
351{
352 if (auto treeStore = dynamic_cast<RooTreeDataStore*>(_dstore)) {
353 _dstore = new RooVectorDataStore(*treeStore, _vars, GetName());
354 delete treeStore;
356 }
357}
358
359////////////////////////////////////////////////////////////////////////////////
360
361bool RooAbsData::changeObservableName(const char* from, const char* to)
362{
363 bool ret = _dstore->changeObservableName(from,to) ;
364
365 RooAbsArg* tmp = _vars.find(from) ;
366 if (tmp) {
367 tmp->SetName(to) ;
368 }
369 return ret ;
370}
371
372////////////////////////////////////////////////////////////////////////////////
373
375{
376 _dstore->fill() ;
377}
378
379////////////////////////////////////////////////////////////////////////////////
380
382{
383 return nullptr != _dstore ? _dstore->numEntries() : 0;
384}
385
386////////////////////////////////////////////////////////////////////////////////
387
389{
390 _dstore->reset() ;
391}
392
393////////////////////////////////////////////////////////////////////////////////
394
396{
397 checkInit() ;
398 return _dstore->get(index) ;
399}
400
401////////////////////////////////////////////////////////////////////////////////
402/// Internal method -- Cache given set of functions with data
403
404void RooAbsData::cacheArgs(const RooAbsArg* cacheOwner, RooArgSet& varSet, const RooArgSet* nset, bool skipZeroWeights)
405{
406 _dstore->cacheArgs(cacheOwner,varSet,nset,skipZeroWeights) ;
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// Internal method -- Remove cached function values
411
413{
416}
417
418////////////////////////////////////////////////////////////////////////////////
419/// Internal method -- Attach dataset copied with cache contents to copied instances of functions
420
421void RooAbsData::attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars)
422{
423 _dstore->attachCache(newOwner, cachedVars) ;
424}
425
426////////////////////////////////////////////////////////////////////////////////
427
428void RooAbsData::setArgStatus(const RooArgSet& set, bool active)
429{
430 _dstore->setArgStatus(set,active) ;
431}
432
433////////////////////////////////////////////////////////////////////////////////
434/// Control propagation of dirty flags from observables in dataset
435
437{
438 _dstore->setDirtyProp(flag) ;
439}
440
441////////////////////////////////////////////////////////////////////////////////
442/// Create a reduced copy of this dataset. The caller takes ownership of the returned dataset
443///
444/// The following optional named arguments are accepted
445/// <table>
446/// <tr><td> `SelectVars(const RooArgSet& vars)` <td> Only retain the listed observables in the output dataset
447/// <tr><td> `Cut(const char* expression)` <td> Only retain event surviving the given cut expression
448/// <tr><td> `Cut(const RooFormulaVar& expr)` <td> Only retain event surviving the given cut formula
449/// <tr><td> `CutRange(const char* name)` <td> Only retain events inside range with given name. Multiple CutRange
450/// arguments may be given to select multiple ranges
451/// <tr><td> `EventRange(int lo, int hi)` <td> Only retain events with given sequential event numbers
452/// <tr><td> `Name(const char* name)` <td> Give specified name to output dataset
453/// <tr><td> `Title(const char* name)` <td> Give specified title to output dataset
454/// </table>
455
456RooAbsData* RooAbsData::reduce(const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3,const RooCmdArg& arg4,
457 const RooCmdArg& arg5,const RooCmdArg& arg6,const RooCmdArg& arg7,const RooCmdArg& arg8)
458{
459 // Define configuration for this method
460 RooCmdConfig pc(Form("RooAbsData::reduce(%s)",GetName())) ;
461 pc.defineString("name","Name",0,"") ;
462 pc.defineString("title","Title",0,"") ;
463 pc.defineString("cutRange","CutRange",0,"") ;
464 pc.defineString("cutSpec","CutSpec",0,"") ;
465 pc.defineObject("cutVar","CutVar",0,0) ;
466 pc.defineInt("evtStart","EventRange",0,0) ;
467 pc.defineInt("evtStop","EventRange",1,std::numeric_limits<int>::max()) ;
468 pc.defineObject("varSel","SelectVars",0,0) ;
469 pc.defineMutex("CutVar","CutSpec") ;
470
471 // Process & check varargs
472 pc.process(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
473 if (!pc.ok(true)) {
474 return nullptr;
475 }
476
477 // Extract values from named arguments
478 const char* cutRange = pc.getString("cutRange",0,true) ;
479 const char* cutSpec = pc.getString("cutSpec",0,true) ;
480 RooFormulaVar* cutVar = static_cast<RooFormulaVar*>(pc.getObject("cutVar",0)) ;
481 Int_t nStart = pc.getInt("evtStart",0) ;
482 Int_t nStop = pc.getInt("evtStop",std::numeric_limits<int>::max()) ;
483 RooArgSet* varSet = static_cast<RooArgSet*>(pc.getObject("varSel")) ;
484 const char* name = pc.getString("name",0,true) ;
485 const char* title = pc.getString("title",0,true) ;
486
487 // Make sure varSubset doesn't contain any variable not in this dataset
488 RooArgSet varSubset ;
489 if (varSet) {
490 varSubset.add(*varSet) ;
491 for (const auto arg : varSubset) {
492 if (!_vars.find(arg->GetName())) {
493 coutW(InputArguments) << "RooAbsData::reduce(" << GetName() << ") WARNING: variable "
494 << arg->GetName() << " not in dataset, ignored" << endl ;
495 varSubset.remove(*arg) ;
496 }
497 }
498 } else {
499 varSubset.add(*get()) ;
500 }
501
502 RooAbsData* ret = 0 ;
503 if (cutSpec) {
504
505 RooFormulaVar cutVarTmp(cutSpec,cutSpec,*get()) ;
506 ret = reduceEng(varSubset,&cutVarTmp,cutRange,nStart,nStop) ;
507
508 } else if (cutVar) {
509
510 ret = reduceEng(varSubset,cutVar,cutRange,nStart,nStop) ;
511
512 } else {
513
514 ret = reduceEng(varSubset,0,cutRange,nStart,nStop) ;
515
516 }
517
518 if (!ret) return nullptr;
519
520 if (name) ret->SetName(name) ;
521 if (title) ret->SetTitle(title) ;
522
523 ret->copyGlobalObservables(*this);
524 return ret ;
525}
526
527////////////////////////////////////////////////////////////////////////////////
528/// Create a subset of the data set by applying the given cut on the data points.
529/// The cut expression can refer to any variable in the data set. For cuts involving
530/// other variables, such as intermediate formula objects, use the equivalent
531/// reduce method specifying the as a RooFormulVar reference.
532
534{
535 RooFormulaVar cutVar(cut,cut,*get()) ;
536 RooAbsData* ret = reduceEng(*get(),&cutVar,0,0,std::numeric_limits<std::size_t>::max()) ;
537 ret->copyGlobalObservables(*this);
538 return ret;
539}
540
541////////////////////////////////////////////////////////////////////////////////
542/// Create a subset of the data set by applying the given cut on the data points.
543/// The 'cutVar' formula variable is used to select the subset of data points to be
544/// retained in the reduced data collection.
545
547{
548 RooAbsData* ret = reduceEng(*get(),&cutVar,0,0,std::numeric_limits<std::size_t>::max()) ;
549 ret->copyGlobalObservables(*this);
550 return ret;
551}
552
553////////////////////////////////////////////////////////////////////////////////
554/// Create a subset of the data set by applying the given cut on the data points
555/// and reducing the dimensions to the specified set.
556///
557/// The cut expression can refer to any variable in the data set. For cuts involving
558/// other variables, such as intermediate formula objects, use the equivalent
559/// reduce method specifying the as a RooFormulVar reference.
560
561RooAbsData* RooAbsData::reduce(const RooArgSet& varSubset, const char* cut)
562{
563 // Make sure varSubset doesn't contain any variable not in this dataset
564 RooArgSet varSubset2(varSubset) ;
565 for (const auto arg : varSubset) {
566 if (!_vars.find(arg->GetName())) {
567 coutW(InputArguments) << "RooAbsData::reduce(" << GetName() << ") WARNING: variable "
568 << arg->GetName() << " not in dataset, ignored" << endl ;
569 varSubset2.remove(*arg) ;
570 }
571 }
572
573 RooAbsData* ret = nullptr;
574 if (cut && strlen(cut)>0) {
575 RooFormulaVar cutVar(cut, cut, *get(), false);
576 ret = reduceEng(varSubset2,&cutVar,0,0,std::numeric_limits<std::size_t>::max());
577 } else {
578 ret = reduceEng(varSubset2,0,0,0,std::numeric_limits<std::size_t>::max());
579 }
580 ret->copyGlobalObservables(*this);
581 return ret;
582}
583
584////////////////////////////////////////////////////////////////////////////////
585/// Create a subset of the data set by applying the given cut on the data points
586/// and reducing the dimensions to the specified set.
587///
588/// The 'cutVar' formula variable is used to select the subset of data points to be
589/// retained in the reduced data collection.
590
591RooAbsData* RooAbsData::reduce(const RooArgSet& varSubset, const RooFormulaVar& cutVar)
592{
593 // Make sure varSubset doesn't contain any variable not in this dataset
594 RooArgSet varSubset2(varSubset) ;
595 for(RooAbsArg * arg : varSubset) {
596 if (!_vars.find(arg->GetName())) {
597 coutW(InputArguments) << "RooAbsData::reduce(" << GetName() << ") WARNING: variable "
598 << arg->GetName() << " not in dataset, ignored" << endl ;
599 varSubset2.remove(*arg) ;
600 }
601 }
602
603 RooAbsData* ret = reduceEng(varSubset2,&cutVar,0,0,std::numeric_limits<std::size_t>::max()) ;
604 ret->copyGlobalObservables(*this);
605 return ret;
606}
607
608
609RooPlot* RooAbsData::plotOn(RooPlot* frame, const RooCmdArg& arg1, const RooCmdArg& arg2,
610 const RooCmdArg& arg3, const RooCmdArg& arg4, const RooCmdArg& arg5,
611 const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8) const
612{
614 l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
615 l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
616 l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
617 l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
618 return plotOn(frame,l) ;
619}
620
621////////////////////////////////////////////////////////////////////////////////
622/// Create and fill a ROOT histogram TH1,TH2 or TH3 with the values of this dataset for the variables with given names
623/// The range of each observable that is histogrammed is always automatically calculated from the distribution in
624/// the dataset. The number of bins can be controlled using the [xyz]bins parameters. For a greater degree of control
625/// use the createHistogram() method below with named arguments
626///
627/// The caller takes ownership of the returned histogram
628
629TH1 *RooAbsData::createHistogram(const char* varNameList, Int_t xbins, Int_t ybins, Int_t zbins) const
630{
631 coutW(DataHandling) << "'RooAbsData::createHistogram' is deprecated and will be removed in ROOT v6.30: "
632 << "Use the overload of 'RooAbsData::createHistogram' that takes RooFit command arguments."
633 << std::endl;
634
635 // Parse list of variable names
636 const auto varNames = ROOT::Split(varNameList, ",:");
637 RooLinkedList argList;
638 RooRealVar* vars[3] = {nullptr, nullptr, nullptr};
639
640 for (unsigned int i = 0; i < varNames.size(); ++i) {
641 if (i >= 3) {
642 coutW(InputArguments) << "RooAbsData::createHistogram(" << GetName() << "): Can only create 3-dimensional histograms. Variable "
643 << i << " " << varNames[i] << " unused." << std::endl;
644 continue;
645 }
646
647 vars[i] = static_cast<RooRealVar*>( get()->find(varNames[i].data()) );
648 if (!vars[i]) {
649 coutE(InputArguments) << "RooAbsData::createHistogram(" << GetName() << ") ERROR: dataset does not contain an observable named " << varNames[i] << std::endl;
650 return nullptr;
651 }
652 }
653
654 if (!vars[0]) {
655 coutE(InputArguments) << "RooAbsData::createHistogram(" << GetName() << "): No variable to be histogrammed in list '" << varNameList << "'" << std::endl;
656 return nullptr;
657 }
658
659 if (xbins<=0 || !vars[0]->hasMax() || !vars[0]->hasMin() ) {
660 argList.Add(RooFit::AutoBinning(xbins==0?vars[0]->numBins():abs(xbins)).Clone()) ;
661 } else {
662 argList.Add(RooFit::Binning(xbins).Clone()) ;
663 }
664
665 if (vars[1]) {
666 if (ybins<=0 || !vars[1]->hasMax() || !vars[1]->hasMin() ) {
667 argList.Add(RooFit::YVar(*vars[1],RooFit::AutoBinning(ybins==0?vars[1]->numBins():abs(ybins))).Clone()) ;
668 } else {
669 argList.Add(RooFit::YVar(*vars[1],RooFit::Binning(ybins)).Clone()) ;
670 }
671 }
672 if (vars[2]) {
673 if (zbins<=0 || !vars[2]->hasMax() || !vars[2]->hasMin() ) {
674 argList.Add(RooFit::ZVar(*vars[2],RooFit::AutoBinning(zbins==0?vars[2]->numBins():abs(zbins))).Clone()) ;
675 } else {
676 argList.Add(RooFit::ZVar(*vars[2],RooFit::Binning(zbins)).Clone()) ;
677 }
678 }
679
680
681 // Call implementation function
682 TH1* result = createHistogram(GetName(), *vars[0], argList);
683
684 // Delete temporary list of RooCmdArgs
685 argList.Delete() ;
686
687 return result ;
688}
689
690
692 const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
693 const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8) const
694{
696 l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
697 l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
698 l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
699 l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
700
701 return createHistogram(name,xvar,l) ;
702}
703
704////////////////////////////////////////////////////////////////////////////////
705/// Create and fill a ROOT histogram TH1,TH2 or TH3 with the values of this
706/// dataset for the variables with given names.
707///
708/// \param[in] varNameList Comma-separated variable names.
709/// \param[in] binArgX Control the binning for the `x` variable.
710/// \param[in] binArgY Control the binning for the `y` variable.
711/// \param[in] binArgZ Control the binning for the `z` variable.
712/// \return Histogram now owned by user.
713///
714/// The possible binning command arguments for each axis are:
715///
716/// <table>
717/// <tr><td> `AutoBinning(Int_t nbins, Double_y margin)` <td> Automatically calculate range with given added fractional margin, set binning to nbins
718/// <tr><td> `AutoSymBinning(Int_t nbins, Double_y margin)` <td> Automatically calculate range with given added fractional margin,
719/// with additional constraint that mean of data is in center of range, set binning to nbins
720/// <tr><td> `Binning(const char* name)` <td> Apply binning with given name to x axis of histogram
721/// <tr><td> `Binning(RooAbsBinning& binning)` <td> Apply specified binning to x axis of histogram
722/// <tr><td> `Binning(int nbins, double lo, double hi)` <td> Apply specified binning to x axis of histogram
723///
724/// <tr><td> `YVar(const RooAbsRealLValue& var,...)` <td> Observable to be mapped on y axis of ROOT histogram
725/// <tr><td> `ZVar(const RooAbsRealLValue& var,...)` <td> Observable to be mapped on z axis of ROOT histogram
726/// </table>
727
728TH1 *RooAbsData::createHistogram(const char* varNameList,
729 const RooCmdArg& binArgX,
730 const RooCmdArg& binArgY,
731 const RooCmdArg& binArgZ) const
732{
733 // Parse list of variable names
734 const auto varNames = ROOT::Split(varNameList, ",:");
735 RooRealVar* vars[3] = {nullptr, nullptr, nullptr};
736
737 for (unsigned int i = 0; i < varNames.size(); ++i) {
738 if (i >= 3) {
739 coutW(InputArguments) << "RooAbsData::createHistogram(" << GetName() << "): Can only create 3-dimensional histograms. Variable "
740 << i << " " << varNames[i] << " unused." << std::endl;
741 continue;
742 }
743
744 vars[i] = static_cast<RooRealVar*>( get()->find(varNames[i].data()) );
745 if (!vars[i]) {
746 coutE(InputArguments) << "RooAbsData::createHistogram(" << GetName() << ") ERROR: dataset does not contain an observable named " << varNames[i] << std::endl;
747 return nullptr;
748 }
749 }
750
751 if (!vars[0]) {
752 coutE(InputArguments) << "RooAbsData::createHistogram(" << GetName() << "): No variable to be histogrammed in list '" << varNameList << "'" << std::endl;
753 return nullptr;
754 }
755
756 // Fill command argument list
757 RooLinkedList argList;
758 argList.Add(binArgX.Clone());
759 if (vars[1]) {
760 argList.Add(RooFit::YVar(*vars[1],binArgY).Clone());
761 }
762 if (vars[2]) {
763 argList.Add(RooFit::ZVar(*vars[2],binArgZ).Clone());
764 }
765
766 // Call implementation function
767 TH1* result = createHistogram(GetName(), *vars[0], argList);
768
769 // Delete temporary list of RooCmdArgs
770 argList.Delete() ;
771
772 return result ;
773}
774
775////////////////////////////////////////////////////////////////////////////////
776///
777/// This function accepts the following arguments
778///
779/// \param[in] name Name of the ROOT histogram
780/// \param[in] xvar Observable to be mapped on x axis of ROOT histogram
781/// \param[in] argListIn list of input arguments
782/// \return Histogram now owned by user.
783///
784/// <table>
785/// <tr><td> `AutoBinning(Int_t nbins, Double_y margin)` <td> Automatically calculate range with given added fractional margin, set binning to nbins
786/// <tr><td> `AutoSymBinning(Int_t nbins, Double_y margin)` <td> Automatically calculate range with given added fractional margin,
787/// with additional constraint that mean of data is in center of range, set binning to nbins
788/// <tr><td> `Binning(const char* name)` <td> Apply binning with given name to x axis of histogram
789/// <tr><td> `Binning(RooAbsBinning& binning)` <td> Apply specified binning to x axis of histogram
790/// <tr><td> `Binning(int nbins, double lo, double hi)` <td> Apply specified binning to x axis of histogram
791///
792/// <tr><td> `YVar(const RooAbsRealLValue& var,...)` <td> Observable to be mapped on y axis of ROOT histogram
793/// <tr><td> `ZVar(const RooAbsRealLValue& var,...)` <td> Observable to be mapped on z axis of ROOT histogram
794/// </table>
795///
796/// The YVar() and ZVar() arguments can be supplied with optional Binning() Auto(Sym)Range() arguments to control the binning of the Y and Z axes, e.g.
797/// ```
798/// createHistogram("histo",x,Binning(-1,1,20), YVar(y,Binning(-1,1,30)), ZVar(z,Binning("zbinning")))
799/// ```
800///
801/// The caller takes ownership of the returned histogram
802
803TH1 *RooAbsData::createHistogram(const char *name, const RooAbsRealLValue& xvar, const RooLinkedList& argListIn) const
804{
805 RooLinkedList argList(argListIn) ;
806
807 // Define configuration for this method
808 RooCmdConfig pc(Form("RooAbsData::createHistogram(%s)",GetName())) ;
809 pc.defineString("cutRange","CutRange",0,"",true) ;
810 pc.defineString("cutString","CutSpec",0,"") ;
811 pc.defineObject("yvar","YVar",0,0) ;
812 pc.defineObject("zvar","ZVar",0,0) ;
813 pc.allowUndefined() ;
814
815 // Process & check varargs
816 pc.process(argList) ;
817 if (!pc.ok(true)) {
818 return 0 ;
819 }
820
821 const char* cutSpec = pc.getString("cutString",0,true) ;
822 const char* cutRange = pc.getString("cutRange",0,true) ;
823
824 RooArgList vars(xvar) ;
825 RooAbsArg* yvar = static_cast<RooAbsArg*>(pc.getObject("yvar")) ;
826 if (yvar) {
827 vars.add(*yvar) ;
828 }
829 RooAbsArg* zvar = static_cast<RooAbsArg*>(pc.getObject("zvar")) ;
830 if (zvar) {
831 vars.add(*zvar) ;
832 }
833
834 pc.stripCmdList(argList,"CutRange,CutSpec") ;
835
836 // Swap Auto(Sym)RangeData with a Binning command
837 RooLinkedList ownedCmds ;
838 RooCmdArg* autoRD = (RooCmdArg*) argList.find("AutoRangeData") ;
839 if (autoRD) {
840 double xmin,xmax ;
841 if (!getRange((RooRealVar&)xvar,xmin,xmax,autoRD->getDouble(0),autoRD->getInt(0))) {
842 RooCmdArg* bincmd = (RooCmdArg*) RooFit::Binning(autoRD->getInt(1),xmin,xmax).Clone() ;
843 ownedCmds.Add(bincmd) ;
844 argList.Replace(autoRD,bincmd) ;
845 }
846 }
847
848 if (yvar) {
849 RooCmdArg* autoRDY = (RooCmdArg*) ((RooCmdArg*)argList.find("YVar"))->subArgs().find("AutoRangeData") ;
850 if (autoRDY) {
851 double ymin,ymax ;
852 if (!getRange((RooRealVar&)(*yvar),ymin,ymax,autoRDY->getDouble(0),autoRDY->getInt(0))) {
853 RooCmdArg* bincmd = (RooCmdArg*) RooFit::Binning(autoRDY->getInt(1),ymin,ymax).Clone() ;
854 //ownedCmds.Add(bincmd) ;
855 ((RooCmdArg*)argList.find("YVar"))->subArgs().Replace(autoRDY,bincmd) ;
856 }
857 delete autoRDY ;
858 }
859 }
860
861 if (zvar) {
862 RooCmdArg* autoRDZ = (RooCmdArg*) ((RooCmdArg*)argList.find("ZVar"))->subArgs().find("AutoRangeData") ;
863 if (autoRDZ) {
864 double zmin,zmax ;
865 if (!getRange((RooRealVar&)(*zvar),zmin,zmax,autoRDZ->getDouble(0),autoRDZ->getInt(0))) {
866 RooCmdArg* bincmd = (RooCmdArg*) RooFit::Binning(autoRDZ->getInt(1),zmin,zmax).Clone() ;
867 //ownedCmds.Add(bincmd) ;
868 ((RooCmdArg*)argList.find("ZVar"))->subArgs().Replace(autoRDZ,bincmd) ;
869 }
870 delete autoRDZ ;
871 }
872 }
873
874
875 TH1* histo = xvar.createHistogram(name,argList) ;
876 fillHistogram(histo,vars,cutSpec,cutRange) ;
877
878 ownedCmds.Delete() ;
879
880 return histo ;
881}
882
883////////////////////////////////////////////////////////////////////////////////
884/// Construct table for product of categories in catSet
885
886Roo1DTable* RooAbsData::table(const RooArgSet& catSet, const char* cuts, const char* opts) const
887{
888 RooArgSet catSet2 ;
889
890 string prodName("(") ;
891 TIterator* iter = catSet.createIterator() ;
892 RooAbsArg* arg ;
893 while((arg=(RooAbsArg*)iter->Next())) {
894 if (dynamic_cast<RooAbsCategory*>(arg)) {
895 RooAbsCategory* varsArg = dynamic_cast<RooAbsCategory*>(_vars.find(arg->GetName())) ;
896 if (varsArg != 0) catSet2.add(*varsArg) ;
897 else catSet2.add(*arg) ;
898 if (prodName.length()>1) {
899 prodName += " x " ;
900 }
901 prodName += arg->GetName() ;
902 } else {
903 coutW(InputArguments) << "RooAbsData::table(" << GetName() << ") non-RooAbsCategory input argument " << arg->GetName() << " ignored" << endl ;
904 }
905 }
906 prodName += ")" ;
907 delete iter ;
908
909 RooMultiCategory tmp(prodName.c_str(),prodName.c_str(),catSet2) ;
910 return table(tmp,cuts,opts) ;
911}
912
913////////////////////////////////////////////////////////////////////////////////
914/// Print name of dataset
915
916void RooAbsData::printName(ostream& os) const
917{
918 os << GetName() ;
919}
920
921////////////////////////////////////////////////////////////////////////////////
922/// Print title of dataset
923
924void RooAbsData::printTitle(ostream& os) const
925{
926 os << GetTitle() ;
927}
928
929////////////////////////////////////////////////////////////////////////////////
930/// Print class name of dataset
931
932void RooAbsData::printClassName(ostream& os) const
933{
934 os << IsA()->GetName() ;
935}
936
937////////////////////////////////////////////////////////////////////////////////
938
939void RooAbsData::printMultiline(ostream& os, Int_t contents, bool verbose, TString indent) const
940{
941 _dstore->printMultiline(os,contents,verbose,indent) ;
942}
943
944////////////////////////////////////////////////////////////////////////////////
945/// Define default print options, for a given print style
946
948{
950}
951
952////////////////////////////////////////////////////////////////////////////////
953/// Calculate standardized moment.
954///
955/// \param[in] var Variable to be used for calculating the moment.
956/// \param[in] order Order of the moment.
957/// \param[in] cutSpec If specified, the moment is calculated on the subset of the data which pass the C++ cut specification expression 'cutSpec'
958/// \param[in] cutRange If specified, calculate inside the range named 'cutRange' (also applies cut spec)
959/// \return \f$ \frac{\left< \left( X - \left< X \right> \right)^n \right>}{\sigma^n} \f$, where n = order.
960
961double RooAbsData::standMoment(const RooRealVar &var, double order, const char* cutSpec, const char* cutRange) const
962{
963 // Hardwire invariant answer for first and second moment
964 if (order==1) return 0 ;
965 if (order==2) return 1 ;
966
967 return moment(var,order,cutSpec,cutRange) / TMath::Power(sigma(var,cutSpec,cutRange),order) ;
968}
969
970////////////////////////////////////////////////////////////////////////////////
971/// Calculate moment of requested order.
972///
973/// \param[in] var Variable to be used for calculating the moment.
974/// \param[in] order Order of the moment.
975/// \param[in] cutSpec If specified, the moment is calculated on the subset of the data which pass the C++ cut specification expression 'cutSpec'
976/// \param[in] cutRange If specified, calculate inside the range named 'cutRange' (also applies cut spec)
977/// \return \f$ \left< \left( X - \left< X \right> \right)^n \right> \f$ of order \f$n\f$.
978///
979
980double RooAbsData::moment(const RooRealVar& var, double order, const char* cutSpec, const char* cutRange) const
981{
982 double offset = order>1 ? moment(var,1,cutSpec,cutRange) : 0 ;
983 return moment(var,order,offset,cutSpec,cutRange) ;
984
985}
986
987////////////////////////////////////////////////////////////////////////////////
988/// Return the 'order'-ed moment of observable 'var' in this dataset. If offset is non-zero it is subtracted
989/// from the values of 'var' prior to the moment calculation. If cutSpec and/or cutRange are specified
990/// the moment is calculated on the subset of the data which pass the C++ cut specification expression 'cutSpec'
991/// and/or are inside the range named 'cutRange'
992
993double RooAbsData::moment(const RooRealVar& var, double order, double offset, const char* cutSpec, const char* cutRange) const
994{
995 // Lookup variable in dataset
996 auto arg = _vars.find(var.GetName());
997 if (!arg) {
998 coutE(InputArguments) << "RooDataSet::moment(" << GetName() << ") ERROR: unknown variable: " << var.GetName() << endl ;
999 return 0;
1000 }
1001
1002 auto varPtr = dynamic_cast<const RooRealVar*>(arg);
1003 // Check if found variable is of type RooRealVar
1004 if (!varPtr) {
1005 coutE(InputArguments) << "RooDataSet::moment(" << GetName() << ") ERROR: variable " << var.GetName() << " is not of type RooRealVar" << endl ;
1006 return 0;
1007 }
1008
1009 // Check if dataset is not empty
1010 if(sumEntries(cutSpec, cutRange) == 0.) {
1011 coutE(InputArguments) << "RooDataSet::moment(" << GetName() << ") WARNING: empty dataset" << endl ;
1012 return 0;
1013 }
1014
1015 // Setup RooFormulaVar for cutSpec if it is present
1016 std::unique_ptr<RooFormula> select;
1017 if (cutSpec) {
1018 select.reset(new RooFormula("select",cutSpec,*get()));
1019 }
1020
1021
1022 // Calculate requested moment
1024 for(Int_t index= 0; index < numEntries(); index++) {
1025 const RooArgSet* vars = get(index) ;
1026 if (select && select->eval()==0) continue ;
1027 if (cutRange && vars->allInRange(cutRange)) continue ;
1028
1029 sum += weight() * TMath::Power(varPtr->getVal() - offset,order);
1030 }
1031
1032 return sum/sumEntries(cutSpec, cutRange);
1033}
1034
1035////////////////////////////////////////////////////////////////////////////////
1036/// Internal method to check if given RooRealVar maps to a RooRealVar in this dataset
1037
1038RooRealVar* RooAbsData::dataRealVar(const char* methodname, const RooRealVar& extVar) const
1039{
1040 // Lookup variable in dataset
1041 RooRealVar *xdata = (RooRealVar*) _vars.find(extVar.GetName());
1042 if(!xdata) {
1043 coutE(InputArguments) << "RooDataSet::" << methodname << "(" << GetName() << ") ERROR: variable : " << extVar.GetName() << " is not in data" << endl ;
1044 return 0;
1045 }
1046 // Check if found variable is of type RooRealVar
1047 if (!dynamic_cast<RooRealVar*>(xdata)) {
1048 coutE(InputArguments) << "RooDataSet::" << methodname << "(" << GetName() << ") ERROR: variable : " << extVar.GetName() << " is not of type RooRealVar in data" << endl ;
1049 return 0;
1050 }
1051 return xdata;
1052}
1053
1054////////////////////////////////////////////////////////////////////////////////
1055/// Internal method to calculate single correlation and covariance elements
1056
1057double RooAbsData::corrcov(const RooRealVar &x, const RooRealVar &y, const char* cutSpec, const char* cutRange, bool corr) const
1058{
1059 // Lookup variable in dataset
1060 RooRealVar *xdata = dataRealVar(corr?"correlation":"covariance",x) ;
1061 RooRealVar *ydata = dataRealVar(corr?"correlation":"covariance",y) ;
1062 if (!xdata||!ydata) return 0 ;
1063
1064 // Check if dataset is not empty
1065 if(sumEntries(cutSpec, cutRange) == 0.) {
1066 coutW(InputArguments) << "RooDataSet::" << (corr?"correlation":"covariance") << "(" << GetName() << ") WARNING: empty dataset, returning zero" << endl ;
1067 return 0;
1068 }
1069
1070 // Setup RooFormulaVar for cutSpec if it is present
1071 RooFormula* select = cutSpec ? new RooFormula("select",cutSpec,*get()) : 0 ;
1072
1073 // Calculate requested moment
1074 double xysum(0),xsum(0),ysum(0),x2sum(0),y2sum(0);
1075 const RooArgSet* vars ;
1076 for(Int_t index= 0; index < numEntries(); index++) {
1077 vars = get(index) ;
1078 if (select && select->eval()==0) continue ;
1079 if (cutRange && vars->allInRange(cutRange)) continue ;
1080
1081 xysum += weight()*xdata->getVal()*ydata->getVal() ;
1082 xsum += weight()*xdata->getVal() ;
1083 ysum += weight()*ydata->getVal() ;
1084 if (corr) {
1085 x2sum += weight()*xdata->getVal()*xdata->getVal() ;
1086 y2sum += weight()*ydata->getVal()*ydata->getVal() ;
1087 }
1088 }
1089
1090 // Normalize entries
1091 xysum/=sumEntries(cutSpec, cutRange) ;
1092 xsum/=sumEntries(cutSpec, cutRange) ;
1093 ysum/=sumEntries(cutSpec, cutRange) ;
1094 if (corr) {
1095 x2sum/=sumEntries(cutSpec, cutRange) ;
1096 y2sum/=sumEntries(cutSpec, cutRange) ;
1097 }
1098
1099 // Cleanup
1100 if (select) delete select ;
1101
1102 // Return covariance or correlation as requested
1103 if (corr) {
1104 return (xysum-xsum*ysum)/(sqrt(x2sum-(xsum*xsum))*sqrt(y2sum-(ysum*ysum))) ;
1105 } else {
1106 return (xysum-xsum*ysum);
1107 }
1108}
1109
1110////////////////////////////////////////////////////////////////////////////////
1111/// Return covariance matrix from data for given list of observables
1112
1113TMatrixDSym* RooAbsData::corrcovMatrix(const RooArgList& vars, const char* cutSpec, const char* cutRange, bool corr) const
1114{
1115 RooArgList varList ;
1116 TIterator* iter = vars.createIterator() ;
1117 RooRealVar* var ;
1118 while((var=(RooRealVar*)iter->Next())) {
1119 RooRealVar* datavar = dataRealVar("covarianceMatrix",*var) ;
1120 if (!datavar) {
1121 delete iter ;
1122 return 0 ;
1123 }
1124 varList.add(*datavar) ;
1125 }
1126 delete iter ;
1127
1128
1129 // Check if dataset is not empty
1130 if(sumEntries(cutSpec, cutRange) == 0.) {
1131 coutW(InputArguments) << "RooDataSet::covariance(" << GetName() << ") WARNING: empty dataset, returning zero" << endl ;
1132 return 0;
1133 }
1134
1135 // Setup RooFormulaVar for cutSpec if it is present
1136 RooFormula* select = cutSpec ? new RooFormula("select",cutSpec,*get()) : 0 ;
1137
1138 iter = varList.createIterator() ;
1139 TIterator* iter2 = varList.createIterator() ;
1140
1141 TMatrixDSym xysum(varList.getSize()) ;
1142 vector<double> xsum(varList.getSize()) ;
1143 vector<double> x2sum(varList.getSize()) ;
1144
1145 // Calculate <x_i> and <x_i y_j>
1146 for(Int_t index= 0; index < numEntries(); index++) {
1147 const RooArgSet* dvars = get(index) ;
1148 if (select && select->eval()==0) continue ;
1149 if (cutRange && dvars->allInRange(cutRange)) continue ;
1150
1151 RooRealVar* varx, *vary ;
1152 iter->Reset() ;
1153 Int_t ix=0,iy=0 ;
1154 while((varx=(RooRealVar*)iter->Next())) {
1155 xsum[ix] += weight()*varx->getVal() ;
1156 if (corr) {
1157 x2sum[ix] += weight()*varx->getVal()*varx->getVal() ;
1158 }
1159
1160 *iter2=*iter ; iy=ix ;
1161 vary=varx ;
1162 while(vary) {
1163 xysum(ix,iy) += weight()*varx->getVal()*vary->getVal() ;
1164 xysum(iy,ix) = xysum(ix,iy) ;
1165 iy++ ;
1166 vary=(RooRealVar*)iter2->Next() ;
1167 }
1168 ix++ ;
1169 }
1170
1171 }
1172
1173 // Normalize sums
1174 for (Int_t ix=0 ; ix<varList.getSize() ; ix++) {
1175 xsum[ix] /= sumEntries(cutSpec, cutRange) ;
1176 if (corr) {
1177 x2sum[ix] /= sumEntries(cutSpec, cutRange) ;
1178 }
1179 for (Int_t iy=0 ; iy<varList.getSize() ; iy++) {
1180 xysum(ix,iy) /= sumEntries(cutSpec, cutRange) ;
1181 }
1182 }
1183
1184 // Calculate covariance matrix
1185 TMatrixDSym* C = new TMatrixDSym(varList.getSize()) ;
1186 for (Int_t ix=0 ; ix<varList.getSize() ; ix++) {
1187 for (Int_t iy=0 ; iy<varList.getSize() ; iy++) {
1188 (*C)(ix,iy) = xysum(ix,iy)-xsum[ix]*xsum[iy] ;
1189 if (corr) {
1190 (*C)(ix,iy) /= sqrt((x2sum[ix]-(xsum[ix]*xsum[ix]))*(x2sum[iy]-(xsum[iy]*xsum[iy]))) ;
1191 }
1192 }
1193 }
1194
1195 if (select) delete select ;
1196 delete iter ;
1197 delete iter2 ;
1198
1199 return C ;
1200}
1201
1202////////////////////////////////////////////////////////////////////////////////
1203/// Create a RooRealVar containing the mean of observable 'var' in
1204/// this dataset. If cutSpec and/or cutRange are specified the
1205/// moment is calculated on the subset of the data which pass the C++
1206/// cut specification expression 'cutSpec' and/or are inside the
1207/// range named 'cutRange'
1208
1209RooRealVar* RooAbsData::meanVar(const RooRealVar &var, const char* cutSpec, const char* cutRange) const
1210{
1211 // Create a new variable with appropriate strings. The error is calculated as
1212 // RMS/Sqrt(N) which is generally valid.
1213
1214 // Create holder variable for mean
1215 TString name(var.GetName()),title("Mean of ") ;
1216 name.Append("Mean");
1217 title.Append(var.GetTitle());
1218 RooRealVar *meanv= new RooRealVar(name,title,0) ;
1219 meanv->setConstant(false) ;
1220
1221 // Adjust plot label
1222 TString label("<") ;
1223 label.Append(var.getPlotLabel());
1224 label.Append(">");
1225 meanv->setPlotLabel(label.Data());
1226
1227 // fill in this variable's value and error
1228 double meanVal=moment(var,1,0,cutSpec,cutRange) ;
1229 double N(sumEntries(cutSpec,cutRange)) ;
1230
1231 double rmsVal= sqrt(moment(var,2,meanVal,cutSpec,cutRange)*N/(N-1));
1232 meanv->setVal(meanVal) ;
1233 meanv->setError(N > 0 ? rmsVal/sqrt(N) : 0);
1234
1235 return meanv;
1236}
1237
1238////////////////////////////////////////////////////////////////////////////////
1239/// Create a RooRealVar containing the RMS of observable 'var' in
1240/// this dataset. If cutSpec and/or cutRange are specified the
1241/// moment is calculated on the subset of the data which pass the C++
1242/// cut specification expression 'cutSpec' and/or are inside the
1243/// range named 'cutRange'
1244
1245RooRealVar* RooAbsData::rmsVar(const RooRealVar &var, const char* cutSpec, const char* cutRange) const
1246{
1247 // Create a new variable with appropriate strings. The error is calculated as
1248 // RMS/(2*Sqrt(N)) which is only valid if the variable has a Gaussian distribution.
1249
1250 // Create RMS value holder
1251 TString name(var.GetName()),title("RMS of ") ;
1252 name.Append("RMS");
1253 title.Append(var.GetTitle());
1254 RooRealVar *rms= new RooRealVar(name,title,0) ;
1255 rms->setConstant(false) ;
1256
1257 // Adjust plot label
1258 TString label(var.getPlotLabel());
1259 label.Append("_{RMS}");
1260 rms->setPlotLabel(label);
1261
1262 // Fill in this variable's value and error
1263 double meanVal(moment(var,1,0,cutSpec,cutRange)) ;
1264 double N(sumEntries(cutSpec, cutRange));
1265 double rmsVal= sqrt(moment(var,2,meanVal,cutSpec,cutRange)*N/(N-1));
1266 rms->setVal(rmsVal) ;
1267 rms->setError(rmsVal/sqrt(2*N));
1268
1269 return rms;
1270}
1271
1272////////////////////////////////////////////////////////////////////////////////
1273/// Add a box with statistics information to the specified frame. By default a box with the
1274/// event count, mean and rms of the plotted variable is added.
1275///
1276/// The following optional named arguments are accepted
1277/// <table>
1278/// <tr><td> `What(const char* whatstr)` <td> Controls what is printed: "N" = count, "M" is mean, "R" is RMS.
1279/// <tr><td> `Format(const char* optStr)` <td> \deprecated Classing parameter formatting options, provided for backward compatibility
1280///
1281/// <tr><td> `Format(const char* what,...)` <td> Parameter formatting options.
1282/// <table>
1283/// <tr><td> const char* what <td> Controls what is shown:
1284/// - "N" adds name
1285/// - "E" adds error
1286/// - "A" shows asymmetric error
1287/// - "U" shows unit
1288/// - "H" hides the value
1289/// <tr><td> `FixedPrecision(int n)` <td> Controls precision, set fixed number of digits
1290/// <tr><td> `AutoPrecision(int n)` <td> Controls precision. Number of shown digits is calculated from error + n specified additional digits (1 is sensible default)
1291/// <tr><td> `VerbatimName(bool flag)` <td> Put variable name in a \\verb+ + clause.
1292/// </table>
1293/// <tr><td> `Label(const chat* label)` <td> Add header label to parameter box
1294/// <tr><td> `Layout(double xmin, double xmax, double ymax)` <td> Specify relative position of left,right side of box and top of box. Position of
1295/// bottom of box is calculated automatically from number lines in box
1296/// <tr><td> `Cut(const char* expression)` <td> Apply given cut expression to data when calculating statistics
1297/// <tr><td> `CutRange(const char* rangeName)` <td> Only consider events within given range when calculating statistics. Multiple
1298/// CutRange() argument may be specified to combine ranges.
1299///
1300/// </table>
1301
1302RooPlot* RooAbsData::statOn(RooPlot* frame, const RooCmdArg& arg1, const RooCmdArg& arg2,
1303 const RooCmdArg& arg3, const RooCmdArg& arg4, const RooCmdArg& arg5,
1304 const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
1305{
1306 // Stuff all arguments in a list
1307 RooLinkedList cmdList;
1308 cmdList.Add(const_cast<RooCmdArg*>(&arg1)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg2)) ;
1309 cmdList.Add(const_cast<RooCmdArg*>(&arg3)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg4)) ;
1310 cmdList.Add(const_cast<RooCmdArg*>(&arg5)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg6)) ;
1311 cmdList.Add(const_cast<RooCmdArg*>(&arg7)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg8)) ;
1312
1313 // Select the pdf-specific commands
1314 RooCmdConfig pc(Form("RooTreeData::statOn(%s)",GetName())) ;
1315 pc.defineString("what","What",0,"MNR") ;
1316 pc.defineString("label","Label",0,"") ;
1317 pc.defineDouble("xmin","Layout",0,0.65) ;
1318 pc.defineDouble("xmax","Layout",1,0.99) ;
1319 pc.defineInt("ymaxi","Layout",0,Int_t(0.95*10000)) ;
1320 pc.defineString("formatStr","Format",0,"NELU") ;
1321 pc.defineInt("sigDigit","Format",0,2) ;
1322 pc.defineInt("dummy","FormatArgs",0,0) ;
1323 pc.defineString("cutRange","CutRange",0,"",true) ;
1324 pc.defineString("cutString","CutSpec",0,"") ;
1325 pc.defineMutex("Format","FormatArgs") ;
1326
1327 // Process and check varargs
1328 pc.process(cmdList) ;
1329 if (!pc.ok(true)) {
1330 return frame ;
1331 }
1332
1333 const char* label = pc.getString("label") ;
1334 double xmin = pc.getDouble("xmin") ;
1335 double xmax = pc.getDouble("xmax") ;
1336 double ymax = pc.getInt("ymaxi") / 10000. ;
1337 const char* formatStr = pc.getString("formatStr") ;
1338 Int_t sigDigit = pc.getInt("sigDigit") ;
1339 const char* what = pc.getString("what") ;
1340
1341 const char* cutSpec = pc.getString("cutString",0,true) ;
1342 const char* cutRange = pc.getString("cutRange",0,true) ;
1343
1344 if (pc.hasProcessed("FormatArgs")) {
1345 RooCmdArg* formatCmd = static_cast<RooCmdArg*>(cmdList.FindObject("FormatArgs")) ;
1346 return statOn(frame,what,label,0,0,xmin,xmax,ymax,cutSpec,cutRange,formatCmd) ;
1347 } else {
1348 return statOn(frame,what,label,sigDigit,formatStr,xmin,xmax,ymax,cutSpec,cutRange) ;
1349 }
1350}
1351
1352////////////////////////////////////////////////////////////////////////////////
1353/// Implementation back-end of statOn() method with named arguments
1354
1355RooPlot* RooAbsData::statOn(RooPlot* frame, const char* what, const char *label, Int_t sigDigits,
1356 Option_t *options, double xmin, double xmax, double ymax,
1357 const char* cutSpec, const char* cutRange, const RooCmdArg* formatCmd)
1358{
1359 bool showLabel= (label != 0 && strlen(label) > 0);
1360
1361 TString whatStr(what) ;
1362 whatStr.ToUpper() ;
1363 bool showN = whatStr.Contains("N") ;
1364 bool showR = whatStr.Contains("R") ;
1365 bool showM = whatStr.Contains("M") ;
1366 Int_t nPar= 0;
1367 if (showN) nPar++ ;
1368 if (showR) nPar++ ;
1369 if (showM) nPar++ ;
1370
1371 // calculate the box's size
1372 double dy(0.06), ymin(ymax-nPar*dy);
1373 if(showLabel) ymin-= dy;
1374
1375 // create the box and set its options
1376 TPaveText *box= new TPaveText(xmin,ymax,xmax,ymin,"BRNDC");
1377 if(!box) return 0;
1378 box->SetName(Form("%s_statBox",GetName())) ;
1379 box->SetFillColor(0);
1380 box->SetBorderSize(1);
1381 box->SetTextAlign(12);
1382 box->SetTextSize(0.04F);
1383 box->SetFillStyle(1001);
1384
1385 // add formatted text for each statistic
1386 RooRealVar N("N","Number of Events",sumEntries(cutSpec,cutRange));
1387 N.setPlotLabel("Entries") ;
1388 RooRealVar *meanv= meanVar(*(RooRealVar*)frame->getPlotVar(),cutSpec,cutRange);
1389 meanv->setPlotLabel("Mean") ;
1390 RooRealVar *rms= rmsVar(*(RooRealVar*)frame->getPlotVar(),cutSpec,cutRange);
1391 rms->setPlotLabel("RMS") ;
1392 TString *rmsText, *meanText, *NText ;
1393 if (options) {
1394 rmsText= rms->format(sigDigits,options);
1395 meanText= meanv->format(sigDigits,options);
1396 NText= N.format(sigDigits,options);
1397 } else {
1398 rmsText= rms->format(*formatCmd);
1399 meanText= meanv->format(*formatCmd);
1400 NText= N.format(*formatCmd);
1401 }
1402 if (showR) box->AddText(rmsText->Data());
1403 if (showM) box->AddText(meanText->Data());
1404 if (showN) box->AddText(NText->Data());
1405
1406 // cleanup heap memory
1407 delete NText;
1408 delete meanText;
1409 delete rmsText;
1410 delete meanv;
1411 delete rms;
1412
1413 // add the optional label if specified
1414 if(showLabel) box->AddText(label);
1415
1416 frame->addObject(box) ;
1417 return frame ;
1418}
1419
1420////////////////////////////////////////////////////////////////////////////////
1421/// Loop over columns of our tree data and fill the input histogram. Returns a pointer to the
1422/// input histogram, or zero in case of an error. The input histogram can be any TH1 subclass, and
1423/// therefore of arbitrary dimension. Variables are matched with the (x,y,...) dimensions of the input
1424/// histogram according to the order in which they appear in the input plotVars list.
1425
1426TH1 *RooAbsData::fillHistogram(TH1 *hist, const RooArgList &plotVars, const char *cuts, const char* cutRange) const
1427{
1428 // Do we have a valid histogram to use?
1429 if(0 == hist) {
1430 coutE(InputArguments) << ClassName() << "::" << GetName() << ":fillHistogram: no valid histogram to fill" << endl;
1431 return 0;
1432 }
1433
1434 // Check that the number of plotVars matches the input histogram's dimension
1435 Int_t hdim= hist->GetDimension();
1436 if(hdim != plotVars.getSize()) {
1437 coutE(InputArguments) << ClassName() << "::" << GetName() << ":fillHistogram: plotVars has the wrong dimension" << endl;
1438 return 0;
1439 }
1440
1441 // Check that the plot variables are all actually RooAbsReal's and print a warning if we do not
1442 // explicitly depend on one of them. Clone any variables that we do not contain directly and
1443 // redirect them to use our event data.
1444 RooArgSet plotClones,localVars;
1445 for(Int_t index= 0; index < plotVars.getSize(); index++) {
1446 const RooAbsArg *var= plotVars.at(index);
1447 const RooAbsReal *realVar= dynamic_cast<const RooAbsReal*>(var);
1448 if(0 == realVar) {
1449 coutE(InputArguments) << ClassName() << "::" << GetName() << ":fillHistogram: cannot plot variable \"" << var->GetName()
1450 << "\" of type " << var->ClassName() << endl;
1451 return 0;
1452 }
1453 RooAbsArg *found= _vars.find(realVar->GetName());
1454 if(!found) {
1455 RooAbsArg *clone= plotClones.addClone(*realVar,true); // do not complain about duplicates
1456 assert(0 != clone);
1457 if(!clone->dependsOn(_vars)) {
1458 coutE(InputArguments) << ClassName() << "::" << GetName()
1459 << ":fillHistogram: Data does not contain the variable '" << realVar->GetName() << "'." << endl;
1460 return nullptr;
1461 }
1462 else {
1464 }
1465 localVars.add(*clone);
1466 }
1467 else {
1468 localVars.add(*found);
1469 }
1470 }
1471
1472 // Create selection formula if selection cuts are specified
1473 std::unique_ptr<RooFormula> select;
1474 if (cuts != nullptr && strlen(cuts) > 0) {
1475 select.reset(new RooFormula(cuts, cuts, _vars, false));
1476 if (!select || !select->ok()) {
1477 coutE(InputArguments) << ClassName() << "::" << GetName() << ":fillHistogram: invalid cuts \"" << cuts << "\"" << endl;
1478 return 0 ;
1479 }
1480 }
1481
1482 // Lookup each of the variables we are binning in our tree variables
1483 const RooAbsReal *xvar = 0;
1484 const RooAbsReal *yvar = 0;
1485 const RooAbsReal *zvar = 0;
1486 switch(hdim) {
1487 case 3:
1488 zvar= dynamic_cast<RooAbsReal*>(localVars.find(plotVars.at(2)->GetName()));
1489 assert(0 != zvar);
1490 // fall through to next case...
1491 case 2:
1492 yvar= dynamic_cast<RooAbsReal*>(localVars.find(plotVars.at(1)->GetName()));
1493 assert(0 != yvar);
1494 // fall through to next case...
1495 case 1:
1496 xvar= dynamic_cast<RooAbsReal*>(localVars.find(plotVars.at(0)->GetName()));
1497 assert(0 != xvar);
1498 break;
1499 default:
1500 coutE(InputArguments) << ClassName() << "::" << GetName() << ":fillHistogram: cannot fill histogram with "
1501 << hdim << " dimensions" << endl;
1502 break;
1503 }
1504
1505 // Parse cutRange specification
1506 const auto cutVec = ROOT::Split(cutRange ? cutRange : "", ",");
1507
1508 // Loop over events and fill the histogram
1509 if (hist->GetSumw2()->fN==0) {
1510 hist->Sumw2() ;
1511 }
1512 Int_t nevent= numEntries() ; //(Int_t)_tree->GetEntries();
1513 for(Int_t i=0; i < nevent; ++i) {
1514
1515 //Int_t entryNumber= _tree->GetEntryNumber(i);
1516 //if (entryNumber<0) break;
1517 get(i);
1518
1519 // Apply expression based selection criteria
1520 if (select && select->eval()==0) {
1521 continue ;
1522 }
1523
1524
1525 // Apply range based selection criteria
1526 bool selectByRange = true ;
1527 if (cutRange) {
1528 for (const auto arg : _vars) {
1529 bool selectThisArg = false ;
1530 for (auto const& cut : cutVec) {
1531 if (!cut.empty() && arg->inRange(cut.c_str())) {
1532 selectThisArg = true ;
1533 break ;
1534 }
1535 }
1536 if (!selectThisArg) {
1537 selectByRange = false ;
1538 break ;
1539 }
1540 }
1541 }
1542
1543 if (!selectByRange) {
1544 // Go to next event in loop over events
1545 continue ;
1546 }
1547
1548 Int_t bin(0);
1549 switch(hdim) {
1550 case 1:
1551 bin= hist->FindBin(xvar->getVal());
1552 hist->Fill(xvar->getVal(),weight()) ;
1553 break;
1554 case 2:
1555 bin= hist->FindBin(xvar->getVal(),yvar->getVal());
1556 static_cast<TH2*>(hist)->Fill(xvar->getVal(),yvar->getVal(),weight()) ;
1557 break;
1558 case 3:
1559 bin= hist->FindBin(xvar->getVal(),yvar->getVal(),zvar->getVal());
1560 static_cast<TH3*>(hist)->Fill(xvar->getVal(),yvar->getVal(),zvar->getVal(),weight()) ;
1561 break;
1562 default:
1563 assert(hdim < 3);
1564 break;
1565 }
1566
1567
1568 double error2 = TMath::Power(hist->GetBinError(bin),2)-TMath::Power(weight(),2) ;
1569 double we = weightError(RooAbsData::SumW2) ;
1570 if (we==0) we = weight() ;
1571 error2 += TMath::Power(we,2) ;
1572
1573
1574// double we = weightError(RooAbsData::SumW2) ;
1575// double error2(0) ;
1576// if (we==0) {
1577// we = weight() ; //sqrt(weight()) ;
1578// error2 = TMath::Power(hist->GetBinError(bin),2)-TMath::Power(weight(),2) + TMath::Power(we,2) ;
1579// } else {
1580// error2 = TMath::Power(hist->GetBinError(bin),2)-TMath::Power(weight(),2) + TMath::Power(we,2) ;
1581// }
1582 //hist->AddBinContent(bin,weight());
1583 hist->SetBinError(bin,sqrt(error2)) ;
1584
1585 //cout << "RooTreeData::fillHistogram() bin = " << bin << " weight() = " << weight() << " we = " << we << endl ;
1586
1587 }
1588
1589 return hist;
1590}
1591
1592////////////////////////////////////////////////////////////////////////////////
1593/// Split dataset into subsets based on states of given splitCat in this dataset.
1594/// A TList of RooDataSets is returned in which each RooDataSet is named
1595/// after the state name of splitCat of which it contains the dataset subset.
1596/// The observables splitCat itself is no longer present in the sub datasets.
1597/// If createEmptyDataSets is false (default) this method only creates datasets for states
1598/// which have at least one entry The caller takes ownership of the returned list and its contents
1599
1600TList* RooAbsData::split(const RooAbsCategory& splitCat, bool createEmptyDataSets) const
1601{
1602 // Sanity check
1603 if (!splitCat.dependsOn(*get())) {
1604 coutE(InputArguments) << "RooTreeData::split(" << GetName() << ") ERROR category " << splitCat.GetName()
1605 << " doesn't depend on any variable in this dataset" << endl ;
1606 return 0 ;
1607 }
1608
1609 // Clone splitting category and attach to self
1610 RooAbsCategory* cloneCat =0;
1611 RooArgSet* cloneSet = 0;
1612 if (splitCat.isDerived()) {
1613 cloneSet = (RooArgSet*) RooArgSet(splitCat).snapshot(true) ;
1614 if (!cloneSet) {
1615 coutE(InputArguments) << "RooTreeData::split(" << GetName() << ") Couldn't deep-clone splitting category, abort." << endl ;
1616 return 0 ;
1617 }
1618 cloneCat = (RooAbsCategory*) cloneSet->find(splitCat.GetName()) ;
1619 cloneCat->attachDataSet(*this) ;
1620 } else {
1621 cloneCat = dynamic_cast<RooAbsCategory*>(get()->find(splitCat.GetName())) ;
1622 if (!cloneCat) {
1623 coutE(InputArguments) << "RooTreeData::split(" << GetName() << ") ERROR category " << splitCat.GetName()
1624 << " is fundamental and does not appear in this dataset" << endl ;
1625 return 0 ;
1626 }
1627 }
1628
1629 // Split a dataset in a series of subsets, each corresponding
1630 // to a state of splitCat
1631 TList* dsetList = new TList ;
1632
1633 // Construct set of variables to be included in split sets = full set - split category
1634 RooArgSet subsetVars(*get()) ;
1635 if (splitCat.isDerived()) {
1636 RooArgSet* vars = splitCat.getVariables() ;
1637 subsetVars.remove(*vars,true,true) ;
1638 delete vars ;
1639 } else {
1640 subsetVars.remove(splitCat,true,true) ;
1641 }
1642
1643 // Add weight variable explicitly if dataset has weights, but no top-level weight
1644 // variable exists (can happen with composite datastores)
1645 bool addWV(false) ;
1646 RooRealVar newweight("weight","weight",-1e9,1e9) ;
1648 subsetVars.add(newweight) ;
1649 addWV = true ;
1650 }
1651
1652 // If createEmptyDataSets is true, prepopulate with empty sets corresponding to all states
1653 if (createEmptyDataSets) {
1654 for (const auto& nameIdx : *cloneCat) {
1655 RooAbsData* subset = emptyClone(nameIdx.first.c_str(), nameIdx.first.c_str(), &subsetVars,(addWV?"weight":0)) ;
1656 dsetList->Add((RooAbsArg*)subset) ;
1657 }
1658 }
1659
1660
1661 // Loop over dataset and copy event to matching subset
1662 const bool propWeightSquared = isWeighted();
1663 for (Int_t i = 0; i < numEntries(); ++i) {
1664 const RooArgSet* row = get(i);
1665 RooAbsData* subset = (RooAbsData*) dsetList->FindObject(cloneCat->getCurrentLabel());
1666 if (!subset) {
1667 subset = emptyClone(cloneCat->getCurrentLabel(),cloneCat->getCurrentLabel(),&subsetVars,(addWV?"weight":0));
1668 dsetList->Add((RooAbsArg*)subset);
1669 }
1670 if (!propWeightSquared) {
1671 subset->add(*row, weight());
1672 } else {
1673 subset->add(*row, weight(), weightSquared());
1674 }
1675 }
1676
1677 delete cloneSet;
1678 return dsetList;
1679}
1680
1681////////////////////////////////////////////////////////////////////////////////
1682/// Split dataset into subsets based on the categorisation of the RooSimultaneous
1683/// A TList of RooDataSets is returned in which each RooDataSet is named
1684/// after the state name of splitCat of which it contains the dataset subset.
1685/// The observables splitCat itself is no longer present in the sub datasets, as well as the
1686/// observables of the other categories.
1687/// If createEmptyDataSets is false (default) this method only creates datasets for states
1688/// which have at least one entry The caller takes ownership of the returned list and its contents
1689
1690TList* RooAbsData::split(const RooSimultaneous& simpdf, bool createEmptyDataSets) const
1691{
1692 auto& splitCat = const_cast<RooAbsCategoryLValue&>(simpdf.indexCat());
1693
1694 // Sanity check
1695 if (!splitCat.dependsOn(*get())) {
1696 coutE(InputArguments) << "RooTreeData::split(" << GetName() << ") ERROR category " << splitCat.GetName()
1697 << " doesn't depend on any variable in this dataset" << endl ;
1698 return nullptr;
1699 }
1700
1701 // Clone splitting category and attach to self
1702 RooAbsCategory* cloneCat =0;
1703 std::unique_ptr<RooArgSet> cloneSet;
1704 if (splitCat.isDerived()) {
1705 cloneSet.reset(static_cast<RooArgSet*>(RooArgSet(splitCat).snapshot(true)));
1706 if (!cloneSet) {
1707 coutE(InputArguments) << "RooTreeData::split(" << GetName() << ") Couldn't deep-clone splitting category, abort." << endl ;
1708 return nullptr;
1709 }
1710 cloneCat = (RooAbsCategory*) cloneSet->find(splitCat.GetName()) ;
1711 cloneCat->attachDataSet(*this) ;
1712 } else {
1713 cloneCat = dynamic_cast<RooAbsCategory*>(get()->find(splitCat.GetName())) ;
1714 if (!cloneCat) {
1715 coutE(InputArguments) << "RooTreeData::split(" << GetName() << ") ERROR category " << splitCat.GetName()
1716 << " is fundamental and does not appear in this dataset" << endl ;
1717 return nullptr;
1718 }
1719 }
1720
1721 // Split a dataset in a series of subsets, each corresponding
1722 // to a state of splitCat
1723 TList* dsetList = new TList ;
1724
1725 // Construct set of variables to be included in split sets = full set - split category
1726 RooArgSet subsetVars(*get()) ;
1727 if (splitCat.isDerived()) {
1728 std::unique_ptr<RooArgSet> vars{splitCat.getVariables()};
1729 subsetVars.remove(*vars,true,true) ;
1730 } else {
1731 subsetVars.remove(splitCat,true,true) ;
1732 }
1733
1734 // Add weight variable explicitly if dataset has weights, but no top-level weight
1735 // variable exists (can happen with composite datastores)
1736 bool addWV(false) ;
1737 RooRealVar newweight("weight","weight",-1e9,1e9) ;
1739 subsetVars.add(newweight) ;
1740 addWV = true ;
1741 }
1742
1743 // Get the observables for a given pdf in the RooSimultaneous, or an empty
1744 // RooArgSet if no pdf is set
1745 auto getPdfObservables = [this, &simpdf](const char * label) {
1746 RooArgSet obsSet;
1747 if(RooAbsPdf* catPdf = simpdf.getPdf(label)) {
1748 catPdf->getObservables(this->get(), obsSet);
1749 }
1750 return obsSet;
1751 };
1752
1753 // By default, remove all category observables from the subdatasets
1754 RooArgSet allObservables;
1755 for( const auto& catPair : splitCat) {
1756 allObservables.add(getPdfObservables(catPair.first.c_str()));
1757 }
1758 subsetVars.remove(allObservables, true, true);
1759
1760
1761 // If createEmptyDataSets is true, prepopulate with empty sets corresponding to all states
1762 if (createEmptyDataSets) {
1763 for (const auto& nameIdx : *cloneCat) {
1764 // Add in the subset only the observables corresponding to this category
1765 RooArgSet subsetVarsCat(subsetVars);
1766 subsetVarsCat.add(getPdfObservables(nameIdx.first.c_str()));
1767 RooAbsData* subset = emptyClone(nameIdx.first.c_str(), nameIdx.first.c_str(), &subsetVarsCat,(addWV?"weight":0)) ;
1768 dsetList->Add(subset) ;
1769 }
1770 }
1771
1772
1773 // Loop over dataset and copy event to matching subset
1774 const bool propWeightSquared = isWeighted();
1775 for (Int_t i = 0; i < numEntries(); ++i) {
1776 const RooArgSet* row = get(i);
1777 RooAbsData* subset = (RooAbsData*) dsetList->FindObject(cloneCat->getCurrentLabel());
1778 if (!subset) {
1779 // Add in the subset only the observables corresponding to this category
1780 RooArgSet subsetVarsCat(subsetVars);
1781 subsetVarsCat.add(getPdfObservables(cloneCat->getCurrentLabel()));
1782 subset = emptyClone(cloneCat->getCurrentLabel(),cloneCat->getCurrentLabel(),&subsetVarsCat,(addWV?"weight":0));
1783 dsetList->Add(subset);
1784 }
1785 if (!propWeightSquared) {
1786 subset->add(*row, weight());
1787 } else {
1788 subset->add(*row, weight(), weightSquared());
1789 }
1790 }
1791
1792 return dsetList;
1793}
1794
1795////////////////////////////////////////////////////////////////////////////////
1796/// Plot dataset on specified frame.
1797///
1798/// By default:
1799/// - An unbinned dataset will use the default binning of the target frame.
1800/// - A binned dataset will retain its intrinsic binning.
1801///
1802/// The following optional named arguments can be used to modify the behaviour:
1803/// \note Please follow the function links in the left column to learn about PyROOT specifics for a given option.
1804///
1805/// <table>
1806///
1807/// <tr><th> <th> Data representation options
1808/// <tr><td> RooFit::Asymmetry(const RooCategory& c)
1809/// <td> Show the asymmetry of the data in given two-state category [F(+)-F(-)] / [F(+)+F(-)].
1810/// Category must have two states with indices -1 and +1 or three states with indices -1,0 and +1.
1811/// <tr><td> RooFit::Efficiency(const RooCategory& c)
1812/// <td> Show the efficiency F(acc)/[F(acc)+F(rej)]. Category must have two states with indices 0 and 1
1813/// <tr><td> RooFit::DataError(Int_t)
1814/// <td> Select the type of error drawn:
1815/// - `Auto(default)` results in Poisson for unweighted data and SumW2 for weighted data
1816/// - `Poisson` draws asymmetric Poisson confidence intervals.
1817/// - `SumW2` draws symmetric sum-of-weights error ( \f$ \left( \sum w \right)^2 / \sum\left(w^2\right) \f$ )
1818/// - `None` draws no error bars
1819/// <tr><td> RooFit::Binning(int nbins, double xlo, double xhi)
1820/// <td> Use specified binning to draw dataset
1821/// <tr><td> RooFit::Binning(const RooAbsBinning&)
1822/// <td> Use specified binning to draw dataset
1823/// <tr><td> RooFit::Binning(const char* name)
1824/// <td> Use binning with specified name to draw dataset
1825/// <tr><td> RooFit::RefreshNorm()
1826/// <td> Force refreshing for PDF normalization information in frame.
1827/// If set, any subsequent PDF will normalize to this dataset, even if it is
1828/// not the first one added to the frame. By default only the 1st dataset
1829/// added to a frame will update the normalization information
1830/// <tr><td> RooFit::Rescale(double f)
1831/// <td> Rescale drawn histogram by given factor.
1832/// <tr><td> RooFit::Cut(const char*)
1833/// <td> Only plot entries that pass the given cut.
1834/// Apart from cutting in continuous variables `Cut("x>5")`, this can also be used to plot a specific
1835/// category state. Use something like `Cut("myCategory == myCategory::stateA")`, where
1836/// `myCategory` resolves to the state number for a given entry and
1837/// `myCategory::stateA` resolves to the state number of the state named "stateA".
1838///
1839/// <tr><td> RooFit::CutRange(const char*)
1840/// <td> Only plot data from given range. Separate multiple ranges with ",".
1841/// \note This often requires passing the normalisation when plotting the PDF because RooFit does not save
1842/// how many events were being plotted (it will only work for cutting slices out of uniformly distributed
1843/// variables).
1844/// ```
1845/// data->plotOn(frame01, CutRange("SB1"));
1846/// const double nData = data->sumEntries("", "SB1");
1847/// // Make clear that the target normalisation is nData. The enumerator NumEvent
1848/// // is needed to switch between relative and absolute scaling.
1849/// model.plotOn(frame01, Normalization(nData, RooAbsReal::NumEvent),
1850/// ProjectionRange("SB1"));
1851/// ```
1852///
1853/// <tr><th> <th> Histogram drawing options
1854/// <tr><td> RooFit::DrawOption(const char* opt)
1855/// <td> Select ROOT draw option for resulting TGraph object
1856/// <tr><td> RooFit::LineStyle(Style_t style)
1857/// <td> Select line style by ROOT line style code, default is solid
1858/// <tr><td> RooFit::LineColor(Color_t color)
1859/// <td> Select line color by ROOT color code, default is black
1860/// <tr><td> RooFit::LineWidth(Width_t width)
1861/// <td> Select line with in pixels, default is 3
1862/// <tr><td> RooFit::MarkerStyle(Style_t style)
1863/// <td> Select the ROOT marker style, default is 21
1864/// <tr><td> RooFit::MarkerColor(Color_t color)
1865/// <td> Select the ROOT marker color, default is black
1866/// <tr><td> RooFit::MarkerSize(Size_t size)
1867/// <td> Select the ROOT marker size
1868/// <tr><td> RooFit::FillStyle(Style_t style)
1869/// <td> Select fill style, default is filled.
1870/// <tr><td> RooFit::FillColor(Color_t color)
1871/// <td> Select fill color by ROOT color code
1872/// <tr><td> RooFit::XErrorSize(double frac)
1873/// <td> Select size of X error bar as fraction of the bin width, default is 1
1874///
1875/// <tr><th> <th> Misc. other options
1876/// <tr><td> RooFit::Name(const char* name)
1877/// <td> Give curve specified name in frame. Useful if curve is to be referenced later
1878/// <tr><td> RooFit::Invisible()
1879/// <td> Add curve to frame, but do not display. Useful in combination AddTo()
1880/// <tr><td> RooFit::AddTo(const char* name, double wgtSel, double wgtOther)
1881/// <td> Add constructed histogram to already existing histogram with given name and relative weight factors
1882///
1883/// </table>
1884
1885RooPlot* RooAbsData::plotOn(RooPlot* frame, const RooLinkedList& argList) const
1886{
1887 // New experimental plotOn() with varargs...
1888
1889 // Define configuration for this method
1890 RooCmdConfig pc(Form("RooAbsData::plotOn(%s)",GetName())) ;
1891 pc.defineString("drawOption","DrawOption",0,"P") ;
1892 pc.defineString("cutRange","CutRange",0,"",true) ;
1893 pc.defineString("cutString","CutSpec",0,"") ;
1894 pc.defineString("histName","Name",0,"") ;
1895 pc.defineObject("cutVar","CutVar",0) ;
1896 pc.defineObject("binning","Binning",0) ;
1897 pc.defineString("binningName","BinningName",0,"") ;
1898 pc.defineInt("nbins","BinningSpec",0,100) ;
1899 pc.defineDouble("xlo","BinningSpec",0,0) ;
1900 pc.defineDouble("xhi","BinningSpec",1,1) ;
1901 pc.defineObject("asymCat","Asymmetry",0) ;
1902 pc.defineObject("effCat","Efficiency",0) ;
1903 pc.defineInt("lineColor","LineColor",0,-999) ;
1904 pc.defineInt("lineStyle","LineStyle",0,-999) ;
1905 pc.defineInt("lineWidth","LineWidth",0,-999) ;
1906 pc.defineInt("markerColor","MarkerColor",0,-999) ;
1907 pc.defineInt("markerStyle","MarkerStyle",0,-999) ;
1908 pc.defineDouble("markerSize","MarkerSize",0,-999) ;
1909 pc.defineInt("fillColor","FillColor",0,-999) ;
1910 pc.defineInt("fillStyle","FillStyle",0,-999) ;
1911 pc.defineInt("errorType","DataError",0,(Int_t)RooAbsData::Auto) ;
1912 pc.defineInt("histInvisible","Invisible",0,0) ;
1913 pc.defineInt("refreshFrameNorm","RefreshNorm",0,1) ;
1914 pc.defineString("addToHistName","AddTo",0,"") ;
1915 pc.defineDouble("addToWgtSelf","AddTo",0,1.) ;
1916 pc.defineDouble("addToWgtOther","AddTo",1,1.) ;
1917 pc.defineDouble("xErrorSize","XErrorSize",0,1.) ;
1918 pc.defineDouble("scaleFactor","Rescale",0,1.) ;
1919 pc.defineMutex("DataError","Asymmetry","Efficiency") ;
1920 pc.defineMutex("Binning","BinningName","BinningSpec") ;
1921
1922 // Process & check varargs
1923 pc.process(argList) ;
1924 if (!pc.ok(true)) {
1925 return frame ;
1926 }
1927
1928 PlotOpt o ;
1929
1930 // Extract values from named arguments
1931 o.drawOptions = pc.getString("drawOption") ;
1932 o.cuts = pc.getString("cutString") ;
1933 if (pc.hasProcessed("Binning")) {
1934 o.bins = (RooAbsBinning*) pc.getObject("binning") ;
1935 } else if (pc.hasProcessed("BinningName")) {
1936 o.bins = &frame->getPlotVar()->getBinning(pc.getString("binningName")) ;
1937 } else if (pc.hasProcessed("BinningSpec")) {
1938 double xlo = pc.getDouble("xlo") ;
1939 double xhi = pc.getDouble("xhi") ;
1940 o.bins = new RooUniformBinning((xlo==xhi)?frame->getPlotVar()->getMin():xlo,
1941 (xlo==xhi)?frame->getPlotVar()->getMax():xhi,pc.getInt("nbins")) ;
1942 }
1943 const RooAbsCategoryLValue* asymCat = (const RooAbsCategoryLValue*) pc.getObject("asymCat") ;
1944 const RooAbsCategoryLValue* effCat = (const RooAbsCategoryLValue*) pc.getObject("effCat") ;
1945 o.etype = (RooAbsData::ErrorType) pc.getInt("errorType") ;
1946 o.histInvisible = pc.getInt("histInvisible") ;
1947 o.xErrorSize = pc.getDouble("xErrorSize") ;
1948 o.cutRange = pc.getString("cutRange",0,true) ;
1949 o.histName = pc.getString("histName",0,true) ;
1950 o.addToHistName = pc.getString("addToHistName",0,true) ;
1951 o.addToWgtSelf = pc.getDouble("addToWgtSelf") ;
1952 o.addToWgtOther = pc.getDouble("addToWgtOther") ;
1953 o.refreshFrameNorm = pc.getInt("refreshFrameNorm") ;
1954 o.scaleFactor = pc.getDouble("scaleFactor") ;
1955
1956 // Map auto error type to actual type
1957 if (o.etype == Auto) {
1959 if (o.etype == SumW2) {
1960 coutI(InputArguments) << "RooAbsData::plotOn(" << GetName()
1961 << ") INFO: dataset has non-integer weights, auto-selecting SumW2 errors instead of Poisson errors" << endl ;
1962 }
1963 }
1964
1965 if (o.addToHistName && !frame->findObject(o.addToHistName,RooHist::Class())) {
1966 coutE(InputArguments) << "RooAbsData::plotOn(" << GetName() << ") cannot find existing histogram " << o.addToHistName
1967 << " to add to in RooPlot" << endl ;
1968 return frame ;
1969 }
1970
1971 RooPlot* ret ;
1972 if (!asymCat && !effCat) {
1973 ret = plotOn(frame,o) ;
1974 } else if (asymCat) {
1975 ret = plotAsymOn(frame,*asymCat,o) ;
1976 } else {
1977 ret = plotEffOn(frame,*effCat,o) ;
1978 }
1979
1980 Int_t lineColor = pc.getInt("lineColor") ;
1981 Int_t lineStyle = pc.getInt("lineStyle") ;
1982 Int_t lineWidth = pc.getInt("lineWidth") ;
1983 Int_t markerColor = pc.getInt("markerColor") ;
1984 Int_t markerStyle = pc.getInt("markerStyle") ;
1985 Size_t markerSize = pc.getDouble("markerSize") ;
1986 Int_t fillColor = pc.getInt("fillColor") ;
1987 Int_t fillStyle = pc.getInt("fillStyle") ;
1988 if (lineColor!=-999) ret->getAttLine()->SetLineColor(lineColor) ;
1989 if (lineStyle!=-999) ret->getAttLine()->SetLineStyle(lineStyle) ;
1990 if (lineWidth!=-999) ret->getAttLine()->SetLineWidth(lineWidth) ;
1991 if (markerColor!=-999) ret->getAttMarker()->SetMarkerColor(markerColor) ;
1992 if (markerStyle!=-999) ret->getAttMarker()->SetMarkerStyle(markerStyle) ;
1993 if (markerSize!=-999) ret->getAttMarker()->SetMarkerSize(markerSize) ;
1994 if (fillColor!=-999) ret->getAttFill()->SetFillColor(fillColor) ;
1995 if (fillStyle!=-999) ret->getAttFill()->SetFillStyle(fillStyle) ;
1996
1997 if (pc.hasProcessed("BinningSpec")) {
1998 delete o.bins ;
1999 }
2000
2001 return ret ;
2002}
2003
2004////////////////////////////////////////////////////////////////////////////////
2005/// Create and fill a histogram of the frame's variable and append it to the frame.
2006/// The frame variable must be one of the data sets dimensions.
2007///
2008/// The plot range and the number of plot bins is determined by the parameters
2009/// of the plot variable of the frame (RooAbsReal::setPlotRange(), RooAbsReal::setPlotBins()).
2010///
2011/// The optional cut string expression can be used to select the events to be plotted.
2012/// The cut specification may refer to any variable contained in the data set.
2013///
2014/// The drawOptions are passed to the TH1::Draw() method.
2015/// \see RooAbsData::plotOn(RooPlot*,const RooLinkedList&) const
2017{
2018 if(0 == frame) {
2019 coutE(Plotting) << ClassName() << "::" << GetName() << ":plotOn: frame is null" << endl;
2020 return 0;
2021 }
2023 if(0 == var) {
2024 coutE(Plotting) << ClassName() << "::" << GetName()
2025 << ":plotOn: frame does not specify a plot variable" << endl;
2026 return 0;
2027 }
2028
2029 // create and fill a temporary histogram of this variable
2030 TString histName(GetName());
2031 histName.Append("_plot");
2032 std::unique_ptr<TH1> hist;
2033 if (o.bins) {
2034 hist.reset( var->createHistogram(histName.Data(), RooFit::AxisLabel("Events"), RooFit::Binning(*o.bins)) );
2035 } else if (!frame->getPlotVar()->getBinning().isUniform()) {
2036 hist.reset( var->createHistogram(histName.Data(), RooFit::AxisLabel("Events"),
2037 RooFit::Binning(frame->getPlotVar()->getBinning())) );
2038 } else {
2039 hist.reset( var->createHistogram(histName.Data(), "Events",
2040 frame->GetXaxis()->GetXmin(), frame->GetXaxis()->GetXmax(), frame->GetNbinsX()) );
2041 }
2042
2043 // Keep track of sum-of-weights error
2044 hist->Sumw2() ;
2045
2046 if(0 == fillHistogram(hist.get(), RooArgList(*var),o.cuts,o.cutRange)) {
2047 coutE(Plotting) << ClassName() << "::" << GetName()
2048 << ":plotOn: fillHistogram() failed" << endl;
2049 return 0;
2050 }
2051
2052 // If frame has no predefined bin width (event density) it will be adjusted to
2053 // our histograms bin width so we should force that bin width here
2054 double nomBinWidth ;
2055 if (frame->getFitRangeNEvt()==0 && o.bins) {
2056 nomBinWidth = o.bins->averageBinWidth() ;
2057 } else {
2058 nomBinWidth = o.bins ? frame->getFitRangeBinW() : 0 ;
2059 }
2060
2061 // convert this histogram to a RooHist object on the heap
2062 RooHist *graph= new RooHist(*hist,nomBinWidth,1,o.etype,o.xErrorSize,o.correctForBinWidth,o.scaleFactor);
2063 if(0 == graph) {
2064 coutE(Plotting) << ClassName() << "::" << GetName()
2065 << ":plotOn: unable to create a RooHist object" << endl;
2066 return 0;
2067 }
2068
2069 // If the dataset variable has a wide range than the plot variable,
2070 // calculate the number of entries in the dataset in the plot variable fit range
2071 RooAbsRealLValue* dataVar = (RooAbsRealLValue*) _vars.find(var->GetName()) ;
2072 double nEnt(sumEntries()) ;
2073 if (dataVar->getMin()<var->getMin() || dataVar->getMax()>var->getMax()) {
2074 RooAbsData* tmp = ((RooAbsData*)this)->reduce(*var) ;
2075 nEnt = tmp->sumEntries() ;
2076 delete tmp ;
2077 }
2078
2079 // Store the number of entries before the cut, if any was made
2080 if ((o.cuts && strlen(o.cuts)) || o.cutRange) {
2081 coutI(Plotting) << "RooTreeData::plotOn: plotting " << hist->GetSumOfWeights() << " events out of " << nEnt << " total events" << endl ;
2082 graph->setRawEntries(nEnt) ;
2083 }
2084
2085 // Add self to other hist if requested
2086 if (o.addToHistName) {
2087 RooHist* otherGraph = static_cast<RooHist*>(frame->findObject(o.addToHistName,RooHist::Class())) ;
2088
2089 if (!graph->hasIdenticalBinning(*otherGraph)) {
2090 coutE(Plotting) << "RooTreeData::plotOn: ERROR Histogram to be added to, '" << o.addToHistName << "',has different binning" << endl ;
2091 delete graph ;
2092 return frame ;
2093 }
2094
2095 RooHist* sumGraph = new RooHist(*graph,*otherGraph,o.addToWgtSelf,o.addToWgtOther,o.etype) ;
2096 delete graph ;
2097 graph = sumGraph ;
2098 }
2099
2100 // Rename graph if requested
2101 if (o.histName) {
2102 graph->SetName(o.histName) ;
2103 } else {
2104 TString hname(Form("h_%s",GetName())) ;
2105 if (o.cutRange && strlen(o.cutRange)>0) {
2106 hname.Append(Form("_CutRange[%s]",o.cutRange)) ;
2107 }
2108 if (o.cuts && strlen(o.cuts)>0) {
2109 hname.Append(Form("_Cut[%s]",o.cuts)) ;
2110 }
2111 graph->SetName(hname.Data()) ;
2112 }
2113
2114 // initialize the frame's normalization setup, if necessary
2115 frame->updateNormVars(_vars);
2116
2117
2118 // add the RooHist to the specified plot
2120
2121 return frame;
2122}
2123
2124////////////////////////////////////////////////////////////////////////////////
2125/// Create and fill a histogram with the asymmetry N[+] - N[-] / ( N[+] + N[-] ),
2126/// where N(+/-) is the number of data points with asymCat=+1 and asymCat=-1
2127/// as function of the frames variable. The asymmetry category 'asymCat' must
2128/// have exactly 2 (or 3) states defined with index values +1,-1 (and 0)
2129///
2130/// The plot range and the number of plot bins is determined by the parameters
2131/// of the plot variable of the frame (RooAbsReal::setPlotRange(), RooAbsReal::setPlotBins())
2132///
2133/// The optional cut string expression can be used to select the events to be plotted.
2134/// The cut specification may refer to any variable contained in the data set
2135///
2136/// The drawOptions are passed to the TH1::Draw() method
2137
2139{
2140 if(0 == frame) {
2141 coutE(Plotting) << ClassName() << "::" << GetName() << ":plotAsymOn: frame is null" << endl;
2142 return 0;
2143 }
2145 if(0 == var) {
2146 coutE(Plotting) << ClassName() << "::" << GetName()
2147 << ":plotAsymOn: frame does not specify a plot variable" << endl;
2148 return 0;
2149 }
2150
2151 // create and fill temporary histograms of this variable for each state
2152 TString hist1Name(GetName()),hist2Name(GetName());
2153 hist1Name.Append("_plot1");
2154 std::unique_ptr<TH1> hist1, hist2;
2155 hist2Name.Append("_plot2");
2156
2157 if (o.bins) {
2158 hist1.reset( var->createHistogram(hist1Name.Data(), "Events", *o.bins) );
2159 hist2.reset( var->createHistogram(hist2Name.Data(), "Events", *o.bins) );
2160 } else {
2161 hist1.reset( var->createHistogram(hist1Name.Data(), "Events",
2162 frame->GetXaxis()->GetXmin(), frame->GetXaxis()->GetXmax(),
2163 frame->GetNbinsX()) );
2164 hist2.reset( var->createHistogram(hist2Name.Data(), "Events",
2165 frame->GetXaxis()->GetXmin(), frame->GetXaxis()->GetXmax(),
2166 frame->GetNbinsX()) );
2167 }
2168
2169 assert(hist1 && hist2);
2170
2171 TString cuts1,cuts2 ;
2172 if (o.cuts && strlen(o.cuts)) {
2173 cuts1 = Form("(%s)&&(%s>0)",o.cuts,asymCat.GetName());
2174 cuts2 = Form("(%s)&&(%s<0)",o.cuts,asymCat.GetName());
2175 } else {
2176 cuts1 = Form("(%s>0)",asymCat.GetName());
2177 cuts2 = Form("(%s<0)",asymCat.GetName());
2178 }
2179
2180 if(! fillHistogram(hist1.get(), RooArgList(*var),cuts1.Data(),o.cutRange) ||
2181 ! fillHistogram(hist2.get(), RooArgList(*var),cuts2.Data(),o.cutRange)) {
2182 coutE(Plotting) << ClassName() << "::" << GetName()
2183 << ":plotAsymOn: createHistogram() failed" << endl;
2184 return 0;
2185 }
2186
2187 // convert this histogram to a RooHist object on the heap
2188 RooHist *graph= new RooHist(*hist1,*hist2,0,1,o.etype,o.xErrorSize,false,o.scaleFactor);
2189 graph->setYAxisLabel(Form("Asymmetry in %s",asymCat.GetName())) ;
2190
2191 // initialize the frame's normalization setup, if necessary
2192 frame->updateNormVars(_vars);
2193
2194 // Rename graph if requested
2195 if (o.histName) {
2196 graph->SetName(o.histName) ;
2197 } else {
2198 TString hname(Form("h_%s_Asym[%s]",GetName(),asymCat.GetName())) ;
2199 if (o.cutRange && strlen(o.cutRange)>0) {
2200 hname.Append(Form("_CutRange[%s]",o.cutRange)) ;
2201 }
2202 if (o.cuts && strlen(o.cuts)>0) {
2203 hname.Append(Form("_Cut[%s]",o.cuts)) ;
2204 }
2205 graph->SetName(hname.Data()) ;
2206 }
2207
2208 // add the RooHist to the specified plot
2210
2211 return frame;
2212}
2213
2214////////////////////////////////////////////////////////////////////////////////
2215/// Create and fill a histogram with the efficiency N[1] / ( N[1] + N[0] ),
2216/// where N(1/0) is the number of data points with effCat=1 and effCat=0
2217/// as function of the frames variable. The efficiency category 'effCat' must
2218/// have exactly 2 +1 and 0.
2219///
2220/// The plot range and the number of plot bins is determined by the parameters
2221/// of the plot variable of the frame (RooAbsReal::setPlotRange(), RooAbsReal::setPlotBins())
2222///
2223/// The optional cut string expression can be used to select the events to be plotted.
2224/// The cut specification may refer to any variable contained in the data set
2225///
2226/// The drawOptions are passed to the TH1::Draw() method
2227
2229{
2230 if(0 == frame) {
2231 coutE(Plotting) << ClassName() << "::" << GetName() << ":plotEffOn: frame is null" << endl;
2232 return 0;
2233 }
2235 if(0 == var) {
2236 coutE(Plotting) << ClassName() << "::" << GetName()
2237 << ":plotEffOn: frame does not specify a plot variable" << endl;
2238 return 0;
2239 }
2240
2241 // create and fill temporary histograms of this variable for each state
2242 TString hist1Name(GetName()),hist2Name(GetName());
2243 hist1Name.Append("_plot1");
2244 std::unique_ptr<TH1> hist1, hist2;
2245 hist2Name.Append("_plot2");
2246
2247 if (o.bins) {
2248 hist1.reset( var->createHistogram(hist1Name.Data(), "Events", *o.bins) );
2249 hist2.reset( var->createHistogram(hist2Name.Data(), "Events", *o.bins) );
2250 } else {
2251 hist1.reset( var->createHistogram(hist1Name.Data(), "Events",
2252 frame->GetXaxis()->GetXmin(), frame->GetXaxis()->GetXmax(),
2253 frame->GetNbinsX()) );
2254 hist2.reset( var->createHistogram(hist2Name.Data(), "Events",
2255 frame->GetXaxis()->GetXmin(), frame->GetXaxis()->GetXmax(),
2256 frame->GetNbinsX()) );
2257 }
2258
2259 assert(hist1 && hist2);
2260
2261 TString cuts1,cuts2 ;
2262 if (o.cuts && strlen(o.cuts)) {
2263 cuts1 = Form("(%s)&&(%s==1)",o.cuts,effCat.GetName());
2264 cuts2 = Form("(%s)&&(%s==0)",o.cuts,effCat.GetName());
2265 } else {
2266 cuts1 = Form("(%s==1)",effCat.GetName());
2267 cuts2 = Form("(%s==0)",effCat.GetName());
2268 }
2269
2270 if(! fillHistogram(hist1.get(), RooArgList(*var),cuts1.Data(),o.cutRange) ||
2271 ! fillHistogram(hist2.get(), RooArgList(*var),cuts2.Data(),o.cutRange)) {
2272 coutE(Plotting) << ClassName() << "::" << GetName()
2273 << ":plotEffOn: createHistogram() failed" << endl;
2274 return 0;
2275 }
2276
2277 // convert this histogram to a RooHist object on the heap
2278 RooHist *graph= new RooHist(*hist1,*hist2,0,1,o.etype,o.xErrorSize,true);
2279 graph->setYAxisLabel(Form("Efficiency of %s=%s", effCat.GetName(), effCat.lookupName(1).c_str()));
2280
2281 // initialize the frame's normalization setup, if necessary
2282 frame->updateNormVars(_vars);
2283
2284 // Rename graph if requested
2285 if (o.histName) {
2286 graph->SetName(o.histName) ;
2287 } else {
2288 TString hname(Form("h_%s_Eff[%s]",GetName(),effCat.GetName())) ;
2289 if (o.cutRange && strlen(o.cutRange)>0) {
2290 hname.Append(Form("_CutRange[%s]",o.cutRange)) ;
2291 }
2292 if (o.cuts && strlen(o.cuts)>0) {
2293 hname.Append(Form("_Cut[%s]",o.cuts)) ;
2294 }
2295 graph->SetName(hname.Data()) ;
2296 }
2297
2298 // add the RooHist to the specified plot
2300
2301 return frame;
2302}
2303
2304////////////////////////////////////////////////////////////////////////////////
2305/// Create and fill a 1-dimensional table for given category column
2306/// This functions is the equivalent of plotOn() for category dimensions.
2307///
2308/// The optional cut string expression can be used to select the events to be tabulated
2309/// The cut specification may refer to any variable contained in the data set
2310///
2311/// The option string is currently not used
2312
2313Roo1DTable* RooAbsData::table(const RooAbsCategory& cat, const char* cuts, const char* /*opts*/) const
2314{
2315 // First see if var is in data set
2316 RooAbsCategory* tableVar = (RooAbsCategory*) _vars.find(cat.GetName()) ;
2317 RooArgSet *tableSet = 0;
2318 bool ownPlotVar(false) ;
2319 if (!tableVar) {
2320 if (!cat.dependsOn(_vars)) {
2321 coutE(Plotting) << "RooTreeData::Table(" << GetName() << "): Argument " << cat.GetName()
2322 << " is not in dataset and is also not dependent on data set" << endl ;
2323 return 0 ;
2324 }
2325
2326 // Clone derived variable
2327 tableSet = (RooArgSet*) RooArgSet(cat).snapshot(true) ;
2328 if (!tableSet) {
2329 coutE(Plotting) << "RooTreeData::table(" << GetName() << ") Couldn't deep-clone table category, abort." << endl ;
2330 return 0 ;
2331 }
2332 tableVar = (RooAbsCategory*) tableSet->find(cat.GetName()) ;
2333 ownPlotVar = true ;
2334
2335 //Redirect servers of derived clone to internal ArgSet representing the data in this set
2336 tableVar->recursiveRedirectServers(_vars) ;
2337 }
2338
2339 TString tableName(GetName()) ;
2340 if (cuts && strlen(cuts)) {
2341 tableName.Append("(") ;
2342 tableName.Append(cuts) ;
2343 tableName.Append(")") ;
2344 }
2345 Roo1DTable* table2 = tableVar->createTable(tableName) ;
2346
2347 // Make cut selector if cut is specified
2348 RooFormulaVar* cutVar = 0;
2349 if (cuts && strlen(cuts)) {
2350 cutVar = new RooFormulaVar("cutVar",cuts,_vars) ;
2351 }
2352
2353 // Dump contents
2354 Int_t nevent= numEntries() ;
2355 for(Int_t i=0; i < nevent; ++i) {
2356 get(i);
2357
2358 if (cutVar && cutVar->getVal()==0) continue ;
2359
2360 table2->fill(*tableVar,weight()) ;
2361 }
2362
2363 if (ownPlotVar) delete tableSet ;
2364 if (cutVar) delete cutVar ;
2365
2366 return table2 ;
2367}
2368
2369////////////////////////////////////////////////////////////////////////////////
2370/// Fill Doubles 'lowest' and 'highest' with the lowest and highest value of
2371/// observable 'var' in this dataset. If the return value is true and error
2372/// occurred
2373
2374bool RooAbsData::getRange(const RooAbsRealLValue& var, double& lowest, double& highest, double marginFrac, bool symMode) const
2375{
2376 // Lookup variable in dataset
2377 const auto arg = _vars.find(var.GetName());
2378 if (!arg) {
2379 coutE(InputArguments) << "RooDataSet::getRange(" << GetName() << ") ERROR: unknown variable: " << var.GetName() << endl ;
2380 return true;
2381 }
2382
2383 auto varPtr = dynamic_cast<const RooRealVar*>(arg);
2384 // Check if found variable is of type RooRealVar
2385 if (!varPtr) {
2386 coutE(InputArguments) << "RooDataSet::getRange(" << GetName() << ") ERROR: variable " << var.GetName() << " is not of type RooRealVar" << endl ;
2387 return true;
2388 }
2389
2390 // Check if dataset is not empty
2391 if(sumEntries() == 0.) {
2392 coutE(InputArguments) << "RooDataSet::getRange(" << GetName() << ") WARNING: empty dataset" << endl ;
2393 return true;
2394 }
2395
2396 // Look for highest and lowest value
2397 lowest = RooNumber::infinity() ;
2398 highest = -RooNumber::infinity() ;
2399 for (Int_t i=0 ; i<numEntries() ; i++) {
2400 get(i) ;
2401 if (varPtr->getVal()<lowest) {
2402 lowest = varPtr->getVal() ;
2403 }
2404 if (varPtr->getVal()>highest) {
2405 highest = varPtr->getVal() ;
2406 }
2407 }
2408
2409 if (marginFrac>0) {
2410 if (symMode==false) {
2411
2412 double margin = marginFrac*(highest-lowest) ;
2413 lowest -= margin ;
2414 highest += margin ;
2415 if (lowest<var.getMin()) lowest = var.getMin() ;
2416 if (highest>var.getMax()) highest = var.getMax() ;
2417
2418 } else {
2419
2420 double mom1 = moment(*varPtr,1) ;
2421 double delta = ((highest-mom1)>(mom1-lowest)?(highest-mom1):(mom1-lowest))*(1+marginFrac) ;
2422 lowest = mom1-delta ;
2423 highest = mom1+delta ;
2424 if (lowest<var.getMin()) lowest = var.getMin() ;
2425 if (highest>var.getMax()) highest = var.getMax() ;
2426
2427 }
2428 }
2429
2430 return false ;
2431}
2432
2433////////////////////////////////////////////////////////////////////////////////
2434/// Prepare dataset for use with cached constant terms listed in
2435/// 'cacheList' of expression 'arg'. Deactivate tree branches
2436/// for any dataset observable that is either not used at all,
2437/// or is used exclusively by cached branch nodes.
2438
2439void RooAbsData::optimizeReadingWithCaching(RooAbsArg& arg, const RooArgSet& cacheList, const RooArgSet& keepObsList)
2440{
2441 RooArgSet pruneSet ;
2442
2443 // Add unused observables in this dataset to pruneSet
2444 pruneSet.add(*get()) ;
2445 RooArgSet* usedObs = arg.getObservables(*this) ;
2446 pruneSet.remove(*usedObs,true,true) ;
2447
2448 // Add observables exclusively used to calculate cached observables to pruneSet
2449 TIterator* vIter = get()->createIterator() ;
2450 RooAbsArg *var ;
2451 while ((var=(RooAbsArg*) vIter->Next())) {
2452 if (allClientsCached(var,cacheList)) {
2453 pruneSet.add(*var) ;
2454 }
2455 }
2456 delete vIter ;
2457
2458
2459 if (pruneSet.getSize()!=0) {
2460
2461 // Go over all used observables and check if any of them have parameterized
2462 // ranges in terms of pruned observables. If so, remove those observable
2463 // from the pruning list
2464 for(auto const* rrv : dynamic_range_cast<RooRealVar*>(*usedObs)) {
2465 if (rrv && !rrv->getBinning().isShareable()) {
2466 RooArgSet depObs ;
2467 RooAbsReal* loFunc = rrv->getBinning().lowBoundFunc() ;
2468 RooAbsReal* hiFunc = rrv->getBinning().highBoundFunc() ;
2469 if (loFunc) {
2470 loFunc->leafNodeServerList(&depObs,0,true) ;
2471 }
2472 if (hiFunc) {
2473 hiFunc->leafNodeServerList(&depObs,0,true) ;
2474 }
2475 if (depObs.getSize()>0) {
2476 pruneSet.remove(depObs,true,true) ;
2477 }
2478 }
2479 }
2480 }
2481
2482
2483 // Remove all observables in keep list from prune list
2484 pruneSet.remove(keepObsList,true,true) ;
2485
2486 if (pruneSet.getSize()!=0) {
2487
2488 // Deactivate tree branches here
2489 cxcoutI(Optimization) << "RooTreeData::optimizeReadingForTestStatistic(" << GetName() << "): Observables " << pruneSet
2490 << " in dataset are either not used at all, orserving exclusively p.d.f nodes that are now cached, disabling reading of these observables for TTree" << endl ;
2491 setArgStatus(pruneSet,false) ;
2492 }
2493
2494 delete usedObs ;
2495
2496}
2497
2498////////////////////////////////////////////////////////////////////////////////
2499/// Utility function that determines if all clients of object 'var'
2500/// appear in given list of cached nodes.
2501
2503{
2504 bool ret(true), anyClient(false) ;
2505
2506 for (const auto client : var->valueClients()) {
2507 anyClient = true ;
2508 if (!cacheList.find(client->GetName())) {
2509 // If client is not cached recurse
2510 ret &= allClientsCached(client,cacheList) ;
2511 }
2512 }
2513
2514 return anyClient?ret:false ;
2515}
2516
2517////////////////////////////////////////////////////////////////////////////////
2518
2520{
2521 _dstore->attachBuffers(extObs) ;
2522}
2523
2524////////////////////////////////////////////////////////////////////////////////
2525
2527{
2529}
2530
2531////////////////////////////////////////////////////////////////////////////////
2532
2534{
2535 if (_ownedComponents.size()>0) {
2536 return true ;
2537 }
2538 return false ;
2539}
2540
2541////////////////////////////////////////////////////////////////////////////////
2542
2544{
2545 map<string,RooAbsData*>::iterator i = _ownedComponents.find(name) ;
2546 if (i==_ownedComponents.end()) return 0 ;
2547 return i->second ;
2548}
2549
2550////////////////////////////////////////////////////////////////////////////////
2551
2553{
2554 _ownedComponents[idxlabel]= &data ;
2555}
2556
2557////////////////////////////////////////////////////////////////////////////////
2558/// Stream an object of class RooAbsData.
2559
2561{
2562 if (R__b.IsReading()) {
2565
2566 // Convert on the fly to vector storage if that the current working default
2569 }
2570
2571 } else {
2573 }
2574}
2575
2576////////////////////////////////////////////////////////////////////////////////
2577
2579{
2580 _dstore->checkInit() ;
2581}
2582
2583////////////////////////////////////////////////////////////////////////////////
2584/// Forward draw command to data store
2585
2587{
2588 if (_dstore) _dstore->Draw(option) ;
2589}
2590
2591////////////////////////////////////////////////////////////////////////////////
2592
2594{
2595 return _dstore->hasFilledCache() ;
2596}
2597
2598////////////////////////////////////////////////////////////////////////////////
2599/// Return a pointer to the TTree which stores the data. Returns a nullpointer
2600/// if vector-based storage is used. The RooAbsData remains owner of the tree.
2601/// GetClonedTree() can be used to get a tree even if the internal storage does not use one.
2602
2604{
2606 return _dstore->tree();
2607 } else {
2608 coutW(InputArguments) << "RooAbsData::tree(" << GetName() << ") WARNING: is not of StorageType::Tree. "
2609 << "Use GetClonedTree() instead or convert to tree storage." << endl;
2610 return (TTree *)nullptr;
2611 }
2612}
2613
2614////////////////////////////////////////////////////////////////////////////////
2615/// Return a clone of the TTree which stores the data or create such a tree
2616/// if vector storage is used. The user is responsible for deleting the tree
2617
2619{
2621 auto tmp = const_cast<TTree *>(_dstore->tree());
2622 return tmp->CloneTree();
2623 } else {
2624 RooTreeDataStore buffer(GetName(), GetTitle(), *get(), *_dstore);
2625 return buffer.tree().CloneTree();
2626 }
2627}
2628
2629////////////////////////////////////////////////////////////////////////////////
2630/// Convert vector-based storage to tree-based storage
2631
2633{
2636 delete _dstore;
2637 _dstore = newStore;
2639 }
2640}
2641
2642////////////////////////////////////////////////////////////////////////////////
2643/// If one of the TObject we have a referenced to is deleted, remove the
2644/// reference.
2645
2647{
2648 for(auto &iter : _ownedComponents) {
2649 if (iter.second == obj) {
2650 iter.second = nullptr;
2651 }
2652 }
2653}
2654
2655
2656////////////////////////////////////////////////////////////////////////////////
2657/// Sets the global observables stored in this data. A snapshot of the
2658/// observables will be saved.
2659/// \param[in] globalObservables The set of global observables to take a snapshot of.
2660
2661void RooAbsData::setGlobalObservables(RooArgSet const& globalObservables) {
2662 if(_globalObservables == nullptr) _globalObservables = std::make_unique<RooArgSet>();
2663 else _globalObservables->clear();
2664 globalObservables.snapshot(*_globalObservables);
2665 for(auto * arg : *_globalObservables) {
2666 arg->setAttribute("global",true);
2667 // Global observables are also always constant in fits
2668 if(auto lval = dynamic_cast<RooAbsRealLValue*>(arg)) lval->setConstant(true);
2669 if(auto lval = dynamic_cast<RooAbsCategoryLValue*>(arg)) lval->setConstant(true);
2670 }
2671}
2672
2673
2674////////////////////////////////////////////////////////////////////////////////
2675
2676void RooAbsData::SetName(const char* name)
2677{
2679 auto newPtr = RooNameReg::instance().constPtr(GetName()) ;
2680 if (newPtr != _namePtr) {
2681 //cout << "Rename '" << _namePtr->GetName() << "' to '" << name << "' (set flag in new name)" << endl;
2682 _namePtr = newPtr;
2685 }
2686}
2687
2688
2689
2690
2691////////////////////////////////////////////////////////////////////////////////
2692
2693void RooAbsData::SetNameTitle(const char *name, const char *title)
2694{
2695 TNamed::SetTitle(title) ;
2696 SetName(name);
2697}
2698
2699
2700
2701////////////////////////////////////////////////////////////////////////////////
2702/// Return sum of squared weights of this data.
2703
2705 const RooSpan<const double> eventWeights = getWeightBatch(0, numEntries(), /*sumW2=*/true);
2706 if (eventWeights.empty()) {
2707 return numEntries() * weightSquared();
2708 }
2709
2711 for (std::size_t i = 0; i < eventWeights.size(); ++i) {
2712 kahanWeight.AddIndexed(eventWeights[i], i);
2713 }
2714 return kahanWeight.Sum();
2715}
2716
2717
2718////////////////////////////////////////////////////////////////////////////////
2719/// Write information to retrieve data columns into `evalData.spans`.
2720/// All spans belonging to variables of this dataset are overwritten. Spans to other
2721/// variables remain intact.
2722/// \param[out] evalData Store references to all data batches in this struct's `spans`.
2723/// The key to retrieve an item is the pointer of the variable that owns the data.
2724/// \param begin Index of first event that ends up in the batch.
2725/// \param len Number of events in each batch.
2726void RooAbsData::getBatches(RooBatchCompute::RunContext& evalData, std::size_t begin, std::size_t len) const {
2727 for (auto&& batch : store()->getBatches(begin, len).spans) {
2728 evalData.spans[batch.first] = std::move(batch.second);
2729 }
2730}
2731
2732
2733std::map<const std::string, RooSpan<const RooAbsCategory::value_type>> RooAbsData::getCategoryBatches(
2734 std::size_t first, std::size_t len) const {
2735 return store()->getCategoryBatches(first, len);
2736}
2737
2738////////////////////////////////////////////////////////////////////////////////
2739/// Create a TH2F histogram of the distribution of the specified variable
2740/// using this dataset. Apply any cuts to select which events are used.
2741/// The variable being plotted can either be contained directly in this
2742/// dataset, or else be a function of the variables in this dataset.
2743/// The histogram will be created using RooAbsReal::createHistogram() with
2744/// the name provided (with our dataset name prepended).
2745
2746TH2F *RooAbsData::createHistogram(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2, const char *cuts,
2747 const char *name) const
2748{
2749 checkInit();
2750 return createHistogram(var1, var2, var1.getBins(), var2.getBins(), cuts, name);
2751}
2752
2753////////////////////////////////////////////////////////////////////////////////
2754/// Create a TH2F histogram of the distribution of the specified variable
2755/// using this dataset. Apply any cuts to select which events are used.
2756/// The variable being plotted can either be contained directly in this
2757/// dataset, or else be a function of the variables in this dataset.
2758/// The histogram will be created using RooAbsReal::createHistogram() with
2759/// the name provided (with our dataset name prepended).
2760
2761TH2F *RooAbsData::createHistogram(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2, int nx, int ny,
2762 const char *cuts, const char *name) const
2763{
2764 checkInit();
2765 static int counter(0);
2766
2767 std::unique_ptr<RooAbsReal> ownedPlotVarX;
2768 // Is this variable in our dataset?
2769 auto *plotVarX = static_cast<RooAbsReal *>(_vars.find(var1.GetName()));
2770 if (plotVarX == nullptr) {
2771 // Is this variable a client of our dataset?
2772 if (!var1.dependsOn(_vars)) {
2773 coutE(InputArguments) << GetName() << "::createHistogram: Argument " << var1.GetName()
2774 << " is not in dataset and is also not dependent on data set" << std::endl;
2775 return nullptr;
2776 }
2777
2778 // Clone derived variable
2779 ownedPlotVarX.reset(static_cast<RooAbsReal *>(var1.Clone()));
2780 plotVarX = ownedPlotVarX.get();
2781
2782 // Redirect servers of derived clone to internal ArgSet representing the data in this set
2783 plotVarX->redirectServers(const_cast<RooArgSet &>(_vars));
2784 }
2785
2786 std::unique_ptr<RooAbsReal> ownedPlotVarY;
2787 // Is this variable in our dataset?
2788 RooAbsReal *plotVarY = (RooAbsReal *)_vars.find(var2.GetName());
2789 if (plotVarY == nullptr) {
2790 // Is this variable a client of our dataset?
2791 if (!var2.dependsOn(_vars)) {
2792 coutE(InputArguments) << GetName() << "::createHistogram: Argument " << var2.GetName()
2793 << " is not in dataset and is also not dependent on data set" << std::endl;
2794 return nullptr;
2795 }
2796
2797 // Clone derived variable
2798 ownedPlotVarY.reset(static_cast<RooAbsReal *>(var2.Clone()));
2799 plotVarY = ownedPlotVarY.get();
2800
2801 // Redirect servers of derived clone to internal ArgSet representing the data in this set
2802 plotVarY->redirectServers(const_cast<RooArgSet &>(_vars));
2803 }
2804
2805 // Create selection formula if selection cuts are specified
2806 std::unique_ptr<RooFormula> select;
2807 if (0 != cuts && strlen(cuts)) {
2808 select = std::make_unique<RooFormula>(cuts, cuts, _vars);
2809 if (!select->ok()) {
2810 return nullptr;
2811 }
2812 }
2813
2814 TString histName(name);
2815 histName.Prepend("_");
2816 histName.Prepend(GetName());
2817 histName.Append("_");
2818 histName.Append(Form("%08x", counter++));
2819
2820 // create the histogram
2821 auto *histogram =
2822 new TH2F(histName.Data(), "Events", nx, var1.getMin(), var1.getMax(), ny, var2.getMin(), var2.getMax());
2823 if (!histogram) {
2824 coutE(DataHandling) << GetName() << "::createHistogram: unable to create a new histogram" << endl;
2825 return nullptr;
2826 }
2827
2828 // Dump contents
2829 Int_t nevent = numEntries();
2830 for (Int_t i = 0; i < nevent; ++i) {
2831 get(i);
2832
2833 if (select && select->eval() == 0)
2834 continue;
2835 histogram->Fill(plotVarX->getVal(), plotVarY->getVal(), weight());
2836 }
2837
2838 return histogram;
2839}
static std::map< RooAbsData *, int > _dcc
Definition: RooAbsData.cxx:127
#define coutI(a)
Definition: RooMsgService.h:34
#define cxcoutI(a)
Definition: RooMsgService.h:89
#define coutW(a)
Definition: RooMsgService.h:36
#define coutE(a)
Definition: RooMsgService.h:37
int Int_t
Definition: RtypesCore.h:45
float Size_t
Definition: RtypesCore.h:96
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:375
static void indent(ostringstream &buf, int indent_level)
#define N
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
char name[80]
Definition: TGX11.cxx:110
float xmin
Definition: THbookFile.cxx:95
float ymin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
float ymax
Definition: THbookFile.cxx:95
TMatrixTSym< Double_t > TMatrixDSym
Binding & operator=(OUT(*fun)(void))
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2447
T Sum() const
Definition: Util.h:240
void AddIndexed(T input, std::size_t index)
Add input to the sum.
Definition: Util.h:231
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:23
void fill(RooAbsCategory &cat, double weight=1.0) override
Increment the counter of the table slot with the name corresponding to that of the current category s...
Definition: Roo1DTable.cxx:102
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:77
void leafNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=0, bool recurseNonDerived=false) const
Fill supplied list with all leaf nodes of the arg tree, starting with ourself as top node.
Definition: RooAbsArg.cxx:500
TObject * Clone(const char *newname=0) const override
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:89
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
Definition: RooAbsArg.cxx:1197
void attachArgs(const RooAbsCollection &set)
Bind this node to objects in set.
Definition: RooAbsArg.cxx:1615
RooArgSet * getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
Definition: RooAbsArg.h:317
void SetName(const char *name) override
Set the name of the TNamed.
Definition: RooAbsArg.cxx:2399
const RefCountList_t & valueClients() const
List of all value clients of this object. Value clients receive value updates.
Definition: RooAbsArg.h:194
bool redirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool isRecursionStep=false)
Replace all direct servers of this object with the new servers in newServerList.
Definition: RooAbsArg.cxx:1031
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=0, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
Definition: RooAbsArg.cxx:835
RooArgSet * getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2067
virtual bool isDerived() const
Does value or shape of this arg depend on any other arg?
Definition: RooAbsArg.h:97
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
Definition: RooAbsArg.cxx:1630
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
Definition: RooAbsBinning.h:26
virtual double averageBinWidth() const =0
virtual bool isUniform() const
Definition: RooAbsBinning.h:48
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
A space to attach TBranches.
virtual const char * getCurrentLabel() const
Return label string of current state.
const std::string & lookupName(value_type index) const
Get the name corresponding to the given index.
Roo1DTable * createTable(const char *label) const
Create a table matching the shape of this category.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
bool allInRange(const char *rangeSpec) const
Return true if all contained object report to have their value inside the specified range.
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
TIterator * createIterator(bool dir=kIterForward) const
TIterator-style iteration over contained elements.
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 reset()=0
virtual void attachBuffers(const RooArgSet &extObs)=0
virtual const RooArgSet * get(Int_t index) const =0
virtual void resetBuffers()=0
virtual const TTree * tree() const
virtual std::map< const std::string, RooSpan< const RooAbsCategory::value_type > > getCategoryBatches(std::size_t, std::size_t) const
virtual void checkInit() const
virtual Int_t fill()=0
virtual bool changeObservableName(const char *from, const char *to)=0
virtual void setArgStatus(const RooArgSet &set, bool active)=0
virtual RooAbsDataStore * clone(const char *newname=0) const =0
virtual bool hasFilledCache() const
virtual void cacheArgs(const RooAbsArg *cacheOwner, RooArgSet &varSet, const RooArgSet *nset=0, bool skipZeroWeights=false)=0
void printMultiline(std::ostream &os, Int_t content, bool verbose, TString indent) const override
Detailed printing interface.
virtual void resetCache()=0
virtual void setDirtyProp(bool flag)
virtual void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)=0
virtual Int_t numEntries() const =0
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:61
virtual double weight() const =0
virtual double sumEntries() const =0
Return effective number of entries in dataset, i.e., sum all weights.
RooRealVar * meanVar(const RooRealVar &var, const char *cutSpec=0, const char *cutRange=0) const
Create a RooRealVar containing the mean of observable 'var' in this dataset.
virtual const RooArgSet * get() const
Definition: RooAbsData.h:105
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Interface for detailed printing of object.
Definition: RooAbsData.cxx:939
const TNamed * _namePtr
! De-duplicated name pointer. This will be equal for all objects with the same name.
Definition: RooAbsData.h:371
RooAbsData()
Default constructor.
Definition: RooAbsData.cxx:173
static void setDefaultStorageType(StorageType s)
Definition: RooAbsData.cxx:133
void SetName(const char *name) override
Set the name of the TNamed.
double standMoment(const RooRealVar &var, double order, const char *cutSpec=0, const char *cutRange=0) const
Calculate standardized moment.
Definition: RooAbsData.cxx:961
RooRealVar * dataRealVar(const char *methodname, const RooRealVar &extVar) const
Internal method to check if given RooRealVar maps to a RooRealVar in this dataset.
virtual Roo1DTable * table(const RooArgSet &catSet, const char *cuts="", const char *opts="") const
Construct table for product of categories in catSet.
Definition: RooAbsData.cxx:886
void setGlobalObservables(RooArgSet const &globalObservables)
Sets the global observables stored in this data.
RooAbsDataStore * store()
Definition: RooAbsData.h:81
void printClassName(std::ostream &os) const override
Print class name of dataset.
Definition: RooAbsData.cxx:932
virtual void reset()
Definition: RooAbsData.cxx:388
void Draw(Option_t *option="") override
Forward draw command to data store.
virtual bool changeObservableName(const char *from, const char *to)
Definition: RooAbsData.cxx:361
void printTitle(std::ostream &os) const override
Print title of dataset.
Definition: RooAbsData.cxx:924
virtual std::map< const std::string, RooSpan< const RooAbsCategory::value_type > > getCategoryBatches(std::size_t first=0, std::size_t len=std::numeric_limits< std::size_t >::max()) const
double moment(const RooRealVar &var, double order, const char *cutSpec=0, const char *cutRange=0) const
Calculate moment of requested order.
Definition: RooAbsData.cxx:980
void RecursiveRemove(TObject *obj) override
If one of the TObject we have a referenced to is deleted, remove the reference.
virtual double weightError(ErrorType=Poisson) const
Return the symmetric error on the current weight.
Definition: RooAbsData.h:116
void setDirtyProp(bool flag)
Control propagation of dirty flags from observables in dataset.
Definition: RooAbsData.cxx:436
virtual TH1 * fillHistogram(TH1 *hist, const RooArgList &plotVars, const char *cuts="", const char *cutRange=0) const
Loop over columns of our tree data and fill the input histogram.
virtual RooPlot * statOn(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())
Add a box with statistics information to the specified frame.
TClass * IsA() const override
Definition: RooAbsData.h:378
double sigma(const RooRealVar &var, const char *cutSpec=0, const char *cutRange=0) const
Definition: RooAbsData.h:255
void checkInit() const
virtual void setArgStatus(const RooArgSet &set, bool active)
Definition: RooAbsData.cxx:428
virtual RooPlot * plotEffOn(RooPlot *frame, const RooAbsCategoryLValue &effCat, PlotOpt o) const
Create and fill a histogram with the efficiency N[1] / ( N[1] + N[0] ), where N(1/0) is the number of...
virtual void add(const RooArgSet &row, double weight=1, double weightError=0)=0
virtual void optimizeReadingWithCaching(RooAbsArg &arg, const RooArgSet &cacheList, const RooArgSet &keepObsList)
Prepare dataset for use with cached constant terms listed in 'cacheList' of expression 'arg'.
static void claimVars(RooAbsData *)
Definition: RooAbsData.cxx:151
static StorageType defaultStorageType
Definition: RooAbsData.h:325
double corrcov(const RooRealVar &x, const RooRealVar &y, const char *cutSpec, const char *cutRange, bool corr) const
Internal method to calculate single correlation and covariance elements.
bool allClientsCached(RooAbsArg *, const RooArgSet &)
Utility function that determines if all clients of object 'var' appear in given list of cached nodes.
static TClass * Class()
void addOwnedComponent(const char *idxlabel, RooAbsData &data)
virtual void fill()
Definition: RooAbsData.cxx:374
RooArgSet _vars
Dimensions of this data set.
Definition: RooAbsData.h:362
bool canSplitFast() const
static bool releaseVars(RooAbsData *)
If return value is true variables can be deleted.
Definition: RooAbsData.cxx:160
virtual RooPlot * plotAsymOn(RooPlot *frame, const RooAbsCategoryLValue &asymCat, PlotOpt o) const
Create and fill a histogram with the asymmetry N[+] - N[-] / ( N[+] + N[-] ), where N(+/-) is the num...
RooAbsData * getSimData(const char *idxstate)
void copyGlobalObservables(const RooAbsData &other)
Definition: RooAbsData.cxx:314
virtual bool isNonPoissonWeighted() const
Definition: RooAbsData.h:158
bool hasFilledCache() const
RooRealVar * rmsVar(const RooRealVar &var, const char *cutSpec=0, const char *cutRange=0) const
Create a RooRealVar containing the RMS of observable 'var' in this dataset.
double sumEntriesW2() const
Return sum of squared weights of this data.
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:421
void convertToVectorStore()
Convert tree-based storage to vector-based storage.
Definition: RooAbsData.cxx:350
virtual RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len, bool sumW2=false) const =0
Return event weights of all events in range [first, first+len).
RooArgSet _cachedVars
! External variables cached with this data set
Definition: RooAbsData.h:363
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Definition: RooAbsData.cxx:381
virtual RooAbsData * reduceEng(const RooArgSet &varSubset, const RooFormulaVar *cutVar, const char *cutRange=0, std::size_t nStart=0, std::size_t=std::numeric_limits< std::size_t >::max())=0
virtual void getBatches(RooBatchCompute::RunContext &evalData, std::size_t first=0, std::size_t len=std::numeric_limits< std::size_t >::max()) const
Write information to retrieve data columns into evalData.spans.
virtual void convertToTreeStore()
Convert vector-based storage to tree-based storage.
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Definition: RooAbsData.cxx:609
bool getRange(const RooAbsRealLValue &var, double &lowest, double &highest, double marginFrac=0, bool symMode=false) const
Fill Doubles 'lowest' and 'highest' with the lowest and highest value of observable 'var' in this dat...
StorageType storageType
Definition: RooAbsData.h:327
RooAbsData & operator=(const RooAbsData &other)
Definition: RooAbsData.cxx:271
void SetNameTitle(const char *name, const char *title) override
Set all the TNamed parameters (name and title).
virtual void resetCache()
Internal method – Remove cached function values.
Definition: RooAbsData.cxx:412
virtual TList * split(const RooAbsCategory &splitCat, bool createEmptyDataSets=false) const
Split dataset into subsets based on states of given splitCat in this dataset.
Int_t defaultPrintContents(Option_t *opt) const override
Define default print options, for a given print style.
Definition: RooAbsData.cxx:947
std::unique_ptr< RooArgSet > _globalObservables
Snapshot of global observables.
Definition: RooAbsData.h:369
virtual double weightSquared() const =0
TTree * GetClonedTree() const
Return a clone of the TTree which stores the data or create such a tree if vector storage is used.
RooAbsData * reduce(const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg())
Create a reduced copy of this dataset.
Definition: RooAbsData.cxx:456
void attachBuffers(const RooArgSet &extObs)
virtual RooAbsData * emptyClone(const char *newName=0, const char *newTitle=0, const RooArgSet *vars=0, const char *wgtVarName=0) const =0
std::map< std::string, RooAbsData * > _ownedComponents
Owned external components.
Definition: RooAbsData.h:367
TH1 * createHistogram(const char *name, const RooAbsRealLValue &xvar, 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 createHistogram(const char *name, const RooAbsRealLValue& xvar, const RooLinkedList& argList) c...
Definition: RooAbsData.cxx:691
static StorageType getDefaultStorageType()
Definition: RooAbsData.cxx:144
virtual bool isWeighted() const
Definition: RooAbsData.h:154
void Streamer(TBuffer &) override
Stream an object of class RooAbsData.
void resetBuffers()
virtual void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=0, bool skipZeroWeights=false)
Internal method – Cache given set of functions with data.
Definition: RooAbsData.cxx:404
TMatrixDSym * corrcovMatrix(const RooArgList &vars, const char *cutSpec, const char *cutRange, bool corr) const
Return covariance matrix from data for given list of observables.
RooAbsDataStore * _dstore
Data storage implementation.
Definition: RooAbsData.h:365
void printName(std::ostream &os) const override
Print name of dataset.
Definition: RooAbsData.cxx:916
const TTree * tree() const
Return a pointer to the TTree which stores the data.
~RooAbsData() override
Destructor.
Definition: RooAbsData.cxx:328
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual double getMax(const char *name=0) const
Get maximum of currently defined range.
void setConstant(bool value=true)
virtual const RooAbsBinning & getBinning(const char *name=0, bool verbose=true, bool createOnTheFly=false) const =0
Retrive binning configuration with given name or default binning.
virtual double getMin(const char *name=0) const
Get minimum of currently defined range.
virtual Int_t getBins(const char *name=0) const
Get number of bins of currently defined range.
TH1 * createHistogram(const char *name, 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
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:64
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:94
const char * getPlotLabel() const
Get the label associated with the variable.
Definition: RooAbsReal.cxx:446
void setPlotLabel(const char *label)
Set the label associated with this variable.
Definition: RooAbsReal.cxx:456
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition: RooArgList.h:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:180
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:28
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:26
double getDouble(Int_t idx) const
Return double stored in slot idx.
Definition: RooCmdArg.h:91
Int_t getInt(Int_t idx) const
Definition: RooCmdArg.h:86
TObject * Clone(const char *newName=0) const override
Make a clone of an object using the Streamer facility.
Definition: RooCmdArg.h:57
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
Definition: RooCmdConfig.h:31
RooCompositeDataStore combines several disjunct datasets into one.
static TClass * Class()
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooFormula internally uses ROOT's TFormula to compute user-defined expressions of RooAbsArgs.
Definition: RooFormula.h:33
double eval(const RooArgSet *nset=0) const
Evalute all parameters/observables, and then evaluate formula.
Definition: RooFormula.cxx:432
A RooHist is a graphical representation of binned data based on the TGraphAsymmErrors class.
Definition: RooHist.h:27
static TClass * Class()
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:38
bool Replace(const TObject *oldArg, const TObject *newArg)
Replace object 'oldArg' in collection with new object 'newArg'.
void Delete(Option_t *o=0) override
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
TObject * find(const char *name) const
Return pointer to object with given name in collection.
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:67
TObject * FindObject(const char *name) const override
Return pointer to obejct with given name.
RooMultiCategory connects several RooAbsCategory objects into a single category.
RooNameReg is a registry for const char* names.
Definition: RooNameReg.h:25
const TNamed * constPtr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
Definition: RooNameReg.cxx:60
static RooNameReg & instance()
Return reference to singleton instance.
Definition: RooNameReg.cxx:50
@ kRenamedArg
TNamed flag to indicate that some RooAbsArg has been renamed (flag set in new name)
Definition: RooNameReg.h:38
static void incrementRenameCounter()
The renaming counter has to be incremented every time a RooAbsArg is renamed.
Definition: RooNameReg.cxx:127
static double infinity()
Return internal infinity representation.
Definition: RooNumber.cxx:48
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:43
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
Definition: RooPlot.cxx:413
TAttMarker * getAttMarker(const char *name=0) const
Return a pointer to the marker attributes of the named object in this plot, or zero if the named obje...
Definition: RooPlot.cxx:872
double getFitRangeNEvt() const
Return the number of events in the fit range.
Definition: RooPlot.h:142
TAttFill * getAttFill(const char *name=0) const
Return a pointer to the fill attributes of the named object in this plot, or zero if the named object...
Definition: RooPlot.cxx:862
RooAbsRealLValue * getPlotVar() const
Definition: RooPlot.h:140
TAttLine * getAttLine(const char *name=0) const
Return a pointer to the line attributes of the named object in this plot, or zero if the named object...
Definition: RooPlot.cxx:852
TAxis * GetXaxis() const
Definition: RooPlot.cxx:1271
void updateNormVars(const RooArgSet &vars)
Install the given set of observables are reference normalization variables for this frame.
Definition: RooPlot.cxx:371
Int_t GetNbinsX() const
Definition: RooPlot.cxx:1275
TObject * findObject(const char *name, const TClass *clas=0) const
Find the named object in our list of items and return a pointer to it.
Definition: RooPlot.cxx:987
void addPlotable(RooPlotable *plotable, Option_t *drawOptions="", bool invisible=false, bool refreshNorm=false)
Add the specified plotable object to our plot.
Definition: RooPlot.cxx:561
double getFitRangeBinW() const
Return the bin width that is being used to normalise the PDF.
Definition: RooPlot.h:145
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
Definition: RooPrintable.h:25
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
void setVal(double value) override
Set value of variable to 'value'.
Definition: RooRealVar.cxx:281
void setError(double value)
Definition: RooRealVar.h:63
TString * format(const RooCmdArg &formatArg) const
Format contents of RooRealVar for pretty printing on RooPlot parameter boxes.
Definition: RooRealVar.cxx:881
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
const RooAbsCategoryLValue & indexCat() const
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
constexpr std::span< T >::index_type size() const noexcept
Definition: RooSpan.h:121
constexpr bool empty() const noexcept
Definition: RooSpan.h:125
The RooStringView is a wrapper around a C-syle string that can also be constructed from a std::string...
Definition: RooStringView.h:27
static void destroy(const TObject *obj)
Register deletion of object 'obj'.
Definition: RooTrace.cxx:79
static void create(const TObject *obj)
Register creation of object 'obj'.
Definition: RooTrace.cxx:66
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.
Int_t fN
Definition: TArray.h:38
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:39
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:41
Double_t GetXmax() const
Definition: TAxis.h:135
Double_t GetXmin() const
Definition: TAxis.h:134
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
Bool_t IsReading() const
Definition: TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8938
virtual Int_t GetDimension() const
Definition: TH1.h:281
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
Definition: TH1.cxx:9081
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3348
virtual TArrayD * GetSumw2()
Definition: TH1.h:311
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
Definition: TH1.cxx:3678
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition: TH1.cxx:8895
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:257
Service class for 2-D histogram classes.
Definition: TH2.h:30
The 3-D histogram classes derived from the 1-D histogram classes.
Definition: TH3.h:31
Iterator abstract base class.
Definition: TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
A doubly linked list.
Definition: TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition: TList.cxx:578
void Add(TObject *obj) override
Definition: TList.h:81
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:74
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:51
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Clear(Option_t *="")
Definition: TObject.h:115
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
Basic string class.
Definition: TString.h:136
const char * Data() const
Definition: TString.h:369
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1163
TString & Prepend(const char *cs)
Definition: TString.h:661
TString & Append(const char *cs)
Definition: TString.h:564
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
A TTree represents a columnar dataset.
Definition: TTree.h:79
virtual TTree * CloneTree(Long64_t nentries=-1, Option_t *option="")
Create a clone of this tree and copy nentries.
Definition: TTree.cxx:3110
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooCmdArg ZVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooCmdArg AutoBinning(Int_t nbins=100, double marginFactor=0.1)
RooCmdArg AxisLabel(const char *name)
RooCmdArg Binning(const RooAbsBinning &binning)
RVec< PromoteType< T > > abs(const RVec< T > &v)
Definition: RVec.hxx:1739
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
static double C[]
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
Definition: StringUtils.cxx:23
static Roo_reg_AGKInteg1D instance
@ Optimization
Definition: RooGlobalFunc.h:64
@ DataHandling
Definition: RooGlobalFunc.h:65
@ InputArguments
Definition: RooGlobalFunc.h:64
static constexpr double s
static constexpr double pc
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:685
Definition: first.py:1
const double xbins[xbins_n]
Definition: graph.py:1
static const char * what
Definition: stlLoader.cc:6
const char * cuts
Definition: RooAbsData.h:184
const char * cutRange
Definition: RooAbsData.h:188
const char * histName
Definition: RooAbsData.h:189
const char * addToHistName
Definition: RooAbsData.h:191
RooAbsData::ErrorType etype
Definition: RooAbsData.h:187
RooAbsBinning * bins
Definition: RooAbsData.h:186
Option_t * drawOptions
Definition: RooAbsData.h:185
This struct enables passing computation data around between elements of a computation graph.
Definition: RunContext.h:31
std::map< const RooAbsArg *, 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
static uint64_t sum(uint64_t i)
Definition: Factory.cxx:2345