ThePEG  1.8.0
RhoDMatrix.h
1 // -*- C++ -*-
2 //
3 // RhoDMatrix.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 2003-2011 Peter Richardson, Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 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"
14 #include "ThePEG/Helicity/HelicityDefinitions.h"
15 #include <cassert>
16 
17 namespace ThePEG {
18 
27 class RhoDMatrix {
28 
29 public:
30 
36  RhoDMatrix() : _spin(), _ispin() {}
37 
42  RhoDMatrix(PDT::Spin inspin, bool average = true)
43  : _spin(inspin), _ispin(abs(int(inspin))) {
44  assert(_ispin <= MAXSPIN);
45  // initialize to average
46  for(size_t ix=0; ix<_ispin; ++ix)
47  for(size_t iy=0; iy<_ispin; ++iy)
48  _matrix[ix][iy] = (average && ix==iy) ? 1./_ispin : 0.;
49  }
51 
52 public:
53 
59  Complex operator() (size_t ix, size_t iy) const {
60  assert(ix < _ispin);
61  assert(iy < _ispin);
62  return _matrix[ix][iy];
63  }
64 
68  Complex & operator() (size_t ix, size_t iy) {
69  assert(ix < _ispin);
70  assert(iy < _ispin);
71  return _matrix[ix][iy];
72  }
73 
77  void normalize() {
78 #ifndef NDEBUG
79  static const double epsa=1e-30, epsb=1e-10;
80 #endif
81  Complex norm = 0.;
82  for(size_t ix=0; ix<_ispin; ++ix)
83  norm += _matrix[ix][ix];
84  assert(norm.real() > epsa);
85  assert(norm.imag()/norm.real() < epsb);
86  double invnorm = 1./norm.real();
87  for(size_t ix=0; ix<_ispin; ++ix)
88  for(size_t iy=0; iy<_ispin; ++iy)
89  _matrix[ix][iy]*=invnorm;
90  }
92 
95 
99  PDT::Spin iSpin() const { return _spin; }
101 
105  friend ostream & operator<<(ostream & os, const RhoDMatrix & rd);
106 
107 private:
108 
113 
117  size_t _ispin;
118 
122  enum { MAXSPIN = 5 };
123 
127  // Deliberately not using vector<> to avoid calls to 'new'
128  // from this commonly used class.
129  Complex _matrix[MAXSPIN][MAXSPIN];
130 
131 };
132 
134 inline ostream & operator<<(ostream & os, const RhoDMatrix & rd) {
135  for (size_t ix = 0; ix < rd._ispin; ++ix) {
136  for (size_t iy = 0; iy < rd._ispin; ++iy)
137  os << rd._matrix[ix][iy] << " ";
138  os << '\n';
139  }
140  return os;
141 }
142 
143 }
144 
145 #endif /* ThePEG_RhoDMatrix_H */
RhoDMatrix()
Default constructor with undefined spin.
Definition: RhoDMatrix.h:36
size_t _ispin
Storage of 2s+1 for speed.
Definition: RhoDMatrix.h:117
std::complex< double > Complex
ThePEG code should use Complex for all complex scalars.
Definition: Complex.h:23
PDT::Spin iSpin() const
Get the spin.
Definition: RhoDMatrix.h:99
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Complex _matrix[MAXSPIN][MAXSPIN]
Storage for the matrix allowing up to spin 2 particles.
Definition: RhoDMatrix.h:129
RhoDMatrix(PDT::Spin inspin, bool average=true)
Standard constructor giving the spin as 2s+1.
Definition: RhoDMatrix.h:42
Spin
Definition of enumerated values used for spin information.
Definition: PDT.h:32
void normalize()
renormalise the matrix so it has unit trace
Definition: RhoDMatrix.h:77
Complex operator()(size_t ix, size_t iy) const
Return an element of the matrix.
Definition: RhoDMatrix.h:59
friend ostream & operator<<(ostream &os, const RhoDMatrix &rd)
Output the spin density matrix for debugging purposes.
Definition: RhoDMatrix.h:134
PDT::Spin _spin
2s+1 for the particle.
Definition: RhoDMatrix.h:112
The RhoDMatrix class is designed to implement the storage of the rho and D matrices which are require...
Definition: RhoDMatrix.h:27