laura is hosted by Hepforge, IPPP Durham
Laura++  v2r1
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 
19 #include "TMath.h"
20 #include "TRandom.h"
21 
22 #include "LauRealImagCPCoeffSet.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 LauRealImagCPCoeffSet::LauRealImagCPCoeffSet(const TString& compName, Double_t x, Double_t y, Double_t xbar, Double_t ybar,
33  Bool_t xFixed, Bool_t yFixed, Bool_t xbarFixed, Bool_t ybarFixed) :
34  LauAbsCoeffSet(compName),
35  x_(new LauParameter("X", x, minRealImagPart_, maxRealImagPart_, xFixed)),
36  y_(new LauParameter("Y", y, minRealImagPart_, maxRealImagPart_, yFixed)),
37  xbar_(new LauParameter("Xbar", xbar, minRealImagPart_, maxRealImagPart_, xbarFixed)),
38  ybar_(new LauParameter("Ybar", ybar, minRealImagPart_, maxRealImagPart_, ybarFixed)),
39  particleCoeff_(x,y),
40  antiparticleCoeff_(xbar,ybar),
41  acp_("ACP", 0.0, -1.0, 1.0, kTRUE)
42 {
43 }
44 
46  x_(0),
47  y_(0),
48  xbar_(0),
49  ybar_(0),
50  particleCoeff_( rhs.particleCoeff_ ),
51  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
52  acp_( rhs.acp_ )
53 {
54  if ( cloneOption == All || cloneOption == TieRealPart ) {
55  x_ = rhs.x_->createClone(constFactor);
56  xbar_ = rhs.xbar_->createClone(constFactor);
57  } else {
58  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
59  xbar_ = new LauParameter("Xbar", rhs.xbar_->value(), minRealImagPart_, maxRealImagPart_, rhs.xbar_->fixed());
60  }
61 
62  if ( cloneOption == All || cloneOption == TieImagPart ) {
63  y_ = rhs.y_->createClone(constFactor);
64  ybar_ = rhs.ybar_->createClone(constFactor);
65  } else {
66  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
67  ybar_ = new LauParameter("Ybar", rhs.ybar_->value(), minRealImagPart_, maxRealImagPart_, rhs.ybar_->fixed());
68  }
69 }
70 
71 std::vector<LauParameter*> LauRealImagCPCoeffSet::getParameters()
72 {
73  std::vector<LauParameter*> pars;
74  pars.push_back(x_);
75  pars.push_back(y_);
76  pars.push_back(xbar_);
77  pars.push_back(ybar_);
78  return pars;
79 }
80 
82 {
83  std::cout << "INFO in LauRealImagCPCoeffSet::printParValues : Component \"" << this->name() << "\" has ";
84  std::cout << "x = " << x_->value() << ",\t";
85  std::cout << "y = " << y_->value() << ",\t";
86  std::cout << "xbar = " << xbar_->value() << ",\t";
87  std::cout << "ybar = " << ybar_->value() << "." << std::endl;
88 }
89 
90 void LauRealImagCPCoeffSet::printTableHeading(std::ostream& stream) const
91 {
92  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<std::endl;
93  stream<<"\\hline"<<std::endl;
94  stream<<"Component & Particle Real Part & Particle Imaginary Part & Antiparticle Real Part & Antiparticle Imaginary Part \\\\"<<std::endl;
95  stream<<"\\hline"<<std::endl;
96 }
97 
98 void LauRealImagCPCoeffSet::printTableRow(std::ostream& stream) const
99 {
100  LauPrint print;
101  TString resName = this->name();
102  resName = resName.ReplaceAll("_", "\\_");
103  stream<<resName<<" & $";
104  print.printFormat(stream, x_->value());
105  stream<<" \\pm ";
106  print.printFormat(stream, x_->error());
107  stream<<"$ & $";
108  print.printFormat(stream, y_->value());
109  stream<<" \\pm ";
110  print.printFormat(stream, y_->error());
111  stream<<"$ & $";
112  print.printFormat(stream, xbar_->value());
113  stream<<" \\pm ";
114  print.printFormat(stream, xbar_->error());
115  stream<<"$ & $";
116  print.printFormat(stream, ybar_->value());
117  stream<<" \\pm ";
118  print.printFormat(stream, ybar_->error());
119  stream<<"$ \\\\"<<std::endl;
120 }
121 
123 {
124  if (x_->fixed() == kFALSE) {
125  // Choose a value for "X" between -3.0 and 3.0
126  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
127  x_->initValue(value); x_->value(value);
128  }
129  if (y_->fixed() == kFALSE) {
130  // Choose a value for "Y" between -3.0 and 3.0
131  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
132  y_->initValue(value); y_->value(value);
133  }
134  if (xbar_->fixed() == kFALSE) {
135  // Choose a value for "Xbar" between -3.0 and 3.0
136  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
137  xbar_->initValue(value); xbar_->value(value);
138  }
139  if (ybar_->fixed() == kFALSE) {
140  // Choose a value for "Ybar" between -3.0 and 3.0
141  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
142  ybar_->initValue(value); ybar_->value(value);
143  }
144 }
145 
147 {
148  // update the pulls
149  x_->updatePull();
150  y_->updatePull();
151  xbar_->updatePull();
152  ybar_->updatePull();
153 }
154 
156 {
158  return particleCoeff_;
159 }
160 
162 {
164  return antiparticleCoeff_;
165 }
166 
167 void LauRealImagCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
168 {
169  Double_t xVal( coeff.re() );
170  Double_t yVal( coeff.im() );
171  Double_t xBarVal( coeffBar.re() );
172  Double_t yBarVal( coeffBar.im() );
173 
174  x_->value( xVal );
175  y_->value( yVal );
176  xbar_->value( xBarVal );
177  ybar_->value( yBarVal );
178 
179  if ( init ) {
180  x_->genValue( xVal );
181  y_->genValue( yVal );
182  xbar_->genValue( xBarVal );
183  ybar_->genValue( yBarVal );
184 
185  x_->initValue( xVal );
186  y_->initValue( yVal );
187  xbar_->initValue( xBarVal );
188  ybar_->initValue( yBarVal );
189  }
190 }
191 
193 {
194  // set the name
195  TString parName(this->baseName()); parName += "_ACP";
196  acp_.name(parName);
197 
198  // work out the ACP value
199  Double_t csq = x_->value()*x_->value() + y_->value()*y_->value();
200  Double_t cbarsq = xbar_->value()*xbar_->value() + ybar_->value()*ybar_->value();
201  Double_t numer = cbarsq - csq;
202  Double_t denom = cbarsq + csq;
203  Double_t value = numer/denom;
204 
205  // is it fixed?
206  Bool_t fixed = x_->fixed() && y_->fixed() && xbar_->fixed() && ybar_->fixed();
207  acp_.fixed(fixed);
208 
209  // we can't work out the error without the covariance matrix
210  Double_t error(0.0);
211 
212  // set the value and error
213  acp_.valueAndErrors(value,error);
214 
215  return acp_;
216 }
217 
218 LauAbsCoeffSet* LauRealImagCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
219 {
220  LauAbsCoeffSet* clone(0);
221  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart ) {
222  clone = new LauRealImagCPCoeffSet( *this, cloneOption, constFactor );
223  clone->name( newName );
224  } else {
225  std::cerr << "ERROR in LauRealImagCPCoeffSet::createClone : Invalid clone option" << std::endl;
226  }
227  return clone;
228 }
229 
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 void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar, Bool_t init)
Set the parameters based on the complex coefficients for particles and antiparticles.
ClassImp(LauAbsCoeffSet)
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
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
static Double_t maxRealImagPart_
Maximum allowed value of real/imaginary part parameters.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
File containing declaration of LauPrint class.
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.
CloneOption
Options for cloning operation.
Bool_t clone() const
Check whether is a clone or not.
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 LauParameter class.
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:33
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.
static Double_t minRealImagPart_
Minimum allowed value of real/imaginary part parameters.
LauParameter * ybar_
The imaginary part for the antiparticle.
File containing LauRandom namespace.
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
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 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.
Double_t value() const
The value of the parameter.
virtual const TString & baseName() const
Retrieve the base name of the coefficient set.
Double_t genValue() const
The value generated for the parameter.
virtual LauParameter acp()
Calculate the CP asymmetry.
virtual void printParValues() const
Print the current values of the parameters.