thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
RhoDMatrix.h
1// -*- C++ -*-
2//
3// RhoDMatrix.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 2003-2019 Peter Richardson, Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef ThePEG_RhoDMatrix_H
10#define ThePEG_RhoDMatrix_H
11// This is the declaration of the RhoDMatrix class.
12
13#include "ThePEG/PDT/PDT.h"
15#include <cassert>
16#include <array>
17
18namespace ThePEG {
19
29
30public:
31
37 RhoDMatrix() = default;
38
43 RhoDMatrix(PDT::Spin inspin, bool average = true)
44 : _spin(inspin), _ispin(abs(int(inspin))) {
45 assert(_ispin <= MAXSPIN);
46 // initialize to average
47 if ( average )
48 for(size_t ix=0; ix<_ispin; ++ix)
49 _matrix[ix][ix] = 1./_ispin;
50 }
52
53public:
54
60 Complex operator() (size_t ix, size_t iy) const {
61 assert(ix < _ispin);
62 assert(iy < _ispin);
63 return _matrix[ix][iy];
64 }
65
69 Complex & operator() (size_t ix, size_t iy) {
70 assert(ix < _ispin);
71 assert(iy < _ispin);
72 return _matrix[ix][iy];
73 }
74
78 void normalize() {
79#ifndef NDEBUG
80 static const double epsa=1e-40, epsb=1e-10;
81#endif
82 Complex norm = 0.;
83 for(size_t ix=0; ix<_ispin; ++ix)
84 norm += _matrix[ix][ix];
85 assert(norm.real() > epsa);
86 assert(norm.imag()/norm.real() < epsb);
87 double invnorm = 1./norm.real();
88 for(size_t ix=0; ix<_ispin; ++ix)
89 for(size_t iy=0; iy<_ispin; ++iy)
90 _matrix[ix][iy]*=invnorm;
91 }
93
97 void reset(bool average = true) {
98 for(size_t ix=0; ix<_ispin; ++ix)
99 for(size_t iy=0; iy<_ispin; ++iy)
100 _matrix[ix][iy]=0.;
101 if ( average )
102 for(size_t ix=0; ix<_ispin; ++ix)
103 _matrix[ix][ix] = 1./_ispin;
104 }
105
108
112 PDT::Spin iSpin() const { return _spin; }
114
118 friend ostream & operator<<(ostream & os, const RhoDMatrix & rd);
119
120private:
121
126
130 size_t _ispin;
131
135 enum { MAXSPIN = 7 };
136
140 // Deliberately not using vector<> to avoid calls to 'new'
141 // from this commonly used class.
142 std::array<std::array<Complex,MAXSPIN>,MAXSPIN> _matrix;
143
144};
145
147inline ostream & operator<<(ostream & os, const RhoDMatrix & rd) {
148 for (size_t ix = 0; ix < rd._ispin; ++ix) {
149 for (size_t iy = 0; iy < rd._ispin; ++iy)
150 os << rd._matrix[ix][iy] << " ";
151 os << '\n';
152 }
153 return os;
154}
155
156}
157
158#endif /* ThePEG_RhoDMatrix_H */
This file contains enumerations used by LorentzSpinor and LorentzSpinorBar classes.
Spin
Definition of enumerated values used for spin information.
Definition: PDT.h:32
The RhoDMatrix class is designed to implement the storage of the rho and D matrices which are require...
Definition: RhoDMatrix.h:28
Complex operator()(size_t ix, size_t iy) const
Return an element of the matrix.
Definition: RhoDMatrix.h:60
RhoDMatrix(PDT::Spin inspin, bool average=true)
Standard constructor giving the spin as 2s+1.
Definition: RhoDMatrix.h:43
size_t _ispin
Storage of 2s+1 for speed.
Definition: RhoDMatrix.h:130
void reset(bool average=true)
Reset.
Definition: RhoDMatrix.h:97
void normalize()
renormalise the matrix so it has unit trace
Definition: RhoDMatrix.h:78
PDT::Spin iSpin() const
Get the spin.
Definition: RhoDMatrix.h:112
friend ostream & operator<<(ostream &os, const RhoDMatrix &rd)
Output the spin density matrix for debugging purposes.
Definition: RhoDMatrix.h:147
PDT::Spin _spin
2s+1 for the particle.
Definition: RhoDMatrix.h:125
std::array< std::array< Complex, MAXSPIN >, MAXSPIN > _matrix
Storage for the matrix allowing up to spin 2 particles.
Definition: RhoDMatrix.h:142
RhoDMatrix()=default
Default constructor with undefined spin.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
std::complex< double > Complex
ThePEG code should use Complex for all complex scalars.
Definition: Complex.h:23
vector< T > & operator<<(vector< T > &tv, const U &u)
Overload the left shift operator for vector to push_back objects to a vector.
Definition: Containers.h:179