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