laura is hosted by Hepforge, IPPP Durham
Laura++  v1r2
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  particleCoeff_( (a+b)*TMath::Cos(delta+phi), (a+b)*TMath::Sin(delta+phi) ),
47  antiparticleCoeff_( (a-b)*TMath::Cos(delta-phi), (a-b)*TMath::Sin(delta-phi) ),
48  acp_("ACP", (-2.0*a*b)/(a*a+b*b), -1.0, 1.0, bFixed&&phiFixed)
49 {
50  // Print message
51  cout<<"Set component \""<<this->name()<<"\" to have a-magnitude = "<<a_->value()<<",\tdelta = "<<delta_->value()<<",\t";
52  cout<<"b-magnitude = "<<b_->value()<<",\tphi = "<<phi_->value()<<"."<<endl;
53 }
54 
56 {
57  minMag_ = rhs.minMag_;
58  maxMag_ = rhs.maxMag_;
59  minPhase_ = rhs.minPhase_;
60  maxPhase_ = rhs.maxPhase_;
61  a_ = rhs.a_->createClone(constFactor);
62  b_ = rhs.b_->createClone(constFactor);
63  delta_ = rhs.delta_->createClone(constFactor);
64  phi_ = rhs.phi_->createClone(constFactor);
67  acp_ = rhs.acp_;
68 }
69 
71 {
72  if (&rhs != this) {
73  this->name(rhs.name());
74  minMag_ = rhs.minMag_;
75  maxMag_ = rhs.maxMag_;
76  minPhase_ = rhs.minPhase_;
77  maxPhase_ = rhs.maxPhase_;
78  a_ = rhs.a_->createClone();
79  b_ = rhs.b_->createClone();
80  delta_ = rhs.delta_->createClone();
81  phi_ = rhs.phi_->createClone();
84  acp_ = rhs.acp_;
85  }
86  return *this;
87 }
88 
89 std::vector<LauParameter*> LauCleoCPCoeffSet::getParameters()
90 {
91  std::vector<LauParameter*> pars;
92  pars.push_back(a_);
93  pars.push_back(b_);
94  pars.push_back(delta_);
95  pars.push_back(phi_);
96  return pars;
97 }
98 
99 void LauCleoCPCoeffSet::printTableHeading(std::ostream& stream)
100 {
101  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<endl;
102  stream<<"\\hline"<<endl;
103  stream<<"Component & a-Magnitude & delta & b-Magnitude & phi \\\\"<<endl;
104  stream<<"\\hline"<<endl;
105 }
106 
107 void LauCleoCPCoeffSet::printTableRow(std::ostream& stream)
108 {
109  LauPrint print;
110  TString resName = this->name();
111  resName = resName.ReplaceAll("_", "\\_");
112  stream<<resName<<" & $";
113  print.printFormat(stream, a_->value());
114  stream<<" \\pm ";
115  print.printFormat(stream, a_->error());
116  stream<<"$ & $";
117  print.printFormat(stream, delta_->value());
118  stream<<" \\pm ";
119  print.printFormat(stream, delta_->error());
120  stream<<"$ & $";
121  print.printFormat(stream, b_->value());
122  stream<<" \\pm ";
123  print.printFormat(stream, b_->error());
124  stream<<"$ & $";
125  print.printFormat(stream, phi_->value());
126  stream<<" \\pm ";
127  print.printFormat(stream, phi_->error());
128  stream<<"$ \\\\"<<endl;
129 }
130 
132 {
133  if (a_->fixed() == kFALSE) {
134  // Choose an a-magnitude between 0.0 and 2.0
135  Double_t mag = LauRandom::zeroSeedRandom()->Rndm()*2.0;
136  a_->initValue(mag); a_->value(mag);
137  }
138  if (b_->fixed() == kFALSE) {
139  // Choose a b-magnitude between 0.0 and 0.1
140  Double_t mag = LauRandom::zeroSeedRandom()->Rndm()*0.1;
141  b_->initValue(mag); b_->value(mag);
142  }
143  if (delta_->fixed() == kFALSE) {
144  // Choose a phase between +- pi
146  delta_->initValue(phase); delta_->value(phase);
147  }
148  if (phi_->fixed() == kFALSE) {
149  // Choose a phase between +- pi
151  phi_->initValue(phase); phi_->value(phase);
152  }
153 }
154 
156 {
157  // retrieve the current values from the parameters
158  Double_t aVal = a_->value();
159  Double_t bVal = b_->value();
160  Double_t deltaVal = delta_->value();
161  Double_t phiVal = phi_->value();
162  Double_t genDelta = delta_->genValue();
163  Double_t genPhi = phi_->genValue();
164 
165  // Check whether we have a negative "a" magnitude.
166  // If so make it positive and add pi to the "delta" phase.
167  if (aVal < 0.0) {
168  aVal *= -1.0;
169  bVal *= -1.0;
170  deltaVal += LauConstants::pi;
171  }
172 
173  // Check now whether the phases lies in the right range (-pi to pi).
174  Bool_t deltaWithinRange(kFALSE);
175  Bool_t phiWithinRange(kFALSE);
176  while (deltaWithinRange == kFALSE && phiWithinRange == kFALSE) {
177  if (deltaVal > -LauConstants::pi && deltaVal < LauConstants::pi) {
178  deltaWithinRange = kTRUE;
179  } else {
180  // Not within the specified range
181  if (deltaVal > LauConstants::pi) {
182  deltaVal -= LauConstants::twoPi;
183  } else if (deltaVal < -LauConstants::pi) {
184  deltaVal += LauConstants::twoPi;
185  }
186  }
187 
188  if (phiVal > -LauConstants::pi && phiVal < LauConstants::pi) {
189  phiWithinRange = kTRUE;
190  } else {
191  // Not within the specified range
192  if (phiVal > LauConstants::pi) {
193  phiVal -= LauConstants::twoPi;
194  } else if (phiVal < -LauConstants::pi) {
195  phiVal += LauConstants::twoPi;
196  }
197  }
198  }
199 
200  // A further problem can occur when the generated phase is close to -pi or pi.
201  // The phase can wrap over to the other end of the scale -
202  // this leads to artificially large pulls so we wrap it back.
203  Double_t diff = deltaVal - genDelta;
204  if (diff > LauConstants::pi) {
205  deltaVal -= LauConstants::twoPi;
206  } else if (diff < -LauConstants::pi) {
207  deltaVal += LauConstants::twoPi;
208  }
209 
210  diff = phiVal - genPhi;
211  if (diff > LauConstants::pi) {
212  phiVal -= LauConstants::twoPi;
213  } else if (diff < -LauConstants::pi) {
214  phiVal += LauConstants::twoPi;
215  }
216 
217  // finally store the new values in the parameters
218  // and update the pulls
219  a_->value(aVal); a_->updatePull();
220  b_->value(bVal); b_->updatePull();
221  delta_->value(deltaVal); delta_->updatePull();
222  phi_->value(phiVal); phi_->updatePull();
223 }
224 
226 {
227  Double_t magnitude = a_->value() + b_->value();
228  Double_t phase = delta_->value() + phi_->value();
229  particleCoeff_.setRealImagPart(magnitude*TMath::Cos(phase), magnitude*TMath::Sin(phase));
230  return particleCoeff_;
231 }
232 
234 {
235  Double_t magnitude = a_->value() - b_->value();
236  Double_t phase = delta_->value() - phi_->value();
237  antiparticleCoeff_.setRealImagPart(magnitude*TMath::Cos(phase), magnitude*TMath::Sin(phase));
238  return antiparticleCoeff_;
239 }
240 
241 void LauCleoCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar )
242 {
243  Double_t mag = coeff.abs();
244  Double_t magBar = coeffBar.abs();
245  Double_t phase = coeff.arg();
246  Double_t phaseBar = coeffBar.arg();
247 
248  a_->value( 0.5 * ( mag + magBar ) );
249  delta_->value( 0.5 * ( phase + phaseBar ) );
250 
251  b_->value( 0.5 * ( mag - magBar ) );
252  phi_->value( 0.5 * ( phase - phaseBar ) );
253 }
254 
256 {
257  // set the name
258  TString parName(this->baseName()); parName += "_ACP";
259  acp_.name(parName);
260 
261  // work out the ACP value
262  Double_t numer = -2.0*a_->value()*b_->value();
263  Double_t denom = a_->value()*a_->value()+b_->value()*b_->value();
264  Double_t value = numer/denom;
265 
266  // is it fixed?
267  Bool_t fixed = a_->fixed() && b_->fixed();
268  acp_.fixed(fixed);
269 
270  // we can't work out the error without the covariance matrix
271  Double_t error(0.0);
272 
273  // set the value and error
274  acp_.valueAndErrors(value,error);
275 
276  return acp_;
277 }
278 
279 LauAbsCoeffSet* LauCleoCPCoeffSet::createClone(const TString& newName, Double_t constFactor)
280 {
281  LauAbsCoeffSet* clone = new LauCleoCPCoeffSet( *this, constFactor );
282  clone->name( newName );
283  return clone;
284 }
285 
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
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
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.
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.
LauComplex particleCoeff_
The particle complex coefficient.
LauParameter * phi_
The weak phase.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
Bool_t clone() const
Check whether is a clone or not.
virtual LauParameter acp()
Calculate the CP asymmetry.
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.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:311
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 const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
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.