BMAD based computer excercises

g2_tracking and first_turn are programs that you will use to explore beam dynamics of the g-2 storage ring. Both are based on the Bmad library of accelerator modeling routines, and field maps computed with Opera, Poisson, FEMME, etc. The layout of the injection channel and ring are defined in the Bmad lattice file(s).

The program first_turn is used to track a single particle, compute closed orbit and twiss parameters, tunes, chromaticity, etc. Parameters are initialized in the lattice file bmad_ring.lat and on the command line.

g2_tracking is used to propagate a single particle or a distribution of particles. Tracking is initiated at the end of the M5 line or in the ring. Input parameters are set in an initialization file named input.dat as well as the lattice file bmad_g2_tracking.lat

Update USPAS computer with latest bmad

Characterize the ring

Using first_turn
  1. Compute and plot the closed orbit for the magic momentum
    1. Compute and plot the closed orbit for fractional momentum offsets Δp/p = -0.003,-0.002 ... 0.003 Instructions
    2. Use the momentum dependent closed orbit data to determine the dispersion (dx/dp)
    3. Compute the closed orbit for the asymmetric quad voltage corresponding to the start of the quad ramp and compare to the end of scraping orbit. (Vary quad voltages as required in the bmad_ring.lat file)
    4. Determine the dependence of the closed orbit on a radial component of the field.
  2. Compute and plot horizontal and vertical β functions and tunes and dispersion (η). Is the dispersion consistent with your earlier calculation?
    1. Compute beta functions and tunes for start of scraping quad voltages
    2. Determine dependence of beta functions and tunes on quad voltage. Plot tune vs voltage. Plot betatron frequency vs voltage
    3. Compute and plot tunes and betatron frequency vs momentum.
  3. The beam is focused to a waist to clear the narrow inflector aperture.
    1. Estimate values of horizontal and vertical β required at the inflector to insure that 95% of the particles in an injected distribution with emittance ε= 40 mm-mrad clear the inflector (28mm full width, 56mm full height). Then propagate β around the ring. Compare the mismatched β function with your result from above.
    2. Estimate the value of the dispersion at the inflector to insure that 95% of the particles in an injected distribution with 2% momentum spread clear the aperture. Propagate that value of dispersion around the ring and compare to the closed ring dispersion computed above.

Spin tracking

Using g2_tracking
  1. Propagate polarization of a single muon through many turns. The NAFF algorithm is used to compute spin tunes. Keep in mind that in order to evaluate systematics we need to measure spin tune. with ~10 part per billion precision. How many turns do we need to track to achieve that precision? (Use initialization file input_ST.dat) Instructions The polarization on each turn is recorded in the file single_particle_tbt.dat
  2. Track a single particle, for however many turns is required to determine spin tune with part per billion precision, with momenta -0.002,-0.001,...,0.002 and plot omega_a vs momentum. Compare the change in omega_a for each momentum to the contribution from average (βXE) along the particle trajectory. Plot the running average of (βXE) and translate to Ce (E-field correction) using BetaCrossE-single-uspas.gnu
  3. Track a single on momentum particle with initial vertical displacements -0.035,-0.025,...,0.035 m and determine dependence of omega_a on vertical amplitude. Compare the shift in omega_a for each vertical amplitude to the average (β•B)β contribution.

Track a distribution

Using g2_tracking
  1. Create a distribution of 1000 muons with εxy = 40 mm-mrad, Δp/p=0 and 120ns bunch length. Propagate for 400 microseconds. Plot and characterize the fast rotation signal and its fourier transform. (Use initialization file input_FR1.dat)Instructions
  2. Create a distribution of 1000 muons with εxy = 40 mm-mrad, Δp/p=0.002. Characterize the fast rotation signal and use FFT to reconstruct the frequency distribution from the FR data. How is the frequency distribution related to the momentum distribution? (Use input_FR2.dat)


Programs

First_turn

The program first_turn reads the lattice field bmad_ring.lat that defines the geometry of the ring, quads, fields, collimators, etc.

Output: Twiss parameters and closed orbit are written to the file beta_eta_x_y.dat

