laura is hosted by Hepforge, IPPP Durham
Laura++  v2r1
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  }
50 
51  if ( cloneOption == All || cloneOption == TieImagPart ) {
52  y_ = rhs.y_->createClone(constFactor);
53  } else {
54  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
55  }
56 }
57 
58 std::vector<LauParameter*> LauRealImagCoeffSet::getParameters()
59 {
60  std::vector<LauParameter*> pars;
61  pars.push_back(x_);
62  pars.push_back(y_);
63  return pars;
64 }
65 
67 {
68  std::cout<<"INFO in LauRealImagCoeffSet::printParValues : Component \""<<this->name()<<"\" has real part = "<<x_->value()<<" and imaginary part = "<<y_->value()<<"."<<std::endl;
69 }
70 
71 void LauRealImagCoeffSet::printTableHeading(std::ostream& stream) const
72 {
73  stream<<"\\begin{tabular}{|l|c|c|}"<<std::endl;
74  stream<<"\\hline"<<std::endl;
75  stream<<"Component & Real Part & Imaginary Part \\\\"<<std::endl;
76  stream<<"\\hline"<<std::endl;
77 }
78 
79 void LauRealImagCoeffSet::printTableRow(std::ostream& stream) const
80 {
81  LauPrint print;
82  TString resName = this->name();
83  resName = resName.ReplaceAll("_", "\\_");
84  stream<<resName<<" & $";
85  print.printFormat(stream, x_->value());
86  stream<<" \\pm ";
87  print.printFormat(stream, x_->error());
88  stream<<"$ & $";
89  print.printFormat(stream, y_->value());
90  stream<<" \\pm ";
91  print.printFormat(stream, y_->error());
92  stream<<"$ \\\\"<<std::endl;
93 }
94 
96 {
97  if (x_->fixed() == kFALSE) {
98  // Choose a value between -10.0 and 10.0
99  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*20.0 - 10.0;
100  x_->initValue(value); x_->value(value);
101  }
102  if (y_->fixed() == kFALSE) {
103  // Choose a value between -10.0 and 10.0
104  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*20.0 - 10.0;
105  y_->initValue(value); y_->value(value);
106  }
107 }
108 
110 {
111  x_->updatePull();
112  y_->updatePull();
113 }
114 
116 {
118  return coeff_;
119 }
120 
122 {
123  return this->particleCoeff();
124 }
125 
126 void LauRealImagCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
127 {
128  LauComplex average( coeff );
129  average += coeffBar;
130  average.rescale( 0.5 );
131 
132  Double_t xVal( average.re() );
133  Double_t yVal( average.im() );
134 
135  x_->value( xVal );
136  y_->value( yVal );
137 
138  if ( init ) {
139  x_->genValue( xVal );
140  y_->genValue( yVal );
141 
142  x_->initValue( xVal );
143  y_->initValue( yVal );
144  }
145 }
146 
148 {
149  TString parName(this->baseName()); parName += "_ACP";
150  return LauParameter(parName,0.0);
151 }
152 
153 LauAbsCoeffSet* LauRealImagCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
154 {
155  LauAbsCoeffSet* clone(0);
156  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart ) {
157  clone = new LauRealImagCoeffSet( *this, cloneOption, constFactor );
158  clone->name( newName );
159  } else {
160  std::cerr << "ERROR in LauRealImagCoeffSet::createClone : Invalid clone option" << std::endl;
161  }
162  return clone;
163 }
164 
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:202
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:211
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.
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.
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:33
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.
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:311
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:282
Double_t initValue() const
The initial value of 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
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.
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.
Double_t genValue() const
The value generated for the parameter.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.