laura is hosted by Hepforge, IPPP Durham
Laura++  v3r2
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  inline LauComplex() : re_(0.0), im_(0.0) {}
52 
54 
58  inline LauComplex(Double_t a, Double_t b) : re_(a), im_(b) {}
59 
61  virtual ~LauComplex() {}
62 
64 
67  inline LauComplex(const LauComplex& other) : re_(other.re_), im_(other.im_) {}
68 
70 
74  inline LauComplex& operator=(const LauComplex& other)
75  {
76  if ( &other != this ) {
77  re_ = other.re_;
78  im_ = other.im_;
79  }
80  return *this;
81  }
82 
84 
87  inline LauComplex operator-() const
88  {
89  return LauComplex(-re_,-im_);
90  }
91 
93 
97  inline LauComplex operator+(const LauComplex& other) const
98  {
99  LauComplex tmpCmplx( *this );
100  tmpCmplx += other;
101  return tmpCmplx;
102  }
103 
105 
109  inline LauComplex operator-(const LauComplex& other) const
110  {
111  LauComplex tmpCmplx( *this );
112  tmpCmplx -= other;
113  return tmpCmplx;
114  }
115 
117 
121  inline LauComplex operator*(const LauComplex& other) const
122  {
123  LauComplex tmpCmplx( *this );
124  tmpCmplx *= other;
125  return tmpCmplx;
126  }
127 
129 
133  inline LauComplex operator/(const LauComplex& other) const
134  {
135  LauComplex tmpCmplx( *this );
136  tmpCmplx /= other;
137  return tmpCmplx;
138  }
139 
141 
145  inline LauComplex operator+=(const LauComplex& other)
146  {
147  this->re_ += other.re_;
148  this->im_ += other.im_;
149  return (*this);
150  }
151 
153 
157  inline LauComplex operator-=(const LauComplex& other)
158  {
159  this->re_ -= other.re_;
160  this->im_ -= other.im_;
161  return (*this);
162  }
163 
165 
169  inline LauComplex operator*=(const LauComplex& other)
170  {
171  Double_t realPart = this->re_*other.re_ - this->im_*other.im_;
172  Double_t imagPart = this->re_*other.im_ + this->im_*other.re_;
173  this->setRealImagPart( realPart, imagPart );
174  return (*this);
175  }
176 
178 
182  inline LauComplex operator/=(const LauComplex& other)
183  {
184  Double_t x(other.abs2());
185  Double_t realPart = (this->re_*other.re_ + this->im_*other.im_)/x;
186  Double_t imagPart = (this->im_*other.re_ - this->re_*other.im_)/x;
187  this->setRealImagPart( realPart, imagPart );
188  return (*this);
189  }
190 
192 
196  inline Bool_t operator==(const LauComplex& other) const
197  {
198  return (re_==other.re_ && im_==other.im_) ;
199  }
200 
202 
205  inline Double_t re() const
206  {
207  return re_;
208  }
209 
211 
214  inline Double_t im() const
215  {
216  return im_;
217  }
218 
220 
223  inline Double_t abs() const
224  {
225  return TMath::Sqrt( this->abs2() );
226  }
227 
229 
232  inline Double_t abs2() const
233  {
234  return re_*re_ + im_*im_;
235  }
236 
238 
241  inline Double_t arg() const
242  {
243  return TMath::ATan2( im_, re_ );
244  }
245 
247 
250  inline LauComplex exp() const
251  {
252  Double_t mag(TMath::Exp(re_));
253  return LauComplex(mag*TMath::Cos(im_),mag*TMath::Sin(im_));
254  }
255 
257 
260  inline LauComplex conj() const
261  {
262  return LauComplex(re_,-im_);
263  }
264 
266  inline void makeConj()
267  {
268  im_ = -im_;
269  }
270 
272 
276  inline LauComplex scale(Double_t scaleVal) const
277  {
278  return LauComplex(scaleVal*re_, scaleVal*im_);
279  }
280 
282 
285  inline void rescale(Double_t scaleVal)
286  {
287  re_ *= scaleVal;
288  im_ *= scaleVal;
289  }
290 
292 
295  inline void setRealPart(Double_t realpart)
296  {
297  re_ = realpart;
298  }
299 
301 
304  inline void setImagPart(Double_t imagpart)
305  {
306  im_ = imagpart;
307  }
308 
310 
314  inline void setRealImagPart(Double_t realpart, Double_t imagpart)
315  {
316  this->setRealPart( realpart );
317  this->setImagPart( imagpart );
318  }
319 
321  inline void zero()
322  {
323  this->setRealImagPart(0.0,0.0);
324  }
325 
327  void print() const;
328 
329  private:
331  Double_t re_;
333  Double_t im_;
334 
335  ClassDef(LauComplex,0) // a non-persistent bare-bones complex class
336 };
337 
339 std::istream& operator>>(std::istream& os, LauComplex& z);
340 std::ostream& operator<<(std::ostream& os, const LauComplex& z);
341 
342 #endif
virtual ~LauComplex()
Destructor.
Definition: LauComplex.hh:61
LauComplex operator-() const
Unary minus operator.
Definition: LauComplex.hh:87
LauComplex(const LauComplex &other)
Copy constructor.
Definition: LauComplex.hh:67
LauComplex()
Default Constructor.
Definition: LauComplex.hh:51
LauComplex operator+(const LauComplex &other) const
Addition operator.
Definition: LauComplex.hh:97
Double_t re() const
Get the real part.
Definition: LauComplex.hh:205
LauComplex operator*=(const LauComplex &other)
Multiplication assignment operator.
Definition: LauComplex.hh:169
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:214
LauComplex operator+=(const LauComplex &other)
Addition assignment operator.
Definition: LauComplex.hh:145
LauComplex operator/(const LauComplex &other) const
Division operator.
Definition: LauComplex.hh:133
LauComplex(Double_t a, Double_t b)
Constructor.
Definition: LauComplex.hh:58
LauComplex exp() const
Obtain the exponential of the complex number.
Definition: LauComplex.hh:250
LauComplex operator-(const LauComplex &other) const
Subtraction operator.
Definition: LauComplex.hh:109
LauComplex conj() const
Obtain the complex conjugate.
Definition: LauComplex.hh:260
Double_t abs2() const
Obtain the square of the absolute value of the complex number.
Definition: LauComplex.hh:232
void setImagPart(Double_t imagpart)
Set the imaginary part.
Definition: LauComplex.hh:304
std::ostream & operator<<(std::ostream &os, const LauComplex &z)
Definition: LauComplex.cc:43
LauComplex operator-=(const LauComplex &other)
Subtraction assignment operator.
Definition: LauComplex.hh:157
LauComplex & operator=(const LauComplex &other)
Copy assignment operator.
Definition: LauComplex.hh:74
void setRealPart(Double_t realpart)
Set the real part.
Definition: LauComplex.hh:295
LauComplex operator/=(const LauComplex &other)
Division assignment operator.
Definition: LauComplex.hh:182
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:314
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:285
void zero()
Set both real and imaginary part to zero.
Definition: LauComplex.hh:321
LauComplex operator*(const LauComplex &other) const
Multiplication operator.
Definition: LauComplex.hh:121
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:241
Bool_t operator==(const LauComplex &other) const
Boolean comparison operator.
Definition: LauComplex.hh:196
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:223
Double_t re_
The real part.
Definition: LauComplex.hh:331
Double_t im_
The imaginary part.
Definition: LauComplex.hh:333
LauComplex scale(Double_t scaleVal) const
Obtain the complex number scaled by some factor.
Definition: LauComplex.hh:276
void makeConj()
Transform this to its complex conjugate.
Definition: LauComplex.hh:266