laura is hosted by Hepforge, IPPP Durham
Laura++  v3r5
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauCartesianCPCoeffSet.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 <iostream>
30 #include <fstream>
31 #include <vector>
32 
33 #include "TMath.h"
34 #include "TRandom.h"
35 
37 #include "LauComplex.hh"
38 #include "LauConstants.hh"
39 #include "LauParameter.hh"
40 #include "LauPrint.hh"
41 
43 
44 
45 LauCartesianCPCoeffSet::LauCartesianCPCoeffSet(const TString& compName, Double_t x, Double_t y, Double_t deltaX, Double_t deltaY,
46  Bool_t xFixed, Bool_t yFixed, Bool_t deltaXFixed, Bool_t deltaYFixed, Bool_t deltaXSecondStage, Bool_t deltaYSecondStage) :
47  LauAbsCoeffSet(compName),
48  x_(new LauParameter("X", x, minRealImagPart_, maxRealImagPart_, xFixed)),
49  y_(new LauParameter("Y", y, minRealImagPart_, maxRealImagPart_, yFixed)),
50  deltaX_(new LauParameter("DeltaX", deltaX, minDelta_, maxDelta_, deltaXFixed)),
51  deltaY_(new LauParameter("DeltaY", deltaY, minDelta_, maxDelta_, deltaYFixed)),
52  particleCoeff_( x+deltaX, y+deltaY ),
53  antiparticleCoeff_( x-deltaX, y-deltaY ),
54  acp_("ACP", -2.0*(x*deltaX + y*deltaY)/(x*x + deltaX*deltaX + y*y + deltaY*deltaY), -1.0, 1.0, deltaXFixed&&deltaYFixed)
55 {
56  if (deltaXSecondStage && !deltaXFixed) {
57  deltaX_->secondStage(kTRUE);
58  deltaX_->initValue(0.0);
59  }
60  if (deltaYSecondStage && !deltaYFixed) {
61  deltaY_->secondStage(kTRUE);
62  deltaY_->initValue(0.0);
63  }
64 }
65 
67  x_(0),
68  y_(0),
69  deltaX_(0),
70  deltaY_(0),
71  particleCoeff_( rhs.particleCoeff_ ),
72  antiparticleCoeff_( rhs.antiparticleCoeff_ ),
73  acp_( rhs.acp_ )
74 {
75  if ( cloneOption == All || cloneOption == TieRealPart ) {
76  x_ = rhs.x_->createClone(constFactor);
77  } else {
78  x_ = new LauParameter("X", rhs.x_->value(), minRealImagPart_, maxRealImagPart_, rhs.x_->fixed());
79  if ( rhs.x_->blind() ) {
80  const LauBlind* blinder = rhs.x_->blinder();
81  x_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
82  }
83  }
84 
85  if ( cloneOption == All || cloneOption == TieImagPart ) {
86  y_ = rhs.y_->createClone(constFactor);
87  } else {
88  y_ = new LauParameter("Y", rhs.y_->value(), minRealImagPart_, maxRealImagPart_, rhs.y_->fixed());
89  if ( rhs.y_->blind() ) {
90  const LauBlind* blinder = rhs.y_->blinder();
91  y_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
92  }
93  }
94 
95  if ( cloneOption == All || cloneOption == TieCPPars ) {
96  deltaX_ = rhs.deltaX_->createClone(constFactor);
97  deltaY_ = rhs.deltaY_->createClone(constFactor);
98  } else {
99  deltaX_ = new LauParameter("DeltaX", rhs.deltaX_->value(), minDelta_, maxDelta_, rhs.deltaX_->fixed());
100  deltaY_ = new LauParameter("DeltaY", rhs.deltaY_->value(), minDelta_, maxDelta_, rhs.deltaY_->fixed());
101  if ( rhs.deltaX_->secondStage() && !rhs.deltaX_->fixed() ) {
102  deltaX_->secondStage(kTRUE);
103  deltaX_->initValue(0.0);
104  }
105  if ( rhs.deltaY_->secondStage() && !rhs.deltaY_->fixed() ) {
106  deltaY_->secondStage(kTRUE);
107  deltaY_->initValue(0.0);
108  }
109  if ( rhs.deltaX_->blind() ) {
110  const LauBlind* blinder = rhs.deltaX_->blinder();
111  deltaX_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
112  }
113  if ( rhs.deltaY_->blind() ) {
114  const LauBlind* blinder = rhs.deltaY_->blinder();
115  deltaY_->blindParameter( blinder->blindingString(), blinder->blindingWidth() );
116  }
117  }
118 }
119 
120 std::vector<LauParameter*> LauCartesianCPCoeffSet::getParameters()
121 {
122  std::vector<LauParameter*> pars;
123  pars.push_back(x_);
124  pars.push_back(y_);
125  pars.push_back(deltaX_);
126  pars.push_back(deltaY_);
127  return pars;
128 }
129 
131 {
132  std::cout<<"INFO in LauCartesianCPCoeffSet::printParValues : Component \""<<this->name()<<"\" has ";
133  std::cout<<"x = "<<x_->value()<<",\t";
134  std::cout<<"y = "<<y_->value()<<",\t";
135  std::cout<<"Delta x = "<<deltaX_->value()<<",\t";
136  std::cout<<"Delta y = "<<deltaY_->value()<<"."<<std::endl;
137 }
138 
139 void LauCartesianCPCoeffSet::printTableHeading(std::ostream& stream) const
140 {
141  stream<<"\\begin{tabular}{|l|c|c|c|c|}"<<std::endl;
142  stream<<"\\hline"<<std::endl;
143  stream<<"Component & Real Part & Imaginary Part & $\\Delta$ Real Part & $\\Delta$ Imaginary Part \\\\"<<std::endl;
144  stream<<"\\hline"<<std::endl;
145 }
146 
147 void LauCartesianCPCoeffSet::printTableRow(std::ostream& stream) const
148 {
149  LauPrint print;
150  TString resName = this->name();
151  resName = resName.ReplaceAll("_", "\\_");
152  stream<<resName<<" & $";
153  print.printFormat(stream, x_->value());
154  stream<<" \\pm ";
155  print.printFormat(stream, x_->error());
156  stream<<"$ & $";
157  print.printFormat(stream, y_->value());
158  stream<<" \\pm ";
159  print.printFormat(stream, y_->error());
160  stream<<"$ & $";
161  print.printFormat(stream, deltaX_->value());
162  stream<<" \\pm ";
163  print.printFormat(stream, deltaX_->error());
164  stream<<"$ & $";
165  print.printFormat(stream, deltaY_->value());
166  stream<<" \\pm ";
167  print.printFormat(stream, deltaY_->error());
168  stream<<"$ \\\\"<<std::endl;
169 }
170 
172 {
173  if (x_->fixed() == kFALSE) {
174  // Choose a value for "X" between -3.0 and 3.0
175  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
176  x_->initValue(value); x_->value(value);
177  }
178  if (y_->fixed() == kFALSE) {
179  // Choose a value for "Y" between -3.0 and 3.0
180  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*6.0 - 3.0;
181  y_->initValue(value); y_->value(value);
182  }
183  if (deltaX_->fixed() == kFALSE && deltaX_->secondStage() == kFALSE) {
184  // Choose a value for "Delta X" between -0.5 and 0.5
185  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*1.0 - 0.5;
186  deltaX_->initValue(value); deltaX_->value(value);
187  }
188  if (deltaY_->fixed() == kFALSE && deltaY_->secondStage() == kFALSE) {
189  // Choose a value for "Delta Y" between -0.5 and 0.5
190  Double_t value = LauAbsCoeffSet::getRandomiser()->Rndm()*1.0 - 0.5;
191  deltaY_->initValue(value); deltaY_->value(value);
192  }
193 }
194 
196 {
197  // update the pulls
198  x_->updatePull();
199  y_->updatePull();
200  deltaX_->updatePull();
201  deltaY_->updatePull();
202 }
203 
205 {
207  return particleCoeff_;
208 }
209 
211 {
213  return antiparticleCoeff_;
214 }
215 
216 void LauCartesianCPCoeffSet::setCoeffValues( const LauComplex& coeff, const LauComplex& coeffBar, Bool_t init )
217 {
218  LauComplex average( coeff );
219  average += coeffBar;
220  average.rescale( 0.5 );
221 
222  Double_t xVal( average.re() );
223  Double_t yVal( average.im() );
224  Double_t deltaXVal( coeff.re() - average.re() );
225  Double_t deltaYVal( coeff.im() - average.im() );
226 
227  x_->value( xVal );
228  y_->value( yVal );
229  deltaX_->value( deltaXVal );
230  deltaY_->value( deltaYVal );
231 
232  if ( init ) {
233  x_->genValue( xVal );
234  y_->genValue( yVal );
235  deltaX_->genValue( deltaXVal );
236  deltaY_->genValue( deltaYVal );
237 
238  x_->initValue( xVal );
239  y_->initValue( yVal );
240  deltaX_->initValue( deltaXVal );
241  deltaY_->initValue( deltaYVal );
242  }
243 }
244 
246 {
247  // set the name
248  TString parName(this->baseName()); parName += "_ACP";
249  acp_.name(parName);
250 
251  // work out the ACP value
252  Double_t numer = x_->value()*deltaX_->value() + y_->value()*deltaY_->value();
253  Double_t denom = x_->value()*x_->value() + deltaX_->value()*deltaX_->value() + y_->value()*y_->value() + deltaY_->value()*deltaY_->value();
254  Double_t value = -2.0*numer/denom;
255 
256  // is it fixed?
257  Bool_t fixed = deltaX_->fixed() && deltaY_->fixed();
258  acp_.fixed(fixed);
259 
260  // we can't work out the error without the covariance matrix
261  Double_t error(0.0);
262 
263  // set the value and error
264  acp_.valueAndErrors(value,error);
265 
266  return acp_;
267 }
268 
269 LauAbsCoeffSet* LauCartesianCPCoeffSet::createClone(const TString& newName, CloneOption cloneOption, Double_t constFactor)
270 {
271  LauAbsCoeffSet* clone(0);
272  if ( cloneOption == All || cloneOption == TieRealPart || cloneOption == TieImagPart || cloneOption == TieCPPars ) {
273  clone = new LauCartesianCPCoeffSet( *this, cloneOption, constFactor );
274  clone->name( newName );
275  } else {
276  std::cerr << "ERROR in LauCartesianCPCoeffSet::createClone : Invalid clone option" << std::endl;
277  }
278  return clone;
279 }
280 
LauParameter * deltaY_
The asymmetric imaginary part.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
virtual void printParValues() const
Print the current values of the parameters.
static Double_t minDelta_
Minimum allowed value of CP-violating real/imaginary part parameters.
LauCartesianCPCoeffSet(const TString &compName, Double_t x, Double_t y, Double_t deltaX, Double_t deltaY, Bool_t xFixed, Bool_t yFixed, Bool_t deltaXFixed, Bool_t deltaYFixed, Bool_t deltaXSecondStage=kFALSE, Bool_t deltaYSecondStage=kFALSE)
Constructor.
ClassImp(LauAbsCoeffSet)
LauParameter * deltaX_
The asymmetric real part.
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()
Default constructor.
Definition: LauParameter.cc:44
const TString & name() const
The parameter name.
LauParameter * x_
The average real part.
Double_t re() const
Get the real part.
Definition: LauComplex.hh:219
virtual LauParameter acp()
Calculate the CP asymmetry.
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:228
static Double_t maxRealImagPart_
Maximum allowed value of real/imaginary part parameters.
LauComplex particleCoeff_
The particle complex coefficient.
static Double_t maxDelta_
Maximum allowed value of CP-violating real/imaginary part parameters.
File containing declaration of LauPrint class.
Class to define various output print commands.
Definition: LauPrint.hh:43
virtual const LauComplex & antiparticleCoeff()
Retrieve the complex coefficient for an antiparticle.
CloneOption
Options for cloning operation.
Bool_t clone() const
Check whether is a clone or not.
Bool_t blind() const
The blinding state.
virtual LauAbsCoeffSet * createClone(const TString &newName, CloneOption cloneOption=All, Double_t constFactor=1.0)
Create a clone of the coefficient set.
virtual void printTableRow(std::ostream &stream) const
Print the parameters of the complex coefficient as a row in the results table.
virtual const LauComplex & particleCoeff()
Retrieve the complex coefficient for a particle.
File containing declaration of LauParameter class.
LauParameter * y_
The average imaginary part.
Bool_t secondStage() const
Check whether the parameter should be floated only in the second stage of a two stage fit...
File containing declaration of LauComplex class.
const TString & blindingString() const
Obtain the blinding string.
Definition: LauBlind.hh:76
Double_t error() const
The error on the parameter.
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.
static Double_t minRealImagPart_
Minimum allowed value of real/imaginary part parameters.
File containing declaration of LauCartesianCPCoeffSet class.
const LauBlind * blinder() const
Access the blinder object.
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:328
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:299
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 * 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.
virtual void finaliseValues()
Make sure values are in &quot;standard&quot; ranges, e.g. phases should be between -pi and pi.
Double_t value() const
The value of the parameter.
virtual std::vector< LauParameter * > getParameters()
Retrieve the parameters of the coefficient, e.g. so that they can be loaded into a fit...
LauParameter acp_
The CP asymmetry.
virtual void printTableHeading(std::ostream &stream) const
Print the column headings for a results table.
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.
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.
Class for defining a complex coefficient using the Cartesian CP convention.
LauComplex antiparticleCoeff_
The antiparticle complex coefficient.
virtual void randomiseInitValues()
Randomise the starting values of the parameters for a fit.