Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:31

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 "Acts/Utilities/AnnealingUtility.hpp"
0010 
0011 #include "Acts/Utilities/AlgebraHelpers.hpp"
0012 
0013 namespace {
0014 /// @brief Gaussian-like function for weight calculation
0015 /// Note: Factor 2 in denominator is included in inverse temperature
0016 ///
0017 /// @param chi2 Chi^2 value
0018 /// @param invTemp Denominator 1/(2 * temperature)
0019 ///
0020 /// @return exp(-chi2 * invTemp)
0021 double computeAnnealingWeight(double chi2, double invTemp) {
0022   return Acts::safeExp(-chi2 * invTemp);
0023 }
0024 }  // namespace
0025 
0026 Acts::AnnealingUtility::Config::Config() = default;
0027 
0028 void Acts::AnnealingUtility::anneal(State& state) const {
0029   if (state.currentTemperatureIndex < m_cfg.setOfTemperatures.size() - 1) {
0030     ++state.currentTemperatureIndex;
0031   } else {
0032     state.equilibriumReached = true;
0033   }
0034 }
0035 
0036 double Acts::AnnealingUtility::getWeight(
0037     State& state, double chi2, const std::vector<double>& allChi2) const {
0038   unsigned int idx = state.currentTemperatureIndex;
0039   // Calculate 1/denominator in exp function already here
0040   const double currentInvTemp = 1. / (2. * m_cfg.setOfTemperatures[idx]);
0041 
0042   double num = computeAnnealingWeight(chi2, currentInvTemp);
0043 
0044   double denom = m_gaussCutTempVec[idx];
0045 
0046   for (double val : allChi2) {
0047     denom += computeAnnealingWeight(val, currentInvTemp);
0048   }
0049 
0050   return num / denom;
0051 }
0052 
0053 double Acts::AnnealingUtility::getWeight(State& state, double chi2) const {
0054   // Calculate 1/denominator in exp function
0055   const double currentInvTemp =
0056       1. / (2 * m_cfg.setOfTemperatures[state.currentTemperatureIndex]);
0057 
0058   return 1. /
0059          (1. + computeAnnealingWeight(m_cfg.cutOff - chi2, currentInvTemp));
0060 }