Skip to content

Commit

Permalink
Merge pull request #233 from smash-transport/sparkx_devel
Browse files Browse the repository at this point in the history
Sparkx devel
  • Loading branch information
Hendrik1704 committed May 8, 2024
2 parents 2cc72e1 + 6e3650b commit 9ec4c69
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 72 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ The main categories for changes in this file are:

A `Deprecated` section could be added if needed for soon-to-be removed features.

## v1.2.1-Newton
Date: 2024-05-08

### Fixed
* Jetscape: Fix for Jetscape charged particle filtering

[Link to diff from previous version](https://github.com/smash-transport/sparkx/compare/v1.2.0...v1.2.1)

## v1.2.0-Newton
Date: 2024-04-21

Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The SPARKX Team

Author |  E-Mail  | Copyright ©
:----: | :----: | :---------: |
Niklas Götz | [✉️](mailto:goetz@fias.uni-frankfurt.de) | `2023 -` |
Hendrik Roch | [✉️](mailto:[email protected]) | `2023 -` |
Nils Sass | [✉️](mailto:nsass@fias.uni-frankfurt.de) | `2023 -` |
Niklas Götz | [✉️](mailto:goetz@itp.uni-frankfurt.de) | `2023 -` |
Hendrik Roch | [✉️](mailto:[email protected]) | `2023 -` |
Nils Sass | [✉️](mailto:nsass@itp.uni-frankfurt.de) | `2023 -` |

2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
project = 'sparkx'
copyright = '2024, SPARKX Collaboration'
author = 'Hendrik Roch, Nils Sass, Niklas Götz'
release = '1.2.0'
release = '1.2.1'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ build-backend = "hatchling.build"

[project]
name = "sparkx"
version = "1.2.0"
version = "1.2.1"
authors = [
{ name="Niklas Götz", email="goetz@fias.uni-frankfurt.de"},
{ name="Hendrik Roch", email="[email protected]" },
{ name="Nils Sass", email="nsass@fias.uni-frankfurt.de" }
{ name="Niklas Götz", email="goetz@itp.uni-frankfurt.de"},
{ name="Hendrik Roch", email="[email protected]" },
{ name="Nils Sass", email="nsass@itp.uni-frankfurt.de" }
]
description = "Software Package for Analyzing Relativistic Kinematics in Collision eXperiments"
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"fastjet==3.4.1.3",
"matplotlib>=3.7.1",
],
version='1.2.0',
version='1.2.1',
description='Software Package for Analyzing Relativistic Kinematics in Collision eXperiments',
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
author='Niklas Götz, Hendrik Roch, Nils Sass',
author_email="goetz@fias.uni-frankfurt.de, [email protected], nsass@fias.uni-frankfurt.de",
author_email="goetz@itp.uni-frankfurt.de, [email protected], nsass@itp.uni-frankfurt.de",
url="https://smash-transport.github.io/sparkx/",
download_url="https://github.com/smash-transport/sparkx",
license='MIT',
Expand Down
39 changes: 30 additions & 9 deletions src/sparkx/Particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ class Particle:
def __init__(self,input_format=None,particle_array=None):
self.data_ = np.array(25*[np.nan],dtype=float)
self.pdg_valid = False

if ((input_format is not None) and (particle_array is None)) or ((input_format is None) and (particle_array is not None)):
raise ValueError("'input_format' or 'particle_array' not given")

if (input_format is not None) and (particle_array is not None):
self.__initialize_from_array(input_format,particle_array)


def __initialize_from_array(self,input_format,particle_array):
"""
Initialize instance attributes based on the provided input format and array.
Expand Down Expand Up @@ -368,16 +368,20 @@ def __initialize_from_array(self,input_format,particle_array):
else:
self.data_[index[0]] = int(particle_array[index[1]])

# It is important for JETSCAPE particles to compute pdg_valid
# here because the compute_charge_from_pdg function depends on it.
self.pdg_valid = PDGID(self.pdg).is_valid

if input_format == "JETSCAPE":
self.mass = self.compute_mass_from_energy_momentum()
self.charge = self.compute_charge_from_pdg()
if self.pdg_valid == False and np.isnan(self.charge):
warnings.warn('The PDG code ' + str(int(self.pdg)) + ' is not known by PDGID, charge could not be computed. Consider setting it by hand.')
else:
raise ValueError("The input file is corrupted! " +\
"A line with wrong number of columns "+str(len(particle_array))+" was found.")
else:
raise ValueError(f"Unsupported input format '{input_format}'")

self.pdg_valid = PDGID(self.pdg).is_valid

if(not self.pdg_valid):
warnings.warn('The PDG code ' + str(int(self.pdg)) + ' is not valid. '+
Expand Down Expand Up @@ -434,6 +438,7 @@ def z(self):
z : float
"""
return self.data_[3]

