Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetIndicesMatcher_bkup.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetIndicesMatcher_bkup.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 
15  eta_reco.clear();
16  phi_reco.clear();
17  pt_reco.clear();
18 
19  indices_fake.clear();
20  indices_miss.clear();
21  indices_matched.clear();
22 }
23 
24 /* void JetIndicesMatcher::add_truth(float eta, float phi, float pt) { */
25 /* /1* if (fabs(eta)>0.6) return; *1/ */
26 /* eta_truth.push_back(eta); */
27 /* phi_truth.push_back(phi); */
28 /* pt_truth.push_back(pt); */
29 /* } */
30 
31 /* void JetIndicesMatcher::add_reco(float eta, float phi, float pt) { */
32 /* /1* if (fabs(eta)>0.6) return; *1/ */
33 /* eta_reco.push_back(eta); */
34 /* phi_reco.push_back(phi); */
35 /* pt_reco.push_back(pt); */
36 /* } */
37 
38 void JetIndicesMatcher::add_truth(vector<float>& eta, vector<float>& phi, vector<float>& pt) {
39  vector<array<float,3>> jets;
40  for (unsigned int i=0; i<eta.size(); ++i) {
41  jets.push_back({pt[i],eta[i],phi[i]});
42  }
43  std::sort(jets.rbegin(), jets.rend());
44  for (auto jet : jets) {
45  pt_truth .push_back(jet[0]);
46  eta_truth .push_back(jet[1]);
47  phi_truth .push_back(jet[2]);
48  }
49 }
50 void JetIndicesMatcher::add_reco(vector<float>& eta, vector<float>& phi, vector<float>& pt) {
51  vector<array<float,3>> jets;
52  for (unsigned int i=0; i<eta.size(); ++i) {
53  jets.push_back({pt[i],eta[i],phi[i]});
54  }
55  /* cout << " First: " << endl; */
56  /* for (auto jet : jets) cout << jet[0] <<":"<<jet[1]<<":"<<jet[2] << endl; */
57  std::sort(jets.rbegin(), jets.rend());
58  /* cout << " second: " << endl; */
59  for (auto jet : jets) {
60  /* cout << jet[0] <<":"<<jet[1]<<":"<<jet[2] << endl; */
61  pt_reco .push_back(jet[0]);
62  eta_reco .push_back(jet[1]);
63  phi_reco .push_back(jet[2]);
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({T,R});
102 
103  /* cout << " ADDED MATCH( " << T << ":"<<R<<")" << endl; */
104  break;
105  }
106  }
107  if (!found_match) indices_miss.push_back(T);
108  }
109  for (unsigned int R=0;R<eta_reco.size();++R) {
110  if (pt_reco[R]<min_pT_reco) continue;
111  if (!is_matched[R]) indices_fake.push_back(R);
112  }
113  return {static_cast<unsigned int>(indices_matched.size()),
114  static_cast<unsigned int>(indices_miss.size()),
115  static_cast<unsigned int>(indices_fake.size())};
116 }