Filling TTree branches with the parameters of a looped fit

Dear all,

I’m looping on a fit and trying to put the parameters at each iteration into the branches of a TTree, to have a final distribution of the parameters in each branch. I’m using RooFit v2.91 for the fit and writing in python language. For this purpose, I wrote the following lines. For example, Phi_s is one of the fit parameters

Phi_s = RooRealVar(‘Phi_s’,‘Phi_s’,-0.04,-pi,pi)

f = TFile(‘Params.root’,‘recreate’)
ParamTTree = TTree(‘ParamTTree’,‘ParamTTree’)
ParamTTree.Branch(‘phis’,Phi_s,‘phis/F’)

then I generate data and fit my PDF to the data (code not written here)

paramList=RooArgSet()
paramList=myPdf.getParameters(data)
paramList.Print(‘v’)

So, now, it seems that all my fit parameters are in the RooArgSet paramList. When I print it, I can therefore see that it works. The problem is now that I don’t know how to pass one of the parameters contained in the RooArgSet to one branch of the TTree I’ve created. I tried for example :

phis=paramList.getRealValue(“Phi_s”), but it puts only zeros in my TTree…

Then, in the loop :

ParamTTree.Fill()

Outside the loop :

f.Write()
f.Close()

Would someone knows how, in python, I can pass what is contained in RooArgSet ParamList into different TTree branches ?

Thank you very much for helping,

Géraldine

Géraldine,

there are a couple of things that won’t work the way you set it up, but separate from that, I believe (I’m not a RooFit expert) that RooFit has its own way of doing things … The following snippet worked for me, and maybe you can modify it to work the way you want it to:[code]Phi_s = RooRealVar(‘Phi_s’,‘Phi_s’,-0.04,-pi,pi)
dataset1 = RooDataSet( “ParamTTree”, “my phis”, RooArgSet( Phi_s ) )

Phi_s.setVal( -0.1 )
dataset1.fill()

Phi_s.setVal( 0.1 )
dataset1.fill()

ParamTTree = dataset1.tree()

ParamTTree.GetEntry( 0 )
print ParamTTree.Phi_s[/code]
Cheers,
Wim

Dear Wim,

I thank you very much for your help ! I finally managed to have the information in a TTree, following your good advice, thanks again.

Cheers,
Géraldine