laura is hosted by Hepforge, IPPP Durham
Laura++  v3r5
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauRealImagCoeffSet.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2006 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 "LauComplex.hh"
37 #include "LauConstants.hh"
38 #include "LauRealImagCoeffSet.hh"
39 #include "LauParameter.hh"
40 #include "LauPrint.hh"
41 
43 
44 
45 LauRealImagCoeffSet::LauRealImagCoeffSet(const TString& compName, Double_t x, Double_t y, Bool_t xFixed, Bool_t yFixed) :
46  LauAbsCoeffSet(compName),
47  x_(new LauParameter("X",x,minRealImagPart_,maxRealImagPart_,xFixed)),
48  y_(new LauParameter("Y",y,minRealImagPart_,maxRealImagPart_,yFixed)),
49  coeff_(x,y)
50 {
51 }
52 
53 LauRealImagCoeffSet::LauRealImagCoeffSet(const LauRealImagCoeffSet& rhs, CloneOption cloneOption, Double_t constFactor) : LauAbsCoeffSet(rhs.name()),
54  x_(0),
55  y_(0),
56  coeff_( rhs.coeff_ )
57 {
58  if ( cloneOption == All || cloneOption == TieRealPart ) {
59  x_ = rhs.x_->createClone(constFactor);
60  } else {
61  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
62  if ( rhs.x_->blind() ) {
63  const LauBlind* blinder = rhs.x_->blinder();
64  x_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
65  }
66  }
67 
68  if ( cloneOption == All || cloneOption == TieImagPart ) {
69  y_ = rhs.y_->createClone(constFactor);
70  } else {
71  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
72  if ( rhs.y_->blind() ) {
73  const LauBlind* blinder = rhs.y_->blinder();
74  y_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
75  }
76  }
77 }
78 
79 std::vector<LauParameter*> LauRealImagCoeffSet::getParameters()
80 {
81  std::vector<LauParameter*> pars;
82  pars.push_back(x_);
83  pars.push_back(y_);
84  return pars;
85 }
86 
88 {
89  std::cout<<"INFO in LauRealImagCoeffSet::printParValues : Component \""<<this->name()<<"\" has real part = "<<x_->value()<<" and imaginary part = "<<y_->value()<<"."<<std::endl;
90 }
91 
92 void LauRealImagCoeffSet::printTableHeading(std::ostream& stream) const
93 {
94  stream<<"\\begin{tabular}{|l|c|c|}"<<std::endl;
95  stream<<"\\hline"<<std::endl;
96  stream<<"Component & Real Part & Imaginary Part \\\\"<<std::endl;
97  stream<<"\\hline"<<std::endl;
98 }
99 
100 void LauRealImagCoeffSet::printTableRow(std::ostream& stream) const
101 {
102  LauPrint print;
103  TString resName = this->name();
104  resName = resName.ReplaceAll("_", "\\_");
105  stream<<resName<<" & $";
106  print.printFormat(stream, x_->value());
107  stream<<" \\pm ";
108  print.printFormat(stream, x_->error());
109  stream<<"$ & $";
110  print.printFormat(stream, y_->value());
111  stream<<" \\pm ";
112  print.printFormat(stream, y_->error());
113  stream<<"$ \\\\"<<std::endl;
114 }
115 
117 {
118  if (x_->fixed() == kFALSE) {
119  // Choose a value between -10.0 and 10.0
120  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*20.0 - 10.0;
121  x_->initValue(value); x_->value(value);
122  }
123  if (y_->fixed() == kFALSE) {
124  // Choose a value between -10.0 and 10.0
125  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*20.0 - 10.0;
126  y_->initValue(value); y_->value(value);
127  }
128 }
129 
131 {
132  x_->updatePull();
133  y_->updatePull();
134 }
135 
137 {
139  return coeff_;
140 }
141 
143 {
144  return this->particleCoeff();
145 }
146 
147 void LauRealImagCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
148 {
149  LauComplex average( coeff );
150  average += coeffBar;
151  average.rescale( 0.5 );
152 
153  Double_t xVal( average.re() );
154  Double_t yVal( average.im() );
155 
156  x_->value( xVal );
157  y_->value( yVal );
158 
159  if ( init ) {
160  x_->genValue( xVal );
161  y_->genValue( yVal );
162 
163  x_->initValue( xVal );
164  y_->initValue( yVal );
165  }
166 }
167 
169 {
170  TString parName(this->baseName()); parName += "_ACP";
171  return LauParameter(parName,0.0);
172 }
173 
174 LauAbsCoeffSet* LauRealImagCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
175 {
176  LauAbsCoeffSet* clone(0);
177  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart ) {
178  clone = new LauRealImagCoeffSet( *this, cloneOption, constFactor );
179  clone->name( newName );
180  } else {
181  std::cerr << "ERROR in LauRealImagCoeffSet::createClone : Invalid clone option" << std::endl;
182  }
183  return clone;
184 }
185 
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:44
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: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.
LauParameter * x_
The real part.
File containing declaration of LauPrint class.
Class to define various output print commands.
Definition: LauPrint.hh:43
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: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
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:328
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:299
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:46
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: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.
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:82
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:42
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.