RooFit Sampling from multiple dimension PDF

Hi, I’m trying to generate a MC sample from a 2 dimensional Histogram.

Here is how I expected to do it:

[code]RooRealVar x(“x”, “x”, leftx, rightx);
RooRealVar y(“y”, “y”, lefty, righty);

RooDataHist* roo_hist2d = new RooDataHist(“roo_hist2d”, “roo_hist2d”, RooArgSet(x,y), RooFit::Import(((TH1)hist2d)));

RooHistPdf* roo_hist2d_pdf = new RooHistPdf(“hist2d_pdf”, “hist2d_pdf”, RooArgSet(x,y), *roo_hist2d, 0);

RooDataSet* sampled_data = roo_hist2d_pdf->generate(RooArgSet(x,y), RooFit::Verbose(true), RooFit::NumEvents(100));

for(unsigned int I=0;I<sampled_data->numEntries();I++) {
const RooArgSet* arg_set = sampled_data->get(I);
double x = arg_set->getRealValue(“x”);
double y = arg_set->getRealValue(“y”);
//Do stuff with x and y

Now, I want to use the data in the RooDataSet to my own ends, so ideally I would iterate through the list of generated events much like a TTree. Since the function RooDataSet::get(int) returns a RooArgSet, I figured I could do this, using the RooArgSet to find the value generated for the x and y value. At least I used this in the past for 1 dimensional data sets.

For somereason, sampled_data->numEntries() returns 10000. Its like it sampled 100 times from one dimension, and then for each point, it sampled 100 times from the other dimension.

Can somebody explain to me how to do this properly? I fail to see why RooDataSet should generate 10000 events when I ask for 100.