Skip to content

Commit

Permalink
fix everything
Browse files Browse the repository at this point in the history
  • Loading branch information
RenataKrupczak committed Oct 24, 2024
1 parent 7cb7bb0 commit eeef181
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 72 deletions.
1 change: 0 additions & 1 deletion docs/source/classes/Jetscape/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ Jetscape
:members:
:inherited-members:

.. automethod:: Jetscape.create_loader
2 changes: 0 additions & 2 deletions docs/source/classes/Oscar/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ Oscar
:members:
:inherited-members:


.. automethod:: Oscar.create_loader
3 changes: 0 additions & 3 deletions docs/source/classes/loader/JetscapeLoader/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ JetscapeLoader
.. autoclass:: JetscapeLoader
:members:
:inherited-members:

.. automethod:: JetscapeLoader._get_num_skip_lines
.. automethod:: JetscapeLoader.event_end_lines
3 changes: 0 additions & 3 deletions docs/source/classes/loader/OscarLoader/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ OscarLoader
:members:
:inherited-members:


.. automethod:: OscarLoader.oscar_format
.. automethod:: OscarLoader.event_end_lines
6 changes: 3 additions & 3 deletions src/sparkx/BaseStorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from sparkx.Filter import *
import numpy as np
from abc import ABC, abstractmethod
from sparkx.Particle import Particle
from typing import List, Union, Tuple, Optional
from sparkx.loader.BaseLoader import BaseLoader

Expand Down Expand Up @@ -74,7 +75,7 @@ class BaseStorer(ABC):
"""

def __init__(
self, path: Union[str, List[List["Particle"]]], **kwargs
self, path: Union[str, List[List[Particle]]], **kwargs
) -> None:
"""
Parameters
Expand All @@ -94,7 +95,7 @@ def __init__(
self.loader_: Optional[BaseLoader] = None
self.num_output_per_event_: Optional[np.ndarray] = None
self.num_events_: Optional[int] = None
self.particle_list_: Optional[List] = None
self.particle_list_: List[List[Particle]] = [[]]
self.create_loader(path)
if self.loader_ is not None:
(
Expand Down Expand Up @@ -229,7 +230,6 @@ def uncharged_particles(self) -> "BaseStorer":
self : BaseStorer object
Containing uncharged particles in every event only
"""

self.particle_list_ = uncharged_particles(self.particle_list_)
self._update_num_output_per_event_after_filter()

Expand Down
8 changes: 4 additions & 4 deletions src/sparkx/EventCharacteristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ def generate_eBQS_densities_Milne_from_OSCAR_IC(self,
raise TypeError(
"The smearing function only works with EventCharacteristics derived from particles."
)
if not isinstance(self.event_data_, (list, np.ndarray)):
raise TypeError("The input is not a list nor a numpy.ndarray.")
if not isinstance(self.event_data_, list):
raise TypeError("The input is not a list.")

energy_density = Lattice3D(
x_min,
Expand Down Expand Up @@ -628,8 +628,8 @@ def generate_eBQS_densities_Minkowski_from_OSCAR_IC(
raise TypeError(
"The smearing function only works with EventCharacteristics derived from particles."
)
if not isinstance(self.event_data_, (list, np.ndarray)):
raise TypeError("The input is not a list nor a numpy.ndarray.")
if not isinstance(self.event_data_, list):
raise TypeError("The input is not a list.")

energy_density = Lattice3D(
x_min,
Expand Down
4 changes: 2 additions & 2 deletions src/sparkx/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,10 @@ def spacetime_cut(particle_list: List[List[Particle]], dim: str,
return updated_particle_list


def pt_cut(particle_list: List[List[Particle]],
def pT_cut(particle_list: List[List[Particle]],
cut_value_tuple: Tuple[Optional[float], Optional[float]]) -> List[List[Particle]]:
"""
Apply p_t cut to all events by passing an acceptance range by
Apply p_T cut to all events by passing an acceptance range by
::code`cut_value_tuple`. All particles outside this range will
be removed.
Expand Down
4 changes: 2 additions & 2 deletions src/sparkx/Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def average_weighted(self, weights: np.ndarray) -> 'Histogram':
np.average(self.systematic_error_**2.0, axis=0, weights=weights)
)
self.histogram_raw_count_ = np.sum(self.histograms_raw_count_, axis=0)
self.scaling_ = self.scaling_[0]
self.scaling_ = np.asarray(self.scaling_[0])

if self.scaling_.ndim == 1:
self.scaling_ = self.scaling_.reshape(1, -1)
Expand Down Expand Up @@ -716,7 +716,7 @@ def average_weighted_by_error(self) -> 'Histogram':
np.average(self.systematic_error_**2.0, axis=0, weights=weights)
)
self.histogram_raw_count_ = np.sum(self.histograms_raw_count_, axis=0)
self.scaling_ = self.scaling_[0]
self.scaling_ = np.asarray(self.scaling_[0])

