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