-
Notifications
You must be signed in to change notification settings - Fork 94
test: ATLAS Physlite CI test for RNTuple dev #1411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4e3b5c2
Adding one CI test for RNTuple dev, on ATLAS PHYSLITE DAOD RNTuples
ArturU043 30be54d
use np.isclose to fix assertion faillure in Numpy1 build
ArturU043 8e2253c
style: pre-commit fixes
pre-commit-ci[bot] 330efa5
fixing typo
ArturU043 c194313
style: pre-commit fixes
pre-commit-ci[bot] 964a97f
Merge branch 'main' into main
ArturU043 5f2d38a
change test name to PR 1411
ArturU043 1a0c2f4
style: pre-commit fixes
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import skhep_testdata as skhtd | ||
| import uproot | ||
| import pytest | ||
| import numpy as np | ||
|
|
||
| ak = pytest.importorskip("awkward") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
ariostas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def physlite_file(): | ||
| """Fixture that returns an open EventData tree from the test ROOT file.""" | ||
| file_path = skhtd.data_path("uproot-physlite-rntuple_v1-0-0-0.root") | ||
| with uproot.open(file_path) as f: | ||
| assert "EventData" in f, "'EventData' RNTuple not found in file" | ||
| assert ( | ||
| f["EventData"].classname == "ROOT::RNTuple" | ||
| ), "EventData is not an RNTuple" | ||
| yield f["EventData"] # keeps file open | ||
|
|
||
|
|
||
| def test_analysis_muons_kinematics(physlite_file): | ||
| """Test that kinematic variables of AnalysisMuons can be read and match expected length.""" | ||
| cols = [ | ||
| "AnalysisMuonsAuxDyn:pt", | ||
| "AnalysisMuonsAuxDyn:eta", | ||
| "AnalysisMuonsAuxDyn:phi", | ||
| ] | ||
|
|
||
| # Check if cols are in rntp | ||
| arrays = {} | ||
| for col in cols: | ||
| assert col in physlite_file.keys(), f"Column '{col}' not found" | ||
| arrays[col] = physlite_file[col].array() | ||
|
|
||
| # Check same structure, number of total muons, and values | ||
| n_expected_muons = 88 | ||
| # Expected mean values for pt, eta and phi rounded to 2 decimals | ||
| expected_means = [28217.96, -0.21, -0.18] | ||
| i = 0 | ||
| for col, arr in arrays.items(): | ||
ArturU043 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert isinstance(arr, ak.Array), f"{col} is not an Awkward Array" | ||
| assert ( | ||
| len(ak.flatten(arr)) == n_expected_muons | ||
| ), f"{col} does not match expected muon count" | ||
| assert ( | ||
| round(ak.mean(arr), 2) == expected_means[i] | ||
| ), f"{col} mean value does not match the expected one" | ||
| i += 1 | ||
|
|
||
|
|
||
| def test_event_info(physlite_file): | ||
| """Test that eventInfo variables can be read and match expected first event.""" | ||
| cols = [ | ||
| "EventInfoAuxDyn:eventNumber", | ||
| "EventInfoAuxDyn:averageInteractionsPerCrossing", | ||
| "EventInfoAuxDyn:lumiBlock", | ||
| ] | ||
|
|
||
| first_event = {} | ||
| for col in cols: | ||
| assert col in physlite_file.keys(), f"Column '{col}' not found" | ||
| first_event[col] = physlite_file[col].array()[0] | ||
|
|
||
| # Check first event values | ||
| # expected event info values: Number, pile-up, lumiBlock | ||
| expected_values = [293298001, 26.5, 1] | ||
| i = 0 | ||
| for col, value in first_event.items(): | ||
| assert ( | ||
| value == expected_values[i] | ||
| ), f"First event {col} doest not match the expected value" | ||
| i += 1 | ||
|
|
||
|
|
||
| def test_truth_muon_containers(physlite_file): | ||
| """Test that truth muon variables can be read and match expected values.""" | ||
| cols = [ | ||
| "TruthMuons", # AOD Container | ||
| "TruthMuonsAuxDyn:pdgId", | ||
| "TruthMuonsAuxDyn:m", | ||
| ] | ||
|
|
||
| # Check for columns in the RNTuple | ||
| arrays = {} | ||
| for col in cols: | ||
| assert col in physlite_file.keys(), f"Column '{col}' not found" | ||
| arrays[col] = physlite_file[col].array() | ||
|
|
||
| # Check values | ||
| mass_evt_0 = 105.7 | ||
| AOD_type = [":_0"] # Uproot interpretation of AOD containers | ||
| mu_pdgid = [13, -13] | ||
|
|
||
| assert ( | ||
| arrays["TruthMuons"].fields == AOD_type | ||
| ), f"TruthMuons fields have changed, {arrays['TruthMuons'].fields} instead of {AOD_type}" | ||
| assert np.isclose( | ||
| ak.flatten(arrays["TruthMuonsAuxDyn:m"])[0], mass_evt_0 | ||
| ), "Truth mass of first event does not match expected value" | ||
| assert np.all( | ||
| np.isin(ak.to_numpy(ak.flatten(arrays["TruthMuonsAuxDyn:pdgId"])), mu_pdgid) | ||
| ), "Retrieved pdgids are not 13/-13" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.