AmpTools
DerivedParameter.h
Go to the documentation of this file.
1 #if !defined(MINUITINTERFACE_DERIVEDPARAMETER_H)
2 #define MINUITINTERFACE_DERIVEDPARAMETER_H
3 
4 // This file is a part of MinuitInterface - a front end for the Minuit minimization
5 // package (Minuit itself was authored by Fred James, of CERN)
6 //
7 //
8 // Copyright Cornell University 1993, 1996, All Rights Reserved.
9 //
10 // This software written by Lawrence Gibbons, Cornell University.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions
14 // are met:
15 // 1. Redistributions of source code must retain the above copyright
16 // notice and author attribution, this list of conditions and the
17 // following disclaimer.
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice and author attribution, this list of conditions and the
20 // following disclaimer in the documentation and/or other materials
21 // provided with the distribution.
22 // 3. Neither the name of the University nor the names of its contributors
23 // may be used to endorse or promote products derived from this software
24 // without specific prior written permission.
25 //
26 // Creation of derivative forms of this software for commercial
27 // utilization may be subject to restriction; written permission may be
28 // obtained from Cornell University.
29 //
30 // CORNELL MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way
31 // of example, but not limitation, CORNELL MAKES NO REPRESENTATIONS OR
32 // WARRANTIES OF MERCANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT
33 // THE USE OF THIS SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS,
34 // COPYRIGHTS, TRADEMARKS, OR OTHER RIGHTS. Cornell University shall not be
35 // held liable for any liability with respect to any claim by the user or any
36 // other party arising from use of the program.
37 //
38 
39 // The DerivedParameter is a parameter that depends on one or
40 // more other parameters via a known functional form. The
41 // template class T communicates the set of "parent"
42 // parameters upon which this class depends. The only
43 // constraint on T is
44 // 1) an "attach()" member function, which causes this
45 // parameter to be attached to the base MISubject
46 // of all of the parent Parameters. That will cause this
47 // DerivedParameter to be updated whenever any of the
48 // parent parameters is updated.
49 // 2) similarly, a "detach()" member function
50 //
51 // The update is handled by a ConversionFunction, which implements
52 // an operator()( T& ) member function, with a pure virual definition
53 // in the ConversionFunction base class.
54 
55 #include <string>
56 
60 
61 template< class T>
62 class DerivedParameter : public Parameter, public MIObserver
63 {
64 public:
65 
66  DerivedParameter( const std::string& name,
67  T& parentParameters,
68  ConversionFunction<T>& converter );
69 
70  virtual ~DerivedParameter();
71 
72  void update( const MISubject* updatedParameter );
73 
74 protected:
75  // DerivedParameter only updates via changes in any of the base parameters
76  // upon which it depends
77  void setValue( double newValue ) { Parameter::setValue( newValue ); }
78  void setError( double newError, bool notify = false ) { Parameter::setError( newError, notify ); }
79  void setValueError( double newValue, double newError ) { Parameter::setValueError( newValue, newError ); }
80 
81 private:
82  // ------------ unused copy/assignment constructors
83  DerivedParameter(); // stop default
84  DerivedParameter( const DerivedParameter& ); // stop default
85 
86  // ------------ member data ----------
87  ConversionFunction<T>& m_converter;
88  T& m_baseParameters;
89 };
90 
91 template<class T>
93  T& parentParameters,
94  ConversionFunction<T>& converter ) :
95 Parameter(name),
96 MIObserver(),
97 m_converter( converter ),
98 m_baseParameters( parentParameters )
99 {
100  m_baseParameters.attach( this );
101  setValue( m_converter( m_baseParameters ) );
102 }
103 
104 template<class T>
106  m_baseParameters.detach( this );
107 }
108 
109 template<class T>
110 void
111 DerivedParameter<T>::update( const MISubject* updatedParameter ) {
112  setValueError( m_converter(m_baseParameters), m_converter.error(m_baseParameters) );
113 }
114 #endif
virtual ~DerivedParameter()
void setValue(double newValue)
Definition: Parameter.cc:52
void setValue(double newValue)
void setValueError(double newValue, double newError)
Definition: Parameter.cc:73
void notify()
Definition: MISubject.cc:60
void update(const MISubject *updatedParameter)
void setError(double newError, bool notify=false)
virtual void setError(double newError, bool notify=false)
Definition: Parameter.cc:67
void setValueError(double newValue, double newError)
const std::string & name() const
Definition: Parameter.cc:80