RooMCStudy: are the fits converged in MIGRAD by default?


I am running RooMCStudy manager to test my fitter, its stability and
possible biases. I have a simple question: I am running
many job segments on the Grid ( ~24hrs CPU per segment),
save the fitParDataset() to file and then merge/analyze
the results offline.

The code looks like this:

RooMCStudy* mcstudy = new RooMCStudy( (*modelTot), sbmQvalue, Binned(kFALSE), Silence(),
Extended(kTRUE), FitOptions( Hesse(kTRUE), Save(kTRUE), PrintEvalErrors(0) ) );

mcstudy ->generateAndFit(350, 0, kTRUE);

const RooDataSet& resultPars1 = mcstudy ->fitParDataSet();

printf("\n>>>> RooMCStudy: Tested PDF: print internal fit par dataset.\n");

// clone fit par dataset:
RooDataSet* outParameters1 = new RooDataSet(resultPars1, “fitParData_TestPdf”);

printf("\n>>>> RooMCStudy: Tested PDF: print fit par dataset (cloned) to be exported.\n");
Int_t nEntries1 = outParameters1 ->numEntries();
printf("\n\n>>>>>>> The size of this dataset: = %d:\n", nEntries1);
outParameters1 ->Print(“v”);

// C r e a t e w o r k s p a c e a n d w r i t e i t t o f i l e :

// Create a new empty workspace with name: "wrksp"
RooWorkspace* wrksp = new RooWorkspace(“wrksp”,“workspace”);

// Import cloned fit par dataset into the workspace
wrksp ->import((*outParameters1));

// Print workspace content
wrksp ->Print(“v”);

// Save the workspace into a file
wrksp ->writeToFile(outfitfile);

// Workspace will remain in memory after macro finishes
gDirectory->Add(wrksp) ;

My question:
What is the MIGRAD return code for every fit of every trial?
Are they ALL by default converged in MIGRAD and have rc=0
or, better,
When do fit results get saved into

  .  const RooDataSet& fitParDataSet()
  .   const RooFitResult* fitResult(Int_t sampleNum) const


If not how do I analyze the status of every fit in my case offline
after burning many CPU hrs on the Grid ?

Thank you in advance.


Hi Igor,

The current procedure in RooMCStudy is that in the fitParDataSet() only entries are stored for which the fit was converged. However all fit results, including those of non-converged fits, are kept if you provide the Save() fitOption as you do. So at then end of your batch job all information is still here.

From there you can consider several options:

Minimally you can check for the number of failed fits per batch job comparing the number stored fit results to the number of entries in fitParDataSet.

More generally, you can store all fit results in an output file. RooFitResult objects are directly persistable (even without a workspace). Simply attach them to the directory of an open TFile and they will write themselves to that file. You can also store them inside a workspace using on the following methods

Bool_t import(TObject& object, Bool_t replaceExisting=kFALSE) ;
Bool_t import(TObject& object, const char* aliasName, Bool_t replaceExisting=kFALSE) ;

You probably need the 2nd form as each workspace entry requires a unique name and the default name of all RooFitResults from the same pdf/data combination have the same name.

Finally, if you have all the RooFitResults stored in files, you can also ‘replay’ the toy MC study in an interactive session. For that you construct the RooMCStudy object as you would usually. Next, instead of calling generateAndFit() you call

Bool_t addFitResult(const RooFitResult& fr) ;

for each fit result from your batch job. This will reconstitute a fitParDataSet() as well as use the various direct plotting methods.


1 Like

Hello Wouter,

Thank you very much for the comprehensive answer.

As now I understand:

 .  every segment of my grid job generates and  fits 350 samples.
 .  I do see that the RooDataSet* fitParDataSet  have 350 
    entries as well. That is 100% of samples have been fitted 
    with converged MIGRAD. Right?


Hi Igor,

That is almost correct, as there is one more detail: the fit result status code captures the status of the last MINUIT operation that was performed. By default this is HESSE, not MIGRAD. Often, when one has problems the other has too, but not always.


Hello Wouter,

Thank you again for you fast responses!

Yes, I have specified HESSE at the end, i.e.
I have rc=0 from HESSE, but probably
it does not mean that fitter always
produces the matrix quality of 3,
as I can see from fitter response distributions…


Hi Igor,

The ideal solution is to save the status of all steps, but this is currently not supported in RooMCStudy.
What you can do in the mean time is e.g. configure the study to omit HESSE by adding Hesse(kFALSE)
to your fitoptions. Your error matrix will be a rougher estimated made by MIGRAD, but you will be able
to retrieve the MIGRAD error status this way.