Skip to content

Commit

Permalink
Merge pull request #237 from smash-transport/roch/fix_little_things
Browse files Browse the repository at this point in the history
Fix small things
  • Loading branch information
Hendrik1704 committed Jun 13, 2024
2 parents 6e3650b + 10c090e commit 68c2109
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 106 deletions.
35 changes: 17 additions & 18 deletions src/sparkx/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def particle_species(particle_list, pdg_list):
Filtered list of lists containing particle objects for each event
"""
if not isinstance(pdg_list, (str, int, list, np.integer, np.ndarray, tuple, float)):
raise TypeError('Input value for pgd codes has not one of the ' +\
'following types: str, int, float, np.integer, list ' +\
raise TypeError('Input value for pgd codes has not one of the ' +
'following types: str, int, float, np.integer, list ' +
'of str, list of int, list of int np.ndarray, tuple')

if isinstance(pdg_list, float):
Expand Down Expand Up @@ -122,8 +122,8 @@ def particle_species(particle_list, pdg_list):
and not np.isnan(elem.pdg))]

else:
raise TypeError('Input value for pgd codes has not one of the ' +\
'following types: str, int, float, np.integer, list ' +\
raise TypeError('Input value for pgd codes has not one of the ' +
'following types: str, int, float, np.integer, list ' +
'of str, list of int, list of float, np.ndarray, tuple')
return particle_list

Expand All @@ -150,8 +150,8 @@ def remove_particle_species(particle_list, pdg_list):
Filtered list of lists containing particle objects for each event
"""
if not isinstance(pdg_list, (str, int, float, list, np.integer, np.ndarray, tuple)):
raise TypeError('Input value for pgd codes has not one of the ' +\
'following types: str, int, float, np.integer, list ' +\
raise TypeError('Input value for pgd codes has not one of the ' +
'following types: str, int, float, np.integer, list ' +
'of str, list of int, list of float, np.ndarray, tuple')

if isinstance(pdg_list, float):
Expand All @@ -172,16 +172,15 @@ def remove_particle_species(particle_list, pdg_list):

elif isinstance(pdg_list, (list, np.ndarray, tuple)):
pdg_list = np.asarray(pdg_list, dtype=np.int64)
print(pdg_list)

for i in range(0, len(particle_list)):
particle_list[i] = [elem for elem in particle_list[i]
if (int(elem.pdg) not in pdg_list
and not np.isnan(elem.pdg))]

else:
raise TypeError('Input value for pgd codes has not one of the ' +\
'following types: str, int, float, np.integer, list ' +\
raise TypeError('Input value for pgd codes has not one of the ' +
'following types: str, int, float, np.integer, list ' +
'of str, list of int, list of float, np.ndarray, tuple')
return particle_list

Expand Down Expand Up @@ -254,7 +253,7 @@ def lower_event_energy_cut(particle_list,minimum_event_energy):
If the minimum_event_energy parameter is NaN.
"""
if not isinstance(minimum_event_energy, (int, float)):
raise TypeError('Input value for lower event energy cut has not ' +\
raise TypeError('Input value for lower event energy cut has not ' +
'one of the following types: int, float')
if np.isnan(minimum_event_energy):
raise ValueError('Input value should not be NaN')
Expand Down Expand Up @@ -367,7 +366,7 @@ def pt_cut(particle_list, cut_value_tuple):
Filtered list of lists containing particle objects for each event
"""
if not isinstance(cut_value_tuple, tuple) or len(cut_value_tuple) != 2:
raise TypeError('Input value must be a tuple containing either '+\
raise TypeError('Input value must be a tuple containing either '+
'positive numbers or None of length two')
elif any(val is not None and not isinstance(val, (int, float)) for val in cut_value_tuple):
raise ValueError('Non-numeric value found in cut_value_tuple')
Expand Down Expand Up @@ -425,7 +424,7 @@ def rapidity_cut(particle_list, cut_value):
"""
if isinstance(cut_value, tuple):
if len(cut_value) != 2:
raise TypeError('If input value is a tuple, then it must contain '+\
raise TypeError('If input value is a tuple, then it must contain '+
'two numbers')
elif any(not isinstance(val, (int, float)) for val in cut_value):
raise ValueError('Non-numeric value found in cut_value')
Expand All @@ -435,7 +434,7 @@ def rapidity_cut(particle_list, cut_value):
warnings.warn(warn_msg)

elif not isinstance(cut_value, (int, float)):
raise TypeError('Input value must be a number or a tuple ' +\
raise TypeError('Input value must be a number or a tuple ' +
'with the cut limits (cut_min, cut_max)')

if isinstance(cut_value, (int, float)):
Expand Down Expand Up @@ -489,7 +488,7 @@ def pseudorapidity_cut(particle_list, cut_value):
"""
if isinstance(cut_value, tuple):
if len(cut_value) != 2:
raise TypeError('If input value is a tuple, then it must contain '+\
raise TypeError('If input value is a tuple, then it must contain '+
'two numbers')
elif any(not isinstance(val, (int, float)) for val in cut_value):
raise ValueError('Non-numeric value found in cut_value')
Expand All @@ -499,7 +498,7 @@ def pseudorapidity_cut(particle_list, cut_value):
warnings.warn(warn_msg)

elif not isinstance(cut_value, (int, float)):
raise TypeError('Input value must be a number or a tuple ' +\
raise TypeError('Input value must be a number or a tuple ' +
'with the cut limits (cut_min, cut_max)')

if isinstance(cut_value, (int, float)):
Expand Down Expand Up @@ -553,7 +552,7 @@ def spatial_rapidity_cut(particle_list, cut_value):
"""
if isinstance(cut_value, tuple):
if len(cut_value) != 2:
raise TypeError('If input value is a tuple, then it must contain '+\
raise TypeError('If input value is a tuple, then it must contain '+
'two numbers')
elif any(not isinstance(val, (int, float)) for val in cut_value):
raise ValueError('Non-numeric value found in cut_value')
Expand All @@ -563,7 +562,7 @@ def spatial_rapidity_cut(particle_list, cut_value):
warnings.warn(warn_msg)

elif not isinstance(cut_value, (int, float)):
raise TypeError('Input value must be a number or a tuple ' +\
raise TypeError('Input value must be a number or a tuple ' +
'with the cut limits (cut_min, cut_max)')

if isinstance(cut_value, (int, float)):
Expand Down Expand Up @@ -646,7 +645,7 @@ def particle_status(particle_list, status_list):
Filtered list of lists containing particle objects for each event
"""
if not isinstance(status_list, (int, list, tuple, np.ndarray)):
raise TypeError('Input for status codes must be int, or '+\
raise TypeError('Input for status codes must be int, or '+
'list/tuple/array of int values')
if isinstance(status_list, (list, tuple, np.ndarray)):
if any(not isinstance(val, int) for val in status_list):
Expand Down
4 changes: 2 additions & 2 deletions src/sparkx/Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def __init__(self, bin_boundaries):
self.systematic_error_ = np.zeros(self.number_of_bins_)

else:
raise TypeError('Input must be a tuple (hist_min, hist_max, num_bins) '+\
raise TypeError('Input must be a tuple (hist_min, hist_max, num_bins) '+
'or a list/numpy.ndarray containing the bin edges!')

def histogram(self):
Expand Down Expand Up @@ -675,7 +675,7 @@ def write_to_file(self, filename, hist_labels, comment='', columns=None):
+ " provided. Use the header for all histograms."
warnings.warn(error_message)
elif self.number_of_histograms_ > 1 and (len(hist_labels) > 1 and len(hist_labels) < self.number_of_histograms_):
raise ValueError("Print multiple histograms to file, more than one,"\
raise ValueError("Print multiple histograms to file, more than one,"
+" but less than number of histograms headers provided.")

if columns is None:
Expand Down
26 changes: 13 additions & 13 deletions src/sparkx/JetAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def __initialize_and_check_parameters(self, hadron_data, jet_R, jet_eta_range,

# check jet eta range
if not isinstance(jet_eta_range, tuple):
raise TypeError("jet_eta_range is not a tuple. " +\
raise TypeError("jet_eta_range is not a tuple. " +
"It must contain either values or None.")
if len(jet_eta_range) != 2:
raise ValueError("jet_eta_range must contain exactly two values.")
Expand All @@ -186,12 +186,12 @@ def __initialize_and_check_parameters(self, hadron_data, jet_R, jet_eta_range,
self.jet_eta_range_ = (lower_cut, upper_cut)
else:
self.jet_eta_range_ = (upper_cut, lower_cut)
warnings.warn("The lower jet eta cut value is larger than the " +\
warnings.warn("The lower jet eta cut value is larger than the " +
"upper one. They are interchanged automatically.")

# check the jet pt range
if not isinstance(jet_pt_range, tuple):
raise TypeError("jet_pt_range is not a tuple. " +\
raise TypeError("jet_pt_range is not a tuple. " +
"It must contain either values or None.")
if len(jet_pt_range) != 2:
raise ValueError("jet_pt_range must contain exactly two values.")
Expand All @@ -204,7 +204,7 @@ def __initialize_and_check_parameters(self, hadron_data, jet_R, jet_eta_range,
self.jet_pt_range_ = (lower_cut, upper_cut)
else:
self.jet_pt_range_ = (upper_cut, lower_cut)
warnings.warn("The lower jet pt cut value is larger than the " +\
warnings.warn("The lower jet pt cut value is larger than the " +
"upper one. They are interchanged automatically.")

def create_fastjet_PseudoJets(self, event_hadrons):
Expand Down Expand Up @@ -257,7 +257,7 @@ def fill_associated_particles(self,jet,event,status_selection,only_charged):
(only_charged and hadron.charge == 0):
continue

fastjet_particle = fj.PseudoJet(hadron.px,hadron.py,\
fastjet_particle = fj.PseudoJet(hadron.px,hadron.py,
hadron.pz,hadron.E)
delta_eta = fastjet_particle.eta() - jet.eta()
delta_phi = fastjet_particle.delta_phi_to(jet)
Expand Down Expand Up @@ -335,15 +335,15 @@ def write_jet_output(self,output_filename,jet,associated_hadrons,event,
output_list = []

if jet.perp() < self.jet_pt_range_[1]:
output_list = [[0,jet.perp(),jet.eta(),jet.phi(),jet_status,\
output_list = [[0,jet.perp(),jet.eta(),jet.phi(),jet_status,
jet_pid,jet.e(),event]]

# associated hadrons
for i, associated in enumerate(associated_hadrons, start=1):
pseudo_jet = fj.PseudoJet(associated.px,associated.py,\
pseudo_jet = fj.PseudoJet(associated.px,associated.py,
associated.pz,associated.E)
output = [i,pseudo_jet.perp(),pseudo_jet.eta(),\
pseudo_jet.phi(),associated.status,\
output = [i,pseudo_jet.perp(),pseudo_jet.eta(),
pseudo_jet.phi(),associated.status,
associated.pdg,associated.E,event]
output_list.append(output)

Expand Down Expand Up @@ -425,8 +425,8 @@ def perform_jet_finding(self, hadron_data, jet_R, jet_eta_range, jet_pt_range,
status_selection='positive',
only_charged=assoc_only_charged)
jet = self.jet_hole_subtraction(jet, holes_in_jet)
new_file = self.write_jet_output(output_filename, jet,\
associated_particles,\
new_file = self.write_jet_output(output_filename, jet,
associated_particles,
event,new_file)

def read_jet_data(self, input_filename):
Expand All @@ -448,8 +448,8 @@ def read_jet_data(self, input_filename):
if jet_index == 0 and current_jet:
jet_data.append(current_jet)
current_jet = []
current_jet.append([int(row[0]), float(row[1]), float(row[2]),\
float(row[3]), int(row[4]), int(row[5]),\
current_jet.append([int(row[0]), float(row[1]), float(row[2]),
float(row[3]), int(row[4]), int(row[5]),
float(row[6]), int(row[7])])
if current_jet:
jet_data.append(current_jet)
Expand Down
20 changes: 10 additions & 10 deletions src/sparkx/Jetscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def __get_num_skip_lines(self):
cumulate_lines += self.num_output_per_event_[i,1] + 1
skip_lines = 1 + cumulate_lines
else:
raise TypeError('Value given as flag "events" is not of type ' +\
raise TypeError('Value given as flag "events" is not of type ' +
'int or a tuple of two int values')

return skip_lines
Expand Down Expand Up @@ -309,12 +309,12 @@ def __get_num_read_lines(self):
def __particle_as_list(self, particle):
particle_list = [0.0]*7
particle_list[0] = int(particle.ID)
particle_list[1] = int(particle.pdg)
particle_list[2] = int(particle.status)
particle_list[3] = float(particle.E)
particle_list[4] = float(particle.px)
particle_list[5] = float(particle.py)
particle_list[6] = float(particle.pz)
particle_list[1] = int(particle.pdg)
particle_list[2] = int(particle.status)
particle_list[3] = float(particle.E)
particle_list[4] = float(particle.px)
particle_list[5] = float(particle.py)
particle_list[6] = float(particle.pz)

return particle_list

Expand Down Expand Up @@ -377,7 +377,7 @@ def set_particle_list(self, kwargs):
self.num_output_per_event_[len(particle_list)]=(len(particle_list)+1,len(data))
particle_list.append(data)
elif i == 0 and '#' not in line and 'weight' not in line:
raise ValueError('First line of the event is not a comment ' +\
raise ValueError('First line of the event is not a comment ' +
'line or does not contain "weight"')
elif 'Event' in line and 'weight' in line:
line = line.replace('\n','').replace('\t',' ').split(' ')
Expand All @@ -403,8 +403,8 @@ def set_particle_list(self, kwargs):
# Correct num_output_per_event and num_events
if not kwargs or 'events' not in self.optional_arguments_.keys():
if len(particle_list) != self.num_events_:
raise IndexError('Number of events in Jetscape file does not match the '+\
'number of events specified by the comments in the '+\
raise IndexError('Number of events in Jetscape file does not match the '+
'number of events specified by the comments in the '+
'Jetscape file!')
elif isinstance(kwargs['events'], int):
update = self.num_output_per_event_[kwargs['events']]
Expand Down
6 changes: 3 additions & 3 deletions src/sparkx/Lattice3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ def __init__(self, x_min, x_max, y_min, y_max, z_min, z_max, num_points_x, num_p
self.n_sigma_y_ = float(n_sigma_y) if n_sigma_y is not None else 3
self.n_sigma_z_ = float(n_sigma_z) if n_sigma_z is not None else 3

self.spacing_x_ = self.x_values_[1]-self.x_values_[0] if num_points_x >1 else None
self.spacing_y_ = self.y_values_[1]-self.y_values_[0] if num_points_y >1 else None
self.spacing_z_ = self.z_values_[1]-self.z_values_[0] if num_points_z >1 else None
self.spacing_x_ = self.x_values_[1]-self.x_values_[0] if num_points_x >1 else None
self.spacing_y_ = self.y_values_[1]-self.y_values_[0] if num_points_y >1 else None
self.spacing_z_ = self.z_values_[1]-self.z_values_[0] if num_points_z >1 else None
self.density_x_ = (self.x_max_-self.x_min_)/self.num_points_x_
self.density_y_ = (self.y_max_-self.y_min_)/self.num_points_y_
self.density_z_ = (self.z_max_-self.z_min_)/self.num_points_z_
Expand Down
Loading

0 comments on commit 68c2109

Please sign in to comment.