laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
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 "LauRealImagCPCoeffSet.hh"
30 
31 #include "LauComplex.hh"
32 #include "LauConstants.hh"
33 #include "LauParameter.hh"
34 #include "LauPrint.hh"
35 
36 #include "TMath.h"
37 #include "TRandom.h"
38 
39 #include <fstream>
40 #include <iostream>
41 #include <vector>
42 
44  Double_t x,
45  Double_t y,
46  Double_t xbar,
47  Double_t ybar,
48  Bool_t xFixed,
49  Bool_t yFixed,
50  Bool_t xbarFixed,
51  Bool_t ybarFixed ) :
52  LauAbsCoeffSet( compName ),
53  x_( new LauParameter( "X", x, minRealImagPart_, maxRealImagPart_, xFixed ) ),
54  y_( new LauParameter( "Y", y, minRealImagPart_, maxRealImagPart_, yFixed ) ),
55  xbar_( new LauParameter( "Xbar", xbar, minRealImagPart_, maxRealImagPart_, xbarFixed ) ),
56  ybar_( new LauParameter( "Ybar", ybar, minRealImagPart_, maxRealImagPart_, ybarFixed ) ),
57  particleCoeff_( x, y ),
58  antiparticleCoeff_( xbar, ybar ),
59  acp_( "ACP", 0.0, -1.0, 1.0, kTRUE )
60 {
61 }
62 
64  CloneOption cloneOption,
65  Double_t constFactor ) :
66  LauAbsCoeffSet( rhs.name() ),
67  x_( 0 ),
68  y_( 0 ),
69  xbar_( 0 ),
70  ybar_( 0 ),
71  particleCoeff_( rhs.particleCoeff_ ),
72  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
73  acp_( rhs.acp_ )
74 {
75  if ( cloneOption == All || cloneOption == TieRealPart ) {
76  x_ = rhs.x_->createClone( constFactor );
77  xbar_ = rhs.xbar_->createClone( constFactor );
78  } else {
79  x_ = new LauParameter( "X",
80  rhs.x_->value(),
83  rhs.x_->fixed() );
84  if ( rhs.x_->blind() ) {
85  const LauBlind* blinder = rhs.x_->blinder();
87  }
88  xbar_ = new LauParameter( "Xbar",
89  rhs.xbar_->value(),
92  rhs.xbar_->fixed() );
93  if ( rhs.xbar_->blind() ) {
94  const LauBlind* blinder = rhs.xbar_->blinder();
96  }
97  }
98 
99  if ( cloneOption == All || cloneOption == TieImagPart ) {
100  y_ = rhs.y_->createClone( constFactor );
101  ybar_ = rhs.ybar_->createClone( constFactor );
102  } else {
103  y_ = new LauParameter( "Y",
104  rhs.y_->value(),
107  rhs.y_->fixed() );
108  if ( rhs.y_->blind() ) {
109  const LauBlind* blinder = rhs.y_->blinder();
111  }
112  ybar_ = new LauParameter( "Ybar",
113  rhs.ybar_->value(),
116  rhs.ybar_->fixed() );
117  if ( rhs.ybar_->blind() ) {
118  const LauBlind* blinder = rhs.ybar_->blinder();
120  }
121  }
122 }
123 
124 std::vector<LauParameter*> LauRealImagCPCoeffSet::getParameters()
125 {
126  std::vector<LauParameter*> pars;
127  pars.push_back( x_ );
128  pars.push_back( y_ );
129  pars.push_back( xbar_ );
130  pars.push_back( ybar_ );
131  return pars;
132 }
133 
135 {
136  std::cout << "INFO in LauRealImagCPCoeffSet::printParValues : Component \"" << this->name()
137  << "\" has ";
138  std::cout << "x = " << x_->value() << ",\t";
139  std::cout << "y = " << y_->value() << ",\t";
140  std::cout << "xbar = " << xbar_->value() << ",\t";
141  std::cout << "ybar = " << ybar_->value() << "." << std::endl;
142 }
143 
144 void LauRealImagCPCoeffSet::printTableHeading( std::ostream& stream ) const
145 {
146  stream << "\\begin{tabular}{|l|c|c|c|c|}" << std::endl;
147  stream << "\\hline" << std::endl;
148  stream << "Component & Particle Real Part & Particle Imaginary Part & Antiparticle Real Part & Antiparticle Imaginary Part \\\\"
149  << std::endl;
150  stream << "\\hline" << std::endl;
151 }
152 
153 void LauRealImagCPCoeffSet::printTableRow( std::ostream& stream ) const
154 {
155  LauPrint print;
156  TString resName = this->name();
157  resName = resName.ReplaceAll( "_", "\\_" );
158  stream << resName << " & $";
159  print.printFormat( stream, x_->value() );
160  stream << " \\pm ";
161  print.printFormat( stream, x_->error() );
162  stream << "$ & $";
163  print.printFormat( stream, y_->value() );
164  stream << " \\pm ";
165  print.printFormat( stream, y_->error() );
166  stream << "$ & $";
167  print.printFormat( stream, xbar_->value() );
168  stream << " \\pm ";
169  print.printFormat( stream, xbar_->error() );
170  stream << "$ & $";
171  print.printFormat( stream, ybar_->value() );
172  stream << " \\pm ";
173  print.printFormat( stream, ybar_->error() );
174  stream << "$ \\\\" << std::endl;
175 }
176 
178 {
179  if ( x_->fixed() == kFALSE ) {
180  // Choose a value for "X" between -3.0 and 3.0
181  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm() * 6.0 - 3.0;
182  x_->initValue( value );
183  x_->value( value );
184  }
185  if ( y_->fixed() == kFALSE ) {
186  // Choose a value for "Y" between -3.0 and 3.0
187  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm() * 6.0 - 3.0;
188  y_->initValue( value );
189  y_->value( value );
190  }
191  if ( xbar_->fixed() == kFALSE ) {
192  // Choose a value for "Xbar" between -3.0 and 3.0
193  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm() * 6.0 - 3.0;
194  xbar_->initValue( value );
195  xbar_->value( value );
196  }
197  if ( ybar_->fixed() == kFALSE ) {
198  // Choose a value for "Ybar" between -3.0 and 3.0
199  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm() * 6.0 - 3.0;
200  ybar_->initValue( value );
201  ybar_->value( value );
202  }
203 }
204 
206 {
207  // update the pulls
208  x_->updatePull();
209  y_->updatePull();
210  xbar_->updatePull();
211  ybar_->updatePull();
212 }
213 
215 {
217  return particleCoeff_;
218 }
219 
221 {
223  return antiparticleCoeff_;
224 }
225 
227  const LauComplex& coeffBar,
228  Bool_t init )
229 {
230  Double_t xVal( coeff.re() );
231  Double_t yVal( coeff.im() );
232  Double_t xBarVal( coeffBar.re() );
233  Double_t yBarVal( coeffBar.im() );
234 
235  x_->value( xVal );
236  y_->value( yVal );
237  xbar_->value( xBarVal );
238  ybar_->value( yBarVal );
239 
240  if ( init ) {
241  x_->genValue( xVal );
242  y_->genValue( yVal );
243  xbar_->genValue( xBarVal );
244  ybar_->genValue( yBarVal );
245 
246  x_->initValue( xVal );
247  y_->initValue( yVal );
248  xbar_->initValue( xBarVal );
249  ybar_->initValue( yBarVal );
250  }
251 }
252 
254 {
255  // set the name
256  TString parName( this->baseName() );
257  parName += "_ACP";
258  acp_.name( parName );
259 
260  // work out the ACP value
261  Double_t csq = x_->value() * x_->value() + y_->value() * y_->value();
262  Double_t cbarsq = xbar_->value() * xbar_->value() + ybar_->value() * ybar_->value();
263  Double_t numer = cbarsq - csq;
264  Double_t denom = cbarsq + csq;
265  Double_t value = numer / denom;
266 
267  // is it fixed?
268  Bool_t fixed = x_->fixed() && y_->fixed() && xbar_->fixed() && ybar_->fixed();
269  acp_.fixed( fixed );
270 
271  // we can't work out the error without the covariance matrix
272  Double_t error( 0.0 );
273 
274  // set the value and error
276 
277  return acp_;
278 }
279 
281  CloneOption cloneOption,
282  Double_t constFactor )
283 {
284  LauAbsCoeffSet* clone( 0 );
285  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart ) {
286  clone = new LauRealImagCPCoeffSet( *this, cloneOption, constFactor );
287  clone->name( newName );
288  } else {
289  std::cerr << "ERROR in LauRealImagCPCoeffSet::createClone : Invalid clone option"
290  << std::endl;
291  }
292  return clone;
293 }
virtual void finaliseValues()
Make sure values are in "standard" ranges, e.g. phases should be between -pi and pi.
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.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
Class for defining the abstract interface for complex coefficient classes.
Class for defining the fit parameter objects.
Definition: LauParameter.hh:49
Double_t unblindValue() const
The unblinded value of the parameter.
LauParameter * x_
The real part for the particle.
Double_t value() const
The value of the parameter.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
const LauBlind * blinder() const
Access the blinder object.
LauComplex particleCoeff_
The particle complex coefficient.
virtual TString name() const
Retrieve the name of the coefficient set.
File containing declaration of LauParameter class.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit.
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
virtual void printParValues() const
Print the current values of the 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 void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
virtual const TString & baseName() const
Retrieve the base name of the coefficient set.
Class for defining a complex number.
Definition: LauComplex.hh:61
virtual LauParameter acp()
Calculate the CP asymmetry.
Bool_t blind() const
The blinding state.
Class for blinding and unblinding a number based on a blinding string.
Definition: LauBlind.hh:42
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:324
Bool_t clone() const
Check whether is a clone or not.
Class for defining a complex coefficient using a simple Cartesian CP convention.
File containing declaration of LauComplex class.
LauParameter * createClone(Double_t constFactor=1.0)
Method to create a clone from the parent parameter using the copy constructor.
void blindParameter(const TString &blindingString, const Double_t width)
Blind the parameter.
Double_t blindingWidth() const
Obtain the Gaussian width.
Definition: LauBlind.hh:82
Bool_t fixed() const
Check whether the parameter is fixed or floated.
LauParameter()
Default constructor.
Definition: LauParameter.cc:40
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 LauRealImagCPCoeffSet class.
File containing LauConstants namespace.
Double_t re() const
Get the real part.
Definition: LauComplex.hh:242
const TString & name() const
The parameter name.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:76
Double_t error() const
The error on the parameter.
LauParameter * xbar_
The real part for the antiparticle.
static TRandom * getRandomiser()
Access the randomiser.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
LauParameter acp_
The CP asymmetry.
void updatePull()
Call to update the bias and pull values.
File containing declaration of LauPrint class and LauOutputLevel enum.
CloneOption
Options for cloning operation.
static Double_t maxRealImagPart_
Maximum allowed value of real/imaginary part parameters.
Class to define various output print commands.
Definition: LauPrint.hh:54
LauParameter * y_
The imaginary part for the particle.
Double_t genValue() const
The value generated for the parameter.
static Double_t minRealImagPart_
Minimum allowed value of real/imaginary part parameters.
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.
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:248
void printFormat(std::ostream &stream, Double_t value) const
Method to choose the printing format to a specified level of precision.
Definition: LauPrint.cc:43
Double_t initValue() const
The initial value of the parameter.