@z.setter
def z(self,value):
self.data_[3] = value
Expand Down Expand Up @@ -761,7 +766,7 @@ def pdg_valid(self):

@pdg_valid.setter
def pdg_valid(self,value):
self.data_[10] = value
self.data_[10] = 1 if value else 0

def print_particle(self):
"""Print the whole particle information as csv string.
Expand Down Expand Up @@ -1114,7 +1119,7 @@ def is_heavy_flavor(self):
return True
else:
return False

def spin(self):
"""
Get the total spin :math:`J` of the particle.
Expand All @@ -1131,7 +1136,7 @@ def spin(self):
if not self.pdg_valid:
return np.nan
return PDGID(self.pdg).J

def spin_degeneracy(self):
"""
Get the number of all possible spin projections (:math:`2J + 1`).
Expand All @@ -1148,4 +1153,20 @@ def spin_degeneracy(self):
if not self.pdg_valid:
return np.nan
return PDGID(self.pdg).j_spin


format1 = "JETSCAPE"
array1 = np.array([1,211,27,4.36557,3.56147,0.562961,2.45727])

p1 = Particle(input_format=format1,particle_array=array1)
assert p1.ID == 1
assert p1.pdg == 211
assert p1.status == 27
assert p1.E == 4.36557
assert p1.px == 3.56147
assert p1.py == 0.562961
assert p1.pz == 2.45727
assert np.isclose(p1.mass, 0.137956238, rtol=1e-6)
assert p1.pdg_valid == True
assert p1.charge == 1

print(p1.compute_charge_from_pdg())
6 changes: 5 additions & 1 deletion tests/test_Jetscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,8 @@ def test_Jetscape_print(jetscape_file_path, output_path):
def test_Jetscape_get_sigmaGen(jetscape_file_path):
jetscape = Jetscape(jetscape_file_path)
assert jetscape.get_sigmaGen() == (0.000314633,6.06164e-07)


def test_Jetscape_charge_filter_one_event(jetscape_file_path):
jetscape = Jetscape(jetscape_file_path, events=0).charged_particles()
assert jetscape.num_events() == 1
assert (jetscape.num_output_per_event() == np.array([[1, 14]])).all()
23 changes: 18 additions & 5 deletions tests/test_Particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,20 @@ def test_status():

def test_initialize_from_array_valid_formats():
format1 = "JETSCAPE"
array1 = np.array([1,211,27,3.0,0.5,1.0,1.5])
array1 = np.array([1,211,27,4.36557,3.56147,0.562961,2.45727])

p1 = Particle(input_format=format1,particle_array=array1)
assert p1.ID == 1
assert p1.pdg == 211
assert p1.status == 27
assert p1.E == 3.0
assert p1.px == 0.5
assert p1.py == 1.0
assert p1.pz == 1.5
assert p1.E == 4.36557
assert p1.px == 3.56147
assert p1.py == 0.562961
assert p1.pz == 2.45727
assert np.isclose(p1.mass, 0.137956238, rtol=1e-6)
assert p1.pdg_valid == True
assert p1.charge == 1


format2 = "Oscar2013"
array2 = np.array([0.0,1.0,2.0,3.0,0.138,4.0,5.0,6.0,7.0,211,100,1])
Expand Down Expand Up @@ -284,6 +288,15 @@ def test_initialize_from_array_valid_formats():
assert p5.pdg_mother2 == 2212
assert p5.weight == 0.75

def test_initialize_from_array_Jetscape_invalid_pdg_warning():
format1 = "JETSCAPE"
array1 = np.array([1,99999999,27,4.36557,3.56147,0.562961,2.45727])

# check that a warning is issued
with pytest.warns(UserWarning, match=r"The PDG code 99999999 is not known by PDGID, charge could not be computed. Consider setting it by hand."):
Particle(input_format=format1,particle_array=array1)


def test_initialize_from_array_invalid_format():
with pytest.raises(ValueError, match=r"Unsupported input format 'InvalidFormat'"):
Particle(input_format="InvalidFormat", particle_array=np.array([1, 2, 3]))
Expand Down
55 changes: 8 additions & 47 deletions tests/test_files/test_jet_finding.csv
Original file line number Diff line number Diff line change
@@ -1,63 +1,35 @@
0,33.49336878176815,-0.5351630556762148,3.885673126776016,10,10,39.219071,0
1,28.69180868627839,-0.548891876164362,3.8881234165058642,27,-521,33.5418,0
2,0.39474684628252577,-0.5125312039695005,3.9155800407211583,27,-211,0.468524,0
3,1.0703653974975087,-0.9140314113512277,3.778770645888928,27,221,1.64355,0
4,0.9546150584062666,-0.25558569378031015,4.07239128043879,27,111,0.995576,0
5,0.25721402741880156,-0.6697025836383824,4.157563752997232,27,111,0.345811,0
6,2.1676407998789835,-0.21835663305558334,3.7867010404432873,27,211,2.22381,0
3,2.1676407998789835,-0.21835663305558334,3.7867010404432873,27,211,2.22381,0
0,27.811205216320992,0.49911586174288225,1.0015291112410842,10,10,31.84106,0
1,26.83926025843484,0.5066307909200954,1.0023102414845264,27,523,30.8206,0
2,0.9721792260277937,0.2819647295235115,0.9799625312437784,27,111,1.02046,0
0,38.905139227373354,-0.1903254131094699,2.4360701843229697,10,10,39.724850999999994,1
1,4.72121902160872,-0.1338109962514527,2.5114147692920117,27,-211,4.76555,1
2,9.268011479346582,-0.15629195172723095,2.3931260510711154,27,211,9.38245,1
3,3.5502187912437173,-0.20764332354627427,2.3890977872631076,27,211,3.62965,1
4,1.2907822629417405,-0.4488139000490507,2.4952359082453186,27,-211,1.42966,1
5,13.787406238625886,-0.19176596729039372,2.448944029296549,27,211,14.0424,1
6,4.41619991423622,-0.23761107050172292,2.4477537262966846,27,-211,4.54355,1
7,0.5742317272774119,-0.064355875066456,2.330108096825775,27,22,0.575421,1
8,1.3303211384692042,-0.1967981921994863,2.4093992539065545,27,22,1.35617,1
0,26.430384916656095,0.2606772277857613,5.953084641411709,10,10,27.803325,1
1,5.233109403070033,0.09137498825664488,5.884151661028977,27,-321,5.27814,1
2,0.9540624860678676,0.2620324602712372,5.950021883105497,27,211,0.996605,1
3,2.101592928471163,0.24400551001153353,5.778509481985555,27,321,2.22012,1
4,3.4242367545629784,0.11205519251803245,5.828625139408159,27,-211,3.44852,1
5,1.2234592349976356,0.23931504501955775,5.795398539817037,27,211,1.2662,1
6,1.350753323367742,0.28510073752133464,6.100883566912945,27,22,1.40602,1
7,8.132458155170552,0.3165618775507524,6.075024498736697,27,22,8.54336,1
8,1.086733572836047,0.420411333943206,5.965634030708567,27,22,1.1842,1
9,3.088571200691511,0.4857435108569696,5.999670757662501,27,22,3.46016,1
0,16.682921317371754,0.018131545432005087,5.118240355889198,10,10,17.271604000000004,1
1,3.0788218466809667,0.04900984656003954,5.158201261726367,27,2112,3.22207,1
2,2.7870198165782747,-0.0005900854722224802,5.173161088239877,27,-2112,2.94063,1
3,1.6593360779784787,-0.25793703359761755,4.9439166183084815,27,311,1.78458,1
4,5.263711490621422,0.07377506152376165,5.098167033757785,27,22,5.27805,1
5,0.5668346655683648,0.27535567909894443,5.00032646130724,27,22,0.588459,1
6,1.2171485906478305,0.2764286098589836,5.163007984320346,27,22,1.26395,1
7,0.5129253569604451,-0.02138959060314676,5.359398599076454,27,22,0.513042,1
8,0.5991983220553943,-0.12902723626783866,5.220917185747329,27,22,0.604193,1
9,1.0553435017874513,-0.2005205001364386,5.0668218736766075,27,22,1.07663,1
0,14.337111638891425,-1.5621916761808663,1.6735434193813699,10,10,35.75758,2
1,10.690159956618984,-1.5446482236328953,1.6792946370959663,27,2112,26.2062,2
2,3.647646647231061,-1.611870684144707,1.6566876173421685,27,-2112,9.55138,2
0,12.37243859396166,1.3068668990283434,4.745113250197566,10,10,24.566383,2
1,0.6585572787461164,0.9925906083962184,4.591550246185365,27,-321,1.12479,2
2,5.053691145103745,1.3218912662314775,4.833766611366548,27,211,10.1516,2
3,3.972887144368137,1.2797145935085552,4.7218323539948175,27,-211,7.69619,2
4,0.07800454861740819,1.0079808356535866,4.737732010274475,27,22,0.121103,2
5,1.50204041129425,1.3420545692884875,4.53034407208192,27,22,3.07033,2
6,0.5726094355904816,1.2605964999751382,4.6178970309737375,27,22,1.09111,2
7,1.253854658091794,1.2833163944224082,4.775732688136079,27,22,2.43605,2
0,41.80758893193016,-0.17640489885844948,3.659935275370665,10,10,42.898163,3
1,2.1030858862395516,-0.39472711314367676,3.6983800151331074,27,-2212,2.4553,3
2,7.37739264252622,-0.16191143000068992,3.6562433423324627,27,-311,7.49061,3
3,0.916709020774313,0.009424835901553867,3.6888565555001542,27,22,0.91675,3
4,0.4434917638074015,0.10644258073214823,3.8772710452008257,27,22,0.446006,3
5,15.065203608544426,-0.15496209269296063,3.6316524754811432,27,321,15.2545,3
6,10.697655580719543,-0.1721830616015073,3.6381532888200345,27,-321,10.8679,3
7,1.9038704410752323,-0.293539208775587,3.752127565601132,27,211,1.99127,3
8,2.621689946675617,-0.12289378068867308,3.8191470850722626,27,-211,2.64512,3
9,0.7484940585395451,-0.43120033868222807,3.515648347603089,27,-211,0.830707,3
2,15.065203608544426,-0.15496209269296063,3.6316524754811432,27,321,15.2545,3
3,10.697655580719543,-0.1721830616015073,3.6381532888200345,27,-321,10.8679,3
4,1.9038704410752323,-0.293539208775587,3.752127565601132,27,211,1.99127,3
5,2.621689946675617,-0.12289378068867308,3.8191470850722626,27,-211,2.64512,3
6,0.7484940585395451,-0.43120033868222807,3.515648347603089,27,-211,0.830707,3
0,36.42717652731888,0.2745215651984534,0.5003884242889252,10,10,38.17007100000001,3
1,3.0053311749788905,0.42925878990364813,0.43399202736866044,27,211,3.2894,3
2,3.644456553177716,0.14942100945082648,0.4830420143426729,27,-211,3.68779,3
Expand All @@ -66,23 +38,12 @@
5,3.04448844655387,0.20367683072151857,0.6005144777120114,27,-211,3.11092,3
6,6.804477542354006,0.2460605289342807,0.5692087191468599,27,211,7.01287,3
7,2.4263779249943735,0.08346670356135504,0.46674223336904513,27,-211,2.43874,3
8,0.7245523434072931,0.23180360557794355,0.5583991811334225,27,22,0.744106,3
9,0.40552566476858154,0.20570619140575064,0.31011883751175634,27,22,0.414136,3
10,1.9075760376026953,0.3147932891699279,0.5177177067165832,27,22,2.00288,3
11,2.9846374260201185,0.30721819756219876,0.4847943942040535,27,11,3.1266,3
12,0.1752180568932323,0.36176569485305043,0.3939852665942875,27,-11,0.18681,3
13,0.6766280621501003,0.45352882880057616,0.5790314035484285,27,22,0.747416,3
14,1.3101966891257206,0.42798939758073234,0.43784951679362893,27,22,1.43204,3
15,0.14196910937063034,-0.03235766110230304,0.47279429948915686,27,22,0.142043,3
8,2.9846374260201185,0.30721819756219876,0.4847943942040535,27,11,3.1266,3
9,0.1752180568932323,0.36176569485305043,0.3939852665942875,27,-11,0.18681,3
0,11.21380957419721,1.6553173882675978,3.7749953632685496,10,10,30.48894,4
1,1.0953267641119704,1.3014009824737631,3.7002630014754305,27,-211,2.1658,4
2,2.4424330540262513,1.687695972521736,3.8132931547224382,27,211,6.83038,4
3,6.208142522075343,1.6038886865519846,3.757018553812884,27,-211,16.0593,4
4,1.4771378452091057,1.976606014956678,3.8426505667849744,27,22,5.43346,4
0,10.275890435601237,-1.5533927684074336,0.35447680942603377,10,10,25.47627,4
1,1.6720572044149686,-1.3838806010638198,0.09105807925555832,27,-211,3.54825,4
2,4.639934376357062,-1.5942587871551437,0.41720196638934237,27,211,11.8969,4
3,0.6504992157981437,-1.7585474105753374,0.3482302818485385,27,22,1.94379,4
4,0.6558795486162075,-1.2553601052579906,0.5129662709131718,27,22,1.24422,4
5,1.763661911104563,-1.3486739190797825,0.42905818573114224,27,22,3.626,4
6,0.9776158121905558,-1.8603390836273852,0.26604346415421726,27,22,3.21711,4

0 comments on commit 9ec4c69

Please sign in to comment.