While the positive outcomes of undergraduate research experiences (UREs) have been extensively categorized, the mechanisms for those outcomes are less understood. Through lightly structured focus group interviews, we have extracted the cognitive tasks that students identify as engaging in during their UREs. We also use their many comparative statements about their coursework, especially lab courses, to evaluate their experimental physics-related cognitive tasks in those environments. We find there are a number of cognitive tasks consistently encountered in physics UREs that are present in most experimental research. These are seldom encountered in lab or lecture courses, with some notable exceptions. Having time to reflect and fix or revise, and having a sense of autonomy, were both repeatedly cited as key enablers of the benefits of UREs. We also identify tasks encountered in actual experimental research that are not encountered in UREs. We use these findings to identify opportunities for better integration of the cognitive tasks in UREs and lab courses, as well as discussing the barriers that exist. This work responds to extensive calls for science education to better develop students' scientific skills and practices, as well as calls to expose more students to scientific research.