AmpTools
ComplexParameter.cc
Go to the documentation of this file.
1 //******************************************************************************
2 // This file is part of AmpTools, a package for performing Amplitude Analysis
3 //
4 // Copyright Trustees of Indiana University 2010, all rights reserved
5 //
6 // This software written by Matthew Shepherd, Ryan Mitchell, and
7 // Hrayr Matevosyan at Indiana University, Bloomington
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions
11 // are met:
12 // 1. Redistributions of source code must retain the above copyright
13 // notice and author attribution, this list of conditions and the
14 // following disclaimer.
15 // 2. Redistributions in binary form must reproduce the above copyright
16 // notice and author attribution, this list of conditions and the
17 // following disclaimer in the documentation and/or other materials
18 // provided with the distribution.
19 // 3. Neither the name of the University nor the names of its contributors
20 // may be used to endorse or promote products derived from this software
21 // without specific prior written permission.
22 //
23 // Creation of derivative forms of this software for commercial
24 // utilization may be subject to restriction; written permission may be
25 // obtained from the Trustees of Indiana University.
26 //
27 // INDIANA UNIVERSITY AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES,
28 // EXPRESS OR IMPLIED. By way of example, but not limitation, INDIANA
29 // UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCANTABILITY OR
30 // FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THIS SOFTWARE OR
31 // DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS,
32 // OR OTHER RIGHTS. Neither Indiana University nor the authors shall be
33 // held liable for any liability with respect to any claim by the user or
34 // any other party arising from use of the program.
35 //******************************************************************************
36 
37 #include <iostream>
38 #include <string>
39 #include <complex>
40 #include <cassert>
41 
45 
47  MinuitMinimizationManager& fitManager,
48  complex< double > initialValue,
49  bool purelyReal ) :
50 MIObserver(),
51 m_name( name ),
52 m_value( initialValue ),
53 m_purelyReal( purelyReal ),
54 m_realPar( NULL ),
55 m_imPar( NULL )
56 {
57 
58  // be sure we have a valid reference to MinuitMinimizationManager before
59  // registering the new parameters -- otherwise this object looks
60  // just like complex number
61 
62  m_realPar = new MinuitParameter( name + "_re",
63  fitManager.parameterManager(),
64  real( m_value ) );
65 
66  m_realPar->attach( this );
67 
68  if( !purelyReal ){
69 
70  m_imPar = new MinuitParameter( name + "_im",
71  fitManager.parameterManager(),
72  imag( m_value ) );
73  m_imPar->attach( this );
74  }
75 
76 }
77 
79 {
80  // not yet supported un UpRootMinuit
81  // m_realMagPar->unregister();
82  // m_imPhasePar->unregister();
83 
84  // problems with double delete?
85  // delete m_realPar;
86  // delete m_imPar;
87 }
88 
89 void
90 ComplexParameter::update( const MISubject* callingSubject ){
91 
92  if( callingSubject == m_realPar ){
93 
94  m_value = complex< double >( m_realPar->value(), imag( m_value ) );
95  }
96  else if( callingSubject == m_imPar ){
97 
98  m_value = complex< double >( real( m_value ), m_imPar->value() );
99  }
100 }
101 
102 void
103 ComplexParameter::setValue( complex< double > value ){
104 
105  // the set value calls below will trigger the notify() method
106  // of MISubject, which will call the update method above
107  // to set the member data m_value to the new value
108 
109  m_realPar->setValue( real( value ) );
110  if( !m_purelyReal ) m_imPar->setValue( imag( value ) );
111 }
112 
113 void
115 
116  m_realPar->fix();
117  if( !m_purelyReal ) m_imPar->fix();
118 }
119 
120 void
122 
123  m_realPar->free();
124  if( !m_purelyReal ) m_imPar->free();
125 }
126 
127 bool
129 
130  return !m_realPar->floating();
131 }
132 
bool floating() const
double value() const
Definition: Parameter.h:54
void update(const MISubject *callingSubject)
void setValue(double newValue)
Definition: Parameter.cc:52
ComplexParameter(const string &name, MinuitMinimizationManager &aManager, complex< double > initialValue=complex< double >(1, 0), bool purelyReal=false)
#define NULL
Definition: URtypes.h:72
void attach(MIObserver *)
Definition: MISubject.cc:48
void setValue(complex< double > value)
bool isFixed() const
MinuitParameterManager & parameterManager()
complex< double > value() const