Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 48 additions & 22 deletions PWGJE/Core/JetFindingUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
#include "PWGJE/DataModel/Jet.h"
#include "PWGJE/DataModel/JetReducedData.h"

#include <CommonConstants/MathConstants.h>
#include <CommonConstants/PhysicsConstants.h>
#include <Framework/ASoA.h>
#include <Framework/AnalysisHelpers.h>
#include <Framework/O2DatabasePDGPlugin.h>

#include <THn.h>
#include <TParticlePDG.h>

#include <fastjet/ClusterSequenceArea.hh>
#include <fastjet/PseudoJet.hh>
Expand All @@ -38,11 +40,8 @@
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

#include <math.h>

namespace jetfindingutilities
{

Expand Down Expand Up @@ -296,7 +295,7 @@ void findJets(JetFinder& jetFinder, std::vector<fastjet::PseudoJet> const& input
std::vector<fastjet::PseudoJet> jets;
fastjet::ClusterSequenceArea clusterSeq(jetFinder.findJets(inputParticles, jets));
for (const auto& jet : jets) {
if (jet.has_area() && jet.area() < jetAreaFractionMin * M_PI * R * R) {
if (jet.has_area() && jet.area() < jetAreaFractionMin * o2::constants::math::PI * R * R) {
continue;
}
if (fillThnSparse) {
Expand Down Expand Up @@ -336,6 +335,49 @@ void findJets(JetFinder& jetFinder, std::vector<fastjet::PseudoJet> const& input
}
}

/**
* Applies the particle status and charge selections shared by jet finding and background QA.
* Kinematic acceptance cuts are applied to the input particle table separately.
*/
template <typename T, typename U>
bool isParticleSelected(T const& particle, const std::string& particleSelection, int jetTypeParticleLevel, U const& pdgDatabase, TParticlePDG const*& pdgParticle)
{
if (particleSelection == "PhysicalPrimary" && !particle.isPhysicalPrimary()) {
return false;
} else if (particleSelection == "HepMCStatus" && particle.getHepMCStatusCode() != 1) {
return false;
} else if (particleSelection == "GenStatus" && particle.getGenStatusCode() != 1) {
return false;
} else if (particleSelection == "PhysicalPrimaryAndHepMCStatus" && (!particle.isPhysicalPrimary() || particle.getHepMCStatusCode() != 1)) {
return false;
}
if (std::isinf(particle.eta())) {
return false;
}
pdgParticle = pdgDatabase->GetParticle(particle.pdgCode());
if (pdgParticle == nullptr) {
return false;
}
auto pdgCharge = std::abs(pdgParticle->Charge());
if (jetTypeParticleLevel == static_cast<int>(JetType::charged) && pdgCharge < 3.0) {
return false;
}
if (jetTypeParticleLevel == static_cast<int>(JetType::neutral) && pdgCharge != 0.0) {
return false;
}
return true;
}

/**
* Overload of isParticleSelected without the pdgParticle output parameter.
*/
template <typename T, typename U>
bool isParticleSelected(T const& particle, const std::string& particleSelection, int jetTypeParticleLevel, U const& pdgDatabase)
{
TParticlePDG const* pdgParticle = nullptr;
return isParticleSelected(particle, particleSelection, jetTypeParticleLevel, pdgDatabase, pdgParticle);
}

/**
* Adds particles to a fastjet inputParticles list
*
Expand All @@ -350,24 +392,8 @@ template <bool checkIsDaughter, typename T, typename U>
void analyseParticles(std::vector<fastjet::PseudoJet>& inputParticles, const std::string& particleSelection, int jetTypeParticleLevel, T const& particles, o2::framework::Service<o2::framework::O2DatabasePDG> pdgDatabase, const U* candidate = nullptr)
{
for (auto& particle : particles) {
if (particleSelection == "PhysicalPrimary" && !particle.isPhysicalPrimary()) { // CHECK : Does this exclude the HF hadron?
continue;
} else if (particleSelection == "HepMCStatus" && particle.getHepMCStatusCode() != 1) { // do we need isPhysicalPrimary as well? Note: Might give unforseen results if the generator isnt PYTHIA
continue;
} else if (particleSelection == "GenStatus" && particle.getGenStatusCode() != 1) {
continue;
} else if (particleSelection == "PhysicalPrimaryAndHepMCStatus" && (!particle.isPhysicalPrimary() || particle.getHepMCStatusCode() != 1)) {
continue;
}
if (std::isinf(particle.eta())) {
continue;
}
auto pdgParticle = pdgDatabase->GetParticle(particle.pdgCode());
auto pdgCharge = pdgParticle ? std::abs(pdgParticle->Charge()) : -1.0;
if (jetTypeParticleLevel == static_cast<int>(JetType::charged) && pdgCharge < 3.0) {
continue;
}
if (jetTypeParticleLevel == static_cast<int>(JetType::neutral) && pdgCharge != 0.0) {
TParticlePDG const* pdgParticle = nullptr;
if (!isParticleSelected(particle, particleSelection, jetTypeParticleLevel, pdgDatabase, pdgParticle)) {
continue;
}
if constexpr (jetcandidateutilities::isMcCandidate<U>() && !jetv0utilities::isV0McCandidate<U>()) {
Expand Down
27 changes: 19 additions & 8 deletions PWGJE/TableProducer/jetGnnInference.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct JetGnnInferenceTask {
Configurable<float> leadingConstituentPtMin{"leadingConstituentPtMin", -99.0, "minimum pT selection on jet constituent"};
Configurable<float> leadingConstituentPtMax{"leadingConstituentPtMax", 9999.0, "maximum pT selection on jet constituent"};
Configurable<float> jetAreaFractionMin{"jetAreaFractionMin", -99.0, "used to make a cut on the jet areas"};
Configurable<uint32_t> nTracksMin{"nTracksMin", 2, "minimum number of tracks for GNN evaluation"};

// ML configuration
Configurable<int> nJetConst{"nJetConst", 100, "maximum number of jet constituents to be used for ML evaluation"};
Expand All @@ -107,7 +108,6 @@ struct JetGnnInferenceTask {
Configurable<bool> loadModelsFromCCDB{"loadModelsFromCCDB", false, "Flag to enable or disable the loading of models from CCDB"};

// GNN configuration
Configurable<float> jetpTMin{"jetpTMin", 5., "minimum jet pT for QA histograms"};
Configurable<float> dbMin{"dbMin", -15., "minimum GNN Db"};
Configurable<float> dbMax{"dbMax", 15., "maximum GNN Db"};
Configurable<double> fC{"fC", 0.018, "Parameter f_c for D_b calculation"};
Expand Down Expand Up @@ -196,7 +196,7 @@ struct JetGnnInferenceTask {
template <typename Jet>
void fillHistograms(Jet const& jet, float db, std::vector<float> const* trackScores = nullptr)
{
if (jet.pt() < jetpTMin) {
if (jet.pt() < jetPtMin) {
return;
}
float dbRange;
Expand Down Expand Up @@ -334,17 +334,28 @@ struct JetGnnInferenceTask {
}

template <typename Jet, typename Tracks>
float evaluateJet(Jet const& jet, Tracks const& tracks, std::vector<float>* trackScores = nullptr)
float evaluateJet(Jet const& jet, Tracks const& tracks)
{
return evaluateJetImpl<false>(jet, tracks, nullptr);
}

template <typename Jet, typename Tracks>
float evaluateJet(Jet const& jet, Tracks const& tracks, std::vector<float>& trackScores)
{
return evaluateJetImpl<true>(jet, tracks, &trackScores);
}

template <bool fullInference, typename Jet, typename Tracks>
float evaluateJetImpl(Jet const& jet, Tracks const& tracks, std::vector<float>* trackScores)
{
std::vector<std::vector<float>> trkFeat;
if (trackScores) {
trackScores->clear();
if constexpr (fullInference) {
if constexpr (!std::is_void_v<JetGnnInfTrackTable> && requires { jet.tracksGnnIds(); }) {
// The definition backbone owns track selection and model-node order.
// Do not reapply inference-side cuts or select a different track subset.
auto const gnnTracks = jet.template tracksGnn_as<JetGnnTracksTable>();
trackScores->assign(gnnTracks.size(), invalidGnnScore);
if (gnnTracks.size() <= 1) {
if (gnnTracks.size() < nTracksMin) {
return invalidGnnScore;
}
if (gnnTracks.size() > static_cast<std::size_t>(nJetConst.value)) {
Expand Down Expand Up @@ -380,7 +391,7 @@ struct JetGnnInferenceTask {
tensorAlloc.getGNNInput(jetFeat, trkFeat, feat, gnnInput);

float db;
if (trackScores) {
if constexpr (fullInference) {
// Exported head order: edge_outputs, node_outputs, flav_preds.
// Retrieve jet and track logits in one model evaluation; leave edges unused.
auto const outputs = bMlResponse.getModelOutputs(gnnInput, 0);
Expand Down Expand Up @@ -447,7 +458,7 @@ struct JetGnnInferenceTask {
}
float db = invalidGnnScore;
if (acceptedCollision) {
db = evaluateJet(jet, tracks, &trackScores);
db = evaluateJet(jet, tracks, trackScores);
} else {
// A different definition-side selection may have left backbone rows.
// Keep one invalid prediction per row instead of breaking the join.
Expand Down
Loading
Loading