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