Dear experts!
I would like to add the option to a background model using a RooKeysPDF made from a histogram to shift in x-axis direction. I do need this for shifting a MC data distribution to improve the calibration wrt to the data. The shape of the background PDF is OK …
If I have understood you well, I think you would need to pass as input to the RooKeysPdf not the RooRealVar representing x, but a RooAbsReal function describing x+shift.
This question I had long time ago and I solved my problem in another way. Nowadays, I understand Lorenzo’s answer in the following way:
If you’d map an x to a whatever f(x) e.g. one has computed a RooKeysPDF. Then one could compute a shift by later using the same obtained f(x) but when asking for a value for e.g. a concrete x_0 with a shift, e.g. s_0 for the whole f(x) one can calculate f(x_0) using x_0 = x - s_0.
thank you for your replies. I was trying a similar thing using RooFormulaVar instead of RooAddition. I believe these should be the same, but I tried implementing this using RooAddition as well.
However, I keep running into either a segfault (using RooFormulaVar), or a
teminate called after throwing an instance of 'std::bad_alloc'
when using RooAddition. It looks like some memory allocation is going wrong, and I am not sure why.
Here are the relevant lines in my code:
std::bad_alloc might mean that you are running out of memory. Try to reduce the size of the dataset by a factor 100, and see if it works.
And yes, the two should do the same, only that the FormulaVar gets interpreted, while the Addition is compiled. Therefore, the addition should be a bit faster.
The dataset I am fitting is ~100mb and the dataset I am converting to a RooKeysPDF I have reduced to ~50kb and I still get the same error. I am wondering whether constructing the RooKeysPDF in this way is too memory intensive even with very small samples…
edit –
I managed to solve this issue using a different approach:
that’s great. However, the memory error doesn’t seem to be that you are running out of memory if the dataset is only 50k.
If you have the time, would you open a bug report, and attach the dataset and the macro to run it so I can try to reproduce the error?
This is supported in RooFit and there is no actual bug. You just called the wrong constructor of the RooKeysPdf.
Here is what you did:
RooDataSet data_R1("data_R1","dataset with x", RooArgSet(Delta_Mcorr), Import(*tree_R1));
RooKeysPdf R1_feed("R1_feed","R1_feed",R1_shift,data_R1,RooKeysPdf::NoMirror) ;
But if the x variable of the RooKeysPdf is not the same as the one in data, you should use the constructor that you tell which variable from the data you’re going to map to the RooKeysPdf.
RooDataSet data_R1("data_R1","dataset with x", RooArgSet(Delta_Mcorr), Import(*tree_R1));
RooKeysPdf R1_feed("R1_feed","R1_feed",R1_shift,Delta_Mcorr,data_R1,RooKeysPdf::NoMirror) ;
This should do the job and I’ll close the Jira issue.