Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooVectorDataStore.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 RooVectorDataStore.cxx
19\class RooVectorDataStore
20\ingroup Roofitcore
21
22Uses `std::vector` to store data columns. Each of these vectors
23is associated to an instance of a RooAbsReal, whose values it represents. Those
24RooAbsReal are the observables of the dataset.
25In addition to the observables, a data column can be bound to a different instance
26of a RooAbsReal (e.g., the column "x" can be bound to the observable "x" of a computation
27graph using attachBuffers()). In this case, a get() operation writes the value of
28the requested column into the bound real.
29
30As a faster alternative to loading values one-by-one, one can use the function getBatches(),
31which returns spans pointing directly to the data.
32**/
33
34#include "RooVectorDataStore.h"
35
36#include "RooMsgService.h"
37#include "RooTreeDataStore.h"
38#include "RooFormulaVar.h"
39#include "RooRealVar.h"
40#include "RooCategory.h"
41#include "RooHistError.h"
42#include "RooTrace.h"
43#include "RooFitImplHelpers.h"
44
45#include "Math/Util.h"
46#include "ROOT/StringUtils.hxx"
47#include "TBuffer.h"
48
49#include <iomanip>
50using std::string, std::vector, std::cout, std::endl, std::list;
51
55
56
57////////////////////////////////////////////////////////////////////////////////
58
60{
62}
63
64
65
66////////////////////////////////////////////////////////////////////////////////
67
69 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
70 _varsww(vars),
71 _wgtVar(weightVar(vars,wgtVarName))
72{
73 for (auto arg : _varsww) {
74 arg->attachToVStore(*this) ;
75 }
76
79}
80
81
82
83////////////////////////////////////////////////////////////////////////////////
84
86{
87 for (auto realVec : _realStoreList) {
88 realVec->setNativeBuffer();
89 }
90
91 for (auto fullVec : _realfStoreList) {
92 fullVec->setNativeBuffer();
93 }
94
95 for (auto catVec : _catStoreList) {
96 catVec->setNativeBuffer();
97 }
98}
99
100
101
102
103////////////////////////////////////////////////////////////////////////////////
104/// Utility function for constructors
105/// Return RooArgSet that is copy of allVars minus variable matching wgtName if specified
106
107RooArgSet RooVectorDataStore::varsNoWeight(const RooArgSet& allVars, const char* wgtName)
108{
109 RooArgSet ret(allVars) ;
110 if(wgtName) {
111 RooAbsArg* wgt = allVars.find(wgtName) ;
112 if (wgt) {
113 ret.remove(*wgt,true,true) ;
114 }
115 }
116 return ret ;
117}
118
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// Utility function for constructors
123/// Return pointer to weight variable if it is defined
124
125RooRealVar* RooVectorDataStore::weightVar(const RooArgSet& allVars, const char* wgtName)
126{
127 if(wgtName) {
128 RooRealVar* wgt = dynamic_cast<RooRealVar*>(allVars.find(wgtName)) ;
129 return wgt ;
130 }
131 return nullptr ;
132}
133
134
135
136
137////////////////////////////////////////////////////////////////////////////////
138/// Regular copy constructor.
139
141 RooAbsDataStore(other,newname),
142 _varsww(other._varsww),
143 _wgtVar(other._wgtVar),
144 _sumWeight(other._sumWeight),
145 _sumWeightCarry(other._sumWeightCarry),
146 _extWgtArray(other._extWgtArray),
147 _extWgtErrLoArray(other._extWgtErrLoArray),
148 _extWgtErrHiArray(other._extWgtErrHiArray),
149 _extSumW2Array(other._extSumW2Array),
150 _currentWeightIndex(other._currentWeightIndex)
151{
152 for (const auto realVec : other._realStoreList) {
153 _realStoreList.push_back(new RealVector(*realVec, static_cast<RooAbsReal*>(_varsww.find(realVec->_nativeReal->GetName())))) ;
154 }
155
156 for (const auto realFullVec : other._realfStoreList) {
157 _realfStoreList.push_back(new RealFullVector(*realFullVec, static_cast<RooAbsReal*>(_varsww.find(realFullVec->_nativeReal->GetName())))) ;
158 }
159
160 for (const auto catVec : other._catStoreList) {
161 _catStoreList.push_back(new CatVector(*catVec, static_cast<RooAbsCategory*>(_varsww.find(catVec->_cat->GetName())))) ;
162 }
163
165
167}
168
169
170////////////////////////////////////////////////////////////////////////////////
171
172RooVectorDataStore::RooVectorDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname) :
173 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():nullptr),newname),
174 _varsww(vars),
175 _wgtVar(weightVar(vars,other._wgtVar?other._wgtVar->GetName():nullptr))
176{
177 for (const auto arg : _varsww) {
178 arg->attachToVStore(*this) ;
179 }
180
182
183 // now copy contents of tree storage here
184 reserve(other.numEntries());
185 for (Int_t i=0 ; i<other.numEntries() ; i++) {
186 other.get(i) ;
187 _varsww.assign(other._varsww) ;
188 fill() ;
189 }
191
192}
193
194
195////////////////////////////////////////////////////////////////////////////////
196/// Clone constructor, must connect internal storage to given new external set of variables.
197
198RooVectorDataStore::RooVectorDataStore(const RooVectorDataStore& other, const RooArgSet& vars, const char* newname) :
199 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():nullptr),newname),
200 _varsww(vars),
201 _wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):nullptr),
202 _sumWeight(other._sumWeight),
203 _sumWeightCarry(other._sumWeightCarry),
204 _extWgtArray(other._extWgtArray),
205 _extWgtErrLoArray(other._extWgtErrLoArray),
206 _extWgtErrHiArray(other._extWgtErrHiArray),
207 _extSumW2Array(other._extSumW2Array),
208 _currentWeightIndex(other._currentWeightIndex)
209{
210 for (const auto realVec : other._realStoreList) {
211 auto real = static_cast<RooAbsReal*>(vars.find(realVec->bufArg()->GetName()));
212 if (real) {
213 // Clone vector
214 _realStoreList.push_back(new RealVector(*realVec, real)) ;
215 // Adjust buffer pointer
216 real->attachToVStore(*this) ;
217 }
218 }
219
220 auto forwardIter = other._realfStoreList.begin() ;
221 for (; forwardIter!=other._realfStoreList.end() ; ++forwardIter) {
222 RooAbsReal* real = static_cast<RooAbsReal*>(vars.find((*forwardIter)->bufArg()->GetName())) ;
223 if (real) {
224 // Clone vector
225 _realfStoreList.push_back(new RealFullVector(**forwardIter,real)) ;
226 // Adjust buffer pointer
227 real->attachToVStore(*this) ;
228 }
229 }
230
231 vector<CatVector*>::const_iterator citer = other._catStoreList.begin() ;
232 for (; citer!=other._catStoreList.end() ; ++citer) {
233 RooAbsCategory* cat = static_cast<RooAbsCategory*>(vars.find((*citer)->bufArg()->GetName())) ;
234 if (cat) {
235 // Clone vector
236 _catStoreList.push_back(new CatVector(**citer,cat)) ;
237 // Adjust buffer pointer
238 cat->attachToVStore(*this) ;
239 }
240 }
241
243
245
246}
247
248
249std::unique_ptr<RooAbsDataStore> RooVectorDataStore::reduce(RooStringView name, RooStringView title,
250 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
251 std::size_t nStart, std::size_t nStop) {
252 RooArgSet tmp(vars) ;
253 if(_wgtVar && !tmp.contains(*_wgtVar)) {
254 tmp.add(*_wgtVar) ;
255 }
256 const char* wgtVarName = _wgtVar ? _wgtVar->GetName() : nullptr;
257 return std::make_unique<RooVectorDataStore>(name, title, *this, tmp, cutVar, cutRange, nStart, nStop, wgtVarName);
258}
259
260
261
262////////////////////////////////////////////////////////////////////////////////
263
265 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
266 std::size_t nStart, std::size_t nStop, const char* wgtVarName) :
267
268 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
269 _varsww(vars),
270 _wgtVar(weightVar(vars,wgtVarName))
271{
272 for (const auto arg : _varsww) {
273 arg->attachToVStore(*this) ;
274 }
275
277
278 // Deep clone cutVar and attach clone to this dataset
279 std::unique_ptr<RooFormulaVar> cloneVar;
280 if (cutVar) {
281 cloneVar.reset(static_cast<RooFormulaVar*>(cutVar->cloneTree()));
282 cloneVar->attachDataStore(tds) ;
283 }
284
285 RooVectorDataStore* vds = dynamic_cast<RooVectorDataStore*>(&tds) ;
286 if (vds && vds->_cache) {
287 _cache = new RooVectorDataStore(*vds->_cache) ;
288 }
289
290 loadValues(&tds,cloneVar.get(),cutRange,nStart,nStop);
291
293}
294
295
296
297
298
299
300////////////////////////////////////////////////////////////////////////////////
301/// Destructor
302
304{
305 for (auto elm : _realStoreList) {
306 delete elm;
307 }
308
309 for (auto elm : _realfStoreList) {
310 delete elm;
311 }
312
313 for (auto elm : _catStoreList) {
314 delete elm;
315 }
316
317 delete _cache ;
319}
320
321
322////////////////////////////////////////////////////////////////////////////////
323/// Interface function to TTree::Fill
324
326{
327 for (auto realVec : _realStoreList) {
328 realVec->fill() ;
329 }
330
331 for (auto fullVec : _realfStoreList) {
332 fullVec->fill() ;
333 }
334
335 for (auto catVec : _catStoreList) {
336 catVec->fill() ;
337 }
338 // use Kahan's algorithm to sum up weights to avoid loss of precision
339 double y = (_wgtVar ? _wgtVar->getVal() : 1.) - _sumWeightCarry;
340 double t = _sumWeight + y;
341 _sumWeightCarry = (t - _sumWeight) - y;
342 _sumWeight = t;
343
344 return 0 ;
345}
346
347
348
349////////////////////////////////////////////////////////////////////////////////
350/// Load the n-th data point (n='index') into the variables of this dataset,
351/// and return a pointer to the RooArgSet that holds them.
353{
354 if (index < 0 || static_cast<std::size_t>(index) >= size()) return nullptr;
355
356 for (const auto realV : _realStoreList) {
357 realV->load(index);
358 }
359
360 for (const auto fullRealP : _realfStoreList) {
361 fullRealP->load(index);
362 }
363
364 for (const auto catP : _catStoreList) {
365 catP->load(index);
366 }
367
368 if (_doDirtyProp) {
369 // Raise all dirty flags
370 for (auto var : _vars) {
371 var->setValueDirty(); // This triggers recalculation of all clients
372 }
373 }
374
375 // Update current weight cache
377
378 if (_cache) {
379 _cache->get(index) ;
380 }
381
382 return &_vars;
383}
384
385
386////////////////////////////////////////////////////////////////////////////////
387/// Return the error of the current weight.
388/// @param[in] etype Switch between simple Poisson or sum-of-weights statistics
389
391{
392 if (_extWgtArray) {
393
394 // We have a weight array, use that info
395
396 // Return symmetric error on current bin calculated either from Poisson statistics or from SumOfWeights
397 double lo = 0;
398 double hi = 0;
399 weightError(lo,hi,etype) ;
400 return (lo+hi)/2 ;
401
402 } else if (_wgtVar) {
403
404 // We have a weight variable, use that info
405 if (_wgtVar->hasAsymError()) {
406 return ( _wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo() ) / 2 ;
407 } else if (_wgtVar->hasError(false)) {
408 return _wgtVar->getError();
409 } else {
410 return 0 ;
411 }
412
413 } else {
414
415 // We have no weights
416 return 0 ;
417
418 }
419}
420
421
422
423////////////////////////////////////////////////////////////////////////////////
424
425void RooVectorDataStore::weightError(double& lo, double& hi, RooAbsData::ErrorType etype) const
426{
427 if (_extWgtArray) {
428 double wgt;
429
430 // We have a weight array, use that info
431 switch (etype) {
432
433 case RooAbsData::Auto:
434 throw string(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
435 break ;
436
438 throw string(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
439 break ;
440
442 // Weight may be preset or precalculated
446 return ;
447 }
448
449 // Otherwise Calculate poisson errors
450 wgt = weight();
451 double ym;
452 double yp;
454 lo = wgt-ym;
455 hi = yp-wgt;
456 return ;
457
460 hi = lo;
461 return ;
462
463 case RooAbsData::None:
464 lo = 0 ;
465 hi = 0 ;
466 return ;
467 }
468
469 } else if (_wgtVar) {
470
471 // We have a weight variable, use that info
472 if (_wgtVar->hasAsymError()) {
474 lo = _wgtVar->getAsymErrorLo() ;
475 } else {
476 hi = _wgtVar->getError() ;
477 lo = _wgtVar->getError() ;
478 }
479
480 } else {
481
482 // We are unweighted
483 lo=0 ;
484 hi=0 ;
485
486 }
487}
488
489
490
491////////////////////////////////////////////////////////////////////////////////
492///
493
494void RooVectorDataStore::loadValues(const RooAbsDataStore *ads, const RooFormulaVar* select, const char* rangeName, std::size_t nStart, std::size_t nStop)
495{
496 // Load values from dataset 't' into this data collection, optionally
497 // selecting events using 'select' RooFormulaVar
498 //
499
500 // Redirect formula servers to source data row
501 std::unique_ptr<RooFormulaVar> selectClone;
502 if (select) {
503 selectClone.reset( static_cast<RooFormulaVar*>(select->cloneTree()) );
504 selectClone->recursiveRedirectServers(*ads->get()) ;
505 selectClone->setOperMode(RooAbsArg::ADirty,true) ;
506 }
507
508 // Force DS internal initialization
509 ads->get(0) ;
510
511 // Loop over events in source tree
512 const auto numEntr = static_cast<std::size_t>(ads->numEntries());
513 const std::size_t nevent = nStop < numEntr ? nStop : numEntr;
514
515 auto treeDS = dynamic_cast<const RooTreeDataStore*>(ads);
516 auto vectorDS = dynamic_cast<const RooVectorDataStore*>(ads);
517
518 // Check if weight is being renamed - if so set flag to enable special handling in copy loop
519 bool weightRename(false) ;
520 const bool newWeightVar = _wgtVar ? _wgtVar->getAttribute("NewWeight") : false ;
521
522 if (_wgtVar && vectorDS && vectorDS->_wgtVar) {
523 if (std::string(_wgtVar->GetName()) != vectorDS->_wgtVar->GetName() && !newWeightVar) {
524 weightRename=true ;
525 }
526 }
527 if (_wgtVar && treeDS && treeDS->_wgtVar) {
528 if (std::string(_wgtVar->GetName()) != treeDS->_wgtVar->GetName() && !newWeightVar) {
529 weightRename=true ;
530 }
531 }
532
533 std::vector<std::string> ranges;
534 if (rangeName) {
535 ranges = ROOT::Split(rangeName, ",");
536 }
537
538 reserve(numEntries() + (nevent - nStart));
539 for(auto i=nStart; i < nevent ; ++i) {
540 ads->get(i);
541
542 // Does this event pass the cuts?
543 if (selectClone && selectClone->getVal()==0) {
544 continue ;
545 }
546
547 RooArgSet const* otherVarsww = nullptr;
548
549 if (treeDS) {
550 otherVarsww = &treeDS->_varsww;
551 if (weightRename) {
552 _wgtVar->setVal(treeDS->_wgtVar->getVal()) ;
553 }
554 } else if (vectorDS) {
555 otherVarsww = &vectorDS->_varsww;
556 if (weightRename) {
557 _wgtVar->setVal(vectorDS->_wgtVar->getVal()) ;
558 }
559 } else {
560 otherVarsww = ads->get();
561 }
562
563 // Check that all copied values are valid and in range
564 bool allValid = true;
565 for (const auto arg : *otherVarsww) {
566 allValid &= arg->isValid();
567 if (allValid && !ranges.empty()) {
568 // If we have one or multiple ranges to be selected, the value
569 // must be in one of them to be valid
570 allValid &= std::any_of(ranges.begin(), ranges.end(), [arg](const std::string& range){
571 return arg->inRange(range.c_str());});
572 }
573 if (!allValid)
574 break ;
575 }
576
577 if (!allValid) {
578 continue ;
579 }
580
581 _varsww.assign(*otherVarsww) ;
582
583 fill() ;
584 }
585
586 SetTitle(ads->GetTitle());
587}
588
589
590
591
592
593////////////////////////////////////////////////////////////////////////////////
594
595bool RooVectorDataStore::changeObservableName(const char* /*from*/, const char* /*to*/)
596{
597 return false ;
598}
599
600
601
602////////////////////////////////////////////////////////////////////////////////
603/// Add a new column to the data set which holds the pre-calculated values
604/// of 'newVar'. This operation is only meaningful if 'newVar' is a derived
605/// value.
606///
607/// The return value points to the added element holding 'newVar's value
608/// in the data collection. The element is always the corresponding fundamental
609/// type of 'newVar' (e.g. a RooRealVar if 'newVar' is a RooFormulaVar)
610///
611/// Note: This function is explicitly NOT intended as a speed optimization
612/// opportunity for the user. Components of complex PDFs that can be
613/// precalculated with the dataset are automatically identified as such
614/// and will be precalculated when fitting to a dataset
615///
616/// By forcibly precalculating functions with non-trivial Jacobians,
617/// or functions of multiple variables occurring in the data set,
618/// using addColumn(), you may alter the outcome of the fit.
619///
620/// Only in cases where such a modification of fit behaviour is intentional,
621/// this function should be used.
622
623RooAbsArg* RooVectorDataStore::addColumn(RooAbsArg& newVar, bool /*adjustRange*/)
624{
625 // Create a fundamental object of the right type to hold newVar values
626 auto valHolder = std::unique_ptr<RooAbsArg>{newVar.createFundamental()}.release();
627 // Sanity check that the holder really is fundamental
628 if(!valHolder->isFundamental()) {
629 coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
630 << valHolder->GetName() << "\"" << endl;
631 return nullptr;
632 }
633
634 // Attention: need to do this now, as adding an empty column might give 0 as size
635 const std::size_t numEvt = size();
636
637 // Clone variable and attach to cloned tree
638 std::unique_ptr<RooAbsArg> newVarClone{newVar.cloneTree()};
639 newVarClone->recursiveRedirectServers(_vars,false) ;
640
641 // Attach value place holder to this tree
642 valHolder->attachToVStore(*this) ;
643 _vars.add(*valHolder) ;
644 _varsww.add(*valHolder) ;
645
646 // Fill values of placeholder
647 RealVector* rv(nullptr) ;
648 CatVector* cv(nullptr) ;
649 assert(numEvt != 0);
650 if (dynamic_cast<RooAbsReal*>(valHolder)) {
651 rv = addReal(static_cast<RooAbsReal*>(valHolder));
652 rv->resize(numEvt) ;
653 } else if (dynamic_cast<RooAbsCategory*>(static_cast<RooAbsCategory*>(valHolder))) {
654 cv = addCategory(static_cast<RooAbsCategory*>(valHolder)) ;
655 cv->resize(numEvt) ;
656 }
657
658 for (std::size_t i=0; i < numEvt; i++) {
659 get(i) ;
660
661 newVarClone->syncCache(&_vars) ;
662 valHolder->copyCache(newVarClone.get()) ;
663
664 if (rv) rv->write(i) ;
665 if (cv) cv->write(i) ;
666 }
667
668 return valHolder ;
669}
670
671
672
673////////////////////////////////////////////////////////////////////////////////
674/// Merge columns of supplied data set(s) with this data set. All
675/// data sets must have equal number of entries. In case of
676/// duplicate columns the column of the last dataset in the list
677/// prevails
678
679RooAbsDataStore* RooVectorDataStore::merge(const RooArgSet& allVars, list<RooAbsDataStore*> dstoreList)
680{
681 RooVectorDataStore* mergedStore = new RooVectorDataStore("merged","merged",allVars) ;
682
683 const auto nevt = dstoreList.front()->numEntries();
684 mergedStore->reserve(nevt);
685 for (int i=0 ; i<nevt ; i++) {
686
687 // Copy data from self
688 mergedStore->_vars.assign(*get(i)) ;
689
690 // Copy variables from merge sets
691 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
692 const RooArgSet* partSet = (*iter)->get(i) ;
693 mergedStore->_vars.assign(*partSet) ;
694 }
695
696 mergedStore->fill() ;
697 }
698 return mergedStore ;
699}
700
701
702
704{
705 for (auto elm : _realStoreList) {
706 elm->reserve(nEvts);
707 }
708
709 for (auto elm : _realfStoreList) {
710 elm->reserve(nEvts);
711 }
712
713 for (auto elm : _catStoreList) {
714 elm->reserve(nEvts);
715 }
716}
717
718////////////////////////////////////////////////////////////////////////////////
719
721{
722 Int_t nevt = other.numEntries() ;
723 reserve(nevt + numEntries());
724 for (int i=0 ; i<nevt ; i++) {
725 _vars.assign(*other.get(i)) ;
726 if (_wgtVar) {
727 _wgtVar->setVal(other.weight()) ;
728 }
729
730 fill() ;
731 }
732}
733
734
735
736////////////////////////////////////////////////////////////////////////////////
737
739{
741
742 for (auto elm : _realStoreList) {
743 elm->reset() ;
744 }
745
746 for (auto elm : _realfStoreList) {
747 elm->reset() ;
748 }
749
750 for (auto elm : _catStoreList) {
751 elm->reset() ;
752 }
753
754}
755
756////////////////////////////////////////////////////////////////////////////////
757/// Cache given RooAbsArgs: The tree is
758/// given direct write access of the args internal cache
759/// the args values is pre-calculated for all data points
760/// in this data collection. Upon a get() call, the
761/// internal cache of 'newVar' will be loaded with the
762/// precalculated value and it's dirty flag will be cleared.
763
764void RooVectorDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, const RooArgSet* nset, bool skipZeroWeights)
765{
766 // Delete previous cache, if any
767 delete _cache ;
768 _cache = nullptr ;
769
770 // Reorder cached elements. First constant nodes, then tracked nodes in order of dependence
771
772 // Step 1 - split in constant and tracked
773 RooArgSet newVarSetCopy(newVarSet);
774 RooArgSet orderedArgs;
775 vector<RooAbsArg*> trackArgs;
776 for (const auto arg : newVarSetCopy) {
777 if (arg->getAttribute("ConstantExpression") && !arg->getAttribute("NOCacheAndTrack")) {
778 orderedArgs.add(*arg) ;
779 } else {
780
781 // Explicitly check that arg depends on any of the observables, if this
782 // is not the case, skip it, as inclusion would result in repeated
783 // calculation of a function that has the same value for every event
784 // in the likelihood
785 if (arg->dependsOn(_vars) && !arg->getAttribute("NOCacheAndTrack")) {
786 trackArgs.push_back(arg) ;
787 } else {
788 newVarSet.remove(*arg) ;
789 }
790 }
791 }
792
793 // Step 2 - reorder tracked nodes
794 std::sort(trackArgs.begin(), trackArgs.end(), [](RooAbsArg* left, RooAbsArg* right){
795 //LM: exclude same comparison. This avoids an issue when using sort in MacOS versions
796 if (left == right) return false;
797 return right->dependsOn(*left);
798 });
799
800 // Step 3 - put back together
801 for (const auto trackedArg : trackArgs) {
802 orderedArgs.add(*trackedArg);
803 }
804
805 // WVE need to prune tracking entries _below_ constant nodes as the're not needed
806// cout << "Number of Cache-and-Tracked args are " << trackArgs.size() << endl ;
807// cout << "Compound ordered cache parameters = " << endl ;
808// orderedArgs.Print("v") ;
809
810 checkInit() ;
811
812 std::vector<std::unique_ptr<RooArgSet>> vlist;
813 RooArgList cloneSet;
814
815 for (const auto var : orderedArgs) {
816
817 // Clone variable and attach to cloned tree
818 auto newVarCloneList = std::make_unique<RooArgSet>();
819 RooArgSet(*var).snapshot(*newVarCloneList);
820 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
821 newVarClone->recursiveRedirectServers(_vars,false) ;
822
823 vlist.emplace_back(std::move(newVarCloneList));
824 cloneSet.add(*newVarClone) ;
825 }
826
827 _cacheOwner = const_cast<RooAbsArg *>(owner);
828 RooVectorDataStore* newCache = new RooVectorDataStore("cache","cache",orderedArgs) ;
829
830
832
833 std::vector<RooArgSet*> nsetList ;
834 std::vector<std::unique_ptr<RooArgSet>> argObsList ;
835
836 // Now need to attach branch buffers of clones
837 for (const auto arg : cloneSet) {
838 arg->attachToVStore(*newCache) ;
839
840 if(nset) argObsList.emplace_back(arg->getObservables(*nset));
841 else argObsList.emplace_back(arg->getVariables());
842 RooArgSet* argObs = argObsList.back().get();
843
844 RooArgSet* normSet(nullptr) ;
845 const char* catNset = arg->getStringAttribute("CATNormSet") ;
846 if (catNset) {
847// cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a normalization set specification CATNormSet = " << catNset << endl ;
848
849 RooArgSet anset = RooHelpers::selectFromArgSet(nset ? *nset : RooArgSet{}, catNset);
850 normSet = anset.selectCommon(*argObs);
851
852 }
853 const char* catCset = arg->getStringAttribute("CATCondSet") ;
854 if (catCset) {
855// cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a conditional observable set specification CATCondSet = " << catCset << endl ;
856
857 RooArgSet acset = RooHelpers::selectFromArgSet(nset ? *nset : RooArgSet{}, catCset);
858 argObs->remove(acset,true,true) ;
859 normSet = argObs ;
860 }
861
862 // now construct normalization set for component from cset/nset spec
863// if (normSet) {
864// cout << "RooVectorDaraStore::cacheArgs() component " << arg->GetName() << " has custom normalization set " << *normSet << endl ;
865// }
866 nsetList.push_back(normSet) ;
867 }
868
869
870 // Fill values of placeholder
871 const std::size_t numEvt = size();
872 newCache->reserve(numEvt);
873 for (std::size_t i=0; i < numEvt; i++) {
874 get(i) ;
875 if (weight()!=0 || !skipZeroWeights) {
876 for (unsigned int j = 0; j < cloneSet.size(); ++j) {
877 auto& cloneArg = cloneSet[j];
878 auto argNSet = nsetList[j];
879 // WVE need to intervene here for condobs from ProdPdf
880 cloneArg.syncCache(argNSet ? argNSet : nset) ;
881 }
882 }
883 newCache->fill() ;
884 }
885
887
888
889 // Now need to attach branch buffers of original function objects
890 for (const auto arg : orderedArgs) {
891 arg->attachToVStore(*newCache) ;
892
893 // Activate change tracking mode, if requested
894 if (!arg->getAttribute("ConstantExpression") && dynamic_cast<RooAbsReal*>(arg)) {
895 RealVector* rv = newCache->addReal(static_cast<RooAbsReal*>(arg)) ;
896 RooArgSet deps;
897 arg->getParameters(&_vars, deps);
898 rv->setDependents(deps) ;
899
900 // WV lookup normalization set and associate with RealVector
901 // find ordinal number of arg in original list
902 Int_t idx = cloneSet.index(arg->GetName()) ;
903
904 coutI(Optimization) << "RooVectorDataStore::cacheArg() element " << arg->GetName() << " has change tracking enabled on parameters " << deps << endl ;
905 rv->setNset(nsetList[idx]) ;
906 }
907
908 }
909
910 _cache = newCache ;
912}
913
914
916{
917 if (_cache) _forcedUpdate = true ;
918}
919
920
921
922////////////////////////////////////////////////////////////////////////////////
923
924void RooVectorDataStore::recalculateCache( const RooArgSet *projectedArgs, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, bool skipZeroWeights)
925{
926 if (!_cache) return ;
927
928 std::vector<RooVectorDataStore::RealVector *> tv;
929 tv.reserve(static_cast<std::size_t>(_cache->_realStoreList.size() * 0.7)); // Typically, 30..60% need to be recalculated
930
931 // Check which items need recalculation
932 for (const auto realVec : _cache->_realStoreList) {
933 if (_forcedUpdate || realVec->needRecalc()) {
934 tv.push_back(realVec);
935 realVec->_nativeReal->setOperMode(RooAbsArg::ADirty);
936 realVec->_nativeReal->_operMode = RooAbsArg::Auto;
937 }
938 }
939 _forcedUpdate = false ;
940
941 // If no recalculations are needed stop here
942 if (tv.empty()) {
943 return;
944 }
945
946
947 // Refill caches of elements that require recalculation
948 std::unique_ptr<RooArgSet> ownedNset;
949 RooArgSet* usedNset = nullptr;
950 if (projectedArgs && !projectedArgs->empty()) {
951 ownedNset = std::make_unique<RooArgSet>();
952 _vars.snapshot(*ownedNset, false) ;
953 ownedNset->remove(*projectedArgs,false,true);
954 usedNset = ownedNset.get();
955 } else {
956 usedNset = &_vars ;
957 }
958
959
960 for (int i=firstEvent ; i<lastEvent ; i+=stepSize) {
961 get(i) ;
962 bool zeroWeight = (weight()==0) ;
963 if (!zeroWeight || !skipZeroWeights) {
964 for (auto realVector : tv) {
965 realVector->_nativeReal->_valueDirty = true;
966 realVector->_nativeReal->getValV(realVector->_nset ? realVector->_nset : usedNset);
967 realVector->write(i);
968 }
969 }
970 }
971
972 for (auto realVector : tv) {
973 realVector->_nativeReal->setOperMode(RooAbsArg::AClean);
974 }
975}
976
977
978////////////////////////////////////////////////////////////////////////////////
979/// Initialize cache of dataset: attach variables of cache ArgSet
980/// to the corresponding TTree branches
981
982void RooVectorDataStore::attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVarsIn)
983{
984 // Only applicable if a cache exists
985 if (!_cache) return ;
986
987 // Clone constructor, must connect internal storage to given new external set of variables
988 std::vector<RealVector*> cacheElements(_cache->realStoreList());
989 cacheElements.insert(cacheElements.end(), _cache->_realfStoreList.begin(), _cache->_realfStoreList.end());
990
991 for (const auto elm : cacheElements) {
992 auto real = static_cast<RooAbsReal*>(cachedVarsIn.find(elm->bufArg()->GetName()));
993 if (real) {
994 // Adjust buffer pointer
995 real->attachToVStore(*_cache) ;
996 }
997 }
998
999 for (const auto catVec : _cache->_catStoreList) {
1000 auto cat = static_cast<RooAbsCategory*>(cachedVarsIn.find(catVec->bufArg()->GetName()));
1001 if (cat) {
1002 // Adjust buffer pointer
1003 cat->attachToVStore(*_cache) ;
1004 }
1005 }
1006
1007 _cacheOwner = const_cast<RooAbsArg*>(newOwner);
1008}
1009
1010
1011
1012
1013////////////////////////////////////////////////////////////////////////////////
1014
1016{
1017 delete _cache;
1018 _cache = nullptr;
1019 _cacheOwner = nullptr;
1020 return ;
1021}
1022
1023
1024
1025
1026
1027////////////////////////////////////////////////////////////////////////////////
1028/// Disabling of branches is (intentionally) not implemented in vector
1029/// data stores (as the doesn't result in a net saving of time)
1030
1031void RooVectorDataStore::setArgStatus(const RooArgSet& /*set*/, bool /*active*/)
1032{
1033 return ;
1034}
1035
1036
1037
1038
1039////////////////////////////////////////////////////////////////////////////////
1040
1042{
1043 for (auto arg : _varsww) {
1044 RooAbsArg* extArg = extObs.find(arg->GetName()) ;
1045 if (extArg) {
1046 extArg->attachToVStore(*this) ;
1047 }
1048 }
1049}
1050
1051
1052
1053////////////////////////////////////////////////////////////////////////////////
1054
1056{
1057 for (auto arg : _varsww) {
1058 arg->attachToVStore(*this);
1059 }
1060}
1061
1062
1063
1064////////////////////////////////////////////////////////////////////////////////
1065
1067{
1068 cout << "RooVectorDataStor::dump()" << endl ;
1069
1070 cout << "_varsww = " << endl ; _varsww.Print("v") ;
1071 cout << "realVector list is" << endl ;
1072
1073 for (const auto elm : _realStoreList) {
1074 cout << "RealVector " << elm << " _nativeReal = " << elm->_nativeReal << " = " << elm->_nativeReal->GetName() << " bufptr = " << elm->_buf << endl ;
1075 cout << " values : " ;
1076 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1077 for (Int_t i=0 ; i<imax ; i++) {
1078 cout << elm->_vec[i] << " " ;
1079 }
1080 cout << endl ;
1081 }
1082
1083 for (const auto elm : _realfStoreList) {
1084 cout << "RealFullVector " << elm << " _nativeReal = " << elm->_nativeReal << " = " << elm->_nativeReal->GetName()
1085 << " bufptr = " << elm->_buf << " errbufptr = " << elm->bufE() << endl ;
1086
1087 cout << " values : " ;
1088 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1089 for (Int_t i=0 ; i<imax ; i++) {
1090 cout << elm->_vec[i] << " " ;
1091 }
1092 cout << endl ;
1093 if (elm->bufE()) {
1094 cout << " errors : " ;
1095 for (Int_t i=0 ; i<imax ; i++) {
1096 cout << elm->dataE()[i] << " " ;
1097 }
1098 cout << endl ;
1099
1100 }
1101 }
1102}
1103
1104
1105////////////////////////////////////////////////////////////////////////////////
1106/// Stream an object of class RooVectorDataStore.
1107
1109{
1110 if (R__b.IsReading()) {
1112
1113 for (auto elm : _realStoreList) {
1114 RooAbsArg* arg = _varsww.find(elm->_nativeReal->GetName()) ;
1115 arg->attachToVStore(*this) ;
1116 }
1117 for (auto elm : _realfStoreList) {
1118 RooAbsArg* arg = _varsww.find(elm->_nativeReal->GetName()) ;
1119 arg->attachToVStore(*this) ;
1120 }
1121 for (auto elm : _catStoreList) {
1122 RooAbsArg* arg = _varsww.find(elm->_cat->GetName()) ;
1123 arg->attachToVStore(*this) ;
1124 }
1125
1126 } else {
1128 }
1129}
1130
1131
1132////////////////////////////////////////////////////////////////////////////////
1133/// Return batches of the data columns for the requested events.
1134/// \param[in] first First event in the batches.
1135/// \param[in] len Number of events in batches.
1136/// \return Spans with the associated data.
1137RooAbsData::RealSpans RooVectorDataStore::getBatches(std::size_t first, std::size_t len) const {
1138 RooAbsData::RealSpans evalData;
1139
1140 auto emplace = [this,&evalData,first,len](const RealVector* realVec) {
1141 auto span = realVec->getRange(first, first + len);
1142 auto result = evalData.emplace(realVec->_nativeReal, span);
1143 if (result.second == false || result.first->second.size() != len) {
1144 const auto size = result.second ? result.first->second.size() : 0;
1145 coutE(DataHandling) << "A batch of data for '" << realVec->_nativeReal->GetName()
1146 << "' was requested from " << first << " to " << first+len
1147 << ", but only the events [" << first << ", " << first + size << ") are available." << std::endl;
1148 }
1149 if (realVec->_real) {
1150 // If a buffer is attached, i.e. we are ready to load into a RooAbsReal outside of our dataset,
1151 // we can directly map our spans to this real.
1152 evalData.emplace(realVec->_real, span);
1153 }
1154 };
1155
1156 for (const auto realVec : _realStoreList) {
1157 emplace(realVec);
1158 }
1159 for (const auto realVec : _realfStoreList) {
1160 emplace(realVec);
1161 }
1162
1163 if (_cache) {
1164 for (const auto realVec : _cache->_realStoreList) {
1165 emplace(realVec);
1166 }
1167 for (const auto realVec : _cache->_realfStoreList) {
1168 emplace(realVec);
1169 }
1170 }
1171
1172 return evalData;
1173}
1174
1175
1178
1179 auto emplace = [this,&evalData,first,len](const CatVector* catVec) {
1180 auto span = catVec->getRange(first, first + len);
1181 auto result = evalData.emplace(catVec->_cat, span);
1182 if (result.second == false || result.first->second.size() != len) {
1183 const auto size = result.second ? result.first->second.size() : 0;
1184 coutE(DataHandling) << "A batch of data for '" << catVec->_cat->GetName()
1185 << "' was requested from " << first << " to " << first+len
1186 << ", but only the events [" << first << ", " << first + size << ") are available." << std::endl;
1187 }
1188 };
1189
1190 for (const auto& catVec : _catStoreList) {
1191 emplace(catVec);
1192 }
1193
1194 return evalData;
1195}
1196
1197
1198////////////////////////////////////////////////////////////////////////////////
1199/// Return the weights of all events in the range [first, first+len).
1200/// If an array with weights is stored, a batch with these weights will be returned. If
1201/// no weights are stored, an empty batch is returned. Use weight() to check if there's
1202/// a constant weight.
1203std::span<const double> RooVectorDataStore::getWeightBatch(std::size_t first, std::size_t len) const
1204{
1205 if (_extWgtArray) {
1206 return std::span<const double>(_extWgtArray + first, _extWgtArray + first + len);
1207 }
1208
1209 if (_wgtVar) {
1210 auto findWeightVar = [this](const RealVector* realVec) {
1211 return realVec->_nativeReal == _wgtVar || realVec->_nativeReal->GetName() == _wgtVar->GetName();
1212 };
1213
1214 auto storageIter = std::find_if(_realStoreList.begin(), _realStoreList.end(), findWeightVar);
1215 if (storageIter != _realStoreList.end())
1216 return (*storageIter)->getRange(first, first + len);
1217
1218 auto fstorageIter = std::find_if(_realfStoreList.begin(), _realfStoreList.end(), findWeightVar);
1219 if (fstorageIter != _realfStoreList.end())
1220 return (*fstorageIter)->getRange(first, first + len);
1221
1222 throw std::logic_error("RooVectorDataStore::getWeightBatch(): Could not retrieve data for _wgtVar.");
1223 }
1224 return {};
1225}
1226
1227
1229
1230 // First try a match by name
1231 for (auto catVec : _catStoreList) {
1232 if (std::string(catVec->bufArg()->GetName())==cat->GetName()) {
1233 return catVec;
1234 }
1235 }
1236
1237 // If nothing found this will make an entry
1238 _catStoreList.push_back(new CatVector(cat)) ;
1239
1240 return _catStoreList.back() ;
1241}
1242
1243
1245
1246 // First try a match by name
1247 for (auto realVec : _realStoreList) {
1248 if (realVec->bufArg()->namePtr()==real->namePtr()) {
1249 return realVec;
1250 }
1251 }
1252
1253 // Then check if an entry already exists for a full real
1254 for (auto fullVec : _realfStoreList) {
1255 if (fullVec->bufArg()->namePtr()==real->namePtr()) {
1256 // Return full vector as RealVector base class here
1257 return fullVec;
1258 }
1259 }
1260
1261 // If nothing found this will make an entry
1262 _realStoreList.push_back(new RealVector(real)) ;
1263
1264 return _realStoreList.back() ;
1265}
1266
1267
1269
1270 // First try a match by name
1271 for (auto fullVec : _realfStoreList) {
1272 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1273 return true ;
1274 }
1275 }
1276 return false ;
1277}
1278
1279
1281
1282 // First try a match by name
1283 for (auto fullVec : _realfStoreList) {
1284 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1285 return fullVec->bufE();
1286 }
1287 }
1288 return false ;
1289}
1290
1291
1293
1294 // First try a match by name
1295 for (auto fullVec : _realfStoreList) {
1296 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1297 return fullVec->bufEL();
1298 }
1299 }
1300 return false ;
1301}
1302
1303
1305
1306 // First try a match by name
1307 for (auto fullVec : _realfStoreList) {
1308 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1309 return fullVec;
1310 }
1311 }
1312
1313 // Then check if an entry already exists for a bare real
1314 for (auto realVec : _realStoreList) {
1315 if (std::string(realVec->bufArg()->GetName())==real->GetName()) {
1316
1317 // Convert element to full and add to full list
1318 _realfStoreList.push_back(new RealFullVector(*realVec,real)) ;
1319
1320 // Delete bare element
1321 _realStoreList.erase(std::find(_realStoreList.begin(), _realStoreList.end(), realVec));
1322 delete realVec;
1323
1324 return _realfStoreList.back() ;
1325 }
1326 }
1327
1328 // If nothing found this will make an entry
1329 _realfStoreList.push_back(new RealFullVector(real)) ;
1330
1331 return _realfStoreList.back() ;
1332}
1333
1334
1335/// Trigger a recomputation of the cached weight sums. Meant for use by RooFit
1336/// dataset converter functions such as the NumPy converter functions
1337/// implemented as pythonizations.
1339 double const* arr = nullptr;
1340 if (_extWgtArray) {
1341 arr = _extWgtArray;
1342 }
1343 if (_wgtVar) {
1344 const std::string wgtName = _wgtVar->GetName();
1345 for(auto const* real : _realStoreList) {
1346 if(wgtName == real->_nativeReal->GetName())
1347 arr = real->_vec.data();
1348 }
1349 for(auto const* real : _realfStoreList) {
1350 if(wgtName == real->_nativeReal->GetName())
1351 arr = real->_vec.data();
1352 }
1353 }
1354 if(arr == nullptr) {
1355 _sumWeight = size();
1356 return;
1357 }
1359 _sumWeight = result.Sum();
1360 _sumWeightCarry = result.Carry();
1361}
1362
1363
1364/// Exports all arrays in this RooVectorDataStore into a simple datastructure
1365/// to be used by RooFit internal export functions.
1367 ArraysStruct out;
1368 out.size = size();
1369
1370 for(auto const* real : _realStoreList) {
1371 out.reals.emplace_back(real->_nativeReal->GetName(), real->_vec.data());
1372 }
1373 for(auto const* realf : _realfStoreList) {
1374 std::string name = realf->_nativeReal->GetName();
1375 out.reals.emplace_back(name, realf->_vec.data());
1376 if(realf->bufE()) out.reals.emplace_back(name + "Err", realf->dataE().data());
1377 if(realf->bufEL()) out.reals.emplace_back(name + "ErrLo", realf->dataEL().data());
1378 if(realf->bufEH()) out.reals.emplace_back(name + "ErrHi", realf->dataEH().data());
1379 }
1380 for(auto const* cat : _catStoreList) {
1381 out.cats.emplace_back(cat->_cat->GetName(), cat->_vec.data());
1382 }
1383
1384 if(_extWgtArray) out.reals.emplace_back("weight", _extWgtArray);
1385 if(_extWgtErrLoArray) out.reals.emplace_back("wgtErrLo", _extWgtErrLoArray);
1386 if(_extWgtErrHiArray) out.reals.emplace_back("wgtErrHi", _extWgtErrHiArray);
1387 if(_extSumW2Array) out.reals.emplace_back("sumW2",_extSumW2Array);
1388
1389 return out;
1390}
#define coutI(a)
#define coutE(a)
#define TRACE_DESTROY
Definition RooTrace.h:24
#define TRACE_CREATE
Definition RooTrace.h:23
int Int_t
Definition RtypesCore.h:45
#define ClassImp(name)
Definition Rtypes.h:382
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
#define hi
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
static KahanSum< T, N > Accumulate(Iterator begin, Iterator end, T initialValue=T{})
Iterate over a range and return an instance of a KahanSum.
Definition Util.h:211
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
Definition RooAbsArg.h:504
virtual RooFit::OwningPtr< RooAbsArg > createFundamental(const char *newname=nullptr) const =0
Create a fundamental-type object that stores our type of value.
static void setDirtyInhibit(bool flag)
Control global dirty inhibit mode.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
virtual RooAbsArg * cloneTree(const char *newname=nullptr) const
Clone tree expression of objects.
virtual void attachToVStore(RooVectorDataStore &vstore)=0
A space to attach TBranches.
void attachToVStore(RooVectorDataStore &vstore) override
Attach the category index and label to as branches to the given vector store.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
Storage_t const & get() const
Const access to the underlying stl container.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
Storage_t::size_type size() const
RooAbsArg * find(const char *name) const
Find object with given name in list.
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
Abstract base class for a data collection.
virtual const RooArgSet * get(Int_t index) const =0
virtual void checkInit() const
bool _doDirtyProp
Switch do (de)activate dirty state propagation when loading a data point.
virtual double weight() const =0
virtual Int_t numEntries() const =0
std::map< RooFit::Detail::DataKey, std::span< const double > > RealSpans
Definition RooAbsData.h:131
std::map< RooFit::Detail::DataKey, std::span< const RooAbsCategory::value_type > > CategorySpans
Definition RooAbsData.h:132
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
void attachToVStore(RooVectorDataStore &vstore) override
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:154
RooArgSet * selectCommon(const RooAbsCollection &refColl) const
Use RooAbsCollection::selecCommon(), but return as RooArgSet.
Definition RooArgSet.h:149
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
bool getPoissonInterval(Int_t n, double &mu1, double &mu2, double nSigma=1) const
Return a confidence interval for the expected number of events given n observed (unweighted) events.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
void setVal(double value) override
Set value of variable to 'value'.
double getError() const
Definition RooRealVar.h:58
bool hasError(bool allowZero=true) const
Definition RooRealVar.h:59
bool hasAsymError(bool allowZero=true) const
Definition RooRealVar.h:64
double getAsymErrorHi() const
Definition RooRealVar.h:63
double getAsymErrorLo() const
Definition RooRealVar.h:62
The RooStringView is a wrapper around a C-style string that can also be constructed from a std::strin...
TTree-backed data storage.
const RooArgSet * get(Int_t index) const override
Load the n-th data point (n='index') in memory and return a pointer to the internal RooArgSet holding...
Int_t numEntries() const override
RooArgSet _varsww
Was object constructed with default ctor?
void setNset(RooArgSet *newNset)
void setDependents(const RooArgSet &deps)
Uses std::vector to store data columns.
void recalculateCache(const RooArgSet *, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, bool skipZeroWeights) override
void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars) override
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
std::vector< RealFullVector * > _realfStoreList
Int_t numEntries() const override
RooAbsArg * addColumn(RooAbsArg &var, bool adjustRange=true) override
Add a new column to the data set which holds the pre-calculated values of 'newVar'.
RooVectorDataStore * _cache
! Optimization cache
const double * _extWgtErrHiArray
! External weight array - high error
std::span< const double > getWeightBatch(std::size_t first, std::size_t len) const override
Return the weights of all events in the range [first, first+len).
~RooVectorDataStore() override
Destructor.
static TClass * Class()
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return pointer to weight variable if it is defined.
void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=nullptr, bool skipZeroWeights=true) override
Cache given RooAbsArgs: The tree is given direct write access of the args internal cache the args val...
RooRealVar * _wgtVar
Pointer to weight variable (if set)
std::vector< RealVector * > _realStoreList
CatVector * addCategory(RooAbsCategory *cat)
void loadValues(const RooAbsDataStore *tds, const RooFormulaVar *select=nullptr, const char *rangeName=nullptr, std::size_t nStart=0, std::size_t nStop=std::numeric_limits< std::size_t >::max()) override
const RooArgSet * get(Int_t index) const override
Load the n-th data point (n='index') into the variables of this dataset, and return a pointer to the ...
RealFullVector * addRealFull(RooAbsReal *real)
double weight() const override
Return the weight of the last-retrieved data point.
RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const override
Return batches of the data columns for the requested events.
bool isFullReal(RooAbsReal *real)
Int_t fill() override
Interface function to TTree::Fill.
const double * _extWgtErrLoArray
! External weight array - low error
bool _forcedUpdate
! Request for forced cache update
void append(RooAbsDataStore &other) override
bool hasError(RooAbsReal *real)
std::vector< CatVector * > _catStoreList
void setArgStatus(const RooArgSet &set, bool active) override
Disabling of branches is (intentionally) not implemented in vector data stores (as the doesn't result...
double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override
Return the error of the current weight.
void attachBuffers(const RooArgSet &extObs) override
ArraysStruct getArrays() const
Exports all arrays in this RooVectorDataStore into a simple datastructure to be used by RooFit intern...
RooAbsData::CategorySpans getCategoryBatches(std::size_t, std::size_t len) const override
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList) override
Merge columns of supplied data set(s) with this data set.
void setDirtyProp(bool flag) override
RealVector * addReal(RooAbsReal *real)
bool hasAsymError(RooAbsReal *real)
bool changeObservableName(const char *from, const char *to) override
void forceCacheUpdate() override
const double * _extSumW2Array
! External sum of weights array
void recomputeSumWeight()
Trigger a recomputation of the cached weight sums.
std::vector< RealVector * > & realStoreList()
std::size_t size() const
Get size of stored dataset.
std::unique_ptr< RooAbsDataStore > reduce(RooStringView name, RooStringView title, const RooArgSet &vars, const RooFormulaVar *cutVar, const char *cutRange, std::size_t nStart, std::size_t nStop) override
virtual const RooArgSet * get() const
const double * _extWgtArray
! External weight array
void Streamer(TBuffer &) override
Stream an object of class RooVectorDataStore.
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
RooAbsArg * _cacheOwner
! Cache owner
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
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
Double_t y[n]
Definition legend1.C:17
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
RooArgSet selectFromArgSet(RooArgSet const &, std::string const &names)
Output struct for the RooVectorDataStore::getArrays() helper function.