Example code to read a file, apply a transformation and plot before and after.
More...
Example code to read a file, apply a transformation and plot before and after.
2 \namespace xboa::examples::Example_4
4 Example code to read a file, apply a transformation and plot before and after
6 \include xboa/examples/Example_4.py
28 target_beta = 420.*Common.units[
'mm']
31 print '========= XBOA example 4 ========='
35 Now we start manipulating the data. The idea here is to take particles from
36 one system, apply a match condition so that they can be used in another system.
37 Aim is to mimic an ideal transfer line.
39 print "Loading file... "
40 bunch_list = Bunch.new_list_from_read_builtin(
'g4mice_virtual_hit', sys.prefix+
'/share/xboa/data/Sim.out.gz')
44 bunch = bunch_list[-1]
47 bunch.cut({
'energy':400}, operator.ge)
48 bunch.cut({
'energy':150}, operator.le)
50 bunch.cut({
'amplitude x y':90}, operator.ge)
51 bunch.root_scatter_graph(
't',
'energy',
'ns',
'MeV', include_weightless=
False)
53 bunch.period_transformation( bunch[0][
't'], 0.20125*Common.units[
'GHz'])
54 bunch.root_scatter_graph(
't',
'energy',
'ns',
'MeV', include_weightless=
False)
57 print "Longitudinal phase space covariance matrix\n",bunch.covariance_matrix([
't',
'energy'])
58 print 'Longitudinal RMS beta ',bunch.get_beta([
'ct']),
'mm'
59 print 'Longitudinal RMS alpha ',bunch.get_alpha([
'ct'])
60 print 'Longitudinal RMS gamma ',bunch.get_gamma([
'ct']),
'mm^{-1}'
61 print 'Longitudinal RMS emittance',bunch.get_emittance([
'ct']),
'mm'
65 bunch.set_geometric_momentum(
True)
68 emit_trans = bunch.get_emittance([
'x'])
69 print '\nInput phase space (x,x\') covariance matrix\n',bunch.covariance_matrix([
'x',
'x\''])
70 print 'Input RMS beta ',bunch.get_beta([
'x']),
'mm'
71 print 'Input RMS alpha ',bunch.get_alpha([
'x'])
72 print 'Input RMS gamma ',bunch.get_gamma([
'x']),
'mm^{-1}'
73 print 'Input RMS emittance',bunch.get_emittance([
'x']),
'mm'
76 bunch.root_scatter_graph(
'x',
'x\'',
'MeV/c',
'MeV/c', include_weightless=
False)
77 bunch.root_histogram(
'amplitude x',
'mm')
80 target_ellipse = Bunch.build_ellipse_2d(target_beta, target_alpha, emit_trans, bunch.mean([
'p'])[
'p'], Common.pdg_pid_to_mass[13],
True)
81 bunch.transform_to([
'x',
'x\''], target_ellipse, mass_shell_variable=
'energy')
84 print '\nNow I will make a transformation to target (x,x\') covariance matrix\n',target_ellipse
85 print 'Target RMS beta ',target_beta,
'mm'
86 print 'Target RMS alpha ',target_alpha
87 print 'Target RMS gamma ',(1.+target_alpha**2)/target_beta,
'mm^{-1}'
88 print 'Transformation will conserve emittance by construction'
92 print "Transformed phase space (x,x\') covariance matrix\n",bunch.covariance_matrix([
'x',
'x\''])
93 print 'Transformed RMS beta ',bunch.get_beta([
'x']),
'mm'
94 print 'Transformed RMS alpha ',bunch.get_alpha([
'x'])
95 print 'Transformed RMS gamma ',bunch.get_gamma([
'x']),
'mm^{-1}'
96 print 'Transformed RMS emittance',bunch.get_emittance([
'x']),
'mm'
100 bunch.root_scatter_graph(
'x',
'x\'',
'MeV/c',
'MeV/c', include_weightless=
False)
101 bunch.root_histogram(
'amplitude x',
'mm')
104 print 'Mean z at start',bunch.mean([
'z'])[
'z']
105 bunch.translate({
'z':-bunch.mean([
'z'])[
'z']})
106 print 'Mean z at end ',bunch.mean([
'z'])[
'z']
109 bunch.hit_write_builtin(
'icool_for003',
'for003_test.dat',
'for003 file generated by XBOA')
111 print 'Press <return> key to finish'
113 Bunch.clear_global_weights()