Help with fitting

Dear Root experts,
I have a normalized histogram of my signal that I got it from MC and I would like to use it to fit data.
In my code I create a TF1 as follows:

TF1* PsiSignal = new TF1("J/Psi Signal", "[0]*(h_MCPsiMass->GetBinContent(h_MCPsiMass->FindBin(*X)))", PsiLeftCut, PsiRightCut);

In fact, I would like to use the shape of the signal to fit the data. Here [0] is supposed to be my normalization factor.

I can compile the code but I get the following message when running:
FindBin is unknown.
h_MCPsiMass is unknown.
GetBinContent is unknown.
Error in TFormula::Eval: Formula is invalid and not ready to execute

I am pretty sure I am not doing it right, but I am hoping you should show me the right way to use a normalized histogram to fit data.

As always, thank you in advance

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

The function expression can only contain simple stuff. For your case, try the types 4, 5 or 6 in the TF1 docs, i.e., the cases with “general C/C++ function” or “member function with a class”.

Hi @dastudillo
Thank you for the help. My code works now.
I used type 4 and at the first attempt I got an error that the histogram is not available but then I defined the histogram as a global variable and that solved the problem.
Thank you very much for your help