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