CGEM BOSS 6.6.5.g
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//
22#include <stdlib.h>
23#include <iostream>
24#include <math.h>
25#include <assert.h>
29using std::endl;
30using std::ostream;
31
32
34 dim=0;
35 rho=0;
36
37 int i,j;
38 SetDim(density.dim);
39
40 for(i=0;i<dim;i++){
41 for(j=0;j<dim;j++){
42 rho[i][j]=density.rho[i][j];
43 }
44 }
45}
46
48 int i,j;
49 SetDim(density.dim);
50
51 for(i=0;i<dim;i++){
52 for(j=0;j<dim;j++){
53 rho[i][j]=density.rho[i][j];
54 }
55 }
56
57 return *this;
58
59}
60
62 if (dim!=0){
63 int i;
64 for(i=0;i<dim;i++) delete [] rho[i];
65 }
66
67 delete [] rho;
68}
69
71 dim=0;
72 rho=0;
73}
74
76 if (dim==n) return;
77 if (dim!=0){
78 int i;
79 for(i=0;i<dim;i++) delete [] rho[i];
80 delete [] rho;
81 rho=0;
82 dim=0;
83 }
84 if (n==0) return;
85 dim=n;
86 rho=new EvtComplexPtr[n];
87 int i;
88 for(i=0;i<n;i++){
89 rho[i]=new EvtComplex[n];
90 }
91
92
93}
94
96 return dim;
97}
98
99void EvtSpinDensity::Set(int i,int j,const EvtComplex& rhoij){
100 assert(i<dim&&j<dim);
101 rho[i][j]=rhoij;
102}
103
104const EvtComplex& EvtSpinDensity::Get(int i,int j)const{
105 assert(i<dim&&j<dim);
106 return rho[i][j];
107}
108
110 SetDim(n);
111 int i,j;
112
113 for(i=0;i<n;i++){
114 for(j=0;j<n;j++){
115 rho[i][j]=EvtComplex(0.0);
116 }
117 rho[i][i]=EvtComplex(1.0);
118 }
119}
120
122
123 int i,j;
124 EvtComplex prob(0.0,0.0);
125 double norm=0.0;
126
127 if (dim!=d.dim) {
128 report(ERROR,"EvtGen")<<"Not matching dimensions in NormalizedProb"<<endl;
129 ::abort();
130 }
131
132 for(i=0;i<dim;i++){
133 norm+=real(rho[i][i]);
134 for(j=0;j<dim;j++){
135 prob+=rho[i][j]*d.rho[i][j];
136 }
137 }
138
139 if (imag(prob)>0.00000001*real(prob)) {
140 report(ERROR,"EvtGen")<<"Imaginary probability:"<<prob<<" "<<norm<<endl;
141 }
142 if (real(prob)<0.0) {
143 report(ERROR,"EvtGen")<<"Negative probability:"<<prob<<" "<<norm<<endl;
144 }
145
146 return real(prob)/norm;
147
148}
149
151
152 if (dim<1) {
153 report(ERROR,"EvtGen")<<"dim="<<dim<<"in SpinDensity::Check"<<endl;
154 }
155
156 int i,j;
157
158 for(i=0;i<dim;i++){
159
160 if (real(rho[i][i])<0.0) return 0;
161 if (imag(rho[i][i])*1000000.0>abs(rho[i][i])) {
162 report(INFO,"EvtGen") << "Failing 1"<<endl;
163 return 0;
164 }
165 }
166
167 for(i=0;i<dim;i++){
168 for(j=i+1;j<dim;j++){
169 if (fabs(real(rho[i][j]-rho[j][i]))>
170 0.00000001*(abs(rho[i][i])+abs(rho[j][j]))) {
171 report(INFO,"EvtGen") << "Failing 2"<<endl;
172 return 0;
173 }
174 if (fabs(imag(rho[i][j]+rho[j][i]))>
175 0.00000001*(abs(rho[i][i])+abs(rho[j][j]))) {
176 report(INFO,"EvtGen") << "Failing 3"<<endl;
177 return 0;
178 }
179 }
180 }
181
182 return 1;
183}
184
185ostream& operator<<(ostream& s,const EvtSpinDensity& d){
186
187 int i,j;
188
189 s << endl;
190 s << "Dimension:"<<d.dim<<endl;
191
192 for (i=0;i<d.dim;i++){
193 for (j=0;j<d.dim;j++){
194 s << d.rho[i][j]<<" ";
195 }
196 s <<endl;
197 }
198
199 return s;
200
201}
202
203
204
const Int_t n
double imag(const EvtComplex &c)
Definition: EvtComplex.hh:246
double real(const EvtComplex &c)
Definition: EvtComplex.hh:240
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
ostream & report(Severity severity, const char *facility)
Definition: EvtReport.cc:36
@ ERROR
Definition: EvtReport.hh:49
@ INFO
Definition: EvtReport.hh:52
ostream & operator<<(ostream &s, const EvtSpinDensity &d)
XmlRpcServer s
Definition: HelloServer.cpp:11
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)
virtual ~EvtSpinDensity()