Logo ROOT  
Reference Guide
RooDataSet.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 RooDataSet.cxx
19 \class RooDataSet
20 \ingroup Roofitcore
21 
22 RooDataSet is a container class to hold unbinned data. Each data point
23 in N-dimensional space is represented by a RooArgSet of RooRealVar, RooCategory
24 or RooStringVar objects.
25 
26 There are two storage backends:
27 - RooVectorDataStore (default): std::vectors in memory. They are fast, but they
28 cannot be serialised if the dataset exceeds a size of 1 Gb
29 - RooTreeDataStore: Uses a TTree, which can be file backed if a file is opened
30 before creating the dataset. This significantly reduces the memory pressure, as the
31 baskets of the tree can be written to a file, and only the basket that's currently
32 being read stays in RAM.
33  - Enable tree-backed storage similar to this:
34  ```
35  TFile outputFile("filename.root", "RECREATE");
36  RooAbsData::setDefaultStorageType(RooAbsData::Tree);
37  RooDataSet mydata(...);
38  ```
39  - Or convert an existing memory-backed data storage:
40  ```
41  RooDataSet mydata(...);
42 
43  TFile outputFile("filename.root", "RECREATE");
44  mydata.convertToTreeStore();
45  ```
46 
47 For the inverse conversion, see `RooAbsData::convertToVectorStore()`.
48 
49 **/
50 
51 #include "RooDataSet.h"
52 
53 #include "RooPlot.h"
54 #include "RooAbsReal.h"
55 #include "Roo1DTable.h"
56 #include "RooCategory.h"
57 #include "RooFormulaVar.h"
58 #include "RooArgList.h"
59 #include "RooAbsRealLValue.h"
60 #include "RooRealVar.h"
61 #include "RooDataHist.h"
62 #include "RooMsgService.h"
63 #include "RooCmdConfig.h"
64 #include "RooHist.h"
65 #include "RooTreeDataStore.h"
66 #include "RooVectorDataStore.h"
67 #include "RooCompositeDataStore.h"
68 #include "RooSentinel.h"
69 #include "RooTrace.h"
70 #include "RooHelpers.h"
71 
72 #include "TTree.h"
73 #include "TH2.h"
74 #include "TDirectory.h"
75 #include "TROOT.h"
76 #include "TFile.h"
77 #include "TBuffer.h"
78 #include "ROOT/RMakeUnique.hxx"
79 
80 #include <iostream>
81 #include <fstream>
82 
83 
84 #if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3)
85 char* operator+( streampos&, char* );
86 #endif
87 
88 using namespace std;
89 
91 
92 #ifndef USEMEMPOOLFORDATASET
94 #else
95 
96 #include "MemPoolForRooSets.h"
97 
100  static auto * memPool = new RooDataSet::MemPool();
101  return memPool;
102 }
103 
104 void RooDataSet::cleanup() {
105  auto pool = memPool();
106  pool->teardown();
107 
108  //The pool will have to leak if it's not empty at this point.
109  if (pool->empty())
110  delete pool;
111 }
112 
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Overloaded new operator guarantees that all RooDataSets allocated with new
116 /// have a unique address, a property that is exploited in several places
117 /// in roofit to quickly index contents on normalization set pointers.
118 /// The memory pool only allocates space for the class itself. The elements
119 /// stored in the set are stored outside the pool.
120 
121 void* RooDataSet::operator new (size_t bytes)
122 {
123  //This will fail if a derived class uses this operator
124  assert(sizeof(RooDataSet) == bytes);
125 
126  return memPool()->allocate(bytes);
127 }
128 
129 
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Memory is owned by pool, we need to do nothing to release it
133 
134 void RooDataSet::operator delete (void* ptr)
135 {
136  // Decrease use count in pool that ptr is on
137  if (memPool()->deallocate(ptr))
138  return;
139 
140  std::cerr << __func__ << " " << ptr << " is not in any of the pools." << std::endl;
141 
142  // Not part of any pool; use global op delete:
143  ::operator delete(ptr);
144 }
145 
146 #endif
147 
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Default constructor for persistence
151 
152 RooDataSet::RooDataSet() : _wgtVar(0)
153 {
155 }
156 
157 
158 
159 
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Construct an unbinned dataset from a RooArgSet defining the dimensions of the data space. Optionally, data
163 /// can be imported at the time of construction.
164 ///
165 /// <table>
166 /// <tr><th> %RooCmdArg <th> Effect
167 /// <tr><td> Import(TTree*) <td> Import contents of given TTree. Only braches of the TTree that have names
168 /// corresponding to those of the RooAbsArgs that define the RooDataSet are
169 /// imported.
170 /// <tr><td> ImportFromFile(const char* fileName, const char* treeName) <td> Import tree with given name from file with given name.
171 /// <tr><td> Import(RooDataSet&)
172 /// <td> Import contents of given RooDataSet. Only observables that are common with the definition of this dataset will be imported
173 /// <tr><td> Index(RooCategory&) <td> Prepare import of datasets into a N+1 dimensional RooDataSet
174 /// where the extra discrete dimension labels the source of the imported histogram.
175 /// <tr><td> Import(const char*, RooDataSet&)
176 /// <td> Import a dataset to be associated with the given state name of the index category
177 /// specified in Index(). If the given state name is not yet defined in the index
178 /// category it will be added on the fly. The import command can be specified multiple times.
179 /// <tr><td> Link(const char*, RooDataSet&) <td> Link contents of supplied RooDataSet to this dataset for given index category state name.
180 /// In this mode, no data is copied and the linked dataset must be remain live for the duration
181 /// of this dataset. Note that link is active for both reading and writing, so modifications
182 /// to the aggregate dataset will also modify its components. Link() and Import() are mutually exclusive.
183 /// <tr><td> OwnLinked() <td> Take ownership of all linked datasets
184 /// <tr><td> Import(map<string,RooDataSet*>&) <td> As above, but allows specification of many imports in a single operation
185 /// <tr><td> Link(map<string,RooDataSet*>&) <td> As above, but allows specification of many links in a single operation
186 /// <tr><td> Cut(const char*) <br>
187 /// Cut(RooFormulaVar&)
188 /// <td> Apply the given cut specification when importing data
189 /// <tr><td> CutRange(const char*) <td> Only accept events in the observable range with the given name
190 /// <tr><td> WeightVar(const char*) <br>
191 /// WeightVar(const RooAbsArg&)
192 /// <td> Interpret the given variable as event weight rather than as observable
193 /// <tr><td> StoreError(const RooArgSet&) <td> Store symmetric error along with value for given subset of observables
194 /// <tr><td> StoreAsymError(const RooArgSet&) <td> Store asymmetric error along with value for given subset of observables
195 /// </table>
196 ///
197 
198 RooDataSet::RooDataSet(const char* name, const char* title, const RooArgSet& vars, const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3,
199  const RooCmdArg& arg4,const RooCmdArg& arg5,const RooCmdArg& arg6,const RooCmdArg& arg7,const RooCmdArg& arg8) :
200  RooAbsData(name,title,RooArgSet(vars,(RooAbsArg*)RooCmdConfig::decodeObjOnTheFly("RooDataSet::RooDataSet", "IndexCat",0,0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)))
201 {
202  // Define configuration for this method
203  RooCmdConfig pc(Form("RooDataSet::ctor(%s)",GetName())) ;
204  pc.defineInt("ownLinked","OwnLinked",0) ;
205  pc.defineObject("impTree","ImportTree",0) ;
206  pc.defineObject("impData","ImportData",0) ;
207  pc.defineObject("indexCat","IndexCat",0) ;
208  pc.defineObject("impSliceData","ImportDataSlice",0,0,kTRUE) ; // array
209  pc.defineString("impSliceState","ImportDataSlice",0,"",kTRUE) ; // array
210  pc.defineObject("lnkSliceData","LinkDataSlice",0,0,kTRUE) ; // array
211  pc.defineString("lnkSliceState","LinkDataSlice",0,"",kTRUE) ; // array
212  pc.defineString("cutSpec","CutSpec",0,"") ;
213  pc.defineObject("cutVar","CutVar",0) ;
214  pc.defineString("cutRange","CutRange",0,"") ;
215  pc.defineString("wgtVarName","WeightVarName",0,"") ;
216  pc.defineInt("newWeight1","WeightVarName",0,0) ;
217  pc.defineString("fname","ImportFromFile",0,"") ;
218  pc.defineString("tname","ImportFromFile",1,"") ;
219  pc.defineObject("wgtVar","WeightVar",0) ;
220  pc.defineInt("newWeight2","WeightVar",0,0) ;
221  pc.defineObject("dummy1","ImportDataSliceMany",0) ;
222  pc.defineObject("dummy2","LinkDataSliceMany",0) ;
223  pc.defineSet("errorSet","StoreError",0) ;
224  pc.defineSet("asymErrSet","StoreAsymError",0) ;
225  pc.defineMutex("ImportTree","ImportData","ImportDataSlice","LinkDataSlice","ImportFromFile") ;
226  pc.defineMutex("CutSpec","CutVar") ;
227  pc.defineMutex("WeightVarName","WeightVar") ;
228  pc.defineDependency("ImportDataSlice","IndexCat") ;
229  pc.defineDependency("LinkDataSlice","IndexCat") ;
230  pc.defineDependency("OwnLinked","LinkDataSlice") ;
231 
232 
233  RooLinkedList l ;
234  l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
235  l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
236  l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
237  l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
238 
239  // Process & check varargs
240  pc.process(l) ;
241  if (!pc.ok(kTRUE)) {
242  assert(0) ;
243  return ;
244  }
245 
246  // Extract relevant objects
247  TTree* impTree = static_cast<TTree*>(pc.getObject("impTree")) ;
248  RooDataSet* impData = static_cast<RooDataSet*>(pc.getObject("impData")) ;
249  RooFormulaVar* cutVar = static_cast<RooFormulaVar*>(pc.getObject("cutVar")) ;
250  const char* cutSpec = pc.getString("cutSpec","",kTRUE) ;
251  const char* cutRange = pc.getString("cutRange","",kTRUE) ;
252  const char* wgtVarName = pc.getString("wgtVarName","",kTRUE) ;
253  RooRealVar* wgtVar = static_cast<RooRealVar*>(pc.getObject("wgtVar")) ;
254  const char* impSliceNames = pc.getString("impSliceState","",kTRUE) ;
255  const RooLinkedList& impSliceData = pc.getObjectList("impSliceData") ;
256  const char* lnkSliceNames = pc.getString("lnkSliceState","",kTRUE) ;
257  const RooLinkedList& lnkSliceData = pc.getObjectList("lnkSliceData") ;
258  RooCategory* indexCat = static_cast<RooCategory*>(pc.getObject("indexCat")) ;
259  RooArgSet* errorSet = pc.getSet("errorSet") ;
260  RooArgSet* asymErrorSet = pc.getSet("asymErrSet") ;
261  const char* fname = pc.getString("fname") ;
262  const char* tname = pc.getString("tname") ;
263  Int_t ownLinked = pc.getInt("ownLinked") ;
264  Int_t newWeight = pc.getInt("newWeight1") + pc.getInt("newWeight2") ;
265 
266  // Case 1 --- Link multiple dataset as slices
267  if (lnkSliceNames) {
268 
269  // Make import mapping if index category is specified
270  map<string,RooAbsData*> hmap ;
271  if (indexCat) {
272  char tmp[64000];
273  strlcpy(tmp, lnkSliceNames, 64000);
274  char *token = strtok(tmp, ",");
275  TIterator *hiter = lnkSliceData.MakeIterator();
276  while (token) {
277  hmap[token] = (RooAbsData *)hiter->Next();
278  token = strtok(0, ",");
279  }
280  delete hiter ;
281  }
282 
283  // Lookup name of weight variable if it was specified by object reference
284  if (wgtVar) {
285  // coverity[UNUSED_VALUE]
286  wgtVarName = wgtVar->GetName() ;
287  }
288 
289  appendToDir(this,kTRUE) ;
290 
291  // Initialize RooDataSet with optional weight variable
292  initialize(0) ;
293 
294  map<string,RooAbsDataStore*> storeMap ;
295  RooCategory* icat = (RooCategory*) (indexCat ? _vars.find(indexCat->GetName()) : 0 ) ;
296  if (!icat) {
297  throw std::string("RooDataSet::RooDataSet() ERROR in constructor, cannot find index category") ;
298  }
299  for (map<string,RooAbsData*>::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) {
300  // Define state labels in index category (both in provided indexCat and in internal copy in dataset)
301  if (indexCat && !indexCat->hasLabel(hiter->first)) {
302  indexCat->defineType(hiter->first) ;
303  coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ;
304  }
305  if (icat && !icat->hasLabel(hiter->first)) {
306  icat->defineType(hiter->first) ;
307  }
308  icat->setLabel(hiter->first.c_str()) ;
309  storeMap[icat->getCurrentLabel()]=hiter->second->store() ;
310 
311  // Take ownership of slice if requested
312  if (ownLinked) {
313  addOwnedComponent(hiter->first.c_str(),*hiter->second) ;
314  }
315  }
316 
317  // Create composite datastore
318  _dstore = new RooCompositeDataStore(name,title,_vars,*icat,storeMap) ;
319 
320  } else {
321 
322  if (wgtVar) {
323  wgtVarName = wgtVar->GetName() ;
324  }
325 
326  // Clone weight variable of imported dataset if we are not weighted
327  if (!wgtVar && !wgtVarName && impData && impData->_wgtVar) {
328  _wgtVar = (RooRealVar*) impData->_wgtVar->createFundamental() ;
330  wgtVarName = _wgtVar->GetName() ;
331  }
332 
333  // Create empty datastore
334  RooTreeDataStore* tstore(0) ;
335  RooVectorDataStore* vstore(0) ;
336 
337  if (defaultStorageType==Tree) {
338  tstore = new RooTreeDataStore(name,title,_vars,wgtVarName) ;
339  _dstore = tstore ;
340  } else if (defaultStorageType==Vector) {
341  if (wgtVarName && newWeight) {
342  RooAbsArg* wgttmp = _vars.find(wgtVarName) ;
343  if (wgttmp) {
344  wgttmp->setAttribute("NewWeight") ;
345  }
346  }
347  vstore = new RooVectorDataStore(name,title,_vars,wgtVarName) ;
348  _dstore = vstore ;
349  } else {
350  _dstore = 0 ;
351  }
352 
353 
354  // Make import mapping if index category is specified
355  map<string,RooDataSet*> hmap ;
356  if (indexCat) {
357  TIterator* hiter = impSliceData.MakeIterator() ;
358  for (const auto& token : RooHelpers::tokenise(impSliceNames, ",")) {
359  hmap[token] = (RooDataSet*) hiter->Next() ;
360  }
361  delete hiter ;
362  }
363 
364  // process StoreError requests
365  if (errorSet) {
366  RooArgSet* intErrorSet = (RooArgSet*) _vars.selectCommon(*errorSet) ;
367  intErrorSet->setAttribAll("StoreError") ;
368  TIterator* iter = intErrorSet->createIterator() ;
369  RooAbsArg* arg ;
370  while((arg=(RooAbsArg*)iter->Next())) {
371  arg->attachToStore(*_dstore) ;
372  }
373  delete iter ;
374  delete intErrorSet ;
375  }
376  if (asymErrorSet) {
377  RooArgSet* intAsymErrorSet = (RooArgSet*) _vars.selectCommon(*asymErrorSet) ;
378  intAsymErrorSet->setAttribAll("StoreAsymError") ;
379  TIterator* iter = intAsymErrorSet->createIterator() ;
380  RooAbsArg* arg ;
381  while((arg=(RooAbsArg*)iter->Next())) {
382  arg->attachToStore(*_dstore) ;
383  }
384  delete iter ;
385  delete intAsymErrorSet ;
386  }
387 
388  // Lookup name of weight variable if it was specified by object reference
389  if (wgtVar) {
390  wgtVarName = wgtVar->GetName() ;
391  }
392 
393 
394  appendToDir(this,kTRUE) ;
395 
396  // Initialize RooDataSet with optional weight variable
397  if (wgtVarName && *wgtVarName) {
398  // Use the supplied weight column
399  initialize(wgtVarName) ;
400 
401  } else {
402  if (impData && impData->_wgtVar && vars.find(impData->_wgtVar->GetName())) {
403 
404  // Use the weight column of the source data set
405  initialize(impData->_wgtVar->GetName()) ;
406 
407  } else if (indexCat) {
408 
409  RooDataSet* firstDS = hmap.begin()->second ;
410  if (firstDS->_wgtVar && vars.find(firstDS->_wgtVar->GetName())) {
411  initialize(firstDS->_wgtVar->GetName()) ;
412  } else {
413  initialize(0) ;
414  }
415  } else {
416  initialize(0) ;
417  }
418  }
419 
420  // Import one or more datasets with a cut specification
421  if (cutSpec && *cutSpec) {
422 
423  // Create a RooFormulaVar cut from given cut expression
424  if (indexCat) {
425 
426  // Case 2a --- Import multiple RooDataSets as slices with cutspec
427  RooCategory* icat = (RooCategory*) _vars.find(indexCat->GetName()) ;
428  for (map<string,RooDataSet*>::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) {
429  // Define state labels in index category (both in provided indexCat and in internal copy in dataset)
430  if (!indexCat->hasLabel(hiter->first)) {
431  indexCat->defineType(hiter->first) ;
432  coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ;
433  }
434  if (!icat->hasLabel(hiter->first)) {
435  icat->defineType(hiter->first) ;
436  }
437  icat->setLabel(hiter->first.c_str()) ;
438 
439  RooFormulaVar cutVarTmp(cutSpec,cutSpec,hiter->second->_vars) ;
440  _dstore->loadValues(hiter->second->store(),&cutVarTmp,cutRange) ;
441  }
442 
443  } else if (impData) {
444 
445  // Case 3a --- Import RooDataSet with cutspec
446  RooFormulaVar cutVarTmp(cutSpec,cutSpec,impData->_vars) ;
447  _dstore->loadValues(impData->store(),&cutVarTmp,cutRange);
448  } else if (impTree) {
449 
450  // Case 4a --- Import TTree from memory with cutspec
451  RooFormulaVar cutVarTmp(cutSpec,cutSpec,_vars) ;
452  if (tstore) {
453  tstore->loadValues(impTree,&cutVarTmp,cutRange);
454  } else {
455  RooTreeDataStore tmpstore(name,title,_vars,wgtVarName) ;
456  tmpstore.loadValues(impTree,&cutVarTmp,cutRange) ;
457  _dstore->append(tmpstore) ;
458  }
459  } else if (fname && strlen(fname)) {
460 
461  // Case 5a --- Import TTree from file with cutspec
462  TFile *f = TFile::Open(fname) ;
463  if (!f) {
464  coutE(InputArguments) << "RooDataSet::ctor(" << GetName() << ") ERROR file '" << fname << "' cannot be opened or does not exist" << endl ;
465  throw string(Form("RooDataSet::ctor(%s) ERROR file %s cannot be opened or does not exist",GetName(),fname)) ;
466  }
467  TTree* t = dynamic_cast<TTree*>(f->Get(tname)) ;
468  if (!t) {
469  coutE(InputArguments) << "RooDataSet::ctor(" << GetName() << ") ERROR file '" << fname << "' does not contain a TTree named '" << tname << "'" << endl ;
470  throw string(Form("RooDataSet::ctor(%s) ERROR file %s does not contain a TTree named %s",GetName(),fname,tname)) ;
471  }
472  RooFormulaVar cutVarTmp(cutSpec,cutSpec,_vars) ;
473  if (tstore) {
474  tstore->loadValues(t,&cutVarTmp,cutRange);
475  } else {
476  RooTreeDataStore tmpstore(name,title,_vars,wgtVarName) ;
477  tmpstore.loadValues(t,&cutVarTmp,cutRange) ;
478  _dstore->append(tmpstore) ;
479  }
480  f->Close() ;
481 
482  }
483 
484  // Import one or more datasets with a cut formula
485  } else if (cutVar) {
486 
487  if (indexCat) {
488 
489  // Case 2b --- Import multiple RooDataSets as slices with cutvar
490 
491  RooCategory* icat = (RooCategory*) _vars.find(indexCat->GetName()) ;
492  for (map<string,RooDataSet*>::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) {
493  // Define state labels in index category (both in provided indexCat and in internal copy in dataset)
494  if (!indexCat->hasLabel(hiter->first)) {
495  indexCat->defineType(hiter->first) ;
496  coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ;
497  }
498  if (!icat->hasLabel(hiter->first)) {
499  icat->defineType(hiter->first) ;
500  }
501  icat->setLabel(hiter->first.c_str()) ;
502  _dstore->loadValues(hiter->second->store(),cutVar,cutRange) ;
503  }
504 
505 
506  } else if (impData) {
507  // Case 3b --- Import RooDataSet with cutvar
508  _dstore->loadValues(impData->store(),cutVar,cutRange);
509  } else if (impTree) {
510  // Case 4b --- Import TTree from memory with cutvar
511  if (tstore) {
512  tstore->loadValues(impTree,cutVar,cutRange);
513  } else {
514  RooTreeDataStore tmpstore(name,title,_vars,wgtVarName) ;
515  tmpstore.loadValues(impTree,cutVar,cutRange) ;
516  _dstore->append(tmpstore) ;
517  }
518  } else if (fname && strlen(fname)) {
519  // Case 5b --- Import TTree from file with cutvar
520  TFile *f = TFile::Open(fname) ;
521  if (!f) {
522  coutE(InputArguments) << "RooDataSet::ctor(" << GetName() << ") ERROR file '" << fname << "' cannot be opened or does not exist" << endl ;
523  throw string(Form("RooDataSet::ctor(%s) ERROR file %s cannot be opened or does not exist",GetName(),fname)) ;
524  }
525  TTree* t = dynamic_cast<TTree*>(f->Get(tname)) ;
526  if (!t) {
527  coutE(InputArguments) << "RooDataSet::ctor(" << GetName() << ") ERROR file '" << fname << "' does not contain a TTree named '" << tname << "'" << endl ;
528  throw string(Form("RooDataSet::ctor(%s) ERROR file %s does not contain a TTree named %s",GetName(),fname,tname)) ;
529  }
530  if (tstore) {
531  tstore->loadValues(t,cutVar,cutRange);
532  } else {
533  RooTreeDataStore tmpstore(name,title,_vars,wgtVarName) ;
534  tmpstore.loadValues(t,cutVar,cutRange) ;
535  _dstore->append(tmpstore) ;
536  }
537 
538  f->Close() ;
539  }
540 
541  // Import one or more datasets without cuts
542  } else {
543 
544  if (indexCat) {
545 
546  RooCategory* icat = (RooCategory*) _vars.find(indexCat->GetName()) ;
547  for (map<string,RooDataSet*>::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) {
548  // Define state labels in index category (both in provided indexCat and in internal copy in dataset)
549  if (!indexCat->hasLabel(hiter->first)) {
550  indexCat->defineType(hiter->first) ;
551  coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ;
552  }
553  if (!icat->hasLabel(hiter->first)) {
554  icat->defineType(hiter->first) ;
555  }
556  icat->setLabel(hiter->first.c_str()) ;
557  // Case 2c --- Import multiple RooDataSets as slices
558  _dstore->loadValues(hiter->second->store(),0,cutRange) ;
559  }
560 
561  } else if (impData) {
562  // Case 3c --- Import RooDataSet
563  _dstore->loadValues(impData->store(),0,cutRange);
564 
565  } else if (impTree || (fname && strlen(fname))) {
566  // Case 4c --- Import TTree from memory / file
567  std::unique_ptr<TFile> file;
568 
569  if (impTree == nullptr) {
570  file.reset(TFile::Open(fname));
571  if (!file) {
572  coutE(InputArguments) << "RooDataSet::ctor(" << GetName() << ") ERROR file '" << fname << "' cannot be opened or does not exist" << endl ;
573  throw std::invalid_argument(Form("RooDataSet::ctor(%s) ERROR file %s cannot be opened or does not exist",GetName(),fname)) ;
574  }
575 
576  file->GetObject(tname, impTree);
577  if (!impTree) {
578  coutE(InputArguments) << "RooDataSet::ctor(" << GetName() << ") ERROR file '" << fname << "' does not contain a TTree named '" << tname << "'" << endl ;
579  throw std::invalid_argument(Form("RooDataSet::ctor(%s) ERROR file %s does not contain a TTree named %s",GetName(),fname,tname)) ;
580  }
581  }
582 
583  if (tstore) {
584  tstore->loadValues(impTree,0,cutRange);
585  } else {
586  RooTreeDataStore tmpstore(name,title,_vars,wgtVarName) ;
587  tmpstore.loadValues(impTree,0,cutRange) ;
588  _dstore->append(tmpstore) ;
589  }
590  }
591  }
592 
593  }
595 }
596 
597 
598 
599 ////////////////////////////////////////////////////////////////////////////////
600 /// Constructor of an empty data set from a RooArgSet defining the dimensions
601 /// of the data space.
602 
603 RooDataSet::RooDataSet(const char *name, const char *title, const RooArgSet& vars, const char* wgtVarName) :
604  RooAbsData(name,title,vars)
605 {
606 // cout << "RooDataSet::ctor(" << this << ") storageType = " << ((defaultStorageType==Tree)?"Tree":"Vector") << endl ;
607  _dstore = (defaultStorageType==Tree) ? ((RooAbsDataStore*) new RooTreeDataStore(name,title,_vars,wgtVarName)) :
608  ((RooAbsDataStore*) new RooVectorDataStore(name,title,_vars,wgtVarName)) ;
609 
610  appendToDir(this,kTRUE) ;
611  initialize(wgtVarName) ;
613 }
614 
615 
616 ////////////////////////////////////////////////////////////////////////////////
617 /// Constructor of a data set from (part of) an existing data
618 /// set. The dimensions of the data set are defined by the 'vars'
619 /// RooArgSet, which can be identical to 'dset' dimensions, or a
620 /// subset thereof. The 'cuts' string is an optional RooFormula
621 /// expression and can be used to select the subset of the data
622 /// points in 'dset' to be copied. The cut expression can refer to
623 /// any variable in the source dataset. For cuts involving variables
624 /// other than those contained in the source data set, such as
625 /// intermediate formula objects, use the equivalent constructor
626 /// accepting RooFormulaVar reference as cut specification.
627 ///
628 /// This constructor will internally store the data in a TTree.
629 ///
630 /// For most uses the RooAbsData::reduce() wrapper function, which
631 /// uses this constructor, is the most convenient way to create a
632 /// subset of an existing data
633 ///
634 
635 RooDataSet::RooDataSet(const char *name, const char *title, RooDataSet *dset,
636  const RooArgSet& vars, const char *cuts, const char* wgtVarName) :
637  RooAbsData(name,title,vars)
638 {
639  // Initialize datastore
640  _dstore = new RooTreeDataStore(name,title,_vars,*dset->_dstore,cuts,wgtVarName) ;
641 
642  appendToDir(this,kTRUE) ;
643 
644  if (wgtVarName) {
645  // Use the supplied weight column
646  initialize(wgtVarName) ;
647  } else {
648  if (dset->_wgtVar && vars.find(dset->_wgtVar->GetName())) {
649  // Use the weight column of the source data set
650  initialize(dset->_wgtVar->GetName()) ;
651  } else {
652  initialize(0) ;
653  }
654  }
656 }
657 
658 
659 ////////////////////////////////////////////////////////////////////////////////
660 /// Constructor of a data set from (part of) an existing data
661 /// set. The dimensions of the data set are defined by the 'vars'
662 /// RooArgSet, which can be identical to 'dset' dimensions, or a
663 /// subset thereof. The 'cutVar' formula variable is used to select
664 /// the subset of data points to be copied. For subsets without
665 /// selection on the data points, or involving cuts operating
666 /// exclusively and directly on the data set dimensions, the
667 /// equivalent constructor with a string based cut expression is
668 /// recommended.
669 ///
670 /// This constructor will internally store the data in a TTree.
671 ///
672 /// For most uses the RooAbsData::reduce() wrapper function, which
673 /// uses this constructor, is the most convenient way to create a
674 /// subset of an existing data
675 
676 RooDataSet::RooDataSet(const char *name, const char *title, RooDataSet *dset,
677  const RooArgSet& vars, const RooFormulaVar& cutVar, const char* wgtVarName) :
678  RooAbsData(name,title,vars)
679 {
680  // Initialize datastore
681  _dstore = new RooTreeDataStore(name,title,_vars,*dset->_dstore,cutVar,wgtVarName) ;
682 
683  appendToDir(this,kTRUE) ;
684 
685  if (wgtVarName) {
686  // Use the supplied weight column
687  initialize(wgtVarName) ;
688  } else {
689  if (dset->_wgtVar && vars.find(dset->_wgtVar->GetName())) {
690  // Use the weight column of the source data set
691  initialize(dset->_wgtVar->GetName()) ;
692  } else {
693  initialize(0) ;
694  }
695  }
697 }
698 
699 
700 
701 
702 ////////////////////////////////////////////////////////////////////////////////
703 /// Constructor of a data set from (part of) an ROOT TTRee. The dimensions
704 /// of the data set are defined by the 'vars' RooArgSet. For each dimension
705 /// specified, the TTree must have a branch with the same name. For category
706 /// branches, this branch should contain the numeric index value. Real dimensions
707 /// can be constructed from either 'Double_t' or 'Float_t' tree branches. In the
708 /// latter case, an automatic conversion is applied.
709 ///
710 /// The 'cutVar' formula variable
711 /// is used to select the subset of data points to be copied.
712 /// For subsets without selection on the data points, or involving cuts
713 /// operating exclusively and directly on the data set dimensions, the equivalent
714 /// constructor with a string based cut expression is recommended.
715 
716 RooDataSet::RooDataSet(const char *name, const char *title, TTree *theTree,
717  const RooArgSet& vars, const RooFormulaVar& cutVar, const char* wgtVarName) :
718  RooAbsData(name,title,vars)
719 {
720  // Create tree version of datastore
721  RooTreeDataStore* tstore = new RooTreeDataStore(name,title,_vars,*theTree,cutVar,wgtVarName) ;
722 
723  // Convert to vector datastore if needed
724  if (defaultStorageType==Tree) {
725  _dstore = tstore ;
726  } else if (defaultStorageType==Vector) {
727  RooVectorDataStore* vstore = new RooVectorDataStore(name,title,_vars,wgtVarName) ;
728  _dstore = vstore ;
729  _dstore->append(*tstore) ;
730  delete tstore ;
731  } else {
732  _dstore = 0 ;
733  }
734 
735  appendToDir(this,kTRUE) ;
736  initialize(wgtVarName) ;
738 }
739 
740 
741 
742 ////////////////////////////////////////////////////////////////////////////////
743 /// Constructor of a data set from (part of) a ROOT TTree.
744 ///
745 /// \param[in] name Name of this dataset.
746 /// \param[in] title Title for e.g. plotting.
747 /// \param[in] tree Tree to be imported.
748 /// \param[in] vars Defines the columns of the data set. For each dimension
749 /// specified, the TTree must have a branch with the same name. For category
750 /// branches, this branch should contain the numeric index value. Real dimensions
751 /// can be constructed from either 'Double_t' or 'Float_t' tree branches. In the
752 /// latter case, an automatic conversion is applied.
753 /// \param[in] cuts Optional RooFormula expression to select the subset of the data points
754 /// to be imported. The cut expression can refer to any variable in `vars`.
755 /// \warning The expression only evaluates variables that are also in `vars`.
756 /// Passing e.g.
757 /// ```
758 /// RooDataSet("data", "data", tree, RooArgSet(x), "x>y")
759 /// ```
760 /// Will load `x` from the tree, but leave `y` at an undefined value.
761 /// If other expressions are needed, such as intermediate formula objects, use
762 /// RooDataSet::RooDataSet(const char*,const char*,TTree*,const RooArgSet&,const RooFormulaVar&,const char*)
763 /// \param[in] wgtVarName Name of the variable in `vars` that represents an event weight.
764 RooDataSet::RooDataSet(const char* name, const char* title, TTree* theTree,
765  const RooArgSet& vars, const char* cuts, const char* wgtVarName) :
766  RooAbsData(name,title,vars)
767 {
768  // Create tree version of datastore
769  RooTreeDataStore* tstore = new RooTreeDataStore(name,title,_vars,*theTree,cuts,wgtVarName);
770 
771  // Convert to vector datastore if needed
772  if (defaultStorageType==Tree) {
773  _dstore = tstore ;
774  } else if (defaultStorageType==Vector) {
775  RooVectorDataStore* vstore = new RooVectorDataStore(name,title,_vars,wgtVarName) ;
776  _dstore = vstore ;
777  _dstore->append(*tstore) ;
778  delete tstore ;
779  } else {
780  _dstore = 0 ;
781  }
782 
783  appendToDir(this,kTRUE) ;
784 
785  initialize(wgtVarName) ;
787 }
788 
789 
790 
791 ////////////////////////////////////////////////////////////////////////////////
792 /// Copy constructor
793 
794 RooDataSet::RooDataSet(RooDataSet const & other, const char* newname) :
795  RooAbsData(other,newname), RooDirItem()
796 {
797  appendToDir(this,kTRUE) ;
798  initialize(other._wgtVar?other._wgtVar->GetName():0) ;
800 }
801 
802 ////////////////////////////////////////////////////////////////////////////////
803 /// Protected constructor for internal use only
804 
805 RooDataSet::RooDataSet(const char *name, const char *title, RooDataSet *dset,
806  const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
807  std::size_t nStart, std::size_t nStop, Bool_t copyCache, const char* wgtVarName) :
808  RooAbsData(name,title,vars)
809 {
810  if (defaultStorageType == Tree) {
811  _dstore = new RooTreeDataStore(name, title, *dset->_dstore, _vars, cutVar, cutRange, nStart, nStop,
812  copyCache, wgtVarName);
813  } else {
814  _dstore = new RooVectorDataStore(name, title, *dset->_dstore, _vars, cutVar, cutRange, nStart,
815  nStop, copyCache, wgtVarName);
816  }
817 
819 
820  appendToDir(this, kTRUE);
821  initialize(dset->_wgtVar ? dset->_wgtVar->GetName() : 0);
823 }
824 
825 
826 ////////////////////////////////////////////////////////////////////////////////
827 /// Helper function for constructor that adds optional weight variable to construct
828 /// total set of observables
829 
830 RooArgSet RooDataSet::addWgtVar(const RooArgSet& origVars, const RooAbsArg* wgtVar)
831 {
832  RooArgSet tmp(origVars) ;
833  if (wgtVar) tmp.add(*wgtVar) ;
834  return tmp ;
835 }
836 
837 
838 
839 ////////////////////////////////////////////////////////////////////////////////
840 /// Return a clone of this dataset containing only the cached variables
841 
842 RooAbsData* RooDataSet::cacheClone(const RooAbsArg* newCacheOwner, const RooArgSet* newCacheVars, const char* newName)
843 {
844  RooDataSet* dset = new RooDataSet(newName?newName:GetName(),GetTitle(),this,_vars,(RooFormulaVar*)0,0,0,2000000000,kTRUE,_wgtVar?_wgtVar->GetName():0) ;
845  //if (_wgtVar) dset->setWeightVar(_wgtVar->GetName()) ;
846 
847  RooArgSet* selCacheVars = (RooArgSet*) newCacheVars->selectCommon(dset->_cachedVars) ;
848  dset->attachCache(newCacheOwner, *selCacheVars) ;
849  delete selCacheVars ;
850 
851  return dset ;
852 }
853 
854 
855 
856 ////////////////////////////////////////////////////////////////////////////////
857 /// Return an empty clone of this dataset. If vars is not null, only the variables in vars
858 /// are added to the definition of the empty clone
859 
860 RooAbsData* RooDataSet::emptyClone(const char* newName, const char* newTitle, const RooArgSet* vars, const char* wgtVarName) const
861 {
862  // If variables are given, be sure to include weight variable if it exists and is not included
863  RooArgSet vars2 ;
864  RooRealVar* tmpWgtVar = _wgtVar ;
865  if (wgtVarName && vars && !_wgtVar) {
866  tmpWgtVar = (RooRealVar*) vars->find(wgtVarName) ;
867  }
868 
869  if (vars) {
870  vars2.add(*vars) ;
871  if (_wgtVar && !vars2.find(_wgtVar->GetName())) {
872  vars2.add(*_wgtVar) ;
873  }
874  } else {
875  vars2.add(_vars) ;
876  }
877 
878  RooDataSet* dset = new RooDataSet(newName?newName:GetName(),newTitle?newTitle:GetTitle(),vars2,tmpWgtVar?tmpWgtVar->GetName():0) ;
879  //if (_wgtVar) dset->setWeightVar(_wgtVar->GetName()) ;
880  return dset ;
881 }
882 
883 
884 
885 ////////////////////////////////////////////////////////////////////////////////
886 /// Initialize the dataset. If wgtVarName is not null, interpret the observable
887 /// with that name as event weight
888 
889 void RooDataSet::initialize(const char* wgtVarName)
890 {
892  _varsNoWgt.add(_vars) ;
893  _wgtVar = 0 ;
894  if (wgtVarName) {
895  RooAbsArg* wgt = _varsNoWgt.find(wgtVarName) ;
896  if (!wgt) {
897  coutW(DataHandling) << "RooDataSet::RooDataSet(" << GetName() << ") WARNING: designated weight variable "
898  << wgtVarName << " not found in set of variables, no weighting will be assigned" << endl ;
899  } else if (!dynamic_cast<RooRealVar*>(wgt)) {
900  coutW(DataHandling) << "RooDataSet::RooDataSet(" << GetName() << ") WARNING: designated weight variable "
901  << wgtVarName << " is not of type RooRealVar, no weighting will be assigned" << endl ;
902  } else {
903  _varsNoWgt.remove(*wgt) ;
904  _wgtVar = (RooRealVar*) wgt ;
905  }
906  }
907 }
908 
909 
910 
911 ////////////////////////////////////////////////////////////////////////////////
912 /// Implementation of RooAbsData virtual method that drives the RooAbsData::reduce() methods
913 
914 RooAbsData* RooDataSet::reduceEng(const RooArgSet& varSubset, const RooFormulaVar* cutVar, const char* cutRange,
915  std::size_t nStart, std::size_t nStop, Bool_t copyCache)
916 {
917  checkInit() ;
918 
919  //cout << "reduceEng varSubset = " << varSubset << " _wgtVar = " << (_wgtVar ? _wgtVar->GetName() : "") << endl;
920 
921  RooArgSet tmp(varSubset) ;
922  if (_wgtVar) {
923  tmp.add(*_wgtVar) ;
924  }
925  RooDataSet* ret = new RooDataSet(GetName(), GetTitle(), this, tmp, cutVar, cutRange, nStart, nStop, copyCache,_wgtVar?_wgtVar->GetName():0) ;
926 
927  // WVE - propagate optional weight variable
928  // check behaviour in plotting.
929  // if (_wgtVar) {
930  // ret->setWeightVar(_wgtVar->GetName()) ;
931  // }
932  return ret ;
933 }
934 
935 
936 
937 ////////////////////////////////////////////////////////////////////////////////
938 /// Destructor
939 
941 {
942  removeFromDir(this) ;
944 }
945 
946 
947 
948 ////////////////////////////////////////////////////////////////////////////////
949 /// Return binned clone of this dataset
950 
951 RooDataHist* RooDataSet::binnedClone(const char* newName, const char* newTitle) const
952 {
953  TString title, name ;
954  if (newName) {
955  name = newName ;
956  } else {
957  name = Form("%s_binned",GetName()) ;
958  }
959  if (newTitle) {
960  title = newTitle ;
961  } else {
962  title = Form("%s_binned",GetTitle()) ;
963  }
964 
965  return new RooDataHist(name,title,*get(),*this) ;
966 }
967 
968 
969 
970 ////////////////////////////////////////////////////////////////////////////////
971 /// Return event weight of current event
972 
974 {
975  return store()->weight() ;
976 }
977 
978 
979 
980 ////////////////////////////////////////////////////////////////////////////////
981 /// Return squared event weight of current event
982 
984 {
985  return store()->weight()*store()->weight() ;
986 }
987 
988 
989 
990 // See base class.
991 RooSpan<const double> RooDataSet::getWeightBatch(std::size_t first, std::size_t len) const {
992  return _dstore->getWeightBatch(first, len);
993 }
994 
995 
996 ////////////////////////////////////////////////////////////////////////////////
997 
999 {
1000  store()->weightError(lo,hi,etype) ;
1001 }
1002 
1003 
1004 
1005 ////////////////////////////////////////////////////////////////////////////////
1006 
1008 {
1009  return store()->weightError(etype) ;
1010 }
1011 
1012 
1013 
1014 ////////////////////////////////////////////////////////////////////////////////
1015 /// Return RooArgSet with coordinates of event 'index'
1016 
1017 const RooArgSet* RooDataSet::get(Int_t index) const
1018 {
1019  const RooArgSet* ret = RooAbsData::get(index) ;
1020  return ret ? &_varsNoWgt : 0 ;
1021 }
1022 
1023 
1024 ////////////////////////////////////////////////////////////////////////////////
1025 
1027 {
1028  return store()->sumEntries() ;
1029 
1030  //---------
1031 
1032  // Shortcut for unweighted unselected datasets
1033  if (!isWeighted()) {
1034  return numEntries() ;
1035  }
1036 
1037  // Otherwise sum the weights in the event
1038  Double_t sumw(0), carry(0);
1039  Int_t i ;
1040  for (i=0 ; i<numEntries() ; i++) {
1041  get(i) ;
1042  Double_t y = weight() - carry;
1043  Double_t t = sumw + y;
1044  carry = (t - sumw) - y;
1045  sumw = t;
1046  }
1047 
1048  return sumw ;
1049 }
1050 
1051 
1052 ////////////////////////////////////////////////////////////////////////////////
1053 /// Return the sum of weights in all entries matching cutSpec (if specified)
1054 /// and in named range cutRange (if specified)
1055 
1056 Double_t RooDataSet::sumEntries(const char* cutSpec, const char* cutRange) const
1057 {
1058  // Setup RooFormulaVar for cutSpec if it is present
1059  RooFormula* select = 0 ;
1060  if (cutSpec && strlen(cutSpec) > 0) {
1061  select = new RooFormula("select",cutSpec,*get()) ;
1062  }
1063 
1064  // Shortcut for unweighted unselected datasets
1065  if (!select && !cutRange && !isWeighted()) {
1066  return numEntries() ;
1067  }
1068 
1069  // Otherwise sum the weights in the event
1070  Double_t sumw(0), carry(0);
1071  Int_t i ;
1072  for (i=0 ; i<numEntries() ; i++) {
1073  get(i) ;
1074  if (select && select->eval()==0.) continue ;
1075  if (cutRange && !_vars.allInRange(cutRange)) continue ;
1076  Double_t y = weight() - carry;
1077  Double_t t = sumw + y;
1078  carry = (t - sumw) - y;
1079  sumw = t;
1080  }
1081 
1082  if (select) delete select ;
1083 
1084  return sumw ;
1085 }
1086 
1087 
1088 
1089 
1090 ////////////////////////////////////////////////////////////////////////////////
1091 /// Return true if dataset contains weighted events
1092 
1094 {
1095  return store()->isWeighted() ;
1096 }
1097 
1098 
1099 
1100 ////////////////////////////////////////////////////////////////////////////////
1101 /// Returns true if histogram contains bins with entries with a non-integer weight
1102 
1104 {
1105  // Return false if we have no weights
1106  if (!_wgtVar) return kFALSE ;
1107 
1108  // Now examine individual weights
1109  for (int i=0 ; i<numEntries() ; i++) {
1110  get(i) ;
1111  if (fabs(weight()-Int_t(weight()))>1e-10) return kTRUE ;
1112  }
1113  // If sum of weights is less than number of events there are negative (integer) weights
1114  if (sumEntries()<numEntries()) return kTRUE ;
1115 
1116  return kFALSE ;
1117 }
1118 
1119 
1120 
1121 
1122 ////////////////////////////////////////////////////////////////////////////////
1123 /// Return a RooArgSet with the coordinates of the current event
1124 
1126 {
1127  return &_varsNoWgt ;
1128 }
1129 
1130 
1131 
1132 ////////////////////////////////////////////////////////////////////////////////
1133 /// Add a data point, with its coordinates specified in the 'data' argset, to the data set.
1134 /// Any variables present in 'data' but not in the dataset will be silently ignored.
1135 /// \param[in] data Data point.
1136 /// \param[in] wgt Event weight. Defaults to 1. The current value of the weight variable is
1137 /// ignored.
1138 /// \note To obtain weighted events, a variable must be designated `WeightVar` in the constructor.
1139 /// \param[in] wgtError Optional weight error.
1140 /// \note This requires including the weight variable in the set of `StoreError` variables when constructing
1141 /// the dataset.
1142 
1143 void RooDataSet::add(const RooArgSet& data, Double_t wgt, Double_t wgtError)
1144 {
1145  checkInit() ;
1146 
1147  const double oldW = _wgtVar ? _wgtVar->getVal() : 0.;
1148 
1149  _varsNoWgt = data;
1150 
1151  if (_wgtVar) {
1152  _wgtVar->setVal(wgt) ;
1153  if (wgtError!=0.) {
1154  _wgtVar->setError(wgtError) ;
1155  }
1156  } else if ((wgt != 1. || wgtError != 0.) && _errorMsgCount < 5) {
1157  ccoutE(DataHandling) << "An event weight/error was passed but no weight variable was defined"
1158  << " in the dataset '" << GetName() << "'. The weight will be ignored." << std::endl;
1159  ++_errorMsgCount;
1160  }
1161 
1163  && wgtError != 0.
1164  && fabs(wgt*wgt - wgtError)/wgtError > 1.E-15 //Exception for standard wgt^2 errors, which need not be stored.
1165  && _errorMsgCount < 5 && !_wgtVar->getAttribute("StoreError")) {
1166  coutE(DataHandling) << "An event weight error was passed to the RooDataSet '" << GetName()
1167  << "', but the weight variable '" << _wgtVar->GetName()
1168  << "' does not store errors. Check `StoreError` in the RooDataSet constructor." << std::endl;
1169  ++_errorMsgCount;
1170  }
1171 
1172  fill();
1173 
1174  // Restore weight state
1175  if (_wgtVar) {
1176  _wgtVar->setVal(oldW);
1177  _wgtVar->removeError();
1178  }
1179 }
1180 
1181 
1182 
1183 
1184 ////////////////////////////////////////////////////////////////////////////////
1185 /// Add a data point, with its coordinates specified in the 'data' argset, to the data set.
1186 /// Any variables present in 'data' but not in the dataset will be silently ignored.
1187 /// \param[in] data Data point.
1188 /// \param[in] wgt Event weight. The current value of the weight variable is ignored.
1189 /// \note To obtain weighted events, a variable must be designated `WeightVar` in the constructor.
1190 /// \param[in] wgtErrorLo Asymmetric weight error.
1191 /// \param[in] wgtErrorHi Asymmetric weight error.
1192 /// \note This requires including the weight variable in the set of `StoreAsymError` variables when constructing
1193 /// the dataset.
1194 
1195 void RooDataSet::add(const RooArgSet& indata, Double_t inweight, Double_t weightErrorLo, Double_t weightErrorHi)
1196 {
1197  checkInit() ;
1198 
1199  const double oldW = _wgtVar ? _wgtVar->getVal() : 0.;
1200 
1201  _varsNoWgt = indata;
1202  if (_wgtVar) {
1203  _wgtVar->setVal(inweight) ;
1204  _wgtVar->setAsymError(weightErrorLo,weightErrorHi) ;
1205  } else if (inweight != 1. && _errorMsgCount < 5) {
1206  ccoutE(DataHandling) << "An event weight was given but no weight variable was defined"
1207  << " in the dataset '" << GetName() << "'. The weight will be ignored." << std::endl;
1208  ++_errorMsgCount;
1209  }
1210 
1212  && _errorMsgCount < 5 && !_wgtVar->getAttribute("StoreAsymError")) {
1213  coutE(DataHandling) << "An event weight error was passed to the RooDataSet '" << GetName()
1214  << "', but the weight variable '" << _wgtVar->GetName()
1215  << "' does not store errors. Check `StoreAsymError` in the RooDataSet constructor." << std::endl;
1216  ++_errorMsgCount;
1217  }
1218 
1219  fill();
1220 
1221  // Restore weight state
1222  if (_wgtVar) {
1223  _wgtVar->setVal(oldW);
1225  }
1226 }
1227 
1228 
1229 
1230 
1231 
1232 ////////////////////////////////////////////////////////////////////////////////
1233 /// Add a data point, with its coordinates specified in the 'data' argset, to the data set.
1234 /// \attention The order and type of the input variables are **assumed** to be the same as
1235 /// for the RooArgSet returned by RooDataSet::get(). Input values will just be written
1236 /// into the internal data columns by ordinal position.
1237 /// \param[in] data Data point.
1238 /// \param[in] wgt Event weight. Defaults to 1. The current value of the weight variable is
1239 /// ignored.
1240 /// \note To obtain weighted events, a variable must be designated `WeightVar` in the constructor.
1241 /// \param[in] wgtError Optional weight error.
1242 /// \note This requires including the weight variable in the set of `StoreError` variables when constructing
1243 /// the dataset.
1244 
1245 void RooDataSet::addFast(const RooArgSet& data, Double_t wgt, Double_t wgtError)
1246 {
1247  checkInit() ;
1248 
1249  const double oldW = _wgtVar ? _wgtVar->getVal() : 0.;
1250 
1252  if (_wgtVar) {
1253  _wgtVar->setVal(wgt) ;
1254  if (wgtError!=0.) {
1255  _wgtVar->setError(wgtError) ;
1256  }
1257  } else if (wgt != 1. && _errorMsgCount < 5) {
1258  ccoutE(DataHandling) << "An event weight was given but no weight variable was defined"
1259  << " in the dataset '" << GetName() << "'. The weight will be ignored." << std::endl;
1260  ++_errorMsgCount;
1261  }
1262 
1263  fill();
1264 
1266  && wgtError != 0. && wgtError != wgt*wgt //Exception for standard weight error, which need not be stored
1267  && _errorMsgCount < 5 && !_wgtVar->getAttribute("StoreError")) {
1268  coutE(DataHandling) << "An event weight error was passed to the RooDataSet '" << GetName()
1269  << "', but the weight variable '" << _wgtVar->GetName()
1270  << "' does not store errors. Check `StoreError` in the RooDataSet constructor." << std::endl;
1271  ++_errorMsgCount;
1272  }
1273  if (_wgtVar && _doWeightErrorCheck) {
1274  _doWeightErrorCheck = false;
1275  }
1276 
1277  if (_wgtVar) {
1278  _wgtVar->setVal(oldW);
1279  _wgtVar->removeError();
1280  }
1281 }
1282 
1283 
1284 
1285 ////////////////////////////////////////////////////////////////////////////////
1286 
1288  RooDataSet* data4, RooDataSet* data5, RooDataSet* data6)
1289 {
1290  checkInit() ;
1291  list<RooDataSet*> dsetList ;
1292  if (data1) dsetList.push_back(data1) ;
1293  if (data2) dsetList.push_back(data2) ;
1294  if (data3) dsetList.push_back(data3) ;
1295  if (data4) dsetList.push_back(data4) ;
1296  if (data5) dsetList.push_back(data5) ;
1297  if (data6) dsetList.push_back(data6) ;
1298  return merge(dsetList) ;
1299 }
1300 
1301 
1302 
1303 ////////////////////////////////////////////////////////////////////////////////
1304 /// Merge columns of supplied data set(s) with this data set. All
1305 /// data sets must have equal number of entries. In case of
1306 /// duplicate columns the column of the last dataset in the list
1307 /// prevails
1308 
1309 Bool_t RooDataSet::merge(list<RooDataSet*>dsetList)
1310 {
1311 
1312  checkInit() ;
1313  // Sanity checks: data sets must have the same size
1314  for (list<RooDataSet*>::iterator iter = dsetList.begin() ; iter != dsetList.end() ; ++iter) {
1315  if (numEntries()!=(*iter)->numEntries()) {
1316  coutE(InputArguments) << "RooDataSet::merge(" << GetName() << ") ERROR: datasets have different size" << endl ;
1317  return kTRUE ;
1318  }
1319  }
1320 
1321  // Extend vars with elements of other dataset
1322  list<RooAbsDataStore*> dstoreList ;
1323  for (list<RooDataSet*>::iterator iter = dsetList.begin() ; iter != dsetList.end() ; ++iter) {
1324  _vars.addClone((*iter)->_vars,kTRUE) ;
1325  dstoreList.push_back((*iter)->store()) ;
1326  }
1327 
1328  // Merge data stores
1329  RooAbsDataStore* mergedStore = _dstore->merge(_vars,dstoreList) ;
1330  mergedStore->SetName(_dstore->GetName()) ;
1331  mergedStore->SetTitle(_dstore->GetTitle()) ;
1332 
1333  // Replace current data store with merged store
1334  delete _dstore ;
1335  _dstore = mergedStore ;
1336 
1338  return kFALSE ;
1339 }
1340 
1341 
1342 ////////////////////////////////////////////////////////////////////////////////
1343 /// Add all data points of given data set to this data set.
1344 /// Observable in 'data' that are not in this dataset
1345 /// with not be transferred
1346 
1348 {
1349  checkInit() ;
1350  _dstore->append(*data._dstore) ;
1351 }
1352 
1353 
1354 
1355 ////////////////////////////////////////////////////////////////////////////////
1356 /// Add a column with the values of the given (function) argument
1357 /// to this dataset. The function value is calculated for each
1358 /// event using the observable values of each event in case the
1359 /// function depends on variables with names that are identical
1360 /// to the observable names in the dataset
1361 
1363 {
1364  checkInit() ;
1365  RooAbsArg* ret = _dstore->addColumn(var,adjustRange) ;
1366  _vars.addOwned(*ret) ;
1368  return ret ;
1369 }
1370 
1371 
1372 ////////////////////////////////////////////////////////////////////////////////
1373 /// Add a column with the values of the given list of (function)
1374 /// argument to this dataset. Each function value is calculated for
1375 /// each event using the observable values of the event in case the
1376 /// function depends on variables with names that are identical to
1377 /// the observable names in the dataset
1378 
1380 {
1381  checkInit() ;
1382  RooArgSet* ret = _dstore->addColumns(varList) ;
1383  _vars.addOwned(*ret) ;
1385  return ret ;
1386 }
1387 
1388 
1389 
1390 ////////////////////////////////////////////////////////////////////////////////
1391 /// Create a TH2F histogram of the distribution of the specified variable
1392 /// using this dataset. Apply any cuts to select which events are used.
1393 /// The variable being plotted can either be contained directly in this
1394 /// dataset, or else be a function of the variables in this dataset.
1395 /// The histogram will be created using RooAbsReal::createHistogram() with
1396 /// the name provided (with our dataset name prepended).
1397 
1398 TH2F* RooDataSet::createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, const char* cuts, const char *name) const
1399 {
1400  checkInit() ;
1401  return createHistogram(var1, var2, var1.getBins(), var2.getBins(), cuts, name);
1402 }
1403 
1404 
1405 
1406 ////////////////////////////////////////////////////////////////////////////////
1407 /// Create a TH2F histogram of the distribution of the specified variable
1408 /// using this dataset. Apply any cuts to select which events are used.
1409 /// The variable being plotted can either be contained directly in this
1410 /// dataset, or else be a function of the variables in this dataset.
1411 /// The histogram will be created using RooAbsReal::createHistogram() with
1412 /// the name provided (with our dataset name prepended).
1413 
1415  Int_t nx, Int_t ny, const char* cuts, const char *name) const
1416 {
1417  checkInit() ;
1418  static Int_t counter(0) ;
1419 
1420  Bool_t ownPlotVarX(kFALSE) ;
1421  // Is this variable in our dataset?
1422  RooAbsReal* plotVarX= (RooAbsReal*)_vars.find(var1.GetName());
1423  if(0 == plotVarX) {
1424  // Is this variable a client of our dataset?
1425  if (!var1.dependsOn(_vars)) {
1426  coutE(InputArguments) << GetName() << "::createHistogram: Argument " << var1.GetName()
1427  << " is not in dataset and is also not dependent on data set" << endl ;
1428  return 0 ;
1429  }
1430 
1431  // Clone derived variable
1432  plotVarX = (RooAbsReal*) var1.Clone() ;
1433  ownPlotVarX = kTRUE ;
1434 
1435  //Redirect servers of derived clone to internal ArgSet representing the data in this set
1436  plotVarX->redirectServers(const_cast<RooArgSet&>(_vars)) ;
1437  }
1438 
1439  Bool_t ownPlotVarY(kFALSE) ;
1440  // Is this variable in our dataset?
1441  RooAbsReal* plotVarY= (RooAbsReal*)_vars.find(var2.GetName());
1442  if(0 == plotVarY) {
1443  // Is this variable a client of our dataset?
1444  if (!var2.dependsOn(_vars)) {
1445  coutE(InputArguments) << GetName() << "::createHistogram: Argument " << var2.GetName()
1446  << " is not in dataset and is also not dependent on data set" << endl ;
1447  return 0 ;
1448  }
1449 
1450  // Clone derived variable
1451  plotVarY = (RooAbsReal*) var2.Clone() ;
1452  ownPlotVarY = kTRUE ;
1453 
1454  //Redirect servers of derived clone to internal ArgSet representing the data in this set
1455  plotVarY->redirectServers(const_cast<RooArgSet&>(_vars)) ;
1456  }
1457 
1458  // Create selection formula if selection cuts are specified
1459  RooFormula* select = 0;
1460  if(0 != cuts && strlen(cuts)) {
1461  select=new RooFormula(cuts,cuts,_vars);
1462  if (!select || !select->ok()) {
1463  delete select;
1464  return 0 ;
1465  }
1466  }
1467 
1468  TString histName(name);
1469  histName.Prepend("_");
1470  histName.Prepend(fName);
1471  histName.Append("_") ;
1472  histName.Append(Form("%08x",counter++)) ;
1473 
1474  // create the histogram
1475  TH2F* histogram=new TH2F(histName.Data(), "Events", nx, var1.getMin(), var1.getMax(),
1476  ny, var2.getMin(), var2.getMax());
1477  if(!histogram) {
1478  coutE(DataHandling) << fName << "::createHistogram: unable to create a new histogram" << endl;
1479  return 0;
1480  }
1481 
1482  // Dump contents
1483  Int_t nevent= numEntries() ;
1484  for(Int_t i=0; i < nevent; ++i)
1485  {
1486  get(i);
1487 
1488  if (select && select->eval()==0) continue ;
1489  histogram->Fill(plotVarX->getVal(), plotVarY->getVal(),weight()) ;
1490  }
1491 
1492  if (ownPlotVarX) delete plotVarX ;
1493  if (ownPlotVarY) delete plotVarY ;
1494  if (select) delete select ;
1495 
1496  return histogram ;
1497 }
1498 
1499 
1500 
1501 
1502 
1503 ////////////////////////////////////////////////////////////////////////////////
1504 /// Special plot method for 'X-Y' datasets used in \f$ \chi^2 \f$ fitting. These datasets
1505 /// have one observable (X) and have weights (Y) and associated errors.
1506 /// <table>
1507 /// <tr><th> Contents options <th> Effect
1508 /// <tr><td> YVar(RooRealVar& var) <td> Designate specified observable as 'y' variable
1509 /// If not specified, the event weight will be the y variable
1510 /// <tr><th> Histogram drawing options <th> Effect
1511 /// <tr><td> DrawOption(const char* opt) <td> Select ROOT draw option for resulting TGraph object
1512 /// <tr><td> LineStyle(Int_t style) <td> Select line style by ROOT line style code, default is solid
1513 /// <tr><td> LineColor(Int_t color) <td> Select line color by ROOT color code, default is black
1514 /// <tr><td> LineWidth(Int_t width) <td> Select line with in pixels, default is 3
1515 /// <tr><td> MarkerStyle(Int_t style) <td> Select the ROOT marker style, default is 21
1516 /// <tr><td> MarkerColor(Int_t color) <td> Select the ROOT marker color, default is black
1517 /// <tr><td> MarkerSize(Double_t size) <td> Select the ROOT marker size
1518 /// <tr><td> Rescale(Double_t factor) <td> Apply global rescaling factor to histogram
1519 /// <tr><th> Misc. other options <th> Effect
1520 /// <tr><td> Name(const chat* name) <td> Give curve specified name in frame. Useful if curve is to be referenced later
1521 /// <tr><td> Invisible(Bool_t flag) <td> Add curve to frame, but do not display. Useful in combination AddTo()
1522 /// </table>
1523 
1524 RooPlot* RooDataSet::plotOnXY(RooPlot* frame, const RooCmdArg& arg1, const RooCmdArg& arg2,
1525  const RooCmdArg& arg3, const RooCmdArg& arg4,
1526  const RooCmdArg& arg5, const RooCmdArg& arg6,
1527  const RooCmdArg& arg7, const RooCmdArg& arg8) const
1528 {
1529  checkInit() ;
1530 
1531  RooLinkedList argList ;
1532  argList.Add((TObject*)&arg1) ; argList.Add((TObject*)&arg2) ;
1533  argList.Add((TObject*)&arg3) ; argList.Add((TObject*)&arg4) ;
1534  argList.Add((TObject*)&arg5) ; argList.Add((TObject*)&arg6) ;
1535  argList.Add((TObject*)&arg7) ; argList.Add((TObject*)&arg8) ;
1536 
1537  // Process named arguments
1538  RooCmdConfig pc(Form("RooDataSet::plotOnXY(%s)",GetName())) ;
1539  pc.defineString("drawOption","DrawOption",0,"P") ;
1540  pc.defineString("histName","Name",0,"") ;
1541  pc.defineInt("lineColor","LineColor",0,-999) ;
1542  pc.defineInt("lineStyle","LineStyle",0,-999) ;
1543  pc.defineInt("lineWidth","LineWidth",0,-999) ;
1544  pc.defineInt("markerColor","MarkerColor",0,-999) ;
1545  pc.defineInt("markerStyle","MarkerStyle",0,8) ;
1546  pc.defineDouble("markerSize","MarkerSize",0,-999) ;
1547  pc.defineInt("fillColor","FillColor",0,-999) ;
1548  pc.defineInt("fillStyle","FillStyle",0,-999) ;
1549  pc.defineInt("histInvisible","Invisible",0,0) ;
1550  pc.defineDouble("scaleFactor","Rescale",0,1.) ;
1551  pc.defineObject("xvar","XVar",0,0) ;
1552  pc.defineObject("yvar","YVar",0,0) ;
1553 
1554 
1555  // Process & check varargs
1556  pc.process(argList) ;
1557  if (!pc.ok(kTRUE)) {
1558  return frame ;
1559  }
1560 
1561  // Extract values from named arguments
1562  const char* drawOptions = pc.getString("drawOption") ;
1563  Int_t histInvisible = pc.getInt("histInvisible") ;
1564  const char* histName = pc.getString("histName",0,kTRUE) ;
1565  Double_t scaleFactor = pc.getDouble("scaleFactor") ;
1566 
1567  RooRealVar* xvar = (RooRealVar*) _vars.find(frame->getPlotVar()->GetName()) ;
1568 
1569  // Determine Y variable (default is weight, if present)
1570  RooRealVar* yvar = (RooRealVar*)(pc.getObject("yvar")) ;
1571 
1572  // Sanity check. XY plotting only applies to weighted datasets if no YVar is specified
1573  if (!_wgtVar && !yvar) {
1574  coutE(InputArguments) << "RooDataSet::plotOnXY(" << GetName() << ") ERROR: no YVar() argument specified and dataset is not weighted" << endl ;
1575  return 0 ;
1576  }
1577 
1578  RooRealVar* dataY = yvar ? (RooRealVar*) _vars.find(yvar->GetName()) : 0 ;
1579  if (yvar && !dataY) {
1580  coutE(InputArguments) << "RooDataSet::plotOnXY(" << GetName() << ") ERROR on YVar() argument, dataset does not contain a variable named " << yvar->GetName() << endl ;
1581  return 0 ;
1582  }
1583 
1584 
1585  // Make RooHist representing XY contents of data
1586  RooHist* graph = new RooHist ;
1587  if (histName) {
1588  graph->SetName(histName) ;
1589  } else {
1590  graph->SetName(Form("hxy_%s",GetName())) ;
1591  }
1592 
1593  for (int i=0 ; i<numEntries() ; i++) {
1594  get(i) ;
1595  Double_t x = xvar->getVal() ;
1596  Double_t exlo = xvar->getErrorLo() ;
1597  Double_t exhi = xvar->getErrorHi() ;
1598  Double_t y,eylo,eyhi ;
1599  if (!dataY) {
1600  y = weight() ;
1601  weightError(eylo,eyhi) ;
1602  } else {
1603  y = dataY->getVal() ;
1604  eylo = dataY->getErrorLo() ;
1605  eyhi = dataY->getErrorHi() ;
1606  }
1607  graph->addBinWithXYError(x,y,-1*exlo,exhi,-1*eylo,eyhi,scaleFactor) ;
1608  }
1609 
1610  // Adjust style options according to named arguments
1611  Int_t lineColor = pc.getInt("lineColor") ;
1612  Int_t lineStyle = pc.getInt("lineStyle") ;
1613  Int_t lineWidth = pc.getInt("lineWidth") ;
1614  Int_t markerColor = pc.getInt("markerColor") ;
1615  Int_t markerStyle = pc.getInt("markerStyle") ;
1616  Size_t markerSize = pc.getDouble("markerSize") ;
1617  Int_t fillColor = pc.getInt("fillColor") ;
1618  Int_t fillStyle = pc.getInt("fillStyle") ;
1619 
1620  if (lineColor!=-999) graph->SetLineColor(lineColor) ;
1621  if (lineStyle!=-999) graph->SetLineStyle(lineStyle) ;
1622  if (lineWidth!=-999) graph->SetLineWidth(lineWidth) ;
1623  if (markerColor!=-999) graph->SetMarkerColor(markerColor) ;
1624  if (markerStyle!=-999) graph->SetMarkerStyle(markerStyle) ;
1625  if (markerSize!=-999) graph->SetMarkerSize(markerSize) ;
1626  if (fillColor!=-999) graph->SetFillColor(fillColor) ;
1627  if (fillStyle!=-999) graph->SetFillStyle(fillStyle) ;
1628 
1629  // Add graph to frame
1630  frame->addPlotable(graph,drawOptions,histInvisible) ;
1631 
1632  return frame ;
1633 }
1634 
1635 
1636 
1637 
1638 ////////////////////////////////////////////////////////////////////////////////
1639 /// Read given list of ascii files, and construct a data set, using the given
1640 /// ArgList as structure definition.
1641 /// \param fileList Multiple file names, comma separated. Each
1642 /// file is optionally prefixed with 'commonPath' if such a path is
1643 /// provided
1644 ///
1645 /// \param varList Specify the dimensions of the dataset to be built.
1646 /// This list describes the order in which these dimensions appear in the
1647 /// ascii files to be read.
1648 /// Each line in the ascii file should contain N white-space separated
1649 /// tokens, with N the number of args in `varList`. Any text beyond
1650 /// N tokens will be ignored with a warning message.
1651 /// (NB: This is the default output of RooArgList::writeToStream())
1652 ///
1653 /// \param verbOpt `Q` be quiet, `D` debug mode (verbose)
1654 ///
1655 /// \param commonPath All filenames in `fileList` will be prefixed with this optional path.
1656 ///
1657 /// \param indexCatName Interpret the data as belonging to category `indexCatName`.
1658 /// When multiple files are read, a RooCategory arg in `varList` can
1659 /// optionally be designated to hold information about the source file
1660 /// of each data point. This feature is enabled by giving the name
1661 /// of the (already existing) category variable in `indexCatName`.
1662 ///
1663 /// \attention If the value of any of the variables on a given line exceeds the
1664 /// fit range associated with that dimension, the entire line will be
1665 /// ignored. A warning message is printed in each case, unless the
1666 /// `Q` verbose option is given. The number of events read and skipped
1667 /// is always summarized at the end.
1668 ///
1669 /// If no further information is given a label name 'fileNNN' will
1670 /// be assigned to each event, where NNN is the sequential number of
1671 /// the source file in `fileList`.
1672 ///
1673 /// Alternatively, it is possible to override the default label names
1674 /// of the index category by specifying them in the fileList string:
1675 /// When instead of `file1.txt,file2.txt` the string
1676 /// `file1.txt:FOO,file2.txt:BAR` is specified, a state named "FOO"
1677 /// is assigned to the index category for each event originating from
1678 /// file1.txt. The labels FOO,BAR may be predefined in the index
1679 /// category via defineType(), but don't have to be.
1680 ///
1681 /// Finally, one can also assign the same label to multiple files,
1682 /// either by specifying `file1.txt:FOO,file2,txt:FOO,file3.txt:BAR`
1683 /// or `file1.txt,file2.txt:FOO,file3.txt:BAR`.
1684 ///
1685 
1686 RooDataSet *RooDataSet::read(const char *fileList, const RooArgList &varList,
1687  const char *verbOpt, const char* commonPath,
1688  const char* indexCatName) {
1689  // Make working copy of variables list
1690  RooArgList variables(varList) ;
1691 
1692  // Append blinding state category to variable list if not already there
1693  Bool_t ownIsBlind(kTRUE) ;
1694  RooAbsArg* blindState = variables.find("blindState") ;
1695  if (!blindState) {
1696  blindState = new RooCategory("blindState","Blinding State") ;
1697  variables.add(*blindState) ;
1698  } else {
1699  ownIsBlind = kFALSE ;
1700  if (blindState->IsA()!=RooCategory::Class()) {
1701  oocoutE((TObject*)0,DataHandling) << "RooDataSet::read: ERROR: variable list already contains"
1702  << "a non-RooCategory blindState member" << endl ;
1703  return 0 ;
1704  }
1705  oocoutW((TObject*)0,DataHandling) << "RooDataSet::read: WARNING: recycling existing "
1706  << "blindState category in variable list" << endl ;
1707  }
1708  RooCategory* blindCat = (RooCategory*) blindState ;
1709 
1710  // Configure blinding state category
1711  blindCat->setAttribute("Dynamic") ;
1712  blindCat->defineType("Normal",0) ;
1713  blindCat->defineType("Blind",1) ;
1714 
1715  // parse the option string
1716  TString opts= verbOpt;
1717  opts.ToLower();
1718  Bool_t verbose= !opts.Contains("q");
1719  Bool_t debug= opts.Contains("d");
1720 
1721  auto data = std::make_unique<RooDataSet>("dataset", fileList, variables);
1722  if (ownIsBlind) { variables.remove(*blindState) ; delete blindState ; }
1723  if(!data) {
1724  oocoutE((TObject*)0,DataHandling) << "RooDataSet::read: unable to create a new dataset"
1725  << endl;
1726  return nullptr;
1727  }
1728 
1729  // Redirect blindCat to point to the copy stored in the data set
1730  blindCat = (RooCategory*) data->_vars.find("blindState") ;
1731 
1732  // Find index category, if requested
1733  RooCategory *indexCat = 0;
1734  //RooCategory *indexCatOrig = 0;
1735  if (indexCatName) {
1736  RooAbsArg* tmp = 0;
1737  tmp = data->_vars.find(indexCatName) ;
1738  if (!tmp) {
1739  oocoutE(data.get(),DataHandling) << "RooDataSet::read: no index category named "
1740  << indexCatName << " in supplied variable list" << endl ;
1741  return nullptr;
1742  }
1743  if (tmp->IsA()!=RooCategory::Class()) {
1744  oocoutE(data.get(),DataHandling) << "RooDataSet::read: variable " << indexCatName
1745  << " is not a RooCategory" << endl ;
1746  return nullptr;
1747  }
1748  indexCat = (RooCategory*)tmp ;
1749 
1750  // Prevent RooArgSet from attempting to read in indexCat
1751  indexCat->setAttribute("Dynamic") ;
1752  }
1753 
1754 
1755  Int_t outOfRange(0) ;
1756 
1757  // Loop over all names in comma separated list
1758  Int_t fileSeqNum(0);
1759  for (const auto& filename : RooHelpers::tokenise(std::string(fileList), ", ")) {
1760  // Determine index category number, if this option is active
1761  if (indexCat) {
1762 
1763  // Find and detach optional file category name
1764  const char *catname = strchr(filename.c_str(),':');
1765 
1766  if (catname) {
1767  // Use user category name if provided
1768  catname++ ;
1769 
1770  if (indexCat->hasLabel(catname)) {
1771  // Use existing category index
1772  indexCat->setLabel(catname);
1773  } else {
1774  // Register cat name
1775  indexCat->defineType(catname,fileSeqNum) ;
1776  indexCat->setIndex(fileSeqNum) ;
1777  }
1778  } else {
1779  // Assign autogenerated name
1780  char newLabel[128] ;
1781  snprintf(newLabel,128,"file%03d",fileSeqNum) ;
1782  if (indexCat->defineType(newLabel,fileSeqNum)) {
1783  oocoutE(data.get(), DataHandling) << "RooDataSet::read: Error, cannot register automatic type name " << newLabel
1784  << " in index category " << indexCat->GetName() << endl ;
1785  return 0 ;
1786  }
1787  // Assign new category number
1788  indexCat->setIndex(fileSeqNum) ;
1789  }
1790  }
1791 
1792  oocoutI(data.get(), DataHandling) << "RooDataSet::read: reading file " << filename << endl ;
1793 
1794  // Prefix common path
1795  TString fullName(commonPath) ;
1796  fullName.Append(filename) ;
1797  ifstream file(fullName) ;
1798 
1799  if (!file.good()) {
1800  oocoutE(data.get(), DataHandling) << "RooDataSet::read: unable to open '"
1801  << filename << "'. Returning nullptr now." << endl;
1802  return nullptr;
1803  }
1804 
1805 // Double_t value;
1806  Int_t line(0) ;
1807  Bool_t haveBlindString(false) ;
1808 
1809  while(file.good() && !file.eof()) {
1810  line++;
1811  if(debug) oocxcoutD(data.get(),DataHandling) << "reading line " << line << endl;
1812 
1813  // process comment lines
1814  if (file.peek() == '#')
1815  {
1816  if(debug) oocxcoutD(data.get(),DataHandling) << "skipping comment on line " << line << endl;
1817  }
1818  else {
1819 
1820  // Skip empty lines
1821  // if(file.peek() == '\n') { file.get(); }
1822 
1823  // Read single line
1824  Bool_t readError = variables.readFromStream(file,kTRUE,verbose) ;
1825  data->_vars = variables ;
1826 // Bool_t readError = data->_vars.readFromStream(file,kTRUE,verbose) ;
1827 
1828  // Stop at end of file or on read error
1829  if(file.eof()) break ;
1830  if(!file.good()) {
1831  oocoutE(data.get(), DataHandling) << "RooDataSet::read(static): read error at line " << line << endl ;
1832  break;
1833  }
1834 
1835  if (readError) {
1836  outOfRange++ ;
1837  continue ;
1838  }
1839  blindCat->setIndex(haveBlindString) ;
1840  data->fill(); // store this event
1841  }
1842  }
1843 
1844  file.close();
1845 
1846  // get next file name
1847  fileSeqNum++ ;
1848  }
1849 
1850  if (indexCat) {
1851  // Copy dynamically defined types from new data set to indexCat in original list
1852  assert(dynamic_cast<RooCategory*>(variables.find(indexCatName)));
1853  const auto origIndexCat = static_cast<RooCategory*>(variables.find(indexCatName));
1854  for (const auto& nameIdx : *indexCat) {
1855  origIndexCat->defineType(nameIdx.first, nameIdx.second);
1856  }
1857  }
1858  oocoutI(data.get(),DataHandling) << "RooDataSet::read: read " << data->numEntries()
1859  << " events (ignored " << outOfRange << " out of range events)" << endl;
1860 
1861  return data.release();
1862 }
1863 
1864 
1865 
1866 
1867 ////////////////////////////////////////////////////////////////////////////////
1868 /// Write the contents of this dataset to an ASCII file with the specified name.
1869 /// Each event will be written as a single line containing the written values
1870 /// of each observable in the order they were declared in the dataset and
1871 /// separated by whitespaces
1872 
1873 Bool_t RooDataSet::write(const char* filename) const
1874 {
1875  // Open file for writing
1876  ofstream ofs(filename) ;
1877  if (ofs.fail()) {
1878  coutE(DataHandling) << "RooDataSet::write(" << GetName() << ") cannot create file " << filename << endl ;
1879  return kTRUE ;
1880  }
1881 
1882  // Write all lines as arglist in compact mode
1883  coutI(DataHandling) << "RooDataSet::write(" << GetName() << ") writing ASCII file " << filename << endl ;
1884  return write(ofs);
1885 }
1886 
1887 ////////////////////////////////////////////////////////////////////////////////
1888 /// Write the contents of this dataset to the stream.
1889 /// Each event will be written as a single line containing the written values
1890 /// of each observable in the order they were declared in the dataset and
1891 /// separated by whitespaces
1892 
1893 Bool_t RooDataSet::write(ostream & ofs) const {
1894  checkInit();
1895 
1896  for (Int_t i=0; i<numEntries(); ++i) {
1897  get(i)->writeToStream(ofs,kTRUE);
1898  }
1899 
1900  if (ofs.fail()) {
1901  coutW(DataHandling) << "RooDataSet::write(" << GetName() << "): WARNING error(s) have occured in writing" << endl ;
1902  }
1903 
1904  return ofs.fail() ;
1905 }
1906 
1907 
1908 ////////////////////////////////////////////////////////////////////////////////
1909 /// Print info about this dataset to the specified output stream.
1910 ///
1911 /// Standard: number of entries
1912 /// Shape: list of variables we define & were generated with
1913 
1914 void RooDataSet::printMultiline(ostream& os, Int_t contents, Bool_t verbose, TString indent) const
1915 {
1916  checkInit() ;
1918  if (_wgtVar) {
1919  os << indent << " Dataset variable \"" << _wgtVar->GetName() << "\" is interpreted as the event weight" << endl ;
1920  }
1921 }
1922 
1923 
1924 ////////////////////////////////////////////////////////////////////////////////
1925 /// Print value of the dataset, i.e. the sum of weights contained in the dataset
1926 
1927 void RooDataSet::printValue(ostream& os) const
1928 {
1929  os << numEntries() << " entries" ;
1930  if (isWeighted()) {
1931  os << " (" << sumEntries() << " weighted)" ;
1932  }
1933 }
1934 
1935 
1936 
1937 ////////////////////////////////////////////////////////////////////////////////
1938 /// Print argument of dataset, i.e. the observable names
1939 
1940 void RooDataSet::printArgs(ostream& os) const
1941 {
1942  os << "[" ;
1943  TIterator* iter = _varsNoWgt.createIterator() ;
1944  RooAbsArg* arg ;
1945  Bool_t first(kTRUE) ;
1946  while((arg=(RooAbsArg*)iter->Next())) {
1947  if (first) {
1948  first=kFALSE ;
1949  } else {
1950  os << "," ;
1951  }
1952  os << arg->GetName() ;
1953  }
1954  if (_wgtVar) {
1955  os << ",weight:" << _wgtVar->GetName() ;
1956  }
1957  os << "]" ;
1958  delete iter ;
1959 }
1960 
1961 
1962 
1963 ////////////////////////////////////////////////////////////////////////////////
1964 /// Change the name of this dataset into the given name
1965 
1966 void RooDataSet::SetName(const char *name)
1967 {
1968  if (_dir) _dir->GetList()->Remove(this);
1970  if (_dir) _dir->GetList()->Add(this);
1971 }
1972 
1973 
1974 ////////////////////////////////////////////////////////////////////////////////
1975 /// Change the title of this dataset into the given name
1976 
1977 void RooDataSet::SetNameTitle(const char *name, const char* title)
1978 {
1979  if (_dir) _dir->GetList()->Remove(this);
1980  TNamed::SetNameTitle(name,title) ;
1981  if (_dir) _dir->GetList()->Add(this);
1982 }
1983 
1984 
1985 ////////////////////////////////////////////////////////////////////////////////
1986 /// Stream an object of class RooDataSet.
1987 
1988 void RooDataSet::Streamer(TBuffer &R__b)
1989 {
1990  if (R__b.IsReading()) {
1991 
1992  UInt_t R__s, R__c;
1993  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1994 
1995  if (R__v>1) {
1996 
1997  // Use new-style streaming for version >1
1998  R__b.ReadClassBuffer(RooDataSet::Class(),this,R__v,R__s,R__c);
1999 
2000  } else {
2001 
2002  // Legacy dataset conversion happens here. Legacy RooDataSet inherits from RooTreeData
2003  // which in turn inherits from RooAbsData. Manually stream RooTreeData contents on
2004  // file here and convert it into a RooTreeDataStore which is installed in the
2005  // new-style RooAbsData base class
2006 
2007  // --- This is the contents of the streamer code of RooTreeData version 1 ---
2008  UInt_t R__s1, R__c1;
2009  Version_t R__v1 = R__b.ReadVersion(&R__s1, &R__c1); if (R__v1) { }
2010 
2011  RooAbsData::Streamer(R__b);
2012  TTree* X_tree(0) ; R__b >> X_tree;
2013  RooArgSet X_truth ; X_truth.Streamer(R__b);
2014  TString X_blindString ; X_blindString.Streamer(R__b);
2015  R__b.CheckByteCount(R__s1, R__c1, TClass::GetClass("RooTreeData"));
2016  // --- End of RooTreeData-v1 streamer
2017 
2018  // Construct RooTreeDataStore from X_tree and complete initialization of new-style RooAbsData
2019  _dstore = new RooTreeDataStore(X_tree,_vars) ;
2020  _dstore->SetName(GetName()) ;
2021  _dstore->SetTitle(GetTitle()) ;
2022  _dstore->checkInit() ;
2023 
2024  // This is the contents of the streamer code of RooDataSet version 1
2025  RooDirItem::Streamer(R__b);
2026  _varsNoWgt.Streamer(R__b);
2027  R__b >> _wgtVar;
2028  R__b.CheckByteCount(R__s, R__c, RooDataSet::IsA());
2029 
2030 
2031  }
2032  } else {
2033  R__b.WriteClassBuffer(RooDataSet::Class(),this);
2034  }
2035 }
2036 
2037 
2038 
2039 ////////////////////////////////////////////////////////////////////////////////
2040 /// Convert vector-based storage to tree-based storage. This implementation overrides the base class
2041 /// implementation because the latter doesn't transfer weights.
2043 {
2044  if (storageType != RooAbsData::Tree) {
2045  RooTreeDataStore *newStore = new RooTreeDataStore(GetName(), GetTitle(), _vars, *_dstore, nullptr, _wgtVar ? _wgtVar->GetName() : nullptr);
2046  delete _dstore;
2047  _dstore = newStore;
2049  }
2050 }
2051 
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:257
StorageType storageType
Definition: RooAbsData.h:240
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
bool hasLabel(const std::string &label) const
Check if a state with name label exists.
Bool_t IsReading() const
Definition: TBuffer.h:85
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
#define coutE(a)
Definition: RooMsgService.h:33
A simple container to hold a batch of data values.
Definition: RooSpan.h:32
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const override
Print info about this dataset to the specified output stream.
void addOwnedComponent(const char *idxlabel, RooAbsData &data)
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
virtual Bool_t isNonPoissonWeighted() const override
Returns true if histogram contains bins with entries with a non-integer weight.
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
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
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3942
Bool_t dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=0, Bool_t valueOnly=kFALSE) const
Test whether we depend on (ie, are served by) any object in the specified collection.
Definition: RooAbsArg.cxx:730
bool _doWeightErrorCheck
Counter to silence error messages when filling dataset.
Definition: RooDataSet.h:170
virtual Double_t weight() const =0
short Version_t
Definition: RtypesCore.h:63
TLine * line
virtual RooArgSet * addColumns(const RooArgList &varList)
Add a column with the values of the given list of (function) argument to this dataset.
virtual const RooArgSet * get() const
Definition: RooAbsData.h:87
float Size_t
Definition: RtypesCore.h:85
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 &#39;t&#39; into this data collection, optionally selecting events using the RooFormula...
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
#define coutI(a)
Definition: RooMsgService.h:30
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
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+size).
static MemPool * memPool()
virtual RooArgSet * addColumns(const RooArgList &varList)=0
virtual const RooArgSet * get() const override
Return a RooArgSet with the coordinates of the current event.
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
RooArgSet _varsNoWgt
Definition: RooDataSet.h:161
Memory pool for RooArgSet and RooDataSet.
Definition: RooArgSet.h:26
#define oocoutI(o, a)
Definition: RooMsgService.h:45
RooAbsArg * createFundamental(const char *newname=0) const
Create a RooRealVar fundamental object with our properties.
void addPlotable(RooPlotable *plotable, Option_t *drawOptions="", Bool_t invisible=kFALSE, Bool_t refreshNorm=kFALSE)
Add the specified plotable object to our plot.
Definition: RooPlot.cxx:591
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:53
virtual RooAbsData * emptyClone(const char *newName=0, const char *newTitle=0, const RooArgSet *vars=0, const char *wgtVarName=0) const override
Return an empty clone of this dataset.
Definition: RooDataSet.cxx:860
virtual Double_t sumEntries() const
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Double_t sumEntries() const override
RooDataSet()
Default constructor for persistence.
Definition: RooDataSet.cxx:152
Basic string class.
Definition: TString.h:131
virtual RooPlot * plotOnXY(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Special plot method for &#39;X-Y&#39; datasets used in fitting.
virtual Bool_t setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
#define f(i)
Definition: RSha256.hxx:104
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
int Int_t
Definition: RtypesCore.h:43
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:85
static RooDataSet * read(const char *filename, const RooArgList &variables, const char *opts="", const char *commonPath="", const char *indexCatName=0)
Read given list of ascii files, and construct a data set, using the given ArgList as structure defini...
STL namespace.
#define coutW(a)
Definition: RooMsgService.h:32
RooTreeDataStore is a TTree-backed data storage.
TString & Prepend(const char *cs)
Definition: TString.h:656
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition: TNamed.cxx:154
Iterator abstract base class.
Definition: TIterator.h:30
void attachToStore(RooAbsDataStore &store)
Attach this argument to the data store such that it reads data from there.
Definition: RooAbsArg.cxx:2155
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
virtual Bool_t isWeighted() const override
Return true if dataset contains weighted events.
virtual void weightError(Double_t &lo, Double_t &hi, ErrorType etype=SumW2) const override
Return asymmetric error on weight. (Dummy implementation returning zero)
Definition: RooDataSet.cxx:998
void appendToDir(TObject *obj, Bool_t forceMemoryResident=kFALSE)
Append object to directory.
Definition: RooDirItem.cxx:57
Double_t getErrorLo() const
Definition: RooRealVar.h:71
const RooArgSet & cachedVars() const
A RooHist is a graphical representation of binned data based on the TGraphAsymmErrors class...
Definition: RooHist.h:27
#define TRACE_CREATE
Definition: RooTrace.h:22
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
Double_t x[n]
Definition: legend1.C:17
virtual Double_t weightSquared() const override
Return squared event weight of current event.
Definition: RooDataSet.cxx:983
RooDataHist * binnedClone(const char *newName=0, const char *newTitle=0) const
Return binned clone of this dataset.
Definition: RooDataSet.cxx:951
virtual void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)
Internal method – Attach dataset copied with cache contents to copied instances of functions...
Definition: RooAbsData.cxx:346
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a column with the values of the given (function) argument to this dataset.
void Class()
Definition: Class.C:29
RooAbsData * reduceEng(const RooArgSet &varSubset, const RooFormulaVar *cutVar, const char *cutRange=0, std::size_t nStart=0, std::size_t nStop=std::numeric_limits< std::size_t >::max(), Bool_t copyCache=kTRUE) override
Implementation of RooAbsData virtual method that drives the RooAbsData::reduce() methods.
Definition: RooDataSet.cxx:914
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
Bool_t allInRange(const char *rangeSpec) const
Return true if all contained object report to have their value inside the specified range...
#define oocoutE(o, a)
Definition: RooMsgService.h:48
RooVectorDataStore is the abstract base class for data collection that use a TTree as internal storag...
#define oocxcoutD(o, a)
Definition: RooMsgService.h:83
TString & Append(const char *cs)
Definition: TString.h:559
virtual void append(RooAbsDataStore &other)=0
void setAsymError(Double_t lo, Double_t hi)
Definition: RooRealVar.h:70
virtual RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len) const override
Return event weights of all events in range [first, first+len).
Definition: RooDataSet.cxx:991
virtual const char * getCurrentLabel() const
Return label string of current state.
void assignFast(const RooAbsCollection &other, Bool_t setValDirty=kTRUE)
Functional equivalent of operator=() but assumes this and other collection have same layout...
virtual TList * GetList() const
Definition: TDirectory.h:165
virtual Bool_t isWeighted() const =0
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
Definition: TString.cxx:1474
RooCompositeDataStore combines several disjunct datasets into one.
virtual RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore *> dstoreList)=0
RooFormula internally uses ROOT&#39;s TFormula to compute user-defined expressions of RooAbsArgs...
Definition: RooFormula.h:28
Double_t eval(const RooArgSet *nset=0) const
Evalute all parameters/observables, and then evaluate formula.
Definition: RooFormula.cxx:340
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
virtual void addClone(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:96
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Interface for detailed printing of object.
Definition: RooAbsData.cxx:801
virtual void setVal(Double_t value)
Set value of variable to &#39;value&#39;.
Definition: RooRealVar.cxx:225
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
bool defineType(const std::string &label)
Define a state with given name.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
virtual void checkInit() const
#define ccoutE(a)
Definition: RooMsgService.h:41
RooArgSet _cachedVars
Definition: RooAbsData.h:274
void setAttribAll(const Text_t *name, Bool_t value=kTRUE)
Set given attribute in each element of the collection by calling each elements setAttribute() functio...
virtual Double_t weight() const override
Return event weight of current event.
Definition: RooDataSet.cxx:973
static constexpr double pc
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:821
TH2F * createHistogram(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2, const char *cuts="", const char *name="hist") const
Create a TH2F histogram of the distribution of the specified variable using this dataset.
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:90
void initialize(const char *wgtVarName)
Initialize the dataset.
Definition: RooDataSet.cxx:889
unsigned int UInt_t
Definition: RtypesCore.h:44
char * Form(const char *fmt,...)
virtual RooAbsData * cacheClone(const RooAbsArg *newCacheOwner, const RooArgSet *newCacheVars, const char *newName=0) override
Return a clone of this dataset containing only the cached variables.
Definition: RooDataSet.cxx:842
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
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
Definition: RooCmdConfig.h:27
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:44
virtual void fill()
Definition: RooAbsData.cxx:299
static void indent(ostringstream &buf, int indent_level)
RooAbsDataStore * store()
Definition: RooAbsData.h:63
Bool_t write(const char *filename) const
Write the contents of this dataset to an ASCII file with the specified name.
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
Definition: RooDirItem.cxx:44
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
TString fName
Definition: TNamed.h:32
Definition: graph.py:1
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:23
MemPoolForRooSets< RooDataSet, 5 *150 > MemPool
Definition: RooDataSet.h:166
constexpr Double_t E()
Base of natural log: .
Definition: TMath.h:97
TDirectory * _dir
Definition: RooDirItem.h:33
virtual void loadValues(const RooAbsDataStore *tds, const RooFormulaVar *select=0, const char *rangeName=0, std::size_t nStart=0, std::size_t nStop=std::numeric_limits< std::size_t >::max())=0
virtual void addFast(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0)
Add a data point, with its coordinates specified in the &#39;data&#39; argset, to the data set...
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:44
const Bool_t kFALSE
Definition: RtypesCore.h:90
void checkInit() const
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:35
static void activate()
Install atexit handler that calls CleanupRooFitAtExit() on program termination.
Definition: RooSentinel.cxx:57
RooArgSet addWgtVar(const RooArgSet &origVars, const RooAbsArg *wgtVar)
Helper function for constructor that adds optional weight variable to construct total set of observab...
Definition: RooDataSet.cxx:830
#define ClassImp(name)
Definition: Rtypes.h:361
RooAbsArg * find(const char *name) const
Find object with given name in list.
void convertToTreeStore() override
Convert vector-based storage to tree-based storage.
double Double_t
Definition: RtypesCore.h:57
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:60
RooDirItem is a utility base class for RooFit objects that are to be attached to ROOT directories...
Definition: RooDirItem.h:22
RooAbsDataStore * _dstore
External variables cached with this data set.
Definition: RooAbsData.h:276
void append(RooDataSet &data)
Add all data points of given data set to this data set.
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:29
Double_t y[n]
Definition: legend1.C:17
#define TRACE_DESTROY
Definition: RooTrace.h:23
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
void SetName(const char *name) override
Change the name of this dataset into the given name.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
virtual void printValue(std::ostream &os) const override
Print value of the dataset, i.e. the sum of weights contained in the dataset.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2937
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
virtual void printArgs(std::ostream &os) const override
Print argument of dataset, i.e. the observable names.
static StorageType defaultStorageType
Definition: RooAbsData.h:238
#define oocoutW(o, a)
Definition: RooMsgService.h:47
void removeAsymError()
Definition: RooRealVar.h:69
Mother of all ROOT objects.
Definition: TObject.h:37
unsigned short _errorMsgCount
Definition: RooDataSet.h:169
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
std::vector< std::string > tokenise(const std::string &str, const std::string &delims, bool returnEmptyToken=true)
Tokenise the string by splitting at the characters in delims.
Definition: RooHelpers.cxx:62
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
Bool_t merge(RooDataSet *data1, RooDataSet *data2=0, RooDataSet *data3=0, RooDataSet *data4=0, RooDataSet *data5=0, RooDataSet *data6=0)
virtual void Add(TObject *obj)
Definition: TList.h:87
auto * l
Definition: textangle.C:4
RooAbsRealLValue * getPlotVar() const
Definition: RooPlot.h:139
Definition: file.py:1
virtual TObject * Next()=0
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const =0
#define snprintf
Definition: civetweb.c:1540
virtual ~RooDataSet()
Destructor.
Definition: RooDataSet.cxx:940
RooRealVar * _wgtVar
Definition: RooDataSet.h:162
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
A TTree represents a columnar dataset.
Definition: TTree.h:78
float type_of_call hi(const int &, const int &)
virtual Int_t getBins(const char *name=0) const
Get number of bins of currently defined range.
Definition: first.py:1
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:73
RooArgSet _vars
Definition: RooAbsData.h:273
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)=0
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
Bool_t redirectServers(const RooAbsCollection &newServerList, Bool_t mustReplaceAll=kFALSE, Bool_t nameChange=kFALSE, Bool_t isRecursionStep=kFALSE)
Substitute our servers with those listed in newSet.
Definition: RooAbsArg.cxx:909
const Bool_t kTRUE
Definition: RtypesCore.h:89
void removeError()
Definition: RooRealVar.h:65
Bool_t ok() const
Definition: RooFormula.h:53
Double_t getErrorHi() const
Definition: RooRealVar.h:72
void variables(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
char name[80]
Definition: TGX11.cxx:109
Bool_t dirtyProp() const
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:306
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
static void cleanup()
Definition: RooDataSet.cxx:93
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0) override
Add a data point, with its coordinates specified in the &#39;data&#39; argset, to the data set...
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:28
void setError(Double_t value)
Definition: RooRealVar.h:64
const char * Data() const
Definition: TString.h:364
void SetNameTitle(const char *name, const char *title) override
Change the title of this dataset into the given name.