From 7feb862536c8580aaa1d7c97907c6376067ef04a Mon Sep 17 00:00:00 2001 From: Jan Scharf Date: Tue, 24 Nov 2026 15:31:50 +0100 Subject: [PATCH 1/5] PWGJE: add task for neutral meson measurements in full jets --- PWGJE/Tasks/CMakeLists.txt | 6 + PWGJE/Tasks/neutralMesonInFullJets.cxx | 650 +++++++++++++++++++++++++ 2 files changed, 656 insertions(+) create mode 100644 PWGJE/Tasks/neutralMesonInFullJets.cxx diff --git a/PWGJE/Tasks/CMakeLists.txt b/PWGJE/Tasks/CMakeLists.txt index a9cd8c98d0d..3a558ae55df 100644 --- a/PWGJE/Tasks/CMakeLists.txt +++ b/PWGJE/Tasks/CMakeLists.txt @@ -453,6 +453,12 @@ if(FastJet_FOUND) PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore O2Physics::EventFilteringUtils O2Physics::AnalysisCCDB COMPONENT_NAME Analysis) + o2physics_add_dpl_workflow(neutral-meson-in-full-jets + SOURCES neutralMesonInFullJets.cxx + REUSE_FROM JetSubstructureHFPCH + PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::PWGJECore O2Physics::AnalysisCore O2Physics::EventFilteringUtils + O2Physics::AnalysisCCDB + COMPONENT_NAME Analysis) o2physics_add_dpl_workflow(bjet-tagging-ml SOURCES bjetTaggingML.cxx REUSE_FROM JetSubstructureHFPCH diff --git a/PWGJE/Tasks/neutralMesonInFullJets.cxx b/PWGJE/Tasks/neutralMesonInFullJets.cxx new file mode 100644 index 00000000000..8d52b000ce1 --- /dev/null +++ b/PWGJE/Tasks/neutralMesonInFullJets.cxx @@ -0,0 +1,650 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +// +/// \file neutralMesonsInFullJets.cxx +/// \brief Task for neutral meson measurement in full jets +/// \author Jan Scharf + +/// TO DO : Add Neutral Mesons measurement to the current full jet measuremtn + +#include "PWGJE/Core/JetDerivedDataUtilities.h" +#include "PWGJE/DataModel/Jet.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace o2; +using namespace o2::framework; +using namespace o2::framework::expressions; + +struct neutralMesonInFullJets { + HistogramRegistry registry; + // define different enum classes to avoid "magic numbers" + // DataType used in eventSelection and saving of histograms, and more + // MatchingScheme defines the typ of matching between MCP and MCD jets + // ResponseType for saving response histograms + // JetAcceptanceCut for customization of the eta and phi jet cut + enum class DataType { + Data, + MCP, + MCD + }; + enum class MatchingScheme { + Geo, + Pt, + GeoAndPt + }; + enum class ResponseType { + Response, + Fake, + Miss + }; + enum class JetAccpetanceCut { + FullR, + HalfR + }; + + // CONFIGURABLES + // General event Configurables + Configurable vertexZCut{"vertexZCut", 10.0f, "Accepted z-vertex range"}; + Configurable pTHatMax{"pTHatMax", 2.5, "maximum fraction of hard scattering for jet acceptance in MC"}; + Configurable pTHatExponent{"pTHatExponent", 4.0, "exponent of the event weight for the calculation of pTHeventSelectionBitsat"}; // 6 for MB MC and 4 for JJ MC + Configurable pTHatMin{"pTHatAbsoluteMin", 0.0, "minimum value of pTHat"}; + Configurable doMBGapTrigger{"doMBGapTrigger", true, "set to true only when using MB-Gap Trigger JJ MC to reject MB events at the collision and track level"}; + Configurable applyRCTSelections{"applyRCTSelections", true, "decide to apply RCT selections"}; + Configurable eventSelections{"eventSelections", "selMC", "choose event selection"}; // selMC for MC and sel8 for data + Configurable matchingScheme{"matchingScheme", 2, "Matching scheme: 0 = Geo, 1 = Pt, 2 = GeoAndPt"}; + + // Jet Configurables + Configurable jetPtMin{"jetPtMin", 5.0, "minimum jet pT cut"}; + Configurable jetAccpetanceCut{"jetAcceptanceCut", 0, "Jet acceptance cut: 0 = FullR, 1 = HalfR"}; + Configurable jetEtaMax{"jetEtaMax", 0.7, "Min jet eta based on EMCAL acceptance"}; + Configurable jetPhiMin{"jetPhiMin", 1.3962634, "Min jet phi based on EMCAL acceptance"}; + Configurable jetPhiMax{"jetPhiMax", 3.2836100, "Max jet phi based on EMCAL acceptance"}; + + // Track Configurables + + // Cluster or EMCAL Configurables + + std::vector eventSelectionBits; + + void init(InitContext const&) + { + // Create all histograms to safe later + // processDataJets: + registry.add("h_data_jet_pt", "data jet pT;#it{p}_{T,jet} (GeV/#it{c});entries", {HistType::kTH1F, {{300, 0., 300.}}}); + registry.add("h_data_jet_eta", "data jet #eta; #eta; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); + registry.add("h_data_jet_phi", "data jet #phi; #phi; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_data_jet_eta_phi", "data jet #eta #phi; #eta; #phi; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, 0, 2 * o2::constants::math::PI}}}); + + // processMCPJets + registry.add("h_mcp_jet_pt", "MCP jet pT;#it{p}_{T,jet} (GeV/#it{c});entries", {HistType::kTH1F, {{300, 0., 300.}}}); + registry.add("h_mcp_jet_eta", "MCP jet #eta; #eta; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); + registry.add("h_mcp_jet_phi", "MCP jet #phi; #phi; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_mcp_jet_eta_phi", "MCP jet #eta #phi; #eta; #phi; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, 0, 2 * o2::constants::math::PI}}}); + + // processMCDJets + registry.add("h_mcd_jet_pt", "MCD jet pT;#it{p}_{T,jet} (GeV/#it{c});entries", {HistType::kTH1F, {{300, 0., 300.}}}); + registry.add("h_mcd_jet_eta", "MCD jet #eta; #eta; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); + registry.add("h_mcd_jet_phi", "MCD jet #phi; #phi; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_mcd_jet_eta_phi", "MCD jet #eta #phi; #eta; #phi; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, 0, 2 * o2::constants::math::PI}}}); + + // Matching histograms using Geo "0" matching + registry.add("h_jet_response_pt_geomatching", "Matched jets using geometrical matching; #p_{T, MCD}; #p_{T, MCP}; entries", {HistType::kTH2F, {{300, 0., 300.}, {300, 0., 300.}}}); + registry.add("h_jet_reponse_pt_fake_geomatching", "Fake jets using geometrical matching; #p_{T, MCP}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); + registry.add("h_jet_reponse_pt_miss_geomatching", "Miss jets using geometrical matching; #p_{T, MCD}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); + registry.add("h_jet_response_phi_geomatching", "Matched jets using geometrical matching; #phi_{MCD}; #phi_{MCP}; entries", {HistType::kTH2F, {{100, 0, 2 * o2::constants::math::PI}, {100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_reponse_phi_fake_geomatching", "Fake jets using geometrical matching; #phi_{MCP}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_reponse_phi_miss_geomatching", "Miss jets using geometrical matching; #phi_{MCD}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_response_eta_geomatching", "Matched jets using geometrical matching; #eta_{MCD}; #eta_{MCP}; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, -0.8, 0.8}}}); + registry.add("h_jet_reponse_eta_fake_geomatching", "Fake jets using geometrical matching; #eta_{MCP}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); + registry.add("h_jet_reponse_eta_miss_geomatching", "Miss jets using geometrical matching; #eta_{MCD}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); + + // Matching histograms using Pt "1" matching + registry.add("h_jet_response_pt_ptmatching", "Matched jets using pT-fraction matching; #p_{T, MCD}; #p_{T, MCP}; entries", {HistType::kTH2F, {{300, 0., 300.}, {300, 0., 300.}}}); + registry.add("h_jet_reponse_pt_fake_ptmatching", "Fake jets using pT-fraction matching; #p_{T, MCP}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); + registry.add("h_jet_reponse_pt_miss_ptmatching", "Miss jets using pT-fraction matching; #p_{T, MCD}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); + registry.add("h_jet_response_phi_ptmatching", "Matched jets using pT-fraction matching; #phi_{MCD}; #phi_{MCP}; entries", {HistType::kTH2F, {{100, 0, 2 * o2::constants::math::PI}, {100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_reponse_phi_fake_ptmatching", "Fake jets using pT-fraction matching; #phi_{MCP}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_reponse_phi_miss_ptmatching", "Miss jets using pT-fraction matching; #phi_{MCD}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_response_eta_ptmatching", "Matched jets using pT-fraction matching; #eta_{MCD}; #eta_{MCP}; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, -0.8, 0.8}}}); + registry.add("h_jet_reponse_eta_fake_ptmatching", "Fake jets using pT-fraction matching; #eta_{MCP}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); + registry.add("h_jet_reponse_eta_miss_ptmatching", "Miss jets using pT-fraction matching; #eta_{MCD}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); + + // Matching histograms using Geo and Pt "2" matching + registry.add("h_jet_response_pt_geoptmatching", "Matched jets using geometrical AND pT-fraction matching; #p_{T, MCD}; #p_{T, MCP}; entries", {HistType::kTH2F, {{300, 0., 300.}, {300, 0., 300.}}}); + registry.add("h_jet_reponse_pt_fake_geoptmatching", "Fake jets using geometrical AND pT-fraction matching; #p_{T, MCP}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); + registry.add("h_jet_reponse_pt_miss_geoptmatching", "Miss jets using geometrical AND pT-fraction matching; #p_{T, MCD}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); + registry.add("h_jet_response_phi_geoptmatching", "Matched jets using geometrical AND pT-fraction matching; #phi_{MCD}; #phi_{MCP}; entries", {HistType::kTH2F, {{100, 0, 2 * o2::constants::math::PI}, {100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_reponse_phi_fake_geoptmatching", "Fake jets using geometrical AND pT-fraction matching; #phi_{MCP}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_reponse_phi_miss_geoptmatching", "Miss jets using geometrical AND pT-fraction matching; #phi_{MCD}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_response_eta_geoptmatching", "Matched jets using geometrical AND pT-fraction matching; #eta_{MCD}; #eta_{MCP}; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, -0.8, 0.8}}}); + registry.add("h_jet_reponse_eta_fake_geoptmatching", "Fake jets using geometrical AND pT-fraction matching; #eta_{MCP}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); + registry.add("h_jet_reponse_eta_miss_geoptmatching", "Miss jets using geometrical AND pT-fraction matching; #eta_{MCD}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); + + // QA + registry.add("h_mcd_collision_counter", "MCD events ; event status; entries", {HistType::kTH1F, {{12, 0.0, 12.0}}}); + registry.add("h_mcp_collision_counter", "MCP events ; event status; entries", {HistType::kTH1F, {{12, 0.0, 12.0}}}); + registry.add("h_data_jet_acceptance_counter", "Data jet acceptance Counter; Data jets; jet status; entries", {HistType::kTH1F, {{2, 0.0, 2.0}}}); + registry.add("h_mcd_jet_acceptance_counter", "MCD jet acceptance Counter; MCD jets; jet status; entries", {HistType::kTH1F, {{2, 0.0, 2.0}}}); + registry.add("h_mcp_jet_acceptance_counter", "MCP jet acceptance Counter; MCP jets; jet status; entries", {HistType::kTH1F, {{2, 0.0, 2.0}}}); + } + + // TABLES + // Matching tables in both directions + using JetTableMCDMatchedJoined = soa::Join; + using JetTableMCPMatchedJoined = soa::Join; + // Tables with added EMCAL information, especially for acceptance + using EMCCollisionsData = o2::soa::Join; // JetCollisions with EMCAL Collision Labels + using EMCCollisionsMCD = o2::soa::Join; // where, JetCollisionsMCD = JetCollisions+JMcCollisionLbs + + // Filters + Filter jetCuts = aod::jet::pt > jetPtMin; + Filter collisionFilter = nabs(aod::jcollision::posZ) < vertexZCut; // Filter is not sufficient and is performed again manually in the event Selection + + PresliceOptional JetMCPPerMcCollision = aod::jet::mcCollisionId; // used in MC matching + PresliceUnsortedOptional CollisionsPerMCPCollision = aod::jmccollisionlb::mcCollisionId; // ensure a for a MCP collision a matched MCD collision is accepted + + // HELPER FUNCTIONS + // fill jet pt, eta and phi histograms for DataType Data, MCP and MCD + template + void fillJetHistograms(Jet const& jet, + float weight = 1.f) + { + if constexpr (T == DataType::Data) { + registry.fill(HIST("h_data_jet_pt"), jet.pt(), weight); + registry.fill(HIST("h_data_jet_eta"), jet.eta(), weight); + registry.fill(HIST("h_data_jet_phi"), jet.phi(), weight); + registry.fill(HIST("h_data_jet_eta_phi"), jet.eta(), jet.phi(), weight); + } else if constexpr (T == DataType::MCP) { + registry.fill(HIST("h_mcp_jet_pt"), jet.pt(), weight); + registry.fill(HIST("h_mcp_jet_eta"), jet.eta(), weight); + registry.fill(HIST("h_mcp_jet_phi"), jet.phi(), weight); + registry.fill(HIST("h_mcp_jet_eta_phi"), jet.eta(), jet.phi(), weight); + } else if constexpr (T == DataType::MCD) { + registry.fill(HIST("h_mcd_jet_pt"), jet.pt(), weight); + registry.fill(HIST("h_mcd_jet_eta"), jet.eta(), weight); + registry.fill(HIST("h_mcd_jet_phi"), jet.phi(), weight); + registry.fill(HIST("h_mcd_jet_eta_phi"), jet.eta(), jet.phi(), weight); + } + } + + // Helper function to fill collision counter hisograms for QA + template + void fillCollisionCounter(float step, + float weight) + { + if constexpr (T == DataType::MCD) { + registry.fill(HIST("h_mcd_collision_counter"), step, weight); + } else if constexpr (T == DataType::MCP) { + registry.fill(HIST("h_mcp_collision_counter"), step, weight); + } + } + + // Jet-level acceptance cut on eta and phi, based on the acceptance of the EMCAL + template + bool isJetInAcceptance(T const& jet) const + { + const double R = static_cast(jet.r()) / 100.0; + double radiusFraction = 1.0; + + // Different cut types, could be customized furthur and more methods can be added + // radius Fraction sets the range in which jet is accepted, for FullR eta leads to -0.3 to 0.3 + switch (static_cast(jetAccpetanceCut.value)) { + case JetAccpetanceCut::FullR: + radiusFraction = 1.0; + break; + case JetAccpetanceCut::HalfR: + radiusFraction = 0.5; + break; + default: + LOGF(fatal, "Invalud jet acceptance cut selection: %d", jetAccpetanceCut.value); + } + const double margin = radiusFraction * R; + + // Eta acceptance + const double jetFidEtaMax = jetEtaMax.value - margin; + if (std::abs(jet.eta()) > jetFidEtaMax) { + return false; + } + // Phi acceptance + double jetFidPhiMin = jetPhiMin.value + margin; + double jetFidPhiMax = jetPhiMax.value - margin; + + // Normalize phi to [0, 2pi) + auto norm = [&](double a) { + while (a < 0) { + a += o2::constants::math::TwoPI; + } + while (a >= o2::constants::math::TwoPI) { + a -= o2::constants::math::TwoPI; + } + return a; + }; + + // Normalize using the above function + const double phi = norm(jet.phi()); + jetFidPhiMin = norm(jetFidPhiMin); + jetFidPhiMax = norm(jetFidPhiMax); + + // cut on Phi + if (jetFidPhiMin <= jetFidPhiMax) { + return phi >= jetFidPhiMin && phi <= jetFidPhiMax; + } + + // Wrap around case, the method should be fixed either by cutting the residual fraction or the jet radius + LOGF(info, "Feducial window is wraped around (PhiMax < PhiMin)."); + return phi >= jetFidPhiMin || phi <= jetFidPhiMax; + } + + // Helper function to check if for a MCP collision a matched MCD collision exisits that is accepted by the event Selection + template + bool hasAcceptedDetectorCollision(ParticleCollision const& partcollisions, + DetectorCollision const& detcollisions, + float weight) + { + // To select MCP collision, it is ensured that it can be matched to accepted MCD collision, otherwise this collision is not usefull for matching and further study + // In other words, the MCP collision needs to be measureable + + // Find all matched MCD collision to the specific MCP collision (no direct matching between MCP->MCD, therefore more possible) + auto collisionspermcpjet = detcollisions.sliceBy(CollisionsPerMCPCollision, partcollisions.globalIndex()); + if (collisionspermcpjet.size() < 1) // at least one match is required + { + fillCollisionCounter(7.5f, weight); // collisions that are cut, because they have no matched MCD collisions + return false; + } + for (auto const& collision : collisionspermcpjet) { + // detecor-level collision should also be selected based on the event Selection (not all cuts like vertex Z cut require, because that is already ensured by cutting on MCP collision) + if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, doMBGapTrigger, applyRCTSelections, "CBT_calo")) { + continue; + } + if (!collision.isAmbiguous() && jetderiveddatautilities::eventEMCAL(collision) && collision.alias_bit(kTVXinEMC)) { + fillCollisionCounter(8.5f, weight); // collisions that are cut, because the matched MCD collisions are not accepted by the standard event selection or are unmeasurebale in EMCAL + return true; + } + } + return false; + } + + // Event-level selection for Data, MCP and MCD + template + bool eventSelection(Collision const& collision, + Jets const& jets, + float weight = 1.f, + float pTHat = 0.f, + DetectorCollisions const* detectorCollisions = nullptr) + { + // 0: All collisions + fillCollisionCounter(0.5, weight); // all collisions + + // 1: Additional Vertx Z selection (Filter is not sufficient) + if (std::abs(collision.posZ()) > vertexZCut) { + return false; + } + fillCollisionCounter(1.5, weight); // collisions after vertex z cut + + // 2: MC pT-Hat outlier rejection + if constexpr (T != DataType::Data) { + if (pTHat <= 0.f || pTHat < pTHatMin) { + fillCollisionCounter(2.5f, weight); // collisions cut by the pT-Hat outlier rejection + return false; + } + for (auto const& jet : jets) { + if (jet.pt() > pTHatMax * pTHat) { + fillCollisionCounter(2.5f, weight); // collisions cut by the pT-Hat outlier rejection + return false; + } + } + } + + // not available for particle-level MC, workaround below + if constexpr (T != DataType::MCP) { + // 3: Standard event selection + if (!jetderiveddatautilities::selectCollision( + collision, + eventSelectionBits, + doMBGapTrigger, + applyRCTSelections, "CBT_calo")) { + fillCollisionCounter(3.5f, weight); // collisions cut by the standard event selection (also MB Gap) + return false; + } + + // 4: EMCAL event selection + if (collision.isAmbiguous() || !jetderiveddatautilities::eventEMCAL(collision) || !collision.alias_bit(kTVXinEMC)) { + fillCollisionCounter(4.5f, weight); // collisions cut by not measured by EMCAL + return false; + } + } + // workaournd for MCP + else if constexpr (T == DataType::MCP) { + // 3 and 4: MB Gap Selection + EMCAL selection using associated MCD collisions + if (doMBGapTrigger && collision.getSubGeneratorId() == jetderiveddatautilities::JCollisionSubGeneratorId::mbGap) { + fillCollisionCounter(6.5f, weight); // collisions cut by MB Gap + return false; + } + if (detectorCollisions == nullptr || !hasAcceptedDetectorCollision(collision, *detectorCollisions, weight)) { + return false; + } + } + + return true; + } + + // retrieve matching mcpjet for a mcdjet based on the selected MatchingScheme, Geo, Pt or Geo and Pt + template + void forEachAcceptedMatch(MCDJet const& mcdjet, Callback&& callback) + { + // Geo matching on the delta R closeness of the jets, Pt matching on the pt fraction of the matched constituents in the jet itself + // Pt matching can be directional and needs to be accepted in both directions MCD->MCP and MCP->MCD (Geo is not directional MCD<->MCP) + + if constexpr (Scheme == MatchingScheme::Geo) { + if (mcdjet.has_matchedJetGeo()) { + for (auto const& mcpjet : mcdjet.template matchedJetGeo_as()) { + callback(mcpjet); + } + } + } + + else if constexpr (Scheme == MatchingScheme::Pt) { + if (mcdjet.has_matchedJetPt()) { + for (auto const& mcpjet : mcdjet.template matchedJetPt_as()) { + // first loop for MCD->MCP matching + bool hasReversePtMatch = false; + if (mcpjet.has_matchedJetPt()) { + for (auto const& matchedMCD : mcpjet.template matchedJetPt_as()) { + // ensuring MCP->MCD matching + if (matchedMCD.globalIndex() == mcdjet.globalIndex()) { + hasReversePtMatch = true; + break; + } + } + } + + if (hasReversePtMatch) { + callback(mcpjet); + } + } + } + } + + else if constexpr (Scheme == MatchingScheme::GeoAndPt) { + std::unordered_set ptMatchedMCPJetIds; + if (mcdjet.has_matchedJetPt()) { + for (auto const& mcpjet : mcdjet.template matchedJetPt_as()) { + ptMatchedMCPJetIds.insert(mcpjet.globalIndex()); + } + } + if (mcdjet.has_matchedJetGeo()) { + for (auto const& mcpjet : mcdjet.template matchedJetGeo_as()) { + if (ptMatchedMCPJetIds.find(mcpjet.globalIndex()) == ptMatchedMCPJetIds.end()) { + continue; + } + bool hasReversePtMatch = false; + if (mcpjet.has_matchedJetPt()) { + for (auto const& matchedMCD : mcpjet.template matchedJetPt_as()) { + if (matchedMCD.globalIndex() == mcdjet.globalIndex()) { + hasReversePtMatch = true; + break; + } + } + } + if (hasReversePtMatch) { + callback(mcpjet); + } + } + } + } + } + + // Helper function fill the histograms of the matching part 1 only response + template + void fillMatchingResponse(MCDJet const& mcdjet, MCPJet const& mcpjet, float weight) + { + static_assert(Type == ResponseType::Response, "This is only for response histograms"); + if constexpr (Scheme == MatchingScheme::Geo) { + registry.fill(HIST("h_jet_response_pt_geomatching"), mcdjet.pt(), mcpjet.pt(), weight); + registry.fill(HIST("h_jet_response_phi_geomatching"), mcdjet.phi(), mcpjet.phi(), weight); + registry.fill(HIST("h_jet_response_eta_geomatching"), mcdjet.eta(), mcpjet.eta(), weight); + } else if constexpr (Scheme == MatchingScheme::Pt) { + registry.fill(HIST("h_jet_response_pt_ptmatching"), mcdjet.pt(), mcpjet.pt(), weight); + registry.fill(HIST("h_jet_response_phi_ptmatching"), mcdjet.phi(), mcpjet.phi(), weight); + registry.fill(HIST("h_jet_response_eta_ptmatching"), mcdjet.eta(), mcpjet.eta(), weight); + } else if constexpr (Scheme == MatchingScheme::GeoAndPt) { + registry.fill(HIST("h_jet_response_pt_geoptmatching"), mcdjet.pt(), mcpjet.pt(), weight); + registry.fill(HIST("h_jet_response_phi_geoptmatching"), mcdjet.phi(), mcpjet.phi(), weight); + registry.fill(HIST("h_jet_response_eta_geoptmatching"), mcdjet.eta(), mcpjet.eta(), weight); + } + } + + // Helper function fill the histograms of the matching part 2 for miss and fake + template + void fillMatchingResponse(Jet const& jet, float weight) + { + static_assert(Type != ResponseType::Response, + "Response histograms require both jets"); + + if constexpr (Type == ResponseType::Fake) { + + if constexpr (Scheme == MatchingScheme::Geo) { + registry.fill(HIST("h_jet_reponse_pt_fake_geomatching"), jet.pt(), weight); + registry.fill(HIST("h_jet_reponse_phi_fake_geomatching"), jet.phi(), weight); + registry.fill(HIST("h_jet_reponse_eta_fake_geomatching"), jet.eta(), weight); + + } else if constexpr (Scheme == MatchingScheme::Pt) { + registry.fill(HIST("h_jet_reponse_pt_fake_ptmatching"), jet.pt(), weight); + registry.fill(HIST("h_jet_reponse_phi_fake_ptmatching"), jet.phi(), weight); + registry.fill(HIST("h_jet_reponse_eta_fake_ptmatching"), jet.eta(), weight); + + } else if constexpr (Scheme == MatchingScheme::GeoAndPt) { + registry.fill(HIST("h_jet_reponse_pt_fake_geoptmatching"), jet.pt(), weight); + registry.fill(HIST("h_jet_reponse_phi_fake_geoptmatching"), jet.phi(), weight); + registry.fill(HIST("h_jet_reponse_eta_fake_geoptmatching"), jet.eta(), weight); + } + + } else if constexpr (Type == ResponseType::Miss) { + + if constexpr (Scheme == MatchingScheme::Geo) { + registry.fill(HIST("h_jet_reponse_pt_miss_geomatching"), jet.pt(), weight); + registry.fill(HIST("h_jet_reponse_phi_miss_geomatching"), jet.phi(), weight); + registry.fill(HIST("h_jet_reponse_eta_miss_geomatching"), jet.eta(), weight); + + } else if constexpr (Scheme == MatchingScheme::Pt) { + registry.fill(HIST("h_jet_reponse_pt_miss_ptmatching"), jet.pt(), weight); + registry.fill(HIST("h_jet_reponse_phi_miss_ptmatching"), jet.phi(), weight); + registry.fill(HIST("h_jet_reponse_eta_miss_ptmatching"), jet.eta(), weight); + + } else if constexpr (Scheme == MatchingScheme::GeoAndPt) { + registry.fill(HIST("h_jet_reponse_pt_miss_geoptmatching"), jet.pt(), weight); + registry.fill(HIST("h_jet_reponse_phi_miss_geoptmatching"), jet.phi(), weight); + registry.fill(HIST("h_jet_reponse_eta_miss_geoptmatching"), jet.eta(), weight); + } + } + } + + // run the matching and the mcdjet loop, also aplly the event and jet selection + template + void runJetMatching( + EMCCollisionsMCD::iterator const& collision, + JetTableMCDMatchedJoined const& mcdjets, + JetTableMCPMatchedJoined const& mcpjets) + { + const float weight = collision.mcCollision().weight(); + const float pTHat = 10. / std::pow(weight, 1.0 / pTHatExponent); + + // MCD event selection + if (!eventSelection(collision, mcdjets, weight, pTHat)) { + return; + } + + // Retrieve MCP jets associated with this MC collision + auto mcpJetsPerMcCollision = mcpjets.sliceBy(JetMCPPerMcCollision, collision.mcCollisionId()); + std::unordered_set matchedMCPJetIds; + + for (const auto& mcdjet : mcdjets) { + bool hasAcceptedMatch = false; + + // Detector-level acceptance + if (!isJetInAcceptance(mcdjet)) { + continue; + } + + forEachAcceptedMatch(mcdjet, [&](auto const& mcpjet) { // Jet Matching + // Particle-level acceptance + if (!isJetInAcceptance(mcpjet)) { + return; + } + hasAcceptedMatch = true; + matchedMCPJetIds.insert(mcpjet.globalIndex()); + fillMatchingResponse(mcdjet, mcpjet, weight); + }); + + // Fake (Unmatched but accepted MCD jets) + if (!hasAcceptedMatch) { + fillMatchingResponse(mcdjet, weight); + } + } + // Miss (Unmatched but accepted MCP jets) + for (const auto& mcpjet : mcpJetsPerMcCollision) { + + // Particle-level acceptance + if (!isJetInAcceptance(mcpjet)) { + continue; + } + if (matchedMCPJetIds.find(mcpjet.globalIndex()) == matchedMCPJetIds.end()) { + fillMatchingResponse(mcpjet, weight); + } + } + } + + // PROCESSES + + // Dummy for testing + void processDummy(aod::JetMcCollision const&) + { + } + PROCESS_SWITCH(neutralMesonInFullJets, processDummy, "dummy process", false) + + // Measuring Jet pt, eta, phi for jets in data + void processDataJets(soa::Filtered::iterator const& collision, + soa::Filtered const& jets) + { + if (!eventSelection(collision, jets)) { + return; + } + + for (auto const& jet : jets) { + registry.fill(HIST("h_data_jet_acceptance_counter"), 0.5); // all jets in accepted collisions + if (!isJetInAcceptance(jet)) { + continue; + } + registry.fill(HIST("h_data_jet_acceptance_counter"), 1.5); // only accepted jets + fillJetHistograms(jet); + } + } + PROCESS_SWITCH(neutralMesonInFullJets, processDataJets, "Full jet measurement in data", false) + + // Measuring Jet pt, eta, phi for jets in MC detector-level + void processMCDJets(soa::Filtered::iterator const& collision, + soa::Filtered const& jets, + aod::JMcCollisions const&) + { + const float weight = collision.mcCollision().weight(); + const float pTHat = 10. / (std::pow(weight, 1.0 / pTHatExponent)); + + if (!eventSelection( + collision, jets, weight, pTHat)) { + return; + } + + for (auto const& jet : jets) { + registry.fill(HIST("h_mcd_jet_acceptance_counter"), 0.5); // all jets in accepted collisions + if (!isJetInAcceptance(jet)) { + continue; + } + registry.fill(HIST("h_mcd_jet_acceptance_counter"), 1.5); // only accepted jets + fillJetHistograms(jet, weight); + } + } + PROCESS_SWITCH(neutralMesonInFullJets, processMCDJets, "Full detector-level MC jet measurement", false) + + // Measuring Jet pt, eta, phi for jets in MC particle-level + void processMCPJets(aod::JetMcCollisions::iterator const& collision, + soa::Filtered const& jets, + soa::SmallGroups const& detectorCollisions) + { + // TO DO: Do I need to add a at least one jet in collision cut or is this already taken care of? + const float weight = collision.weight(); + const float pTHat = 10. / (std::pow(weight, 1.0 / pTHatExponent)); + + if (!eventSelection( + collision, jets, weight, pTHat, &detectorCollisions)) { + return; + } + + for (auto const& jet : jets) { + registry.fill(HIST("h_mcp_jet_acceptance_counter"), 0.5); // all jets in accepted collisions + if (!isJetInAcceptance(jet)) { + continue; + } + registry.fill(HIST("h_mcp_jet_acceptance_counter"), 1.5); // only accepted jets + fillJetHistograms(jet, weight); + } + } + PROCESS_SWITCH(neutralMesonInFullJets, processMCPJets, "Full particle-level MC jet measurement", false) + + // Matching MC detector and particle-level jets to calculate the response, fake and miss histogram for later use in unfolding + void processJetMatching(EMCCollisionsMCD::iterator const& collision, // removed soa::Filtered here, was an issue in the matching + JetTableMCDMatchedJoined const& mcdjets, + aod::JetMcCollisions const&, + JetTableMCPMatchedJoined const& mcpjets) + { + switch (matchingScheme.value) { + case 0: + runJetMatching( + collision, mcdjets, mcpjets); + break; + case 1: + runJetMatching( + collision, mcdjets, mcpjets); + break; + case 2: + runJetMatching( + collision, mcdjets, mcpjets); + break; + default: + LOGF(fatal, "Invalud matching scheme: %d", matchingScheme.value); + } + } + PROCESS_SWITCH(neutralMesonInFullJets, processJetMatching, "Jet matching for MC-based unfolding", false) +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + return WorkflowSpec{ + adaptAnalysisTask(cfgc)}; +} From 379459d1f62a713c67aae04c9ccd3ad7c5f116a3 Mon Sep 17 00:00:00 2001 From: Jan Scharf Date: Tue, 24 Nov 2026 19:30:43 +0100 Subject: [PATCH 2/5] Change from pull request. In processMCDJets JMcCollisions is removed and weight is instead retrieved from collision (from the underlying JCollisionMcInfo table, which already part of JetCollisions). --- PWGJE/Tasks/neutralMesonInFullJets.cxx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/PWGJE/Tasks/neutralMesonInFullJets.cxx b/PWGJE/Tasks/neutralMesonInFullJets.cxx index 8d52b000ce1..deeb42e89a9 100644 --- a/PWGJE/Tasks/neutralMesonInFullJets.cxx +++ b/PWGJE/Tasks/neutralMesonInFullJets.cxx @@ -570,10 +570,9 @@ struct neutralMesonInFullJets { // Measuring Jet pt, eta, phi for jets in MC detector-level void processMCDJets(soa::Filtered::iterator const& collision, - soa::Filtered const& jets, - aod::JMcCollisions const&) + soa::Filtered const& jets) { - const float weight = collision.mcCollision().weight(); + const float weight = collision.weight(); const float pTHat = 10. / (std::pow(weight, 1.0 / pTHatExponent)); if (!eventSelection( From 06a1ce121db183e3195f7b2538d23dff2ce690b1 Mon Sep 17 00:00:00 2001 From: Jan Scharf Date: Fri, 27 Nov 2026 17:02:28 +0100 Subject: [PATCH 3/5] Adding pi0 in jet reconstruction in two different ways by assuming all cluster in the jet are photons and are paired to mesons or all clusters in the collision are paired to mesons and then matched to a jet. Also added a check if the particles of the cluster actually have a shared pi0 in their ancestory. To do: add comments, histograms and clean up code and naming of variables. --- PWGJE/Tasks/neutralMesonInFullJets.cxx | 312 ++++++++++++++++++++++++- 1 file changed, 309 insertions(+), 3 deletions(-) diff --git a/PWGJE/Tasks/neutralMesonInFullJets.cxx b/PWGJE/Tasks/neutralMesonInFullJets.cxx index deeb42e89a9..54a4dcd5a6f 100644 --- a/PWGJE/Tasks/neutralMesonInFullJets.cxx +++ b/PWGJE/Tasks/neutralMesonInFullJets.cxx @@ -16,7 +16,11 @@ /// TO DO : Add Neutral Mesons measurement to the current full jet measuremtn #include "PWGJE/Core/JetDerivedDataUtilities.h" +#include "PWGJE/DataModel/EMCALClusters.h" #include "PWGJE/DataModel/Jet.h" +#include "PWGJE/DataModel/JetReducedData.h" + +#include "Common/CCDB/TriggerAliases.h" #include #include @@ -24,17 +28,19 @@ #include #include #include +#include #include -#include - #include +#include #include #include #include #include +#include #include +#include #include #include @@ -42,6 +48,57 @@ using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; +struct Photon { + Photon(float eta_tmp, float phi_tmp, float energy_tmp, int clusid = 0, uint8_t sm_tmp = 0) + : eta(eta_tmp), + phi(phi_tmp), + energy(energy_tmp), + theta(2.f * std::atan2(std::exp(-eta), 1)), + px(energy * std::sin(theta) * std::cos(phi)), + py(energy * std::sin(theta) * std::sin(phi)), + pz(energy * std::cos(theta)), + pt(std::sqrt(px * px + py * py)), + photon(px, py, pz, energy), + id(clusid), + sm(sm_tmp), + onDCal(phi < 6 && phi > 4) // o2-linter: disable=magic-number (DCal phi range) + { + } + + float eta; + float phi; + float energy; + float theta; + float px; + float py; + float pz; + float pt; + ROOT::Math::PxPyPzEVector photon; + int id; + uint8_t sm; + bool onDCal{phi < 6 && phi > 4}; // Checks whether photon is in phi region of the DCal, otherwise: EMCal +}; +struct Meson { + Meson(Photon const& p1, Photon const& p2) : pgamma1(p1), pgamma2(p2), pMeson(p1.photon + p2.photon) + { + } + Photon pgamma1; + Photon pgamma2; + ROOT::Math::PxPyPzEVector pMeson; + + [[nodiscard]] float getMass() const { return pMeson.M(); } + [[nodiscard]] float getPt() const { return pMeson.Pt(); } + [[nodiscard]] float eta() const { return pMeson.Eta(); } + [[nodiscard]] float phi() const { return pMeson.Phi(); } + [[nodiscard]] float getOpeningAngle() const + { + float cosAngle = pgamma1.photon.Vect().Dot(pgamma2.photon.Vect()) / (pgamma1.photon.P() * pgamma2.photon.P()); + float angle = std::acos(std::clamp(cosAngle, -1.0f, 1.0f)); + return angle; + } + [[nodiscard]] ROOT::Math::PxPyPzEVector getMathVector() const { return pMeson; } +}; + struct neutralMesonInFullJets { HistogramRegistry registry; // define different enum classes to avoid "magic numbers" @@ -68,6 +125,10 @@ struct neutralMesonInFullJets { FullR, HalfR }; + enum class MesonReconstructionScheme { + JetConstituents, + AllClusters + }; // CONFIGURABLES // General event Configurables @@ -79,6 +140,8 @@ struct neutralMesonInFullJets { Configurable applyRCTSelections{"applyRCTSelections", true, "decide to apply RCT selections"}; Configurable eventSelections{"eventSelections", "selMC", "choose event selection"}; // selMC for MC and sel8 for data Configurable matchingScheme{"matchingScheme", 2, "Matching scheme: 0 = Geo, 1 = Pt, 2 = GeoAndPt"}; + Configurable mesonReconstructionScheme{"mesonReconstructionScheme", 0, "Meson reconstruction scheme: 0 = Jet constituents, 1 = All event clusters"}; + Configurable maxMesonJetDeltaR{"maxMesonJetDeltaR", 0.4f, "Maximum delta R for meson-jet association"}; // Jet Configurables Configurable jetPtMin{"jetPtMin", 5.0, "minimum jet pT cut"}; @@ -90,6 +153,7 @@ struct neutralMesonInFullJets { // Track Configurables // Cluster or EMCAL Configurables + // Configurable mMinOpenAngleCut{"mMinOpenAngleCut", 0.0202, "apply min opening angle cut"}; std::vector eventSelectionBits; @@ -153,6 +217,16 @@ struct neutralMesonInFullJets { registry.add("h_data_jet_acceptance_counter", "Data jet acceptance Counter; Data jets; jet status; entries", {HistType::kTH1F, {{2, 0.0, 2.0}}}); registry.add("h_mcd_jet_acceptance_counter", "MCD jet acceptance Counter; MCD jets; jet status; entries", {HistType::kTH1F, {{2, 0.0, 2.0}}}); registry.add("h_mcp_jet_acceptance_counter", "MCP jet acceptance Counter; MCP jets; jet status; entries", {HistType::kTH1F, {{2, 0.0, 2.0}}}); + + // Meson in jet measurements + registry.add("h_mcd_meson_invarient_mass_JetConstituents", "MCD Mesons JetConstituents; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); + registry.add("h_mcd_meson_invarient_mass_pt_JetConstituents", "MCD Mesons JetConstituents; invariant mass; #p_{T, MCD}; entries", {HistType::kTH2F, {{100, 0.0, 1.0}, {100, 0.0, 100.}}}); + registry.add("h_mcd_true_pi0_mass_JetConstituents", "MCD True Mesons JetConstituents; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); + registry.add("h_mcd_background_mass_JetConstituents", "MCD Background Mesons JetConstituents; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); + registry.add("h_mcd_meson_invarient_mass_AllClusters", "MCD Mesons AllClusters; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); + registry.add("h_mcd_meson_invarient_mass_pt_AllClusters", "MCD Mesons AllClusters; invariant mass; #p_{T, MCD}; entries", {HistType::kTH2F, {{100, 0.0, 1.0}, {100, 0.0, 100.}}}); + registry.add("h_mcd_true_pi0_mass_AllClusters", "MCD True Mesons AllClusters; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); + registry.add("h_mcd_background_mass_AllClusters", "MCD Background Mesons AllClusters; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); } // TABLES @@ -162,6 +236,8 @@ struct neutralMesonInFullJets { // Tables with added EMCAL information, especially for acceptance using EMCCollisionsData = o2::soa::Join; // JetCollisions with EMCAL Collision Labels using EMCCollisionsMCD = o2::soa::Join; // where, JetCollisionsMCD = JetCollisions+JMcCollisionLbs + // For constituent information + using JetTableMCDWithConstituents = soa::Join; // Filters Filter jetCuts = aod::jet::pt > jetPtMin; @@ -169,6 +245,7 @@ struct neutralMesonInFullJets { PresliceOptional JetMCPPerMcCollision = aod::jet::mcCollisionId; // used in MC matching PresliceUnsortedOptional CollisionsPerMCPCollision = aod::jmccollisionlb::mcCollisionId; // ensure a for a MCP collision a matched MCD collision is accepted + PresliceOptional ClusterPerCollision = aod::emcalcluster::collisionId; // EMCAL cluster per collision // HELPER FUNCTIONS // fill jet pt, eta and phi histograms for DataType Data, MCP and MCD @@ -540,7 +617,6 @@ struct neutralMesonInFullJets { } } } - // PROCESSES // Dummy for testing @@ -640,6 +716,236 @@ struct neutralMesonInFullJets { } } PROCESS_SWITCH(neutralMesonInFullJets, processJetMatching, "Jet matching for MC-based unfolding", false) + + /// Meson measurement helper functions + template + std::vector reconstructPhotonsFromAllClusters(ClusterTable const& clusters) + { + std::vector photons; + + for (const auto& cluster : clusters) { + // cluster selection + photons.emplace_back(cluster.eta(), cluster.phi(), cluster.energy(), cluster.globalIndex()); + } + return photons; + } + + template + std::vector reconstructPhotonsFromJetClusters(Jet const& jet) + { + std::vector photons; + for (const auto& cluster : jet.template clusters_as()) { + // cluster selection + photons.emplace_back(cluster.eta(), cluster.phi(), cluster.energy(), cluster.globalIndex()); + } + return photons; + } + + std::vector reconstructMesons(std::vector const& photons) + { + std::vector mesons; + for (size_t i = 0; i < photons.size(); ++i) { + for (size_t j = i + 1; j < photons.size(); ++j) { + Meson meson(photons[i], photons[j]); + // Apply opening angle and other meson cuts + mesons.push_back(meson); + } + } + return mesons; + } + + template + float getMesonJetDeltaR(Meson const& meson, Jet const& jet) + { + const float deltaEta = meson.eta() - jet.eta(); + const float deltaPhi = std::atan2(std::sin(meson.phi() - jet.phi()), std::cos(meson.phi() - jet.phi())); + return std::sqrt(deltaEta * deltaEta + deltaPhi * deltaPhi); + } + + template + auto findClosestJet(Meson const& meson, JetTable const& jets) + { + using JetType = std::remove_reference_t; + float minDeltaR = maxMesonJetDeltaR; + JetType const* closestJet = nullptr; + for (const auto& jet : jets) { + const float deltaR = getMesonJetDeltaR(meson, jet); + if (deltaR < minDeltaR) { + minDeltaR = deltaR; + closestJet = &jet; + } + } + return closestJet; + } + + template + int findPi0Ancestors(McParticle const& particle, + aod::McParticles const& mcParticles, + std::vector& pi0Ancestors, + std::vector& visited) + { + for (auto motherId : particle.mothersIds()) { + if (motherId < 0) { + continue; + } + + if (std::find(visited.begin(), visited.end(), motherId) != visited.end()) { + continue; + } + visited.push_back(motherId); + auto mother = mcParticles.iteratorAt(motherId); + + if (std::abs(mother.pdgCode()) == 111) { + pi0Ancestors.push_back(motherId); + } + findPi0Ancestors(mother, mcParticles, pi0Ancestors, visited); + } + } + + template + bool isTruePi0(Meson const& meson, + aod::EMCALMCClusters const& mcClusterLables, + McParticles const& mcParticles) + { + auto mcCluster1 = mcClusterLables.iteratorAt(meson.pgamma1.id); + auto mcCluster2 = mcClusterLables.iteratorAt(meson.pgamma2.id); + + auto const& particleIds1 = mcCluster1.mcParticleIds(); + auto const& amplitudes1 = mcCluster1.amplitudeA(); + + auto const& particleIds2 = mcCluster2.mcParticleIds(); + auto const& amplitudes2 = mcCluster2.amplitudeA(); + + if (particleIds1.empty() || amplitudes1.empty() || particleIds2.empty() || amplitudes2.empty()) { + return false; + } + if (particleIds1.size() != amplitudes1.size() || particleIds2.size() != amplitudes2.size()) { + return false; + } + + auto leadingIt1 = std::max_element(amplitudes1.begin(), amplitudes1.end()); + auto leadingIndex1 = std::distance(amplitudes1.begin(), leadingIt1); + int mcParticleId1 = particleIds1[leadingIndex1]; + auto leadingIt2 = std::max_element(amplitudes2.begin(), amplitudes2.end()); + auto leadingIndex2 = std::distance(amplitudes2.begin(), leadingIt2); + int mcParticleId2 = particleIds2[leadingIndex2]; + + auto particle1 = mcParticles.iteratorAt(mcParticleId1); + auto particle2 = mcParticles.iteratorAt(mcParticleId2); + + // Change this so that it does not necessarily can be a photon, and it can go back further in the ancestory until it reaches a pi0 or is empty (no mother/end of ancestory) + + std::vector pi0Ancestors1; + std::vector pi0Ancestors2; + + std::vector visited1; + std::vector visited2; + + findPi0Ancestors(particle1, mcParticles, pi0Ancestors1, visited1); + findPi0Ancestors(particle2, mcParticles, pi0Ancestors2, visited2); + + for (auto pi0Id1 : pi0Ancestors1) { + for (auto pi0Id2 : pi0Ancestors2) { + if (pi0Id1 == pi0Id2) { + return true; + } + } + } + return false; + } + + template + void fillMesonsInJet(Meson const& meson, Jet const& jet, McClusterLabels const& mcClusterLabels, McParticles const& mcParticles) + { + if constexpr (type == DataType::Data) { + if constexpr (Scheme == MesonReconstructionScheme::JetConstituents) { + // Add hists + } else if constexpr (Scheme == MesonReconstructionScheme::AllClusters) { + // Add hists + } else { + LOGF(fatal, "Invalid meson reconstruction scheme: %d", Scheme); + } + } else if constexpr (type == DataType::MCD) { + bool isPi0 = isTruePi0(meson, mcClusterLabels, mcParticles); + if constexpr (Scheme == MesonReconstructionScheme::JetConstituents) { + registry.fill(HIST("h_mcd_meson_invarient_mass_JetConstituents"), meson.getMass()); + registry.fill(HIST("h_mcd_meson_invarient_mass_pt_JetConstituents"), meson.getMass(), meson.getPt()); + // Add hists + if (isPi0) { + registry.fill(HIST("h_mcd_true_pi0_mass_JetConstituents"), + meson.getMass()); + } else { + registry.fill(HIST("h_mcd_background_mass_JetConstituents"), + meson.getMass()); + } + } else if constexpr (Scheme == MesonReconstructionScheme::AllClusters) { + registry.fill(HIST("h_mcd_meson_invarient_mass_AllClusters"), meson.getMass()); + registry.fill(HIST("h_mcd_meson_invarient_mass_pt_AllClusters"), meson.getMass(), meson.getPt()); + // Add hists + if (isPi0) { + registry.fill(HIST("h_mcd_true_pi0_mass_AllClusters"), + meson.getMass()); + } else { + registry.fill(HIST("h_mcd_background_mass_AllClusters"), + meson.getMass()); + } + } else { + LOGF(fatal, "Invalid meson reconstruction scheme: %d", Scheme); + } + } else { + LOGF(fatal, "Invalid data type: %d", type); + } + } + + void processMCDMesonsInFullJets( + EMCCollisionsMCD::iterator const& collision, + soa::Filtered const& jets, + aod::EMCALClusters const& clusters, + aod::JetClustersMCD const&, + aod::EMCALMCClusters const& mcClusterLabels, + aod::McParticles const& mcParticles) + { + const float weight = collision.weight(); + const float pTHat = 10. / (std::pow(weight, 1.0 / pTHatExponent)); + + if (!eventSelection( + collision, jets, weight, pTHat)) { + return; + } + + switch (static_cast(mesonReconstructionScheme.value)) { + case MesonReconstructionScheme::JetConstituents: { + + for (const auto& jet : jets) { + auto photons = reconstructPhotonsFromJetClusters(jet); + auto mesons = reconstructMesons(photons); + for (const auto& meson : mesons) { + fillMesonsInJet(meson, jet, mcClusterLabels, mcParticles); + } + } + break; + } + + case MesonReconstructionScheme::AllClusters: { + + auto clustersPerCollision = clusters.sliceBy(ClusterPerCollision, collision.globalIndex()); + auto photons = reconstructPhotonsFromAllClusters(clustersPerCollision); + auto mesons = reconstructMesons(photons); + for (const auto& meson : mesons) { + auto associatedJet = findClosestJet(meson, jets); + if (associatedJet == nullptr) { + continue; + } + fillMesonsInJet(meson, *associatedJet, mcClusterLabels, mcParticles); + } + break; + } + + default: + LOGF(fatal, "Invalid meson reconstruction scheme: %d", mesonReconstructionScheme.value); + } + } + PROCESS_SWITCH(neutralMesonInFullJets, processMCDMesonsInFullJets, "Measuring mesons in full jets in MCD", false) }; WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) From 62e46fe8ddb325d3195b01f299a574d87d736a94 Mon Sep 17 00:00:00 2001 From: Jan Scharf Date: Mon, 30 Nov 2026 18:52:12 +0100 Subject: [PATCH 4/5] Adding meson measurements in jets. TO DO add further cuts and check for bugs. --- PWGJE/Tasks/neutralMesonInFullJets.cxx | 462 ++++++++++++++++--------- 1 file changed, 307 insertions(+), 155 deletions(-) diff --git a/PWGJE/Tasks/neutralMesonInFullJets.cxx b/PWGJE/Tasks/neutralMesonInFullJets.cxx index 54a4dcd5a6f..17d4ca03bb1 100644 --- a/PWGJE/Tasks/neutralMesonInFullJets.cxx +++ b/PWGJE/Tasks/neutralMesonInFullJets.cxx @@ -29,19 +29,23 @@ #include #include #include +#include #include +#include -#include +#include #include #include #include #include #include -#include +#include #include #include +#include #include +#include #include using namespace o2; @@ -126,8 +130,8 @@ struct neutralMesonInFullJets { HalfR }; enum class MesonReconstructionScheme { - JetConstituents, - AllClusters + JetClusters, // Photon canidates a reconstructed from the cluster signals that are associated to jet + AllClusters // Photon canidates a reconstructed from all cluster signals in the collision and then matched (using Geo matching) to a jet }; // CONFIGURABLES @@ -140,8 +144,6 @@ struct neutralMesonInFullJets { Configurable applyRCTSelections{"applyRCTSelections", true, "decide to apply RCT selections"}; Configurable eventSelections{"eventSelections", "selMC", "choose event selection"}; // selMC for MC and sel8 for data Configurable matchingScheme{"matchingScheme", 2, "Matching scheme: 0 = Geo, 1 = Pt, 2 = GeoAndPt"}; - Configurable mesonReconstructionScheme{"mesonReconstructionScheme", 0, "Meson reconstruction scheme: 0 = Jet constituents, 1 = All event clusters"}; - Configurable maxMesonJetDeltaR{"maxMesonJetDeltaR", 0.4f, "Maximum delta R for meson-jet association"}; // Jet Configurables Configurable jetPtMin{"jetPtMin", 5.0, "minimum jet pT cut"}; @@ -153,7 +155,12 @@ struct neutralMesonInFullJets { // Track Configurables // Cluster or EMCAL Configurables - // Configurable mMinOpenAngleCut{"mMinOpenAngleCut", 0.0202, "apply min opening angle cut"}; + + // Meson analysis Configurable + Configurable minOpenAngleCut{"minOpenAngleCut", 0.0202, "apply min opening angle cut"}; + Configurable mesonReconstructionScheme{"mesonReconstructionScheme", 0, "Meson reconstruction scheme: 0 = Jet clusters, 1 = All collision clusters"}; + Configurable maxMesonJetDeltaR{"maxMesonJetDeltaR", 0.4f, "Maximum delta R for meson-jet association"}; + Configurable MCneutralmesonParticleId{"MCneutralmesonParticleId", 111, "PDG code of the neutral meson that is measured, default is pi0 (111)"}; std::vector eventSelectionBits; @@ -219,14 +226,39 @@ struct neutralMesonInFullJets { registry.add("h_mcp_jet_acceptance_counter", "MCP jet acceptance Counter; MCP jets; jet status; entries", {HistType::kTH1F, {{2, 0.0, 2.0}}}); // Meson in jet measurements - registry.add("h_mcd_meson_invarient_mass_JetConstituents", "MCD Mesons JetConstituents; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); - registry.add("h_mcd_meson_invarient_mass_pt_JetConstituents", "MCD Mesons JetConstituents; invariant mass; #p_{T, MCD}; entries", {HistType::kTH2F, {{100, 0.0, 1.0}, {100, 0.0, 100.}}}); - registry.add("h_mcd_true_pi0_mass_JetConstituents", "MCD True Mesons JetConstituents; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); - registry.add("h_mcd_background_mass_JetConstituents", "MCD Background Mesons JetConstituents; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); - registry.add("h_mcd_meson_invarient_mass_AllClusters", "MCD Mesons AllClusters; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); - registry.add("h_mcd_meson_invarient_mass_pt_AllClusters", "MCD Mesons AllClusters; invariant mass; #p_{T, MCD}; entries", {HistType::kTH2F, {{100, 0.0, 1.0}, {100, 0.0, 100.}}}); - registry.add("h_mcd_true_pi0_mass_AllClusters", "MCD True Mesons AllClusters; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); - registry.add("h_mcd_background_mass_AllClusters", "MCD Background Mesons AllClusters; invariant mass; entries", {HistType::kTH1F, {{100, 0.0, 1.0}}}); + registry.add("h_mc_meson_mass_JetClusters", "MC Mesons JetClusters; #m_{ClCl, meson}; entries", {HistType::kTH1F, {{300, 0.0, 3.0}}}); + registry.add("h_mc_meson_mass_pt_JetClusters", "MC Mesons JetClusters; #m_{ClCl, meson}; #p_{T, meson}; entries", {HistType::kTH2F, {{300, 0.0, 3.0}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_mass_pt_jetPt_JetClusters", "MC Mesons JetClusters; #m_{ClCl, meson}; #p_{T, meson}; #p_{T, Jet}; entries", {HistType::kTH3F, {{300, 0.0, 3.0}, {300, 0.0, 300.}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_z_JetClusters", "MC Mesons JetClusters; #z_{T, meson}; entries", {HistType::kTH1F, {{120, 0.0, 1.0}}}); + registry.add("h_mc_meson_mass_JetClusters_true", "MC true Mesons JetClusters; #m_{ClCl, meson}; entries", {HistType::kTH1F, {{300, 0.0, 3.0}}}); + registry.add("h_mc_meson_mass_pt_JetClusters_true", "MC true Mesons JetClusters; #m_{ClCl, meson}; #p_{T, meson}; entries", {HistType::kTH2F, {{300, 0.0, 3.0}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_mass_pt_jetPt_JetClusters_true", "MC true Mesons JetClusters; #m_{ClCl, meson}; #p_{T, meson}; #p_{T, Jet}; entries", {HistType::kTH3F, {{300, 0.0, 3.0}, {300, 0.0, 300.}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_z_JetClusters_true", "MC true Mesons JetClusters; #z_{T, meson}; entries", {HistType::kTH1F, {{120, 0.0, 1.0}}}); + registry.add("h_mc_meson_mass_JetClusters_background", "MC background Mesons JetClusters; #m_{ClCl, meson}; entries", {HistType::kTH1F, {{300, 0.0, 3.0}}}); + registry.add("h_mc_meson_mass_pt_JetClusters_background", "MC background Mesons JetClusters; #m_{ClCl, meson}; #p_{T, meson}; entries", {HistType::kTH2F, {{300, 0.0, 3.0}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_mass_pt_jetPt_JetClusters_background", "MC background Mesons JetClusters; #m_{ClCl, meson}; #p_{T, meson}; #p_{T, Jet}; entries", {HistType::kTH3F, {{300, 0.0, 3.0}, {300, 0.0, 300.}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_z_JetClusters_background", "MC background Mesons JetClusters; #z_{T, meson}; entries", {HistType::kTH1F, {{120, 0.0, 1.0}}}); + registry.add("h_mc_meson_mass_AllClusters", "MC Mesons AllClusters; #m_{ClCl, meson}; entries", {HistType::kTH1F, {{300, 0.0, 3.0}}}); + registry.add("h_mc_meson_mass_pt_AllClusters", "MC Mesons AllClusters; #m_{ClCl, meson}; #p_{T, meson}; entries", {HistType::kTH2F, {{300, 0.0, 3.0}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_mass_pt_jetPt_AllClusters", "MC Mesons AllClusters; #m_{ClCl, meson}; #p_{T, meson}; #p_{T, Jet}; entries", {HistType::kTH3F, {{300, 0.0, 3.0}, {300, 0.0, 300.}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_z_AllClusters", "MC Mesons AllClusters; #z_{T, meson}; entries", {HistType::kTH1F, {{120, 0.0, 1.0}}}); + registry.add("h_mc_meson_mass_AllClusters_true", "MC true Mesons AllClusters; #m_{ClCl, meson}; entries", {HistType::kTH1F, {{300, 0.0, 3.0}}}); + registry.add("h_mc_meson_mass_pt_AllClusters_true", "MC true Mesons AllClusters; #m_{ClCl, meson}; #p_{T, meson}; entries", {HistType::kTH2F, {{300, 0.0, 3.0}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_mass_pt_jetPt_AllClusters_true", "MC true Mesons AllClusters; #m_{ClCl, meson}; #p_{T, meson}; #p_{T, Jet}; entries", {HistType::kTH3F, {{300, 0.0, 3.0}, {300, 0.0, 300.}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_z_AllClusters_true", "MC true Mesons AllClusters; #z_{T, meson}; entries", {HistType::kTH1F, {{120, 0.0, 1.0}}}); + registry.add("h_mc_meson_mass_AllClusters_background", "MC background Mesons AllClusters; #m_{ClCl, meson}; entries", {HistType::kTH1F, {{300, 0.0, 3.0}}}); + registry.add("h_mc_meson_mass_pt_AllClusters_background", "MC background Mesons AllClusters; #m_{ClCl, meson}; #p_{T, meson}; entries", {HistType::kTH2F, {{300, 0.0, 3.0}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_mass_pt_jetPt_AllClusters_background", "MC background Mesons AllClusters; #m_{ClCl, meson}; #p_{T, meson}; #p_{T, Jet}; entries", {HistType::kTH3F, {{300, 0.0, 3.0}, {300, 0.0, 300.}, {300, 0.0, 300.}}}); + registry.add("h_mc_meson_z_AllClusters_background", "MC background Mesons AllClusters; #z_{T, meson}; entries", {HistType::kTH1F, {{120, 0.0, 1.0}}}); + + registry.add("h_data_meson_mass_JetClusters", "Data Mesons JetClusters; #m_{ClCl, meson}; entries", {HistType::kTH1F, {{300, 0.0, 3.0}}}); + registry.add("h_data_meson_mass_pt_JetClusters", "Data Mesons JetClusters; #m_{ClCl, meson}; #p_{T, meson}; entries", {HistType::kTH2F, {{300, 0.0, 3.0}, {300, 0.0, 300.}}}); + registry.add("h_data_meson_mass_pt_jetPt_JetClusters", "Data Mesons JetClusters; #m_{ClCl, meson}; #p_{T, meson}; #p_{T, Jet}; entries", {HistType::kTH3F, {{300, 0.0, 3.0}, {300, 0.0, 300.}, {300, 0.0, 300.}}}); + registry.add("h_data_meson_z_JetClusters", "Data Mesons JetClusters; #z_{T, meson}; entries", {HistType::kTH1F, {{120, 0.0, 1.0}}}); + registry.add("h_data_meson_mass_AllClusters", "Data Mesons AllClusters; #m_{ClCl, meson}; entries", {HistType::kTH1F, {{300, 0.0, 3.0}}}); + registry.add("h_data_meson_mass_pt_AllClusters", "Data Mesons AllClusters; #m_{ClCl, meson}; #p_{T, meson}; entries", {HistType::kTH2F, {{300, 0.0, 3.0}, {300, 0.0, 300.}}}); + registry.add("h_data_meson_mass_pt_jetPt_AllClusters", "Data Mesons AllClusters; #m_{ClCl, meson}; #p_{T, meson}; #p_{T, Jet}; entries", {HistType::kTH3F, {{300, 0.0, 3.0}, {300, 0.0, 300.}, {300, 0.0, 300.}}}); + registry.add("h_data_meson_z_AllClusters", "Data Mesons AllClusters; #z_{T, meson}; entries", {HistType::kTH1F, {{120, 0.0, 1.0}}}); } // TABLES @@ -238,6 +270,7 @@ struct neutralMesonInFullJets { using EMCCollisionsMCD = o2::soa::Join; // where, JetCollisionsMCD = JetCollisions+JMcCollisionLbs // For constituent information using JetTableMCDWithConstituents = soa::Join; + using JetTableDataWithConstituents = soa::Join; // Filters Filter jetCuts = aod::jet::pt > jetPtMin; @@ -287,8 +320,8 @@ struct neutralMesonInFullJets { template bool isJetInAcceptance(T const& jet) const { - const double R = static_cast(jet.r()) / 100.0; - double radiusFraction = 1.0; + const float R = static_cast(jet.r()) / 100.0; + float radiusFraction = 1.0; // Different cut types, could be customized furthur and more methods can be added // radius Fraction sets the range in which jet is accepted, for FullR eta leads to -0.3 to 0.3 @@ -302,32 +335,22 @@ struct neutralMesonInFullJets { default: LOGF(fatal, "Invalud jet acceptance cut selection: %d", jetAccpetanceCut.value); } - const double margin = radiusFraction * R; + const float margin = radiusFraction * R; // Eta acceptance - const double jetFidEtaMax = jetEtaMax.value - margin; + const float jetFidEtaMax = jetEtaMax.value - margin; if (std::abs(jet.eta()) > jetFidEtaMax) { return false; } // Phi acceptance - double jetFidPhiMin = jetPhiMin.value + margin; - double jetFidPhiMax = jetPhiMax.value - margin; - - // Normalize phi to [0, 2pi) - auto norm = [&](double a) { - while (a < 0) { - a += o2::constants::math::TwoPI; - } - while (a >= o2::constants::math::TwoPI) { - a -= o2::constants::math::TwoPI; - } - return a; - }; + float jetFidPhiMin = jetPhiMin.value + margin; + float jetFidPhiMax = jetPhiMax.value - margin; // Normalize using the above function - const double phi = norm(jet.phi()); - jetFidPhiMin = norm(jetFidPhiMin); - jetFidPhiMax = norm(jetFidPhiMax); + float phi = jet.phi(); + o2::math_utils::bringTo02Pi(phi); + o2::math_utils::bringTo02Pi(jetFidPhiMin); + o2::math_utils::bringTo02Pi(jetFidPhiMax); // cut on Phi if (jetFidPhiMin <= jetFidPhiMax) { @@ -434,7 +457,7 @@ struct neutralMesonInFullJets { // retrieve matching mcpjet for a mcdjet based on the selected MatchingScheme, Geo, Pt or Geo and Pt template - void forEachAcceptedMatch(MCDJet const& mcdjet, Callback&& callback) + void forEachAcceptedMatch(MCDJet const& mcdjet, Callback callback) { // Geo matching on the delta R closeness of the jets, Pt matching on the pt fraction of the matched constituents in the jet itself // Pt matching can be directional and needs to be accepted in both directions MCD->MCP and MCP->MCD (Geo is not directional MCD<->MCP) @@ -478,7 +501,7 @@ struct neutralMesonInFullJets { } if (mcdjet.has_matchedJetGeo()) { for (auto const& mcpjet : mcdjet.template matchedJetGeo_as()) { - if (ptMatchedMCPJetIds.find(mcpjet.globalIndex()) == ptMatchedMCPJetIds.end()) { + if (!ptMatchedMCPJetIds.contains(mcpjet.globalIndex())) { continue; } bool hasReversePtMatch = false; @@ -612,7 +635,7 @@ struct neutralMesonInFullJets { if (!isJetInAcceptance(mcpjet)) { continue; } - if (matchedMCPJetIds.find(mcpjet.globalIndex()) == matchedMCPJetIds.end()) { + if (!matchedMCPJetIds.contains(mcpjet.globalIndex())) { fillMatchingResponse(mcpjet, weight); } } @@ -655,6 +678,7 @@ struct neutralMesonInFullJets { collision, jets, weight, pTHat)) { return; } + fillCollisionCounter(10.5f, weight); // accepted collisions for (auto const& jet : jets) { registry.fill(HIST("h_mcd_jet_acceptance_counter"), 0.5); // all jets in accepted collisions @@ -680,6 +704,7 @@ struct neutralMesonInFullJets { collision, jets, weight, pTHat, &detectorCollisions)) { return; } + fillCollisionCounter(10.5f, weight); // accepted collisions for (auto const& jet : jets) { registry.fill(HIST("h_mcp_jet_acceptance_counter"), 0.5); // all jets in accepted collisions @@ -717,37 +742,31 @@ struct neutralMesonInFullJets { } PROCESS_SWITCH(neutralMesonInFullJets, processJetMatching, "Jet matching for MC-based unfolding", false) + // Meson measurement /// Meson measurement helper functions - template - std::vector reconstructPhotonsFromAllClusters(ClusterTable const& clusters) - { - std::vector photons; - - for (const auto& cluster : clusters) { - // cluster selection - photons.emplace_back(cluster.eta(), cluster.phi(), cluster.energy(), cluster.globalIndex()); - } - return photons; - } - - template - std::vector reconstructPhotonsFromJetClusters(Jet const& jet) - { - std::vector photons; - for (const auto& cluster : jet.template clusters_as()) { - // cluster selection - photons.emplace_back(cluster.eta(), cluster.phi(), cluster.energy(), cluster.globalIndex()); - } - return photons; - } - std::vector reconstructMesons(std::vector const& photons) { + // Pair all combinations of photon canidates to meson canidates std::vector mesons; for (size_t i = 0; i < photons.size(); ++i) { + // protection against zero momentum in caclulations + auto const& p1 = photons[i].photon; + if (p1.P() <= 0.f) { + continue; + } for (size_t j = i + 1; j < photons.size(); ++j) { + auto const& p2 = photons[j].photon; + if (p2.P() <= 0.f) { + continue; + } Meson meson(photons[i], photons[j]); - // Apply opening angle and other meson cuts + // TO DO: Apply opening angle and other meson cuts + if (meson.pMeson.P() <= 0.f) { + continue; + } + if (meson.getOpeningAngle() >= minOpenAngleCut) { + continue; + } mesons.push_back(meson); } } @@ -757,6 +776,7 @@ struct neutralMesonInFullJets { template float getMesonJetDeltaR(Meson const& meson, Jet const& jet) { + // Calculate geometrical distance between jet and meson canidate, for geometric matching const float deltaEta = meson.eta() - jet.eta(); const float deltaPhi = std::atan2(std::sin(meson.phi() - jet.phi()), std::cos(meson.phi() - jet.phi())); return std::sqrt(deltaEta * deltaEta + deltaPhi * deltaPhi); @@ -765,10 +785,14 @@ struct neutralMesonInFullJets { template auto findClosestJet(Meson const& meson, JetTable const& jets) { + // Match closes jet to a meson canidate, with a threshold of a maxMesonJetDeltaR using JetType = std::remove_reference_t; float minDeltaR = maxMesonJetDeltaR; JetType const* closestJet = nullptr; for (const auto& jet : jets) { + if (!isJetInAcceptance(jet)) { + continue; + } const float deltaR = getMesonJetDeltaR(meson, jet); if (deltaR < minDeltaR) { minDeltaR = deltaR; @@ -779,74 +803,116 @@ struct neutralMesonInFullJets { } template - int findPi0Ancestors(McParticle const& particle, - aod::McParticles const& mcParticles, - std::vector& pi0Ancestors, - std::vector& visited) + void findMesonAncestors(McParticle const& particle, + aod::McParticles const& mcParticles, + std::vector& MesonAncestors, + std::unordered_set& visited) { + // A recursive tree search to find all chosen neutral mesons in the ancestory of a photon canidate, full ancestory because of pi0->yy->ye-e+ (can also be identified by the clusters) for (auto motherId : particle.mothersIds()) { - if (motherId < 0) { + if (motherId < 0 || !visited.insert(motherId).second) { continue; } - if (std::find(visited.begin(), visited.end(), motherId) != visited.end()) { - continue; - } - visited.push_back(motherId); + // if (std::find(visited.begin(), visited.end(), motherId) != visited.end()) { + // continue; + // } + // visited.push_back(motherId); auto mother = mcParticles.iteratorAt(motherId); - if (std::abs(mother.pdgCode()) == 111) { - pi0Ancestors.push_back(motherId); + if (std::abs(mother.pdgCode()) == MCneutralmesonParticleId) { + MesonAncestors.push_back(motherId); } - findPi0Ancestors(mother, mcParticles, pi0Ancestors, visited); + findMesonAncestors(mother, mcParticles, MesonAncestors, visited); } } - template - bool isTruePi0(Meson const& meson, - aod::EMCALMCClusters const& mcClusterLables, - McParticles const& mcParticles) + template + Photon reconstructPhoton(Cluster const& cluster) { - auto mcCluster1 = mcClusterLables.iteratorAt(meson.pgamma1.id); - auto mcCluster2 = mcClusterLables.iteratorAt(meson.pgamma2.id); - - auto const& particleIds1 = mcCluster1.mcParticleIds(); - auto const& amplitudes1 = mcCluster1.amplitudeA(); - - auto const& particleIds2 = mcCluster2.mcParticleIds(); - auto const& amplitudes2 = mcCluster2.amplitudeA(); + static_assert(T == DataType::Data); + return Photon(cluster.eta(), cluster.phi(), cluster.energy(), cluster.globalIndex()); + } - if (particleIds1.empty() || amplitudes1.empty() || particleIds2.empty() || amplitudes2.empty()) { - return false; + template + Photon reconstructPhoton( + Cluster const& cluster, + aod::EMCALMCClusters const& mcClusterLabels, + aod::McParticles const& mcParticles, + std::unordered_map>& photonAncestors) + { + static_assert(T == DataType::MCD); + + Photon photon( + cluster.eta(), + cluster.phi(), + cluster.energy(), + cluster.globalIndex()); + auto mcCluster = mcClusterLabels.iteratorAt(cluster.globalIndex()); + auto const& particleIds = mcCluster.mcParticleIds(); + auto const& amplitudes = mcCluster.amplitudeA(); + if (particleIds.empty() || amplitudes.empty() || particleIds.size() != amplitudes.size()) { + return photon; } - if (particleIds1.size() != amplitudes1.size() || particleIds2.size() != amplitudes2.size()) { - return false; + auto leadingIt = std::max_element(amplitudes.begin(), amplitudes.end()); + auto leadingIndex = std::distance(amplitudes.begin(), leadingIt); + const int leadingParticleId = particleIds[leadingIndex]; + if (leadingParticleId < 0) { + return photon; } + auto particle = mcParticles.iteratorAt(leadingParticleId); + std::vector ancestors; + std::unordered_set visited; + visited.insert(leadingParticleId); + findMesonAncestors(particle, mcParticles, ancestors, visited); + photonAncestors.emplace(photon.id, std::move(ancestors)); + return photon; + } - auto leadingIt1 = std::max_element(amplitudes1.begin(), amplitudes1.end()); - auto leadingIndex1 = std::distance(amplitudes1.begin(), leadingIt1); - int mcParticleId1 = particleIds1[leadingIndex1]; - auto leadingIt2 = std::max_element(amplitudes2.begin(), amplitudes2.end()); - auto leadingIndex2 = std::distance(amplitudes2.begin(), leadingIt2); - int mcParticleId2 = particleIds2[leadingIndex2]; - - auto particle1 = mcParticles.iteratorAt(mcParticleId1); - auto particle2 = mcParticles.iteratorAt(mcParticleId2); - - // Change this so that it does not necessarily can be a photon, and it can go back further in the ancestory until it reaches a pi0 or is empty (no mother/end of ancestory) - - std::vector pi0Ancestors1; - std::vector pi0Ancestors2; + template + std::vector reconstructPhotonsFromAllClusters( + ClusterTable const& clusters, + Args&... args) + { + // Reconstruct all cluster singals in the collision into photon canidates + std::vector photons; - std::vector visited1; - std::vector visited2; + for (const auto& cluster : clusters) { + // TO DO: cluster selection + photons.emplace_back(reconstructPhoton(cluster, args...)); + } + return photons; + } - findPi0Ancestors(particle1, mcParticles, pi0Ancestors1, visited1); - findPi0Ancestors(particle2, mcParticles, pi0Ancestors2, visited2); + template + std::vector reconstructPhotonsFromJetClusters( + Jet const& jet, + Args&... args) + { + // Reconstruct all cluster singals that are part of a jet into photon canidates + std::vector photons; + for (const auto& cluster : jet.template clusters_as()) { + // TO DO: cluster selection + photons.emplace_back(reconstructPhoton(cluster, args...)); + } + return photons; + } - for (auto pi0Id1 : pi0Ancestors1) { - for (auto pi0Id2 : pi0Ancestors2) { - if (pi0Id1 == pi0Id2) { + template + bool isTrueMeson( + Photon const& photon1, + Photon const& photon2, + std::unordered_map> const& photonAncestors) + { + // test if the photon canidates of a meson canidates actually have a matching chosen meson in their ancestory + auto it1 = photonAncestors.find(photon1.id); + auto it2 = photonAncestors.find(photon2.id); + if (it1 == photonAncestors.end() || it2 == photonAncestors.end()) { + return false; + } + for (auto MesonId1 : it1->second) { + for (auto MesonId2 : it2->second) { + if (MesonId1 == MesonId2) { return true; } } @@ -854,50 +920,131 @@ struct neutralMesonInFullJets { return false; } - template - void fillMesonsInJet(Meson const& meson, Jet const& jet, McClusterLabels const& mcClusterLabels, McParticles const& mcParticles) + template + float momentumFraction(Meson const& meson, Jet const& jet) { - if constexpr (type == DataType::Data) { - if constexpr (Scheme == MesonReconstructionScheme::JetConstituents) { - // Add hists - } else if constexpr (Scheme == MesonReconstructionScheme::AllClusters) { - // Add hists + ROOT::Math::XYZVector pMeson(meson.pMeson.Px(), meson.pMeson.Py(), meson.pMeson.Pz()); + ROOT::Math::XYZVector pJet(jet.px(), jet.py(), jet.pz()); + float jetP2 = pJet.Mag2(); + if (jetP2 <= 0.f) { + LOGF(warning, "Jet with a negative or 0 transverse mometum was measured"); + } + return pMeson.Dot(pJet) / jetP2; + } + + template + void fillMesonsInJet(Meson const& meson, + Jet const& jet, + std::unordered_map> const& photonAncestors, + float weight) + { + static_assert(T == DataType::MCD); + + double z = momentumFraction(meson, jet); + bool isMeson = isTrueMeson(meson.pgamma1, meson.pgamma2, photonAncestors); + if constexpr (Scheme == MesonReconstructionScheme::JetClusters) { + registry.fill(HIST("h_mc_meson_mass_JetClusters"), meson.getMass(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_JetClusters"), meson.getMass(), meson.getPt(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_jetPt_JetClusters"), meson.getMass(), meson.getPt(), jet.pt(), weight); + registry.fill(HIST("h_mc_meson_z_JetClusters"), z, weight); + // Add hists + if (isMeson) { + registry.fill(HIST("h_mc_meson_mass_JetClusters_true"), meson.getMass(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_JetClusters_true"), meson.getMass(), meson.getPt(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_jetPt_JetClusters_true"), meson.getMass(), meson.getPt(), jet.pt(), weight); + registry.fill(HIST("h_mc_meson_z_JetClusters_true"), z, weight); } else { - LOGF(fatal, "Invalid meson reconstruction scheme: %d", Scheme); - } - } else if constexpr (type == DataType::MCD) { - bool isPi0 = isTruePi0(meson, mcClusterLabels, mcParticles); - if constexpr (Scheme == MesonReconstructionScheme::JetConstituents) { - registry.fill(HIST("h_mcd_meson_invarient_mass_JetConstituents"), meson.getMass()); - registry.fill(HIST("h_mcd_meson_invarient_mass_pt_JetConstituents"), meson.getMass(), meson.getPt()); - // Add hists - if (isPi0) { - registry.fill(HIST("h_mcd_true_pi0_mass_JetConstituents"), - meson.getMass()); - } else { - registry.fill(HIST("h_mcd_background_mass_JetConstituents"), - meson.getMass()); - } - } else if constexpr (Scheme == MesonReconstructionScheme::AllClusters) { - registry.fill(HIST("h_mcd_meson_invarient_mass_AllClusters"), meson.getMass()); - registry.fill(HIST("h_mcd_meson_invarient_mass_pt_AllClusters"), meson.getMass(), meson.getPt()); - // Add hists - if (isPi0) { - registry.fill(HIST("h_mcd_true_pi0_mass_AllClusters"), - meson.getMass()); - } else { - registry.fill(HIST("h_mcd_background_mass_AllClusters"), - meson.getMass()); - } + registry.fill(HIST("h_mc_meson_mass_JetClusters_background"), meson.getMass(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_JetClusters_background"), meson.getMass(), meson.getPt(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_jetPt_JetClusters_background"), meson.getMass(), meson.getPt(), jet.pt(), weight); + registry.fill(HIST("h_mc_meson_z_JetClusters_background"), z, weight); + } + } else if constexpr (Scheme == MesonReconstructionScheme::AllClusters) { + registry.fill(HIST("h_mc_meson_mass_AllClusters"), meson.getMass(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_AllClusters"), meson.getMass(), meson.getPt(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_jetPt_AllClusters"), meson.getMass(), meson.getPt(), jet.pt(), weight); + registry.fill(HIST("h_mc_meson_z_AllClusters"), z, weight); + // Add hists + if (isMeson) { + registry.fill(HIST("h_mc_meson_mass_AllClusters_true"), meson.getMass(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_AllClusters_true"), meson.getMass(), meson.getPt(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_jetPt_AllClusters_true"), meson.getMass(), meson.getPt(), jet.pt(), weight); + registry.fill(HIST("h_mc_meson_z_AllClusters_true"), z, weight); } else { - LOGF(fatal, "Invalid meson reconstruction scheme: %d", Scheme); + registry.fill(HIST("h_mc_meson_mass_AllClusters_background"), meson.getMass(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_AllClusters_background"), meson.getMass(), meson.getPt(), weight); + registry.fill(HIST("h_mc_meson_mass_pt_jetPt_AllClusters_background"), meson.getMass(), meson.getPt(), jet.pt(), weight); + registry.fill(HIST("h_mc_meson_z_AllClusters_background"), z, weight); } } else { - LOGF(fatal, "Invalid data type: %d", type); + LOGF(fatal, "Invalid meson reconstruction scheme: %d", mesonReconstructionScheme.value); + } + } + + template + void fillMesonsInJet(Meson const& meson, + Jet const& jet) + { + static_assert(T == DataType::Data); + + double z = momentumFraction(meson, jet); + if constexpr (Scheme == MesonReconstructionScheme::JetClusters) { + registry.fill(HIST("h_data_meson_mass_JetClusters"), meson.getMass()); + registry.fill(HIST("h_data_meson_mass_pt_JetClusters"), meson.getMass(), meson.getPt()); + registry.fill(HIST("h_data_meson_mass_pt_jetPt_JetClusters"), meson.getMass(), meson.getPt(), jet.pt()); + registry.fill(HIST("h_data_meson_z_JetClusters"), z); + + } else if constexpr (Scheme == MesonReconstructionScheme::AllClusters) { + registry.fill(HIST("h_data_meson_mass_AllClusters"), meson.getMass()); + registry.fill(HIST("h_data_meson_mass_pt_AllClusters"), meson.getMass(), meson.getPt()); + registry.fill(HIST("h_data_meson_mass_pt_jetPt_AllClusters"), meson.getMass(), meson.getPt(), jet.pt()); + registry.fill(HIST("h_data_meson_z_AllClusters"), z); + + } else { + LOGF(fatal, "Invalid meson reconstruction scheme: %d", mesonReconstructionScheme.value); } } - void processMCDMesonsInFullJets( + void processDataMesonsInFullJets( + soa::Filtered::iterator const& collision, + soa::Filtered const& jets, + aod::EMCALClusters const& clusters) + { + if (!eventSelection(collision, jets)) { + return; + } + + switch (static_cast(mesonReconstructionScheme.value)) { + case MesonReconstructionScheme::JetClusters: { + for (const auto& jet : jets) { + auto photons = reconstructPhotonsFromJetClusters(jet); + auto mesons = reconstructMesons(photons); + for (const auto& meson : mesons) { + fillMesonsInJet(meson, jet); + } + } + break; + } + case MesonReconstructionScheme::AllClusters: { + auto clustersPerCollision = clusters.sliceBy(ClusterPerCollision, collision.globalIndex()); + auto photons = reconstructPhotonsFromAllClusters(clustersPerCollision); + auto mesons = reconstructMesons(photons); + for (const auto& meson : mesons) { + auto associatedJet = findClosestJet(meson, jets); + if (associatedJet == nullptr) { + continue; + } + fillMesonsInJet(meson, *associatedJet); + } + break; + } + default: + LOGF(fatal, "Invalid meson reconstruction scheme: %d", mesonReconstructionScheme.value); + } + } + PROCESS_SWITCH(neutralMesonInFullJets, processDataMesonsInFullJets, "Measuring mesons in full jets in data", false) + + void processMCMesonsInFullJets( EMCCollisionsMCD::iterator const& collision, soa::Filtered const& jets, aod::EMCALClusters const& clusters, @@ -913,14 +1060,19 @@ struct neutralMesonInFullJets { return; } + std::unordered_map> photonAncestors; + switch (static_cast(mesonReconstructionScheme.value)) { - case MesonReconstructionScheme::JetConstituents: { + case MesonReconstructionScheme::JetClusters: { for (const auto& jet : jets) { - auto photons = reconstructPhotonsFromJetClusters(jet); + if (!isJetInAcceptance(jet)) { + continue; + } + auto photons = reconstructPhotonsFromJetClusters(jet, mcClusterLabels, mcParticles, photonAncestors); auto mesons = reconstructMesons(photons); for (const auto& meson : mesons) { - fillMesonsInJet(meson, jet, mcClusterLabels, mcParticles); + fillMesonsInJet(meson, jet, photonAncestors, weight); } } break; @@ -929,14 +1081,14 @@ struct neutralMesonInFullJets { case MesonReconstructionScheme::AllClusters: { auto clustersPerCollision = clusters.sliceBy(ClusterPerCollision, collision.globalIndex()); - auto photons = reconstructPhotonsFromAllClusters(clustersPerCollision); + auto photons = reconstructPhotonsFromAllClusters(clustersPerCollision, mcClusterLabels, mcParticles, photonAncestors); auto mesons = reconstructMesons(photons); for (const auto& meson : mesons) { auto associatedJet = findClosestJet(meson, jets); if (associatedJet == nullptr) { continue; } - fillMesonsInJet(meson, *associatedJet, mcClusterLabels, mcParticles); + fillMesonsInJet(meson, *associatedJet, photonAncestors, weight); } break; } @@ -945,11 +1097,11 @@ struct neutralMesonInFullJets { LOGF(fatal, "Invalid meson reconstruction scheme: %d", mesonReconstructionScheme.value); } } - PROCESS_SWITCH(neutralMesonInFullJets, processMCDMesonsInFullJets, "Measuring mesons in full jets in MCD", false) + PROCESS_SWITCH(neutralMesonInFullJets, processMCMesonsInFullJets, "Measuring mesons in full jets in MCD", false) }; -WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +WorkflowSpec defineDataProcessing(ConfigContext const& context) { return WorkflowSpec{ - adaptAnalysisTask(cfgc)}; + adaptAnalysisTask(context)}; } From 54e4bfbece4efb411994d84e745d9139cc3a4a4b Mon Sep 17 00:00:00 2001 From: Jan Scharf Date: Mon, 30 Nov 2026 20:24:40 +0100 Subject: [PATCH 5/5] Fixed O2-linter warnings. --- PWGJE/Tasks/neutralMesonInFullJets.cxx | 124 ++++++++++++------------- 1 file changed, 59 insertions(+), 65 deletions(-) diff --git a/PWGJE/Tasks/neutralMesonInFullJets.cxx b/PWGJE/Tasks/neutralMesonInFullJets.cxx index 17d4ca03bb1..9cb1471d734 100644 --- a/PWGJE/Tasks/neutralMesonInFullJets.cxx +++ b/PWGJE/Tasks/neutralMesonInFullJets.cxx @@ -9,12 +9,10 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. // -/// \file neutralMesonsInFullJets.cxx +/// \file neutralMesonInFullJets.cxx /// \brief Task for neutral meson measurement in full jets /// \author Jan Scharf -/// TO DO : Add Neutral Mesons measurement to the current full jet measuremtn - #include "PWGJE/Core/JetDerivedDataUtilities.h" #include "PWGJE/DataModel/EMCALClusters.h" #include "PWGJE/DataModel/Jet.h" @@ -64,8 +62,8 @@ struct Photon { pt(std::sqrt(px * px + py * py)), photon(px, py, pz, energy), id(clusid), - sm(sm_tmp), - onDCal(phi < 6 && phi > 4) // o2-linter: disable=magic-number (DCal phi range) + sm(sm_tmp) + // onDCal(phi < 6 && phi > 4) { } @@ -80,7 +78,7 @@ struct Photon { ROOT::Math::PxPyPzEVector photon; int id; uint8_t sm; - bool onDCal{phi < 6 && phi > 4}; // Checks whether photon is in phi region of the DCal, otherwise: EMCal + // bool onDCal{phi < 6 && phi > 4}; // Checks whether photon is in phi region of the DCal, otherwise: EMCal }; struct Meson { Meson(Photon const& p1, Photon const& p2) : pgamma1(p1), pgamma2(p2), pMeson(p1.photon + p2.photon) @@ -103,7 +101,7 @@ struct Meson { [[nodiscard]] ROOT::Math::PxPyPzEVector getMathVector() const { return pMeson; } }; -struct neutralMesonInFullJets { +struct NeutralMesonInFullJets { HistogramRegistry registry; // define different enum classes to avoid "magic numbers" // DataType used in eventSelection and saving of histograms, and more @@ -125,13 +123,13 @@ struct neutralMesonInFullJets { Fake, Miss }; - enum class JetAccpetanceCut { + enum class JetAcceptanceCut { FullR, HalfR }; enum class MesonReconstructionScheme { - JetClusters, // Photon canidates a reconstructed from the cluster signals that are associated to jet - AllClusters // Photon canidates a reconstructed from all cluster signals in the collision and then matched (using Geo matching) to a jet + JetClusters, // Photon candidates a reconstructed from the cluster signals that are associated to jet + AllClusters // Photon candidates a reconstructed from all cluster signals in the collision and then matched (using Geo matching) to a jet }; // CONFIGURABLES @@ -139,7 +137,7 @@ struct neutralMesonInFullJets { Configurable vertexZCut{"vertexZCut", 10.0f, "Accepted z-vertex range"}; Configurable pTHatMax{"pTHatMax", 2.5, "maximum fraction of hard scattering for jet acceptance in MC"}; Configurable pTHatExponent{"pTHatExponent", 4.0, "exponent of the event weight for the calculation of pTHeventSelectionBitsat"}; // 6 for MB MC and 4 for JJ MC - Configurable pTHatMin{"pTHatAbsoluteMin", 0.0, "minimum value of pTHat"}; + Configurable pTHatMin{"pTHatMin", 0.0, "minimum value of pTHat"}; Configurable doMBGapTrigger{"doMBGapTrigger", true, "set to true only when using MB-Gap Trigger JJ MC to reject MB events at the collision and track level"}; Configurable applyRCTSelections{"applyRCTSelections", true, "decide to apply RCT selections"}; Configurable eventSelections{"eventSelections", "selMC", "choose event selection"}; // selMC for MC and sel8 for data @@ -147,7 +145,7 @@ struct neutralMesonInFullJets { // Jet Configurables Configurable jetPtMin{"jetPtMin", 5.0, "minimum jet pT cut"}; - Configurable jetAccpetanceCut{"jetAcceptanceCut", 0, "Jet acceptance cut: 0 = FullR, 1 = HalfR"}; + Configurable jetAcceptanceCut{"jetAcceptanceCut", 0, "Jet acceptance cut: 0 = FullR, 1 = HalfR"}; Configurable jetEtaMax{"jetEtaMax", 0.7, "Min jet eta based on EMCAL acceptance"}; Configurable jetPhiMin{"jetPhiMin", 1.3962634, "Min jet phi based on EMCAL acceptance"}; Configurable jetPhiMax{"jetPhiMax", 3.2836100, "Max jet phi based on EMCAL acceptance"}; @@ -160,7 +158,7 @@ struct neutralMesonInFullJets { Configurable minOpenAngleCut{"minOpenAngleCut", 0.0202, "apply min opening angle cut"}; Configurable mesonReconstructionScheme{"mesonReconstructionScheme", 0, "Meson reconstruction scheme: 0 = Jet clusters, 1 = All collision clusters"}; Configurable maxMesonJetDeltaR{"maxMesonJetDeltaR", 0.4f, "Maximum delta R for meson-jet association"}; - Configurable MCneutralmesonParticleId{"MCneutralmesonParticleId", 111, "PDG code of the neutral meson that is measured, default is pi0 (111)"}; + Configurable mCneutralmesonParticleId{"mCneutralmesonParticleId", 111, "PDG code of the neutral meson that is measured, default is pi0 (111)"}; std::vector eventSelectionBits; @@ -170,28 +168,28 @@ struct neutralMesonInFullJets { // processDataJets: registry.add("h_data_jet_pt", "data jet pT;#it{p}_{T,jet} (GeV/#it{c});entries", {HistType::kTH1F, {{300, 0., 300.}}}); registry.add("h_data_jet_eta", "data jet #eta; #eta; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); - registry.add("h_data_jet_phi", "data jet #phi; #phi; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); - registry.add("h_data_jet_eta_phi", "data jet #eta #phi; #eta; #phi; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_data_jet_phi", "data jet #phi; #phi; entries", {HistType::kTH1F, {{100, 0, o2::constants::math::TwoPI}}}); + registry.add("h_data_jet_eta_phi", "data jet #eta #phi; #eta; #phi; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, 0, o2::constants::math::TwoPI}}}); // processMCPJets registry.add("h_mcp_jet_pt", "MCP jet pT;#it{p}_{T,jet} (GeV/#it{c});entries", {HistType::kTH1F, {{300, 0., 300.}}}); registry.add("h_mcp_jet_eta", "MCP jet #eta; #eta; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); - registry.add("h_mcp_jet_phi", "MCP jet #phi; #phi; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); - registry.add("h_mcp_jet_eta_phi", "MCP jet #eta #phi; #eta; #phi; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_mcp_jet_phi", "MCP jet #phi; #phi; entries", {HistType::kTH1F, {{100, 0, o2::constants::math::TwoPI}}}); + registry.add("h_mcp_jet_eta_phi", "MCP jet #eta #phi; #eta; #phi; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, 0, o2::constants::math::TwoPI}}}); // processMCDJets registry.add("h_mcd_jet_pt", "MCD jet pT;#it{p}_{T,jet} (GeV/#it{c});entries", {HistType::kTH1F, {{300, 0., 300.}}}); registry.add("h_mcd_jet_eta", "MCD jet #eta; #eta; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); - registry.add("h_mcd_jet_phi", "MCD jet #phi; #phi; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); - registry.add("h_mcd_jet_eta_phi", "MCD jet #eta #phi; #eta; #phi; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_mcd_jet_phi", "MCD jet #phi; #phi; entries", {HistType::kTH1F, {{100, 0, o2::constants::math::TwoPI}}}); + registry.add("h_mcd_jet_eta_phi", "MCD jet #eta #phi; #eta; #phi; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, 0, o2::constants::math::TwoPI}}}); // Matching histograms using Geo "0" matching registry.add("h_jet_response_pt_geomatching", "Matched jets using geometrical matching; #p_{T, MCD}; #p_{T, MCP}; entries", {HistType::kTH2F, {{300, 0., 300.}, {300, 0., 300.}}}); registry.add("h_jet_reponse_pt_fake_geomatching", "Fake jets using geometrical matching; #p_{T, MCP}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); registry.add("h_jet_reponse_pt_miss_geomatching", "Miss jets using geometrical matching; #p_{T, MCD}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); - registry.add("h_jet_response_phi_geomatching", "Matched jets using geometrical matching; #phi_{MCD}; #phi_{MCP}; entries", {HistType::kTH2F, {{100, 0, 2 * o2::constants::math::PI}, {100, 0, 2 * o2::constants::math::PI}}}); - registry.add("h_jet_reponse_phi_fake_geomatching", "Fake jets using geometrical matching; #phi_{MCP}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); - registry.add("h_jet_reponse_phi_miss_geomatching", "Miss jets using geometrical matching; #phi_{MCD}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_response_phi_geomatching", "Matched jets using geometrical matching; #phi_{MCD}; #phi_{MCP}; entries", {HistType::kTH2F, {{100, 0, o2::constants::math::TwoPI}, {100, 0, o2::constants::math::TwoPI}}}); + registry.add("h_jet_reponse_phi_fake_geomatching", "Fake jets using geometrical matching; #phi_{MCP}; entries", {HistType::kTH1F, {{100, 0, o2::constants::math::TwoPI}}}); + registry.add("h_jet_reponse_phi_miss_geomatching", "Miss jets using geometrical matching; #phi_{MCD}; entries", {HistType::kTH1F, {{100, 0, o2::constants::math::TwoPI}}}); registry.add("h_jet_response_eta_geomatching", "Matched jets using geometrical matching; #eta_{MCD}; #eta_{MCP}; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, -0.8, 0.8}}}); registry.add("h_jet_reponse_eta_fake_geomatching", "Fake jets using geometrical matching; #eta_{MCP}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); registry.add("h_jet_reponse_eta_miss_geomatching", "Miss jets using geometrical matching; #eta_{MCD}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); @@ -200,9 +198,9 @@ struct neutralMesonInFullJets { registry.add("h_jet_response_pt_ptmatching", "Matched jets using pT-fraction matching; #p_{T, MCD}; #p_{T, MCP}; entries", {HistType::kTH2F, {{300, 0., 300.}, {300, 0., 300.}}}); registry.add("h_jet_reponse_pt_fake_ptmatching", "Fake jets using pT-fraction matching; #p_{T, MCP}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); registry.add("h_jet_reponse_pt_miss_ptmatching", "Miss jets using pT-fraction matching; #p_{T, MCD}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); - registry.add("h_jet_response_phi_ptmatching", "Matched jets using pT-fraction matching; #phi_{MCD}; #phi_{MCP}; entries", {HistType::kTH2F, {{100, 0, 2 * o2::constants::math::PI}, {100, 0, 2 * o2::constants::math::PI}}}); - registry.add("h_jet_reponse_phi_fake_ptmatching", "Fake jets using pT-fraction matching; #phi_{MCP}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); - registry.add("h_jet_reponse_phi_miss_ptmatching", "Miss jets using pT-fraction matching; #phi_{MCD}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_response_phi_ptmatching", "Matched jets using pT-fraction matching; #phi_{MCD}; #phi_{MCP}; entries", {HistType::kTH2F, {{100, 0, o2::constants::math::TwoPI}, {100, 0, o2::constants::math::TwoPI}}}); + registry.add("h_jet_reponse_phi_fake_ptmatching", "Fake jets using pT-fraction matching; #phi_{MCP}; entries", {HistType::kTH1F, {{100, 0, o2::constants::math::TwoPI}}}); + registry.add("h_jet_reponse_phi_miss_ptmatching", "Miss jets using pT-fraction matching; #phi_{MCD}; entries", {HistType::kTH1F, {{100, 0, o2::constants::math::TwoPI}}}); registry.add("h_jet_response_eta_ptmatching", "Matched jets using pT-fraction matching; #eta_{MCD}; #eta_{MCP}; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, -0.8, 0.8}}}); registry.add("h_jet_reponse_eta_fake_ptmatching", "Fake jets using pT-fraction matching; #eta_{MCP}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); registry.add("h_jet_reponse_eta_miss_ptmatching", "Miss jets using pT-fraction matching; #eta_{MCD}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); @@ -211,9 +209,9 @@ struct neutralMesonInFullJets { registry.add("h_jet_response_pt_geoptmatching", "Matched jets using geometrical AND pT-fraction matching; #p_{T, MCD}; #p_{T, MCP}; entries", {HistType::kTH2F, {{300, 0., 300.}, {300, 0., 300.}}}); registry.add("h_jet_reponse_pt_fake_geoptmatching", "Fake jets using geometrical AND pT-fraction matching; #p_{T, MCP}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); registry.add("h_jet_reponse_pt_miss_geoptmatching", "Miss jets using geometrical AND pT-fraction matching; #p_{T, MCD}; entries", {HistType::kTH1F, {{300, 0., 300.}}}); - registry.add("h_jet_response_phi_geoptmatching", "Matched jets using geometrical AND pT-fraction matching; #phi_{MCD}; #phi_{MCP}; entries", {HistType::kTH2F, {{100, 0, 2 * o2::constants::math::PI}, {100, 0, 2 * o2::constants::math::PI}}}); - registry.add("h_jet_reponse_phi_fake_geoptmatching", "Fake jets using geometrical AND pT-fraction matching; #phi_{MCP}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); - registry.add("h_jet_reponse_phi_miss_geoptmatching", "Miss jets using geometrical AND pT-fraction matching; #phi_{MCD}; entries", {HistType::kTH1F, {{100, 0, 2 * o2::constants::math::PI}}}); + registry.add("h_jet_response_phi_geoptmatching", "Matched jets using geometrical AND pT-fraction matching; #phi_{MCD}; #phi_{MCP}; entries", {HistType::kTH2F, {{100, 0, o2::constants::math::TwoPI}, {100, 0, o2::constants::math::TwoPI}}}); + registry.add("h_jet_reponse_phi_fake_geoptmatching", "Fake jets using geometrical AND pT-fraction matching; #phi_{MCP}; entries", {HistType::kTH1F, {{100, 0, o2::constants::math::TwoPI}}}); + registry.add("h_jet_reponse_phi_miss_geoptmatching", "Miss jets using geometrical AND pT-fraction matching; #phi_{MCD}; entries", {HistType::kTH1F, {{100, 0, o2::constants::math::TwoPI}}}); registry.add("h_jet_response_eta_geoptmatching", "Matched jets using geometrical AND pT-fraction matching; #eta_{MCD}; #eta_{MCP}; entries", {HistType::kTH2F, {{100, -0.8, 0.8}, {100, -0.8, 0.8}}}); registry.add("h_jet_reponse_eta_fake_geoptmatching", "Fake jets using geometrical AND pT-fraction matching; #eta_{MCP}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); registry.add("h_jet_reponse_eta_miss_geoptmatching", "Miss jets using geometrical AND pT-fraction matching; #eta_{MCD}; entries", {HistType::kTH1F, {{100, -0.8, 0.8}}}); @@ -276,9 +274,9 @@ struct neutralMesonInFullJets { Filter jetCuts = aod::jet::pt > jetPtMin; Filter collisionFilter = nabs(aod::jcollision::posZ) < vertexZCut; // Filter is not sufficient and is performed again manually in the event Selection - PresliceOptional JetMCPPerMcCollision = aod::jet::mcCollisionId; // used in MC matching - PresliceUnsortedOptional CollisionsPerMCPCollision = aod::jmccollisionlb::mcCollisionId; // ensure a for a MCP collision a matched MCD collision is accepted - PresliceOptional ClusterPerCollision = aod::emcalcluster::collisionId; // EMCAL cluster per collision + PresliceOptional jetMCPPerMcCollision = aod::jet::mcCollisionId; // used in MC matching + PresliceUnsortedOptional collisionsPerMCPCollision = aod::jmccollisionlb::mcCollisionId; // ensure a for a MCP collision a matched MCD collision is accepted + PresliceOptional clusterPerCollision = aod::emcalcluster::collisionId; // EMCAL cluster per collision // HELPER FUNCTIONS // fill jet pt, eta and phi histograms for DataType Data, MCP and MCD @@ -320,22 +318,22 @@ struct neutralMesonInFullJets { template bool isJetInAcceptance(T const& jet) const { - const float R = static_cast(jet.r()) / 100.0; + const float r = static_cast(jet.r()) / 100.0; float radiusFraction = 1.0; // Different cut types, could be customized furthur and more methods can be added - // radius Fraction sets the range in which jet is accepted, for FullR eta leads to -0.3 to 0.3 - switch (static_cast(jetAccpetanceCut.value)) { - case JetAccpetanceCut::FullR: + // radius Fraction sets the range in which jet is accepted, for Fullreta leads to -0.3 to 0.3 + switch (static_cast(jetAcceptanceCut.value)) { + case JetAcceptanceCut::FullR: radiusFraction = 1.0; break; - case JetAccpetanceCut::HalfR: + case JetAcceptanceCut::HalfR: radiusFraction = 0.5; break; default: - LOGF(fatal, "Invalud jet acceptance cut selection: %d", jetAccpetanceCut.value); + LOGF(fatal, "Invalid jet acceptance cut selection: %d", jetAcceptanceCut.value); } - const float margin = radiusFraction * R; + const float margin = radiusFraction * r; // Eta acceptance const float jetFidEtaMax = jetEtaMax.value - margin; @@ -369,10 +367,10 @@ struct neutralMesonInFullJets { float weight) { // To select MCP collision, it is ensured that it can be matched to accepted MCD collision, otherwise this collision is not usefull for matching and further study - // In other words, the MCP collision needs to be measureable + // In other words, the MCP collision needs to be measurable // Find all matched MCD collision to the specific MCP collision (no direct matching between MCP->MCD, therefore more possible) - auto collisionspermcpjet = detcollisions.sliceBy(CollisionsPerMCPCollision, partcollisions.globalIndex()); + auto collisionspermcpjet = detcollisions.sliceBy(collisionsPerMCPCollision, partcollisions.globalIndex()); if (collisionspermcpjet.size() < 1) // at least one match is required { fillCollisionCounter(7.5f, weight); // collisions that are cut, because they have no matched MCD collisions @@ -602,7 +600,7 @@ struct neutralMesonInFullJets { } // Retrieve MCP jets associated with this MC collision - auto mcpJetsPerMcCollision = mcpjets.sliceBy(JetMCPPerMcCollision, collision.mcCollisionId()); + auto mcpJetsPerMcCollision = mcpjets.sliceBy(jetMCPPerMcCollision, collision.mcCollisionId()); std::unordered_set matchedMCPJetIds; for (const auto& mcdjet : mcdjets) { @@ -646,7 +644,7 @@ struct neutralMesonInFullJets { void processDummy(aod::JetMcCollision const&) { } - PROCESS_SWITCH(neutralMesonInFullJets, processDummy, "dummy process", false) + PROCESS_SWITCH(NeutralMesonInFullJets, processDummy, "dummy process", false) // Measuring Jet pt, eta, phi for jets in data void processDataJets(soa::Filtered::iterator const& collision, @@ -665,7 +663,7 @@ struct neutralMesonInFullJets { fillJetHistograms(jet); } } - PROCESS_SWITCH(neutralMesonInFullJets, processDataJets, "Full jet measurement in data", false) + PROCESS_SWITCH(NeutralMesonInFullJets, processDataJets, "Full jet measurement in data", false) // Measuring Jet pt, eta, phi for jets in MC detector-level void processMCDJets(soa::Filtered::iterator const& collision, @@ -689,7 +687,7 @@ struct neutralMesonInFullJets { fillJetHistograms(jet, weight); } } - PROCESS_SWITCH(neutralMesonInFullJets, processMCDJets, "Full detector-level MC jet measurement", false) + PROCESS_SWITCH(NeutralMesonInFullJets, processMCDJets, "Full detector-level MC jet measurement", false) // Measuring Jet pt, eta, phi for jets in MC particle-level void processMCPJets(aod::JetMcCollisions::iterator const& collision, @@ -715,7 +713,7 @@ struct neutralMesonInFullJets { fillJetHistograms(jet, weight); } } - PROCESS_SWITCH(neutralMesonInFullJets, processMCPJets, "Full particle-level MC jet measurement", false) + PROCESS_SWITCH(NeutralMesonInFullJets, processMCPJets, "Full particle-level MC jet measurement", false) // Matching MC detector and particle-level jets to calculate the response, fake and miss histogram for later use in unfolding void processJetMatching(EMCCollisionsMCD::iterator const& collision, // removed soa::Filtered here, was an issue in the matching @@ -737,16 +735,16 @@ struct neutralMesonInFullJets { collision, mcdjets, mcpjets); break; default: - LOGF(fatal, "Invalud matching scheme: %d", matchingScheme.value); + LOGF(fatal, "Invalid matching scheme: %d", matchingScheme.value); } } - PROCESS_SWITCH(neutralMesonInFullJets, processJetMatching, "Jet matching for MC-based unfolding", false) + PROCESS_SWITCH(NeutralMesonInFullJets, processJetMatching, "Jet matching for MC-based unfolding", false) // Meson measurement /// Meson measurement helper functions std::vector reconstructMesons(std::vector const& photons) { - // Pair all combinations of photon canidates to meson canidates + // Pair all combinations of photon candidates to meson candidates std::vector mesons; for (size_t i = 0; i < photons.size(); ++i) { // protection against zero momentum in caclulations @@ -808,19 +806,15 @@ struct neutralMesonInFullJets { std::vector& MesonAncestors, std::unordered_set& visited) { - // A recursive tree search to find all chosen neutral mesons in the ancestory of a photon canidate, full ancestory because of pi0->yy->ye-e+ (can also be identified by the clusters) - for (auto motherId : particle.mothersIds()) { + // A recursive tree search to find all chosen neutral mesons in the ancestry of a photon canidate, full ancestry because of pi0->yy->ye-e+ (can also be identified by the clusters) + for (const auto& motherId : particle.mothersIds()) { if (motherId < 0 || !visited.insert(motherId).second) { continue; } - // if (std::find(visited.begin(), visited.end(), motherId) != visited.end()) { - // continue; - // } - // visited.push_back(motherId); auto mother = mcParticles.iteratorAt(motherId); - if (std::abs(mother.pdgCode()) == MCneutralmesonParticleId) { + if (std::abs(mother.pdgCode()) == mCneutralmesonParticleId) { MesonAncestors.push_back(motherId); } findMesonAncestors(mother, mcParticles, MesonAncestors, visited); @@ -874,7 +868,7 @@ struct neutralMesonInFullJets { ClusterTable const& clusters, Args&... args) { - // Reconstruct all cluster singals in the collision into photon canidates + // Reconstruct all cluster singals in the collision into photon candidates std::vector photons; for (const auto& cluster : clusters) { @@ -889,7 +883,7 @@ struct neutralMesonInFullJets { Jet const& jet, Args&... args) { - // Reconstruct all cluster singals that are part of a jet into photon canidates + // Reconstruct all cluster singals that are part of a jet into photon candidates std::vector photons; for (const auto& cluster : jet.template clusters_as()) { // TO DO: cluster selection @@ -904,14 +898,14 @@ struct neutralMesonInFullJets { Photon const& photon2, std::unordered_map> const& photonAncestors) { - // test if the photon canidates of a meson canidates actually have a matching chosen meson in their ancestory + // test if the photon candidates of a meson candidates actually have a matching chosen meson in their ancestry auto it1 = photonAncestors.find(photon1.id); auto it2 = photonAncestors.find(photon2.id); if (it1 == photonAncestors.end() || it2 == photonAncestors.end()) { return false; } - for (auto MesonId1 : it1->second) { - for (auto MesonId2 : it2->second) { + for (const auto& MesonId1 : it1->second) { + for (const auto& MesonId2 : it2->second) { if (MesonId1 == MesonId2) { return true; } @@ -1026,7 +1020,7 @@ struct neutralMesonInFullJets { break; } case MesonReconstructionScheme::AllClusters: { - auto clustersPerCollision = clusters.sliceBy(ClusterPerCollision, collision.globalIndex()); + auto clustersPerCollision = clusters.sliceBy(clusterPerCollision, collision.globalIndex()); auto photons = reconstructPhotonsFromAllClusters(clustersPerCollision); auto mesons = reconstructMesons(photons); for (const auto& meson : mesons) { @@ -1042,7 +1036,7 @@ struct neutralMesonInFullJets { LOGF(fatal, "Invalid meson reconstruction scheme: %d", mesonReconstructionScheme.value); } } - PROCESS_SWITCH(neutralMesonInFullJets, processDataMesonsInFullJets, "Measuring mesons in full jets in data", false) + PROCESS_SWITCH(NeutralMesonInFullJets, processDataMesonsInFullJets, "Measuring mesons in full jets in data", false) void processMCMesonsInFullJets( EMCCollisionsMCD::iterator const& collision, @@ -1080,7 +1074,7 @@ struct neutralMesonInFullJets { case MesonReconstructionScheme::AllClusters: { - auto clustersPerCollision = clusters.sliceBy(ClusterPerCollision, collision.globalIndex()); + auto clustersPerCollision = clusters.sliceBy(clusterPerCollision, collision.globalIndex()); auto photons = reconstructPhotonsFromAllClusters(clustersPerCollision, mcClusterLabels, mcParticles, photonAncestors); auto mesons = reconstructMesons(photons); for (const auto& meson : mesons) { @@ -1097,11 +1091,11 @@ struct neutralMesonInFullJets { LOGF(fatal, "Invalid meson reconstruction scheme: %d", mesonReconstructionScheme.value); } } - PROCESS_SWITCH(neutralMesonInFullJets, processMCMesonsInFullJets, "Measuring mesons in full jets in MCD", false) + PROCESS_SWITCH(NeutralMesonInFullJets, processMCMesonsInFullJets, "Measuring mesons in full jets in MCD", false) }; WorkflowSpec defineDataProcessing(ConfigContext const& context) { return WorkflowSpec{ - adaptAnalysisTask(context)}; + adaptAnalysisTask(context)}; }