- I don’t know how to ensure that each set of toy data is independent, i.e. not just a copy > of the previous set. Basically I can’t find a way to set the seed for the generated data.
RooFit has a private copy of the a random generator, that is created once per session.
Thus if you generate multiple sets of data, they should be all different, but when you
quite root and start again, the first set generated will be the same again as the first
set generated in the previous session (provided nothing else changed.)
You access the random generator and explicitly set the seed at any moment as follows
2)Also, if I try to run the generation and fitting in a loop, I get a seg. fault. Is there a way to > generate a “vector” of sets of toy data and the pdfs, and generate and fit to each element > of the vector in turn?
To debug your SEGV I need a self-contained & complete example to reproduce it.
More generally, there is exist a convient tool in RooFit to do all of the above for you:
class RooMCStudy. Use as follows
RooAbsPdf* pdf ; // your p.d.f (assumed to be defined previously)
RooMCStudy mcs(*pdf,x) ; // x is assumed to be your observable (variable in data)
mcs.generateAndFit(100,500) ; // generate & fit 100 samples of 500 events each
The output can be processed in two ways
mcs.fitParDataSet() returns a RooDataSet with the fitted parameters for each toy
or you can use the utility to immediately make plots of parameter distributions,
error distributions and pull distributions
RooPlot* frame1 = mcs.plotParam(param) ; // Draw distribution of parameter
RooPlot* frame2 = mcs.plotError(param) ; // Draw distribution of parameter error
RooPlot* frame3 = mcs.plotPull(param) ; // Draw distribution of parameter pull
where param is any floating parameter of your model.