laura is hosted by Hepforge, IPPP Durham
Laura++  v3r5
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauRealImagCPCoeffSet.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2014 University of Warwick
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 */
17 
18 /*
19 Laura++ package authors:
20 John Back
21 Paul Harrison
22 Thomas Latham
23 */
24 
29 #include <iostream>
30 #include <fstream>
31 #include <vector>
32 
33 #include "TMath.h"
34 #include "TRandom.h"
35 
36 #include "LauRealImagCPCoeffSet.hh"
37 #include "LauComplex.hh"
38 #include "LauConstants.hh"
39 #include "LauParameter.hh"
40 #include "LauPrint.hh"
41 
43 
44 
45 LauRealImagCPCoeffSet::LauRealImagCPCoeffSet(const TString& compName, Double_t x, Double_t y, Double_t xbar, Double_t ybar,
46  Bool_t xFixed, Bool_t yFixed, Bool_t xbarFixed, Bool_t ybarFixed) :
47  LauAbsCoeffSet(compName),
48  x_(new LauParameter("X", x, minRealImagPart_, maxRealImagPart_, xFixed)),
49  y_(new LauParameter("Y", y, minRealImagPart_, maxRealImagPart_, yFixed)),
50  xbar_(new LauParameter("Xbar", xbar, minRealImagPart_, maxRealImagPart_, xbarFixed)),
51  ybar_(new LauParameter("Ybar", ybar, minRealImagPart_, maxRealImagPart_, ybarFixed)),
52  particleCoeff_(x,y),
53  antiparticleCoeff_(xbar,ybar),
54  acp_("ACP", 0.0, -1.0, 1.0, kTRUE)
55 {
56 }
57 
59  x_(0),
60  y_(0),
61  xbar_(0),
62  ybar_(0),
63  particleCoeff_( rhs.particleCoeff_ ),
64  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
65  acp_( rhs.acp_ )
66 {
67  if ( cloneOption == All || cloneOption == TieRealPart ) {
68  x_ = rhs.x_->createClone(constFactor);
69  xbar_ = rhs.xbar_->createClone(constFactor);
70  } else {
71  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
72  if ( rhs.x_->blind() ) {
73  const LauBlind* blinder = rhs.x_->blinder();
74  x_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
75  }
76  xbar_ = new LauParameter("Xbar", rhs.xbar_->value(), minRealImagPart_, maxRealImagPart_, rhs.xbar_->fixed());
77  if ( rhs.xbar_->blind() ) {
78  const LauBlind* blinder = rhs.xbar_->blinder();
79  xbar_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
80  }
81  }
82 
83  if ( cloneOption == All || cloneOption == TieImagPart ) {
84  y_ = rhs.y_->createClone(constFactor);
85  ybar_ = rhs.ybar_->createClone(constFactor);
86  } else {
87  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
88  if ( rhs.y_->blind() ) {
89  const LauBlind* blinder = rhs.y_->blinder();
90  y_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
91  }
92  ybar_ = new LauParameter("Ybar", rhs.ybar_->value(), minRealImagPart_, maxRealImagPart_, rhs.ybar_->fixed());
93  if ( rhs.ybar_->blind() ) {
94  const LauBlind* blinder = rhs.ybar_->blinder();
95  ybar_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
96  }
97  }
98 }
99 
100 std::vector<LauParameter*> LauRealImagCPCoeffSet::getParameters()
101 {
102  std::vector<LauParameter*> pars;
103  pars.push_back(x_);
104  pars.push_back(y_);
105  pars.push_back(xbar_);
106  pars.push_back(ybar_);
107  return pars;
108 }
109 
111 {
112  std::cout << "INFO in LauRealImagCPCoeffSet::printParValues : Component \"" << this->name() << "\" has ";
113  std::cout << "x = " << x_->value() << ",\t";
114  std::cout << "y = " << y_->value() << ",\t";
115  std::cout << "xbar = " << xbar_->value() << ",\t";
116  std::cout << "ybar = " << ybar_->value() << "." << std::endl;
117 }
118 
119 void LauRealImagCPCoeffSet::printTableHeading(std::ostream& stream) const
120 {
121  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<std::endl;
122  stream<<"\\hline"<<std::endl;
123  stream<<"Component & Particle Real Part & Particle Imaginary Part & Antiparticle Real Part & Antiparticle Imaginary Part \\\\"<<std::endl;
124  stream<<"\\hline"<<std::endl;
125 }
126 
127 void LauRealImagCPCoeffSet::printTableRow(std::ostream& stream) const
128 {
129  LauPrint print;
130  TString resName = this->name();
131  resName = resName.ReplaceAll("_", "\\_");
132  stream<<resName<<" & $";
133  print.printFormat(stream, x_->value());
134  stream<<" \\pm ";
135  print.printFormat(stream, x_->error());
136  stream<<"$ & $";
137  print.printFormat(stream, y_->value());
138  stream<<" \\pm ";
139  print.printFormat(stream, y_->error());
140  stream<<"$ & $";
141  print.printFormat(stream, xbar_->value());
142  stream<<" \\pm ";
143  print.printFormat(stream, xbar_->error());
144  stream<<"$ & $";
145  print.printFormat(stream, ybar_->value());
146  stream<<" \\pm ";
147  print.printFormat(stream, ybar_->error());
148  stream<<"$ \\\\"<<std::endl;
149 }
150 
152 {
153  if (x_->fixed() == kFALSE) {
154  // Choose a value for "X" between -3.0 and 3.0
155  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
156  x_->initValue(value); x_->value(value);
157  }
158  if (y_->fixed() == kFALSE) {
159  // Choose a value for "Y" between -3.0 and 3.0
160  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
161  y_->initValue(value); y_->value(value);
162  }
163  if (xbar_->fixed() == kFALSE) {
164  // Choose a value for "Xbar" between -3.0 and 3.0
165  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
166  xbar_->initValue(value); xbar_->value(value);
167  }
168  if (ybar_->fixed() == kFALSE) {
169  // Choose a value for "Ybar" between -3.0 and 3.0
170  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
171  ybar_->initValue(value); ybar_->value(value);
172  }
173 }
174 
176 {
177  // update the pulls
178  x_->updatePull();
179  y_->updatePull();
180  xbar_->updatePull();
181  ybar_->updatePull();
182 }
183 
185 {
187  return particleCoeff_;
188 }
189 
191 {
193  return antiparticleCoeff_;
194 }
195 
196 void LauRealImagCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
197 {
198  Double_t xVal( coeff.re() );
199  Double_t yVal( coeff.im() );
200  Double_t xBarVal( coeffBar.re() );
201  Double_t yBarVal( coeffBar.im() );
202 
203  x_->value( xVal );
204  y_->value( yVal );
205  xbar_->value( xBarVal );
206  ybar_->value( yBarVal );
207 
208  if ( init ) {
209  x_->genValue( xVal );
210  y_->genValue( yVal );
211  xbar_->genValue( xBarVal );
212  ybar_->genValue( yBarVal );
213 
214  x_->initValue( xVal );
215  y_->initValue( yVal );
216  xbar_->initValue( xBarVal );
217  ybar_->initValue( yBarVal );
218  }
219 }
220 
222 {
223  // set the name
224  TString parName(this->baseName()); parName += "_ACP";
225  acp_.name(parName);
226 
227  // work out the ACP value
228  Double_t csq = x_->value()*x_->value() + y_->value()*y_->value();
229  Double_t cbarsq = xbar_->value()*xbar_->value() + ybar_->value()*ybar_->value();
230  Double_t numer = cbarsq - csq;
231  Double_t denom = cbarsq + csq;
232  Double_t value = numer/denom;
233 
234  // is it fixed?
235  Bool_t fixed = x_->fixed() && y_->fixed() && xbar_->fixed() && ybar_->fixed();
236  acp_.fixed(fixed);
237 
238  // we can't work out the error without the covariance matrix
239  Double_t error(0.0);
240 
241  // set the value and error
242  acp_.valueAndErrors(value,error);
243 
244  return acp_;
245 }
246 
247 LauAbsCoeffSet* LauRealImagCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
248 {
249  LauAbsCoeffSet* clone(0);
250  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart ) {
251  clone = new LauRealImagCPCoeffSet( *this, cloneOption, constFactor );
252  clone->name( newName );
253  } else {
254  std::cerr << "ERROR in LauRealImagCPCoeffSet::createClone : Invalid clone option" << std::endl;
255  }
256  return clone;
257 }
258 
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:44
const TString & name() const
The parameter name.
Double_t re() const
Get the real part.
Definition: LauComplex.hh:219
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:228
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:43
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:76
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:49
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:328
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:46
Double_t unblindValue() const
The unblinded value of the parameter.
Class for defining a complex number.
Definition: LauComplex.hh:61
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:82
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:42
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.