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(wip): edm4hep development #822

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
09bb414
proof of concept edm4hep schema, only does PFOs
lgray May 14, 2023
4fefeb5
Adding changes to edm4hep.py so that MCParticlesSkimmed are taken int…
jbrewster7 May 19, 2023
9967630
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 23, 2023
075ab83
fix typo
lgray May 23, 2023
452daf8
Merge branch 'master' into main_dev
lgray Jun 4, 2023
715679b
Merge branch 'master' into main_dev
lgray Jun 5, 2023
dea81da
Updating the edm4hep schema to include linking between reconstructed …
jbrewster7 Jun 5, 2023
14bafa3
Merge branch 'main_dev' of github.com:jbrewster7/coffea into main_dev
jbrewster7 Jun 5, 2023
7f628ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2023
db9ae5a
Addition of track and cluster imports to edm4hep schema. Tracks impor…
jbrewster7 Jun 5, 2023
b384b2a
Merge branch 'master' into main_dev
lgray Jun 6, 2023
b242f74
Merge branch 'master' into main_dev
lgray Jun 6, 2023
9f6a06e
Merge branch 'main_dev' of github.com:jbrewster7/coffea into main_dev
jbrewster7 Jun 6, 2023
1c80e1e
Merge branch 'main_dev' of github.com:jbrewster7/coffea into main_dev
jbrewster7 Jun 6, 2023
462fbe3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 6, 2023
ffe68c4
Merge branch 'master' into main_dev
lgray Jun 6, 2023
0b1539f
Fixing bug in import of PandoraClusters.
jbrewster7 Jun 6, 2023
f85653b
Adding some documentation to classes and functions.
jbrewster7 Jun 7, 2023
2308baa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 7, 2023
fc33205
Adding changes to tracks to be able to create 4-vectors from tracks.
jbrewster7 Jun 12, 2023
be60458
Merge branch 'main_dev' of github.com:jbrewster7/coffea into main_dev
jbrewster7 Jun 12, 2023
094c100
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 12, 2023
3c38ab0
Merge branch 'master' into main_dev
lgray Jun 12, 2023
1c8d0d1
Adding file edm4hep_index_shaping_test.py in tests to act as a canned…
jbrewster7 Jun 16, 2023
ebe30d1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 16, 2023
539eed9
Adding an alias E() for `t` to the LorentzVector classes to integrate…
jbrewster7 Jun 16, 2023
87987a6
Merge branch 'main_dev' of github.com:jbrewster7/coffea into main_dev
jbrewster7 Jun 16, 2023
31b1d93
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 16, 2023
e30ec4a
Merge branch 'master' into main_dev
lgray Jun 17, 2023
5c2ba79
low level working features of reco -> mc and mc -> reco crossrefs
lgray Jun 17, 2023
1514441
_apply_global_mapping functions (but is a bit ugly/delicate) and is c…
lgray Jun 18, 2023
0ac084d
remove test that relies on files not in repository
lgray Jun 19, 2023
5e6fdb1
Updating edm4hep schema and classes to include linking to gen particl…
jbrewster7 Jun 19, 2023
cd78d5e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 19, 2023
e014d49
Adding linking from gen particles to tracks and clusters.
jbrewster7 Jun 19, 2023
79252f1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 19, 2023
d0b4a4d
Merge branch 'master' into main_dev
lgray Jun 20, 2023
abf0758
Merge branch 'master' into main_dev
lgray Jun 21, 2023
8e0a95d
Merge branch 'master' into main_dev
lgray Jun 22, 2023
c840e34
Merge branch 'master' into main_dev
lgray Jun 23, 2023
f1433bf
Merge branch 'master' into main_dev
lgray Jun 27, 2023
8eed3dc
Merge branch 'master' into main_dev
lgray Jun 27, 2023
ac57498
Merge branch 'master' into main_dev
lgray Jul 13, 2023
2870978
Merge branch 'master' into main_dev
lgray Jul 25, 2023
db65a48
Development of new edm4hep format (removal of magic numbers)
jbrewster7 Aug 1, 2023
d451464
Merge branch 'master' into main_dev
lgray Aug 2, 2023
57bfea3
Importing parents and daughters begin and end arrays.
jbrewster7 Aug 3, 2023
96192cf
make mc particle parents and children work
lgray Aug 18, 2023
4cb2acb
Merge pull request #1 from lgray/edm4hep_schema
jbrewster7 Aug 21, 2023
1cd6588
committing new edm4hep business
jbrewster7 Aug 21, 2023
b7725b7
Merge branch 'main_dev' of github.com:jbrewster7/coffea into main_dev
jbrewster7 Aug 21, 2023
c59bf1b
Merge branch 'newedm4hep' into main_dev
jbrewster7 Aug 21, 2023
390c848
Little fixes (mostly removing old commented-out code)
jbrewster7 Aug 23, 2023
a50c181
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 29, 2023
9f58a88
Merge branch 'master' into main_dev
lgray Aug 30, 2023
87d4225
Fixing f string formatting problem.
jbrewster7 Aug 31, 2023
91f7dc9
Merge branch 'main_dev' of github.com:jbrewster7/coffea into main_dev
jbrewster7 Aug 31, 2023
45d5a38
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 31, 2023
3ed8167
Example notebook for edm4hep & coffea
jbrewster7 Aug 31, 2023
3980198
Merge branch 'main_dev' of github.com:jbrewster7/coffea into main_dev
jbrewster7 Aug 31, 2023
eff2556
Merge branch 'master' into main_dev
lgray Oct 17, 2023
70cab5e
Merge branch 'master' into main_dev
lgray Oct 18, 2023
26dd92e
Merge branch 'master' into main_dev
lgray Oct 20, 2023
1144d3b
Merge branch 'master' into main_dev
lgray Nov 6, 2023
4518a7e
Merge branch 'master' into main_dev
lgray Nov 9, 2023
9506315
interface change
lgray Nov 9, 2023
679633b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2023
f1733dc
Merge branch 'master' into main_dev
lgray Dec 7, 2023
2be5d11
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 7, 2023
a693321
may need to debug typetracing here.
lgray Dec 7, 2023
e68b7f2
Merge branch 'master' into main_dev
lgray Dec 12, 2023
0b23cd1
Merge branch 'master' into main_dev
lgray Dec 13, 2023
d2269aa
Merge branch 'master' into main_dev
lgray Jan 6, 2024
cb4082f
Merge branch 'master' into main_dev
lgray Jan 13, 2024
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
687 changes: 687 additions & 0 deletions docs/source/notebooks/edm4hep.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/coffea/nanoevents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from coffea.nanoevents.schemas import (
BaseSchema,
DelphesSchema,
EDM4HEPSchema,
NanoAODSchema,
PDUNESchema,
PFNanoAODSchema,
Expand All @@ -21,4 +22,5 @@
"PHYSLITESchema",
"DelphesSchema",
"PDUNESchema",
"EDM4HEPSchema",
]
5 changes: 5 additions & 0 deletions src/coffea/nanoevents/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def _remove_not_interpretable(branch):
f"Skipping {branch.name} as it is it cannot be represented as an Awkward array"
)
return False
except uproot.interpretation.identify.UnknownInterpretation:
warnings.warn(
f"Skipping {branch.name} as it is it cannot be interpreted by Uproot"
)
return False
else:
return True

