[RF] Deprecate RooMinuit class (adapter between RooFit and minuit, got replaced by the more general RooMinimizer)#8609
Conversation
This also includes an update of the reference file `stressRooFit_ref.root`, because the fit results differed at the 6th digit with the new RooMinimzer: ``` RooFitResult::isIdentical: constant parameter sigma_g2 differs in value: 4.18951 vs. 4.18946 (1.25945e-05) RooFitResult::isIdentical: final parameter frac differs in value: 0.656146 vs. 0.65613 (2.51561e-05) RooUnitTest ERROR: comparison of object RooFitResult::nll from result rf601_r2 fails comparison with counterpart in reference RooFitResult nll Test 38 : Interactive Minuit.....................................FAILED ```
In particular, this means means removing the `OldMinuit` value for the `Minimzer` command argument of `RooAbsPdf::fitTo()`. A more general minimizer adapter class called `RooMinimizer` was introduced in ROOT 5.24 (see commit 12389f7). With ROOT 6.08, the new RooMinimizer became the default interface to minuit in RooFit. Now, this commit removed the option to use the old `RooMinuit` in `RooAbsPdf::fitTo()` for 6.24.
The code of the RooMinuit class is moved to the RooFitLegacy subdirectories to clearly mark them as deprecated.
hageboeck
left a comment
There was a problem hiding this comment.
LGTM, but I have a few more suggestions.
| // void setAlwaysStartFromMin(Bool_t flag) { _startFromMin = flag ; } | ||
| // Bool_t alwaysStartFromMin() const { return _startFromMin ; } | ||
|
|
||
| //RooMinuit* minuit() { return _minuit ; } | ||
| //RooMinimizer* minimizer() { return _minimizer ; } | ||
| RooAbsReal& nll() { return const_cast<RooAbsReal&>(_nll.arg()) ; } | ||
| // const RooArgSet& bestFitParams() const ; | ||
| // const RooArgSet& bestFitObs() const ; |
There was a problem hiding this comment.
Maybe clean this up while you are at it ...
There was a problem hiding this comment.
It's all code that will just rot because it's never being compiled.
| TIterator* _oiter ; //! Iterator of profile likelihood output parameter(s) | ||
| */ | ||
|
|
||
| // mutable RooMinuit* _minuit ; //! Internal minuit instance | ||
| // mutable RooMinimizer* _minimizer ; //! Internal minimizer instance | ||
|
|
||
| // mutable Bool_t _absMinValid ; // flag if absmin is up-to-date | ||
| // mutable Double_t _absMin ; // absolute minimum of -log(L) |
| /* | ||
| RooMsgService::instance().setGlobalKillBelow(RooFit::DEBUG) ; | ||
| profile->getVal(); | ||
| RooMinuit* minuit = ((RooProfileLL*) profile)->minuit(); | ||
| RooMinimizer* minuit = ((RooProfileLL*) profile)->minimizer(); | ||
| minuit->setPrintLevel(5) ; // Print MINUIT messages | ||
| minuit->setVerbose(5) ; // Print RooMinuit messages with parameter | ||
| minuit->setVerbose(5) ; // Print RooMinimizer messages with parameter | ||
| // changes (corresponds to the Verbose() option of fitTo() | ||
| */ |
| TIterator* _piter ; //! Iterator over profile likelihood parameters to be minimized | ||
| TIterator* _oiter ; //! Iterator of profile likelihood output parameter(s) |
There was a problem hiding this comment.
When you see (mutable) iterator members that are not serialised (//!), that is almost always a sign that a range-based for loop or a counting loop should be used. Less members, faster, easier to understand.
Just saying, maybe for another day ...
| for(auto const& arg : obsSetOrig) { | ||
| auto var = dynamic_cast<RooRealVar*>(arg); | ||
| if(var == nullptr) break; |
There was a problem hiding this comment.
This pattern was used in a lot of old loops, and although it looks like a double check (both for checking that the loop isn't finished and that the type is correct), it's usually only checking if the loop is finished. In almost all cases, you can static_cast and run through the full collection. For good measure, I put an assert with a dynamic_cast into the loop. It brings extra debug info, and it doesn't cost anything in release builds.
Note also that if they were really checking the types, it wouldn't make any sense if you put {var, var, otherType, var} in a collection, because the last var would never be reached. That's most probably a bug.
Long story short: Those loops usually work with range-base and static_cast, and they will be much faster this way. Consider this as a standard way to modernise those kinds of loops (and make the var const whenever you can; here you can't). Also note that although auto const& looks like an awesome thing for "normal" collections, it's actually obfuscating the fact that you have a collection of pointers.
| for(auto const& arg : obsSetOrig) { | |
| auto var = dynamic_cast<RooRealVar*>(arg); | |
| if(var == nullptr) break; | |
| for(auto const arg : obsSetOrig) { | |
| auto var = static_cast<RooRealVar*>(arg); | |
| assert(dynamic_cast<RooRealVar*>(arg)); |
There was a problem hiding this comment.
And if you want (I never went there), you can write an adapter that exposes a special kind of iterator:
for (auto const pvar : CastCollection<const RooRealVar*>(obsSetOrig) ) {
pvar->GetName();
}Maybe you can get some inspiration from #8421
There was a problem hiding this comment.
Thanks for the comment! Very good point, I was too cautions here and didn't want to change the logic of the code. I'll do it now.
* use `std::unique_ptr` * use range-based loops * use overloads of `getObservables` and `getParameters that don't do heap allocation
e144515 to
1bdeafd
Compare
|
@phsft-bot build |
|
Starting build on |
|
Build failed on ROOT-debian10-i386/cxx14. Errors:
|
|
Build failed on ROOT-ubuntu16/nortcxxmod. Failing tests: |
|
@phsft-bot build (ne more round of tests now that |
|
Starting build on |
|
Build failed on ROOT-ubuntu16/nortcxxmod. Errors:
|
|
Since the ROOT-ubuntu16 tests passed already in the previous round on a machine where it worked, we have now all the tested configurations passing. |
|
Build failed on ROOT-debian10-i386/cxx14. Errors:
|
|
Build failed on ROOT-performance-centos8-multicore/default. Errors:
|
|
Build failed on mac1014/python3. Errors:
|
|
Build failed on windows10/cxx14. Errors:
|
|
Build failed on mac11.0/cxx17. Errors:
|
See commit descriptions.