laura is hosted by Hepforge, IPPP Durham
Laura++  v3r0p1
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 
19 #include "TMath.h"
20 #include "TRandom.h"
21 
23 #include "LauComplex.hh"
24 #include "LauConstants.hh"
25 #include "LauParameter.hh"
26 #include "LauPrint.hh"
27 #include "LauRandom.hh"
28 
30 
31 
32 LauCartesianCPCoeffSet::LauCartesianCPCoeffSet(const TString& compName, Double_t x, Double_t y, Double_t deltaX, Double_t deltaY,
33  Bool_t xFixed, Bool_t yFixed, Bool_t deltaXFixed, Bool_t deltaYFixed, Bool_t deltaXSecondStage, Bool_t deltaYSecondStage) :
34  LauAbsCoeffSet(compName),
35  x_(new LauParameter("X", x, minRealImagPart_, maxRealImagPart_, xFixed)),
36  y_(new LauParameter("Y", y, minRealImagPart_, maxRealImagPart_, yFixed)),
37  deltaX_(new LauParameter("DeltaX", deltaX, minDelta_, maxDelta_, deltaXFixed)),
38  deltaY_(new LauParameter("DeltaY", deltaY, minDelta_, maxDelta_, deltaYFixed)),
39  particleCoeff_( x+deltaX, y+deltaY ),
40  antiparticleCoeff_( x-deltaX, y-deltaY ),
41  acp_("ACP", -2.0*(x*deltaX + y*deltaY)/(x*x + deltaX*deltaX + y*y + deltaY*deltaY), -1.0, 1.0, deltaXFixed&&deltaYFixed)
42 {
43  if (deltaXSecondStage && !deltaXFixed) {
44  deltaX_->secondStage(kTRUE);
45  deltaX_->initValue(0.0);
46  }
47  if (deltaYSecondStage && !deltaYFixed) {
48  deltaY_->secondStage(kTRUE);
49  deltaY_->initValue(0.0);
50  }
51 }
52 
54  x_(0),
55  y_(0),
56  deltaX_(0),
57  deltaY_(0),
58  particleCoeff_( rhs.particleCoeff_ ),
59  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
60  acp_( rhs.acp_ )
61 {
62  if ( cloneOption == All || cloneOption == TieRealPart ) {
63  x_ = rhs.x_->createClone(constFactor);
64  } else {
65  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
66  }
67 
68  if ( cloneOption == All || cloneOption == TieImagPart ) {
69  y_ = rhs.y_->createClone(constFactor);
70  } else {
71  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
72  }
73 
74  if ( cloneOption == All || cloneOption == TieCPPars ) {
75  deltaX_ = rhs.deltaX_->createClone(constFactor);
76  deltaY_ = rhs.deltaY_->createClone(constFactor);
77  } else {
78  deltaX_ = new LauParameter("DeltaX", rhs.deltaX_->value(), minDelta_, maxDelta_, rhs.deltaX_->fixed());
79  deltaY_ = new LauParameter("DeltaY", rhs.deltaY_->value(), minDelta_, maxDelta_, rhs.deltaY_->fixed());
80  if ( rhs.deltaX_->secondStage() && !rhs.deltaX_->fixed() ) {
81  deltaX_->secondStage(kTRUE);
82  deltaX_->initValue(0.0);
83  }
84  if ( rhs.deltaY_->secondStage() && !rhs.deltaY_->fixed() ) {
85  deltaY_->secondStage(kTRUE);
86  deltaY_->initValue(0.0);
87  }
88  }
89 }
90 
91 std::vector<LauParameter*> LauCartesianCPCoeffSet::getParameters()
92 {
93  std::vector<LauParameter*> pars;
94  pars.push_back(x_);
95  pars.push_back(y_);
96  pars.push_back(deltaX_);
97  pars.push_back(deltaY_);
98  return pars;
99 }
100 
102 {
103  std::cout<<"INFO in LauCartesianCPCoeffSet::printParValues : Component \""<<this->name()<<"\" has ";
104  std::cout<<"x = "<<x_->value()<<",\t";
105  std::cout<<"y = "<<y_->value()<<",\t";
106  std::cout<<"Delta x = "<<deltaX_->value()<<",\t";
107  std::cout<<"Delta y = "<<deltaY_->value()<<"."<<std::endl;
108 }
109 
110 void LauCartesianCPCoeffSet::printTableHeading(std::ostream& stream) const
111 {
112  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<std::endl;
113  stream<<"\\hline"<<std::endl;
114  stream<<"Component & Real Part & Imaginary Part & $\\Delta$ Real Part & $\\Delta$ Imaginary Part \\\\"<<std::endl;
115  stream<<"\\hline"<<std::endl;
116 }
117 
118 void LauCartesianCPCoeffSet::printTableRow(std::ostream& stream) const
119 {
120  LauPrint print;
121  TString resName = this->name();
122  resName = resName.ReplaceAll("_", "\\_");
123  stream<<resName<<" & $";
124  print.printFormat(stream, x_->value());
125  stream<<" \\pm ";
126  print.printFormat(stream, x_->error());
127  stream<<"$ & $";
128  print.printFormat(stream, y_->value());
129  stream<<" \\pm ";
130  print.printFormat(stream, y_->error());
131  stream<<"$ & $";
132  print.printFormat(stream, deltaX_->value());
133  stream<<" \\pm ";
134  print.printFormat(stream, deltaX_->error());
135  stream<<"$ & $";
136  print.printFormat(stream, deltaY_->value());
137  stream<<" \\pm ";
138  print.printFormat(stream, deltaY_->error());
139  stream<<"$ \\\\"<<std::endl;
140 }
141 
143 {
144  if (x_->fixed() == kFALSE) {
145  // Choose a value for "X" between -3.0 and 3.0
146  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
147  x_->initValue(value); x_->value(value);
148  }
149  if (y_->fixed() == kFALSE) {
150  // Choose a value for "Y" between -3.0 and 3.0
151  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
152  y_->initValue(value); y_->value(value);
153  }
154  if (deltaX_->fixed() == kFALSE && deltaX_->secondStage() == kFALSE) {
155  // Choose a value for "Delta X" between -0.5 and 0.5
156  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*1.0 - 0.5;
157  deltaX_->initValue(value); deltaX_->value(value);
158  }
159  if (deltaY_->fixed() == kFALSE && deltaY_->secondStage() == kFALSE) {
160  // Choose a value for "Delta Y" between -0.5 and 0.5
161  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*1.0 - 0.5;
162  deltaY_->initValue(value); deltaY_->value(value);
163  }
164 }
165 
167 {
168  // update the pulls
169  x_->updatePull();
170  y_->updatePull();
171  deltaX_->updatePull();
172  deltaY_->updatePull();
173 }
174 
176 {
178  return particleCoeff_;
179 }
180 
182 {
184  return antiparticleCoeff_;
185 }
186 
187 void LauCartesianCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
188 {
189  LauComplex average( coeff );
190  average += coeffBar;
191  average.rescale( 0.5 );
192 
193  Double_t xVal( average.re() );
194  Double_t yVal( average.im() );
195  Double_t deltaXVal( coeff.re() - average.re() );
196  Double_t deltaYVal( coeff.im() - average.im() );
197 
198  x_->value( xVal );
199  y_->value( yVal );
200  deltaX_->value( deltaXVal );
201  deltaY_->value( deltaYVal );
202 
203  if ( init ) {
204  x_->genValue( xVal );
205  y_->genValue( yVal );
206  deltaX_->genValue( deltaXVal );
207  deltaY_->genValue( deltaYVal );
208 
209  x_->initValue( xVal );
210  y_->initValue( yVal );
211  deltaX_->initValue( deltaXVal );
212  deltaY_->initValue( deltaYVal );
213  }
214 }
215 
217 {
218  // set the name
219  TString parName(this->baseName()); parName += "_ACP";
220  acp_.name(parName);
221 
222  // work out the ACP value
223  Double_t numer = x_->value()*deltaX_->value() + y_->value()*deltaY_->value();
224  Double_t denom = x_->value()*x_->value() + deltaX_->value()*deltaX_->value() + y_->value()*y_->value() + deltaY_->value()*deltaY_->value();
225  Double_t value = -2.0*numer/denom;
226 
227  // is it fixed?
228  Bool_t fixed = deltaX_->fixed() && deltaY_->fixed();
229  acp_.fixed(fixed);
230 
231  // we can't work out the error without the covariance matrix
232  Double_t error(0.0);
233 
234  // set the value and error
235  acp_.valueAndErrors(value,error);
236 
237  return acp_;
238 }
239 
240 LauAbsCoeffSet* LauCartesianCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
241 {
242  LauAbsCoeffSet* clone(0);
243  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart || cloneOption == TieCPPars ) {
244  clone = new LauCartesianCPCoeffSet( *this, cloneOption, constFactor );
245  clone->name( newName );
246  } else {
247  std::cerr << "ERROR in LauCartesianCPCoeffSet::createClone : Invalid clone option" << std::endl;
248  }
249  return clone;
250 }
251 
LauParameter * deltaY_
The asymmetric imaginary part.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
virtual void printParValues() const
Print the current values of the parameters.
static Double_t minDelta_
Minimum allowed value of CP-violating real/imaginary part parameters.
TRandom * zeroSeedRandom()
Access the singleton random number generator with seed set from machine clock time (within +-1 sec)...
Definition: LauRandom.cc:30
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.
ClassImp(LauAbsCoeffSet)
LauParameter * deltaX_
The asymmetric real part.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar, Bool_t init)
Set the parameters based on the complex coefficients for particles and antiparticles.
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
const TString & name() const
The parameter name.
LauParameter * x_
The average real part.
Double_t re() const
Get the real part.
Definition: LauComplex.hh:205
virtual LauParameter acp()
Calculate the CP asymmetry.
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:214
static Double_t maxRealImagPart_
Maximum allowed value of real/imaginary part parameters.
LauComplex particleCoeff_
The particle complex coefficient.
static Double_t maxDelta_
Maximum allowed value of CP-violating real/imaginary part parameters.
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.
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.
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.
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:34
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.
File containing declaration of LauCartesianCPCoeffSet class.
File containing LauRandom namespace.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:314
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:285
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.
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 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.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
virtual const TString & baseName() const
Retrieve the base name of the coefficient set.
Double_t genValue() const
The value generated for the parameter.
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.