Hallc optics optim

From HallCWiki
Jump to: navigation, search

New version of the Hall C optics optimization code. This is a slimmed down version of the old code. In addition, the new code takes into account the correction in the optics matrix for the vertical position of outgoing particle at the Z=0 optics axis when optimizing the xptar and delta matrix elements. THe optimization is divided into two parts. First, one uses PAW kumacs to set cuts on ntuples to define good events. The cuts are written to files and used by the optimization program. Second, one runs the optimization code. Presently the new code is not setup for delta optimization.

Doing an optimization

  • Replay the optics data.
  • If needed you can filter the data ntuple further using kumacs in the filter subdirectory. Presently the filter subdirectory has two Gep3 data files.
  • Edit pkumacs/set_xs_ys_cuts.kumac to set the spectrometer central angle, number of foils and z-position of the foils for each run.
  • Run paw++ and exec pkumacs/set_xs_ys_cuts.kumac nrun=#####
    • First one identifies each foil by placing a polygon cut on ytar vs xfp . For each foil, the kumac creates a file hsytar_hsxfp_nmat_run#_foil#.dat in the subdirectory dat_files with the points of the polygon. If the file already existed, then the cut is plotted on the histogram and the user can accept the cuts or create a new one.
    • Using the ytar vs xfp cut to identify, the script plots the xptar and yptar projected to the collimator and shows the known hole positions. Cut on the histogram to make a box around the xptar/yptar data to identify it with the appropriate sieve slit hole.
    • The script creates a file xsieve_ysieve__nmat_run#_foil#.dat with the known x and y sieve hole positions and the four corners of the boxes.

Analyze Directory

  • Available at /group/hallc/mkj/optimization_hallc_optics/analyze
  • Files and Directories
    • optimize is symbolic link to ../source_code/optimize.
    • run_optimize is a script which links input.db to proper file

Optimization Source Code

  • Code is available at /group/hallc/mkj/optimization_hallc_optics/source_code. On JLab ifarml64 machines, define the proper cernlib by executing setup cernlib/2005 before compiling using make .
  • optimize.f
    • Main program calls subroutines read_input, read_matrix, fit_init, fit_matrix.
  • read_input.f
    • reads in the input file.
    • Presently hardcoded to use the input filename as input.db
  • read_matrix.f
    • Reads in the standard replay optics matrix data file
    • Hardcode the constant offsets terms for xp,yp,y and delta.
  • fit_init.f
    • Hardcode collimator distance zcol = 166.+1.6
    • Hardcode dflag=0 . Set dflag=1 for delta optimization.
    • Hardcode the spec_type =1 for HMS which assumes 81 sieve holes. spec_type =2 could be used for SHMS. Need to have this a part of input.db
    • Hardcoded to look for variables HSXPFP,HSYTAR,HSXPTAR, HSYPTAR, gbeam_y,eventID,xtar in the ntuple.
    • If doing delta optimization set up for ep elastics. Assumes that in the ntuple the energy loss for the beam and scattering electron will be the 13th and 14th variable.
    • Loops through the ntuples using 2d ytar/xfp and xsieve/ysieve cut to select events. Hardcoded to accept a maximum of 200 events per hole and 100000 events total.
    • Fills arrays
      • Focal plane quantities pts(i,ntotal) = i=1,4 (for xfp,xpfp,yfp,ypfp) for each event
      • Known y (ydata) , xp (thdata) and yp (phdata) values.
zzero(ntotal) = ztarpos(k)*dcos(spec_ang)/100.0
ydata(ntotal) = ztarpos(k)*dsin(spec_ang)/100.0
If SHMS need to set ydata(ntotal) =−ztarpos(k)*dsin(spec_ang)/100.0
thdata(ntotal) = xsr(k,nh_found)/(zcol−zzero(ntotal)*100)
phdata(ntotal) = (ysr(k,nh_found)−ydata(ntotal)*100)/(zcol−zzero(ntotal)*100)
  • fit_matrix.f
    • Not setup for delta optimization
    • Uses the read−in optics matrix to calculate the target quantities.
      • First determine target xp,y,yp and delta using xtar=(−1.)*gbeam_y(nd)/100
      • With estimate of target xp,y,yp calculating xtar as ztemp= ytar* ( cos(spangle) / tan(spangle − yptar) + sin(spangle)) and xtar= hut(5) = (−1.)*gbeam_y(nd)/100 − xptar*ztemp*cos(spangle)
      • xtar correction is for xptar and delta calculation determine only target xp and delta again and keep track in "psum" of the contribution to xp and delta from the optic matrix elements which use xtar coefficients.
      • The optic matrix elements to be fit are all terms except those that use xtar. Fill array "fit_term" which is (xfp)^i*(xpfp)^j*(yfp)^l*(ypfp)
      • The array "fit_data" is filled with with the known target xp,y or yp (thdata,ydata,phdata) depending on which target quantity is be fitted. For xp fit , "psum" is subtracted from thdata.
      • Calculates the average center position for each sieve hole using original matrix and compares to known position.
    • Calls subroutine svdfit
    • Writes new optics matrix to a file
    • Calculates the average center position for each sieve hole using new matrix and compares to known position.
  • svdfit.f
    • Called by fit_matrix.f
    • Least squares fitting routine
    • Fitted coefficients stored in "fit_parm" array and determined in svbksb subroutine.