Expand Down
138 changes: 138 additions & 0 deletions src/coffea/nanoevents/methods/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,144 @@ def _content(self):
Used with global indexes to resolve cross-references"""
return self._getlistarray().content

@dask_method
def _apply_global_mapping(
self, actual_from, original_from, from_map, onto_map, _dask_array_=None
):
"""Internal method to take from a collection using a flat mapping
(i.e. two flat indices that need to be sorted and taken from)

This is often necessary to be able to still resolve cross-references on
reduced arrays or single records.
"""

def flat_take(layout):
idx = awkward.Array(layout)
return self._content()[idx.mask[idx >= 0]]

def descend(layout, depth, **kwargs):
if layout.purelist_depth == 1:
return flat_take(layout)

def maybe_meta(array):
return array._meta if isinstance(array, dask_awkward.Array) else array

maybe_actual_from_meta = maybe_meta(actual_from)
maybe_original_from_meta = maybe_meta(original_from)
maybe_from_map_meta = maybe_meta(from_map)
maybe_onto_map_meta = maybe_meta(onto_map)

actual_index = None
actual_offsets = None
if awkward.backend(maybe_from_map_meta) != "typetracer" and isinstance(
maybe_actual_from_meta.layout.content, awkward.contents.IndexedArray
):
actual_offsets = awkward.Array(maybe_actual_from_meta.layout.offsets.data)
actual_index = awkward.Array(
maybe_actual_from_meta.layout.content.index.data
)

sorter = awkward.argsort(maybe_from_map_meta)
sorted_from = (maybe_from_map_meta)[sorter]
sorted_onto = (maybe_onto_map_meta)[sorter]

original_index_local = awkward.local_index(maybe_original_from_meta)
original_offsets = awkward.Array(
awkward.typetracer.length_zero_if_typetracer(
original_index_local
).layout.offsets.data
)
original_index = awkward.flatten(original_index_local + original_offsets[:-1])

sparse_index = awkward.unflatten(
awkward.typetracer.length_zero_if_typetracer(sorted_from),
awkward.flatten(
awkward.run_lengths(
awkward.typetracer.length_zero_if_typetracer(sorted_from)
)
),
axis=1,
)
sparse_index = awkward.flatten(awkward.firsts(sparse_index, axis=-1))
sparse_index_from_zero = awkward.local_index(sparse_index)

original_index = awkward.typetracer.length_zero_if_typetracer(
original_index
).to_numpy()
masked_from_index = numpy.full_like(original_index, -1)
masked_from_index[sparse_index] = sparse_index_from_zero
masked_from_index = awkward.unflatten(
awkward.Array(masked_from_index),
original_offsets[1:] - original_offsets[:-1],
)

index = awkward.unflatten(
awkward.typetracer.length_zero_if_typetracer(sorted_onto),
awkward.flatten(
awkward.run_lengths(
awkward.typetracer.length_zero_if_typetracer(sorted_from)
),
axis=1,
),
axis=1,
)

if actual_index is None:
index = awkward.Array(
awkward.contents.ListOffsetArray(
masked_from_index.layout.offsets,
awkward.contents.IndexedOptionArray(
awkward.index.Index64(awkward.flatten(masked_from_index)),
index.layout.content,
),
),
behavior=index.behavior,
)
else:
index = awkward.Array(
awkward.contents.ListOffsetArray(
awkward.index.Index64(actual_offsets),
awkward.contents.IndexedOptionArray(
awkward.index.Index64(
awkward.flatten(masked_from_index)[actual_index]
),
index.layout.content,
),
),
behavior=index.behavior,
)

if awkward.backend(sorter) == "typetracer":
index = awkward.Array(
index.layout.to_typetracer(forget_length=True), behavior=index.behavior
)

(index_out,) = awkward.broadcast_arrays(
index,
)

layout_out = awkward.transform(descend, index_out.layout, highlevel=False)
out = awkward.Array(layout_out, behavior=self.behavior)
return out

@_apply_global_mapping.dask
def _apply_global_mapping(
self,
dask_array,
actual_from,
original_from,
from_map,
onto_map,
):
return dask_array.map_partitions(
_ClassMethodFn("_apply_global_mapping"),
actual_from,
original_from,
from_map,
onto_map,
label="_apply_global_mapping",
)

@dask_method
def _apply_global_index(self, index):
"""Internal method to take from a collection using a flat index
Expand Down
Loading
Loading