laura is hosted by Hepforge, IPPP Durham
Laura++  v3r3
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauRealImagCoeffSet.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 
22 #include "LauComplex.hh"
23 #include "LauConstants.hh"
24 #include "LauRealImagCoeffSet.hh"
25 #include "LauParameter.hh"
26 #include "LauPrint.hh"
27 
29 
30 
31 LauRealImagCoeffSet::LauRealImagCoeffSet(const TString& compName, Double_t x, Double_t y, Bool_t xFixed, Bool_t yFixed) :
32  LauAbsCoeffSet(compName),
33  x_(new LauParameter("X",x,minRealImagPart_,maxRealImagPart_,xFixed)),
34  y_(new LauParameter("Y",y,minRealImagPart_,maxRealImagPart_,yFixed)),
35  coeff_(x,y)
36 {
37 }
38 
39 LauRealImagCoeffSet::LauRealImagCoeffSet(const LauRealImagCoeffSet& rhs, CloneOption cloneOption, Double_t constFactor) : LauAbsCoeffSet(rhs.name()),
40  x_(0),
41  y_(0),
42  coeff_( rhs.coeff_ )
43 {
44  if ( cloneOption == All || cloneOption == TieRealPart ) {
45  x_ = rhs.x_->createClone(constFactor);
46  } else {
47  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
48  if ( rhs.x_->blind() ) {
49  const LauBlind* blinder = rhs.x_->blinder();
50  x_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
51  }
52  }
53 
54  if ( cloneOption == All || cloneOption == TieImagPart ) {
55  y_ = rhs.y_->createClone(constFactor);
56  } else {
57  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
58  if ( rhs.y_->blind() ) {
59  const LauBlind* blinder = rhs.y_->blinder();
60  y_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
61  }
62  }
63 }
64 
65 std::vector<LauParameter*> LauRealImagCoeffSet::getParameters()
66 {
67  std::vector<LauParameter*> pars;
68  pars.push_back(x_);
69  pars.push_back(y_);
70  return pars;
71 }
72 
74 {
75  std::cout<<"INFO in LauRealImagCoeffSet::printParValues : Component \""<<this->name()<<"\" has real part = "<<x_->value()<<" and imaginary part = "<<y_->value()<<"."<<std::endl;
76 }
77 
78 void LauRealImagCoeffSet::printTableHeading(std::ostream& stream) const
79 {
80  stream<<"\\begin{tabular}{|l|c|c|}"<<std::endl;
81  stream<<"\\hline"<<std::endl;
82  stream<<"Component & Real Part & Imaginary Part \\\\"<<std::endl;
83  stream<<"\\hline"<<std::endl;
84 }
85 
86 void LauRealImagCoeffSet::printTableRow(std::ostream& stream) const
87 {
88  LauPrint print;
89  TString resName = this->name();
90  resName = resName.ReplaceAll("_", "\\_");
91  stream<<resName<<" & $";
92  print.printFormat(stream, x_->value());
93  stream<<" \\pm ";
94  print.printFormat(stream, x_->error());
95  stream<<"$ & $";
96  print.printFormat(stream, y_->value());
97  stream<<" \\pm ";
98  print.printFormat(stream, y_->error());
99  stream<<"$ \\\\"<<std::endl;
100 }
101 
103 {
104  if (x_->fixed() == kFALSE) {
105  // Choose a value between -10.0 and 10.0
106  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*20.0 - 10.0;
107  x_->initValue(value); x_->value(value);
108  }
109  if (y_->fixed() == kFALSE) {
110  // Choose a value between -10.0 and 10.0
111  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*20.0 - 10.0;
112  y_->initValue(value); y_->value(value);
113  }
114 }
115 
117 {
118  x_->updatePull();
119  y_->updatePull();
120 }
121 
123 {
125  return coeff_;
126 }
127 
129 {
130  return this->particleCoeff();
131 }
132 
133 void LauRealImagCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
134 {
135  LauComplex average( coeff );
136  average += coeffBar;
137  average.rescale( 0.5 );
138 
139  Double_t xVal( average.re() );
140  Double_t yVal( average.im() );
141 
142  x_->value( xVal );
143  y_->value( yVal );
144 
145  if ( init ) {
146  x_->genValue( xVal );
147  y_->genValue( yVal );
148 
149  x_->initValue( xVal );
150  y_->initValue( yVal );
151  }
152 }
153 
155 {
156  TString parName(this->baseName()); parName += "_ACP";
157  return LauParameter(parName,0.0);
158 }
159 
160 LauAbsCoeffSet* LauRealImagCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
161 {
162  LauAbsCoeffSet* clone(0);
163  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart ) {
164  clone = new LauRealImagCoeffSet( *this, cloneOption, constFactor );
165  clone->name( newName );
166  } else {
167  std::cerr << "ERROR in LauRealImagCoeffSet::createClone : Invalid clone option" << std::endl;
168  }
169  return clone;
170 }
171 
virtual void printParValues() const
Print the current values of the parameters.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
ClassImp(LauAbsCoeffSet)
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
const TString & name() const
The parameter name.
LauRealImagCoeffSet(const TString &compName, Double_t x, Double_t y, Bool_t xFixed, Bool_t yFixed)
Constructor.
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.
LauParameter * x_
The real part.
File containing declaration of LauPrint class.
Class to define various output print commands.
Definition: LauPrint.hh:29
CloneOption
Options for cloning operation.
Bool_t clone() const
Check whether is a clone or not.
Bool_t blind() const
The blinding state.
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
LauComplex coeff_
The complex coefficient.
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...
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.
Class for defining the fit parameter objects.
Definition: LauParameter.hh:35
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
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 LauParameter acp()
Calculate the CP asymmetry.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:314
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:285
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.
Class for defining a complex coefficient using real and imaginary parts.
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.
File containing declaration of LauRealImagCoeffSet class.
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 * y_
The imaginary 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 setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar, Bool_t init)
Set the parameters based on the complex coefficients for particles and antiparticles.
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 const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.