MINT2
FitComplexPolar.cpp
Go to the documentation of this file.
1 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
2 // status: Mon 9 Feb 2009 19:17:55 GMT
3 #include <cmath>
4 #include <string>
5 
7 
8 #include "Mint/FitComplexPolar.h"
9 #include "Mint/NamedParameter.h"
10 #include "Mint/Utils.h"
11 
12 using namespace std;
13 using namespace MINT;
14 
15 double FitComplexPolar::_degFac = -9999;
16 void FitComplexPolar::calculateDegFac(){
17  NamedParameter<std::string> phaseOpt("Phases given in"
18  , (std::string) "degrees");
19  if(phaseOpt.getVal() == (std::string) "degrees"){
20  _degFac = pi/180.0;
21  }else if(phaseOpt.getVal() == (std::string) "rad"){
22  _degFac = 1.0;
23  }else{
24  cout << " ERROR in FitComplexPolar::calculateDegFac()"
25  << " Unknown option " << phaseOpt
26  << " Allowed values are are: \"degrees\" and \"rad\"."
27  << " Assuming you mean rad."
28  << endl;
29  _degFac=1.0;
30  }
31  return;
32 }
33 
34 std::string FitComplexPolar::makeAmpName(const std::string& varName){
35  return varName + "_Amp";
36 }
37 std::string FitComplexPolar::makePhaseName(const std::string& varName){
38  return varName + "_Phase";
39 }
40 
41 FitComplexPolar::FitComplexPolar(const std::string& varName
42  , const char* fname
43  , MinuitParameterSet* pset
44  , IFitParRegister* daddy
47 
48  )
49  : FitComplex(daddy)
50  , _amp (makeAmpName( varName), fname, pset, fow, vb)
51  , _phase(makePhaseName(varName), fname, pset, fow, vb)
52 {
53  //cout << "FitComplexPolar, just made: " << _amp
54  // << " and " << _phase << endl;
55 }
56 FitComplexPolar::FitComplexPolar(const std::string& varName
57  , MinuitParameterSet* pset
58  , IFitParRegister* daddy
61  )
62  : FitComplex(daddy)
63  , _amp (makeAmpName( varName), pset, fow, vb)
64  , _phase(makePhaseName(varName), pset, fow, vb)
65 {
66 }
67 
69 }
71  return amp().gotInitialised() && phase().gotInitialised();
72 }
73 
74 /*
75 FitComplexPolar::FitComplexPolar(const FitComplexPolar& other){
76  : _amp(varName + "_Amp", other)
77  , phase()(varName + "_Phase", other)
78 {
79 }
80 */
81 
82 std::complex<double> FitComplexPolar::getVal()const{
83  double a(amp());
84  if(0.0 == a) return 0;
85  double p(phase());
86  p*=degFac();
87  return std::complex<double>(a*cos(p), a*sin(p));
88  /*
89  double a(amp());
90  if(0.0 == a) return 0;
91  double p(phase());
92  p*=degFac();
93  return std::polar(a,p);
94  */
95 }
96 std::complex<double> FitComplexPolar::getValInit()const{
97  double a=amp().meanInit();
98  double p = phase().meanInit() * degFac();
99 
100  return std::complex<double>(a*cos(p), a*sin(p));
101  // return std::polar( amp().meanInit(), phase().meanInit() * degFac());
102 }
103 
105  amp().defaultInit();
106  phase().defaultInit();
107 }
108 
109 void FitComplexPolar::set(std::complex<double> z){
110  _amp = abs(z);
111  _phase = arg(z);
112 }
113 
114 void FitComplexPolar::print(std::ostream& os) const{
115  os << amp() << "\n"
116  << phase();
117 }
118 
119 
120 //
virtual void set(std::complex< double > z)
const FitParameter & phase() const
double meanInit() const
static const double pi
FitComplexPolar(const std::string &varName, const char *fname=0, MinuitParameterSet *pset=0, MINT::IFitParRegister *daddy=0, FitParameter::FIX_OR_WHAT fow=FitParameter::FIX, NamedParameterBase::VERBOSITY vb=NamedParameterBase::VERBOSE)
const FitParameter & amp() const
virtual void print(std::ostream &os=std::cout) const
virtual std::complex< double > getValInit() const
static double degFac()
virtual std::complex< double > getVal() const
virtual bool gotInitialised() const
virtual const T & getVal(int i=0) const