Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More digi #46

Merged
merged 55 commits into from
Apr 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
73e64ba
Initial implementation of new digitization classes.
lucabaldini Apr 11, 2024
cb25732
Continued implementation of sparse readout class
chiaratomaiuolo Apr 11, 2024
921e568
Minor.
lucabaldini Apr 12, 2024
7693351
First complete implementation of the sparse readout.
lucabaldini Apr 12, 2024
aca4816
Started implementing circular readout
chiaratomaiuolo Apr 12, 2024
5cc029d
Merge conflicts fixed
chiaratomaiuolo Apr 12, 2024
b49776a
Minor.
lucabaldini Apr 12, 2024
1cf5489
Started working on the refactoring of the fileio.
lucabaldini Apr 12, 2024
1dc9b44
Fix for trigger id.
lucabaldini Apr 12, 2024
ca99f4b
Initial import.
lucabaldini Apr 12, 2024
2274f01
Old DigiEvent class removed and fixed unit tests
lucabaldini Apr 12, 2024
b0f714c
Old generic classes removed.
lucabaldini Apr 12, 2024
1dd58a8
Initial import.
lucabaldini Apr 12, 2024
06c8030
Old digi module split into digi and readout.
lucabaldini Apr 12, 2024
b3b7fb3
pylinted.
lucabaldini Apr 12, 2024
6d667dd
Started implementing circular readout
chiaratomaiuolo Apr 15, 2024
cd4a77c
Merge branch 'main' into more_digi
lucabaldini Apr 16, 2024
e406e34
Small refactoring.
lucabaldini Apr 16, 2024
37a95db
Minor.
lucabaldini Apr 16, 2024
2379b5b
finished testing conversion from logic coords to 7-adc coords
chiaratomaiuolo Apr 16, 2024
2f0c3a9
Implementing circular readout
chiaratomaiuolo Apr 17, 2024
77b5fe4
Minor.
lucabaldini Apr 19, 2024
28f27be
removed CircularROI class
chiaratomaiuolo Apr 19, 2024
398e746
minor
chiaratomaiuolo Apr 19, 2024
c92f9d4
Implemented DigiEventCircular ascii function
chiaratomaiuolo Apr 20, 2024
688f263
started implementing readout_strategy option for the simulation
chiaratomaiuolo Apr 22, 2024
c5f7013
Minor.
lucabaldini Apr 22, 2024
18de75e
started implementation of different DigiOutputFile(s) and started tes…
chiaratomaiuolo Apr 22, 2024
a63b459
continued implementing I/O for the different modes of readout
chiaratomaiuolo Apr 23, 2024
fff434c
continued implementing I/O for different readout types
chiaratomaiuolo Apr 23, 2024
eaf2793
Continued implementing classes for file I/O
chiaratomaiuolo Apr 23, 2024
7f6d16c
Continued implementing I/O facilities
chiaratomaiuolo Apr 23, 2024
ed9518c
Finished implementing I/O for every radout mode and tested the readin…
chiaratomaiuolo Apr 24, 2024
4c533ff
Minor
chiaratomaiuolo Apr 24, 2024
9359be4
Created DigiInputFileBase class
chiaratomaiuolo Apr 24, 2024
7559e3e
Modified run() function for different modes of readout
chiaratomaiuolo Apr 24, 2024
1ddfe5d
minor
chiaratomaiuolo Apr 24, 2024
13b5921
continued updating header in I/O files for every readout mode
chiaratomaiuolo Apr 24, 2024
8dedfed
minor
chiaratomaiuolo Apr 24, 2024
e0b0f88
minor
chiaratomaiuolo Apr 24, 2024
32b55c4
minor
chiaratomaiuolo Apr 29, 2024
c46036f
/minor/
chiaratomaiuolo Apr 29, 2024
460f241
minor
chiaratomaiuolo Apr 29, 2024
c4ba7ea
minor
chiaratomaiuolo Apr 29, 2024
9e05588
Implemented some plots for evaluating reconstruction
chiaratomaiuolo Apr 29, 2024
2b9eeef
minor
chiaratomaiuolo Apr 29, 2024
c0be1ef
minor
chiaratomaiuolo Apr 29, 2024
255fa85
created file for recon vs MC quantities evaluation
chiaratomaiuolo Apr 29, 2024
f0d4f26
minor
chiaratomaiuolo Apr 29, 2024
2854e39
Minor.
lucabaldini Apr 30, 2024
67e7f94
Merge branch 'more_digi' of github.com:lucabaldini/hexsample into mor…
lucabaldini Apr 30, 2024
a35f823
minor
chiaratomaiuolo Apr 30, 2024
6e21816
hexsample/bin/hxplots.py
chiaratomaiuolo Apr 30, 2024
34827bc
Fixed unit tests.
lucabaldini Apr 30, 2024
18dd12d
Updated release notes.
lucabaldini Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implemented DigiEventCircular ascii function
chiaratomaiuolo committed Apr 20, 2024
commit c92f9d42023893aecd26babd2a4d4720ab64daa3
63 changes: 20 additions & 43 deletions hexsample/digi.py
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
from loguru import logger
import numpy as np

