laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
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 "Rtypes.h"
57 #include "TMath.h"
58 
59 #include <iosfwd>
60 
61 class LauComplex {
62 
63  public:
65  inline LauComplex() :
66  re_( 0.0 ),
67  im_( 0.0 )
68  {
69  }
70 
72 
76  inline LauComplex( Double_t a, Double_t b ) :
77  re_( a ),
78  im_( b )
79  {
80  }
81 
83  virtual ~LauComplex() {}
84 
86 
89  inline LauComplex( const LauComplex& other ) :
90  re_( other.re_ ),
91  im_( other.im_ )
92  {
93  }
94 
96 
100  inline LauComplex& operator=( const LauComplex& other )
101  {
102  if ( &other != this ) {
103  re_ = other.re_;
104  im_ = other.im_;
105  }
106  return *this;
107  }
108 
110 
113  inline LauComplex operator-() const { return LauComplex( -re_, -im_ ); }
114 
116 
120  inline LauComplex operator+( const LauComplex& other ) const
121  {
122  LauComplex tmpCmplx( *this );
123  tmpCmplx += other;
124  return tmpCmplx;
125  }
126 
128 
132  inline LauComplex operator-( const LauComplex& other ) const
133  {
134  LauComplex tmpCmplx( *this );
135  tmpCmplx -= other;
136  return tmpCmplx;
137  }
138 
140 
144  inline LauComplex operator*( const LauComplex& other ) const
145  {
146  LauComplex tmpCmplx( *this );
147  tmpCmplx *= other;
148  return tmpCmplx;
149  }
150 
152 
156  inline LauComplex operator/( const LauComplex& other ) const
157  {
158  LauComplex tmpCmplx( *this );
159  tmpCmplx /= other;
160  return tmpCmplx;
161  }
162 
164 
168  inline LauComplex operator+=( const LauComplex& other )
169  {
170  this->re_ += other.re_;
171  this->im_ += other.im_;
172  return ( *this );
173  }
174 
176 
180  inline LauComplex operator-=( const LauComplex& other )
181  {
182  this->re_ -= other.re_;
183  this->im_ -= other.im_;
184  return ( *this );
185  }
186 
188 
192  inline LauComplex operator*=( const LauComplex& other )
193  {
194  Double_t realPart = this->re_ * other.re_ - this->im_ * other.im_;
195  Double_t imagPart = this->re_ * other.im_ + this->im_ * other.re_;
196  this->setRealImagPart( realPart, imagPart );
197  return ( *this );
198  }
199 
201 
205  inline LauComplex operator/=( const LauComplex& other )
206  {
207  Double_t x( other.abs2() );
208  Double_t realPart = ( this->re_ * other.re_ + this->im_ * other.im_ ) / x;
209  Double_t imagPart = ( this->im_ * other.re_ - this->re_ * other.im_ ) / x;
210  this->setRealImagPart( realPart, imagPart );
211  return ( *this );
212  }
213 
215 
219  inline Bool_t operator==( const LauComplex& other ) const
220  {
221  return ( re_ == other.re_ && im_ == other.im_ );
222  }
223 
225 
228  inline Double_t re() const { return re_; }
229 
231 
234  inline Double_t im() const { return im_; }
235 
237 
240  inline Double_t abs() const { return TMath::Sqrt( this->abs2() ); }
241 
243 
246  inline Double_t abs2() const { return re_ * re_ + im_ * im_; }
247 
249 
252  inline Double_t arg() const { return TMath::ATan2( im_, re_ ); }
253 
255 
258  inline LauComplex exp() const
259  {
260  Double_t mag( TMath::Exp( re_ ) );
261  return LauComplex( mag * TMath::Cos( im_ ), mag * TMath::Sin( im_ ) );
262  }
263 
265 
268  inline LauComplex conj() const { return LauComplex( re_, -im_ ); }
269 
271  inline void makeConj() { im_ = -im_; }
272 
274 
278  inline LauComplex scale( Double_t scaleVal ) const
279  {
280  return LauComplex( scaleVal * re_, scaleVal * im_ );
281  }
282 
284 
287  inline void rescale( Double_t scaleVal )
288  {
289  re_ *= scaleVal;
290  im_ *= scaleVal;
291  }
292 
294 
297  inline void setRealPart( Double_t realpart ) { re_ = realpart; }
298 
300 
303  inline void setImagPart( Double_t imagpart ) { im_ = imagpart; }
304 
306 
310  inline void setRealImagPart( Double_t realpart, Double_t imagpart )
311  {
312  this->setRealPart( realpart );
313  this->setImagPart( imagpart );
314  }
315 
317  inline void zero() { this->setRealImagPart( 0.0, 0.0 ); }
318 
320  void print() const;
321 
322  private:
324  Double_t re_;
326  Double_t im_;
327 
328  ClassDef( LauComplex, 0 ) // a non-persistent bare-bones complex class
329 };
330 
332 std::istream& operator>>( std::istream& os, LauComplex& z );
334 std::ostream& operator<<( std::ostream& os, const LauComplex& z );
335 
336 #endif
LauComplex operator+(const LauComplex &other) const
Addition operator.
Definition: LauComplex.hh:134
LauComplex & operator=(const LauComplex &other)
Copy assignment operator.
Definition: LauComplex.hh:114
void setRealPart(Double_t realpart)
Set the real part.
Definition: LauComplex.hh:311
LauComplex operator/=(const LauComplex &other)
Division assignment operator.
Definition: LauComplex.hh:219
LauComplex scale(Double_t scaleVal) const
Obtain the complex number scaled by some factor.
Definition: LauComplex.hh:292
LauComplex conj() const
Obtain the complex conjugate.
Definition: LauComplex.hh:282
LauComplex operator/(const LauComplex &other) const
Division operator.
Definition: LauComplex.hh:170
virtual ~LauComplex()
Destructor.
Definition: LauComplex.hh:97
Double_t re_
The real part.
Definition: LauComplex.hh:338
Bool_t operator==(const LauComplex &other) const
Boolean comparison operator.
Definition: LauComplex.hh:233
void zero()
Set both real and imaginary part to zero.
Definition: LauComplex.hh:331
Class for defining a complex number.
Definition: LauComplex.hh:61
LauComplex()
Default Constructor.
Definition: LauComplex.hh:79
void print() const
Print the complex number.
Definition: LauComplex.cc:49
void rescale(Double_t scaleVal)
Scale this by a factor.
Definition: LauComplex.hh:301
void setRealImagPart(Double_t realpart, Double_t imagpart)
Set both real and imaginary part.
Definition: LauComplex.hh:324
Double_t abs() const
Obtain the absolute value of the complex number.
Definition: LauComplex.hh:254
LauComplex exp() const
Obtain the exponential of the complex number.
Definition: LauComplex.hh:272
std::ostream & operator<<(std::ostream &os, const LauComplex &z)
output operator formatting of a complex number
Definition: LauComplex.cc:54
Double_t abs2() const
Obtain the square of the absolute value of the complex number.
Definition: LauComplex.hh:260
Double_t re() const
Get the real part.
Definition: LauComplex.hh:242
Double_t im_
The imaginary part.
Definition: LauComplex.hh:340
std::istream & operator>>(std::istream &os, LauComplex &z)
input operator formatting of a complex number
Definition: LauComplex.cc:59
LauComplex operator-() const
Unary minus operator.
Definition: LauComplex.hh:127
void makeConj()
Transform this to its complex conjugate.
Definition: LauComplex.hh:285
Double_t arg() const
Obtain the phase angle of the complex number.
Definition: LauComplex.hh:266
LauComplex operator*=(const LauComplex &other)
Multiplication assignment operator.
Definition: LauComplex.hh:206
Double_t im() const
Get the imaginary part.
Definition: LauComplex.hh:248
void setImagPart(Double_t imagpart)
Set the imaginary part.
Definition: LauComplex.hh:317
LauComplex operator+=(const LauComplex &other)
Addition assignment operator.
Definition: LauComplex.hh:182
LauComplex operator*(const LauComplex &other) const
Multiplication operator.
Definition: LauComplex.hh:158
LauComplex operator-=(const LauComplex &other)
Subtraction assignment operator.
Definition: LauComplex.hh:194