laura is hosted by Hepforge, IPPP Durham
Laura++  v3r1
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauMagPhaseCPCoeffSet.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2011 - 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 "LauMagPhaseCPCoeffSet.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 LauMagPhaseCPCoeffSet::LauMagPhaseCPCoeffSet(const TString& compName, Double_t mag, Double_t phase, Double_t magBar, Double_t phaseBar,
33  Bool_t magFixed, Bool_t phaseFixed,Bool_t magBarFixed, Bool_t phaseBarFixed) :
34  LauAbsCoeffSet(compName),
35  mag_(new LauParameter("Mag", mag, minMagnitude_, maxMagnitude_, magFixed)),
36  phase_(new LauParameter("Phase", phase, minPhase_, maxPhase_, phaseFixed)),
37  magBar_(new LauParameter("MagBar", magBar, minMagnitude_, maxMagnitude_, magBarFixed)),
38  phaseBar_(new LauParameter("PhaseBar", phaseBar, minPhase_, maxPhase_, phaseBarFixed)),
39  particleCoeff_( mag*TMath::Cos(phase), mag*TMath::Sin(phase) ),
40  antiparticleCoeff_( magBar*TMath::Cos(phaseBar), magBar*TMath::Sin(phaseBar) ),
41  acp_("ACP", (magBar*magBar - mag*mag)/(magBar*magBar + mag*mag), -1.0, 1.0)
42 {
43 }
44 
46  mag_(0),
47  phase_(0),
48  magBar_(0),
49  phaseBar_(0),
50  particleCoeff_( rhs.particleCoeff_ ),
51  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
52  acp_( rhs.acp_ )
53 {
54  if ( cloneOption == All || cloneOption == TieMagnitude ) {
55  mag_ = rhs.mag_->createClone(constFactor);
56  magBar_ = rhs.magBar_->createClone(constFactor);
57  } else {
58  mag_ = new LauParameter("Mag", rhs.mag_->value(), minMagnitude_, maxMagnitude_, rhs.mag_->fixed());
59  if ( rhs.mag_->blind() ) {
60  const LauBlind* blinder = rhs.mag_->blinder();
61  mag_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
62  }
63  magBar_ = new LauParameter("MagBar", rhs.magBar_->value(), minMagnitude_, maxMagnitude_, rhs.magBar_->fixed());
64  if ( rhs.magBar_->blind() ) {
65  const LauBlind* blinder = rhs.magBar_->blinder();
66  magBar_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
67  }
68  }
69 
70  if ( cloneOption == All || cloneOption == TiePhase ) {
71  phase_ = rhs.phase_->createClone(constFactor);
72  phaseBar_ = rhs.phaseBar_->createClone(constFactor);
73  } else {
74  phase_ = new LauParameter("Phase", rhs.phase_->value(), minPhase_, maxPhase_, rhs.phase_->fixed());
75  if ( rhs.phase_->blind() ) {
76  const LauBlind* blinder = rhs.phase_->blinder();
77  phase_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
78  }
79  phaseBar_ = new LauParameter("PhaseBar", rhs.phaseBar_->value(), minPhase_, maxPhase_, rhs.phaseBar_->fixed());
80  if ( rhs.phaseBar_->blind() ) {
81  const LauBlind* blinder = rhs.phaseBar_->blinder();
82  phaseBar_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
83  }
84  }
85 }
86 
87 std::vector<LauParameter*> LauMagPhaseCPCoeffSet::getParameters()
88 {
89  std::vector<LauParameter*> pars;
90  pars.push_back(mag_);
91  pars.push_back(phase_);
92  pars.push_back(magBar_);
93  pars.push_back(phaseBar_);
94  return pars;
95 }
96 
98 {
99  std::cout<<"INFO in LauMagPhaseCPCoeffSet::printParValues : Component \""<<this->name()<<"\" has ";
100  std::cout<<"mag = "<<mag_->value()<<",\t";
101  std::cout<<"phase = "<<phase_->value()<<",\t";
102  std::cout<<"magBar = "<<magBar_->value()<<",\t";
103  std::cout<<"phaseBar = "<<phaseBar_->value()<<"."<<std::endl;
104 }
105 
106 void LauMagPhaseCPCoeffSet::printTableHeading(std::ostream& stream) const
107 {
108  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<std::endl;
109  stream<<"\\hline"<<std::endl;
110  stream<<"Component & Magnitude & Phase & Magnitude_bar & Phase_bar \\\\"<<std::endl;
111  stream<<"\\hline"<<std::endl;
112 }
113 
114 void LauMagPhaseCPCoeffSet::printTableRow(std::ostream& stream) const
115 {
116  LauPrint print;
117  TString resName = this->name();
118  resName = resName.ReplaceAll("_", "\\_");
119  stream<<resName<<" & $";
120  print.printFormat(stream, mag_->value());
121  stream<<" \\pm ";
122  print.printFormat(stream, mag_->error());
123  stream<<"$ & $";
124  print.printFormat(stream, phase_->value());
125  stream<<" \\pm ";
126  print.printFormat(stream, phase_->error());
127  stream<<"$ & $";
128  print.printFormat(stream, magBar_->value());
129  stream<<" \\pm ";
130  print.printFormat(stream, magBar_->error());
131  stream<<"$ & $";
132  print.printFormat(stream, phaseBar_->value());
133  stream<<" \\pm ";
134  print.printFormat(stream, phaseBar_->error());
135  stream<<"$ \\\\"<<std::endl;
136 }
137 
139 {
140  if (mag_->fixed() == kFALSE) {
141  // Choose a value for "magnitude" between 0.0 and 2.0
142  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*2.0;
143  mag_->initValue(value); mag_->value(value);
144  }
145  if (phase_->fixed() == kFALSE) {
146  // Choose a phase between +- pi
148  phase_->initValue(value); phase_->value(value);
149  }
150  if (magBar_->fixed() == kFALSE) {
151  // Choose a value for "magnitude" between 0.0 and 2.0
152  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*2.0;
153  magBar_->initValue(value); magBar_->value(value);
154  }
155  if (phaseBar_->fixed() == kFALSE) {
156  // Choose a phase between +- pi
158  phaseBar_->initValue(value); phaseBar_->value(value);
159  }
160 }
161 
163 {
164  // retrieve the current values from the parameters
165  Double_t mVal= mag_->value();
166  Double_t pVal= phase_->value();
167  Double_t mBarVal= magBar_->value();
168  Double_t pBarVal= phaseBar_->value();
169  Double_t genPhase = phase_->genValue();
170  Double_t genPhaseBar = phaseBar_->genValue();
171 
172  // Check whether we have a negative magnitude.
173  // If so make it positive and add pi to the phase.
174  if (mVal < 0.0) {
175  mVal *= -1.0;
176  pVal += LauConstants::pi;
177  }
178  if (mBarVal < 0.0) {
179  mBarVal *= -1.0;
180  pBarVal += LauConstants::pi;
181  }
182 
183  // Check now whether the phases lies in the right range (-pi to pi).
184  Bool_t pWithinRange(kFALSE);
185  Bool_t pBarWithinRange(kFALSE);
186  while (pWithinRange == kFALSE && pBarWithinRange == kFALSE) {
187  if (pVal > -LauConstants::pi && pVal < LauConstants::pi) {
188  pWithinRange = kTRUE;
189  } else {
190  // Not within the specified range
191  if (pVal > LauConstants::pi) {
192  pVal -= LauConstants::twoPi;
193  } else if (pVal < -LauConstants::pi) {
194  pVal += LauConstants::twoPi;
195  }
196  }
197 
198  if (pBarVal > -LauConstants::pi && pBarVal < LauConstants::pi) {
199  pBarWithinRange = kTRUE;
200  } else {
201  // Not within the specified range
202  if (pBarVal > LauConstants::pi) {
203  pBarVal -= LauConstants::twoPi;
204  } else if (pBarVal < -LauConstants::pi) {
205  pBarVal += LauConstants::twoPi;
206  }
207  }
208  }
209 
210  // A further problem can occur when the generated phase is close to -pi or pi.
211  // The phase can wrap over to the other end of the scale -
212  // this leads to artificially large pulls so we wrap it back.
213  Double_t diff = pVal - genPhase;
214  if (diff > LauConstants::pi) {
215  pVal -= LauConstants::twoPi;
216  } else if (diff < -LauConstants::pi) {
217  pVal += LauConstants::twoPi;
218  }
219 
220  diff = pBarVal - genPhaseBar;
221  if (diff > LauConstants::pi) {
222  pBarVal -= LauConstants::twoPi;
223  } else if (diff < -LauConstants::pi) {
224  pBarVal += LauConstants::twoPi;
225  }
226 
227  // finally store the new values in the parameters
228  // and update the pulls
229  mag_->value(mVal); mag_->updatePull();
230  phase_->value(pVal); phase_->updatePull();
231  magBar_->value(mBarVal); magBar_->updatePull();
232  phaseBar_->value(pBarVal); phaseBar_->updatePull();
233 
234 
235 }
236 
238 {
240  return particleCoeff_;
241 }
242 
244 {
246  return antiparticleCoeff_;
247 }
248 
249 void LauMagPhaseCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
250 {
251  Double_t magVal( coeff.abs() );
252  Double_t phaseVal( coeff.arg() );
253  Double_t magBarVal( coeffBar.abs() );
254  Double_t phaseBarVal( coeffBar.arg() );
255 
256  mag_->value( magVal );
257  phase_->value( phaseVal );
258  magBar_->value( magBarVal );
259  phaseBar_->value( phaseBarVal );
260 
261  if ( init ) {
262  mag_->genValue( magVal );
263  phase_->genValue( phaseVal );
264  magBar_->genValue( magBarVal );
265  phaseBar_->genValue( phaseBarVal );
266 
267  mag_->initValue( magVal );
268  phase_->initValue( phaseVal );
269  magBar_->initValue( magBarVal );
270  phaseBar_->initValue( phaseBarVal );
271  }
272 }
273 
275 {
276  // set the name
277  TString parName(this->baseName()); parName += "_ACP";
278  acp_.name(parName);
279 
280  // work out the ACP value
281 
282  Double_t value(-99.0);
283  value = (magBar_->value()*magBar_->value() - mag_->value()*mag_->value())/(magBar_->value()*magBar_->value() + mag_->value()*mag_->value());
284 
285  // is it fixed?
286  Bool_t fixed = magBar_->fixed() && mag_->fixed();
287  acp_.fixed(fixed);
288 
289  // we can't work out the error without the covariance matrix
290  Double_t error(0.0);
291 
292  // set the value and error
293  acp_.valueAndErrors(value,error);
294 
295  return acp_;
296 }
297 
298 LauAbsCoeffSet* LauMagPhaseCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
299 {
300  LauAbsCoeffSet* clone(0);
301  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude ) {
302  clone = new LauMagPhaseCPCoeffSet( *this, cloneOption, constFactor );
303  clone->name( newName );
304  } else {
305  std::cerr << "ERROR in LauMagPhaseCPCoeffSet::createClone : Invalid clone option" << std::endl;
306  }
307  return clone;
308 }
309 
static Double_t maxPhase_
Maximum allowed value of phase parameters.
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 void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
LauParameter acp_
The CP asymmetry.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
const Double_t twoPi
Two times Pi.
Definition: LauConstants.hh:93
File containing declaration of LauMagPhaseCPCoeffSet class.
ClassImp(LauAbsCoeffSet)
LauParameter * phase_
The phase for particles.
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
const TString & name() const
The parameter name.
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
File containing declaration of LauPrint class.
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
Class to define various output print commands.
Definition: LauPrint.hh:29
Class for defining a complex coefficient using seperate magnitudes and phases for particles and antip...
virtual void printParValues() const
Print the current values of the parameters.
CloneOption
Options for cloning operation.
Bool_t clone() const
Check whether is a clone or not.
Bool_t blind() const
The blinding state.
static Double_t maxMagnitude_
Maximum allowed value of magnitude parameters.
File containing declaration of LauParameter class.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
File containing declaration of LauComplex class.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:62
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 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 LauParameter acp()
Calculate the CP asymmetry.
LauParameter * magBar_
The magnitude for antiparticles.
File containing LauRandom namespace.
const LauBlind * blinder() const
Access the blinder object.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:314
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.
Class for defining a complex number.
Definition: LauComplex.hh:47
void updatePull()
Call to update the bias and pull values.
LauParameter * mag_
The magnitude for particles.
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.
LauMagPhaseCPCoeffSet(const TString &compName, Double_t mag, Double_t phase, Double_t magBar, Double_t phaseBar, Bool_t magFixed, Bool_t phaseFixed, Bool_t magBarFixed, Bool_t phaseBarFixed)
Constructor.
static Double_t minPhase_
Minimum allowed value of phase parameters.
Double_t value() const
The value of the parameter.
LauComplex particleCoeff_
The particle complex coefficient.
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.
LauParameter * phaseBar_
The phase for antiparticles.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
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.