laura is hosted by Hepforge, IPPP Durham
Laura++  v3r1
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 
19 #include "TMath.h"
20 #include "TRandom.h"
21 
22 #include "LauComplex.hh"
23 #include "LauConstants.hh"
24 #include "LauBelleCPCoeffSet.hh"
25 #include "LauParameter.hh"
26 #include "LauPrint.hh"
27 #include "LauRandom.hh"
28 
30 
31 
32 LauBelleCPCoeffSet::LauBelleCPCoeffSet(const TString& compName, Double_t a, Double_t delta, Double_t b, Double_t phi,
33  Bool_t aFixed, Bool_t deltaFixed, Bool_t bFixed, Bool_t phiFixed, Bool_t bSecondStage, Bool_t phiSecondStage) :
34  LauAbsCoeffSet(compName),
35  a_(new LauParameter("A", a, minMagnitude_, maxMagnitude_, aFixed)),
36  b_(new LauParameter("B", b, minMagnitude_, maxMagnitude_, bFixed)),
37  delta_(new LauParameter("Delta", delta, minPhase_, maxPhase_, deltaFixed)),
38  phi_(new LauParameter("Phi", phi, minPhase_, maxPhase_, phiFixed)),
39  particleCoeff_(0.0,0.0),
40  antiparticleCoeff_(0.0,0.0),
41  acp_("ACP", (-2.0*b*TMath::Cos(phi))/(1.0+b*b), -1.0, 1.0, bFixed&&phiFixed)
42 {
43  if (bSecondStage && !bFixed) {
44  b_->secondStage(kTRUE);
45  b_->initValue(0.0);
46  }
47  if (phiSecondStage && !phiFixed) {
48  phi_->secondStage(kTRUE);
49  phi_->initValue(0.0);
50  }
51 }
52 
53 LauBelleCPCoeffSet::LauBelleCPCoeffSet(const LauBelleCPCoeffSet& rhs, CloneOption cloneOption, Double_t constFactor) : LauAbsCoeffSet(rhs.name()),
54  a_(0),
55  b_(0),
56  delta_(0),
57  phi_(0),
58  particleCoeff_( rhs.particleCoeff_ ),
59  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
60  acp_( rhs.acp_ )
61 {
62  if ( cloneOption == All || cloneOption == TieMagnitude ) {
63  a_ = rhs.a_->createClone(constFactor);
64  } else {
65  a_ = new LauParameter("A", rhs.a_->value(), minMagnitude_, maxMagnitude_, rhs.a_->fixed());
66  if ( rhs.a_->blind() ) {
67  const LauBlind* blinder = rhs.a_->blinder();
68  a_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
69  }
70  }
71 
72  if ( cloneOption == All || cloneOption == TieCPPars ) {
73  b_ = rhs.b_->createClone(constFactor);
74  } else {
75  b_ = new LauParameter("B", rhs.b_->value(), minMagnitude_, maxMagnitude_, rhs.b_->fixed());
76  if ( rhs.b_->blind() ) {
77  const LauBlind* blinder = rhs.b_->blinder();
78  b_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
79  }
80  }
81 
82  if ( cloneOption == All || cloneOption == TiePhase ) {
83  delta_ = rhs.delta_->createClone(constFactor);
84  } else {
85  delta_ = new LauParameter("Delta", rhs.delta_->value(), minPhase_, maxPhase_, rhs.delta_->fixed());
86  if ( rhs.delta_->blind() ) {
87  const LauBlind* blinder = rhs.delta_->blinder();
88  delta_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
89  }
90  }
91 
92  if ( cloneOption == All || cloneOption == TieCPPars ) {
93  phi_ = rhs.phi_->createClone(constFactor);
94  } else {
95  phi_ = new LauParameter("Phi", rhs.phi_->value(), minPhase_, maxPhase_, rhs.phi_->fixed());
96  if ( rhs.phi_->blind() ) {
97  const LauBlind* blinder = rhs.phi_->blinder();
98  phi_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
99  }
100  }
101 }
102 
103 std::vector<LauParameter*> LauBelleCPCoeffSet::getParameters()
104 {
105  std::vector<LauParameter*> pars;
106  pars.push_back(a_);
107  pars.push_back(b_);
108  pars.push_back(delta_);
109  pars.push_back(phi_);
110  return pars;
111 }
112 
114 {
115  std::cout<<"INFO in LauBelleCPCoeffSet::printParValues : Component \""<<this->name()<<"\" has ";
116  std::cout<<"a-magnitude = "<<a_->value()<<",\t";
117  std::cout<<"delta = "<<delta_->value()<<",\t";
118  std::cout<<"b-magnitude = "<<b_->value()<<",\t";
119  std::cout<<"phi = "<<phi_->value()<<"."<<std::endl;
120 }
121 
122 void LauBelleCPCoeffSet::printTableHeading(std::ostream& stream) const
123 {
124  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<std::endl;
125  stream<<"\\hline"<<std::endl;
126  stream<<"Component & a-Magnitude & delta & b-Magnitude & phi \\\\"<<std::endl;
127  stream<<"\\hline"<<std::endl;
128 }
129 
130 void LauBelleCPCoeffSet::printTableRow(std::ostream& stream) const
131 {
132  LauPrint print;
133  TString resName = this->name();
134  resName = resName.ReplaceAll("_", "\\_");
135  stream<<resName<<" & $";
136  print.printFormat(stream, a_->value());
137  stream<<" \\pm ";
138  print.printFormat(stream, a_->error());
139  stream<<"$ & $";
140  print.printFormat(stream, delta_->value());
141  stream<<" \\pm ";
142  print.printFormat(stream, delta_->error());
143  stream<<"$ & $";
144  print.printFormat(stream, b_->value());
145  stream<<" \\pm ";
146  print.printFormat(stream, b_->error());
147  stream<<"$ & $";
148  print.printFormat(stream, phi_->value());
149  stream<<" \\pm ";
150  print.printFormat(stream, phi_->error());
151  stream<<"$ \\\\"<<std::endl;
152 }
153 
155 {
156  if (a_->fixed() == kFALSE) {
157  // Choose an a-magnitude between 0.0 and 2.0
158  Double_t mag = LauRandom::zeroSeedRandom()->Rndm()*2.0;
159  a_->initValue(mag); a_->value(mag);
160  }
161  if (b_->fixed() == kFALSE && b_->secondStage() == kFALSE) {
162  // Choose a b-magnitude between 0.0 and 0.1
163  Double_t mag = LauRandom::zeroSeedRandom()->Rndm()*0.1;
164  b_->initValue(mag); b_->value(mag);
165  }
166  if (delta_->fixed() == kFALSE) {
167  // Choose a phase between +- pi
169  delta_->initValue(phase); delta_->value(phase);
170  }
171  if (phi_->fixed() == kFALSE && phi_->secondStage() == kFALSE) {
172  // Choose a phase between +- pi
174  phi_->initValue(phase); phi_->value(phase);
175  }
176 }
177 
179 {
180  // retrieve the current values from the parameters
181  Double_t aVal = a_->value();
182  Double_t bVal = b_->value();
183  Double_t deltaVal = delta_->value();
184  Double_t phiVal = phi_->value();
185  Double_t genDelta = delta_->genValue();
186  Double_t genPhi = phi_->genValue();
187 
188  // Check whether we have a negative "a" magnitude.
189  // If so make it positive and add pi to the "delta" phase.
190  if (aVal < 0.0) {
191  aVal *= -1.0;
192  deltaVal += LauConstants::pi;
193  }
194 
195  // Check whether we have a negative "b" magnitude.
196  // If so make it positive and add pi to the "phi" phase.
197  if (bVal < 0.0) {
198  bVal *= -1.0;
199  phiVal += LauConstants::pi;
200  }
201 
202  // Check now whether the phases lies in the right range (-pi to pi).
203  Bool_t deltaWithinRange(kFALSE);
204  Bool_t phiWithinRange(kFALSE);
205  while (deltaWithinRange == kFALSE && phiWithinRange == kFALSE) {
206  if (deltaVal > -LauConstants::pi && deltaVal < LauConstants::pi) {
207  deltaWithinRange = kTRUE;
208  } else {
209  // Not within the specified range
210  if (deltaVal > LauConstants::pi) {
211  deltaVal -= LauConstants::twoPi;
212  } else if (deltaVal < -LauConstants::pi) {
213  deltaVal += LauConstants::twoPi;
214  }
215  }
216 
217  if (phiVal > -LauConstants::pi && phiVal < LauConstants::pi) {
218  phiWithinRange = kTRUE;
219  } else {
220  // Not within the specified range
221  if (phiVal > LauConstants::pi) {
222  phiVal -= LauConstants::twoPi;
223  } else if (phiVal < -LauConstants::pi) {
224  phiVal += LauConstants::twoPi;
225  }
226  }
227  }
228 
229  // A further problem can occur when the generated phase is close to -pi or pi.
230  // The phase can wrap over to the other end of the scale -
231  // this leads to artificially large pulls so we wrap it back.
232  Double_t diff = deltaVal - genDelta;
233  if (diff > LauConstants::pi) {
234  deltaVal -= LauConstants::twoPi;
235  } else if (diff < -LauConstants::pi) {
236  deltaVal += LauConstants::twoPi;
237  }
238 
239  diff = phiVal - genPhi;
240  if (diff > LauConstants::pi) {
241  phiVal -= LauConstants::twoPi;
242  } else if (diff < -LauConstants::pi) {
243  phiVal += LauConstants::twoPi;
244  }
245 
246  // finally store the new values in the parameters
247  // and update the pulls
248  a_->value(aVal); a_->updatePull();
249  b_->value(bVal); b_->updatePull();
250  delta_->value(deltaVal); delta_->updatePull();
251  phi_->value(phiVal); phi_->updatePull();
252 }
253 
255 {
256  LauComplex aTerm(a_->unblindValue()*TMath::Cos(delta_->unblindValue()), a_->unblindValue()*TMath::Sin(delta_->unblindValue()));
257  LauComplex bTerm(b_->unblindValue()*TMath::Cos(phi_->unblindValue()), b_->unblindValue()*TMath::Sin(phi_->unblindValue()));
259  particleCoeff_ += bTerm;
260  particleCoeff_ *= aTerm;
261  return particleCoeff_;
262 }
263 
265 {
266  LauComplex aTerm(a_->unblindValue()*TMath::Cos(delta_->unblindValue()), a_->unblindValue()*TMath::Sin(delta_->unblindValue()));
267  LauComplex bTerm(b_->unblindValue()*TMath::Cos(phi_->unblindValue()), b_->unblindValue()*TMath::Sin(phi_->unblindValue()));
269  antiparticleCoeff_ -= bTerm;
270  antiparticleCoeff_ *= aTerm;
271  return antiparticleCoeff_;
272 }
273 
274 void LauBelleCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
275 {
276  LauComplex sum = coeff + coeffBar;
277  LauComplex diff = coeff - coeffBar;
278  LauComplex ratio = diff / sum;
279 
280  Double_t aVal( 0.5 * sum.abs() );
281  Double_t deltaVal( sum.arg() );
282  Double_t bVal( ratio.abs() );
283  Double_t phiVal( ratio.arg() );
284 
285  a_->value( aVal );
286  delta_->value( deltaVal );
287  b_->value( bVal );
288  phi_->value( phiVal );
289 
290  if ( init ) {
291  a_->genValue( aVal );
292  delta_->genValue( deltaVal );
293  b_->genValue( bVal );
294  phi_->genValue( phiVal );
295 
296  a_->initValue( aVal );
297  delta_->initValue( deltaVal );
298  b_->initValue( bVal );
299  phi_->initValue( phiVal );
300  }
301 }
302 
304 {
305  // set the name
306  TString parName(this->baseName()); parName += "_ACP";
307  acp_.name(parName);
308 
309  // work out the ACP value
310  Double_t value = (-2.0*b_->value()*TMath::Cos(phi_->value()))/(1.0+b_->value()*b_->value());
311 
312  // is it fixed?
313  Bool_t fixed = b_->fixed() && phi_->fixed();
314  acp_.fixed(fixed);
315 
316  // we can't work out the error without the covariance matrix
317  Double_t error(0.0);
318 
319  // set the value and error
320  acp_.valueAndErrors(value,error);
321 
322  return acp_;
323 }
324 
325 LauAbsCoeffSet* LauBelleCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
326 {
327  LauAbsCoeffSet* clone(0);
328  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude || cloneOption == TieCPPars ) {
329  clone = new LauBelleCPCoeffSet( *this, cloneOption, constFactor );
330  clone->name( newName );
331  } else {
332  std::cerr << "ERROR in LauBelleCPCoeffSet::createClone : Invalid clone option" << std::endl;
333  }
334  return clone;
335 }
336 
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
static Double_t maxPhase_
Maximum allowed value of phase parameters.
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
const Double_t twoPi
Two times Pi.
Definition: LauConstants.hh:93
ClassImp(LauAbsCoeffSet)
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
const TString & name() const
The parameter name.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
File containing declaration of LauPrint class.
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, Bool_t bSecondStage=kFALSE, Bool_t phiSecondStage=kFALSE)
Constructor.
Class to define various output print commands.
Definition: LauPrint.hh:29
LauParameter * delta_
The strong phase.
CloneOption
Options for cloning operation.
Bool_t clone() const
Check whether is a clone or not.
Bool_t blind() const
The blinding state.
LauParameter * phi_
The weak phase.
LauParameter * a_
The magnitude a.
static Double_t maxMagnitude_
Maximum allowed value of magnitude parameters.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
File containing declaration of LauParameter class.
LauParameter * b_
The magnitude b.
Bool_t secondStage() const
Check whether the parameter should be floated only in the second stage of a two stage fit...
File containing declaration of LauComplex class.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:62
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:35
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 void printParValues() const
Print the current values of the parameters.
File containing LauRandom namespace.
File containing declaration of LauBelleCPCoeffSet class.
const LauBlind * blinder() const
Access the blinder object.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:314
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar, Bool_t init)
Set the parameters based on the complex coefficients for particles and antiparticles.
Double_t initValue() const
The initial value of the parameter.
void blindParameter(const TString &blindingString, const Double_t width)
Blind the parameter.
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
Double_t unblindValue() const
The unblinded value of the parameter.
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:241
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.
static Double_t minPhase_
Minimum allowed value of phase parameters.
Double_t value() const
The value of the parameter.
static Double_t minMagnitude_
Minimum allowed value of magnitude parameters.
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:223
Double_t blindingWidth() const
Obtain the Gaussian width.
Definition: LauBlind.hh:68
virtual const TString & baseName() const
Retrieve the base name of the coefficient set.
Class for blinding and unblinding a number based on a blinding string.
Definition: LauBlind.hh:28
Double_t genValue() const
The value generated for the parameter.
LauParameter acp_
The CP asymmetry.