laura is hosted by Hepforge, IPPP Durham
Laura++  v3r5
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 <iostream>
30 #include <fstream>
31 #include <vector>
32 
33 #include "TMath.h"
34 #include "TRandom.h"
35 
36 #include "LauMagPhaseCPCoeffSet.hh"
37 #include "LauComplex.hh"
38 #include "LauConstants.hh"
39 #include "LauParameter.hh"
40 #include "LauPrint.hh"
41 
43 
44 
45 LauMagPhaseCPCoeffSet::LauMagPhaseCPCoeffSet(const TString& compName, Double_t mag, Double_t phase, Double_t magBar, Double_t phaseBar,
46  Bool_t magFixed, Bool_t phaseFixed,Bool_t magBarFixed, Bool_t phaseBarFixed) :
47  LauAbsCoeffSet(compName),
48  mag_(new LauParameter("Mag", mag, minMagnitude_, maxMagnitude_, magFixed)),
49  phase_(new LauParameter("Phase", phase, minPhase_, maxPhase_, phaseFixed)),
50  magBar_(new LauParameter("MagBar", magBar, minMagnitude_, maxMagnitude_, magBarFixed)),
51  phaseBar_(new LauParameter("PhaseBar", phaseBar, minPhase_, maxPhase_, phaseBarFixed)),
52  particleCoeff_( mag*TMath::Cos(phase), mag*TMath::Sin(phase) ),
53  antiparticleCoeff_( magBar*TMath::Cos(phaseBar), magBar*TMath::Sin(phaseBar) ),
54  acp_("ACP", (magBar*magBar - mag*mag)/(magBar*magBar + mag*mag), -1.0, 1.0)
55 {
56 }
57 
59  mag_(0),
60  phase_(0),
61  magBar_(0),
62  phaseBar_(0),
63  particleCoeff_( rhs.particleCoeff_ ),
64  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
65  acp_( rhs.acp_ )
66 {
67  if ( cloneOption == All || cloneOption == TieMagnitude ) {
68  mag_ = rhs.mag_->createClone(constFactor);
69  magBar_ = rhs.magBar_->createClone(constFactor);
70  } else {
71  mag_ = new LauParameter("Mag", rhs.mag_->value(), minMagnitude_, maxMagnitude_, rhs.mag_->fixed());
72  if ( rhs.mag_->blind() ) {
73  const LauBlind* blinder = rhs.mag_->blinder();
74  mag_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
75  }
76  magBar_ = new LauParameter("MagBar", rhs.magBar_->value(), minMagnitude_, maxMagnitude_, rhs.magBar_->fixed());
77  if ( rhs.magBar_->blind() ) {
78  const LauBlind* blinder = rhs.magBar_->blinder();
79  magBar_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
80  }
81  }
82 
83  if ( cloneOption == All || cloneOption == TiePhase ) {
84  phase_ = rhs.phase_->createClone(constFactor);
85  phaseBar_ = rhs.phaseBar_->createClone(constFactor);
86  } else {
87  phase_ = new LauParameter("Phase", rhs.phase_->value(), minPhase_, maxPhase_, rhs.phase_->fixed());
88  if ( rhs.phase_->blind() ) {
89  const LauBlind* blinder = rhs.phase_->blinder();
90  phase_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
91  }
92  phaseBar_ = new LauParameter("PhaseBar", rhs.phaseBar_->value(), minPhase_, maxPhase_, rhs.phaseBar_->fixed());
93  if ( rhs.phaseBar_->blind() ) {
94  const LauBlind* blinder = rhs.phaseBar_->blinder();
95  phaseBar_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
96  }
97  }
98 }
99 
100 std::vector<LauParameter*> LauMagPhaseCPCoeffSet::getParameters()
101 {
102  std::vector<LauParameter*> pars;
103  pars.push_back(mag_);
104  pars.push_back(phase_);
105  pars.push_back(magBar_);
106  pars.push_back(phaseBar_);
107  return pars;
108 }
109 
111 {
112  std::cout<<"INFO in LauMagPhaseCPCoeffSet::printParValues : Component \""<<this->name()<<"\" has ";
113  std::cout<<"mag = "<<mag_->value()<<",\t";
114  std::cout<<"phase = "<<phase_->value()<<",\t";
115  std::cout<<"magBar = "<<magBar_->value()<<",\t";
116  std::cout<<"phaseBar = "<<phaseBar_->value()<<"."<<std::endl;
117 }
118 
119 void LauMagPhaseCPCoeffSet::printTableHeading(std::ostream& stream) const
120 {
121  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<std::endl;
122  stream<<"\\hline"<<std::endl;
123  stream<<"Component & Magnitude & Phase & Magnitude_bar & Phase_bar \\\\"<<std::endl;
124  stream<<"\\hline"<<std::endl;
125 }
126 
127 void LauMagPhaseCPCoeffSet::printTableRow(std::ostream& stream) const
128 {
129  LauPrint print;
130  TString resName = this->name();
131  resName = resName.ReplaceAll("_", "\\_");
132  stream<<resName<<" & $";
133  print.printFormat(stream, mag_->value());
134  stream<<" \\pm ";
135  print.printFormat(stream, mag_->error());
136  stream<<"$ & $";
137  print.printFormat(stream, phase_->value());
138  stream<<" \\pm ";
139  print.printFormat(stream, phase_->error());
140  stream<<"$ & $";
141  print.printFormat(stream, magBar_->value());
142  stream<<" \\pm ";
143  print.printFormat(stream, magBar_->error());
144  stream<<"$ & $";
145  print.printFormat(stream, phaseBar_->value());
146  stream<<" \\pm ";
147  print.printFormat(stream, phaseBar_->error());
148  stream<<"$ \\\\"<<std::endl;
149 }
150 
152 {
153  if (mag_->fixed() == kFALSE) {
154  // Choose a value for "magnitude" between 0.0 and 2.0
155  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*2.0;
156  mag_->initValue(value); mag_->value(value);
157  }
158  if (phase_->fixed() == kFALSE) {
159  // Choose a phase between +- pi
161  phase_->initValue(value); phase_->value(value);
162  }
163  if (magBar_->fixed() == kFALSE) {
164  // Choose a value for "magnitude" between 0.0 and 2.0
165  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*2.0;
166  magBar_->initValue(value); magBar_->value(value);
167  }
168  if (phaseBar_->fixed() == kFALSE) {
169  // Choose a phase between +- pi
171  phaseBar_->initValue(value); phaseBar_->value(value);
172  }
173 }
174 
176 {
177  // retrieve the current values from the parameters
178  Double_t mVal= mag_->value();
179  Double_t pVal= phase_->value();
180  Double_t mBarVal= magBar_->value();
181  Double_t pBarVal= phaseBar_->value();
182  Double_t genPhase = phase_->genValue();
183  Double_t genPhaseBar = phaseBar_->genValue();
184 
185  // Check whether we have a negative magnitude.
186  // If so make it positive and add pi to the phase.
187  if (mVal < 0.0) {
188  mVal *= -1.0;
189  pVal += LauConstants::pi;
190  }
191  if (mBarVal < 0.0) {
192  mBarVal *= -1.0;
193  pBarVal += LauConstants::pi;
194  }
195 
196  // Check now whether the phases lies in the right range (-pi to pi).
197  Bool_t pWithinRange(kFALSE);
198  Bool_t pBarWithinRange(kFALSE);
199  while (pWithinRange == kFALSE && pBarWithinRange == kFALSE) {
200  if (pVal > -LauConstants::pi && pVal < LauConstants::pi) {
201  pWithinRange = kTRUE;
202  } else {
203  // Not within the specified range
204  if (pVal > LauConstants::pi) {
205  pVal -= LauConstants::twoPi;
206  } else if (pVal < -LauConstants::pi) {
207  pVal += LauConstants::twoPi;
208  }
209  }
210 
211  if (pBarVal > -LauConstants::pi && pBarVal < LauConstants::pi) {
212  pBarWithinRange = kTRUE;
213  } else {
214  // Not within the specified range
215  if (pBarVal > LauConstants::pi) {
216  pBarVal -= LauConstants::twoPi;
217  } else if (pBarVal < -LauConstants::pi) {
218  pBarVal += LauConstants::twoPi;
219  }
220  }
221  }
222 
223  // A further problem can occur when the generated phase is close to -pi or pi.
224  // The phase can wrap over to the other end of the scale -
225  // this leads to artificially large pulls so we wrap it back.
226  Double_t diff = pVal - genPhase;
227  if (diff > LauConstants::pi) {
228  pVal -= LauConstants::twoPi;
229  } else if (diff < -LauConstants::pi) {
230  pVal += LauConstants::twoPi;
231  }
232 
233  diff = pBarVal - genPhaseBar;
234  if (diff > LauConstants::pi) {
235  pBarVal -= LauConstants::twoPi;
236  } else if (diff < -LauConstants::pi) {
237  pBarVal += LauConstants::twoPi;
238  }
239 
240  // finally store the new values in the parameters
241  // and update the pulls
242  mag_->value(mVal); mag_->updatePull();
243  phase_->value(pVal); phase_->updatePull();
244  magBar_->value(mBarVal); magBar_->updatePull();
245  phaseBar_->value(pBarVal); phaseBar_->updatePull();
246 
247 
248 }
249 
251 {
253  return particleCoeff_;
254 }
255 
257 {
259  return antiparticleCoeff_;
260 }
261 
262 void LauMagPhaseCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
263 {
264  Double_t magVal( coeff.abs() );
265  Double_t phaseVal( coeff.arg() );
266  Double_t magBarVal( coeffBar.abs() );
267  Double_t phaseBarVal( coeffBar.arg() );
268 
269  mag_->value( magVal );
270  phase_->value( phaseVal );
271  magBar_->value( magBarVal );
272  phaseBar_->value( phaseBarVal );
273 
274  if ( init ) {
275  mag_->genValue( magVal );
276  phase_->genValue( phaseVal );
277  magBar_->genValue( magBarVal );
278  phaseBar_->genValue( phaseBarVal );
279 
280  mag_->initValue( magVal );
281  phase_->initValue( phaseVal );
282  magBar_->initValue( magBarVal );
283  phaseBar_->initValue( phaseBarVal );
284  }
285 }
286 
288 {
289  // set the name
290  TString parName(this->baseName()); parName += "_ACP";
291  acp_.name(parName);
292 
293  // work out the ACP value
294 
295  Double_t value(-99.0);
296  value = (magBar_->value()*magBar_->value() - mag_->value()*mag_->value())/(magBar_->value()*magBar_->value() + mag_->value()*mag_->value());
297 
298  // is it fixed?
299  Bool_t fixed = magBar_->fixed() && mag_->fixed();
300  acp_.fixed(fixed);
301 
302  // we can't work out the error without the covariance matrix
303  Double_t error(0.0);
304 
305  // set the value and error
306  acp_.valueAndErrors(value,error);
307 
308  return acp_;
309 }
310 
311 LauAbsCoeffSet* LauMagPhaseCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
312 {
313  LauAbsCoeffSet* clone(0);
314  if ( cloneOption == All || cloneOption == TiePhase || cloneOption == TieMagnitude ) {
315  clone = new LauMagPhaseCPCoeffSet( *this, cloneOption, constFactor );
316  clone->name( newName );
317  } else {
318  std::cerr << "ERROR in LauMagPhaseCPCoeffSet::createClone : Invalid clone option" << std::endl;
319  }
320  return clone;
321 }
322 
static Double_t maxPhase_
Maximum allowed value of phase parameters.
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.
LauParameter acp_
The CP asymmetry.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
const Double_t twoPi
Two times Pi.
File containing declaration of LauMagPhaseCPCoeffSet class.
ClassImp(LauAbsCoeffSet)
LauParameter * phase_
The phase for particles.
LauParameter()
Default constructor.
Definition: LauParameter.cc:44
const TString & name() const
The parameter name.
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 LauPrint class.
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
Class to define various output print commands.
Definition: LauPrint.hh:43
Class for defining a complex coefficient using seperate magnitudes and phases for particles and antip...
virtual void printParValues() const
Print the current values of the parameters.
CloneOption
Options for cloning operation.
Bool_t clone() const
Check whether is a clone or not.
Bool_t blind() const
The blinding state.
static Double_t maxMagnitude_
Maximum allowed value of magnitude parameters.
File containing declaration of LauParameter class.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
File containing declaration of LauComplex class.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:76
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 error() const
The error on the parameter.
const Double_t pi
Pi.
Class for defining the abstract interface for complex coefficient classes.
Class for defining the fit parameter objects.
Definition: LauParameter.hh:49
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.
LauParameter * magBar_
The magnitude for antiparticles.
const LauBlind * blinder() const
Access the blinder object.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:328
Double_t initValue() const
The initial value of the parameter.
void blindParameter(const TString &blindingString, const Double_t width)
Blind the parameter.
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.
LauParameter * mag_
The magnitude for particles.
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 TString name() const
Retrieve the 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.
static Double_t minPhase_
Minimum allowed value of phase parameters.
Double_t value() const
The value of the parameter.
LauComplex particleCoeff_
The particle complex coefficient.
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.
LauParameter * phaseBar_
The phase for antiparticles.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
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.