Skip to content

Commit 1a12302

Browse files
authored
[PWGJE] reducing cpu of rho estimator (#10278)
1 parent c4efa89 commit 1a12302

File tree

6 files changed

+271
-85
lines changed

6 files changed

+271
-85
lines changed

PWGJE/Core/JetMatchingUtilities.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,14 @@ template <bool jetsBaseIsMc, bool jetsTagIsMc, typename T, typename U, typename
365365
void MatchHF(T const& jetsBasePerCollision, U const& jetsTagPerCollision, std::vector<std::vector<int>>& baseToTagMatchingHF, std::vector<std::vector<int>>& tagToBaseMatchingHF, V const& /*candidatesBase*/, M const& /*candidatesTag*/, N const& tracksBase, O const& tracksTag)
366366
{
367367
for (const auto& jetBase : jetsBasePerCollision) {
368+
if (jetBase.candidatesIds().size() == 0) {
369+
continue;
370+
}
368371
const auto candidateBase = jetBase.template candidates_first_as<V>();
369372
for (const auto& jetTag : jetsTagPerCollision) {
373+
if (jetTag.candidatesIds().size() == 0) {
374+
continue;
375+
}
370376
if (std::round(jetBase.r()) != std::round(jetTag.r())) {
371377
continue;
372378
}

PWGJE/TableProducer/Matching/Substructure/jetSubstructureMatching.cxx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct JetSubstructureMatching {
5858
Configurable<bool> doMatchingHf{"doMatchingHf", false, "Enable HF matching"};
5959
Configurable<float> maxMatchingDistance{"maxMatchingDistance", 0.24f, "Max matching distance"};
6060
Configurable<float> minPtFraction{"minPtFraction", 0.5f, "Minimum pt fraction for pt matching"};
61+
Configurable<bool> requireGeoMatchedJets{"requireGeoMatchedJets", false, "require jets are geo matched as well"};
6162
Configurable<bool> requirePtMatchedJets{"requirePtMatchedJets", false, "require jets are pT matched as well"};
6263
Configurable<bool> requireHFMatchedJets{"requireHFMatchedJets", false, "require jets are HF matched as well"};
6364

@@ -107,6 +108,16 @@ struct JetSubstructureMatching {
107108
}
108109
}
109110

111+
template <typename T>
112+
auto defaultMatchedJets(T const& jetTag)
113+
{
114+
if constexpr (jetcandidateutilities::isCandidateTable<CandidatesBase>()) {
115+
return jetTag.template matchedJetCand_as<JetsBase>();
116+
} else {
117+
return jetTag.template matchedJetGeo_as<JetsBase>();
118+
}
119+
}
120+
110121
void processData(JetsTag const& jetsTag,
111122
JetsBase const&,
112123
SplittingsBase const& jetsBaseSplittings,
@@ -144,7 +155,13 @@ struct JetSubstructureMatching {
144155
jetBasePairsMap.resize(jetsBasePairs.size(), -1);
145156

146157
for (auto jetTag : jetsTag) {
147-
if (jetTag.has_matchedJetGeo()) {
158+
bool hasMatchedJet = false;
159+
if constexpr (jetcandidateutilities::isCandidateTable<CandidatesBase>()) {
160+
hasMatchedJet = jetTag.has_matchedJetCand();
161+
} else {
162+
hasMatchedJet = jetTag.has_matchedJetGeo();
163+
}
164+
if (hasMatchedJet) {
148165
// auto const& jetTagSplittings = jetsTagSplittings.sliceBy(TagSplittingsPerTagJet, jetTag.globalIndex());
149166
auto const& jetTagSplittings = slicedPerJetForMatching<CandidatesTag>(jetsTagSplittings, jetTag, TagSplittingsPerTagJetInclusive, TagSplittingsPerTagJetD0, TagSplittingsPerTagJetDplus, TagSplittingsPerTagJetLc, TagSplittingsPerTagJetBplus, TagSplittingsPerTagJetDielectron);
150167
int tagSplittingIndex = 0;
@@ -159,7 +176,18 @@ struct JetSubstructureMatching {
159176
jetTagPairsMap[jetTagPair.globalIndex()] = tagPairIndex;
160177
tagPairIndex++;
161178
}
162-
for (auto& jetBase : jetTag.template matchedJetGeo_as<JetsBase>()) {
179+
for (auto& jetBase : defaultMatchedJets(jetTag)) {
180+
if (requireGeoMatchedJets) {
181+
bool jetsMatchedWithGeo = false;
182+
for (auto& jetBaseForMatchGeo : jetTag.template matchedJetGeo_as<JetsBase>()) {
183+
if (jetBaseForMatchGeo.globalIndex() == jetBase.globalIndex()) {
184+
jetsMatchedWithGeo = true;
185+
}
186+
}
187+
if (!jetsMatchedWithGeo) {
188+
continue;
189+
}
190+
}
163191
if (requirePtMatchedJets) {
164192
bool jetsMatchedWithPt = false;
165193
for (auto& jetBaseForMatchPt : jetTag.template matchedJetPt_as<JetsBase>()) {

PWGJE/TableProducer/Matching/Substructure/jetSubstructureMatchingSub.cxx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct JetSubstructureMatchingSub {
5959
Configurable<bool> doMatchingHf{"doMatchingHf", false, "Enable HF matching"};
6060
Configurable<float> maxMatchingDistance{"maxMatchingDistance", 0.24f, "Max matching distance"};
6161
Configurable<float> minPtFraction{"minPtFraction", 0.5f, "Minimum pt fraction for pt matching"};
62+
Configurable<bool> requireGeoMatchedJets{"requireGeoMatchedJets", false, "require jets are geo matched as well"};
6263
Configurable<bool> requirePtMatchedJets{"requirePtMatchedJets", false, "require jets are pT matched as well"};
6364
Configurable<bool> requireHFMatchedJets{"requireHFMatchedJets", false, "require jets are HF matched as well"};
6465

@@ -108,6 +109,16 @@ struct JetSubstructureMatchingSub {
108109
}
109110
}
110111

112+
template <typename T>
113+
auto defaultMatchedJets(T const& jetTag)
114+
{
115+
if constexpr (jetcandidateutilities::isCandidateTable<Candidates>()) {
116+
return jetTag.template matchedJetCand_as<JetsBase>();
117+
} else {
118+
return jetTag.template matchedJetGeo_as<JetsBase>();
119+
}
120+
}
121+
111122
void processData(JetsTag const& jetsTag,
112123
JetsBase const&,
113124
SplittingsBase const& jetsBaseSplittings,
@@ -145,7 +156,13 @@ struct JetSubstructureMatchingSub {
145156
jetBasePairsMap.resize(jetsBasePairs.size(), -1);
146157

147158
for (auto jetTag : jetsTag) {
148-
if (jetTag.has_matchedJetGeo()) {
159+
bool hasMatchedJet = false;
160+
if constexpr (jetcandidateutilities::isCandidateTable<Candidates>()) {
161+
hasMatchedJet = jetTag.has_matchedJetCand();
162+
} else {
163+
hasMatchedJet = jetTag.has_matchedJetGeo();
164+
}
165+
if (hasMatchedJet) {
149166
// auto const& jetTagSplittings = jetsTagSplittings.sliceBy(TagSplittingsPerTagJet, jetTag.globalIndex());
150167
auto const& jetTagSplittings = slicedPerJetForMatching<Candidates>(jetsTagSplittings, jetTag, TagSplittingsPerTagJetInclusive, TagSplittingsPerTagJetD0, TagSplittingsPerTagJetDplus, TagSplittingsPerTagJetLc, TagSplittingsPerTagJetBplus, TagSplittingsPerTagJetDielectron);
151168
int tagSplittingIndex = 0;
@@ -160,7 +177,18 @@ struct JetSubstructureMatchingSub {
160177
jetTagPairsMap[jetTagPair.globalIndex()] = tagPairIndex;
161178
tagPairIndex++;
162179
}
163-
for (auto& jetBase : jetTag.template matchedJetGeo_as<JetsBase>()) {
180+
for (auto& jetBase : defaultMatchedJets(jetTag)) {
181+
if (requireGeoMatchedJets) {
182+
bool jetsMatchedWithGeo = false;
183+
for (auto& jetBaseForMatchGeo : jetTag.template matchedJetGeo_as<JetsBase>()) {
184+
if (jetBaseForMatchGeo.globalIndex() == jetBase.globalIndex()) {
185+
jetsMatchedWithGeo = true;
186+
}
187+
}
188+
if (!jetsMatchedWithGeo) {
189+
continue;
190+
}
191+
}
164192
if (requirePtMatchedJets) {
165193
bool jetsMatchedWithPt = false;
166194
for (auto& jetBaseForMatchPt : jetTag.template matchedJetPt_as<JetsBase>()) {

0 commit comments

Comments
 (0)