Extract the RooRealVar values


I have some issue in extracting the values of a RooRealVar which is used as a fitting variable.
Here is my code,

 TFile *file = new TFile("data.root");
 TTree *tree =(TTree*)file->Get("h1");
 RooRealVar mbc("mbc","mbc",5.2,5.29);

 Float_t s_mbc;
        for(int j=0;j<tree->GetEntries();j++){
        RooDataSet *data = new RooDataSet("data","data",RooArgSet(mbc));
        for(int i=0;i<tree->GetEntries();i++){
        if(i == j) continue; 

I have used a gaussian + Argus model to fit the data. And I want to extract the mbc value for each iteration. To do so, I have called


But it seems, it is showing a single value for any iteration.
Any suggestion will help.

You can just import the tree directly. Here is a tutorial:

Hi @StephanH,

Thank you for your feedback.
So I used the below lines according to your suggestion (following the tutorial),

  RooDataSet ds("ds", "ds", RooArgSet(mbc), Import(*tree));

which give rises the mbc to be

    1)     mbc = 5.21996  L(5.2 - 5.29)  "mbc"

for any iteration. This is the same value I obtained from mbc.getVal();.
But, I expect different values for different iteration.

ds.Print() only prints one value of the variable. You can try


Note also that if you import, you don’t need iterations, any more. It will import the entire tree for you.

Hi @StephanH,

Thank you. It works. :blush:

1 Like

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