Changeset View
Changeset View
Standalone View
Standalone View
EvtGenBase/EvtSpinDensity.hh
Show All 16 Lines | |||||
* You should have received a copy of the GNU General Public License * | * You should have received a copy of the GNU General Public License * | ||||
* along with EvtGen. If not, see <https://www.gnu.org/licenses/>. * | * along with EvtGen. If not, see <https://www.gnu.org/licenses/>. * | ||||
***********************************************************************/ | ***********************************************************************/ | ||||
#ifndef EVTSPINDENSITY_HH | #ifndef EVTSPINDENSITY_HH | ||||
#define EVTSPINDENSITY_HH | #define EVTSPINDENSITY_HH | ||||
#include "EvtGenBase/EvtComplex.hh" | #include "EvtGenBase/EvtComplex.hh" | ||||
#include <cassert> | |||||
// Description: This class holds a spin density matrix, it is | // Description: This class holds a spin density matrix, it is | ||||
// a complex nxn matrix. | // a complex nxn matrix. | ||||
class EvtSpinDensity { | class EvtSpinDensity { | ||||
public: | public: | ||||
EvtSpinDensity() : dim( 0 ), rho( nullptr ) {} | |||||
EvtSpinDensity( int n ) : dim( 0 ), rho( nullptr ) { setDim( n ); } | |||||
EvtSpinDensity( const EvtSpinDensity& density ); | EvtSpinDensity( const EvtSpinDensity& density ); | ||||
EvtSpinDensity& operator=( const EvtSpinDensity& density ); | EvtSpinDensity& operator=( const EvtSpinDensity& density ); | ||||
virtual ~EvtSpinDensity(); | virtual ~EvtSpinDensity(); | ||||
EvtSpinDensity(); | |||||
void setDim( int n ); | void setDim( int n ); | ||||
int getDim() const; | int getDim() const { return dim; } | ||||
void set( int i, int j, const EvtComplex& rhoij ); | void set( int i, int j, const EvtComplex& rhoij ) | ||||
const EvtComplex& get( int i, int j ) const; | { | ||||
double normalizedProb( const EvtSpinDensity& d ); | assert( i < dim && j < dim ); | ||||
rho[i * dim + j] = rhoij; | |||||
} | |||||
EvtComplex get( int i, int j ) const | |||||
{ | |||||
assert( i < dim && j < dim ); | |||||
return rho[i * dim + j]; | |||||
} | |||||
EvtComplex operator()( int i, int j ) const | |||||
{ | |||||
assert( i < dim && j < dim ); | |||||
return rho[i * dim + j]; | |||||
} | |||||
EvtComplex& operator()( int i, int j ) | |||||
{ | |||||
assert( i < dim && j < dim ); | |||||
return rho[i * dim + j]; | |||||
} | |||||
EvtSpinDensity& operator-=( const EvtSpinDensity& d ) | |||||
{ | |||||
assert( dim == d.dim ); | |||||
for ( int i = 0; i < dim * dim; i++ ) | |||||
rho[i] -= d.rho[i]; | |||||
return *this; | |||||
} | |||||
EvtSpinDensity& operator+=( const EvtSpinDensity& d ) | |||||
{ | |||||
assert( dim == d.dim ); | |||||
for ( int i = 0; i < dim * dim; i++ ) | |||||
rho[i] += d.rho[i]; | |||||
return *this; | |||||
} | |||||
double normalizedProb( const EvtSpinDensity& d ) const; | |||||
friend std::ostream& operator<<( std::ostream& s, const EvtSpinDensity& d ); | friend std::ostream& operator<<( std::ostream& s, const EvtSpinDensity& d ); | ||||
void setDiag( int n ); | void setDiag( int n ); | ||||
int check(); | int check(); | ||||
private: | private: | ||||
EvtComplexPtrPtr rho; | |||||
int dim; | int dim; | ||||
EvtComplex* rho; | |||||
}; | }; | ||||
inline EvtSpinDensity operator-( const EvtSpinDensity& a, const EvtSpinDensity& b ) | |||||
{ | |||||
EvtSpinDensity t( a ); | |||||
t -= b; | |||||
return t; | |||||
} | |||||
inline EvtSpinDensity operator+( const EvtSpinDensity& a, const EvtSpinDensity& b ) | |||||
{ | |||||
EvtSpinDensity t( a ); | |||||
t -= b; | |||||
return t; | |||||
} | |||||
#endif | #endif |