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 
22 RooTreeDataStore is a TTree-backed data storage. When a file is opened before
23 creating the data storage, the storage will be file-backed. This reduces memory
24 pressure because it allows storing the data in the file and reading it on demand.
25 For a completely memory-backed storage, which is faster than the file-backed storage,
26 RooVectorDataStore can be used.
27 
28 With 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
33 storage.
34 ```
35 TFile outputFile("filename.root", "RECREATE");
36 RooAbsData::setDefaultStorageType(RooAbsData::Tree);
37 RooDataSet mydata(...);
38 ```
39 
40 One can also change between TTree- and std::vector-backed storage using
41 RooAbsData::convertToTreeStore() and
42 RooAbsData::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>
63 using 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 
92 RooTreeDataStore::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 
109 RooTreeDataStore::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 
130 RooTreeDataStore::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 
151 RooTreeDataStore::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 
179 RooTreeDataStore::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 
200 RooTreeDataStore::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 
229 RooTreeDataStore::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 
274 RooArgSet 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 
292 RooRealVar* 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 
308 void 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 
330 RooTreeDataStore::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 
353 RooTreeDataStore::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 
414 void 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.
455 void 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  Bool_t missingBranches = kFALSE;
469  for (const auto var : *sourceArgSet) {
470  if (!tClone->GetBranch(var->GetName())) {
471  missingBranches = kTRUE;
472  coutE(InputArguments) << "Didn't find a branch in Tree '" << tClone->GetName() << "' to read variable '"
473  << var->GetName() << "' from."
474  << "\n\tNote: Name the RooFit variable the same as the branch." << std::endl;
475  }
476  }
477  if (missingBranches) {
478  coutE(InputArguments) << "Cannot import data from TTree '" << tClone->GetName()
479  << "' because some branches are missing !" << std::endl;
480  return;
481  }
482 
483  // Attach args in cloned list to cloned source tree
484  for (const auto sourceArg : *sourceArgSet) {
485  sourceArg->attachToTree(*tClone,_defTreeBufSize) ;
486  }
487 
488  // Redirect formula servers to sourceArgSet
489  std::unique_ptr<RooFormulaVar> selectClone;
490  if (select) {
491  selectClone.reset( static_cast<RooFormulaVar*>(select->cloneTree()) );
492  selectClone->recursiveRedirectServers(*sourceArgSet) ;
493  selectClone->setOperMode(RooAbsArg::ADirty,kTRUE) ;
494  }
495 
496  // Loop over events in source tree
497  Int_t numInvalid(0) ;
498  const Long64_t nevent = tClone->GetEntries();
499  for(Long64_t i=0; i < nevent; ++i) {
500  const auto entryNumber = tClone->GetEntryNumber(i);
501  if (entryNumber<0) break;
502  tClone->GetEntry(entryNumber,1);
503 
504  // Copy from source to destination
505  Bool_t allOK(kTRUE) ;
506  for (unsigned int j=0; j < sourceArgSet->size(); ++j) {
507  auto destArg = _varsww[j];
508  const auto sourceArg = (*sourceArgSet)[j];
509 
510  destArg->copyCache(sourceArg) ;
511  sourceArg->copyCache(destArg) ;
512  if (!destArg->isValid()) {
513  numInvalid++ ;
514  allOK=kFALSE ;
515  if (numInvalid < 5) {
516  coutI(DataHandling) << "RooTreeDataStore::loadValues(" << GetName() << ") Skipping event #" << i << " because " << destArg->GetName()
517  << " cannot accommodate the value " << static_cast<RooAbsReal*>(sourceArg)->getVal() << std::endl;
518  } else if (numInvalid == 5) {
519  coutI(DataHandling) << "RooTreeDataStore::loadValues(" << GetName() << ") Skipping ..." << std::endl;
520  }
521  break ;
522  }
523  }
524 
525  // Does this event pass the cuts?
526  if (!allOK || (selectClone && selectClone->getVal()==0)) {
527  continue ;
528  }
529 
530  fill() ;
531  }
532 
533  if (numInvalid>0) {
534  coutW(DataHandling) << "RooTreeDataStore::loadValues(" << GetName() << ") Ignored " << numInvalid << " out-of-range events" << endl ;
535  }
536 
537  SetTitle(t->GetTitle());
538 }
539 
540 
541 
542 
543 
544 
545 ////////////////////////////////////////////////////////////////////////////////
546 /// Load values from dataset 't' into this data collection, optionally
547 /// selecting events using 'select' RooFormulaVar
548 ///
549 
551  const char* rangeName, std::size_t nStart, std::size_t nStop)
552 {
553  // Redirect formula servers to source data row
554  std::unique_ptr<RooFormulaVar> selectClone;
555  if (select) {
556  selectClone.reset( static_cast<RooFormulaVar*>(select->cloneTree()) );
557  selectClone->recursiveRedirectServers(*ads->get()) ;
558  selectClone->setOperMode(RooAbsArg::ADirty,kTRUE) ;
559  }
560 
561  // Force RDS internal initialization
562  ads->get(0) ;
563 
564  // Loop over events in source tree
565  const auto numEntr = static_cast<std::size_t>(ads->numEntries());
566  std::size_t nevent = nStop < numEntr ? nStop : numEntr;
567 
568  auto TDS = dynamic_cast<const RooTreeDataStore*>(ads) ;
569  if (TDS) {
570  const_cast<RooTreeDataStore*>(TDS)->resetBuffers();
571  }
572 
573  std::vector<std::string> ranges;
574  if (rangeName) {
575  ranges = RooHelpers::tokenise(rangeName, ",");
576  }
577 
578  for (auto i=nStart; i < nevent ; ++i) {
579  ads->get(i) ;
580 
581  // Does this event pass the cuts?
582  if (selectClone && selectClone->getVal()==0) {
583  continue ;
584  }
585 
586 
587  if (TDS) {
588  _varsww.assignValueOnly(TDS->_varsww) ;
589  } else {
590  _varsww.assignValueOnly(*ads->get()) ;
591  }
592 
593  // Check that all copied values are valid
594  bool allValid = true;
595  for (const auto arg : _varsww) {
596  allValid = arg->isValid() && (ranges.empty() || std::any_of(ranges.begin(), ranges.end(),
597  [arg](const std::string& range){return arg->inRange(range.c_str());}) );
598  if (!allValid)
599  break ;
600  }
601 
602  if (!allValid) {
603  continue ;
604  }
605 
606  _cachedVars = ((RooTreeDataStore*)ads)->_cachedVars ;
607  fill() ;
608  }
609 
610  if (TDS) {
611  const_cast<RooTreeDataStore*>(TDS)->restoreAlternateBuffers();
612  }
613 
614  SetTitle(ads->GetTitle());
615 }
616 
617 
618 
619 ////////////////////////////////////////////////////////////////////////////////
620 /// Return true if currently loaded coordinate is considered valid within
621 /// the current range definitions of all observables
622 
624 {
625  return kTRUE ;
626 }
627 
628 
629 
630 
631 ////////////////////////////////////////////////////////////////////////////////
632 /// Interface function to TTree::Fill
633 
635 {
636  return _tree->Fill() ;
637 }
638 
639 
640 
641 ////////////////////////////////////////////////////////////////////////////////
642 /// Load the n-th data point (n='index') in memory
643 /// and return a pointer to the internal RooArgSet
644 /// holding its coordinates.
645 
647 {
648  checkInit() ;
649 
650  Int_t ret = ((RooTreeDataStore*)this)->GetEntry(index, 1) ;
651 
652  if(!ret) return 0;
653 
654  if (_doDirtyProp) {
655  // Raise all dirty flags
656  for (auto var : _vars) {
657  var->setValueDirty(); // This triggers recalculation of all clients
658  }
659 
660  for (auto var : _cachedVars) {
661  var->setValueDirty(); // This triggers recalculation of all clients, but doesn't recalculate self
662  var->clearValueDirty();
663  }
664  }
665 
666  // Update current weight cache
667  if (_extWgtArray) {
668 
669  // If external array is specified use that
670  _curWgt = _extWgtArray[index] ;
674 
675  } else if (_wgtVar) {
676 
677  // Otherwise look for weight variable
678  _curWgt = _wgtVar->getVal() ;
682 
683  } else {
684 
685  // Otherwise return 1
686  _curWgt=1.0 ;
687  _curWgtErrLo = 0 ;
688  _curWgtErrHi = 0 ;
689  _curWgtErr = 0 ;
690 
691  }
692 
693  return &_vars;
694 }
695 
696 
697 
698 ////////////////////////////////////////////////////////////////////////////////
699 /// Return the weight of the n-th data point (n='index') in memory
700 
702 {
703  get(index) ;
704  return weight() ;
705 }
706 
707 
708 
709 ////////////////////////////////////////////////////////////////////////////////
710 /// Return the weight of the n-th data point (n='index') in memory
711 
713 {
714  return _curWgt ;
715 }
716 
717 
718 ////////////////////////////////////////////////////////////////////////////////
719 
721 {
722  if (_extWgtArray) {
723 
724  // We have a weight array, use that info
725 
726  // Return symmetric error on current bin calculated either from Poisson statistics or from SumOfWeights
727  Double_t lo = 0, hi =0;
728  weightError(lo,hi,etype) ;
729  return (lo+hi)/2 ;
730 
731  } else if (_wgtVar) {
732 
733  // We have a a weight variable, use that info
734  if (_wgtVar->hasAsymError()) {
735  return ( _wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo() ) / 2 ;
736  } else {
737  return _wgtVar->getError() ;
738  }
739 
740  } else {
741 
742  // We have no weights
743  return 0 ;
744 
745  }
746 }
747 
748 
749 
750 ////////////////////////////////////////////////////////////////////////////////
751 
753 {
754  if (_extWgtArray) {
755 
756  // We have a weight array, use that info
757  switch (etype) {
758 
759  case RooAbsData::Auto:
760  throw string(Form("RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
761  break ;
762 
764  throw string(Form("RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
765  break ;
766 
767  case RooAbsData::Poisson:
768  // Weight may be preset or precalculated
769  if (_curWgtErrLo>=0) {
770  lo = _curWgtErrLo ;
771  hi = _curWgtErrHi ;
772  return ;
773  }
774 
775  // Otherwise Calculate poisson errors
776  Double_t ym,yp ;
778  lo = weight()-ym ;
779  hi = yp-weight() ;
780  return ;
781 
782  case RooAbsData::SumW2:
783  lo = _curWgtErr ;
784  hi = _curWgtErr ;
785  return ;
786 
787  case RooAbsData::None:
788  lo = 0 ;
789  hi = 0 ;
790  return ;
791  }
792 
793  } else if (_wgtVar) {
794 
795  // We have a a weight variable, use that info
796  if (_wgtVar->hasAsymError()) {
797  hi = _wgtVar->getAsymErrorHi() ;
798  lo = _wgtVar->getAsymErrorLo() ;
799  } else {
800  hi = _wgtVar->getError() ;
801  lo = _wgtVar->getError() ;
802  }
803 
804  } else {
805 
806  // We are unweighted
807  lo=0 ;
808  hi=0 ;
809 
810  }
811 }
812 
813 
814 ////////////////////////////////////////////////////////////////////////////////
815 /// Change name of internal observable named 'from' into 'to'
816 
817 Bool_t RooTreeDataStore::changeObservableName(const char* from, const char* to)
818 {
819  // Find observable to be changed
820  RooAbsArg* var = _vars.find(from) ;
821 
822  // Check that we found it
823  if (!var) {
824  coutE(InputArguments) << "RooTreeDataStore::changeObservableName(" << GetName() << " no observable " << from << " in this dataset" << endl ;
825  return kTRUE ;
826  }
827 
828  // Process name change
829  TString oldBranchName = var->cleanBranchName() ;
830  var->SetName(to) ;
831 
832  // Change the branch name as well
833  if (_tree->GetBranch(oldBranchName.Data())) {
834 
835  // Simple case varName = branchName
836  _tree->GetBranch(oldBranchName.Data())->SetName(var->cleanBranchName().Data()) ;
837 
838  // Process any error branch if existing
839  if (_tree->GetBranch(Form("%s_err",oldBranchName.Data()))) {
840  _tree->GetBranch(Form("%s_err",oldBranchName.Data()))->SetName(Form("%s_err",var->cleanBranchName().Data())) ;
841  }
842  if (_tree->GetBranch(Form("%s_aerr_lo",oldBranchName.Data()))) {
843  _tree->GetBranch(Form("%s_aerr_lo",oldBranchName.Data()))->SetName(Form("%s_aerr_lo",var->cleanBranchName().Data())) ;
844  }
845  if (_tree->GetBranch(Form("%s_aerr_hi",oldBranchName.Data()))) {
846  _tree->GetBranch(Form("%s_aerr_hi",oldBranchName.Data()))->SetName(Form("%s_aerr_hi",var->cleanBranchName().Data())) ;
847  }
848 
849  } else {
850 
851  // Native category case branchNames = varName_idx and varName_lbl
852  if (_tree->GetBranch(Form("%s_idx",oldBranchName.Data()))) {
853  _tree->GetBranch(Form("%s_idx",oldBranchName.Data()))->SetName(Form("%s_idx",var->cleanBranchName().Data())) ;
854  }
855  if (_tree->GetBranch(Form("%s_lbl",oldBranchName.Data()))) {
856  _tree->GetBranch(Form("%s_lbl",oldBranchName.Data()))->SetName(Form("%s_lb",var->cleanBranchName().Data())) ;
857  }
858 
859  }
860 
861  return kFALSE ;
862 }
863 
864 
865 
866 ////////////////////////////////////////////////////////////////////////////////
867 /// Add a new column to the data set which holds the pre-calculated values
868 /// of 'newVar'. This operation is only meaningful if 'newVar' is a derived
869 /// value.
870 ///
871 /// The return value points to the added element holding 'newVar's value
872 /// in the data collection. The element is always the corresponding fundamental
873 /// type of 'newVar' (e.g. a RooRealVar if 'newVar' is a RooFormulaVar)
874 ///
875 /// Note: This function is explicitly NOT intended as a speed optimization
876 /// opportunity for the user. Components of complex PDFs that can be
877 /// precalculated with the dataset are automatically identified as such
878 /// and will be precalculated when fitting to a dataset
879 ///
880 /// By forcibly precalculating functions with non-trivial Jacobians,
881 /// or functions of multiple variables occurring in the data set,
882 /// using addColumn(), you may alter the outcome of the fit.
883 ///
884 /// Only in cases where such a modification of fit behaviour is intentional,
885 /// this function should be used.
886 
888 {
889  checkInit() ;
890 
891  // Create a fundamental object of the right type to hold newVar values
892  RooAbsArg* valHolder= newVar.createFundamental();
893  // Sanity check that the holder really is fundamental
894  if(!valHolder->isFundamental()) {
895  coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
896  << valHolder->GetName() << "\"" << endl;
897  return 0;
898  }
899 
900  // WVE need to reset TTRee buffers to original datamembers here
901  resetBuffers() ;
902 
903  // Clone variable and attach to cloned tree
904  RooAbsArg* newVarClone = newVar.cloneTree() ;
905  newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
906 
907  // Attach value place holder to this tree
908  ((RooAbsArg*)valHolder)->attachToTree(*_tree,_defTreeBufSize) ;
909  _vars.add(*valHolder) ;
910  _varsww.add(*valHolder) ;
911 
912 
913  // Fill values of of placeholder
914  for (int i=0 ; i<GetEntries() ; i++) {
915  get(i) ;
916 
917  newVarClone->syncCache(&_vars) ;
918  valHolder->copyCache(newVarClone) ;
919  valHolder->fillTreeBranch(*_tree) ;
920  }
921 
922  // WVE need to restore TTRee buffers to previous values here
924 
925  if (adjustRange) {
926 // // Set range of valHolder to (just) bracket all values stored in the dataset
927 // Double_t vlo,vhi ;
928 // RooRealVar* rrvVal = dynamic_cast<RooRealVar*>(valHolder) ;
929 // if (rrvVal) {
930 // getRange(*rrvVal,vlo,vhi,0.05) ;
931 // rrvVal->setRange(vlo,vhi) ;
932 // }
933  }
934 
935 
936 
937  delete newVarClone ;
938  return valHolder ;
939 }
940 
941 
942 
943 ////////////////////////////////////////////////////////////////////////////////
944 /// Utility function to add multiple columns in one call
945 /// See addColumn() for details
946 
948 {
949  TIterator* vIter = varList.createIterator() ;
950  RooAbsArg* var ;
951 
952  checkInit() ;
953 
954  TList cloneSetList ;
955  RooArgSet cloneSet ;
956  RooArgSet* holderSet = new RooArgSet ;
957 
958  // WVE need to reset TTRee buffers to original datamembers here
959  resetBuffers() ;
960 
961 
962  while((var=(RooAbsArg*)vIter->Next())) {
963  // Create a fundamental object of the right type to hold newVar values
964  RooAbsArg* valHolder= var->createFundamental();
965  holderSet->add(*valHolder) ;
966 
967  // Sanity check that the holder really is fundamental
968  if(!valHolder->isFundamental()) {
969  coutE(InputArguments) << GetName() << "::addColumn: holder argument is not fundamental: \""
970  << valHolder->GetName() << "\"" << endl;
971  return 0;
972  }
973 
974  // Clone variable and attach to cloned tree
975  RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
976  if (!newVarCloneList) {
977  coutE(InputArguments) << "RooTreeDataStore::RooTreeData(" << GetName()
978  << ") Couldn't deep-clone variable " << var->GetName() << ", abort." << endl ;
979  return 0 ;
980  }
981  RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
982  newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
983  newVarClone->recursiveRedirectServers(*holderSet,kFALSE) ;
984 
985  cloneSetList.Add(newVarCloneList) ;
986  cloneSet.add(*newVarClone) ;
987 
988  // Attach value place holder to this tree
989  ((RooAbsArg*)valHolder)->attachToTree(*_tree,_defTreeBufSize) ;
990  _vars.addOwned(*valHolder) ;
991  }
992  delete vIter ;
993 
994 
995  TIterator* cIter = cloneSet.createIterator() ;
996  TIterator* hIter = holderSet->createIterator() ;
997  RooAbsArg *cloneArg, *holder ;
998  // Fill values of of placeholder
999  for (int i=0 ; i<GetEntries() ; i++) {
1000  get(i) ;
1001 
1002  cIter->Reset() ;
1003  hIter->Reset() ;
1004  while((cloneArg=(RooAbsArg*)cIter->Next())) {
1005  holder = (RooAbsArg*)hIter->Next() ;
1006 
1007  cloneArg->syncCache(&_vars) ;
1008  holder->copyCache(cloneArg) ;
1009  holder->fillTreeBranch(*_tree) ;
1010  }
1011  }
1012 
1013  // WVE need to restore TTRee buffers to previous values here
1015 
1016  delete cIter ;
1017  delete hIter ;
1018 
1019  cloneSetList.Delete() ;
1020  return holderSet ;
1021 }
1022 
1023 
1024 
1025 
1026 ////////////////////////////////////////////////////////////////////////////////
1027 /// Merge columns of supplied data set(s) with this data set. All
1028 /// data sets must have equal number of entries. In case of
1029 /// duplicate columns the column of the last dataset in the list
1030 /// prevails
1031 
1032 RooAbsDataStore* RooTreeDataStore::merge(const RooArgSet& allVars, list<RooAbsDataStore*> dstoreList)
1033 {
1034  RooTreeDataStore* mergedStore = new RooTreeDataStore("merged","merged",allVars) ;
1035 
1036  Int_t nevt = dstoreList.front()->numEntries() ;
1037  for (int i=0 ; i<nevt ; i++) {
1038 
1039  // Cope data from self
1040  mergedStore->_vars = *get(i) ;
1041 
1042  // Copy variables from merge sets
1043  for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
1044  const RooArgSet* partSet = (*iter)->get(i) ;
1045  mergedStore->_vars = *partSet ;
1046  }
1047 
1048  mergedStore->fill() ;
1049  }
1050  return mergedStore ;
1051 }
1052 
1053 
1054 
1055 
1056 
1057 ////////////////////////////////////////////////////////////////////////////////
1058 
1060 {
1061  Int_t nevt = other.numEntries() ;
1062  for (int i=0 ; i<nevt ; i++) {
1063  _vars = *other.get(i) ;
1064  if (_wgtVar) {
1065  _wgtVar->setVal(other.weight()) ;
1066  }
1067 
1068  fill() ;
1069  }
1070 }
1071 
1072 
1073 ////////////////////////////////////////////////////////////////////////////////
1074 
1076 {
1077  if (_wgtVar) {
1078 
1079  Double_t sum(0), carry(0);
1080  Int_t nevt = numEntries() ;
1081  for (int i=0 ; i<nevt ; i++) {
1082  get(i) ;
1083  // Kahan's algorithm for summing to avoid loss of precision
1084  Double_t y = _wgtVar->getVal() - carry;
1085  Double_t t = sum + y;
1086  carry = (t - sum) - y;
1087  sum = t;
1088  }
1089  return sum ;
1090 
1091  } else if (_extWgtArray) {
1092 
1093  Double_t sum(0) , carry(0);
1094  Int_t nevt = numEntries() ;
1095  for (int i=0 ; i<nevt ; i++) {
1096  // Kahan's algorithm for summing to avoid loss of precision
1097  Double_t y = _extWgtArray[i] - carry;
1098  Double_t t = sum + y;
1099  carry = (t - sum) - y;
1100  sum = t;
1101  }
1102  return sum ;
1103 
1104  } else {
1105 
1106  return numEntries() ;
1107 
1108  }
1109 }
1110 
1111 
1112 
1113 
1114 ////////////////////////////////////////////////////////////////////////////////
1115 
1117 {
1118  return _tree->GetEntries() ;
1119 }
1120 
1121 
1122 
1123 ////////////////////////////////////////////////////////////////////////////////
1124 
1126 {
1127  Reset() ;
1128 }
1129 
1130 
1131 
1132 ////////////////////////////////////////////////////////////////////////////////
1133 /// Cache given RooAbsArgs with this tree: The tree is
1134 /// given direct write access of the args internal cache
1135 /// the args values is pre-calculated for all data points
1136 /// in this data collection. Upon a get() call, the
1137 /// internal cache of 'newVar' will be loaded with the
1138 /// precalculated value and it's dirty flag will be cleared.
1139 
1140 void RooTreeDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, const RooArgSet* nset, Bool_t /*skipZeroWeights*/)
1141 {
1142  checkInit() ;
1143 
1144  _cacheOwner = owner ;
1145 
1146  RooArgSet* constExprVarSet = (RooArgSet*) newVarSet.selectByAttrib("ConstantExpression",kTRUE) ;
1147  TIterator *iter = constExprVarSet->createIterator() ;
1148  RooAbsArg *arg ;
1149 
1150  Bool_t doTreeFill = (_cachedVars.getSize()==0) ;
1151 
1152  while ((arg=(RooAbsArg*)iter->Next())) {
1153  // Attach original newVar to this tree
1155  //arg->recursiveRedirectServers(_vars) ;
1156  _cachedVars.add(*arg) ;
1157  }
1158 
1159  // WVE need to reset TTRee buffers to original datamembers here
1160  //resetBuffers() ;
1161 
1162  // Refill regular and cached variables of current tree from clone
1163  for (int i=0 ; i<GetEntries() ; i++) {
1164  get(i) ;
1165 
1166  // Evaluate the cached variables and store the results
1167  iter->Reset() ;
1168  while ((arg=(RooAbsArg*)iter->Next())) {
1169  arg->setValueDirty() ;
1170  arg->syncCache(nset) ;
1171  if (!doTreeFill) {
1172  arg->fillTreeBranch(*_cacheTree) ;
1173  }
1174  }
1175 
1176  if (doTreeFill) {
1177  _cacheTree->Fill() ;
1178  }
1179  }
1180 
1181  // WVE need to restore TTRee buffers to previous values here
1182  //restoreAlternateBuffers() ;
1183 
1184  delete iter ;
1185  delete constExprVarSet ;
1186 }
1187 
1188 
1189 
1190 
1191 ////////////////////////////////////////////////////////////////////////////////
1192 /// Activate or deactivate the branch status of the TTree branch associated
1193 /// with the given set of dataset observables
1194 
1196 {
1197  TIterator* iter = set.createIterator() ;
1198  RooAbsArg* arg ;
1199  while ((arg=(RooAbsArg*)iter->Next())) {
1200  RooAbsArg* depArg = _vars.find(arg->GetName()) ;
1201  if (!depArg) {
1202  coutE(InputArguments) << "RooTreeDataStore::setArgStatus(" << GetName()
1203  << ") dataset doesn't contain variable " << arg->GetName() << endl ;
1204  continue ;
1205  }
1206  depArg->setTreeBranchStatus(*_tree,active) ;
1207  }
1208  delete iter ;
1209 }
1210 
1211 
1212 
1213 ////////////////////////////////////////////////////////////////////////////////
1214 /// Remove tree with values of cached observables
1215 /// and clear list of cached observables
1216 
1218 {
1219  // Empty list of cached functions
1221 
1222  // Delete & recreate cache tree
1223  delete _cacheTree ;
1224  _cacheTree = 0 ;
1225  createTree(makeTreeName().c_str(), GetTitle());
1226 
1227  return ;
1228 }
1229 
1230 
1231 
1232 
1233 ////////////////////////////////////////////////////////////////////////////////
1234 
1236 {
1238  for (const auto arg : _varsww) {
1239  RooAbsArg* extArg = extObs.find(arg->GetName()) ;
1240  if (extArg) {
1241  if (arg->getAttribute("StoreError")) {
1242  extArg->setAttribute("StoreError") ;
1243  }
1244  if (arg->getAttribute("StoreAsymError")) {
1245  extArg->setAttribute("StoreAsymError") ;
1246  }
1247  extArg->attachToTree(*_tree) ;
1248  _attachedBuffers.add(*extArg) ;
1249  }
1250  }
1251 }
1252 
1253 
1254 
1255 ////////////////////////////////////////////////////////////////////////////////
1256 
1258 {
1259  RooFIter iter = _varsww.fwdIterator() ;
1260  RooAbsArg* arg ;
1261  while((arg=iter.next())) {
1262  arg->attachToTree(*_tree) ;
1263  }
1264 }
1265 
1266 
1267 
1268 ////////////////////////////////////////////////////////////////////////////////
1269 
1271 {
1273  RooAbsArg* arg ;
1274  while((arg=iter.next())) {
1275  arg->attachToTree(*_tree) ;
1276  }
1277 }
1278 
1279 
1280 
1281 ////////////////////////////////////////////////////////////////////////////////
1282 
1284 {
1285  if (_defCtor) {
1286  const_cast<RooTreeDataStore*>(this)->initialize() ;
1287  _defCtor = kFALSE ;
1288  }
1289 }
1290 
1291 
1292 
1293 
1294 
1295 ////////////////////////////////////////////////////////////////////////////////
1296 /// Interface function to TTree::GetEntries
1297 
1299 {
1300  return _tree->GetEntries() ;
1301 }
1302 
1303 
1304 ////////////////////////////////////////////////////////////////////////////////
1305 /// Interface function to TTree::Reset
1306 
1308 {
1309  _tree->Reset(option) ;
1310 }
1311 
1312 
1313 ////////////////////////////////////////////////////////////////////////////////
1314 /// Interface function to TTree::Fill
1315 
1317 {
1318  return _tree->Fill() ;
1319 }
1320 
1321 
1322 ////////////////////////////////////////////////////////////////////////////////
1323 /// Interface function to TTree::GetEntry
1324 
1326 {
1327  Int_t ret1 = _tree->GetEntry(entry,getall) ;
1328  if (!ret1) return 0 ;
1329  _cacheTree->GetEntry(entry,getall) ;
1330  return ret1 ;
1331 }
1332 
1333 
1334 ////////////////////////////////////////////////////////////////////////////////
1335 
1337 {
1338  _tree->Draw(option) ;
1339 }
1340 
1341 ////////////////////////////////////////////////////////////////////////////////
1342 /// Stream an object of class RooTreeDataStore.
1343 
1344 void RooTreeDataStore::Streamer(TBuffer &R__b)
1345 {
1346  if (R__b.IsReading()) {
1347  UInt_t R__s, R__c;
1348  const Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1349 
1350  R__b.ReadClassBuffer(RooTreeDataStore::Class(), this, R__v, R__s, R__c);
1351 
1352  if (!_tree) {
1353  // If the tree has not been deserialised automatically, it is time to load
1354  // it now.
1355  TFile* parent = dynamic_cast<TFile*>(R__b.GetParent());
1356  assert(parent);
1357  parent->GetObject(makeTreeName().c_str(), _tree);
1358  }
1359 
1360  initialize();
1361 
1362  } else {
1363 
1364  TTree* tmpTree = _tree;
1365  auto parent = dynamic_cast<TDirectory*>(R__b.GetParent());
1366  if (_tree && parent) {
1367  // Large trees cannot be written because of the 1Gb I/O limitation.
1368  // Here, we take the tree away from our instance, write it, and continue
1369  // to write the rest of the class normally
1370  auto tmpDir = _tree->GetDirectory();
1371 
1372  _tree->SetDirectory(parent);
1373  _tree->FlushBaskets(false);
1374  parent->WriteObject(_tree, makeTreeName().c_str());
1375  _tree->SetDirectory(tmpDir);
1376  _tree = nullptr;
1377  }
1378 
1380 
1381  _tree = tmpTree;
1382  }
1383 }
1384 
1385 ////////////////////////////////////////////////////////////////////////////////
1386 /// Generate a name for the storage tree from the name and title of this instance.
1387 std::string RooTreeDataStore::makeTreeName() const {
1388  std::string title = GetTitle();
1389  std::replace(title.begin(), title.end(), ' ', '_');
1390  std::replace(title.begin(), title.end(), '-', '_');
1391  return std::string("RooTreeDataStore_") + GetName() + "_" + title;
1392 }
1393 
1394 
1395 ////////////////////////////////////////////////////////////////////////////////
1396 /// Get the weights of the events in the range [first, first+len).
1397 /// This implementation will fill a vector with every event retrieved one by one
1398 /// (even if the weight is constant). Then, it returns a span.
1399 RooSpan<const double> RooTreeDataStore::getWeightBatch(std::size_t first, std::size_t len) const {
1400 
1401  if (_extWgtArray) {
1402  return {_extWgtArray + first, len};
1403  }
1404 
1405  if (!_weightBuffer) {
1406  _weightBuffer.reset(new std::vector<double>());
1407  _weightBuffer->reserve(len);
1408 
1409  for (std::size_t i = 0; i < GetEntries(); ++i) {
1410  _weightBuffer->push_back(weight(i));
1411  }
1412  }
1413 
1414  return {_weightBuffer->data() + first, len};
1415 }
RooFormulaVar.h
TObject::kMustCleanup
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition: TObject.h:60
RooRealVar::getAsymErrorHi
Double_t getAsymErrorHi() const
Definition: RooRealVar.h:65
RooTreeDataStore::resetCache
virtual void resetCache()
Remove tree with values of cached observables and clear list of cached observables.
Definition: RooTreeDataStore.cxx:1217
RooAbsArg::fillTreeBranch
virtual void fillTreeBranch(TTree &t)=0
TTree::Reset
virtual void Reset(Option_t *option="")
Reset baskets, buffers and entries count in all branches and leaves.
Definition: TTree.cxx:7938
RooAbsArg::ADirty
@ ADirty
Definition: RooAbsArg.h:390
first
Definition: first.py:1
RooHelpers.h
RooRealVar::setVal
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:257
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
Version_t
short Version_t
Definition: RtypesCore.h:65
RooMsgService.h
RooTreeDataStore::GetEntry
Int_t GetEntry(Int_t entry=0, Int_t getall=0)
Interface function to TTree::GetEntry.
Definition: RooTreeDataStore.cxx:1325
TDirectory.h
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
Option_t
const char Option_t
Definition: RtypesCore.h:66
RooAbsData::SumW2
@ SumW2
Definition: RooAbsData.h:99
RooFit.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:61
RooTreeDataStore::tree
TTree & tree()
Definition: RooTreeDataStore.h:106
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
TString::Data
const char * Data() const
Definition: TString.h:369
TDirectory::GetObject
void GetObject(const char *namecycle, T *&ptr)
Get an object with proper type checking.
Definition: TDirectory.h:203
RooTreeDataStore::cacheArgs
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...
Definition: RooTreeDataStore.cxx:1140
TTree::FlushBaskets
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:5083
tree
Definition: tree.py:1
RooTreeDataStore::RooTreeDataStore
RooTreeDataStore()
Definition: RooTreeDataStore.cxx:74
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
RooTreeDataStore::Reset
void Reset(Option_t *option=0)
Interface function to TTree::Reset.
Definition: RooTreeDataStore.cxx:1307
RooAbsArg::cleanBranchName
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:1929
RooAbsCollection::assignValueOnly
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.
Definition: RooAbsCollection.cxx:344
RooTreeDataStore::_extWgtErrHiArray
const Double_t * _extWgtErrHiArray
External weight array - low error.
Definition: RooTreeDataStore.h:168
TBuffer::ReadClassBuffer
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
RooTreeDataStore::reset
virtual void reset()
Definition: RooTreeDataStore.cxx:1125
RooAbsCollection::fwdIterator
RooFIter fwdIterator() const
One-time forward iterator.
Definition: RooAbsCollection.h:193
RooTreeDataStore::addColumn
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'.
Definition: RooTreeDataStore.cxx:887
sum
static uint64_t sum(uint64_t i)
Definition: Factory.cxx:2345
TBranch.h
Long64_t
long long Long64_t
Definition: RtypesCore.h:80
coutE
#define coutE(a)
Definition: RooMsgService.h:33
coutW
#define coutW(a)
Definition: RooMsgService.h:32
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
TTree
A TTree represents a columnar dataset.
Definition: TTree.h:79
RooTreeDataStore::addColumns
virtual RooArgSet * addColumns(const RooArgList &varList)
Utility function to add multiple columns in one call See addColumn() for details.
Definition: RooTreeDataStore.cxx:947
RooAbsData::Auto
@ Auto
Definition: RooAbsData.h:99
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooTreeDataStore::_defCtor
Bool_t _defCtor
Object owning cache contents.
Definition: RooTreeDataStore.h:161
RooAbsArg::SetName
void SetName(const char *name)
Set the name of the TNamed.
Definition: RooAbsArg.cxx:2325
RooAbsArg::createFundamental
virtual RooAbsArg * createFundamental(const char *newname=0) const =0
Create a fundamental-type object that stores our type of value.
Int_t
int Int_t
Definition: RtypesCore.h:45
RooAbsCollection::remove
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
Definition: RooAbsCollection.cxx:585
RooAbsCollection::find
RooAbsArg * find(const char *name) const
Find object with given name in list.
Definition: RooAbsCollection.cxx:810
coutI
#define coutI(a)
Definition: RooMsgService.h:30
RooHistError::getPoissonInterval
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.
Definition: RooHistError.cxx:79
RooTreeDataStore::valid
virtual Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
Definition: RooTreeDataStore.cxx:623
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
TBuffer
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
TTree::Fill
virtual Int_t Fill()
Fill all branches.
Definition: TTree.cxx:4563
RooAbsArg::recursiveRedirectServers
Bool_t recursiveRedirectServers(const RooAbsCollection &newServerList, Bool_t mustReplaceAll=kFALSE, Bool_t nameChange=kFALSE, Bool_t recurseInNewSet=kTRUE)
Recursively replace all servers with the new servers in newSet.
Definition: RooAbsArg.cxx:1159
TTree.h
TString
Basic string class.
Definition: TString.h:136
RooAbsDataStore::_cachedVars
RooArgSet _cachedVars
Definition: RooAbsDataStore.h:131
RooTreeDataStore::_defTreeBufSize
static Int_t _defTreeBufSize
Definition: RooTreeDataStore.h:155
RooAbsData::ErrorType
ErrorType
Definition: RooAbsData.h:99
TTree::GetEntry
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:5581
RooTreeDataStore.h
TFile.h
bool
TIterator
Iterator abstract base class.
Definition: TIterator.h:30
RooTreeDataStore::_extWgtErrLoArray
const Double_t * _extWgtErrLoArray
External weight array.
Definition: RooTreeDataStore.h:167
RooHistError::instance
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
Definition: RooHistError.cxx:49
TROOT.h
RooTreeDataStore::append
virtual void append(RooAbsDataStore &other)
Definition: RooTreeDataStore.cxx:1059
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:115
RooTreeDataStore::GetEntries
Stat_t GetEntries() const
Interface function to TTree::GetEntries.
Definition: RooTreeDataStore.cxx:1298
hi
float type_of_call hi(const int &, const int &)
TTree::GetBranch
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition: TTree.cxx:5248
RooTreeDataStore::restoreAlternateBuffers
void restoreAlternateBuffers()
Definition: RooTreeDataStore.cxx:1270
RooTreeDataStore::checkInit
virtual void checkInit() const
Definition: RooTreeDataStore.cxx:1283
RooAbsData::Expected
@ Expected
Definition: RooAbsData.h:99
RooFit::DataHandling
@ DataHandling
Definition: RooGlobalFunc.h:62
RooTreeDataStore::_tree
TTree * _tree
Definition: RooTreeDataStore.h:158
TChain.h
RooFormulaVar
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
TBuffer.h
RooRealVar::getError
Double_t getError() const
Definition: RooRealVar.h:60
TObject::ResetBit
void ResetBit(UInt_t f)
Definition: TObject.h:186
RooRealVar::getAsymErrorLo
Double_t getAsymErrorLo() const
Definition: RooRealVar.h:64
Double_t
RooAbsArg::syncCache
virtual void syncCache(const RooArgSet *nset=0)=0
RooTreeDataStore::_extWgtArray
const Double_t * _extWgtArray
Definition: RooTreeDataStore.h:166
RooTreeDataStore::Fill
Int_t Fill()
Interface function to TTree::Fill.
Definition: RooTreeDataStore.cxx:1316
RooAbsDataStore::_vars
RooArgSet _vars
Definition: RooAbsDataStore.h:126
RooFIter
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
Definition: RooLinkedListIter.h:40
TBuffer::WriteClassBuffer
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
RooAbsCollection::get
Storage_t const & get() const
Const access to the underlying stl container.
Definition: RooAbsCollection.h:76
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
RooAbsArg::setTreeBranchStatus
virtual void setTreeBranchStatus(TTree &t, Bool_t active)=0
RooTreeDataStore::weight
virtual Double_t weight() const
Return the weight of the n-th data point (n='index') in memory.
Definition: RooTreeDataStore.cxx:712
TNamed::Clone
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:74
RooTreeDataStore::_extSumW2Array
const Double_t * _extSumW2Array
External weight array - high error.
Definition: RooTreeDataStore.h:169
RooAbsCollection::createIterator
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
Definition: RooAbsCollection.h:178
RooTreeDataStore::get
virtual const RooArgSet * get(Int_t index) const=0
gDirectory
#define gDirectory
Definition: TDirectory.h:327
RooFIter::next
RooAbsArg * next()
Return next element or nullptr if at end.
Definition: RooLinkedListIter.h:49
RooAbsArg::attachDataStore
void attachDataStore(const RooAbsDataStore &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
Definition: RooAbsArg.cxx:1572
RooTreeDataStore::fill
virtual Int_t fill()
Interface function to TTree::Fill.
Definition: RooTreeDataStore.cxx:634
TTree::Draw
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:427
RooAbsCollection::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:455
RooTreeDataStore::makeTreeName
std::string makeTreeName() const
Generate a name for the storage tree from the name and title of this instance.
Definition: RooTreeDataStore.cxx:1387
y
Double_t y[n]
Definition: legend1.C:17
sqrt
double sqrt(double)
RooTreeDataStore::setArgStatus
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...
Definition: RooTreeDataStore.cxx:1195
RooTreeDataStore::getWeightBatch
virtual RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len) const
Get the weights of the events in the range [first, first+len).
Definition: RooTreeDataStore.cxx:1399
RooTreeDataStore::weightError
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const
Definition: RooTreeDataStore.cxx:720
TBuffer::GetParent
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition: TBuffer.cxx:262
RooRealVar.h
RooAbsDataStore::get
virtual const RooArgSet * get(Int_t index) const =0
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TTree::SetDirectory
virtual void SetDirectory(TDirectory *dir)
Change the tree's directory.
Definition: TTree.cxx:8854
RooTreeDataStore::Draw
void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: RooTreeDataStore.cxx:1336
TBuffer::ReadVersion
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
TObject::kCanDelete
@ kCanDelete
if object in a list can be deleted
Definition: TObject.h:58
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
RooAbsCollection::addOwned
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:403
RooTreeDataStore::numEntries
virtual Int_t numEntries() const
Definition: RooTreeDataStore.cxx:1116
RooTreeDataStore
RooTreeDataStore is a TTree-backed data storage.
Definition: RooTreeDataStore.h:32
RooAbsData::Poisson
@ Poisson
Definition: RooAbsData.h:99
TIterator::Next
virtual TObject * Next()=0
RooAbsDataStore::weight
virtual Double_t weight() const =0
RooTreeDataStore::_curWgtErrLo
Double_t _curWgtErrLo
Definition: RooTreeDataStore.h:173
RooTreeDataStore::weightVar
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return pointer to weight variable if it is defined.
Definition: RooTreeDataStore.cxx:292
RooTreeDataStore::createTree
void createTree(const char *name, const char *title)
Create TTree object that lives in memory, independent of current location of gDirectory.
Definition: RooTreeDataStore.cxx:414
unsigned int
TTree::GetDirectory
TDirectory * GetDirectory() const
Definition: TTree.h:457
RooAbsArg::isFundamental
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
RooHelpers::tokenise
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:67
RooAbsArg::copyCache
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE)=0
TIterator::Reset
virtual void Reset()=0
RooTreeDataStore::_cacheOwner
const RooAbsArg * _cacheOwner
TTree holding the cached function values.
Definition: RooTreeDataStore.h:160
RooAbsDataStore::numEntries
virtual Int_t numEntries() const =0
RooAbsData::None
@ None
Definition: RooAbsData.h:99
RooAbsDataStore::_doDirtyProp
Bool_t _doDirtyProp
Definition: RooAbsDataStore.h:133
RooTreeDataStore::~RooTreeDataStore
virtual ~RooTreeDataStore()
Destructor.
Definition: RooTreeDataStore.cxx:379
RooTreeDataStore::merge
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList)
Merge columns of supplied data set(s) with this data set.
Definition: RooTreeDataStore.cxx:1032
TBuffer::IsReading
Bool_t IsReading() const
Definition: TBuffer.h:86
RooTreeDataStore::sumEntries
virtual Double_t sumEntries() const
Definition: RooTreeDataStore.cxx:1075
RooTreeDataStore::varsNoWeight
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName=0)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
Definition: RooTreeDataStore.cxx:274
RooTreeDataStore::_curWgt
Double_t _curWgt
Buffer for weights in case a batch of values is requested.
Definition: RooTreeDataStore.h:172
RooTreeDataStore::_cacheTree
TTree * _cacheTree
Definition: RooTreeDataStore.h:159
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
RooRealVar::hasAsymError
Bool_t hasAsymError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:66
RooAbsArg::setAttribute
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:291
RooTreeDataStore::initialize
void initialize()
One-time initialization common to all constructor forms.
Definition: RooTreeDataStore.cxx:395
RooAbsArg::cloneTree
virtual RooAbsArg * cloneTree(const char *newname=0) const
Clone tree expression of objects.
Definition: RooAbsArg.cxx:2230
name
char name[80]
Definition: TGX11.cxx:110
RooTreeDataStore::_weightBuffer
std::unique_ptr< std::vector< double > > _weightBuffer
External sum of weights array.
Definition: RooTreeDataStore.h:170
TDirectory
Describe directory structure in memory.
Definition: TDirectory.h:45
RooTreeDataStore::attachCache
void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
Definition: RooTreeDataStore.cxx:308
TTree::CopyEntries
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:3496
RooTreeDataStore::_curWgtErrHi
Double_t _curWgtErrHi
Definition: RooTreeDataStore.h:174
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooTreeDataStore::loadValues
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...
Definition: RooTreeDataStore.cxx:455
RooAbsArg::setValueDirty
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:490
RooTreeDataStore::_curWgtErr
Double_t _curWgtErr
Definition: RooTreeDataStore.h:175
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
RooTreeDataStore::resetBuffers
virtual void resetBuffers()
Definition: RooTreeDataStore.cxx:1257
RooAbsDataStore
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
Definition: RooAbsDataStore.h:34
Stat_t
double Stat_t
Definition: RtypesCore.h:86
Class
void Class()
Definition: Class.C:29
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
RooAbsCollection::removeAll
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
Definition: RooAbsCollection.cxx:644
RooTreeDataStore::_attachedBuffers
RooArgSet _attachedBuffers
Definition: RooTreeDataStore.h:177
RooHistError.h
RooTreeDataStore::attachBuffers
virtual void attachBuffers(const RooArgSet &extObs)
Definition: RooTreeDataStore.cxx:1235
RooTreeDataStore::_wgtVar
RooRealVar * _wgtVar
Definition: RooTreeDataStore.h:164
TTree::GetEntries
virtual Long64_t GetEntries() const
Definition: TTree.h:458
RooAbsCollection::selectByAttrib
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...
Definition: RooAbsCollection.cxx:678
RooTreeDataStore::_varsww
RooArgSet _varsww
Was object constructed with default ctor?
Definition: RooTreeDataStore.h:163
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:231
TList
A doubly linked list.
Definition: TList.h:44
RooSpan
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:33
gROOT
#define gROOT
Definition: TROOT.h:404
TDirectory::WriteObject
Int_t WriteObject(void *obj, const char *name, Option_t *option="", Int_t bufsize=0)
int
RooTreeDataStore::changeObservableName
virtual Bool_t changeObservableName(const char *from, const char *to)
Change name of internal observable named 'from' into 'to'.
Definition: RooTreeDataStore.cxx:817
RooAbsArg::attachToTree
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:1353