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