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