print("gamma0 : %.4e" % gamma0 )
        print("emitn  : %.4e" % emitn  )
        print("aw0m   : %.4f" % am     )
        print("xlamdm : %.4f" % lambdam)
        print("aw0r   : %.4f" % au     )
        print("xlamdr : %.4f" % lambdau)
        print("imagl  : %.4f" % imagl  )
        print("idril  : %.4f" % idril  )
        print("ibfield: %.4f" % ibfield)

def matchCalculate(self, latlengthname='fullat.hghg'):
        m0 = 9.10938215e-31
        e0 = 1.602176487e-19
        c0 = 299792458

        modparams = ParseParams(self.infile_mod, self.latfile_mod)
        gamma0 = modparams.getElectronGamma()
        emitn = modparams.getElectronEmitx()
        am = modparams.getUndulatorParameter()
        lambdam = modparams.getUndulatorPeriod()

        radparams = ParseParams(self.infile_rad, self.latfile_rad)
        au = radparams.getUndulatorParameter()
        lambdau = radparams.getUndulatorPeriod()
        imagl = radparams.getChicaneMagnetLength()
        idril = radparams.getChicaneDriftLength()
        ibfield = radparams.getChicaneMagnetField()

        lo1, lum, lo2, lo3, lf, lo4, lur, lo5, ld = parseLattice(latlengthname)

        kp, kn = self.qfval, self.qdval
        Kp = e0 * kp / m0 / c0 / sqrt(gamma0 ** 2 - 1)
        Kn = e0 * kn / m0 / c0 / sqrt(gamma0 ** 2 - 1)

        lambdas = lambdau / 2.0 / gamma0 ** 2 * (1 + au ** 2) * 1.0e9

        ku = 2.0 * np.pi / lambdau
        Ku = sqrt(2.0) * au
        Kbetau = 0.5 * (Ku * ku / gamma0) ** 2

        Km = sqrt(2.0) * am
        km = 2.0 * np.pi / lambdam
        Kbetam = 0.5 * (Km * km / gamma0) ** 2

        # print(" ".join([Kp,Kn,lambdas,ku,Ku,Kbetau,Km,km,Kbetam,lambdau,lambdam])

        N = np.array([lo3, lf * 0.5, lo4, lur, lo5, ld, lo4, lur, lo5, 0.5 * lf])
        # one FODO period: N[1:], N[0]: drift length before QF

        mx = mathutils.funTransQuadF(Kp, N[1] * lambdau) * mathutils.funTransDrift(
            N[2] * lambdau) * mathutils.funTransUnduH(N[3] * lambdau) * mathutils.funTransDrift(
            N[4] * lambdau) * mathutils.funTransQuadF(Kn, N[5] * lambdau) * mathutils.funTransDrift(
            N[6] * lambdau) * mathutils.funTransUnduH(N[7] * lambdau) * mathutils.funTransDrift(
            N[8] * lambdau) * mathutils.funTransQuadF(Kp, N[9] * lambdau)
        if (mx[0, 0] + mx[1, 1]) ** 2 > 4 or mx[0, 1] <= 0:
            self.matchOK = False
            return self.matchOK

        my = mathutils.funTransQuadF(-Kp, N[1] * lambdau) * mathutils.funTransDrift(
            N[2] * lambdau) * mathutils.funTransUnduV(Kbetau, N[3] * lambdau) * mathutils.funTransDrift(
            N[4] * lambdau) * mathutils.funTransQuadF(-Kn, N[5] * lambdau) * mathutils.funTransDrift(
            N[6] * lambdau) * mathutils.funTransUnduV(Kbetau, N[7] * lambdau) * mathutils.funTransDrift(
            N[8] * lambdau) * mathutils.funTransQuadF(-Kp, N[9] * lambdau)
        if (my[0, 0] + my[1, 1]) ** 2 > 4 or my[0, 1] <= 0:
            self.matchOK = False
            return self.matchOK

        # print(mx)
        # print(my)

        ## twiss parameters of FODO
        # mx
        alphax_FODO = (mx[0, 0] - mx[1, 1]) / sqrt(4.0 - (mx[0, 0] + mx[1, 1]) ** 2)
        betax_FODO = 2.0 * mx[0, 1] / sqrt(4.0 - (mx[0, 0] + mx[1, 1]) ** 2)
        gammax_FODO = (1.0 + alphax_FODO ** 2) / betax_FODO
        # my
        alphay_FODO = (my[0, 0] - my[1, 1]) / sqrt(4.0 - (my[0, 0] + my[1, 1]) ** 2)
        betay_FODO = 2.0 * my[0, 1] / sqrt(4.0 - (my[0, 0] + my[1, 1]) ** 2)
        gammay_FODO = (1.0 + alphay_FODO ** 2) / betay_FODO

        ## match to the entrance of radiator
        # forward match to 'O + QF/2'
        AX = mathutils.funTransQuadF(Kp, N[1] * lambdau) * mathutils.funTransDrift(N[0] * lambdau)
        AY = mathutils.funTransQuadF(-Kp, N[1] * lambdau) * mathutils.funTransDrift(N[0] * lambdau)
        AX = inv(AX)
        AY = inv(AY)
        Nx = np.matrix([[AX[0, 0] ** 2, -2 * AX[0, 0] * AX[0, 1], AX[0, 1] ** 2],
                        [-AX[0, 0] * AX[1, 0], 1 + 2 * AX[0, 1] * AX[1, 0], -AX[0, 1] * AX[1, 1]],
                        [AX[1, 0] ** 2, -2 * AX[1, 0] * AX[1, 1], AX[1, 1] ** 2]])
        Ny = np.matrix([[AY[0, 0] ** 2, -2 * AY[0, 0] * AY[0, 1], AY[0, 1] ** 2],
                        [-AY[0, 0] * AY[1, 0], 1 + 2 * AY[0, 1] * AY[1, 0], -AY[0, 1] * AY[1, 1]],
                        [AY[1, 0] ** 2, -2 * AY[1, 0] * AY[1, 1], AY[1, 1] ** 2]])

        Bx = Nx * np.matrix([[betax_FODO], [alphax_FODO], [gammax_FODO]])
        By = Ny * np.matrix([[betay_FODO], [alphay_FODO], [gammay_FODO]])

        betax_rad = Bx[0, 0]
        betay_rad = By[0, 0]
        alphax_rad = Bx[1, 0]
        alphay_rad = By[1, 0]
        gammax_rad = Bx[2, 0]
        gammay_rad = By[2, 0]
        sigmax_rad = sqrt(betax_rad * emitn / gamma0)
        sigmay_rad = sqrt(betay_rad * emitn / gamma0)

        # matched beam for radiator input 
        self.alphax_rad = alphax_rad
        self.alphay_rad = alphay_rad
        self.sigmax_rad = sigmax_rad
        self.sigmay_rad = sigmay_rad

        ## forward match to mod + chicane, find configurations for mod input
        AX = mathutils.funTransChica(imagl, idril, ibfield, gamma0, 'x') * mathutils.funTransDrift(
            lo2 * lambdam) * mathutils.funTransUnduH(lum * lambdam) * mathutils.funTransDrift(lo1 * lambdam)
        AY = mathutils.funTransChica(imagl, idril, ibfield, gamma0, 'y') * mathutils.funTransDrift(
            lo2 * lambdam) * mathutils.funTransUnduV(Kbetam, lum * lambdam) * mathutils.funTransDrift(lo1 * lambdam)
        AX = inv(AX)
        AY = inv(AY)
        Nx = np.matrix([[AX[0, 0] ** 2, -2 * AX[0, 0] * AX[0, 1], AX[0, 1] ** 2],
                        [-AX[0, 0] * AX[1, 0], 1 + 2 * AX[0, 1] * AX[1, 0], -AX[0, 1] * AX[1, 1]],
                        [AX[1, 0] ** 2, -2 * AX[1, 0] * AX[1, 1], AX[1, 1] ** 2]])
        Ny = np.matrix([[AY[0, 0] ** 2, -2 * AY[0, 0] * AY[0, 1], AY[0, 1] ** 2],
                        [-AY[0, 0] * AY[1, 0], 1 + 2 * AY[0, 1] * AY[1, 0], -AY[0, 1] * AY[1, 1]],
                        [AY[1, 0] ** 2, -2 * AY[1, 0] * AY[1, 1], AY[1, 1] ** 2]])
        Bx = Nx * np.matrix([[betax_rad], [alphax_rad], [gammax_rad]])
        By = Ny * np.matrix([[betay_rad], [alphay_rad], [gammay_rad]])

        betax_mod = Bx[0, 0]
        betay_mod = By[0, 0]
        alphax_mod = Bx[1, 0]
        alphay_mod = By[1, 0]
        gammax_mod = Bx[2, 0]
        gammay_mod = By[2, 0]
        sigmax_mod = sqrt(betax_mod * emitn / gamma0)
        sigmay_mod = sqrt(betay_mod * emitn / gamma0)

        # matched beam for modulator input 
        self.alphax_mod = alphax_mod
        self.alphay_mod = alphay_mod
        self.sigmax_mod = sigmax_mod
        self.sigmay_mod = sigmay_mod

        """
        print("gamma0 : %.4e" % gamma0 )
        print("emitn  : %.4e" % emitn  )
        print("aw0m   : %.4f" % am     )
        print("xlamdm : %.4f" % lambdam)
        print("aw0r   : %.4f" % au     )
        print("xlamdr : %.4f" % lambdau)
        print("imagl  : %.4f" % imagl  )
        print("idril  : %.4f" % idril  )
        print("ibfield: %.4f" % ibfield)
        """

        return self.matchOK