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