Skip to content

Touschek#191

Open
gbrogginess wants to merge 44 commits intoxsuite:mainfrom
gbrogginess:touschek
Open

Touschek#191
gbrogginess wants to merge 44 commits intoxsuite:mainfrom
gbrogginess:touschek

Conversation

@gbrogginess
Copy link
Copy Markdown
Contributor

Description

This PR introduces the possibility to perform Monte Carlo simulations of Touschek scattering in xfields.

It provides:

  • a new TouschekScattering beam element implementing a Monte Carlo Touschek scattering kernel,

  • a TouschekManager that configures Touschek scattering centers using optics and a supplied local momentum aperture profile,

  • a TouschekCalculator that evaluates Piwinski Touschek scattering rates and integrated per-section rates, used to correctly weight scattered macroparticles.

This enables end-to-end Touschek studies within Xsuite, including generation of Touschek-scattered particles, tracking, Touschek loss maps analysis, and Touschek lifetime evaluations.

Checklist

Mandatory:

  • I have added tests to cover my changes
  • All the tests are passing, including my new ones
  • I described my changes in this PR description

Optional:

  • The code I wrote follows good style practices (see PEP 8 and PEP 20).
  • I have updated the docs in relation to my changes, if applicable
  • I have tested also GPU contexts

`compt_scale` is a multiplicative factor applied to the total Compton
cross-section. Increasing this factor scales up photon generation in the
radiative Bhabha model. This can be useful for testing or for producing
a larger number of radiative Bhabha scattering events.
When a line is generated through MAD-X sequence conversion, the line end up having markers sequencename$start and sequencename$end. In the line table these are present, but they do not have an associated s position and this causes an error!
Prevented sampling of particles with |δ|>LMA in Touschek MC by reducing the
longitudinal cutoff per element where needed:

    nz_eff = min(nz, 0.9 * min(|δN|, δP) / σδ)

This ensures sampled δ stays strictly within the LMA,
avoiding pathological small-angle events with huge weights that distorted
RMC/RP and Touschek lifetime estimates.

- Adjustment is local: only elements with tight acceptance are clamped
- Prints a warning when nz_eff < nz
- Restores stable RMC/RP≈1 and meaningful lifetime results
for ii, nn in enumerate(tab_bends_quads.name):
tscatter_name = f'TScatter_{ii}'
env.elements[tscatter_name] = xf.TouschekScattering()
line.insert(tscatter_name, at=0.0, from_=nn)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More efficient implementation:

insertions = []
for ii, nn in enumerate(tab_bends_quads.name):
    tscatter_name = f'TScatter_{ii}'
    env.elements[tscatter_name] = xf.TouschekScattering()
    insertions.append(env.place(tscatter_name, at=0.0, from_=nn))
line.insert(insertion)

Comment on lines +87 to +88
needs_aperture = np.unique(tab.element_type)[
~np.isin(np.unique(tab.element_type), ["", "Drift", "Marker"])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use this as alternative:

 tt.rows.match_not(element_type='Drift.*|Marker')

# Evaluate local momentum aperture at the touschek scattering centers
momentum_aperture = line.momentum_aperture(
# twiss=tw,
include_type_pattern="TouschekScattering",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support only element names, and select them using the line table


touschek_manager = xf.TouschekManager(
line,
momentum_aperture=df_momentum_aperture,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say that all our API takes tables and not Pandas dataframe

Comment on lines +167 to +189

touschek_manager.initialise_touschek()

touschek_elements = tab.rows[tab.element_type == 'TouschekScattering'].name

line.discard_tracker()
line.build_tracker(_context=xo.ContextCpu(omp_num_threads='auto'))

particles_list = []
for ii in range(len(touschek_elements)):
element = touschek_elements[ii] # xf.TouschekScattering
s_start_elem = tab.rows[tab.name == element].s[0]

# Touschek!
particles = line[element].scatter()

# Track!
print(f"\nTrack particles scattered at {element} at s = {s_start_elem}")
line.track(particles, ele_start=element, ele_stop=element, num_turns=nturns, with_progress=1)

particles_list.append(particles)

particles = xt.Particles.merge(particles_list)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain with comments what different steps are doing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need, lets' put the acknowledgment in the file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once merged this should go in the Xsuite docs

Comment on lines +5 to +10
If you publish results obtained with this routine, please cite:

- M. Borland, “elegant: A Flexible SDDS-Compliant Code for Accelerator Simulation,” APS LS-287 (2000).

- A. Xiao and M. Borland, “Monte Carlo simulation of Touschek effect,” *Phys. Rev. ST Accel. Beams* **13**, 074201 (2010).
DOI: 10.1103/PhysRevSTAB.13.074201
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put these references in the Python docstring so that they are visible in the documentation

Comment thread MANIFEST.in
# Include the license file
# Include the license files
include LICENSE.txt
recursive-include xfields/third_party *LICENSE*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove

Comment thread MANIFEST.in

recursive-include xfields *.h
recursive-include xfields *.clh
recursive-include xfields *.clh No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re add new line at the end

Copy link
Copy Markdown
Member

@giadarol giadarol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a Touscheck chapter in Physics Guide

CLASSICAL_ELECTRON_RADIUS = physical_constants['classical electron radius'][0]

class TouschekCalculator:
def __init__(self, manager):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring

break


class TouschekManager:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants