  In this paper, we use a reconfigurable intelligent surface (RIS) to enhance
the radar sensing and communication capabilities of a mmWave dual function
radar communication system. To simultaneously localize the target and to serve
the user, we propose to adaptively partition the RIS by reserving separate RIS
elements for sensing and communication. We design a multi-stage hierarchical
codebook to localize the target while ensuring a strong communication link to
the user. We also present a method to choose the number of times to transmit
the same beam in each stage to achieve a desired target localization
probability of error. The proposed algorithm typically requires fewer
transmissions than an exhaustive search scheme to achieve a desired target
localization probability of error. Furthermore, the average spectral efficiency
of the user with the proposed algorithm is found to be comparable to that of a
RIS-assisted MIMO communication system without sensing capabilities and is much
better than that of traditional MIMO systems without RIS.
