File indexing completed on 2025-08-06 08:14:12
0001 #include "JetIndicesMatcher.h"
0002 #include "cmath"
0003 using namespace std;
0004
0005 JetIndicesMatcher::JetIndicesMatcher(float R, float min_T, float min_R)
0006 : R2 {R*R}, min_pT_truth{min_T}, min_pT_reco{min_R}
0007 {}
0008
0009 void JetIndicesMatcher::reset()
0010 {
0011 eta_truth.clear();
0012 phi_truth.clear();
0013 pt_truth.clear();
0014 index_truth.clear();
0015
0016 eta_reco.clear();
0017 phi_reco.clear();
0018 pt_reco.clear();
0019 index_reco.clear();
0020
0021 indices_fake.clear();
0022 indices_miss.clear();
0023 indices_matched.clear();
0024 }
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 void JetIndicesMatcher::add_truth(vector<float>& eta, vector<float>& phi, vector<float>& pt) {
0041 vector<array<float,4>> jets;
0042 for (unsigned int i=0; i<eta.size(); ++i) {
0043 jets.push_back({pt[i],eta[i],phi[i], (float) i});
0044 }
0045 std::sort(jets.rbegin(), jets.rend());
0046 for (auto jet : jets) {
0047 pt_truth .push_back(jet[0]);
0048 eta_truth .push_back(jet[1]);
0049 phi_truth .push_back(jet[2]);
0050 index_truth .push_back((int)jet[3]);
0051 }
0052 }
0053 void JetIndicesMatcher::add_reco(vector<float>& eta, vector<float>& phi, vector<float>& pt) {
0054 vector<array<float,4>> jets;
0055 for (unsigned int i=0; i<eta.size(); ++i) {
0056 jets.push_back({pt[i],eta[i],phi[i], (float)i});
0057 }
0058 std::sort(jets.rbegin(), jets.rend());
0059 for (auto jet : jets) {
0060 pt_reco .push_back(jet[0]);
0061 eta_reco .push_back(jet[1]);
0062 phi_reco .push_back(jet[2]);
0063 index_reco .push_back((int)jet[3]);
0064 }
0065 }
0066 array<unsigned int,3> JetIndicesMatcher::do_matching() {
0067 indices_fake.clear();
0068 indices_miss.clear();
0069 indices_matched.clear();
0070
0071 vector<bool> is_matched (eta_reco.size(),false);
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 for (unsigned int T=0;T<eta_truth.size();++T) {
0087 if (pt_truth[T]<min_pT_truth) continue;
0088
0089 bool found_match { false };
0090 for (unsigned int R=0;R<eta_reco.size();++R) {
0091 if (pt_reco[R]<min_pT_reco) continue;
0092
0093 if (is_matched[R]) continue;
0094 float dphi = fabs(phi_truth[T]-phi_reco[R]);
0095 while (dphi>M_PI) dphi = fabs(dphi - 2*M_PI);
0096 const float deta = eta_truth[T]-eta_reco[R];
0097 const float R2_comp = deta*deta + dphi*dphi;
0098 if (R2_comp<=R2) {
0099 found_match = true;
0100 is_matched[R] = true;
0101 indices_matched.push_back({index_truth[T],index_reco[R]});
0102
0103
0104 break;
0105 }
0106 }
0107 if (!found_match) indices_miss.push_back(index_truth[T]);
0108 }
0109 for (unsigned int R=0;R<eta_reco.size();++R) {
0110
0111 if (pt_reco[R]<min_pT_reco) continue;
0112 if (!is_matched[R]) {
0113 indices_fake.push_back(index_reco[R]);
0114
0115 }
0116 }
0117 return {static_cast<unsigned int>(indices_matched.size()),
0118 static_cast<unsigned int>(indices_miss.size()),
0119 static_cast<unsigned int>(indices_fake.size())};
0120 }