Logo ROOT  
Reference Guide
RooVectorDataStore.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $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#ifndef ROO_VECTOR_DATA_STORE
17#define ROO_VECTOR_DATA_STORE
18
19#include "RooAbsDataStore.h"
20#include "RooAbsCategory.h"
21#include "RooAbsReal.h"
22#include "RooChangeTracker.h"
23#include "RooRealVar.h"
24
25#include "ROOT/RStringView.hxx"
26#include "Rtypes.h"
27
28#include <list>
29#include <vector>
30#include <algorithm>
31
32class RooAbsArg ;
33class RooArgList ;
34class TTree ;
35class RooFormulaVar ;
36class RooArgSet ;
37class RooTreeDataStore ;
38
39#define VECTOR_BUFFER_SIZE 1024
40
42public:
43
45
46 // Empty ctor
47 RooVectorDataStore(RooStringView name, RooStringView title, const RooArgSet& vars, const char* wgtVarName=nullptr) ;
48
49 RooAbsDataStore* clone(const char* newname=nullptr) const override { return new RooVectorDataStore(*this,newname) ; }
50 RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=nullptr) const override { return new RooVectorDataStore(*this,vars,newname) ; }
51
52 std::unique_ptr<RooAbsDataStore> reduce(RooStringView name, RooStringView title,
53 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
54 std::size_t nStart, std::size_t nStop) override;
55
56 RooVectorDataStore(const RooVectorDataStore& other, const char* newname=nullptr) ;
57 RooVectorDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname=nullptr) ;
58 RooVectorDataStore(const RooVectorDataStore& other, const RooArgSet& vars, const char* newname=nullptr) ;
59
60
62 const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
63 std::size_t nStart, std::size_t nStop, const char* wgtVarName=nullptr) ;
64
65 ~RooVectorDataStore() override ;
66
67 /// \class ArraysStruct
68 /// Output struct for the RooVectorDataStore::getArrays() helper function.
69 /// Meant to be used for RooFit internal use and might change without warning.
70 struct ArraysStruct {
71
72 template<class T>
73 struct ArrayInfo {
74 ArrayInfo(RooStringView n, T const* d) : name{n}, data{d} {}
75 std::string name;
76 T const* data;
77 };
78
79 std::vector<ArrayInfo<double>> reals;
80 std::vector<ArrayInfo<RooAbsCategory::value_type>> cats;
81
82 std::size_t size;
83 };
84
85 /// \name Internal RooFit interface.
86 /// The classes and functions in the internal RooFit interface are
87 /// implementation details and not part of the public user interface.
88 /// Everything in this group might change without warning.
89 /// @{
90 ArraysStruct getArrays() const;
91 void recomputeSumWeight();
92 /// @}
93
94private:
95 RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName);
96 RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName);
97
98 // reserve storage for nEvt entries
99 void reserve(Int_t nEvt);
100
101public:
102 // Write current row
103 Int_t fill() override;
104
105 // Retrieve a row
107 const RooArgSet* get(Int_t index) const override;
108
109 virtual const RooArgSet* getNative(Int_t index) const;
110
112 /// Return the weight of the last-retrieved data point.
113 double weight() const override
114 {
115 if (_extWgtArray)
117 if (_wgtVar)
118 return _wgtVar->getVal();
119
120 return 1.0;
121 }
122 double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override;
123 void weightError(double& lo, double& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const override;
124 bool isWeighted() const override { return _wgtVar || _extWgtArray; }
125
126 RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const override;
127 RooAbsData::CategorySpans getCategoryBatches(std::size_t /*first*/, std::size_t len) const override;
128 RooSpan<const double> getWeightBatch(std::size_t first, std::size_t len) const override;
129
130 // Change observable name
131 bool changeObservableName(const char* from, const char* to) override;
132
133 // Add one column
134 RooAbsArg* addColumn(RooAbsArg& var, bool adjustRange=true) override;
135
136 // Merge column-wise
137 RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) override;
138
139 // Add rows
140 void append(RooAbsDataStore& other) override;
141
142 // General & bookkeeping methods
143 Int_t numEntries() const override { return static_cast<int>(size()); }
144 double sumEntries() const override { return _sumWeight ; }
145 /// Get size of stored dataset.
146 std::size_t size() const {
147 if (!_realStoreList.empty()) {
148 return _realStoreList.front()->size();
149 } else if (!_realfStoreList.empty()) {
150 return _realfStoreList.front()->size();
151 } else if (!_catStoreList.empty()) {
152 return _catStoreList.front()->size();
153 }
154
155 return 0;
156 }
157 void reset() override;
158
159 // Buffer redirection routines used in inside RooAbsOptTestStatistics
160 void attachBuffers(const RooArgSet& extObs) override;
161 void resetBuffers() override;
162
163
164 // Constant term optimizer interface
165 const RooAbsArg* cacheOwner() override { return _cacheOwner ; }
166 void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=nullptr, bool skipZeroWeights=true) override;
167 void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) override;
168 void resetCache() override;
169 void recalculateCache(const RooArgSet* /*proj*/, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, bool skipZeroWeights) override;
170
171 void setArgStatus(const RooArgSet& set, bool active) override;
172
173 const RooVectorDataStore* cache() const { return _cache ; }
174
175 void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=nullptr, const char* rangeName=nullptr, std::size_t nStart=0, std::size_t nStop = std::numeric_limits<std::size_t>::max()) override;
176
177 void dump() override;
178
179 void setExternalWeightArray(const double* arrayWgt, const double* arrayWgtErrLo,
180 const double* arrayWgtErrHi, const double* arraySumW2) override {
181 _extWgtArray = arrayWgt ;
182 _extWgtErrLoArray = arrayWgtErrLo ;
183 _extWgtErrHiArray = arrayWgtErrHi ;
184 _extSumW2Array = arraySumW2 ;
185 }
186
187 void setDirtyProp(bool flag) override {
188 _doDirtyProp = flag ;
189 if (_cache) {
190 _cache->setDirtyProp(flag) ;
191 }
192 }
193
194 const RooArgSet& row() { return _varsww ; }
195
197 public:
198
199 RealVector(UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(double))) :
200 _nativeReal(nullptr), _real(nullptr), _buf(nullptr), _nativeBuf(nullptr), _tracker(nullptr), _nset(nullptr) {
201 _vec.reserve(initialCapacity);
202 }
203
204 RealVector(RooAbsReal* arg, UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(double))) :
205 _nativeReal(arg), _real(nullptr), _buf(nullptr), _nativeBuf(nullptr), _tracker(nullptr), _nset(nullptr) {
206 _vec.reserve(initialCapacity);
207 }
208
209 virtual ~RealVector() {
210 delete _tracker;
211 if (_nset) delete _nset ;
212 }
213
214 RealVector(const RealVector& other, RooAbsReal* real=nullptr) :
215 _vec(other._vec), _nativeReal(real?real:other._nativeReal), _real(real?real:other._real), _buf(other._buf), _nativeBuf(other._nativeBuf), _nset(nullptr) {
216 if (other._tracker) {
217 _tracker = new RooChangeTracker(Form("track_%s",_nativeReal->GetName()),"tracker",other._tracker->parameters()) ;
218 } else {
219 _tracker = nullptr ;
220 }
221 if (other._nset) {
222 _nset = new RooArgSet(*other._nset) ;
223 }
224 }
225
227 if (&other==this) return *this;
228 _nativeReal = other._nativeReal;
229 _real = other._real;
230 _buf = other._buf;
231 _nativeBuf = other._nativeBuf;
232 if (other._vec.size() <= _vec.capacity() / 2 && _vec.capacity() > (VECTOR_BUFFER_SIZE / sizeof(double))) {
233 std::vector<double> tmp;
234 tmp.reserve(std::max(other._vec.size(), VECTOR_BUFFER_SIZE / sizeof(double)));
235 tmp.assign(other._vec.begin(), other._vec.end());
236 _vec.swap(tmp);
237 } else {
238 _vec = other._vec;
239 }
240
241 return *this;
242 }
243
244 void setNset(RooArgSet* newNset) { _nset = newNset ? new RooArgSet(*newNset) : nullptr ; }
245
246 RooArgSet* nset() const { return _nset ; }
247
248 void setBufArg(RooAbsReal* arg) { _nativeReal = arg ; }
249 const RooAbsReal* bufArg() const { return _nativeReal ; }
250
251 void setBuffer(RooAbsReal* real, double* newBuf) {
252 _real = real ;
253 _buf = newBuf ;
254 if (_nativeBuf==nullptr) {
255 _nativeBuf=newBuf ;
256 }
257 }
258
259 void setNativeBuffer(double* newBuf=nullptr) {
260 _nativeBuf = newBuf ? newBuf : _buf ;
261 }
262
263 void setDependents(const RooArgSet& deps) {
264 if (_tracker) {
265 delete _tracker ;
266 }
267 _tracker = new RooChangeTracker(Form("track_%s",_nativeReal->GetName()),"tracker",deps) ;
268 }
269
270 bool needRecalc() {
271 if (!_tracker) return false ;
272 return _tracker->hasChanged(true) ;
273 }
274
275 void fill() {
276 _vec.push_back(*_buf);
277 }
278
279 void write(Int_t i) {
280 assert(static_cast<std::size_t>(i) < _vec.size());
281 _vec[i] = *_buf ;
282 }
283
284 void reset() {
285 _vec.clear();
286 }
287
288 inline void load(std::size_t idx) const {
289 assert(idx < _vec.size());
290 *_buf = *(_vec.begin() + idx) ;
291 }
292
293 RooSpan<const double> getRange(std::size_t first, std::size_t last) const {
294 auto beg = std::min(_vec.cbegin() + first, _vec.cend());
295 auto end = std::min(_vec.cbegin() + last, _vec.cend());
296
297 return RooSpan<const double>(beg, end);
298 }
299
300 inline void loadToNative(std::size_t idx) const {
301 *_nativeBuf = *(_vec.begin() + idx) ;
302 }
303
304 std::size_t size() const { return _vec.size() ; }
305
306 void resize(Int_t siz) {
307 if (siz < Int_t(_vec.capacity()) / 2 && _vec.capacity() > (VECTOR_BUFFER_SIZE / sizeof(double))) {
308 // do an expensive copy, if we save at least a factor 2 in size
309 std::vector<double> tmp;
310 tmp.reserve(std::max(siz, Int_t(VECTOR_BUFFER_SIZE / sizeof(double))));
311 if (!_vec.empty())
312 tmp.assign(_vec.begin(), std::min(_vec.end(), _vec.begin() + siz));
313 if (Int_t(tmp.size()) != siz)
314 tmp.resize(siz);
315 _vec.swap(tmp);
316 } else {
317 _vec.resize(siz);
318 }
319 }
320
321 void reserve(Int_t siz) {
322 _vec.reserve(siz);
323 }
324
325 const std::vector<double>& data() const {
326 return _vec;
327 }
328
329 std::vector<double>& data() { return _vec; }
330
331 protected:
332 std::vector<double> _vec;
333
334 private:
335 friend class RooVectorDataStore ;
336 RooAbsReal* _nativeReal ; ///< Instance which our data belongs to. This is the variable in the dataset.
337 RooAbsReal* _real ; ///< Instance where we should write data into when load() is called.
338 double* _buf ; ///<!
339 double* _nativeBuf ; ///<!
342 ClassDef(RealVector,1) // STL-vector-based Data Storage class
343 } ;
344
345
346 class RealFullVector : public RealVector {
347 public:
348 RealFullVector(UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(double))) : RealVector(initialCapacity),
349 _bufE(nullptr), _bufEL(nullptr), _bufEH(nullptr),
350 _nativeBufE(nullptr), _nativeBufEL(nullptr), _nativeBufEH(nullptr),
351 _vecE(nullptr), _vecEL(nullptr), _vecEH(nullptr) {
352 }
353
354 RealFullVector(RooAbsReal* arg, UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(double))) :
355 RealVector(arg,initialCapacity),
356 _bufE(nullptr), _bufEL(nullptr), _bufEH(nullptr),
357 _nativeBufE(nullptr), _nativeBufEL(nullptr), _nativeBufEH(nullptr),
358 _vecE(nullptr), _vecEL(nullptr), _vecEH(nullptr) {
359 }
360
361 ~RealFullVector() override {
362 if (_vecE) delete _vecE ;
363 if (_vecEL) delete _vecEL ;
364 if (_vecEH) delete _vecEH ;
365 }
366
367 RealFullVector(const RealFullVector& other, RooAbsReal* real=nullptr) : RealVector(other,real),
368 _bufE(other._bufE), _bufEL(other._bufEL), _bufEH(other._bufEH),
370 _vecE = (other._vecE) ? new std::vector<double>(*other._vecE) : nullptr ;
371 _vecEL = (other._vecEL) ? new std::vector<double>(*other._vecEL) : nullptr ;
372 _vecEH = (other._vecEH) ? new std::vector<double>(*other._vecEH) : nullptr ;
373 }
374
375 RealFullVector(const RealVector& other, RooAbsReal* real=nullptr) : RealVector(other,real),
376 _bufE(nullptr), _bufEL(nullptr), _bufEH(nullptr),
377 _nativeBufE(nullptr), _nativeBufEL(nullptr), _nativeBufEH(nullptr) {
378 _vecE = nullptr ;
379 _vecEL = nullptr ;
380 _vecEH = nullptr ;
381 }
382
384 if (&other==this) return *this;
386 _bufE = other._bufE;
387 _bufEL = other._bufEL;
388 _bufEH = other._bufEH;
389 _nativeBufE = other._nativeBufE;
392 std::vector<double>* src[3] = { other._vecE, other._vecEL, other._vecEH };
393 std::vector<double>* dst[3] = { _vecE, _vecEL, _vecEH };
394 for (unsigned i = 0; i < 3; ++i) {
395 if (src[i]) {
396 if (dst[i]) {
397 if (dst[i]->size() <= src[i]->capacity() / 2 &&
398 src[i]->capacity() > (VECTOR_BUFFER_SIZE / sizeof(double))) {
399 std::vector<double> tmp;
400 tmp.reserve(std::max(src[i]->size(), VECTOR_BUFFER_SIZE / sizeof(double)));
401 tmp.assign(src[i]->begin(), src[i]->end());
402 dst[i]->swap(tmp);
403 } else {
404 *dst[i] = *src[i];
405 }
406 } else {
407 dst[i] = new std::vector<double>(*src[i]);
408 }
409 } else {
410 delete dst[i];
411 dst[i] = nullptr;
412 }
413 }
414 return *this;
415 }
416
417 void setErrorBuffer(double* newBuf) {
418 /* std::cout << "setErrorBuffer(" << _nativeReal->GetName() << ") newBuf = " << newBuf << std::endl ; */
419 _bufE = newBuf ;
420 if (!_vecE) _vecE = new std::vector<double> ;
421 _vecE->reserve(_vec.capacity()) ;
423 }
424 void setAsymErrorBuffer(double* newBufL, double* newBufH) {
425 _bufEL = newBufL ; _bufEH = newBufH ;
426 if (!_vecEL) {
427 _vecEL = new std::vector<double> ;
428 _vecEH = new std::vector<double> ;
429 _vecEL->reserve(_vec.capacity()) ;
430 _vecEH->reserve(_vec.capacity()) ;
431 }
432 if (!_nativeBufEL) {
435 }
436 }
437
438 inline void loadToNative(Int_t idx) const {
440 if (_vecE) {
441 *_nativeBufE = (*_vecE)[idx] ;
442 }
443 if (_vecEL) {
444 *_nativeBufEL = (*_vecEL)[idx] ;
445 *_nativeBufEH = (*_vecEH)[idx] ;
446 }
447 }
448
449 void fill() {
451 if (_vecE) _vecE->push_back(*_bufE) ;
452 if (_vecEL) _vecEL->push_back(*_bufEL) ;
453 if (_vecEH) _vecEH->push_back(*_bufEH) ;
454 } ;
455
456 void write(Int_t i) {
458 if (_vecE) (*_vecE)[i] = *_bufE ;
459 if (_vecEL) (*_vecEL)[i] = *_bufEL ;
460 if (_vecEH) (*_vecEH)[i] = *_bufEH ;
461 }
462
463 void reset() {
465 if (_vecE) {
466 std::vector<double> tmp;
467 _vecE->swap(tmp);
468 }
469 if (_vecEL) {
470 std::vector<double> tmp;
471 _vecEL->swap(tmp);
472 }
473 if (_vecEH) {
474 std::vector<double> tmp;
475 _vecEH->swap(tmp);
476 }
477 }
478
479 inline void get(Int_t idx) const {
480 RealVector::load(idx) ;
481 if (_vecE) *_bufE = (*_vecE)[idx];
482 if (_vecEL) *_bufEL = (*_vecEL)[idx] ;
483 if (_vecEH) *_bufEH = (*_vecEH)[idx] ;
484 }
485
486 void resize(Int_t siz) {
488 std::vector<double>* vlist[3] = { _vecE, _vecEL, _vecEH };
489 for (unsigned i = 0; i < 3; ++i) {
490 if (!vlist[i]) continue;
491 if (vlist[i]) {
492 if (siz < Int_t(vlist[i]->capacity()) / 2 && vlist[i]->capacity() > (VECTOR_BUFFER_SIZE / sizeof(double))) {
493 // if we gain a factor of 2 in memory, we copy and swap
494 std::vector<double> tmp;
495 tmp.reserve(std::max(siz, Int_t(VECTOR_BUFFER_SIZE / sizeof(double))));
496 if (!vlist[i]->empty())
497 tmp.assign(vlist[i]->begin(),
498 std::min(_vec.end(), _vec.begin() + siz));
499 if (Int_t(tmp.size()) != siz)
500 tmp.resize(siz);
501 vlist[i]->swap(tmp);
502 } else {
503 vlist[i]->resize(siz);
504 }
505 }
506 }
507 }
508
509 void reserve(Int_t siz) {
511 if (_vecE) _vecE->reserve(siz);
512 if (_vecEL) _vecEL->reserve(siz);
513 if (_vecEH) _vecEH->reserve(siz);
514 }
515
516 std::vector<double>* dataE() { return _vecE; }
517 std::vector<double>* dataEL() { return _vecEL; }
518 std::vector<double>* dataEH() { return _vecEH; }
519
520 private:
521 friend class RooVectorDataStore ;
522 double *_bufE ; ///<!
523 double *_bufEL ; ///<!
524 double *_bufEH ; ///<!
525 double *_nativeBufE ; ///<!
526 double *_nativeBufEL ; ///<!
527 double *_nativeBufEH ; ///<!
528 std::vector<double> *_vecE, *_vecEL, *_vecEH ;
529 ClassDefOverride(RealFullVector,1) // STL-vector-based Data Storage class
530 } ;
531
532
533 class CatVector {
534 public:
536 _cat(nullptr), _buf(nullptr), _nativeBuf(nullptr)
537 {
538 _vec.reserve(initialCapacity);
539 }
540
542 _cat(cat), _buf(nullptr), _nativeBuf(nullptr)
543 {
544 _vec.reserve(initialCapacity);
545 }
546
547 virtual ~CatVector() {
548 }
549
550 CatVector(const CatVector& other, RooAbsCategory* cat = nullptr) :
551 _cat(cat?cat:other._cat), _buf(other._buf), _nativeBuf(other._nativeBuf), _vec(other._vec)
552 {
553
554 }
555
557 if (&other==this) return *this;
558 _cat = other._cat;
559 _buf = other._buf;
560 _nativeBuf = other._nativeBuf;
561 if (other._vec.size() <= _vec.capacity() / 2 && _vec.capacity() > VECTOR_BUFFER_SIZE) {
562 std::vector<RooAbsCategory::value_type> tmp;
563 tmp.reserve(std::max(other._vec.size(), std::size_t(VECTOR_BUFFER_SIZE)));
564 tmp.assign(other._vec.begin(), other._vec.end());
565 _vec.swap(tmp);
566 } else {
567 _vec = other._vec;
568 }
569
570 return *this;
571 }
572
574 _buf = newBuf ;
575 if (!_nativeBuf) _nativeBuf = newBuf;
576 }
577
579 _nativeBuf = newBuf ? newBuf : _buf;
580 }
581
582 void fill() {
583 _vec.push_back(*_buf) ;
584 }
585
586 void write(std::size_t i) {
587 _vec[i] = *_buf;
588 }
589
590 void reset() {
591 // make sure the vector releases the underlying memory
592 std::vector<RooAbsCategory::value_type> tmp;
593 _vec.swap(tmp);
594 }
595
596 inline void load(std::size_t idx) const {
597 *_buf = _vec[idx];
598 }
599
600 RooSpan<const RooAbsCategory::value_type> getRange(std::size_t first, std::size_t last) const {
601 auto beg = std::min(_vec.cbegin() + first, _vec.cend());
602 auto end = std::min(_vec.cbegin() + last, _vec.cend());
603
605 }
606
607
608 inline void loadToNative(std::size_t idx) const {
609 *_nativeBuf = _vec[idx];
610 }
611
612 std::size_t size() const { return _vec.size() ; }
613
614 void resize(Int_t siz) {
615 if (siz < Int_t(_vec.capacity()) / 2 && _vec.capacity() > VECTOR_BUFFER_SIZE) {
616 // do an expensive copy, if we save at least a factor 2 in size
617 std::vector<RooAbsCategory::value_type> tmp;
618 tmp.reserve(std::max(siz, VECTOR_BUFFER_SIZE));
619 if (!_vec.empty())
620 tmp.assign(_vec.begin(), std::min(_vec.end(), _vec.begin() + siz));
621 if (Int_t(tmp.size()) != siz)
622 tmp.resize(siz);
623 _vec.swap(tmp);
624 } else {
625 _vec.resize(siz);
626 }
627 }
628
629 void reserve(Int_t siz) {
630 _vec.reserve(siz);
631 }
632
633 void setBufArg(RooAbsCategory* arg) { _cat = arg; }
634 const RooAbsCategory* bufArg() const { return _cat; }
635
636 std::vector<RooAbsCategory::value_type>& data() { return _vec; }
637
638 private:
639 friend class RooVectorDataStore ;
643 std::vector<RooAbsCategory::value_type> _vec;
644 ClassDef(CatVector,2) // STL-vector-based Data Storage class
645 } ;
646
647 std::vector<RealVector*>& realStoreList() { return _realStoreList ; }
648 std::vector<RealFullVector*>& realfStoreList() { return _realfStoreList ; }
649 std::vector<CatVector*>& catStoreList() { return _catStoreList ; }
650
651 protected:
652
653 friend class RooAbsReal ;
654 friend class RooAbsCategory ;
655 friend class RooRealVar ;
656
658
660
661 bool isFullReal(RooAbsReal* real);
662
663 bool hasError(RooAbsReal* real);
664
665 bool hasAsymError(RooAbsReal* real);
666
668
669 bool hasFilledCache() const override { return _cache ? true : false ; }
670
671 void forceCacheUpdate() override;
672
673 private:
675 RooRealVar* _wgtVar = nullptr; ///< Pointer to weight variable (if set)
676
677 std::vector<RealVector*> _realStoreList ;
678 std::vector<RealFullVector*> _realfStoreList ;
679 std::vector<CatVector*> _catStoreList ;
680
681 void setAllBuffersNative() ;
682
683 double _sumWeight = 0.0;
684 double _sumWeightCarry = 0.0;
685
686 const double* _extWgtArray = nullptr; ///<! External weight array
687 const double* _extWgtErrLoArray = nullptr; ///<! External weight array - low error
688 const double* _extWgtErrHiArray = nullptr; ///<! External weight array - high error
689 const double* _extSumW2Array = nullptr; ///<! External sum of weights array
690
692
693 RooVectorDataStore* _cache = nullptr; ///<! Optimization cache
694 RooAbsArg* _cacheOwner = nullptr; ///<! Cache owner
695
696 bool _forcedUpdate = false; ///<! Request for forced cache update
697
698 ClassDefOverride(RooVectorDataStore, 7) // STL-vector-based Data Storage class
699};
700
701
702#endif
#define d(i)
Definition: RSha256.hxx:102
#define VECTOR_BUFFER_SIZE
int Int_t
Definition: RtypesCore.h:45
unsigned long long ULong64_t
Definition: RtypesCore.h:81
#define ClassDef(name, id)
Definition: Rtypes.h:335
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
char name[80]
Definition: TGX11.cxx:110
#define hi
Definition: THbookFile.cxx:128
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2452
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:71
A space to attach TBranches.
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
const RooArgSet & cachedVars() const
bool _doDirtyProp
Switch do (de)activate dirty state propagation when loading a data point.
virtual double weight() const =0
virtual const RooArgSet * get() const
std::map< RooFit::Detail::DataKey, RooSpan< const double > > RealSpans
Definition: RooAbsData.h:136
std::map< RooFit::Detail::DataKey, RooSpan< const RooAbsCategory::value_type > > CategorySpans
Definition: RooAbsData.h:137
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
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:56
RooChangeTracker is a meta object that tracks value changes in a given set of RooAbsArgs by registeri...
bool hasChanged(bool clearState)
Returns true if state has changed since last call with clearState=true.
RooArgSet parameters() const
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
The RooStringView is a wrapper around a C-syle string that can also be constructed from a std::string...
Definition: RooStringView.h:27
RooTreeDataStore is a TTree-backed data storage.
void setBufArg(RooAbsCategory *arg)
void setBuffer(RooAbsCategory::value_type *newBuf)
RooSpan< const RooAbsCategory::value_type > getRange(std::size_t first, std::size_t last) const
CatVector(UInt_t initialCapacity=1024)
RooAbsCategory::value_type * _buf
!
RooAbsCategory::value_type * _nativeBuf
!
CatVector & operator=(const CatVector &other)
void load(std::size_t idx) const
std::vector< RooAbsCategory::value_type > _vec
void setNativeBuffer(RooAbsCategory::value_type *newBuf=nullptr)
void loadToNative(std::size_t idx) const
CatVector(RooAbsCategory *cat, UInt_t initialCapacity=1024)
const RooAbsCategory * bufArg() const
std::vector< RooAbsCategory::value_type > & data()
CatVector(const CatVector &other, RooAbsCategory *cat=nullptr)
std::vector< double > * dataEL()
RealFullVector(RooAbsReal *arg, UInt_t initialCapacity=(1024/sizeof(double)))
RealFullVector(const RealFullVector &other, RooAbsReal *real=nullptr)
std::vector< double > * dataEH()
RealFullVector(UInt_t initialCapacity=(1024/sizeof(double)))
RealFullVector(const RealVector &other, RooAbsReal *real=nullptr)
RealFullVector & operator=(const RealFullVector &other)
void setAsymErrorBuffer(double *newBufL, double *newBufH)
RealVector & operator=(const RealVector &other)
RealVector(const RealVector &other, RooAbsReal *real=nullptr)
const RooAbsReal * bufArg() const
void setNset(RooArgSet *newNset)
std::vector< double > & data()
void loadToNative(std::size_t idx) const
RooSpan< const double > getRange(std::size_t first, std::size_t last) const
RooAbsReal * _nativeReal
Instance which our data belongs to. This is the variable in the dataset.
void setDependents(const RooArgSet &deps)
RealVector(UInt_t initialCapacity=(1024/sizeof(double)))
RooAbsReal * _real
Instance where we should write data into when load() is called.
void setBuffer(RooAbsReal *real, double *newBuf)
RealVector(RooAbsReal *arg, UInt_t initialCapacity=(1024/sizeof(double)))
void load(std::size_t idx) const
void setNativeBuffer(double *newBuf=nullptr)
const std::vector< double > & data() const
RooVectorDataStore uses std::vectors to store data columns.
const RooArgSet & row()
void resetCache() override
void recalculateCache(const RooArgSet *, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, bool skipZeroWeights) override
RooAbsDataStore * clone(const RooArgSet &vars, const char *newname=nullptr) const override
std::vector< CatVector * > & catStoreList()
void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars) override
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
std::vector< RealFullVector * > _realfStoreList
void setExternalWeightArray(const double *arrayWgt, const double *arrayWgtErrLo, const double *arrayWgtErrHi, const double *arraySumW2) override
Int_t numEntries() const override
RooAbsDataStore * clone(const char *newname=nullptr) const override
RooAbsArg * addColumn(RooAbsArg &var, bool adjustRange=true) override
Add a new column to the data set which holds the pre-calculated values of 'newVar'.
const RooVectorDataStore * cache() const
RooVectorDataStore * _cache
! Optimization cache
const double * _extWgtErrHiArray
! External weight array - high error
~RooVectorDataStore() override
Destructor.
void resetBuffers() override
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return pointer to weight variable if it is defined.
void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=nullptr, bool skipZeroWeights=true) override
Cache given RooAbsArgs: The tree is given direct write access of the args internal cache the args val...
RooRealVar * _wgtVar
Pointer to weight variable (if set)
std::vector< RealVector * > _realStoreList
CatVector * addCategory(RooAbsCategory *cat)
void loadValues(const RooAbsDataStore *tds, const RooFormulaVar *select=nullptr, const char *rangeName=nullptr, std::size_t nStart=0, std::size_t nStop=std::numeric_limits< std::size_t >::max()) override
RealFullVector * addRealFull(RooAbsReal *real)
double weight() const override
Return the weight of the last-retrieved data point.
RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const override
Return batches of the data columns for the requested events.
bool isFullReal(RooAbsReal *real)
virtual const RooArgSet * getNative(Int_t index) const
Load the n-th data point (n='index') into the variables of this dataset, and return a pointer to the ...
bool isWeighted() const override
double sumEntries() const override
Int_t fill() override
Interface function to TTree::Fill.
std::vector< RealFullVector * > & realfStoreList()
const double * _extWgtErrLoArray
! External weight array - low error
bool _forcedUpdate
! Request for forced cache update
void append(RooAbsDataStore &other) override
bool hasError(RooAbsReal *real)
std::vector< CatVector * > _catStoreList
void setArgStatus(const RooArgSet &set, bool active) override
Disabling of branches is (intentionally) not implemented in vector data stores (as the doesn't result...
double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override
Return the error of the current weight.
void attachBuffers(const RooArgSet &extObs) override
ArraysStruct getArrays() const
Exports all arrays in this RooVectorDataStore into a simple datastructure to be used by RooFit intern...
RooAbsData::CategorySpans getCategoryBatches(std::size_t, std::size_t len) const override
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList) override
Merge columns of supplied data set(s) with this data set.
void setDirtyProp(bool flag) override
RealVector * addReal(RooAbsReal *real)
bool hasAsymError(RooAbsReal *real)
bool changeObservableName(const char *from, const char *to) override
void forceCacheUpdate() override
const RooAbsArg * cacheOwner() override
const double * _extSumW2Array
! External sum of weights array
void recomputeSumWeight()
Trigger a recomputation of the cached weight sums.
std::vector< RealVector * > & realStoreList()
std::size_t size() const
Get size of stored dataset.
std::unique_ptr< RooAbsDataStore > reduce(RooStringView name, RooStringView title, const RooArgSet &vars, const RooFormulaVar *cutVar, const char *cutRange, std::size_t nStart, std::size_t nStop) override
void reserve(Int_t nEvt)
RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len) const override
Return the weights of all events in the range [first, first+len).
virtual const RooArgSet * get() const
const double * _extWgtArray
! External weight array
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
RooAbsArg * _cacheOwner
! Cache owner
bool hasFilledCache() const override
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
A TTree represents a columnar dataset.
Definition: TTree.h:79
const Int_t n
Definition: legend1.C:16
double T(double x)
Definition: ChebyshevPol.h:34
Definition: first.py:1
Output struct for the RooVectorDataStore::getArrays() helper function.
std::vector< ArrayInfo< double > > reals
std::vector< ArrayInfo< RooAbsCategory::value_type > > cats