laura is hosted by Hepforge, IPPP Durham
Laura++  v3r3
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauRealImagCPCoeffSet.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 
22 #include "LauRealImagCPCoeffSet.hh"
23 #include "LauComplex.hh"
24 #include "LauConstants.hh"
25 #include "LauParameter.hh"
26 #include "LauPrint.hh"
27 
29 
30 
31 LauRealImagCPCoeffSet::LauRealImagCPCoeffSet(const TString& compName, Double_t x, Double_t y, Double_t xbar, Double_t ybar,
32  Bool_t xFixed, Bool_t yFixed, Bool_t xbarFixed, Bool_t ybarFixed) :
33  LauAbsCoeffSet(compName),
34  x_(new LauParameter("X", x, minRealImagPart_, maxRealImagPart_, xFixed)),
35  y_(new LauParameter("Y", y, minRealImagPart_, maxRealImagPart_, yFixed)),
36  xbar_(new LauParameter("Xbar", xbar, minRealImagPart_, maxRealImagPart_, xbarFixed)),
37  ybar_(new LauParameter("Ybar", ybar, minRealImagPart_, maxRealImagPart_, ybarFixed)),
38  particleCoeff_(x,y),
39  antiparticleCoeff_(xbar,ybar),
40  acp_("ACP", 0.0, -1.0, 1.0, kTRUE)
41 {
42 }
43 
45  x_(0),
46  y_(0),
47  xbar_(0),
48  ybar_(0),
49  particleCoeff_( rhs.particleCoeff_ ),
50  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
51  acp_( rhs.acp_ )
52 {
53  if ( cloneOption == All || cloneOption == TieRealPart ) {
54  x_ = rhs.x_->createClone(constFactor);
55  xbar_ = rhs.xbar_->createClone(constFactor);
56  } else {
57  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
58  if ( rhs.x_->blind() ) {
59  const LauBlind* blinder = rhs.x_->blinder();
60  x_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
61  }
62  xbar_ = new LauParameter("Xbar", rhs.xbar_->value(), minRealImagPart_, maxRealImagPart_, rhs.xbar_->fixed());
63  if ( rhs.xbar_->blind() ) {
64  const LauBlind* blinder = rhs.xbar_->blinder();
65  xbar_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
66  }
67  }
68 
69  if ( cloneOption == All || cloneOption == TieImagPart ) {
70  y_ = rhs.y_->createClone(constFactor);
71  ybar_ = rhs.ybar_->createClone(constFactor);
72  } else {
73  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
74  if ( rhs.y_->blind() ) {
75  const LauBlind* blinder = rhs.y_->blinder();
76  y_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
77  }
78  ybar_ = new LauParameter("Ybar", rhs.ybar_->value(), minRealImagPart_, maxRealImagPart_, rhs.ybar_->fixed());
79  if ( rhs.ybar_->blind() ) {
80  const LauBlind* blinder = rhs.ybar_->blinder();
81  ybar_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
82  }
83  }
84 }
85 
86 std::vector<LauParameter*> LauRealImagCPCoeffSet::getParameters()
87 {
88  std::vector<LauParameter*> pars;
89  pars.push_back(x_);
90  pars.push_back(y_);
91  pars.push_back(xbar_);
92  pars.push_back(ybar_);
93  return pars;
94 }
95 
97 {
98  std::cout << "INFO in LauRealImagCPCoeffSet::printParValues : Component \"" << this->name() << "\" has ";
99  std::cout << "x = " << x_->value() << ",\t";
100  std::cout << "y = " << y_->value() << ",\t";
101  std::cout << "xbar = " << xbar_->value() << ",\t";
102  std::cout << "ybar = " << ybar_->value() << "." << std::endl;
103 }
104 
105 void LauRealImagCPCoeffSet::printTableHeading(std::ostream& stream) const
106 {
107  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<std::endl;
108  stream<<"\\hline"<<std::endl;
109  stream<<"Component & Particle Real Part & Particle Imaginary Part & Antiparticle Real Part & Antiparticle Imaginary Part \\\\"<<std::endl;
110  stream<<"\\hline"<<std::endl;
111 }
112 
113 void LauRealImagCPCoeffSet::printTableRow(std::ostream& stream) const
114 {
115  LauPrint print;
116  TString resName = this->name();
117  resName = resName.ReplaceAll("_", "\\_");
118  stream<<resName<<" & $";
119  print.printFormat(stream, x_->value());
120  stream<<" \\pm ";
121  print.printFormat(stream, x_->error());
122  stream<<"$ & $";
123  print.printFormat(stream, y_->value());
124  stream<<" \\pm ";
125  print.printFormat(stream, y_->error());
126  stream<<"$ & $";
127  print.printFormat(stream, xbar_->value());
128  stream<<" \\pm ";
129  print.printFormat(stream, xbar_->error());
130  stream<<"$ & $";
131  print.printFormat(stream, ybar_->value());
132  stream<<" \\pm ";
133  print.printFormat(stream, ybar_->error());
134  stream<<"$ \\\\"<<std::endl;
135 }
136 
138 {
139  if (x_->fixed() == kFALSE) {
140  // Choose a value for "X" between -3.0 and 3.0
141  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
142  x_->initValue(value); x_->value(value);
143  }
144  if (y_->fixed() == kFALSE) {
145  // Choose a value for "Y" between -3.0 and 3.0
146  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
147  y_->initValue(value); y_->value(value);
148  }
149  if (xbar_->fixed() == kFALSE) {
150  // Choose a value for "Xbar" between -3.0 and 3.0
151  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
152  xbar_->initValue(value); xbar_->value(value);
153  }
154  if (ybar_->fixed() == kFALSE) {
155  // Choose a value for "Ybar" between -3.0 and 3.0
156  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
157  ybar_->initValue(value); ybar_->value(value);
158  }
159 }
160 
162 {
163  // update the pulls
164  x_->updatePull();
165  y_->updatePull();
166  xbar_->updatePull();
167  ybar_->updatePull();
168 }
169 
171 {
173  return particleCoeff_;
174 }
175 
177 {
179  return antiparticleCoeff_;
180 }
181 
182 void LauRealImagCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
183 {
184  Double_t xVal( coeff.re() );
185  Double_t yVal( coeff.im() );
186  Double_t xBarVal( coeffBar.re() );
187  Double_t yBarVal( coeffBar.im() );
188 
189  x_->value( xVal );
190  y_->value( yVal );
191  xbar_->value( xBarVal );
192  ybar_->value( yBarVal );
193 
194  if ( init ) {
195  x_->genValue( xVal );
196  y_->genValue( yVal );
197  xbar_->genValue( xBarVal );
198  ybar_->genValue( yBarVal );
199 
200  x_->initValue( xVal );
201  y_->initValue( yVal );
202  xbar_->initValue( xBarVal );
203  ybar_->initValue( yBarVal );
204  }
205 }
206 
208 {
209  // set the name
210  TString parName(this->baseName()); parName += "_ACP";
211  acp_.name(parName);
212 
213  // work out the ACP value
214  Double_t csq = x_->value()*x_->value() + y_->value()*y_->value();
215  Double_t cbarsq = xbar_->value()*xbar_->value() + ybar_->value()*ybar_->value();
216  Double_t numer = cbarsq - csq;
217  Double_t denom = cbarsq + csq;
218  Double_t value = numer/denom;
219 
220  // is it fixed?
221  Bool_t fixed = x_->fixed() && y_->fixed() && xbar_->fixed() && ybar_->fixed();
222  acp_.fixed(fixed);
223 
224  // we can't work out the error without the covariance matrix
225  Double_t error(0.0);
226 
227  // set the value and error
228  acp_.valueAndErrors(value,error);
229 
230  return acp_;
231 }
232 
233 LauAbsCoeffSet* LauRealImagCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
234 {
235  LauAbsCoeffSet* clone(0);
236  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart ) {
237  clone = new LauRealImagCPCoeffSet( *this, cloneOption, constFactor );
238  clone->name( newName );
239  } else {
240  std::cerr << "ERROR in LauRealImagCPCoeffSet::createClone : Invalid clone option" << std::endl;
241  }
242  return clone;
243 }
244 
LauRealImagCPCoeffSet(const TString &compName, Double_t x, Double_t y, Double_t xbar, Double_t ybar, Bool_t xFixed, Bool_t yFixed, Bool_t xbarFixed, Bool_t ybarFixed)
Constructor.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
File containing declaration of LauRealImagCPCoeffSet class.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar, Bool_t init)
Set the parameters based on the complex coefficients for particles and antiparticles.
ClassImp(LauAbsCoeffSet)
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
const TString & name() const
The parameter name.
Double_t re() const
Get the real part.
Definition: LauComplex.hh:205
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:214
static Double_t maxRealImagPart_
Maximum allowed value of real/imaginary part parameters.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
File containing declaration of LauPrint class.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
Class to define various output print commands.
Definition: LauPrint.hh:29
LauParameter * y_
The imaginary part for the particle.
LauComplex particleCoeff_
The particle complex coefficient.
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.
File containing declaration of LauParameter class.
File containing declaration of LauComplex class.
LauParameter acp_
The CP asymmetry.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
LauParameter * x_
The real part for the particle.
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.
LauParameter * ybar_
The imaginary part for the antiparticle.
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.
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
virtual void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
Class for defining a complex coefficient using a simple Cartesian CP convention.
Double_t initValue() const
The initial value of the parameter.
void blindParameter(const TString &blindingString, const Double_t width)
Blind the parameter.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
File containing LauConstants namespace.
LauParameter * xbar_
The real part for the antiparticle.
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.
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.
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.
virtual LauParameter acp()
Calculate the CP asymmetry.
virtual void printParValues() const
Print the current values of the parameters.