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