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()
117 }
118
119 return true ;
120 }
121
122 // Compare values against reference
123 if (clearState) {
124
125 bool valuesChanged(false) ;
126
127 // Check if any of the real values changed
128 for (unsigned int i=0; i < _realSet.size(); ++i) {
129 auto real = static_cast<const RooAbsReal*>(_realSet.at(i));
130 if (real->getVal() != _realRef[i]) {
132 _realRef[i] = real->getVal() ;
133 }
134 }
135 // Check if any of the categories changed
136 for (unsigned int i=0; i < _catSet.size(); ++i) {
137 auto cat = static_cast<const RooAbsCategory*>(_catSet.at(i));
138 if (cat->getCurrentIndex() != _catRef[i]) {
140 _catRef[i] = cat->getCurrentIndex() ;
141 }
142 }
143
145
146
147 if (!_init) {
149 _init = true ;
150 }
151
152 return valuesChanged ;
153
154 } else {
155
156 // Return true as soon as any input has changed
157
158 // Check if any of the real values changed
159 for (unsigned int i=0; i < _realSet.size(); ++i) {
160 auto real = static_cast<const RooAbsReal*>(_realSet.at(i));
161 if (real->getVal() != _realRef[i]) {
162 return true ;
163 }
164 }
165 // Check if any of the categories changed
166 for (unsigned int i=0; i < _catSet.size(); ++i) {
167 auto cat = static_cast<const RooAbsCategory*>(_catSet.at(i));
168 if (cat->getCurrentIndex() != _catRef[i]) {
169 return true ;
170 }
171 }
172
173 }
174
175 return false ;
176}
177
178////////////////////////////////////////////////////////////////////////////////
179
181{
182 RooArgSet ret ;
183 ret.add(_realSet) ;
184 ret.add(_catSet) ;
185 return ret ;
186}
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:148
void clearValueDirty() const
Definition RooAbsArg.h:542
bool isValueDirty() const
Definition RooAbsArg.h:356
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...