Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ data/*
.ipynb_checkpoints/
notebooks/root_tests
visualization/SiphraReader/build
__pycache__/
*.pyc
# Do not ignore the sample_data. Track only .dat and .json files
!data/test_data
data/test_data/*
Expand Down
Binary file removed Output.root
Binary file not shown.
3 changes: 2 additions & 1 deletion analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .fit import *
from .calibration import *

__all__ = ['gauspeak', 'bg_exp', 'peak_and_bg', 'fit_peak_expbg']
__all__ = ['gauspeak', 'bg_exp', 'peak_and_bg', 'fit_peak_expbg', 'calibration_fit', 'calibrated_histogram', 'calibrated_acquisition' ]
Binary file removed analysis/__pycache__/__init__.cpython-314.pyc
Binary file not shown.
Binary file removed analysis/__pycache__/fit.cpython-314.pyc
Binary file not shown.
66 changes: 66 additions & 0 deletions analysis/calibration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import ROOT
import numpy as np

def calibration_fit(histogram, energy_ranges, energies):
"""Function to create a linear calibration fit based on a histogram. Returns slope and constant of linear fit.
Inputs: Histogram to base calibration on.
Ranges within which the peaks of the histogram are located, input as a list if tuples. AT LEAST 2 points.
Known energies of these peaks, in MeV."""

channels = []
for i in range(len(energy_ranges)):
cal_fit=ROOT.TF1("cal_fit_" + str(i), "gaus", energy_ranges[i][0], energy_ranges[i][1])
histogram.Fit(cal_fit, "R+S")
channels.append(cal_fit.GetParameter('Mean'))

channels = np.array(channels, dtype='float64')
energies = np.array(energies, dtype='float64')

graph = ROOT.TGraph(len(channels), channels, energies)
fit = ROOT.TF1("calib", "pol1", min(channels), max(channels))
graph.Fit(fit)

a = fit.GetParameter(1)
b = fit.GetParameter(0)

return [a, b]


def calibrated_histogram(linear_fit, acquisition, n_of_bins):
a = linear_fit[0]
b = linear_fit[1]
data_cal = a * (acquisition['s']/len(acquisition.active_chs)) + b

emax = a * n_of_bins + b
emin = b

hist_cal = ROOT.TH1F("h_cal", "Calibrated Spectrum", n_of_bins, emin, emax)
hist_cal.Fill(data_cal)

return(hist_cal)


def calibrated_acquisition(linear_fit, acquisition, n_of_bins):
a = linear_fit[0]
b = linear_fit[1]
data_cal = a * (acquisition['s']/len(acquisition.active_chs)) + b

emax = a * n_of_bins + b
emin = b

return(data_cal, emin, emax)


def energy_resolution(hist, peak_ranges, peak_energies):
"""Calculates energy resolution. Input peak_ranges as a list of tuples.
Outputs a list of resolutions for the different energies."""
resolutions = []
for i in range (len(peak_ranges)):
resolution_fit = ROOT.TF1("res_fit_" + str(i), "gaus", peak_ranges[i][0], peak_ranges[i][1])
hist.Fit(resolution_fit, "R+S")

std_dev = resolution_fit.GetParameter('Sigma')
resolution = (2.355 * std_dev)/peak_energies[i]
resolutions.append(resolution)

return resolutions
Binary file not shown.
607 changes: 64 additions & 543 deletions noteboks/baseline_subtraction.ipynb

Large diffs are not rendered by default.

893 changes: 893 additions & 0 deletions noteboks/energyResolution-Copy1.ipynb

Large diffs are not rendered by default.

142 changes: 0 additions & 142 deletions noteboks/root_tests/hist010.ipynb

This file was deleted.

44 changes: 0 additions & 44 deletions noteboks/root_tests/hist010_TH1_two_scales.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
783 changes: 783 additions & 0 deletions notebooks/Calibration_EnergyResolution.ipynb

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
695 changes: 695 additions & 0 deletions notebooks/Voltage_dependency.ipynb

Large diffs are not rendered by default.

File renamed without changes.
1,143 changes: 1,143 additions & 0 deletions notebooks/baseline_subtraction.ipynb

Large diffs are not rendered by default.

539 changes: 539 additions & 0 deletions notebooks/energyResolution-Copy1.ipynb

Large diffs are not rendered by default.

929 changes: 929 additions & 0 deletions notebooks/energyResolution-Copy2.ipynb

Large diffs are not rendered by default.

307 changes: 307 additions & 0 deletions notebooks/energyResolution.ipynb

Large diffs are not rendered by default.

687 changes: 687 additions & 0 deletions notebooks/gainTesting.ipynb

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
Binary file removed processing/__pycache__/__init__.cpython-314.pyc
Binary file not shown.
Binary file removed processing/__pycache__/metadata.cpython-314.pyc
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions processing/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Metadata:
active_chs: list[int]
sipm_chs: str | list[str]
n_events: int
source: str | None

class MetadataLoader:

Expand All @@ -29,10 +30,12 @@ def load(path: PathLike) -> Metadata:
@staticmethod
def _parse_v1(raw: dict) -> Metadata:
acq = raw["acquisition"]
source = raw["source"]["type"]

return Metadata(
exposure_sec=acq["exposure_sec"],
active_chs=[int(ch) for ch in acq["active_chs"]],
sipm_chs=acq["sipm_chs"],
n_events=acq["counts"],
source=source,
)
Binary file removed siphractl/__pycache__/d2a_lib.cpython-314.pyc
Binary file not shown.
112 changes: 0 additions & 112 deletions siphractl/siphra_controller.py

This file was deleted.

7 changes: 4 additions & 3 deletions siphractl/acquire.py → siphractrl/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ def parse_args():
help="A single string containing \'Background\' or any radioactive source present")
parser.add_argument("--source-description", type=str, default='[NOT SPECIFIED]',
help="A single string.")
parser.add_argument("--notes", type=str, default='[NONE]')
parser.add_argument("--notes", type=str, default='[NONE]',
help="A single string.")
parser.add_argument("--siphra-config-file", type=str, default='D2a/Ongoing.txt',
help="By default, it takes the \'Ongoing.txt\' file in the \'D2a\' directory and writes its contents to the metadata file. If any other configuration is used, the path to the text file containing it must be specified here.")
parser.add_argument("-s", "--size", type=int, default=4095,
help="([DO NOT CHANGE UNLESS CHANGING dma_to_raw_file SETTINGS]. Block size. Default is 4095.")
help="[DO NOT CHANGE UNLESS CHANGING dma_to_raw_file SETTINGS]. Block size. Default is 4095.")
parser.add_argument("--device", default="/dev/D2A_DMA",
help = "([DO NOT CHANGE UNLESS CHANGING dma_to_raw_file SETTINGS].")
help = "[DO NOT CHANGE UNLESS CHANGING dma_to_raw_file SETTINGS].")


return parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion siphractl/d2a_lib.py → siphractrl/d2a_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def compareUpTo(a, b, len):

class D2a:
'''
Contains all fucntions required to interface with hardware devices through OS.
Contains all functions required to interface with hardware devices through OS.
'''
def __init__(self, uio='/dev/uio0', spi='/dev/spi'):
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)

# Register 0x10: Summing channel configuration registers
SUMM_CHANNEL = BitStruct(
SUM_CHANNEL = BitStruct(
Padding(18),
'cal_select_channel' / Flag,
'qc_threshold' / BitsInteger(8),
Expand Down Expand Up @@ -88,4 +88,46 @@
'pu_mb' / Flag,
)

#
# Register 0x16
CAL_CTRL = BitStruct(
Padding(26),
'cal_cv_range_low' / Flag,
'cal_cv_range_mid' / Flag,
'cal_cv_range_high' / Flag,
'cal_trigger_select' / Flag,
'cal_mode' / BitsInteger(2)
)

# Register 0x17
ch_names = [f'CH_{n}_rofl' for n in range(16, 0, -1)]
READOUT_FIXED_LIST = BitStruct(
Padding(13),
'ADC_IN_rofl' / Flag,
'SUM_CH_rofl' / Flag,
*[name / Flag for name in ch_names],
'ADC_PT100_SENSE_rofl' / Flag,
)

# Register 0x18
READOUT_MODE = BitStruct(
Padding(17),
'int_hold_tune' / BitsInteger(5),
'int_hold_delay' / BitsInteger(4),
'int_hold_source' / BitsInteger(2),
'readout_list_mode' / BitsInteger(1),
'readout_en_spi_forced_start' / Flag,
'readout_en_ext_hold_start' / Flag,
'readout_en_int_hold_start' / Flag,
)

reg_str_lst = [*[CHANNEL]*16,
SUM_CHANNEL,
CHANNEL_CONFIG,
CHANNEL_CONTROL,
ADC_CONFIG,
CAL_DAC,
PD_MODULES,
CAL_CTRL,
READOUT_FIXED_LIST,
READOUT_MODE,
]
Loading