Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 07:53:00

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/Plugins/Json/AmbiguityConfigJsonConverter.hpp"
0010 
0011 #include "Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp"
0012 #include "Acts/Plugins/Json/ActsJson.hpp"
0013 
0014 void initializeEtaVector(std::vector<std::size_t>& target,
0015                          const std::vector<std::size_t>& source,
0016                          std::size_t etaBinSize) {
0017   if (source.size() == etaBinSize - 1) {
0018     // Directly copy if sizes match
0019     target = source;
0020   } else if (source.size() == 1) {
0021     // Resize target to the required size
0022     target.resize(etaBinSize - 1);
0023     // Fill with the single value from source
0024     std::fill(target.begin(), target.end(), source[0]);
0025   } else {
0026     throw std::invalid_argument("Invalid cuts size. Expected 1 or " +
0027                                 std::to_string(etaBinSize - 1) + ", got " +
0028                                 std::to_string(source.size()));
0029   }
0030 }
0031 namespace Acts {
0032 
0033 void from_json(const nlohmann::json& j, ConfigPair& p) {
0034   std::vector<ScoreBasedAmbiguityResolution::DetectorConfig> detectorConfigs;
0035   std::map<std::size_t, std::size_t> volumeMap;
0036 
0037   for (auto& [key, value] : j.items()) {
0038     ScoreBasedAmbiguityResolution::DetectorConfig detectorConfig;
0039 
0040     std::size_t detectorId = std::stoi(key);
0041 
0042     detectorConfig.hitsScoreWeight = value["hitsScoreWeight"];
0043     detectorConfig.holesScoreWeight = value["holesScoreWeight"];
0044     detectorConfig.outliersScoreWeight = value["outliersScoreWeight"];
0045     detectorConfig.otherScoreWeight = value["otherScoreWeight"];
0046 
0047     detectorConfig.sharedHitsFlag = value["sharedHitsFlag"];
0048 
0049     const std::vector<double>& goodHits = value["goodHits"];
0050     const std::vector<double>& goodHoles = value["goodHoles"];
0051 
0052     const std::vector<double>& fakeHits = value["fakeHits"];
0053     const std::vector<double>& fakeHoles = value["fakeHoles"];
0054 
0055     const std::vector<double>& etaBins = value["etaBins"];
0056 
0057     // Validate eta bins
0058     if (!etaBins.empty()) {
0059       // Verify monotonically increasing eta bins
0060       if (!std::is_sorted(etaBins.begin(), etaBins.end())) {
0061         throw std::invalid_argument(
0062             "Eta bins must be monotonically increasing");
0063       }
0064 
0065       detectorConfig.etaBins = etaBins;
0066     }
0067 
0068     const std::vector<std::size_t>& minHitsPerEta = value["minHitsPerEta"];
0069     initializeEtaVector(detectorConfig.minHitsPerEta, minHitsPerEta,
0070                         detectorConfig.etaBins.size());
0071 
0072     const std::vector<std::size_t>& maxHolesPerEta = value["maxHolesPerEta"];
0073     initializeEtaVector(detectorConfig.maxHolesPerEta, maxHolesPerEta,
0074                         detectorConfig.etaBins.size());
0075 
0076     const std::vector<std::size_t>& maxOutliersPerEta =
0077         value["maxOutliersPerEta"];
0078     initializeEtaVector(detectorConfig.maxOutliersPerEta, maxOutliersPerEta,
0079                         detectorConfig.etaBins.size());
0080 
0081     const std::vector<std::size_t>& maxSharedHitsPerEta =
0082         value["maxSharedHitsPerEta"];
0083     initializeEtaVector(detectorConfig.maxSharedHitsPerEta, maxSharedHitsPerEta,
0084                         detectorConfig.etaBins.size());
0085 
0086     if (goodHits.size() != fakeHits.size()) {
0087       throw std::invalid_argument("goodHits and FakeHits size mismatch");
0088     }
0089 
0090     detectorConfig.factorHits = {};
0091     detectorConfig.maxHits = goodHits.size() - 1;
0092     for (std::size_t i = 0; i < goodHits.size(); i++) {
0093       detectorConfig.factorHits.push_back(goodHits[i] / fakeHits[i]);
0094     }
0095 
0096     if (goodHoles.size() != fakeHoles.size()) {
0097       throw std::invalid_argument("goodHoles and FakeHoles size mismatch");
0098     }
0099 
0100     detectorConfig.factorHoles = {};
0101     detectorConfig.maxHoles = goodHoles.size() - 1;
0102     for (std::size_t i = 0; i < goodHoles.size(); i++) {
0103       detectorConfig.factorHoles.push_back(goodHoles[i] / fakeHoles[i]);
0104     }
0105 
0106     detectorConfigs.push_back(detectorConfig);
0107 
0108     std::vector<std::size_t> volumesIds = value["volumesIds"];
0109     for (auto volumeId : volumesIds) {
0110       volumeMap[volumeId] = detectorId;
0111     }
0112   }
0113   p = std::make_pair(volumeMap, detectorConfigs);
0114 }
0115 
0116 }  // namespace Acts