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

fix: updates from review #1130

Merged
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
39 changes: 23 additions & 16 deletions src/coffea/nanoevents/methods/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy

from coffea.nanoevents.methods import vector
from coffea.util import register_projection_classes

behavior = dict(vector.behavior)

Expand Down Expand Up @@ -70,23 +71,29 @@ class PtEtaPhiECandidate(Candidate, vector.PtEtaPhiELorentzVector):
pass


awkward.behavior.update(
awkward._util.copy_behaviors(vector.LorentzVector, Candidate, behavior)
)

CandidateArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
CandidateArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
CandidateArray.ProjectionClass4D = vector.LorentzVectorArray # noqa: F821
CandidateArray.MomentumClass = CandidateArray # noqa: F821
behavior.update(awkward._util.copy_behaviors(vector.LorentzVector, Candidate, behavior))

PtEtaPhiMCandidateArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
PtEtaPhiMCandidateArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
PtEtaPhiMCandidateArray.ProjectionClass4D = vector.LorentzVectorArray # noqa: F821
PtEtaPhiMCandidateArray.MomentumClass = PtEtaPhiMCandidateArray # noqa: F821
register_projection_classes(
CandidateArray, # noqa: F821
vector.PolarTwoVectorArray,
vector.SphericalThreeVectorArray,
vector.LorentzVectorArray,
CandidateArray, # noqa: F821
)
register_projection_classes(
PtEtaPhiMCandidateArray, # noqa: F821
vector.PolarTwoVectorArray,
vector.SphericalThreeVectorArray,
vector.LorentzVectorArray,
PtEtaPhiMCandidateArray, # noqa: F821
)
register_projection_classes(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this is my misunderstanding, I hadn't realized each case is somewhat different so the function doesn't in the end save any code duplication. Though at least for many of these the first 3 arguments are the same

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case what you had before was more readable code, is it ok to revert? No need to make separate PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arg, sorry, I thought convo was done, my bad

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to create a separate "revert" PR to fix this. There are some changes in this PR that should go in, like the extra tests and not modifying the global awkward behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to revert the subset of changes directly on the other PR and push, or make a revert PR if you prefer

PtEtaPhiECandidateArray, # noqa: F821
vector.PolarTwoVectorArray,
vector.SphericalThreeVectorArray,
vector.LorentzVectorArray,
PtEtaPhiECandidateArray, # noqa: F821
)

PtEtaPhiECandidateArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
PtEtaPhiECandidateArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
PtEtaPhiECandidateArray.ProjectionClass4D = vector.LorentzVectorArray # noqa: F821
PtEtaPhiECandidateArray.MomentumClass = PtEtaPhiECandidateArray # noqa: F821

__all__ = ["Candidate", "PtEtaPhiMCandidate", "PtEtaPhiECandidate"]
134 changes: 77 additions & 57 deletions src/coffea/nanoevents/methods/delphes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy

from coffea.nanoevents.methods import base, candidate, vector
from coffea.util import register_projection_classes

behavior = {}
behavior.update(base.behavior)
Expand Down Expand Up @@ -130,15 +131,16 @@ def z(self):


