def _setIdBump(idname, xc, thetac, **kwargs): """ idname - name of ID in the middle of 4 BPMs. 2 BPMs each side. xc - beam position at center of ID. [mm] thetac - bema angle at center of ID. [mrad] plane - 'x' or 'y'. default 'x'. Hard coded Error if absolute value: - bpms distance > 20.0m or, - xc > 5mm, or - thetac > 1mrad TODO: fix the [mm], [mrad] default unit """ if np.abs(xc) > 5.0 or np.abs(thetac) > 1.0: raise RuntimeError("xc or thetac overflow: {0}, {1}".format( xc, thetac)) plane = kwargs.get("plane", 'x') nbs = getNeighbors(idname, "COR", n=2) cors = [nbs[0], nbs[1], nbs[-2], nbs[-1]] cx0 = fget(cors, plane, unitsys=None, handle="setpoint") # assuming each ID has two UBPM bpmsact = getNeighbors(idname, "BPM", n=1) if len(bpmsact) < 3: raise RuntimeError("can not find two bounding UBPMs " "for {0}".format(idname)) bpmsact = [bpmsact[0], bpmsact[-1]] allbpms = getGroupMembers(["BPM", "UBPM"], op="union") bpmsi, bpmso = getBoundedElements(allbpms, cors[0].sb, cors[-1].se) vx0 = fget(bpmsact, plane, unitsys=None) # sposition of bpms and ID center s0, s1 = [(b.se + b.sb) / 2.0 for b in bpmsact] sc = [(c.sb + c.se) / 2.0 for c in getElements(idname)][0] L = (bpmsact[-1].se + bpmsact[-1].sb) / 2.0 - \ (bpmsact[0].se + bpmsact[0].sb) / 2.0 if L <= 0.0 or L > 20.0: raise RuntimeError("ID BPM distance might be wrong: {0}".format(L)) x0 = xc - (sc - s0) / 1000.0 * thetac x1 = xc + (s1 - sc) / 1000.0 * thetac dvx = np.array([x0, x1], 'd') - vx0 dcs = meas4CorBump(cors, bpmsact, bpmso, dvx) for i, c in enumerate(cors): print(i, c.name, dcs[i]) c.put(plane, dcs[i] + cx0[i], unitsys=None)
def setIdBump(idname, xc, thetac, **kwargs): """ idname - name of ID in the middle of 4 BPMs. 2 BPMs each side. xc - beam position at center of ID. [mm] thetac - bema angle at center of ID. [mrad] plane - 'x' or 'y'. default 'x'. ncor - number of correctors, default 6 each side. Hard coded Error if absolute value: - bpms distance > 20.0m or, - xc > 5mm, or - thetac > 1mrad TODO: fix the [mm], [mrad] default unit """ if np.abs(xc) > 5.0 or np.abs(thetac) > 1.0: raise RuntimeError("xc or thetac overflow: {0}, {1}".format( xc, thetac)) fld = kwargs.get("plane", 'x') ncor = kwargs.get("ncor", 6) dImax = kwargs.get("dImax", 0.5) idobj = getElements(idname)[0] # find the correctors, 3 before ID, 3 after cors_ = getNeighbors(idname, "COR", n=ncor) cors = cors_[:ncor] + cors_[-ncor:] bpms_c = getNeighbors(idname, ["BPM", "UBPM"], n=1) bpms_l = getNeighbors(cors[0].name, "BPM", n=ncor - 1)[:ncor - 1] bpms_r = getNeighbors(cors[-1].name, "BPM", n=ncor - 1)[1 - ncor:] bpms = bpms_l + bpms_c[:1] + bpms_c[-1:] + bpms_r ref = fget(bpms, fld, unitsys=None) b0, b1 = bpms[ncor - 1], bpms[ncor] L = b1.sb - b0.sb ref[ncor - 1] = xc - L * thetac / 2.0 ref[ncor] = xc + L * thetac / 2.0 norm0, norm1, norm2, corvals = \ setLocalBump([(b.name, fld) for b in bpms], [(c.name, fld) for c in cors], ref, dImax=dImax, check=True, fullm=False) return norm0, norm1, norm2, corvals