anchor.diff:    z  = z - zp*s_rot
     s  = zero
   
  +  write(*,*) 'x after reference change', x, xp
  +
     ! Check that particle hit the crystal
     if(x >= zero .and. x < c_xmax) then
   
  
positive.code:       A_F = alpha_F**2 + one
        B_F = two*alpha_F*beta_F - two*c_rcurv
        C_F = beta_F**2 -c_xmax*(c_xmax-two*c_rcurv)
      endif
      
      x_F = (-B_F-sqrt(B_F**2-four*A_F*C_F))/(two*A_F)
      s_F = alpha_F*x_F + beta_F
  
    endif
  
    ! MISCUT fourth step: deflection and length
    a = sqrt(s_F**2+(x-x_F)**2)
    tchan = acos_mb((two*r**2-a**2)/(two*r**2))
    L_chan = r*tchan
    write(*,*) "Results", tchan, L_chan
  
    xp_rel = xp - c_miscut
  
  
negative.code:   else
  
      if(x < zero) then ! Crystal hit from below
        write(*,*) 'CHECK', x
        xp_tangent = sqrt((-(two*x)*c_rcurv + x**2)/c_rcurv**2)
        write(*,*) 'tangent', xp_tangent, xp
      else ! Crystal hit from above
        write(*,*) 'CHECK', x
        xp_tangent = asin_mb((c_rcurv*(one - c_cBend) - x)/sqrt(((two*c_rcurv)*(c_rcurv - x))*(one - c_cBend) + x**2))
        write(*,*) 'tangent', xp_tangent, xp
      end if
  
      ! If the hit is below, the angle must be greater or equal than the tangent,
  