laura is hosted by Hepforge, IPPP Durham
Laura++  v3r5
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauComplex.hh
Go to the documentation of this file.
1 
2 /*
3 Copyright 2004 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 
37 /*****************************************************************************
38  * Class based on RooFit/RooComplex. *
39  * Original copyright given below. *
40  *****************************************************************************
41  * Authors: *
42  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
43  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
44  * *
45  * Copyright (c) 2000-2005, Regents of the University of California *
46  * and Stanford University. All rights reserved. *
47  * *
48  * Redistribution and use in source and binary forms, *
49  * with or without modification, are permitted according to the terms *
50  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
51  *****************************************************************************/
52 
53 #ifndef LAU_COMPLEX
54 #define LAU_COMPLEX
55 
56 #include <iosfwd>
57 
58 #include "TMath.h"
59 
60 
61 class LauComplex {
62 
63  public:
65  inline LauComplex() : re_(0.0), im_(0.0) {}
66 
68 
72  inline LauComplex(Double_t a, Double_t b) : re_(a), im_(b) {}
73 
75  virtual ~LauComplex() {}
76 
78 
81  inline LauComplex(const LauComplex& other) : re_(other.re_), im_(other.im_) {}
82 
84 
88  inline LauComplex& operator=(const LauComplex& other)
89  {
90  if ( &other != this ) {
91  re_ = other.re_;
92  im_ = other.im_;
93  }
94  return *this;
95  }
96 
98 
101  inline LauComplex operator-() const
102  {
103  return LauComplex(-re_,-im_);
104  }
105 
107 
111  inline LauComplex operator+(const LauComplex& other) const
112  {
113  LauComplex tmpCmplx( *this );
114  tmpCmplx += other;
115  return tmpCmplx;
116  }
117 
119 
123  inline LauComplex operator-(const LauComplex& other) const
124  {
125  LauComplex tmpCmplx( *this );
126  tmpCmplx -= other;
127  return tmpCmplx;
128  }
129 
131 
135  inline LauComplex operator*(const LauComplex& other) const
136  {
137  LauComplex tmpCmplx( *this );
138  tmpCmplx *= other;
139  return tmpCmplx;
140  }
141 
143 
147  inline LauComplex operator/(const LauComplex& other) const
148  {
149  LauComplex tmpCmplx( *this );
150  tmpCmplx /= other;
151  return tmpCmplx;
152  }
153 
155 
159  inline LauComplex operator+=(const LauComplex& other)
160  {
161  this->re_ += other.re_;
162  this->im_ += other.im_;
163  return (*this);
164  }
165 
167 
171  inline LauComplex operator-=(const LauComplex& other)
172  {
173  this->re_ -= other.re_;
174  this->im_ -= other.im_;
175  return (*this);
176  }
177 
179 
183  inline LauComplex operator*=(const LauComplex& other)
184  {
185  Double_t realPart = this->re_*other.re_ - this->im_*other.im_;
186  Double_t imagPart = this->re_*other.im_ + this->im_*other.re_;
187  this->setRealImagPart( realPart, imagPart );
188  return (*this);
189  }
190 
192 
196  inline LauComplex operator/=(const LauComplex& other)
197  {
198  Double_t x(other.abs2());
199  Double_t realPart = (this->re_*other.re_ + this->im_*other.im_)/x;
200  Double_t imagPart = (this->im_*other.re_ - this->re_*other.im_)/x;
201  this->setRealImagPart( realPart, imagPart );
202  return (*this);
203  }
204 
206 
210  inline Bool_t operator==(const LauComplex& other) const
211  {
212  return (re_==other.re_ && im_==other.im_) ;
213  }
214 
216 
219  inline Double_t re() const
220  {
221  return re_;
222  }
223 
225 
228  inline Double_t im() const
229  {
230  return im_;
231  }
232 
234 
237  inline Double_t abs() const
238  {
239  return TMath::Sqrt( this->abs2() );
240  }
241 
243 
246  inline Double_t abs2() const
247  {
248  return re_*re_ + im_*im_;
249  }
250 
252 
255  inline Double_t arg() const
256  {
257  return TMath::ATan2( im_, re_ );
258  }
259 
261 
264  inline LauComplex exp() const
265  {
266  Double_t mag(TMath::Exp(re_));
267  return LauComplex(mag*TMath::Cos(im_),mag*TMath::Sin(im_));
268  }
269 
271 
274  inline LauComplex conj() const
275  {
276  return LauComplex(re_,-im_);
277  }
278 
280  inline void makeConj()
281  {
282  im_ = -im_;
283  }
284 
286 
290  inline LauComplex scale(Double_t scaleVal) const
291  {
292  return LauComplex(scaleVal*re_, scaleVal*im_);
293  }
294 
296 
299  inline void rescale(Double_t scaleVal)
300  {
301  re_ *= scaleVal;
302  im_ *= scaleVal;
303  }
304 
306 
309  inline void setRealPart(Double_t realpart)
310  {
311  re_ = realpart;
312  }
313 
315 
318  inline void setImagPart(Double_t imagpart)
319  {
320  im_ = imagpart;
321  }
322 
324 
328  inline void setRealImagPart(Double_t realpart, Double_t imagpart)
329  {
330  this->setRealPart( realpart );
331  this->setImagPart( imagpart );
332  }
333 
335  inline void zero()
336  {
337  this->setRealImagPart(0.0,0.0);
338  }
339 
341  void print() const;
342 
343  private:
345  Double_t re_;
347  Double_t im_;
348 
349  ClassDef(LauComplex,0) // a non-persistent bare-bones complex class
350 };
351 
353 std::istream& operator>>(std::istream& os, LauComplex& z);
354 std::ostream& operator<<(std::ostream& os, const LauComplex& z);
355 
356 #endif
virtual ~LauComplex()
Destructor.
Definition: LauComplex.hh:75
LauComplex operator-() const
Unary minus operator.
Definition: LauComplex.hh:101
LauComplex(const LauComplex &other)
Copy constructor.
Definition: LauComplex.hh:81
LauComplex()
Default Constructor.
Definition: LauComplex.hh:65
LauComplex operator+(const LauComplex &other) const
Addition operator.
Definition: LauComplex.hh:111
Double_t re() const
Get the real part.
Definition: LauComplex.hh:219
LauComplex operator*=(const LauComplex &other)
Multiplication assignment operator.
Definition: LauComplex.hh:183
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:228
LauComplex operator+=(const LauComplex &other)
Addition assignment operator.
Definition: LauComplex.hh:159
LauComplex operator/(const LauComplex &other) const
Division operator.
Definition: LauComplex.hh:147
LauComplex(Double_t a, Double_t b)
Constructor.
Definition: LauComplex.hh:72
LauComplex exp() const
Obtain the exponential of the complex number.
Definition: LauComplex.hh:264
LauComplex operator-(const LauComplex &other) const
Subtraction operator.
Definition: LauComplex.hh:123
LauComplex conj() const
Obtain the complex conjugate.
Definition: LauComplex.hh:274
Double_t abs2() const
Obtain the square of the absolute value of the complex number.
Definition: LauComplex.hh:246
void setImagPart(Double_t imagpart)
Set the imaginary part.
Definition: LauComplex.hh:318
std::ostream & operator<<(std::ostream &os, const LauComplex &z)
Definition: LauComplex.cc:57
LauComplex operator-=(const LauComplex &other)
Subtraction assignment operator.
Definition: LauComplex.hh:171
LauComplex & operator=(const LauComplex &other)
Copy assignment operator.
Definition: LauComplex.hh:88
void setRealPart(Double_t realpart)
Set the real part.
Definition: LauComplex.hh:309
LauComplex operator/=(const LauComplex &other)
Division assignment operator.
Definition: LauComplex.hh:196
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
void zero()
Set both real and imaginary part to zero.
Definition: LauComplex.hh:335
LauComplex operator*(const LauComplex &other) const
Multiplication operator.
Definition: LauComplex.hh:135
Class for defining a complex number.
Definition: LauComplex.hh:61
Double_t arg() const
Obtain the phase angle of the complex number.
Definition: LauComplex.hh:255
Bool_t operator==(const LauComplex &other) const
Boolean comparison operator.
Definition: LauComplex.hh:210
std::istream & operator>>(std::istream &os, LauComplex &z)
input/output operator formatting of a complex number
Definition: LauComplex.cc:62
void print() const
Print the complex number.
Definition: LauComplex.cc:52
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:237
Double_t re_
The real part.
Definition: LauComplex.hh:345
Double_t im_
The imaginary part.
Definition: LauComplex.hh:347
LauComplex scale(Double_t scaleVal) const
Obtain the complex number scaled by some factor.
Definition: LauComplex.hh:290
void makeConj()
Transform this to its complex conjugate.
Definition: LauComplex.hh:280