RooNDKeys Very Slow At Generating Data

Hi there,

I’m hoping to use a KEYS distribution to create a PDF for a quick MC study. I’ve noticed that RooFit provides two classes that can help me to do this: RooKeysPdf and RooNDKeysPDF, where RooNDKeysPDF is just a generalization of RooKeysPdf into n-dimensions.

Even though I only need a 1-dimensional PDF, I have to use RooNDKeysPDF because it supports per event weighting (when creating it), which RooKeysPDF does not.

But the problem is that RooNDKeysPDF takes a long time to generate data! It takes about 20 seconds to do so, and this appears to be independent of the number of events requested. I’ve tried to turn of mirroring and per-event weighing, but that did not speed things up. On the other hand, RooKeysPDF takes almost no time…

I’ve added the Verbose() option to generate(), it hangs for a long time andthen quickly prints out the following and finishes.

[quote] — RooGenContext —
Using PDF RooNDKeysPdf::Wmunu_met[ varList=(met) weight=weight weightParams=() ]
Use PDF generator for ()
Use MC sampling generator RooFoamGenerator for (met)[/quote]

My question is, does anyone have experience of using RooNDKeysPdf? And if they do, is it expected to be that slow or am I doing something wrong?

I’ve attached the macro (nd_test) that I use to test this. Also I’ve attached a more simplified macro (nd_test2) where I create a dataset from a Gaussian, and feed that into the keys distribution.

The root tree used to create the distribution contains 5195 events after all of the applied cuts. I’m using ROOT 2.24, compiled by myself for Ubuntu Jaunty. Also, I’ve run the macro in compiled mode (ei: root nd_test.C+).
ndkeys_test2.C (792 Bytes)
ndkeys_test.C (2.44 KB)

1 Like

Hi Karol,

(Sorry for the late reply - I just returned from vacation )

I’ll have a look into this and discuss ways to improve this with the Max Baak (the author of the ND keys p.d.f.). Aside from that I will also add support for weighted events in RooKeysPdf, which is straightforward to do.

The 1D pdf is generally faster than the ND version because the former precalculates the shapes and caches it in a very finely binned histogram, while the latter cannot do that as that strategy does not scale well to other dimensions.

In the mean time, you can explicitly apply the caching strategy of RooKeysPdf to
RooNDKeysPdf through the use of RooCachedPdf, i.e.

RooNDKeysPdf* k;
RooCachedPdf kc(“kc”,“kc”,*k) ;

and then use kc instead of k The default cache granularity is 100 bins. To increase
this, do x.setBins(“cache”,N) where x is your observable and N is the desired number
of bins.