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