Add new fit options in RooFit

Hi,

I would like to know if there is any possibility to add my own fit options in the RooAbsPdf::fitTo() method, without having to write a lot of new inherited RooFit classes .

To be more precise, we are working for the KaliVeda toolkit on a backtracing method based on RooFit. We had some issues on this procedure because the number of calls and the number of iterations can’t be changed.
We have finally added these new options by adding new RooGlobalFunc.{h,cpp} files with new RooCmdArg:

RooCmdArg SetMaxIter(Int_t maxiter) {return RooCmdArg(“SetMaxIter”, maxiter, 0, 0, 0, 0, 0, 0,0 ); };
RooCmdArg SetMaxCalls(Int_t maxcalls) {return RooCmdArg(“SetMaxCalls”, maxiter, 0, 0, 0, 0, 0, 0,0 ); };

We then have written a “NewRooAddPdf” class which inherits from RooAddPdf and where we have added the new fit commands in a new fit method, the NewRooAddPdf::improvedFitTo(RooAbsData& data, const RooLinkedList& cmdList), this looks like:

RooCmdConfig pc(Form(“RooAbsPdf::ImprovedFitTo(%s”), GetName()));
pc.defineInt(“numiter”, “SetMaxIter”, 0, 0);
pc.defineInt(“numcalls”,"SetMaxCalls, 0, 0);

and then added these commands for the RooMinimizer:

fnll= createNLL(data, nllCmdList);
RooMinimizer m(*fnll) ;
m.setMaxIterations(numiter);
m.setMaxFunctionCalls(numcalls);

For simplicity, I have just drawn here the simple steps, because we had to create some other inherited classes (RooAddPdf, RooFitResult, RooMinimizer, RooMinimizerFcn, RooGlobalFunc, RooMinuit).
All this work has been done using the ROOT version 5.34, and you can access to the files with this link: github.com/kaliveda-dev/kalived … Track/base.

I don’t know if it was the best choice to add new options, because we would like now to make the backtracing procedure possible with the ROOT version 6.05 (so as to try to solve fit issues), where apparently some methods have been changed, making the migration between versions complicated…

Best regards,
Quentin.

Hi Quentin,

we saw your message and will come back to you soon with an answer.

Best,
Danilo

Hi Danilo,

thanks a lot for your help !

Best regards,
Quentin.

Hi,

What you are proposing seems sensible to me. Do you have a patch implementing it ?

Lorenzo

Hi Lorenzo and sorry to be so late,

In attachment are the files I’ve first modified to define the wanted options (modify the number of calls and iterations of the fit): NewRooGlobalFunc.{h,cpp}.

I have then written a inherited class from RooAddPdf called “NewRooAddPdf” where I have added the new method: RooFitResult* improvedFitTo(RooDataHist& data, const RooLinkedList& cmdList).
This method is almost a copy of the RooFitResult* FitTo(RooDataHist& data, const RooLinkedList& cmdList), where I have added the new options (see the code).

The main problem I have doing this is I need then to create some other inherited classes from RooAddPdf, RooFitResult, RooMinimizer, RooMinimizerFcn, RooGlobalFunc, RooMinuit, because of protected methods/friend class problems.

Thanks for your help,
Quentin.
NewRooAddPdf.cpp (35.9 KB)
NewRooAddPdf.h (2.48 KB)
NewRooGlobalFunc.cpp (602 Bytes)
NewRooGlobalFunc.h (292 Bytes)

Hi,

Thank you for the file. It could be useful to have the new options in ROOT, however I would prefer to have directly as new commands in RooAbsPdf::fitTo and not in a new class.
Why did you create a new class ?

Lorenzo

Hello Lorenzo,

we needed to add these option for our backtracing procedure for the KaliVeda data analysis toolkit, for the moment using ROOT version 5.34. The only solution we found to make it accessible and usable without modifying the source files was to create new classes (maybe there is a better way ?).

Is it possible to add these options in ROOT ?

Best regards,
Quentin.

Hi,

Yes, the options could be added to ROOT, but in this case should be done modifying the existing class and not adding new ones.
Would it be possible to you to send me a patch where you add the options directly in RooAbsPdf, RooMinimizer and RooGlobalFunc ?

Best

Lorenzo

Hi Lorenzo,

here are the files from root-v5.34.34 version ( from roofit/roofitcore/inc and roofit/roofitcore/src) I had to modify so as to get the new options working.

Do you think that these new options can be applied also in root-v6 ?

Best regards,
Quentin.
RooAbsPdf.h (16.1 KB)
RooGlobalFunc.h (15.1 KB)
RooMinuit.cxx (37.2 KB)
RooMinimizer.cxx (27.8 KB)
RooAbsPdf.cxx (130 KB)
RooGlobalFunc.cxx (28.7 KB)

Sorry, I forgot this one…
RooMinuit.h (5.19 KB)

Hi,

any news about my demand ?

Regards,
Quentin.

Hi,

Sorry for my late reply. The files are related to 5.34. Could you please update and change to make it available for ROOT 6. This requires applying your changes on top of the master revision of ROOT. It would be great if you could do that and send me pull request on github or a patch file.
Otherwise I could do that but it will require some editing, since the files in ROOT 6 have changed a lot for the move to the Doxygen documentation.

Thank you

Lorenzo

Hi and sorry for my (very) late reply,

I don’t understand very well what you mean by “update and change to make it available for ROOT6”. Do I need to just modify the aforementioned classes (related to 5.34) in a Git clone file (git clone root.cern.ch/git/root.git) and send a pull request ?

Thanks,
Quentin.

Hi,

The ROOT 6 code contains several changes due to different commenting format, so I cannot include your code as it is in the new version.
You need to apply your modifications on top of the current master and the best if you send me a pull request (for example on git hub mirror, github.com/root-mirror/root ) or just a formatted patch file

Thank you

Lorenzo

Hi,

I have just sent a github pull request.

Best regards,
Quentin.

Thank you !!
I will look at it

Best Regards

Lorenzo

Hi Lorenzo,

any news about the pull request ?

Regards,
Quentin.