laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
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 "LauMagPhaseCoeffSet.hh"
30 
31 #include "LauComplex.hh"
32 #include "LauConstants.hh"
33 #include "LauParameter.hh"
34 #include "LauPrint.hh"
35 
36 #include "TMath.h"
37 #include "TRandom.h"
38 
39 #include <fstream>
40 #include <iostream>
41 #include <vector>
42 
44  Double_t magnitude,
45  Double_t phase,
46  Bool_t magFixed,
47  Bool_t phaseFixed ) :
48  LauAbsCoeffSet( compName ),
49  magnitude_( new LauParameter( "A", magnitude, minMagnitude_, maxMagnitude_, magFixed ) ),
50  phase_( new LauParameter( "Delta", phase, minPhase_, maxPhase_, phaseFixed ) ),
51  coeff_( magnitude * TMath::Cos( phase ), magnitude * TMath::Sin( phase ) )
52 {
53 }
54 
56  CloneOption cloneOption,
57  Double_t constFactor ) :
58  LauAbsCoeffSet( rhs.name() ),
59  magnitude_( 0 ),
60  phase_( 0 ),
61  coeff_( rhs.coeff_ )
62 {
63  if ( cloneOption == All || cloneOption == TieMagnitude ) {
64  magnitude_ = rhs.magnitude_->createClone( constFactor );
65  } else {
66  magnitude_ = new LauParameter( "A",
67  rhs.magnitude_->value(),
70  rhs.magnitude_->fixed() );
71  if ( rhs.magnitude_->blind() ) {
72  const LauBlind* blinder = rhs.magnitude_->blinder();
74  }
75  }
76 
77  if ( cloneOption == All || cloneOption == TiePhase ) {
78  phase_ = rhs.phase_->createClone( constFactor );
79  } else {
80  phase_ =
81  new LauParameter( "Delta", rhs.phase_->value(), minPhase_, maxPhase_, rhs.phase_->fixed() );
82  if ( rhs.phase_->blind() ) {
83  const LauBlind* blinder = rhs.phase_->blinder();
85  }
86  }
87 }
88 
89 std::vector<LauParameter*> LauMagPhaseCoeffSet::getParameters()
90 {
91  std::vector<LauParameter*> pars;
92  pars.push_back( magnitude_ );
93  pars.push_back( phase_ );
94  return pars;
95 }
96 
98 {
99  std::cout << "INFO in LauMagPhaseCoeffSet::printParValues : Component \"" << this->name()
100  << "\" has magnitude = " << magnitude_->value() << " and phase = " << phase_->value()
101  << "." << std::endl;
102 }
103 
104 void LauMagPhaseCoeffSet::printTableHeading( std::ostream& stream ) const
105 {
106  stream << "\\begin{tabular}{|l|c|c|}" << std::endl;
107  stream << "\\hline" << std::endl;
108  stream << "Component & Magnitude & Phase \\\\" << std::endl;
109  stream << "\\hline" << std::endl;
110 }
111 
112 void LauMagPhaseCoeffSet::printTableRow( std::ostream& stream ) const
113 {
114  LauPrint print;
115  TString resName = this->name();
116  resName = resName.ReplaceAll( "_", "\\_" );
117  stream << resName << " & $";
118  print.printFormat( stream, magnitude_->value() );
119  stream << " \\pm ";
120  print.printFormat( stream, magnitude_->error() );
121  stream << "$ & $";
122  print.printFormat( stream, phase_->value() );
123  stream << " \\pm ";
124  print.printFormat( stream, phase_->error() );
125  stream << "$ \\\\" << std::endl;
126 }
127 
129 {
130  if ( magnitude_->fixed() == kFALSE ) {
131  // Choose a magnitude between 0.0 and 2.0
132  Double_t mag = LauAbsCoeffSet::getRandomiser()->Rndm() * 2.0;
133  magnitude_->initValue( mag );
134  magnitude_->value( mag );
135  }
136  if ( phase_->fixed() == kFALSE ) {
137  // Choose a phase between +- pi
138  Double_t phase = LauAbsCoeffSet::getRandomiser()->Rndm() * LauConstants::twoPi -
140  phase_->initValue( phase );
141  phase_->value( phase );
142  }
143 }
144 
146 {
147  // retrieve the current values from the parameters
148  Double_t mag = magnitude_->value();
149  Double_t phase = phase_->value();
150  Double_t genPhase = phase_->genValue();
151 
152  // Check whether we have a negative magnitude.
153  // If so make it positive and add pi to the phase.
154  if ( mag < 0.0 ) {
155  mag *= -1.0;
156  phase += LauConstants::pi;
157  }
158 
159  // Check now whether the phase lies in the right range (-pi to pi).
160  Bool_t withinRange( kFALSE );
161  while ( withinRange == kFALSE ) {
162  if ( phase > -LauConstants::pi && phase <= LauConstants::pi ) {
163  withinRange = kTRUE;
164  } else {
165  // Not within the specified range
166  if ( phase > LauConstants::pi ) {
167  phase -= LauConstants::twoPi;
168  } else if ( phase <= -LauConstants::pi ) {
169  phase += LauConstants::twoPi;
170  }
171  }
172  }
173 
174  // A further problem can occur when the generated phase is close to -pi or pi.
175  // The phase can wrap over to the other end of the scale -
176  // this leads to artificially large pulls so we wrap it back.
177  Double_t diff = phase - genPhase;
178  if ( diff > LauConstants::pi ) {
179  phase -= LauConstants::twoPi;
180  } else if ( diff < -LauConstants::pi ) {
181  phase += LauConstants::twoPi;
182  }
183 
184  // finally store the new values in the parameters
185  // and update the pulls
186  magnitude_->value( mag );
188  phase_->value( phase );
189  phase_->updatePull();
190 }
191 
193 {
195  magnitude_->unblindValue() * TMath::Sin( phase_->unblindValue() ) );
196  return coeff_;
197 }
198 
200 {
201  return this->particleCoeff();
202 }
203 
205  const LauComplex& coeffBar,
206  Bool_t init )
207 {
208  LauComplex average( coeff );
209  average += coeffBar;
210  average.rescale( 0.5 );
211 
212  Double_t magVal( average.abs() );
213  Double_t phaseVal( average.arg() );
214 
215  magnitude_->value( magVal );
216  phase_->value( phaseVal );
217 
218  if ( init ) {
219  magnitude_->genValue( magVal );
220  phase_->genValue( phaseVal );
221 
222  magnitude_->initValue( magVal );
223  phase_->initValue( phaseVal );
224  }
225 }
226 
228 {
229  TString parName( this->baseName() );
230  parName += "_ACP";
231  return LauParameter( parName, 0.0 );
232 }
233 
235  CloneOption cloneOption,
236  Double_t constFactor )
237 {
238  LauAbsCoeffSet* clone( 0 );
239  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude ) {
240  clone = new LauMagPhaseCoeffSet( *this, cloneOption, constFactor );
241  clone->name( newName );
242  } else {
243  std::cerr << "ERROR in LauMagPhaseCoeffSet::createClone : Invalid clone option" << std::endl;
244  }
245  return clone;
246 }
Class for defining the abstract interface for complex coefficient classes.
Class for defining the fit parameter objects.
Definition: LauParameter.hh:49
Double_t unblindValue() const
The unblinded value of the parameter.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
Double_t value() const
The value of the parameter.
const LauBlind * blinder() const
Access the blinder object.
File containing declaration of LauMagPhaseCoeffSet class.
virtual TString name() const
Retrieve the name of the coefficient set.
File containing declaration of LauParameter class.
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
const Double_t pi
Pi.
static Double_t maxPhase_
Maximum allowed value of phase parameters.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
LauMagPhaseCoeffSet(const TString &compName, Double_t magnitude, Double_t phase, Bool_t magFixed, Bool_t phaseFixed)
Constructor.
static Double_t maxMagnitude_
Maximum allowed value of magnitude parameters.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit.
virtual void finaliseValues()
Make sure values are in "standard" ranges, e.g. phases should be between -pi and pi.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar, Bool_t init)
Set the parameters based on the complex coefficients for particles and antiparticles.
virtual const TString & baseName() const
Retrieve the base name of the coefficient set.
Class for defining a complex number.
Definition: LauComplex.hh:61
Bool_t blind() const
The blinding state.
Class for blinding and unblinding a number based on a blinding string.
Definition: LauBlind.hh:42
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:301
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:324
Bool_t clone() const
Check whether is a clone or not.
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:254
File containing declaration of LauComplex class.
LauParameter * phase_
The phase.
LauParameter * createClone(Double_t constFactor=1.0)
Method to create a clone from the parent parameter using the copy constructor.
void blindParameter(const TString &blindingString, const Double_t width)
Blind the parameter.
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
Double_t blindingWidth() const
Obtain the Gaussian width.
Definition: LauBlind.hh:82
Bool_t fixed() const
Check whether the parameter is fixed or floated.
LauParameter()
Default constructor.
Definition: LauParameter.cc:40
LauParameter * magnitude_
The magnitude.
File containing LauConstants namespace.
const TString & name() const
The parameter name.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:76
Double_t error() const
The error on the parameter.
LauComplex coeff_
The complex coefficient.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
static TRandom * getRandomiser()
Access the randomiser.
void updatePull()
Call to update the bias and pull values.
File containing declaration of LauPrint class and LauOutputLevel enum.
CloneOption
Options for cloning operation.
Double_t arg() const
Obtain the phase angle of the complex number.
Definition: LauComplex.hh:266
Class to define various output print commands.
Definition: LauPrint.hh:54
Class for defining a complex coefficient using a magnitude and a phase.
static Double_t minMagnitude_
Minimum allowed value of magnitude parameters.
Double_t genValue() const
The value generated for the parameter.
void printFormat(std::ostream &stream, Double_t value) const
Method to choose the printing format to a specified level of precision.
Definition: LauPrint.cc:43
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
static Double_t minPhase_
Minimum allowed value of phase parameters.
virtual void printParValues() const
Print the current values of the parameters.
virtual LauParameter acp()
Calculate the CP asymmetry.
Double_t initValue() const
The initial value of the parameter.
const Double_t twoPi
Two times Pi.