Logo ROOT  
Reference Guide
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 "RooHelpers.h"
44
45#include "Math/Util.h"
46#include "ROOT/StringUtils.hxx"
47#include "TBuffer.h"
48
49#include <iomanip>
50using namespace std;
51
54
55
56////////////////////////////////////////////////////////////////////////////////
57
59{
61}
62
63
64
65////////////////////////////////////////////////////////////////////////////////
66
68 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
69 _varsww(vars),
70 _wgtVar(weightVar(vars,wgtVarName))
71{
72 for (auto arg : _varsww) {
73 arg->attachToVStore(*this) ;
74 }
75
78}
79
80
81
82////////////////////////////////////////////////////////////////////////////////
83
85{
86 for (auto realVec : _realStoreList) {
87 realVec->setNativeBuffer();
88 }
89
90 for (auto fullVec : _realfStoreList) {
91 fullVec->setNativeBuffer();
92 }
93
94 for (auto catVec : _catStoreList) {
95 catVec->setNativeBuffer();
96 }
97}
98
99
100
101
102////////////////////////////////////////////////////////////////////////////////
103/// Utility function for constructors
104/// Return RooArgSet that is copy of allVars minus variable matching wgtName if specified
105
106RooArgSet RooVectorDataStore::varsNoWeight(const RooArgSet& allVars, const char* wgtName)
107{
108 RooArgSet ret(allVars) ;
109 if(wgtName) {
110 RooAbsArg* wgt = allVars.find(wgtName) ;
111 if (wgt) {
112 ret.remove(*wgt,true,true) ;
113 }
114 }
115 return ret ;
116}
117
118
119
120////////////////////////////////////////////////////////////////////////////////
121/// Utility function for constructors
122/// Return pointer to weight variable if it is defined
123
124RooRealVar* RooVectorDataStore::weightVar(const RooArgSet& allVars, const char* wgtName)
125{
126 if(wgtName) {
127 RooRealVar* wgt = dynamic_cast<RooRealVar*>(allVars.find(wgtName)) ;
128 return wgt ;
129 }
130 return 0 ;
131}
132
133
134
135
136////////////////////////////////////////////////////////////////////////////////
137/// Regular copy ctor
138
140 RooAbsDataStore(other,newname),
141 _varsww(other._varsww),
142 _wgtVar(other._wgtVar),
143 _sumWeight(other._sumWeight),
144 _sumWeightCarry(other._sumWeightCarry),
145 _extWgtArray(other._extWgtArray),
146 _extWgtErrLoArray(other._extWgtErrLoArray),
147 _extWgtErrHiArray(other._extWgtErrHiArray),
148 _extSumW2Array(other._extSumW2Array),
149 _currentWeightIndex(other._currentWeightIndex)
150{
151 for (const auto realVec : other._realStoreList) {
152 _realStoreList.push_back(new RealVector(*realVec, (RooAbsReal*)_varsww.find(realVec->_nativeReal->GetName()))) ;
153 }
154
155 for (const auto realFullVec : other._realfStoreList) {
156 _realfStoreList.push_back(new RealFullVector(*realFullVec, (RooAbsReal*)_varsww.find(realFullVec->_nativeReal->GetName()))) ;
157 }
158
159 for (const auto catVec : other._catStoreList) {
160 _catStoreList.push_back(new CatVector(*catVec, (RooAbsCategory*)_varsww.find(catVec->_cat->GetName()))) ;
161 }
162
164
166}
167
168
169////////////////////////////////////////////////////////////////////////////////
170
171RooVectorDataStore::RooVectorDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname) :
172 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
173 _varsww(vars),
174 _wgtVar(weightVar(vars,other._wgtVar?other._wgtVar->GetName():0))
175{
176 for (const auto arg : _varsww) {
177 arg->attachToVStore(*this) ;
178 }
179
181
182 // now copy contents of tree storage here
183 reserve(other.numEntries());
184 for (Int_t i=0 ; i<other.numEntries() ; i++) {
185 other.get(i) ;
186 _varsww.assign(other._varsww) ;
187 fill() ;
188 }
190
191}
192
193
194////////////////////////////////////////////////////////////////////////////////
195/// Clone ctor, must connect internal storage to given new external set of vars
196
197RooVectorDataStore::RooVectorDataStore(const RooVectorDataStore& other, const RooArgSet& vars, const char* newname) :
198 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
199 _varsww(vars),
200 _wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):0),
201 _sumWeight(other._sumWeight),
202 _sumWeightCarry(other._sumWeightCarry),
203 _extWgtArray(other._extWgtArray),
204 _extWgtErrLoArray(other._extWgtErrLoArray),
205 _extWgtErrHiArray(other._extWgtErrHiArray),
206 _extSumW2Array(other._extSumW2Array),
207 _currentWeightIndex(other._currentWeightIndex)
208{
209 for (const auto realVec : other._realStoreList) {
210 auto real = static_cast<RooAbsReal*>(vars.find(realVec->bufArg()->GetName()));
211 if (real) {
212 // Clone vector
213 _realStoreList.push_back(new RealVector(*realVec, real)) ;
214 // Adjust buffer pointer
215 real->attachToVStore(*this) ;
216 }
217 }
218
219 vector<RealFullVector*>::const_iterator fiter = other._realfStoreList.begin() ;
220 for (; fiter!=other._realfStoreList.end() ; ++fiter) {
221 RooAbsReal* real = (RooAbsReal*) vars.find((*fiter)->bufArg()->GetName()) ;
222 if (real) {
223 // Clone vector
224 _realfStoreList.push_back(new RealFullVector(**fiter,real)) ;
225 // Adjust buffer pointer
226 real->attachToVStore(*this) ;
227 }
228 }
229
230 vector<CatVector*>::const_iterator citer = other._catStoreList.begin() ;
231 for (; citer!=other._catStoreList.end() ; ++citer) {
232 RooAbsCategory* cat = (RooAbsCategory*) vars.find((*citer)->bufArg()->GetName()) ;
233 if (cat) {
234 // Clone vector
235 _catStoreList.push_back(new CatVector(**citer,cat)) ;
236 // Adjust buffer pointer
237 cat->attachToVStore(*this) ;
238 }
239 }
240
242
244
245}
246
247
248std::unique_ptr<RooAbsDataStore> RooVectorDataStore::reduce(RooStringView name, RooStringView title,
249 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
250 std::size_t nStart, std::size_t nStop) {
251 RooArgSet tmp(vars) ;
252 if(_wgtVar && !tmp.contains(*_wgtVar)) {
253 tmp.add(*_wgtVar) ;
254 }
255 const char* wgtVarName = _wgtVar ? _wgtVar->GetName() : nullptr;
256 return std::make_unique<RooVectorDataStore>(name, title, *this, tmp, cutVar, cutRange, nStart, nStop, wgtVarName);
257}
258
259
260
261////////////////////////////////////////////////////////////////////////////////
262
264 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
265 std::size_t nStart, std::size_t nStop, const char* wgtVarName) :
266
267 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
268 _varsww(vars),
269 _wgtVar(weightVar(vars,wgtVarName))
270{
271 for (const auto arg : _varsww) {
272 arg->attachToVStore(*this) ;
273 }
274
276
277 // Deep clone cutVar and attach clone to this dataset
278 RooFormulaVar* cloneVar = 0;
279 if (cutVar) {
280 cloneVar = (RooFormulaVar*) cutVar->cloneTree() ;
281 cloneVar->attachDataStore(tds) ;
282 }
283
284 RooVectorDataStore* vds = dynamic_cast<RooVectorDataStore*>(&tds) ;
285 if (vds && vds->_cache) {
286 _cache = new RooVectorDataStore(*vds->_cache) ;
287 }
288
289 loadValues(&tds,cloneVar,cutRange,nStart,nStop);
290
291 delete cloneVar ;
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 0;
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 TDS = dynamic_cast<const RooTreeDataStore*>(ads);
514 auto VDS = 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 bool newWeightVar = _wgtVar ? _wgtVar->getAttribute("NewWeight") : false ;
519
520 if (_wgtVar && VDS && ((RooVectorDataStore*)(ads))->_wgtVar) {
521 if (string(_wgtVar->GetName())!=((RooVectorDataStore*)(ads))->_wgtVar->GetName() && !newWeightVar) {
522 weightRename=true ;
523 }
524 }
525 if (_wgtVar && TDS && ((RooTreeDataStore*)(ads))->_wgtVar) {
526 if (string(_wgtVar->GetName())!=((RooTreeDataStore*)(ads))->_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 if (TDS) {
546 _varsww.assignValueOnly(TDS->_varsww) ;
547 if (weightRename) {
548 _wgtVar->setVal(TDS->_wgtVar->getVal()) ;
549 }
550 } else if (VDS) {
551 _varsww.assignValueOnly(VDS->_varsww) ;
552 if (weightRename) {
553 _wgtVar->setVal(VDS->_wgtVar->getVal()) ;
554 }
555 } else {
556 _varsww.assignValueOnly(*ads->get()) ;
557 }
558
559 // Check that all copied values are valid and in range
560 bool allValid = true;
561 for (const auto arg : _varsww) {
562 allValid &= arg->isValid();
563 if (allValid && !ranges.empty()) {
564 // If we have one or multiple ranges to be selected, the value
565 // must be in one of them to be valid
566 allValid &= std::any_of(ranges.begin(), ranges.end(), [arg](const std::string& range){
567 return arg->inRange(range.c_str());});
568 }
569 if (!allValid)
570 break ;
571 }
572
573 if (!allValid) {
574 continue ;
575 }
576
577 fill() ;
578 }
579
580 SetTitle(ads->GetTitle());
581}
582
583
584
585
586
587////////////////////////////////////////////////////////////////////////////////
588
589bool RooVectorDataStore::changeObservableName(const char* /*from*/, const char* /*to*/)
590{
591 return false ;
592}
593
594
595
596////////////////////////////////////////////////////////////////////////////////
597/// Add a new column to the data set which holds the pre-calculated values
598/// of 'newVar'. This operation is only meaningful if 'newVar' is a derived
599/// value.
600///
601/// The return value points to the added element holding 'newVar's value
602/// in the data collection. The element is always the corresponding fundamental
603/// type of 'newVar' (e.g. a RooRealVar if 'newVar' is a RooFormulaVar)
604///
605/// Note: This function is explicitly NOT intended as a speed optimization
606/// opportunity for the user. Components of complex PDFs that can be
607/// precalculated with the dataset are automatically identified as such
608/// and will be precalculated when fitting to a dataset
609///
610/// By forcibly precalculating functions with non-trivial Jacobians,
611/// or functions of multiple variables occurring in the data set,
612/// using addColumn(), you may alter the outcome of the fit.
613///
614/// Only in cases where such a modification of fit behaviour is intentional,
615/// this function should be used.
616
617RooAbsArg* RooVectorDataStore::addColumn(RooAbsArg& newVar, bool /*adjustRange*/)
618{
619 // Create a fundamental object of the right type to hold newVar values
620 RooAbsArg* valHolder= newVar.createFundamental();
621 // Sanity check that the holder really is fundamental
622 if(!valHolder->isFundamental()) {
623 coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
624 << valHolder->GetName() << "\"" << endl;
625 return 0;
626 }
627
628 // Attention: need to do this now, as adding an empty column might give 0 as size
629 const std::size_t numEvt = size();
630
631 // Clone variable and attach to cloned tree
632 RooAbsArg* newVarClone = newVar.cloneTree() ;
633 newVarClone->recursiveRedirectServers(_vars,false) ;
634
635 // Attach value place holder to this tree
636 valHolder->attachToVStore(*this) ;
637 _vars.add(*valHolder) ;
638 _varsww.add(*valHolder) ;
639
640 // Fill values of placeholder
641 RealVector* rv(0) ;
642 CatVector* cv(0) ;
643 assert(numEvt != 0);
644 if (dynamic_cast<RooAbsReal*>(valHolder)) {
645 rv = addReal((RooAbsReal*)valHolder);
646 rv->resize(numEvt) ;
647 } else if (dynamic_cast<RooAbsCategory*>((RooAbsCategory*)valHolder)) {
648 cv = addCategory((RooAbsCategory*)valHolder) ;
649 cv->resize(numEvt) ;
650 }
651
652 for (std::size_t i=0; i < numEvt; i++) {
653 get(i) ;
654
655 newVarClone->syncCache(&_vars) ;
656 valHolder->copyCache(newVarClone) ;
657
658 if (rv) rv->write(i) ;
659 if (cv) cv->write(i) ;
660 }
661
662 delete newVarClone ;
663 return valHolder ;
664
665}
666
667
668
669////////////////////////////////////////////////////////////////////////////////
670/// Merge columns of supplied data set(s) with this data set. All
671/// data sets must have equal number of entries. In case of
672/// duplicate columns the column of the last dataset in the list
673/// prevails
674
675RooAbsDataStore* RooVectorDataStore::merge(const RooArgSet& allVars, list<RooAbsDataStore*> dstoreList)
676{
677 RooVectorDataStore* mergedStore = new RooVectorDataStore("merged","merged",allVars) ;
678
679 const auto nevt = dstoreList.front()->numEntries();
680 mergedStore->reserve(nevt);
681 for (int i=0 ; i<nevt ; i++) {
682
683 // Copy data from self
684 mergedStore->_vars.assign(*get(i)) ;
685
686 // Copy variables from merge sets
687 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
688 const RooArgSet* partSet = (*iter)->get(i) ;
689 mergedStore->_vars.assign(*partSet) ;
690 }
691
692 mergedStore->fill() ;
693 }
694 return mergedStore ;
695}
696
697
698
700{
701 for (auto elm : _realStoreList) {
702 elm->reserve(nEvts);
703 }
704
705 for (auto elm : _realfStoreList) {
706 elm->reserve(nEvts);
707 }
708
709 for (auto elm : _catStoreList) {
710 elm->reserve(nEvts);
711 }
712}
713
714////////////////////////////////////////////////////////////////////////////////
715
717{
718 Int_t nevt = other.numEntries() ;
719 reserve(nevt + numEntries());
720 for (int i=0 ; i<nevt ; i++) {
721 _vars.assign(*other.get(i)) ;
722 if (_wgtVar) {
723 _wgtVar->setVal(other.weight()) ;
724 }
725
726 fill() ;
727 }
728}
729
730
731
732////////////////////////////////////////////////////////////////////////////////
733
735{
737
738 for (auto elm : _realStoreList) {
739 elm->reset() ;
740 }
741
742 for (auto elm : _realfStoreList) {
743 elm->reset() ;
744 }
745
746 for (auto elm : _catStoreList) {
747 elm->reset() ;
748 }
749
750}
751
752////////////////////////////////////////////////////////////////////////////////
753/// Cache given RooAbsArgs: The tree is
754/// given direct write access of the args internal cache
755/// the args values is pre-calculated for all data points
756/// in this data collection. Upon a get() call, the
757/// internal cache of 'newVar' will be loaded with the
758/// precalculated value and it's dirty flag will be cleared.
759
760void RooVectorDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, const RooArgSet* nset, bool skipZeroWeights)
761{
762 // Delete previous cache, if any
763 delete _cache ;
764 _cache = 0 ;
765
766 // Reorder cached elements. First constant nodes, then tracked nodes in order of dependence
767
768 // Step 1 - split in constant and tracked
769 RooArgSet newVarSetCopy(newVarSet);
770 RooArgSet orderedArgs;
771 vector<RooAbsArg*> trackArgs;
772 for (const auto arg : newVarSetCopy) {
773 if (arg->getAttribute("ConstantExpression") && !arg->getAttribute("NOCacheAndTrack")) {
774 orderedArgs.add(*arg) ;
775 } else {
776
777 // Explicitly check that arg depends on any of the observables, if this
778 // is not the case, skip it, as inclusion would result in repeated
779 // calculation of a function that has the same value for every event
780 // in the likelihood
781 if (arg->dependsOn(_vars) && !arg->getAttribute("NOCacheAndTrack")) {
782 trackArgs.push_back(arg) ;
783 } else {
784 newVarSet.remove(*arg) ;
785 }
786 }
787 }
788
789 // Step 2 - reorder tracked nodes
790 std::sort(trackArgs.begin(), trackArgs.end(), [](RooAbsArg* left, RooAbsArg* right){
791 //LM: exclude same comparison. This avoids an issue when using sort in MacOS versions
792 if (left == right) return false;
793 return right->dependsOn(*left);
794 });
795
796 // Step 3 - put back together
797 for (const auto trackedArg : trackArgs) {
798 orderedArgs.add(*trackedArg);
799 }
800
801 // WVE need to prune tracking entries _below_ constant nodes as the're not needed
802// cout << "Number of Cache-and-Tracked args are " << trackArgs.size() << endl ;
803// cout << "Compound ordered cache parameters = " << endl ;
804// orderedArgs.Print("v") ;
805
806 checkInit() ;
807
808 std::vector<RooArgSet*> vlist;
809 RooArgList cloneSet;
810
811 for (const auto var : orderedArgs) {
812
813 // Clone variable and attach to cloned tree
814 RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
815 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
816 newVarClone->recursiveRedirectServers(_vars,false) ;
817
818 vlist.push_back(newVarCloneList) ;
819 cloneSet.add(*newVarClone) ;
820 }
821
822 _cacheOwner = (RooAbsArg*) owner ;
823 RooVectorDataStore* newCache = new RooVectorDataStore("cache","cache",orderedArgs) ;
824
825
827
828 std::vector<RooArgSet*> nsetList ;
829 std::vector<RooArgSet*> argObsList ;
830
831 // Now need to attach branch buffers of clones
832 for (const auto arg : cloneSet) {
833 arg->attachToVStore(*newCache) ;
834
835 RooArgSet* argObs = nset ? arg->getObservables(*nset) : arg->getVariables() ;
836 argObsList.push_back(argObs) ;
837
838 RooArgSet* normSet(0) ;
839 const char* catNset = arg->getStringAttribute("CATNormSet") ;
840 if (catNset) {
841// cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a normalization set specification CATNormSet = " << catNset << endl ;
842
843 RooArgSet anset = RooHelpers::selectFromArgSet(nset ? *nset : RooArgSet{}, catNset);
844 normSet = (RooArgSet*) anset.selectCommon(*argObs) ;
845
846 }
847 const char* catCset = arg->getStringAttribute("CATCondSet") ;
848 if (catCset) {
849// cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a conditional observable set specification CATCondSet = " << catCset << endl ;
850
851 RooArgSet acset = RooHelpers::selectFromArgSet(nset ? *nset : RooArgSet{}, catCset);
852 argObs->remove(acset,true,true) ;
853 normSet = argObs ;
854 }
855
856 // now construct normalization set for component from cset/nset spec
857// if (normSet) {
858// cout << "RooVectorDaraStore::cacheArgs() component " << arg->GetName() << " has custom normalization set " << *normSet << endl ;
859// }
860 nsetList.push_back(normSet) ;
861 }
862
863
864 // Fill values of of placeholder
865 const std::size_t numEvt = size();
866 newCache->reserve(numEvt);
867 for (std::size_t i=0; i < numEvt; i++) {
868 get(i) ;
869 if (weight()!=0 || !skipZeroWeights) {
870 for (unsigned int j = 0; j < cloneSet.size(); ++j) {
871 auto& cloneArg = cloneSet[j];
872 auto argNSet = nsetList[j];
873 // WVE need to intervene here for condobs from ProdPdf
874 cloneArg.syncCache(argNSet ? argNSet : nset) ;
875 }
876 }
877 newCache->fill() ;
878 }
879
881
882
883 // Now need to attach branch buffers of original function objects
884 for (const auto arg : orderedArgs) {
885 arg->attachToVStore(*newCache) ;
886
887 // Activate change tracking mode, if requested
888 if (!arg->getAttribute("ConstantExpression") && dynamic_cast<RooAbsReal*>(arg)) {
889 RealVector* rv = newCache->addReal((RooAbsReal*)arg) ;
890 RooArgSet* deps = arg->getParameters(_vars) ;
891 rv->setDependents(*deps) ;
892
893 // WV lookup normalization set and associate with RealVector
894 // find ordinal number of arg in original list
895 Int_t idx = cloneSet.index(arg->GetName()) ;
896
897 coutI(Optimization) << "RooVectorDataStore::cacheArg() element " << arg->GetName() << " has change tracking enabled on parameters " << *deps << endl ;
898 rv->setNset(nsetList[idx]) ;
899 delete deps ;
900 }
901
902 }
903
904
905 for (auto set : vlist) {
906 delete set;
907 }
908 for (auto set : argObsList) {
909 delete set;
910 }
911
912 _cache = newCache ;
914}
915
916
918{
919 if (_cache) _forcedUpdate = true ;
920}
921
922
923
924////////////////////////////////////////////////////////////////////////////////
925
926void RooVectorDataStore::recalculateCache( const RooArgSet *projectedArgs, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, bool skipZeroWeights)
927{
928 if (!_cache) return ;
929
930 std::vector<RooVectorDataStore::RealVector *> tv;
931 tv.reserve(static_cast<std::size_t>(_cache->_realStoreList.size() * 0.7)); // Typically, 30..60% need to be recalculated
932
933 // Check which items need recalculation
934 for (const auto realVec : _cache->_realStoreList) {
935 if (_forcedUpdate || realVec->needRecalc()) {
936 tv.push_back(realVec);
937 realVec->_nativeReal->setOperMode(RooAbsArg::ADirty);
938 realVec->_nativeReal->_operMode = RooAbsArg::Auto;
939 }
940 }
941 _forcedUpdate = false ;
942
943 // If no recalculations are needed stop here
944 if (tv.empty()) {
945 return;
946 }
947
948
949 // Refill caches of elements that require recalculation
950 RooArgSet* ownedNset = 0 ;
951 RooArgSet* usedNset = 0 ;
952 if (projectedArgs && projectedArgs->getSize()>0) {
953 ownedNset = (RooArgSet*) _vars.snapshot(false) ;
954 ownedNset->remove(*projectedArgs,false,true);
955 usedNset = ownedNset ;
956 } else {
957 usedNset = &_vars ;
958 }
959
960
961 for (int i=firstEvent ; i<lastEvent ; i+=stepSize) {
962 get(i) ;
963 bool zeroWeight = (weight()==0) ;
964 if (!zeroWeight || !skipZeroWeights) {
965 for (auto realVector : tv) {
966 realVector->_nativeReal->_valueDirty = true;
967 realVector->_nativeReal->getValV(realVector->_nset ? realVector->_nset : usedNset);
968 realVector->write(i);
969 }
970 }
971 }
972
973 for (auto realVector : tv) {
974 realVector->_nativeReal->setOperMode(RooAbsArg::AClean);
975 }
976
977 delete ownedNset ;
978
979}
980
981
982////////////////////////////////////////////////////////////////////////////////
983/// Initialize cache of dataset: attach variables of cache ArgSet
984/// to the corresponding TTree branches
985
986void RooVectorDataStore::attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVarsIn)
987{
988 // Only applicable if a cache exists
989 if (!_cache) return ;
990
991 // Clone ctor, must connect internal storage to given new external set of vars
992 std::vector<RealVector*> cacheElements(_cache->realStoreList());
993 cacheElements.insert(cacheElements.end(), _cache->_realfStoreList.begin(), _cache->_realfStoreList.end());
994
995 for (const auto elm : cacheElements) {
996 auto real = static_cast<RooAbsReal*>(cachedVarsIn.find(elm->bufArg()->GetName()));
997 if (real) {
998 // Adjust buffer pointer
999 real->attachToVStore(*_cache) ;
1000 }
1001 }
1002
1003 for (const auto catVec : _cache->_catStoreList) {
1004 auto cat = static_cast<RooAbsCategory*>(cachedVarsIn.find(catVec->bufArg()->GetName()));
1005 if (cat) {
1006 // Adjust buffer pointer
1007 cat->attachToVStore(*_cache) ;
1008 }
1009 }
1010
1011 _cacheOwner = (RooAbsArg*) newOwner ;
1012}
1013
1014
1015
1016
1017////////////////////////////////////////////////////////////////////////////////
1018
1020{
1021 delete _cache;
1022 _cache = nullptr;
1023 _cacheOwner = nullptr;
1024 return ;
1025}
1026
1027
1028
1029
1030
1031////////////////////////////////////////////////////////////////////////////////
1032/// Disabling of branches is (intentionally) not implemented in vector
1033/// data stores (as the doesn't result in a net saving of time)
1034
1035void RooVectorDataStore::setArgStatus(const RooArgSet& /*set*/, bool /*active*/)
1036{
1037 return ;
1038}
1039
1040
1041
1042
1043////////////////////////////////////////////////////////////////////////////////
1044
1046{
1047 for (auto arg : _varsww) {
1048 RooAbsArg* extArg = extObs.find(arg->GetName()) ;
1049 if (extArg) {
1050 extArg->attachToVStore(*this) ;
1051 }
1052 }
1053}
1054
1055
1056
1057////////////////////////////////////////////////////////////////////////////////
1058
1060{
1061 for (auto arg : _varsww) {
1062 arg->attachToVStore(*this);
1063 }
1064}
1065
1066
1067
1068////////////////////////////////////////////////////////////////////////////////
1069
1071{
1072 cout << "RooVectorDataStor::dump()" << endl ;
1073
1074 cout << "_varsww = " << endl ; _varsww.Print("v") ;
1075 cout << "realVector list is" << endl ;
1076
1077 for (const auto elm : _realStoreList) {
1078 cout << "RealVector " << elm << " _nativeReal = " << elm->_nativeReal << " = " << elm->_nativeReal->GetName() << " bufptr = " << elm->_buf << endl ;
1079 cout << " values : " ;
1080 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1081 for (Int_t i=0 ; i<imax ; i++) {
1082 cout << elm->_vec[i] << " " ;
1083 }
1084 cout << endl ;
1085 }
1086
1087 for (const auto elm : _realfStoreList) {
1088 cout << "RealFullVector " << elm << " _nativeReal = " << elm->_nativeReal << " = " << elm->_nativeReal->GetName()
1089 << " bufptr = " << elm->_buf << " errbufptr = " << elm->_bufE << endl ;
1090
1091 cout << " values : " ;
1092 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1093 for (Int_t i=0 ; i<imax ; i++) {
1094 cout << elm->_vec[i] << " " ;
1095 }
1096 cout << endl ;
1097 if (elm->_vecE) {
1098 cout << " errors : " ;
1099 for (Int_t i=0 ; i<imax ; i++) {
1100 cout << (*elm->_vecE)[i] << " " ;
1101 }
1102 cout << endl ;
1103
1104 }
1105 }
1106}
1107
1108
1109////////////////////////////////////////////////////////////////////////////////
1110/// Stream an object of class RooVectorDataStore.
1111
1113{
1114 if (R__b.IsReading()) {
1116
1117 for (auto elm : _realStoreList) {
1118 RooAbsArg* arg = _varsww.find(elm->_nativeReal->GetName()) ;
1119 arg->attachToVStore(*this) ;
1120 }
1121 for (auto elm : _realfStoreList) {
1122 RooAbsArg* arg = _varsww.find(elm->_nativeReal->GetName()) ;
1123 arg->attachToVStore(*this) ;
1124 }
1125 for (auto elm : _catStoreList) {
1126 RooAbsArg* arg = _varsww.find(elm->_cat->GetName()) ;
1127 arg->attachToVStore(*this) ;
1128 }
1129
1130 } else {
1132 }
1133}
1134
1135
1136////////////////////////////////////////////////////////////////////////////////
1137/// Stream an object of class RooVectorDataStore::RealFullVector.
1138
1140{
1141 if (R__b.IsReading()) {
1143
1144 // WVE - It seems that ROOT persistence turns null pointers to vectors into pointers to null-sized vectors
1145 // Intervene here to remove those null-sized vectors and replace with null pointers to not break
1146 // assumptions made elsewhere in this class
1147 if (_vecE && _vecE->empty()) { delete _vecE ; _vecE = 0 ; }
1148 if (_vecEL && _vecEL->empty()) { delete _vecEL ; _vecEL = 0 ; }
1149 if (_vecEH && _vecEH->empty()) { delete _vecEH ; _vecEH = 0 ; }
1150 } else {
1152 }
1153}
1154
1155
1156////////////////////////////////////////////////////////////////////////////////
1157/// Return batches of the data columns for the requested events.
1158/// \param[in] first First event in the batches.
1159/// \param[in] len Number of events in batches.
1160/// \return Spans with the associated data.
1162 RooAbsData::RealSpans evalData;
1163
1164 auto emplace = [this,&evalData,first,len](const RealVector* realVec) {
1165 auto span = realVec->getRange(first, first + len);
1166 auto result = evalData.emplace(realVec->_nativeReal, span);
1167 if (result.second == false || result.first->second.size() != len) {
1168 const auto size = result.second ? result.first->second.size() : 0;
1169 coutE(DataHandling) << "A batch of data for '" << realVec->_nativeReal->GetName()
1170 << "' was requested from " << first << " to " << first+len
1171 << ", but only the events [" << first << ", " << first + size << ") are available." << std::endl;
1172 }
1173 if (realVec->_real) {
1174 // If a buffer is attached, i.e. we are ready to load into a RooAbsReal outside of our dataset,
1175 // we can directly map our spans to this real.
1176 evalData.emplace(realVec->_real, std::move(span));
1177 }
1178 };
1179
1180 for (const auto realVec : _realStoreList) {
1181 emplace(realVec);
1182 }
1183 for (const auto realVec : _realfStoreList) {
1184 emplace(realVec);
1185 }
1186
1187 if (_cache) {
1188 for (const auto realVec : _cache->_realStoreList) {
1189 emplace(realVec);
1190 }
1191 for (const auto realVec : _cache->_realfStoreList) {
1192 emplace(realVec);
1193 }
1194 }
1195
1196 return evalData;
1197}
1198
1199
1202
1203 auto emplace = [this,&evalData,first,len](const CatVector* catVec) {
1204 auto span = catVec->getRange(first, first + len);
1205 auto result = evalData.emplace(catVec->_cat, span);
1206 if (result.second == false || result.first->second.size() != len) {
1207 const auto size = result.second ? result.first->second.size() : 0;
1208 coutE(DataHandling) << "A batch of data for '" << catVec->_cat->GetName()
1209 << "' was requested from " << first << " to " << first+len
1210 << ", but only the events [" << first << ", " << first + size << ") are available." << std::endl;
1211 }
1212 };
1213
1214 for (const auto& catVec : _catStoreList) {
1215 emplace(catVec);
1216 }
1217
1218 return evalData;
1219}
1220
1221
1222////////////////////////////////////////////////////////////////////////////////
1223/// Return the weights of all events in the range [first, first+len).
1224/// If an array with weights is stored, a batch with these weights will be returned. If
1225/// no weights are stored, an empty batch is returned. Use weight() to check if there's
1226/// a constant weight.
1228{
1229 if (_extWgtArray) {
1231 }
1232
1233 if (_wgtVar) {
1234 auto findWeightVar = [this](const RealVector* realVec) {
1235 return realVec->_nativeReal == _wgtVar || realVec->_nativeReal->GetName() == _wgtVar->GetName();
1236 };
1237
1238 auto storageIter = std::find_if(_realStoreList.begin(), _realStoreList.end(), findWeightVar);
1239 if (storageIter != _realStoreList.end())
1240 return (*storageIter)->getRange(first, first + len);
1241
1242 auto fstorageIter = std::find_if(_realfStoreList.begin(), _realfStoreList.end(), findWeightVar);
1243 if (fstorageIter != _realfStoreList.end())
1244 return (*fstorageIter)->getRange(first, first + len);
1245
1246 throw std::logic_error("RooVectorDataStore::getWeightBatch(): Could not retrieve data for _wgtVar.");
1247 }
1248 return {};
1249}
1250
1251
1253
1254 // First try a match by name
1255 for (auto catVec : _catStoreList) {
1256 if (std::string(catVec->bufArg()->GetName())==cat->GetName()) {
1257 return catVec;
1258 }
1259 }
1260
1261 // If nothing found this will make an entry
1262 _catStoreList.push_back(new CatVector(cat)) ;
1263
1264 return _catStoreList.back() ;
1265}
1266
1267
1269
1270 // First try a match by name
1271 for (auto realVec : _realStoreList) {
1272 if (realVec->bufArg()->namePtr()==real->namePtr()) {
1273 return realVec;
1274 }
1275 }
1276
1277 // Then check if an entry already exists for a full real
1278 for (auto fullVec : _realfStoreList) {
1279 if (fullVec->bufArg()->namePtr()==real->namePtr()) {
1280 // Return full vector as RealVector base class here
1281 return fullVec;
1282 }
1283 }
1284
1285 // If nothing found this will make an entry
1286 _realStoreList.push_back(new RealVector(real)) ;
1287
1288 return _realStoreList.back() ;
1289}
1290
1291
1293
1294 // First try a match by name
1295 for (auto fullVec : _realfStoreList) {
1296 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1297 return true ;
1298 }
1299 }
1300 return false ;
1301}
1302
1303
1305
1306 // First try a match by name
1307 for (auto fullVec : _realfStoreList) {
1308 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1309 return fullVec->_vecE ? true : false ;
1310 }
1311 }
1312 return false ;
1313}
1314
1315
1317
1318 // First try a match by name
1319 for (auto fullVec : _realfStoreList) {
1320 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1321 return fullVec->_vecEL ? true : false ;
1322 }
1323 }
1324 return false ;
1325}
1326
1327
1329
1330 // First try a match by name
1331 for (auto fullVec : _realfStoreList) {
1332 if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1333 return fullVec;
1334 }
1335 }
1336
1337 // Then check if an entry already exists for a bare real
1338 for (auto realVec : _realStoreList) {
1339 if (std::string(realVec->bufArg()->GetName())==real->GetName()) {
1340
1341 // Convert element to full and add to full list
1342 _realfStoreList.push_back(new RealFullVector(*realVec,real)) ;
1343
1344 // Delete bare element
1345 _realStoreList.erase(std::find(_realStoreList.begin(), _realStoreList.end(), realVec));
1346 delete realVec;
1347
1348 return _realfStoreList.back() ;
1349 }
1350 }
1351
1352 // If nothing found this will make an entry
1353 _realfStoreList.push_back(new RealFullVector(real)) ;
1354
1355 return _realfStoreList.back() ;
1356}
1357
1358
1359/// Trigger a recomputation of the cached weight sums. Meant for use by RooFit
1360/// dataset converter functions such as the NumPy converter functions
1361/// implemented as pythonizations.
1363 double const* arr = nullptr;
1364 if (_extWgtArray) {
1365 arr = _extWgtArray;
1366 }
1367 if (_wgtVar) {
1368 const std::string wgtName = _wgtVar->GetName();
1369 for(auto const* real : _realStoreList) {
1370 if(wgtName == real->_nativeReal->GetName())
1371 arr = real->_vec.data();
1372 }
1373 for(auto const* real : _realfStoreList) {
1374 if(wgtName == real->_nativeReal->GetName())
1375 arr = real->_vec.data();
1376 }
1377 }
1378 if(arr == nullptr) {
1379 _sumWeight = size();
1380 return;
1381 }
1383 _sumWeight = result.Sum();
1384 _sumWeightCarry = result.Carry();
1385}
1386
1387
1388/// Exports all arrays in this RooVectorDataStore into a simple datastructure
1389/// to be used by RooFit internal export functions.
1391 ArraysStruct out;
1392 out.size = size();
1393
1394 for(auto const* real : _realStoreList) {
1395 out.reals.emplace_back(real->_nativeReal->GetName(), real->_vec.data());
1396 }
1397 for(auto const* realf : _realfStoreList) {
1398 std::string name = realf->_nativeReal->GetName();
1399 out.reals.emplace_back(name, realf->_vec.data());
1400 if(realf->_vecE) out.reals.emplace_back(name + "Err", realf->_vecE->data());
1401 if(realf->_vecEL) out.reals.emplace_back(name + "ErrLo", realf->_vecEL->data());
1402 if(realf->_vecEH) out.reals.emplace_back(name + "ErrHi", realf->_vecEH->data());
1403 }
1404 for(auto const* cat : _catStoreList) {
1405 out.cats.emplace_back(cat->_cat->GetName(), cat->_vec.data());
1406 }
1407
1408 if(_extWgtArray) out.reals.emplace_back("weight", _extWgtArray);
1409 if(_extWgtErrLoArray) out.reals.emplace_back("wgtErrLo", _extWgtErrLoArray);
1410 if(_extWgtErrHiArray) out.reals.emplace_back("wgtErrHi", _extWgtErrHiArray);
1411 if(_extSumW2Array) out.reals.emplace_back("sumW2",_extSumW2Array);
1412
1413 return out;
1414}
#define coutI(a)
Definition: RooMsgService.h:34
#define coutE(a)
Definition: RooMsgService.h:37
#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:375
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
Definition: THbookFile.cxx:128
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2456
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
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:71
virtual void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDirty=true)=0
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
Definition: RooAbsArg.cxx:1165
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
Definition: RooAbsArg.h:562
void attachDataStore(const RooAbsDataStore &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
Definition: RooAbsArg.cxx:1634
virtual void syncCache(const RooArgSet *nset=nullptr)=0
virtual 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.
Definition: RooAbsArg.cxx:219
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:269
virtual RooAbsArg * cloneTree(const char *newname=nullptr) const
Clone tree expression of objects.
Definition: RooAbsArg.cxx:2220
virtual void attachToVStore(RooVectorDataStore &vstore)=0
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition: RooAbsArg.h:241
RooArgSet * getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Definition: RooAbsArg.cxx:541
A space to attach TBranches.
void attachToVStore(RooVectorDataStore &vstore) override
Attach the category index and label to as branches to the given vector store.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
Storage_t const & get() const
Const access to the underlying stl container.
RooAbsCollection & assignValueOnly(const RooAbsCollection &other, bool forceIfSizeOne=false)
Sets the value of any argument in our set that also appears in the other set.
bool contains(const RooAbsArg &var) const
Check if collection contains an argument with the same name as var.
Int_t getSize() const
Return the number of elements in the collection.
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, RooSpan< const double > > RealSpans
Definition: RooAbsData.h:136
std::map< RooFit::Detail::DataKey, RooSpan< const RooAbsCategory::value_type > > CategorySpans
Definition: RooAbsData.h:137
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
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:56
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:179
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
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:40
void setVal(double value) override
Set value of variable to 'value'.
Definition: RooRealVar.cxx:254
double getError() const
Definition: RooRealVar.h:62
bool hasError(bool allowZero=true) const
Definition: RooRealVar.h:63
bool hasAsymError(bool allowZero=true) const
Definition: RooRealVar.h:68
double getAsymErrorHi() const
Definition: RooRealVar.h:67
double getAsymErrorLo() const
Definition: RooRealVar.h:66
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
The RooStringView is a wrapper around a C-syle string that can also be constructed from a std::string...
Definition: RooStringView.h:27
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 Streamer(TBuffer &) override
Stream an object of class RooVectorDataStore::RealFullVector.
void setNset(RooArgSet *newNset)
void setDependents(const RooArgSet &deps)
RooVectorDataStore uses std::vectors to store data columns.
void resetCache() override
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
~RooVectorDataStore() override
Destructor.
void resetBuffers() override
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
void reserve(Int_t nEvt)
RooSpan< 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).
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
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
Definition: StringUtils.cxx:23
@ Optimization
Definition: RooGlobalFunc.h:62
@ DataHandling
Definition: RooGlobalFunc.h:63
@ InputArguments
Definition: RooGlobalFunc.h:62
RooArgSet selectFromArgSet(RooArgSet const &, std::string const &names)
Construct a RooArgSet of objects in a RooArgSet whose names match to those in the names string.
Definition: RooHelpers.cxx:277
Definition: first.py:1
Output struct for the RooVectorDataStore::getArrays() helper function.
std::vector< ArrayInfo< double > > reals
std::vector< ArrayInfo< RooAbsCategory::value_type > > cats