How to use fastjet-contrib methods in python?
10:48 13 Dec 2025

I'm trying to use EnergyCorrelator and Nsubjettiness packages from fastjet-contrib. My goal is to calculate these features on jets clustered from tower objects read from a .root file, within a PyROOT macro, but i can't find a way to use them in python:

Below is my code:

import fastjet

def to_pseudojets(constits):
    return [fastjet.PseudoJet(
        c.pt * math.cos(c.phi),
        c.pt * math.sin(c.phi),
        c.pt * math.sinh(c.eta),
        c.pt * math.cosh(c.eta)
    ) for c in constits]

def compute_nsubjettiness(constits, R0=1.0, beta=1.0):
    jets = to_pseudojets(constits)

    axis_def = fastjet.contrib.KT_Axes()
    measure_def = fastjet.contrib.UnnormalizedMeasure(beta)

    tau1 = fastjet.contrib.Nsubjettiness(1, axis_def, measure_def)(jets)
    tau2 = fastjet.contrib.Nsubjettiness(2, axis_def, measure_def)(jets)
    tau3 = fastjet.contrib.Nsubjettiness(3, axis_def, measure_def)(jets)

    return tau1, tau2, tau3

def compute_ecfs(constits, beta=1.0):
    jets = to_pseudojets(constits)

    ecf2 = fjcontrib.ECF(2, beta)
    ecf3 = fjcontrib.ECF(3, beta)

    e2 = ecf2(jets)
    e3 = ecf3(jets)

    return e2, e3

def compute_c2_d2(e2, e3):
    c2 = e3 / (e2**2) if e2 > 0 else -1
    d2 = e3 / (e2**3) if e2 > 0 else -1
    return c2, d2

class ConstituentData:
    """A simple class to hold constituent kinematics for fastjet conversion."""
    def __init__(self, pt, eta, phi, m=0.0):
        self.pt = pt
        self.eta = eta
        self.phi = phi
        self.m = m 

I installed fastjet with pip, on Linux machine, and i find the files /.venv/lib/python3.12/site-packages/fastjet/include/fastjet/contrib/Nsubjettiness.hh but have no clue on how to use them in python. Can someone please help me? Very appertained.

python-3.x pyroot