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
src
EvtGenBase
EvtSpinDensity.cpp
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
#include "
EvtGenBase/EvtSpinDensity.hh
"
22
23
#include "
EvtGenBase/EvtComplex.hh
"
24
#include "
EvtGenBase/EvtReport.hh
"
25
26
#include <assert.h>
27
#include <iostream>
28
#include <math.h>
29
#include <stdlib.h>
30
using
std::endl;
31
using
std::ostream;
32
33
EvtSpinDensity::EvtSpinDensity
(
const
EvtSpinDensity
& density )
34
{
35
m_dim
= 0;
36
m_rho
=
nullptr
;
37
38
int
i, j;
39
setDim
( density.
m_dim
);
40
41
for
( i = 0; i <
m_dim
; i++ ) {
42
for
( j = 0; j <
m_dim
; j++ ) {
43
m_rho
[i][j] = density.
m_rho
[i][j];
44
}
45
}
46
}
47
48
EvtSpinDensity
&
EvtSpinDensity::operator=
(
const
EvtSpinDensity
& density )
49
{
50
int
i, j;
51
setDim
( density.
m_dim
);
52
53
for
( i = 0; i <
m_dim
; i++ ) {
54
for
( j = 0; j <
m_dim
; j++ ) {
55
m_rho
[i][j] = density.
m_rho
[i][j];
56
}
57
}
58
59
return
*
this
;
60
}
61
62
EvtSpinDensity::~EvtSpinDensity
()
63
{
64
if
(
m_dim
!= 0 ) {
65
int
i;
66
for
( i = 0; i <
m_dim
; i++ )
67
delete
[]
m_rho
[i];
68
}
69
70
delete
[]
m_rho
;
71
}
72
73
EvtSpinDensity::EvtSpinDensity
()
74
{
75
m_dim
= 0;
76
m_rho
=
nullptr
;
77
}
78
79
void
EvtSpinDensity::setDim
(
int
n )
80
{
81
if
(
m_dim
== n )
82
return
;
83
if
(
m_dim
!= 0 ) {
84
int
i;
85
for
( i = 0; i <
m_dim
; i++ )
86
delete
[]
m_rho
[i];
87
delete
[]
m_rho
;
88
m_rho
=
nullptr
;
89
m_dim
= 0;
90
}
91
if
( n == 0 )
92
return
;
93
m_dim
= n;
94
m_rho
=
new
EvtComplexPtr
[n];
95
int
i;
96
for
( i = 0; i < n; i++ ) {
97
m_rho
[i] =
new
EvtComplex
[n];
98
}
99
}
100
101
int
EvtSpinDensity::getDim
()
const
102
{
103
return
m_dim
;
104
}
105
106
void
EvtSpinDensity::set
(
int
i,
int
j,
const
EvtComplex
& rhoij )
107
{
108
assert( i <
m_dim
&& j <
m_dim
);
109
m_rho
[i][j] = rhoij;
110
}
111
112
const
EvtComplex
&
EvtSpinDensity::get
(
int
i,
int
j )
const
113
{
114
assert( i <
m_dim
&& j <
m_dim
);
115
return
m_rho
[i][j];
116
}
117
118
void
EvtSpinDensity::setDiag
(
int
n )
119
{
120
setDim
( n );
121
int
i, j;
122
123
for
( i = 0; i < n; i++ ) {
124
for
( j = 0; j < n; j++ ) {
125
m_rho
[i][j] =
EvtComplex
( 0.0 );
126
}
127
m_rho
[i][i] =
EvtComplex
( 1.0 );
128
}
129
}
130
131
double
EvtSpinDensity::normalizedProb
(
const
EvtSpinDensity
& d )
132
{
133
int
i, j;
134
EvtComplex
prob( 0.0, 0.0 );
135
double
norm = 0.0;
136
137
if
(
m_dim
!= d.
m_dim
) {
138
EvtGenReport
(
EVTGEN_ERROR
,
"EvtGen"
)
139
<<
"Not matching dimensions in NormalizedProb"
<< endl;
140
::abort();
141
}
142
143
for
( i = 0; i <
m_dim
; i++ ) {
144
norm +=
real
(
m_rho
[i][i] );
145
for
( j = 0; j <
m_dim
; j++ ) {
146
prob +=
m_rho
[i][j] * d.
m_rho
[i][j];
147
}
148
}
149
150
if
(
imag
( prob ) > 0.00000001 *
real
( prob ) ) {
151
EvtGenReport
(
EVTGEN_ERROR
,
"EvtGen"
)
152
<<
"Imaginary probability:"
<< prob <<
" "
<< norm << endl;
153
}
154
if
(
real
( prob ) < 0.0 ) {
155
EvtGenReport
(
EVTGEN_ERROR
,
"EvtGen"
)
156
<<
"Negative probability:"
<< prob <<
" "
<< norm << endl;
157
}
158
159
return
real
( prob ) / norm;
160
}
161
162
int
EvtSpinDensity::check
()
163
{
164
if
(
m_dim
< 1 ) {
165
EvtGenReport
(
EVTGEN_ERROR
,
"EvtGen"
)
166
<<
"dim="
<<
m_dim
<<
"in SpinDensity::Check"
<< endl;
167
}
168
169
int
i, j;
170
171
double
trace( 0.0 );
172
173
for
( i = 0; i <
m_dim
; i++ ) {
174
trace +=
abs
(
m_rho
[i][i] );
175
}
176
177
for
( i = 0; i <
m_dim
; i++ ) {
178
if
(
real
(
m_rho
[i][i] ) < 0.0 )
179
return
0;
180
if
(
imag
(
m_rho
[i][i] ) * 1000000.0 > trace ) {
181
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
) << *
this
<< endl;
182
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
) << trace << endl;
183
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
) <<
"Failing 1"
<< endl;
184
return
0;
185
}
186
}
187
188
for
( i = 0; i <
m_dim
; i++ ) {
189
for
( j = i + 1; j <
m_dim
; j++ ) {
190
if
( fabs(
real
(
m_rho
[i][j] -
m_rho
[j][i] ) ) >
191
0.00000001 * (
abs
(
m_rho
[i][i] ) +
abs
(
m_rho
[j][j] ) ) ) {
192
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
) <<
"Failing 2"
<< endl;
193
return
0;
194
}
195
if
( fabs(
imag
(
m_rho
[i][j] +
m_rho
[j][i] ) ) >
196
0.00000001 * (
abs
(
m_rho
[i][i] ) +
abs
(
m_rho
[j][j] ) ) ) {
197
EvtGenReport
(
EVTGEN_INFO
,
"EvtGen"
) <<
"Failing 3"
<< endl;
198
return
0;
199
}
200
}
201
}
202
203
return
1;
204
}
205
206
ostream&
operator<<
( ostream& s,
const
EvtSpinDensity
& d )
207
{
208
int
i, j;
209
210
s << endl;
211
s <<
"Dimension:"
<< d.
m_dim
<< endl;
212
213
for
( i = 0; i < d.
m_dim
; i++ ) {
214
for
( j = 0; j < d.
m_dim
; j++ ) {
215
s << d.
m_rho
[i][j] <<
" "
;
216
}
217
s << endl;
218
}
219
220
return
s;
221
}
EvtComplex.hh
imag
double imag(const EvtComplex &c)
Definition
EvtComplex.hh:237
real
double real(const EvtComplex &c)
Definition
EvtComplex.hh:232
EvtComplexPtr
EvtComplex * EvtComplexPtr
Definition
EvtComplex.hh:78
abs
double abs(const EvtComplex &c)
Definition
EvtComplex.hh:203
EvtReport.hh
EvtGenReport
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=nullptr)
Definition
EvtReport.cpp:32
EVTGEN_INFO
@ EVTGEN_INFO
Definition
EvtReport.hh:52
EVTGEN_ERROR
@ EVTGEN_ERROR
Definition
EvtReport.hh:49
operator<<
ostream & operator<<(ostream &s, const EvtSpinDensity &d)
Definition
EvtSpinDensity.cpp:206
EvtSpinDensity.hh
EvtComplex
Definition
EvtComplex.hh:29
EvtSpinDensity
Definition
EvtSpinDensity.hh:28
EvtSpinDensity::getDim
int getDim() const
Definition
EvtSpinDensity.cpp:101
EvtSpinDensity::setDim
void setDim(int n)
Definition
EvtSpinDensity.cpp:79
EvtSpinDensity::m_rho
EvtComplexPtrPtr m_rho
Definition
EvtSpinDensity.hh:46
EvtSpinDensity::EvtSpinDensity
EvtSpinDensity()
Definition
EvtSpinDensity.cpp:73
EvtSpinDensity::normalizedProb
double normalizedProb(const EvtSpinDensity &d)
Definition
EvtSpinDensity.cpp:131
EvtSpinDensity::operator=
EvtSpinDensity & operator=(const EvtSpinDensity &density)
Definition
EvtSpinDensity.cpp:48
EvtSpinDensity::setDiag
void setDiag(int n)
Definition
EvtSpinDensity.cpp:118
EvtSpinDensity::get
const EvtComplex & get(int i, int j) const
Definition
EvtSpinDensity.cpp:112
EvtSpinDensity::m_dim
int m_dim
Definition
EvtSpinDensity.hh:47
EvtSpinDensity::EvtSpinDensity
EvtSpinDensity(const EvtSpinDensity &density)
Definition
EvtSpinDensity.cpp:33
EvtSpinDensity::set
void set(int i, int j, const EvtComplex &rhoij)
Definition
EvtSpinDensity.cpp:106
EvtSpinDensity::check
int check()
Definition
EvtSpinDensity.cpp:162
EvtSpinDensity::~EvtSpinDensity
virtual ~EvtSpinDensity()
Definition
EvtSpinDensity.cpp:62
Generated by
1.17.0