EvtGen
2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Toggle main menu visibility
Loading...
Searching...
No Matches
EvtGenBase
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
24
#include "
EvtGenBase/EvtConst.hh
"
25
26
#include <iostream>
27
#include <math.h>
28
29
class
EvtComplex
{
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 ) :
59
m_rpart
( c.
m_rpart
),
m_ipart
( c.
m_ipart
)
60
{
61
}
62
inline
EvtComplex
&
operator*=
(
double
d );
63
inline
EvtComplex
&
operator/=
(
double
d );
64
EvtComplex
&
operator*=
(
EvtComplex
c );
65
EvtComplex
&
operator/=
(
EvtComplex
c );
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
:
75
double
m_rpart
,
m_ipart
;
76
};
77
78
typedef
EvtComplex
*
EvtComplexPtr
;
79
typedef
EvtComplexPtr
*
EvtComplexPtrPtr
;
80
typedef
EvtComplexPtrPtr
*
EvtComplexPtrPtrPtr
;
81
82
EvtComplex
&
EvtComplex::operator=
(
const
EvtComplex
& c )
83
{
84
m_rpart
= c.
m_rpart
;
85
m_ipart
= c.
m_ipart
;
86
87
return
*
this
;
88
}
89
90
EvtComplex
&
EvtComplex::operator+=
(
const
EvtComplex
& c )
91
{
92
m_rpart
+= c.
m_rpart
;
93
m_ipart
+= c.
m_ipart
;
94
95
return
*
this
;
96
}
97
98
EvtComplex
&
EvtComplex::operator-=
(
const
EvtComplex
& c )
99
{
100
m_rpart
-= c.
m_rpart
;
101
m_ipart
-= c.
m_ipart
;
102
103
return
*
this
;
104
}
105
106
EvtComplex
&
EvtComplex::operator+=
(
double
d )
107
{
108
m_rpart
+= d;
109
110
return
*
this
;
111
}
112
113
EvtComplex
&
EvtComplex::operator-=
(
double
d )
114
{
115
m_rpart
-= d;
116
117
return
*
this
;
118
}
119
120
EvtComplex
operator*
(
double
d,
const
EvtComplex
& c )
121
{
122
return
EvtComplex
( c.
m_rpart
* d, c.
m_ipart
* d );
123
}
124
125
EvtComplex
operator*
(
const
EvtComplex
& c,
double
d )
126
{
127
return
EvtComplex
( c.
m_rpart
* d, c.
m_ipart
* d );
128
}
129
130
EvtComplex
operator/
(
const
EvtComplex
& c,
double
d )
131
{
132
return
EvtComplex
( c.
m_rpart
/ d, c.
m_ipart
/ d );
133
}
134
135
EvtComplex
&
EvtComplex::operator*=
(
double
d )
136
{
137
m_rpart
*= d;
138
m_ipart
*= d;
139
140
return
*
this
;
141
}
142
143
EvtComplex
&
EvtComplex::operator/=
(
double
d )
144
{
145
m_rpart
/= d;
146
m_ipart
/= d;
147
148
return
*
this
;
149
}
150
151
EvtComplex
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
158
EvtComplex
operator/
(
const
EvtComplex
& c1,
const
EvtComplex
& c2 )
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
167
EvtComplex
operator*
(
const
EvtComplex
& c1,
const
EvtComplex
& c2 )
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
173
EvtComplex
operator-
(
const
EvtComplex
& c1,
const
EvtComplex
& c2 )
174
{
175
return
EvtComplex
( c1.
m_rpart
- c2.
m_rpart
, c1.
m_ipart
- c2.
m_ipart
);
176
}
177
178
EvtComplex
operator+
(
const
EvtComplex
& c1,
const
EvtComplex
& c2 )
179
{
180
return
EvtComplex
( c1.
m_rpart
+ c2.
m_rpart
, c1.
m_ipart
+ c2.
m_ipart
);
181
}
182
183
int
EvtComplex::operator==
(
const
EvtComplex
c )
184
{
185
return
m_rpart
== c.
m_rpart
&&
m_ipart
== c.
m_ipart
;
186
}
187
188
int
EvtComplex::operator!=
(
const
EvtComplex
c )
189
{
190
return
m_rpart
!= c.
m_rpart
||
m_ipart
!= c.
m_ipart
;
191
}
192
193
EvtComplex
operator-
(
const
EvtComplex
& c )
194
{
195
return
EvtComplex
( -c.
m_rpart
, -c.
m_ipart
);
196
}
197
198
EvtComplex
conj
(
const
EvtComplex
& c )
199
{
200
return
EvtComplex
( c.
m_rpart
, -c.
m_ipart
);
201
}
202
203
double
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
211
double
abs2
(
const
EvtComplex
& c )
212
{
213
return
c.
m_rpart
* c.
m_rpart
+ c.
m_ipart
* c.
m_ipart
;
214
}
215
216
double
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
232
double
real
(
const
EvtComplex
& c )
233
{
234
return
c.
m_rpart
;
235
}
236
237
double
imag
(
const
EvtComplex
& c )
238
{
239
return
c.
m_ipart
;
240
}
241
242
EvtComplex
exp
(
const
EvtComplex
& c )
243
{
244
return
exp
( c.
m_rpart
) *
EvtComplex
( cos( c.
m_ipart
), sin( c.
m_ipart
) );
245
}
246
247
#endif
conj
EvtComplex conj(const EvtComplex &c)
Definition
EvtComplex.hh:198
imag
double imag(const EvtComplex &c)
Definition
EvtComplex.hh:237
EvtComplexPtrPtrPtr
EvtComplexPtrPtr * EvtComplexPtrPtrPtr
Definition
EvtComplex.hh:80
real
double real(const EvtComplex &c)
Definition
EvtComplex.hh:232
abs2
double abs2(const EvtComplex &c)
Definition
EvtComplex.hh:211
exp
EvtComplex exp(const EvtComplex &c)
Definition
EvtComplex.hh:242
operator/
EvtComplex operator/(const EvtComplex &c, double d)
Definition
EvtComplex.hh:130
EvtComplexPtr
EvtComplex * EvtComplexPtr
Definition
EvtComplex.hh:78
operator*
EvtComplex operator*(double d, const EvtComplex &c)
Definition
EvtComplex.hh:120
operator-
EvtComplex operator-(const EvtComplex &c1, const EvtComplex &c2)
Definition
EvtComplex.hh:173
arg
double arg(const EvtComplex &c)
Definition
EvtComplex.hh:216
operator+
EvtComplex operator+(const EvtComplex &c1, const EvtComplex &c2)
Definition
EvtComplex.hh:178
abs
double abs(const EvtComplex &c)
Definition
EvtComplex.hh:203
EvtComplexPtrPtr
EvtComplexPtr * EvtComplexPtrPtr
Definition
EvtComplex.hh:79
EvtConst.hh
EvtComplex
Definition
EvtComplex.hh:29
EvtComplex::operator+=
EvtComplex & operator+=(const EvtComplex &c)
Definition
EvtComplex.hh:90
EvtComplex::conj
friend EvtComplex conj(const EvtComplex &c)
Definition
EvtComplex.hh:198
EvtComplex::imag
friend double imag(const EvtComplex &c)
Definition
EvtComplex.hh:237
EvtComplex::operator<<
friend std::ostream & operator<<(std::ostream &s, const EvtComplex &c)
EvtComplex::EvtComplex
EvtComplex()
Definition
EvtComplex.hh:53
EvtComplex::operator=
EvtComplex & operator=(const EvtComplex &c)
Definition
EvtComplex.hh:82
EvtComplex::real
friend double real(const EvtComplex &c)
Definition
EvtComplex.hh:232
EvtComplex::abs2
friend double abs2(const EvtComplex &c)
Definition
EvtComplex.hh:211
EvtComplex::EvtComplex
EvtComplex(const EvtComplex &c)
Definition
EvtComplex.hh:58
EvtComplex::exp
friend EvtComplex exp(const EvtComplex &c)
Definition
EvtComplex.hh:242
EvtComplex::operator*=
EvtComplex & operator*=(double d)
Definition
EvtComplex.hh:135
EvtComplex::operator/
friend EvtComplex operator/(const EvtComplex &c, double d)
Definition
EvtComplex.hh:130
EvtComplex::m_rpart
double m_rpart
Definition
EvtComplex.hh:75
EvtComplex::operator!=
int operator!=(const EvtComplex c)
Definition
EvtComplex.hh:188
EvtComplex::EvtComplex
EvtComplex(double rpart, double ipart=0.0)
Definition
EvtComplex.hh:54
EvtComplex::m_ipart
double m_ipart
Definition
EvtComplex.hh:75
EvtComplex::operator*
friend EvtComplex operator*(double d, const EvtComplex &c)
Definition
EvtComplex.hh:120
EvtComplex::operator-=
EvtComplex & operator-=(const EvtComplex &c)
Definition
EvtComplex.hh:98
EvtComplex::operator/=
EvtComplex & operator/=(double d)
Definition
EvtComplex.hh:143
EvtComplex::operator-
friend EvtComplex operator-(const EvtComplex &c1, const EvtComplex &c2)
Definition
EvtComplex.hh:173
EvtComplex::arg
friend double arg(const EvtComplex &c)
Definition
EvtComplex.hh:216
EvtComplex::operator+
friend EvtComplex operator+(const EvtComplex &c1, const EvtComplex &c2)
Definition
EvtComplex.hh:178
EvtComplex::operator==
int operator==(const EvtComplex c)
Definition
EvtComplex.hh:183
EvtComplex::abs
friend double abs(const EvtComplex &c)
Definition
EvtComplex.hh:203
EvtConst::pi
static const double pi
Definition
EvtConst.hh:26
Generated by
1.17.0