_set_repr_name("Vertex")
awkward.behavior.update(
awkward._util.copy_behaviors(vector.LorentzVector, Vertex, behavior)
behavior.update(awkward._util.copy_behaviors(vector.LorentzVector, Vertex, behavior))

register_projection_classes(
VertexArray, # noqa: F821
vector.TwoVectorArray, # noqa: F821
vector.ThreeVectorArray, # noqa: F821
VertexArray, # noqa: F821
vector.LorentzVectorArray, # noqa: F821
)

VertexArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
VertexArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
VertexArray.ProjectionClass4D = VertexArray # noqa: F821
VertexArray.MomentumClass = vector.LorentzVectorArray # noqa: F821


@awkward.mixin_class(behavior)
class Particle(vector.PtEtaPhiMLorentzVector):
Expand Down Expand Up @@ -178,14 +180,17 @@ def mass(self):


_set_repr_name("Particle")
awkward.behavior.update(
behavior.update(
awkward._util.copy_behaviors(vector.PtEtaPhiMLorentzVector, Particle, behavior)
)

ParticleArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
ParticleArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
ParticleArray.ProjectionClass4D = ParticleArray # noqa: F821
ParticleArray.MomentumClass = vector.LorentzVectorArray # noqa: F821
register_projection_classes(
ParticleArray, # noqa: F821
vector.TwoVectorArray, # noqa: F821
vector.ThreeVectorArray, # noqa: F821
ParticleArray, # noqa: F821
vector.LorentzVectorArray, # noqa: F821
)


@awkward.mixin_class(behavior)
Expand All @@ -196,83 +201,95 @@ def mass(self):


_set_repr_name("MasslessParticle")
awkward.behavior.update(
awkward._util.copy_behaviors(Particle, MasslessParticle, behavior)
behavior.update(awkward._util.copy_behaviors(Particle, MasslessParticle, behavior))

register_projection_classes(
MasslessParticleArray, # noqa: F821
vector.TwoVectorArray, # noqa: F821
vector.ThreeVectorArray, # noqa: F821
MasslessParticleArray, # noqa: F821
vector.LorentzVectorArray, # noqa: F821
)

MasslessParticleArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
MasslessParticleArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
MasslessParticleArray.ProjectionClass4D = MasslessParticleArray # noqa: F821
MasslessParticleArray.MomentumClass = vector.LorentzVectorArray # noqa: F821


@awkward.mixin_class(behavior)
class Photon(MasslessParticle, base.NanoCollection): ...


_set_repr_name("Photon")
awkward.behavior.update(
awkward._util.copy_behaviors(MasslessParticle, Photon, behavior)
behavior.update(awkward._util.copy_behaviors(MasslessParticle, Photon, behavior))

register_projection_classes(
PhotonArray, # noqa: F821
vector.TwoVectorArray, # noqa: F821
vector.ThreeVectorArray, # noqa: F821
PhotonArray, # noqa: F821
vector.LorentzVectorArray, # noqa: F821
)

PhotonArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
PhotonArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
PhotonArray.ProjectionClass4D = PhotonArray # noqa: F821
PhotonArray.MomentumClass = vector.LorentzVectorArray # noqa: F821


@awkward.mixin_class(behavior)
class Electron(MasslessParticle, base.NanoCollection): ...


_set_repr_name("Electron")
awkward.behavior.update(
awkward._util.copy_behaviors(MasslessParticle, Electron, behavior)
behavior.update(awkward._util.copy_behaviors(MasslessParticle, Electron, behavior))

register_projection_classes(
ElectronArray, # noqa: F821
vector.TwoVectorArray, # noqa: F821
vector.ThreeVectorArray, # noqa: F821
ElectronArray, # noqa: F821
vector.LorentzVectorArray, # noqa: F821
)

ElectronArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
ElectronArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
ElectronArray.ProjectionClass4D = ElectronArray # noqa: F821
ElectronArray.MomentumClass = vector.LorentzVectorArray # noqa: F821


@awkward.mixin_class(behavior)
class Muon(MasslessParticle, base.NanoCollection): ...


_set_repr_name("Muon")
awkward.behavior.update(awkward._util.copy_behaviors(MasslessParticle, Muon, behavior))

MuonArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
MuonArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
MuonArray.ProjectionClass4D = MuonArray # noqa: F821
MuonArray.MomentumClass = vector.LorentzVectorArray # noqa: F821
behavior.update(awkward._util.copy_behaviors(MasslessParticle, Muon, behavior))

register_projection_classes(
MuonArray, # noqa: F821
vector.TwoVectorArray, # noqa: F821
vector.ThreeVectorArray, # noqa: F821
MuonArray, # noqa: F821
vector.LorentzVectorArray, # noqa: F821
)


@awkward.mixin_class(behavior)
class Jet(Particle, base.NanoCollection): ...


_set_repr_name("Jet")
awkward.behavior.update(awkward._util.copy_behaviors(Particle, Jet, behavior))

JetArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
JetArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
JetArray.ProjectionClass4D = JetArray # noqa: F821
JetArray.MomentumClass = vector.LorentzVectorArray # noqa: F821
behavior.update(awkward._util.copy_behaviors(Particle, Jet, behavior))

register_projection_classes(
JetArray, # noqa: F821
vector.TwoVectorArray, # noqa: F821
vector.ThreeVectorArray, # noqa: F821
JetArray, # noqa: F821
vector.LorentzVectorArray, # noqa: F821
)


@awkward.mixin_class(behavior)
class Track(Particle, base.NanoCollection): ...


_set_repr_name("Track")
awkward.behavior.update(awkward._util.copy_behaviors(Particle, Track, behavior))

TrackArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
TrackArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
TrackArray.ProjectionClass4D = TrackArray # noqa: F821
TrackArray.MomentumClass = vector.LorentzVectorArray # noqa: F821
behavior.update(awkward._util.copy_behaviors(Particle, Track, behavior))

register_projection_classes(
TrackArray, # noqa: F821
vector.TwoVectorArray, # noqa: F821
vector.ThreeVectorArray, # noqa: F821
TrackArray, # noqa: F821
vector.LorentzVectorArray, # noqa: F821
)


@awkward.mixin_class(behavior)
Expand All @@ -283,12 +300,15 @@ def pt(self):


_set_repr_name("Tower")
awkward.behavior.update(awkward._util.copy_behaviors(MasslessParticle, Tower, behavior))

TowerArray.ProjectionClass2D = vector.TwoVectorArray # noqa: F821
TowerArray.ProjectionClass3D = vector.ThreeVectorArray # noqa: F821
TowerArray.ProjectionClass4D = TowerArray # noqa: F821
TowerArray.MomentumClass = vector.LorentzVectorArray # noqa: F821
behavior.update(awkward._util.copy_behaviors(MasslessParticle, Tower, behavior))

register_projection_classes(
TowerArray, # noqa: F821
vector.TwoVectorArray, # noqa: F821
vector.ThreeVectorArray, # noqa: F821
TowerArray, # noqa: F821
vector.LorentzVectorArray, # noqa: F821
)


__all__ = [
Expand Down
Loading
Loading