laura is hosted by Hepforge, IPPP Durham
Laura++  v3r1
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauCartesianGammaCPCoeffSet.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2006 - 2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 // Authors:
7 // Thomas Latham
8 // John Back
9 // Paul Harrison
10 
15 #include <iostream>
16 #include <fstream>
17 #include <vector>
18 
19 #include "TMath.h"
20 #include "TRandom.h"
21 
23 #include "LauComplex.hh"
24 #include "LauConstants.hh"
25 #include "LauParameter.hh"
26 #include "LauPrint.hh"
27 #include "LauRandom.hh"
28 
30 
31 
32 LauCartesianGammaCPCoeffSet::LauCartesianGammaCPCoeffSet(const TString& compName, const Double_t x, const Double_t y, const Double_t xCP, const Double_t yCP, const Double_t deltaXCP, const Double_t deltaYCP,
33  const Bool_t xFixed, const Bool_t yFixed, const Bool_t xCPFixed, const Bool_t yCPFixed, const Bool_t deltaXCPFixed, const Bool_t deltaYCPFixed, const Bool_t deltaXCPSecondStage, const Bool_t deltaYCPSecondStage) :
34  LauAbsCoeffSet(compName),
35  x_(new LauParameter("X", x, minRealImagPart_, maxRealImagPart_, xFixed)),
36  y_(new LauParameter("Y", y, minRealImagPart_, maxRealImagPart_, yFixed)),
37  xCP_(new LauParameter("XCP", xCP, minRealImagPart_, maxRealImagPart_, xCPFixed)),
38  yCP_(new LauParameter("YCP", yCP, minRealImagPart_, maxRealImagPart_, yCPFixed)),
39  deltaXCP_(new LauParameter("DeltaXCP", deltaXCP, minDelta_, maxDelta_, deltaXCPFixed)),
40  deltaYCP_(new LauParameter("DeltaYCP", deltaYCP, minDelta_, maxDelta_, deltaYCPFixed)),
41  nonCPPart_( x, y),
42  cpPart_( 1+xCP+deltaXCP, yCP+deltaYCP),
43  cpAntiPart_( 1+xCP-deltaXCP, yCP-deltaYCP),
44  particleCoeff_( nonCPPart_ * cpPart_ ),
45  antiparticleCoeff_( nonCPPart_ * cpAntiPart_ ),
46  acp_("ACP", (antiparticleCoeff_.abs2()-particleCoeff_.abs2())/(antiparticleCoeff_.abs2()+particleCoeff_.abs2()), -1.0, 1.0, deltaXCPFixed&&deltaYCPFixed)
47 {
48  if (deltaXCPSecondStage && !deltaXCPFixed) {
49  deltaXCP_->secondStage(kTRUE);
50  deltaXCP_->initValue(0.0);
51  }
52  if (deltaYCPSecondStage && !deltaYCPFixed) {
53  deltaYCP_->secondStage(kTRUE);
54  deltaYCP_->initValue(0.0);
55  }
56 }
57 
59  x_(0),
60  y_(0),
61  xCP_(0),
62  yCP_(0),
63  deltaXCP_(0),
64  deltaYCP_(0),
65  nonCPPart_( rhs.nonCPPart_ ),
66  cpPart_( rhs.cpPart_ ),
67  cpAntiPart_( rhs.cpAntiPart_ ),
68  particleCoeff_( rhs.particleCoeff_ ),
69  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
70  acp_( rhs.acp_ )
71 {
72  if ( cloneOption == All || cloneOption == TieRealPart ) {
73  x_ = rhs.x_->createClone(constFactor);
74  } else {
75  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
76  if ( rhs.x_->blind() ) {
77  const LauBlind* blinder = rhs.x_->blinder();
78  x_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
79  }
80  }
81 
82  if ( cloneOption == All || cloneOption == TieImagPart ) {
83  y_ = rhs.y_->createClone(constFactor);
84  } else {
85  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
86  if ( rhs.y_->blind() ) {
87  const LauBlind* blinder = rhs.y_->blinder();
88  y_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
89  }
90  }
91 
92  if ( cloneOption == All || cloneOption == TieCPPars ) {
93  xCP_ = rhs.xCP_->createClone(constFactor);
94  yCP_ = rhs.yCP_->createClone(constFactor);
95  deltaXCP_ = rhs.deltaXCP_->createClone(constFactor);
96  deltaYCP_ = rhs.deltaYCP_->createClone(constFactor);
97  } else {
98  xCP_ = new LauParameter("XCP", rhs.xCP_->value(), minRealImagPart_, maxRealImagPart_, rhs.xCP_->fixed());
99  if ( rhs.xCP_->blind() ) {
100  const LauBlind* blinder = rhs.xCP_->blinder();
101  xCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
102  }
103  yCP_ = new LauParameter("YCP", rhs.yCP_->value(), minRealImagPart_, maxRealImagPart_, rhs.yCP_->fixed());
104  if ( rhs.yCP_->blind() ) {
105  const LauBlind* blinder = rhs.yCP_->blinder();
106  yCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
107  }
108  deltaXCP_ = new LauParameter("DeltaXCP", rhs.deltaXCP_->value(), minDelta_, maxDelta_, rhs.deltaXCP_->fixed());
109  deltaYCP_ = new LauParameter("DeltaYCP", rhs.deltaYCP_->value(), minDelta_, maxDelta_, rhs.deltaYCP_->fixed());
110  if ( rhs.deltaXCP_->secondStage() && !rhs.deltaXCP_->fixed() ) {
111  deltaXCP_->secondStage(kTRUE);
112  deltaXCP_->initValue(0.0);
113  }
114  if ( rhs.deltaYCP_->secondStage() && !rhs.deltaYCP_->fixed() ) {
115  deltaYCP_->secondStage(kTRUE);
116  deltaYCP_->initValue(0.0);
117  }
118  if ( rhs.deltaXCP_->blind() ) {
119  const LauBlind* blinder = rhs.deltaXCP_->blinder();
120  deltaXCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
121  }
122  if ( rhs.deltaYCP_->blind() ) {
123  const LauBlind* blinder = rhs.deltaYCP_->blinder();
124  deltaYCP_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
125  }
126  }
127 }
128 
129 std::vector<LauParameter*> LauCartesianGammaCPCoeffSet::getParameters()
130 {
131  std::vector<LauParameter*> pars;
132  pars.push_back(x_);
133  pars.push_back(y_);
134  if(!xCP_->fixed()) pars.push_back(xCP_);
135  if(!yCP_->fixed()) pars.push_back(yCP_);
136  if(!deltaXCP_->fixed()) pars.push_back(deltaXCP_);
137  if(!deltaYCP_->fixed()) pars.push_back(deltaYCP_);
138  return pars;
139 }
140 
142 {
143  std::cout<<"INFO in LauCartesianGammaCPCoeffSet::printParValues : Component \""<<this->name()<<"\" has ";
144  std::cout<<"x = "<<x_->value()<<",\t";
145  std::cout<<"y = "<<y_->value()<<",\t";
146  std::cout<<"xCP = "<<xCP_->value()<<",\t";
147  std::cout<<"yCP = "<<yCP_->value()<<",\t";
148  std::cout<<"Delta xCP = "<<deltaXCP_->value()<<",\t";
149  std::cout<<"Delta yCP = "<<deltaYCP_->value()<<"."<<std::endl;
150 }
151 
152 void LauCartesianGammaCPCoeffSet::printTableHeading(std::ostream& stream) const
153 {
154  stream<<"\\begin{tabular}{|l|c|c|c|c|c|c|}"<<std::endl;
155  stream<<"\\hline"<<std::endl;
156  stream<<"Component & Real Part & Imaginary Part & Real CP Part & Imaginary CP Part & $\\Delta$ Real CP Part & $\\Delta$ Imaginary CP Part \\\\"<<std::endl;
157  stream<<"\\hline"<<std::endl;
158 }
159 
160 void LauCartesianGammaCPCoeffSet::printTableRow(std::ostream& stream) const
161 {
162  LauPrint print;
163  TString resName = this->name();
164  resName = resName.ReplaceAll("_", "\\_");
165  stream<<resName<<" & $";
166  print.printFormat(stream, x_->value());
167  stream<<" \\pm ";
168  print.printFormat(stream, x_->error());
169  stream<<"$ & $";
170  print.printFormat(stream, y_->value());
171  stream<<" \\pm ";
172  print.printFormat(stream, y_->error());
173  stream<<"$ & $";
174  print.printFormat(stream, xCP_->value());
175  stream<<" \\pm ";
176  print.printFormat(stream, xCP_->error());
177  stream<<"$ & $";
178  print.printFormat(stream, yCP_->value());
179  stream<<" \\pm ";
180  print.printFormat(stream, yCP_->error());
181  stream<<"$ & $";
182  print.printFormat(stream, deltaXCP_->value());
183  stream<<" \\pm ";
184  print.printFormat(stream, deltaXCP_->error());
185  stream<<"$ & $";
186  print.printFormat(stream, deltaYCP_->value());
187  stream<<" \\pm ";
188  print.printFormat(stream, deltaYCP_->error());
189  stream<<"$ \\\\"<<std::endl;
190 }
191 
193 {
194  if (x_->fixed() == kFALSE) {
195  // Choose a value for "X" between -3.0 and 3.0
196  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
197  x_->initValue(value); x_->value(value);
198  }
199  if (y_->fixed() == kFALSE) {
200  // Choose a value for "Y" between -3.0 and 3.0
201  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
202  y_->initValue(value); y_->value(value);
203  }
204  if (xCP_->fixed() == kFALSE) {
205  // Choose a value for "XCP" between -3.0 and 3.0
206  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
207  xCP_->initValue(value); xCP_->value(value);
208  }
209  if (yCP_->fixed() == kFALSE) {
210  // Choose a value for "YCP" between -3.0 and 3.0
211  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*6.0 - 3.0;
212  yCP_->initValue(value); yCP_->value(value);
213  }
214  if (deltaXCP_->fixed() == kFALSE && deltaXCP_->secondStage() == kFALSE) {
215  // Choose a value for "Delta XCP" between -0.5 and 0.5
216  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*1.0 - 0.5;
217  deltaXCP_->initValue(value); deltaXCP_->value(value);
218  }
219  if (deltaYCP_->fixed() == kFALSE && deltaYCP_->secondStage() == kFALSE) {
220  // Choose a value for "Delta YCP" between -0.5 and 0.5
221  Double_t value = LauRandom::zeroSeedRandom()->Rndm()*1.0 - 0.5;
222  deltaYCP_->initValue(value); deltaYCP_->value(value);
223  }
224 }
225 
227 {
228  // update the pulls
229  x_->updatePull();
230  y_->updatePull();
231  xCP_->updatePull();
232  yCP_->updatePull();
235 }
236 
238 {
242  return particleCoeff_;
243 }
244 
246 {
250  return antiparticleCoeff_;
251 }
252 
254 {
255  std::cerr << "ERROR in LauCartesianGammaCPCoeffSet::setCoeffValues : Method not supported by this class - too many parameters" << std::endl;
256 }
257 
259 {
260  // set the name
261  TString parName(this->baseName()); parName += "_ACP";
262  acp_.name(parName);
263 
264  // work out the ACP value
265  const LauComplex nonCPPart( x_->value(), y_->value() );
266  const LauComplex cpPart( 1.0+xCP_->value()+deltaXCP_->value(), yCP_->value()+deltaYCP_->value() );
267  const LauComplex cpAntiPart( 1.0+xCP_->value()-deltaXCP_->value(), yCP_->value()-deltaYCP_->value() );
268  const LauComplex partCoeff = nonCPPart * cpPart;
269  const LauComplex antiCoeff = nonCPPart * cpAntiPart;
270 
271  const Double_t numer = antiCoeff.abs2() - partCoeff.abs2();
272  const Double_t denom = antiCoeff.abs2() + partCoeff.abs2();
273  const Double_t value = numer/denom;
274 
275  // is it fixed?
276  const Bool_t fixed = deltaXCP_->fixed() && deltaYCP_->fixed();
277  acp_.fixed(fixed);
278 
279  // we can't work out the error without the covariance matrix
280  const Double_t error(0.0);
281 
282  // set the value and error
283  acp_.valueAndErrors(value,error);
284 
285  return acp_;
286 }
287 
288 LauAbsCoeffSet* LauCartesianGammaCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
289 {
290  LauAbsCoeffSet* clone(0);
291  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart || cloneOption == TieCPPars ) {
292  clone = new LauCartesianGammaCPCoeffSet( *this, cloneOption, constFactor );
293  clone->name( newName );
294  } else {
295  std::cerr << "ERROR in LauCartesianGammaCPCoeffSet::createClone : Invalid clone option" << std::endl;
296  }
297  return clone;
298 }
299 
LauParameter * yCP_
The average CP imaginary part.
virtual LauParameter acp()
Calculate the CP asymmetry.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
LauComplex cpAntiPart_
The CP part of the complex coefficient for the antiparticle.
static Double_t minDelta_
Minimum allowed value of CP-violating real/imaginary part parameters.
TRandom * zeroSeedRandom()
Access the singleton random number generator with seed set from machine clock time (within +-1 sec)...
Definition: LauRandom.cc:30
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
Class for defining a complex coefficient using the Cartesian gamma CP convention. ...
ClassImp(LauAbsCoeffSet)
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
const TString & name() const
The parameter name.
LauComplex cpPart_
The CP part of the complex coefficient for the particle.
static Double_t maxRealImagPart_
Maximum allowed value of real/imaginary part parameters.
static Double_t maxDelta_
Maximum allowed value of CP-violating real/imaginary part parameters.
LauParameter * y_
The nonCP imaginary part.
File containing declaration of LauPrint class.
Class to define various output print commands.
Definition: LauPrint.hh:29
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
CloneOption
Options for cloning operation.
Double_t abs2() const
Obtain the square of the absolute value of the complex number.
Definition: LauComplex.hh:232
Bool_t clone() const
Check whether is a clone or not.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.
Bool_t blind() const
The blinding state.
LauComplex particleCoeff_
The particle complex coefficient.
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
LauParameter acp_
The CP asymmetry.
File containing declaration of LauParameter class.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
Bool_t secondStage() const
Check whether the parameter should be floated only in the second stage of a two stage fit...
LauParameter * deltaXCP_
The asymmetric CP real part.
File containing declaration of LauComplex class.
LauParameter * x_
The nonCP real part.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:62
Double_t error() const
The error on the parameter.
LauParameter * xCP_
The average CP real part.
Class for defining the abstract interface for complex coefficient classes.
Class for defining the fit parameter objects.
Definition: LauParameter.hh:35
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 void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
static Double_t minRealImagPart_
Minimum allowed value of real/imaginary part parameters.
File containing LauRandom namespace.
const LauBlind * blinder() const
Access the blinder object.
virtual void setCoeffValues(const LauComplex &coeff, const LauComplex &coeffBar, Bool_t init)
Set the parameters based on the complex coefficients for particles and antiparticles.
LauParameter * deltaYCP_
The asymmetric CP imaginary part.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:314
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:32
Double_t unblindValue() const
The unblinded value of the parameter.
Class for defining a complex number.
Definition: LauComplex.hh:47
void updatePull()
Call to update the bias and pull values.
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.
File containing declaration of LauCartesianGammaCPCoeffSet class.
LauCartesianGammaCPCoeffSet(const TString &compName, const Double_t x, const Double_t y, const Double_t xCP, const Double_t yCP, const Double_t deltaXCP, const Double_t deltaYCP, const Bool_t xFixed, const Bool_t yFixed, const Bool_t xCPFixed, const Bool_t yCPFixed, const Bool_t deltaXCPFixed, const Bool_t deltaYCPFixed, const Bool_t deltaXCPSecondStage=kFALSE, const Bool_t deltaYCPSecondStage=kFALSE)
Constructor.
Double_t value() const
The value of the parameter.
virtual void printParValues() const
Print the current values of the parameters.
Double_t blindingWidth() const
Obtain the Gaussian width.
Definition: LauBlind.hh:68
virtual const TString & baseName() const
Retrieve the base name of the coefficient set.
Class for blinding and unblinding a number based on a blinding string.
Definition: LauBlind.hh:28
LauComplex nonCPPart_
The nonCP part of the complex coefficient.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.