Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "turn" input to atpass #376

Merged
merged 9 commits into from
Mar 31, 2022
Merged

Add a "turn" input to atpass #376

merged 9 commits into from
Mar 31, 2022

Conversation

lfarv
Copy link
Contributor

@lfarv lfarv commented Feb 25, 2022

Until now, the default passmethod for cavities is CavityPass. #372 (pending) will change it for RFCavityPass.
Unlike CavityPass, RFCavityPass can handle multi-turn tracking with a RF frequency different from nominal. For this, it has to compute the total path length since the beginning of tracking ("turn 0"). This is done by internally maintaining a "turn counter". This has a drawback: since the turn counter is set to zero on each call to atpass, splitting a long tracking is wrong. A statement like:

lattice_pass(ring, particle, nturns=100)

is correct, but the sequence:

for turn in range(100):
    lattice_pass(ring, particle, nturns=1)

is wrong because the turn counter is reset to zero, thus re-synchronising the particle with the RF on each turn. The same applies to the Matlab equivalent ringpass. In such a case, we are back to the behaviour of CavityPass!

This PR adds a new keyword turn to lattice_pass, allowing to handle the "turn counter" externally, so that the sequence:

for turn in range(100):
    lattice_pass(ring, particle, nturns=1, turn=turn)

is now correct.

@lfarv lfarv added Matlab For Matlab/Octave AT code Python For python AT code labels Feb 25, 2022
@lfarv lfarv changed the title Turn number Add a "turn" input to atpass Feb 25, 2022
@lfarv lfarv marked this pull request as draft February 25, 2022 11:03
@lfarv lfarv marked this pull request as ready for review February 25, 2022 14:21
Copy link
Contributor

@swhite2401 swhite2401 left a comment

Choose a reason for hiding this comment

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

Indeed this is necessary!

@swhite2401
Copy link
Contributor

I have a question: what happens if we input the wrong counter, i.e. if turn is non zero but inconsistent with ct drift?

@swhite2401
Copy link
Contributor

Wouldn't it be more convenient to have an input argument keep_counter that would just increment instead of resetting to zero at each atpass call?

@lfarv
Copy link
Contributor Author

lfarv commented Feb 28, 2022

The way the absolute path length is computed is:

dct (lengthening with respect to the reference) + turn * circumference (absolute path length of the reference).

The location of the cavity along the circumference does not matter when β=1: the time reference for a cavity at any location is the passage of the reference particle.

So if you enter a wrong turn number,

  • on the nominal frequency, the circumference is a multiple of the RF wave length (by definition), so turn does not matter. That's why CavityPass works,
  • if not on the nominal frequency, then you get garbage ! The starting point does not matter, 0 just means that you start in phase with the RF. The critical point is that it increases by 1 on each turn.

Looking at the examples given for DA computation or Hassinski, a turn argument is the easiest to use. In different cases, keep_counter could be convenient… So we can provide both ! (in 3 weeks…)

@lfarv
Copy link
Contributor Author

lfarv commented Mar 24, 2022

Added a keep_counter keyword (python) and a KeepCounter flag (Matlab).
This is an alternative to the turn keyword to ensure the continuity of the turn number for splitted tracking.

So now one can choose between:

for turn in range(100):
    lattice_pass(ring, particle, nturns=1, turn=turn)

and:

lattice_pass(ring, particle, nturns=1)
for turn in range(1,100):
    lattice_pass(ring, particle, nturns=1, keep_counter=True)

@lfarv
Copy link
Contributor Author

lfarv commented Mar 30, 2022

Any more comment ?

@swhite2401
Copy link
Contributor

Any more comment ?

All good for me

@lfarv lfarv merged commit 685a000 into master Mar 31, 2022
@lfarv lfarv deleted the turn_number branch March 31, 2022 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Matlab For Matlab/Octave AT code Python For python AT code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants