laura is hosted by Hepforge, IPPP Durham
Laura++  v1r2
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauRealImagCPCoeffSet.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2013 - 2014.
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 
22 #include "TMath.h"
23 #include "TRandom.h"
24 
25 #include "LauRealImagCPCoeffSet.hh"
26 #include "LauComplex.hh"
27 #include "LauConstants.hh"
28 #include "LauParameter.hh"
29 #include "LauPrint.hh"
30 #include "LauRandom.hh"
31 
32 ClassImp(LauRealImagCPCoeffSet)
33 
34 
35 LauRealImagCPCoeffSet::LauRealImagCPCoeffSet(const TString& compName, Double_t x, Double_t y, Double_t xbar, Double_t ybar,
36  Bool_t xFixed, Bool_t yFixed, Bool_t xbarFixed, Bool_t ybarFixed) :
37  LauAbsCoeffSet(compName),
38  minPar_(-10.0),
39  maxPar_(+10.0),
40  x_(new LauParameter("X", x, minPar_, maxPar_, xFixed)),
41  y_(new LauParameter("Y", y, minPar_, maxPar_, yFixed)),
42  xbar_(new LauParameter("Xbar", xbar, minPar_, maxPar_, xbarFixed)),
43  ybar_(new LauParameter("Ybar", ybar, minPar_, maxPar_, ybarFixed)),
44  particleCoeff_(x,y),
45  antiparticleCoeff_(xbar,ybar),
46  acp_("ACP", 0.0, -1.0, 1.0, kTRUE)
47 {
48  // Print message
49  std::cout << "Set component \"" << this->name() << "\" to have x = " << x_->value() << ",\ty = " << y_->value() << ",\t";
50  std::cout << "xbar = " << xbar_->value() << ",\tybar = " << ybar_->value() << "." << std::endl;
51 }
52 
54 {
55  minPar_ = rhs.minPar_;
56  maxPar_ = rhs.maxPar_;
57  x_ = rhs.x_->createClone(constFactor);
58  y_ = rhs.y_->createClone(constFactor);
59  xbar_ = rhs.xbar_->createClone(constFactor);
60  ybar_ = rhs.ybar_->createClone(constFactor);
63  acp_ = rhs.acp_;
64 }
65 
67 {
68  if (&rhs != this) {
69  this->name(rhs.name());
70  minPar_ = rhs.minPar_;
71  maxPar_ = rhs.maxPar_;
72  x_ = rhs.x_->createClone();
73  y_ = rhs.y_->createClone();
74  xbar_ = rhs.xbar_->createClone();
75  ybar_ = rhs.ybar_->createClone();
78  acp_ = rhs.acp_;
79  }
80  return *this;
81 }
82 
83 std::vector<LauParameter*> LauRealImagCPCoeffSet::getParameters()
84 {
85  std::vector<LauParameter*> pars;
86  pars.push_back(x_);
87  pars.push_back(y_);
88  pars.push_back(xbar_);
89  pars.push_back(ybar_);
90  return pars;
91 }
92 
93 void LauRealImagCPCoeffSet::printTableHeading(std::ostream& stream)
94 {
95  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<endl;
96  stream<<"\\hline"<<endl;
97  stream<<"Component & Particle Real Part & Particle Imaginary Part & Antiparticle Real Part & Antiparticle Imaginary Part \\\\"<<endl;
98  stream<<"\\hline"<<endl;
99 }
100 
101 void LauRealImagCPCoeffSet::printTableRow(std::ostream& stream)
102 {
103  LauPrint print;
104  TString resName = this->name();
105  resName = resName.ReplaceAll("_", "\\_");
106  stream<<resName<<" & $";
107  print.printFormat(stream, x_->value());
108  stream<<" \\pm ";
109  print.printFormat(stream, x_->error());
110  stream<<"$ & $";
111  print.printFormat(stream, y_->value());
112  stream<<" \\pm ";
113  print.printFormat(stream, y_->error());
114  stream<<"$ & $";
115  print.printFormat(stream, xbar_->value());
116  stream<<" \\pm ";
117  print.printFormat(stream, xbar_->error());
118  stream<<"$ & $";
119  print.printFormat(stream, ybar_->value());
120  stream<<" \\pm ";
121  print.printFormat(stream, ybar_->error());
122  stream<<"$ \\\\"<<endl;
123 }
124 
126 {
127  if (x_->fixed() == kFALSE && x_->secondStage() == kFALSE) {
128  // Choose a value for "X" between -3.0 and 3.0
129  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
130  x_->initValue(value); x_->value(value);
131  }
132  if (y_->fixed() == kFALSE && y_->secondStage() == kFALSE) {
133  // Choose a value for "Y" between -3.0 and 3.0
134  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
135  y_->initValue(value); y_->value(value);
136  }
137  if (xbar_->fixed() == kFALSE && xbar_->secondStage() == kFALSE) {
138  // Choose a value for "Delta X" between -3.0 and 3.0
139  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
140  xbar_->initValue(value); xbar_->value(value);
141  }
142  if (ybar_->fixed() == kFALSE && ybar_->secondStage() == kFALSE) {
143  // Choose a value for "Delta Y" between -3.0 and 3.0
144  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
145  ybar_->initValue(value); ybar_->value(value);
146  }
147 }
148 
150 {
151  // update the pulls
152  x_->updatePull();
153  y_->updatePull();
154  xbar_->updatePull();
155  ybar_->updatePull();
156 }
157 
159 {
161  return particleCoeff_;
162 }
163 
165 {
167  return antiparticleCoeff_;
168 }
169 
170 void LauRealImagCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar )
171 {
172  x_->value( coeff.re() );
173  y_->value( coeff.im() );
174  xbar_->value( coeffBar.re() );
175  ybar_->value( coeffBar.im() );
176 }
177 
179 {
180  // set the name
181  TString parName(this->baseName()); parName += "_ACP";
182  acp_.name(parName);
183 
184  // work out the ACP value
185  Double_t csq = x_->value()*x_->value() + y_->value()*y_->value();
186  Double_t cbarsq = xbar_->value()*xbar_->value() + ybar_->value()*ybar_->value();
187  Double_t numer = cbarsq - csq;
188  Double_t denom = cbarsq + csq;
189  Double_t value = numer/denom;
190 
191  // is it fixed?
192  Bool_t fixed = x_->fixed() && y_->fixed() && xbar_->fixed() && ybar_->fixed();
193  acp_.fixed(fixed);
194 
195  // we can't work out the error without the covariance matrix
196  Double_t error(0.0);
197 
198  // set the value and error
199  acp_.valueAndErrors(value,error);
200 
201  return acp_;
202 }
203 
204 LauAbsCoeffSet* LauRealImagCPCoeffSet::createClone(const TString& newName, Double_t constFactor)
205 {
206  LauAbsCoeffSet* clone = new LauRealImagCPCoeffSet( *this, constFactor );
207  clone->name( newName );
208  return clone;
209 }
210 
Double_t maxPar_
The maximum allowed value.
LauRealImagCPCoeffSet(const TString &compName, Double_t x, Double_t y, Double_t xbar, Double_t ybar, Bool_t xFixed, Bool_t yFixed, Bool_t xbarFixed, Bool_t ybarFixed)
Constructor.
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 const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
File containing declaration of LauRealImagCPCoeffSet class.
virtual TString baseName() const
Retrieve the base name of the coefficient set.
const TString & name() const
The parameter name.
Double_t re() const
Get the real part.
Definition: LauComplex.hh:202
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:211
virtual LauAbsCoeffSet * createClone(const TString &newName, Double_t constFactor=1.0)
Create a clone of the coefficient set.
File containing declaration of LauPrint class.
Double_t minPar_
The minimum allowed value.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
Class to define various output print commands.
Definition: LauPrint.hh:29
LauParameter * y_
The imaginary part for the particle.
LauComplex particleCoeff_
The particle complex coefficient.
Bool_t clone() const
Check whether is a clone or not.
File containing declaration of LauParameter class.
virtual void printTableRow(std::ostream &stream)
Print the parameters of the complex coefficient as a row in the results table.
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.
LauParameter acp_
The CP asymmetry.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
LauParameter * x_
The real part for the particle.
Double_t error() const
The error on the parameter.
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.
LauParameter * ybar_
The imaginary part for the antiparticle.
File containing LauRandom namespace.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
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
virtual void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
Class for defining a complex coefficient using a simple Cartesian CP convention.
Double_t initValue() const
The initial value of the parameter.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar)
Set the parameters based on the complex coefficients for particles and antiparticles.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
File containing LauConstants namespace.
LauParameter * xbar_
The real part for the antiparticle.
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
Class for defining a complex number.
Definition: LauComplex.hh:47
void updatePull()
Call to update the bias and pull values.
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.
LauRealImagCPCoeffSet & operator=(const LauRealImagCPCoeffSet &rhs)
Copy assignment operator.
Double_t value() const
The value of the parameter.
virtual LauParameter acp()
Calculate the CP asymmetry.