How to get the Median value of a RooDataSet?

Hi there. I am a beginner user of ROOT and Roofit. I have generated a RooDataSet corresponding to a specific RooRealVar containing 1000 entries, and I basically want to get the median value of this RooDataSet, so in this case it would be the value of the (500th + 501st data points) / 2, where the data points are ordered from smallest to largest. I have tried reading various documentation but can’t work out a way to do this. I don’t believe there is a RooStats function to extract the median either. If anyone could help me it would be much appreciated

You can get certain events be using:

RooArgSet * datapoint500 =  data.get(500);
RooArgSet * datapoint501 =  data.get(501);

While data is a RooDataSet. With that you can save the event 500 and event 501 extract their value with

Double_t val500 = datapoint500.getRealValue (const char *name);
Double_t val501 = datapoint501.getRealValue (const char *name);

Where name is the name of your RooRealVar variable. Then just sum them up and divide by two.

Hi Sharku,

Thanks for your reply. I have thought of your answer already, the problem I have is that in order for the 500th plus 501st point divided by two to be the median that would require the RooDataSet to be ordered with the 1st point being the smallest and the 1000th being the largest. Do you have any idea how I might implement this?

I would transform the RooData Set into a std vector of type RooArgSet.
Then you can use the c++ sorting algorithm std::sort which is explained here:
http://en.cppreference.com/w/cpp/algorithm/sort

and vectors are explained here:
http://www.cplusplus.com/reference/vector/vector/

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