anchor.diff:  
     ! Adding the orbit offset at start of ring
     if(do_thisdis /= 0 .or. radial) then
  -    xv1(1:napx) = c1e3 * xv1(1:napx) + torbx(1)
  -    yv1(1:napx) = c1e3 * yv1(1:napx) + torbxp(1)
  -    xv2(1:napx) = c1e3 * xv2(1:napx) + torby(1)
  -    yv2(1:napx) = c1e3 * yv2(1:napx) + torbyp(1)
  +    xv1(1:napx) = c1e3*xv1(1:napx) + torbx(1)
  +    yv1(1:napx) = c1e3*yv1(1:napx) + torbxp(1)
  +    xv2(1:napx) = c1e3*xv2(1:napx) + torby(1)
  +    yv2(1:napx) = c1e3*yv2(1:napx) + torbyp(1)
     end if
   
     call part_updatePartEnergy(1,.false.)
  
positive.code:     pj  = ejv(j)/c1e3
  
      if(part_abs_pos(j) == 0 .and. part_abs_turn(j) == 0) then
        nspx         = sqrt(abs(gammax*(xj)**2 + two*talphax(ie)*xj*xpj + tbetax(ie)*xpj**2)/c_emitx0_collgap)
        nspy         = sqrt(abs(gammay*(yj)**2 + two*talphay(ie)*yj*ypj + tbetay(ie)*ypj**2)/c_emity0_collgap)
        sum_ax(ie)   = sum_ax(ie) + nspx
        sqsum_ax(ie) = sqsum_ax(ie) + nspx**2
        sum_ay(ie)   = sum_ay(ie) + nspy
  
negative.code:   nsig        = nsig + gap_rms_error(icoll)
    xmax        = nsig*sqrt(bx_dist*c_emitx0_collgap)
    ymax        = nsig*sqrt(by_dist*c_emity0_collgap)
    xmax_pencil = (nsig + pencil_offset)*sqrt(bx_dist*c_emitx0_collgap)
    ymax_pencil = (nsig + pencil_offset)*sqrt(by_dist*c_emity0_collgap)
    xmax_nom    = cdb_cNSig(icoll)*sqrt(cdb_cBx(icoll)*c_emitx0_collgap)
    ymax_nom    = cdb_cNSig(icoll)*sqrt(cdb_cBy(icoll)*c_emity0_collgap)
  
    cry_proc(:) = -1
  
    calc_aperture = sqrt(    xmax**2*cRot**2 +     ymax**2*sRot**2)
    nom_aperture  = sqrt(xmax_nom**2*cRot**2 + ymax_nom**2*sRot**2)
  
    ! Get x and y offsets at collimator center point
    x_pencil(icoll) = xmax_pencil * cRot
    y_pencil(icoll) = ymax_pencil * sRot
  
    ! Get corresponding beam angles (uses xp_max)
    xp_pencil(icoll) = (((-one*sqrt(c_emitx0_collgap/tbetax(ie)))*talphax(ie))*xmax)/sqrt(c_emitx0_collgap*tbetax(ie))
    yp_pencil(icoll) = (((-one*sqrt(c_emity0_collgap/tbetay(ie)))*talphay(ie))*ymax)/sqrt(c_emity0_collgap*tbetay(ie))
    xp_pencil0 = xp_pencil(icoll)
    yp_pencil0 = yp_pencil(icoll)
  
    pencil_dx(icoll) = sqrt(xmax_pencil**2 * cRot**2 + ymax_pencil**2 * sRot**2) - calc_aperture
  
    ! Added condition that pencil_distr /= 3 in order to do the tilt
    if(icoll == ipencil .and. iturn == 1 .and. pencil_distr /= 3) then
      ! To align the jaw/pencil to the beam always use the minus regardless which
      ! orientation of the jaws was used (symmetric/antisymmetric)
      c_tilt(1) = c_tilt(1) + (xp_pencil0 * cRot + sRot * yp_pencil0)
      c_tilt(2) = c_tilt(2) - (xp_pencil0 * cRot + sRot * yp_pencil0)
      write(lout,*) "INFO> Changed tilt1  ICOLL  to  ANGLE  ", icoll, c_tilt(1)
      write(lout,*) "INFO> Changed tilt2  ICOLL  to  ANGLE  ", icoll, c_tilt(2)
    end if
  