Skip to content

Plot the shapes of a datacard bin from where the maker reads them (input_categories) - #31

Merged
kandrosov merged 2 commits into
cms-flaf:mainfrom
kandrosov:shape-plots-input-categories
Oct 19, 2026
Merged

kandrosov merged 2 commits into
cms-flaf:mainfrom
kandrosov:shape-plots-input-categories

Conversation

@kandrosov

@kandrosov kandrosov commented Oct 19, 2026 •

Copy link
Copy Markdown

Summary

Fixes cms-flaf/FLAF#351. CreateDatacardsTask drew its shape plots from each datacard category's own name, while the datacard maker reads a category listed in input_categories from the mapped directory (SR/res2b from SR_SL_M${MX}/res2b). As a result:

  • The HH_bbWW single-lepton cards (CI and production) got no shape plots.
  • The only trace was one no shapes to plot warning per variable, and a _summed_*.root file was left in plots/.
  • If a directory under the configured name also existed, it was plotted instead of the one the cards read.

The plots now look each category up where the maker does. While mapping the multi-era change set C, a second defect turned up: the plotter did not get the task's --user-custom, which FLAF's HistPlotTask does pass. It is fixed here too.

Changes

  • law/StatInferenceTask.py: get_variable_points() returns {variable: [model points]}, and get_required_variables() is its sorted keys (the same list as before).
  • law/CreateDatacardsTask.py:
    • _present_keys(shape_file, cfg, points) resolves each category with InputCategories.path (the maker's rule, dc_make/maker.py histDir).
    • A category that the model points of one variable would read from different directories is not plotted, and a warning says so.
    • HistPlotter's keys name the input directory; the plot files and the grids keep the datacard bin's name.
    • With nothing to plot, the summed file is removed, and the warning gives the reason:
      • the paths it looked up;
      • or that the summed file cannot be read;
      • or that no category is read from one directory.
    • --user-custom is passed to HistPlotter when the task has one.
  • test/test_shape_plots.py (7 tests), added to unit-tests.yaml, the README and the copilot-instructions Tests row.

A configuration without input_categories is unaffected: the lookup paths, keys, file names and grid panels are the same as before.

Known and not changed here:

  • The plotter labels a mapped panel by its input directory (SR_SL_M300), which has no customregion_text entry in the plot config.
  • A card that sets hist_bins and has no preprocess: step (CI_card_SL.yaml) is plotted at the input binning, as unmapped categories already were.

Testing

  • test_law_chain.py (14) and test_shape_plots.py (7): 21 passed. The environment was a Python 3.13 venv holding only pyyaml, numpy, luigi 3.8.1, law 0.1.21 and pytest (env -i), with FLAF 4d9602c next to this branch, as in the unit-tests workflow.
  • Every shape-plot test fails on the unfixed code (checked by the reviewer against origin/main's law/).
  • Each of 10 mutations of the fix makes the suite fail:
    • the keys built from the configured names;
    • the lookup ignoring input_categories;
    • the summed shapes left behind;
    • no --user-custom;
    • the grid panels or the file names taken from the input directory;
    • the first of several directories plotted;
    • every variable resolved at the first mass;
    • a category skipped as ambiguous counted as looked up;
    • an unreadable file reported as "looked up nothing".
  • Real run, with real ROOT/hadd, FLAF HistPlotter.py and pypdf, no mocks:
    • plot_rebinned_shapes ran on the four summed single-lepton shape files from the HH_bbWW integration job 84505422 (Run3_2022 … Run3_2023BPix). Each file holds {e,mu}/SR_SL_M300/{res2b,recovery} and no SR/....
    • The setup was an HH_bbWW tree at f0efc2c with FLAF 4d9602c, and ci_custom.yaml with a local fs_default.
    • TESTER VERDICT: PASS for 281e5c9. In every era: the 4 per-bin PDFs and the 2 grid PDFs (1 page each), HistPlotter keys e:res2b:SR_SL_M300 …, --user-custom passed, no summed file left, and no no shapes to plot or shape plotting failed line.
    • Negative control, today's code 1efded7 on the same inputs: 4 × no shapes to plot, no PDF, and _summed_TwoStageDNN_M300_binary.root left in every era. This is FLAF#351.
    • 513dc63 differs from 281e5c9 only in two test lines, the review's suggestions 1 and 3 of its last round.
  • flaf-reviewer:
    • REVIEWER OK for 0fa40aa + 6b6f36d, after the rebase onto StatInference#30 (the first round's blocker was the test wiring).
    • REVIEWER OK for 5010c4e + 281e5c9: the delta (the exact warning reasons and the hardened unreadable-file test).
    • 513dc63 adds the suggested assertion on the paths looked up for an ambiguous category.
  • Integration pipeline 16086077 (child 16086078): 117/117 jobs passed.
    • The HH_bbWW multi-era job 84507382 builds the single-lepton CI card (CI_card_SL.yaml).
    • Its log has 0 × no shapes to plot (the baseline job 84505422 had 4), 0 × shape plotting failed and 8 × Wrote grid.
    • Its artifact holds the 4 per-bin PDFs and 2 grids per era, and no _summed_*.root (the baseline left 13 MB per era).
  • Datacards and limits are unchanged against job 84505422: all 21 cards and all 5 limit files are byte-identical, and every histogram in the shape files is identical in content.
  • The CI passes no --user-custom (flaf_integration copies its configuration to config/user_custom.yaml), so it exercises only the empty case. The non-empty case is covered by the unit test and the real run above.

No docs change: the analysis and FLAF docs describe neither the datacard shape plots nor input_categories; the plots now appear as the code always intended.

@kandrosov

Copy link
Copy Markdown
Author

@cms-flaf-bot please test

@cms-flaf-bot

Copy link
Copy Markdown

pipeline#16086077 started

@cms-flaf-bot

Copy link
Copy Markdown

pipeline#16086077 passed

@kandrosov
kandrosov merged commit 31b4c6a into cms-flaf:main Oct 19, 2026
5 checks passed
@kandrosov
kandrosov deleted the shape-plots-input-categories branch October 19, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Datacard shape plots ignore input_categories: no plots for the HH_bbWW single-lepton cards (CI and production)

2 participants