Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-26 08:20:26

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Validation/HistogramFit.hpp"
0010 
0011 #include <utility>
0012 
0013 namespace ActsExamples {
0014 
0015 std::optional<HistogramFitResult> iterativeFit(
0016     const HistogramFitFunction& fitFn,
0017     const Acts::Experimental::Histogram1& hist, double sigmaRange,
0018     int iterations, const Acts::Logger& logger) {
0019   std::optional<HistogramFitResult> result = fitFn(hist, std::nullopt);
0020   if (!result.has_value()) {
0021     ACTS_DEBUG("Failed to fit initial Gaussian to '" << hist.name() << "'");
0022     return result;
0023   }
0024 
0025   for (int i = 0; i < iterations - 1; ++i) {
0026     const double mean = std::get<0>(*result);
0027     const double sigma = std::get<1>(*result);
0028     const double xMin = mean - sigmaRange * sigma;
0029     const double xMax = mean + sigmaRange * sigma;
0030 
0031     std::optional<HistogramFitResult> restricted =
0032         fitFn(hist, HistogramFitRange{xMin, xMax});
0033     if (!restricted.has_value()) {
0034       ACTS_DEBUG("Failed to fit iteration " << i << " Gaussian to '"
0035                                             << hist.name() << "'");
0036       return restricted;
0037     }
0038 
0039     result = std::move(restricted);
0040   }
0041 
0042   return result;
0043 }
0044 
0045 }  // namespace ActsExamples