Skip to content

Commit

Permalink
Merge pull request #243 from smash-transport/roch/add_sin_ReactionPla…
Browse files Browse the repository at this point in the history
…neFlow

Add event plane angle return in reaction plane flow
  • Loading branch information
Hendrik1704 authored Jul 1, 2024
2 parents 68c2109 + 63f87fa commit 91e595b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ 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.2-Newton
Date: XXX

### Added
* ReactionPlaneFlow: Returns also the angle, not only the flow value


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

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

Expand Down
39 changes: 29 additions & 10 deletions src/sparkx/flow/EventPlaneFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ def f1_wrapper(x):

def __compute_flow_particles(self, particle_data, weights, Q_vector, u_vectors, resolution, self_corr):
flow_values = []
psi_values = []
for event in range(len(particle_data)):
flow_values_event = []
psi_values_event = []
for particle in range(len(particle_data[event])):
weight_particle = np.abs(weights[event][particle])
Q_vector_particle = Q_vector[event]
Expand All @@ -271,9 +273,10 @@ def __compute_flow_particles(self, particle_data, weights, Q_vector, u_vectors,

flow_of_particle = vn_obs / resolution
flow_values_event.append(flow_of_particle)
psi_values_event.append(Psi_n)
flow_values.extend([flow_values_event])

return flow_values
psi_values.extend([psi_values_event])
return flow_values, psi_values

def __calculate_reference(self, particle_data_event_plane):
event_weights_event_plane = self.__compute_particle_weights(particle_data_event_plane)
Expand All @@ -286,34 +289,46 @@ def __calculate_reference(self, particle_data_event_plane):
def __calculate_particle_flow(self, particle_data, resolution, Q_vector, self_corr):
event_weights = self.__compute_particle_weights(particle_data)
u_vectors = self.__compute_u_vectors(particle_data)
sum_weights_u = self.__sum_weights(event_weights)
flow_values, psi_values = self.__compute_flow_particles(particle_data,event_weights,Q_vector,u_vectors,resolution,self_corr)

return self.__compute_flow_particles(particle_data,event_weights,Q_vector,u_vectors,resolution, self_corr)
return flow_values, psi_values

def __calculate_flow_event_average(self, particle_data, flow_particle_list):
def __calculate_flow_event_average(self, particle_data, flow_particle_list, psi_particle_list):
# compute the integrated flow
number_of_particles = 0
flowvalue = 0.0
flowvalue_squared = 0.0
psivalue = 0.0
psivalue_squared = 0.0
for event in range(len(flow_particle_list)):
for particle in range(len(flow_particle_list[event])):
weight = 1. if np.isnan(particle_data[event][particle].weight) else particle_data[event][particle].weight
number_of_particles += weight
flowvalue += flow_particle_list[event][particle]*weight
flowvalue_squared += flow_particle_list[event][particle]**2.*weight**2.
psivalue += psi_particle_list[event][particle]*weight
psivalue_squared += psi_particle_list[event][particle]**2.*weight**2.

vn_integrated = 0.0
Psi_n = 0.0
sigma = 0.0
sigma_Psi = 0.0
if number_of_particles == 0:
vn_integrated = 0.0
Psi_n = 0.0
sigma = 0.0
sigma_Psi = 0.0
else:
vn_integrated = flowvalue / number_of_particles
Psi_n = psivalue / number_of_particles
vn_squared = flowvalue_squared / number_of_particles**2.
Psi_n_squared = psivalue_squared / number_of_particles**2.
std_deviation = np.sqrt(vn_integrated**2. - vn_squared)
std_deviation_Psi = np.sqrt(Psi_n**2. - Psi_n_squared)
sigma = std_deviation / np.sqrt(number_of_particles)
sigma_Psi = std_deviation_Psi / np.sqrt(number_of_particles)

return vn_integrated, sigma
return vn_integrated, sigma, Psi_n, sigma_Psi

def integrated_flow(self,particle_data,particle_data_event_plane, self_corr=True):
"""
Expand All @@ -333,12 +348,14 @@ def integrated_flow(self,particle_data,particle_data_event_plane, self_corr=True
-------
tuple
A tuple containing the integrated flow value and the corresponding
uncertainty.
uncertainty. The third and fourth element are the event plane angle
and the corresponding uncertainty.
"""
if not isinstance(self_corr, bool):
raise TypeError('self_corr has to be bool')
resolution, Q_vector = self.__calculate_reference(particle_data_event_plane)
return self.__calculate_flow_event_average(particle_data, self.__calculate_particle_flow(particle_data, resolution, Q_vector, self_corr))
flow_values, psi_values = self.__calculate_particle_flow(particle_data, resolution, Q_vector, self_corr)
return self.__calculate_flow_event_average(particle_data, flow_values, psi_values)

def differential_flow(self, particle_data, bins, flow_as_function_of, particle_data_event_plane, self_corr=True):
"""
Expand All @@ -363,7 +380,8 @@ def differential_flow(self, particle_data, bins, flow_as_function_of, particle_d
-------
list
A list of tuples containing the flow values and uncertainties for
each bin.
each bin. The third and fourth element are the event plane angle
and the corresponding uncertainty.
"""
if not isinstance(self_corr, bool):
raise TypeError('self_corr has to be bool')
Expand Down Expand Up @@ -396,6 +414,7 @@ def differential_flow(self, particle_data, bins, flow_as_function_of, particle_d

flow_bin = []
for bin in range(len(bins)-1):
flow_bin.append(self.__calculate_flow_event_average(particle_data, self.__calculate_particle_flow(particles_bin[bin],resolution,Q_vector,self_corr)))
flow_values, psi_values = self.__calculate_particle_flow(particles_bin[bin],resolution,Q_vector,self_corr)
flow_bin.append(self.__calculate_flow_event_average(particle_data, flow_values, psi_values))

return flow_bin

0 comments on commit 91e595b

Please sign in to comment.