laura is hosted by Hepforge, IPPP Durham
Laura++  v1r0
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauMagPhaseCoeffSet.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2006 - 2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 // Authors:
7 // Thomas Latham
8 // John Back
9 // Paul Harrison
10 
15 #include <iostream>
16 #include <fstream>
17 #include <vector>
18 using std::cout;
19 using std::cerr;
20 using std::endl;
21 
22 #include "TMath.h"
23 #include "TRandom.h"
24 
25 #include "LauComplex.hh"
26 #include "LauConstants.hh"
27 #include "LauMagPhaseCoeffSet.hh"
28 #include "LauParameter.hh"
29 #include "LauPrint.hh"
30 #include "LauRandom.hh"
31 
32 ClassImp(LauMagPhaseCoeffSet)
33 
34 
35 LauMagPhaseCoeffSet::LauMagPhaseCoeffSet(const TString& compName, Double_t magnitude, Double_t phase, Bool_t magFixed, Bool_t phaseFixed) :
36  LauAbsCoeffSet(compName),
37  minMag_(-10.0),
38  maxMag_(+10.0),
39  minPhase_(-LauConstants::threePi),
40  maxPhase_(+LauConstants::threePi),
41  magnitude_(new LauParameter("A",magnitude,minMag_,maxMag_,magFixed)),
42  phase_(new LauParameter("Delta",phase,minPhase_,maxPhase_,phaseFixed))
43 {
44  // Print message
45  cout<<"Set component \""<<this->name()<<"\" to have magnitude = "<<magnitude_->value()<<" and phase = "<<phase_->value()<<"."<<endl;
46 }
47 
49 {
50  minMag_ = rhs.minMag_;
51  maxMag_ = rhs.maxMag_;
52  minPhase_ = rhs.minPhase_;
53  maxPhase_ = rhs.maxPhase_;
54  magnitude_ = rhs.magnitude_->createClone(constFactor);
55  phase_ = rhs.phase_->createClone(constFactor);
56 }
57 
59 {
60  if (&rhs == this) {
61  return *this;
62  }
63  this->name(rhs.name());
64  minMag_ = rhs.minMag_;
65  maxMag_ = rhs.maxMag_;
66  minPhase_ = rhs.minPhase_;
67  maxPhase_ = rhs.maxPhase_;
69  phase_ = rhs.phase_->createClone();
70  return *this;
71 }
72 
73 std::vector<LauParameter*> LauMagPhaseCoeffSet::getParameters()
74 {
75  std::vector<LauParameter*> pars;
76  pars.push_back(magnitude_);
77  pars.push_back(phase_);
78  return pars;
79 }
80 
81 void LauMagPhaseCoeffSet::printTableHeading(std::ostream& stream)
82 {
83  stream<<"\\begin{tabular}{|l|c|c|}"<<endl;
84  stream<<"\\hline"<<endl;
85  stream<<"Component & Magnitude & Phase \\\\"<<endl;
86  stream<<"\\hline"<<endl;
87 }
88 
89 void LauMagPhaseCoeffSet::printTableRow(std::ostream& stream)
90 {
91  LauPrint print;
92  TString resName = this->name();
93  resName = resName.ReplaceAll("_", "\\_");
94  stream<<resName<<" & $";
95  print.printFormat(stream, magnitude_->value());
96  stream<<" \\pm ";
97  print.printFormat(stream, magnitude_->error());
98  stream<<"$ & $";
99  print.printFormat(stream, phase_->value());
100  stream<<" \\pm ";
101  print.printFormat(stream, phase_->error());
102  stream<<"$ \\\\"<<endl;
103 }
104 
106 {
107  if (magnitude_->fixed() == kFALSE) {
108  // Choose a magnitude between 0.0 and 2.0
109  Double_t mag = LauRandom::zeroSeedRandom()->Rndm()*2.0;
110  magnitude_->initValue(mag); magnitude_->value(mag);
111  }
112  if (phase_->fixed() == kFALSE) {
113  // Choose a phase between +- pi
115  phase_->initValue(phase); phase_->value(phase);
116  }
117 }
118 
120 {
121  // retrieve the current values from the parameters
122  Double_t mag = magnitude_->value();
123  Double_t phase = phase_->value();
124  Double_t genPhase = phase_->genValue();
125 
126  // Check whether we have a negative magnitude.
127  // If so make it positive and add pi to the phase.
128  if (mag < 0.0) {
129  mag *= -1.0;
130  phase += LauConstants::pi;
131  }
132 
133  // Check now whether the phase lies in the right range (-pi to pi).
134  Bool_t withinRange(kFALSE);
135  while (withinRange == kFALSE) {
136  if (phase > -LauConstants::pi && phase < LauConstants::pi) {
137  withinRange = kTRUE;
138  } else {
139  // Not within the specified range
140  if (phase > LauConstants::pi) {
141  phase -= LauConstants::twoPi;
142  } else if (phase < -LauConstants::pi) {
143  phase += LauConstants::twoPi;
144  }
145  }
146  }
147 
148  // A further problem can occur when the generated phase is close to -pi or pi.
149  // The phase can wrap over to the other end of the scale -
150  // this leads to artificially large pulls so we wrap it back.
151  Double_t diff = phase - genPhase;
152  if (diff > LauConstants::pi) {
153  phase -= LauConstants::twoPi;
154  } else if (diff < -LauConstants::pi) {
155  phase += LauConstants::twoPi;
156  }
157 
158  // finally store the new values in the parameters
159  // and update the pulls
161  phase_->value(phase); phase_->updatePull();
162 }
163 
165 {
166  LauComplex coeff(magnitude_->value()*TMath::Cos(phase_->value()), magnitude_->value()*TMath::Sin(phase_->value()));
167  return coeff;
168 }
169 
171 {
172  return this->particleCoeff();
173 }
174 
175 void LauMagPhaseCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar )
176 {
177  LauComplex average( coeff );
178  average += coeffBar;
179  average.rescale( 0.5 );
180 
181  magnitude_->value( average.abs() );
182  phase_->value( average.arg() );
183 }
184 
186 {
187  TString parName(this->baseName()); parName += "_ACP";
188  return LauParameter(parName,0.0);
189 }
190 
191 LauAbsCoeffSet* LauMagPhaseCoeffSet::createClone(const TString& newName, Double_t constFactor)
192 {
193  LauAbsCoeffSet* clone = new LauMagPhaseCoeffSet( *this, constFactor );
194  clone->name( newName );
195  return clone;
196 }
197 
LauParameter * magnitude_
The magnitude.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
virtual void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
Double_t maxPhase_
The maximum allowed value for phases.
TRandom * zeroSeedRandom()
Access the singleton random number generator with seed set from machine clock time (within +-1 sec)...
Definition: LauRandom.cc:30
const Double_t twoPi
Two times Pi.
Definition: LauConstants.hh:93
virtual TString baseName() const
Retrieve the base name of the coefficient set.
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
const TString & name() const
The parameter name.
virtual LauComplex particleCoeff()
Retrieve the complex coefficient for a particle.
File containing declaration of LauPrint class.
virtual LauAbsCoeffSet * createClone(const TString &newName, Double_t constFactor=1.0)
Create a clone of the coefficient set.
Class to define various output print commands.
Definition: LauPrint.hh:29
LauMagPhaseCoeffSet(const TString &compName, Double_t magnitude, Double_t phase, Bool_t magFixed, Bool_t phaseFixed)
Constructor.
Double_t minMag_
The minimum allowed value for magnitudes.
virtual LauParameter acp()
Calculate the CP asymmetry.
Bool_t clone() const
Check whether is a clone or not.
const Double_t threePi
Three times Pi.
Definition: LauConstants.hh:95
virtual void printTableRow(std::ostream &stream)
Print the parameters of the complex coefficient as a row in the results table.
File containing declaration of LauParameter class.
Double_t maxMag_
The maximum allowed value for magnitudes.
File containing declaration of LauComplex class.
Double_t error() const
The error on the parameter.
const Double_t pi
Pi.
Definition: LauConstants.hh:89
Class for defining the abstract interface for complex coefficient classes.
Class for defining the fit parameter objects.
Definition: LauParameter.hh:31
File containing LauRandom namespace.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar)
Set the parameters based on the complex coefficients for particles and antiparticles.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
virtual LauComplex antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
LauParameter * phase_
The phase.
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:282
Double_t initValue() const
The initial value of the parameter.
File containing LauConstants namespace.
void printFormat(std::ostream &stream, Double_t value) const
Method to choose the printing format to a specified level of precision.
Definition: LauPrint.cc:32
virtual void printTableHeading(std::ostream &stream)
Print the column headings for a results table.
Class for defining a complex number.
Definition: LauComplex.hh:47
void updatePull()
Call to update the bias and pull values.
Double_t arg() const
Obtain the phase angle of the complex number.
Definition: LauComplex.hh:238
LauParameter * createClone(Double_t constFactor=1.0)
Method to create a clone from the parent parameter using the copy constructor.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
virtual TString name() const
Retrieve the name of the coefficient set.
File containing declaration of LauMagPhaseCoeffSet class.
Double_t value() const
The value of the parameter.
LauMagPhaseCoeffSet & operator=(const LauMagPhaseCoeffSet &rhs)
Copy assignment operator.
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:220
Double_t minPhase_
The minimum allowed value for phases.
Double_t genValue() const
The value generated for the parameter.
Class for defining a complex coefficient using a magnitude and a phase.