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