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
110 /// Return the weight of the last-retrieved data point.
111 double weight() const override
112 {
113 if (_extWgtArray)
115 if (_wgtVar)
116 return _wgtVar->getVal();
117
118 return 1.0;
119 }
120 double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override;
121 void weightError(double& lo, double& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const override;
122 bool isWeighted() const override { return _wgtVar || _extWgtArray; }
123
124 RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const override;
125 RooAbsData::CategorySpans getCategoryBatches(std::size_t /*first*/, std::size_t len) const override;
126 RooSpan<const double> getWeightBatch(std::size_t first, std::size_t len) const override;
127
128 // Change observable name
129 bool changeObservableName(const char* from, const char* to) override;
130
131 // Add one column
132 RooAbsArg* addColumn(RooAbsArg& var, bool adjustRange=true) override;
133
134 // Merge column-wise
135 RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) override;
136
137 // Add rows
138 void append(RooAbsDataStore& other) override;
139
140 // General & bookkeeping methods
141 Int_t numEntries() const override { return static_cast<int>(size()); }
142 double sumEntries() const override { return _sumWeight ; }
143 /// Get size of stored dataset.
144 std::size_t size() const {
145 if (!_realStoreList.empty()) {
146 return _realStoreList.front()->size();
147 } else if (!_realfStoreList.empty()) {
148 return _realfStoreList.front()->size();
149 } else if (!_catStoreList.empty()) {
150 return _catStoreList.front()->size();
151 }
152
153 return 0;
154 }
155 void reset() override;
156
157 // Buffer redirection routines used in inside RooAbsOptTestStatistics
158 void attachBuffers(const RooArgSet& extObs) override;
159 void resetBuffers() override;
160
161
162 // Constant term optimizer interface
163 const RooAbsArg* cacheOwner() override { return _cacheOwner ; }
164 void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=nullptr, bool skipZeroWeights=true) override;
165 void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) override;
166 void resetCache() override;
167 void recalculateCache(const RooArgSet* /*proj*/, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, bool skipZeroWeights) override;
168
169 void setArgStatus(const RooArgSet& set, bool active) override;
170
171 const RooVectorDataStore* cache() const { return _cache ; }
172
173 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;
174
175 void dump() override;
176
177 void setExternalWeightArray(const double* arrayWgt, const double* arrayWgtErrLo,
178 const double* arrayWgtErrHi, const double* arraySumW2) override {
179 _extWgtArray = arrayWgt ;
180 _extWgtErrLoArray = arrayWgtErrLo ;
181 _extWgtErrHiArray = arrayWgtErrHi ;
182 _extSumW2Array = arraySumW2 ;
183 }
184
185 void setDirtyProp(bool flag) override {
186 _doDirtyProp = flag ;
187 if (_cache) {
188 _cache->setDirtyProp(flag) ;
189 }
190 }
191
192 const RooArgSet& row() { return _varsww ; }
193
195 public:
196
197 RealVector(UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(double))) :
198 _nativeReal(nullptr), _real(nullptr), _buf(nullptr), _nativeBuf(nullptr), _tracker(nullptr), _nset(nullptr) {
199 _vec.reserve(initialCapacity);
200 }
201
202 RealVector(RooAbsReal* arg, UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(double))) :
203 _nativeReal(arg), _real(nullptr), _buf(nullptr), _nativeBuf(nullptr), _tracker(nullptr), _nset(nullptr) {
204 _vec.reserve(initialCapacity);
205 }
206
207 virtual ~RealVector() {
208 delete _tracker;
209 if (_nset) delete _nset ;
210 }
211
212 RealVector(const RealVector& other, RooAbsReal* real=nullptr) :
213 _vec(other._vec), _nativeReal(real?real:other._nativeReal), _real(real?real:other._real), _buf(other._buf), _nativeBuf(other._nativeBuf), _nset(nullptr) {
214 if (other._tracker) {
215 _tracker = new RooChangeTracker(Form("track_%s",_nativeReal->GetName()),"tracker",other._tracker->parameters()) ;
216 } else {
217 _tracker = nullptr ;
218 }
219 if (other._nset) {
220 _nset = new RooArgSet(*other._nset) ;
221 }
222 }
223
225 if (&other==this) return *this;
226 _nativeReal = other._nativeReal;
227 _real = other._real;
228 _buf = other._buf;
229 _nativeBuf = other._nativeBuf;
230 if (other._vec.size() <= _vec.capacity() / 2 && _vec.capacity() > (VECTOR_BUFFER_SIZE / sizeof(double))) {
231 std::vector<double> tmp;
232 tmp.reserve(std::max(other._vec.size(), VECTOR_BUFFER_SIZE / sizeof(double)));
233 tmp.assign(other._vec.begin(), other._vec.end());
234 _vec.swap(tmp);
235 } else {
236 _vec = other._vec;
237 }
238
239 return *this;
240 }
241
242 void setNset(RooArgSet* newNset) { _nset = newNset ? new RooArgSet(*newNset) : nullptr ; }
243
244 RooArgSet* nset() const { return _nset ; }
245
246 void setBufArg(RooAbsReal* arg) { _nativeReal = arg ; }
247 const RooAbsReal* bufArg() const { return _nativeReal ; }
248
249 void setBuffer(RooAbsReal* real, double* newBuf) {
250 _real = real ;
251 _buf = newBuf ;
252 if (_nativeBuf==nullptr) {
253 _nativeBuf=newBuf ;
254 }
255 }
256
257 void setNativeBuffer(double* newBuf=nullptr) {
258 _nativeBuf = newBuf ? newBuf : _buf ;
259 }
260
261 void setDependents(const RooArgSet& deps) {
262 if (_tracker) {
263 delete _tracker ;
264 }
265 _tracker = new RooChangeTracker(Form("track_%s",_nativeReal->GetName()),"tracker",deps) ;
266 }
267
268 bool needRecalc() {
269 if (!_tracker) return false ;
270 return _tracker->hasChanged(true) ;
271 }
272
273 void fill() {
274 _vec.push_back(*_buf);
275 }
276
277 void write(Int_t i) {
278 assert(static_cast<std::size_t>(i) < _vec.size());
279 _vec[i] = *_buf ;
280 }
281
282 void reset() {
283 _vec.clear();
284 }
285
286 inline void load(std::size_t idx) const {
287 assert(idx < _vec.size());
288 *_buf = *(_vec.begin() + idx) ;
289 *_nativeBuf = *_buf ;
290 }
291
292 RooSpan<const double> getRange(std::size_t first, std::size_t last) const {
293 auto beg = std::min(_vec.cbegin() + first, _vec.cend());
294 auto end = std::min(_vec.cbegin() + last, _vec.cend());
295
296 return RooSpan<const double>(beg, end);
297 }
298
299 std::size_t size() const { return _vec.size() ; }
300
301 void resize(Int_t siz) {
302 if (siz < Int_t(_vec.capacity()) / 2 && _vec.capacity() > (VECTOR_BUFFER_SIZE / sizeof(double))) {
303 // do an expensive copy, if we save at least a factor 2 in size
304 std::vector<double> tmp;
305 tmp.reserve(std::max(siz, Int_t(VECTOR_BUFFER_SIZE / sizeof(double))));
306 if (!_vec.empty())
307 tmp.assign(_vec.begin(), std::min(_vec.end(), _vec.begin() + siz));
308 if (Int_t(tmp.size()) != siz)
309 tmp.resize(siz);
310 _vec.swap(tmp);
311 } else {
312 _vec.resize(siz);
313 }
314 }
315
316 void reserve(Int_t siz) {
317 _vec.reserve(siz);
318 }
319
320 const std::vector<double>& data() const {
321 return _vec;
322 }
323
324 std::vector<double>& data() { return _vec; }
325
326 protected:
327 std::vector<double> _vec;
328
329 private:
330 friend class RooVectorDataStore ;
331 RooAbsReal* _nativeReal ; ///< Instance which our data belongs to. This is the variable in the dataset.
332 RooAbsReal* _real ; ///< Instance where we should write data into when load() is called.
333 double* _buf ; ///<!
334 double* _nativeBuf ; ///<!
337 ClassDef(RealVector,1) // STL-vector-based Data Storage class
338 } ;
339
340
341 class RealFullVector : public RealVector {
342 public:
343 RealFullVector(UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(double))) : RealVector(initialCapacity),
344 _bufE(nullptr), _bufEL(nullptr), _bufEH(nullptr),
345 _nativeBufE(nullptr), _nativeBufEL(nullptr), _nativeBufEH(nullptr),
346 _vecE(nullptr), _vecEL(nullptr), _vecEH(nullptr) {
347 }
348
349 RealFullVector(RooAbsReal* arg, UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(double))) :
350 RealVector(arg,initialCapacity),
351 _bufE(nullptr), _bufEL(nullptr), _bufEH(nullptr),
352 _nativeBufE(nullptr), _nativeBufEL(nullptr), _nativeBufEH(nullptr),
353 _vecE(nullptr), _vecEL(nullptr), _vecEH(nullptr) {
354 }
355
356 ~RealFullVector() override {
357 if (_vecE) delete _vecE ;
358 if (_vecEL) delete _vecEL ;
359 if (_vecEH) delete _vecEH ;
360 }
361
362 RealFullVector(const RealFullVector& other, RooAbsReal* real=nullptr) : RealVector(other,real),
363 _bufE(other._bufE), _bufEL(other._bufEL), _bufEH(other._bufEH),
365 _vecE = (other._vecE) ? new std::vector<double>(*other._vecE) : nullptr ;
366 _vecEL = (other._vecEL) ? new std::vector<double>(*other._vecEL) : nullptr ;
367 _vecEH = (other._vecEH) ? new std::vector<double>(*other._vecEH) : nullptr ;
368 }
369
370 RealFullVector(const RealVector& other, RooAbsReal* real=nullptr) : RealVector(other,real),
371 _bufE(nullptr), _bufEL(nullptr), _bufEH(nullptr),
372 _nativeBufE(nullptr), _nativeBufEL(nullptr), _nativeBufEH(nullptr) {
373 _vecE = nullptr ;
374 _vecEL = nullptr ;
375 _vecEH = nullptr ;
376 }
377
379 if (&other==this) return *this;
381 _bufE = other._bufE;
382 _bufEL = other._bufEL;
383 _bufEH = other._bufEH;
384 _nativeBufE = other._nativeBufE;
387 std::vector<double>* src[3] = { other._vecE, other._vecEL, other._vecEH };
388 std::vector<double>* dst[3] = { _vecE, _vecEL, _vecEH };
389 for (unsigned i = 0; i < 3; ++i) {
390 if (src[i]) {
391 if (dst[i]) {
392 if (dst[i]->size() <= src[i]->capacity() / 2 &&
393 src[i]->capacity() > (VECTOR_BUFFER_SIZE / sizeof(double))) {
394 std::vector<double> tmp;
395 tmp.reserve(std::max(src[i]->size(), VECTOR_BUFFER_SIZE / sizeof(double)));
396 tmp.assign(src[i]->begin(), src[i]->end());
397 dst[i]->swap(tmp);
398 } else {
399 *dst[i] = *src[i];
400 }
401 } else {
402 dst[i] = new std::vector<double>(*src[i]);
403 }
404 } else {
405 delete dst[i];
406 dst[i] = nullptr;
407 }
408 }
409 return *this;
410 }
411
412 void setErrorBuffer(double* newBuf) {
413 /* std::cout << "setErrorBuffer(" << _nativeReal->GetName() << ") newBuf = " << newBuf << std::endl ; */
414 _bufE = newBuf ;
415 if (!_vecE) _vecE = new std::vector<double> ;
416 _vecE->reserve(_vec.capacity()) ;
418 }
419 void setAsymErrorBuffer(double* newBufL, double* newBufH) {
420 _bufEL = newBufL ; _bufEH = newBufH ;
421 if (!_vecEL) {
422 _vecEL = new std::vector<double> ;
423 _vecEH = new std::vector<double> ;
424 _vecEL->reserve(_vec.capacity()) ;
425 _vecEH->reserve(_vec.capacity()) ;
426 }
427 if (!_nativeBufEL) {
430 }
431 }
432
433 void fill() {
435 if (_vecE) _vecE->push_back(*_bufE) ;
436 if (_vecEL) _vecEL->push_back(*_bufEL) ;
437 if (_vecEH) _vecEH->push_back(*_bufEH) ;
438 } ;
439
440 void write(Int_t i) {
442 if (_vecE) (*_vecE)[i] = *_bufE ;
443 if (_vecEL) (*_vecEL)[i] = *_bufEL ;
444 if (_vecEH) (*_vecEH)[i] = *_bufEH ;
445 }
446
447 void reset() {
449 if (_vecE) {
450 std::vector<double> tmp;
451 _vecE->swap(tmp);
452 }
453 if (_vecEL) {
454 std::vector<double> tmp;
455 _vecEL->swap(tmp);
456 }
457 if (_vecEH) {
458 std::vector<double> tmp;
459 _vecEH->swap(tmp);
460 }
461 }
462
463 inline void load(Int_t idx) const {
464 RealVector::load(idx) ;
465 if (_vecE) {
466 *_bufE = (*_vecE)[idx];
467 *_nativeBufE = (*_vecE)[idx] ;
468 }
469 if (_vecEL) {
470 *_bufEL = (*_vecEL)[idx] ;
471 *_nativeBufEL = (*_vecEL)[idx] ;
472 }
473 if (_vecEH) {
474 *_bufEH = (*_vecEH)[idx] ;
475 *_nativeBufEH = (*_vecEH)[idx] ;
476 }
477 }
478
479 void resize(Int_t siz) {
481 std::vector<double>* vlist[3] = { _vecE, _vecEL, _vecEH };
482 for (unsigned i = 0; i < 3; ++i) {
483 if (!vlist[i]) continue;
484 if (vlist[i]) {
485 if (siz < Int_t(vlist[i]->capacity()) / 2 && vlist[i]->capacity() > (VECTOR_BUFFER_SIZE / sizeof(double))) {
486 // if we gain a factor of 2 in memory, we copy and swap
487 std::vector<double> tmp;
488 tmp.reserve(std::max(siz, Int_t(VECTOR_BUFFER_SIZE / sizeof(double))));
489 if (!vlist[i]->empty())
490 tmp.assign(vlist[i]->begin(),
491 std::min(_vec.end(), _vec.begin() + siz));
492 if (Int_t(tmp.size()) != siz)
493 tmp.resize(siz);
494 vlist[i]->swap(tmp);
495 } else {
496 vlist[i]->resize(siz);
497 }
498 }
499 }
500 }
501
502 void reserve(Int_t siz) {
504 if (_vecE) _vecE->reserve(siz);
505 if (_vecEL) _vecEL->reserve(siz);
506 if (_vecEH) _vecEH->reserve(siz);
507 }
508
509 std::vector<double>* dataE() { return _vecE; }
510 std::vector<double>* dataEL() { return _vecEL; }
511 std::vector<double>* dataEH() { return _vecEH; }
512
513 private:
514 friend class RooVectorDataStore ;
515 double *_bufE ; ///<!
516 double *_bufEL ; ///<!
517 double *_bufEH ; ///<!
518 double *_nativeBufE ; ///<!
519 double *_nativeBufEL ; ///<!
520 double *_nativeBufEH ; ///<!
521 std::vector<double> *_vecE, *_vecEL, *_vecEH ;
522 ClassDefOverride(RealFullVector,1) // STL-vector-based Data Storage class
523 } ;
524
525
526 class CatVector {
527 public:
529 _cat(nullptr), _buf(nullptr), _nativeBuf(nullptr)
530 {
531 _vec.reserve(initialCapacity);
532 }
533
535 _cat(cat), _buf(nullptr), _nativeBuf(nullptr)
536 {
537 _vec.reserve(initialCapacity);
538 }
539
540 virtual ~CatVector() {
541 }
542
543 CatVector(const CatVector& other, RooAbsCategory* cat = nullptr) :
544 _cat(cat?cat:other._cat), _buf(other._buf), _nativeBuf(other._nativeBuf), _vec(other._vec)
545 {
546
547 }
548
550 if (&other==this) return *this;
551 _cat = other._cat;
552 _buf = other._buf;
553 _nativeBuf = other._nativeBuf;
554 if (other._vec.size() <= _vec.capacity() / 2 && _vec.capacity() > VECTOR_BUFFER_SIZE) {
555 std::vector<RooAbsCategory::value_type> tmp;
556 tmp.reserve(std::max(other._vec.size(), std::size_t(VECTOR_BUFFER_SIZE)));
557 tmp.assign(other._vec.begin(), other._vec.end());
558 _vec.swap(tmp);
559 } else {
560 _vec = other._vec;
561 }
562
563 return *this;
564 }
565
567 _buf = newBuf ;
568 if (!_nativeBuf) _nativeBuf = newBuf;
569 }
570
572 _nativeBuf = newBuf ? newBuf : _buf;
573 }
574
575 void fill() {
576 _vec.push_back(*_buf) ;
577 }
578
579 void write(std::size_t i) {
580 _vec[i] = *_buf;
581 }
582
583 void reset() {
584 // make sure the vector releases the underlying memory
585 std::vector<RooAbsCategory::value_type> tmp;
586 _vec.swap(tmp);
587 }
588
589 inline void load(std::size_t idx) const {
590 *_buf = _vec[idx];
591 *_nativeBuf = *_buf;
592 }
593
594 RooSpan<const RooAbsCategory::value_type> getRange(std::size_t first, std::size_t last) const {
595 auto beg = std::min(_vec.cbegin() + first, _vec.cend());
596 auto end = std::min(_vec.cbegin() + last, _vec.cend());
597
599 }
600
601
602 std::size_t size() const { return _vec.size() ; }
603
604 void resize(Int_t siz) {
605 if (siz < Int_t(_vec.capacity()) / 2 && _vec.capacity() > VECTOR_BUFFER_SIZE) {
606 // do an expensive copy, if we save at least a factor 2 in size
607 std::vector<RooAbsCategory::value_type> tmp;
608 tmp.reserve(std::max(siz, VECTOR_BUFFER_SIZE));
609 if (!_vec.empty())
610 tmp.assign(_vec.begin(), std::min(_vec.end(), _vec.begin() + siz));
611 if (Int_t(tmp.size()) != siz)
612 tmp.resize(siz);
613 _vec.swap(tmp);
614 } else {
615 _vec.resize(siz);
616 }
617 }
618
619 void reserve(Int_t siz) {
620 _vec.reserve(siz);
621 }
622
623 void setBufArg(RooAbsCategory* arg) { _cat = arg; }
624 const RooAbsCategory* bufArg() const { return _cat; }
625
626 std::vector<RooAbsCategory::value_type>& data() { return _vec; }
627
628 private:
629 friend class RooVectorDataStore ;
633 std::vector<RooAbsCategory::value_type> _vec;
634 ClassDef(CatVector,2) // STL-vector-based Data Storage class
635 } ;
636
637 std::vector<RealVector*>& realStoreList() { return _realStoreList ; }
638 std::vector<RealFullVector*>& realfStoreList() { return _realfStoreList ; }
639 std::vector<CatVector*>& catStoreList() { return _catStoreList ; }
640
641 protected:
642
643 friend class RooAbsReal ;
644 friend class RooAbsCategory ;
645 friend class RooRealVar ;
646
648
650
651 bool isFullReal(RooAbsReal* real);
652
653 bool hasError(RooAbsReal* real);
654
655 bool hasAsymError(RooAbsReal* real);
656
658
659 bool hasFilledCache() const override { return _cache ? true : false ; }
660
661 void forceCacheUpdate() override;
662
663 private:
665 RooRealVar* _wgtVar = nullptr; ///< Pointer to weight variable (if set)
666
667 std::vector<RealVector*> _realStoreList ;
668 std::vector<RealFullVector*> _realfStoreList ;
669 std::vector<CatVector*> _catStoreList ;
670
671 void setAllBuffersNative() ;
672
673 double _sumWeight = 0.0;
674 double _sumWeightCarry = 0.0;
675
676 const double* _extWgtArray = nullptr; ///<! External weight array
677 const double* _extWgtErrLoArray = nullptr; ///<! External weight array - low error
678 const double* _extWgtErrHiArray = nullptr; ///<! External weight array - high error
679 const double* _extSumW2Array = nullptr; ///<! External sum of weights array
680
682
683 RooVectorDataStore* _cache = nullptr; ///<! Optimization cache
684 RooAbsArg* _cacheOwner = nullptr; ///<! Cache owner
685
686 bool _forcedUpdate = false; ///<! Request for forced cache update
687
688 ClassDefOverride(RooVectorDataStore, 7) // STL-vector-based Data Storage class
689};
690
691
692#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:2456
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)
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()
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)
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