# RookeysPdf documentation clarification

Dear expert
When reading the RookeysPdf doxygen I encountered this in the description

If the 'adaptive mode' is enabled, the width of the Gaussian is adaptively calculated from the local density of events, i.e. narrow for regions with high event density to preserve details and wide for regions with low event density to promote smoothness.


This is exactly what I would like to do for a shape to avoid implementing a full Beeston Barlow method in my analysis.
The question I have is , how exactly one enable this adaptive behaviour? Mirror options seems to not being documented on what they do, so one has to try and see but I doubt one of them enable the adaptive mode, while rho sounds to be a customizable flag ( at least it has always been for me)

So the question I have is , how does one enable the adaptive behaviour? And can eventually be fixed in the documentation on what to do to enable it?

Renato

Hi @RENATO_QUAGLIANI, excellent question!

We are aware of the flaws in the RooKeysPdf documentation and we are working on improvements (see also issue #8507 on GitHub).

The comment about the “adaptive mode” in the documentation is indeed misleading, because it suggests that the adaptive mode has to be enabled. But in fact, the adaptive mode can’t be switched off! The only control you have over the RooKeysPdf is the \rho parameter as an overall scaling to the kernel width, and the various mirror options.

If you want to toggle the adaptive mode, you need to use the more general RooNDKeysPdf.

The RooNDKeysPdf implementation is however much more complicated in order to generalize to n dimensions. So it might have some additional performance overhead, just as a heads up.

On a related note, if you are using a weighted dataset for the density estimation, you have to use the RooNDKeys pdf because the RooKeysPdf was giving wrong estimates for weighted datasets in all ROOT releases so far. This problem got only fixed last week in ROOT master.

Hope this is informative, let me know if you have further questions!
Jonas

Thanks a lot @jonas , Let’s say i would like to try to get this behaviour working in ROOT 6.18/06.
Do you have suggestions on how to backport it?
Unfortunately i cannot switch to root master , so i need to do something diry editing the code probably…

Thanks
Renato

Hi! What do you mean by “this behavior”, the support for weighted datasets of RooKeysPdf? Everything else I mentioned also applies to 6.18/06.

If you want to do use weighted datasets, you just have the use the RooNDKeysPdf, which has always implemented weighted dataset support correctly.

Dear @jonas ,

So if i use RooNDKeysPdf out of the box in ROOT 6.18/04 the bug you mentioned about using weighted dataset for the density estimation, i should have to make a fix to backport the latest ROOT master changes?

Thanks,
Renato

Right, the RooNDKeysPdf doesn’t have this bug, so you don’t have to do any backport when using it for weighted datasets

If you use the RooKeysPdf (without the ND) with weighted weighted datasets, you need to apply the backport.

1 Like

I have a follow-up

TBufferFile::WriteObjectAny:0: RuntimeWarning: since RooNDKeysPdf has no public constructor
which can be called without argument, objects of this class
can not be read with the current library. You will need to


When in ROOT 6.18/04 i try to save to a workspace the NDKeysPdf  i get this, does it mean in 6.18 i cannot load it back?

Yes, that’s exactly what it means. This got fixed in ROOT 6.20.00 however.

Is there a good reason for you to use such an old ROOT version? I can really encourage you to use a newer one. Especially RooFit has evolved a lot over the last releases with many bugfixes and performance improvements.

The reason is that some of the code is not forward compatible with the changes done in RooFit, and i need to do many changes in my code. Does 6.20.00 should be backward compatible with 6.18.04?
If so i just compile a new class copying the source code and use it.
Thanks

EDIT:
Just copying headers/source and compile them as a new pdf RooKeysNDPdf2 seems to work, ( copy done from 6.20.00)

Does 6.20.00 should be backward compatible with 6.18.04?
If so i just compile a new class copying the source code and use it.

Yes that should definitely work. You can also cherry-pick the relevant commit:

Still, then you are depending on either a patched ROOT version or a custom class. I think this is a much bigger burden than migrating your code to ROOT 6.20, which usually doesn’t require many lines of change (and you can always ask here if you need help with that ).

Hello,
For some reasons I am trying to understand, I enabled the saving and loading from workspace and it works, however the pdf once loaded and after doing the redirectServerHooks on a variable with a different range for the X value It has errors on the normalisation.
I try to debug further , unfortunately I tried to upgrade to 6.20 but I have other code to port which instantiate some class which has been upgraded.

that’s interesting! Can you maybe upload a script here to reproduce the problem? Thanks!

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