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::list;
51
52
53
54////////////////////////////////////////////////////////////////////////////////
55
60
61
62
63////////////////////////////////////////////////////////////////////////////////
64
66 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
67 _varsww(vars),
68 _wgtVar(weightVar(vars,wgtVarName))
69{
70 for (auto arg : _varsww) {
71 arg->attachToVStore(*this) ;
72 }
73
76}
77
78
79
80////////////////////////////////////////////////////////////////////////////////
81
83{
84 for (auto realVec : _realStoreList) {
85 realVec->setNativeBuffer();
86 }
87
88 for (auto fullVec : _realfStoreList) {
89 fullVec->setNativeBuffer();
90 }
91
92 for (auto catVec : _catStoreList) {
93 catVec->setNativeBuffer();
94 }
95}
96
97
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Utility function for constructors
102/// Return RooArgSet that is copy of allVars minus variable matching wgtName if specified
103
105{
106 RooArgSet ret(allVars) ;
107 if(wgtName) {
108 RooAbsArg* wgt = allVars.find(wgtName) ;
109 if (wgt) {
110 ret.remove(*wgt,true,true) ;
111 }
112 }
113 return ret ;
114}
115
116
117
118////////////////////////////////////////////////////////////////////////////////
119/// Utility function for constructors
120/// Return pointer to weight variable if it is defined
121
123{
124 if(wgtName) {
125 RooRealVar* wgt = dynamic_cast<RooRealVar*>(allVars.find(wgtName)) ;
126 return wgt ;
127 }
128 return nullptr ;
129}
130
131
132
133
134////////////////////////////////////////////////////////////////////////////////
135/// Regular copy constructor.
136
139 _varsww(other._varsww),
140 _wgtVar(other._wgtVar),
141 _sumWeight(other._sumWeight),
142 _sumWeightCarry(other._sumWeightCarry),
143 _extWgtArray(other._extWgtArray),
144 _extWgtErrLoArray(other._extWgtErrLoArray),
145 _extWgtErrHiArray(other._extWgtErrHiArray),
146 _extSumW2Array(other._extSumW2Array),
147 _currentWeightIndex(other._currentWeightIndex)
148{
149 for (const auto realVec : other._realStoreList) {
150 _realStoreList.push_back(new RealVector(*realVec, static_cast<RooAbsReal*>(_varsww.find(realVec->_nativeReal->GetName())))) ;
151 }
152
153 for (const auto realFullVec : other._realfStoreList) {
154 _realfStoreList.push_back(new RealFullVector(*realFullVec, static_cast<RooAbsReal*>(_varsww.find(realFullVec->_nativeReal->GetName())))) ;
155 }
156
157 for (const auto catVec : other._catStoreList) {
158 _catStoreList.push_back(new CatVector(*catVec, static_cast<RooAbsCategory*>(_varsww.find(catVec->_cat->GetName())))) ;
159 }
160
162
164}
165
166
167////////////////////////////////////////////////////////////////////////////////
168
170 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():nullptr),newname),
171 _varsww(vars),
172 _wgtVar(weightVar(vars,other._wgtVar?other._wgtVar->GetName():nullptr))
173{
174 for (const auto arg : _varsww) {
175 arg->attachToVStore(*this) ;
176 }
177
179
180 // now copy contents of tree storage here
181 reserve(other.numEntries());
182 for (Int_t i=0 ; i<other.numEntries() ; i++) {
183 other.get(i) ;
184 _varsww.assign(other._varsww) ;
185 fill() ;
186 }
188
189}
190
191
192////////////////////////////////////////////////////////////////////////////////
193/// Clone constructor, must connect internal storage to given new external set of variables.
194
196 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():nullptr),newname),
197 _varsww(vars),
198 _wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):nullptr),
199 _sumWeight(other._sumWeight),
200 _sumWeightCarry(other._sumWeightCarry),
201 _extWgtArray(other._extWgtArray),
202 _extWgtErrLoArray(other._extWgtErrLoArray),
203 _extWgtErrHiArray(other._extWgtErrHiArray),
204 _extSumW2Array(other._extSumW2Array),
205 _currentWeightIndex(other._currentWeightIndex)
206{
207 for (const auto realVec : other._realStoreList) {
208 auto real = static_cast<RooAbsReal*>(vars.find(realVec->bufArg()->GetName()));
209 if (real) {
210 // Clone vector
211 _realStoreList.push_back(new RealVector(*realVec, real)) ;
212 // Adjust buffer pointer
213 real->attachToVStore(*this) ;
214 }
215 }
216
217 auto forwardIter = other._realfStoreList.begin() ;
218 for (; forwardIter!=other._realfStoreList.end() ; ++forwardIter) {
219 RooAbsReal* real = static_cast<RooAbsReal*>(vars.find((*forwardIter)->bufArg()->GetName())) ;
220 if (real) {
221 // Clone vector
223 // Adjust buffer pointer
224 real->attachToVStore(*this) ;
225 }
226 }
227
228 vector<CatVector*>::const_iterator citer = other._catStoreList.begin() ;
229 for (; citer!=other._catStoreList.end() ; ++citer) {
230 RooAbsCategory* cat = static_cast<RooAbsCategory*>(vars.find((*citer)->bufArg()->GetName())) ;
231 if (cat) {
232 // Clone vector
233 _catStoreList.push_back(new CatVector(**citer,cat)) ;
234 // Adjust buffer pointer
235 cat->attachToVStore(*this) ;
236 }
237 }
238
240
242
243}
244
245
246std::unique_ptr<RooAbsDataStore> RooVectorDataStore::reduce(RooStringView name, RooStringView title,
247 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
248 std::size_t nStart, std::size_t nStop) {
249 RooArgSet tmp(vars) ;
250 if(_wgtVar && !tmp.contains(*_wgtVar)) {
251 tmp.add(*_wgtVar) ;
252 }
253 const char* wgtVarName = _wgtVar ? _wgtVar->GetName() : nullptr;
254 return std::make_unique<RooVectorDataStore>(name, title, *this, tmp, cutVar, cutRange, nStart, nStop, wgtVarName);
255}
256
257
258
259////////////////////////////////////////////////////////////////////////////////
260
262 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
263 std::size_t nStart, std::size_t nStop, const char* wgtVarName) :
264
265 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
266 _varsww(vars),
267 _wgtVar(weightVar(vars,wgtVarName))
268{
269 for (const auto arg : _varsww) {
270 arg->attachToVStore(*this) ;
271 }
272
274
275 // Deep clone cutVar and attach clone to this dataset
276 std::unique_ptr<RooFormulaVar> cloneVar;
277 if (cutVar) {
278 cloneVar.reset(static_cast<RooFormulaVar*>(cutVar->cloneTree()));
279 cloneVar->attachDataStore(tds) ;
280 }
281
282 RooVectorDataStore* vds = dynamic_cast<RooVectorDataStore*>(&tds) ;
283 if (vds && vds->_cache) {
284 _cache = new RooVectorDataStore(*vds->_cache) ;
285 }
286
287 loadValues(&tds,cloneVar.get(),cutRange,nStart,nStop);
288
290}
291
292
293
294
295
296
297////////////////////////////////////////////////////////////////////////////////
298/// Destructor
299
301{
302 for (auto elm : _realStoreList) {
303 delete elm;
304 }
305
306 for (auto elm : _realfStoreList) {
307 delete elm;
308 }
309
310 for (auto elm : _catStoreList) {
311 delete elm;
312 }
313
314 delete _cache ;
316}
317
318
319////////////////////////////////////////////////////////////////////////////////
320/// Interface function to TTree::Fill
321
323{
324 for (auto realVec : _realStoreList) {
325 realVec->fill() ;
326 }
327
328 for (auto fullVec : _realfStoreList) {
329 fullVec->fill() ;
330 }
331
332 for (auto catVec : _catStoreList) {
333 catVec->fill() ;
334 }
335 // use Kahan's algorithm to sum up weights to avoid loss of precision
336 double y = (_wgtVar ? _wgtVar->getVal() : 1.) - _sumWeightCarry;
337 double t = _sumWeight + y;
338 _sumWeightCarry = (t - _sumWeight) - y;
339 _sumWeight = t;
340
341 return 0 ;
342}
343
344
345
346////////////////////////////////////////////////////////////////////////////////
347/// Load the n-th data point (n='index') into the variables of this dataset,
348/// and return a pointer to the RooArgSet that holds them.
350{
351 if (index < 0 || static_cast<std::size_t>(index) >= size()) return nullptr;
352
353 for (const auto realV : _realStoreList) {
354 realV->load(index);
355 }
356
357 for (const auto fullRealP : _realfStoreList) {
358 fullRealP->load(index);
359 }
360
361 for (const auto catP : _catStoreList) {
362 catP->load(index);
363 }
364
365 if (_doDirtyProp) {
366 // Raise all dirty flags
367 for (auto var : _vars) {
368 var->setValueDirty(); // This triggers recalculation of all clients
369 }
370 }
371
372 // Update current weight cache
374
375 if (_cache) {
376 _cache->get(index) ;
377 }
378
379 return &_vars;
380}
381
382
383////////////////////////////////////////////////////////////////////////////////
384/// Return the error of the current weight.
385/// @param[in] etype Switch between simple Poisson or sum-of-weights statistics
386
388{
389 if (_extWgtArray) {
390
391 // We have a weight array, use that info
392
393 // Return symmetric error on current bin calculated either from Poisson statistics or from SumOfWeights
394 double lo = 0;
395 double hi = 0;
396 weightError(lo,hi,etype) ;
397 return (lo+hi)/2 ;
398
399 } else if (_wgtVar) {
400
401 // We have a weight variable, use that info
402 if (_wgtVar->hasAsymError()) {
403 return ( _wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo() ) / 2 ;
404 } else if (_wgtVar->hasError(false)) {
405 return _wgtVar->getError();
406 } else {
407 return 0 ;
408 }
409
410 } else {
411
412 // We have no weights
413 return 0 ;
414
415 }
416}
417
418
419
420////////////////////////////////////////////////////////////////////////////////
421
422void RooVectorDataStore::weightError(double& lo, double& hi, RooAbsData::ErrorType etype) const
423{
424 if (_extWgtArray) {
425 double wgt;
426
427 // We have a weight array, use that info
428 switch (etype) {
429
430 case RooAbsData::Auto:
431 throw string(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
432 break ;
433
435 throw string(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
436 break ;
437
439 // Weight may be preset or precalculated
443 return ;
444 }
445
446 // Otherwise Calculate poisson errors
447 wgt = weight();
448 double ym;
449 double yp;
450 RooHistError::instance().getPoissonInterval(Int_t(wgt+0.5),ym,yp,1);
451 lo = wgt-ym;
452 hi = yp-wgt;
453 return ;
454
457 hi = lo;
458 return ;
459
460 case RooAbsData::None:
461 lo = 0 ;
462 hi = 0 ;
463 return ;
464 }
465
466 } else if (_wgtVar) {
467
468 // We have a weight variable, use that info
469 if (_wgtVar->hasAsymError()) {
471 lo = _wgtVar->getAsymErrorLo() ;
472 } else {
473 hi = _wgtVar->getError() ;
474 lo = _wgtVar->getError() ;
475 }
476
477 } else {
478
479 // We are unweighted
480 lo=0 ;
481 hi=0 ;
482
483 }
484}
485
486
487
488////////////////////////////////////////////////////////////////////////////////
489///
490
491void RooVectorDataStore::loadValues(const RooAbsDataStore *ads, const RooFormulaVar* select, const char* rangeName, std::size_t nStart, std::size_t nStop)
492{
493 // Load values from dataset 't' into this data collection, optionally
494 // selecting events using 'select' RooFormulaVar
495 //
496
497 // Redirect formula servers to source data row
498 std::unique_ptr<RooFormulaVar> selectClone;
499 if (select) {
500 selectClone.reset( static_cast<RooFormulaVar*>(select->cloneTree()) );
501 selectClone->recursiveRedirectServers(*ads->get()) ;
502 selectClone->setOperMode(RooAbsArg::ADirty,true) ;
503 }
504
505 // Force DS internal initialization
506 ads->get(0) ;
507
508 // Loop over events in source tree
509 const auto numEntr = static_cast<std::size_t>(ads->numEntries());
510 const std::size_t nevent = nStop < numEntr ? nStop : numEntr;
511
512 auto treeDS = dynamic_cast<const RooTreeDataStore*>(ads);
513 auto vectorDS = dynamic_cast<const RooVectorDataStore*>(ads);
514
515 // Check if weight is being renamed - if so set flag to enable special handling in copy loop
516 bool weightRename(false) ;
517 const bool newWeightVar = _wgtVar ? _wgtVar->getAttribute("NewWeight") : false ;
518
519 if (_wgtVar && vectorDS && vectorDS->_wgtVar) {
520 if (std::string(_wgtVar->GetName()) != vectorDS->_wgtVar->GetName() && !newWeightVar) {
522 }
523 }
524 if (_wgtVar && treeDS && treeDS->_wgtVar) {
525 if (std::string(_wgtVar->GetName()) != treeDS->_wgtVar->GetName() && !newWeightVar) {
527 }
528 }
529
530 std::vector<std::string> ranges;
531 if (rangeName) {
532 ranges = ROOT::Split(rangeName, ",");
533 }
534
535 reserve(numEntries() + (nevent - nStart));
536 for(auto i=nStart; i < nevent ; ++i) {
537 ads->get(i);
538
539 // Does this event pass the cuts?
540 if (selectClone && selectClone->getVal()==0) {
541 continue ;
542 }
543
544 RooArgSet const* otherVarsww = nullptr;
545
546 if (treeDS) {
547 otherVarsww = &treeDS->_varsww;
548 if (weightRename) {
549 _wgtVar->setVal(treeDS->_wgtVar->getVal()) ;
550 }
551 } else if (vectorDS) {
552 otherVarsww = &vectorDS->_varsww;
553 if (weightRename) {
554 _wgtVar->setVal(vectorDS->_wgtVar->getVal()) ;
555 }
556 } else {
557 otherVarsww = ads->get();
558 }
559
560 // Check that all copied values are valid and in range
561 bool allValid = true;
562 for (const auto arg : *otherVarsww) {
563 allValid &= arg->isValid();
564 if (allValid && !ranges.empty()) {
565 // If we have one or multiple ranges to be selected, the value
566 // must be in one of them to be valid
567 allValid &= std::any_of(ranges.begin(), ranges.end(), [arg](const std::string& range){
568 return arg->inRange(range.c_str());});
569 }
570 if (!allValid)
571 break ;
572 }
573
574 if (!allValid) {
575 continue ;
576 }
577
579
580 fill() ;
581 }
582
583 SetTitle(ads->GetTitle());
584}
585
586
587
588
589
590////////////////////////////////////////////////////////////////////////////////
591
592bool RooVectorDataStore::changeObservableName(const char* /*from*/, const char* /*to*/)
593{
594 return false ;
595}
596
597
598
599////////////////////////////////////////////////////////////////////////////////
600/// Add a new column to the data set which holds the pre-calculated values
601/// of 'newVar'. This operation is only meaningful if 'newVar' is a derived
602/// value.
603///
604/// The return value points to the added element holding 'newVar's value
605/// in the data collection. The element is always the corresponding fundamental
606/// type of 'newVar' (e.g. a RooRealVar if 'newVar' is a RooFormulaVar)
607///
608/// Note: This function is explicitly NOT intended as a speed optimization
609/// opportunity for the user. Components of complex PDFs that can be
610/// precalculated with the dataset are automatically identified as such
611/// and will be precalculated when fitting to a dataset
612///
613/// By forcibly precalculating functions with non-trivial Jacobians,
614/// or functions of multiple variables occurring in the data set,
615/// using addColumn(), you may alter the outcome of the fit.
616///
617/// Only in cases where such a modification of fit behaviour is intentional,
618/// this function should be used.
619
621{
622 // Create a fundamental object of the right type to hold newVar values
623 auto valHolder = std::unique_ptr<RooAbsArg>{newVar.createFundamental()}.release();
624 // Sanity check that the holder really is fundamental
625 if(!valHolder->isFundamental()) {
626 coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
627 << valHolder->GetName() << "\"" << std::endl;
628 return nullptr;
629 }
630
631 // Attention: need to do this now, as adding an empty column might give 0 as size
632 const std::size_t numEvt = size();
633
634 // Clone variable and attach to cloned tree
635 std::unique_ptr<RooAbsArg> newVarClone{newVar.cloneTree()};
636 newVarClone->recursiveRedirectServers(_vars,false) ;
637
638 // Attach value place holder to this tree
639 valHolder->attachToVStore(*this) ;
642
643 // Fill values of placeholder
644 RealVector* rv(nullptr) ;
645 CatVector* cv(nullptr) ;
646 assert(numEvt != 0);
647 if (dynamic_cast<RooAbsReal*>(valHolder)) {
648 rv = addReal(static_cast<RooAbsReal*>(valHolder));
649 rv->resize(numEvt) ;
650 } else if (dynamic_cast<RooAbsCategory*>(static_cast<RooAbsCategory*>(valHolder))) {
651 cv = addCategory(static_cast<RooAbsCategory*>(valHolder)) ;
652 cv->resize(numEvt) ;
653 }
654
655 for (std::size_t i=0; i < numEvt; i++) {
656 get(i) ;
657
658 newVarClone->syncCache(&_vars) ;
659 valHolder->copyCache(newVarClone.get()) ;
660
661 if (rv) rv->write(i) ;
662 if (cv) cv->write(i) ;
663 }
664
665 return valHolder ;
666}
667
668
669
670////////////////////////////////////////////////////////////////////////////////
671/// Merge columns of supplied data set(s) with this data set. All
672/// data sets must have equal number of entries. In case of
673/// duplicate columns the column of the last dataset in the list
674/// prevails
675
677{
678 RooVectorDataStore* mergedStore = new RooVectorDataStore("merged","merged",allVars) ;
679
680 const auto nevt = dstoreList.front()->numEntries();
681 mergedStore->reserve(nevt);
682 for (int i=0 ; i<nevt ; i++) {
683
684 // Copy data from self
685 mergedStore->_vars.assign(*get(i)) ;
686
687 // Copy variables from merge sets
688 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
689 const RooArgSet* partSet = (*iter)->get(i) ;
690 mergedStore->_vars.assign(*partSet) ;
691 }
692
693 mergedStore->fill() ;
694 }
695 return mergedStore ;
696}
697
698
699
701{
702 for (auto elm : _realStoreList) {
703 elm->reserve(nEvts);
704 }
705
706 for (auto elm : _realfStoreList) {
707 elm->reserve(nEvts);
708 }
709
710 for (auto elm : _catStoreList) {
711 elm->reserve(nEvts);
712 }
713}
714
715////////////////////////////////////////////////////////////////////////////////
716
718{
719 Int_t nevt = other.numEntries() ;
720 reserve(nevt + numEntries());
721 for (int i=0 ; i<nevt ; i++) {
722 _vars.assign(*other.get(i)) ;
723 if (_wgtVar) {
724 _wgtVar->setVal(other.weight()) ;
725 }
726
727 fill() ;
728 }
729}
730
731
732
733////////////////////////////////////////////////////////////////////////////////
734
736{
738
739 for (auto elm : _realStoreList) {
740 elm->reset() ;
741 }
742
743 for (auto elm : _realfStoreList) {
744 elm->reset() ;
745 }
746
747 for (auto elm : _catStoreList) {
748 elm->reset() ;
749 }
750
751}
752
753////////////////////////////////////////////////////////////////////////////////
754/// Cache given RooAbsArgs: The tree is
755/// given direct write access of the args internal cache
756/// the args values is pre-calculated for all data points
757/// in this data collection. Upon a get() call, the
758/// internal cache of 'newVar' will be loaded with the
759/// precalculated value and it's dirty flag will be cleared.
760
762{
763 // Delete previous cache, if any
764 delete _cache ;
765 _cache = nullptr ;
766
767 // Reorder cached elements. First constant nodes, then tracked nodes in order of dependence
768
769 // Step 1 - split in constant and tracked
773 for (const auto arg : newVarSetCopy) {
774 if (arg->getAttribute("ConstantExpression") && !arg->getAttribute("NOCacheAndTrack")) {
775 orderedArgs.add(*arg) ;
776 } else {
777
778 // Explicitly check that arg depends on any of the observables, if this
779 // is not the case, skip it, as inclusion would result in repeated
780 // calculation of a function that has the same value for every event
781 // in the likelihood
782 if (arg->dependsOn(_vars) && !arg->getAttribute("NOCacheAndTrack")) {
783 trackArgs.push_back(arg) ;
784 } else {
785 newVarSet.remove(*arg) ;
786 }
787 }
788 }
789
790 // Step 2 - reorder tracked nodes
791 std::sort(trackArgs.begin(), trackArgs.end(), [](RooAbsArg* left, RooAbsArg* right){
792 //LM: exclude same comparison. This avoids an issue when using sort in MacOS versions
793 if (left == right) return false;
794 return right->dependsOn(*left);
795 });
796
797 // Step 3 - put back together
798 for (const auto trackedArg : trackArgs) {
800 }
801
802 // WVE need to prune tracking entries _below_ constant nodes as the're not needed
803// std::cout << "Number of Cache-and-Tracked args are " << trackArgs.size() << std::endl ;
804// std::cout << "Compound ordered cache parameters = " << std::endl ;
805// orderedArgs.Print("v") ;
806
807 checkInit() ;
808
809 std::vector<std::unique_ptr<RooArgSet>> vlist;
811
812 for (const auto var : orderedArgs) {
813
814 // Clone variable and attach to cloned tree
815 auto newVarCloneList = std::make_unique<RooArgSet>();
817 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
818 newVarClone->recursiveRedirectServers(_vars,false) ;
819
820 vlist.emplace_back(std::move(newVarCloneList));
821 cloneSet.add(*newVarClone) ;
822 }
823
824 _cacheOwner = const_cast<RooAbsArg *>(owner);
826
827
829
830 std::vector<RooArgSet*> nsetList ;
831 std::vector<std::unique_ptr<RooArgSet>> argObsList ;
832 std::vector<std::unique_ptr<RooArgSet>> ownedNsets;
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// std::cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a normalization set specification CATNormSet = " << catNset << std::endl ;
846
848 ownedNsets.emplace_back(anset.selectCommon(*argObs));
849 normSet = ownedNsets.back().get();
850 }
851 const char* catCset = arg->getStringAttribute("CATCondSet") ;
852 if (catCset) {
853// std::cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a conditional observable set specification CATCondSet = " << catCset << std::endl ;
854
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// std::cout << "RooVectorDaraStore::cacheArgs() component " << arg->GetName() << " has custom normalization set " << *normSet << std::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(static_cast<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 << std::endl ;
903 rv->setNset(nsetList[idx]) ;
904 }
905
906 }
907
908 _cache = newCache ;
910}
911
912
917
918
919
920////////////////////////////////////////////////////////////////////////////////
921
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 }
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
981{
982 // Only applicable if a cache exists
983 if (!_cache) return ;
984
985 // Clone constructor, must connect internal storage to given new external set of variables
986 std::vector<RealVector*> cacheElements(_cache->realStoreList());
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 = const_cast<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 std::cout << "RooVectorDataStor::dump()" << std::endl ;
1067
1068 std::cout << "_varsww = " << std::endl ; _varsww.Print("v") ;
1069 std::cout << "realVector list is" << std::endl ;
1070
1071 for (const auto elm : _realStoreList) {
1072 std::cout << "RealVector " << elm << " _nativeReal = " << elm->_nativeReal << " = " << elm->_nativeReal->GetName() << " bufptr = " << elm->_buf << std::endl ;
1073 std::cout << " values : " ;
1074 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1075 for (Int_t i=0 ; i<imax ; i++) {
1076 std::cout << elm->_vec[i] << " " ;
1077 }
1078 std::cout << std::endl ;
1079 }
1080
1081 for (const auto elm : _realfStoreList) {
1082 std::cout << "RealFullVector " << elm << " _nativeReal = " << elm->_nativeReal << " = " << elm->_nativeReal->GetName()
1083 << " bufptr = " << elm->_buf << " errbufptr = " << elm->bufE() << std::endl ;
1084
1085 std::cout << " values : " ;
1086 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1087 for (Int_t i=0 ; i<imax ; i++) {
1088 std::cout << elm->_vec[i] << " " ;
1089 }
1090 std::cout << std::endl ;
1091 if (elm->bufE()) {
1092 std::cout << " errors : " ;
1093 for (Int_t i=0 ; i<imax ; i++) {
1094 std::cout << elm->dataE()[i] << " " ;
1095 }
1096 std::cout << std::endl ;
1097
1098 }
1099 }
1100}
1101
1102
1103////////////////////////////////////////////////////////////////////////////////
1104/// Stream an object of class RooVectorDataStore.
1105
1107{
1108 if (R__b.IsReading()) {
1109 R__b.ReadClassBuffer(RooVectorDataStore::Class(),this);
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 {
1125 R__b.WriteClassBuffer(RooVectorDataStore::Class(),this);
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.
1135RooAbsData::RealSpans RooVectorDataStore::getBatches(std::size_t first, std::size_t len) const {
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, 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);
1214 return (*storageIter)->getRange(first, first + len);
1215
1216 auto fstorageIter = std::find_if(_realfStoreList.begin(), _realfStoreList.end(), findWeightVar);
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}
#define coutI(a)
#define coutE(a)
#define TRACE_DESTROY
Definition RooTrace.h:24
#define TRACE_CREATE
Definition RooTrace.h:23
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:148
#define hi
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2496
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:230
const_iterator begin() const
const_iterator end() const
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
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 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 add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
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...
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 void checkInit() const
bool _doDirtyProp
Switch do (de)activate dirty state propagation when loading a data point.
std::map< RooFit::Detail::DataKey, std::span< const double > > RealSpans
Definition RooAbsData.h:132
std::map< RooFit::Detail::DataKey, std::span< const RooAbsCategory::value_type > > CategorySpans
Definition RooAbsData.h:133
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:107
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:159
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.
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:59
bool hasError(bool allowZero=true) const
Definition RooRealVar.h:60
bool hasAsymError(bool allowZero=true) const
Definition RooRealVar.h:65
double getAsymErrorHi() const
Definition RooRealVar.h:64
double getAsymErrorLo() const
Definition RooRealVar.h:63
The RooStringView is a wrapper around a C-style string that can also be constructed from a std::strin...
TTree-backed data storage.
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 void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
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.
std::vector< ArrayInfo< double > > reals
std::vector< ArrayInfo< RooAbsCategory::value_type > > cats