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 
22 RooVectorDataStore uses std::vectors to store data columns. Each of these vectors
23 is associated to an instance of a RooAbsReal, whose values it represents. Those
24 RooAbsReal are the observables of the dataset.
25 In addition to the observables, a data column can be bound to a different instance
26 of a RooAbsReal (e.g., the column "x" can be bound to the observable "x" of a computation
27 graph using attachBuffers()). In this case, a get() operation writes the value of
28 the requested column into the bound real.
29 
30 As a faster alternative to loading values one-by-one, one can use the function getBatches(),
31 which 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>
52 using 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 
79 RooVectorDataStore::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 
127 RooArgSet 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 
145 RooRealVar* 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 
160 RooVectorDataStore::RooVectorDataStore(const RooVectorDataStore& other, const char* newname) :
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 
195 RooVectorDataStore::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 
231 RooVectorDataStore::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 
289 RooVectorDataStore::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 
537  case RooAbsData::Poisson:
538  // Weight may be preset or precalculated
542  return ;
543  }
544 
545  // Otherwise Calculate poisson errors
546  wgt = weight();
547  Double_t ym,yp ;
548  RooHistError::instance().getPoissonInterval(Int_t(wgt+0.5),ym,yp,1);
549  lo = wgt-ym;
550  hi = yp-wgt;
551  return ;
552 
553  case RooAbsData::SumW2:
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()) {
568  hi = _wgtVar->getAsymErrorHi() ;
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 
589 void 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 
686 Bool_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() ;
730  newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
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()) ;
801  newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
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 
854 RooAbsDataStore* 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 
939 void 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  return right->dependsOn(*left);
971  });
972 
973  // Step 3 - put back together
974  for (const auto trackedArg : trackArgs) {
975  orderedArgs.add(*trackedArg);
976  }
977 
978  // WVE need to prune tracking entries _below_ constant nodes as the're not needed
979 // cout << "Number of Cache-and-Tracked args are " << trackArgs.size() << endl ;
980 // cout << "Compound ordered cache parameters = " << endl ;
981 // orderedArgs.Print("v") ;
982 
983  checkInit() ;
984 
985  std::vector<RooArgSet*> vlist;
986  RooArgList cloneSet;
987 
988  for (const auto var : orderedArgs) {
989 
990  // Clone variable and attach to cloned tree
991  RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
992  RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
993  newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
994 
995  vlist.push_back(newVarCloneList) ;
996  cloneSet.add(*newVarClone) ;
997  }
998 
999  _cacheOwner = (RooAbsArg*) owner ;
1000  RooVectorDataStore* newCache = new RooVectorDataStore("cache","cache",orderedArgs) ;
1001 
1002 
1004 
1005  std::vector<RooArgSet*> nsetList ;
1006  std::vector<RooArgSet*> argObsList ;
1007 
1008  // Now need to attach branch buffers of clones
1009  RooArgSet *anset(0), *acset(0) ;
1010  for (const auto arg : cloneSet) {
1011  arg->attachToVStore(*newCache) ;
1012 
1013  RooArgSet* argObs = nset ? arg->getObservables(*nset) : arg->getVariables() ;
1014  argObsList.push_back(argObs) ;
1015 
1016  RooArgSet* normSet(0) ;
1017  const char* catNset = arg->getStringAttribute("CATNormSet") ;
1018  if (catNset) {
1019 // cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a normalization set specification CATNormSet = " << catNset << endl ;
1020  RooNameSet rns ;
1021  rns.setNameList(catNset) ;
1022  anset = rns.select(nset?*nset:RooArgSet()) ;
1023  normSet = (RooArgSet*) anset->selectCommon(*argObs) ;
1024 
1025  }
1026  const char* catCset = arg->getStringAttribute("CATCondSet") ;
1027  if (catCset) {
1028 // cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a conditional observable set specification CATCondSet = " << catCset << endl ;
1029  RooNameSet rns ;
1030  rns.setNameList(catCset) ;
1031  acset = rns.select(nset?*nset:RooArgSet()) ;
1032 
1033  argObs->remove(*acset,kTRUE,kTRUE) ;
1034  normSet = argObs ;
1035  }
1036 
1037  // now construct normalization set for component from cset/nset spec
1038 // if (normSet) {
1039 // cout << "RooVectorDaraStore::cacheArgs() component " << arg->GetName() << " has custom normalization set " << *normSet << endl ;
1040 // }
1041  nsetList.push_back(normSet) ;
1042  }
1043 
1044 
1045  // Fill values of of placeholder
1046  const std::size_t numEvt = size();
1047  newCache->reserve(numEvt);
1048  for (std::size_t i=0; i < numEvt; i++) {
1049  getNative(i) ;
1050  if (weight()!=0 || !skipZeroWeights) {
1051  for (unsigned int j = 0; j < cloneSet.size(); ++j) {
1052  auto& cloneArg = cloneSet[j];
1053  auto argNSet = nsetList[j];
1054  // WVE need to intervene here for condobs from ProdPdf
1055  cloneArg.syncCache(argNSet ? argNSet : nset) ;
1056  }
1057  }
1058  newCache->fill() ;
1059  }
1060 
1062 
1063 
1064  // Now need to attach branch buffers of original function objects
1065  for (const auto arg : orderedArgs) {
1066  arg->attachToVStore(*newCache) ;
1067 
1068  // Activate change tracking mode, if requested
1069  if (!arg->getAttribute("ConstantExpression") && dynamic_cast<RooAbsReal*>(arg)) {
1070  RealVector* rv = newCache->addReal((RooAbsReal*)arg) ;
1071  RooArgSet* deps = arg->getParameters(_vars) ;
1072  rv->setDependents(*deps) ;
1073 
1074  // WV lookup normalization set and associate with RealVector
1075  // find ordinal number of arg in original list
1076  Int_t idx = cloneSet.index(arg->GetName()) ;
1077 
1078  coutI(Optimization) << "RooVectorDataStore::cacheArg() element " << arg->GetName() << " has change tracking enabled on parameters " << *deps << endl ;
1079  rv->setNset(nsetList[idx]) ;
1080  delete deps ;
1081  }
1082 
1083  }
1084 
1085 
1086  for (auto set : vlist) {
1087  delete set;
1088  }
1089  for (auto set : argObsList) {
1090  delete set;
1091  }
1092 
1093  _cache = newCache ;
1095 }
1096 
1097 
1099 {
1100  if (_cache) _forcedUpdate = kTRUE ;
1101 }
1102 
1103 
1104 
1105 ////////////////////////////////////////////////////////////////////////////////
1106 
1107 void RooVectorDataStore::recalculateCache( const RooArgSet *projectedArgs, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, Bool_t skipZeroWeights)
1108 {
1109  if (!_cache) return ;
1110 
1111  std::vector<RooVectorDataStore::RealVector *> tv;
1112  tv.reserve(static_cast<std::size_t>(_cache->_realStoreList.size() * 0.7)); // Typically, 30..60% need to be recalculated
1113 
1114  // Check which items need recalculation
1115  for (const auto realVec : _cache->_realStoreList) {
1116  if (_forcedUpdate || realVec->needRecalc()) {
1117  tv.push_back(realVec);
1118  realVec->_nativeReal->setOperMode(RooAbsArg::ADirty);
1119  realVec->_nativeReal->_operMode = RooAbsArg::Auto;
1120  }
1121  }
1122  _forcedUpdate = kFALSE ;
1123 
1124  // If no recalculations are needed stop here
1125  if (tv.empty()) {
1126  return;
1127  }
1128 
1129 
1130  // Refill caches of elements that require recalculation
1131  RooArgSet* ownedNset = 0 ;
1132  RooArgSet* usedNset = 0 ;
1133  if (projectedArgs && projectedArgs->getSize()>0) {
1134  ownedNset = (RooArgSet*) _vars.snapshot(kFALSE) ;
1135  ownedNset->remove(*projectedArgs,kFALSE,kTRUE);
1136  usedNset = ownedNset ;
1137  } else {
1138  usedNset = &_vars ;
1139  }
1140 
1141 
1142  for (int i=firstEvent ; i<lastEvent ; i+=stepSize) {
1143  get(i) ;
1144  Bool_t zeroWeight = (weight()==0) ;
1145  if (!zeroWeight || !skipZeroWeights) {
1146  for (auto realVector : tv) {
1147  realVector->_nativeReal->_valueDirty = kTRUE;
1148  realVector->_nativeReal->getValV(realVector->_nset ? realVector->_nset : usedNset);
1149  realVector->write(i);
1150  }
1151  }
1152  }
1153 
1154  for (auto realVector : tv) {
1155  realVector->_nativeReal->setOperMode(RooAbsArg::AClean);
1156  }
1157 
1158  delete ownedNset ;
1159 
1160 }
1161 
1162 
1163 ////////////////////////////////////////////////////////////////////////////////
1164 /// Initialize cache of dataset: attach variables of cache ArgSet
1165 /// to the corresponding TTree branches
1166 
1167 void RooVectorDataStore::attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVarsIn)
1168 {
1169  // Only applicable if a cache exists
1170  if (!_cache) return ;
1171 
1172  // Clone ctor, must connect internal storage to given new external set of vars
1173  std::vector<RealVector*> cacheElements(_cache->realStoreList());
1174  cacheElements.insert(cacheElements.end(), _cache->_realfStoreList.begin(), _cache->_realfStoreList.end());
1175 
1176  for (const auto elm : cacheElements) {
1177  auto real = static_cast<RooAbsReal*>(cachedVarsIn.find(elm->bufArg()->GetName()));
1178  if (real) {
1179  // Adjust buffer pointer
1180  real->attachToVStore(*_cache) ;
1181  }
1182  }
1183 
1184  for (const auto catVec : _cache->_catStoreList) {
1185  auto cat = static_cast<RooAbsCategory*>(cachedVarsIn.find(catVec->bufArg()->GetName()));
1186  if (cat) {
1187  // Adjust buffer pointer
1188  cat->attachToVStore(*_cache) ;
1189  }
1190  }
1191 
1192  _cacheOwner = (RooAbsArg*) newOwner ;
1193 }
1194 
1195 
1196 
1197 
1198 ////////////////////////////////////////////////////////////////////////////////
1199 
1201 {
1202  delete _cache;
1203  _cache = nullptr;
1204  _cacheOwner = nullptr;
1205  return ;
1206 }
1207 
1208 
1209 
1210 
1211 
1212 ////////////////////////////////////////////////////////////////////////////////
1213 /// Disabling of branches is (intentionally) not implemented in vector
1214 /// data stores (as the doesn't result in a net saving of time)
1215 
1216 void RooVectorDataStore::setArgStatus(const RooArgSet& /*set*/, Bool_t /*active*/)
1217 {
1218  return ;
1219 }
1220 
1221 
1222 
1223 
1224 ////////////////////////////////////////////////////////////////////////////////
1225 
1227 {
1228  for (auto arg : _varsww) {
1229  RooAbsArg* extArg = extObs.find(arg->GetName()) ;
1230  if (extArg) {
1231  extArg->attachToVStore(*this) ;
1232  }
1233  }
1234 }
1235 
1236 
1237 
1238 ////////////////////////////////////////////////////////////////////////////////
1239 
1241 {
1242  for (auto arg : _varsww) {
1243  arg->attachToVStore(*this);
1244  }
1245 }
1246 
1247 
1248 
1249 ////////////////////////////////////////////////////////////////////////////////
1250 
1252 {
1253  cout << "RooVectorDataStor::dump()" << endl ;
1254 
1255  cout << "_varsww = " << endl ; _varsww.Print("v") ;
1256  cout << "realVector list is" << endl ;
1257 
1258  for (const auto elm : _realStoreList) {
1259  cout << "RealVector " << elm << " _nativeReal = " << elm->_nativeReal << " = " << elm->_nativeReal->GetName() << " bufptr = " << elm->_buf << endl ;
1260  cout << " values : " ;
1261  Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1262  for (Int_t i=0 ; i<imax ; i++) {
1263  cout << elm->_vec[i] << " " ;
1264  }
1265  cout << endl ;
1266  }
1267 
1268  for (const auto elm : _realfStoreList) {
1269  cout << "RealFullVector " << elm << " _nativeReal = " << elm->_nativeReal << " = " << elm->_nativeReal->GetName()
1270  << " bufptr = " << elm->_buf << " errbufptr = " << elm->_bufE << endl ;
1271 
1272  cout << " values : " ;
1273  Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1274  for (Int_t i=0 ; i<imax ; i++) {
1275  cout << elm->_vec[i] << " " ;
1276  }
1277  cout << endl ;
1278  if (elm->_vecE) {
1279  cout << " errors : " ;
1280  for (Int_t i=0 ; i<imax ; i++) {
1281  cout << (*elm->_vecE)[i] << " " ;
1282  }
1283  cout << endl ;
1284 
1285  }
1286  }
1287 }
1288 
1289 
1290 ////////////////////////////////////////////////////////////////////////////////
1291 /// Stream an object of class RooVectorDataStore.
1292 
1293 void RooVectorDataStore::Streamer(TBuffer &R__b)
1294 {
1295  if (R__b.IsReading()) {
1297 
1298  for (auto elm : _realStoreList) {
1299  RooAbsArg* arg = _varsww.find(elm->_nativeReal->GetName()) ;
1300  arg->attachToVStore(*this) ;
1301  }
1302  for (auto elm : _realfStoreList) {
1303  RooAbsArg* arg = _varsww.find(elm->_nativeReal->GetName()) ;
1304  arg->attachToVStore(*this) ;
1305  }
1306  for (auto elm : _catStoreList) {
1307  RooAbsArg* arg = _varsww.find(elm->_cat->GetName()) ;
1308  arg->attachToVStore(*this) ;
1309  }
1310 
1311  } else {
1313  }
1314 }
1315 
1316 
1317 ////////////////////////////////////////////////////////////////////////////////
1318 /// Stream an object of class RooVectorDataStore::RealFullVector.
1319 
1320 void RooVectorDataStore::RealFullVector::Streamer(TBuffer &R__b)
1321 {
1322  if (R__b.IsReading()) {
1324 
1325  // WVE - It seems that ROOT persistence turns null pointers to vectors into pointers to null-sized vectors
1326  // Intervene here to remove those null-sized vectors and replace with null pointers to not break
1327  // assumptions made elsewhere in this class
1328  if (_vecE && _vecE->empty()) { delete _vecE ; _vecE = 0 ; }
1329  if (_vecEL && _vecEL->empty()) { delete _vecEL ; _vecEL = 0 ; }
1330  if (_vecEH && _vecEH->empty()) { delete _vecEH ; _vecEH = 0 ; }
1331  } else {
1333  }
1334 }
1335 
1336 
1337 ////////////////////////////////////////////////////////////////////////////////
1338 /// Return batches of the data columns for the requested events.
1339 /// \param[in] first First event in the batches.
1340 /// \param[in] len Number of events in batches.
1341 /// \return RunContext object whose member `spans` maps RooAbsReal pointers to spans with
1342 /// the associated data.
1344  RooBatchCompute::RunContext evalData;
1345 
1346  auto emplace = [this,&evalData,first,len](const RealVector* realVec) {
1347  auto span = realVec->getRange(first, first + len);
1348  auto result = evalData.spans.emplace(realVec->_nativeReal, span);
1349  if (result.second == false || result.first->second.size() != len) {
1350  const auto size = result.second ? result.first->second.size() : 0;
1351  coutE(DataHandling) << "A batch of data for '" << realVec->_nativeReal->GetName()
1352  << "' was requested from " << first << " to " << first+len
1353  << ", but only the events [" << first << ", " << first + size << ") are available." << std::endl;
1354  }
1355  if (realVec->_real) {
1356  // If a buffer is attached, i.e. we are ready to load into a RooAbsReal outside of our dataset,
1357  // we can directly map our spans to this real.
1358  evalData.spans.emplace(realVec->_real, std::move(span));
1359  }
1360  };
1361 
1362  for (const auto realVec : _realStoreList) {
1363  emplace(realVec);
1364  }
1365  for (const auto realVec : _realfStoreList) {
1366  emplace(realVec);
1367  }
1368 
1369  if (_cache) {
1370  for (const auto realVec : _cache->_realStoreList) {
1371  emplace(realVec);
1372  }
1373  for (const auto realVec : _cache->_realfStoreList) {
1374  emplace(realVec);
1375  }
1376  }
1377 
1378  return evalData;
1379 }
1380 
1381 
1382 ////////////////////////////////////////////////////////////////////////////////
1383 /// Return the weights of all events in the range [first, first+len).
1384 /// If an array with weights is stored, a batch with these weights will be returned. If
1385 /// no weights are stored, an empty batch is returned. Use weight() to check if there's
1386 /// a constant weight.
1388 {
1389  if (_extWgtArray) {
1391  }
1392 
1393  if (_wgtVar) {
1394  auto findWeightVar = [this](const RealVector* realVec) {
1395  return realVec->_nativeReal == _wgtVar || realVec->_nativeReal->GetName() == _wgtVar->GetName();
1396  };
1397 
1398  auto storageIter = std::find_if(_realStoreList.begin(), _realStoreList.end(), findWeightVar);
1399  if (storageIter != _realStoreList.end())
1400  return (*storageIter)->getRange(first, first + len);
1401 
1402  auto fstorageIter = std::find_if(_realfStoreList.begin(), _realfStoreList.end(), findWeightVar);
1403  if (fstorageIter != _realfStoreList.end())
1404  return (*fstorageIter)->getRange(first, first + len);
1405 
1406  throw std::logic_error("RooVectorDataStore::getWeightBatch(): Could not retrieve data for _wgtVar.");
1407  }
1408  return {};
1409 }
1410 
1411 
1413 
1414  // First try a match by name
1415  for (auto catVec : _catStoreList) {
1416  if (std::string(catVec->bufArg()->GetName())==cat->GetName()) {
1417  return catVec;
1418  }
1419  }
1420 
1421  // If nothing found this will make an entry
1422  _catStoreList.push_back(new CatVector(cat)) ;
1423 
1424  return _catStoreList.back() ;
1425 }
1426 
1427 
1429 
1430  // First try a match by name
1431  for (auto realVec : _realStoreList) {
1432  if (realVec->bufArg()->namePtr()==real->namePtr()) {
1433  return realVec;
1434  }
1435  }
1436 
1437  // Then check if an entry already exists for a full real
1438  for (auto fullVec : _realfStoreList) {
1439  if (fullVec->bufArg()->namePtr()==real->namePtr()) {
1440  // Return full vector as RealVector base class here
1441  return fullVec;
1442  }
1443  }
1444 
1445  // If nothing found this will make an entry
1446  _realStoreList.push_back(new RealVector(real)) ;
1447 
1448  return _realStoreList.back() ;
1449 }
1450 
1451 
1453 
1454  // First try a match by name
1455  for (auto fullVec : _realfStoreList) {
1456  if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1457  return kTRUE ;
1458  }
1459  }
1460  return kFALSE ;
1461 }
1462 
1463 
1465 
1466  // First try a match by name
1467  for (auto fullVec : _realfStoreList) {
1468  if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1469  return fullVec->_vecE ? kTRUE : kFALSE ;
1470  }
1471  }
1472  return kFALSE ;
1473 }
1474 
1475 
1477 
1478  // First try a match by name
1479  for (auto fullVec : _realfStoreList) {
1480  if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1481  return fullVec->_vecEL ? kTRUE : kFALSE ;
1482  }
1483  }
1484  return kFALSE ;
1485 }
1486 
1487 
1489 
1490  // First try a match by name
1491  for (auto fullVec : _realfStoreList) {
1492  if (std::string(fullVec->bufArg()->GetName())==real->GetName()) {
1493  return fullVec;
1494  }
1495  }
1496 
1497  // Then check if an entry already exists for a bare real
1498  for (auto realVec : _realStoreList) {
1499  if (std::string(realVec->bufArg()->GetName())==real->GetName()) {
1500 
1501  // Convert element to full and add to full list
1502  _realfStoreList.push_back(new RealFullVector(*realVec,real)) ;
1503 
1504  // Delete bare element
1505  _realStoreList.erase(std::find(_realStoreList.begin(), _realStoreList.end(), realVec));
1506  delete realVec;
1507 
1508  return _realfStoreList.back() ;
1509  }
1510  }
1511 
1512  // If nothing found this will make an entry
1513  _realfStoreList.push_back(new RealFullVector(real)) ;
1514 
1515  return _realfStoreList.back() ;
1516 }
RooFormulaVar.h
RooVectorDataStore::loadValues
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
Definition: RooVectorDataStore.cxx:589
RooRealVar::getAsymErrorHi
Double_t getAsymErrorHi() const
Definition: RooRealVar.h:65
RooAbsCategory::copyCache
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValueDirty=kTRUE)
Copy the cached value from given source and raise dirty flag.
Definition: RooAbsCategory.cxx:530
RooVectorDataStore::_extSumW2Array
const Double_t * _extSumW2Array
External weight array - high error.
Definition: RooVectorDataStore.h:639
RooVectorDataStore::addReal
RealVector * addReal(RooAbsReal *real)
Definition: RooVectorDataStore.cxx:1428
RooAbsArg::ADirty
@ ADirty
Definition: RooAbsArg.h:388
RooVectorDataStore::append
virtual void append(RooAbsDataStore &other) override
Definition: RooVectorDataStore.cxx:895
first
Definition: first.py:1
RooHelpers.h
RooRealVar::setVal
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:257
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:95
RooVectorDataStore::~RooVectorDataStore
virtual ~RooVectorDataStore()
Destructor.
Definition: RooVectorDataStore.cxx:337
RooMsgService.h
RooVectorDataStore::RealFullVector::_vecEL
std::vector< double > * _vecEL
Definition: RooVectorDataStore.h:487
RooVectorDataStore::recalculateCache
virtual void recalculateCache(const RooArgSet *, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, Bool_t skipZeroWeights) override
Definition: RooVectorDataStore.cxx:1107
RooAbsData::SumW2
@ SumW2
Definition: RooAbsData.h:99
RooVectorDataStore::changeObservableName
virtual Bool_t changeObservableName(const char *from, const char *to) override
Definition: RooVectorDataStore.cxx:686
RooFit.h
RooVectorDataStore::_realStoreList
std::vector< RealVector * > _realStoreList
Definition: RooVectorDataStore.h:626
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:68
RooVectorDataStore::addColumns
virtual RooArgSet * addColumns(const RooArgList &varList) override
Utility function to add multiple columns in one call See addColumn() for details.
Definition: RooVectorDataStore.cxx:770
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
RooAbsArg::Auto
@ Auto
Definition: RooAbsArg.h:388
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
RooVectorDataStore::cacheArgs
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...
Definition: RooVectorDataStore.cxx:939
RooTreeDataStore::get
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...
Definition: RooTreeDataStore.cxx:646
RooAbsCollection::assignValueOnly
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.
Definition: RooAbsCollection.cxx:330
TBuffer::ReadClassBuffer
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
RooVectorDataStore::weightVar
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return pointer to weight variable if it is defined.
Definition: RooVectorDataStore.cxx:145
RooVectorDataStore::CatVector::write
void write(std::size_t i)
Definition: RooVectorDataStore.h:545
coutE
#define coutE(a)
Definition: RooMsgService.h:33
RooAbsArg::namePtr
const TNamed * namePtr() const
Definition: RooAbsArg.h:530
RooVectorDataStore::RooVectorDataStore
RooVectorDataStore()
Definition: RooVectorDataStore.cxx:60
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooAbsData::Auto
@ Auto
Definition: RooAbsData.h:99
RooVectorDataStore::RealVector::setDependents
void setDependents(const RooArgSet &deps)
Definition: RooVectorDataStore.h:228
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooFit::Optimization
@ Optimization
Definition: RooGlobalFunc.h:68
RooAbsArg::createFundamental
virtual RooAbsArg * createFundamental(const char *newname=0) const =0
Create a fundamental-type object that stores our type of value.
Int_t
int Int_t
Definition: RtypesCore.h:45
RooAbsCollection::remove
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
Definition: RooAbsCollection.cxx:584
RooVectorDataStore::CatVector::resize
void resize(Int_t siz)
Definition: RooVectorDataStore.h:565
RooVectorDataStore::_cacheOwner
RooAbsArg * _cacheOwner
Optimization cache.
Definition: RooVectorDataStore.h:644
RooAbsCollection::find
RooAbsArg * find(const char *name) const
Find object with given name in list.
Definition: RooAbsCollection.cxx:813
RooVectorDataStore::_currentWeightIndex
std::size_t _currentWeightIndex
External sum of weights array.
Definition: RooVectorDataStore.h:641
coutI
#define coutI(a)
Definition: RooMsgService.h:30
TList.h
RooHistError::getPoissonInterval
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.
Definition: RooHistError.cxx:79
RooNameSet.h
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
TBuffer
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
RooVectorDataStore::size
std::size_t size() const
Get size of stored dataset.
Definition: RooVectorDataStore.h:111
RooNameSet::select
RooArgSet * select(const RooArgSet &list) const
Construct a RooArgSet of objects in input 'list' whose names match to those in the internal name list...
Definition: RooNameSet.cxx:185
RooAbsArg::attachToVStore
virtual void attachToVStore(RooVectorDataStore &vstore)=0
RooVectorDataStore::RealVector::setNset
void setNset(RooArgSet *newNset)
Definition: RooVectorDataStore.h:209
RooAbsArg::recursiveRedirectServers
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.
Definition: RooAbsArg.cxx:1123
RooVectorDataStore::_sumWeightCarry
Double_t _sumWeightCarry
Definition: RooVectorDataStore.h:634
RooAbsData::ErrorType
ErrorType
Definition: RooAbsData.h:99
RooVectorDataStore::get
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 ...
Definition: RooVectorDataStore.cxx:400
RooVectorDataStore::setAllBuffersNative
void setAllBuffersNative()
Definition: RooVectorDataStore.cxx:105
RooTreeDataStore.h
RooVectorDataStore::_extWgtErrLoArray
const Double_t * _extWgtErrLoArray
External weight array.
Definition: RooVectorDataStore.h:637
RooAbsCategory::attachToVStore
virtual void attachToVStore(RooVectorDataStore &vstore)
Attach the category index and label to as branches to the given vector store.
Definition: RooAbsCategory.cxx:428
RooVectorDataStore::hasAsymError
Bool_t hasAsymError(RooAbsReal *real)
Definition: RooVectorDataStore.cxx:1476
bool
RooVectorDataStore::dump
void dump() override
Definition: RooVectorDataStore.cxx:1251
RooVectorDataStore::_extWgtErrHiArray
const Double_t * _extWgtErrHiArray
External weight array - low error.
Definition: RooVectorDataStore.h:638
RooHistError::instance
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
Definition: RooHistError.cxx:49
RooVectorDataStore::realStoreList
std::vector< RealVector * > & realStoreList()
Definition: RooVectorDataStore.h:602
RooAbsCategory
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
Definition: RooAbsCategory.h:37
RooVectorDataStore::isFullReal
Bool_t isFullReal(RooAbsReal *real)
Definition: RooVectorDataStore.cxx:1452
RooAbsArg::getParameters
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) 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:579
RooVectorDataStore::reset
virtual void reset() override
Definition: RooVectorDataStore.cxx:913
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:118
RooTrace.h
hi
float type_of_call hi(const int &, const int &)
RooAbsData::Expected
@ Expected
Definition: RooAbsData.h:99
RooVectorDataStore::_forcedUpdate
Bool_t _forcedUpdate
Cache owner.
Definition: RooVectorDataStore.h:646
RooFit::DataHandling
@ DataHandling
Definition: RooGlobalFunc.h:69
RooVectorDataStore::valid
virtual Bool_t valid() const override
Return true if currently loaded coordinate is considered valid within the current range definitions o...
Definition: RooVectorDataStore.cxx:362
RooVectorDataStore::attachCache
virtual void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars) override
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
Definition: RooVectorDataStore.cxx:1167
RooFormulaVar
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
TBuffer.h
RooVectorDataStore::_realfStoreList
std::vector< RealFullVector * > _realfStoreList
Definition: RooVectorDataStore.h:627
RooRealVar::getError
Double_t getError() const
Definition: RooRealVar.h:60
TRACE_DESTROY
#define TRACE_DESTROY
Definition: RooTrace.h:24
RooRealVar::getAsymErrorLo
Double_t getAsymErrorLo() const
Definition: RooRealVar.h:64
RooVectorDataStore::weightError
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override
Return the error of the current weight.
Definition: RooVectorDataStore.cxx:487
RooVectorDataStore::addCategory
CatVector * addCategory(RooAbsCategory *cat)
Definition: RooVectorDataStore.cxx:1412
RooVectorDataStore::addColumn
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'.
Definition: RooVectorDataStore.cxx:714
RooAbsArg::syncCache
virtual void syncCache(const RooArgSet *nset=0)=0
RooAbsDataStore::_vars
RooArgSet _vars
Definition: RooAbsDataStore.h:126
TBuffer::WriteClassBuffer
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:96
RooArgSet::add
Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to non-owning set.
Definition: RooArgSet.cxx:261
RooAbsCollection::selectCommon
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
Definition: RooAbsCollection.cxx:700
RooVectorDataStore::weight
Double_t weight() const override
Return the weight of the last-retrieved data point.
Definition: RooVectorDataStore.h:76
RooVectorDataStore::setDirtyProp
virtual void setDirtyProp(Bool_t flag) override
Definition: RooVectorDataStore.h:152
RooAbsArg::attachDataStore
void attachDataStore(const RooAbsDataStore &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
Definition: RooAbsArg.cxx:1536
RooAbsArg::AClean
@ AClean
Definition: RooAbsArg.h:388
TRACE_CREATE
#define TRACE_CREATE
Definition: RooTrace.h:23
RooAbsCollection::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:437
RooCategory.h
y
Double_t y[n]
Definition: legend1.C:17
sqrt
double sqrt(double)
RooVectorDataStore::RealVector::write
void write(Int_t i)
Definition: RooVectorDataStore.h:244
RooVectorDataStore::RealVector
Definition: RooVectorDataStore.h:161
RooRealVar.h
RooAbsDataStore::get
virtual const RooArgSet * get(Int_t index) const =0
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
RooVectorDataStore::getWeightBatch
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).
Definition: RooVectorDataStore.cxx:1387
RooVectorDataStore::_cache
RooVectorDataStore * _cache
Definition: RooVectorDataStore.h:643
RooVectorDataStore::RealFullVector::_vecEH
std::vector< double > * _vecEH
Definition: RooVectorDataStore.h:487
RooVectorDataStore::CatVector
Definition: RooVectorDataStore.h:492
RooTreeDataStore::numEntries
virtual Int_t numEntries() const
Definition: RooTreeDataStore.cxx:1116
RooTreeDataStore
RooTreeDataStore is a TTree-backed data storage.
Definition: RooTreeDataStore.h:32
RooAbsData::Poisson
@ Poisson
Definition: RooAbsData.h:99
RooAbsDataStore::weight
virtual Double_t weight() const =0
RooVectorDataStore::merge
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList) override
Merge columns of supplied data set(s) with this data set.
Definition: RooVectorDataStore.cxx:854
RooVectorDataStore::hasError
Bool_t hasError(RooAbsReal *real)
Definition: RooVectorDataStore.cxx:1464
RooVectorDataStore::numEntries
virtual Int_t numEntries() const override
Definition: RooVectorDataStore.h:108
RooAbsArg::isFundamental
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
RooHelpers::tokenise
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: RooHelpers.cxx:62
RooVectorDataStore::RealVector::resize
void resize(Int_t siz)
Definition: RooVectorDataStore.h:271
RooAbsDataStore::numEntries
virtual Int_t numEntries() const =0
RooAbsData::None
@ None
Definition: RooAbsData.h:99
RooAbsDataStore::_doDirtyProp
Bool_t _doDirtyProp
Definition: RooAbsDataStore.h:133
TBuffer::IsReading
Bool_t IsReading() const
Definition: TBuffer.h:86
RooNameSet
RooNameSet is a utility class that stores the names the objects in a RooArget.
Definition: RooNameSet.h:24
RooAbsDataStore::checkInit
virtual void checkInit() const
Definition: RooAbsDataStore.h:116
RooVectorDataStore::get
virtual const RooArgSet * get(Int_t index) const=0
Double_t
double Double_t
Definition: RtypesCore.h:59
RooVectorDataStore::_varsww
RooArgSet _varsww
Definition: RooVectorDataStore.h:623
RooVectorDataStore::addRealFull
RealFullVector * addRealFull(RooAbsReal *real)
Definition: RooVectorDataStore.cxx:1488
RooVectorDataStore::RealFullVector
Definition: RooVectorDataStore.h:309
RooVectorDataStore
RooVectorDataStore uses std::vectors to store data columns.
Definition: RooVectorDataStore.h:37
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
RooRealVar::hasAsymError
Bool_t hasAsymError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:66
RooVectorDataStore::resetBuffers
virtual void resetBuffers() override
Definition: RooVectorDataStore.cxx:1240
RooVectorDataStore::getNative
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 ...
Definition: RooVectorDataStore.cxx:437
RooAbsArg::cloneTree
virtual RooAbsArg * cloneTree(const char *newname=0) const
Clone tree expression of objects.
Definition: RooAbsArg.cxx:2194
name
char name[80]
Definition: TGX11.cxx:110
RooNameSet::setNameList
void setNameList(const char *givenList)
Definition: RooNameSet.cxx:142
RooVectorDataStore::_wgtVar
RooRealVar * _wgtVar
Definition: RooVectorDataStore.h:624
RunContext.h
RooVectorDataStore::resetCache
virtual void resetCache() override
Definition: RooVectorDataStore.cxx:1200
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooVectorDataStore::getBatches
RooBatchCompute::RunContext getBatches(std::size_t first, std::size_t len) const override
Return batches of the data columns for the requested events.
Definition: RooVectorDataStore.cxx:1343
RooAbsCollection::Print
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
Definition: RooAbsCollection.h:210
RooVectorDataStore::reserve
void reserve(Int_t nEvt)
Definition: RooVectorDataStore.cxx:878
RooAbsArg::setDirtyInhibit
static void setDirtyInhibit(Bool_t flag)
Control global dirty inhibit mode.
Definition: RooAbsArg.cxx:265
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
RooVectorDataStore.h
RooAbsDataStore
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
Definition: RooAbsDataStore.h:34
RooVectorDataStore::RealFullVector::_vecE
std::vector< double > * _vecE
Definition: RooVectorDataStore.h:487
RooVectorDataStore::fill
virtual Int_t fill() override
Interface function to TTree::Fill.
Definition: RooVectorDataStore.cxx:373
Class
void Class()
Definition: Class.C:29
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
RooHistError.h
RooVectorDataStore::attachBuffers
virtual void attachBuffers(const RooArgSet &extObs) override
Definition: RooVectorDataStore.cxx:1226
RooVectorDataStore::_extWgtArray
const Double_t * _extWgtArray
Definition: RooVectorDataStore.h:636
RooTreeDataStore::_varsww
RooArgSet _varsww
Was object constructed with default ctor?
Definition: RooTreeDataStore.h:163
RooVectorDataStore::_catStoreList
std::vector< CatVector * > _catStoreList
Definition: RooVectorDataStore.h:628
RooBatchCompute::RunContext::spans
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
RooBatchCompute::RunContext
This struct enables passing computation data around between elements of a computation graph.
Definition: RunContext.h:31
RooVectorDataStore::forceCacheUpdate
void forceCacheUpdate() override
Definition: RooVectorDataStore.cxx:1098
RooVectorDataStore::setArgStatus
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...
Definition: RooVectorDataStore.cxx:1216
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:182
TList
A doubly linked list.
Definition: TList.h:44
RooSpan
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
RooVectorDataStore::varsNoWeight
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
Definition: RooVectorDataStore.cxx:127
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
RooRealVar::hasError
Bool_t hasError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:61
int
RooVectorDataStore::_sumWeight
Double_t _sumWeight
Definition: RooVectorDataStore.h:633
RooAbsArg::getAttribute
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:315
RooAbsReal::attachToVStore
virtual void attachToVStore(RooVectorDataStore &vstore)
Definition: RooAbsReal.cxx:3233