# Get number of entries within certain range from TOY generated data sets

Hello,

I generate some TOY data sets from a PDF within a certain range. Now I want to get the number of data points with different sub-ranges from the generated data sets.

The generated toy data distribution is shown here.

.

Now I want to get how many events are there in between (1,1.3) and (1.3,1.8) etc. can anyone let me know how to calculate the number of entries within the subranges.

Thanks

1 Like

Hi,
Thank You for the prompt answer. But in that way, I need to convert from Roodataset to TH1. Can you let me know how to convert?

Thanks

`RooDataSet::sumEntries(const char* cutSpec, const char* cutRange = 0)`

You can either set ranges on the observable, and name them one by one, or you just list cuts such as `myDataSet.sumEntries("0 < x && x < 5")`.
Replace `x` with the name of your observable.

Hi Stephan,

Thank You! This works directly without converting to TH1. But I try to convert to TH1. After converting,the Integral() is not working properly when I specify limits. But Integral() without mentioning the range gives the total number of entries.

cout<<“Sum of entries…”<< data->sumEntries(“1.3 < x && x < 1.5”)<<endl;

TH1 h1 = (TH1)data->createHistogram(“h1”,x);

Double_t calc;
calc = h1->Integral(1.3,1.5);
cout<<"Integral …= "<<calc<<endl;

Output:

: warning: implicit conversion from ‘double’ to ‘Int_t’ (aka ‘int’) changes value from 1.5 to 1 [-Wliteral-conversion]
calc = h1->Integral(1.3,1.5);
~~~~~~~~ ^~~

Output:
Sum of entries…4
Integral …= 1

I don’t recommend converting to TH1, as you will lose information when things are sorted into bins. Nevertheless,

The integral function takes bin numbers, not x values.

1 Like

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