Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-03 08:59:02

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 <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Utilities/AnnealingUtility.hpp"
0012 
0013 #include <iostream>
0014 #include <vector>
0015 
0016 using namespace Acts;
0017 
0018 namespace ActsTests {
0019 
0020 BOOST_AUTO_TEST_SUITE(UtilitiesSuite)
0021 
0022 BOOST_AUTO_TEST_CASE(annealing_tool_singleChi2_tests) {
0023   std::vector<double> temperatures{64., 16., 4., 2., 1.5, 1.};
0024   AnnealingUtility::Config config;
0025   config.setOfTemperatures = temperatures;
0026   AnnealingUtility annealingTool(config);
0027 
0028   AnnealingUtility::State state;
0029 
0030   // Test weight decrease when annealing for chi2>cutOff
0031   // choose a chi2 greater than default config.cutOff (=9.),
0032   // such that it should decrease with decreasing temperature
0033   double chi2 = config.cutOff + 3.14;
0034 
0035   // cache last weight
0036   double previousWeight = 1.;
0037 
0038   std::cout << "Check weight decrease:" << std::endl;
0039   for (auto temp : temperatures) {
0040     double weight = annealingTool.getWeight(state, chi2);
0041 
0042     bool hasDecreased = weight < previousWeight;
0043 
0044     BOOST_CHECK(hasDecreased);
0045 
0046     previousWeight = weight;
0047     annealingTool.anneal(state);
0048 
0049     std::cout << "\tTemperature: " << temp << ", weight: " << weight
0050               << std::endl;
0051   }
0052 
0053   // equilibrium should be reached here
0054   BOOST_CHECK_EQUAL(state.equilibriumReached, true);
0055 
0056   // test reset
0057   state = AnnealingUtility::State();
0058 
0059   BOOST_CHECK_EQUAL(state.currentTemperatureIndex, 0u);
0060   BOOST_CHECK_EQUAL(state.equilibriumReached, false);
0061 
0062   // Test weight increase when annealing for chi2<cutOff
0063   // choose a chi2 smaller than default config.cutOff (=9.),
0064   // such that it should increase with decreasing temperature
0065   chi2 = config.cutOff - 3.14;
0066 
0067   // cache last weight
0068   previousWeight = 0.;
0069 
0070   std::cout << "Check weight increase:" << std::endl;
0071   for (auto temp : temperatures) {
0072     double weight = annealingTool.getWeight(state, chi2);
0073 
0074     bool hasIncreased = weight > previousWeight;
0075 
0076     BOOST_CHECK(hasIncreased);
0077 
0078     previousWeight = weight;
0079     annealingTool.anneal(state);
0080 
0081     std::cout << "\tTemperature: " << temp << ", weight: " << weight
0082               << std::endl;
0083   }
0084 
0085   // reset for last test
0086   state = AnnealingUtility::State();
0087 
0088   // Test weight insensitivity when annealing for chi2==cutOff
0089   // choose a chi2 equal default config.cutOff (=9.),
0090   // such that it should be insensitive to decreasing temperature
0091   chi2 = config.cutOff;
0092 
0093   // cache last weight
0094   previousWeight = 0.5;
0095 
0096   std::cout << "Check weight insensitivity:" << std::endl;
0097   for (auto temp : temperatures) {
0098     double weight = annealingTool.getWeight(state, chi2);
0099 
0100     bool hasNotChanged = weight == previousWeight;
0101 
0102     BOOST_CHECK(hasNotChanged);
0103 
0104     previousWeight = weight;
0105     annealingTool.anneal(state);
0106 
0107     std::cout << "\tTemperature: " << temp << ", weight: " << weight
0108               << std::endl;
0109   }
0110 }
0111 
0112 BOOST_AUTO_TEST_CASE(annealing_tool_multiChi2_tests) {
0113   // vector of different chi2
0114   std::vector<double> allChi2{1.3, 4.5, 8.4,  0.4, 10.3, 12.3,
0115                               3.5, 5.8, 11.0, 1.1, 3.5,  6.7};
0116 
0117   std::vector<double> temperatures{64., 16., 4., 2., 1.5, 1.};
0118   AnnealingUtility::Config config;
0119   config.setOfTemperatures = {64., 16., 4., 2., 1.5, 1.};
0120   AnnealingUtility annealingTool(config);
0121 
0122   AnnealingUtility::State state;
0123 
0124   // Test weight decrease when annealing for chi2>cutOff
0125   // choose a chi2 greater than default config.cutOff (=9.),
0126   // such that it should decrease with decreasing temperature
0127   double chi2 = config.cutOff + 5.;
0128 
0129   // cache last weight
0130   double previousWeight = 1.;
0131 
0132   std::cout << "Check weight decrease:" << std::endl;
0133   for (auto temp : temperatures) {
0134     double weight = annealingTool.getWeight(state, chi2, allChi2);
0135 
0136     bool hasDecreased = weight < previousWeight;
0137 
0138     BOOST_CHECK(hasDecreased);
0139 
0140     previousWeight = weight;
0141     annealingTool.anneal(state);
0142 
0143     std::cout << "\tTemperature: " << temp << ", weight: " << weight
0144               << std::endl;
0145   }
0146 
0147   // equilibrium should be reached here
0148   BOOST_CHECK_EQUAL(state.equilibriumReached, true);
0149 
0150   // test reset
0151   state = AnnealingUtility::State();
0152 
0153   BOOST_CHECK_EQUAL(state.currentTemperatureIndex, 0u);
0154   BOOST_CHECK_EQUAL(state.equilibriumReached, false);
0155 
0156   // Test weight increase when annealing for chi2<cutOff
0157   // choose a chi2 smaller than default config.cutOff (=9.),
0158   // such that it should increase with decreasing temperature
0159   chi2 = 1.234;
0160 
0161   // cache last weight
0162   previousWeight = 0.;
0163 
0164   std::cout << "Check weight increase:" << std::endl;
0165   for (auto temp : temperatures) {
0166     double weight = annealingTool.getWeight(state, chi2, allChi2);
0167 
0168     bool hasIncreased = weight > previousWeight;
0169 
0170     BOOST_CHECK(hasIncreased);
0171 
0172     previousWeight = weight;
0173     annealingTool.anneal(state);
0174 
0175     std::cout << "\tTemperature: " << temp << ", weight: " << weight
0176               << std::endl;
0177   }
0178 }
0179 
0180 BOOST_AUTO_TEST_SUITE_END()
0181 
0182 }  // namespace ActsTests