MapAnalyser.h 4.37 KB
Newer Older
1
//
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// Class: MapAnalyser
//   Organizes the function for a linear map analysis from
//   ThickTracker.
//   Transfer map -> tunes, symplecticity and stability
//   Sigma Matrix -> (not projected) beam emittance
//
// This class is in an unfinished state.
// For some dicussion see https://gitlab.psi.ch/OPAL/src/issues/464
// Some cleanup was done in https://gitlab.psi.ch/OPAL/src/merge_requests/294
//
// Copyright (c) 2018, Philippe Ganz, ETH Zürich
// All rights reserved
//
// Implemented as part of the Master thesis
// "s-based maps from TPS & Lie-Series applied to Proton-Therapy Gantries"
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
24
//
25 26
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
27 28
//

snuverink_j's avatar
snuverink_j committed
29 30 31 32 33
#ifndef MAP_ANALYSER_H
#define MAP_ANALYSER_H

#include "Classic/FixedAlgebra/FMatrix.h"

34 35
#include "Utility/IpplTimings.h"

snuverink_j's avatar
snuverink_j committed
36 37 38 39 40 41 42 43
#include <array>
#include <complex>

class MapAnalyser
{
public:
    typedef FMatrix<double, 6, 6> fMatrix_t;
    typedef FMatrix<std::complex<double>, 6, 6> cfMatrix_t;
44

snuverink_j's avatar
snuverink_j committed
45
    MapAnalyser();
46

snuverink_j's avatar
snuverink_j committed
47
    /*!
48
     * Analyzes the transfer matrix for tunes, symplecticity and stability
snuverink_j's avatar
snuverink_j committed
49 50 51
     *
     * @param tMatrix Transfer matrix
     */
52
    void linTAnalyze(const fMatrix_t& /*tMatrix*/) {};
53

snuverink_j's avatar
snuverink_j committed
54 55 56 57 58 59

    /*!
     * Analyzes the transfer matrix
     *
     * @ param sigMatrix Sigma Matrix
     */
60
    void linSigAnalyze(fMatrix_t& /*sigMatrix*/) {};
snuverink_j's avatar
snuverink_j committed
61
private:
62

snuverink_j's avatar
snuverink_j committed
63 64 65 66 67 68 69 70 71 72 73 74 75
    /*!
     * Eigen-decomposition of M
     *
     * \f[
     *  \mathbf{M} = \mathbf{E} \mathbf{\Lambda} \mathbf{E}^{-1}
     * \f]
     *
     * @param M Matrix to analyze
     * @param eigenVal EigenValues of \f$\mathbf{M}\f$ \f$\mathbf{\Lambda}\f$
     * @param eigenVec EigenVectors of \f$\mathbf{M}\f$ \f$\mathbf{E}\f$
     * @param invEigenVec inverted EigenVectors of \f$\mathbf{M}\f$ \f$\mathbf{E}^{-1}\f$
     */
    void eigenDecomp_m(const fMatrix_t& M, cfMatrix_t& eigenVal, cfMatrix_t& eigenVec, cfMatrix_t& invEigenVec);
76

snuverink_j's avatar
snuverink_j committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    /*!
     * Returns the block diagonal form rotation matrix \f$ \mathbf{R}\f$. \n
     * This Matrix gets created by applying a symplectic and its inverse Matrix \f$U\f$ on M \f$ \mathbf{R} = \mathbf{UMU}^{-1}\f$
     * @cite Wolski_2005
     *
     * \f[
     *  \mathbf{R}_{\left( \mu_x,\mu_y, \mu_z  \right)}=
     *  \begin{pmatrix}
     *      \mathbf{R}_{2\left( \mu_x\right)} & 0 &0 \\
     *      0 & \mathbf{R}_{2\left( \mu_y\right)} &0 \\
     *      0 & 0 &\mathbf{R}_{2\left( \mu_z\right)} \end{pmatrix}
     *  , \qquad
     *  \mathbf{R_2}_{\left( \alpha \right)}=
     *  \begin{pmatrix}
     *  \cos\left( \alpha \right) & \sin\left( \alpha \right)\\
     *   -\sin\left( \alpha \right) & \cos\left( \alpha \right)\\
     *   \end{pmatrix}
     * \f]
     *
     * @param M Matrix to analyze
     * @param eigenVec EigenVectors of \f$\mathbf{M}\f$
     * @param invEigenVec inverted EigenVectors of \f$\mathbf{M}\f$
     *
     */
    cfMatrix_t getBlockDiagonal_m(const fMatrix_t& M, cfMatrix_t& eigenVecM, cfMatrix_t& invEigenVecM);
102

snuverink_j's avatar
snuverink_j committed
103 104 105 106 107 108 109 110
    /*!
     * :TODO: WIP Prints phase shift
     *
     * @param Sigma Sigma Matirx
     * @param tM Transfer Matirx
     * @param oldN \f$\mathbf{N}\f$ matrix
     */
    void printPhaseShift_m(fMatrix_t& Sigma, fMatrix_t tM, cfMatrix_t& oldN);
111

snuverink_j's avatar
snuverink_j committed
112 113 114 115 116 117 118 119 120
    /*!
    * sets a symplectic \f$ \mathbf{N} \f$ matrix. \n
    * This function is a subfunction of ThickTracker::getBlockDiagonal. \cite Wolski_2005
    *
    * @param M Matrix to analyze
    * @param N symplectic \f$\mathbf{N}\f$ matrix
    * @param invN inverted symplectic \f$\mathbf{N}^{-1}\f$ matrix
    */
    void setNMatrix_m(fMatrix_t& M, cfMatrix_t& N, cfMatrix_t& invN);
121

snuverink_j's avatar
snuverink_j committed
122 123

    fMatrix_t createRotMatrix_m(std::array<double, 3> phi);
124

snuverink_j's avatar
snuverink_j committed
125
    fMatrix_t createSkewMatrix_m();
126

snuverink_j's avatar
snuverink_j committed
127
    fMatrix_t realPartOfMatrix_m(cfMatrix_t cM);
128

snuverink_j's avatar
snuverink_j committed
129
    fMatrix_t imagPartOfMatrix_m(cfMatrix_t cM);
130

snuverink_j's avatar
snuverink_j committed
131 132 133
    cfMatrix_t complexTypeMatrix_m(fMatrix_t M);

    cfMatrix_t invertMatrix_m(const cfMatrix_t &M);
134

135 136 137
    void rearrangeEigen_m(cfMatrix_t& /*EigenVal*/, cfMatrix_t& /*EigenVec*/) {};

    void normalizeEigen_m(cfMatrix_t& eigenVec, cfMatrix_t& invEigenVec);
138

snuverink_j's avatar
snuverink_j committed
139 140 141 142 143 144
private:
    IpplTimings::TimerRef mapAnalysis_m;
    IpplTimings::TimerRef bunchAnalysis_m;
};

#endif