Main Modules
LHC Detuning Corrections
Caution
THIS FILE CANNOT BE RUN AS A SCRIPT !!!
It does contain the main simulation functions for the LHC scenarios, but to set the parameters needed (e.g. the measurement), see the examples.
This module contains the main function to run an LHC simulation with the given parameters via MAD-X and calculate the corrections based on the provided targets.
This module is similar to the main function to run and calculate the correction, but also allows to use different crossing-schemes. That is, you can specify a crossing scheme per measurement and the feed-down is calculated based on that scheme. As the simulation takes a while and multiple measurements might rely on the same crossing scheme, the optics are calculated and saved first. They can be then either read or passed to the correction function.
- class ir_amplitude_detuning.lhc_detuning_corrections.CorrectionResults(name: str, series: pd.Series, dataframe: tfs.TfsDataFrame, madx: str)[source]
Class to store the results of a correction calculation.
- name
The name of the correction target.
- Type:
- series
Series of the correction KNL values for each corrector.
- Type:
pd.Series
- dataframe
Same information as the Series, but in a DataFrame format, with the corrector-magnet names as index and the other data split into columns. See
generate_knl_tfs().- Type:
tfs.TfsDataFrame
- madx
The MAD-X code to apply the correction.
- Type:
- ir_amplitude_detuning.lhc_detuning_corrections.calculate_corrections(beams: Sequence[int], outputdir: Path, targets: Sequence[Target], method: Method = auto) dict[str, CorrectionResults][source]
Calculate corrections based on targets and given correctors.
- Parameters:
beams (
Sequence[int]) -- The beam numbers to calculate corrections for.outputdir (
Path) -- The output directory.targets (
Sequence[Target]) -- The targets to calculate corrections for.method (
Method) -- The method to use for calculating the corrections (seeir_amplitude_detuning.detuning.calculations()).
- Returns:
The results for each target.
- Return type:
- ir_amplitude_detuning.lhc_detuning_corrections.check_corrections_analytically(outputdir: Path, optics: TwissPerBeam, results: CorrectionResults) dict[int, pd.DataFrame][source]
Calculate the
effective detuningfor each beam and write the results into atfsfile.- Parameters:
outputdir (
Path) -- The output directory.optics (
TwissPerBeam) -- The machine optics.results (
CorrectionResults) -- The calculated correction results.
- ir_amplitude_detuning.lhc_detuning_corrections.check_corrections_ptc(outputdir: Path, lhc_beams: dict[int, LHCBeam] | None = None, beams: Sequence[int] | None = None, xing: dict[str, dict] | None = None, optics: Path | None = None, year: int = 2018, tune_x: float = 62.28, tune_y: float = 60.31)[source]
Check the corrections via PTC.
This installs decapole corrector magnets and reads the corrections from the settings file. If
lhc_beamsare given, the output paths will be adapted and these used, otherwise newLHCBeams will be set up.PTC is run for the
nominalmachine as well as allsettings.*files found in the output directory. The PTC output ids are parsed from the settings file names.
- ir_amplitude_detuning.lhc_detuning_corrections.create_optics(beams: Sequence[int], outputdir: Path, output_id: str = '', xing: dict[str, str | float] | None = None, optics: str | Path | None = None, year: int = 2018, tune_x: float = 62.28, tune_y: float = 60.31) dict[int, LHCBeam][source]
Run MAD-X to create optics for all crossing-schemes.
The optics are saved in subfolders of the output directory.
- Parameters:
beams (
Sequence[int]) -- The beam numbers.outputdir (
Path) -- The output directory.output_id (
str, optional) -- The output id. Defaults to ‘’.xing (
dict[str,dict], optional) -- The crossing scheme. Defaults toNone, which is set to the top-energy collision scheme below.optics (
str, optional) -- The optics. Defaults to “round3030”.year (
int, optional) -- The year. Defaults to 2018.tune_x (
float, optional) -- The horizontal tune. Defaults to 62.31.tune_y (
float, optional) -- The vertical tune. Defaults to 60.32.
- Returns:
The LHC beams, i.e. a dictionary of LHCBeam objects.
- Return type:
LHCBeams
- ir_amplitude_detuning.lhc_detuning_corrections.detuning_tfs_out_with_and_without_errors(lhc_out: LHCBeam | FakeLHCBeam, id_: str, df: pd.DataFrame)[source]
Write out the detuning results, given as
DataFrameinto atfsfile. If the inputDataFramecontainsMeasureValueobjects, the values and errors are extracted and two files are written: One with only the values and one with the values and errors.- Parameters:
lhc_out (
LHCBeam | FakeLHCBeam) -- LHCBeam object to find the correct output path.id (
str) -- The identifier (e.g. target name) of the calculation.df (
pd.DataFrame) -- The calculated detuning terms.
- ir_amplitude_detuning.lhc_detuning_corrections.generate_knl_tfs(values: pd.Series) tfs.TfsDataFrame[source]
Generate a TFS dataframe with the corrector values.
- Parameters:
values (
pd.Series) -- The correction values. Assumes the index areCorrectorobjects.
- ir_amplitude_detuning.lhc_detuning_corrections.generate_madx_command(values: pd.Series) str[source]
Generate a MAD-X command to set the corrector values.
- Parameters:
values (
pd.Series) -- The correction values. Assumes the index are the Corrector objects.
- ir_amplitude_detuning.lhc_detuning_corrections.get_label_outputdir(outputdir: Path, label: str, beam: int) Path[source]
Get the outputdir sub-dir for a given label and beam.
- ir_amplitude_detuning.lhc_detuning_corrections.get_nominal_optics(beams: LHCBeams | Sequence[int], outputdir: Path | None = None, label: str = '') TwissPerBeam[source]
Return previously generated nominal machine optics as a dictionary of TfsDataFrames per Beam, either directly from the LHCBeams objects (if given) or reading from the labeled sub-folder in the output-path.
- Parameters:
beams (
LHCBeams | Sequence[int]) -- The LHCBeams objects or a sequence of beam numbers.outputdir (
Path) -- The output directory.label (
str) -- The label for the sub-dir (e.g. a name for the optics)