laura is hosted by Hepforge, IPPP Durham
Laura++  v1r2
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauCartesianCPCoeffSet.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 using std::cout;
19 using std::cerr;
20 using std::endl;
21 
22 #include "TMath.h"
23 #include "TRandom.h"
24 
26 #include "LauComplex.hh"
27 #include "LauConstants.hh"
28 #include "LauParameter.hh"
29 #include "LauPrint.hh"
30 #include "LauRandom.hh"
31 
32 ClassImp(LauCartesianCPCoeffSet)
33 
34 
35 LauCartesianCPCoeffSet::LauCartesianCPCoeffSet(const TString& compName, Double_t x, Double_t y, Double_t deltaX, Double_t deltaY,
36  Bool_t xFixed, Bool_t yFixed, Bool_t deltaXFixed, Bool_t deltaYFixed, Bool_t deltaXSecondStage, Bool_t deltaYSecondStage) :
37  LauAbsCoeffSet(compName),
38  minPar_(-10.0),
39  maxPar_(+10.0),
40  minDeltaPar_(-2.0),
41  maxDeltaPar_(+2.0),
42  x_(new LauParameter("X", x, minPar_, maxPar_, xFixed)),
43  y_(new LauParameter("Y", y, minPar_, maxPar_, yFixed)),
44  deltaX_(new LauParameter("DeltaX", deltaX, minDeltaPar_, maxDeltaPar_, deltaXFixed)),
45  deltaY_(new LauParameter("DeltaY", deltaY, minDeltaPar_, maxDeltaPar_, deltaYFixed)),
46  particleCoeff_( x+deltaX, y+deltaY ),
47  antiparticleCoeff_( x-deltaX, y-deltaY ),
48  acp_("ACP", -2.0*(x*deltaX + y*deltaY)/(x*x + deltaX*deltaX + y*y + deltaY*deltaY), -1.0, 1.0, deltaXFixed&&deltaYFixed)
49 {
50  // Print message
51  cout<<"Set component \""<<this->name()<<"\" to have x = "<<x_->value()<<",\ty = "<<y_->value()<<",\t";
52  cout<<"Delta x = "<<deltaX_->value()<<",\tDelta y = "<<deltaY_->value()<<"."<<endl;
53 
54  if (deltaXSecondStage && !deltaXFixed) {
55  deltaX_->secondStage(kTRUE);
56  deltaX_->initValue(0.0);
57  }
58  if (deltaYSecondStage && !deltaYFixed) {
59  deltaY_->secondStage(kTRUE);
60  deltaY_->initValue(0.0);
61  }
62 }
63 
65 {
66  minPar_ = rhs.minPar_;
67  maxPar_ = rhs.maxPar_;
70  x_ = rhs.x_->createClone(constFactor);
71  y_ = rhs.y_->createClone(constFactor);
72  deltaX_ = rhs.deltaX_->createClone(constFactor);
73  deltaY_ = rhs.deltaY_->createClone(constFactor);
76  acp_ = rhs.acp_;
77 }
78 
80 {
81  if (&rhs != this) {
82  this->name(rhs.name());
83  minPar_ = rhs.minPar_;
84  maxPar_ = rhs.maxPar_;
87  x_ = rhs.x_->createClone();
88  y_ = rhs.y_->createClone();
89  deltaX_ = rhs.deltaX_->createClone();
90  deltaY_ = rhs.deltaY_->createClone();
93  acp_ = rhs.acp_;
94  }
95  return *this;
96 }
97 
98 std::vector<LauParameter*> LauCartesianCPCoeffSet::getParameters()
99 {
100  std::vector<LauParameter*> pars;
101  pars.push_back(x_);
102  pars.push_back(y_);
103  pars.push_back(deltaX_);
104  pars.push_back(deltaY_);
105  return pars;
106 }
107 
109 {
110  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<endl;
111  stream<<"\\hline"<<endl;
112  stream<<"Component & Real Part & Imaginary Part & $\\Delta$ Real Part & $\\Delta$ Imaginary Part \\\\"<<endl;
113  stream<<"\\hline"<<endl;
114 }
115 
116 void LauCartesianCPCoeffSet::printTableRow(std::ostream& stream)
117 {
118  LauPrint print;
119  TString resName = this->name();
120  resName = resName.ReplaceAll("_", "\\_");
121  stream<<resName<<" & $";
122  print.printFormat(stream, x_->value());
123  stream<<" \\pm ";
124  print.printFormat(stream, x_->error());
125  stream<<"$ & $";
126  print.printFormat(stream, y_->value());
127  stream<<" \\pm ";
128  print.printFormat(stream, y_->error());
129  stream<<"$ & $";
130  print.printFormat(stream, deltaX_->value());
131  stream<<" \\pm ";
132  print.printFormat(stream, deltaX_->error());
133  stream<<"$ & $";
134  print.printFormat(stream, deltaY_->value());
135  stream<<" \\pm ";
136  print.printFormat(stream, deltaY_->error());
137  stream<<"$ \\\\"<<endl;
138 }
139 
141 {
142  if (x_->fixed() == kFALSE && x_->secondStage() == kFALSE) {
143  // Choose a value for "X" between -3.0 and 3.0
144  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
145  x_->initValue(value); x_->value(value);
146  }
147  if (y_->fixed() == kFALSE && y_->secondStage() == kFALSE) {
148  // Choose a value for "Y" between -3.0 and 3.0
149  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
150  y_->initValue(value); y_->value(value);
151  }
152  if (deltaX_->fixed() == kFALSE && deltaX_->secondStage() == kFALSE) {
153  // Choose a value for "Delta X" between -0.5 and 0.5
154  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*1.0 - 0.5;
155  deltaX_->initValue(value); deltaX_->value(value);
156  }
157  if (deltaY_->fixed() == kFALSE && deltaY_->secondStage() == kFALSE) {
158  // Choose a value for "Delta Y" between -0.5 and 0.5
159  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*1.0 - 0.5;
160  deltaY_->initValue(value); deltaY_->value(value);
161  }
162 }
163 
165 {
166  // update the pulls
167  x_->updatePull();
168  y_->updatePull();
169  deltaX_->updatePull();
170  deltaY_->updatePull();
171 }
172 
174 {
176  return particleCoeff_;
177 }
178 
180 {
182  return antiparticleCoeff_;
183 }
184 
185 void LauCartesianCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar )
186 {
187  LauComplex average( coeff );
188  average += coeffBar;
189  average.rescale( 0.5 );
190 
191  x_->value( average.re() );
192  y_->value( average.im() );
193  deltaX_->value( coeff.re() - average.re() );
194  deltaY_->value( coeff.im() - average.im() );
195 }
196 
198 {
199  // set the name
200  TString parName(this->baseName()); parName += "_ACP";
201  acp_.name(parName);
202 
203  // work out the ACP value
204  Double_t numer = x_->value()*deltaX_->value() + y_->value()*deltaY_->value();
205  Double_t denom = x_->value()*x_->value() + deltaX_->value()*deltaX_->value() + y_->value()*y_->value() + deltaY_->value()*deltaY_->value();
206  Double_t value = -2.0*numer/denom;
207 
208  // is it fixed?
209  Bool_t fixed = deltaX_->fixed() && deltaY_->fixed();
210  acp_.fixed(fixed);
211 
212  // we can't work out the error without the covariance matrix
213  Double_t error(0.0);
214 
215  // set the value and error
216  acp_.valueAndErrors(value,error);
217 
218  return acp_;
219 }
220 
221 LauAbsCoeffSet* LauCartesianCPCoeffSet::createClone(const TString& newName, Double_t constFactor)
222 {
223  LauAbsCoeffSet* clone = new LauCartesianCPCoeffSet( *this, constFactor );
224  clone->name( newName );
225  return clone;
226 }
227 
LauParameter * deltaY_
The asymmetric imaginary part.
Double_t maxDeltaPar_
The maximum allowed value for the asymmetric parts.
Double_t maxPar_
The maximum allowed value for the average parts.
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
Double_t minDeltaPar_
The minimum allowed value for the asymmetric parts.
LauCartesianCPCoeffSet(const TString &compName, Double_t x, Double_t y, Double_t deltaX, Double_t deltaY, Bool_t xFixed, Bool_t yFixed, Bool_t deltaXFixed, Bool_t deltaYFixed, Bool_t deltaXSecondStage=kFALSE, Bool_t deltaYSecondStage=kFALSE)
Constructor.
virtual TString baseName() const
Retrieve the base name of the coefficient set.
LauParameter * deltaX_
The asymmetric real part.
const TString & name() const
The parameter name.
LauParameter * x_
The average real part.
Double_t re() const
Get the real part.
Definition: LauComplex.hh:202
virtual LauParameter acp()
Calculate the CP asymmetry.
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:211
LauComplex particleCoeff_
The particle complex coefficient.
File containing declaration of LauPrint class.
Class to define various output print commands.
Definition: LauPrint.hh:29
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
Bool_t clone() const
Check whether is a clone or not.
Double_t minPar_
The minimum allowed value for the average parts.
LauCartesianCPCoeffSet & operator=(const LauCartesianCPCoeffSet &rhs)
Copy assignment operator.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
File containing declaration of LauParameter class.
LauParameter * y_
The average imaginary part.
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.
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.
File containing declaration of LauCartesianCPCoeffSet class.
virtual void printTableRow(std::ostream &stream)
Print the parameters of the complex coefficient as a row in the results table.
File containing LauRandom namespace.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:311
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:282
Double_t initValue() const
The initial value of 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
Class for defining a complex number.
Definition: LauComplex.hh:47
void updatePull()
Call to update the bias and pull values.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar)
Set the parameters based on the complex coefficients for particles and antiparticles.
virtual void printTableHeading(std::ostream &stream)
Print the column headings for a results table.
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 LauAbsCoeffSet * createClone(const TString &newName, Double_t constFactor=1.0)
Create a clone 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.
Double_t value() const
The 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...
LauParameter acp_
The CP asymmetry.
Class for defining a complex coefficient using the Cartesian CP convention.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.