Hi @Natilus! As explained in the thread that was linked by @RENATO_QUAGLIANI, the TGraph::GetMinimum()
function simply returns the data member fMinimum
which is not always set. Hence you get the default value of -1111 when you try to find the minimum.
Indeed, it’s a reasonable approach here to manipulate the TGraph directly. Building on your code snippet, I have written some example code here that shows how you can do that:
using namespace RooFit;
/// Find the minimum y-value of TGraph within interval `[xMin, xMax]`
double findMinimum(TGraph const& graph, double xMin, double xMax) {
double yMin = std::numeric_limits<double>::max();
auto xVals = graph.GetX();
auto yVals = graph.GetY();
for(int i = 0; i < graph.GetN(); ++i) {
if (xVals[i] >= xMin && xVals[i] <= xMax) {
yMin = std::min(yMin, yVals[i]);
}
}
return yMin;
}
/// Shift the y-values of a TGraph by constant value
void shiftTGraphY(TGraph& graph, double shift) {
for(int i = 0; i < graph.GetN(); ++i) {
graph.SetPointY(i, graph.GetPointY(i) + shift);
}
}
void my_example() {
const double JPsiMass_PDG = 3.;
RooRealVar mass("mass","mass", 1.8, 4.8);
RooRealVar JPsiMean("JPsiMean","Mean of Gaussian",JPsiMass_PDG);
RooRealVar JPsiSigma("JPsiSigma","Sigma of Gaussian", 0.6);
RooGaussian JPsiSignal("JPsiSignal","Signal P.D.F.",
mass, JPsiMean, JPsiSigma);
RooPolynomial JPsiBkg("JPsiBkg","Polynomial Background P.D.F.", mass,
RooArgSet(
RooConst(-5.61596639 - 0.004),
RooConst(5.24971989),
RooConst(-1.57142857),
RooConst(0.15406162)
)
);
RooPlot* massFrame = mass.frame();
auto sigCurve = JPsiSignal.plotOn(massFrame)->getCurve();
auto bkgCurve = JPsiBkg.plotOn(massFrame)->getCurve();
// Find the minimum of background curve within desired interval
double bkgMin = findMinimum(*bkgCurve, mass.getMin(), mass.getMax());
// Subtract the minimum from both signal and background curve
shiftTGraphY(*bkgCurve, -bkgMin);
shiftTGraphY(*sigCurve, -bkgMin);
massFrame->Draw();
}
The the RooCurve directly inherits from TGraph, so the TGraph documentation can be quite useful here.
I hope my code example solves the problem for you or at least helps you to get started. If not, please let me know!
Cheers,
Jonas