CentralityClasses

class CentralityClasses.CentralityClasses(events_multiplicity: List[float] | ndarray, centrality_bins: List[float] | ndarray)[source]

Class for defining centrality classes based on event multiplicity.

Note

It is the user’s responsibility to ensure that the amount of events used to determine the centrality classes is sufficient to provide reliable results. The recommended minimum number of events is at least a few hundred.

Parameters:
events_multiplicitylist or numpy.ndarray

List or array containing the multiplicity values for each event.

centrality_binslist or numpy.ndarray

List or array defining the boundaries of centrality classes as percentages.

Raises:
TypeError

If events_multiplicity or centrality_bins is not a list or numpy.ndarray.

Examples

 1>>> from sparkx import *
 2>>> # ============================================================
 3>>> # 1. Load and filter input particles from simulation output
 4>>> # ============================================================
 5
 6>>> # You can obtain a list of Particle objects using either the
 7>>> # Oscar or Jetscape classes. Alternatively, you may use a
 8>>> # custom user-defined list of Particle objects.
 9>>> #
10>>> # In this example, we use the Oscar class and filter the output
11>>> # to include only charged particles.
12>>>
13>>> OSCAR_FILE_PATH = [Oscar_directory]/particle_lists.oscar
14>>> oscar = Oscar(OSCAR_FILE_PATH, filters={'charged_particles': True})
15>>> number_particles_event = oscar.num_output_per_event()
16>>> # Keep multiplicities from events with non-zero multiplicity only
17>>> multiplicities = number_particles_event[number_particles_event[:, 1] != 0, 1]
18
19>>> # =====================================
20>>> # 2. Calculate centrality classes
21>>> # =====================================
22>>> # Define the centrality class boundaries (in percent)
23>>> centrality_bins = [0, 10, 30, 50, 70, 90, 100]
24>>> centrality_obj = CentralityClasses(events_multiplicity=multiplicities,
25...                                   centrality_bins=centrality_bins)
26>>> # Get the centrality class for a specific event multiplicity value
27>>> # (e.g. 1490)
28>>> # The function returns the index of the centrality bin in `centrality_bins`.
29>>> centrality_obj.get_centrality_class(1490)
300
31>>> # This event has index 0, which corresponds to the most central bin (0-10%).
32>>> centrality_obj.output_centrality_classes('centrality_output.txt')
Attributes:
events_multiplicity_list or numpy.ndarray

Stores the input multiplicity values for each event.

centrality_bins_list or numpy.ndarray

Stores the input boundaries of centrality classes.

dNchdetaMin_list

Minimum values of multiplicity for each centrality class.

dNchdetaMax_list

Maximum values of multiplicity for each centrality class.

dNchdetaAvg_list

Average values of multiplicity for each centrality class.

dNchdetaAvgErr_list

Average errors of multiplicity for each centrality class.

Methods

get_centrality_class:

Return the index of the centrality bin for a given multiplicity value.

output_centrality_classes:

Write centrality class information to a file.

CentralityClasses.get_centrality_class(dNchdEta: float) int[source]

This function determines the index of the centrality bin for a given multiplicity value based on the predefined centrality classes.

In the case that the multiplicity input exceeds the largest or smallest value of the multiplicity used to determine the centrality classes, the function returns the index of the most central or most peripheral bin, respectively.

Parameters:
dNchdEtafloat

Multiplicity value.

Returns:
int

Index of the centrality bin.

CentralityClasses.output_centrality_classes(fname: str) None[source]

Write centrality class information to a file.

Parameters:
fnamestr

Name of the output file.

Raises:
TypeError

If fname is not a string.

Notes

This function writes the centrality class information, including minimum, maximum, average multiplicities, and average errors, to the specified file.