Reading data from files in TMinuit fitting

Hi ,everyone! I want to ask a question ,if it is necessary to read the data in the main program when I fit datas with TMinuit class?Can I read it in the function that I define to to be minimized? Why?

You may want to review https://root.cern/doc/master/classTMinuit.html
or https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#numerical-minimization