10 #include "Math/VectorUtil.h"
27 template<
typename RecContainer = std::vector<RecJet>,
28 typename GenContainer = std::vector<GenJet>>
struct JMEmatching {
30 using RecIt = RecContainer::iterator;
31 using GenIt = GenContainer::iterator;
32 using Couple = std::pair<RecIt, GenIt>;
41 GenContainer& genJets)
47 size_t nRec = distance(recJets.begin(), recJets.end()),
48 nGen = distance(genJets.begin(), genJets.end());
52 typedef pair<size_t,size_t> Indices;
54 auto DeltaR2 = [&recJets,&genJets](
const Indices& indices) {
55 const FourVector& recJet = recJets[indices.first ].p4,
56 genJet = genJets[indices.second].p4;
57 return ROOT::Math::VectorUtil::DeltaR2(recJet, genJet);
60 auto ascending_DR2 = [&DeltaR2](
const Indices& l,
const Indices& r) {
61 return DeltaR2(l) > DeltaR2(r);
67 priority_queue< Indices,
68 vector<Indices>, decltype(ascending_DR2)>
69 candidates(ascending_DR2);
70 for (
size_t iRec = 0; iRec < nRec; ++iRec)
71 for (
size_t iGen = 0; iGen < nGen; ++iGen) {
72 Indices indices {iRec, iGen};
73 auto DR2 = DeltaR2(indices);
74 if (DR2 >= pow(
maxDR,2))
continue;
75 candidates.emplace( move(indices) );
80 vector<bool> matchedRec(nRec,
false),
81 matchedGen(nGen,
false);
83 while (!candidates.empty()) {
84 auto [iRec, iGen] = candidates.top();
88 if (matchedRec.at(iRec))
continue;
89 if (matchedGen.at(iGen))
continue;
90 matchedRec.at(iRec) =
true;
91 matchedGen.at(iGen) =
true;
93 RecIt rec_it = recJets.begin();
94 GenIt gen_it = genJets.begin();
95 advance(rec_it, iRec);
96 advance(gen_it, iGen);
98 match_its.push_back( make_pair(rec_it, gen_it) );
104 for (
int iRec = 0; iRec < nRec; ++iRec) {
105 if (matchedRec.at(iRec))
continue;
106 RecIt fake_it = recJets.begin();
107 advance(fake_it, iRec);
112 for (
int iGen = 0; iGen < nGen; ++iGen) {
113 if (matchedGen.at(iGen))
continue;
114 GenIt miss_it = genJets.begin();
115 advance(miss_it, iGen);
120 template<
typename RecContainer,
typename GenContainer>