you haven't shown us y_sorgente or Event_Stop_Sorgente which are the two custom files specific to the ODE you're working on. You also haven't explained what your inputs (ys) are and what ys(4:6) consists of.
Just posting the code won't garner much replies though, either, you really have to debug a bit and nail your problem down so that you can ask a more specific question. Try tracking your problem down. You may even solve it without our help!