Skip to content

Conversation

@feliponelguapon
Copy link
Collaborator

I added some classes to be able to simulate an achromatic spectrometer. The tracking is done with the standard easy equations, I will work on another version which uses ImpactX.

Parameters
----------
length : float, optional
Length of the source [m]. Default is 0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great job adding the documentation! Just please put the unit on the first line of the parameter declaration. E.g. length : [m] float, optional.

Parameters
----------
_ : None, optional
Placeholder parameter. Default is None.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Variables in text should be inside ````. E.g. Default is None.

Returns
-------
Beam
The tracked beam object.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beam object


# ==================================================
# Filter out particles whose z < z_cutoff for testing instability etc.
def z_filter(self, beam):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks strangely familiar. Is it copied from another file? If so, perhaps we should consider moving it to e.g. utilities to avoid duplication.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed here I just copied the source_basic.py and added the added input energy_comb_delta and the function reorder_particle_energies(self, beam, plot=False). Thinking about it more, I guess it would make sense to inherit from it and add these two things to the child only?

@ben-c-2013
Copy link
Collaborator

Looks great overall! Could you please also write some tests? There are already some tests under the tests folder for you to look at. Otherwise, there is also this pull request #49, which should be merged into main soon.

@kyrsjo
Copy link
Collaborator

kyrsjo commented Apr 3, 2025

I made together with @ben-c-2013 a PR to this branch: #51

The point is to undo some of the changes you did to whitespace in beam.py, which would make mergings to main unneccesarily complicated since many people are working on this file.

Please consider merging this to your branch ASAP - but remember commit / push or drop or stash any uncommited local changes before merging that here on github.

…er-whitespace_stays_put_for_now

Acromatic spectrometer whitespace stays put for now
Merging because main was updated
self.remove_charge_outside(beam, plot=False)

# drift half the distance
beam.transport(self.length/2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

In case of a "thick" plasma lens, where the beam position in the lens changes significantly as the particle passes through the lens, it is probably needed to have several slices. This is the case at CLEAR due to low beam energy.

I would strongly recommend to have a parameter for setting the number of kicks used to track, i.e. for approximating the change of position and momentum on the particles.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For quads there is some literature for how to optimally slice, I think this is a good reference:
https://cds.cern.ch/record/165372/files/p35.pdf
The TEAPOT algorithm is implemented in MadX's MAKETHIN command if I remember correctly. There has probably also been updates by Helmut Burkhardt since TEAPOT was originally written - I think there is an IPAC paper somewhere at least.

Copy link
Collaborator

Choose a reason for hiding this comment

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

However as a first go, I would just add a loop over the number of slices N, then for each slice do

  1. drift
  2. kick
  3. drift
    where the drift length is L/N and the kick integral length is also L/N.

One can be slightly more clever and combine the "abutting" drifts, for slightly better performance, but I doubt it matters.

I implented something like this here, for JT model:
https://gitlab.cern.ch/CLEAR/CLEAR_DAN/-/blob/master/utilities/tracking_thick_JT.m?ref_type=heads#L79

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, is this somewhat overlapping with what @Hektor1201 is working on?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, the idea is that Felipe does this simple one first, and then we switch it to using Hektor’s thick-lens implementation when that is ready. In the meantime, Felipe implements the achromatic spectrometer also in ImpactX.

@ax3l
Copy link
Collaborator

ax3l commented Sep 26, 2025

Awesome!

Just because this PR is still open, let me cross link our ImpactX example:
https://impactx.readthedocs.io/en/latest/usage/examples/achromatic_spectrometer/README.html

We discussed (and implemented locally) at EAAC that we should add a dipedge element to make the sector bend a rectangular bend, for realism.
BLAST-ImpactX/impactx#1160

@kyrsjo
Copy link
Collaborator

kyrsjo commented Nov 11, 2025

@feliponelguapon what is the status of this one?

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.

6 participants