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