Skip to content

Commit

Permalink
Merge pull request #458 from diana-hep/scikit-hep-packages
Browse files Browse the repository at this point in the history
Replace scikit-hep by vector pkg
  • Loading branch information
Sinclert authored Jun 17, 2021
2 parents d2358bd + 2f5d150 commit 8494307
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 29 deletions.
7 changes: 3 additions & 4 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ channels:
- defaults
dependencies:
- python=3.6.*
- h5py
- matplotlib>=2.0.0
- numpy>=1.13.0
- h5py
- scipy>=1.0.0
- scikit-learn>=0.19.0
- pytorch>=1.0.0
- pytest
- pip
- pip:
- uproot
- scikit-hep>=0.5.0, <0.6.0
- uproot3>=3.14.1
- vector>=0.8.0
10 changes: 8 additions & 2 deletions madminer/__info__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
__authors__ = ", ".join(["Johann Brehmer", "Felix Kling", "Irina Espejo", "Sinclert Perez", "Kyle Cranmer"])
__authors__ = ", ".join([
"Johann Brehmer",
"Felix Kling",
"Irina Espejo",
"Sinclert Perez",
"Kyle Cranmer",
])

__version__ = "0.8.0"
__version__ = "0.8.1"
20 changes: 10 additions & 10 deletions madminer/utils/interfaces/delphes_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_objects(ievent):
"met": met_all_events[ievent][0],
"visible": visible_momentum,
"all": all_momentum,
"boost_to_com": lambda momentum: momentum.boost(all_momentum.boost_vector()),
"boost_to_com": lambda momentum: momentum.boost(all_momentum.to_Vector3D()),
}
)

Expand Down Expand Up @@ -269,7 +269,7 @@ def _get_particles_truth(tree, pt_min, eta_max, included_pdgids=None):
continue

particle = MadMinerParticle()
particle.setptetaphie(pt, eta, phi, e)
particle.from_rhophietat(pt, phi, eta, e)
particle.set_pdgid(pdgid)
event_particles.append(particle)

