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