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