laura is hosted by Hepforge, IPPP Durham
Laura++  v2r1
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauMagPhaseCoeffSet.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 "LauMagPhaseCoeffSet.hh"
25 #include "LauParameter.hh"
26 #include "LauPrint.hh"
27 #include "LauRandom.hh"
28 
30 
31 
32 LauMagPhaseCoeffSet::LauMagPhaseCoeffSet(const TString& compName, Double_t magnitude, Double_t phase, Bool_t magFixed, Bool_t phaseFixed) :
33  LauAbsCoeffSet(compName),
34  magnitude_(new LauParameter("A",magnitude,minMagnitude_,maxMagnitude_,magFixed)),
35  phase_(new LauParameter("Delta",phase,minPhase_,maxPhase_,phaseFixed)),
36  coeff_(magnitude*TMath::Cos(phase), magnitude*TMath::Sin(phase))
37 {
38 }
39 
40 LauMagPhaseCoeffSet::LauMagPhaseCoeffSet(const LauMagPhaseCoeffSet& rhs, CloneOption cloneOption, Double_t constFactor) : LauAbsCoeffSet(rhs.name()),
41  magnitude_(0),
42  phase_(0),
43  coeff_( rhs.coeff_ )
44 {
45  if ( cloneOption == All || cloneOption == TieMagnitude ) {
46  magnitude_ = rhs.magnitude_->createClone(constFactor);
47  } else {
49  }
50 
51  if ( cloneOption == All || cloneOption == TiePhase ) {
52  phase_ = rhs.phase_->createClone(constFactor);
53  } else {
54  phase_ = new LauParameter("Delta", rhs.phase_->value(), minPhase_, maxPhase_, rhs.phase_->fixed());
55  }
56 }
57 
58 std::vector<LauParameter*> LauMagPhaseCoeffSet::getParameters()
59 {
60  std::vector<LauParameter*> pars;
61  pars.push_back(magnitude_);
62  pars.push_back(phase_);
63  return pars;
64 }
65 
67 {
68  std::cout<<"INFO in LauMagPhaseCoeffSet::printParValues : Component \""<<this->name()<<"\" has magnitude = "<<magnitude_->value()<<" and phase = "<<phase_->value()<<"."<<std::endl;
69 }
70 
71 void LauMagPhaseCoeffSet::printTableHeading(std::ostream& stream) const
72 {
73  stream<<"\\begin{tabular}{|l|c|c|}"<<std::endl;
74  stream<<"\\hline"<<std::endl;
75  stream<<"Component & Magnitude & Phase \\\\"<<std::endl;
76  stream<<"\\hline"<<std::endl;
77 }
78 
79 void LauMagPhaseCoeffSet::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, magnitude_->value());
86  stream<<" \\pm ";
87  print.printFormat(stream, magnitude_->error());
88  stream<<"$ & $";
89  print.printFormat(stream, phase_->value());
90  stream<<" \\pm ";
91  print.printFormat(stream, phase_->error());
92  stream<<"$ \\\\"<<std::endl;
93 }
94 
96 {
97  if (magnitude_->fixed() == kFALSE) {
98  // Choose a magnitude between 0.0 and 2.0
99  Double_t mag = LauRandom::zeroSeedRandom()->Rndm()*2.0;
100  magnitude_->initValue(mag); magnitude_->value(mag);
101  }
102  if (phase_->fixed() == kFALSE) {
103  // Choose a phase between +- pi
105  phase_->initValue(phase); phase_->value(phase);
106  }
107 }
108 
110 {
111  // retrieve the current values from the parameters
112  Double_t mag = magnitude_->value();
113  Double_t phase = phase_->value();
114  Double_t genPhase = phase_->genValue();
115 
116  // Check whether we have a negative magnitude.
117  // If so make it positive and add pi to the phase.
118  if (mag < 0.0) {
119  mag *= -1.0;
120  phase += LauConstants::pi;
121  }
122 
123  // Check now whether the phase lies in the right range (-pi to pi).
124  Bool_t withinRange(kFALSE);
125  while (withinRange == kFALSE) {
126  if (phase > -LauConstants::pi && phase < LauConstants::pi) {
127  withinRange = kTRUE;
128  } else {
129  // Not within the specified range
130  if (phase > LauConstants::pi) {
131  phase -= LauConstants::twoPi;
132  } else if (phase < -LauConstants::pi) {
133  phase += LauConstants::twoPi;
134  }
135  }
136  }
137 
138  // A further problem can occur when the generated phase is close to -pi or pi.
139  // The phase can wrap over to the other end of the scale -
140  // this leads to artificially large pulls so we wrap it back.
141  Double_t diff = phase - genPhase;
142  if (diff > LauConstants::pi) {
143  phase -= LauConstants::twoPi;
144  } else if (diff < -LauConstants::pi) {
145  phase += LauConstants::twoPi;
146  }
147 
148  // finally store the new values in the parameters
149  // and update the pulls
151  phase_->value(phase); phase_->updatePull();
152 }
153 
155 {
156  coeff_.setRealImagPart(magnitude_->value()*TMath::Cos(phase_->value()), magnitude_->value()*TMath::Sin(phase_->value()));
157  return coeff_;
158 }
159 
161 {
162  return this->particleCoeff();
163 }
164 
165 void LauMagPhaseCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
166 {
167  LauComplex average( coeff );
168  average += coeffBar;
169  average.rescale( 0.5 );
170 
171  Double_t magVal( average.abs() );
172  Double_t phaseVal( average.arg() );
173 
174  magnitude_->value( magVal );
175  phase_->value( phaseVal );
176 
177  if ( init ) {
178  magnitude_->genValue( magVal );
179  phase_->genValue( phaseVal );
180 
181  magnitude_->initValue( magVal );
182  phase_->initValue( phaseVal );
183  }
184 }
185 
187 {
188  TString parName(this->baseName()); parName += "_ACP";
189  return LauParameter(parName,0.0);
190 }
191 
192 LauAbsCoeffSet* LauMagPhaseCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
193 {
194  LauAbsCoeffSet* clone(0);
195  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude ) {
196  clone = new LauMagPhaseCoeffSet( *this, cloneOption, constFactor );
197  clone->name( newName );
198  } else {
199  std::cerr << "ERROR in LauMagPhaseCoeffSet::createClone : Invalid clone option" << std::endl;
200  }
201  return clone;
202 }
203 
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
static Double_t maxPhase_
Maximum allowed value of phase parameters.
LauParameter * magnitude_
The magnitude.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
virtual void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
TRandom * zeroSeedRandom()
Access the singleton random number generator with seed set from machine clock time (within +-1 sec)...
Definition: LauRandom.cc:30
const Double_t twoPi
Two times Pi.
Definition: LauConstants.hh:93
ClassImp(LauAbsCoeffSet)
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
const TString & name() const
The parameter name.
File containing declaration of LauPrint class.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
Class to define various output print commands.
Definition: LauPrint.hh:29
LauMagPhaseCoeffSet(const TString &compName, Double_t magnitude, Double_t phase, Bool_t magFixed, Bool_t phaseFixed)
Constructor.
virtual LauParameter acp()
Calculate the CP asymmetry.
CloneOption
Options for cloning operation.
Bool_t clone() const
Check whether is a clone or not.
LauComplex coeff_
The complex coefficient.
static Double_t maxMagnitude_
Maximum allowed value of magnitude parameters.
File containing declaration of LauParameter class.
virtual void printParValues() const
Print the current values of the parameters.
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
File containing declaration of LauComplex class.
Double_t error() const
The error on the parameter.
const Double_t pi
Pi.
Definition: LauConstants.hh:89
Class for defining the abstract interface for complex coefficient classes.
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 defining the fit parameter objects.
Definition: LauParameter.hh:33
File containing LauRandom namespace.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:311
LauParameter * phase_
The phase.
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:282
Double_t initValue() const
The initial value of the parameter.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
File containing LauConstants namespace.
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
Class for defining a complex number.
Definition: LauComplex.hh:47
void updatePull()
Call to update the bias and pull values.
Double_t arg() const
Obtain the phase angle of the complex number.
Definition: LauComplex.hh:238
LauParameter * createClone(Double_t constFactor=1.0)
Method to create a clone from the parent parameter using the copy constructor.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
virtual TString name() const
Retrieve the name of the coefficient set.
File containing declaration of LauMagPhaseCoeffSet class.
static Double_t minPhase_
Minimum allowed value of phase parameters.
Double_t value() const
The value of the parameter.
static Double_t minMagnitude_
Minimum allowed value of magnitude parameters.
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:220
virtual const TString & baseName() const
Retrieve the base name of the coefficient set.
Double_t genValue() const
The value generated for the parameter.
Class for defining a complex coefficient using a magnitude and a phase.