39 for ( i = 0; i < dim; i++ )
41 for ( j = 0; j < dim; j++ ) { rho[i][j] = density.rho[i][j]; }
49 for ( i = 0; i < dim; i++ )
51 for ( j = 0; j < dim; j++ ) { rho[i][j] = density.rho[i][j]; }
61 for ( i = 0; i < dim; i++ )
delete[] rho[i];
73 if ( dim ==
n )
return;
77 for ( i = 0; i < dim; i++ )
delete[] rho[i];
86 for ( i = 0; i <
n; i++ ) { rho[i] =
new EvtComplex[
n]; }
92 assert( i < dim && j < dim );
97 assert( i < dim && j < dim );
105 for ( i = 0; i <
n; i++ )
107 for ( j = 0; j <
n; j++ ) { rho[i][j] =
EvtComplex( 0.0 ); }
120 report(
ERROR,
"EvtGen" ) <<
"Not matching dimensions in NormalizedProb" << endl;
124 for ( i = 0; i < dim; i++ )
126 norm +=
real( rho[i][i] );
127 for ( j = 0; j < dim; j++ ) { prob += rho[i][j] * d.rho[i][j]; }
130 if (
imag( prob ) > 0.00000001 *
real( prob ) )
131 {
report(
ERROR,
"EvtGen" ) <<
"Imaginary probability:" << prob <<
" " << norm << endl; }
132 if (
real( prob ) < 0.0 )
133 {
report(
ERROR,
"EvtGen" ) <<
"Negative probability:" << prob <<
" " << norm << endl; }
135 return real( prob ) / norm;
141 {
report(
ERROR,
"EvtGen" ) <<
"dim=" << dim <<
"in SpinDensity::Check" << endl; }
145 for ( i = 0; i < dim; i++ )
148 if (
real( rho[i][i] ) < 0.0 )
return 0;
149 if (
imag( rho[i][i] ) * 1000000.0 >
abs( rho[i][i] ) )
151 report(
INFO,
"EvtGen" ) <<
"Failing 1" << endl;
156 for ( i = 0; i < dim; i++ )
158 for ( j = i + 1; j < dim; j++ )
160 if ( fabs(
real( rho[i][j] - rho[j][i] ) ) >
161 0.00000001 * (
abs( rho[i][i] ) +
abs( rho[j][j] ) ) )
163 report(
INFO,
"EvtGen" ) <<
"Failing 2" << endl;
166 if ( fabs(
imag( rho[i][j] + rho[j][i] ) ) >
167 0.00000001 * (
abs( rho[i][i] ) +
abs( rho[j][j] ) ) )
169 report(
INFO,
"EvtGen" ) <<
"Failing 3" << endl;
183 s <<
"Dimension:" << d.dim << endl;
185 for ( i = 0; i < d.dim; i++ )
187 for ( j = 0; j < d.dim; j++ ) {
s << d.rho[i][j] <<
" "; }
double imag(const EvtComplex &c)
EvtComplex * EvtComplexPtr
ostream & report(Severity severity, const char *facility)
ostream & operator<<(ostream &s, const EvtSpinDensity &d)
double NormalizedProb(const EvtSpinDensity &d)
const EvtComplex & Get(int i, int j) const
void Set(int i, int j, const EvtComplex &rhoij)
EvtSpinDensity & operator=(const EvtSpinDensity &density)
EvtSpinDensity(const EvtSpinDensity &density)
virtual ~EvtSpinDensity()