Logo ROOT   6.18/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
22RooVectorDataStore is the abstract base class for data collection that
23use 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#include "RooHelpers.h"
43
44#include <iomanip>
45using namespace std ;
46
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
87RooVectorDataStore::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
152RooArgSet 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
170RooRealVar* 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
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
236RooVectorDataStore::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
285RooVectorDataStore::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
357RooVectorDataStore::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 for (auto var : _vars) {
512 var->setValueDirty(); // This triggers recalculation of all clients
513 }
514 }
515
516 // Update current weight cache
517 if (_extWgtArray) {
518
519 // If external array is specified use that
520 _curWgt = _extWgtArray[index] ;
523 _curWgtErr = sqrt(_extSumW2Array[index]) ;
524
525 } else if (_wgtVar) {
526
527 // Otherwise look for weight variable
528 _curWgt = _wgtVar->getVal() ;
532
533 } // else {
534
535// // Otherwise return 1
536// _curWgt=1.0 ;
537// _curWgtErrLo = 0 ;
538// _curWgtErrHi = 0 ;
539// _curWgtErr = 0 ;
540
541// }
542
543 if (_cache) {
544 _cache->get(index) ;
545 }
546
547 return &_vars;
548}
549
550
551
552////////////////////////////////////////////////////////////////////////////////
553/// Load the n-th data point (n='index') in memory
554/// and return a pointer to the internal RooArgSet
555/// holding its coordinates.
556
558{
559 if (index>=_nEntries) return 0 ;
560
561 for (Int_t i=0 ; i<_nReal ; i++) {
562 (*(_firstReal+i))->getNative(index) ;
563 }
564
565 if (_nRealF>0) {
566 for (Int_t i=0 ; i<_nRealF ; i++) {
567 (*(_firstRealF+i))->getNative(index) ;
568 }
569 }
570
571 if (_nCat>0) {
572 for (Int_t i=0 ; i<_nCat ; i++) {
573 (*(_firstCat+i))->getNative(index) ;
574 }
575 }
576
577 if (_doDirtyProp) {
578 // Raise all dirty flags
579 for (auto var : _vars) {
580 var->setValueDirty() ; // This triggers recalculation of all clients
581 }
582 }
583
584 // Update current weight cache
585 if (_extWgtArray) {
586
587 // If external array is specified use that
588 _curWgt = _extWgtArray[index] ;
591 _curWgtErr = sqrt(_extSumW2Array[index]) ;
592
593 } else if (_wgtVar) {
594
595 // Otherwise look for weight variable
596 _curWgt = _wgtVar->getVal() ;
600
601 } else {
602
603 // Otherwise return 1
604 _curWgt=1.0 ;
605 _curWgtErrLo = 0 ;
606 _curWgtErrHi = 0 ;
607 _curWgtErr = 0 ;
608
609 }
610
611 if (_cache) {
612 _cache->getNative(index) ;
613 }
614
615 return &_vars;
616}
617
618
619
620////////////////////////////////////////////////////////////////////////////////
621/// Return the weight of the n-th data point (n='index') in memory
622
624{
625 get(index) ;
626 return weight() ;
627}
628
629
630
631////////////////////////////////////////////////////////////////////////////////
632/// Return the weight of the n-th data point (n='index') in memory
633
635{
636 return _curWgt ;
637}
638
639
640////////////////////////////////////////////////////////////////////////////////
641
643{
644 if (_extWgtArray) {
645
646 // We have a weight array, use that info
647
648 // Return symmetric error on current bin calculated either from Poisson statistics or from SumOfWeights
649 Double_t lo,hi ;
650 weightError(lo,hi,etype) ;
651 return (lo+hi)/2 ;
652
653 } else if (_wgtVar) {
654
655 // We have a a weight variable, use that info
656 if (_wgtVar->hasAsymError()) {
657 return ( _wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo() ) / 2 ;
658 } else if (_wgtVar->hasError(kFALSE)) {
659 return _wgtVar->getError() ;
660 } else {
661 return 0 ;
662 }
663
664 } else {
665
666 // We have no weights
667 return 0 ;
668
669 }
670}
671
672
673
674////////////////////////////////////////////////////////////////////////////////
675
677{
678 if (_extWgtArray) {
679
680 // We have a weight array, use that info
681 switch (etype) {
682
683 case RooAbsData::Auto:
684 throw string(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
685 break ;
686
688 throw string(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
689 break ;
690
692 // Weight may be preset or precalculated
693 if (_curWgtErrLo>=0) {
694 lo = _curWgtErrLo ;
695 hi = _curWgtErrHi ;
696 return ;
697 }
698
699 // Otherwise Calculate poisson errors
700 Double_t ym,yp ;
702 lo = weight()-ym ;
703 hi = yp-weight() ;
704 return ;
705
707 lo = _curWgtErr ;
708 hi = _curWgtErr ;
709 return ;
710
711 case RooAbsData::None:
712 lo = 0 ;
713 hi = 0 ;
714 return ;
715 }
716
717 } else if (_wgtVar) {
718
719 // We have a a weight variable, use that info
720 if (_wgtVar->hasAsymError()) {
722 lo = _wgtVar->getAsymErrorLo() ;
723 } else {
724 hi = _wgtVar->getError() ;
725 lo = _wgtVar->getError() ;
726 }
727
728 } else {
729
730 // We are unweighted
731 lo=0 ;
732 hi=0 ;
733
734 }
735}
736
737
738
739////////////////////////////////////////////////////////////////////////////////
740/// throw(std::string("RooVectorDataSore::loadValues() NOT IMPLEMENTED")) ;
741
742void RooVectorDataStore::loadValues(const RooAbsDataStore *ads, const RooFormulaVar* select, const char* rangeName, Int_t nStart, Int_t nStop)
743{
744 // Load values from dataset 't' into this data collection, optionally
745 // selecting events using 'select' RooFormulaVar
746 //
747
748 // Redirect formula servers to source data row
749 RooFormulaVar* selectClone(0) ;
750 if (select) {
751 selectClone = (RooFormulaVar*) select->cloneTree() ;
752 selectClone->recursiveRedirectServers(*ads->get()) ;
753 selectClone->setOperMode(RooAbsArg::ADirty,kTRUE) ;
754 }
755
756 // Force DS internal initialization
757 ads->get(0) ;
758
759 // Loop over events in source tree
760 Int_t nevent = nStop < ads->numEntries() ? nStop : ads->numEntries() ;
761
762 Bool_t isTDS = dynamic_cast<const RooTreeDataStore*>(ads) ;
763 Bool_t isVDS = dynamic_cast<const RooVectorDataStore*>(ads) ;
764
765 // Check if weight is being renamed - if so set flag to enable special handling in copy loop
766 Bool_t weightRename(kFALSE) ;
767 Bool_t newWeightVar = _wgtVar ? _wgtVar->getAttribute("NewWeight") : kFALSE ;
768
769 if (_wgtVar && isVDS && ((RooVectorDataStore*)(ads))->_wgtVar) {
770 if (string(_wgtVar->GetName())!=((RooVectorDataStore*)(ads))->_wgtVar->GetName() && !newWeightVar) {
771 weightRename=kTRUE ;
772 }
773 }
774 if (_wgtVar && isTDS && ((RooTreeDataStore*)(ads))->_wgtVar) {
775 if (string(_wgtVar->GetName())!=((RooTreeDataStore*)(ads))->_wgtVar->GetName() && !newWeightVar) {
776 weightRename=kTRUE ;
777 }
778 }
779
780 std::vector<std::string> ranges;
781 if (rangeName) {
782 ranges = RooHelpers::tokenise(rangeName, ",");
783 }
784
785 reserve(numEntries() + (nevent - nStart));
786 for(Int_t i=nStart; i < nevent ; ++i) {
787 ads->get(i) ;
788
789 // Does this event pass the cuts?
790 if (selectClone && selectClone->getVal()==0) {
791 continue ;
792 }
793
794
795 if (isTDS) {
797 if (weightRename) {
799 }
800 } else if (isVDS) {
802 if (weightRename) {
804 }
805 } else {
806 _varsww.assignValueOnly(*ads->get()) ;
807 }
808
809 // Check that all copied values are valid
810 bool allValid = true;
811 for (const auto arg : _varsww) {
812 allValid = arg->isValid() && (ranges.empty() || std::any_of(ranges.begin(), ranges.end(),
813 [arg](const std::string& range){return arg->inRange(range.c_str());}) );
814 if (!allValid)
815 break ;
816 }
817 if (!allValid) {
818 continue ;
819 }
820
821 //_cachedVars = ((RooTreeDataStore*)ads)->_cachedVars ;
822 fill() ;
823 }
824
825 delete selectClone ;
826
827 SetTitle(ads->GetTitle());
828}
829
830
831
832
833
834////////////////////////////////////////////////////////////////////////////////
835
836Bool_t RooVectorDataStore::changeObservableName(const char* /*from*/, const char* /*to*/)
837{
838 return kFALSE ;
839}
840
841
842
843////////////////////////////////////////////////////////////////////////////////
844/// Add a new column to the data set which holds the pre-calculated values
845/// of 'newVar'. This operation is only meaningful if 'newVar' is a derived
846/// value.
847///
848/// The return value points to the added element holding 'newVar's value
849/// in the data collection. The element is always the corresponding fundamental
850/// type of 'newVar' (e.g. a RooRealVar if 'newVar' is a RooFormulaVar)
851///
852/// Note: This function is explicitly NOT intended as a speed optimization
853/// opportunity for the user. Components of complex PDFs that can be
854/// precalculated with the dataset are automatically identified as such
855/// and will be precalculated when fitting to a dataset
856///
857/// By forcibly precalculating functions with non-trivial Jacobians,
858/// or functions of multiple variables occurring in the data set,
859/// using addColumn(), you may alter the outcome of the fit.
860///
861/// Only in cases where such a modification of fit behaviour is intentional,
862/// this function should be used.
863
865{
866 // Create a fundamental object of the right type to hold newVar values
867 RooAbsArg* valHolder= newVar.createFundamental();
868 // Sanity check that the holder really is fundamental
869 if(!valHolder->isFundamental()) {
870 coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
871 << valHolder->GetName() << "\"" << endl;
872 return 0;
873 }
874
875 // Clone variable and attach to cloned tree
876 RooAbsArg* newVarClone = newVar.cloneTree() ;
878
879 // Attach value place holder to this tree
880 valHolder->attachToVStore(*this) ;
881 _vars.add(*valHolder) ;
882 _varsww.add(*valHolder) ;
883
884 // Fill values of of placeholder
885 RealVector* rv(0) ;
886 CatVector* cv(0) ;
887 if (dynamic_cast<RooAbsReal*>(valHolder)) {
888 rv = addReal((RooAbsReal*)valHolder);
889 rv->resize(numEntries()) ;
890 } else if (dynamic_cast<RooAbsCategory*>((RooAbsCategory*)valHolder)) {
891 cv = addCategory((RooAbsCategory*)valHolder) ;
892 cv->resize(numEntries()) ;
893 }
894
895 for (int i=0 ; i<numEntries() ; i++) {
896 getNative(i) ;
897
898 newVarClone->syncCache(&_vars) ;
899 valHolder->copyCache(newVarClone) ;
900
901 if (rv) rv->write(i) ;
902 if (cv) cv->write(i) ;
903 }
904
905 delete newVarClone ;
906 return valHolder ;
907
908}
909
910
911
912////////////////////////////////////////////////////////////////////////////////
913/// Utility function to add multiple columns in one call
914/// See addColumn() for details
915
917{
918 TIterator* vIter = varList.createIterator() ;
919 RooAbsArg* var ;
920
921 checkInit() ;
922
923 TList cloneSetList ;
924 RooArgSet cloneSet ;
925 RooArgSet* holderSet = new RooArgSet ;
926
927 while((var=(RooAbsArg*)vIter->Next())) {
928 // Create a fundamental object of the right type to hold newVar values
929 RooAbsArg* valHolder= var->createFundamental();
930 holderSet->add(*valHolder) ;
931
932 // Sanity check that the holder really is fundamental
933 if(!valHolder->isFundamental()) {
934 coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
935 << valHolder->GetName() << "\"" << endl;
936 return 0;
937 }
938
939 // Clone variable and attach to cloned tree
940 RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
941 if (!newVarCloneList) {
942 coutE(InputArguments) << "RooTreeDataStore::RooTreeData(" << GetName()
943 << ") Couldn't deep-clone variable " << var->GetName() << ", abort." << endl ;
944 return 0 ;
945 }
946 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
948 newVarClone->recursiveRedirectServers(*holderSet,kFALSE) ;
949
950 cloneSetList.Add(newVarCloneList) ;
951 cloneSet.add(*newVarClone) ;
952
953 // Attach value place holder to this tree
954 valHolder->attachToVStore(*this) ;
955 _vars.add(*valHolder) ;
956 }
957 delete vIter ;
958
959
960 TIterator* cIter = cloneSet.createIterator() ;
961 TIterator* hIter = holderSet->createIterator() ;
962 RooAbsArg *cloneArg, *holder ;
963
964 // Dimension storage area for new vectors
965 while((holder = (RooAbsArg*)hIter->Next())) {
966 if (dynamic_cast<RooAbsReal*>(holder)) {
967 addReal((RooAbsReal*)holder)->resize(numEntries()) ;
968 } else {
970 }
971 }
972
973 // Fill values of of placeholder
974 for (int i=0 ; i<numEntries() ; i++) {
975 getNative(i) ;
976
977 cIter->Reset() ;
978 hIter->Reset() ;
979 while((cloneArg=(RooAbsArg*)cIter->Next())) {
980 holder = (RooAbsArg*)hIter->Next() ;
981
982 cloneArg->syncCache(&_vars) ;
983
984 holder->copyCache(cloneArg) ;
985
986 if (dynamic_cast<RooAbsReal*>(holder)) {
987 addReal((RooAbsReal*)holder)->write(i) ;
988 } else {
989 addCategory((RooAbsCategory*)holder)->write(i) ;
990 }
991 }
992 }
993
994 delete cIter ;
995 delete hIter ;
996
997 cloneSetList.Delete() ;
998 return holderSet ;
999}
1000
1001
1002
1003
1004////////////////////////////////////////////////////////////////////////////////
1005/// Merge columns of supplied data set(s) with this data set. All
1006/// data sets must have equal number of entries. In case of
1007/// duplicate columns the column of the last dataset in the list
1008/// prevails
1009
1010RooAbsDataStore* RooVectorDataStore::merge(const RooArgSet& allVars, list<RooAbsDataStore*> dstoreList)
1011{
1012 RooVectorDataStore* mergedStore = new RooVectorDataStore("merged","merged",allVars) ;
1013
1014 Int_t nevt = dstoreList.front()->numEntries() ;
1015 mergedStore->reserve(nevt);
1016 for (int i=0 ; i<nevt ; i++) {
1017
1018 // Copy data from self
1019 mergedStore->_vars = *get(i) ;
1020
1021 // Copy variables from merge sets
1022 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
1023 const RooArgSet* partSet = (*iter)->get(i) ;
1024 mergedStore->_vars = *partSet ;
1025 }
1026
1027 mergedStore->fill() ;
1028 }
1029 return mergedStore ;
1030}
1031
1032
1033
1035{
1036 vector<RealVector*>::iterator iter = _realStoreList.begin() ;
1037 for ( ; iter!=_realStoreList.end() ; ++iter) {
1038 (*iter)->reserve(nEvts);
1039 }
1040 vector<RealFullVector*>::iterator iter3 = _realfStoreList.begin() ;
1041 for ( ; iter3!=_realfStoreList.end() ; ++iter3) {
1042 (*iter3)->reserve(nEvts);
1043 }
1044 vector<CatVector*>::iterator iter2 = _catStoreList.begin() ;
1045 for ( ; iter2!=_catStoreList.end() ; ++iter2) {
1046 (*iter2)->reserve(nEvts);
1047 }
1048}
1049
1050////////////////////////////////////////////////////////////////////////////////
1051
1053{
1054 Int_t nevt = other.numEntries() ;
1055 reserve(nevt + numEntries());
1056 for (int i=0 ; i<nevt ; i++) {
1057 _vars = *other.get(i) ;
1058 if (_wgtVar) {
1059 _wgtVar->setVal(other.weight()) ;
1060 }
1061
1062 fill() ;
1063 }
1064}
1065
1066
1067
1068////////////////////////////////////////////////////////////////////////////////
1069
1071{
1072 return _nEntries ;
1073}
1074
1075
1076
1077////////////////////////////////////////////////////////////////////////////////
1078
1080{
1081 _nEntries=0 ;
1083 vector<RealVector*>::iterator iter = _realStoreList.begin() ;
1084 for ( ; iter!=_realStoreList.end() ; ++iter) {
1085 (*iter)->reset() ;
1086 }
1087 vector<RealFullVector*>::iterator iter3 = _realfStoreList.begin() ;
1088 for ( ; iter3!=_realfStoreList.end() ; ++iter3) {
1089 (*iter3)->reset() ;
1090 }
1091 vector<CatVector*>::iterator iter2 = _catStoreList.begin() ;
1092 for ( ; iter2!=_catStoreList.end() ; ++iter2) {
1093 (*iter2)->reset() ;
1094 }
1095
1096}
1097
1098
1099struct less_dep : public binary_function<RooAbsArg*, RooAbsArg*, bool> {
1100 bool operator()(RooAbsArg* x, RooAbsArg* y) {
1101 return y->dependsOn(*x);
1102 }
1103};
1104
1105////////////////////////////////////////////////////////////////////////////////
1106/// Cache given RooAbsArgs with this tree: The tree is
1107/// given direct write access of the args internal cache
1108/// the args values is pre-calculated for all data points
1109/// in this data collection. Upon a get() call, the
1110/// internal cache of 'newVar' will be loaded with the
1111/// precalculated value and it's dirty flag will be cleared.
1112
1113void RooVectorDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, const RooArgSet* nset, Bool_t skipZeroWeights)
1114{
1115 // Delete previous cache, if any
1116 delete _cache ;
1117 _cache = 0 ;
1118
1119 // Reorder cached elements. First constant nodes, then tracked nodes in order of dependence
1120
1121 // Step 1 - split in constant and tracked
1122 RooArgSet newVarSetCopy(newVarSet) ;
1123 RooFIter itern = newVarSetCopy.fwdIterator() ;
1124 RooAbsArg* arg ;
1125 RooArgSet orderedArgs ;
1126 vector<RooAbsArg*> trackArgs ;
1127 while((arg=itern.next())) {
1128 if (arg->getAttribute("ConstantExpression") && !arg->getAttribute("NOCacheAndTrack")) {
1129 orderedArgs.add(*arg) ;
1130 } else {
1131
1132 // Explicitly check that arg depends on any of the observables, if this
1133 // is not the case, skip it, as inclusion would result in repeated
1134 // calculation of a function that has the same value for every event
1135 // in the likelihood
1136 if (arg->dependsOn(_vars) && !arg->getAttribute("NOCacheAndTrack")) {
1137 trackArgs.push_back(arg) ;
1138 } else {
1139 newVarSet.remove(*arg) ;
1140 }
1141 }
1142 }
1143
1144 // Step 2 - reorder tracked nodes
1145 if (trackArgs.size()>1) {
1146 sort(trackArgs.begin(),trackArgs.end(),less_dep()) ;
1147 }
1148
1149 // Step 3 - put back together
1150 for (vector<RooAbsArg*>::iterator viter = trackArgs.begin() ; viter!=trackArgs.end() ; ++viter) {
1151 orderedArgs.add(**viter) ;
1152 }
1153
1154 // WVE need to prune tracking entries _below_ constant nodes as the're not needed
1155// cout << "Number of Cache-and-Tracked args are " << trackArgs.size() << endl ;
1156// cout << "Compound ordered cache parameters = " << endl ;
1157// orderedArgs.Print("v") ;
1158
1159 TIterator* vIter = orderedArgs.createIterator() ;
1160 RooAbsArg* var ;
1161
1162 checkInit() ;
1163
1164 list<RooArgSet*> vlist ;
1165 RooArgList cloneSet ;
1166
1167 while((var=(RooAbsArg*)vIter->Next())) {
1168
1169 // Clone variable and attach to cloned tree
1170 RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
1171 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
1172 newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
1173
1174 vlist.push_back(newVarCloneList) ;
1175 cloneSet.add(*newVarClone) ;
1176
1177 }
1178 delete vIter ;
1179
1180 _cacheOwner = (RooAbsArg*) owner ;
1181 RooVectorDataStore* newCache = new RooVectorDataStore("cache","cache",orderedArgs) ;
1182
1183 TIterator* cIter = cloneSet.createIterator() ;
1184 RooAbsArg *cloneArg ;
1185
1187
1188 vector<RooArgSet*> nsetList ;
1189 list<RooArgSet*> argObsList ;
1190
1191 // Now need to attach branch buffers of clones
1192 TIterator* it = cloneSet.createIterator() ;
1193 RooArgSet *anset(0), *acset(0) ;
1194 while ((arg=(RooAbsArg*)it->Next())) {
1195 arg->attachToVStore(*newCache) ;
1196
1197 RooArgSet* argObs = nset ? arg->getObservables(*nset) : arg->getVariables() ;
1198 argObsList.push_back(argObs) ;
1199
1200 RooArgSet* normSet(0) ;
1201 const char* catNset = arg->getStringAttribute("CATNormSet") ;
1202 if (catNset) {
1203// cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a normalization set specification CATNormSet = " << catNset << endl ;
1204 RooNameSet rns ;
1205 rns.setNameList(catNset) ;
1206 anset = rns.select(nset?*nset:RooArgSet()) ;
1207 normSet = (RooArgSet*) anset->selectCommon(*argObs) ;
1208
1209 }
1210 const char* catCset = arg->getStringAttribute("CATCondSet") ;
1211 if (catCset) {
1212// cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a conditional observable set specification CATCondSet = " << catCset << endl ;
1213 RooNameSet rns ;
1214 rns.setNameList(catCset) ;
1215 acset = rns.select(nset?*nset:RooArgSet()) ;
1216
1217 argObs->remove(*acset,kTRUE,kTRUE) ;
1218 normSet = argObs ;
1219 }
1220
1221 // now construct normalization set for component from cset/nset spec
1222// if (normSet) {
1223// cout << "RooVectorDaraStore::cacheArgs() component " << arg->GetName() << " has custom normalization set " << *normSet << endl ;
1224// }
1225 nsetList.push_back(normSet) ;
1226 }
1227 delete it ;
1228
1229 // Fill values of of placeholder
1230 newCache->reserve(numEntries());
1231 for (int i=0 ; i<numEntries() ; i++) {
1232 getNative(i) ;
1233 if (weight()!=0 || !skipZeroWeights) {
1234 cIter->Reset() ;
1235 vector<RooArgSet*>::iterator niter = nsetList.begin() ;
1236 while((cloneArg=(RooAbsArg*)cIter->Next())) {
1237 // WVE need to intervene here for condobs from ProdPdf
1238 RooArgSet* argNset = *niter ;
1239 cloneArg->syncCache(argNset?argNset:nset) ;
1240 ++niter ;
1241 }
1242 }
1243 newCache->fill() ;
1244 }
1245 delete cIter ;
1246
1248
1249
1250 // Now need to attach branch buffers of original function objects
1251 it = orderedArgs.createIterator() ;
1252 while ((arg=(RooAbsArg*)it->Next())) {
1253 arg->attachToVStore(*newCache) ;
1254
1255 // Activate change tracking mode, if requested
1256 if (!arg->getAttribute("ConstantExpression") && dynamic_cast<RooAbsReal*>(arg)) {
1257 RealVector* rv = newCache->addReal((RooAbsReal*)arg) ;
1258 RooArgSet* deps = arg->getParameters(_vars) ;
1259 rv->setDependents(*deps) ;
1260
1261 // WV lookup normalization set and associate with RealVector
1262 // find ordinal number of arg in original list
1263 Int_t idx = cloneSet.index(arg->GetName()) ;
1264
1265 coutI(Optimization) << "RooVectorDataStore::cacheArg() element " << arg->GetName() << " has change tracking enabled on parameters " << *deps << endl ;
1266 rv->setNset(nsetList[idx]) ;
1267 delete deps ;
1268 }
1269
1270 }
1271 delete it ;
1272
1273 for (list<RooArgSet*>::iterator iter = vlist.begin() ; iter!=vlist.end() ; ++iter) {
1274 delete *iter ;
1275 }
1276 for (list<RooArgSet*>::iterator iter = argObsList.begin() ; iter!=argObsList.end() ; ++iter) {
1277 delete *iter ;
1278 }
1279
1280 _cache = newCache ;
1282}
1283
1284
1286{
1287 if (_cache) _forcedUpdate = kTRUE ;
1288}
1289
1290
1291
1292////////////////////////////////////////////////////////////////////////////////
1293
1294void RooVectorDataStore::recalculateCache( const RooArgSet *projectedArgs, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, Bool_t skipZeroWeights)
1295{
1296 if (!_cache) return ;
1297
1298 std::vector<RooVectorDataStore::RealVector *> tv;
1299 tv.reserve(_cache->_nReal * 0.7); // Typically, 30..60% need to be recalculated
1300
1301 // Check which items need recalculation
1302 for (Int_t i=0 ; i<_cache->_nReal ; i++) {
1303 if ((*(_cache->_firstReal+i))->needRecalc() || _forcedUpdate) {
1305 tv.push_back(cacheElem);
1308 }
1309 }
1311
1312 // If no recalculations are needed stop here
1313 if (tv.empty()) {
1314 return;
1315 }
1316 // Refill caches of elements that require recalculation
1317// cout << "recalc error count before update = " << RooAbsReal::numEvalErrors() << endl ;
1318 //RooAbsReal::ErrorLoggingMode origMode = RooAbsReal::evalErrorLoggingMode() ;
1319 RooArgSet* ownedNset = 0 ;
1320 RooArgSet* usedNset = 0 ;
1321 if (projectedArgs && projectedArgs->getSize()>0) {
1322 ownedNset = (RooArgSet*) _vars.snapshot(kFALSE) ;
1323 ownedNset->remove(*projectedArgs,kFALSE,kTRUE);
1324 usedNset = ownedNset ;
1325 } else {
1326 usedNset = &_vars ;
1327 }
1328
1329 //cout << "RooVectorDataStore::recalculateCache: _vars = " << _vars << " projected = " << (projectedArgs?*projectedArgs:RooArgSet()) << " nset = " << *nset << endl;
1330 //Int_t ne = numEntries() ;
1331 for (int i=firstEvent ; i<lastEvent ; i+=stepSize) {
1332 get(i) ;
1333 Bool_t zeroWeight = (weight()==0) ;
1334 if (!zeroWeight || !skipZeroWeights) {
1335 for (std::vector<RooVectorDataStore::RealVector *>::iterator cacheIt = tv.begin(); cacheIt != tv.end();
1336 ++cacheIt) {
1337 (*cacheIt)->_nativeReal->_valueDirty = kTRUE;
1338 (*cacheIt)->_nativeReal->getValV((*cacheIt)->_nset ? (*cacheIt)->_nset : usedNset);
1339 (*cacheIt)->write(i);
1340 }
1341 }
1342// if (zeroWeight) {
1343// // cout << "update - slot " << i << " has zero weight, ignoring event errors" << endl ;
1344// RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::Ignore) ;
1345// }
1346// for (int j=0 ; j<ntv ; j++) {
1347// tv[j]->_nativeReal->_valueDirty=kTRUE ;
1348// tv[j]->_nativeReal->getValV(tv[j]->_nset ? tv[j]->_nset : usedNset) ;
1349// tv[j]->write(i) ;
1350// }
1351// if (zeroWeight) {
1352// RooAbsReal::setEvalErrorLoggingMode(origMode) ;
1353// }
1354 }
1355
1356// cout << "recalculate: end of updating" << endl ;
1357// cout << "recalc error count after update = " << RooAbsReal::numEvalErrors() << endl ;
1358
1359 for (std::vector<RooVectorDataStore::RealVector *>::iterator cacheIt = tv.begin(); cacheIt != tv.end(); ++cacheIt) {
1360 (*cacheIt)->_nativeReal->setOperMode(RooAbsArg::AClean);
1361 }
1362
1363 delete ownedNset ;
1364
1365}
1366
1367
1368
1369
1370////////////////////////////////////////////////////////////////////////////////
1371/// Initialize cache of dataset: attach variables of cache ArgSet
1372/// to the corresponding TTree branches
1373
1374void RooVectorDataStore::attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVarsIn)
1375{
1376 // Only applicabel if a cache exists
1377 if (!_cache) return ;
1378
1379 // Clone ctor, must connect internal storage to given new external set of vars
1380 vector<RealVector*>::const_iterator oiter = _cache->_realStoreList.begin() ;
1381 for (; oiter!=_cache->_realStoreList.end() ; ++oiter) {
1382 RooAbsReal* real = (RooAbsReal*) cachedVarsIn.find((*oiter)->bufArg()->GetName()) ;
1383 if (real) {
1384 // Adjust buffer pointer
1385 real->attachToVStore(*_cache) ;
1386 }
1387 }
1388
1389 vector<RealFullVector*>::const_iterator fiter = _cache->_realfStoreList.begin() ;
1390 for (; fiter!=_cache->_realfStoreList.end() ; ++fiter) {
1391 RooAbsReal* real = (RooAbsReal*) cachedVarsIn.find((*fiter)->bufArg()->GetName()) ;
1392 if (real) {
1393 // Adjust buffer pointer
1394 real->attachToVStore(*_cache) ;
1395 }
1396 }
1397
1398 vector<CatVector*>::const_iterator citer = _cache->_catStoreList.begin() ;
1399 for (; citer!=_cache->_catStoreList.end() ; ++citer) {
1400 RooAbsCategory* cat = (RooAbsCategory*) cachedVarsIn.find((*citer)->bufArg()->GetName()) ;
1401 if (cat) {
1402 // Adjust buffer pointer
1403 cat->attachToVStore(*_cache) ;
1404 }
1405 }
1406
1407 _cacheOwner = (RooAbsArg*) newOwner ;
1408}
1409
1410
1411
1412
1413////////////////////////////////////////////////////////////////////////////////
1414
1416{
1417 delete _cache ;
1418 _cache = 0 ;
1419 _cacheOwner = 0 ;
1420 return ;
1421}
1422
1423
1424
1425
1426
1427////////////////////////////////////////////////////////////////////////////////
1428/// Disabling of branches is (intentionally) not implemented in vector
1429/// data stores (as the doesn't result in a net saving of time)
1430
1431void RooVectorDataStore::setArgStatus(const RooArgSet& /*set*/, Bool_t /*active*/)
1432{
1433 return ;
1434}
1435
1436
1437
1438
1439////////////////////////////////////////////////////////////////////////////////
1440
1442{
1443 RooFIter iter = _varsww.fwdIterator() ;
1444 RooAbsArg* arg ;
1445 while((arg=iter.next())) {
1446 RooAbsArg* extArg = extObs.find(arg->GetName()) ;
1447 if (extArg) {
1448 extArg->attachToVStore(*this) ;
1449 }
1450 }
1451}
1452
1453
1454
1455////////////////////////////////////////////////////////////////////////////////
1456
1458{
1459 RooFIter iter = _varsww.fwdIterator() ;
1460 RooAbsArg* arg ;
1461 while((arg=iter.next())) {
1462 arg->attachToVStore(*this) ;
1463 }
1464}
1465
1466
1467
1468////////////////////////////////////////////////////////////////////////////////
1469
1471{
1472 cout << "RooVectorDataStor::dump()" << endl ;
1473
1474 cout << "_varsww = " << endl ; _varsww.Print("v") ;
1475 cout << "realVector list is" << endl ;
1476 std::vector<RealVector*>::iterator iter = _realStoreList.begin() ;
1477 for (; iter!=_realStoreList.end() ; ++iter) {
1478 cout << "RealVector " << *iter << " _nativeReal = " << (*iter)->_nativeReal << " = " << (*iter)->_nativeReal->GetName() << " bufptr = " << (*iter)->_buf << endl ;
1479 cout << " values : " ;
1480 Int_t imax = (*iter)->_vec.size()>10 ? 10 : (*iter)->_vec.size() ;
1481 for (Int_t i=0 ; i<imax ; i++) {
1482 cout << (*iter)->_vec[i] << " " ;
1483 }
1484 cout << endl ;
1485 }
1486 std::vector<RealFullVector*>::iterator iter2 = _realfStoreList.begin() ;
1487 for (; iter2!=_realfStoreList.end() ; ++iter2) {
1488 cout << "RealFullVector " << *iter2 << " _nativeReal = " << (*iter2)->_nativeReal << " = " << (*iter2)->_nativeReal->GetName()
1489 << " bufptr = " << (*iter2)->_buf << " errbufptr = " << (*iter2)->_bufE << endl ;
1490
1491 cout << " values : " ;
1492 Int_t imax = (*iter2)->_vec.size()>10 ? 10 : (*iter2)->_vec.size() ;
1493 for (Int_t i=0 ; i<imax ; i++) {
1494 cout << (*iter2)->_vec[i] << " " ;
1495 }
1496 cout << endl ;
1497 if ((*iter2)->_vecE) {
1498 cout << " errors : " ;
1499 for (Int_t i=0 ; i<imax ; i++) {
1500 cout << (*(*iter2)->_vecE)[i] << " " ;
1501 }
1502 cout << endl ;
1503
1504 }
1505 }
1506}
1507
1508
1509////////////////////////////////////////////////////////////////////////////////
1510/// Stream an object of class RooVectorDataStore.
1511
1512void RooVectorDataStore::Streamer(TBuffer &R__b)
1513{
1514 if (R__b.IsReading()) {
1516
1517 if (_realStoreList.size() > 0)
1518 _firstReal = &_realStoreList.front() ;
1519 if (_realfStoreList.size() > 0)
1520 _firstRealF = &_realfStoreList.front() ;
1521 if (_catStoreList.size() > 0)
1522 _firstCat = &_catStoreList.front() ;
1523
1524 for (vector<RealVector*>::iterator iter1 = _realStoreList.begin() ; iter1!=_realStoreList.end() ; ++iter1) {
1525 RooAbsArg* arg = _varsww.find((*iter1)->_nativeReal->GetName()) ;
1526 arg->attachToVStore(*this) ;
1527 }
1528 for (vector<RealFullVector*>::iterator iter2 = _realfStoreList.begin() ; iter2!=_realfStoreList.end() ; ++iter2) {
1529 RooAbsArg* arg = _varsww.find((*iter2)->_nativeReal->GetName()) ;
1530 arg->attachToVStore(*this) ;
1531 }
1532 for (vector<CatVector*>::iterator iter3 = _catStoreList.begin() ; iter3!=_catStoreList.end() ; ++iter3) {
1533 RooAbsArg* arg = _varsww.find((*iter3)->_cat->GetName()) ;
1534 arg->attachToVStore(*this) ;
1535 }
1536
1537 } else {
1539 }
1540}
1541
1542
1543
1544////////////////////////////////////////////////////////////////////////////////
1545/// Stream an object of class RooVectorDataStore::RealVector.
1546
1547void RooVectorDataStore::RealVector::Streamer(TBuffer &R__b)
1548{
1549 if (R__b.IsReading()) {
1551 _vec0 = _vec.size()>0 ? &_vec.front() : 0 ;
1552 } else {
1554 }
1555}
1556
1557////////////////////////////////////////////////////////////////////////////////
1558/// Stream an object of class RooVectorDataStore::RealFullVector.
1559
1560void RooVectorDataStore::RealFullVector::Streamer(TBuffer &R__b)
1561{
1562 if (R__b.IsReading()) {
1564
1565 // WVE - It seems that ROOT persistence turns null pointers to vectors into pointers to null-sized vectors
1566 // Intervene here to remove those null-sized vectors and replace with null pointers to not break
1567 // assumptions made elsewhere in this class
1568 if (_vecE && _vecE->empty()) { delete _vecE ; _vecE = 0 ; }
1569 if (_vecEL && _vecEL->empty()) { delete _vecEL ; _vecEL = 0 ; }
1570 if (_vecEH && _vecEH->empty()) { delete _vecEH ; _vecEH = 0 ; }
1571 } else {
1573 }
1574}
1575
1576////////////////////////////////////////////////////////////////////////////////
1577/// Stream an object of class RooVectorDataStore::CatVector.
1578
1579void RooVectorDataStore::CatVector::Streamer(TBuffer &R__b)
1580{
1581 if (R__b.IsReading()) {
1583 _vec0 = _vec.size()>0 ? &_vec.front() : 0 ;
1584 } else {
1586 }
1587}
1588
1589
1590
1591
1592
1593
1594
void Class()
Definition: Class.C:29
#define coutI(a)
Definition: RooMsgService.h:31
#define coutE(a)
Definition: RooMsgService.h:34
#define TRACE_DESTROY
Definition: RooTrace.h:23
#define TRACE_CREATE
Definition: RooTrace.h:22
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
float type_of_call hi(const int &, const int &)
double sqrt(double)
TRObject operator()(const T1 &t1) const
char * Form(const char *fmt,...)
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:70
virtual RooAbsArg * cloneTree(const char *newname=0) const
Clone tree expression of objects.
Definition: RooAbsArg.cxx:2246
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Return the observables of this pdf given a set of observables.
Definition: RooAbsArg.h:240
void attachDataStore(const RooAbsDataStore &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
Definition: RooAbsArg.cxx:1487
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:729
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE)=0
static void setDirtyInhibit(Bool_t flag)
Control global dirty inhibit mode.
Definition: RooAbsArg.cxx:229
virtual Bool_t isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition: RooAbsArg.h:206
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
Definition: RooAbsArg.cxx:301
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:543
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2034
void setOperMode(OperMode mode, Bool_t recurseADirty=kTRUE)
Change cache operation mode to given mode.
Definition: RooAbsArg.cxx:1719
OperMode _operMode
Definition: RooAbsArg.h:619
virtual void syncCache(const RooArgSet *nset=0)=0
virtual void attachToVStore(RooVectorDataStore &vstore)=0
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:279
virtual RooAbsArg * createFundamental(const char *newname=0) const =0
Create a fundamental-type object that stores our type of value.
Bool_t recursiveRedirectServers(const RooAbsCollection &newServerList, Bool_t mustReplaceAll=kFALSE, Bool_t nameChange=kFALSE, Bool_t recurseInNewSet=kTRUE)
Definition: RooAbsArg.cxx:1065
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
virtual void attachToVStore(RooVectorDataStore &vstore)
Attach the category index and label to as branches to the given vector store.
RooFIter fwdIterator() const R__SUGGEST_ALTERNATIVE("begin()
One-time forward iterator.
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
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.
Int_t getSize() const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
virtual const RooArgSet * get(Int_t index) const =0
virtual void checkInit() const
virtual Double_t weight() const =0
virtual Int_t numEntries() const =0
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)
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:81
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in list.
Definition: RooArgList.h:73
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:134
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
RooAbsArg * next()
Return next element or nullptr if at end.
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:27
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.
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
RooNameSet is a utility class that stores the names the objects in a RooArget.
Definition: RooNameSet.h:24
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:187
void setNameList(const char *givenList)
Definition: RooNameSet.cxx:144
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
Double_t getAsymErrorLo() const
Definition: RooRealVar.h:58
Bool_t hasAsymError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:60
Double_t getAsymErrorHi() const
Definition: RooRealVar.h:59
Bool_t hasError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:55
Double_t getError() const
Definition: RooRealVar.h:54
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:233
RooTreeDataStore is a TTree-backed data storage.
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...
RooArgSet _varsww
Was object constructed with default ctor?
virtual Int_t numEntries() const
void setNset(RooArgSet *newNset)
void setDependents(const RooArgSet &deps)
std::vector< Double_t > _vec
RooVectorDataStore is the abstract base class for data collection that use a TTree as internal storag...
virtual RooArgSet * addColumns(const RooArgList &varList)
Utility function to add multiple columns in one call See addColumn() for details.
virtual Double_t weight() const
Return the weight of the n-th data point (n='index') in memory.
virtual Int_t fill()
Interface function to TTree::Fill.
std::vector< RealFullVector * > _realfStoreList
Double_t * _extSumW2Array
External weight array - high error.
virtual void recalculateCache(const RooArgSet *, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, Bool_t skipZeroWeights)
Double_t * _extWgtErrHiArray
External weight array - low error.
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")) ;
RooVectorDataStore * _cache
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return pointer to weight variable if it is defined.
std::vector< RealVector * > _realStoreList
RealVector * addReal(RooAbsReal *real)
Double_t _sumWeight
do not persist
virtual void attachBuffers(const RooArgSet &extObs)
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...
Double_t * _extWgtErrLoArray
External weight array.
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...
virtual void setDirtyProp(Bool_t flag)
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'.
std::vector< CatVector * > _catStoreList
Bool_t _forcedUpdate
Cache owner.
RealVector ** _firstReal
CatVector ** _firstCat
do not persist
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...
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const
virtual void append(RooAbsDataStore &other)
virtual Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
virtual Bool_t changeObservableName(const char *from, const char *to)
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...
Double_t _curWgt
External sum of weights array.
virtual void reserve(Int_t nEvt)
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList)
Merge columns of supplied data set(s) with this data set.
virtual const RooArgSet * get() const
virtual ~RooVectorDataStore()
Destructor.
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
virtual Int_t numEntries() const
CatVector * addCategory(RooAbsCategory *cat)
RealFullVector ** _firstRealF
do not persist
virtual void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
RooAbsArg * _cacheOwner
Optimization cache.
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
Bool_t IsReading() const
Definition: TBuffer.h:85
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Iterator abstract base class.
Definition: TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:146
@ Optimization
Definition: RooGlobalFunc.h:58
@ InputArguments
Definition: RooGlobalFunc.h:58
std::vector< std::string > tokenise(const std::string &str, const std::string &delims)
Tokenise the string by splitting at the characters in delims.
Definition: RooHelpers.cxx:24