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
22RooVectorDataStore uses std::vectors 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 namespace std;
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 ctor
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, (RooAbsReal*)_varsww.find(realVec->_nativeReal->GetName()))) ;
154 }
155
156 for (const auto realFullVec : other._realfStoreList) {
157 _realfStoreList.push_back(new RealFullVector(*realFullVec, (RooAbsReal*)_varsww.find(realFullVec->_nativeReal->GetName()))) ;
158 }
159
160 for (const auto catVec : other._catStoreList) {
161 _catStoreList.push_back(new CatVector(*catVec, (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 ctor, must connect internal storage to given new external set of vars
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 = (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 = (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, hi = 0 ;
398 weightError(lo,hi,etype) ;
399 return (lo+hi)/2 ;
400
401 } else if (_wgtVar) {
402
403 // We have a weight variable, use that info
404 if (_wgtVar->hasAsymError()) {
405 return ( _wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo() ) / 2 ;
406 } else if (_wgtVar->hasError(false)) {
407 return _wgtVar->getError();
408 } else {
409 return 0 ;
410 }
411
412 } else {
413
414 // We have no weights
415 return 0 ;
416
417 }
418}
419
420
421
422////////////////////////////////////////////////////////////////////////////////
423
424void RooVectorDataStore::weightError(double& lo, double& hi, RooAbsData::ErrorType etype) const
425{
426 if (_extWgtArray) {
427 double wgt;
428
429 // We have a weight array, use that info
430 switch (etype) {
431
432 case RooAbsData::Auto:
433 throw string(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
434 break ;
435
437 throw string(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
438 break ;
439
441 // Weight may be preset or precalculated
445 return ;
446 }
447
448 // Otherwise Calculate poisson errors
449 wgt = weight();
450 double ym,yp ;
452 lo = wgt-ym;
453 hi = yp-wgt;
454 return ;
455
458 hi = lo;
459 return ;
460
461 case RooAbsData::None:
462 lo = 0 ;
463 hi = 0 ;
464 return ;
465 }
466
467 } else if (_wgtVar) {
468
469 // We have a weight variable, use that info
470 if (_wgtVar->hasAsymError()) {
472 lo = _wgtVar->getAsymErrorLo() ;
473 } else {
474 hi = _wgtVar->getError() ;
475 lo = _wgtVar->getError() ;
476 }
477
478 } else {
479
480 // We are unweighted
481 lo=0 ;
482 hi=0 ;
483
484 }
485}
486
487
488
489////////////////////////////////////////////////////////////////////////////////
490///
491
492void RooVectorDataStore::loadValues(const RooAbsDataStore *ads, const RooFormulaVar* select, const char* rangeName, std::size_t nStart, std::size_t nStop)
493{
494 // Load values from dataset 't' into this data collection, optionally
495 // selecting events using 'select' RooFormulaVar
496 //
497
498 // Redirect formula servers to source data row
499 std::unique_ptr<RooFormulaVar> selectClone;
500 if (select) {
501 selectClone.reset( static_cast<RooFormulaVar*>(select->cloneTree()) );
502 selectClone->recursiveRedirectServers(*ads->get()) ;
503 selectClone->setOperMode(RooAbsArg::ADirty,true) ;
504 }
505
506 // Force DS internal initialization
507 ads->get(0) ;
508
509 // Loop over events in source tree
510 const auto numEntr = static_cast<std::size_t>(ads->numEntries());
511 const std::size_t nevent = nStop < numEntr ? nStop : numEntr;
512
513 auto treeDS = dynamic_cast<const RooTreeDataStore*>(ads);
514 auto vectorDS = dynamic_cast<const RooVectorDataStore*>(ads);
515
516 // Check if weight is being renamed - if so set flag to enable special handling in copy loop
517 bool weightRename(false) ;
518 const bool newWeightVar = _wgtVar ? _wgtVar->getAttribute("NewWeight") : false ;
519
520 if (_wgtVar && vectorDS && vectorDS->_wgtVar) {
521 if (std::string(_wgtVar->GetName()) != vectorDS->_wgtVar->GetName() && !newWeightVar) {
522 weightRename=true ;
523 }
524 }
525 if (_wgtVar && treeDS && treeDS->_wgtVar) {
526 if (std::string(_wgtVar->GetName()) != treeDS->_wgtVar->GetName() && !newWeightVar) {
527 weightRename=true ;
528 }
529 }
530
531 std::vector<std::string> ranges;
532 if (rangeName) {
533 ranges = ROOT::Split(rangeName, ",");
534 }
535
536 reserve(numEntries() + (nevent - nStart));
537 for(auto i=nStart; i < nevent ; ++i) {
538 ads->get(i);
539
540 // Does this event pass the cuts?
541 if (selectClone && selectClone->getVal()==0) {
542 continue ;
543 }
544
545 RooArgSet const* otherVarsww = nullptr;
546
547 if (treeDS) {
548 otherVarsww = &treeDS->_varsww;
549 if (weightRename) {
550 _wgtVar->setVal(treeDS->_wgtVar->getVal()) ;
551 }
552 } else if (vectorDS) {
553 otherVarsww = &vectorDS->_varsww;
554 if (weightRename) {
555 _wgtVar->setVal(vectorDS->_wgtVar->getVal()) ;
556 }
557 } else {
558 otherVarsww = ads->get();
559 }
560
561 // Check that all copied values are valid and in range
562 bool allValid = true;
563 for (const auto arg : *otherVarsww) {
564 allValid &= arg->isValid();
565 if (allValid && !ranges.empty()) {
566 // If we have one or multiple ranges to be selected, the value
567 // must be in one of them to be valid
568 allValid &= std::any_of(ranges.begin(), ranges.end(), [arg](const std::string& range){
569 return arg->inRange(range.c_str());});
570 }
571 if (!allValid)
572 break ;
573 }
574
575 if (!allValid) {
576 continue ;
577 }
578
579 _varsww.assign(*otherVarsww) ;
580
581 fill() ;
582 }
583
584 SetTitle(ads->GetTitle());
585}
586
587
588
589
590
591////////////////////////////////////////////////////////////////////////////////
592
593bool RooVectorDataStore::changeObservableName(const char* /*from*/, const char* /*to*/)
594{
595 return false ;
596}
597
598
599
600////////////////////////////////////////////////////////////////////////////////
601/// Add a new column to the data set which holds the pre-calculated values
602/// of 'newVar'. This operation is only meaningful if 'newVar' is a derived
603/// value.
604///
605/// The return value points to the added element holding 'newVar's value
606/// in the data collection. The element is always the corresponding fundamental
607/// type of 'newVar' (e.g. a RooRealVar if 'newVar' is a RooFormulaVar)
608///
609/// Note: This function is explicitly NOT intended as a speed optimization
610/// opportunity for the user. Components of complex PDFs that can be
611/// precalculated with the dataset are automatically identified as such
612/// and will be precalculated when fitting to a dataset
613///
614/// By forcibly precalculating functions with non-trivial Jacobians,
615/// or functions of multiple variables occurring in the data set,
616/// using addColumn(), you may alter the outcome of the fit.
617///
618/// Only in cases where such a modification of fit behaviour is intentional,
619/// this function should be used.
620
621RooAbsArg* RooVectorDataStore::addColumn(RooAbsArg& newVar, bool /*adjustRange*/)
622{
623 // Create a fundamental object of the right type to hold newVar values
624 auto valHolder = std::unique_ptr<RooAbsArg>{newVar.createFundamental()}.release();
625 // Sanity check that the holder really is fundamental
626 if(!valHolder->isFundamental()) {
627 coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
628 << valHolder->GetName() << "\"" << endl;
629 return nullptr;
630 }
631
632 // Attention: need to do this now, as adding an empty column might give 0 as size
633 const std::size_t numEvt = size();
634
635 // Clone variable and attach to cloned tree
636 std::unique_ptr<RooAbsArg> newVarClone{newVar.cloneTree()};
637 newVarClone->recursiveRedirectServers(_vars,false) ;
638
639 // Attach value place holder to this tree
640 valHolder->attachToVStore(*this) ;
641 _vars.add(*valHolder) ;
642 _varsww.add(*valHolder) ;
643
644 // Fill values of placeholder
645 RealVector* rv(nullptr) ;
646 CatVector* cv(nullptr) ;
647 assert(numEvt != 0);
648 if (dynamic_cast<RooAbsReal*>(valHolder)) {
649 rv = addReal((RooAbsReal*)valHolder);
650 rv->resize(numEvt) ;
651 } else if (dynamic_cast<RooAbsCategory*>((RooAbsCategory*)valHolder)) {
652 cv = addCategory((RooAbsCategory*)valHolder) ;
653 cv->resize(numEvt) ;
654 }
655
656 for (std::size_t i=0; i < numEvt; i++) {
657 get(i) ;
658
659 newVarClone->syncCache(&_vars) ;
660 valHolder->copyCache(newVarClone.get()) ;
661
662 if (rv) rv->write(i) ;
663 if (cv) cv->write(i) ;
664 }
665
666 return valHolder ;
667}
668
669
670
671////////////////////////////////////////////////////////////////////////////////
672/// Merge columns of supplied data set(s) with this data set. All
673/// data sets must have equal number of entries. In case of
674/// duplicate columns the column of the last dataset in the list
675/// prevails
676
677RooAbsDataStore* RooVectorDataStore::merge(const RooArgSet& allVars, list<RooAbsDataStore*> dstoreList)
678{
679 RooVectorDataStore* mergedStore = new RooVectorDataStore("merged","merged",allVars) ;
680
681 const auto nevt = dstoreList.front()->numEntries();
682 mergedStore->reserve(nevt);
683 for (int i=0 ; i<nevt ; i++) {
684
685 // Copy data from self
686 mergedStore->_vars.assign(*get(i)) ;
687
688 // Copy variables from merge sets
689 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
690 const RooArgSet* partSet = (*iter)->get(i) ;
691 mergedStore->_vars.assign(*partSet) ;
692 }
693
694 mergedStore->fill() ;
695 }
696 return mergedStore ;
697}
698
699
700
702{
703 for (auto elm : _realStoreList) {
704 elm->reserve(nEvts);
705 }
706
707 for (auto elm : _realfStoreList) {
708 elm->reserve(nEvts);
709 }
710
711 for (auto elm : _catStoreList) {
712 elm->reserve(nEvts);
713 }
714}
715
716////////////////////////////////////////////////////////////////////////////////
717
719{
720 Int_t nevt = other.numEntries() ;
721 reserve(nevt + numEntries());
722 for (int i=0 ; i<nevt ; i++) {
723 _vars.assign(*other.get(i)) ;
724 if (_wgtVar) {
725 _wgtVar->setVal(other.weight()) ;
726 }
727
728 fill() ;
729 }
730}
731
732
733
734////////////////////////////////////////////////////////////////////////////////
735
737{
739
740 for (auto elm : _realStoreList) {
741 elm->reset() ;
742 }
743
744 for (auto elm : _realfStoreList) {
745 elm->reset() ;
746 }
747
748 for (auto elm : _catStoreList) {
749 elm->reset() ;
750 }
751
752}
753
754////////////////////////////////////////////////////////////////////////////////
755/// Cache given RooAbsArgs: The tree is
756/// given direct write access of the args internal cache
757/// the args values is pre-calculated for all data points
758/// in this data collection. Upon a get() call, the
759/// internal cache of 'newVar' will be loaded with the
760/// precalculated value and it's dirty flag will be cleared.
761
762void RooVectorDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, const RooArgSet* nset, bool skipZeroWeights)
763{
764 // Delete previous cache, if any
765 delete _cache ;
766 _cache = nullptr ;
767
768 // Reorder cached elements. First constant nodes, then tracked nodes in order of dependence
769
770 // Step 1 - split in constant and tracked
771 RooArgSet newVarSetCopy(newVarSet);
772 RooArgSet orderedArgs;
773 vector<RooAbsArg*> trackArgs;
774 for (const auto arg : newVarSetCopy) {
775 if (arg->getAttribute("ConstantExpression") && !arg->getAttribute("NOCacheAndTrack")) {
776 orderedArgs.add(*arg) ;
777 } else {
778
779 // Explicitly check that arg depends on any of the observables, if this
780 // is not the case, skip it, as inclusion would result in repeated
781 // calculation of a function that has the same value for every event
782 // in the likelihood
783 if (arg->dependsOn(_vars) && !arg->getAttribute("NOCacheAndTrack")) {
784 trackArgs.push_back(arg) ;
785 } else {
786 newVarSet.remove(*arg) ;
787 }
788 }
789 }
790
791 // Step 2 - reorder tracked nodes
792 std::sort(trackArgs.begin(), trackArgs.end(), [](RooAbsArg* left, RooAbsArg* right){
793 //LM: exclude same comparison. This avoids an issue when using sort in MacOS versions
794 if (left == right) return false;
795 return right->dependsOn(*left);
796 });
797
798 // Step 3 - put back together
799 for (const auto trackedArg : trackArgs) {
800 orderedArgs.add(*trackedArg);
801 }
802
803 // WVE need to prune tracking entries _below_ constant nodes as the're not needed
804// cout << "Number of Cache-and-Tracked args are " << trackArgs.size() << endl ;
805// cout << "Compound ordered cache parameters = " << endl ;
806// orderedArgs.Print("v") ;
807
808 checkInit() ;
809
810 std::vector<std::unique_ptr<RooArgSet>> vlist;
811 RooArgList cloneSet;
812
813 for (const auto var : orderedArgs) {
814
815 // Clone variable and attach to cloned tree
816 auto newVarCloneList = std::make_unique<RooArgSet>();
817 RooArgSet(*var).snapshot(*newVarCloneList);
818 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
819 newVarClone->recursiveRedirectServers(_vars,false) ;
820
821 vlist.emplace_back(std::move(newVarCloneList));
822 cloneSet.add(*newVarClone) ;
823 }
824
825 _cacheOwner = (RooAbsArg*) owner ;
826 RooVectorDataStore* newCache = new RooVectorDataStore("cache","cache",orderedArgs) ;
827
828
830
831 std::vector<RooArgSet*> nsetList ;
832 std::vector<std::unique_ptr<RooArgSet>> argObsList ;
833
834 // Now need to attach branch buffers of clones
835 for (const auto arg : cloneSet) {
836 arg->attachToVStore(*newCache) ;
837
838 if(nset) argObsList.emplace_back(arg->getObservables(*nset));
839 else argObsList.emplace_back(arg->getVariables());
840 RooArgSet* argObs = argObsList.back().get();
841
842 RooArgSet* normSet(nullptr) ;
843 const char* catNset = arg->getStringAttribute("CATNormSet") ;
844 if (catNset) {
845// cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a normalization set specification CATNormSet = " << catNset << endl ;
846
847 RooArgSet anset = RooHelpers::selectFromArgSet(nset ? *nset : RooArgSet{}, catNset);
848 normSet = (RooArgSet*) anset.selectCommon(*argObs) ;
849
850 }
851 const char* catCset = arg->getStringAttribute("CATCondSet") ;
852 if (catCset) {
853// cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a conditional observable set specification CATCondSet = " << catCset << endl ;
854
855 RooArgSet acset = RooHelpers::selectFromArgSet(nset ? *nset : RooArgSet{}, catCset);
856 argObs->remove(acset,true,true) ;
857 normSet = argObs ;
858 }
859
860 // now construct normalization set for component from cset/nset spec
861// if (normSet) {
862// cout << "RooVectorDaraStore::cacheArgs() component " << arg->GetName() << " has custom normalization set " << *normSet << endl ;
863// }
864 nsetList.push_back(normSet) ;
865 }
866
867
868 // Fill values of placeholder
869 const std::size_t numEvt = size();
870 newCache->reserve(numEvt);
871 for (std::size_t i=0; i < numEvt; i++) {
872 get(i) ;
873 if (weight()!=0 || !skipZeroWeights) {
874 for (unsigned int j = 0; j < cloneSet.size(); ++j) {
875 auto& cloneArg = cloneSet[j];
876 auto argNSet = nsetList[j];
877 // WVE need to intervene here for condobs from ProdPdf
878 cloneArg.syncCache(argNSet ? argNSet : nset) ;
879 }
880 }
881 newCache->fill() ;
882 }
883
885
886
887 // Now need to attach branch buffers of original function objects
888 for (const auto arg : orderedArgs) {
889 arg->attachToVStore(*newCache) ;
890
891 // Activate change tracking mode, if requested
892 if (!arg->getAttribute("ConstantExpression") && dynamic_cast<RooAbsReal*>(arg)) {
893 RealVector* rv = newCache->addReal((RooAbsReal*)arg) ;
894 RooArgSet deps;
895 arg->getParameters(&_vars, deps);
896 rv->setDependents(deps) ;
897
898 // WV lookup normalization set and associate with RealVector
899 // find ordinal number of arg in original list
900 Int_t idx = cloneSet.index(arg->GetName()) ;
901
902 coutI(Optimization) << "RooVectorDataStore::cacheArg() element " << arg->GetName() << " has change tracking enabled on parameters " << deps << endl ;
903 rv->setNset(nsetList[idx]) ;
904 }
905
906 }
907
908 _cache = newCache ;
910}
911
912
914{
915 if (_cache) _forcedUpdate = true ;
916}
917
918
919
920////////////////////////////////////////////////////////////////////////////////
921
922void RooVectorDataStore::recalculateCache( const RooArgSet *projectedArgs, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, bool skipZeroWeights)
923{
924 if (!_cache) return ;
925
926 std::vector<RooVectorDataStore::RealVector *> tv;
927 tv.reserve(static_cast<std::size_t>(_cache->_realStoreList.size() * 0.7)); // Typically, 30..60% need to be recalculated
928
929 // Check which items need recalculation
930 for (const auto realVec : _cache->_realStoreList) {
931 if (_forcedUpdate || realVec->needRecalc()) {
932 tv.push_back(realVec);
933 realVec->_nativeReal->setOperMode(RooAbsArg::ADirty);
934 realVec->_nativeReal->_operMode = RooAbsArg::Auto;
935 }
936 }
937 _forcedUpdate = false ;
938
939 // If no recalculations are needed stop here
940 if (tv.empty()) {
941 return;
942 }
943
944
945 // Refill caches of elements that require recalculation
946 std::unique_ptr<RooArgSet> ownedNset;
947 RooArgSet* usedNset = nullptr;
948 if (projectedArgs && !projectedArgs->empty()) {
949 ownedNset = std::make_unique<RooArgSet>();
950 _vars.snapshot(*ownedNset, false) ;
951 ownedNset->remove(*projectedArgs,false,true);
952 usedNset = ownedNset.get();
953 } else {
954 usedNset = &_vars ;
955 }
956
957
958 for (int i=firstEvent ; i<lastEvent ; i+=stepSize) {
959 get(i) ;
960 bool zeroWeight = (weight()==0) ;
961 if (!zeroWeight || !skipZeroWeights) {
962 for (auto realVector : tv) {
963 realVector->_nativeReal->_valueDirty = true;
964 realVector->_nativeReal->getValV(realVector->_nset ? realVector->_nset : usedNset);
965 realVector->write(i);
966 }
967 }
968 }
969
970 for (auto realVector : tv) {
971 realVector->_nativeReal->setOperMode(RooAbsArg::AClean);
972 }
973}
974
975
976////////////////////////////////////////////////////////////////////////////////
977/// Initialize cache of dataset: attach variables of cache ArgSet
978/// to the corresponding TTree branches
979
980void RooVectorDataStore::attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVarsIn)
981{
982 // Only applicable if a cache exists
983 if (!_cache) return ;
984
985 // Clone ctor, must connect internal storage to given new external set of vars
986 std::vector<RealVector*> cacheElements(_cache->realStoreList());
987 cacheElements.insert(cacheElements.end(), _cache->_realfStoreList.begin(), _cache->_realfStoreList.end());
988
989 for (const auto elm : cacheElements) {
990 auto real = static_cast<RooAbsReal*>(cachedVarsIn.find(elm->bufArg()->GetName()));
991 if (real) {
992 // Adjust buffer pointer
993 real->attachToVStore(*_cache) ;
994 }
995 }
996
997 for (const auto catVec : _cache->_catStoreList) {
998 auto cat = static_cast<RooAbsCategory*>(cachedVarsIn.find(catVec->bufArg()->GetName()));
999 if (cat) {
1000 // Adjust buffer pointer
1001 cat->attachToVStore(*_cache) ;
1002 }
1003 }
1004
1005 _cacheOwner = (RooAbsArg*) newOwner ;
1006}
1007
1008
1009
1010
1011////////////////////////////////////////////////////////////////////////////////
1012
1014{
1015 delete _cache;
1016 _cache = nullptr;
1017 _cacheOwner = nullptr;
1018 return ;
1019}
1020
1021
1022
1023
1024
1025////////////////////////////////////////////////////////////////////////////////
1026/// Disabling of branches is (intentionally) not implemented in vector
1027/// data stores (as the doesn't result in a net saving of time)
1028
1029void RooVectorDataStore::setArgStatus(const RooArgSet& /*set*/, bool /*active*/)
1030{
1031 return ;
1032}
1033
1034
1035
1036
1037////////////////////////////////////////////////////////////////////////////////
1038
1040{
1041 for (auto arg : _varsww) {
1042 RooAbsArg* extArg = extObs.find(arg->GetName()) ;
1043 if (extArg) {
1044 extArg->attachToVStore(*this) ;
1045 }
1046 }
1047}
1048
1049
1050
1051////////////////////////////////////////////////////////////////////////////////
1052
1054{
1055 for (auto arg : _varsww) {
1056 arg->attachToVStore(*this);
1057 }
1058}
1059
1060
1061
1062////////////////////////////////////////////////////////////////////////////////
1063
1065{
1066 cout << "RooVectorDataStor::dump()" << endl ;
1067
1068 cout << "_varsww = " << endl ; _varsww.Print("v") ;
1069 cout << "realVector list is" << endl ;
1070
1071 for (const auto elm : _realStoreList) {
1072 cout << "RealVector " << elm << " _nativeReal = " << elm->_nativeReal << " = " << elm->_nativeReal->GetName() << " bufptr = " << elm->_buf << endl ;
1073 cout << " values : " ;
1074 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1075 for (Int_t i=0 ; i<imax ; i++) {
1076 cout << elm->_vec[i] << " " ;
1077 }
1078 cout << endl ;
1079 }
1080
1081 for (const auto elm : _realfStoreList) {
1082 cout << "RealFullVector " << elm << " _nativeReal = " << elm->_nativeReal << " = " << elm->_nativeReal->GetName()
1083 << " bufptr = " << elm->_buf << " errbufptr = " << elm->bufE() << endl ;
1084
1085 cout << " values : " ;
1086 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1087 for (Int_t i=0 ; i<imax ; i++) {
1088 cout << elm->_vec[i] << " " ;
1089 }
1090 cout << endl ;
1091 if (elm->bufE()) {
1092 cout << " errors : " ;
1093 for (Int_t i=0 ; i<imax ; i++) {
1094 cout << elm->dataE()[i] << " " ;
1095 }
1096 cout << endl ;
1097
1098 }
1099 }
1100}
1101
1102
1103////////////////////////////////////////////////////////////////////////////////
1104/// Stream an object of class RooVectorDataStore.
1105
1107{
1108 if (R__b.IsReading()) {
1110
1111 for (auto elm : _realStoreList) {
1112 RooAbsArg* arg = _varsww.find(elm->_nativeReal->GetName()) ;
1113 arg->attachToVStore(*this) ;
1114 }
1115 for (auto elm : _realfStoreList) {
1116 RooAbsArg* arg = _varsww.find(elm->_nativeReal->GetName()) ;
1117 arg->attachToVStore(*this) ;
1118 }
1119 for (auto elm : _catStoreList) {
1120 RooAbsArg* arg = _varsww.find(elm->_cat->GetName()) ;
1121 arg->attachToVStore(*this) ;
1122 }
1123
1124 } else {
1126 }
1127}
1128
1129
1130////////////////////////////////////////////////////////////////////////////////
1131/// Return batches of the data columns for the requested events.
1132/// \param[in] first First event in the batches.
1133/// \param[in] len Number of events in batches.
1134/// \return Spans with the associated data.
1136 RooAbsData::RealSpans evalData;
1137
1138 auto emplace = [this,&evalData,first,len](const RealVector* realVec) {
1139 auto span = realVec->getRange(first, first + len);
1140 auto result = evalData.emplace(realVec->_nativeReal, span);
1141 if (result.second == false || result.first->second.size() != len) {
1142 const auto size = result.second ? result.first->second.size() : 0;
1143 coutE(DataHandling) << "A batch of data for '" << realVec->_nativeReal->GetName()
1144 << "' was requested from " << first << " to " << first+len
1145 << ", but only the events [" << first << ", " << first + size << ") are available." << std::endl;
1146 }
1147 if (realVec->_real) {
1148 // If a buffer is attached, i.e. we are ready to load into a RooAbsReal outside of our dataset,
1149 // we can directly map our spans to this real.
1150 evalData.emplace(realVec->_real, std::move(span));
1151 }
1152 };
1153
1154 for (const auto realVec : _realStoreList) {
1155 emplace(realVec);
1156 }
1157 for (const auto realVec : _realfStoreList) {
1158 emplace(realVec);
1159 }
1160
1161 if (_cache) {
1162 for (const auto realVec : _cache->_realStoreList) {
1163 emplace(realVec);
1164 }
1165 for (const auto realVec : _cache->_realfStoreList) {
1166 emplace(realVec);
1167 }
1168 }
1169
1170 return evalData;
1171}
1172
1173
1176
1177 auto emplace = [this,&evalData,first,len](const CatVector* catVec) {
1178 auto span = catVec->getRange(first, first + len);
1179 auto result = evalData.emplace(catVec->_cat, span);
1180 if (result.second == false || result.first->second.size() != len) {
1181 const auto size = result.second ? result.first->second.size() : 0;
1182 coutE(DataHandling) << "A batch of data for '" << catVec->_cat->GetName()
1183 << "' was requested from " << first << " to " << first+len
1184 << ", but only the events [" << first << ", " << first + size << ") are available." << std::endl;
1185 }
1186 };
1187
1188 for (const auto& catVec : _catStoreList) {
1189 emplace(catVec);
1190 }
1191
1192 return evalData;
1193}
1194
1195
1196////////////////////////////////////////////////////////////////////////////////
1197/// Return the weights of all events in the range [first, first+len).
1198/// If an array with weights is stored, a batch with these weights will be returned. If
1199/// no weights are stored, an empty batch is returned. Use weight() to check if there's
1200/// a constant weight.
1201std::span<const double> RooVectorDataStore::getWeightBatch(std::size_t first, std::size_t len) const
1202{
1203 if (_extWgtArray) {
1204 return std::span<const double>(_extWgtArray + first, _extWgtArray + first + len);
1205 }
1206
1207 if (_wgtVar) {
1208 auto findWeightVar = [this](const RealVector* realVec) {
1209 return realVec->_nativeReal == _wgtVar || realVec->_nativeReal->GetName() == _wgtVar->GetName();
1210 };
1211
1212 auto storageIter = std::find_if(_realStoreList.begin(), _realStoreList.end(), findWeightVar);
1213 if (storageIter != _realStoreList.end())
1214 return (*storageIter)->getRange(first, first + len);
1215
1216 auto fstorageIter = std::find_if(_realfStoreList.begin(), _realfStoreList.end(), findWeightVar);
1217 if (fstorageIter != _realfStoreList.end())
1218 return (*fstorageIter)->getRange(first, first + len);
1219
1220 throw std::logic_error("RooVectorDataStore::getWeightBatch(): Could not retrieve data for _wgtVar.");
1221 }
1222 return {};
1223}
1224
1225
1227
1228 // First try a match by name
1229 for (auto catVec : _catStoreList) {
1230 if (std::string(catVec->bufArg()->GetName())==cat->GetName()) {
1231 return catVec;
1232 }
1233 }
1234
1235 // If nothing found this will make an entry
1236 _catStoreList.push_back(new CatVector(cat)) ;
1237
1238 return _catStoreList.back() ;
1239}
1240
1241
1243
1244 // First try a match by name
1245 for (auto realVec : _realStoreList) {
1246 if (realVec->bufArg()->namePtr()==real->namePtr()) {
1247 return realVec;
1248 }
1249 }
1250
1251 // Then check if an entry already exists for a full real
1252 for (auto fullVec : _realfStoreList) {
1253 if (fullVec->bufArg()->namePtr()==real->namePtr()) {
1254 // Return full vector as RealVector base class here
1255 return fullVec;
1256 }
1257 }
1258
1259 // If nothing found this will make an entry
1260 _realStoreList.push_back(new RealVector(real)) ;
1261
1262 return _realStoreList.back() ;
1263}
1264
1265
1267
1268 // First try a match by name
1269 for (auto fullVec : _realfStoreList) {
1270 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1271 return true ;
1272 }
1273 }
1274 return false ;
1275}
1276
1277
1279
1280 // First try a match by name
1281 for (auto fullVec : _realfStoreList) {
1282 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1283 return fullVec->bufE();
1284 }
1285 }
1286 return false ;
1287}
1288
1289
1291
1292 // First try a match by name
1293 for (auto fullVec : _realfStoreList) {
1294 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1295 return fullVec->bufEL();
1296 }
1297 }
1298 return false ;
1299}
1300
1301
1303
1304 // First try a match by name
1305 for (auto fullVec : _realfStoreList) {
1306 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1307 return fullVec;
1308 }
1309 }
1310
1311 // Then check if an entry already exists for a bare real
1312 for (auto realVec : _realStoreList) {
1313 if (std::string(realVec->bufArg()->GetName())==real->GetName()) {
1314
1315 // Convert element to full and add to full list
1316 _realfStoreList.push_back(new RealFullVector(*realVec,real)) ;
1317
1318 // Delete bare element
1319 _realStoreList.erase(std::find(_realStoreList.begin(), _realStoreList.end(), realVec));
1320 delete realVec;
1321
1322 return _realfStoreList.back() ;
1323 }
1324 }
1325
1326 // If nothing found this will make an entry
1327 _realfStoreList.push_back(new RealFullVector(real)) ;
1328
1329 return _realfStoreList.back() ;
1330}
1331
1332
1333/// Trigger a recomputation of the cached weight sums. Meant for use by RooFit
1334/// dataset converter functions such as the NumPy converter functions
1335/// implemented as pythonizations.
1337 double const* arr = nullptr;
1338 if (_extWgtArray) {
1339 arr = _extWgtArray;
1340 }
1341 if (_wgtVar) {
1342 const std::string wgtName = _wgtVar->GetName();
1343 for(auto const* real : _realStoreList) {
1344 if(wgtName == real->_nativeReal->GetName())
1345 arr = real->_vec.data();
1346 }
1347 for(auto const* real : _realfStoreList) {
1348 if(wgtName == real->_nativeReal->GetName())
1349 arr = real->_vec.data();
1350 }
1351 }
1352 if(arr == nullptr) {
1353 _sumWeight = size();
1354 return;
1355 }
1357 _sumWeight = result.Sum();
1358 _sumWeightCarry = result.Carry();
1359}
1360
1361
1362/// Exports all arrays in this RooVectorDataStore into a simple datastructure
1363/// to be used by RooFit internal export functions.
1365 ArraysStruct out;
1366 out.size = size();
1367
1368 for(auto const* real : _realStoreList) {
1369 out.reals.emplace_back(real->_nativeReal->GetName(), real->_vec.data());
1370 }
1371 for(auto const* realf : _realfStoreList) {
1372 std::string name = realf->_nativeReal->GetName();
1373 out.reals.emplace_back(name, realf->_vec.data());
1374 if(realf->bufE()) out.reals.emplace_back(name + "Err", realf->dataE().data());
1375 if(realf->bufEL()) out.reals.emplace_back(name + "ErrLo", realf->dataEL().data());
1376 if(realf->bufEH()) out.reals.emplace_back(name + "ErrHi", realf->dataEH().data());
1377 }
1378 for(auto const* cat : _catStoreList) {
1379 out.cats.emplace_back(cat->_cat->GetName(), cat->_vec.data());
1380 }
1381
1382 if(_extWgtArray) out.reals.emplace_back("weight", _extWgtArray);
1383 if(_extWgtErrLoArray) out.reals.emplace_back("wgtErrLo", _extWgtErrLoArray);
1384 if(_extWgtErrHiArray) out.reals.emplace_back("wgtErrHi", _extWgtErrHiArray);
1385 if(_extSumW2Array) out.reals.emplace_back("sumW2",_extSumW2Array);
1386
1387 return out;
1388}
double _sumWeight
Global sum of weights needed for normalization.
#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:377
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:2467
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:79
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:563
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 copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValueDirty=true) override
Copy the cached value from given source and raise dirty flag.
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.
bool contains(const RooAbsArg &var) const
Check if collection contains an argument with the same name as var.
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
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
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.
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
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:55
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:178
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.
RooRealVar represents a 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...
RooTreeDataStore is a 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)
RooVectorDataStore uses std::vectors 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)
Definition first.py:1
Output struct for the RooVectorDataStore::getArrays() helper function.