laura is hosted by Hepforge, IPPP Durham
Laura++  v3r2
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 
29 
30 
31 LauMagPhaseCoeffSet::LauMagPhaseCoeffSet(const TString& compName, Double_t magnitude, Double_t phase, Bool_t magFixed, Bool_t phaseFixed) :
32  LauAbsCoeffSet(compName),
33  magnitude_(new LauParameter("A",magnitude,minMagnitude_,maxMagnitude_,magFixed)),
34  phase_(new LauParameter("Delta",phase,minPhase_,maxPhase_,phaseFixed)),
35  coeff_(magnitude*TMath::Cos(phase), magnitude*TMath::Sin(phase))
36 {
37 }
38 
39 LauMagPhaseCoeffSet::LauMagPhaseCoeffSet(const LauMagPhaseCoeffSet& rhs, CloneOption cloneOption, Double_t constFactor) : LauAbsCoeffSet(rhs.name()),
40  magnitude_(0),
41  phase_(0),
42  coeff_( rhs.coeff_ )
43 {
44  if ( cloneOption == All || cloneOption == TieMagnitude ) {
45  magnitude_ = rhs.magnitude_->createClone(constFactor);
46  } else {
48  if ( rhs.magnitude_->blind() ) {
49  const LauBlind* blinder = rhs.magnitude_->blinder();
50  magnitude_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
51  }
52  }
53 
54  if ( cloneOption == All || cloneOption == TiePhase ) {
55  phase_ = rhs.phase_->createClone(constFactor);
56  } else {
57  phase_ = new LauParameter("Delta", rhs.phase_->value(), minPhase_, maxPhase_, rhs.phase_->fixed());
58  if ( rhs.phase_->blind() ) {
59  const LauBlind* blinder = rhs.phase_->blinder();
60  phase_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
61  }
62  }
63 }
64 
65 std::vector<LauParameter*> LauMagPhaseCoeffSet::getParameters()
66 {
67  std::vector<LauParameter*> pars;
68  pars.push_back(magnitude_);
69  pars.push_back(phase_);
70  return pars;
71 }
72 
74 {
75  std::cout<<"INFO in LauMagPhaseCoeffSet::printParValues : Component \""<<this->name()<<"\" has magnitude = "<<magnitude_->value()<<" and phase = "<<phase_->value()<<"."<<std::endl;
76 }
77 
78 void LauMagPhaseCoeffSet::printTableHeading(std::ostream& stream) const
79 {
80  stream<<"\\begin{tabular}{|l|c|c|}"<<std::endl;
81  stream<<"\\hline"<<std::endl;
82  stream<<"Component & Magnitude & Phase \\\\"<<std::endl;
83  stream<<"\\hline"<<std::endl;
84 }
85 
86 void LauMagPhaseCoeffSet::printTableRow(std::ostream& stream) const
87 {
88  LauPrint print;
89  TString resName = this->name();
90  resName = resName.ReplaceAll("_", "\\_");
91  stream<<resName<<" & $";
92  print.printFormat(stream, magnitude_->value());
93  stream<<" \\pm ";
94  print.printFormat(stream, magnitude_->error());
95  stream<<"$ & $";
96  print.printFormat(stream, phase_->value());
97  stream<<" \\pm ";
98  print.printFormat(stream, phase_->error());
99  stream<<"$ \\\\"<<std::endl;
100 }
101 
103 {
104  if (magnitude_->fixed() == kFALSE) {
105  // Choose a magnitude between 0.0 and 2.0
106  Double_t mag = LauAbsCoeffSet::getRandomiser()->Rndm()*2.0;
107  magnitude_->initValue(mag); magnitude_->value(mag);
108  }
109  if (phase_->fixed() == kFALSE) {
110  // Choose a phase between +- pi
112  phase_->initValue(phase); phase_->value(phase);
113  }
114 }
115 
117 {
118  // retrieve the current values from the parameters
119  Double_t mag = magnitude_->value();
120  Double_t phase = phase_->value();
121  Double_t genPhase = phase_->genValue();
122 
123  // Check whether we have a negative magnitude.
124  // If so make it positive and add pi to the phase.
125  if (mag < 0.0) {
126  mag *= -1.0;
127  phase += LauConstants::pi;
128  }
129 
130  // Check now whether the phase lies in the right range (-pi to pi).
131  Bool_t withinRange(kFALSE);
132  while (withinRange == kFALSE) {
133  if (phase > -LauConstants::pi && phase <= LauConstants::pi) {
134  withinRange = kTRUE;
135  } else {
136  // Not within the specified range
137  if (phase > LauConstants::pi) {
138  phase -= LauConstants::twoPi;
139  } else if (phase <= -LauConstants::pi) {
140  phase += LauConstants::twoPi;
141  }
142  }
143  }
144 
145  // A further problem can occur when the generated phase is close to -pi or pi.
146  // The phase can wrap over to the other end of the scale -
147  // this leads to artificially large pulls so we wrap it back.
148  Double_t diff = phase - genPhase;
149  if (diff > LauConstants::pi) {
150  phase -= LauConstants::twoPi;
151  } else if (diff < -LauConstants::pi) {
152  phase += LauConstants::twoPi;
153  }
154 
155  // finally store the new values in the parameters
156  // and update the pulls
158  phase_->value(phase); phase_->updatePull();
159 }
160 
162 {
164  return coeff_;
165 }
166 
168 {
169  return this->particleCoeff();
170 }
171 
172 void LauMagPhaseCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
173 {
174  LauComplex average( coeff );
175  average += coeffBar;
176  average.rescale( 0.5 );
177 
178  Double_t magVal( average.abs() );
179  Double_t phaseVal( average.arg() );
180 
181  magnitude_->value( magVal );
182  phase_->value( phaseVal );
183 
184  if ( init ) {
185  magnitude_->genValue( magVal );
186  phase_->genValue( phaseVal );
187 
188  magnitude_->initValue( magVal );
189  phase_->initValue( phaseVal );
190  }
191 }
192 
194 {
195  TString parName(this->baseName()); parName += "_ACP";
196  return LauParameter(parName,0.0);
197 }
198 
199 LauAbsCoeffSet* LauMagPhaseCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
200 {
201  LauAbsCoeffSet* clone(0);
202  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude ) {
203  clone = new LauMagPhaseCoeffSet( *this, cloneOption, constFactor );
204  clone->name( newName );
205  } else {
206  std::cerr << "ERROR in LauMagPhaseCoeffSet::createClone : Invalid clone option" << std::endl;
207  }
208  return clone;
209 }
210 
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.
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
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
static TRandom * getRandomiser()
Access the randomiser.
Double_t genValue() const
The value generated for the parameter.
Class for defining a complex coefficient using a magnitude and a phase.