Extract the RooRealVar values

Hi,

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;
 tree->SetBranchAddress("mbc",&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++){
        tree->GetEntry(i);
        mbc.setVal(s_mbc);
        if(i == j) continue; 
        data->add(RooArgSet(mbc)); 
        }

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

mbc.getVal();

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:
https://root.cern/doc/master/rf102__dataimport_8C.html

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));
  ds.Print("v");  

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

ds.get(0)->Print("V");
ds.get(1)->Print("V");
...

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.