|
|
|||
File indexing completed on 2026-11-07 09:44:13
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 #pragma once 0010 0011 #include "Acts/Utilities/Histogram.hpp" 0012 0013 #include <optional> 0014 #include <string> 0015 #include <tuple> 0016 #include <utility> 0017 0018 namespace ActsPlugins { 0019 0020 /// Fit a Gaussian to a histogram via ROOT's `TH1::Fit` 0021 /// 0022 /// `operator()`'s signature matches `ActsExamples::HistogramFitFunction` 0023 /// exactly, so a `RootHistogramFit` instance can be used directly as one with 0024 /// no adapter. 0025 class RootHistogramFit { 0026 public: 0027 /// Configuration for @c RootHistogramFit 0028 struct Config { 0029 /// `TH1::Fit` option string. Must keep `"S"` (return a `TFitResult`) and 0030 /// `"0"` (do not draw); the ranged fit adds `"R"` itself. Defaults to 0031 /// ROOT's least-squares fit; use `"LSQ0"` for the likelihood fit instead. 0032 std::string fitOptions = "SQ0"; 0033 }; 0034 0035 /// Outcome of the fit: `(mean, sigma, meanError, sigmaError)` 0036 using Result = std::tuple<double, double, double, double>; 0037 /// Fit range `[xMin, xMax]`, closed, selected by bin centre 0038 using Range = std::pair<double, double>; 0039 0040 RootHistogramFit() = default; 0041 0042 /// Construct with the given configuration 0043 /// @param config The fit configuration 0044 explicit RootHistogramFit(Config config) : m_config(std::move(config)) {} 0045 0046 /// The fit configuration 0047 /// @return The configuration this instance was constructed with 0048 const Config& config() const { return m_config; } 0049 0050 /// Fit a Gaussian to a histogram, optionally restricted to a range 0051 /// 0052 /// @param hist The histogram to fit 0053 /// @param range If set, only bins whose centre lies in `[range->first, 0054 /// range->second]` enter the fit 0055 /// @return `(mean, sigma, meanError, sigmaError)`, or `std::nullopt` if the 0056 /// fit could not be performed 0057 std::optional<Result> operator()( 0058 const Acts::Experimental::Histogram1& hist, 0059 std::optional<Range> range = std::nullopt) const; 0060 0061 private: 0062 Config m_config{}; 0063 }; 0064 0065 } // namespace ActsPlugins
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|