ENH: add in-pixel-hit-distribution for CS and eff. pitch calculation#92
ENH: add in-pixel-hit-distribution for CS and eff. pitch calculation#92YannickDieter wants to merge 7 commits intoSiLab-Bonn:developmentfrom
Conversation
DavidLP
left a comment
There was a problem hiding this comment.
A useful feature but I think it can be reduced by a lot of loc.
testbeam_analysis/result_analysis.py
Outdated
|
|
||
| # read track intersections wiht actual dut for cluster sizes betwenn 1 and 4 | ||
| intersection_x, intersection_y, intersection_z = tracks_chunk[:]['offset_0'], tracks_chunk[:]['offset_1'], tracks_chunk[:]['offset_2'] | ||
| intersection_x_cs_1 = intersection_x[np.where(tracks_chunk[:]['n_hits_dut_%i' % actual_dut] == 1)] |
There was a problem hiding this comment.
np.where creates new arrays and is therefore slow. We should not use it in our heavy data crunching code. Better are boolean mask arrays that create view of the original data. Thus the line should be:
intersection_x_cs_1 = intersection_x[tracks_chunk['n_hits_dut_%i' % actual_dut] == 1]
which is also better to read.
testbeam_analysis/result_analysis.py
Outdated
| inverse=True) | ||
|
|
||
| if not np.allclose(intersection_z_cs_4_local[np.isfinite(intersection_z_cs_4_local)], 0.0): | ||
| print intersection_z_cs_4_local |
There was a problem hiding this comment.
print as an instruction does not exists in Python 3
testbeam_analysis/result_analysis.py
Outdated
| intersection_x_cs_1 = intersection_x[np.where(tracks_chunk[:]['n_hits_dut_%i' % actual_dut] == 1)] | ||
| intersection_y_cs_1 = intersection_y[np.where(tracks_chunk[:]['n_hits_dut_%i' % actual_dut] == 1)] | ||
| intersection_z_cs_1 = intersection_z[np.where(tracks_chunk[:]['n_hits_dut_%i' % actual_dut] == 1)] | ||
| intersection_x_cs_2 = intersection_x[np.where(tracks_chunk[:]['n_hits_dut_%i' % actual_dut] == 2)] |
There was a problem hiding this comment.
Too much copy paste is a sign that it is time for a for loop and/or helper function
testbeam_analysis/result_analysis.py
Outdated
| prealignment=prealignment, | ||
| inverse=True) | ||
|
|
||
| intersection_x_cs_3_local, intersection_y_cs_3_local, intersection_z_cs_3_local = geometry_utils.apply_alignment(intersection_x_cs_3, intersection_y_cs_3, intersection_z_cs_3, |
There was a problem hiding this comment.
Too much copy paste is a sign that it is time for a for loop and/or helper function
testbeam_analysis/result_analysis.py
Outdated
| projection_x_1 = np.mod(intersection_x_cs_1_local, np.array([actual_pixel_size[0]] * len(intersection_x_cs_1_local))) | ||
| projection_y_1 = np.mod(intersection_y_cs_1_local, np.array([actual_pixel_size[1]] * len(intersection_y_cs_1_local))) | ||
| projection_x_2 = np.mod(intersection_x_cs_2_local, np.array([actual_pixel_size[0]] * len(intersection_x_cs_2_local))) | ||
| projection_y_2 = np.mod(intersection_y_cs_2_local, np.array([actual_pixel_size[1]] * len(intersection_y_cs_2_local))) |
There was a problem hiding this comment.
Too much copy paste is a sign that it is time for a for loop and/or helper function
testbeam_analysis/result_analysis.py
Outdated
| projection_x_1_hist, edges_x = np.histogram(projection_x_1, bins=n_bins[0], range=[0.0, actual_pixel_size[0]]) | ||
| projection_y_1_hist, edges_y = np.histogram(projection_y_1, bins=n_bins[1], range=[0.0, actual_pixel_size[1]]) | ||
| projection_x_2_hist, _ = np.histogram(projection_x_2, bins=n_bins[0], range=[0.0, actual_pixel_size[0]]) | ||
| projection_y_2_hist, _ = np.histogram(projection_y_2, bins=n_bins[1], range=[0.0, actual_pixel_size[1]]) |
There was a problem hiding this comment.
One could store these in a list and init in a loop. Much more compact
testbeam_analysis/result_analysis.py
Outdated
| projection_y_1_hist += np.histogram(projection_y_1, bins=edges_y)[0] | ||
| projection_x_2_hist += np.histogram(projection_x_2, bins=edges_x)[0] | ||
| projection_y_2_hist += np.histogram(projection_y_2, bins=edges_y)[0] | ||
| projection_x_3_hist += np.histogram(projection_x_3, bins=edges_x)[0] |
There was a problem hiding this comment.
Other data structure + for-loop
DavidLP
left a comment
There was a problem hiding this comment.
The coverage decreased since there is no unit test for the new function. Can you please add one?
| intersections = np.column_stack((tracks_chunk[:]['offset_0'], tracks_chunk[:]['offset_1'], tracks_chunk[:]['offset_2'])) | ||
|
|
||
| # arrays for intersections for different CS | ||
| intersections_cs_1 = np.zeros(shape=(3, len(n_hits[n_hits == 1]))) |
There was a problem hiding this comment.
For the number of entries of a numpy array the shape attribute should be used.
| inverse=True) | ||
| for cs in range(4): | ||
| if use_prealignment: | ||
| intersections_cs_local[cs][0], intersections_cs_local[cs][1], intersections_cs_local[cs][2] = geometry_utils.apply_alignment(intersections_cs[cs][0], intersections_cs[cs][1], intersections_cs[cs][2], |
There was a problem hiding this comment.
It might be beneficial here to shorten the variable names for readability and PEP8 compliance. maybe intersections_cs_local´--> inters_cs_loc
| projection_y_4 = np.mod(intersection_y_cs_4_local, np.array([actual_pixel_size[1]] * len(intersection_y_cs_4_local))) | ||
|
|
||
| # histogram intersections and CS (for calculation of effective pitch) | ||
| projections_cs = [np.zeros_like(intersections_cs_1), np.zeros_like(intersections_cs_2), |
| projection_3_2d_hist, _, _ = np.histogram2d(x=projection_x_3, y=projection_y_3, bins=[edges_x, edges_y]) | ||
| projection_4_2d_hist, _, _ = np.histogram2d(x=projection_x_4, y=projection_y_4, bins=[edges_x, edges_y]) | ||
| for cs in range(4): | ||
| if cs == 0: |
There was a problem hiding this comment.
Why is this special case handling needed? edges_x, edges_y seems constant for all cs
This adds In-pixel hit distributions for CS between 1- 4. Addidionally the calculation of the effective CS-1-pitch using the CS distribution is estimated which can be used for calculating the pointing resolution.