TH1->FillRandom(...) doesn't work with linear function


Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.20/02
_Platform: Linux
Compiler: Not Provided


Hey there,

I am currently trying to artificially contaminate histograms (made from a MC-Dataset) with a linear background to practice fitting background and distribution at the same time. I wanted to use ->FillRandom() for that, but this function seems to fill in only noise, without my linear function being considered. It doesn’t improve if I increase the events filled. Below I extracted the part of my analysis that does not seem to work and the histogram it produces show the problem really well. Is there anything I can do, to make the FillRandom(…) function a bit less random?

Cheers, Anton

void test(Float_t percentage, Int_t binnum)
{
    TCanvas *c1 = new TCanvas();

    c1->Divide(2,4);

    TF1 *mylin = new TF1("mylin", "[0]*x + [1]", 2.96, 3.02);

    mylin->SetParameter(0, 10000);
    mylin->SetParameter(1, 100);

    for (int i = 1; i < 9; i++)
    {
        TString histname = Form("hdecl_%d", i);
        TString title = Form("Invariant Mass for %d cm < Decay Length < %d cm", (i-1)*5, (i)*5);

        TH1F *hdecl_x = new TH1F(histname, title, binnum, 2.96, 3.02);
        c1->cd(i);

        hdecl_x->FillRandom("mylin", static_cast<Int_t>(percentage*(1000000+hdecl_x->Integral())));
        hdecl_x->Draw();
    }
}

I think @moneta can help you.

Try to replace hdecl_x->Draw(); with hdecl_x->Fit("pol1"); and then call test(1., 10); (well, I think I see no problem).