Instructions

  1. Create a working directory. < mkdir a_name >
  2. Go down to that directory < cd a_name >
  3. Copy the lattice file bmad_ring.lat to the directory < cp <PATH>/g-2/documentation/uspas/bmad_ring.lat . >
  4. Create soft links to all reference files
  5. To run the program first_turn type < ./first_turn >
  6. Here are a couple of examples
    1. In this example we set intial values of twiss parameters to those of the closed ring and the trajectory to the closed orbit
      -bash-4.2$ ./first_turn
       Lattice file name ? (default= bmad.)bmad_ring.lat 
       lat_file = bmad_ring.lat                                                                                                                               
       lat_file = bmad_ring.lat                                                                                                                               
      [INFO] bmad_parser:
          Parsing lattice file(s). This might take a minute or so...
      [INFO] bmad_parser:
          Created new digested file
       Fractional momentum offset ? 0.001
       Fractional momentum offset =   1.0000E-03
      [WARNING] twiss_from_mat6:
          1-TURN MATRIX MARGINALLY SYMPLECTIC WITH SYMPLECTIC ERROR OF:     0.0286
                           Q_x         Q_y      beta_x      beta_y     alpha_x     alpha_y       eta_x
      Closed ring:      0.9505      0.3157      7.6251     22.1736      0.0382     -0.0156      7.9358
       Initialize twiss ,(or use closed ring values ) (y/n)  ? n
       Closed orbit:  9.8786E-03 -2.9061E-04 -2.4785E-03 -9.5512E-07  0.0000E+00  1.0000E-03
       Initialize orbit, (or use closed orbit values) (y/n) ? n
      [WARNING] twiss_from_mat6:
          1-TURN MATRIX MARGINALLY SYMPLECTIC WITH SYMPLECTIC ERROR OF:     0.0338
      [WARNING] twiss_from_mat6:
          1-TURN MATRIX MARGINALLY SYMPLECTIC WITH SYMPLECTIC ERROR OF:     0.0323
       The length is      44.6790
      -bash-4.2$ 
      
    2. Here is a sample session where we set intial values of twiss parameters to: betax=2, betay=10, alphax=0, alphay=0 and and the start of the trajectory to x=0.. px=.,y=0,py=0
      -bash-4.2$ ./first_turn
       Lattice file name ? (default= bmad.)bmad_ring.lat
       lat_file = bmad_ring.lat                                                                                                                               
       lat_file = bmad_ring.lat                                                                                                                               
       Fractional momentum offset ? 0.001
       Fractional momentum offset =   1.0000E-03
      [WARNING] twiss_from_mat6:
          1-TURN MATRIX MARGINALLY SYMPLECTIC WITH SYMPLECTIC ERROR OF:     0.0286
                           Q_x         Q_y      beta_x      beta_y     alpha_x     alpha_y       eta_x
      Closed ring:      0.9505      0.3157      7.6251     22.1736      0.0382     -0.0156      7.9358
       Initialize twiss ,(or use closed ring values ) (y/n)  ? y
      Type betax, betay, alphax, alphay, etax (separate values with comma)
      2. 10. 0. 0. 0.
       Closed orbit:  9.8786E-03 -2.9061E-04 -2.4785E-03 -9.5512E-07  0.0000E+00  1.0000E-03
       Initialize orbit, (or use closed orbit values) (y/n) ? y
      x, px, y,py (separate values with comma)
      0. 0. 0. 0.
      Initial coordinates =   0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  1.0000E-03
       The length is      44.6790
      

    g2_tracking

    Inputs to g2_tracking include:

    Output:

    • A subdirectory with name corresponding to the date and time is created for each run and output files are written to that directory
      • Spin tunes (and cycltron tune) are in spin_tunes.dat
      • The running average of (β•B)β (along with phase space coordinates, etc.) are written to BetaCrossE_turn.dat
      • Turn by turn coordinates of single particles are written to single_particle_tbt.dat
      • Element by element coordinates of single particles are written to single_particle_by_element.dat
      • Turn by turn (and element by element) moments of a distribution are written to Beam_moments_tbt.dat (Beam_moments_by_element.dat
      • Instructions (spin tracking)

        1. Create a working directory. < mkdir a_name >
        2. Go down to that directory < cd a_name >
        3. Copy the lattice file bmad_g2_tracking.lat to the directory < cp < cp <PATH>/g-2/documentation/uspas/bmad_g2_tracking.lat . >
        4. Copy the appropriate input file from <PATH>/g-2/documentation/uspas/ to input.dat in your working directory < cp <PATH>/g-2/documentation/uspas/input_ST.dat input.dat >
        5. Create soft links to all reference files by typing < <PATH>/g-2/softlink_uspas >
        6. To run the program g2_tracking type < ./g2_tracking >
        7. The relevant data files spin_tunes.dat and BetaCrossE_turn.dat will appear in the subdirectory yyyymmdd_hhmmss
          
          
          
      • Instructions (fast rotation)

        1. Create a working directory. < mkdir a_name >
        2. Go down to that directory < cd a_name >
        3. Copy the lattice file bmad_g2_tracking.lat to the directory < cp <PATH>/g-2/documentation/uspas/bmad_g2_tracking.lat . >
        4. Copy the appropriate input file from <PATH>/g-2/documentation/uspas/ to input.dat in your working directory < cp <PATH>/g-2/documentation/uspas/input_FR1.dat input.dat >
        5. Create soft links to all reference files by typing < <PATH>/g-2/softlink_uspas >
        6. To run the program g2_tracking type < ./g2_tracking >
        7. The time binned data is written to Time_Dep_Moments_at_END.dat. The file contains the number of muon hits in an imaginary detector plane in each time bin along with the moments of the distribution. This is the fast rotation data.

Plotting

The first_turn and g2_tracking programs write output to text files. You should use whatever software is most familiar to plot the data.
If you like, you can use the gnuplot plotting package. It is installed on the USPAS computers and it is easy to use. Here are some instructions.
(β•B)β