EvtGen 2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Loading...
Searching...
No Matches
EvtComplex.hh
Go to the documentation of this file.
1
2/***********************************************************************
3* Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4* *
5* This file is part of EvtGen. *
6* *
7* EvtGen is free software: you can redistribute it and/or modify *
8* it under the terms of the GNU General Public License as published by *
9* the Free Software Foundation, either version 3 of the License, or *
10* (at your option) any later version. *
11* *
12* EvtGen is distributed in the hope that it will be useful, *
13* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15* GNU General Public License for more details. *
16* *
17* You should have received a copy of the GNU General Public License *
18* along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19***********************************************************************/
20
21#ifndef EVTCOMPLEX_HH
22#define EVTCOMPLEX_HH
23
25
26#include <iostream>
27#include <math.h>
28
30 inline friend EvtComplex operator*( double d, const EvtComplex& c );
31 inline friend EvtComplex operator*( const EvtComplex& c, double d );
32 inline friend EvtComplex operator/( const EvtComplex& c, double d );
33 inline friend EvtComplex operator/( double d, const EvtComplex& c );
34 inline friend EvtComplex operator*( const EvtComplex& c1,
35 const EvtComplex& c2 );
36 inline friend EvtComplex operator/( const EvtComplex& c1,
37 const EvtComplex& c2 );
38 inline friend EvtComplex operator+( const EvtComplex& c1,
39 const EvtComplex& c2 );
40 inline friend EvtComplex operator-( const EvtComplex& c1,
41 const EvtComplex& c2 );
42 inline friend EvtComplex operator-( const EvtComplex& c );
43 inline friend EvtComplex conj( const EvtComplex& c );
44 inline friend double abs( const EvtComplex& c );
45 inline friend double abs2( const EvtComplex& c );
46 inline friend double arg( const EvtComplex& c );
47 inline friend double real( const EvtComplex& c );
48 inline friend double imag( const EvtComplex& c );
49 inline friend EvtComplex exp( const EvtComplex& c );
50 friend std::ostream& operator<<( std::ostream& s, const EvtComplex& c );
51
52 public:
53 EvtComplex() : m_rpart( 0.0 ), m_ipart( 0.0 ) {}
54 EvtComplex( double rpart, double ipart = 0.0 ) :
55 m_rpart( rpart ), m_ipart( ipart )
56 {
57 }
58 EvtComplex( const EvtComplex& c ) :
60 {
61 }
62 inline EvtComplex& operator*=( double d );
63 inline EvtComplex& operator/=( double d );
66 inline EvtComplex& operator=( const EvtComplex& c );
67 inline EvtComplex& operator+=( const EvtComplex& c );
68 inline EvtComplex& operator-=( const EvtComplex& c );
69 inline EvtComplex& operator+=( double d );
70 inline EvtComplex& operator-=( double d );
71 inline int operator==( const EvtComplex c );
72 inline int operator!=( const EvtComplex c );
73
74 private:
76};
77
81
83{
84 m_rpart = c.m_rpart;
85 m_ipart = c.m_ipart;
86
87 return *this;
88}
89
91{
92 m_rpart += c.m_rpart;
93 m_ipart += c.m_ipart;
94
95 return *this;
96}
97
99{
100 m_rpart -= c.m_rpart;
101 m_ipart -= c.m_ipart;
102
103 return *this;
104}
105
107{
108 m_rpart += d;
109
110 return *this;
111}
112
114{
115 m_rpart -= d;
116
117 return *this;
118}
119
120EvtComplex operator*( double d, const EvtComplex& c )
121{
122 return EvtComplex( c.m_rpart * d, c.m_ipart * d );
123}
124
125EvtComplex operator*( const EvtComplex& c, double d )
126{
127 return EvtComplex( c.m_rpart * d, c.m_ipart * d );
128}
129
130EvtComplex operator/( const EvtComplex& c, double d )
131{
132 return EvtComplex( c.m_rpart / d, c.m_ipart / d );
133}
134
136{
137 m_rpart *= d;
138 m_ipart *= d;
139
140 return *this;
141}
142
144{
145 m_rpart /= d;
146 m_ipart /= d;
147
148 return *this;
149}
150
151EvtComplex operator/( double d, const EvtComplex& c )
152{
153 double Num = d / ( c.m_rpart * c.m_rpart + c.m_ipart * c.m_ipart );
154
155 return EvtComplex( Num * c.m_rpart, -Num * c.m_ipart );
156}
157
159{
160 double inv = 1.0 / ( c2.m_rpart * c2.m_rpart + c2.m_ipart * c2.m_ipart );
161
162 return EvtComplex(
163 inv * ( c1.m_rpart * c2.m_rpart + c1.m_ipart * c2.m_ipart ),
164 inv * ( c1.m_ipart * c2.m_rpart - c1.m_rpart * c2.m_ipart ) );
165}
166
168{
169 return EvtComplex( c1.m_rpart * c2.m_rpart - c1.m_ipart * c2.m_ipart,
170 c1.m_rpart * c2.m_ipart + c1.m_ipart * c2.m_rpart );
171}
172
174{
175 return EvtComplex( c1.m_rpart - c2.m_rpart, c1.m_ipart - c2.m_ipart );
176}
177
179{
180 return EvtComplex( c1.m_rpart + c2.m_rpart, c1.m_ipart + c2.m_ipart );
181}
182
184{
185 return m_rpart == c.m_rpart && m_ipart == c.m_ipart;
186}
187
189{
190 return m_rpart != c.m_rpart || m_ipart != c.m_ipart;
191}
192
194{
195 return EvtComplex( -c.m_rpart, -c.m_ipart );
196}
197
199{
200 return EvtComplex( c.m_rpart, -c.m_ipart );
201}
202
203double abs( const EvtComplex& c )
204{
205 double c2 = c.m_rpart * c.m_rpart + c.m_ipart * c.m_ipart;
206 if ( c2 <= 0.0 )
207 return 0.0;
208 return sqrt( c2 );
209}
210
211double abs2( const EvtComplex& c )
212{
213 return c.m_rpart * c.m_rpart + c.m_ipart * c.m_ipart;
214}
215
216double arg( const EvtComplex& c )
217{
218 if ( ( c.m_rpart == 0 ) && ( c.m_ipart == 0 ) ) {
219 return 0.0;
220 }
221 if ( c.m_rpart == 0 ) {
222 if ( c.m_ipart > 0 ) {
223 return EvtConst::pi / 2;
224 } else {
225 return -EvtConst::pi / 2;
226 }
227 } else {
228 return atan2( c.m_ipart, c.m_rpart );
229 }
230}
231
232double real( const EvtComplex& c )
233{
234 return c.m_rpart;
235}
236
237double imag( const EvtComplex& c )
238{
239 return c.m_ipart;
240}
241
243{
244 return exp( c.m_rpart ) * EvtComplex( cos( c.m_ipart ), sin( c.m_ipart ) );
245}
246
247#endif
EvtComplex conj(const EvtComplex &c)
double imag(const EvtComplex &c)
EvtComplexPtrPtr * EvtComplexPtrPtrPtr
Definition EvtComplex.hh:80
double real(const EvtComplex &c)
double abs2(const EvtComplex &c)
EvtComplex exp(const EvtComplex &c)
EvtComplex operator/(const EvtComplex &c, double d)
EvtComplex * EvtComplexPtr
Definition EvtComplex.hh:78
EvtComplex operator*(double d, const EvtComplex &c)
EvtComplex operator-(const EvtComplex &c1, const EvtComplex &c2)
double arg(const EvtComplex &c)
EvtComplex operator+(const EvtComplex &c1, const EvtComplex &c2)
double abs(const EvtComplex &c)
EvtComplexPtr * EvtComplexPtrPtr
Definition EvtComplex.hh:79
EvtComplex & operator+=(const EvtComplex &c)
Definition EvtComplex.hh:90
friend EvtComplex conj(const EvtComplex &c)
friend double imag(const EvtComplex &c)
friend std::ostream & operator<<(std::ostream &s, const EvtComplex &c)
EvtComplex & operator=(const EvtComplex &c)
Definition EvtComplex.hh:82
friend double real(const EvtComplex &c)
friend double abs2(const EvtComplex &c)
EvtComplex(const EvtComplex &c)
Definition EvtComplex.hh:58
friend EvtComplex exp(const EvtComplex &c)
EvtComplex & operator*=(double d)
friend EvtComplex operator/(const EvtComplex &c, double d)
double m_rpart
Definition EvtComplex.hh:75
int operator!=(const EvtComplex c)
EvtComplex(double rpart, double ipart=0.0)
Definition EvtComplex.hh:54
double m_ipart
Definition EvtComplex.hh:75
friend EvtComplex operator*(double d, const EvtComplex &c)
EvtComplex & operator-=(const EvtComplex &c)
Definition EvtComplex.hh:98
EvtComplex & operator/=(double d)
friend EvtComplex operator-(const EvtComplex &c1, const EvtComplex &c2)
friend double arg(const EvtComplex &c)
friend EvtComplex operator+(const EvtComplex &c1, const EvtComplex &c2)
int operator==(const EvtComplex c)
friend double abs(const EvtComplex &c)
static const double pi
Definition EvtConst.hh:26