/cms:vector-awkwardfrom cms
Computes four-vector kinematics on Awkward arrays from CMS NanoAOD using the scikit-hep vector library: invariant masses, deltaR, deltaPhi, transverse mass with MET, boosts, and nearest-object matching.
Ships in cms. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
vector gives Awkward records physics behaviour: .mass, .deltaR(), +,
boosts. You tag a record with a vector type name and use standard field
names, so no hand-written kinematics are needed. CMS NanoAOD provides
pt/eta/phi/mass per object (Muon_*, Jet_*, Electron_*) and
MET_pt/MET_phi per event, all in GeV.
vector also works without Awkward, through NumPy (vector.array) and single
objects (vector.obj). Awkward is just the natural backend for jagged event
data.
| Type name | Use for | Field names it understands |
|---|---|---|
Momentum4D | Particles (mass, boosts, sums) | pt, eta, phi, mass / px, py, pz, E (also energy, M) |
Momentum3D | Directions (deltaR) without mass | pt, eta, phi / px, py, pz |
Momentum2D | MET, transverse quantities | pt, phi / px, py |
Vector4D | Generic (non-momentum) 4-vectors | x, y, z, t (not px…E and no .pt) |
Extra fields (e.g. charge, btag) ride along on the record and survive
selections. They are dropped by arithmetic (a + b).
import awkward as ak, numpy as np, vector
vector.register_awkward() # once per session, before using vector methods
mu = ak.zip({"pt": arr.Muon_pt, "eta": arr.Muon_eta, "phi": arr.Muon_phi,
"mass": arr.Muon_mass, "charge": arr.Muon_charge}, with_name="Momentum4D")
jet = ak.zip({"pt": arr.Jet_pt, "eta": arr.Jet_eta, "phi": arr.Jet_phi,
"mass": arr.Jet_mass}, with_name="Momentum4D")
met = ak.zip({"pt": arr.MET_pt, "phi": arr.MET_phi}, with_name="Momentum2D") # one per event
Reading NanoAOD with uproot (including the XRootD backend) is covered by the
awkward-array skill.
p = ak.combinations(mu, 2, fields=["a", "b"])
p = p[p.a.charge != p.b.charge] # charge still available here
z = p.a + p.b # Momentum4D; .mass .pt .rapidity
mll = ak.flatten(z.mass, axis=1) # ~91 GeV peak on DY
dr, dphi = p.a.deltaR(p.b), p.a.deltaphi(p.b)
mj = ak.cartesian({"m": mu, "j": jet}, axis=1, nested=True) # per muon: all jets
dr = mj.m.deltaR(mj.j) # events * muons * jets
i = ak.argmin(dr, axis=2, keepdims=True)
nearest_jet, nearest_dr = ak.firsts(mj.j[i], axis=2), ak.firsts(dr[i], axis=2)
lead = ak.firsts(mu) # None if no muon
mt = np.sqrt(2 * lead.pt * met.pt * (1 - np.cos(lead.deltaphi(met))))
Momentum4D.deltaphi(Momentum2D) works directly. met.px and met.py are
available, but met.eta is not (it's 2D).
jets_p4 = ak.sum(jet, axis=1) # per-event vector sum of all jets (Momentum4D)
ht = ak.sum(jet.pt, axis=1) # scalar HT
a_rf = p.a.boostCM_of_p4(z) # muon in the Z rest frame
More recipes and the NumPy/object backends: references/recipes.md.
Vector4D with px/py/pz/E has no .pt: it raises AttributeError: no field named 'pt'. Use Momentum4D for momentum-named fields.Pt or Muon_pt give ValueError: array does not have azimuthal coordinates (x/px, y/py or rho/pt, phi). Rename in
ak.zip (NanoAOD branches → pt/eta/phi/mass).(a + b).fields is
['rho', 'phi', 'eta', 'tau'] and ak.sum(jets, axis=1) gives
['t', 'z', 'x', 'y'], with charge gone in both. Use the properties
(.pt, .mass), not ["pt"], and keep metadata from the inputs (p.a.charge).vector.register_awkward() before ak.zip. Records zipped
before registering stay plain even after you register:
AttributeError: no field named 'deltaR'. Re-zip them. Before
registration, a .mass you see is just the raw field.*_mass for muons, electrons and jets.
Momentum3D has no mass, so sums of Momentum3D cannot give invariant
masses. Zip mass in and use Momentum4D.ak.cartesian(..., nested=True) adds a level, so reduce
with axis=2 (or -1). ak.firsts(..., axis=2) removes the keepdims
level.vector.obj backends, and coordinate
conversions.vector-awkward skill
(BSD 3-Clause; see plugins/cms/VENDORED-LICENSES.md):
https://github.com/iris-hep/marketplace/tree/main/iris-hep/skills/vector-awkwardWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
10 skills in this plugin
/analysis-spec-builderUse when a user wants to plan, scope or write down a CMS physics analysis or plotting task before coding it: creating or updating an analysis specification, turning a quick request ("plot the dimuon mass in 2016 data vs DY", "find the best trijet in ttbar") into a structured document, listing datasets, triggers, selections, histograms, corrections and statistical treatment, or producing a specification.md for later implementation./awkward-arrayUse when working with jagged or variable-length arrays in Python with Awkward Array 2 (import awkward as ak): reading CMS NanoAOD or other ROOT ntuples into arrays with uproot, building per-object records with ak.zip, selecting objects or events with masks, counting with ak.num or ak.count, pairing objects with ak.combinations or ak.cartesian (dilepton masses, deltaR, jet cleaning), taking the leading object or argmax per event, following NanoAOD index branches such as Jet_muonIdx1, flattening for histograms, writing Parquet or JSON, or debugging awkward errors such as "cannot slice", "index out of range" or None values appearing in results./cmsswUse when setting up or working inside a CMSSW release area (cmsrel, cmsenv, scram), choosing a CMSSW release or SCRAM_ARCH for a dataset, running an old release inside a cmssw-el7/el8 container, checking out or patching CMSSW packages with git cms-addpkg or git cms-merge-topic, writing or building an EDAnalyzer, EDProducer or EDFilter, writing or debugging a cmsRun Python configuration (_cfg.py, _cfi.py, _cff.py), inspecting EDM ROOT files (MiniAOD, AOD, RECO) with edm* tools, or installing extra Python packages on top of a CMSSW release./combineUse when working with CMS Combine (HiggsAnalysis-CombinedLimit): writing or debugging a datacard or physics model, choosing or running a Combine method (AsymptoticLimits, FitDiagnostics, MultiDimFit, HybridNew, Significance, GoodnessOfFit, ChannelCompatibilityCheck, Impacts), interpreting Combine output, explaining a Combine error message or warning, asking how or why Combine does something, or running a Combine command (combine, text2workspace.py, combineCards.py, combineTool.py) to reproduce, diagnose or confirm a result./hepdataUse when preparing, writing, validating or reviewing a HEPData record for a CMS paper, PAS, or an Open Data study: converting spectra, efficiencies, cutflows, fit results, limits or hist/ROOT histograms into HEPData YAML with hepdata_lib, filling keywords, qualifiers and asymmetric uncertainties, running hepdata-validate, uploading to the HEPData sandbox, following the CMS (EXO, B2G) HEPData and reinterpretation requirements, or debugging errors such as "Got unexpected extra argument", "takes 2 positional arguments", "The tar ball is not valid", "Inconsistent length of 'values' list" or .nan values in the YAML./histUse when creating, filling, slicing, rebinning, normalising or plotting histograms in Python with scikit-hep hist / boost-histogram and mplhep, especially from CMS NanoAOD arrays: choosing axes and binning for GeV quantities, weighted fills with genWeight (including negative weights), normalising MC to cross section times luminosity, categorical axes for regions, processes or systematics, UHI indexing, CMS-style plots with hep.cms.label, ratio panels, or errors such as "has no attribute 'Weight'", "Select 'histtype' from" or "cannot convert to RegularArray" when filling.npx claudepluginhub cms-ml/marketplace --plugin cmsOther plugins' skills for the same job