laura is hosted by Hepforge, IPPP Durham
Laura++  v1r2
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauMagPhaseCPCoeffSet.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2011 - 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 "LauMagPhaseCPCoeffSet.hh"
26 #include "LauComplex.hh"
27 #include "LauConstants.hh"
28 #include "LauParameter.hh"
29 #include "LauPrint.hh"
30 #include "LauRandom.hh"
31 
32 ClassImp(LauMagPhaseCPCoeffSet)
33 
34 
35 LauMagPhaseCPCoeffSet::LauMagPhaseCPCoeffSet(const TString& compName, Double_t mag, Double_t phase, Double_t magBar, Double_t phaseBar,
36  Bool_t magFixed, Bool_t phaseFixed,Bool_t magBarFixed, Bool_t phaseBarFixed) :
37  LauAbsCoeffSet(compName),
38  minMag_(-40.0),
39  maxMag_(+40.0),
40  minPhase_(-LauConstants::threePi),
41  maxPhase_(+LauConstants::threePi),
42  mag_(new LauParameter("Mag", mag, minMag_, maxMag_, magFixed)),
43  phase_(new LauParameter("Phase", phase, minPhase_, maxPhase_, phaseFixed)),
44  magBar_(new LauParameter("MagBar", magBar, minMag_, maxMag_, magBarFixed)),
45  phaseBar_(new LauParameter("PhaseBar", phaseBar, minPhase_, maxPhase_, phaseBarFixed)),
46  particleCoeff_( mag*TMath::Cos(phase), mag*TMath::Sin(phase) ),
47  antiparticleCoeff_( magBar*TMath::Cos(phaseBar), magBar*TMath::Sin(phaseBar) ),
48  acp_("ACP", (magBar*magBar - mag*mag)/(magBar*magBar + mag*mag), -1.0, 1.0)
49 {
50  // Print message
51  cout<<"Set component \""<<this->name()<<"\" to have mag = "<<mag_->value()<<",\tphase = "<<phase_->value()<<",\t";
52  cout<<"magBar = "<<magBar_->value()<<",\tphaseBar = "<<phaseBar_->value()<<"."<<endl;
53 
54 }
55 
57 {
58  minMag_ = rhs.minMag_;
59  maxMag_ = rhs.maxMag_;
60  minPhase_ = rhs.minPhase_;
61  maxPhase_ = rhs.maxPhase_;
62  mag_ = rhs.mag_->createClone(constFactor);
63  phase_ = rhs.phase_->createClone(constFactor);
64  magBar_ = rhs.magBar_->createClone(constFactor);
65  phaseBar_ = rhs.phaseBar_->createClone(constFactor);
68  acp_ = rhs.acp_;
69 }
70 
72 {
73  if (&rhs != this) {
74  this->name(rhs.name());
75  minMag_ = rhs.minMag_;
76  maxMag_ = rhs.maxMag_;
77  minPhase_ = rhs.minPhase_;
78  maxPhase_ = rhs.maxPhase_;
79  mag_ = rhs.mag_->createClone();
80  phase_ = rhs.phase_->createClone();
81  magBar_ = rhs.magBar_->createClone();
85  acp_ = rhs.acp_;
86  }
87  return *this;
88 }
89 
90 std::vector<LauParameter*> LauMagPhaseCPCoeffSet::getParameters()
91 {
92  std::vector<LauParameter*> pars;
93  pars.push_back(mag_);
94  pars.push_back(phase_);
95  pars.push_back(magBar_);
96  pars.push_back(phaseBar_);
97  return pars;
98 }
99 
101 {
102  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<endl;
103  stream<<"\\hline"<<endl;
104  stream<<"Component & Magnitude & Phase & Magnitude_bar & Phase_bar \\\\"<<endl;
105  stream<<"\\hline"<<endl;
106 }
107 
108 void LauMagPhaseCPCoeffSet::printTableRow(std::ostream& stream)
109 {
110  LauPrint print;
111  TString resName = this->name();
112  resName = resName.ReplaceAll("_", "\\_");
113  stream<<resName<<" & $";
114  print.printFormat(stream, mag_->value());
115  stream<<" \\pm ";
116  print.printFormat(stream, mag_->error());
117  stream<<"$ & $";
118  print.printFormat(stream, phase_->value());
119  stream<<" \\pm ";
120  print.printFormat(stream, phase_->error());
121  stream<<"$ & $";
122  print.printFormat(stream, magBar_->value());
123  stream<<" \\pm ";
124  print.printFormat(stream, magBar_->error());
125  stream<<"$ & $";
126  print.printFormat(stream, phaseBar_->value());
127  stream<<" \\pm ";
128  print.printFormat(stream, phaseBar_->error());
129  stream<<"$ \\\\"<<endl;
130 }
131 
133 {
134  if (mag_->fixed() == kFALSE) {
135  // Choose a value for "magnitude" between 0.0 and 2.0
136  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*2.0;
137  mag_->initValue(value); mag_->value(value);
138  }
139  if (phase_->fixed() == kFALSE) {
140  // Choose a phase between +- pi
142  phase_->initValue(value); phase_->value(value);
143  }
144  if (magBar_->fixed() == kFALSE) {
145  // Choose a value for "magnitude" between 0.0 and 2.0
146  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*2.0;
147  magBar_->initValue(value); magBar_->value(value);
148  }
149  if (phaseBar_->fixed() == kFALSE) {
150  // Choose a phase between +- pi
152  phaseBar_->initValue(value); phaseBar_->value(value);
153  }
154 }
155 
157 {
158  // retrieve the current values from the parameters
159  Double_t mVal= mag_->value();
160  Double_t pVal= phase_->value();
161  Double_t mBarVal= magBar_->value();
162  Double_t pBarVal= phaseBar_->value();
163  Double_t genPhase = phase_->genValue();
164  Double_t genPhaseBar = phaseBar_->genValue();
165 
166  // Check whether we have a negative magnitude.
167  // If so make it positive and add pi to the phase.
168  if (mVal < 0.0) {
169  mVal *= -1.0;
170  pVal += LauConstants::pi;
171  }
172  if (mBarVal < 0.0) {
173  mBarVal *= -1.0;
174  pBarVal += LauConstants::pi;
175  }
176 
177  // Check now whether the phases lies in the right range (-pi to pi).
178  Bool_t pWithinRange(kFALSE);
179  Bool_t pBarWithinRange(kFALSE);
180  while (pWithinRange == kFALSE && pBarWithinRange == kFALSE) {
181  if (pVal > -LauConstants::pi && pVal < LauConstants::pi) {
182  pWithinRange = kTRUE;
183  } else {
184  // Not within the specified range
185  if (pVal > LauConstants::pi) {
186  pVal -= LauConstants::twoPi;
187  } else if (pVal < -LauConstants::pi) {
188  pVal += LauConstants::twoPi;
189  }
190  }
191 
192  if (pBarVal > -LauConstants::pi && pBarVal < LauConstants::pi) {
193  pBarWithinRange = kTRUE;
194  } else {
195  // Not within the specified range
196  if (pBarVal > LauConstants::pi) {
197  pBarVal -= LauConstants::twoPi;
198  } else if (pBarVal < -LauConstants::pi) {
199  pBarVal += LauConstants::twoPi;
200  }
201  }
202  }
203 
204  // A further problem can occur when the generated phase is close to -pi or pi.
205  // The phase can wrap over to the other end of the scale -
206  // this leads to artificially large pulls so we wrap it back.
207  Double_t diff = pVal - genPhase;
208  if (diff > LauConstants::pi) {
209  pVal -= LauConstants::twoPi;
210  } else if (diff < -LauConstants::pi) {
211  pVal += LauConstants::twoPi;
212  }
213 
214  diff = pBarVal - genPhaseBar;
215  if (diff > LauConstants::pi) {
216  pBarVal -= LauConstants::twoPi;
217  } else if (diff < -LauConstants::pi) {
218  pBarVal += LauConstants::twoPi;
219  }
220 
221  // finally store the new values in the parameters
222  // and update the pulls
223  mag_->value(mVal); mag_->updatePull();
224  phase_->value(pVal); phase_->updatePull();
225  magBar_->value(mBarVal); magBar_->updatePull();
226  phaseBar_->value(pBarVal); phaseBar_->updatePull();
227 
228 
229 }
230 
232 {
233  particleCoeff_.setRealImagPart( mag_->value()*TMath::Cos(phase_->value()), mag_->value()*TMath::Sin(phase_->value()) );
234  return particleCoeff_;
235 }
236 
238 {
239  antiparticleCoeff_.setRealImagPart( magBar_->value()*TMath::Cos(phaseBar_->value()), magBar_->value()*TMath::Sin(phaseBar_->value()) );
240  return antiparticleCoeff_;
241 }
242 
243 void LauMagPhaseCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar )
244 {
245  mag_->value( coeff.abs() );
246  phase_->value( coeff.arg() );
247 
248  magBar_->value( coeffBar.abs() );
249  phaseBar_->value( coeffBar.arg() );
250 }
251 
253 {
254  // set the name
255  TString parName(this->baseName()); parName += "_ACP";
256  acp_.name(parName);
257 
258  // work out the ACP value
259 
260  Double_t value(-99.0);
261  value = (magBar_->value()*magBar_->value() - mag_->value()*mag_->value())/(magBar_->value()*magBar_->value() + mag_->value()*mag_->value());
262 
263  // is it fixed?
264  Bool_t fixed = magBar_->fixed() && mag_->fixed();
265  acp_.fixed(fixed);
266 
267  // we can't work out the error without the covariance matrix
268  Double_t error(0.0);
269 
270  // set the value and error
271  acp_.valueAndErrors(value,error);
272 
273  return acp_;
274 }
275 
276 LauAbsCoeffSet* LauMagPhaseCPCoeffSet::createClone(const TString& newName, Double_t constFactor)
277 {
278  LauAbsCoeffSet* clone = new LauMagPhaseCPCoeffSet( *this, constFactor );
279  clone->name( newName );
280  return clone;
281 }
282 
Bool_t fixed() const
Check whether the parameter is fixed or floated.
TRandom * zeroSeedRandom()
Access the singleton random number generator with seed set from machine clock time (within +-1 sec)...
Definition: LauRandom.cc:30
virtual void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
LauParameter acp_
The CP asymmetry.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
const Double_t twoPi
Two times Pi.
Definition: LauConstants.hh:93
File containing declaration of LauMagPhaseCPCoeffSet class.
virtual LauAbsCoeffSet * createClone(const TString &newName, Double_t constFactor=1.0)
Create a clone of the coefficient set.
virtual TString baseName() const
Retrieve the base name of the coefficient set.
LauParameter * phase_
The phase for particles.
const TString & name() const
The parameter name.
Double_t minMag_
The minimum allowed value for magnitudes.
File containing declaration of LauPrint class.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
Double_t maxPhase_
The maximum allowed value for phases.
LauMagPhaseCPCoeffSet & operator=(const LauMagPhaseCPCoeffSet &rhs)
Copy assignment operator.
Class to define various output print commands.
Definition: LauPrint.hh:29
Class for defining a complex coefficient using seperate magnitudes and phases for particles and antip...
Double_t maxMag_
The maximum allowed value for magnitudes.
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.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar)
Set the parameters based on the complex coefficients for particles and antiparticles.
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
void valueAndErrors(Double_t newValue, Double_t newError, Double_t newNegError=0.0, Double_t newPosError=0.0)
Set the value and errors on the parameter.
virtual LauParameter acp()
Calculate the CP asymmetry.
LauParameter * magBar_
The magnitude for antiparticles.
File containing LauRandom namespace.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:311
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
Class for defining a complex number.
Definition: LauComplex.hh:47
void updatePull()
Call to update the bias and pull values.
Double_t minPhase_
The minimum allowed value for phases.
LauParameter * mag_
The magnitude for particles.
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 TString name() const
Retrieve the name of the coefficient set.
LauMagPhaseCPCoeffSet(const TString &compName, Double_t mag, Double_t phase, Double_t magBar, Double_t phaseBar, Bool_t magFixed, Bool_t phaseFixed, Bool_t magBarFixed, Bool_t phaseBarFixed)
Constructor.
virtual void printTableHeading(std::ostream &stream)
Print the column headings for a results table.
Double_t value() const
The value of the parameter.
LauComplex particleCoeff_
The particle complex coefficient.
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:220
LauParameter * phaseBar_
The phase for antiparticles.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
Double_t genValue() const
The value generated for the parameter.