laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauMagPhaseCPCoeffSet.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2011 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 "LauMagPhaseCPCoeffSet.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 mag,
45  Double_t phase,
46  Double_t magBar,
47  Double_t phaseBar,
48  Bool_t magFixed,
49  Bool_t phaseFixed,
50  Bool_t magBarFixed,
51  Bool_t phaseBarFixed ) :
52  LauAbsCoeffSet( compName ),
53  mag_( new LauParameter( "Mag", mag, minMagnitude_, maxMagnitude_, magFixed ) ),
54  phase_( new LauParameter( "Phase", phase, minPhase_, maxPhase_, phaseFixed ) ),
55  magBar_( new LauParameter( "MagBar", magBar, minMagnitude_, maxMagnitude_, magBarFixed ) ),
56  phaseBar_( new LauParameter( "PhaseBar", phaseBar, minPhase_, maxPhase_, phaseBarFixed ) ),
57  particleCoeff_( mag * TMath::Cos( phase ), mag * TMath::Sin( phase ) ),
58  antiparticleCoeff_( magBar * TMath::Cos( phaseBar ), magBar * TMath::Sin( phaseBar ) ),
59  acp_( "ACP", ( magBar * magBar - mag * mag ) / ( magBar * magBar + mag * mag ), -1.0, 1.0 )
60 {
61 }
62 
64  CloneOption cloneOption,
65  Double_t constFactor ) :
66  LauAbsCoeffSet( rhs.name() ),
67  mag_( 0 ),
68  phase_( 0 ),
69  magBar_( 0 ),
70  phaseBar_( 0 ),
71  particleCoeff_( rhs.particleCoeff_ ),
72  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
73  acp_( rhs.acp_ )
74 {
75  if ( cloneOption == All || cloneOption == TieMagnitude ) {
76  mag_ = rhs.mag_->createClone( constFactor );
77  magBar_ = rhs.magBar_->createClone( constFactor );
78  } else {
79  mag_ = new LauParameter( "Mag",
80  rhs.mag_->value(),
83  rhs.mag_->fixed() );
84  if ( rhs.mag_->blind() ) {
85  const LauBlind* blinder = rhs.mag_->blinder();
87  }
88  magBar_ = new LauParameter( "MagBar",
89  rhs.magBar_->value(),
92  rhs.magBar_->fixed() );
93  if ( rhs.magBar_->blind() ) {
94  const LauBlind* blinder = rhs.magBar_->blinder();
96  }
97  }
98 
99  if ( cloneOption == All || cloneOption == TiePhase ) {
100  phase_ = rhs.phase_->createClone( constFactor );
101  phaseBar_ = rhs.phaseBar_->createClone( constFactor );
102  } else {
103  phase_ =
104  new LauParameter( "Phase", rhs.phase_->value(), minPhase_, maxPhase_, rhs.phase_->fixed() );
105  if ( rhs.phase_->blind() ) {
106  const LauBlind* blinder = rhs.phase_->blinder();
108  }
109  phaseBar_ = new LauParameter( "PhaseBar",
110  rhs.phaseBar_->value(),
111  minPhase_,
112  maxPhase_,
113  rhs.phaseBar_->fixed() );
114  if ( rhs.phaseBar_->blind() ) {
115  const LauBlind* blinder = rhs.phaseBar_->blinder();
117  }
118  }
119 }
120 
121 std::vector<LauParameter*> LauMagPhaseCPCoeffSet::getParameters()
122 {
123  std::vector<LauParameter*> pars;
124  pars.push_back( mag_ );
125  pars.push_back( phase_ );
126  pars.push_back( magBar_ );
127  pars.push_back( phaseBar_ );
128  return pars;
129 }
130 
132 {
133  std::cout << "INFO in LauMagPhaseCPCoeffSet::printParValues : Component \"" << this->name()
134  << "\" has ";
135  std::cout << "mag = " << mag_->value() << ",\t";
136  std::cout << "phase = " << phase_->value() << ",\t";
137  std::cout << "magBar = " << magBar_->value() << ",\t";
138  std::cout << "phaseBar = " << phaseBar_->value() << "." << std::endl;
139 }
140 
141 void LauMagPhaseCPCoeffSet::printTableHeading( std::ostream& stream ) const
142 {
143  stream << "\\begin{tabular}{|l|c|c|c|c|}" << std::endl;
144  stream << "\\hline" << std::endl;
145  stream << "Component & Magnitude & Phase & Magnitude_bar & Phase_bar \\\\" << std::endl;
146  stream << "\\hline" << std::endl;
147 }
148 
149 void LauMagPhaseCPCoeffSet::printTableRow( std::ostream& stream ) const
150 {
151  LauPrint print;
152  TString resName = this->name();
153  resName = resName.ReplaceAll( "_", "\\_" );
154  stream << resName << " & $";
155  print.printFormat( stream, mag_->value() );
156  stream << " \\pm ";
157  print.printFormat( stream, mag_->error() );
158  stream << "$ & $";
159  print.printFormat( stream, phase_->value() );
160  stream << " \\pm ";
161  print.printFormat( stream, phase_->error() );
162  stream << "$ & $";
163  print.printFormat( stream, magBar_->value() );
164  stream << " \\pm ";
165  print.printFormat( stream, magBar_->error() );
166  stream << "$ & $";
167  print.printFormat( stream, phaseBar_->value() );
168  stream << " \\pm ";
169  print.printFormat( stream, phaseBar_->error() );
170  stream << "$ \\\\" << std::endl;
171 }
172 
174 {
175  if ( mag_->fixed() == kFALSE ) {
176  // Choose a value for "magnitude" between 0.0 and 2.0
177  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm() * 2.0;
178  mag_->initValue( value );
179  mag_->value( value );
180  }
181  if ( phase_->fixed() == kFALSE ) {
182  // Choose a phase between +- pi
185  phase_->initValue( value );
186  phase_->value( value );
187  }
188  if ( magBar_->fixed() == kFALSE ) {
189  // Choose a value for "magnitude" between 0.0 and 2.0
190  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm() * 2.0;
191  magBar_->initValue( value );
192  magBar_->value( value );
193  }
194  if ( phaseBar_->fixed() == kFALSE ) {
195  // Choose a phase between +- pi
199  phaseBar_->value( value );
200  }
201 }
202 
204 {
205  // retrieve the current values from the parameters
206  Double_t mVal = mag_->value();
207  Double_t pVal = phase_->value();
208  Double_t mBarVal = magBar_->value();
209  Double_t pBarVal = phaseBar_->value();
210  Double_t genPhase = phase_->genValue();
211  Double_t genPhaseBar = phaseBar_->genValue();
212 
213  // Check whether we have a negative magnitude.
214  // If so make it positive and add pi to the phase.
215  if ( mVal < 0.0 ) {
216  mVal *= -1.0;
217  pVal += LauConstants::pi;
218  }
219  if ( mBarVal < 0.0 ) {
220  mBarVal *= -1.0;
221  pBarVal += LauConstants::pi;
222  }
223 
224  // Check now whether the phases lies in the right range (-pi to pi).
225  Bool_t pWithinRange( kFALSE );
226  Bool_t pBarWithinRange( kFALSE );
227  while ( pWithinRange == kFALSE && pBarWithinRange == kFALSE ) {
228  if ( pVal > -LauConstants::pi && pVal < LauConstants::pi ) {
229  pWithinRange = kTRUE;
230  } else {
231  // Not within the specified range
232  if ( pVal > LauConstants::pi ) {
233  pVal -= LauConstants::twoPi;
234  } else if ( pVal < -LauConstants::pi ) {
235  pVal += LauConstants::twoPi;
236  }
237  }
238 
239  if ( pBarVal > -LauConstants::pi && pBarVal < LauConstants::pi ) {
240  pBarWithinRange = kTRUE;
241  } else {
242  // Not within the specified range
243  if ( pBarVal > LauConstants::pi ) {
244  pBarVal -= LauConstants::twoPi;
245  } else if ( pBarVal < -LauConstants::pi ) {
246  pBarVal += LauConstants::twoPi;
247  }
248  }
249  }
250 
251  // A further problem can occur when the generated phase is close to -pi or pi.
252  // The phase can wrap over to the other end of the scale -
253  // this leads to artificially large pulls so we wrap it back.
254  Double_t diff = pVal - genPhase;
255  if ( diff > LauConstants::pi ) {
256  pVal -= LauConstants::twoPi;
257  } else if ( diff < -LauConstants::pi ) {
258  pVal += LauConstants::twoPi;
259  }
260 
261  diff = pBarVal - genPhaseBar;
262  if ( diff > LauConstants::pi ) {
263  pBarVal -= LauConstants::twoPi;
264  } else if ( diff < -LauConstants::pi ) {
265  pBarVal += LauConstants::twoPi;
266  }
267 
268  // finally store the new values in the parameters
269  // and update the pulls
270  mag_->value( mVal );
271  mag_->updatePull();
272  phase_->value( pVal );
273  phase_->updatePull();
274  magBar_->value( mBarVal );
275  magBar_->updatePull();
276  phaseBar_->value( pBarVal );
278 }
279 
281 {
283  mag_->unblindValue() * TMath::Sin( phase_->unblindValue() ) );
284  return particleCoeff_;
285 }
286 
288 {
290  magBar_->unblindValue() * TMath::Cos( phaseBar_->unblindValue() ),
291  magBar_->unblindValue() * TMath::Sin( phaseBar_->unblindValue() ) );
292  return antiparticleCoeff_;
293 }
294 
296  const LauComplex& coeffBar,
297  Bool_t init )
298 {
299  Double_t magVal( coeff.abs() );
300  Double_t phaseVal( coeff.arg() );
301  Double_t magBarVal( coeffBar.abs() );
302  Double_t phaseBarVal( coeffBar.arg() );
303 
304  mag_->value( magVal );
305  phase_->value( phaseVal );
306  magBar_->value( magBarVal );
307  phaseBar_->value( phaseBarVal );
308 
309  if ( init ) {
310  mag_->genValue( magVal );
311  phase_->genValue( phaseVal );
312  magBar_->genValue( magBarVal );
313  phaseBar_->genValue( phaseBarVal );
314 
315  mag_->initValue( magVal );
316  phase_->initValue( phaseVal );
317  magBar_->initValue( magBarVal );
318  phaseBar_->initValue( phaseBarVal );
319  }
320 }
321 
323 {
324  // set the name
325  TString parName( this->baseName() );
326  parName += "_ACP";
327  acp_.name( parName );
328 
329  // work out the ACP value
330 
331  Double_t value( -99.0 );
332  value = ( magBar_->value() * magBar_->value() - mag_->value() * mag_->value() ) /
333  ( magBar_->value() * magBar_->value() + mag_->value() * mag_->value() );
334 
335  // is it fixed?
336  Bool_t fixed = magBar_->fixed() && mag_->fixed();
337  acp_.fixed( fixed );
338 
339  // we can't work out the error without the covariance matrix
340  Double_t error( 0.0 );
341 
342  // set the value and error
344 
345  return acp_;
346 }
347 
349  CloneOption cloneOption,
350  Double_t constFactor )
351 {
352  LauAbsCoeffSet* clone( 0 );
353  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude ) {
354  clone = new LauMagPhaseCPCoeffSet( *this, cloneOption, constFactor );
355  clone->name( newName );
356  } else {
357  std::cerr << "ERROR in LauMagPhaseCPCoeffSet::createClone : Invalid clone option"
358  << std::endl;
359  }
360  return clone;
361 }
void valueAndErrors(Double_t newValue, Double_t newError, Double_t newNegError=0.0, Double_t newPosError=0.0)
Set the value and errors on the parameter.
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.
Double_t value() const
The value of the parameter.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
LauParameter acp_
The CP asymmetry.
LauParameter * magBar_
The magnitude for antiparticles.
const LauBlind * blinder() const
Access the blinder object.
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
virtual TString name() const
Retrieve the name of the coefficient set.
Class for defining a complex coefficient using seperate magnitudes and phases for particles and antip...
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
File containing declaration of LauParameter class.
const Double_t pi
Pi.
static Double_t maxPhase_
Maximum allowed value of phase parameters.
LauComplex particleCoeff_
The particle complex coefficient.
static Double_t maxMagnitude_
Maximum allowed value of magnitude parameters.
virtual void finaliseValues()
Make sure values are in "standard" ranges, e.g. phases should be between -pi and pi.
virtual const TString & baseName() const
Retrieve the base name of the coefficient set.
LauMagPhaseCPCoeffSet(const TString &compName, Double_t mag, Double_t phase, Double_t magBar, Double_t phaseBar, Bool_t magFixed, Bool_t phaseFixed, Bool_t magBarFixed, Bool_t phaseBarFixed)
Constructor.
Class for defining a complex number.
Definition: LauComplex.hh:61
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit.
Bool_t blind() const
The blinding state.
Class for blinding and unblinding a number based on a blinding string.
Definition: LauBlind.hh:42
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.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar, Bool_t init)
Set the parameters based on the complex coefficients for particles and antiparticles.
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:254
File containing declaration of LauComplex class.
LauParameter * createClone(Double_t constFactor=1.0)
Method to create a clone from the parent parameter using the copy constructor.
LauParameter * phaseBar_
The phase for antiparticles.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
void blindParameter(const TString &blindingString, const Double_t width)
Blind the parameter.
Double_t blindingWidth() const
Obtain the Gaussian width.
Definition: LauBlind.hh:82
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
LauParameter()
Default constructor.
Definition: LauParameter.cc:40
LauParameter * phase_
The phase for particles.
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.
static TRandom * getRandomiser()
Access the randomiser.
File containing declaration of LauMagPhaseCPCoeffSet class.
LauParameter * mag_
The magnitude for particles.
void updatePull()
Call to update the bias and pull values.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
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
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
static Double_t minPhase_
Minimum allowed value of phase parameters.
virtual void printParValues() const
Print the current values of the parameters.
Double_t initValue() const
The initial value of the parameter.
const Double_t twoPi
Two times Pi.
virtual LauParameter acp()
Calculate the CP asymmetry.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.