laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauBelleCPCoeffSet.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 "LauBelleCPCoeffSet.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 LauBelleCPCoeffSet::LauBelleCPCoeffSet( 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_( 0.0, 0.0 ),
60  antiparticleCoeff_( 0.0, 0.0 ),
61  acp_( "ACP", ( -2.0 * b * TMath::Cos( phi ) ) / ( 1.0 + 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*> LauBelleCPCoeffSet::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 LauBelleCPCoeffSet::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 LauBelleCPCoeffSet::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 LauBelleCPCoeffSet::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  deltaVal += LauConstants::pi;
224  }
225 
226  // Check whether we have a negative "b" magnitude.
227  // If so make it positive and add pi to the "phi" phase.
228  if ( bVal < 0.0 ) {
229  bVal *= -1.0;
230  phiVal += LauConstants::pi;
231  }
232 
233  // Check now whether the phases lies in the right range (-pi to pi).
234  Bool_t deltaWithinRange( kFALSE );
235  Bool_t phiWithinRange( kFALSE );
236  while ( deltaWithinRange == kFALSE && phiWithinRange == kFALSE ) {
237  if ( deltaVal > -LauConstants::pi && deltaVal < LauConstants::pi ) {
238  deltaWithinRange = kTRUE;
239  } else {
240  // Not within the specified range
241  if ( deltaVal > LauConstants::pi ) {
242  deltaVal -= LauConstants::twoPi;
243  } else if ( deltaVal < -LauConstants::pi ) {
244  deltaVal += LauConstants::twoPi;
245  }
246  }
247 
248  if ( phiVal > -LauConstants::pi && phiVal < LauConstants::pi ) {
249  phiWithinRange = kTRUE;
250  } else {
251  // Not within the specified range
252  if ( phiVal > LauConstants::pi ) {
253  phiVal -= LauConstants::twoPi;
254  } else if ( phiVal < -LauConstants::pi ) {
255  phiVal += LauConstants::twoPi;
256  }
257  }
258  }
259 
260  // A further problem can occur when the generated phase is close to -pi or pi.
261  // The phase can wrap over to the other end of the scale -
262  // this leads to artificially large pulls so we wrap it back.
263  Double_t diff = deltaVal - genDelta;
264  if ( diff > LauConstants::pi ) {
265  deltaVal -= LauConstants::twoPi;
266  } else if ( diff < -LauConstants::pi ) {
267  deltaVal += LauConstants::twoPi;
268  }
269 
270  diff = phiVal - genPhi;
271  if ( diff > LauConstants::pi ) {
272  phiVal -= LauConstants::twoPi;
273  } else if ( diff < -LauConstants::pi ) {
274  phiVal += LauConstants::twoPi;
275  }
276 
277  // finally store the new values in the parameters
278  // and update the pulls
279  a_->value( aVal );
280  a_->updatePull();
281  b_->value( bVal );
282  b_->updatePull();
283  delta_->value( deltaVal );
284  delta_->updatePull();
285  phi_->value( phiVal );
286  phi_->updatePull();
287 }
288 
290 {
291  LauComplex aTerm( a_->unblindValue() * TMath::Cos( delta_->unblindValue() ),
292  a_->unblindValue() * TMath::Sin( delta_->unblindValue() ) );
293  LauComplex bTerm( b_->unblindValue() * TMath::Cos( phi_->unblindValue() ),
294  b_->unblindValue() * TMath::Sin( phi_->unblindValue() ) );
295  particleCoeff_.setRealImagPart( 1.0, 0.0 );
296  particleCoeff_ += bTerm;
297  particleCoeff_ *= aTerm;
298  return particleCoeff_;
299 }
300 
302 {
303  LauComplex aTerm( a_->unblindValue() * TMath::Cos( delta_->unblindValue() ),
304  a_->unblindValue() * TMath::Sin( delta_->unblindValue() ) );
305  LauComplex bTerm( b_->unblindValue() * TMath::Cos( phi_->unblindValue() ),
306  b_->unblindValue() * TMath::Sin( phi_->unblindValue() ) );
308  antiparticleCoeff_ -= bTerm;
309  antiparticleCoeff_ *= aTerm;
310  return antiparticleCoeff_;
311 }
312 
314  const LauComplex& coeffBar,
315  Bool_t init )
316 {
317  LauComplex sum = coeff + coeffBar;
318  LauComplex diff = coeff - coeffBar;
319  LauComplex ratio = diff / sum;
320 
321  Double_t aVal( 0.5 * sum.abs() );
322  Double_t deltaVal( sum.arg() );
323  Double_t bVal( ratio.abs() );
324  Double_t phiVal( ratio.arg() );
325 
326  a_->value( aVal );
327  delta_->value( deltaVal );
328  b_->value( bVal );
329  phi_->value( phiVal );
330 
331  if ( init ) {
332  a_->genValue( aVal );
333  delta_->genValue( deltaVal );
334  b_->genValue( bVal );
335  phi_->genValue( phiVal );
336 
337  a_->initValue( aVal );
338  delta_->initValue( deltaVal );
339  b_->initValue( bVal );
340  phi_->initValue( phiVal );
341  }
342 }
343 
345 {
346  // set the name
347  TString parName( this->baseName() );
348  parName += "_ACP";
349  acp_.name( parName );
350 
351  // work out the ACP value
352  Double_t value = ( -2.0 * b_->value() * TMath::Cos( phi_->value() ) ) /
353  ( 1.0 + b_->value() * b_->value() );
354 
355  // is it fixed?
356  Bool_t fixed = b_->fixed() && phi_->fixed();
357  acp_.fixed( fixed );
358 
359  // we can't work out the error without the covariance matrix
360  Double_t error( 0.0 );
361 
362  // set the value and error
364 
365  return acp_;
366 }
367 
369  CloneOption cloneOption,
370  Double_t constFactor )
371 {
372  LauAbsCoeffSet* clone( 0 );
373  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude ||
374  cloneOption == TieCPPars ) {
375  clone = new LauBelleCPCoeffSet( *this, cloneOption, constFactor );
376  clone->name( newName );
377  } else {
378  std::cerr << "ERROR in LauBelleCPCoeffSet::createClone : Invalid clone option" << std::endl;
379  }
380  return clone;
381 }
LauParameter * a_
The magnitude a.
LauComplex particleCoeff_
The particle complex coefficient.
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 LauParameter acp()
Calculate the CP asymmetry.
virtual void finaliseValues()
Make sure values are in "standard" ranges, e.g. phases should be between -pi and pi.
LauParameter * b_
The magnitude b.
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 LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
Double_t value() const
The value of the parameter.
const LauBlind * blinder() const
Access the blinder object.
virtual TString name() const
Retrieve the name of the coefficient set.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
File containing declaration of LauParameter class.
const Double_t pi
Pi.
static Double_t maxPhase_
Maximum allowed value of phase parameters.
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 void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
Class for defining a complex coefficient using the Belle CP convention. Holds a set of real values th...
static Double_t maxMagnitude_
Maximum allowed value of magnitude parameters.
LauParameter acp_
The CP asymmetry.
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
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:324
virtual void printParValues() const
Print the current values of the parameters.
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 * 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 randomiseInitValues()
Randomise the starting values of the parameters for a fit.
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
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
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.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit.
LauBelleCPCoeffSet(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 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
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
LauParameter * delta_
The strong phase.
static Double_t minPhase_
Minimum allowed value of phase parameters.
Double_t initValue() const
The initial value of the parameter.
File containing declaration of LauBelleCPCoeffSet class.
const Double_t twoPi
Two times Pi.
LauParameter * phi_
The weak phase.