RooFit error while trying to add cuts

Hi eveyone, I am new to using RooFit and I am facing some issues while making cuts. I want to plot a variable (RecMassKK here) and want to make cuts to few other parameters. I read that I need to import all the variables from my tree, which I do and also define them before importing. When I just plot the variable, it works fine but when I try to apply a fit, I get errors. (When I made the same fit, without applying any cuts, it had worked fine as well). I am attaching my code and the error message I get when I try to fit my data. Thanks for any help!

roofit_K.cxx (4.4 KB)

Hi @paulan,

thanks for asking on the ROOT forum! Without also having your data1501.root file at hand, I can only guess what the problem is. But I think there is quite an obvious problem in your script: the RooRealVars for the observable in the model and the data don’t match. Your model uses this observable:

RooRealVar x("x", "RecMassKK", 400, 600); //RecMassKK used here as well

But "x" is nowhere in the data. So I’m surprised that the fit even worked without any cuts, as your model and data don’t share any variables :slight_smile:

You should not create this "x" for the model, and instead just reuse the RecMassKK variable that you have created earlier also for the Gaussian and polynomial:

RooGaussian gauss("gauss", "gaussian PDF", RecMassKK, mean, sigma);
RooPolynomial poly("poly", "Background", RecMassKK, RooArgSet(a0, a1));

Let me know if this is already fixing the problem, otherwise I’ll follow up on this with other comments about things that appear wrong to me in your script (for that it would help if you also share the data file with me somehow).

Cheers,
Jonas

Hi @jonas thank you! This did work for me :slight_smile:
I admit, I was quite a bit confused with the whole script and defining so many variables. I had a little different script (just the variable x) before applying cuts, which is why it had worked. I later introduced all the other variables and imported them to make cuts.

I am also curious to know if there are other mistakes in my script, I’d greatly appreciate if you could point them out. I am attaching a smaller file (1501.root is too big to be attached here), in case you’d need it.
hist-sample.root (346.3 KB)

Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.