if self.scaling_.ndim == 1:
self.scaling_ = self.scaling_.reshape(1, -1)
Expand Down
39 changes: 18 additions & 21 deletions src/sparkx/JetAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ def __init__(self) -> None:
self.hadron_data_: Optional[List[List[Particle]]] = None
self.jet_R_: Optional[float] = None
self.jet_eta_range_: Optional[tuple] = None
self.jet_pt_range_: Optional[tuple] = None
self.jet_pT_range_: Optional[tuple] = None
self.jet_data_: Optional[List[List[Any]]] = None

def __initialize_and_check_parameters(self, hadron_data: List[List[Particle]], jet_R: float,
jet_eta_range: Tuple[Optional[float], Optional[float]],
jet_pt_range: Tuple[Optional[float], Optional[float]]) -> None:
jet_pT_range: Tuple[Optional[float], Optional[float]]) -> None:
"""
Initialize and check the parameters for jet analysis.
Expand Down Expand Up @@ -207,16 +207,16 @@ def __initialize_and_check_parameters(self, hadron_data: List[List[Particle]], j
"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. " +
if not isinstance(jet_pT_range, 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.")
if any(pt is not None and pt < 0 for pt in jet_pt_range):
raise ValueError("All values in jet_pt_range must be non-negative.")
if len(jet_pT_range) != 2:
raise ValueError("jet_pT_range must contain exactly two values.")
if any(pT is not None and pT < 0 for pT in jet_pT_range):
raise ValueError("All values in jet_pT_range must be non-negative.")

lower_cut = 0. if jet_pt_range[0] is None else jet_pt_range[0]
upper_cut = float('inf') if jet_pt_range[1] is None else jet_pt_range[1]
lower_cut = 0. if jet_pT_range[0] is None else jet_pT_range[0]
upper_cut = float('inf') if jet_pT_range[1] is None else jet_pT_range[1]
if lower_cut < upper_cut:
self.jet_pT_range_ = (lower_cut, upper_cut)
else:
Expand Down Expand Up @@ -359,8 +359,8 @@ def write_jet_output(self, output_filename: str, jet: fj.PseudoJet,
bool
False if successful.
"""
if self.jet_pt_range_ is None:
raise TypeError("'jet_pt_range_' is None. It must be initialized before calling the 'write_jet_output' function.")
if self.jet_pT_range_ is None:
raise TypeError("'jet_pT_range_' is None. It must be initialized before calling the 'write_jet_output' function.")

