Skip to content

Commit 1ea9817

Browse files
authored
[PWGJE] Adding Matched MC function + dPhi fixes (#15551)
1 parent 3ab77c2 commit 1ea9817

File tree

1 file changed

+124
-76
lines changed

1 file changed

+124
-76
lines changed

PWGJE/Tasks/jetCorrelationD0.cxx

Lines changed: 124 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,18 @@
1414
/// \author Matthew Ockleton matthew.ockleton@cern.ch, University of Liverpool
1515

1616
#include "PWGJE/Core/JetDerivedDataUtilities.h"
17+
#include "PWGJE/Core/JetHFUtilities.h"
1718
#include "PWGJE/DataModel/Jet.h"
1819
#include "PWGJE/DataModel/JetReducedData.h"
1920

2021
#include "Common/Core/RecoDecay.h"
2122

22-
#include <CommonConstants/MathConstants.h>
23-
#include <Framework/ASoA.h>
24-
#include <Framework/AnalysisDataModel.h>
25-
#include <Framework/AnalysisHelpers.h>
26-
#include <Framework/AnalysisTask.h>
27-
#include <Framework/Configurable.h>
28-
#include <Framework/HistogramRegistry.h>
29-
#include <Framework/HistogramSpec.h>
30-
#include <Framework/InitContext.h>
31-
#include <Framework/OutputObjHeader.h>
32-
#include <Framework/runDataProcessing.h>
33-
34-
#include <cstdlib>
23+
#include "Framework/AnalysisDataModel.h"
24+
#include "Framework/AnalysisTask.h"
25+
#include "Framework/HistogramRegistry.h"
26+
#include "Framework/Logger.h"
27+
#include "Framework/runDataProcessing.h"
28+
3529
#include <string>
3630
#include <type_traits>
3731
#include <vector>
@@ -58,12 +52,15 @@ DECLARE_SOA_TABLE(McCollisionTables, "AOD", "MCCOLLINFOTABLE",
5852
o2::soa::Index<>,
5953
d0collisionInfo::PosZ);
6054

55+
DECLARE_SOA_TABLE(MatchCollTables, "AOD", "MATCHCOLLTABLE",
56+
o2::soa::Index<>,
57+
d0collisionInfo::PosZ);
58+
6159
namespace collisionInfo
6260
{
63-
// DECLARE_SOA_INDEX_COLUMN(CollisionTable, collisionTable);
6461
DECLARE_SOA_INDEX_COLUMN_CUSTOM(CollisionTable, collisionTable, "COLLINFOTABLES");
65-
// DECLARE_SOA_INDEX_COLUMN(McCollisionTable, mcCollisionTable);
6662
DECLARE_SOA_INDEX_COLUMN_CUSTOM(McCollisionTable, mcCollisionTable, "MCCOLLINFOTABLES");
63+
DECLARE_SOA_INDEX_COLUMN_CUSTOM(MatchCollTable, matchCollTable, "MATCHCOLLTABLES");
6764
} // namespace collisionInfo
6865
namespace d0Info
6966
{
@@ -84,7 +81,7 @@ DECLARE_SOA_COLUMN(D0PhiD, d0PhiD, float);
8481
DECLARE_SOA_COLUMN(D0Reflection, d0Reflection, int);
8582
} // namespace d0Info
8683

87-
DECLARE_SOA_TABLE(D0DataTables, "AOD", "D0DATATABLE",
84+
DECLARE_SOA_TABLE(D0DataTables, "AOD", "D0TABLE",
8885
o2::soa::Index<>,
8986
collisionInfo::CollisionTableId,
9087
d0Info::D0PromptBDT,
@@ -114,11 +111,15 @@ DECLARE_SOA_INDEX_COLUMN(D0McPTable, d0McPTable);
114111
DECLARE_SOA_COLUMN(JetPt, jetPt, float);
115112
DECLARE_SOA_COLUMN(JetEta, jetEta, float);
116113
DECLARE_SOA_COLUMN(JetPhi, jetPhi, float);
114+
DECLARE_SOA_COLUMN(PJetPt, pJetPt, float);
115+
DECLARE_SOA_COLUMN(PJetEta, pJetEta, float);
116+
DECLARE_SOA_COLUMN(PJetPhi, pJetPhi, float);
117117
// D0-jet
118118
DECLARE_SOA_COLUMN(D0JetDeltaPhi, d0JetDeltaPhi, float);
119+
DECLARE_SOA_COLUMN(D0JetDeltaPhiP, d0JetDeltaPhiP, float);
119120
} // namespace jetInfo
120121

121-
DECLARE_SOA_TABLE_STAGED(JetDataTables, "JETDATATABLE",
122+
DECLARE_SOA_TABLE_STAGED(JetDataTables, "JETTABLE",
122123
o2::soa::Index<>,
123124
collisionInfo::CollisionTableId,
124125
jetInfo::D0DataTableId,
@@ -127,37 +128,52 @@ DECLARE_SOA_TABLE_STAGED(JetDataTables, "JETDATATABLE",
127128
jetInfo::JetPhi,
128129
jetInfo::D0JetDeltaPhi);
129130

130-
DECLARE_SOA_TABLE_STAGED(JetMCPTables, "JETMCPTABLE",
131+
DECLARE_SOA_TABLE_STAGED(JetMcPTables, "JETMCPTABLE",
131132
o2::soa::Index<>,
132133
collisionInfo::McCollisionTableId,
133134
jetInfo::D0McPTableId,
134135
jetInfo::JetPt,
135136
jetInfo::JetEta,
136137
jetInfo::JetPhi,
137-
jetInfo::D0JetDeltaPhi);
138+
jetInfo::D0JetDeltaPhiP);
139+
140+
DECLARE_SOA_TABLE_STAGED(JetMatchedTables, "JETMATCHEDTABLE",
141+
o2::soa::Index<>,
142+
collisionInfo::MatchCollTableId,
143+
jetInfo::JetPt,
144+
jetInfo::JetEta,
145+
jetInfo::JetPhi,
146+
jetInfo::PJetPt,
147+
jetInfo::PJetEta,
148+
jetInfo::PJetPhi,
149+
jetInfo::D0JetDeltaPhi,
150+
jetInfo::D0JetDeltaPhiP);
138151

139152
} // namespace o2::aod
140153

141154
struct JetCorrelationD0 {
142155
// Define new table
143156
Produces<aod::CollisionTables> tableCollision;
157+
Produces<aod::MatchCollTables> tableMatchedCollision;
144158
Produces<aod::McCollisionTables> tableMcCollision;
145159
Produces<aod::D0DataTables> tableD0;
146-
Produces<aod::D0McPTables> tableD0MCParticle;
160+
Produces<aod::D0McPTables> tableD0McParticle;
147161
Produces<aod::JetDataTables> tableJet;
148-
Produces<aod::JetMCPTables> tableJetMCParticle;
162+
Produces<aod::JetMcPTables> tableJetMcParticle;
163+
Produces<aod::JetMatchedTables> tableJetMatched;
149164

150165
// Configurables
151166
Configurable<std::string> eventSelections{"eventSelections", "sel8", "choose event selection"};
152167
Configurable<bool> skipMBGapEvents{"skipMBGapEvents", false, "decide to run over MB gap events or not"};
153168
Configurable<bool> applyRCTSelections{"applyRCTSelections", true, "decide to apply RCT selections"};
154-
// Configurable<std::string> triggerMasks{"triggerMasks", "", "possible JE Trigger masks: fJetChLowPt,fJetChHighPt,fTrackLowPt,fTrackHighPt,fJetD0ChLowPt,fJetD0ChHighPt,fJetLcChLowPt,fJetLcChHighPt,fEMCALReadout,fJetFullHighPt,fJetFullLowPt,fJetNeutralHighPt,fJetNeutralLowPt,fGammaVeryHighPtEMCAL,fGammaVeryHighPtDCAL,fGammaHighPtEMCAL,fGammaHighPtDCAL,fGammaLowPtEMCAL,fGammaLowPtDCAL,fGammaVeryLowPtEMCAL,fGammaVeryLowPtDCAL"};
155169
Configurable<float> jetPtCutMin{"jetPtCutMin", 5.0, "minimum value of jet pt"};
156170
Configurable<float> d0PtCutMin{"d0PtCutMin", 1.0, "minimum value of d0 pt"};
171+
Configurable<float> jetMcPtCutMin{"jetMcPtCutMin", 3.0, "minimum value of jet pt particle level"};
172+
Configurable<float> d0McPtCutMin{"d0McPtCutMin", 0.5, "minimum value of d0 pt particle level"};
157173
Configurable<float> vertexZCut{"vertexZCut", 10.0, "Accepted z-vertex range"};
158174
Configurable<float> pTHatExponent{"pTHatExponent", 6.0, "exponent of the event weight for the calculation of pTHat"};
159-
Configurable<float> pTHatMaxMCD{"pTHatMaxMCD", 999.0, "maximum fraction of hard scattering for jet acceptance in detector MC"};
160-
Configurable<float> pTHatMaxMCP{"pTHatMaxMCP", 999.0, "maximum fraction of hard scattering for jet acceptance in particle MC"};
175+
Configurable<float> pTHatMaxMcD{"pTHatMaxMcD", 999.0, "maximum fraction of hard scattering for jet acceptance in detector MC"};
176+
Configurable<float> pTHatMaxMcP{"pTHatMaxMcP", 999.0, "maximum fraction of hard scattering for jet acceptance in particle MC"};
161177
Configurable<float> pTHatAbsoluteMin{"pTHatAbsoluteMin", -99.0, "minimum value of pTHat"};
162178

163179
// Filters
@@ -179,13 +195,14 @@ struct JetCorrelationD0 {
179195
registry.fill(HIST("hD0Phi"), d0.phi());
180196
}
181197
template <typename T, typename U>
182-
void fillJetHistograms(T const& jet, U const& dphi)
198+
void fillJetHistograms(T const& jet, U const& dPhi)
183199
{
184200
registry.fill(HIST("hJetPt"), jet.pt());
185201
registry.fill(HIST("hJetEta"), jet.eta());
186202
registry.fill(HIST("hJetPhi"), jet.phi());
187203
registry.fill(HIST("hJet3D"), jet.pt(), jet.eta(), jet.phi());
188-
registry.fill(HIST("h_Jet_pT_D0_Jet_dPhi"), jet.pt(), dphi);
204+
registry.fill(HIST("h_Jet_D0_Jet_dPhi"), dPhi);
205+
registry.fill(HIST("h_Jet_pT_D0_Jet_dPhi"), jet.pt(), dPhi);
189206
}
190207

191208
template <typename T>
@@ -199,26 +216,6 @@ struct JetCorrelationD0 {
199216
registry.fill(HIST("hZvtxSelected"), collision.posZ());
200217
return true;
201218
}
202-
203-
template <typename T, typename U>
204-
// Jetbase is an MCD jet. We then loop through jettagv(MCP jets) to test if they match
205-
// void fillMatchedHistograms(T const& jetBase, float weight = 1.0) // float leadingTrackPtBase,
206-
void fillMatchedHistograms(T const& jetsBase, U const&, float weight = 1.0, float rho = 0.0)
207-
{
208-
for (const auto& jetBase : jetsBase) {
209-
if (jetBase.has_matchedJetGeo()) { // geometric matching
210-
for (auto const& jetTag : jetBase.template matchedJetGeo_as<std::decay_t<U>>()) {
211-
registry.fill(HIST("hPtMatched"), jetBase.pt() - (rho * jetBase.area()), jetTag.pt(), weight);
212-
registry.fill(HIST("hPtMatched1d"), jetTag.pt(), weight);
213-
registry.fill(HIST("hPhiMatched"), jetBase.phi(), jetTag.phi(), weight);
214-
registry.fill(HIST("hEtaMatched"), jetBase.eta(), jetTag.eta(), weight);
215-
registry.fill(HIST("hPtResolution"), jetTag.pt(), (jetTag.pt() - (jetBase.pt() - (rho * jetBase.area()))) / jetTag.pt(), weight);
216-
registry.fill(HIST("hPhiResolution"), jetTag.pt(), jetTag.phi() - jetBase.phi(), weight);
217-
registry.fill(HIST("hEtaResolution"), jetTag.pt(), jetTag.eta() - jetBase.eta(), weight);
218-
}
219-
}
220-
}
221-
}
222219
void init(InitContext const&)
223220
{
224221
eventSelectionBits = jetderiveddatautilities::initialiseEventSelectionBits(static_cast<std::string>(eventSelections));
@@ -246,6 +243,7 @@ struct JetCorrelationD0 {
246243
registry.add("hJetEta", "jet #eta;#eta_{jet};entries", HistType::kTH1F, {axisEta});
247244
registry.add("hJetPhi", "jet #phi;#phi_{jet};entries", HistType::kTH1F, {axisPhi});
248245
registry.add("hJet3D", "3D jet distribution;p_{T};#eta;#phi", {HistType::kTH3F, {{500, -100, 400}, {100, -1.0, 1.0}, {100, 0.0, o2::constants::math::TwoPI}}});
246+
registry.add("h_Jet_D0_Jet_dPhi", "#Delta #phi _{D^{0}, jet}", kTH1F, {{100, 0, o2::constants::math::TwoPI}});
249247
registry.add("h_Jet_pT_D0_Jet_dPhi", "p_{T, jet} vs #Delta #phi _{D^{0}, jet}", kTH2F, {{100, 0, 100}, {100, 0, o2::constants::math::TwoPI}});
250248

251249
// Matching histograms
@@ -284,23 +282,23 @@ struct JetCorrelationD0 {
284282
if (jet.pt() < jetPtCutMin) {
285283
continue;
286284
}
287-
float dphi = RecoDecay::constrainAngle(jet.phi() - d0Candidate.phi());
288-
if (std::abs(dphi - o2::constants::math::PI) > (o2::constants::math::PI / 2)) { // this is quite loose instead of pi/2 could do 0.6
285+
float dPhi = RecoDecay::constrainAngle(jet.phi() - d0Candidate.phi(), -o2::constants::math::PI);
286+
if (std::abs(dPhi - o2::constants::math::PI) > (o2::constants::math::PI / 2)) {
289287
continue;
290288
}
291-
fillJetHistograms(jet, dphi);
289+
fillJetHistograms(jet, dPhi);
292290
tableJet(tableCollision.lastIndex(),
293291
tableD0.lastIndex(),
294292
jet.pt(),
295293
jet.eta(),
296294
jet.phi(),
297-
dphi);
295+
dPhi);
298296
}
299297
}
300298
}
301299
PROCESS_SWITCH(JetCorrelationD0, processData, "charged particle level jet analysis", true);
302300

303-
void processMCDetector(soa::Filtered<aod::JetCollisions>::iterator const& collision,
301+
void processMcDetector(soa::Filtered<aod::JetCollisions>::iterator const& collision,
304302
aod::CandidatesD0MCD const& d0Candidates,
305303
soa::Join<aod::ChargedMCDetectorLevelJets, aod::ChargedMCDetectorLevelJetConstituents> const& jets)
306304
{
@@ -327,60 +325,110 @@ struct JetCorrelationD0 {
327325
if (jet.pt() < jetPtCutMin) {
328326
continue;
329327
}
330-
float dphi = RecoDecay::constrainAngle(jet.phi() - d0Candidate.phi());
331-
if (std::abs(dphi - o2::constants::math::PI) > (o2::constants::math::PI / 2)) { // this is quite loose instead of pi/2 could do 0.6
328+
float dPhi = RecoDecay::constrainAngle(jet.phi() - d0Candidate.phi(), -o2::constants::math::PI);
329+
if (std::abs(dPhi - o2::constants::math::PI) > (o2::constants::math::PI / 2)) {
332330
continue;
333331
}
334-
fillJetHistograms(jet, dphi);
332+
fillJetHistograms(jet, dPhi);
335333
tableJet(tableCollision.lastIndex(),
336334
tableD0.lastIndex(),
337335
jet.pt(),
338336
jet.eta(),
339337
jet.phi(),
340-
dphi);
338+
dPhi);
341339
}
342340
}
343341
}
344-
PROCESS_SWITCH(JetCorrelationD0, processMCDetector, "charged particle level jet analysis", false);
342+
PROCESS_SWITCH(JetCorrelationD0, processMcDetector, "charged detector level jet analysis", false);
345343

346-
void processMCParticle(aod::JetMcCollision const& collision,
347-
aod::CandidatesD0MCP const& d0MCPCandidates,
348-
soa::Filtered<soa::Join<aod::ChargedMCParticleLevelJets, aod::ChargedMCParticleLevelJetConstituents>> const& jets)
344+
void processMcParticle(aod::JetMcCollision const& collision,
345+
aod::CandidatesD0MCP const& d0McPCandidates,
346+
soa::Join<aod::ChargedMCParticleLevelJets, aod::ChargedMCParticleLevelJetConstituents> const& jets)
349347
{
350-
if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, skipMBGapEvents, applyRCTSelections)) { // build without this
348+
if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, skipMBGapEvents, applyRCTSelections)) {
351349
return;
352350
}
353351
tableMcCollision(collision.posZ());
354-
for (const auto& d0MCPCandidate : d0MCPCandidates) {
355-
if (d0MCPCandidate.pt() < d0PtCutMin) {
352+
for (const auto& d0McPCandidate : d0McPCandidates) {
353+
if (d0McPCandidate.pt() < d0McPtCutMin) {
356354
continue;
357355
}
358-
tableD0MCParticle(tableCollision.lastIndex(),
359-
d0MCPCandidate.originMcGen(),
360-
d0MCPCandidate.pt(),
361-
d0MCPCandidate.eta(),
362-
d0MCPCandidate.phi(),
363-
d0MCPCandidate.y());
356+
tableD0McParticle(tableMcCollision.lastIndex(),
357+
d0McPCandidate.originMcGen(),
358+
d0McPCandidate.pt(),
359+
d0McPCandidate.eta(),
360+
d0McPCandidate.phi(),
361+
d0McPCandidate.y());
364362

365363
for (const auto& jet : jets) {
366-
if (jet.pt() < jetPtCutMin) {
364+
if (jet.pt() < jetMcPtCutMin) {
367365
continue;
368366
}
369-
float dphi = RecoDecay::constrainAngle(jet.phi() - d0MCPCandidate.phi());
370-
if (std::abs(dphi - o2::constants::math::PI) > (o2::constants::math::PI / 2)) {
367+
float dPhi = RecoDecay::constrainAngle(jet.phi() - d0McPCandidate.phi(), -o2::constants::math::PI);
368+
if (std::abs(dPhi - o2::constants::math::PI) > (o2::constants::math::PI / 2)) {
371369
continue;
372370
}
373-
fillJetHistograms(jet, dphi);
374-
tableJetMCParticle(tableCollision.lastIndex(),
375-
tableD0MCParticle.lastIndex(),
371+
fillJetHistograms(jet, dPhi);
372+
tableJetMcParticle(tableMcCollision.lastIndex(),
373+
tableD0McParticle.lastIndex(),
376374
jet.pt(),
377375
jet.eta(),
378376
jet.phi(),
379-
dphi);
377+
dPhi);
378+
}
379+
}
380+
}
381+
PROCESS_SWITCH(JetCorrelationD0, processMcParticle, "charged MC Particle jets", false);
382+
383+
void processMcMatched(soa::Filtered<aod::JetCollisions>::iterator const& collision,
384+
aod::CandidatesD0MCD const& d0Candidates,
385+
aod::JetTracksMCD const& tracks,
386+
aod::JetParticles const& particles,
387+
soa::Join<aod::ChargedMCDetectorLevelJets, aod::ChargedMCDetectorLevelJetConstituents, aod::ChargedMCDetectorLevelJetsMatchedToChargedMCParticleLevelJets> const& McDJets,
388+
aod::ChargedMCParticleLevelJets const&)
389+
{
390+
if (!applyCollisionSelections(collision)) {
391+
return;
392+
}
393+
tableMatchedCollision(collision.posZ());
394+
for (const auto& d0Candidate : d0Candidates) {
395+
if (d0Candidate.pt() < d0PtCutMin) { // once settled on a mlcut, then add the lower bound of the systematics as a cut here
396+
continue;
397+
}
398+
bool isMatched = false;
399+
const auto& d0Particle = jethfutilities::matchedHFParticle(d0Candidate, tracks, particles, isMatched);
400+
if (!isMatched) {
401+
continue;
402+
}
403+
for (const auto& McDJet : McDJets) {
404+
if (McDJet.pt() < jetPtCutMin) {
405+
continue;
406+
}
407+
float dPhiD = RecoDecay::constrainAngle(McDJet.phi() - d0Candidate.phi(), -o2::constants::math::PI);
408+
if (std::abs(dPhiD - o2::constants::math::PI) > (o2::constants::math::PI / 2)) {
409+
continue;
410+
}
411+
if (McDJet.has_matchedJetGeo()) { // geometric matching
412+
for (auto const& McPJet : McDJet.template matchedJetGeo_as<aod::ChargedMCParticleLevelJets>()) {
413+
float dPhiP = RecoDecay::constrainAngle(McPJet.phi() - d0Particle.phi(), -o2::constants::math::PI);
414+
// if (std::abs(dPhiP - o2::constants::math::PI) > (o2::constants::math::PI / 2)) {
415+
// continue;
416+
// }
417+
tableJetMatched(tableMatchedCollision.lastIndex(),
418+
McDJet.pt(),
419+
McDJet.eta(),
420+
McDJet.phi(),
421+
McPJet.pt(),
422+
McPJet.eta(),
423+
McPJet.phi(),
424+
dPhiD,
425+
dPhiP);
426+
}
427+
}
380428
}
381429
}
382430
}
383-
PROCESS_SWITCH(JetCorrelationD0, processMCParticle, "process MC Particle jets", false);
431+
PROCESS_SWITCH(JetCorrelationD0, processMcMatched, "process matching of particle level jets to detector level jets", false);
384432
};
385433

386434
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)

0 commit comments

Comments
 (0)