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