Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:55

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