# How to obtain five-dimetional RooHistPdf?

Hi, all:

I want to get a five-dimentional RooHistPdf.
Take 3-dimentiona example:
==>
TH3F* h3 = new TH3F(“h3”, “h3”, 100, 0.0, 2.5, 25, 0.0, 2.5, 16, -1.0, 1.0);
RooDataHist hist3(“hist3”, “hist3”, RooArgSet(m2,q2,cosV), h3);
RooHistPdf bkg(“bkg”, “bkg”, RooArgSet(m2,q2,cosV), hist3);

I find it is fine. But it is going wrong when I use five-dimentianl histogram defined as:

THnSparseF* h5 = new THnSparseF(“h5”, “h5”, dim, bins, xmin, xmax);

It result “RooDataHist hist5(“hist5”, “hist5”, RooArgSet(m2,q2,cosV,cosL,chi), h5);”

Volcano

Dear Volcano,

[quote=“volcanolei”]But it is going wrong when I use five-dimentianl histogram defined as:

THnSparseF* h5 = new THnSparseF(“h5”, “h5”, dim, bins, xmin, xmax);[/quote]

This is because RooDataHist, 4th argument to RooHistPdf, has only a constructor from TH1 and family, not THnSparse.
Please refere to the RooDataHist documentation and, for example, to utorials//roofit/rf401_importttreethx.C, for examples of how to construct N-dimensional RooDataHist.

G Ganis

Thank your reply. But I think the example of rf401_importttreethx.C can’t satisfy my requirement.
I need a five dimetnion RooHistPdf with five varibles.

Here I find the right way:

``````m2.setBin(100);
q2.setBin(20);
cosV.setBin(10);
cosL.setBin(10);
chi.setBin(10);
RooDataSet* databkg = Databkg->reduce(RooArgList(m2,q2,cosV,cosL,chi));
RooDataHist* dataHist = databkg->binnedClone("dataHist","dataHist"); //
RooHistPdf BKG("BKG","BKG",RooArgSet(m2,q2,cosV,cosL,chi), *dataHist);
``````

But the bins size for each dimention in dataHist is still 100. So the dataHist with 100^5 bins need too large memory. Who knows how to reset bin size for dataHist?

Hi,

The RooDataHist allocates nbin^d bins. So it will not scale to 5 dimensions. I would use a simple weighted RooDataSet where you have the entries only for the non empty bins.
So, in your case you should not use the RooHistPdf, but something else, depending exactly on what you need to do.

Best Regards

Lorenzo

1 Like

[quote=“moneta”]Hi,

The RooDataHist allocates nbin^d bins. So it will not scale to 5 dimensions. I would use a simple weighted RooDataSet where you have the entries only for the non empty bins.
So, in your case you should not use the RooHistPdf, but something else, depending exactly on what you need to do.

Best Regards

Lorenzo[/quote]

Thank you, moneta. But I don’t understand your saying " I would use a simple weighted RooDataSet where you have the entries only for the non empty bins. "
And you mean we can not get a five dimentional RooHistPdf function as we like?
It is a pity for that, you know we can get 1~3 dimentional RooHistPdf easily as we like.
I really hope this can be improved.
By the way, I just need a five dimentional pdf function as my background shape.
I know another method to achieve it by using RooNDKeysPdf.
But I meet the problem of generateing background data sets for Input-output check.
As below:

RooNDKeysPdf BKG(“BKG”,“BKG”,RooArgSet(m2,q2,cosV,cosL,chi),data,“am”);
RooDataSet
subdata = BKG.generate(RooArgSet(m2, q2, cosV, cosL, chi), 477);

I don’t know why it don’t work for five dimention case.
Even for 2 or 3 dimention cases, It is very slow for generation process.

Do you have some idea about my case?

Best wishes
Volcano