You give yhour variable the name d/2. For the title this is okay, but for the title you get into trouble if you use special characters like this. Just name is dOver2 or maybe even dd, so it matches with the C++ variable name.
In the formula, you should use C++ code and not Python code, so ROOT.TMath.Erfc should be TMath::Erfc and ROOT.TMath.Sqrt should be TMath::Sqrt.
For your RooGenericPdf, you use dd in the formula, but you have no variable with the name d/2. Remember that the formula expression matches by the TObject name, and not by the C++ variable name. So you have to use the name you gave to dd, which is d/2 right now. But as I said before, you’ll run into problems with the division sign in the name. so the best solution I think is to change the name from d/2 to dd:
Thanks a lot for your patient reply!
After following your advice, there’s still a problem on GenericPdf. Maybe it’s not an allowed pdf. After extract the “dd” outside the pdf, it seems work!