laura is hosted by Hepforge, IPPP Durham
Laura++  v1r2
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  coeff_(magnitude*TMath::Cos(phase), magnitude*TMath::Sin(phase))
44 {
45  // Print message
46  cout<<"Set component \""<<this->name()<<"\" to have magnitude = "<<magnitude_->value()<<" and phase = "<<phase_->value()<<"."<<endl;
47 }
48 
50 {
51  minMag_ = rhs.minMag_;
52  maxMag_ = rhs.maxMag_;
53  minPhase_ = rhs.minPhase_;
54  maxPhase_ = rhs.maxPhase_;
55  magnitude_ = rhs.magnitude_->createClone(constFactor);
56  phase_ = rhs.phase_->createClone(constFactor);
57  coeff_ = rhs.coeff_;
58 }
59 
61 {
62  if (&rhs != this) {
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  coeff_ = rhs.coeff_;
71  }
72  return *this;
73 }
74 
75 std::vector<LauParameter*> LauMagPhaseCoeffSet::getParameters()
76 {
77  std::vector<LauParameter*> pars;
78  pars.push_back(magnitude_);
79  pars.push_back(phase_);
80  return pars;
81 }
82 
83 void LauMagPhaseCoeffSet::printTableHeading(std::ostream& stream)
84 {
85  stream<<"\\begin{tabular}{|l|c|c|}"<<endl;
86  stream<<"\\hline"<<endl;
87  stream<<"Component & Magnitude & Phase \\\\"<<endl;
88  stream<<"\\hline"<<endl;
89 }
90 
91 void LauMagPhaseCoeffSet::printTableRow(std::ostream& stream)
92 {
93  LauPrint print;
94  TString resName = this->name();
95  resName = resName.ReplaceAll("_", "\\_");
96  stream<<resName<<" & $";
97  print.printFormat(stream, magnitude_->value());
98  stream<<" \\pm ";
99  print.printFormat(stream, magnitude_->error());
100  stream<<"$ & $";
101  print.printFormat(stream, phase_->value());
102  stream<<" \\pm ";
103  print.printFormat(stream, phase_->error());
104  stream<<"$ \\\\"<<endl;
105 }
106 
108 {
109  if (magnitude_->fixed() == kFALSE) {
110  // Choose a magnitude between 0.0 and 2.0
111  Double_t mag = LauRandom::zeroSeedRandom()->Rndm()*2.0;
112  magnitude_->initValue(mag); magnitude_->value(mag);
113  }
114  if (phase_->fixed() == kFALSE) {
115  // Choose a phase between +- pi
117  phase_->initValue(phase); phase_->value(phase);
118  }
119 }
120 
122 {
123  // retrieve the current values from the parameters
124  Double_t mag = magnitude_->value();
125  Double_t phase = phase_->value();
126  Double_t genPhase = phase_->genValue();
127 
128  // Check whether we have a negative magnitude.
129  // If so make it positive and add pi to the phase.
130  if (mag < 0.0) {
131  mag *= -1.0;
132  phase += LauConstants::pi;
133  }
134 
135  // Check now whether the phase lies in the right range (-pi to pi).
136  Bool_t withinRange(kFALSE);
137  while (withinRange == kFALSE) {
138  if (phase > -LauConstants::pi && phase < LauConstants::pi) {
139  withinRange = kTRUE;
140  } else {
141  // Not within the specified range
142  if (phase > LauConstants::pi) {
143  phase -= LauConstants::twoPi;
144  } else if (phase < -LauConstants::pi) {
145  phase += LauConstants::twoPi;
146  }
147  }
148  }
149 
150  // A further problem can occur when the generated phase is close to -pi or pi.
151  // The phase can wrap over to the other end of the scale -
152  // this leads to artificially large pulls so we wrap it back.
153  Double_t diff = phase - genPhase;
154  if (diff > LauConstants::pi) {
155  phase -= LauConstants::twoPi;
156  } else if (diff < -LauConstants::pi) {
157  phase += LauConstants::twoPi;
158  }
159 
160  // finally store the new values in the parameters
161  // and update the pulls
163  phase_->value(phase); phase_->updatePull();
164 }
165 
167 {
168  coeff_.setRealImagPart(magnitude_->value()*TMath::Cos(phase_->value()), magnitude_->value()*TMath::Sin(phase_->value()));
169  return coeff_;
170 }
171 
173 {
174  return this->particleCoeff();
175 }
176 
177 void LauMagPhaseCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar )
178 {
179  LauComplex average( coeff );
180  average += coeffBar;
181  average.rescale( 0.5 );
182 
183  magnitude_->value( average.abs() );
184  phase_->value( average.arg() );
185 }
186 
188 {
189  TString parName(this->baseName()); parName += "_ACP";
190  return LauParameter(parName,0.0);
191 }
192 
193 LauAbsCoeffSet* LauMagPhaseCoeffSet::createClone(const TString& newName, Double_t constFactor)
194 {
195  LauAbsCoeffSet* clone = new LauMagPhaseCoeffSet( *this, constFactor );
196  clone->name( newName );
197  return clone;
198 }
199 
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.
File containing declaration of LauPrint class.
virtual LauAbsCoeffSet * createClone(const TString &newName, Double_t constFactor=1.0)
Create a clone of the coefficient set.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
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.
LauComplex coeff_
The complex coefficient.
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.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:311
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.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
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.