laura is hosted by Hepforge, IPPP Durham
Laura++  v3r1
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauRealImagGammaCPCoeffSet.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2013 - 2014.
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 LauRealImagGammaCPCoeffSet::LauRealImagGammaCPCoeffSet(const TString& compName, const Double_t x, const Double_t y, const Double_t xCP, const Double_t yCP, const Double_t xbarCP, const Double_t ybarCP,
33  const Bool_t xFixed, const Bool_t yFixed, const Bool_t xCPFixed, const Bool_t yCPFixed, const Bool_t xbarCPFixed, const Bool_t ybarCPFixed) :
34  LauAbsCoeffSet(compName),
35  x_(new LauParameter("X", x, minRealImagPart_, maxRealImagPart_, xFixed)),
36  y_(new LauParameter("Y", y, minRealImagPart_, maxRealImagPart_, yFixed)),
37  xCP_(new LauParameter("XCP", xCP, minRealImagPart_, maxRealImagPart_, xCPFixed)),
38  yCP_(new LauParameter("YCP", yCP, minRealImagPart_, maxRealImagPart_, yCPFixed)),
39  xbarCP_(new LauParameter("XbarCP", xbarCP, minRealImagPart_, maxRealImagPart_, xbarCPFixed)),
40  ybarCP_(new LauParameter("YbarCP", ybarCP, minRealImagPart_, maxRealImagPart_, ybarCPFixed)),
41  nonCPPart_( x, y),
42  cpPart_( 1+xCP, yCP ),
43  cpAntiPart_( 1+xbarCP, ybarCP ),
44  particleCoeff_( nonCPPart_ * cpPart_ ),
45  antiparticleCoeff_( nonCPPart_ * cpAntiPart_ ),
46  acp_("ACP", (antiparticleCoeff_.abs2()-particleCoeff_.abs2())/(antiparticleCoeff_.abs2()+particleCoeff_.abs2()), -1.0, 1.0, xCPFixed&&yCPFixed&&xbarCPFixed&&ybarCPFixed)
47 {
48 }
49 
51  x_(0),
52  y_(0),
53  xCP_(0),
54  yCP_(0),
55  xbarCP_(0),
56  ybarCP_(0),
57  nonCPPart_( rhs.nonCPPart_ ),
58  cpPart_( rhs.cpPart_ ),
59  cpAntiPart_( rhs.cpAntiPart_ ),
60  particleCoeff_( rhs.particleCoeff_ ),
61  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
62  acp_( rhs.acp_ )
63 {
64  if ( cloneOption == All || cloneOption == TieRealPart ) {
65  x_ = rhs.x_->createClone(constFactor);
66  } else {
67  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
68  if ( rhs.x_->blind() ) {
69  const LauBlind* blinder = rhs.x_->blinder();
70  x_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
71  }
72  }
73 
74  if ( cloneOption == All || cloneOption == TieImagPart ) {
75  y_ = rhs.y_->createClone(constFactor);
76  } else {
77  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
78  if ( rhs.y_->blind() ) {
79  const LauBlind* blinder = rhs.y_->blinder();
80  y_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
81  }
82  }
83 
84  if ( cloneOption == All || cloneOption == TieCPPars ) {
85  xCP_ = rhs.xCP_->createClone(constFactor);
86  yCP_ = rhs.yCP_->createClone(constFactor);
87  xbarCP_ = rhs.xbarCP_->createClone(constFactor);
88  ybarCP_ = rhs.ybarCP_->createClone(constFactor);
89  } else {
90  xCP_ = new LauParameter("XCP", rhs.xCP_->value(), minRealImagPart_, maxRealImagPart_, rhs.xCP_->fixed());
91  if ( rhs.xCP_->blind() ) {
92  const LauBlind* blinder = rhs.xCP_->blinder();
93  xCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
94  }
95  yCP_ = new LauParameter("YCP", rhs.yCP_->value(), minRealImagPart_, maxRealImagPart_, rhs.yCP_->fixed());
96  if ( rhs.yCP_->blind() ) {
97  const LauBlind* blinder = rhs.yCP_->blinder();
98  yCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
99  }
101  if ( rhs.xbarCP_->blind() ) {
102  const LauBlind* blinder = rhs.xbarCP_->blinder();
103  xbarCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
104  }
106  if ( rhs.ybarCP_->blind() ) {
107  const LauBlind* blinder = rhs.ybarCP_->blinder();
108  ybarCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
109  }
110  }
111 }
112 
113 std::vector<LauParameter*> LauRealImagGammaCPCoeffSet::getParameters()
114 {
115  std::vector<LauParameter*> pars;
116  pars.push_back(x_);
117  pars.push_back(y_);
118  if(!xCP_->fixed()) pars.push_back(xCP_);
119  if(!yCP_->fixed()) pars.push_back(yCP_);
120  if(!xbarCP_->fixed()) pars.push_back(xbarCP_);
121  if(!ybarCP_->fixed()) pars.push_back(ybarCP_);
122  return pars;
123 }
124 
126 {
127  std::cout << "INFO in LauRealImagGammaCPCoeffSet::printParValues : Component \"" << this->name() << "\" has ";
128  std::cout << "x = " << x_->value() << ",\t";
129  std::cout << "y = " << y_->value() << ",\t";
130  std::cout << "xCP = " << xCP_->value() << ",\t";
131  std::cout << "yCP = " << yCP_->value() << ",\t";
132  std::cout << "xbarCP = " << xbarCP_->value() << ",\t";
133  std::cout << "ybarCP = " << ybarCP_->value() << "." << std::endl;
134 }
135 
136 void LauRealImagGammaCPCoeffSet::printTableHeading(std::ostream& stream) const
137 {
138  stream<<"\\begin{tabular}{|l|c|c|c|c|c|c|}"<<std::endl;
139  stream<<"\\hline"<<std::endl;
140  stream<<"Component & Real Part & Imaginary Part & Particle CP Real Part & Particle CP Imaginary Part & Antiparticle CP Real Part & Antiparticle CP Imaginary Part \\\\"<<std::endl;
141  stream<<"\\hline"<<std::endl;
142 }
143 
144 void LauRealImagGammaCPCoeffSet::printTableRow(std::ostream& stream) const
145 {
146  LauPrint print;
147  TString resName = this->name();
148  resName = resName.ReplaceAll("_", "\\_");
149  stream<<resName<<" & $";
150  print.printFormat(stream, x_->value());
151  stream<<" \\pm ";
152  print.printFormat(stream, x_->error());
153  stream<<"$ & $";
154  print.printFormat(stream, y_->value());
155  stream<<" \\pm ";
156  print.printFormat(stream, y_->error());
157  stream<<"$ & $";
158  print.printFormat(stream, xCP_->value());
159  stream<<" \\pm ";
160  print.printFormat(stream, xCP_->error());
161  stream<<"$ & $";
162  print.printFormat(stream, yCP_->value());
163  stream<<" \\pm ";
164  print.printFormat(stream, yCP_->error());
165  stream<<"$ & $";
166  print.printFormat(stream, xbarCP_->value());
167  stream<<" \\pm ";
168  print.printFormat(stream, xbarCP_->error());
169  stream<<"$ & $";
170  print.printFormat(stream, ybarCP_->value());
171  stream<<" \\pm ";
172  print.printFormat(stream, ybarCP_->error());
173  stream<<"$ \\\\"<<std::endl;
174 }
175 
177 {
178  if (x_->fixed() == kFALSE) {
179  // Choose a value for "X" between -3.0 and 3.0
180  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
181  x_->initValue(value); x_->value(value);
182  }
183  if (y_->fixed() == kFALSE) {
184  // Choose a value for "Y" between -3.0 and 3.0
185  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
186  y_->initValue(value); y_->value(value);
187  }
188  if (xCP_->fixed() == kFALSE) {
189  // Choose a value for "XCP" between -3.0 and 3.0
190  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
191  xCP_->initValue(value); xCP_->value(value);
192  }
193  if (yCP_->fixed() == kFALSE) {
194  // Choose a value for "YCP" between -3.0 and 3.0
195  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
196  yCP_->initValue(value); yCP_->value(value);
197  }
198  if (xbarCP_->fixed() == kFALSE) {
199  // Choose a value for "XbarCP" between -3.0 and 3.0
200  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
201  xbarCP_->initValue(value); xbarCP_->value(value);
202  }
203  if (ybarCP_->fixed() == kFALSE) {
204  // Choose a value for "YbarCP" between -3.0 and 3.0
205  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
206  ybarCP_->initValue(value); ybarCP_->value(value);
207  }
208 }
209 
211 {
212  // update the pulls
213  x_->updatePull();
214  y_->updatePull();
215  xCP_->updatePull();
216  yCP_->updatePull();
217  xbarCP_->updatePull();
218  ybarCP_->updatePull();
219 }
220 
222 {
226  return particleCoeff_;
227 }
228 
230 {
234  return antiparticleCoeff_;
235 }
236 
238 {
239  std::cerr << "ERROR in LauCartesianGammaCPCoeffSet::setCoeffValues : Method not supported by this class - too many parameters" << std::endl;
240 }
241 
243 {
244  // set the name
245  TString parName(this->baseName()); parName += "_ACP";
246  acp_.name(parName);
247 
248  // work out the ACP value
249  const LauComplex nonCPPart( x_->value(), y_->value() );
250  const LauComplex cpPart( 1.0+xCP_->value(), yCP_->value() );
251  const LauComplex cpAntiPart( 1.0+xbarCP_->value(), ybarCP_->value() );
252  const LauComplex partCoeff = nonCPPart * cpPart;
253  const LauComplex antiCoeff = nonCPPart * cpAntiPart;
254 
255  const Double_t numer = antiCoeff.abs2() - partCoeff.abs2();
256  const Double_t denom = antiCoeff.abs2() + partCoeff.abs2();
257  const Double_t value = numer/denom;
258 
259  // is it fixed?
260  const Bool_t fixed = xCP_->fixed() && yCP_->fixed() && xbarCP_->fixed() && ybarCP_->fixed();
261  acp_.fixed(fixed);
262 
263  // we can't work out the error without the covariance matrix
264  const Double_t error(0.0);
265 
266  // set the value and error
267  acp_.valueAndErrors(value,error);
268 
269  return acp_;
270 }
271 
272 LauAbsCoeffSet* LauRealImagGammaCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
273 {
274  LauAbsCoeffSet* clone(0);
275  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart || cloneOption == TieCPPars ) {
276  clone = new LauRealImagGammaCPCoeffSet( *this, cloneOption, constFactor );
277  clone->name( newName );
278  } else {
279  std::cerr << "ERROR in LauRealImagGammaCPCoeffSet::createClone : Invalid clone option" << std::endl;
280  }
281  return clone;
282 }
283 
LauRealImagGammaCPCoeffSet(const TString &compName, const Double_t x, const Double_t y, const Double_t xCP, const Double_t yCP, const Double_t xbarCP, const Double_t ybarCP, const Bool_t xFixed, const Bool_t yFixed, const Bool_t xCPFixed, const Bool_t yCPFixed, const Bool_t xbarCPFixed, const Bool_t ybarCPFixed)
Constructor.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
TRandom * zeroSeedRandom()
Access the singleton random number generator with seed set from machine clock time (within +-1 sec)...
Definition: LauRandom.cc:30
LauParameter * xbarCP_
The real CP part for the antiparticle.
LauComplex cpAntiPart_
The CP part of the complex coefficient for the antiparticle.
ClassImp(LauAbsCoeffSet)
virtual void printParValues() const
Print the current values of the parameters.
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
const TString & name() const
The parameter name.
Class for defining a complex coefficient using a Cartesian nonCP part multiplied by a simple Cartesia...
static Double_t maxRealImagPart_
Maximum allowed value of 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.
File containing declaration of LauPrint class.
Class to define various output print commands.
Definition: LauPrint.hh:29
LauParameter * ybarCP_
The imaginary CP part for the antiparticle.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
LauComplex particleCoeff_
The particle complex coefficient.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
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.
LauComplex cpPart_
The CP part of the complex coefficient for the particle.
Bool_t blind() const
The blinding state.
LauParameter * yCP_
The imaginary CP part for the particle.
LauParameter * xCP_
The real CP part for the particle.
File containing declaration of LauParameter class.
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.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar, Bool_t init)
Set the parameters based on the complex coefficients for particles and antiparticles.
File containing declaration of LauRealImagGammaCPCoeffSet class.
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 const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
static Double_t minRealImagPart_
Minimum allowed value of real/imaginary part parameters.
File containing LauRandom namespace.
LauParameter * y_
The imaginary nonCP part.
const LauBlind * blinder() const
Access the blinder object.
LauParameter acp_
The CP asymmetry.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:314
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
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.
LauParameter * x_
The real nonCP part.
Double_t value() const
The value of the parameter.
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.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
Class for blinding and unblinding a number based on a blinding string.
Definition: LauBlind.hh:28
LauComplex nonCPPart_
The nonCP part of the complex coefficient.
virtual void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
virtual LauParameter acp()
Calculate the CP asymmetry.