Do not call Paint in TF1::GetHistogram(). Make a new member function TF1::DoCreateHistogram which is called by TF1::Paint and TF1::GetHistogram.