GRIFFINCollaboration / GRSISort

A lean, mean, sorting machine.
MIT License
22 stars 54 forks source link

Background function not drawing after TPeakFitter fit #1429

Closed cnatzke closed 4 months ago

cnatzke commented 5 months ago

I am fitting a combination of two peaks with TPeakFitter and would like to draw the background function. I use the following (simplified) code to extract the function:

    TPeakFitter pf(fitRangeLow, fitRangeHigh);
    TRWPeak ggPeak(twoPhotonCentroid);
    TRWPeak bgPeak(bgCentroid);
    pf.AddPeak(&ggPeak);
    pf.AddPeak(&bgPeak);

    TF1 *ggPeakFunc = ggPeak.GetFitFunction();

    TF1 *bgPeakFunc = bgPeak.GetFitFunction();

    TF1 *bgFunc = pf.GetBackground();

    pf.Fit(total, "LEM");

    TCanvas *c1 = new TCanvas("c1", "c1", width, height);
    gSystem->ProcessEvents();

    gStyle->SetOptStat(0);

    bgFunc->Draw();

I get a blank canvas and the following error:

Error in <GCanvas::Range>: illegal world coordinates range: x1=0.000000, y1=-2519.026069, x2=0.000000, y2=22671.233122
Error in <GCanvas::RangeAxis>: illegal axis coordinates range: xmin=0.000000, ymin=0.000000, xmax=0.000000, ymax=20152.207053

I suspect it's an error on my part but I can't find it.

cnatzke commented 5 months ago

I can draw both the ggPeakFunc and the bgPeakFunc without problem

bgPeakFunc->Draw();
ggPeakFunc->Draw("same");

without issue, but the bgFunc does not draw.

VinzenzBildstein commented 5 months ago

What happens if you use:

bgPeakFunc->SetRange(fitRangeLow, fitRangeHigh)

before you call the Draw command?

cnatzke commented 5 months ago

That fixed it, thanks. I knew it would be something simple.

VinzenzBildstein commented 5 months ago

Okay, thanks for confirming. I will have to look into the peak fitter code to see why the range isn't set automatically.