laura is hosted by Hepforge, IPPP Durham
Laura++  v3r1
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 
19 #include "TMath.h"
20 #include "TRandom.h"
21 
22 #include "LauCleoCPCoeffSet.hh"
23 #include "LauComplex.hh"
24 #include "LauConstants.hh"
25 #include "LauParameter.hh"
26 #include "LauPrint.hh"
27 #include "LauRandom.hh"
28 
30 
31 
32 LauCleoCPCoeffSet::LauCleoCPCoeffSet(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_( (a+b)*TMath::Cos(delta+phi), (a+b)*TMath::Sin(delta+phi) ),
40  antiparticleCoeff_( (a-b)*TMath::Cos(delta-phi), (a-b)*TMath::Sin(delta-phi) ),
41  acp_("ACP", (-2.0*a*b)/(a*a+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 LauCleoCPCoeffSet::LauCleoCPCoeffSet(const LauCleoCPCoeffSet& 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*> LauCleoCPCoeffSet::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 LauCleoCPCoeffSet::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 LauCleoCPCoeffSet::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 LauCleoCPCoeffSet::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  bVal *= -1.0;
193  deltaVal += LauConstants::pi;
194  }
195 
196  // Check now whether the phases lies in the right range (-pi to pi).
197  Bool_t deltaWithinRange(kFALSE);
198  Bool_t phiWithinRange(kFALSE);
199  while (deltaWithinRange == kFALSE && phiWithinRange == kFALSE) {
200  if (deltaVal > -LauConstants::pi && deltaVal < LauConstants::pi) {
201  deltaWithinRange = kTRUE;
202  } else {
203  // Not within the specified range
204  if (deltaVal > LauConstants::pi) {
205  deltaVal -= LauConstants::twoPi;
206  } else if (deltaVal < -LauConstants::pi) {
207  deltaVal += LauConstants::twoPi;
208  }
209  }
210 
211  if (phiVal > -LauConstants::pi && phiVal < LauConstants::pi) {
212  phiWithinRange = kTRUE;
213  } else {
214  // Not within the specified range
215  if (phiVal > LauConstants::pi) {
216  phiVal -= LauConstants::twoPi;
217  } else if (phiVal < -LauConstants::pi) {
218  phiVal += LauConstants::twoPi;
219  }
220  }
221  }
222 
223  // A further problem can occur when the generated phase is close to -pi or pi.
224  // The phase can wrap over to the other end of the scale -
225  // this leads to artificially large pulls so we wrap it back.
226  Double_t diff = deltaVal - genDelta;
227  if (diff > LauConstants::pi) {
228  deltaVal -= LauConstants::twoPi;
229  } else if (diff < -LauConstants::pi) {
230  deltaVal += LauConstants::twoPi;
231  }
232 
233  diff = phiVal - genPhi;
234  if (diff > LauConstants::pi) {
235  phiVal -= LauConstants::twoPi;
236  } else if (diff < -LauConstants::pi) {
237  phiVal += LauConstants::twoPi;
238  }
239 
240  // finally store the new values in the parameters
241  // and update the pulls
242  a_->value(aVal); a_->updatePull();
243  b_->value(bVal); b_->updatePull();
244  delta_->value(deltaVal); delta_->updatePull();
245  phi_->value(phiVal); phi_->updatePull();
246 }
247 
249 {
250  Double_t magnitude = a_->unblindValue() + b_->unblindValue();
251  Double_t phase = delta_->unblindValue() + phi_->unblindValue();
252  particleCoeff_.setRealImagPart(magnitude*TMath::Cos(phase), magnitude*TMath::Sin(phase));
253  return particleCoeff_;
254 }
255 
257 {
258  Double_t magnitude = a_->unblindValue() - b_->unblindValue();
259  Double_t phase = delta_->unblindValue() - phi_->unblindValue();
260  antiparticleCoeff_.setRealImagPart(magnitude*TMath::Cos(phase), magnitude*TMath::Sin(phase));
261  return antiparticleCoeff_;
262 }
263 
264 void LauCleoCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
265 {
266  Double_t mag = coeff.abs();
267  Double_t magBar = coeffBar.abs();
268  Double_t phase = coeff.arg();
269  Double_t phaseBar = coeffBar.arg();
270 
271  Double_t aVal( 0.5 * ( mag + magBar ) );
272  Double_t deltaVal( 0.5 * ( phase + phaseBar ) );
273  Double_t bVal( 0.5 * ( mag - magBar ) );
274  Double_t phiVal( 0.5 * ( phase - phaseBar ) );
275 
276  a_->value( aVal );
277  delta_->value( deltaVal );
278  b_->value( bVal );
279  phi_->value( phiVal );
280 
281  if ( init ) {
282  a_->genValue( aVal );
283  delta_->genValue( deltaVal );
284  b_->genValue( bVal );
285  phi_->genValue( phiVal );
286 
287  a_->initValue( aVal );
288  delta_->initValue( deltaVal );
289  b_->initValue( bVal );
290  phi_->initValue( phiVal );
291  }
292 }
293 
295 {
296  // set the name
297  TString parName(this->baseName()); parName += "_ACP";
298  acp_.name(parName);
299 
300  // work out the ACP value
301  Double_t numer = -2.0*a_->value()*b_->value();
302  Double_t denom = a_->value()*a_->value()+b_->value()*b_->value();
303  Double_t value = numer/denom;
304 
305  // is it fixed?
306  Bool_t fixed = a_->fixed() && b_->fixed();
307  acp_.fixed(fixed);
308 
309  // we can't work out the error without the covariance matrix
310  Double_t error(0.0);
311 
312  // set the value and error
313  acp_.valueAndErrors(value,error);
314 
315  return acp_;
316 }
317 
318 LauAbsCoeffSet* LauCleoCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
319 {
320  LauAbsCoeffSet* clone(0);
321  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude || cloneOption == TieCPPars ) {
322  clone = new LauCleoCPCoeffSet( *this, cloneOption, constFactor );
323  clone->name( newName );
324  } else {
325  std::cerr << "ERROR in LauCleoCPCoeffSet::createClone : Invalid clone option" << std::endl;
326  }
327  return clone;
328 }
329 
virtual void printParValues() const
Print the current values of the parameters.
LauParameter acp_
The CP asymmetry.
static Double_t maxPhase_
Maximum allowed value of phase parameters.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
File containing declaration of LauCleoCPCoeffSet class.
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)
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
const TString & name() const
The parameter name.
LauParameter * delta_
The strong phase.
File containing declaration of LauPrint class.
Class to define various output print commands.
Definition: LauPrint.hh:29
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, Bool_t bSecondStage=kFALSE, Bool_t phiSecondStage=kFALSE)
Constructor.
Class for defining a complex coefficient using the Cleo CP convention.
LauComplex particleCoeff_
The particle complex coefficient.
LauParameter * phi_
The weak phase.
CloneOption
Options for cloning operation.
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.
Bool_t blind() const
The blinding state.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
static Double_t maxMagnitude_
Maximum allowed value of magnitude parameters.
File containing declaration of LauParameter class.
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
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.
LauParameter * b_
The magnitude b.
File containing LauRandom namespace.
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 LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
Double_t initValue() const
The initial value of the parameter.
void blindParameter(const TString &blindingString, const Double_t width)
Blind 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
Double_t unblindValue() const
The unblinded value of the parameter.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar, Bool_t init)
Set the parameters based on the complex coefficients for particles and antiparticles.
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.
static Double_t minPhase_
Minimum allowed value of phase parameters.
Double_t value() const
The value of the parameter.
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
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
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
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.
virtual void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
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.
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.