ROOT  6.06/09
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 //
19 // BEGIN_HTML
20 // RooVectorDataStore is the abstract base class for data collection that
21 // use a TTree as internal storage mechanism
22 // END_HTML
23 //
24 
25 #include "RooFit.h"
26 #include "RooMsgService.h"
27 #include "RooVectorDataStore.h"
28 #include "RooTreeDataStore.h"
29 
30 #include "Riostream.h"
31 #include "TTree.h"
32 #include "TChain.h"
33 #include "TDirectory.h"
34 #include "TROOT.h"
35 #include "RooFormulaVar.h"
36 #include "RooRealVar.h"
37 #include "RooCategory.h"
38 #include "RooNameSet.h"
39 #include "RooHistError.h"
40 #include "RooTrace.h"
41 
42 #include <iomanip>
43 #include <algorithm>
44 #include <memory>
45 using namespace std ;
46 
48 ClassImp(RooVectorDataStore::RealVector)
49 ;
50 
51 
52 
53 
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 
58  _wgtVar(0),
59  _nReal(0),
60  _nRealF(0),
61  _nCat(0),
62  _nEntries(0),
63  _firstReal(0),
64  _firstRealF(0),
65  _firstCat(0),
66  _sumWeight(0),
67  _sumWeightCarry(0),
68  _extWgtArray(0),
69  _extWgtErrLoArray(0),
70  _extWgtErrHiArray(0),
71  _extSumW2Array(0),
72  _curWgt(1),
73  _curWgtErrLo(0),
74  _curWgtErrHi(0),
75  _curWgtErr(0),
76  _cache(0),
77  _cacheOwner(0),
78  _forcedUpdate(kFALSE)
79 {
81 }
82 
83 
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 
87 RooVectorDataStore::RooVectorDataStore(const char* name, const char* title, const RooArgSet& vars, const char* wgtVarName) :
88  RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
89  _varsww(vars),
90  _wgtVar(weightVar(vars,wgtVarName)),
91  _nReal(0),
92  _nRealF(0),
93  _nCat(0),
94  _nEntries(0),
95  _firstReal(0),
96  _firstRealF(0),
97  _firstCat(0),
98  _sumWeight(0),
99  _sumWeightCarry(0),
100  _extWgtArray(0),
101  _extWgtErrLoArray(0),
102  _extWgtErrHiArray(0),
103  _extSumW2Array(0),
104  _curWgt(1),
105  _curWgtErrLo(0),
106  _curWgtErrHi(0),
107  _curWgtErr(0),
108  _cache(0),
109  _cacheOwner(0),
110  _forcedUpdate(kFALSE)
111 {
113  RooAbsArg* arg ;
114  while((arg=(RooAbsArg*)iter->Next())) {
115  arg->attachToVStore(*this) ;
116  }
117  delete iter ;
118 
121 }
122 
123 
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 
128 {
129  vector<RealVector*>::const_iterator oiter = _realStoreList.begin() ;
130  for (; oiter!=_realStoreList.end() ; ++oiter) {
131  (*oiter)->setNativeBuffer() ;
132  }
133 
134  vector<RealFullVector*>::const_iterator fiter = _realfStoreList.begin() ;
135  for (; fiter!=_realfStoreList.end() ; ++fiter) {
136  (*fiter)->setNativeBuffer() ;
137  }
138 
139  vector<CatVector*>::const_iterator citer = _catStoreList.begin() ;
140  for (; citer!=_catStoreList.end() ; ++citer) {
141  (*citer)->setNativeBuffer() ;
142  }
143 }
144 
145 
146 
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Utility function for constructors
150 /// Return RooArgSet that is copy of allVars minus variable matching wgtName if specified
151 
152 RooArgSet RooVectorDataStore::varsNoWeight(const RooArgSet& allVars, const char* wgtName)
153 {
154  RooArgSet ret(allVars) ;
155  if(wgtName) {
156  RooAbsArg* wgt = allVars.find(wgtName) ;
157  if (wgt) {
158  ret.remove(*wgt,kTRUE,kTRUE) ;
159  }
160  }
161  return ret ;
162 }
163 
164 
165 
166 ////////////////////////////////////////////////////////////////////////////////
167 /// Utility function for constructors
168 /// Return pointer to weight variable if it is defined
169 
170 RooRealVar* RooVectorDataStore::weightVar(const RooArgSet& allVars, const char* wgtName)
171 {
172  if(wgtName) {
173  RooRealVar* wgt = dynamic_cast<RooRealVar*>(allVars.find(wgtName)) ;
174  return wgt ;
175  }
176  return 0 ;
177 }
178 
179 
180 
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 /// Regular copy ctor
184 
185 RooVectorDataStore::RooVectorDataStore(const RooVectorDataStore& other, const char* newname) :
186  RooAbsDataStore(other,newname),
187  _varsww(other._varsww),
188  _wgtVar(other._wgtVar),
189  _nReal(0),
190  _nRealF(0),
191  _nCat(0),
192  _nEntries(other._nEntries),
193  _sumWeight(other._sumWeight),
194  _sumWeightCarry(other._sumWeightCarry),
195  _extWgtArray(other._extWgtArray),
196  _extWgtErrLoArray(other._extWgtErrLoArray),
197  _extWgtErrHiArray(other._extWgtErrHiArray),
198  _extSumW2Array(other._extSumW2Array),
199  _curWgt(other._curWgt),
200  _curWgtErrLo(other._curWgtErrLo),
201  _curWgtErrHi(other._curWgtErrHi),
202  _curWgtErr(other._curWgtErr),
203  _cache(0),
204  _cacheOwner(0),
205  _forcedUpdate(kFALSE)
206 {
207  vector<RealVector*>::const_iterator oiter = other._realStoreList.begin() ;
208  for (; oiter!=other._realStoreList.end() ; ++oiter) {
209  _realStoreList.push_back(new RealVector(**oiter,(RooAbsReal*)_varsww.find((*oiter)->_nativeReal->GetName()))) ;
210  _nReal++ ;
211  }
212 
213  vector<RealFullVector*>::const_iterator fiter = other._realfStoreList.begin() ;
214  for (; fiter!=other._realfStoreList.end() ; ++fiter) {
215  _realfStoreList.push_back(new RealFullVector(**fiter,(RooAbsReal*)_varsww.find((*fiter)->_nativeReal->GetName()))) ;
216  _nRealF++ ;
217  }
218 
219  vector<CatVector*>::const_iterator citer = other._catStoreList.begin() ;
220  for (; citer!=other._catStoreList.end() ; ++citer) {
221  _catStoreList.push_back(new CatVector(**citer,(RooAbsCategory*)_varsww.find((*citer)->_cat->GetName()))) ;
222  _nCat++ ;
223  }
224 
226 
227  _firstReal = _realStoreList.size()>0 ? &_realStoreList.front() : 0 ;
228  _firstRealF = _realfStoreList.size()>0 ? &_realfStoreList.front() : 0 ;
229  _firstCat = _catStoreList.size()>0 ? &_catStoreList.front() : 0 ;
231 }
232 
233 
234 ////////////////////////////////////////////////////////////////////////////////
235 
236 RooVectorDataStore::RooVectorDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname) :
237  RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
238  _varsww(vars),
239  _wgtVar(weightVar(vars,other._wgtVar?other._wgtVar->GetName():0)),
240  _nReal(0),
241  _nRealF(0),
242  _nCat(0),
243  _nEntries(0),
244  _firstReal(0),
245  _firstRealF(0),
246  _firstCat(0),
247  _sumWeight(0),
248  _sumWeightCarry(0),
249  _extWgtArray(0),
250  _extWgtErrLoArray(0),
251  _extWgtErrHiArray(0),
252  _extSumW2Array(0),
253  _curWgt(1),
254  _curWgtErrLo(0),
255  _curWgtErrHi(0),
256  _curWgtErr(0),
257  _cache(0),
258  _cacheOwner(0),
259  _forcedUpdate(kFALSE)
260 {
262  RooAbsArg* arg ;
263  while((arg=(RooAbsArg*)iter->Next())) {
264  arg->attachToVStore(*this) ;
265  }
266  delete iter ;
267 
269 
270  // now copy contents of tree storage here
271  reserve(other.numEntries());
272  for (Int_t i=0 ; i<other.numEntries() ; i++) {
273  other.get(i) ;
274  _varsww = other._varsww ;
275  fill() ;
276  }
278 
279 }
280 
281 
282 ////////////////////////////////////////////////////////////////////////////////
283 /// Clone ctor, must connect internal storage to given new external set of vars
284 
285 RooVectorDataStore::RooVectorDataStore(const RooVectorDataStore& other, const RooArgSet& vars, const char* newname) :
286  RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
287  _varsww(vars),
288  _wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):0),
289  _nReal(0),
290  _nRealF(0),
291  _nCat(0),
292  _nEntries(other._nEntries),
293  _sumWeight(other._sumWeight),
294  _sumWeightCarry(other._sumWeightCarry),
295  _extWgtArray(other._extWgtArray),
296  _extWgtErrLoArray(other._extWgtErrLoArray),
297  _extWgtErrHiArray(other._extWgtErrHiArray),
298  _extSumW2Array(other._extSumW2Array),
299  _curWgt(other._curWgt),
300  _curWgtErrLo(other._curWgtErrLo),
301  _curWgtErrHi(other._curWgtErrHi),
302  _curWgtErr(other._curWgtErr),
303  _cache(0),
304  _forcedUpdate(kFALSE)
305 {
306  vector<RealVector*>::const_iterator oiter = other._realStoreList.begin() ;
307  for (; oiter!=other._realStoreList.end() ; ++oiter) {
308  RooAbsReal* real = (RooAbsReal*) vars.find((*oiter)->bufArg()->GetName()) ;
309  if (real) {
310  // Clone vector
311  _realStoreList.push_back(new RealVector(**oiter,real)) ;
312  // Adjust buffer pointer
313  real->attachToVStore(*this) ;
314  _nReal++ ;
315  }
316  }
317 
318  vector<RealFullVector*>::const_iterator fiter = other._realfStoreList.begin() ;
319  for (; fiter!=other._realfStoreList.end() ; ++fiter) {
320  RooAbsReal* real = (RooAbsReal*) vars.find((*fiter)->bufArg()->GetName()) ;
321  if (real) {
322  // Clone vector
323  _realfStoreList.push_back(new RealFullVector(**fiter,real)) ;
324  // Adjust buffer pointer
325  real->attachToVStore(*this) ;
326  _nRealF++ ;
327  }
328  }
329 
330  vector<CatVector*>::const_iterator citer = other._catStoreList.begin() ;
331  for (; citer!=other._catStoreList.end() ; ++citer) {
332  RooAbsCategory* cat = (RooAbsCategory*) vars.find((*citer)->bufArg()->GetName()) ;
333  if (cat) {
334  // Clone vector
335  _catStoreList.push_back(new CatVector(**citer,cat)) ;
336  // Adjust buffer pointer
337  cat->attachToVStore(*this) ;
338  _nCat++ ;
339  }
340  }
341 
343 
344  _firstReal = _realStoreList.size()>0 ? &_realStoreList.front() : 0 ;
345  _firstRealF = _realfStoreList.size()>0 ? &_realfStoreList.front() : 0 ;
346  _firstCat = _catStoreList.size()>0 ? &_catStoreList.front() : 0 ;
348 
349 }
350 
351 
352 
353 
354 
355 ////////////////////////////////////////////////////////////////////////////////
356 
357 RooVectorDataStore::RooVectorDataStore(const char *name, const char *title, RooAbsDataStore& tds,
358  const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
359  Int_t nStart, Int_t nStop, Bool_t /*copyCache*/, const char* wgtVarName) :
360 
361  RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
362  _varsww(vars),
363  _wgtVar(weightVar(vars,wgtVarName)),
364  _nReal(0),
365  _nRealF(0),
366  _nCat(0),
367  _nEntries(0),
368  _firstReal(0),
369  _firstRealF(0),
370  _firstCat(0),
371  _sumWeight(0),
372  _sumWeightCarry(0),
373  _extWgtArray(0),
374  _extWgtErrLoArray(0),
375  _extWgtErrHiArray(0),
376  _extSumW2Array(0),
377  _curWgt(1),
378  _curWgtErrLo(0),
379  _curWgtErrHi(0),
380  _curWgtErr(0),
381  _cache(0),
382  _forcedUpdate(kFALSE)
383 {
385  RooAbsArg* arg ;
386  while((arg=(RooAbsArg*)iter->Next())) {
387  arg->attachToVStore(*this) ;
388  }
389  delete iter ;
390 
392 
393  // Deep clone cutVar and attach clone to this dataset
394  RooFormulaVar* cloneVar = 0;
395  if (cutVar) {
396  cloneVar = (RooFormulaVar*) cutVar->cloneTree() ;
397  cloneVar->attachDataStore(tds) ;
398  }
399 
400  RooVectorDataStore* vds = dynamic_cast<RooVectorDataStore*>(&tds) ;
401  if (vds && vds->_cache) {
402  _cache = new RooVectorDataStore(*vds->_cache) ;
403  }
404 
405  loadValues(&tds,cloneVar,cutRange,nStart,nStop);
406 
407  delete cloneVar ;
409 }
410 
411 
412 
413 
414 
415 
416 ////////////////////////////////////////////////////////////////////////////////
417 /// Destructor
418 
420 {
421  vector<RealVector*>::const_iterator iter = _realStoreList.begin(), iend = _realStoreList.end() ;
422  for ( ; iter!=iend ; ++iter) {
423  delete *iter ;
424  }
425 
426  vector<RealFullVector*>::const_iterator iter3 = _realfStoreList.begin(), iend3 = _realfStoreList.end() ;
427  for ( ; iter3!=iend3 ; ++iter3) {
428  delete *iter3 ;
429  }
430 
431  vector<CatVector*>::const_iterator iter2 = _catStoreList.begin(), iend2 = _catStoreList.end() ;
432  for ( ; iter2!=iend2 ; ++iter2) {
433  delete *iter2 ;
434  }
435 
436  delete _cache ;
438 }
439 
440 
441 
442 
443 ////////////////////////////////////////////////////////////////////////////////
444 /// Return true if currently loaded coordinate is considered valid within
445 /// the current range definitions of all observables
446 
448 {
449  return kTRUE ;
450 }
451 
452 
453 
454 
455 ////////////////////////////////////////////////////////////////////////////////
456 /// Interface function to TTree::Fill
457 
459 {
460  vector<RealVector*>::iterator iter = _realStoreList.begin() ;
461  for ( ; iter!=_realStoreList.end() ; ++iter) {
462  (*iter)->fill() ;
463  }
464  vector<RealFullVector*>::iterator iter3 = _realfStoreList.begin() ;
465  for ( ; iter3!=_realfStoreList.end() ; ++iter3) {
466  (*iter3)->fill() ;
467  }
468  vector<CatVector*>::iterator iter2 = _catStoreList.begin() ;
469  for ( ; iter2!=_catStoreList.end() ; ++iter2) {
470  (*iter2)->fill() ;
471  }
472  // use Kahan's algorithm to sum up weights to avoid loss of precision
474  Double_t t = _sumWeight + y;
475  _sumWeightCarry = (t - _sumWeight) - y;
476  _sumWeight = t;
477  _nEntries++ ;
478 
479  return 0 ;
480 }
481 
482 
483 
484 ////////////////////////////////////////////////////////////////////////////////
485 /// Load the n-th data point (n='index') in memory
486 /// and return a pointer to the internal RooArgSet
487 /// holding its coordinates.
488 
490 {
491  if (index>=_nEntries) return 0 ;
492 
493  for (Int_t i=0 ; i<_nReal ; i++) {
494  (*(_firstReal+i))->get(index) ;
495  }
496 
497  if (_nRealF>0) {
498  for (Int_t i=0 ; i<_nRealF ; i++) {
499  (*(_firstRealF+i))->get(index) ;
500  }
501  }
502 
503  if (_nCat>0) {
504  for (Int_t i=0 ; i<_nCat ; i++) {
505  (*(_firstCat+i))->get(index) ;
506  }
507  }
508 
509  if (_doDirtyProp) {
510  // Raise all dirty flags
511  _iterator->Reset() ;
512  RooAbsArg* var = 0;
513  while ((var=(RooAbsArg*)_iterator->Next())) {
514  var->setValueDirty() ; // This triggers recalculation of all clients
515  }
516  }
517 
518  // Update current weight cache
519  if (_extWgtArray) {
520 
521  // If external array is specified use that
522  _curWgt = _extWgtArray[index] ;
525  _curWgtErr = sqrt(_extSumW2Array[index]) ;
526 
527  } else if (_wgtVar) {
528 
529  // Otherwise look for weight variable
530  _curWgt = _wgtVar->getVal() ;
534 
535  } // else {
536 
537 // // Otherwise return 1
538 // _curWgt=1.0 ;
539 // _curWgtErrLo = 0 ;
540 // _curWgtErrHi = 0 ;
541 // _curWgtErr = 0 ;
542 
543 // }
544 
545  if (_cache) {
546  _cache->get(index) ;
547  }
548 
549  return &_vars;
550 }
551 
552 
553 
554 ////////////////////////////////////////////////////////////////////////////////
555 /// Load the n-th data point (n='index') in memory
556 /// and return a pointer to the internal RooArgSet
557 /// holding its coordinates.
558 
560 {
561  if (index>=_nEntries) return 0 ;
562 
563  for (Int_t i=0 ; i<_nReal ; i++) {
564  (*(_firstReal+i))->getNative(index) ;
565  }
566 
567  if (_nRealF>0) {
568  for (Int_t i=0 ; i<_nRealF ; i++) {
569  (*(_firstRealF+i))->getNative(index) ;
570  }
571  }
572 
573  if (_nCat>0) {
574  for (Int_t i=0 ; i<_nCat ; i++) {
575  (*(_firstCat+i))->getNative(index) ;
576  }
577  }
578 
579  if (_doDirtyProp) {
580  // Raise all dirty flags
581  _iterator->Reset() ;
582  RooAbsArg* var = 0;
583  while ((var=(RooAbsArg*)_iterator->Next())) {
584  var->setValueDirty() ; // This triggers recalculation of all clients
585  }
586  }
587 
588  // Update current weight cache
589  if (_extWgtArray) {
590 
591  // If external array is specified use that
592  _curWgt = _extWgtArray[index] ;
595  _curWgtErr = sqrt(_extSumW2Array[index]) ;
596 
597  } else if (_wgtVar) {
598 
599  // Otherwise look for weight variable
600  _curWgt = _wgtVar->getVal() ;
604 
605  } else {
606 
607  // Otherwise return 1
608  _curWgt=1.0 ;
609  _curWgtErrLo = 0 ;
610  _curWgtErrHi = 0 ;
611  _curWgtErr = 0 ;
612 
613  }
614 
615  if (_cache) {
616  _cache->getNative(index) ;
617  }
618 
619  return &_vars;
620 }
621 
622 
623 
624 ////////////////////////////////////////////////////////////////////////////////
625 /// Return the weight of the n-th data point (n='index') in memory
626 
628 {
629  get(index) ;
630  return weight() ;
631 }
632 
633 
634 
635 ////////////////////////////////////////////////////////////////////////////////
636 /// Return the weight of the n-th data point (n='index') in memory
637 
639 {
640  return _curWgt ;
641 }
642 
643 
644 ////////////////////////////////////////////////////////////////////////////////
645 
647 {
648  if (_extWgtArray) {
649 
650  // We have a weight array, use that info
651 
652  // Return symmetric error on current bin calculated either from Poisson statistics or from SumOfWeights
653  Double_t lo,hi ;
654  weightError(lo,hi,etype) ;
655  return (lo+hi)/2 ;
656 
657  } else if (_wgtVar) {
658 
659  // We have a a weight variable, use that info
660  if (_wgtVar->hasAsymError()) {
661  return ( _wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo() ) / 2 ;
662  } else if (_wgtVar->hasError(kFALSE)) {
663  return _wgtVar->getError() ;
664  } else {
665  return 0 ;
666  }
667 
668  } else {
669 
670  // We have no weights
671  return 0 ;
672 
673  }
674 }
675 
676 
677 
678 ////////////////////////////////////////////////////////////////////////////////
679 
681 {
682  if (_extWgtArray) {
683 
684  // We have a weight array, use that info
685  switch (etype) {
686 
687  case RooAbsData::Auto:
688  throw string(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
689  break ;
690 
692  throw string(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
693  break ;
694 
695  case RooAbsData::Poisson:
696  // Weight may be preset or precalculated
697  if (_curWgtErrLo>=0) {
698  lo = _curWgtErrLo ;
699  hi = _curWgtErrHi ;
700  return ;
701  }
702 
703  // Otherwise Calculate poisson errors
704  Double_t ym,yp ;
706  lo = weight()-ym ;
707  hi = yp-weight() ;
708  return ;
709 
710  case RooAbsData::SumW2:
711  lo = _curWgtErr ;
712  hi = _curWgtErr ;
713  return ;
714 
715  case RooAbsData::None:
716  lo = 0 ;
717  hi = 0 ;
718  return ;
719  }
720 
721  } else if (_wgtVar) {
722 
723  // We have a a weight variable, use that info
724  if (_wgtVar->hasAsymError()) {
725  hi = _wgtVar->getAsymErrorHi() ;
726  lo = _wgtVar->getAsymErrorLo() ;
727  } else {
728  hi = _wgtVar->getError() ;
729  lo = _wgtVar->getError() ;
730  }
731 
732  } else {
733 
734  // We are unweighted
735  lo=0 ;
736  hi=0 ;
737 
738  }
739 }
740 
741 
742 
743 ////////////////////////////////////////////////////////////////////////////////
744 /// throw(std::string("RooVectorDataSore::loadValues() NOT IMPLEMENTED")) ;
745 
746 void RooVectorDataStore::loadValues(const RooAbsDataStore *ads, const RooFormulaVar* select, const char* rangeName, Int_t nStart, Int_t nStop)
747 {
748  // Load values from dataset 't' into this data collection, optionally
749  // selecting events using 'select' RooFormulaVar
750  //
751 
752  // Redirect formula servers to source data row
753  RooFormulaVar* selectClone(0) ;
754  if (select) {
755  selectClone = (RooFormulaVar*) select->cloneTree() ;
756  selectClone->recursiveRedirectServers(*ads->get()) ;
757  selectClone->setOperMode(RooAbsArg::ADirty,kTRUE) ;
758  }
759 
760  // Force DS internal initialization
761  ads->get(0) ;
762 
763  // Loop over events in source tree
764  RooAbsArg* arg = 0;
765  TIterator* destIter = _varsww.createIterator() ;
766  Int_t nevent = nStop < ads->numEntries() ? nStop : ads->numEntries() ;
767  Bool_t allValid ;
768 
769  Bool_t isTDS = dynamic_cast<const RooTreeDataStore*>(ads) ;
770  Bool_t isVDS = dynamic_cast<const RooVectorDataStore*>(ads) ;
771 
772  // Check if weight is being renamed - if so set flag to enable special handling in copy loop
773  Bool_t weightRename(kFALSE) ;
774  Bool_t newWeightVar = _wgtVar ? _wgtVar->getAttribute("NewWeight") : kFALSE ;
775 
776  if (_wgtVar && isVDS && ((RooVectorDataStore*)(ads))->_wgtVar) {
777  if (string(_wgtVar->GetName())!=((RooVectorDataStore*)(ads))->_wgtVar->GetName() && !newWeightVar) {
778  weightRename=kTRUE ;
779  }
780  }
781  if (_wgtVar && isTDS && ((RooTreeDataStore*)(ads))->_wgtVar) {
782  if (string(_wgtVar->GetName())!=((RooTreeDataStore*)(ads))->_wgtVar->GetName() && !newWeightVar) {
783  weightRename=kTRUE ;
784  }
785  }
786 
787  reserve(numEntries() + (nevent - nStart));
788  for(Int_t i=nStart; i < nevent ; ++i) {
789  ads->get(i) ;
790 
791  // Does this event pass the cuts?
792  if (selectClone && selectClone->getVal()==0) {
793  continue ;
794  }
795 
796 
797  if (isTDS) {
799  if (weightRename) {
801  }
802  } else if (isVDS) {
804  if (weightRename) {
806  }
807  } else {
808  _varsww.assignValueOnly(*ads->get()) ;
809  }
810 
811  destIter->Reset() ;
812  // Check that all copied values are valid
813  allValid=kTRUE ;
814  while((arg=(RooAbsArg*)destIter->Next())) {
815  if (!arg->isValid() || (rangeName && !arg->inRange(rangeName))) {
816  allValid=kFALSE ;
817  break ;
818  }
819  }
820  if (!allValid) {
821  continue ;
822  }
823 
824  //_cachedVars = ((RooTreeDataStore*)ads)->_cachedVars ;
825  fill() ;
826  }
827 
828  delete destIter ;
829  delete selectClone ;
830 
831  SetTitle(ads->GetTitle());
832 }
833 
834 
835 
836 
837 
838 ////////////////////////////////////////////////////////////////////////////////
839 
840 Bool_t RooVectorDataStore::changeObservableName(const char* /*from*/, const char* /*to*/)
841 {
842  return kFALSE ;
843 }
844 
845 
846 
847 ////////////////////////////////////////////////////////////////////////////////
848 /// Add a new column to the data set which holds the pre-calculated values
849 /// of 'newVar'. This operation is only meaningful if 'newVar' is a derived
850 /// value.
851 ///
852 /// The return value points to the added element holding 'newVar's value
853 /// in the data collection. The element is always the corresponding fundamental
854 /// type of 'newVar' (e.g. a RooRealVar if 'newVar' is a RooFormulaVar)
855 ///
856 /// Note: This function is explicitly NOT intended as a speed optimization
857 /// opportunity for the user. Components of complex PDFs that can be
858 /// precalculated with the dataset are automatically identified as such
859 /// and will be precalculated when fitting to a dataset
860 ///
861 /// By forcibly precalculating functions with non-trivial Jacobians,
862 /// or functions of multiple variables occurring in the data set,
863 /// using addColumn(), you may alter the outcome of the fit.
864 ///
865 /// Only in cases where such a modification of fit behaviour is intentional,
866 /// this function should be used.
867 
869 {
870  // Create a fundamental object of the right type to hold newVar values
871  RooAbsArg* valHolder= newVar.createFundamental();
872  // Sanity check that the holder really is fundamental
873  if(!valHolder->isFundamental()) {
874  coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
875  << valHolder->GetName() << "\"" << endl;
876  return 0;
877  }
878 
879  // Clone variable and attach to cloned tree
880  RooAbsArg* newVarClone = newVar.cloneTree() ;
881  newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
882 
883  // Attach value place holder to this tree
884  valHolder->attachToVStore(*this) ;
885  _vars.add(*valHolder) ;
886  _varsww.add(*valHolder) ;
887 
888  // Fill values of of placeholder
889  RealVector* rv(0) ;
890  CatVector* cv(0) ;
891  if (dynamic_cast<RooAbsReal*>(valHolder)) {
892  rv = addReal((RooAbsReal*)valHolder);
893  rv->resize(numEntries()) ;
894  } else if (dynamic_cast<RooAbsCategory*>((RooAbsCategory*)valHolder)) {
895  cv = addCategory((RooAbsCategory*)valHolder) ;
896  cv->resize(numEntries()) ;
897  }
898 
899  for (int i=0 ; i<numEntries() ; i++) {
900  getNative(i) ;
901 
902  newVarClone->syncCache(&_vars) ;
903  valHolder->copyCache(newVarClone) ;
904 
905  if (rv) rv->write(i) ;
906  if (cv) cv->write(i) ;
907  }
908 
909  delete newVarClone ;
910  return valHolder ;
911 
912 }
913 
914 
915 
916 ////////////////////////////////////////////////////////////////////////////////
917 /// Utility function to add multiple columns in one call
918 /// See addColumn() for details
919 
921 {
922  TIterator* vIter = varList.createIterator() ;
923  RooAbsArg* var ;
924 
925  checkInit() ;
926 
927  TList cloneSetList ;
928  RooArgSet cloneSet ;
929  RooArgSet* holderSet = new RooArgSet ;
930 
931  while((var=(RooAbsArg*)vIter->Next())) {
932  // Create a fundamental object of the right type to hold newVar values
933  RooAbsArg* valHolder= var->createFundamental();
934  holderSet->add(*valHolder) ;
935 
936  // Sanity check that the holder really is fundamental
937  if(!valHolder->isFundamental()) {
938  coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
939  << valHolder->GetName() << "\"" << endl;
940  return 0;
941  }
942 
943  // Clone variable and attach to cloned tree
944  RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
945  if (!newVarCloneList) {
946  coutE(InputArguments) << "RooTreeDataStore::RooTreeData(" << GetName()
947  << ") Couldn't deep-clone variable " << var->GetName() << ", abort." << endl ;
948  return 0 ;
949  }
950  RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
951  newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
952  newVarClone->recursiveRedirectServers(*holderSet,kFALSE) ;
953 
954  cloneSetList.Add(newVarCloneList) ;
955  cloneSet.add(*newVarClone) ;
956 
957  // Attach value place holder to this tree
958  valHolder->attachToVStore(*this) ;
959  _vars.add(*valHolder) ;
960  }
961  delete vIter ;
962 
963 
964  TIterator* cIter = cloneSet.createIterator() ;
965  TIterator* hIter = holderSet->createIterator() ;
966  RooAbsArg *cloneArg, *holder ;
967 
968  // Dimension storage area for new vectors
969  while((holder = (RooAbsArg*)hIter->Next())) {
970  if (dynamic_cast<RooAbsReal*>(holder)) {
971  addReal((RooAbsReal*)holder)->resize(numEntries()) ;
972  } else {
974  }
975  }
976 
977  // Fill values of of placeholder
978  for (int i=0 ; i<numEntries() ; i++) {
979  getNative(i) ;
980 
981  cIter->Reset() ;
982  hIter->Reset() ;
983  while((cloneArg=(RooAbsArg*)cIter->Next())) {
984  holder = (RooAbsArg*)hIter->Next() ;
985 
986  cloneArg->syncCache(&_vars) ;
987 
988  holder->copyCache(cloneArg) ;
989 
990  if (dynamic_cast<RooAbsReal*>(holder)) {
991  addReal((RooAbsReal*)holder)->write(i) ;
992  } else {
993  addCategory((RooAbsCategory*)holder)->write(i) ;
994  }
995  }
996  }
997 
998  delete cIter ;
999  delete hIter ;
1000 
1001  cloneSetList.Delete() ;
1002  return holderSet ;
1003 }
1004 
1005 
1006 
1007 
1008 ////////////////////////////////////////////////////////////////////////////////
1009 /// Merge columns of supplied data set(s) with this data set. All
1010 /// data sets must have equal number of entries. In case of
1011 /// duplicate columns the column of the last dataset in the list
1012 /// prevails
1013 
1014 RooAbsDataStore* RooVectorDataStore::merge(const RooArgSet& allVars, list<RooAbsDataStore*> dstoreList)
1015 {
1016  RooVectorDataStore* mergedStore = new RooVectorDataStore("merged","merged",allVars) ;
1017 
1018  Int_t nevt = dstoreList.front()->numEntries() ;
1019  mergedStore->reserve(nevt);
1020  for (int i=0 ; i<nevt ; i++) {
1021 
1022  // Copy data from self
1023  mergedStore->_vars = *get(i) ;
1024 
1025  // Copy variables from merge sets
1026  for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; iter++) {
1027  const RooArgSet* partSet = (*iter)->get(i) ;
1028  mergedStore->_vars = *partSet ;
1029  }
1030 
1031  mergedStore->fill() ;
1032  }
1033  return mergedStore ;
1034 }
1035 
1036 
1037 
1039 {
1040  vector<RealVector*>::iterator iter = _realStoreList.begin() ;
1041  for ( ; iter!=_realStoreList.end() ; ++iter) {
1042  (*iter)->reserve(nEvts);
1043  }
1044  vector<RealFullVector*>::iterator iter3 = _realfStoreList.begin() ;
1045  for ( ; iter3!=_realfStoreList.end() ; ++iter3) {
1046  (*iter3)->reserve(nEvts);
1047  }
1048  vector<CatVector*>::iterator iter2 = _catStoreList.begin() ;
1049  for ( ; iter2!=_catStoreList.end() ; ++iter2) {
1050  (*iter2)->reserve(nEvts);
1051  }
1052 }
1053 
1054 ////////////////////////////////////////////////////////////////////////////////
1055 
1057 {
1058  Int_t nevt = other.numEntries() ;
1059  reserve(nevt + numEntries());
1060  for (int i=0 ; i<nevt ; i++) {
1061  _vars = *other.get(i) ;
1062  if (_wgtVar) {
1063  _wgtVar->setVal(other.weight()) ;
1064  }
1065 
1066  fill() ;
1067  }
1068 }
1069 
1070 
1071 
1072 ////////////////////////////////////////////////////////////////////////////////
1073 
1075 {
1076  return _nEntries ;
1077 }
1078 
1079 
1080 
1081 ////////////////////////////////////////////////////////////////////////////////
1082 
1084 {
1085  _nEntries=0 ;
1087  vector<RealVector*>::iterator iter = _realStoreList.begin() ;
1088  for ( ; iter!=_realStoreList.end() ; ++iter) {
1089  (*iter)->reset() ;
1090  }
1091  vector<RealFullVector*>::iterator iter3 = _realfStoreList.begin() ;
1092  for ( ; iter3!=_realfStoreList.end() ; ++iter3) {
1093  (*iter3)->reset() ;
1094  }
1095  vector<CatVector*>::iterator iter2 = _catStoreList.begin() ;
1096  for ( ; iter2!=_catStoreList.end() ; ++iter2) {
1097  (*iter2)->reset() ;
1098  }
1099 
1100 }
1101 
1102 
1103 struct less_dep : public binary_function<RooAbsArg*, RooAbsArg*, bool> {
1104  bool operator()(RooAbsArg* x, RooAbsArg* y) {
1105  return y->dependsOn(*x);
1106  }
1107 };
1108 
1109 ////////////////////////////////////////////////////////////////////////////////
1110 /// Cache given RooAbsArgs with this tree: The tree is
1111 /// given direct write access of the args internal cache
1112 /// the args values is pre-calculated for all data points
1113 /// in this data collection. Upon a get() call, the
1114 /// internal cache of 'newVar' will be loaded with the
1115 /// precalculated value and it's dirty flag will be cleared.
1116 
1117 void RooVectorDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, const RooArgSet* nset, Bool_t skipZeroWeights)
1118 {
1119  // Delete previous cache, if any
1120  delete _cache ;
1121  _cache = 0 ;
1122 
1123  // Reorder cached elements. First constant nodes, then tracked nodes in order of dependence
1124 
1125  // Step 1 - split in constant and tracked
1126  RooArgSet newVarSetCopy(newVarSet) ;
1127  RooFIter itern = newVarSetCopy.fwdIterator() ;
1128  RooAbsArg* arg ;
1129  RooArgSet orderedArgs ;
1130  vector<RooAbsArg*> trackArgs ;
1131  while((arg=itern.next())) {
1132  if (arg->getAttribute("ConstantExpression") && !arg->getAttribute("NOCacheAndTrack")) {
1133  orderedArgs.add(*arg) ;
1134  } else {
1135 
1136  // Explicitly check that arg depends on any of the observables, if this
1137  // is not the case, skip it, as inclusion would result in repeated
1138  // calculation of a function that has the same value for every event
1139  // in the likelihood
1140  if (arg->dependsOn(_vars) && !arg->getAttribute("NOCacheAndTrack")) {
1141  trackArgs.push_back(arg) ;
1142  } else {
1143  newVarSet.remove(*arg) ;
1144  }
1145  }
1146  }
1147 
1148  // Step 2 - reorder tracked nodes
1149  if (trackArgs.size()>1) {
1150  sort(trackArgs.begin(),trackArgs.end(),less_dep()) ;
1151  }
1152 
1153  // Step 3 - put back together
1154  for (vector<RooAbsArg*>::iterator viter = trackArgs.begin() ; viter!=trackArgs.end() ; ++viter) {
1155  orderedArgs.add(**viter) ;
1156  }
1157 
1158  // WVE need to prune tracking entries _below_ constant nodes as the're not needed
1159 // cout << "Number of Cache-and-Tracked args are " << trackArgs.size() << endl ;
1160 // cout << "Compound ordered cache parameters = " << endl ;
1161 // orderedArgs.Print("v") ;
1162 
1163  TIterator* vIter = orderedArgs.createIterator() ;
1164  RooAbsArg* var ;
1165 
1166  checkInit() ;
1167 
1168  list<RooArgSet*> vlist ;
1169  RooArgList cloneSet ;
1170 
1171  while((var=(RooAbsArg*)vIter->Next())) {
1172 
1173  // Clone variable and attach to cloned tree
1174  RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
1175  RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
1176  newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
1177 
1178  vlist.push_back(newVarCloneList) ;
1179  cloneSet.add(*newVarClone) ;
1180 
1181  }
1182  delete vIter ;
1183 
1184  _cacheOwner = (RooAbsArg*) owner ;
1185  RooVectorDataStore* newCache = new RooVectorDataStore("cache","cache",orderedArgs) ;
1186 
1187  TIterator* cIter = cloneSet.createIterator() ;
1188  RooAbsArg *cloneArg ;
1189 
1191 
1192  vector<RooArgSet*> nsetList ;
1193  list<RooArgSet*> argObsList ;
1194 
1195  // Now need to attach branch buffers of clones
1196  TIterator* it = cloneSet.createIterator() ;
1197  RooArgSet *anset(0), *acset(0) ;
1198  while ((arg=(RooAbsArg*)it->Next())) {
1199  arg->attachToVStore(*newCache) ;
1200 
1201  RooArgSet* argObs = nset ? arg->getObservables(*nset) : arg->getVariables() ;
1202  argObsList.push_back(argObs) ;
1203 
1204  RooArgSet* normSet(0) ;
1205  const char* catNset = arg->getStringAttribute("CATNormSet") ;
1206  if (catNset) {
1207 // cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a normalization set specification CATNormSet = " << catNset << endl ;
1208  RooNameSet rns ;
1209  rns.setNameList(catNset) ;
1210  anset = rns.select(nset?*nset:RooArgSet()) ;
1211  normSet = (RooArgSet*) anset->selectCommon(*argObs) ;
1212 
1213  }
1214  const char* catCset = arg->getStringAttribute("CATCondSet") ;
1215  if (catCset) {
1216 // cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a conditional observable set specification CATCondSet = " << catCset << endl ;
1217  RooNameSet rns ;
1218  rns.setNameList(catCset) ;
1219  acset = rns.select(nset?*nset:RooArgSet()) ;
1220 
1221  argObs->remove(*acset,kTRUE,kTRUE) ;
1222  normSet = argObs ;
1223  }
1224 
1225  // now construct normalization set for component from cset/nset spec
1226 // if (normSet) {
1227 // cout << "RooVectorDaraStore::cacheArgs() component " << arg->GetName() << " has custom normalization set " << *normSet << endl ;
1228 // }
1229  nsetList.push_back(normSet) ;
1230  }
1231  delete it ;
1232 
1233  // Fill values of of placeholder
1234  newCache->reserve(numEntries());
1235  for (int i=0 ; i<numEntries() ; i++) {
1236  getNative(i) ;
1237  if (weight()!=0 || !skipZeroWeights) {
1238  cIter->Reset() ;
1239  vector<RooArgSet*>::iterator niter = nsetList.begin() ;
1240  while((cloneArg=(RooAbsArg*)cIter->Next())) {
1241  // WVE need to intervene here for condobs from ProdPdf
1242  RooArgSet* argNset = *niter ;
1243  cloneArg->syncCache(argNset?argNset:nset) ;
1244  ++niter ;
1245  }
1246  }
1247  newCache->fill() ;
1248  }
1249  delete cIter ;
1250 
1252 
1253 
1254  // Now need to attach branch buffers of original function objects
1255  it = orderedArgs.createIterator() ;
1256  while ((arg=(RooAbsArg*)it->Next())) {
1257  arg->attachToVStore(*newCache) ;
1258 
1259  // Activate change tracking mode, if requested
1260  if (!arg->getAttribute("ConstantExpression") && dynamic_cast<RooAbsReal*>(arg)) {
1261  RealVector* rv = newCache->addReal((RooAbsReal*)arg) ;
1262  RooArgSet* deps = arg->getParameters(_vars) ;
1263  rv->setDependents(*deps) ;
1264 
1265  // WV lookup normalization set and associate with RealVector
1266  // find ordinal number of arg in original list
1267  Int_t idx = cloneSet.index(arg->GetName()) ;
1268 
1269  coutI(Optimization) << "RooVectorDataStore::cacheArg() element " << arg->GetName() << " has change tracking enabled on parameters " << *deps << endl ;
1270  rv->setNset(nsetList[idx]) ;
1271  delete deps ;
1272  }
1273 
1274  }
1275  delete it ;
1276 
1277  for (list<RooArgSet*>::iterator iter = vlist.begin() ; iter!=vlist.end() ; ++iter) {
1278  delete *iter ;
1279  }
1280  for (list<RooArgSet*>::iterator iter = argObsList.begin() ; iter!=argObsList.end() ; ++iter) {
1281  delete *iter ;
1282  }
1283 
1284  _cache = newCache ;
1286 }
1287 
1288 
1290 {
1291  if (_cache) _forcedUpdate = kTRUE ;
1292 }
1293 
1294 
1295 
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  pRealVector tv[1000] ;
1304  Int_t ntv(0) ;
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  tv[ntv] = (*(_cache->_firstReal+i)) ;
1312 // cout << "recalculate: need to update " << tv[ntv]->_nativeReal->GetName() << endl ;
1313  ntv++ ;
1314  }
1315  }
1316  _forcedUpdate = kFALSE ;
1317 
1318  // If no recalculations are neede stop here
1319  if (ntv==0) {
1320  return ;
1321  }
1322  // Refill caches of elements that require recalculation
1323 // cout << "recalc error count before update = " << RooAbsReal::numEvalErrors() << endl ;
1324  //RooAbsReal::ErrorLoggingMode origMode = RooAbsReal::evalErrorLoggingMode() ;
1325  RooArgSet* ownedNset = 0 ;
1326  RooArgSet* usedNset = 0 ;
1327  if (projectedArgs && projectedArgs->getSize()>0) {
1328  ownedNset = (RooArgSet*) _vars.snapshot(kFALSE) ;
1329  ownedNset->remove(*projectedArgs,kFALSE,kTRUE);
1330  usedNset = ownedNset ;
1331  } else {
1332  usedNset = &_vars ;
1333  }
1334 
1335  //cout << "RooVectorDataStore::recalculateCache: _vars = " << _vars << " projected = " << (projectedArgs?*projectedArgs:RooArgSet()) << " nset = " << *nset << endl;
1336  //Int_t ne = numEntries() ;
1337  for (int i=firstEvent ; i<lastEvent ; i+=stepSize) {
1338  get(i) ;
1339  Bool_t zeroWeight = (weight()==0) ;
1340  if (!zeroWeight || !skipZeroWeights) {
1341  for (int j=0 ; j<ntv ; j++) {
1342  tv[j]->_nativeReal->_valueDirty=kTRUE ;
1343  tv[j]->_nativeReal->getValV(tv[j]->_nset ? tv[j]->_nset : usedNset) ;
1344  tv[j]->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 (int j=0 ; j<ntv ; j++) {
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 {
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 {
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)
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
#define coutE(a)
Definition: RooMsgService.h:35
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
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:404
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
virtual const RooArgSet * get(Int_t index) const
Load the n-th data point (n='index') in memory and return a pointer to the internal RooArgSet holding...
Double_t * _extSumW2Array
External weight array - high error.
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return pointer to weight variable if it is defined.
Bool_t hasError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:55
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...
Bool_t IsReading() const
Definition: TBuffer.h:81
virtual Double_t weight() const =0
RooVectorDataStore::RealVector * pRealVector
virtual const RooArgSet * get(Int_t index) const
Load the n-th data point (n='index') in memory and return a pointer to the internal RooArgSet holding...
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
virtual Double_t weight() const
Return the weight of the n-th data point (n='index') in memory.
#define coutI(a)
Definition: RooMsgService.h:32
RooFIter fwdIterator() const
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.
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
virtual Bool_t isFundamental() const
Definition: RooAbsArg.h:157
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a new column to the data set which holds the pre-calculated values of 'newVar'.
virtual const RooArgSet * get() const
virtual void recalculateCache(const RooArgSet *, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, Bool_t skipZeroWeights)
virtual RooAbsArg * cloneTree(const char *newname=0) const
Clone tree expression of objects.
Definition: RooAbsArg.cxx:2295
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:145
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
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
STL namespace.
RooAbsArg * _cacheOwner
Optimization cache.
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:288
Double_t _curWgt
External sum of weights array.
Iterator abstract base class.
Definition: TIterator.h:32
std::vector< Double_t > _vec
Bool_t _doDirtyProp
Iterator over cached variables.
Bool_t _valueDirty
Definition: RooAbsArg.h:566
virtual void syncCache(const RooArgSet *nset=0)=0
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
Definition: RooAbsArg.cxx:312
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:23
Double_t x[n]
Definition: legend1.C:17
Bool_t _forcedUpdate
Cache owner.
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
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2081
std::vector< RealVector * > _realStoreList
virtual void attachToVStore(RooVectorDataStore &vstore)=0
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...
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
TIterator * createIterator(Bool_t dir=kIterForward) const
if on multiple lines(like in C++).**The" * configuration fragment. * * The "import myobject continue
Parses the configuration file.
Definition: HLFactory.cxx:368
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
virtual Double_t getValV(const RooArgSet *set=0) const
Return value of object.
Definition: RooAbsReal.cxx:249
virtual void setArgStatus(const RooArgSet &set, Bool_t active)
Disabling of branches is (intentionally) not implemented in vector data stores (as the doesn't result...
virtual RooAbsArg * createFundamental(const char *newname=0) const =0
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Definition: RooAbsArg.cxx:559
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const
A doubly linked list.
Definition: TList.h:47
CatVector ** _firstCat
do not persist
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList)
Merge columns of supplied data set(s) with this data set.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:202
RooAbsArg * find(const char *name) const
Find object with given name in list.
return
Definition: TBase64.cxx:62
Bool_t hasAsymError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:60
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE)=0
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
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:1515
OperMode _operMode
Definition: RooAbsArg.h:570
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual Bool_t inRange(const char *) const
Definition: RooAbsArg.h:289
virtual const RooArgSet * getNative(Int_t index) const
Load the n-th data point (n='index') in memory and return a pointer to the internal RooArgSet holding...
Double_t * _extWgtErrHiArray
External weight array - low error.
Double_t getAsymErrorHi() const
Definition: RooRealVar.h:59
static void setDirtyInhibit(Bool_t flag)
Control global dirty inhibit mode.
Definition: RooAbsArg.cxx:238
virtual Int_t numEntries() const
RooAbsArg * next()
RealVector ** _firstReal
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
std::vector< CatVector * > _catStoreList
TRObject operator()(const T1 &t1) const
RooVectorDataStore * _cache
#define ClassImp(name)
Definition: Rtypes.h:279
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
virtual void attachToVStore(RooVectorDataStore &vstore)
RealVector * addReal(RooAbsReal *real)
Double_t y[n]
Definition: legend1.C:17
#define TRACE_DESTROY
Definition: RooTrace.h:24
void setValueDirty() const
Definition: RooAbsArg.h:439
RooArgSet _varsww
Was object constructed with default ctor?
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual Bool_t isValid() const
WVE (08/21/01) Probably obsolete now.
Definition: RooAbsArg.cxx:1303
virtual Int_t numEntries() const
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.
Double_t getAsymErrorLo() const
Definition: RooRealVar.h:58
virtual void Add(TObject *obj)
Definition: TList.h:81
virtual TObject * Next()=0
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:743
void setOperMode(OperMode mode, Bool_t recurseADirty=kTRUE)
Change cache operation mode to given mode.
Definition: RooAbsArg.cxx:1753
virtual void checkInit() 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)
Int_t getSize() const
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:1087
const Bool_t kTRUE
Definition: Rtypes.h:91
RooArgSet * select(const RooArgSet &list) const
Construct a RooArgSet of objects in input 'list' whose names match to those in the internal name list...
Definition: RooNameSet.cxx:188
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
TIterator * _iterator
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448
Double_t getError() const
Definition: RooRealVar.h:54