Fix bug when writing the tof data