Expand Down Expand Up @@ -299,7 +299,7 @@ def _get_particles_charged(tree, name, mass, pdgid_positive_charge, pt_min, eta_
pdgid = pdgid_positive_charge if charge >= 0.0 else -pdgid_positive_charge

particle = MadMinerParticle()
particle.setptetaphim(pt, eta, phi, mass)
particle.from_rhophietatau(pt, phi, eta, mass)
particle.set_pdgid(pdgid)
event_particles.append(particle)

Expand Down Expand Up @@ -363,7 +363,7 @@ def _get_particles_leptons(tree, pt_min_e, eta_max_e, pt_min_mu, eta_max_mu):
continue

particle = MadMinerParticle()
particle.setptetaphim(pt, eta, phi, mass)
particle.from_rhophietatau(pt, phi, eta, mass)
particle.set_pdgid(pdgid)
event_particles.append(particle)

Expand Down Expand Up @@ -398,7 +398,7 @@ def _get_particles_truth_leptons(tree, pt_min_e, eta_max_e, pt_min_mu, eta_max_m
continue

particle = MadMinerParticle()
particle.setptetaphie(pt, eta, phi, e)
particle.from_rhophietat(pt, phi, eta, e)
particle.set_pdgid(pdgid)
event_particles.append(particle)

Expand Down Expand Up @@ -426,7 +426,7 @@ def _get_particles_photons(tree, pt_min, eta_max):
continue

particle = MadMinerParticle()
particle.setptetaphie(pt, eta, phi, e)
particle.from_rhophietat(pt, phi, eta, e)
particle.set_pdgid(22)
event_particles.append(particle)

Expand Down Expand Up @@ -466,7 +466,7 @@ def _get_particles_jets(tree, pt_min, eta_max):
continue

particle = MadMinerParticle()
particle.setptetaphim(pt, eta, phi, mass)
particle.from_rhophietatau(pt, phi, eta, mass)
particle.set_pdgid(9)
particle.set_tags(tau_tag >= 1, b_tag >= 1, False)
event_particles.append(particle)
Expand Down Expand Up @@ -507,7 +507,7 @@ def _get_particles_truth_jets(tree, pt_min, eta_max):
continue

particle = MadMinerParticle()
particle.setptetaphim(pt, eta, phi, mass)
particle.from_rhophietatau(pt, phi, eta, mass)
particle.set_pdgid(9)
particle.set_tags(tau_tag >= 1, b_tag >= 1, False)
event_particles.append(particle)
Expand All @@ -528,7 +528,7 @@ def _get_particles_truth_met(tree):

for met, phi in zip(mets[ievent], phis[ievent]):
particle = MadMinerParticle()
particle.setptetaphim(met, 0.0, phi, 0.0)
particle.from_rhophietatau(met, phi, 0.0, 0.0)
particle.set_pdgid(0)
event_particles.append(particle)

Expand All @@ -548,7 +548,7 @@ def _get_particles_met(tree):

for met, phi in zip(mets[ievent], phis[ievent]):
particle = MadMinerParticle()
particle.setptetaphim(met, 0.0, phi, 0.0)
particle.from_rhophietatau(met, phi, 0.0, 0.0)
particle.set_pdgid(0)
event_particles.append(particle)

Expand Down
18 changes: 9 additions & 9 deletions madminer/utils/interfaces/lhe.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def _parse_xml_event(event, sampling_benchmark):
e = float(elements[9])
spin = float(elements[12])
particle = MadMinerParticle()
particle.setpxpypze(px, py, pz, e)
particle.from_xyzt(px, py, pz, e)
particle.set_pdgid(pdgid)
particle.set_spin(spin)
particles.append(particle)
Expand Down Expand Up @@ -854,7 +854,7 @@ def _parse_txt_events(filename, sampling_benchmark):
e = float(elements[9])
spin = float(elements[12])
particle = MadMinerParticle()
particle.setpxpypze(px, py, pz, e)
particle.from_xyzt(px, py, pz, e)
particle.set_pdgid(pdgid)
particle.set_spin(spin)
particles.append(particle)
Expand Down Expand Up @@ -945,7 +945,7 @@ def _get_objects(particles, particles_truth, met_resolution=None, global_event_d
# Sum over all particles
ht = 0.0
visible_sum = MadMinerParticle()
visible_sum.setpxpypze(0.0, 0.0, 0.0, 0.0)
visible_sum.from_xyzt(0.0, 0.0, 0.0, 0.0)

for particle in particles:
pdgid = abs(particle.pdgid)
Expand All @@ -963,10 +963,10 @@ def _get_objects(particles, particles_truth, met_resolution=None, global_event_d
noise_y = 0.0

# MET
met_x = -visible_sum.px + noise_x
met_y = -visible_sum.py + noise_y
met_x = -visible_sum.x + noise_x
met_y = -visible_sum.y + noise_y
met = MadMinerParticle()
met.setpxpypze(met_x, met_y, 0.0, (met_x ** 2 + met_y ** 2) ** 0.5)
met.from_xyzt(met_x, met_y, 0.0, (met_x ** 2 + met_y ** 2) ** 0.5)

# Build objects
objects = math_commands()
Expand Down Expand Up @@ -1059,19 +1059,19 @@ def _smear_particles(particles, energy_resolutions, pt_resolutions, eta_resoluti

if None in energy_resolutions[pdgid]:
# Calculate E from on-shell conditions
smeared_particle.setptetaphim(pt, eta, phi, particle.m)
smeared_particle.from_rhophietatau(pt, phi, eta, particle.m)

elif None in pt_resolutions[pdgid]:
# Calculate pT from on-shell conditions
if e > m:
pt = (e ** 2 - m ** 2) ** 0.5 / np.cosh(eta)
else:
pt = 0.0
smeared_particle.setptetaphie(pt, eta, phi, e)
smeared_particle.from_rhophietat(pt, phi, eta, e)

else:
# Everything smeared manually
smeared_particle.setptetaphie(pt, eta, phi, e)
smeared_particle.from_rhophietat(pt, phi, eta, e)

# PDG id (also sets charge)
smeared_particle.set_pdgid(pdgid)
Expand Down
10 changes: 7 additions & 3 deletions madminer/utils/particle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
from skhep.math.vectors import LorentzVector
import vector

logger = logging.getLogger(__name__)


class MadMinerParticle(LorentzVector):
class MadMinerParticle(vector.VectorObject4D):
""" """

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -50,6 +50,7 @@ def set_spin(self, spin):
self.spin = spin

def __iadd__(self, other):
assert isinstance(other, self.__class__)
super(MadMinerParticle, self).__iadd__(other)
self.charge = None if self.charge is None or other.charge is None else self.charge + other.charge
self.pdgid = None
Expand All @@ -60,6 +61,7 @@ def __iadd__(self, other):
return self

def __isub__(self, other):
assert isinstance(other, self.__class__)
super(MadMinerParticle, self).__isub__(other)
self.charge = None if self.charge is None or other.charge is None else self.charge - other.charge
self.pdgid = None
Expand All @@ -73,6 +75,7 @@ def __isub__(self, other):
return self

def __add__(self, other):
assert isinstance(other, self.__class__)
vec = super(MadMinerParticle, self).__add__(other)
vec.charge = None if self.charge is None or other.charge is None else self.charge + other.charge
vec.pdgid = None
Expand All @@ -83,6 +86,7 @@ def __add__(self, other):
return vec

def __sub__(self, other):
assert isinstance(other, self.__class__)
vec = super(MadMinerParticle, self).__sub__(other)
vec.charge = None if self.charge is None or other.charge is None else self.charge - other.charge
vec.pdgid = None
Expand All @@ -95,7 +99,7 @@ def __sub__(self, other):
def boost(self, *args):
vec = super(MadMinerParticle, self).boost(*args)

particle = MadMinerParticle().from4vector(vec)
particle = MadMinerParticle().from_xyzt(vec.x, vec.y, vec.z, vec.t)
particle.charge = self.charge
particle.spin = self.spin
particle.pdgid = self.pdgid
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"matplotlib>=2.0.0",
"numpy>=1.13.0",
"scipy>=1.0.0",
"scikit-hep>=0.5.0, <0.6.0",
"torch>=1.0.0",
"uproot3>=3.14.1",
"vector>=0.8.0",
]

EXTRAS_DOCS = [
Expand Down

0 comments on commit 8494307

Please sign in to comment.