Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and lgray committed Jun 4, 2023
1 parent 4fefeb5 commit 9967630
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/coffea/nanoevents/methods/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,13 @@ class LorentzVectorM(ThreeVector):
(+, -, -, -) metric
This mixin class requires the parent class to provide items `x`, `y`, `z`, and `mass`.
"""

@property
def t(self):
"""Equivalent to `energy`"""
return numpy.sqrt(self.mass*self.mass+self.x*self.x+self.y*self.y+self.z*self.z)
return numpy.sqrt(
self.mass * self.mass + self.x * self.x + self.y * self.y + self.z * self.z
)

@property
def energy(self):
Expand Down Expand Up @@ -995,6 +998,7 @@ def nearest(
return out, metric
return out


@awkward.mixin_class(behavior)
class PtEtaPhiMLorentzVector(LorentzVector, SphericalThreeVector):
"""A Lorentz vector using pseudorapidity and mass
Expand Down
18 changes: 10 additions & 8 deletions src/coffea/nanoevents/schemas/edm4hep.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EDM4HEPSchema(BaseSchema):

# originally this was just _momentum_fields = {"energy", "momentum.x", "momentum.y", "momentum.z"}
_momentum_fields_e = {"energy", "momentum.x", "momentum.y", "momentum.z"}
_momentum_fields_m = {"mass", "momentum.x", "momentum.y", "momentum.z"}
_momentum_fields_m = {"mass", "momentum.x", "momentum.y", "momentum.z"}

def __init__(self, base_form, *args, **kwargs):
super().__init__(base_form, *args, **kwargs)
Expand All @@ -66,7 +66,7 @@ def _build_collections(self, branch_forms):
"Tracks": "LorentzVector"
}
for objname in composite_objects:
if objname != "PandoraPFOs" and objname != "MCParticlesSkimmed":
if objname != "PandoraPFOs" and objname != "MCParticlesSkimmed":
continue
# grab the * from "objname/objname.*"
components = {
Expand All @@ -75,7 +75,7 @@ def _build_collections(self, branch_forms):
if k.startswith(objname + "/")
}

print(components)
print(components)

if all(comp in components for comp in self._momentum_fields_e):
form = zip_forms(
Expand All @@ -85,24 +85,24 @@ def _build_collections(self, branch_forms):
"z": branch_forms.pop(f"{objname}/{objname}.momentum.z"),
"t": branch_forms.pop(f"{objname}/{objname}.energy"),
"charge": branch_forms.pop(f"{objname}/{objname}.charge"),
"pdgId": branch_forms.pop(f"{objname}/{objname}.type"),
"pdgId": branch_forms.pop(f"{objname}/{objname}.type"),
},
objname,
composite_behavior.get(objname, "LorentzVector"),
)
branch_forms[objname] = form
elif all(comp in components for comp in self._momentum_fields_m):
elif all(comp in components for comp in self._momentum_fields_m):
form = zip_forms(
{
"x": branch_forms.pop(f"{objname}/{objname}.momentum.x"),
"y": branch_forms.pop(f"{objname}/{objname}.momentum.y"),
"z": branch_forms.pop(f"{objname}/{objname}.momentum.z"),
"mass": branch_forms.pop(f"{objname}/{objname}.mass"),
"mass": branch_forms.pop(f"{objname}/{objname}.mass"),
"charge": branch_forms.pop(f"{objname}/{objname}.charge"),
"pdgId": branch_forms.pop(f"{objname}/{objname}.PDG"),
},
objname,
composite_behavior.get(objname, "LorentzVectorM"),
composite_behavior.get(objname, "LorentzVectorM"),
)
branch_forms[objname] = form
elif components == {
Expand All @@ -125,7 +125,9 @@ def _build_collections(self, branch_forms):
f"Unrecognized class with split branches: {components}"
)
# Generating collection from branch name
collections = [k for k in branch_forms if k == "PandoraPFOs" or k == "MCParticlesSkimmed"] # added second case
collections = [
k for k in branch_forms if k == "PandoraPFOs" or k == "MCParticlesSkimmed"
] # added second case
collections = {
"_".join(k.split("_")[:-1])
for k in collections
Expand Down

0 comments on commit 9967630

Please sign in to comment.