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