Can't access entries in RooArgSet from RooDataSet

Dear experts,
I need to access variables stored in a RooDataSet, but I can’t figure out how to do it. I’m trying this:

RooDataSet *data;

//Fills data set

for(Int_t i=0; i < data->sumEntries(); i++){
  const RooArgSet &argSet = *(data->get(i));
  argSet.Print("V");
  double_t var = argSet["var_name"];
}

However, I keep getting error: variable type 'RooAbsArg' is an abstract class. How can I get the values from the RooArgSet?

Thank you in advance,
Lucas

You probably need to use the pointer instead of a reference. This might work:

auto argSet = data->get(i);
argSet->Print("V");
double_t var = (*argSet)["var_name"];

Now I get error: no viable conversion from 'RooAbsArg' to 'double_t' (aka 'double'). I can’t find any function to retrieve the value stored in the RooAbsArg.

Then I’m afraid I need to ask @jonas for help.

Hi @lmeyerga!

You fist need to cast the variable to RooAbsReal, and then get the value with getVal():

RooDataSet *data;

//Fills data set

for(Int_t i=0; i < data->sumEntries(); i++){
  const RooArgSet &argSet = *(data->get(i));
  argSet.Print("V");
  double_t var = static_cast<RooAbsReal&>(argSet["var_name"]).getVal();
}

I hope that works for you!

Cheers,
Jonas

1 Like

Hi @jonas, that works! Thank you!

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