Problem in reading a vector in roofit

Dear experts,

I am using roofit and reading a tree. In that tree there is a float variable named var1. I am able to define it as
RooRealVar var1(“var1”, “first variable”, 0., 10.);

But in case, if my variable var1 is defined as vector, then how can I use this variable?
I tried to use it as:
RooRealVar var1(“var1->at(0)”, “first variable”, 0., 10.);

But it is not working this way. Can you please suggest me any better way?

Thanks and regards, Sanjeev

Hi,

perhaps you could define a reference to that element?

auto &var1_at0 = var1->at(0);
RooRealVar var1(“var1_at0”, “first variable”, 0., 10.);

Cheers,
H

1 Like

Hi @sanjeev,

what you are asking might not be possible. A variable is a double, and I doubt you can bind it to anything using just a name. There needs to be a dataset involved that reads a tree.

But let me ask this:

  • Are you trying to give the variable an initial value?
    If yes, do it like this:
RooRealVar var1(“var1”, “first variable”, var[0], 0., 10.);
  • Are you trying to read the final values into a vector? In this case, copy the result after the fit:
RooRealVar var1(“var1”, “first variable”, 0., 10.);
... <fit> ...
var[0] = var1.getVal();

No, I am not giving initial value as you mentioned.
What Guisan mentioned in previous message is the perfect one which I needed.
Thanks

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