@@ -79,19 +79,19 @@ FitResult::FitResult(const FitConfig & fconfig) :
7979
8080 // get parameter values and errors (step sizes)
8181 unsigned int npar = fconfig.NPar ();
82+ fParamBounds .resize (npar);
83+ fFixedParams .resize (npar);
84+ fBoundParams .resize (npar);
8285 for (unsigned int i = 0 ; i < npar; ++i ) {
8386 const ParameterSettings & par = fconfig.ParSettings (i);
8487 fParams [i] = par.Value ();
8588 fErrors [i] = par.StepSize ();
8689 fParNames [i] = par.Name ();
87- if (par.IsFixed () ) fFixedParams [i] = true ;
88- else fNFree ++;
89- if (par.IsBound () ) {
90- double lower = (par.HasLowerLimit ()) ? par.LowerLimit () : - std::numeric_limits<double >::infinity () ;
91- double upper = (par.HasUpperLimit ()) ? par.UpperLimit () : std::numeric_limits<double >::infinity () ;
92- fBoundParams [i] = fParamBounds .size ();
93- fParamBounds .push_back (std::make_pair (lower,upper));
94- }
90+ fFixedParams [i] = par.IsFixed ();
91+ if (!par.IsFixed () ) fNFree ++;
92+ double lower = par.HasLowerLimit () ? par.LowerLimit () : - std::numeric_limits<double >::infinity () ;
93+ double upper = par.HasUpperLimit () ? par.UpperLimit () : std::numeric_limits<double >::infinity () ;
94+ fParamBounds .emplace_back (lower,upper);
9595 }
9696 std::cout << " create fit result from config - nfree " << fNFree << std::endl;
9797}
@@ -155,17 +155,17 @@ void FitResult::FillResult(const std::shared_ptr<ROOT::Math::Minimizer> & min, c
155155
156156 // check for fixed or limited parameters
157157 unsigned int nfree = 0 ;
158- if (!fParamBounds .empty ()) fParamBounds .clear ();
158+ fParamBounds .resize (npar);
159+ fFixedParams .resize (npar);
160+ fBoundParams .resize (npar);
159161 for (unsigned int ipar = 0 ; ipar < npar; ++ipar) {
160162 const ParameterSettings & par = fconfig.ParSettings (ipar);
161- if (par.IsFixed () ) fFixedParams [ipar] = true ;
162- else nfree++;
163- if (par.IsBound () ) {
164- double lower = (par.HasLowerLimit ()) ? par.LowerLimit () : - std::numeric_limits<double >::infinity () ;
165- double upper = (par.HasUpperLimit ()) ? par.UpperLimit () : std::numeric_limits<double >::infinity () ;
166- fBoundParams [ipar] = fParamBounds .size ();
167- fParamBounds .push_back (std::make_pair (lower,upper));
168- }
163+ fFixedParams [ipar] = par.IsFixed ();
164+ fBoundParams [ipar] = par.IsBound ();
165+ if (!par.IsFixed () ) nfree++;
166+ double lower = par.HasLowerLimit () ? par.LowerLimit () : - std::numeric_limits<double >::infinity () ;
167+ double upper = par.HasUpperLimit () ? par.UpperLimit () : std::numeric_limits<double >::infinity () ;
168+ fParamBounds .emplace_back (lower,upper);
169169 }
170170 // check if nfree (from FitConfig) and fNFree (from minimizer) are consistent
171171 if (nfree != fNFree ) {
@@ -343,25 +343,24 @@ int FitResult::Index(const std::string & name) const {
343343 return -1 ; // case name is not found
344344}
345345
346- bool FitResult::IsParameterBound (unsigned int ipar) const {
347- return fBoundParams .find (ipar) != fBoundParams .end ();
346+ bool FitResult::IsParameterBound (unsigned int ipar) const
347+ {
348+ return ipar < fBoundParams .size () ? fBoundParams [ipar] : false ;
348349}
349350
350- bool FitResult::IsParameterFixed (unsigned int ipar) const {
351- return fFixedParams .find (ipar) != fFixedParams .end ();
351+ bool FitResult::IsParameterFixed (unsigned int ipar) const
352+ {
353+ return ipar < fFixedParams .size () ? fFixedParams [ipar] : false ;
352354}
353355
354- bool FitResult::ParameterBounds (unsigned int ipar, double & lower, double & upper) const {
355- std::map< unsigned int , unsigned int >::const_iterator itr = fBoundParams . find (ipar);
356- if (itr == fBoundParams . end () ) {
357- lower = -std::numeric_limits<Double_t>:: infinity ();
358- upper = std::numeric_limits<Double_t>:: infinity () ;
359- return false ;
356+ bool FitResult::ParameterBounds (unsigned int ipar, double &lower, double &upper) const
357+ {
358+ constexpr double inf = std::numeric_limits< double >:: infinity ();
359+ if (ipar < fParamBounds . size ()) {
360+ lower = fParamBounds [ipar]. first ;
361+ upper = fParamBounds [ipar]. second ;
360362 }
361- assert (itr->second < fParamBounds .size () );
362- lower = fParamBounds [itr->second ].first ;
363- upper = fParamBounds [itr->second ].second ;
364- return true ;
363+ return lower != -inf || upper != inf;
365364}
366365
367366std::string FitResult::ParName (unsigned int ipar) const {
0 commit comments