Terahertz-field-induced second-harmonic generation in a beta barium borate crystal and its application in terahertz detection