BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtSpinDensity.cc
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2//
3// Environment:
4// This software is part of the EvtGen package developed jointly
5// for the BaBar and CLEO collaborations. If you use all or part
6// of it, please give an appropriate acknowledgement.
7//
8// Copyright Information: See EvtGen/COPYRIGHT
9// Copyright (C) 1998 Caltech, UCSB
10//
11// Module: EvtSpinDensity.cc
12//
13// Description: Class to reperesent spindensity matrices.
14//
15// Modification history:
16//
17// RYD May 29,1997 Module created
18//
19//------------------------------------------------------------------------
20//
21#include "EvtSpinDensity.hh"
22#include "EvtComplex.hh"
23#include "EvtPatches.hh"
24#include "EvtReport.hh"
25#include <assert.h>
26#include <iostream>
27#include <math.h>
28#include <stdlib.h>
29using std::endl;
30using std::ostream;
31
33 dim = 0;
34 rho = 0;
35
36 int i, j;
37 SetDim( density.dim );
38
39 for ( i = 0; i < dim; i++ )
40 {
41 for ( j = 0; j < dim; j++ ) { rho[i][j] = density.rho[i][j]; }
42 }
43}
44
46 int i, j;
47 SetDim( density.dim );
48
49 for ( i = 0; i < dim; i++ )
50 {
51 for ( j = 0; j < dim; j++ ) { rho[i][j] = density.rho[i][j]; }
52 }
53
54 return *this;
55}
56
58 if ( dim != 0 )
59 {
60 int i;
61 for ( i = 0; i < dim; i++ ) delete[] rho[i];
62 }
63
64 delete[] rho;
65}
66
68 dim = 0;
69 rho = 0;
70}
71
73 if ( dim == n ) return;
74 if ( dim != 0 )
75 {
76 int i;
77 for ( i = 0; i < dim; i++ ) delete[] rho[i];
78 delete[] rho;
79 rho = 0;
80 dim = 0;
81 }
82 if ( n == 0 ) return;
83 dim = n;
84 rho = new EvtComplexPtr[n];
85 int i;
86 for ( i = 0; i < n; i++ ) { rho[i] = new EvtComplex[n]; }
87}
88
89int EvtSpinDensity::GetDim() const { return dim; }
90
91void EvtSpinDensity::Set( int i, int j, const EvtComplex& rhoij ) {
92 assert( i < dim && j < dim );
93 rho[i][j] = rhoij;
94}
95
96const EvtComplex& EvtSpinDensity::Get( int i, int j ) const {
97 assert( i < dim && j < dim );
98 return rho[i][j];
99}
100
102 SetDim( n );
103 int i, j;
104
105 for ( i = 0; i < n; i++ )
106 {
107 for ( j = 0; j < n; j++ ) { rho[i][j] = EvtComplex( 0.0 ); }
108 rho[i][i] = EvtComplex( 1.0 );
109 }
110}
111
113
114 int i, j;
115 EvtComplex prob( 0.0, 0.0 );
116 double norm = 0.0;
117
118 if ( dim != d.dim )
119 {
120 report( ERROR, "EvtGen" ) << "Not matching dimensions in NormalizedProb" << endl;
121 ::abort();
122 }
123
124 for ( i = 0; i < dim; i++ )
125 {
126 norm += real( rho[i][i] );
127 for ( j = 0; j < dim; j++ ) { prob += rho[i][j] * d.rho[i][j]; }
128 }
129
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; }
134
135 return real( prob ) / norm;
136}
137
139
140 if ( dim < 1 )
141 { report( ERROR, "EvtGen" ) << "dim=" << dim << "in SpinDensity::Check" << endl; }
142
143 int i, j;
144
145 for ( i = 0; i < dim; i++ )
146 {
147
148 if ( real( rho[i][i] ) < 0.0 ) return 0;
149 if ( imag( rho[i][i] ) * 1000000.0 > abs( rho[i][i] ) )
150 {
151 report( INFO, "EvtGen" ) << "Failing 1" << endl;
152 return 0;
153 }
154 }
155
156 for ( i = 0; i < dim; i++ )
157 {
158 for ( j = i + 1; j < dim; j++ )
159 {
160 if ( fabs( real( rho[i][j] - rho[j][i] ) ) >
161 0.00000001 * ( abs( rho[i][i] ) + abs( rho[j][j] ) ) )
162 {
163 report( INFO, "EvtGen" ) << "Failing 2" << endl;
164 return 0;
165 }
166 if ( fabs( imag( rho[i][j] + rho[j][i] ) ) >
167 0.00000001 * ( abs( rho[i][i] ) + abs( rho[j][j] ) ) )
168 {
169 report( INFO, "EvtGen" ) << "Failing 3" << endl;
170 return 0;
171 }
172 }
173 }
174
175 return 1;
176}
177
178ostream& operator<<( ostream& s, const EvtSpinDensity& d ) {
179
180 int i, j;
181
182 s << endl;
183 s << "Dimension:" << d.dim << endl;
184
185 for ( i = 0; i < d.dim; i++ )
186 {
187 for ( j = 0; j < d.dim; j++ ) { s << d.rho[i][j] << " "; }
188 s << endl;
189 }
190
191 return s;
192}
const Int_t n
double imag(const EvtComplex &c)
EvtComplex * EvtComplexPtr
Definition EvtComplex.hh:68
ostream & report(Severity severity, const char *facility)
Definition EvtReport.cc:34
@ ERROR
Definition EvtReport.hh:49
@ INFO
Definition EvtReport.hh:52
ostream & operator<<(ostream &s, const EvtSpinDensity &d)
XmlRpcServer s
double NormalizedProb(const EvtSpinDensity &d)
int GetDim() const
void SetDiag(int n)
const EvtComplex & Get(int i, int j) const
void Set(int i, int j, const EvtComplex &rhoij)
EvtSpinDensity & operator=(const EvtSpinDensity &density)
void SetDim(int n)
EvtSpinDensity(const EvtSpinDensity &density)
virtual ~EvtSpinDensity()