Skip to content
Snippets Groups Projects
Commit 54f1dba2 authored by Alexis GAMELIN's avatar Alexis GAMELIN
Browse files

Add uniform beam injection functions

To be tested ...
parent b7631748
Branches
Tags
No related merge requests found
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 1 12:21:40 2023
@author: gamelina
"""
from injection import (get_linac_table,
get_extraction_table,
switch_injection_mode,
set_injection,
inject_beam,
inject_uniform_beam,
SPM_feedback)
\ No newline at end of file
...@@ -129,15 +129,114 @@ def inject_beam(booster_cav): ...@@ -129,15 +129,114 @@ def inject_beam(booster_cav):
else: else:
raise ValueError("booster_cav must be 1 or 2.") raise ValueError("booster_cav must be 1 or 2.")
topup = DeviceProxy("boo/ae/pstopupmodemanager") boo_ps = DeviceProxy("boo/ae/pstopupmodemanager")
central = DeviceProxy("ANS/SY/CENTRAL") central = DeviceProxy("ANS/SY/CENTRAL")
counter = 0
if cav_booster.state() is DevState.ON: if cav_booster.state() is DevState.ON:
if rampe.state() is not DevState.RUNNING: if rampe.state() is not DevState.RUNNING:
rampe.start() rampe.start() # Booster RF ramping
time.sleep(1) time.sleep(1)
topup.nominal() boo_ps.nominal() # Booster power supply ramping
time.sleep(5) time.sleep(5)
while(central.state() != DevState.ON):
counter += 1
time.sleep(0.1)
if counter == 100:
raise ValueError("Central state is not ON for more than 10s.")
central.fireburstevent() central.fireburstevent()
else: else:
raise ValueError("Booster cavity state is not ON.") raise ValueError("Booster cavity state is not ON.")
def inject_uniform_beam(goal_current, booster_cav, fine_delay):
"""
Inject "uniform" filling pattern by rotating the LPM injection bucket by 8
bucket at each injection.
Parameters
----------
goal_current : float
Total beam current to reach in [mA].
booster_cav : int
Booster cavity number to be used.
fine_delay : float
Fine delay in [s].
"""
dcct = DeviceProxy("ANS/DG/DCCT-CTRL")
rendement = DeviceProxy("ANS/DG/RENDEMENT")
eff_booster = np.ones((10,))*100
eff_sr = np.ones((10,))*100
count = 0
while dcct.current < goal_current:
bucket_list = (1 + count*8)%416
set_injection("LPM", bucket_list, fine_delay)
inject_beam(booster_cav)
time.sleep(0.5)
eff_sr[0] = rendement.efficiencyANS_LPM_avg
eff_booster[0] = rendement.efficiencyBOO_LPM_avg
if np.mean(eff_booster) < 40:
raise ValueError("Injection efficiency in booster is too low.")
if np.mean(eff_booster) < 40:
raise ValueError("Injection efficiency in storage ring is too low.")
eff_booster = np.roll(eff_booster, 1)
eff_sr = np.roll(eff_sr, 1)
count += 1
def SPM_feedback(goal_current, booster_cav, fine_delay, max_fill=10):
"""
SPM injection feedback to try to correct a more uniform filling pattern.
Parameters
----------
goal_current : float
Total beam current to reach in [mA].
booster_cav : int
Booster cavity number to be used.
fine_delay : float
Fine delay in [s].
max_fill : int, optional
Maximum number of bucket to fill in a single FB iteration.
The default is 10.
"""
dcct = DeviceProxy("ANS/DG/DCCT-CTRL")
rendement = DeviceProxy("ANS/DG/RENDEMENT")
remplissage = DeviceProxy("ANS/DG/REMPLISSAGE")
eff_booster = np.ones((10,))*100
eff_sr = np.ones((10,))*100
fill = remplissage.bunchesCurrent
h = 416
goal_per_bunch = goal_current/h
while True:
if dcct.current < goal_current:
fill = remplissage.bunchesCurrent
idx = np.argsort(fill)
idx = idx[:max_fill]
to_fill = fill[idx] < goal_per_bunch
bucket_list = idx[to_fill] + 1
print(f"Injecting in buckets: {bucket_list}")
print(f"With current per bunch: {fill[idx[to_fill]]}")
set_injection("SPM", bucket_list, fine_delay)
inject_beam(booster_cav)
time.sleep(0.5)
eff_sr[0] = rendement.efficiencyANS_LPM_avg
eff_booster[0] = rendement.efficiencyBOO_LPM_avg
if np.mean(eff_booster) < 40:
raise ValueError("Injection efficiency in booster is too low.")
if np.mean(eff_booster) < 40:
raise ValueError("Injection efficiency in storage ring is too low.")
eff_booster = np.roll(eff_booster, 1)
eff_sr = np.roll(eff_sr, 1)
else:
time.sleep(5)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment