@@ -332,7 +332,6 @@ void RooMinimizer::determineStatus(bool fitterReturnValue)
332
332
// / \param[in] alg Fit algorithm to use. (Optional)
333
333
int RooMinimizer::minimize (const char *type, const char *alg)
334
334
{
335
- FreezeDisconnectedParametersRAII freeze (this , *_fcn);
336
335
337
336
if (_cfg.timingAnalysis ) {
338
337
#ifdef ROOFIT_MULTIPROCESS
@@ -778,6 +777,7 @@ void RooMinimizer::profileStop()
778
777
779
778
ROOT::Math::IMultiGenFunction *RooMinimizer::getMultiGenFcn () const
780
779
{
780
+
781
781
return _fcn->getMultiGenFcn ();
782
782
}
783
783
@@ -908,19 +908,19 @@ bool RooMinimizer::fitFCN(const ROOT::Math::IMultiGenFunction &fcn)
908
908
{
909
909
// fit a user provided FCN function
910
910
// create fit parameter settings
911
+
911
912
// Check number of parameters
912
913
unsigned int npar = fcn.NDim ();
913
914
if (npar == 0 ) {
914
915
coutE (Minimization) << " RooMinimizer::fitFCN(): FCN function has zero parameters" << std::endl;
915
916
return false ;
916
917
}
917
918
918
- // initiate the minimizer
919
+ // initiate the minimizer
919
920
initMinimizer ();
920
921
921
922
// Identify floating RooCategory parameters
922
923
RooArgSet floatingCats;
923
-
924
924
for (auto arg : _fcn->allParams ()) {
925
925
if (arg->isCategory () && !arg->isConstant ())
926
926
floatingCats.add (*arg);
@@ -942,7 +942,8 @@ bool RooMinimizer::fitFCN(const ROOT::Math::IMultiGenFunction &fcn)
942
942
}
943
943
944
944
if (nPdfs == 0 ) {
945
-
945
+ coutI (Minimization) << " [fitFCN] No discrete parameters, performing continuous minimization only" << std::endl;
946
+ FreezeDisconnectedParametersRAII freeze (this , *_fcn);
946
947
bool isValid = _minimizer->Minimize ();
947
948
if (!_result)
948
949
_result = std::make_unique<FitResult>();
@@ -953,8 +954,7 @@ bool RooMinimizer::fitFCN(const ROOT::Math::IMultiGenFunction &fcn)
953
954
}
954
955
955
956
// set also new parameter values and errors in FitConfig
956
-
957
- // Prepare discrete indices
957
+ // Prepare discrete indices
958
958
std::vector<int > maxIndices;
959
959
for (auto *cat : pdfIndices)
960
960
maxIndices.push_back (cat->size ());
@@ -963,11 +963,10 @@ bool RooMinimizer::fitFCN(const ROOT::Math::IMultiGenFunction &fcn)
963
963
std::map<std::vector<int >, double > nllMap;
964
964
std::vector<int > bestIndices (nPdfs, 0 );
965
965
double bestNLL = 1e30 ;
966
- bool improved = true ;
967
966
967
+ bool improved = true ;
968
968
while (improved) {
969
969
improved = false ;
970
-
971
970
auto combos = generateOrthogonalCombinations (maxIndices);
972
971
reorderCombinations (combos, maxIndices, bestIndices);
973
972
@@ -984,7 +983,7 @@ bool RooMinimizer::fitFCN(const ROOT::Math::IMultiGenFunction &fcn)
984
983
wasConst[i] = pdfIndices[i]->isConstant ();
985
984
pdfIndices[i]->setConstant (true );
986
985
}
987
-
986
+ FreezeDisconnectedParametersRAII freeze ( this , *_fcn);
988
987
_minimizer->Minimize ();
989
988
990
989
for (size_t i = 0 ; i < nPdfs; ++i)
@@ -1002,36 +1001,49 @@ bool RooMinimizer::fitFCN(const ROOT::Math::IMultiGenFunction &fcn)
1002
1001
}
1003
1002
}
1004
1003
1005
- for (size_t i = 0 ; i < nPdfs; ++i)
1004
+ for (size_t i = 0 ; i < nPdfs; ++i) {
1006
1005
pdfIndices[i]->setIndex (bestIndices[i]);
1006
+ pdfIndices[i]->setConstant (true );
1007
+ }
1008
+
1009
+ FreezeDisconnectedParametersRAII freeze (this , *_fcn);
1010
+ _minimizer->Minimize ();
1007
1011
1008
- coutI (Minimization) << " All NLL Values per Combination:\n " << std::endl;
1012
+ coutI (Minimization) << " All NLL Values per Combination:" << std::endl;
1009
1013
for (const auto &entry : nllMap) {
1010
1014
const auto &combo = entry.first ;
1011
1015
double val = entry.second ;
1012
- coutI (Minimization) << " Combo: [" << std::endl;
1013
- for (size_t i = 0 ; i < combo.size (); ++i)
1014
- std::cout << combo[i] << (i + 1 < combo.size () ? " , " : " " );
1015
- coutI (Minimization) << " ], NLL: " << val << " \n " << std::endl;
1016
+
1017
+ std::stringstream ss;
1018
+ ss << " Combo: [" ;
1019
+ for (size_t i = 0 ; i < combo.size (); ++i) {
1020
+ ss << combo[i];
1021
+ if (i + 1 < combo.size ())
1022
+ ss << " , " ;
1023
+ }
1024
+ ss << " ], NLL: " << val;
1025
+
1026
+ coutI (Minimization) << ss.str () << std::endl;
1016
1027
}
1017
1028
1018
- coutI (Minimization) << " DP Best Indices: [" << std::endl;
1029
+ std::stringstream ssBest;
1030
+ ssBest << " DP Best Indices: [" ;
1019
1031
for (size_t i = 0 ; i < bestIndices.size (); ++i) {
1020
- coutI (Minimization) << bestIndices[i] << std::endl ;
1032
+ ssBest << bestIndices[i];
1021
1033
if (i + 1 < bestIndices.size ())
1022
- coutI (Minimization) << " , " << std::endl ;
1034
+ ssBest << " , " ;
1023
1035
}
1024
- coutI (Minimization) << " ], NLL = " << bestNLL << " \n " << std::endl;
1036
+ ssBest << " ], NLL = " << bestNLL;
1037
+
1038
+ coutI (Minimization) << ssBest.str () << std::endl;
1025
1039
1026
- // Fill FitResult and update FitConfig
1027
1040
if (!_result)
1028
1041
_result = std::make_unique<FitResult>();
1029
1042
fillResult (true );
1030
1043
updateFitConfig ();
1031
1044
1032
1045
return true ;
1033
1046
}
1034
-
1035
1047
bool RooMinimizer::calculateHessErrors ()
1036
1048
{
1037
1049
// compute the Hesse errors according to configuration
0 commit comments