laura is hosted by Hepforge, IPPP Durham
Laura++  v3r2
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 
29 
30 
31 LauCartesianCPCoeffSet::LauCartesianCPCoeffSet(const TString& compName, Double_t x, Double_t y, Double_t deltaX, Double_t deltaY,
32  Bool_t xFixed, Bool_t yFixed, Bool_t deltaXFixed, Bool_t deltaYFixed, Bool_t deltaXSecondStage, Bool_t deltaYSecondStage) :
33  LauAbsCoeffSet(compName),
34  x_(new LauParameter("X", x, minRealImagPart_, maxRealImagPart_, xFixed)),
35  y_(new LauParameter("Y", y, minRealImagPart_, maxRealImagPart_, yFixed)),
36  deltaX_(new LauParameter("DeltaX", deltaX, minDelta_, maxDelta_, deltaXFixed)),
37  deltaY_(new LauParameter("DeltaY", deltaY, minDelta_, maxDelta_, deltaYFixed)),
38  particleCoeff_( x+deltaX, y+deltaY ),
39  antiparticleCoeff_( x-deltaX, y-deltaY ),
40  acp_("ACP", -2.0*(x*deltaX + y*deltaY)/(x*x + deltaX*deltaX + y*y + deltaY*deltaY), -1.0, 1.0, deltaXFixed&&deltaYFixed)
41 {
42  if (deltaXSecondStage && !deltaXFixed) {
43  deltaX_->secondStage(kTRUE);
44  deltaX_->initValue(0.0);
45  }
46  if (deltaYSecondStage && !deltaYFixed) {
47  deltaY_->secondStage(kTRUE);
48  deltaY_->initValue(0.0);
49  }
50 }
51 
53  x_(0),
54  y_(0),
55  deltaX_(0),
56  deltaY_(0),
57  particleCoeff_( rhs.particleCoeff_ ),
58  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
59  acp_( rhs.acp_ )
60 {
61  if ( cloneOption == All || cloneOption == TieRealPart ) {
62  x_ = rhs.x_->createClone(constFactor);
63  } else {
64  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
65  if ( rhs.x_->blind() ) {
66  const LauBlind* blinder = rhs.x_->blinder();
67  x_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
68  }
69  }
70 
71  if ( cloneOption == All || cloneOption == TieImagPart ) {
72  y_ = rhs.y_->createClone(constFactor);
73  } else {
74  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
75  if ( rhs.y_->blind() ) {
76  const LauBlind* blinder = rhs.y_->blinder();
77  y_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
78  }
79  }
80 
81  if ( cloneOption == All || cloneOption == TieCPPars ) {
82  deltaX_ = rhs.deltaX_->createClone(constFactor);
83  deltaY_ = rhs.deltaY_->createClone(constFactor);
84  } else {
85  deltaX_ = new LauParameter("DeltaX", rhs.deltaX_->value(), minDelta_, maxDelta_, rhs.deltaX_->fixed());
86  deltaY_ = new LauParameter("DeltaY", rhs.deltaY_->value(), minDelta_, maxDelta_, rhs.deltaY_->fixed());
87  if ( rhs.deltaX_->secondStage() && !rhs.deltaX_->fixed() ) {
88  deltaX_->secondStage(kTRUE);
89  deltaX_->initValue(0.0);
90  }
91  if ( rhs.deltaY_->secondStage() && !rhs.deltaY_->fixed() ) {
92  deltaY_->secondStage(kTRUE);
93  deltaY_->initValue(0.0);
94  }
95  if ( rhs.deltaX_->blind() ) {
96  const LauBlind* blinder = rhs.deltaX_->blinder();
97  deltaX_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
98  }
99  if ( rhs.deltaY_->blind() ) {
100  const LauBlind* blinder = rhs.deltaY_->blinder();
101  deltaY_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
102  }
103  }
104 }
105 
106 std::vector<LauParameter*> LauCartesianCPCoeffSet::getParameters()
107 {
108  std::vector<LauParameter*> pars;
109  pars.push_back(x_);
110  pars.push_back(y_);
111  pars.push_back(deltaX_);
112  pars.push_back(deltaY_);
113  return pars;
114 }
115 
117 {
118  std::cout<<"INFO in LauCartesianCPCoeffSet::printParValues : Component \""<<this->name()<<"\" has ";
119  std::cout<<"x = "<<x_->value()<<",\t";
120  std::cout<<"y = "<<y_->value()<<",\t";
121  std::cout<<"Delta x = "<<deltaX_->value()<<",\t";
122  std::cout<<"Delta y = "<<deltaY_->value()<<"."<<std::endl;
123 }
124 
125 void LauCartesianCPCoeffSet::printTableHeading(std::ostream& stream) const
126 {
127  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<std::endl;
128  stream<<"\\hline"<<std::endl;
129  stream<<"Component & Real Part & Imaginary Part & $\\Delta$ Real Part & $\\Delta$ Imaginary Part \\\\"<<std::endl;
130  stream<<"\\hline"<<std::endl;
131 }
132 
133 void LauCartesianCPCoeffSet::printTableRow(std::ostream& stream) const
134 {
135  LauPrint print;
136  TString resName = this->name();
137  resName = resName.ReplaceAll("_", "\\_");
138  stream<<resName<<" & $";
139  print.printFormat(stream, x_->value());
140  stream<<" \\pm ";
141  print.printFormat(stream, x_->error());
142  stream<<"$ & $";
143  print.printFormat(stream, y_->value());
144  stream<<" \\pm ";
145  print.printFormat(stream, y_->error());
146  stream<<"$ & $";
147  print.printFormat(stream, deltaX_->value());
148  stream<<" \\pm ";
149  print.printFormat(stream, deltaX_->error());
150  stream<<"$ & $";
151  print.printFormat(stream, deltaY_->value());
152  stream<<" \\pm ";
153  print.printFormat(stream, deltaY_->error());
154  stream<<"$ \\\\"<<std::endl;
155 }
156 
158 {
159  if (x_->fixed() == kFALSE) {
160  // Choose a value for "X" between -3.0 and 3.0
161  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
162  x_->initValue(value); x_->value(value);
163  }
164  if (y_->fixed() == kFALSE) {
165  // Choose a value for "Y" between -3.0 and 3.0
166  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
167  y_->initValue(value); y_->value(value);
168  }
169  if (deltaX_->fixed() == kFALSE && deltaX_->secondStage() == kFALSE) {
170  // Choose a value for "Delta X" between -0.5 and 0.5
171  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*1.0 - 0.5;
172  deltaX_->initValue(value); deltaX_->value(value);
173  }
174  if (deltaY_->fixed() == kFALSE && deltaY_->secondStage() == kFALSE) {
175  // Choose a value for "Delta Y" between -0.5 and 0.5
176  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*1.0 - 0.5;
177  deltaY_->initValue(value); deltaY_->value(value);
178  }
179 }
180 
182 {
183  // update the pulls
184  x_->updatePull();
185  y_->updatePull();
186  deltaX_->updatePull();
187  deltaY_->updatePull();
188 }
189 
191 {
193  return particleCoeff_;
194 }
195 
197 {
199  return antiparticleCoeff_;
200 }
201 
202 void LauCartesianCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
203 {
204  LauComplex average( coeff );
205  average += coeffBar;
206  average.rescale( 0.5 );
207 
208  Double_t xVal( average.re() );
209  Double_t yVal( average.im() );
210  Double_t deltaXVal( coeff.re() - average.re() );
211  Double_t deltaYVal( coeff.im() - average.im() );
212 
213  x_->value( xVal );
214  y_->value( yVal );
215  deltaX_->value( deltaXVal );
216  deltaY_->value( deltaYVal );
217 
218  if ( init ) {
219  x_->genValue( xVal );
220  y_->genValue( yVal );
221  deltaX_->genValue( deltaXVal );
222  deltaY_->genValue( deltaYVal );
223 
224  x_->initValue( xVal );
225  y_->initValue( yVal );
226  deltaX_->initValue( deltaXVal );
227  deltaY_->initValue( deltaYVal );
228  }
229 }
230 
232 {
233  // set the name
234  TString parName(this->baseName()); parName += "_ACP";
235  acp_.name(parName);
236 
237  // work out the ACP value
238  Double_t numer = x_->value()*deltaX_->value() + y_->value()*deltaY_->value();
239  Double_t denom = x_->value()*x_->value() + deltaX_->value()*deltaX_->value() + y_->value()*y_->value() + deltaY_->value()*deltaY_->value();
240  Double_t value = -2.0*numer/denom;
241 
242  // is it fixed?
243  Bool_t fixed = deltaX_->fixed() && deltaY_->fixed();
244  acp_.fixed(fixed);
245 
246  // we can't work out the error without the covariance matrix
247  Double_t error(0.0);
248 
249  // set the value and error
250  acp_.valueAndErrors(value,error);
251 
252  return acp_;
253 }
254 
255 LauAbsCoeffSet* LauCartesianCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
256 {
257  LauAbsCoeffSet* clone(0);
258  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart || cloneOption == TieCPPars ) {
259  clone = new LauCartesianCPCoeffSet( *this, cloneOption, constFactor );
260  clone->name( newName );
261  } else {
262  std::cerr << "ERROR in LauCartesianCPCoeffSet::createClone : Invalid clone option" << std::endl;
263  }
264  return clone;
265 }
266 
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.
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.
Bool_t blind() const
The blinding state.
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.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:62
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:35
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.
const LauBlind * blinder() const
Access the blinder object.
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.
void blindParameter(const TString &blindingString, const Double_t width)
Blind 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
Double_t unblindValue() const
The unblinded value of the parameter.
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.
Double_t blindingWidth() const
Obtain the Gaussian width.
Definition: LauBlind.hh:68
virtual const TString & baseName() const
Retrieve the base name of the coefficient set.
Class for blinding and unblinding a number based on a blinding string.
Definition: LauBlind.hh:28
static TRandom * getRandomiser()
Access the randomiser.
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.