# jet data from reconstruction
jet_status = 10
Expand Down Expand Up @@ -408,7 +408,7 @@ def write_jet_output(self, output_filename: str, jet: fj.PseudoJet,

def perform_jet_finding(self, hadron_data: List[List[Particle]], jet_R: float,
jet_eta_range: Tuple[Optional[float], Optional[float]],
jet_pt_range: Tuple[Optional[float], Optional[float]],
jet_pT_range: Tuple[Optional[float], Optional[float]],
output_filename: str, assoc_only_charged: bool = True,
jet_algorithm: fj = fj.antikt_algorithm) -> None:
"""
Expand Down Expand Up @@ -448,16 +448,16 @@ def perform_jet_finding(self, hadron_data: List[List[Particle]], jet_R: float,
package is fixed here.
"""
self.__initialize_and_check_parameters(
hadron_data, jet_R, jet_eta_range, jet_pT_range
)
if self.hadron_data_ is None:
raise TypeError("'hadron_data_' is None. It must be initialized before calling the 'perform_jet_finding' function.")
if self.jet_eta_range_ is None:
raise TypeError("'jet_eta_range_' is None. It must be initialized before calling the 'perform_jet_finding' function.")
if self.jet_pt_range_ is None:
raise TypeError("'jet_pt_range_' is None. It must be initialized before calling the 'perform_jet_finding' function.")
if self.jet_pT_range_ is None:
raise TypeError("'jet_pT_range_' is None. It must be initialized before calling the 'perform_jet_finding' function.")

self.__initialize_and_check_parameters(
hadron_data, jet_R, jet_eta_range, jet_pT_range
)
for event, hadron_data_event in enumerate(self.hadron_data_):
new_file = False
event_PseudoJets = self.create_fastjet_PseudoJets(hadron_data_event)
Expand Down Expand Up @@ -516,9 +516,6 @@ def read_jet_data(self, input_filename: str) -> None:
input_filename: str
Filename of the CSV file containing the jet data.
"""
if self.jet_data_ is None:
raise TypeError("'jet_data_' is None. It must be initialized before calling the 'read_jet_data' function.")

jet_data = []
current_jet: List[List[Any]] = []
with open(input_filename, 'r', newline='') as f:
Expand Down
10 changes: 6 additions & 4 deletions src/sparkx/Jetscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from sparkx.Filter import *
import numpy as np
from sparkx.loader.JetscapeLoader import JetscapeLoader
from sparkx.Particle import Particle
from sparkx.BaseStorer import BaseStorer
from typing import List, Tuple, Union, Dict, Optional

Expand Down Expand Up @@ -181,18 +182,19 @@ def __init__(
)
self.last_line_: str = self.loader_.get_last_line(JETSCAPE_FILE)
del self.loader_

def create_loader(
self, JETSCAPE_FILE: Union[str, List[List["Particle"]]]
self, JETSCAPE_FILE: Union[str, List[List[Particle]]]
) -> None:
"""
Creates a new JetscapeLoader object.
This method initializes a new JetscapeLoader object with the specified JETSCAPE file
and assigns it to the loader_ attribute.
and assigns it to the loader attribute.
Parameters
----------
JETSCAPE_FILE : Union[str, List[List["Particle"]]]
JETSCAPE_FILE : Union[str, List[List[Particle]]]
The path to the JETSCAPE file to be loaded. Must be a string.
Raises
Expand All @@ -210,7 +212,7 @@ def create_loader(

# PRIVATE CLASS METHODS
def _particle_as_list(
self, particle: "Particle"
self, particle: Particle
) -> List[Union[int, float]]:
particle_list: List[Union[int, float]] = [0.0] * 7
particle_list[0] = int(particle.ID)
Expand Down
6 changes: 3 additions & 3 deletions src/sparkx/Lattice3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ def __get_index(self, value: Union[int, float],
The value for which the index is to be determined.
values : list or numpy.ndarray
The list or array containing the range of values, sorted ascending.
num_points : int
The number of points in the range.
Returns
-------
Expand Down Expand Up @@ -1230,7 +1228,7 @@ def interpolate_to_lattice_new_extent(self, num_points_x: int, num_points_y: int
or z < self.z_min_
or z > self.z_max_
):
value = 0
value = 0.0
else:
value = self.interpolate_value(x, y, z)
new_lattice.set_value_by_index(i, j, k, value)
Expand Down Expand Up @@ -1277,6 +1275,8 @@ def add_same_spaced_grid(self, other: 'Lattice3D', center_x: float, center_y: fl
raise TypeError(
"Unsupported operand type. The operand must be of type 'Lattice3D'."
)
if self.spacing_x_ is None or self.spacing_y_ is None or self.spacing_z_ is None:
raise TypeError("At least one of the 'spacing' is None.")
# Check if both lattices have the same spacing
if (
(
Expand Down
2 changes: 1 addition & 1 deletion src/sparkx/MultiParticlePtCorrelations.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def _compute_mean_pT_correlations(

return sum_numerator / sum_denominator

def mean_pt_correlations(self,
def mean_pT_correlations(self,
particle_list_all_events: List[List[Particle]],
compute_error: bool = True,
delete_fraction: float = 0.4,
Expand Down
4 changes: 2 additions & 2 deletions src/sparkx/Oscar.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def __init__(self, OSCAR_FILE: str, **kwargs: Any) -> None:
self.PATH_OSCAR_: str = OSCAR_FILE
if not isinstance(self.loader_, OscarLoader):
raise TypeError("The loader must be an instance of OscarLoader.")
self.oscar_format_: Union[str | None] = self.loader_.oscar_format()
self.oscar_format_: Union[str, None] = self.loader_.oscar_format()
self.event_end_lines_: List[str] = self.loader_.event_end_lines()
del self.loader_

Expand All @@ -181,7 +181,7 @@ def create_loader(self, OSCAR_FILE: str) -> None: # type: ignore[override]
Creates a new OscarLoader object.
This method initializes a new OscarLoader object with the specified OSCAR file
and assigns it to the loader_ attribute.
and assigns it to the loader attribute.
Parameters
----------
Expand Down
8 changes: 4 additions & 4 deletions src/sparkx/flow/EventPlaneFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class EventPlaneFlow(FlowInterface.FlowInterface):
"""

def __init__(self, n: int = 2, weight: str = "pt2", pseudorapidity_gap: float = 0.) -> None:
def __init__(self, n: int = 2, weight: str = "pT2", pseudorapidity_gap: float = 0.) -> None:
"""
Initialize the ScalarProductFlow object.
Expand All @@ -107,7 +107,7 @@ def __init__(self, n: int = 2, weight: str = "pt2", pseudorapidity_gap: float =
n : int, optional
The value of the harmonic. Default is 2.
weight : str, optional
The weight used for calculating the flow. Default is "pt2".
The weight used for calculating the flow. Default is "pT2".
pseudorapidity_gap : float, optional
The pseudorapidity gap used for dividing the particles into sub-events.
Default is 0.0.
Expand All @@ -123,7 +123,7 @@ def __init__(self, n: int = 2, weight: str = "pt2", pseudorapidity_gap: float =
self.n_ = n
if not isinstance(weight, str):
raise TypeError('weight has to be a string')
elif weight not in ["pt", "pt2", "ptn", "rapidity", "pseudorapidity"]:
elif weight not in ["pT", "pT2", "pTn", "rapidity", "pseudorapidity"]:
raise ValueError(
"Invalid weight given, choose one of the following: 'pT', 'pT2', 'pTn', 'rapidity', 'pseudorapidity'"
)
Expand Down Expand Up @@ -495,7 +495,7 @@ def differential_flow(
raise TypeError('bins has to be list or np.ndarray')
if not isinstance(flow_as_function_of, str):
raise TypeError('flow_as_function_of is not a string')
if flow_as_function_of not in ["pt", "rapidity", "pseudorapidity"]:
if flow_as_function_of not in ["pT", "rapidity", "pseudorapidity"]:
raise ValueError(
"flow_as_function_of must be either 'pT', 'rapidity', 'pseudorapidity'"
)
Expand Down
14 changes: 7 additions & 7 deletions src/sparkx/flow/GenerateFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def __thermal_distribution(self, temperature: float, mass: float) -> float:
momentum_radial: float
The magnitude of the momentum.
"""
momentum_radial = 0
momentum_radial = 0.0
energy = 0.0
if temperature > 0.6 * mass:
while True:
Expand Down Expand Up @@ -364,7 +364,7 @@ def __artificial_flow_pT_shape(self, pT: float, pT0_bis: float, pT_sat: float, v

return value

def __distribution_function_pT_differential(self, phi: float, vn_pt_list: List[float]) -> float:
def __distribution_function_pT_differential(self, phi: float, vn_pT_list: List[float]) -> float:
"""
Calculates the pT-differential distribution function for a given
azimuthal angle.
Expand Down Expand Up @@ -433,7 +433,7 @@ def __create_k_particle_correlations(
self.py_ = py
self.pz_ = pz

def __generate_flow_realistic_pt_distribution(
def __generate_flow_realistic_pT_distribution(
self, multiplicity: int, reaction_plane_angle: float) -> None:
pTmax = 4.5
pTmin = 0.1
Expand Down Expand Up @@ -568,7 +568,7 @@ def generate_dummy_JETSCAPE_file(

output.write("# sigmaGen 0.0 sigmaErr 0.0")

def generate_dummy_JETSCAPE_file_realistic_pt_shape(
def generate_dummy_JETSCAPE_file_realistic_pT_shape(
self,
output_path: str,
number_events: int,
Expand Down Expand Up @@ -761,7 +761,7 @@ def generate_dummy_JETSCAPE_file_multi_particle_correlations(

output.write("# sigmaGen 0.0 sigmaErr 0.0")

def generate_dummy_JETSCAPE_file_realistic_pt_shape_multi_particle_correlations(
def generate_dummy_JETSCAPE_file_realistic_pT_shape_multi_particle_correlations(
self,
output_path: str,
number_events: int,
Expand Down Expand Up @@ -962,7 +962,7 @@ def generate_dummy_OSCAR_file(
output.write(
f"# event {event} end 0 impact -1.000 scattering_projectile_target no\n")

def generate_dummy_OSCAR_file_realistic_pt_shape(
def generate_dummy_OSCAR_file_realistic_pT_shape(
self,
output_path: str,
number_events: int,
Expand Down Expand Up @@ -1172,7 +1172,7 @@ def generate_dummy_OSCAR_file_multi_particle_correlations(
output.write(
f"# event {event} end 0 impact -1.000 scattering_projectile_target no\n")

def generate_dummy_OSCAR_file_realistic_pt_shape_multi_particle_correlations(
def generate_dummy_OSCAR_file_realistic_pT_shape_multi_particle_correlations(
self,
output_path: str,
number_events: int,
Expand Down
Loading

0 comments on commit eeef181

Please sign in to comment.