Fast simulation of the CMS detector