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