laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauCleoCPCoeffSet.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 "LauCleoCPCoeffSet.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 
43 LauCleoCPCoeffSet::LauCleoCPCoeffSet( const TString& compName,
44  Double_t a,
45  Double_t delta,
46  Double_t b,
47  Double_t phi,
48  Bool_t aFixed,
49  Bool_t deltaFixed,
50  Bool_t bFixed,
51  Bool_t phiFixed,
52  Bool_t bSecondStage,
53  Bool_t phiSecondStage ) :
54  LauAbsCoeffSet( compName ),
55  a_( new LauParameter( "A", a, minMagnitude_, maxMagnitude_, aFixed ) ),
56  b_( new LauParameter( "B", b, minMagnitude_, maxMagnitude_, bFixed ) ),
57  delta_( new LauParameter( "Delta", delta, minPhase_, maxPhase_, deltaFixed ) ),
58  phi_( new LauParameter( "Phi", phi, minPhase_, maxPhase_, phiFixed ) ),
59  particleCoeff_( ( a + b ) * TMath::Cos( delta + phi ), ( a + b ) * TMath::Sin( delta + phi ) ),
60  antiparticleCoeff_( ( a - b ) * TMath::Cos( delta - phi ), ( a - b ) * TMath::Sin( delta - phi ) ),
61  acp_( "ACP", ( -2.0 * a * b ) / ( a * a + b * b ), -1.0, 1.0, bFixed && phiFixed )
62 {
63  if ( bSecondStage && ! bFixed ) {
64  b_->secondStage( kTRUE );
65  b_->initValue( 0.0 );
66  }
67  if ( phiSecondStage && ! phiFixed ) {
68  phi_->secondStage( kTRUE );
69  phi_->initValue( 0.0 );
70  }
71 }
72 
74  CloneOption cloneOption,
75  Double_t constFactor ) :
76  LauAbsCoeffSet( rhs.name() ),
77  a_( 0 ),
78  b_( 0 ),
79  delta_( 0 ),
80  phi_( 0 ),
81  particleCoeff_( rhs.particleCoeff_ ),
82  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
83  acp_( rhs.acp_ )
84 {
85  if ( cloneOption == All || cloneOption == TieMagnitude ) {
86  a_ = rhs.a_->createClone( constFactor );
87  } else {
88  a_ = new LauParameter( "A", rhs.a_->value(), minMagnitude_, maxMagnitude_, rhs.a_->fixed() );
89  if ( rhs.a_->blind() ) {
90  const LauBlind* blinder = rhs.a_->blinder();
92  }
93  }
94 
95  if ( cloneOption == All || cloneOption == TieCPPars ) {
96  b_ = rhs.b_->createClone( constFactor );
97  } else {
98  b_ = new LauParameter( "B", rhs.b_->value(), minMagnitude_, maxMagnitude_, rhs.b_->fixed() );
99  if ( rhs.b_->blind() ) {
100  const LauBlind* blinder = rhs.b_->blinder();
102  }
103  }
104 
105  if ( cloneOption == All || cloneOption == TiePhase ) {
106  delta_ = rhs.delta_->createClone( constFactor );
107  } else {
108  delta_ =
109  new LauParameter( "Delta", rhs.delta_->value(), minPhase_, maxPhase_, rhs.delta_->fixed() );
110  if ( rhs.delta_->blind() ) {
111  const LauBlind* blinder = rhs.delta_->blinder();
113  }
114  }
115 
116  if ( cloneOption == All || cloneOption == TieCPPars ) {
117  phi_ = rhs.phi_->createClone( constFactor );
118  } else {
119  phi_ = new LauParameter( "Phi", rhs.phi_->value(), minPhase_, maxPhase_, rhs.phi_->fixed() );
120  if ( rhs.phi_->blind() ) {
121  const LauBlind* blinder = rhs.phi_->blinder();
123  }
124  }
125 }
126 
127 std::vector<LauParameter*> LauCleoCPCoeffSet::getParameters()
128 {
129  std::vector<LauParameter*> pars;
130  pars.push_back( a_ );
131  pars.push_back( b_ );
132  pars.push_back( delta_ );
133  pars.push_back( phi_ );
134  return pars;
135 }
136 
138 {
139  std::cout << "INFO in LauCleoCPCoeffSet::printParValues : Component \"" << this->name()
140  << "\" has ";
141  std::cout << "a-magnitude = " << a_->value() << ",\t";
142  std::cout << "delta = " << delta_->value() << ",\t";
143  std::cout << "b-magnitude = " << b_->value() << ",\t";
144  std::cout << "phi = " << phi_->value() << "." << std::endl;
145 }
146 
147 void LauCleoCPCoeffSet::printTableHeading( std::ostream& stream ) const
148 {
149  stream << "\\begin{tabular}{|l|c|c|c|c|}" << std::endl;
150  stream << "\\hline" << std::endl;
151  stream << "Component & a-Magnitude & delta & b-Magnitude & phi \\\\" << std::endl;
152  stream << "\\hline" << std::endl;
153 }
154 
155 void LauCleoCPCoeffSet::printTableRow( std::ostream& stream ) const
156 {
157  LauPrint print;
158  TString resName = this->name();
159  resName = resName.ReplaceAll( "_", "\\_" );
160  stream << resName << " & $";
161  print.printFormat( stream, a_->value() );
162  stream << " \\pm ";
163  print.printFormat( stream, a_->error() );
164  stream << "$ & $";
165  print.printFormat( stream, delta_->value() );
166  stream << " \\pm ";
167  print.printFormat( stream, delta_->error() );
168  stream << "$ & $";
169  print.printFormat( stream, b_->value() );
170  stream << " \\pm ";
171  print.printFormat( stream, b_->error() );
172  stream << "$ & $";
173  print.printFormat( stream, phi_->value() );
174  stream << " \\pm ";
175  print.printFormat( stream, phi_->error() );
176  stream << "$ \\\\" << std::endl;
177 }
178 
180 {
181  if ( a_->fixed() == kFALSE ) {
182  // Choose an a-magnitude between 0.0 and 2.0
183  Double_t mag = LauAbsCoeffSet::getRandomiser()->Rndm() * 2.0;
184  a_->initValue( mag );
185  a_->value( mag );
186  }
187  if ( b_->fixed() == kFALSE && b_->secondStage() == kFALSE ) {
188  // Choose a b-magnitude between 0.0 and 0.1
189  Double_t mag = LauAbsCoeffSet::getRandomiser()->Rndm() * 0.1;
190  b_->initValue( mag );
191  b_->value( mag );
192  }
193  if ( delta_->fixed() == kFALSE ) {
194  // Choose a phase between +- pi
195  Double_t phase = LauAbsCoeffSet::getRandomiser()->Rndm() * LauConstants::twoPi -
197  delta_->initValue( phase );
198  delta_->value( phase );
199  }
200  if ( phi_->fixed() == kFALSE && phi_->secondStage() == kFALSE ) {
201  // Choose a phase between +- pi
202  Double_t phase = LauAbsCoeffSet::getRandomiser()->Rndm() * LauConstants::twoPi -
204  phi_->initValue( phase );
205  phi_->value( phase );
206  }
207 }
208 
210 {
211  // retrieve the current values from the parameters
212  Double_t aVal = a_->value();
213  Double_t bVal = b_->value();
214  Double_t deltaVal = delta_->value();
215  Double_t phiVal = phi_->value();
216  Double_t genDelta = delta_->genValue();
217  Double_t genPhi = phi_->genValue();
218 
219  // Check whether we have a negative "a" magnitude.
220  // If so make it positive and add pi to the "delta" phase.
221  if ( aVal < 0.0 ) {
222  aVal *= -1.0;
223  bVal *= -1.0;
224  deltaVal += LauConstants::pi;
225  }
226 
227  // Check now whether the phases lies in the right range (-pi to pi).
228  Bool_t deltaWithinRange( kFALSE );
229  Bool_t phiWithinRange( kFALSE );
230  while ( deltaWithinRange == kFALSE && phiWithinRange == kFALSE ) {
231  if ( deltaVal > -LauConstants::pi && deltaVal < LauConstants::pi ) {
232  deltaWithinRange = kTRUE;
233  } else {
234  // Not within the specified range
235  if ( deltaVal > LauConstants::pi ) {
236  deltaVal -= LauConstants::twoPi;
237  } else if ( deltaVal < -LauConstants::pi ) {
238  deltaVal += LauConstants::twoPi;
239  }
240  }
241 
242  if ( phiVal > -LauConstants::pi && phiVal < LauConstants::pi ) {
243  phiWithinRange = kTRUE;
244  } else {
245  // Not within the specified range
246  if ( phiVal > LauConstants::pi ) {
247  phiVal -= LauConstants::twoPi;
248  } else if ( phiVal < -LauConstants::pi ) {
249  phiVal += LauConstants::twoPi;
250  }
251  }
252  }
253 
254  // A further problem can occur when the generated phase is close to -pi or pi.
255  // The phase can wrap over to the other end of the scale -
256  // this leads to artificially large pulls so we wrap it back.
257  Double_t diff = deltaVal - genDelta;
258  if ( diff > LauConstants::pi ) {
259  deltaVal -= LauConstants::twoPi;
260  } else if ( diff < -LauConstants::pi ) {
261  deltaVal += LauConstants::twoPi;
262  }
263 
264  diff = phiVal - genPhi;
265  if ( diff > LauConstants::pi ) {
266  phiVal -= LauConstants::twoPi;
267  } else if ( diff < -LauConstants::pi ) {
268  phiVal += LauConstants::twoPi;
269  }
270 
271  // finally store the new values in the parameters
272  // and update the pulls
273  a_->value( aVal );
274  a_->updatePull();
275  b_->value( bVal );
276  b_->updatePull();
277  delta_->value( deltaVal );
278  delta_->updatePull();
279  phi_->value( phiVal );
280  phi_->updatePull();
281 }
282 
284 {
285  Double_t magnitude = a_->unblindValue() + b_->unblindValue();
286  Double_t phase = delta_->unblindValue() + phi_->unblindValue();
287  particleCoeff_.setRealImagPart( magnitude * TMath::Cos( phase ), magnitude * TMath::Sin( phase ) );
288  return particleCoeff_;
289 }
290 
292 {
293  Double_t magnitude = a_->unblindValue() - b_->unblindValue();
294  Double_t phase = delta_->unblindValue() - phi_->unblindValue();
295  antiparticleCoeff_.setRealImagPart( magnitude * TMath::Cos( phase ),
296  magnitude * TMath::Sin( phase ) );
297  return antiparticleCoeff_;
298 }
299 
301  const LauComplex& coeffBar,
302  Bool_t init )
303 {
304  Double_t mag = coeff.abs();
305  Double_t magBar = coeffBar.abs();
306  Double_t phase = coeff.arg();
307  Double_t phaseBar = coeffBar.arg();
308 
309  Double_t aVal( 0.5 * ( mag + magBar ) );
310  Double_t deltaVal( 0.5 * ( phase + phaseBar ) );
311  Double_t bVal( 0.5 * ( mag - magBar ) );
312  Double_t phiVal( 0.5 * ( phase - phaseBar ) );
313 
314  a_->value( aVal );
315  delta_->value( deltaVal );
316  b_->value( bVal );
317  phi_->value( phiVal );
318 
319  if ( init ) {
320  a_->genValue( aVal );
321  delta_->genValue( deltaVal );
322  b_->genValue( bVal );
323  phi_->genValue( phiVal );
324 
325  a_->initValue( aVal );
326  delta_->initValue( deltaVal );
327  b_->initValue( bVal );
328  phi_->initValue( phiVal );
329  }
330 }
331 
333 {
334  // set the name
335  TString parName( this->baseName() );
336  parName += "_ACP";
337  acp_.name( parName );
338 
339  // work out the ACP value
340  Double_t numer = -2.0 * a_->value() * b_->value();
341  Double_t denom = a_->value() * a_->value() + b_->value() * b_->value();
342  Double_t value = numer / denom;
343 
344  // is it fixed?
345  Bool_t fixed = a_->fixed() && b_->fixed();
346  acp_.fixed( fixed );
347 
348  // we can't work out the error without the covariance matrix
349  Double_t error( 0.0 );
350 
351  // set the value and error
353 
354  return acp_;
355 }
356 
358  CloneOption cloneOption,
359  Double_t constFactor )
360 {
361  LauAbsCoeffSet* clone( 0 );
362  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude ||
363  cloneOption == TieCPPars ) {
364  clone = new LauCleoCPCoeffSet( *this, cloneOption, constFactor );
365  clone->name( newName );
366  } else {
367  std::cerr << "ERROR in LauCleoCPCoeffSet::createClone : Invalid clone option" << std::endl;
368  }
369  return clone;
370 }
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.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
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 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 LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
Double_t value() const
The value of the parameter.
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
const LauBlind * blinder() const
Access the blinder object.
virtual TString name() const
Retrieve the name of the coefficient set.
virtual LauParameter acp()
Calculate the CP asymmetry.
File containing declaration of LauParameter class.
const Double_t pi
Pi.
virtual void finaliseValues()
Make sure values are in "standard" ranges, e.g. phases should be between -pi and pi.
static Double_t maxPhase_
Maximum allowed value of phase parameters.
LauCleoCPCoeffSet(const TString &compName, Double_t a, Double_t delta, Double_t b, Double_t phi, Bool_t aFixed, Bool_t deltaFixed, Bool_t bFixed, Bool_t phiFixed, Bool_t bSecondStage=kFALSE, Bool_t phiSecondStage=kFALSE)
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 printParValues() const
Print the current values of the parameters.
virtual const TString & baseName() const
Retrieve the base name of the coefficient set.
Bool_t secondStage() const
Check whether the parameter should be floated only in the second stage of a two stage fit.
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
Class for defining a complex coefficient using the Cleo CP convention.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
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 printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:254
File containing declaration of LauComplex class.
File containing declaration of LauCleoCPCoeffSet class.
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.
LauParameter * delta_
The strong phase.
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
File containing LauConstants namespace.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
const TString & name() const
The parameter name.
LauParameter * phi_
The weak phase.
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:76
LauParameter * b_
The magnitude b.
Double_t error() const
The error on the parameter.
static TRandom * getRandomiser()
Access the randomiser.
LauComplex particleCoeff_
The particle complex coefficient.
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
LauParameter * a_
The magnitude a.
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.
Double_t initValue() const
The initial value of the parameter.
const Double_t twoPi
Two times Pi.
LauParameter acp_
The CP asymmetry.