xboa
Functions
xboa.examples.closed_orbit Namespace Reference

Example code to find a closed orbit. More...

Functions

def get_tracking_object
 Create a tracking object. More...
 
def find_closed_orbit
 Find the closed orbit in x and y. More...
 

Detailed Description

Example code to find a closed orbit.

1 """
2 \namespace xboa::examples::closed_orbit
3 
4 Example code to find a closed orbit
5 
6 \include xboa/examples/closed_orbit.py
7 """
8 
9 import numpy
10 import xboa.common as common
11 from xboa.hit import Hit
12 from xboa.tracking import MatrixTracking
13 from xboa.algorithms import EllipseClosedOrbitFinder
14 
15 
17  """
18  Create a tracking object. This tracking object uses a list of matrices to
19  generate tracking. The tracking goes like
20  - x is a conventional phase space ellipse
21  - y has phase advance of exactly pi
22  - t has phase advance is complex i.e. on a resonance.
23  Each cell or turn we advance through another transfer matrix. The closed
24  orbit is generated by a hard coded offset.
25 
26  Return value is a tuple consisting of a hit object on the closed_orbit and
27  a tracking object that will propagate hit objects through the matrices.
28  """
29  number_of_turns = 5
30  # x is conventional ellipse
31  # y is phase advance = pi
32  # t is phase advance = complex
33  data = [[1.0, 0.5, 0.0, 0.0, 0.0, 0.0],
34  [-0.5, 0.75, 0.0, 0.0, 0.0, 0.0],
35  [0.0, 0.0, 0.0, -1.0, 0.0, 0.0],
36  [0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
37  [0.0, 0.0, 0.0, 0.0, 2.0, 2.0],
38  [0.0, 0.0, 0.0, 0.0, 2.0, 2.5]]
39  matrix = numpy.matrix(data)
40  matrix_list = [matrix**(i+1) for i in range(number_of_turns)]
41  offset = numpy.matrix([10., 7., 0., 0., 0., 1000.])
42  offset_list = [offset]*number_of_turns
43  offset_in = numpy.matrix([10., 7., 0., 0., 0., 1000.])
44  tracking = MatrixTracking(matrix_list,
45  offset_list,
46  offset_in)
47  closed_orbit_hit = Hit.new_from_dict({'x':10., 'px':7., 'energy':1000.,
48  'pid':2212, 'mass':common.pdg_pid_to_mass[2212]},
49  'pz')
50  return closed_orbit_hit, tracking
51 
52 
53 def find_closed_orbit():
54  """
55  Find the closed orbit in x and y
56  """
57  print """
58  We start with a hit displaced from the closed orbit by 1 mm in x and y,
59  track it through the lattice and examine the output, try to fit an ellipse
60  to the output. The iteration finishes if either the signal noise is larger
61  than the ellipse, we reach the numerical precision limit of the numpy
62  library or we reach the maximum number of iterations (default 100).
63  """
64  closed_orbit_hit, tracking = get_tracking_object()
65  test_hit = closed_orbit_hit
66  test_hit["x"] += 1.
67  test_hit["y"] += 1.
68  co_finder = EllipseClosedOrbitFinder(tracking, test_hit)
69  co_generator = co_finder.find_closed_orbit_generator(["x", "x'"],
70  10,
71  max_iterations=10)
72  canvas = None
73  for i, my_co in enumerate(co_generator):
74  print "gen", i
75  canvas, hist, ellipse, graph = my_co.plot_ellipse(
76  "x", "x'",
77  "mm", "", canvas=canvas)
78 
79 if __name__ == "__main__":

Function Documentation

def xboa.examples.closed_orbit.get_tracking_object ( )

Create a tracking object.

This tracking object uses a list of matrices to generate tracking. The tracking goes like

  • x is a conventional phase space ellipse
  • y has phase advance of exactly pi
  • t has phase advance is complex i.e. on a resonance. Each cell or turn we advance through another transfer matrix. The closed orbit is generated by a hard coded offset.

Return value is a tuple consisting of a hit object on the closed_orbit and a tracking object that will propagate hit objects through the matrices.

Definition at line 30 of file closed_orbit.py.

Referenced by xboa.examples.closed_orbit.find_closed_orbit().

def xboa.examples.closed_orbit.find_closed_orbit ( )

Find the closed orbit in x and y.

Definition at line 59 of file closed_orbit.py.

References xboa.examples.closed_orbit.get_tracking_object().