ROOT  6.06/09
Reference Guide
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 //
19 // BEGIN_HTML
20 // RooChangeTracker is a meta object that tracks value
21 // changes in a given set of RooAbsArgs by registering itself as value
22 // client of these objects. The change tracker can perform an
23 // additional validation step where it also compares the numeric
24 // values of the tracked arguments with reference values to ensure
25 // that values have actually changed. This may be useful in case some
26 // of the tracked observables are in binned datasets where each
27 // observable propates a valueDirty flag when an event is loaded even
28 // though usually only one observable actually changes.
29 // END_HTML
30 //
31 
32 
33 #include "RooFit.h"
34 
35 #include "Riostream.h"
36 #include <math.h>
37 
38 #include "RooChangeTracker.h"
39 #include "RooAbsReal.h"
40 #include "RooAbsCategory.h"
41 #include "RooArgSet.h"
42 #include "RooMsgService.h"
43 
44 using namespace std ;
45 
47 ;
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Default constructor
51 
53 {
56 }
57 
58 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Constructor. The set trackSet contains the observables to be
62 /// tracked for changes. If checkValues is true an additional
63 /// validation step is activated where the numeric values of the
64 /// tracked arguments are compared with reference values ensuring
65 /// that values have actually changed.
66 
67 RooChangeTracker::RooChangeTracker(const char* name, const char* title, const RooArgSet& trackSet, Bool_t checkValues) :
68  RooAbsReal(name, title),
69  _realSet("realSet","Set of real-valued components to be tracked",this),
70  _catSet("catSet","Set of discrete-valued components to be tracked",this),
71  _realRef(trackSet.getSize()),
72  _catRef(trackSet.getSize()),
73  _checkVal(checkValues),
74  _init(kFALSE)
75 {
78 
79  TIterator* iter = trackSet.createIterator() ;
80  RooAbsArg* arg ;
81  while((arg=(RooAbsArg*)iter->Next())) {
82  if (dynamic_cast<RooAbsReal*>(arg)) {
83  _realSet.add(*arg) ;
84  }
85  if (dynamic_cast<RooAbsCategory*>(arg)) {
86  _catSet.add(*arg) ;
87  }
88  }
89  delete iter ;
90 
91  if (_checkVal) {
92  RooAbsReal* real ;
93  RooAbsCategory* cat ;
94  Int_t i(0) ;
95  _realSetIter->Reset() ;
96  _catSetIter->Reset() ;
97  while((real=(RooAbsReal*)_realSetIter->Next())) {
98  _realRef[i++] = real->getVal() ;
99  }
100  i=0 ;
101  while((cat=(RooAbsCategory*)_catSetIter->Next())) {
102  _catRef[i++] = cat->getIndex() ;
103  }
104  }
105 
106 }
107 
108 
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Copy constructor
112 
114  RooAbsReal(other, name),
115  _realSet("realSet",this,other._realSet),
116  _catSet("catSet",this,other._catSet),
117  _realRef(other._realRef),
118  _catRef(other._catRef),
119  _checkVal(other._checkVal),
120  _init(kFALSE)
121 {
124 
125 // _realSet.add(other._realSet) ;
126 // _catSet.add(other._catSet) ;
127 
128 }
129 
130 
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Returns true if state has changes since last call with clearState=kTRUE
134 /// If clearState is true, changeState flag will be cleared.
135 
137 {
138 
139  // If dirty flag did not change, object has not changed in any case
140  if (!isValueDirty()) {
141  return kFALSE ;
142  }
143 
144  // If no value checking is required and dirty flag has changed, return true
145  if (!_checkVal) {
146 
147  if (clearState) {
148  // Clear dirty flag by calling getVal()
149  //cout << "RooChangeTracker(" << GetName() << ") clearing isValueDirty" << endl ;
150  clearValueDirty() ;
151  }
152 
153  //cout << "RooChangeTracker(" << GetName() << ") isValueDirty = kTRUE, returning kTRUE" << endl ;
154 
155  return kTRUE ;
156  }
157 
158  // Compare values against reference
159  _realSetIter->Reset() ;
160  _catSetIter->Reset() ;
161  RooAbsReal* real ;
162  RooAbsCategory* cat ;
163  Int_t i(0) ;
164 
165  if (clearState) {
166 
167  Bool_t valuesChanged(kFALSE) ;
168 
169  // Check if any of the real values changed
170  while ((real=(RooAbsReal*)_realSetIter->Next())) {
171  if (real->getVal() != _realRef[i]) {
172  // cout << "RooChangeTracker(" << this << "," << GetName() << ") value of " << real->GetName() << " has changed from " << _realRef[i] << " to " << real->getVal() << " clearState = " << (clearState?"T":"F") << endl ;
173  valuesChanged = kTRUE ;
174  _realRef[i] = real->getVal() ;
175  }
176  i++ ;
177  }
178  // Check if any of the categories changed
179  i=0 ;
180  while ((cat=(RooAbsCategory*)_catSetIter->Next())) {
181  if (cat->getIndex() != _catRef[i++]) {
182  // cout << "RooChangeTracker(" << this << "," << GetName() << ") value of " << cat->GetName() << " has changed from " << _catRef[i-1] << " to " << cat->getIndex() << endl ;
183  valuesChanged = kTRUE ;
184  _catRef[i-1] = cat->getIndex() ;
185  }
186  }
187 
188  clearValueDirty() ;
189 
190 
191  if (!_init) {
192  valuesChanged=kTRUE ;
193  _init = kTRUE ;
194  }
195 
196  // cout << "RooChangeTracker(" << GetName() << ") returning " << (valuesChanged?"T":"F") << endl ;
197 
198  return valuesChanged ;
199 
200  } else {
201 
202  // Return true as soon as any input has changed
203 
204  // Check if any of the real values changed
205  while ((real=(RooAbsReal*)_realSetIter->Next())) {
206  if (real->getVal() != _realRef[i++]) {
207  return kTRUE ;
208  }
209  }
210  // Check if any of the categories changed
211  i=0 ;
212  while ((cat=(RooAbsCategory*)_catSetIter->Next())) {
213  if (cat->getIndex() != _catRef[i++]) {
214  return kTRUE ;
215  }
216  }
217 
218  }
219 
220  return kFALSE ;
221 }
222 
223 
224 
225 ////////////////////////////////////////////////////////////////////////////////
226 /// Destructor
227 
229 {
230  if (_realSetIter) delete _realSetIter ;
231  if (_catSetIter) delete _catSetIter ;
232 }
233 
234 
235 
236 ////////////////////////////////////////////////////////////////////////////////
237 
239 {
240  RooArgSet ret ;
241  ret.add(_realSet) ;
242  ret.add(_catSet) ;
243  return ret ;
244 }
245 
246 
247 
virtual void Reset()=0
virtual ~RooChangeTracker()
Destructor.
virtual Int_t getIndex() const
Return index number of current state.
Bool_t hasChanged(Bool_t clearState)
Returns true if state has changes since last call with clearState=kTRUE If clearState is true...
RooListProxy _realSet
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
std::vector< Int_t > _catRef
Iterator abstract base class.
Definition: TIterator.h:32
RooArgSet parameters() const
RooChangeTracker()
Default constructor.
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
TIterator * createIterator(Bool_t dir=kIterForward) const
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
Bool_t _init
do not persist
TIterator * _catSetIter
do not persist
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
#define name(a, b)
Definition: linkTestLib0.cpp:5
std::vector< Double_t > _realRef
virtual TObject * Next()=0
Bool_t isValueDirty() const
Definition: RooAbsArg.h:336
void clearValueDirty() const
Definition: RooAbsArg.h:447
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
TIterator * _realSetIter
const Bool_t kTRUE
Definition: Rtypes.h:91
RooListProxy _catSet
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448
ClassImp(RooChangeTracker)