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