Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooChangeTracker.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 RooChangeTracker.cxx
19\class RooChangeTracker
20\ingroup Roofitcore
21
22Meta object that tracks value
23changes in a given set of RooAbsArgs by registering itself as value
24client of these objects. The change tracker can perform an
25additional validation step where it also compares the numeric
26values of the tracked arguments with reference values to ensure
27that values have actually changed. This may be useful in case some
28of the tracked observables are in binned datasets where each
29observable propagates a valueDirty flag when an event is loaded even
30though usually only one observable actually changes.
31**/
32
33#include "RooChangeTracker.h"
34#include "RooAbsReal.h"
35#include "RooAbsCategory.h"
36#include "RooArgSet.h"
37
38
39////////////////////////////////////////////////////////////////////////////////
40/// Constructor. The set trackSet contains the observables to be
41/// tracked for changes. If checkValues is true an additional
42/// validation step is activated where the numeric values of the
43/// tracked arguments are compared with reference values ensuring
44/// that values have actually changed.
45
46RooChangeTracker::RooChangeTracker(const char* name, const char* title, const RooArgSet& trackSet, bool checkValues) :
47 RooAbsReal(name, title),
48 _realSet("realSet","Set of real-valued components to be tracked",this),
49 _catSet("catSet","Set of discrete-valued components to be tracked",this),
50 _realRef(trackSet.size()),
51 _catRef(trackSet.size()),
52 _checkVal(checkValues)
53{
54for (const auto arg : trackSet) {
55 if (dynamic_cast<const RooAbsReal*>(arg)) {
56 _realSet.add(*arg) ;
57 }
58 if (dynamic_cast<const RooAbsCategory*>(arg)) {
59 _catSet.add(*arg) ;
60 }
61 }
62
63 if (_checkVal) {
64 for (unsigned int i=0; i < _realSet.size(); ++i) {
65 auto real = static_cast<const RooAbsReal*>(_realSet.at(i));
66 _realRef[i++] = real->getVal() ;
67 }
68
69 for (unsigned int i=0; i < _catSet.size(); ++i) {
70 auto cat = static_cast<const RooAbsCategory*>(_catSet.at(i));
71 _catRef[i++] = cat->getCurrentIndex() ;
72 }
73 }
74
75}
76
77
78
79////////////////////////////////////////////////////////////////////////////////
80/// Copy constructor
81
84 _realSet("realSet",this,other._realSet),
85 _catSet("catSet",this,other._catSet),
86 _realRef(other._realRef),
87 _catRef(other._catRef),
88 _checkVal(other._checkVal)
89{
90}
91
92
93
94////////////////////////////////////////////////////////////////////////////////
95/// Returns true if state has changed since last call with clearState=true.
96/// If clearState is true, changeState flag will be cleared.
97
99{
100
101 // If dirty flag did not change, object has not changed in any case
102 if (!isValueDirty()) {
103 return false ;
104 }
105
106 // If no value checking is required and dirty flag has changed, return true
107 if (!_checkVal) {
108
109 if (clearState) {
110 // Clear dirty flag by calling getVal()
112 }
113
114 return true ;
115 }
116
117 // Compare values against reference
118 if (clearState) {
119
120 bool valuesChanged(false) ;
121
122 // Check if any of the real values changed
123 for (unsigned int i=0; i < _realSet.size(); ++i) {
124 auto real = static_cast<const RooAbsReal*>(_realSet.at(i));
125 if (real->getVal() != _realRef[i]) {
127 _realRef[i] = real->getVal() ;
128 }
129 }
130 // Check if any of the categories changed
131 for (unsigned int i=0; i < _catSet.size(); ++i) {
132 auto cat = static_cast<const RooAbsCategory*>(_catSet.at(i));
133 if (cat->getCurrentIndex() != _catRef[i]) {
135 _catRef[i] = cat->getCurrentIndex() ;
136 }
137 }
138
140
141
142 if (!_init) {
144 _init = true ;
145 }
146
147 return valuesChanged ;
148
149 } else {
150
151 // Return true as soon as any input has changed
152
153 // Check if any of the real values changed
154 for (unsigned int i=0; i < _realSet.size(); ++i) {
155 auto real = static_cast<const RooAbsReal*>(_realSet.at(i));
156 if (real->getVal() != _realRef[i]) {
157 return true ;
158 }
159 }
160 // Check if any of the categories changed
161 for (unsigned int i=0; i < _catSet.size(); ++i) {
162 auto cat = static_cast<const RooAbsCategory*>(_catSet.at(i));
163 if (cat->getCurrentIndex() != _catRef[i]) {
164 return true ;
165 }
166 }
167
168 }
169
170 return false ;
171}
172
173////////////////////////////////////////////////////////////////////////////////
174
176{
177 RooArgSet ret ;
178 ret.add(_realSet) ;
179 ret.add(_catSet) ;
180 return ret ;
181}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:142
void clearValueDirty() const
Definition RooAbsArg.h:521
bool isValueDirty() const
Definition RooAbsArg.h:335
A space to attach TBranches.
Storage_t::size_type size() const
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Meta object that tracks value changes in a given set of RooAbsArgs by registering itself as value cli...
bool hasChanged(bool clearState)
Returns true if state has changed since last call with clearState=true.
RooListProxy _catSet
List of categories to check.
bool _checkVal
Check contents as well if true.
RooChangeTracker()=default
std::vector< Int_t > _catRef
Reference values for categories.
RooArgSet parameters() const
std::vector< double > _realRef
Reference values for reals.
RooListProxy _realSet
List of reals to track.
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...