JetscapeLoader

class JetscapeLoader.JetscapeLoader(JETSCAPE_FILE: str)[source]

A class to load and process JETSCAPE data files.

Attributes:
PATH_JETSCAPE_str

The path to the JETSCAPE data file.

particle_type_str

The type of particles to load (‘hadron’ or ‘parton’).

Methods

load(**kwargs)

Loads the data from the JETSCAPE file based on the specified optional arguments.

set_particle_list(kwargs)

Sets the list of particles based on the specified optional arguments.

set_num_output_per_event()

Sets the number of output lines per event in the JETSCAPE data file.

get_last_line(file_path)

Returns the last line of a file.

get_sigmaGen()

Retrieves the sigmaGen values with error from the last line of a file.

get_particle_type_defining_string()

Returns the string which defines the particle type in the JETSCAPE file.

get_particle_type()

Returns the particle type of the JETSCAPE file.

event_end_lines() List[str][source]

Returns the list of event end lines.

This method returns the list of strings that mark the end of events in the Jetscape data.

Returns:
List[str]

A list of strings that mark the end of events in the Jetscape data.

get_last_line(file_path: str) str[source]

Returns the last line of a file.

Parameters:
file_pathstr

The path to the file.

Returns:
str

The last line of the file, stripped of leading and trailing whitespace.

get_particle_type() str[source]

Returns the particle type of the Jetscape file.

Returns:
string

The particle type.

get_particle_type_defining_string() str[source]

Returns the string which defines the particle type in the Jetscape file.

Returns:
string

The particle type defining string.

get_sigmaGen() Tuple[float, float][source]

Retrieves the sigmaGen values with error from the last line of a file.

Returns:
tuple

A tuple containing the first and second sigmaGen values as floats.

load(**kwargs: Any) Tuple[List[List[Particle]], int, ndarray, List[str]][source]

Loads the data from the JETSCAPE file based on the specified optional arguments.

This method reads the JETSCAPE data file and applies any filters specified in the ‘filters’ key of the kwargs dictionary. It also adjusts the number of events and the number of output lines per event based on the ‘events’ key in the kwargs dictionary. If the ‘particletype’ key is specified, it sets the particle type to either ‘hadron’ or ‘parton’. If any other keys are specified in the kwargs dictionary, it raises a ValueError.

Parameters:
kwargsdict

A dictionary of optional arguments. The following keys are recognized:

  • ‘events’: Either a tuple of two integers specifying the range of events to load, or a single integer specifying a single event to load.

  • ‘filters’: A list of filters to apply to the data.

  • ‘particletype’: A string specifying the type of particles to load (‘hadron’ or ‘parton’).

Returns:
tuple

A tuple containing the list of Particle objects loaded from the JETSCAPE data file, the number of events, and the number of output lines per event.

Raises:
ValueError

If an unknown keyword argument is used, if the first value of the ‘events’ tuple is larger than the second value, if an event number is negative, or if the ‘particletype’ is not ‘hadron’ or ‘parton’.

TypeError

If the ‘events’ key is not a tuple or an integer, or if the ‘particletype’ key is not a string.

set_num_output_per_event() None[source]

Sets the number of output lines per event in the JETSCAPE data file.

This method reads the JETSCAPE data file line by line and determines the number of output lines for each event. It does this by looking for lines that contain a ‘#’ and the particle_type_defining_string_. For each such line, it extracts the event number and the number of output lines from the line and appends them to a list. After reading the entire file, it converts the list to a numpy array and stores it in the num_output_per_event_ attribute. It also sets the num_events_ attribute to the length of the list.

Parameters:
None
Returns:
None
Raises:
None
set_particle_list(kwargs: Dict[str, int | Tuple[int, int] | List[Dict[str, str | float]]]) List[List[Particle]][source]

Sets the list of particles based on the specified optional arguments.

This method reads the JETSCAPE data file and creates a list of Particle objects based on the data in the file. It applies any filters specified in the ‘filters’ key of the kwargs dictionary. It also adjusts the number of events and the number of output lines per event based on the ‘events’ key in the kwargs dictionary. If any other keys are specified in the kwargs dictionary, it raises a ValueError.

Parameters:
kwargsdict

A dictionary of optional arguments. The following keys are recognized:

  • ‘events’: Either a tuple of two integers specifying the range of events to load, or a single integer specifying a single event to load.

  • ‘filters’: A list of filters to apply to the data.

Returns:
particle_listlist

A list of Particle objects loaded from the JETSCAPE data file.

Raises:
IndexError

If the end of the JETSCAPE file is reached before the specified number of lines is read, or if the number of events in the JETSCAPE file does not match the number of events specified by the comments in the file.

ValueError

If the first line of the event is not a comment line or does not contain “weight”, or if an unknown keyword argument is used.