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