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