laura is hosted by Hepforge, IPPP Durham
Laura++  v1r2
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauComplex.hh
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2004 - 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 
23 /*****************************************************************************
24  * Class based on RooFit/RooComplex. *
25  * Original copyright given below. *
26  *****************************************************************************
27  * Authors: *
28  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
29  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
30  * *
31  * Copyright (c) 2000-2005, Regents of the University of California *
32  * and Stanford University. All rights reserved. *
33  * *
34  * Redistribution and use in source and binary forms, *
35  * with or without modification, are permitted according to the terms *
36  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
37  *****************************************************************************/
38 
39 #ifndef LAU_COMPLEX
40 #define LAU_COMPLEX
41 
42 #include <iosfwd>
43 
44 #include "TMath.h"
45 
46 
47 class LauComplex {
48 
49  public:
51 
55  inline LauComplex(Double_t a=0.0, Double_t b=0.0) : re_(a), im_(b) {}
56 
58  virtual ~LauComplex() {}
59 
61 
64  inline LauComplex(const LauComplex& other) : re_(other.re_), im_(other.im_) {}
65 
67 
71  inline LauComplex& operator=(const LauComplex& other)
72  {
73  if ( &other != this ) {
74  re_ = other.re_;
75  im_ = other.im_;
76  }
77  return *this;
78  }
79 
81 
84  inline LauComplex operator-() const
85  {
86  return LauComplex(-re_,-im_);
87  }
88 
90 
94  inline LauComplex operator+(const LauComplex& other) const
95  {
96  LauComplex tmpCmplx( *this );
97  tmpCmplx += other;
98  return tmpCmplx;
99  }
100 
102 
106  inline LauComplex operator-(const LauComplex& other) const
107  {
108  LauComplex tmpCmplx( *this );
109  tmpCmplx -= other;
110  return tmpCmplx;
111  }
112 
114 
118  inline LauComplex operator*(const LauComplex& other) const
119  {
120  LauComplex tmpCmplx( *this );
121  tmpCmplx *= other;
122  return tmpCmplx;
123  }
124 
126 
130  inline LauComplex operator/(const LauComplex& other) const
131  {
132  LauComplex tmpCmplx( *this );
133  tmpCmplx /= other;
134  return tmpCmplx;
135  }
136 
138 
142  inline LauComplex operator+=(const LauComplex& other)
143  {
144  this->re_ += other.re_;
145  this->im_ += other.im_;
146  return (*this);
147  }
148 
150 
154  inline LauComplex operator-=(const LauComplex& other)
155  {
156  this->re_ -= other.re_;
157  this->im_ -= other.im_;
158  return (*this);
159  }
160 
162 
166  inline LauComplex operator*=(const LauComplex& other)
167  {
168  Double_t realPart = this->re_*other.re_ - this->im_*other.im_;
169  Double_t imagPart = this->re_*other.im_ + this->im_*other.re_;
170  this->setRealImagPart( realPart, imagPart );
171  return (*this);
172  }
173 
175 
179  inline LauComplex operator/=(const LauComplex& other)
180  {
181  Double_t x(other.abs2());
182  Double_t realPart = (this->re_*other.re_ + this->im_*other.im_)/x;
183  Double_t imagPart = (this->im_*other.re_ - this->re_*other.im_)/x;
184  this->setRealImagPart( realPart, imagPart );
185  return (*this);
186  }
187 
189 
193  inline Bool_t operator==(const LauComplex& other) const
194  {
195  return (re_==other.re_ && im_==other.im_) ;
196  }
197 
199 
202  inline Double_t re() const
203  {
204  return re_;
205  }
206 
208 
211  inline Double_t im() const
212  {
213  return im_;
214  }
215 
217 
220  inline Double_t abs() const
221  {
222  return TMath::Sqrt( this->abs2() );
223  }
224 
226 
229  inline Double_t abs2() const
230  {
231  return re_*re_ + im_*im_;
232  }
233 
235 
238  inline Double_t arg() const
239  {
240  return TMath::ATan2( im_, re_ );
241  }
242 
244 
247  inline LauComplex exp() const
248  {
249  Double_t mag(TMath::Exp(re_));
250  return LauComplex(mag*TMath::Cos(im_),mag*TMath::Sin(im_));
251  }
252 
254 
257  inline LauComplex conj() const
258  {
259  return LauComplex(re_,-im_);
260  }
261 
263  inline void makeConj()
264  {
265  im_ = -im_;
266  }
267 
269 
273  inline LauComplex scale(Double_t scaleVal) const
274  {
275  return LauComplex(scaleVal*re_, scaleVal*im_);
276  }
277 
279 
282  inline void rescale(Double_t scaleVal)
283  {
284  re_ *= scaleVal;
285  im_ *= scaleVal;
286  }
287 
289 
292  inline void setRealPart(Double_t realpart)
293  {
294  re_ = realpart;
295  }
296 
298 
301  inline void setImagPart(Double_t imagpart)
302  {
303  im_ = imagpart;
304  }
305 
307 
311  inline void setRealImagPart(Double_t realpart, Double_t imagpart)
312  {
313  this->setRealPart( realpart );
314  this->setImagPart( imagpart );
315  }
316 
318  inline void zero()
319  {
320  this->setRealImagPart(0.0,0.0);
321  }
322 
324  void print() const;
325 
326  private:
328  Double_t re_;
330  Double_t im_;
331 
332  ClassDef(LauComplex,0) // a non-persistent bare-bones complex class
333 };
334 
336 std::istream& operator>>(std::istream& os, LauComplex& z);
337 std::ostream& operator<<(std::ostream& os, const LauComplex& z);
338 
339 #endif
virtual ~LauComplex()
Destructor.
Definition: LauComplex.hh:58
LauComplex operator-() const
Unary minus operator.
Definition: LauComplex.hh:84
LauComplex(const LauComplex &other)
Copy constructor.
Definition: LauComplex.hh:64
LauComplex operator+(const LauComplex &other) const
Addition operator.
Definition: LauComplex.hh:94
Double_t re() const
Get the real part.
Definition: LauComplex.hh:202
LauComplex operator*=(const LauComplex &other)
Multiplication assignment operator.
Definition: LauComplex.hh:166
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:211
LauComplex operator+=(const LauComplex &other)
Addition assignment operator.
Definition: LauComplex.hh:142
LauComplex operator/(const LauComplex &other) const
Division operator.
Definition: LauComplex.hh:130
LauComplex(Double_t a=0.0, Double_t b=0.0)
Constructor.
Definition: LauComplex.hh:55
LauComplex exp() const
Obtain the exponential of the complex number.
Definition: LauComplex.hh:247
LauComplex operator-(const LauComplex &other) const
Subtraction operator.
Definition: LauComplex.hh:106
LauComplex conj() const
Obtain the complex conjugate.
Definition: LauComplex.hh:257
Double_t abs2() const
Obtain the square of the absolute value of the complex number.
Definition: LauComplex.hh:229
void setImagPart(Double_t imagpart)
Set the imaginary part.
Definition: LauComplex.hh:301
std::ostream & operator<<(std::ostream &os, const LauComplex &z)
Definition: LauComplex.cc:43
LauComplex operator-=(const LauComplex &other)
Subtraction assignment operator.
Definition: LauComplex.hh:154
LauComplex & operator=(const LauComplex &other)
Copy assignment operator.
Definition: LauComplex.hh:71
void setRealPart(Double_t realpart)
Set the real part.
Definition: LauComplex.hh:292
LauComplex operator/=(const LauComplex &other)
Division assignment operator.
Definition: LauComplex.hh:179
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:311
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:282
void zero()
Set both real and imaginary part to zero.
Definition: LauComplex.hh:318
LauComplex operator*(const LauComplex &other) const
Multiplication operator.
Definition: LauComplex.hh:118
Class for defining a complex number.
Definition: LauComplex.hh:47
Double_t arg() const
Obtain the phase angle of the complex number.
Definition: LauComplex.hh:238
Bool_t operator==(const LauComplex &other) const
Boolean comparison operator.
Definition: LauComplex.hh:193
std::istream & operator>>(std::istream &os, LauComplex &z)
input/output operator formatting of a complex number
Definition: LauComplex.cc:48
void print() const
Print the complex number.
Definition: LauComplex.cc:38
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:220
Double_t re_
The real part.
Definition: LauComplex.hh:328
Double_t im_
The imaginary part.
Definition: LauComplex.hh:330
LauComplex scale(Double_t scaleVal) const
Obtain the complex number scaled by some factor.
Definition: LauComplex.hh:273
void makeConj()
Transform this to its complex conjugate.
Definition: LauComplex.hh:263