from hexsample.hexagon import HexagonalGrid, HexagonalLayout
#from hexsample.readout import HexagonalReadoutCircular
from hexsample.pprint import AnsiFontEffect, ansi_format, space, line
from hexsample.roi import Padding, RegionOfInterest

@@ -289,64 +289,41 @@ class DigiEventCircular(DigiEventBase):
column: int
row: int


'''
def get_neighbors(self):
"""This function returns the offset coordinates of the signal pixel, that
is the highest pixel of the event (as first element), and its neighbors
(starting from the upper left, proceiding clockwisely).
The order of the coordinates corresponds in the arrays of pha to the right
value, in order to properly reconstruct the event.
"""
# Identifying the 6 neighbours of the central pixel and saving the signal pixels
# prepending the cooridnates of the highest one...
neighbors_coords = list(self.grid.neighbors(self.column, self.row)) #returns a list of tuples
# ...and prepending the highest pha pixel to the list...
neighbors_coords.insert(0, (self.column, self.row))
# ...dividing column and row coordinates in different arrays...
columns, rows = zip(*neighbors_coords)
columns, rows = np.array(columns), np.array(rows)
return columns, rows
'''
'''
def as_dict(self) -> dict:
"""Return the pixel content of the event in the form of a {(col, row): pha}
value.

This is useful to address the pixel content at a given coordinate. We refrain,
for the moment, from implementing a __call__() hook on top of this, as the
semantics would be fundamentally different from that implemented with a
rectangular ROI, where the access happen in ROI coordinates, and not in chip
coordinates, but we might want to come back to this.
def __post_init__(self) -> None:
"""Post-initialization code.
"""
columns, rows = self.get_neighbors()
return {(col, row): pha for col, row, pha in zip(columns, rows, self.pha)}
'''
if not len(self.pha) == 7:
raise RuntimeError(f'{self.__class__.__name__} has {len(self.pha)} PHA values'
f'instead of {7}.')


'''
def ascii(self, pha_width: int = 5) -> str:
"""Ascii representation.
"""Ascii representation.
In the specific case of this class, the ascii representation is simply a px
(that is the highest PHA pixel), because the neighbor position is not accessible
by the DigiEvent.
"""
columns, rows = self.get_neighbors()
pha_dict = self.as_dict()
fmt = f'%{pha_width}d'
cols = np.arange(columns.min(), columns.max() + 1)
cols = np.arange(self.column - 1, self.column + 2)
num_cols = cols[-1] - cols[0] + 1
rows = np.arange(rows.min(), rows.max() + 1)
rows = np.arange(self.row - 1, self.row + 2)
big_space = space(2 * pha_width + 1)
text = f'\n{big_space}'
text += ''.join([fmt % col for col in cols])
text += f'\n{big_space}+{line(pha_width * num_cols)}\n'
for row in rows:
text += f' {fmt % row} |'
for r in rows:
text += f' {fmt % r} |'
for col in cols:
try:
pha = fmt % pha_dict[(col, row)]
if col == self.column and r ==self.row:
pha = fmt % max(self.pha)
else:
pha = ' ' * pha_width
except KeyError:
pha = ' ' * pha_width
text += pha
text += f'\n{big_space}|\n'
return text
'''



3 changes: 2 additions & 1 deletion hexsample/readout.py
Original file line number Diff line number Diff line change
@@ -456,6 +456,7 @@ def read(self, timestamp: float, x: np.ndarray, y: np.ndarray, trg_threshold: fl
# See: https://stackoverflow.com/questions/70094914/max-on-collections-counter
coord_max = max(sparse_signal, key=sparse_signal.get)
col_max, row_max = coord_max
print(coord_max)
#... and converting it in ADC channel coordinates (value from 0 to 6)...
adc_max = self.adc_channel(*coord_max)
# ... creating a 7-elements array containing the PHA of the ADC channels from 0 to 6
@@ -476,4 +477,4 @@ def read(self, timestamp: float, x: np.ndarray, y: np.ndarray, trg_threshold: fl
# Do not forget to update the trigger_id!
self.trigger_id += 1
#The pha array is always in the order [pha(adc0), pha(adc1), pha(adc2), pha(adc3), pha(adc4), pha(adc5), pha(adc6)]
return DigiEventCircular(self.trigger_id, seconds, microseconds, livetime, pha, *coords)
return DigiEventCircular(self.trigger_id, seconds, microseconds, livetime, pha, *coord_max)
2 changes: 1 addition & 1 deletion tests/test_digi.py
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ def test_digitization_circular(layout: HexagonalLayout = HexagonalLayout.ODD_R,
x = np.append(x, np.full(num_pairs, x2))
y = np.append(y, np.full(num_pairs, y2))
event = readout.read(0., x, y, 100.) #this is a DigiEventCircular
#print(event.ascii())
print(event.ascii())

def test_digi_event_rectangular(min_col: int = 106, max_col: int = 113, min_row: int = 15,
max_row: int = 22, padding: Padding = Padding(1, 2, 3, 4)):