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
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
22
25
26#include <assert.h>
27#include <iostream>
28#include <math.h>
29#include <stdlib.h>
30using std::endl;
31using std::ostream;
32
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
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
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
74{
75 m_dim = 0;
76 m_rho = nullptr;
77}
78
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
102{
103 return m_dim;
104}
105
106void 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
112const 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
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
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
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
206ostream& 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}
double imag(const EvtComplex &c)
double real(const EvtComplex &c)
EvtComplex * EvtComplexPtr
Definition EvtComplex.hh:78
double abs(const EvtComplex &c)
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=nullptr)
Definition EvtReport.cpp:32
@ EVTGEN_INFO
Definition EvtReport.hh:52
@ EVTGEN_ERROR
Definition EvtReport.hh:49
ostream & operator<<(ostream &s, const EvtSpinDensity &d)
void setDim(int n)
EvtComplexPtrPtr m_rho
double normalizedProb(const EvtSpinDensity &d)
EvtSpinDensity & operator=(const EvtSpinDensity &density)
void setDiag(int n)
const EvtComplex & get(int i, int j) const
EvtSpinDensity(const EvtSpinDensity &density)
void set(int i, int j, const EvtComplex &rhoij)
virtual ~EvtSpinDensity()