laura is hosted by Hepforge, IPPP Durham
Laura++  v1r0
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauCleoCPCoeffSet.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 "LauCleoCPCoeffSet.hh"
26 #include "LauComplex.hh"
27 #include "LauConstants.hh"
28 #include "LauParameter.hh"
29 #include "LauPrint.hh"
30 #include "LauRandom.hh"
31 
32 ClassImp(LauCleoCPCoeffSet)
33 
34 
35 LauCleoCPCoeffSet::LauCleoCPCoeffSet(const TString& compName, Double_t a, Double_t delta, Double_t b, Double_t phi,
36  Bool_t aFixed, Bool_t deltaFixed, Bool_t bFixed, Bool_t phiFixed) :
37  LauAbsCoeffSet(compName),
38  minMag_(-10.0),
39  maxMag_(+10.0),
40  minPhase_(-LauConstants::threePi),
41  maxPhase_(+LauConstants::threePi),
42  a_(new LauParameter("A", a, minMag_, maxMag_, aFixed)),
43  b_(new LauParameter("B", b, minMag_, maxMag_, bFixed)),
44  delta_(new LauParameter("Delta", delta, minPhase_, maxPhase_, deltaFixed)),
45  phi_(new LauParameter("Phi", phi, minPhase_, maxPhase_, phiFixed)),
46  acp_("ACP", (-2.0*a*b)/(a*a+b*b), -1.0, 1.0, bFixed&&phiFixed)
47 {
48  // Print message
49  cout<<"Set component \""<<this->name()<<"\" to have a-magnitude = "<<a_->value()<<",\tdelta = "<<delta_->value()<<",\t";
50  cout<<"b-magnitude = "<<b_->value()<<",\tphi = "<<phi_->value()<<"."<<endl;
51 }
52 
54 {
55  minMag_ = rhs.minMag_;
56  maxMag_ = rhs.maxMag_;
57  minPhase_ = rhs.minPhase_;
58  maxPhase_ = rhs.maxPhase_;
59  a_ = rhs.a_->createClone(constFactor);
60  b_ = rhs.b_->createClone(constFactor);
61  delta_ = rhs.delta_->createClone(constFactor);
62  phi_ = rhs.phi_->createClone(constFactor);
63  acp_ = rhs.acp_;
64 }
65 
67 {
68  if (&rhs == this) {
69  return *this;
70  }
71  this->name(rhs.name());
72  minMag_ = rhs.minMag_;
73  maxMag_ = rhs.maxMag_;
74  minPhase_ = rhs.minPhase_;
75  maxPhase_ = rhs.maxPhase_;
76  a_ = rhs.a_->createClone();
77  b_ = rhs.b_->createClone();
78  delta_ = rhs.delta_->createClone();
79  phi_ = rhs.phi_->createClone();
80  acp_ = rhs.acp_;
81  return *this;
82 }
83 
84 std::vector<LauParameter*> LauCleoCPCoeffSet::getParameters()
85 {
86  std::vector<LauParameter*> pars;
87  pars.push_back(a_);
88  pars.push_back(b_);
89  pars.push_back(delta_);
90  pars.push_back(phi_);
91  return pars;
92 }
93 
94 void LauCleoCPCoeffSet::printTableHeading(std::ostream& stream)
95 {
96  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<endl;
97  stream<<"\\hline"<<endl;
98  stream<<"Component & a-Magnitude & delta & b-Magnitude & phi \\\\"<<endl;
99  stream<<"\\hline"<<endl;
100 }
101 
102 void LauCleoCPCoeffSet::printTableRow(std::ostream& stream)
103 {
104  LauPrint print;
105  TString resName = this->name();
106  resName = resName.ReplaceAll("_", "\\_");
107  stream<<resName<<" & $";
108  print.printFormat(stream, a_->value());
109  stream<<" \\pm ";
110  print.printFormat(stream, a_->error());
111  stream<<"$ & $";
112  print.printFormat(stream, delta_->value());
113  stream<<" \\pm ";
114  print.printFormat(stream, delta_->error());
115  stream<<"$ & $";
116  print.printFormat(stream, b_->value());
117  stream<<" \\pm ";
118  print.printFormat(stream, b_->error());
119  stream<<"$ & $";
120  print.printFormat(stream, phi_->value());
121  stream<<" \\pm ";
122  print.printFormat(stream, phi_->error());
123  stream<<"$ \\\\"<<endl;
124 }
125 
127 {
128  if (a_->fixed() == kFALSE) {
129  // Choose an a-magnitude between 0.0 and 2.0
130  Double_t mag = LauRandom::zeroSeedRandom()->Rndm()*2.0;
131  a_->initValue(mag); a_->value(mag);
132  }
133  if (b_->fixed() == kFALSE) {
134  // Choose a b-magnitude between 0.0 and 0.1
135  Double_t mag = LauRandom::zeroSeedRandom()->Rndm()*0.1;
136  b_->initValue(mag); b_->value(mag);
137  }
138  if (delta_->fixed() == kFALSE) {
139  // Choose a phase between +- pi
141  delta_->initValue(phase); delta_->value(phase);
142  }
143  if (phi_->fixed() == kFALSE) {
144  // Choose a phase between +- pi
146  phi_->initValue(phase); phi_->value(phase);
147  }
148 }
149 
151 {
152  // retrieve the current values from the parameters
153  Double_t aVal = a_->value();
154  Double_t bVal = b_->value();
155  Double_t deltaVal = delta_->value();
156  Double_t phiVal = phi_->value();
157  Double_t genDelta = delta_->genValue();
158  Double_t genPhi = phi_->genValue();
159 
160  // Check whether we have a negative "a" magnitude.
161  // If so make it positive and add pi to the "delta" phase.
162  if (aVal < 0.0) {
163  aVal *= -1.0;
164  bVal *= -1.0;
165  deltaVal += LauConstants::pi;
166  }
167 
168  // Check now whether the phases lies in the right range (-pi to pi).
169  Bool_t deltaWithinRange(kFALSE);
170  Bool_t phiWithinRange(kFALSE);
171  while (deltaWithinRange == kFALSE && phiWithinRange == kFALSE) {
172  if (deltaVal > -LauConstants::pi && deltaVal < LauConstants::pi) {
173  deltaWithinRange = kTRUE;
174  } else {
175  // Not within the specified range
176  if (deltaVal > LauConstants::pi) {
177  deltaVal -= LauConstants::twoPi;
178  } else if (deltaVal < -LauConstants::pi) {
179  deltaVal += LauConstants::twoPi;
180  }
181  }
182 
183  if (phiVal > -LauConstants::pi && phiVal < LauConstants::pi) {
184  phiWithinRange = kTRUE;
185  } else {
186  // Not within the specified range
187  if (phiVal > LauConstants::pi) {
188  phiVal -= LauConstants::twoPi;
189  } else if (phiVal < -LauConstants::pi) {
190  phiVal += LauConstants::twoPi;
191  }
192  }
193  }
194 
195  // A further problem can occur when the generated phase is close to -pi or pi.
196  // The phase can wrap over to the other end of the scale -
197  // this leads to artificially large pulls so we wrap it back.
198  Double_t diff = deltaVal - genDelta;
199  if (diff > LauConstants::pi) {
200  deltaVal -= LauConstants::twoPi;
201  } else if (diff < -LauConstants::pi) {
202  deltaVal += LauConstants::twoPi;
203  }
204 
205  diff = phiVal - genPhi;
206  if (diff > LauConstants::pi) {
207  phiVal -= LauConstants::twoPi;
208  } else if (diff < -LauConstants::pi) {
209  phiVal += LauConstants::twoPi;
210  }
211 
212  // finally store the new values in the parameters
213  // and update the pulls
214  a_->value(aVal); a_->updatePull();
215  b_->value(bVal); b_->updatePull();
216  delta_->value(deltaVal); delta_->updatePull();
217  phi_->value(phiVal); phi_->updatePull();
218 }
219 
221 {
222  Double_t magnitude = a_->value() + b_->value();
223  Double_t phase = delta_->value() + phi_->value();
224  LauComplex coeff(magnitude*TMath::Cos(phase), magnitude*TMath::Sin(phase));
225  return coeff;
226 }
227 
229 {
230  Double_t magnitude = a_->value() - b_->value();
231  Double_t phase = delta_->value() - phi_->value();
232  LauComplex coeff(magnitude*TMath::Cos(phase), magnitude*TMath::Sin(phase));
233  return coeff;
234 }
235 
236 void LauCleoCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar )
237 {
238  Double_t mag = coeff.abs();
239  Double_t magBar = coeffBar.abs();
240  Double_t phase = coeff.arg();
241  Double_t phaseBar = coeffBar.arg();
242 
243  a_->value( 0.5 * ( mag + magBar ) );
244  delta_->value( 0.5 * ( phase + phaseBar ) );
245 
246  b_->value( 0.5 * ( mag - magBar ) );
247  phi_->value( 0.5 * ( phase - phaseBar ) );
248 }
249 
251 {
252  // set the name
253  TString parName(this->baseName()); parName += "_ACP";
254  acp_.name(parName);
255 
256  // work out the ACP value
257  Double_t numer = -2.0*a_->value()*b_->value();
258  Double_t denom = a_->value()*a_->value()+b_->value()*b_->value();
259  Double_t value = numer/denom;
260 
261  // is it fixed?
262  Bool_t fixed = a_->fixed() && b_->fixed();
263  acp_.fixed(fixed);
264 
265  // we can't work out the error without the covariance matrix
266  Double_t error(0.0);
267 
268  // set the value and error
269  acp_.valueAndErrors(value,error);
270 
271  return acp_;
272 }
273 
274 LauAbsCoeffSet* LauCleoCPCoeffSet::createClone(const TString& newName, Double_t constFactor)
275 {
276  LauAbsCoeffSet* clone = new LauCleoCPCoeffSet( *this, constFactor );
277  clone->name( newName );
278  return clone;
279 }
280 
LauParameter acp_
The CP asymmetry.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
File containing declaration of LauCleoCPCoeffSet class.
virtual void printTableHeading(std::ostream &stream)
Print the column headings for a results table.
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.
virtual void printTableRow(std::ostream &stream)
Print the parameters of the complex coefficient as a row in the results table.
LauCleoCPCoeffSet & operator=(const LauCleoCPCoeffSet &rhs)
Copy assignment operator.
Double_t minPhase_
The minimum allowed value for phases.
const TString & name() const
The parameter name.
Double_t minMag_
The minimum allowed value for magnitudes.
LauParameter * delta_
The strong phase.
virtual LauComplex antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
File containing declaration of LauPrint class.
LauCleoCPCoeffSet(const TString &compName, Double_t a, Double_t delta, Double_t b, Double_t phi, Bool_t aFixed, Bool_t deltaFixed, Bool_t bFixed, Bool_t phiFixed)
Constructor.
Double_t maxMag_
The maximum allowed value for magnitudes.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar)
Set the parameters based on the complex coefficients for particles and antiparticles.
Class to define various output print commands.
Definition: LauPrint.hh:29
Class for defining a complex coefficient using the Cleo CP convention.
LauParameter * phi_
The weak phase.
Bool_t clone() const
Check whether is a clone or not.
virtual LauParameter acp()
Calculate the CP asymmetry.
virtual LauComplex particleCoeff()
Retrieve the complex coefficient for a particle.
const Double_t threePi
Three times Pi.
Definition: LauConstants.hh:95
Double_t maxPhase_
The maximum allowed value for phases.
File containing declaration of LauParameter class.
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.
LauParameter * b_
The magnitude b.
File containing LauRandom namespace.
virtual LauAbsCoeffSet * createClone(const TString &newName, Double_t constFactor=1.0)
Create a clone of the coefficient set.
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 randomiseInitValues()
Randomise the starting values of the parameters for a fit.
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 TString name() const
Retrieve the name of the coefficient set.
Double_t value() const
The value of the parameter.
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:220
virtual void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
Double_t genValue() const
The value generated for the parameter.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
LauParameter * a_
The magnitude a.