laura is hosted by Hepforge, IPPP Durham
Laura++  v3r1
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  if ( rhs.magnitude_->blind() ) {
50  const LauBlind* blinder = rhs.magnitude_->blinder();
51  magnitude_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
52  }
53  }
54 
55  if ( cloneOption == All || cloneOption == TiePhase ) {
56  phase_ = rhs.phase_->createClone(constFactor);
57  } else {
58  phase_ = new LauParameter("Delta", rhs.phase_->value(), minPhase_, maxPhase_, rhs.phase_->fixed());
59  if ( rhs.phase_->blind() ) {
60  const LauBlind* blinder = rhs.phase_->blinder();
61  phase_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
62  }
63  }
64 }
65 
66 std::vector<LauParameter*> LauMagPhaseCoeffSet::getParameters()
67 {
68  std::vector<LauParameter*> pars;
69  pars.push_back(magnitude_);
70  pars.push_back(phase_);
71  return pars;
72 }
73 
75 {
76  std::cout<<"INFO in LauMagPhaseCoeffSet::printParValues : Component \""<<this->name()<<"\" has magnitude = "<<magnitude_->value()<<" and phase = "<<phase_->value()<<"."<<std::endl;
77 }
78 
79 void LauMagPhaseCoeffSet::printTableHeading(std::ostream& stream) const
80 {
81  stream<<"\\begin{tabular}{|l|c|c|}"<<std::endl;
82  stream<<"\\hline"<<std::endl;
83  stream<<"Component & Magnitude & Phase \\\\"<<std::endl;
84  stream<<"\\hline"<<std::endl;
85 }
86 
87 void LauMagPhaseCoeffSet::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, magnitude_->value());
94  stream<<" \\pm ";
95  print.printFormat(stream, magnitude_->error());
96  stream<<"$ & $";
97  print.printFormat(stream, phase_->value());
98  stream<<" \\pm ";
99  print.printFormat(stream, phase_->error());
100  stream<<"$ \\\\"<<std::endl;
101 }
102 
104 {
105  if (magnitude_->fixed() == kFALSE) {
106  // Choose a magnitude between 0.0 and 2.0
107  Double_t mag = LauRandom::zeroSeedRandom()->Rndm()*2.0;
108  magnitude_->initValue(mag); magnitude_->value(mag);
109  }
110  if (phase_->fixed() == kFALSE) {
111  // Choose a phase between +- pi
113  phase_->initValue(phase); phase_->value(phase);
114  }
115 }
116 
118 {
119  // retrieve the current values from the parameters
120  Double_t mag = magnitude_->value();
121  Double_t phase = phase_->value();
122  Double_t genPhase = phase_->genValue();
123 
124  // Check whether we have a negative magnitude.
125  // If so make it positive and add pi to the phase.
126  if (mag < 0.0) {
127  mag *= -1.0;
128  phase += LauConstants::pi;
129  }
130 
131  // Check now whether the phase lies in the right range (-pi to pi).
132  Bool_t withinRange(kFALSE);
133  while (withinRange == kFALSE) {
134  if (phase > -LauConstants::pi && phase <= LauConstants::pi) {
135  withinRange = kTRUE;
136  } else {
137  // Not within the specified range
138  if (phase > LauConstants::pi) {
139  phase -= LauConstants::twoPi;
140  } else if (phase <= -LauConstants::pi) {
141  phase += LauConstants::twoPi;
142  }
143  }
144  }
145 
146  // A further problem can occur when the generated phase is close to -pi or pi.
147  // The phase can wrap over to the other end of the scale -
148  // this leads to artificially large pulls so we wrap it back.
149  Double_t diff = phase - genPhase;
150  if (diff > LauConstants::pi) {
151  phase -= LauConstants::twoPi;
152  } else if (diff < -LauConstants::pi) {
153  phase += LauConstants::twoPi;
154  }
155 
156  // finally store the new values in the parameters
157  // and update the pulls
159  phase_->value(phase); phase_->updatePull();
160 }
161 
163 {
165  return coeff_;
166 }
167 
169 {
170  return this->particleCoeff();
171 }
172 
173 void LauMagPhaseCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
174 {
175  LauComplex average( coeff );
176  average += coeffBar;
177  average.rescale( 0.5 );
178 
179  Double_t magVal( average.abs() );
180  Double_t phaseVal( average.arg() );
181 
182  magnitude_->value( magVal );
183  phase_->value( phaseVal );
184 
185  if ( init ) {
186  magnitude_->genValue( magVal );
187  phase_->genValue( phaseVal );
188 
189  magnitude_->initValue( magVal );
190  phase_->initValue( phaseVal );
191  }
192 }
193 
195 {
196  TString parName(this->baseName()); parName += "_ACP";
197  return LauParameter(parName,0.0);
198 }
199 
200 LauAbsCoeffSet* LauMagPhaseCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
201 {
202  LauAbsCoeffSet* clone(0);
203  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude ) {
204  clone = new LauMagPhaseCoeffSet( *this, cloneOption, constFactor );
205  clone->name( newName );
206  } else {
207  std::cerr << "ERROR in LauMagPhaseCoeffSet::createClone : Invalid clone option" << std::endl;
208  }
209  return clone;
210 }
211 
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.
Bool_t blind() const
The blinding state.
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.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:62
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:35
File containing LauRandom namespace.
const LauBlind * blinder() const
Access the blinder object.
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:314
LauParameter * phase_
The phase.
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:285
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.
void blindParameter(const TString &blindingString, const Double_t width)
Blind the parameter.
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
Double_t unblindValue() const
The unblinded value of the parameter.
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:241
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:223
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.
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.
Class for defining a complex coefficient using a magnitude and a phase.