ROBAST logo
// Author: Akira Okumura <mailto:oxon@mac.com>
/******************************************************************************
 * Copyright (C) 2006-, Akira Okumura                                         *
 * All rights reserved.                                                       *
 *****************************************************************************/

#ifndef A_2x2_COMPLEX_MATRIX_H
#define A_2x2_COMPLEX_MATRIX_H

#include <complex>

#include "TObject.h"

///////////////////////////////////////////////////////////////////////////////
//
// A2x2ComplexMatrix
//
// 2 x 2 complex matrix with minimum functionality
//
///////////////////////////////////////////////////////////////////////////////

class A2x2ComplexMatrix {
 private:
  std::complex<Double_t> fC[4];
  // ( fC[0], fC[1] )
  // ( fC[2], fC[3] )

 public:
  A2x2ComplexMatrix() : A2x2ComplexMatrix(0, 0, 0, 0){};
  A2x2ComplexMatrix(std::complex<Double_t> c0, std::complex<Double_t> c1,
                    std::complex<Double_t> c2, std::complex<Double_t> c3);
  virtual ~A2x2ComplexMatrix() {}

  std::complex<Double_t> Get00() const { return fC[0]; }
  std::complex<Double_t> Get01() const { return fC[1]; }
  std::complex<Double_t> Get10() const { return fC[2]; }
  std::complex<Double_t> Get11() const { return fC[3]; }
  A2x2ComplexMatrix Transpose() const {
    return A2x2ComplexMatrix(fC[0], fC[2], fC[1], fC[3]);
  }
  void Print() const;

  inline A2x2ComplexMatrix& operator=(const A2x2ComplexMatrix& other);
  inline A2x2ComplexMatrix operator*(const A2x2ComplexMatrix& other);
  friend A2x2ComplexMatrix operator*(const std::complex<Double_t>& lhs,
                                     const A2x2ComplexMatrix& rhs) {
    return A2x2ComplexMatrix(lhs * rhs.fC[0], lhs * rhs.fC[1], lhs * rhs.fC[2],
                             lhs * rhs.fC[3]);
  }
  friend A2x2ComplexMatrix operator*(const A2x2ComplexMatrix& lhs,
                                     const std::complex<Double_t>& rhs) {
    return A2x2ComplexMatrix(lhs.fC[0] * rhs, lhs.fC[1] * rhs, lhs.fC[2] * rhs,
                             lhs.fC[3] * rhs);
  }
  friend A2x2ComplexMatrix operator/(const A2x2ComplexMatrix& lhs,
                                     const std::complex<Double_t>& rhs) {
    return A2x2ComplexMatrix(lhs.fC[0] / rhs, lhs.fC[1] / rhs, lhs.fC[2] / rhs,
                             lhs.fC[3] / rhs);
  }
};

//______________________________________________________________________________
A2x2ComplexMatrix& A2x2ComplexMatrix::operator=(
    const A2x2ComplexMatrix& other) {
  if (this != &other) {
    int n = sizeof(fC) / sizeof(std::complex<Double_t>);
    for (int i = 0; i < n; ++i) {
      fC[i] = other.fC[i];
    }
  }
  return *this;
}

//______________________________________________________________________________
A2x2ComplexMatrix A2x2ComplexMatrix::operator*(const A2x2ComplexMatrix& other) {
  // (A0, A1)   (B0, B1)
  // (A2, A3) x (B2, B3)
  std::complex<Double_t>* A = fC;
  const std::complex<Double_t>* B = other.fC;

  return A2x2ComplexMatrix(A[0] * B[0] + A[1] * B[2], A[0] * B[1] + A[1] * B[3],
                           A[2] * B[0] + A[3] * B[2],
                           A[2] * B[1] + A[3] * B[3]);
}

#endif  // A_2x2_COMPLEX_MATRIX_H
 A2x2ComplexMatrix.h:1
 A2x2ComplexMatrix.h:2
 A2x2ComplexMatrix.h:3
 A2x2ComplexMatrix.h:4
 A2x2ComplexMatrix.h:5
 A2x2ComplexMatrix.h:6
 A2x2ComplexMatrix.h:7
 A2x2ComplexMatrix.h:8
 A2x2ComplexMatrix.h:9
 A2x2ComplexMatrix.h:10
 A2x2ComplexMatrix.h:11
 A2x2ComplexMatrix.h:12
 A2x2ComplexMatrix.h:13
 A2x2ComplexMatrix.h:14
 A2x2ComplexMatrix.h:15
 A2x2ComplexMatrix.h:16
 A2x2ComplexMatrix.h:17
 A2x2ComplexMatrix.h:18
 A2x2ComplexMatrix.h:19
 A2x2ComplexMatrix.h:20
 A2x2ComplexMatrix.h:21
 A2x2ComplexMatrix.h:22
 A2x2ComplexMatrix.h:23
 A2x2ComplexMatrix.h:24
 A2x2ComplexMatrix.h:25
 A2x2ComplexMatrix.h:26
 A2x2ComplexMatrix.h:27
 A2x2ComplexMatrix.h:28
 A2x2ComplexMatrix.h:29
 A2x2ComplexMatrix.h:30
 A2x2ComplexMatrix.h:31
 A2x2ComplexMatrix.h:32
 A2x2ComplexMatrix.h:33
 A2x2ComplexMatrix.h:34
 A2x2ComplexMatrix.h:35
 A2x2ComplexMatrix.h:36
 A2x2ComplexMatrix.h:37
 A2x2ComplexMatrix.h:38
 A2x2ComplexMatrix.h:39
 A2x2ComplexMatrix.h:40
 A2x2ComplexMatrix.h:41
 A2x2ComplexMatrix.h:42
 A2x2ComplexMatrix.h:43
 A2x2ComplexMatrix.h:44
 A2x2ComplexMatrix.h:45
 A2x2ComplexMatrix.h:46
 A2x2ComplexMatrix.h:47
 A2x2ComplexMatrix.h:48
 A2x2ComplexMatrix.h:49
 A2x2ComplexMatrix.h:50
 A2x2ComplexMatrix.h:51
 A2x2ComplexMatrix.h:52
 A2x2ComplexMatrix.h:53
 A2x2ComplexMatrix.h:54
 A2x2ComplexMatrix.h:55
 A2x2ComplexMatrix.h:56
 A2x2ComplexMatrix.h:57
 A2x2ComplexMatrix.h:58
 A2x2ComplexMatrix.h:59
 A2x2ComplexMatrix.h:60
 A2x2ComplexMatrix.h:61
 A2x2ComplexMatrix.h:62
 A2x2ComplexMatrix.h:63
 A2x2ComplexMatrix.h:64
 A2x2ComplexMatrix.h:65
 A2x2ComplexMatrix.h:66
 A2x2ComplexMatrix.h:67
 A2x2ComplexMatrix.h:68
 A2x2ComplexMatrix.h:69
 A2x2ComplexMatrix.h:70
 A2x2ComplexMatrix.h:71
 A2x2ComplexMatrix.h:72
 A2x2ComplexMatrix.h:73
 A2x2ComplexMatrix.h:74
 A2x2ComplexMatrix.h:75
 A2x2ComplexMatrix.h:76
 A2x2ComplexMatrix.h:77
 A2x2ComplexMatrix.h:78
 A2x2ComplexMatrix.h:79
 A2x2ComplexMatrix.h:80
 A2x2ComplexMatrix.h:81
 A2x2ComplexMatrix.h:82
 A2x2ComplexMatrix.h:83
 A2x2ComplexMatrix.h:84
 A2x2ComplexMatrix.h:85
 A2x2ComplexMatrix.h:86