Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooTreeDataStore.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 RooTreeDataStore.cxx
19\class RooTreeDataStore
20\ingroup Roofitcore
21
22RooTreeDataStore is a TTree-backed data storage. When a file is opened before
23creating the data storage, the storage will be file-backed. This reduces memory
24pressure because it allows storing the data in the file and reading it on demand.
25For a completely memory-backed storage, which is faster than the file-backed storage,
26RooVectorDataStore can be used.
27
28With tree-backed storage, the tree can be found in the file with the name
29`RooTreeDataStore_name_title` for a dataset created as
30`RooDataSet("name", "title", ...)`.
31
32\note A file needs to be opened **before** creating the data storage to enable file-backed
33storage.
34```
35TFile outputFile("filename.root", "RECREATE");
36RooAbsData::setDefaultStorageType(RooAbsData::Tree);
37RooDataSet mydata(...);
38```
39
40One can also change between TTree- and std::vector-backed storage using
41RooAbsData::convertToTreeStore() and
42RooAbsData::convertToVectorStore().
43**/
44
45#include "RooTreeDataStore.h"
46
47#include "RooFit.h"
48#include "RooMsgService.h"
49#include "RooFormulaVar.h"
50#include "RooRealVar.h"
51#include "RooHistError.h"
52
53#include "ROOT/StringUtils.hxx"
54
55#include "TTree.h"
56#include "TFile.h"
57#include "TChain.h"
58#include "TDirectory.h"
59#include "TBuffer.h"
60#include "TBranch.h"
61#include "TROOT.h"
62
63#include <iomanip>
64using namespace std ;
65
67
68
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74
76 _tree(0),
77 _cacheTree(0),
78 _cacheOwner(0),
79 _defCtor(kTRUE),
80 _wgtVar(0),
81 _curWgt(1),
82 _curWgtErrLo(0),
83 _curWgtErrHi(0),
84 _curWgtErr(0)
85{
86}
87
88
89
90////////////////////////////////////////////////////////////////////////////////
91/// Constructor to facilitate reading of legacy RooDataSets
92
93RooTreeDataStore::RooTreeDataStore(TTree* t, const RooArgSet& vars, const char* wgtVarName) :
94 RooAbsDataStore("blah","blah",varsNoWeight(vars,wgtVarName)),
95 _tree(t),
96 _cacheTree(0),
97 _cacheOwner(0),
98 _defCtor(kTRUE),
99 _varsww(vars),
100 _wgtVar(weightVar(vars,wgtVarName)),
101 _curWgt(1)
102{
103}
104
105
106
107
108////////////////////////////////////////////////////////////////////////////////
109
110RooTreeDataStore::RooTreeDataStore(std::string_view name, std::string_view title, const RooArgSet& vars, const char* wgtVarName) :
111 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
112 _tree(0),
113 _cacheTree(0),
114 _cacheOwner(0),
115 _defCtor(kFALSE),
116 _varsww(vars),
117 _wgtVar(weightVar(vars,wgtVarName)),
118 _curWgt(1),
119 _curWgtErrLo(0),
120 _curWgtErrHi(0),
121 _curWgtErr(0)
122{
123 initialize() ;
124}
125
126
127
128
129////////////////////////////////////////////////////////////////////////////////
130
131RooTreeDataStore::RooTreeDataStore(std::string_view name, std::string_view title, const RooArgSet& vars, TTree& t, const RooFormulaVar& select, const char* wgtVarName) :
132 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
133 _tree(0),
134 _cacheTree(0),
135 _cacheOwner(0),
136 _defCtor(kFALSE),
137 _varsww(vars),
138 _wgtVar(weightVar(vars,wgtVarName)),
139 _curWgt(1),
140 _curWgtErrLo(0),
141 _curWgtErrHi(0),
142 _curWgtErr(0)
143{
144 initialize() ;
145 loadValues(&t,&select) ;
146}
147
148
149
150////////////////////////////////////////////////////////////////////////////////
151
152RooTreeDataStore::RooTreeDataStore(std::string_view name, std::string_view title, const RooArgSet& vars, TTree& t, const char* selExpr, const char* wgtVarName) :
153 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
154 _tree(0),
155 _cacheTree(0),
156 _cacheOwner(0),
157 _defCtor(kFALSE),
158 _varsww(vars),
159 _wgtVar(weightVar(vars,wgtVarName)),
160 _curWgt(1),
161 _curWgtErrLo(0),
162 _curWgtErrHi(0),
163 _curWgtErr(0)
164{
165 initialize() ;
166
167 if (selExpr && *selExpr) {
168 // Create a RooFormulaVar cut from given cut expression
169 RooFormulaVar select(selExpr, selExpr, _vars, /*checkVariables=*/false);
170 loadValues(&t,&select);
171 } else {
172 loadValues(&t);
173 }
174}
175
176
177
178////////////////////////////////////////////////////////////////////////////////
179
180RooTreeDataStore::RooTreeDataStore(std::string_view name, std::string_view title, const RooArgSet& vars, const RooAbsDataStore& tds, const RooFormulaVar& select, const char* wgtVarName) :
181 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
182 _tree(0),
183 _cacheTree(0),
184 _cacheOwner(0),
185 _defCtor(kFALSE),
186 _varsww(vars),
187 _wgtVar(weightVar(vars,wgtVarName)),
188 _curWgt(1),
189 _curWgtErrLo(0),
190 _curWgtErrHi(0),
191 _curWgtErr(0)
192{
193 initialize() ;
194 loadValues(&tds,&select) ;
195}
196
197
198
199////////////////////////////////////////////////////////////////////////////////
200
201RooTreeDataStore::RooTreeDataStore(std::string_view name, std::string_view title, const RooArgSet& vars, const RooAbsDataStore& ads, const char* selExpr, const char* wgtVarName) :
202 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
203 _tree(0),
204 _cacheTree(0),
205 _cacheOwner(0),
206 _defCtor(kFALSE),
207 _varsww(vars),
208 _wgtVar(weightVar(vars,wgtVarName)),
209 _curWgt(1),
210 _curWgtErrLo(0),
211 _curWgtErrHi(0),
212 _curWgtErr(0)
213{
214 initialize() ;
215
216 if (selExpr && *selExpr) {
217 // Create a RooFormulaVar cut from given cut expression
218 RooFormulaVar select(selExpr, selExpr, _vars, /*checkVariables=*/false);
219 loadValues(&ads,&select);
220 } else {
221 loadValues(&ads);
222 }
223}
224
225
226
227
228////////////////////////////////////////////////////////////////////////////////
229
230RooTreeDataStore::RooTreeDataStore(std::string_view name, std::string_view title, RooAbsDataStore& tds,
231 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
232 Int_t nStart, Int_t nStop, Bool_t /*copyCache*/, const char* wgtVarName) :
233 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)), _defCtor(kFALSE),
234 _varsww(vars),
235 _wgtVar(weightVar(vars,wgtVarName)),
236 _curWgt(1),
237 _curWgtErrLo(0),
238 _curWgtErrHi(0),
239 _curWgtErr(0)
240{
241 // WVE NEED TO ADJUST THIS FOR WEIGHTS
242
243 // Protected constructor for internal use only
244 _tree = 0 ;
245 _cacheTree = 0 ;
246 createTree(makeTreeName(), title);
247
248 // Deep clone cutVar and attach clone to this dataset
249 RooFormulaVar* cloneVar = 0;
250 if (cutVar) {
251 cloneVar = (RooFormulaVar*) cutVar->cloneTree() ;
252 cloneVar->attachDataStore(tds) ;
253 }
254
255 // Constructor from existing data set with list of variables that preserves the cache
256 initialize();
257
259
260 // WVE copy values of cached variables here!!!
262 _cacheOwner = 0 ;
263
264 loadValues(&tds,cloneVar,cutRange,nStart,nStop);
265
266 if (cloneVar) delete cloneVar ;
267}
268
269
270
271////////////////////////////////////////////////////////////////////////////////
272/// Utility function for constructors
273/// Return RooArgSet that is copy of allVars minus variable matching wgtName if specified
274
275RooArgSet RooTreeDataStore::varsNoWeight(const RooArgSet& allVars, const char* wgtName)
276{
277 RooArgSet ret(allVars) ;
278 if(wgtName) {
279 RooAbsArg* wgt = allVars.find(wgtName) ;
280 if (wgt) {
281 ret.remove(*wgt,kTRUE,kTRUE) ;
282 }
283 }
284 return ret ;
285}
286
287
288
289////////////////////////////////////////////////////////////////////////////////
290/// Utility function for constructors
291/// Return pointer to weight variable if it is defined
292
293RooRealVar* RooTreeDataStore::weightVar(const RooArgSet& allVars, const char* wgtName)
294{
295 if(wgtName) {
296 RooRealVar* wgt = dynamic_cast<RooRealVar*>(allVars.find(wgtName)) ;
297 return wgt ;
298 }
299 return 0 ;
300}
301
302
303
304
305////////////////////////////////////////////////////////////////////////////////
306/// Initialize cache of dataset: attach variables of cache ArgSet
307/// to the corresponding TTree branches
308
309void RooTreeDataStore::attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVarsIn)
310{
311 // iterate over the cache variables for this dataset
313 TIterator* iter = cachedVarsIn.createIterator() ;
314 RooAbsArg *var;
315 while((0 != (var= (RooAbsArg*)iter->Next()))) {
317 _cachedVars.add(*var) ;
318 }
319 delete iter ;
320 _cacheOwner = newOwner ;
321
322}
323
324
325
326
327
328
329////////////////////////////////////////////////////////////////////////////////
330
331RooTreeDataStore::RooTreeDataStore(const RooTreeDataStore& other, const char* newname) :
332 RooAbsDataStore(other,newname),
333 _tree(0),
334 _cacheTree(0),
335 _defCtor(kFALSE),
336 _varsww(other._varsww),
337 _wgtVar(other._wgtVar),
338 _extWgtArray(other._extWgtArray),
339 _extWgtErrLoArray(other._extWgtErrLoArray),
340 _extWgtErrHiArray(other._extWgtErrHiArray),
341 _extSumW2Array(other._extSumW2Array),
342 _curWgt(other._curWgt),
343 _curWgtErrLo(other._curWgtErrLo),
344 _curWgtErrHi(other._curWgtErrHi),
345 _curWgtErr(other._curWgtErr)
346{
347 initialize() ;
348 loadValues(&other) ;
349}
350
351
352////////////////////////////////////////////////////////////////////////////////
353
354RooTreeDataStore::RooTreeDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname) :
355 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
356 _tree(0),
357 _cacheTree(0),
358 _defCtor(kFALSE),
359 _varsww(vars),
360 _wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):0),
361 _extWgtArray(other._extWgtArray),
362 _extWgtErrLoArray(other._extWgtErrLoArray),
363 _extWgtErrHiArray(other._extWgtErrHiArray),
364 _extSumW2Array(other._extSumW2Array),
365 _curWgt(other._curWgt),
366 _curWgtErrLo(other._curWgtErrLo),
367 _curWgtErrHi(other._curWgtErrHi),
368 _curWgtErr(other._curWgtErr)
369{
370 initialize() ;
371 loadValues(&other) ;
372}
373
374
375
376
377////////////////////////////////////////////////////////////////////////////////
378/// Destructor
379
381{
382 if (_tree) {
383 delete _tree ;
384 }
385 if (_cacheTree) {
386 delete _cacheTree ;
387 }
388}
389
390
391
392////////////////////////////////////////////////////////////////////////////////
393/// One-time initialization common to all constructor forms. Attach
394/// variables of internal ArgSet to the corresponding TTree branches
395
397{
398 // Recreate (empty) cache tree
400
401 // Attach each variable to the dataset
402 for (auto var : _varsww) {
403 var->attachToTree(*_tree,_defTreeBufSize) ;
404 }
405}
406
407
408
409
410
411////////////////////////////////////////////////////////////////////////////////
412/// Create TTree object that lives in memory, independent of current
413/// location of gDirectory
414
415void RooTreeDataStore::createTree(std::string_view name, std::string_view title)
416{
417 if (!_tree) {
418 _tree = new TTree(TString{name},TString{title});
421 _tree->SetDirectory(nullptr);
422 }
423
424 TString pwd(gDirectory->GetPath()) ;
425 TString memDir(gROOT->GetName()) ;
426 memDir.Append(":/") ;
427 Bool_t notInMemNow= (pwd!=memDir) ;
428
429 // cout << "RooTreeData::createTree pwd=" << pwd << " memDir=" << memDir << " notInMemNow = " << (notInMemNow?"T":"F") << endl ;
430
431 if (notInMemNow) {
432 gDirectory->cd(memDir) ;
433 }
434
435 if (!_cacheTree) {
436 _cacheTree = new TTree(TString{name} + "_cacheTree", TString{title});
438 gDirectory->RecursiveRemove(_cacheTree) ;
439 }
440
441 if (notInMemNow) {
442 gDirectory->cd(pwd) ;
443 }
444
445}
446
447
448
449
450////////////////////////////////////////////////////////////////////////////////
451/// Load values from tree 't' into this data collection, optionally
452/// selecting events using the RooFormulaVar 'select'.
453///
454/// The source tree 't' is cloned to not disturb its branch
455/// structure when retrieving information from it.
456void RooTreeDataStore::loadValues(const TTree *t, const RooFormulaVar* select, const char* /*rangeName*/, Int_t /*nStart*/, Int_t /*nStop*/)
457{
458 // Make our local copy of the tree, so we can safely loop through it.
459 // We need a custom deleter, because if we don't deregister the Tree from the directory
460 // of the original, it tears it down at destruction time!
461 auto deleter = [](TTree* tree){tree->SetDirectory(nullptr); delete tree;};
462 std::unique_ptr<TTree, decltype(deleter)> tClone(static_cast<TTree*>(t->Clone()), deleter);
463 tClone->SetDirectory(t->GetDirectory());
464
465 // Clone list of variables
466 std::unique_ptr<RooArgSet> sourceArgSet( _varsww.snapshot(kFALSE) );
467
468 // Check that we have the branches:
469 Bool_t missingBranches = kFALSE;
470 for (const auto var : *sourceArgSet) {
471 if (!tClone->GetBranch(var->GetName())) {
472 missingBranches = kTRUE;
473 coutE(InputArguments) << "Didn't find a branch in Tree '" << tClone->GetName() << "' to read variable '"
474 << var->GetName() << "' from."
475 << "\n\tNote: Name the RooFit variable the same as the branch." << std::endl;
476 }
477 }
478 if (missingBranches) {
479 coutE(InputArguments) << "Cannot import data from TTree '" << tClone->GetName()
480 << "' because some branches are missing !" << std::endl;
481 return;
482 }
483
484 // Attach args in cloned list to cloned source tree
485 for (const auto sourceArg : *sourceArgSet) {
486 sourceArg->attachToTree(*tClone,_defTreeBufSize) ;
487 }
488
489 // Redirect formula servers to sourceArgSet
490 std::unique_ptr<RooFormulaVar> selectClone;
491 if (select) {
492 selectClone.reset( static_cast<RooFormulaVar*>(select->cloneTree()) );
493 selectClone->recursiveRedirectServers(*sourceArgSet) ;
494 selectClone->setOperMode(RooAbsArg::ADirty,kTRUE) ;
495 }
496
497 // Loop over events in source tree
498 Int_t numInvalid(0) ;
499 const Long64_t nevent = tClone->GetEntries();
500 for(Long64_t i=0; i < nevent; ++i) {
501 const auto entryNumber = tClone->GetEntryNumber(i);
502 if (entryNumber<0) break;
503 tClone->GetEntry(entryNumber,1);
504
505 // Copy from source to destination
506 Bool_t allOK(kTRUE) ;
507 for (unsigned int j=0; j < sourceArgSet->size(); ++j) {
508 auto destArg = _varsww[j];
509 const auto sourceArg = (*sourceArgSet)[j];
510
511 destArg->copyCache(sourceArg) ;
512 sourceArg->copyCache(destArg) ;
513 if (!destArg->isValid()) {
514 numInvalid++ ;
515 allOK=kFALSE ;
516 if (numInvalid < 5) {
517 auto& log = coutI(DataHandling);
518 log << "RooTreeDataStore::loadValues(" << GetName() << ") Skipping event #" << i << " because " << destArg->GetName()
519 << " cannot accommodate the value ";
520 if(sourceArg->isCategory()) {
521 log << static_cast<RooAbsCategory*>(sourceArg)->getCurrentIndex();
522 } else {
523 log << static_cast<RooAbsReal*>(sourceArg)->getVal();
524 }
525 log << std::endl;
526 } else if (numInvalid == 5) {
527 coutI(DataHandling) << "RooTreeDataStore::loadValues(" << GetName() << ") Skipping ..." << std::endl;
528 }
529 break ;
530 }
531 }
532
533 // Does this event pass the cuts?
534 if (!allOK || (selectClone && selectClone->getVal()==0)) {
535 continue ;
536 }
537
538 fill() ;
539 }
540
541 if (numInvalid>0) {
542 coutW(DataHandling) << "RooTreeDataStore::loadValues(" << GetName() << ") Ignored " << numInvalid << " out-of-range events" << endl ;
543 }
544
545 SetTitle(t->GetTitle());
546}
547
548
549
550
551
552
553////////////////////////////////////////////////////////////////////////////////
554/// Load values from dataset 't' into this data collection, optionally
555/// selecting events using 'select' RooFormulaVar
556///
557
559 const char* rangeName, std::size_t nStart, std::size_t nStop)
560{
561 // Redirect formula servers to source data row
562 std::unique_ptr<RooFormulaVar> selectClone;
563 if (select) {
564 selectClone.reset( static_cast<RooFormulaVar*>(select->cloneTree()) );
565 selectClone->recursiveRedirectServers(*ads->get()) ;
566 selectClone->setOperMode(RooAbsArg::ADirty,kTRUE) ;
567 }
568
569 // Force RDS internal initialization
570 ads->get(0) ;
571
572 // Loop over events in source tree
573 const auto numEntr = static_cast<std::size_t>(ads->numEntries());
574 std::size_t nevent = nStop < numEntr ? nStop : numEntr;
575
576 auto TDS = dynamic_cast<const RooTreeDataStore*>(ads) ;
577 if (TDS) {
578 const_cast<RooTreeDataStore*>(TDS)->resetBuffers();
579 }
580
581 std::vector<std::string> ranges;
582 if (rangeName) {
583 ranges = ROOT::Split(rangeName, ",");
584 }
585
586 for (auto i=nStart; i < nevent ; ++i) {
587 ads->get(i) ;
588
589 // Does this event pass the cuts?
590 if (selectClone && selectClone->getVal()==0) {
591 continue ;
592 }
593
594
595 if (TDS) {
596 _varsww.assignValueOnly(TDS->_varsww) ;
597 } else {
598 _varsww.assignValueOnly(*ads->get()) ;
599 }
600
601 // Check that all copied values are valid
602 bool allValid = true;
603 for (const auto arg : _varsww) {
604 allValid = arg->isValid() && (ranges.empty() || std::any_of(ranges.begin(), ranges.end(),
605 [arg](const std::string& range){return arg->inRange(range.c_str());}) );
606 if (!allValid)
607 break ;
608 }
609
610 if (!allValid) {
611 continue ;
612 }
613
614 _cachedVars.assign(((RooTreeDataStore*)ads)->_cachedVars) ;
615 fill() ;
616 }
617
618 if (TDS) {
619 const_cast<RooTreeDataStore*>(TDS)->restoreAlternateBuffers();
620 }
621
622 SetTitle(ads->GetTitle());
623}
624
625
626////////////////////////////////////////////////////////////////////////////////
627/// Interface function to TTree::Fill
628
630{
631 return _tree->Fill() ;
632}
633
634
635
636////////////////////////////////////////////////////////////////////////////////
637/// Load the n-th data point (n='index') in memory
638/// and return a pointer to the internal RooArgSet
639/// holding its coordinates.
640
642{
643 checkInit() ;
644
645 Int_t ret = ((RooTreeDataStore*)this)->GetEntry(index, 1) ;
646
647 if(!ret) return 0;
648
649 if (_doDirtyProp) {
650 // Raise all dirty flags
651 for (auto var : _vars) {
652 var->setValueDirty(); // This triggers recalculation of all clients
653 }
654
655 for (auto var : _cachedVars) {
656 var->setValueDirty(); // This triggers recalculation of all clients, but doesn't recalculate self
657 var->clearValueDirty();
658 }
659 }
660
661 // Update current weight cache
662 if (_extWgtArray) {
663
664 // If external array is specified use that
665 _curWgt = _extWgtArray[index] ;
668 _curWgtErr = sqrt( _extSumW2Array ? _extSumW2Array[index] : _extWgtArray[index] );
669
670 } else if (_wgtVar) {
671
672 // Otherwise look for weight variable
673 _curWgt = _wgtVar->getVal() ;
677
678 } else {
679
680 // Otherwise return 1
681 _curWgt=1.0 ;
682 _curWgtErrLo = 0 ;
683 _curWgtErrHi = 0 ;
684 _curWgtErr = 0 ;
685
686 }
687
688 return &_vars;
689}
690
691
692////////////////////////////////////////////////////////////////////////////////
693/// Return the weight of the n-th data point (n='index') in memory
694
696{
697 return _curWgt ;
698}
699
700
701////////////////////////////////////////////////////////////////////////////////
702
704{
705 if (_extWgtArray) {
706
707 // We have a weight array, use that info
708
709 // Return symmetric error on current bin calculated either from Poisson statistics or from SumOfWeights
710 Double_t lo = 0, hi =0;
711 weightError(lo,hi,etype) ;
712 return (lo+hi)/2 ;
713
714 } else if (_wgtVar) {
715
716 // We have a a weight variable, use that info
717 if (_wgtVar->hasAsymError()) {
718 return ( _wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo() ) / 2 ;
719 } else {
720 return _wgtVar->getError() ;
721 }
722
723 } else {
724
725 // We have no weights
726 return 0 ;
727
728 }
729}
730
731
732
733////////////////////////////////////////////////////////////////////////////////
734
736{
737 if (_extWgtArray) {
738
739 // We have a weight array, use that info
740 switch (etype) {
741
742 case RooAbsData::Auto:
743 throw string(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
744 break ;
745
747 throw string(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
748 break ;
749
751 // Weight may be preset or precalculated
752 if (_curWgtErrLo>=0) {
753 lo = _curWgtErrLo ;
754 hi = _curWgtErrHi ;
755 return ;
756 }
757
758 // Otherwise Calculate poisson errors
759 Double_t ym,yp ;
761 lo = weight()-ym ;
762 hi = yp-weight() ;
763 return ;
764
766 lo = _curWgtErr ;
767 hi = _curWgtErr ;
768 return ;
769
770 case RooAbsData::None:
771 lo = 0 ;
772 hi = 0 ;
773 return ;
774 }
775
776 } else if (_wgtVar) {
777
778 // We have a a weight variable, use that info
779 if (_wgtVar->hasAsymError()) {
781 lo = _wgtVar->getAsymErrorLo() ;
782 } else {
783 hi = _wgtVar->getError() ;
784 lo = _wgtVar->getError() ;
785 }
786
787 } else {
788
789 // We are unweighted
790 lo=0 ;
791 hi=0 ;
792
793 }
794}
795
796
797////////////////////////////////////////////////////////////////////////////////
798/// Change name of internal observable named 'from' into 'to'
799
800Bool_t RooTreeDataStore::changeObservableName(const char* from, const char* to)
801{
802 // Find observable to be changed
803 RooAbsArg* var = _vars.find(from) ;
804
805 // Check that we found it
806 if (!var) {
807 coutE(InputArguments) << "RooTreeDataStore::changeObservableName(" << GetName() << " no observable " << from << " in this dataset" << endl ;
808 return kTRUE ;
809 }
810
811 // Process name change
812 TString oldBranchName = var->cleanBranchName() ;
813 var->SetName(to) ;
814
815 // Change the branch name as well
816 if (_tree->GetBranch(oldBranchName.Data())) {
817
818 // Simple case varName = branchName
819 _tree->GetBranch(oldBranchName.Data())->SetName(var->cleanBranchName().Data()) ;
820
821 // Process any error branch if existing
822 if (_tree->GetBranch(Form("%s_err",oldBranchName.Data()))) {
823 _tree->GetBranch(Form("%s_err",oldBranchName.Data()))->SetName(Form("%s_err",var->cleanBranchName().Data())) ;
824 }
825 if (_tree->GetBranch(Form("%s_aerr_lo",oldBranchName.Data()))) {
826 _tree->GetBranch(Form("%s_aerr_lo",oldBranchName.Data()))->SetName(Form("%s_aerr_lo",var->cleanBranchName().Data())) ;
827 }
828 if (_tree->GetBranch(Form("%s_aerr_hi",oldBranchName.Data()))) {
829 _tree->GetBranch(Form("%s_aerr_hi",oldBranchName.Data()))->SetName(Form("%s_aerr_hi",var->cleanBranchName().Data())) ;
830 }
831
832 } else {
833
834 // Native category case branchNames = varName_idx and varName_lbl
835 if (_tree->GetBranch(Form("%s_idx",oldBranchName.Data()))) {
836 _tree->GetBranch(Form("%s_idx",oldBranchName.Data()))->SetName(Form("%s_idx",var->cleanBranchName().Data())) ;
837 }
838 if (_tree->GetBranch(Form("%s_lbl",oldBranchName.Data()))) {
839 _tree->GetBranch(Form("%s_lbl",oldBranchName.Data()))->SetName(Form("%s_lb",var->cleanBranchName().Data())) ;
840 }
841
842 }
843
844 return kFALSE ;
845}
846
847
848
849////////////////////////////////////////////////////////////////////////////////
850/// Add a new column to the data set which holds the pre-calculated values
851/// of 'newVar'. This operation is only meaningful if 'newVar' is a derived
852/// value.
853///
854/// The return value points to the added element holding 'newVar's value
855/// in the data collection. The element is always the corresponding fundamental
856/// type of 'newVar' (e.g. a RooRealVar if 'newVar' is a RooFormulaVar)
857///
858/// Note: This function is explicitly NOT intended as a speed optimization
859/// opportunity for the user. Components of complex PDFs that can be
860/// precalculated with the dataset are automatically identified as such
861/// and will be precalculated when fitting to a dataset
862///
863/// By forcibly precalculating functions with non-trivial Jacobians,
864/// or functions of multiple variables occurring in the data set,
865/// using addColumn(), you may alter the outcome of the fit.
866///
867/// Only in cases where such a modification of fit behaviour is intentional,
868/// this function should be used.
869
871{
872 checkInit() ;
873
874 // Create a fundamental object of the right type to hold newVar values
875 RooAbsArg* valHolder= newVar.createFundamental();
876 // Sanity check that the holder really is fundamental
877 if(!valHolder->isFundamental()) {
878 coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
879 << valHolder->GetName() << "\"" << endl;
880 return 0;
881 }
882
883 // WVE need to reset TTRee buffers to original datamembers here
884 resetBuffers() ;
885
886 // Clone variable and attach to cloned tree
887 RooAbsArg* newVarClone = newVar.cloneTree() ;
889
890 // Attach value place holder to this tree
891 ((RooAbsArg*)valHolder)->attachToTree(*_tree,_defTreeBufSize) ;
892 _vars.add(*valHolder) ;
893 _varsww.add(*valHolder) ;
894
895
896 // Fill values of of placeholder
897 for (int i=0 ; i<GetEntries() ; i++) {
898 get(i) ;
899
900 newVarClone->syncCache(&_vars) ;
901 valHolder->copyCache(newVarClone) ;
902 valHolder->fillTreeBranch(*_tree) ;
903 }
904
905 // WVE need to restore TTRee buffers to previous values here
907
908 if (adjustRange) {
909// // Set range of valHolder to (just) bracket all values stored in the dataset
910// Double_t vlo,vhi ;
911// RooRealVar* rrvVal = dynamic_cast<RooRealVar*>(valHolder) ;
912// if (rrvVal) {
913// getRange(*rrvVal,vlo,vhi,0.05) ;
914// rrvVal->setRange(vlo,vhi) ;
915// }
916 }
917
918
919
920 delete newVarClone ;
921 return valHolder ;
922}
923
924
925
926////////////////////////////////////////////////////////////////////////////////
927/// Utility function to add multiple columns in one call
928/// See addColumn() for details
929
931{
932 TIterator* vIter = varList.createIterator() ;
933 RooAbsArg* var ;
934
935 checkInit() ;
936
937 TList cloneSetList ;
938 RooArgSet cloneSet ;
939 RooArgSet* holderSet = new RooArgSet ;
940
941 // WVE need to reset TTRee buffers to original datamembers here
942 resetBuffers() ;
943
944
945 while((var=(RooAbsArg*)vIter->Next())) {
946 // Create a fundamental object of the right type to hold newVar values
947 RooAbsArg* valHolder= var->createFundamental();
948 holderSet->add(*valHolder) ;
949
950 // Sanity check that the holder really is fundamental
951 if(!valHolder->isFundamental()) {
952 coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
953 << valHolder->GetName() << "\"" << endl;
954 return 0;
955 }
956
957 // Clone variable and attach to cloned tree
958 RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
959 if (!newVarCloneList) {
960 coutE(InputArguments) << "RooTreeDataStore::RooTreeData(" << GetName()
961 << ") Couldn't deep-clone variable " << var->GetName() << ", abort." << endl ;
962 return 0 ;
963 }
964 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
966 newVarClone->recursiveRedirectServers(*holderSet,kFALSE) ;
967
968 cloneSetList.Add(newVarCloneList) ;
969 cloneSet.add(*newVarClone) ;
970
971 // Attach value place holder to this tree
972 ((RooAbsArg*)valHolder)->attachToTree(*_tree,_defTreeBufSize) ;
973 _vars.addOwned(*valHolder) ;
974 }
975 delete vIter ;
976
977
978 TIterator* cIter = cloneSet.createIterator() ;
979 TIterator* hIter = holderSet->createIterator() ;
980 RooAbsArg *cloneArg, *holder ;
981 // Fill values of of placeholder
982 for (int i=0 ; i<GetEntries() ; i++) {
983 get(i) ;
984
985 cIter->Reset() ;
986 hIter->Reset() ;
987 while((cloneArg=(RooAbsArg*)cIter->Next())) {
988 holder = (RooAbsArg*)hIter->Next() ;
989
990 cloneArg->syncCache(&_vars) ;
991 holder->copyCache(cloneArg) ;
992 holder->fillTreeBranch(*_tree) ;
993 }
994 }
995
996 // WVE need to restore TTRee buffers to previous values here
998
999 delete cIter ;
1000 delete hIter ;
1001
1002 cloneSetList.Delete() ;
1003 return holderSet ;
1004}
1005
1006
1007
1008
1009////////////////////////////////////////////////////////////////////////////////
1010/// Merge columns of supplied data set(s) with this data set. All
1011/// data sets must have equal number of entries. In case of
1012/// duplicate columns the column of the last dataset in the list
1013/// prevails
1014
1015RooAbsDataStore* RooTreeDataStore::merge(const RooArgSet& allVars, list<RooAbsDataStore*> dstoreList)
1016{
1017 RooTreeDataStore* mergedStore = new RooTreeDataStore("merged","merged",allVars) ;
1018
1019 Int_t nevt = dstoreList.front()->numEntries() ;
1020 for (int i=0 ; i<nevt ; i++) {
1021
1022 // Cope data from self
1023 mergedStore->_vars.assign(*get(i)) ;
1024
1025 // Copy variables from merge sets
1026 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
1027 const RooArgSet* partSet = (*iter)->get(i) ;
1028 mergedStore->_vars.assign(*partSet) ;
1029 }
1030
1031 mergedStore->fill() ;
1032 }
1033 return mergedStore ;
1034}
1035
1036
1037
1038
1039
1040////////////////////////////////////////////////////////////////////////////////
1041
1043{
1044 Int_t nevt = other.numEntries() ;
1045 for (int i=0 ; i<nevt ; i++) {
1046 _vars.assign(*other.get(i)) ;
1047 if (_wgtVar) {
1048 _wgtVar->setVal(other.weight()) ;
1049 }
1050
1051 fill() ;
1052 }
1053}
1054
1055
1056////////////////////////////////////////////////////////////////////////////////
1057
1059{
1060 if (_wgtVar) {
1061
1062 Double_t sum(0), carry(0);
1063 Int_t nevt = numEntries() ;
1064 for (int i=0 ; i<nevt ; i++) {
1065 get(i) ;
1066 // Kahan's algorithm for summing to avoid loss of precision
1067 Double_t y = _wgtVar->getVal() - carry;
1068 Double_t t = sum + y;
1069 carry = (t - sum) - y;
1070 sum = t;
1071 }
1072 return sum ;
1073
1074 } else if (_extWgtArray) {
1075
1076 Double_t sum(0) , carry(0);
1077 Int_t nevt = numEntries() ;
1078 for (int i=0 ; i<nevt ; i++) {
1079 // Kahan's algorithm for summing to avoid loss of precision
1080 Double_t y = _extWgtArray[i] - carry;
1081 Double_t t = sum + y;
1082 carry = (t - sum) - y;
1083 sum = t;
1084 }
1085 return sum ;
1086
1087 } else {
1088
1089 return numEntries() ;
1090
1091 }
1092}
1093
1094
1095
1096
1097////////////////////////////////////////////////////////////////////////////////
1098
1100{
1101 return _tree->GetEntries() ;
1102}
1103
1104
1105
1106////////////////////////////////////////////////////////////////////////////////
1107
1109{
1110 Reset() ;
1111}
1112
1113
1114
1115////////////////////////////////////////////////////////////////////////////////
1116/// Cache given RooAbsArgs with this tree: The tree is
1117/// given direct write access of the args internal cache
1118/// the args values is pre-calculated for all data points
1119/// in this data collection. Upon a get() call, the
1120/// internal cache of 'newVar' will be loaded with the
1121/// precalculated value and it's dirty flag will be cleared.
1122
1123void RooTreeDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, const RooArgSet* nset, Bool_t /*skipZeroWeights*/)
1124{
1125 checkInit() ;
1126
1127 _cacheOwner = owner ;
1128
1129 RooArgSet* constExprVarSet = (RooArgSet*) newVarSet.selectByAttrib("ConstantExpression",kTRUE) ;
1130 TIterator *iter = constExprVarSet->createIterator() ;
1131 RooAbsArg *arg ;
1132
1133 Bool_t doTreeFill = (_cachedVars.getSize()==0) ;
1134
1135 while ((arg=(RooAbsArg*)iter->Next())) {
1136 // Attach original newVar to this tree
1138 //arg->recursiveRedirectServers(_vars) ;
1139 _cachedVars.add(*arg) ;
1140 }
1141
1142 // WVE need to reset TTRee buffers to original datamembers here
1143 //resetBuffers() ;
1144
1145 // Refill regular and cached variables of current tree from clone
1146 for (int i=0 ; i<GetEntries() ; i++) {
1147 get(i) ;
1148
1149 // Evaluate the cached variables and store the results
1150 iter->Reset() ;
1151 while ((arg=(RooAbsArg*)iter->Next())) {
1152 arg->setValueDirty() ;
1153 arg->syncCache(nset) ;
1154 if (!doTreeFill) {
1155 arg->fillTreeBranch(*_cacheTree) ;
1156 }
1157 }
1158
1159 if (doTreeFill) {
1160 _cacheTree->Fill() ;
1161 }
1162 }
1163
1164 // WVE need to restore TTRee buffers to previous values here
1165 //restoreAlternateBuffers() ;
1166
1167 delete iter ;
1168 delete constExprVarSet ;
1169}
1170
1171
1172
1173
1174////////////////////////////////////////////////////////////////////////////////
1175/// Activate or deactivate the branch status of the TTree branch associated
1176/// with the given set of dataset observables
1177
1179{
1180 TIterator* iter = set.createIterator() ;
1181 RooAbsArg* arg ;
1182 while ((arg=(RooAbsArg*)iter->Next())) {
1183 RooAbsArg* depArg = _vars.find(arg->GetName()) ;
1184 if (!depArg) {
1185 coutE(InputArguments) << "RooTreeDataStore::setArgStatus(" << GetName()
1186 << ") dataset doesn't contain variable " << arg->GetName() << endl ;
1187 continue ;
1188 }
1189 depArg->setTreeBranchStatus(*_tree,active) ;
1190 }
1191 delete iter ;
1192}
1193
1194
1195
1196////////////////////////////////////////////////////////////////////////////////
1197/// Remove tree with values of cached observables
1198/// and clear list of cached observables
1199
1201{
1202 // Empty list of cached functions
1204
1205 // Delete & recreate cache tree
1206 delete _cacheTree ;
1207 _cacheTree = 0 ;
1208 createTree(makeTreeName().c_str(), GetTitle());
1209
1210 return ;
1211}
1212
1213
1214
1215
1216////////////////////////////////////////////////////////////////////////////////
1217
1219{
1221 for (const auto arg : _varsww) {
1222 RooAbsArg* extArg = extObs.find(arg->GetName()) ;
1223 if (extArg) {
1224 if (arg->getAttribute("StoreError")) {
1225 extArg->setAttribute("StoreError") ;
1226 }
1227 if (arg->getAttribute("StoreAsymError")) {
1228 extArg->setAttribute("StoreAsymError") ;
1229 }
1230 extArg->attachToTree(*_tree) ;
1231 _attachedBuffers.add(*extArg) ;
1232 }
1233 }
1234}
1235
1236
1237
1238////////////////////////////////////////////////////////////////////////////////
1239
1241{
1242 RooFIter iter = _varsww.fwdIterator() ;
1243 RooAbsArg* arg ;
1244 while((arg=iter.next())) {
1245 arg->attachToTree(*_tree) ;
1246 }
1247}
1248
1249
1250
1251////////////////////////////////////////////////////////////////////////////////
1252
1254{
1256 RooAbsArg* arg ;
1257 while((arg=iter.next())) {
1258 arg->attachToTree(*_tree) ;
1259 }
1260}
1261
1262
1263
1264////////////////////////////////////////////////////////////////////////////////
1265
1267{
1268 if (_defCtor) {
1269 const_cast<RooTreeDataStore*>(this)->initialize() ;
1270 _defCtor = kFALSE ;
1271 }
1272}
1273
1274
1275
1276
1277
1278////////////////////////////////////////////////////////////////////////////////
1279/// Interface function to TTree::GetEntries
1280
1282{
1283 return _tree->GetEntries() ;
1284}
1285
1286
1287////////////////////////////////////////////////////////////////////////////////
1288/// Interface function to TTree::Reset
1289
1291{
1292 _tree->Reset(option) ;
1293}
1294
1295
1296////////////////////////////////////////////////////////////////////////////////
1297/// Interface function to TTree::Fill
1298
1300{
1301 return _tree->Fill() ;
1302}
1303
1304
1305////////////////////////////////////////////////////////////////////////////////
1306/// Interface function to TTree::GetEntry
1307
1309{
1310 Int_t ret1 = _tree->GetEntry(entry,getall) ;
1311 if (!ret1) return 0 ;
1312 _cacheTree->GetEntry(entry,getall) ;
1313 return ret1 ;
1314}
1315
1316
1317////////////////////////////////////////////////////////////////////////////////
1318
1320{
1321 _tree->Draw(option) ;
1322}
1323
1324////////////////////////////////////////////////////////////////////////////////
1325/// Stream an object of class RooTreeDataStore.
1326
1327void RooTreeDataStore::Streamer(TBuffer &R__b)
1328{
1329 if (R__b.IsReading()) {
1330 UInt_t R__s, R__c;
1331 const Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1332
1333 R__b.ReadClassBuffer(RooTreeDataStore::Class(), this, R__v, R__s, R__c);
1334
1335 if (!_tree) {
1336 // If the tree has not been deserialised automatically, it is time to load
1337 // it now.
1338 TFile* parent = dynamic_cast<TFile*>(R__b.GetParent());
1339 assert(parent);
1340 parent->GetObject(makeTreeName().c_str(), _tree);
1341 }
1342
1343 initialize();
1344
1345 } else {
1346
1347 TTree* tmpTree = _tree;
1348 auto parent = dynamic_cast<TDirectory*>(R__b.GetParent());
1349 if (_tree && parent) {
1350 // Large trees cannot be written because of the 1Gb I/O limitation.
1351 // Here, we take the tree away from our instance, write it, and continue
1352 // to write the rest of the class normally
1353 auto tmpDir = _tree->GetDirectory();
1354
1355 _tree->SetDirectory(parent);
1356 _tree->FlushBaskets(false);
1357 parent->WriteObject(_tree, makeTreeName().c_str());
1358 _tree->SetDirectory(tmpDir);
1359 _tree = nullptr;
1360 }
1361
1362 R__b.WriteClassBuffer(RooTreeDataStore::Class(), this);
1363
1364 _tree = tmpTree;
1365 }
1366}
1367
1368////////////////////////////////////////////////////////////////////////////////
1369/// Generate a name for the storage tree from the name and title of this instance.
1371 std::string title = GetTitle();
1372 std::replace(title.begin(), title.end(), ' ', '_');
1373 std::replace(title.begin(), title.end(), '-', '_');
1374 return std::string("RooTreeDataStore_") + GetName() + "_" + title;
1375}
1376
1377
1378////////////////////////////////////////////////////////////////////////////////
1379/// Get the weights of the events in the range [first, first+len).
1380/// This implementation will fill a vector with every event retrieved one by one
1381/// (even if the weight is constant). Then, it returns a span.
1383
1384 if (_extWgtArray) {
1385 return {_extWgtArray + first, len};
1386 }
1387
1388 if (!_weightBuffer) {
1389 _weightBuffer.reset(new std::vector<double>());
1390 _weightBuffer->reserve(len);
1391
1392 for (std::size_t i = 0; i < GetEntries(); ++i) {
1393 _weightBuffer->push_back(weight(i));
1394 }
1395 }
1396
1397 return {_weightBuffer->data() + first, len};
1398}
#define coutI(a)
#define coutW(a)
#define coutE(a)
int Int_t
Definition RtypesCore.h:45
short Version_t
Definition RtypesCore.h:65
const Bool_t kFALSE
Definition RtypesCore.h:101
double Stat_t
Definition RtypesCore.h:86
long long Long64_t
Definition RtypesCore.h:80
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
#define gDirectory
Definition TDirectory.h:385
char name[80]
Definition TGX11.cxx:110
#define hi
#define gROOT
Definition TROOT.h:404
char * Form(const char *fmt,...)
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:69
virtual RooAbsArg * cloneTree(const char *newname=0) const
Clone tree expression of objects.
void attachDataStore(const RooAbsDataStore &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
virtual void setTreeBranchStatus(TTree &t, Bool_t active)=0
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE)=0
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:239
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
virtual void attachToTree(TTree &t, Int_t bufSize=32000)=0
Overloadable function for derived classes to implement attachment as branch to a TTree.
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:505
virtual void syncCache(const RooArgSet *nset=0)=0
TString cleanBranchName() const
Construct a mangled name from the actual name that is free of any math symbols that might be interpre...
virtual RooAbsArg * createFundamental(const char *newname=0) const =0
Create a fundamental-type object that stores our type of value.
virtual void fillTreeBranch(TTree &t)=0
Bool_t recursiveRedirectServers(const RooAbsCollection &newServerList, Bool_t mustReplaceAll=kFALSE, Bool_t nameChange=kFALSE, Bool_t recurseInNewSet=kTRUE)
Recursively replace all servers with the new servers in newSet.
void SetName(const char *name)
Set the name of the TNamed.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
Storage_t const & get() const
Const access to the underlying stl container.
RooAbsCollection & assignValueOnly(const RooAbsCollection &other, bool forceIfSizeOne=false)
Sets the value of any argument in our set that also appears in the other set.
Int_t getSize() const
RooFIter fwdIterator() const
One-time forward iterator.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add an argument and transfer the ownership to the collection.
RooAbsCollection * selectByAttrib(const char *name, Bool_t value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
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 Double_t weight() const =0
virtual Int_t numEntries() const =0
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:94
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:158
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...
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.
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
Double_t getAsymErrorLo() const
Definition RooRealVar.h:66
Bool_t hasAsymError(Bool_t allowZero=kTRUE) const
Definition RooRealVar.h:68
Double_t getAsymErrorHi() const
Definition RooRealVar.h:67
Double_t getError() const
Definition RooRealVar.h:62
virtual void setVal(Double_t value)
Set value of variable to 'value'.
A simple container to hold a batch of data values.
Definition RooSpan.h:34
RooTreeDataStore is a TTree-backed data storage.
const Double_t * _extSumW2Array
External weight array - high error.
const Double_t * _extWgtArray
virtual Double_t weight() const
Return the weight of the n-th data point (n='index') in memory.
void initialize()
One-time initialization common to all constructor forms.
virtual void append(RooAbsDataStore &other)
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
virtual Bool_t changeObservableName(const char *from, const char *to)
Change name of internal observable named 'from' into 'to'.
virtual void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=0, Bool_t skipZeroWeights=kFALSE)
Cache given RooAbsArgs with this tree: The tree is given direct write access of the args internal cac...
virtual void attachBuffers(const RooArgSet &extObs)
std::string makeTreeName() const
Generate a name for the storage tree from the name and title of this instance.
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return pointer to weight variable if it is defined.
const Double_t * _extWgtErrLoArray
External weight array.
virtual Int_t fill()
Interface function to TTree::Fill.
Stat_t GetEntries() const
Interface function to TTree::GetEntries.
Int_t GetEntry(Int_t entry=0, Int_t getall=0)
Interface function to TTree::GetEntry.
Double_t _curWgt
Buffer for weights in case a batch of values is requested.
virtual void checkInit() const
static Int_t _defTreeBufSize
void loadValues(const TTree *t, const RooFormulaVar *select=0, const char *rangeName=0, Int_t nStart=0, Int_t nStop=2000000000)
Load values from tree 't' into this data collection, optionally selecting events using the RooFormula...
const Double_t * _extWgtErrHiArray
External weight array - low error.
void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
virtual void resetCache()
Remove tree with values of cached observables and clear list of cached observables.
Bool_t _defCtor
Object owning cache contents.
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList)
Merge columns of supplied data set(s) with this data set.
void createTree(std::string_view name, std::string_view title)
Create TTree object that lives in memory, independent of current location of gDirectory.
virtual void resetBuffers()
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a new column to the data set which holds the pre-calculated values of 'newVar'.
virtual RooArgSet * addColumns(const RooArgList &varList)
Utility function to add multiple columns in one call See addColumn() for details.
std::unique_ptr< std::vector< double > > _weightBuffer
External sum of weights array.
Int_t Fill()
Interface function to TTree::Fill.
virtual ~RooTreeDataStore()
Destructor.
void Reset(Option_t *option=0)
Interface function to TTree::Reset.
virtual Double_t sumEntries() const
virtual RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len) const
Get the weights of the events in the range [first, first+len).
virtual const RooArgSet * get() const
const RooAbsArg * _cacheOwner
TTree holding the cached function values.
RooArgSet _varsww
Was object constructed with default ctor?
virtual Int_t numEntries() const
virtual void setArgStatus(const RooArgSet &set, Bool_t active)
Activate or deactivate the branch status of the TTree branch associated with the given set of dataset...
void Draw(Option_t *option="")
Default Draw method for all objects.
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition TBuffer.cxx:262
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Describe directory structure in memory.
Definition TDirectory.h:45
std::enable_if_t<!std::is_base_of< TObject, T >::value, Int_t > WriteObject(const T *obj, const char *name, Option_t *option="", Int_t bufsize=0)
Write an object with proper type checking.
Definition TDirectory.h:282
void GetObject(const char *namecycle, T *&ptr)
Get an object with proper type checking.
Definition TDirectory.h:212
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
Iterator abstract base class.
Definition TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
A doubly linked list.
Definition TList.h:38
virtual void Add(TObject *obj)
Definition TList.h:81
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TNamed.cxx:74
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
void ResetBit(UInt_t f)
Definition TObject.h:200
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:62
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:64
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
TString & Append(const char *cs)
Definition TString.h:564
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual Int_t Fill()
Fill all branches.
Definition TTree.cxx:4594
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5279
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Definition TTree.cxx:5622
virtual Int_t FlushBaskets(Bool_t create_cluster=true) const
Write to disk all the basket that have not yet been individually written and create an event cluster ...
Definition TTree.cxx:5114
virtual Long64_t CopyEntries(TTree *tree, Long64_t nentries=-1, Option_t *option="", Bool_t needCopyAddresses=false)
Copy nentries from given tree to this tree.
Definition TTree.cxx:3528
TDirectory * GetDirectory() const
Definition TTree.h:459
virtual void SetDirectory(TDirectory *dir)
Change the tree's directory.
Definition TTree.cxx:8932
virtual Long64_t GetEntries() const
Definition TTree.h:460
virtual void Reset(Option_t *option="")
Reset baskets, buffers and entries count in all branches and leaves.
Definition TTree.cxx:7982
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition TTree.h:428
Double_t y[n]
Definition legend1.C:17
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
Definition first.py:1
Definition tree.py:1
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345