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