Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetIndicesMatcher.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetIndicesMatcher.cc
1 #include "JetIndicesMatcher.h"
2 #include "cmath"
3 using namespace std;
4 
5 JetIndicesMatcher::JetIndicesMatcher(float R, float min_T, float min_R)
6  : R2 {R*R}, min_pT_truth{min_T}, min_pT_reco{min_R}
7 {}
8 
10 {
11  eta_truth.clear();
12  phi_truth.clear();
13  pt_truth.clear();
14  index_truth.clear();
15 
16  eta_reco.clear();
17  phi_reco.clear();
18  pt_reco.clear();
19  index_reco.clear();
20 
21  indices_fake.clear();
22  indices_miss.clear();
23  indices_matched.clear();
24 }
25 
26 /* void JetIndicesMatcher::add_truth(float eta, float phi, float pt) { */
27 /* /1* if (fabs(eta)>0.6) return; *1/ */
28 /* eta_truth.push_back(eta); */
29 /* phi_truth.push_back(phi); */
30 /* pt_truth.push_back(pt); */
31 /* } */
32 
33 /* void JetIndicesMatcher::add_reco(float eta, float phi, float pt) { */
34 /* /1* if (fabs(eta)>0.6) return; *1/ */
35 /* eta_reco.push_back(eta); */
36 /* phi_reco.push_back(phi); */
37 /* pt_reco.push_back(pt); */
38 /* } */
39 
40 void JetIndicesMatcher::add_truth(vector<float>& eta, vector<float>& phi, vector<float>& pt) {
41  vector<array<float,4>> jets;
42  for (unsigned int i=0; i<eta.size(); ++i) {
43  jets.push_back({pt[i],eta[i],phi[i], (float) i});
44  }
45  std::sort(jets.rbegin(), jets.rend());
46  for (auto jet : jets) {
47  pt_truth .push_back(jet[0]);
48  eta_truth .push_back(jet[1]);
49  phi_truth .push_back(jet[2]);
50  index_truth .push_back((int)jet[3]);
51  }
52 }
53 void JetIndicesMatcher::add_reco(vector<float>& eta, vector<float>& phi, vector<float>& pt) {
54  vector<array<float,4>> jets;
55  for (unsigned int i=0; i<eta.size(); ++i) {
56  jets.push_back({pt[i],eta[i],phi[i], (float)i});
57  }
58  std::sort(jets.rbegin(), jets.rend());
59  for (auto jet : jets) {
60  pt_reco .push_back(jet[0]);
61  eta_reco .push_back(jet[1]);
62  phi_reco .push_back(jet[2]);
63  index_reco .push_back((int)jet[3]);
64  }
65 }
66 array<unsigned int,3> JetIndicesMatcher::do_matching() {
67  indices_fake.clear();
68  indices_miss.clear();
69  indices_matched.clear();
70 
71  vector<bool> is_matched (eta_reco.size(),false);
72 
73  //FIXME
74  /* cout << " Matching Truth Jets " << endl; */
75  /* for (int i = 0; i< pt_truth.size(); ++i) { */
76  /* cout << Form(" Tjet [%2i] pt:phi:eta [%5.2f,%5.2f,%5.2f]", */
77  /* i, pt_truth[i],phi_truth[i],eta_truth[i]) <<endl; */
78  /* } */
79  /* cout << " In matcher : Reco Jets " << endl; */
80  /* for (int i = 0; i< pt_reco.size(); ++i) { */
81  /* cout << Form(" Mjet [%2i] pt:phi:eta [%5.2f,%5.2f,%5.2f]", */
82  /* i, pt_reco[i],phi_reco[i],eta_reco[i]) <<endl; */
83  /* } */
84 
85 
86  for (unsigned int T=0;T<eta_truth.size();++T) {
87  if (pt_truth[T]<min_pT_truth) continue;
88  /* if (fabs(eta_truth[T])>0.6) continue; */
89  bool found_match { false };
90  for (unsigned int R=0;R<eta_reco.size();++R) {
91  if (pt_reco[R]<min_pT_reco) continue;
92  /* if (fabs(eta_reco[R])>0.6) continue; */
93  if (is_matched[R]) continue;
94  float dphi = fabs(phi_truth[T]-phi_reco[R]);
95  while (dphi>M_PI) dphi = fabs(dphi - 2*M_PI);
96  const float deta = eta_truth[T]-eta_reco[R];
97  const float R2_comp = deta*deta + dphi*dphi;
98  if (R2_comp<=R2) {
99  found_match = true;
100  is_matched[R] = true;
101  indices_matched.push_back({index_truth[T],index_reco[R]});
102 
103  /* cout << " ADDED MATCH( " << T << ":"<<R<<")" << endl; */
104  break;
105  }
106  }
107  if (!found_match) indices_miss.push_back(index_truth[T]);
108  }
109  for (unsigned int R=0;R<eta_reco.size();++R) {
110  /* cout << " min_pT_reco: " << min_pT_reco << " and["<<R<<"] " << pt_reco[R] << endl; */
111  if (pt_reco[R]<min_pT_reco) continue;
112  if (!is_matched[R]) {
113  indices_fake.push_back(index_reco[R]);
114  /* cout << " indices fake: "; for (auto I : indices_fake) cout << " " << I; cout << endl; */
115  }
116  }
117  return {static_cast<unsigned int>(indices_matched.size()),
118  static_cast<unsigned int>(indices_miss.size()),
119  static_cast<unsigned int>(indices_fake.size())};
120 }