laura is hosted by Hepforge, IPPP Durham
Laura++  v3r2
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauCartesianGammaCPCoeffSet.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 LauCartesianGammaCPCoeffSet::LauCartesianGammaCPCoeffSet(const TString& compName, const Double_t x, const Double_t y, const Double_t xCP, const Double_t yCP, const Double_t deltaXCP, const Double_t deltaYCP,
32  const Bool_t xFixed, const Bool_t yFixed, const Bool_t xCPFixed, const Bool_t yCPFixed, const Bool_t deltaXCPFixed, const Bool_t deltaYCPFixed, const Bool_t deltaXCPSecondStage, const Bool_t deltaYCPSecondStage) :
33  LauAbsCoeffSet(compName),
34  x_(new LauParameter("X", x, minRealImagPart_, maxRealImagPart_, xFixed)),
35  y_(new LauParameter("Y", y, minRealImagPart_, maxRealImagPart_, yFixed)),
36  xCP_(new LauParameter("XCP", xCP, minRealImagPart_, maxRealImagPart_, xCPFixed)),
37  yCP_(new LauParameter("YCP", yCP, minRealImagPart_, maxRealImagPart_, yCPFixed)),
38  deltaXCP_(new LauParameter("DeltaXCP", deltaXCP, minDelta_, maxDelta_, deltaXCPFixed)),
39  deltaYCP_(new LauParameter("DeltaYCP", deltaYCP, minDelta_, maxDelta_, deltaYCPFixed)),
40  nonCPPart_( x, y),
41  cpPart_( 1+xCP+deltaXCP, yCP+deltaYCP),
42  cpAntiPart_( 1+xCP-deltaXCP, yCP-deltaYCP),
43  particleCoeff_( nonCPPart_ * cpPart_ ),
44  antiparticleCoeff_( nonCPPart_ * cpAntiPart_ ),
45  acp_("ACP", (antiparticleCoeff_.abs2()-particleCoeff_.abs2())/(antiparticleCoeff_.abs2()+particleCoeff_.abs2()), -1.0, 1.0, deltaXCPFixed&&deltaYCPFixed)
46 {
47  if (deltaXCPSecondStage && !deltaXCPFixed) {
48  deltaXCP_->secondStage(kTRUE);
49  deltaXCP_->initValue(0.0);
50  }
51  if (deltaYCPSecondStage && !deltaYCPFixed) {
52  deltaYCP_->secondStage(kTRUE);
53  deltaYCP_->initValue(0.0);
54  }
55 }
56 
58  x_(0),
59  y_(0),
60  xCP_(0),
61  yCP_(0),
62  deltaXCP_(0),
63  deltaYCP_(0),
64  nonCPPart_( rhs.nonCPPart_ ),
65  cpPart_( rhs.cpPart_ ),
66  cpAntiPart_( rhs.cpAntiPart_ ),
67  particleCoeff_( rhs.particleCoeff_ ),
68  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
69  acp_( rhs.acp_ )
70 {
71  if ( cloneOption == All || cloneOption == TieRealPart ) {
72  x_ = rhs.x_->createClone(constFactor);
73  } else {
74  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
75  if ( rhs.x_->blind() ) {
76  const LauBlind* blinder = rhs.x_->blinder();
77  x_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
78  }
79  }
80 
81  if ( cloneOption == All || cloneOption == TieImagPart ) {
82  y_ = rhs.y_->createClone(constFactor);
83  } else {
84  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
85  if ( rhs.y_->blind() ) {
86  const LauBlind* blinder = rhs.y_->blinder();
87  y_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
88  }
89  }
90 
91  if ( cloneOption == All || cloneOption == TieCPPars ) {
92  xCP_ = rhs.xCP_->createClone(constFactor);
93  yCP_ = rhs.yCP_->createClone(constFactor);
94  deltaXCP_ = rhs.deltaXCP_->createClone(constFactor);
95  deltaYCP_ = rhs.deltaYCP_->createClone(constFactor);
96  } else {
97  xCP_ = new LauParameter("XCP", rhs.xCP_->value(), minRealImagPart_, maxRealImagPart_, rhs.xCP_->fixed());
98  if ( rhs.xCP_->blind() ) {
99  const LauBlind* blinder = rhs.xCP_->blinder();
100  xCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
101  }
102  yCP_ = new LauParameter("YCP", rhs.yCP_->value(), minRealImagPart_, maxRealImagPart_, rhs.yCP_->fixed());
103  if ( rhs.yCP_->blind() ) {
104  const LauBlind* blinder = rhs.yCP_->blinder();
105  yCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
106  }
107  deltaXCP_ = new LauParameter("DeltaXCP", rhs.deltaXCP_->value(), minDelta_, maxDelta_, rhs.deltaXCP_->fixed());
108  deltaYCP_ = new LauParameter("DeltaYCP", rhs.deltaYCP_->value(), minDelta_, maxDelta_, rhs.deltaYCP_->fixed());
109  if ( rhs.deltaXCP_->secondStage() && !rhs.deltaXCP_->fixed() ) {
110  deltaXCP_->secondStage(kTRUE);
111  deltaXCP_->initValue(0.0);
112  }
113  if ( rhs.deltaYCP_->secondStage() && !rhs.deltaYCP_->fixed() ) {
114  deltaYCP_->secondStage(kTRUE);
115  deltaYCP_->initValue(0.0);
116  }
117  if ( rhs.deltaXCP_->blind() ) {
118  const LauBlind* blinder = rhs.deltaXCP_->blinder();
119  deltaXCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
120  }
121  if ( rhs.deltaYCP_->blind() ) {
122  const LauBlind* blinder = rhs.deltaYCP_->blinder();
123  deltaYCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
124  }
125  }
126 }
127 
128 std::vector<LauParameter*> LauCartesianGammaCPCoeffSet::getParameters()
129 {
130  std::vector<LauParameter*> pars;
131  pars.push_back(x_);
132  pars.push_back(y_);
133  if(!xCP_->fixed()) pars.push_back(xCP_);
134  if(!yCP_->fixed()) pars.push_back(yCP_);
135  if(!deltaXCP_->fixed()) pars.push_back(deltaXCP_);
136  if(!deltaYCP_->fixed()) pars.push_back(deltaYCP_);
137  return pars;
138 }
139 
141 {
142  std::cout<<"INFO in LauCartesianGammaCPCoeffSet::printParValues : Component \""<<this->name()<<"\" has ";
143  std::cout<<"x = "<<x_->value()<<",\t";
144  std::cout<<"y = "<<y_->value()<<",\t";
145  std::cout<<"xCP = "<<xCP_->value()<<",\t";
146  std::cout<<"yCP = "<<yCP_->value()<<",\t";
147  std::cout<<"Delta xCP = "<<deltaXCP_->value()<<",\t";
148  std::cout<<"Delta yCP = "<<deltaYCP_->value()<<"."<<std::endl;
149 }
150 
151 void LauCartesianGammaCPCoeffSet::printTableHeading(std::ostream& stream) const
152 {
153  stream<<"\\begin{tabular}{|l|c|c|c|c|c|c|}"<<std::endl;
154  stream<<"\\hline"<<std::endl;
155  stream<<"Component & Real Part & Imaginary Part & Real CP Part & Imaginary CP Part & $\\Delta$ Real CP Part & $\\Delta$ Imaginary CP Part \\\\"<<std::endl;
156  stream<<"\\hline"<<std::endl;
157 }
158 
159 void LauCartesianGammaCPCoeffSet::printTableRow(std::ostream& stream) const
160 {
161  LauPrint print;
162  TString resName = this->name();
163  resName = resName.ReplaceAll("_", "\\_");
164  stream<<resName<<" & $";
165  print.printFormat(stream, x_->value());
166  stream<<" \\pm ";
167  print.printFormat(stream, x_->error());
168  stream<<"$ & $";
169  print.printFormat(stream, y_->value());
170  stream<<" \\pm ";
171  print.printFormat(stream, y_->error());
172  stream<<"$ & $";
173  print.printFormat(stream, xCP_->value());
174  stream<<" \\pm ";
175  print.printFormat(stream, xCP_->error());
176  stream<<"$ & $";
177  print.printFormat(stream, yCP_->value());
178  stream<<" \\pm ";
179  print.printFormat(stream, yCP_->error());
180  stream<<"$ & $";
181  print.printFormat(stream, deltaXCP_->value());
182  stream<<" \\pm ";
183  print.printFormat(stream, deltaXCP_->error());
184  stream<<"$ & $";
185  print.printFormat(stream, deltaYCP_->value());
186  stream<<" \\pm ";
187  print.printFormat(stream, deltaYCP_->error());
188  stream<<"$ \\\\"<<std::endl;
189 }
190 
192 {
193  if (x_->fixed() == kFALSE) {
194  // Choose a value for "X" between -3.0 and 3.0
195  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
196  x_->initValue(value); x_->value(value);
197  }
198  if (y_->fixed() == kFALSE) {
199  // Choose a value for "Y" between -3.0 and 3.0
200  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
201  y_->initValue(value); y_->value(value);
202  }
203  if (xCP_->fixed() == kFALSE) {
204  // Choose a value for "XCP" between -3.0 and 3.0
205  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
206  xCP_->initValue(value); xCP_->value(value);
207  }
208  if (yCP_->fixed() == kFALSE) {
209  // Choose a value for "YCP" between -3.0 and 3.0
210  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
211  yCP_->initValue(value); yCP_->value(value);
212  }
213  if (deltaXCP_->fixed() == kFALSE && deltaXCP_->secondStage() == kFALSE) {
214  // Choose a value for "Delta XCP" between -0.5 and 0.5
215  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*1.0 - 0.5;
216  deltaXCP_->initValue(value); deltaXCP_->value(value);
217  }
218  if (deltaYCP_->fixed() == kFALSE && deltaYCP_->secondStage() == kFALSE) {
219  // Choose a value for "Delta YCP" between -0.5 and 0.5
220  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*1.0 - 0.5;
221  deltaYCP_->initValue(value); deltaYCP_->value(value);
222  }
223 }
224 
226 {
227  // update the pulls
228  x_->updatePull();
229  y_->updatePull();
230  xCP_->updatePull();
231  yCP_->updatePull();
234 }
235 
237 {
241  return particleCoeff_;
242 }
243 
245 {
249  return antiparticleCoeff_;
250 }
251 
253 {
254  std::cerr << "ERROR in LauCartesianGammaCPCoeffSet::setCoeffValues : Method not supported by this class - too many parameters" << std::endl;
255 }
256 
258 {
259  // set the name
260  TString parName(this->baseName()); parName += "_ACP";
261  acp_.name(parName);
262 
263  // work out the ACP value
264  const LauComplex nonCPPart( x_->value(), y_->value() );
265  const LauComplex cpPart( 1.0+xCP_->value()+deltaXCP_->value(), yCP_->value()+deltaYCP_->value() );
266  const LauComplex cpAntiPart( 1.0+xCP_->value()-deltaXCP_->value(), yCP_->value()-deltaYCP_->value() );
267  const LauComplex partCoeff = nonCPPart * cpPart;
268  const LauComplex antiCoeff = nonCPPart * cpAntiPart;
269 
270  const Double_t numer = antiCoeff.abs2() - partCoeff.abs2();
271  const Double_t denom = antiCoeff.abs2() + partCoeff.abs2();
272  const Double_t value = numer/denom;
273 
274  // is it fixed?
275  const Bool_t fixed = deltaXCP_->fixed() && deltaYCP_->fixed();
276  acp_.fixed(fixed);
277 
278  // we can't work out the error without the covariance matrix
279  const Double_t error(0.0);
280 
281  // set the value and error
282  acp_.valueAndErrors(value,error);
283 
284  return acp_;
285 }
286 
287 LauAbsCoeffSet* LauCartesianGammaCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
288 {
289  LauAbsCoeffSet* clone(0);
290  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart || cloneOption == TieCPPars ) {
291  clone = new LauCartesianGammaCPCoeffSet( *this, cloneOption, constFactor );
292  clone->name( newName );
293  } else {
294  std::cerr << "ERROR in LauCartesianGammaCPCoeffSet::createClone : Invalid clone option" << std::endl;
295  }
296  return clone;
297 }
298 
LauParameter * yCP_
The average CP imaginary part.
virtual LauParameter acp()
Calculate the CP asymmetry.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
LauComplex cpAntiPart_
The CP part of the complex coefficient for the antiparticle.
static Double_t minDelta_
Minimum allowed value of CP-violating real/imaginary part parameters.
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
Class for defining a complex coefficient using the Cartesian gamma CP convention. ...
ClassImp(LauAbsCoeffSet)
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
const TString & name() const
The parameter name.
LauComplex cpPart_
The CP part of the complex coefficient for the particle.
static Double_t maxRealImagPart_
Maximum allowed value of real/imaginary part parameters.
static Double_t maxDelta_
Maximum allowed value of CP-violating real/imaginary part parameters.
LauParameter * y_
The nonCP imaginary part.
File containing declaration of LauPrint class.
Class to define various output print commands.
Definition: LauPrint.hh:29
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
CloneOption
Options for cloning operation.
Double_t abs2() const
Obtain the square of the absolute value of the complex number.
Definition: LauComplex.hh:232
Bool_t clone() const
Check whether is a clone or not.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
Bool_t blind() const
The blinding state.
LauComplex particleCoeff_
The particle complex coefficient.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
LauParameter acp_
The CP asymmetry.
File containing declaration of LauParameter class.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
Bool_t secondStage() const
Check whether the parameter should be floated only in the second stage of a two stage fit...
LauParameter * deltaXCP_
The asymmetric CP real part.
File containing declaration of LauComplex class.
LauParameter * x_
The nonCP real part.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:62
Double_t error() const
The error on the parameter.
LauParameter * xCP_
The average CP real part.
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.
virtual void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
static Double_t minRealImagPart_
Minimum allowed value of real/imaginary part parameters.
const LauBlind * blinder() const
Access the blinder object.
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 * deltaYCP_
The asymmetric CP imaginary part.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:314
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.
File containing declaration of LauCartesianGammaCPCoeffSet class.
LauCartesianGammaCPCoeffSet(const TString &compName, const Double_t x, const Double_t y, const Double_t xCP, const Double_t yCP, const Double_t deltaXCP, const Double_t deltaYCP, const Bool_t xFixed, const Bool_t yFixed, const Bool_t xCPFixed, const Bool_t yCPFixed, const Bool_t deltaXCPFixed, const Bool_t deltaYCPFixed, const Bool_t deltaXCPSecondStage=kFALSE, const Bool_t deltaYCPSecondStage=kFALSE)
Constructor.
Double_t value() const
The value of the parameter.
virtual void printParValues() const
Print the current values of the parameters.
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.
LauComplex nonCPPart_
The nonCP part of the complex coefficient.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.