/cms:muon-tag-and-probefrom cms
Measures muon ID, isolation, and trigger efficiencies and data/MC scale factors from Z→μμ tag and probe in CMS NanoAOD. Handles fitting pass/fail m_μμ spectra, matching to trigger objects, and comparing with Muon POG correctionlib JSON.
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; scripts run unread.
Select Z → μμ events with one well-identified, trigger-matched muon (the tag). The other muon (the probe) is an unbiased sample of real muons for the step you measure. The efficiency is the fraction of probes that pass, after the background under the Z peak is removed by a fit. Measure it in data and in DY MC with the same code, in the POG |η| × pT bins (GeV). The scale factor SF = ε_data / ε_MC is what analyses apply to MC.
The Muon POG publishes official SFs as correctionlib JSON on cvmfs. When the task is to measure scale factors (your own selection, Open Data, a calibration task), the measurement is the answer: compare with the POG as a sanity check on real CMS data, but never report POG values in place of a measurement. In simulated or modified-detector samples the true SFs are not the POG ones.
scripts/tnp.py does the whole chain (pairs, pass/fail fit,
MC counting, SF, comparison with the POG JSON, fit plots) for three working
points: tightid, tightiso, isomu24.
muon_Z.json.gz)trigger-efficiency skill. Not for J/ψ (low pT) or tracking
efficiencies (the method is the same, the probes and fits differ)| Term | Meaning |
|---|---|
| Tag | Tight ID, PF iso < 0.15, pT above the trigger plateau (29 GeV for IsoMu24), matched to the trigger object |
| Probe | Opposite-charge muon passing the denominator of the step; m(tag, probe) in 70–115 GeV |
| Pass / fail | Probes passing / failing the numerator |
| Both as tags | Every pair is used twice (each muon as tag once), so a probe that is also a good tag is not lost |
| Data ε | Simultaneous pass/fail fit: signal shape from MC per category, exponential background, common N_sig and ε |
| MC ε | Counting generator-matched probes (Muon_genPartFlav == 1), weights sign(genWeight) × pileup |
| POG name | NUM_<numerator>_DEN_<denominator>; SFs factorise as ID × ISO × HLT, each on the previous step |
The denominators follow the POG chain:
| Step | Denominator (probe) | Numerator | POG correction (Run 2 UL) |
|---|---|---|---|
tightid | Muon_isTracker | Muon_tightId | NUM_TightID_DEN_TrackerMuons |
tightiso | tight ID, |dxy| < 0.2, |dz| < 0.5 cm | Muon_pfRelIso04_all < 0.15 | NUM_TightRelIso_DEN_TightIDandIPCut |
isomu24 | tight ID and tight iso | matched to a bit-2 (Iso) object | NUM_IsoMu24_or_IsoTkMu24_DEN_CutBasedIdTight_and_PFIsoTight |
source /cvmfs/sft.cern.ch/lcg/views/LCG_109/x86_64-el9-gcc15-opt/setup.sh # correctionlib 2.6.4
ls /cvmfs/cms.cern.ch/rsync/cms-nanoAOD/jsonpog-integration/POG/MUO/2016postVFP_UL/
# muon_HighPt.json.gz muon_JPsi.json.gz muon_Z.json.gz
python3 -c 'import correctionlib, sys; print(*correctionlib.CorrectionSet.from_file(sys.argv[1]), sep="\n")' \
/cvmfs/cms.cern.ch/rsync/cms-nanoAOD/jsonpog-integration/POG/MUO/2016postVFP_UL/muon_Z.json.gz
# NUM_GlobalMuons_DEN_genTracks ... NUM_TightID_DEN_TrackerMuons ... (29 corrections)
(correction summary <file> fails on this file in the LCG_109 view with a
pydantic Input should be a valid number [type=float_type ...] error; the
Python listing works.)
import correctionlib
cs = correctionlib.CorrectionSet.from_file(".../POG/MUO/2016postVFP_UL/muon_Z.json.gz")
sf = cs["NUM_TightID_DEN_TrackerMuons"]
sf.evaluate(-1.5, 35.0, "nominal") # eta (abs taken inside), pt [GeV], variation -> 0.9905
sf.evaluate(-1.5, 35.0, "systup") # stat+syst up boundary -> 0.9944
# SFs: nominal, systup, systdown. Uncertainties (not SFs): stat, syst, AltSig, massBin,
# massRange, tagIso; systup - nominal = hypot(stat, syst). The IsoMu24 correction has no
# tagIso ("Index not available in Category ... tagIso").
Pick the era directory that matches the data: 2016preVFP_UL (B–F early) or
2016postVFP_UL (F late, G, H), 2017_UL, 2018_UL, 2022_Summer22, ....
The pT edges start at 15 GeV (ID, iso) or 26 GeV (IsoMu24); clamp pT into
range before evaluating. Arrays work: sf.evaluate(abs_eta_np, pt_np, "nominal").
S=root://eospublic.cern.ch//eos/opendata/cms
python3 <skill>/scripts/tnp.py \
--data $S/Run2016G/SingleMuon/NANOAOD/UL2016_MiniAODv2_NanoAODv9-v1/70000/<file>.root ... \
--mc $S/mc/RunIISummer20UL16NanoAODv9/ZToMuMu_M-50To120_TuneCP5_13TeV-powheg-pythia8/NANOAODSIM/106X_mcRun2_asymptotic_v17-v1/260000/<file>.root ... \
--wp tightid --era 2016postVFP_UL --out tnp_tightid.json --plots plots/
# |eta| 0.0-0.9 pt 40-50: eff data 0.9630+-0.0010 mc 0.9749+-0.0005 SF 0.9878+-0.0011 POG 0.9867+-0.0031 pull +0.33
# ...
# N_BINS=31 MEAN_PULL=0.92 RMS_PULL=1.19 OUT=tnp_tightid.json
2016 SingleMuon files hold 1.3–3.4 M events (mean 2.3 M); tnp.py needs
about 30 s and 1.3 GB per 1.5 M events (2.5 GB for a 2.9 M-event file). For more than a few files, run the
pair selection on Condor (lpc-condor skill), write a flat pair table, and
fit once at the end. Do not reuse tnp_pairs() for that: it returns one
working point's arrays, applies the HLT requirement itself, and keeps no
run, lumi or HLT columns, so you cannot apply the golden JSON, compute the
luminosity or split by era. Store per pair: run, luminosityBlock, the HLT
flags, m, tag and probe pT/η/ID/iso/IP and the matched trigger-object pT per
filter bit; build every working point and systematic from that table.
fit_pass_fail() can be imported. validation/muon-tnp/condor/skim.py in
the marketplace repository is a tested example.
pair = ak.argcartesian([mu, mu], axis=1) # ordered pairs: each muon is tag once
t, p = mu[pair["0"]], mu[pair["1"]]
good = (pair["0"] != pair["1"]) & is_tag[pair["0"]] & (t.charge * p.charge < 0) & den(p)
m = (t + p).mass # Momentum4D records (vector-awkward skill)
good = good & (m > 70) & (m < 115)
passing = ak.flatten(num(p)[good])
to = events.TrigObj
sel = (to.id == 13) & ((to.filterBits & 2) != 0) & (to.pt >= 24) # Iso bit only, plus threshold
# deltaR(muon, object) < 0.1 with ak.cartesian(..., nested=True), then ak.any(axis=-1)
Read the bit meanings from the branch title of your file:
uproot.open(f)["Events"]["TrigObj_filterBits"].title. In 2016 NanoAODv9,
muon bits are 1 = TrkIsoVVL, 2 = Iso, 4 = OverlapFilter PFTau, 8 = IsoTkMu,
1024 = 1mu (Mu50).
Per bin: ε_data, ε_MC, SF with errors, the POG SF with its systup − nominal
uncertainty, and pull = (SF − SF_POG) / √(σ² + σ_POG²). Over all bins, the
mean and RMS of the pulls. Look at the fit plots of the bins with the largest
pulls and every FIT-NOT-OK bin.
NUM_IsoMu24_or_IsoTkMu24_..., the obvious match (object with bit 2 or 8)
gives an SF 1.0–1.5% above the POG at 30–60 GeV; bit 8 alone is 1.5–4%
below. Matching the probe to a bit-2 (Iso) object, pT ≥ 24 GeV, ΔR < 0.1,
brings |η| 0.9–2.4 within 0.2% of the POG (3.55 fb⁻¹ of 2016G+H). The tag's
match does not matter (≤ 0.0003), and a path-aware match (bit 2 if IsoMu24
fired, bit 8 if IsoTkMu24 fired) equals the OR. tnp.py uses bit 2.HLT_IsoMu24 | HLT_IsoTkMu24 (tnp.py does). With that, probes matched in
events that fired neither path are 5 × 10⁻⁵ of all matched probes, and
dropping or tightening the requirement moves the SF by < 0.001: this is not
the cause of the IsoMu24 offsets above. A higher object threshold (27 GeV)
changes the 26–30 GeV efficiencies a lot but the SF by at most 0.7%.ZToMuMu_M-50To120 powheg sample has
only 2.96 M events (1.8 M pairs), against about 19 M pairs in full G+H data,
so subsample the data or add DYJetsToLL_M-50 (negative weights: use
sign(genWeight)).FIT-NOT-OK), or a valid status
with a useless error (tight iso, |η| 2.1–2.4, pT > 120 GeV: SF error 0.53).
Check the error size, not only the status; merge pT bins or quote the
counting result with a Clopper-Pearson interval
(scipy.stats.beta.ppf([0.16, 0.84], [k, k + 1], [n - k + 1, n - k]))...._DEN_TrackerMuons, and an isolation SF without the IP
cut is not ..._DEN_TightIDandIPCut. A different denominator gives a
different (and not comparable) SF.evaluate(1.0, 10.0, "nominal") fails with
Index below bounds in Binning for input argument 1 value: 10.000000, and
|η| ≥ 2.4 with Index above bounds ... argument 0. Clamp pT to the first
edge (15 or 26 GeV) and select |η| < 2.4 first; pT above the last edge is
fine (overflow bin). η may be signed: the JSON applies abs(x) itself.POG/LUM/<era>/puWeights.json.gz (Collisions16_UltraLegacy_goldenJSON,
input Pileup_nTrueInt).muon_HighPt.json.gz and
the high-pT ID (Muon_highPtId == 2) with TuneP momentum
(Muon_tunepRelPt × Muon_pt); the Z sample runs out of probes there.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
cms, nanoaod, muon-efficiency, scale-factors, tag-and-probe, high-energy-physics
npx claudepluginhub cms-ml/marketplace --plugin cms10 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.Other plugins' skills for the same job