Skip to content
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

feat: Add ScoutingNanoAODSchema #1151

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/coffea/nanoevents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
PDUNESchema,
PFNanoAODSchema,
PHYSLITESchema,
ScoutingNanoAODSchema,
TreeMakerSchema,
)

Expand All @@ -22,4 +23,5 @@
"PHYSLITESchema",
"DelphesSchema",
"PDUNESchema",
"ScoutingNanoAODSchema",
]
3 changes: 2 additions & 1 deletion src/coffea/nanoevents/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .base import BaseSchema
from .delphes import DelphesSchema
from .nanoaod import NanoAODSchema, PFNanoAODSchema
from .nanoaod import NanoAODSchema, PFNanoAODSchema, ScoutingNanoAODSchema
from .pdune import PDUNESchema
from .physlite import PHYSLITESchema
from .treemaker import TreeMakerSchema
Expand All @@ -13,4 +13,5 @@
"PHYSLITESchema",
"DelphesSchema",
"PDUNESchema",
"ScoutingNanoAODSchema",
]
23 changes: 23 additions & 0 deletions src/coffea/nanoevents/schemas/nanoaod.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,26 @@ class PFNanoAODSchema(NanoAODSchema):
"JetSVs_sVIdx": "SV",
"SubJet_subGenJetAK8Idx": "SubGenJetAK8",
}


class ScoutingNanoAODSchema(NanoAODSchema):
"""ScoutingNano schema builder

ScoutingNano is a NanoAOD format that includes Scouting objects
"""

mixins = {
**NanoAODSchema.mixins,
"ScoutingJet": "Jet",
"ScoutingFatJet": "FatJet",
"ScoutingMET": "MissingET",
"ScoutingMuonNoVtxDisplacedVertex": "Vertex",
"ScoutingMuonVtxDisplacedVertex": "Vertex",
"ScoutingPrimaryVertex": "Vertex",
"ScoutingElectron": "Electron",
"ScoutingPhoton": "Photon",
"ScoutingMuonNoVtx": "Muon",
"ScoutingMuonVtx": "Muon",
}

all_cross_references = {**NanoAODSchema.all_cross_references}
Binary file added tests/samples/scouting_nano.root
Binary file not shown.
41 changes: 41 additions & 0 deletions tests/test_nanoevents_scoutingnano.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os

import pytest

from coffea.nanoevents import NanoEventsFactory, ScoutingNanoAODSchema


@pytest.fixture(scope="module")
def events(tests_directory):
path = os.path.join(tests_directory, "samples/scouting_nano.root")
ScoutingNanoAODSchema.warn_missing_crossrefs = False
events = NanoEventsFactory.from_root(
{path: "Events"},
schemaclass=ScoutingNanoAODSchema,
delayed=True,
).events()
return events


@pytest.mark.parametrize(
"field",
[
# Jet Sanity check
"ScoutingJet",
# associated PF candidate
"ScoutingJet.pt",
# FatJet sanity check
"ScoutingFatJet",
# Subjet collection (secondary sanity check)
"ScoutingFatJet.pt",
],
)
def test_nested_collections(events, field):
def check_fields_recursive(coll, field):
if "." not in field:
assert hasattr(coll, field)
else:
split = field.split(".")
return check_fields_recursive(getattr(coll, split[0]), ".".join(split[1:]))

check_fields_recursive(events, field)
Loading