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
34#include "Riostream.h"
35#include <cmath>
36
37#include "RooChangeTracker.h"
38#include "RooAbsReal.h"
39#include "RooAbsCategory.h"
40#include "RooArgSet.h"
41#include "RooMsgService.h"
42
43
44////////////////////////////////////////////////////////////////////////////////
45/// Constructor. The set trackSet contains the observables to be
46/// tracked for changes. If checkValues is true an additional
47/// validation step is activated where the numeric values of the
48/// tracked arguments are compared with reference values ensuring
49/// that values have actually changed.
50
51RooChangeTracker::RooChangeTracker(const char* name, const char* title, const RooArgSet& trackSet, bool checkValues) :
52 RooAbsReal(name, title),
53 _realSet("realSet","Set of real-valued components to be tracked",this),
54 _catSet("catSet","Set of discrete-valued components to be tracked",this),
55 _realRef(trackSet.size()),
56 _catRef(trackSet.size()),
57 _checkVal(checkValues)
58{
59for (const auto arg : trackSet) {
60 if (dynamic_cast<const RooAbsReal*>(arg)) {
61 _realSet.add(*arg) ;
62 }
63 if (dynamic_cast<const RooAbsCategory*>(arg)) {
64 _catSet.add(*arg) ;
65 }
66 }
67
68 if (_checkVal) {
69 for (unsigned int i=0; i < _realSet.size(); ++i) {
70 auto real = static_cast<const RooAbsReal*>(_realSet.at(i));
71 _realRef[i++] = real->getVal() ;
72 }
73
74 for (unsigned int i=0; i < _catSet.size(); ++i) {
75 auto cat = static_cast<const RooAbsCategory*>(_catSet.at(i));
76 _catRef[i++] = cat->getCurrentIndex() ;
77 }
78 }
79
80}
81
82
83
84////////////////////////////////////////////////////////////////////////////////
85/// Copy constructor
86
89 _realSet("realSet",this,other._realSet),
90 _catSet("catSet",this,other._catSet),
91 _realRef(other._realRef),
92 _catRef(other._catRef),
93 _checkVal(other._checkVal)
94{
95}
96
97
98
99////////////////////////////////////////////////////////////////////////////////
100/// Returns true if state has changed since last call with clearState=true.
101/// If clearState is true, changeState flag will be cleared.
102
104{
105
106 // If dirty flag did not change, object has not changed in any case
107 if (!isValueDirty()) {
108 return false ;
109 }
110
111 // If no value checking is required and dirty flag has changed, return true
112 if (!_checkVal) {
113
114 if (clearState) {
115 // Clear dirty flag by calling getVal()
116 //cout << "RooChangeTracker(" << GetName() << ") clearing isValueDirty" << std::endl ;
118 }
119
120 //cout << "RooChangeTracker(" << GetName() << ") isValueDirty = true, returning true" << std::endl ;
121
122 return true ;
123 }
124
125 // Compare values against reference
126 if (clearState) {
127
128 bool valuesChanged(false) ;
129
130 // Check if any of the real values changed
131 for (unsigned int i=0; i < _realSet.size(); ++i) {
132 auto real = static_cast<const RooAbsReal*>(_realSet.at(i));
133 if (real->getVal() != _realRef[i]) {
134 // std::cout << "RooChangeTracker(" << this << "," << GetName() << ") value of " << real->GetName() << " has changed from " << _realRef[i] << " to " << real->getVal() << " clearState = " << (clearState?"T":"F") << std::endl ;
136 _realRef[i] = real->getVal() ;
137 }
138 }
139 // Check if any of the categories changed
140 for (unsigned int i=0; i < _catSet.size(); ++i) {
141 auto cat = static_cast<const RooAbsCategory*>(_catSet.at(i));
142 if (cat->getCurrentIndex() != _catRef[i]) {
143 // std::cout << "RooChangeTracker(" << this << "," << GetName() << ") value of " << cat->GetName() << " has changed from " << _catRef[i-1] << " to " << cat->getIndex() << std::endl ;
145 _catRef[i] = cat->getCurrentIndex() ;
146 }
147 }
148
150
151
152 if (!_init) {
154 _init = true ;
155 }
156
157 // std::cout << "RooChangeTracker(" << GetName() << ") returning " << (valuesChanged?"T":"F") << std::endl ;
158
159 return valuesChanged ;
160
161 } else {
162
163 // Return true as soon as any input has changed
164
165 // Check if any of the real values changed
166 for (unsigned int i=0; i < _realSet.size(); ++i) {
167 auto real = static_cast<const RooAbsReal*>(_realSet.at(i));
168 if (real->getVal() != _realRef[i]) {
169 return true ;
170 }
171 }
172 // Check if any of the categories changed
173 for (unsigned int i=0; i < _catSet.size(); ++i) {
174 auto cat = static_cast<const RooAbsCategory*>(_catSet.at(i));
175 if (cat->getCurrentIndex() != _catRef[i]) {
176 return true ;
177 }
178 }
179
180 }
181
182 return false ;
183}
184
185////////////////////////////////////////////////////////////////////////////////
186
188{
189 RooArgSet ret ;
190 ret.add(_realSet) ;
191 ret.add(_catSet) ;
192 return ret ;
193}
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:110
void clearValueDirty() const
Definition RooAbsArg.h:543
bool isValueDirty() const
Definition RooAbsArg.h:362
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:59
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...