laura is hosted by Hepforge, IPPP Durham
Laura++  v3r1
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 #include "LauRandom.hh"
28 
30 
31 
32 LauRealImagCoeffSet::LauRealImagCoeffSet(const TString& compName, Double_t x, Double_t y, Bool_t xFixed, Bool_t yFixed) :
33  LauAbsCoeffSet(compName),
34  x_(new LauParameter("X",x,minRealImagPart_,maxRealImagPart_,xFixed)),
35  y_(new LauParameter("Y",y,minRealImagPart_,maxRealImagPart_,yFixed)),
36  coeff_(x,y)
37 {
38 }
39 
40 LauRealImagCoeffSet::LauRealImagCoeffSet(const LauRealImagCoeffSet& rhs, CloneOption cloneOption, Double_t constFactor) : LauAbsCoeffSet(rhs.name()),
41  x_(0),
42  y_(0),
43  coeff_( rhs.coeff_ )
44 {
45  if ( cloneOption == All || cloneOption == TieRealPart ) {
46  x_ = rhs.x_->createClone(constFactor);
47  } else {
48  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
49  if ( rhs.x_->blind() ) {
50  const LauBlind* blinder = rhs.x_->blinder();
51  x_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
52  }
53  }
54 
55  if ( cloneOption == All || cloneOption == TieImagPart ) {
56  y_ = rhs.y_->createClone(constFactor);
57  } else {
58  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
59  if ( rhs.y_->blind() ) {
60  const LauBlind* blinder = rhs.y_->blinder();
61  y_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
62  }
63  }
64 }
65 
66 std::vector<LauParameter*> LauRealImagCoeffSet::getParameters()
67 {
68  std::vector<LauParameter*> pars;
69  pars.push_back(x_);
70  pars.push_back(y_);
71  return pars;
72 }
73 
75 {
76  std::cout<<"INFO in LauRealImagCoeffSet::printParValues : Component \""<<this->name()<<"\" has real part = "<<x_->value()<<" and imaginary part = "<<y_->value()<<"."<<std::endl;
77 }
78 
79 void LauRealImagCoeffSet::printTableHeading(std::ostream& stream) const
80 {
81  stream<<"\\begin{tabular}{|l|c|c|}"<<std::endl;
82  stream<<"\\hline"<<std::endl;
83  stream<<"Component & Real Part & Imaginary Part \\\\"<<std::endl;
84  stream<<"\\hline"<<std::endl;
85 }
86 
87 void LauRealImagCoeffSet::printTableRow(std::ostream& stream) const
88 {
89  LauPrint print;
90  TString resName = this->name();
91  resName = resName.ReplaceAll("_", "\\_");
92  stream<<resName<<" & $";
93  print.printFormat(stream, x_->value());
94  stream<<" \\pm ";
95  print.printFormat(stream, x_->error());
96  stream<<"$ & $";
97  print.printFormat(stream, y_->value());
98  stream<<" \\pm ";
99  print.printFormat(stream, y_->error());
100  stream<<"$ \\\\"<<std::endl;
101 }
102 
104 {
105  if (x_->fixed() == kFALSE) {
106  // Choose a value between -10.0 and 10.0
107  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*20.0 - 10.0;
108  x_->initValue(value); x_->value(value);
109  }
110  if (y_->fixed() == kFALSE) {
111  // Choose a value between -10.0 and 10.0
112  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*20.0 - 10.0;
113  y_->initValue(value); y_->value(value);
114  }
115 }
116 
118 {
119  x_->updatePull();
120  y_->updatePull();
121 }
122 
124 {
126  return coeff_;
127 }
128 
130 {
131  return this->particleCoeff();
132 }
133 
134 void LauRealImagCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
135 {
136  LauComplex average( coeff );
137  average += coeffBar;
138  average.rescale( 0.5 );
139 
140  Double_t xVal( average.re() );
141  Double_t yVal( average.im() );
142 
143  x_->value( xVal );
144  y_->value( yVal );
145 
146  if ( init ) {
147  x_->genValue( xVal );
148  y_->genValue( yVal );
149 
150  x_->initValue( xVal );
151  y_->initValue( yVal );
152  }
153 }
154 
156 {
157  TString parName(this->baseName()); parName += "_ACP";
158  return LauParameter(parName,0.0);
159 }
160 
161 LauAbsCoeffSet* LauRealImagCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
162 {
163  LauAbsCoeffSet* clone(0);
164  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart ) {
165  clone = new LauRealImagCoeffSet( *this, cloneOption, constFactor );
166  clone->name( newName );
167  } else {
168  std::cerr << "ERROR in LauRealImagCoeffSet::createClone : Invalid clone option" << std::endl;
169  }
170  return clone;
171 }
172 
virtual void printParValues() const
Print the current values of the parameters.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
TRandom * zeroSeedRandom()
Access the singleton random number generator with seed set from machine clock time (within +-1 sec)...
Definition: LauRandom.cc:30
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.
File containing LauRandom namespace.
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
Double_t genValue() const
The value generated for the parameter.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.