laura is hosted by Hepforge, IPPP Durham
Laura++  v1r0
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  acp_("ACP", -2.0*(x*deltaX + y*deltaY)/(x*x + deltaX*deltaX + y*y + deltaY*deltaY), -1.0, 1.0, deltaXFixed&&deltaYFixed)
47 {
48  // Print message
49  cout<<"Set component \""<<this->name()<<"\" to have x = "<<x_->value()<<",\ty = "<<y_->value()<<",\t";
50  cout<<"Delta x = "<<deltaX_->value()<<",\tDelta y = "<<deltaY_->value()<<"."<<endl;
51 
52  if (deltaXSecondStage && !deltaXFixed) {
53  deltaX_->secondStage(kTRUE);
54  deltaX_->initValue(0.0);
55  }
56  if (deltaYSecondStage && !deltaYFixed) {
57  deltaY_->secondStage(kTRUE);
58  deltaY_->initValue(0.0);
59  }
60 }
61 
63 {
64  minPar_ = rhs.minPar_;
65  maxPar_ = rhs.maxPar_;
68  x_ = rhs.x_->createClone(constFactor);
69  y_ = rhs.y_->createClone(constFactor);
70  deltaX_ = rhs.deltaX_->createClone(constFactor);
71  deltaY_ = rhs.deltaY_->createClone(constFactor);
72  acp_ = rhs.acp_;
73 }
74 
76 {
77  if (&rhs == this) {
78  return *this;
79  }
80  this->name(rhs.name());
81  minPar_ = rhs.minPar_;
82  maxPar_ = rhs.maxPar_;
85  x_ = rhs.x_->createClone();
86  y_ = rhs.y_->createClone();
87  deltaX_ = rhs.deltaX_->createClone();
88  deltaY_ = rhs.deltaY_->createClone();
89  acp_ = rhs.acp_;
90  return *this;
91 }
92 
93 std::vector<LauParameter*> LauCartesianCPCoeffSet::getParameters()
94 {
95  std::vector<LauParameter*> pars;
96  pars.push_back(x_);
97  pars.push_back(y_);
98  pars.push_back(deltaX_);
99  pars.push_back(deltaY_);
100  return pars;
101 }
102 
104 {
105  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<endl;
106  stream<<"\\hline"<<endl;
107  stream<<"Component & Real Part & Imaginary Part & $\\Delta$ Real Part & $\\Delta$ Imaginary Part \\\\"<<endl;
108  stream<<"\\hline"<<endl;
109 }
110 
111 void LauCartesianCPCoeffSet::printTableRow(std::ostream& stream)
112 {
113  LauPrint print;
114  TString resName = this->name();
115  resName = resName.ReplaceAll("_", "\\_");
116  stream<<resName<<" & $";
117  print.printFormat(stream, x_->value());
118  stream<<" \\pm ";
119  print.printFormat(stream, x_->error());
120  stream<<"$ & $";
121  print.printFormat(stream, y_->value());
122  stream<<" \\pm ";
123  print.printFormat(stream, y_->error());
124  stream<<"$ & $";
125  print.printFormat(stream, deltaX_->value());
126  stream<<" \\pm ";
127  print.printFormat(stream, deltaX_->error());
128  stream<<"$ & $";
129  print.printFormat(stream, deltaY_->value());
130  stream<<" \\pm ";
131  print.printFormat(stream, deltaY_->error());
132  stream<<"$ \\\\"<<endl;
133 }
134 
136 {
137  if (x_->fixed() == kFALSE && x_->secondStage() == kFALSE) {
138  // Choose a value for "X" between -3.0 and 3.0
139  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
140  x_->initValue(value); x_->value(value);
141  }
142  if (y_->fixed() == kFALSE && y_->secondStage() == kFALSE) {
143  // Choose a value for "Y" between -3.0 and 3.0
144  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
145  y_->initValue(value); y_->value(value);
146  }
147  if (deltaX_->fixed() == kFALSE && deltaX_->secondStage() == kFALSE) {
148  // Choose a value for "Delta X" between -0.5 and 0.5
149  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*1.0 - 0.5;
150  deltaX_->initValue(value); deltaX_->value(value);
151  }
152  if (deltaY_->fixed() == kFALSE && deltaY_->secondStage() == kFALSE) {
153  // Choose a value for "Delta Y" between -0.5 and 0.5
154  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*1.0 - 0.5;
155  deltaY_->initValue(value); deltaY_->value(value);
156  }
157 }
158 
160 {
161  // update the pulls
162  x_->updatePull();
163  y_->updatePull();
164  deltaX_->updatePull();
165  deltaY_->updatePull();
166 }
167 
169 {
170  return LauComplex( x_->value()+deltaX_->value(), y_->value()+deltaY_->value() );
171 }
172 
174 {
175  return LauComplex( x_->value()-deltaX_->value(), y_->value()-deltaY_->value() );
176 }
177 
178 void LauCartesianCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar )
179 {
180  LauComplex average( coeff );
181  average += coeffBar;
182  average.rescale( 0.5 );
183 
184  x_->value( average.re() );
185  y_->value( average.im() );
186  deltaX_->value( coeff.re() - average.re() );
187  deltaY_->value( coeff.im() - average.im() );
188 }
189 
191 {
192  // set the name
193  TString parName(this->baseName()); parName += "_ACP";
194  acp_.name(parName);
195 
196  // work out the ACP value
197  Double_t numer = x_->value()*deltaX_->value() + y_->value()*deltaY_->value();
198  Double_t denom = x_->value()*x_->value() + deltaX_->value()*deltaX_->value() + y_->value()*y_->value() + deltaY_->value()*deltaY_->value();
199  Double_t value = -2.0*numer/denom;
200 
201  // is it fixed?
202  Bool_t fixed = deltaX_->fixed() && deltaY_->fixed();
203  acp_.fixed(fixed);
204 
205  // we can't work out the error without the covariance matrix
206  Double_t error(0.0);
207 
208  // set the value and error
209  acp_.valueAndErrors(value,error);
210 
211  return acp_;
212 }
213 
214 LauAbsCoeffSet* LauCartesianCPCoeffSet::createClone(const TString& newName, Double_t constFactor)
215 {
216  LauAbsCoeffSet* clone = new LauCartesianCPCoeffSet( *this, constFactor );
217  clone->name( newName );
218  return clone;
219 }
220 
LauParameter * deltaY_
The asymmetric imaginary part.
Double_t maxDeltaPar_
The maximum allowed value for the asymmetric parts.
virtual LauComplex antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
Double_t maxPar_
The maximum allowed value for the average parts.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
virtual LauComplex particleCoeff()
Retrieve the complex coefficient for a particle.
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
File containing declaration of LauPrint class.
Class to define various output print commands.
Definition: LauPrint.hh:29
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.
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 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.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.