Skip to content

Commit bf88ee2

Browse files
Merge pull request #68 from cdunn314/livecount_time
Get live count time and real count time from Compass root file
2 parents 44cdda3 + 242345c commit bf88ee2

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

libra_toolbox/neutron_detection/activation_foils/compass.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pandas as pd
55
from typing import Tuple, Dict
66
import datetime
7+
import uproot
78

89

910
def get_channel(filename):
@@ -138,3 +139,18 @@ def get_start_stop_time(directory: str) -> Tuple[datetime.datetime, datetime.dat
138139
raise ValueError(f"Could not find time.start or time.stop in file {info_file}.")
139140
else:
140141
return start_time, stop_time
142+
143+
144+
def get_live_time_from_root(filename, channel: int):
145+
"""
146+
Gets live and real count time from Compass root file.
147+
Times are given in seconds.
148+
Live time is defined as the difference between the actual time that
149+
a count is occurring and the "dead time," in which the output of detector
150+
pulses is saturated such that additional signals cannot be processed.
151+
"""
152+
153+
with uproot.open(filename) as root_file:
154+
live_count_time = root_file[f"LiveTime_{channel}"].members["fMilliSec"] / 1000
155+
real_count_time = root_file[f"RealTime_{channel}"].members["fMilliSec"] / 1000
156+
return live_count_time, real_count_time

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ description = "Design and analysis tools for LIBRA project"
1515
license = {file = "LICENSE"}
1616
requires-python = ">=3.10"
1717
dynamic = ["version"]
18-
dependencies = ["numpy", "pint", "scipy", "matplotlib", "sympy", "pandas", "h5py"]
18+
dependencies = ["numpy", "pint", "scipy", "matplotlib", "sympy", "pandas", "h5py", "uproot"]
1919

2020
[project.optional-dependencies]
2121
neutronics = ["openmc-data-downloader"]
Binary file not shown.
Binary file not shown.

test/neutron_detection/test_compass.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,44 @@ def test_get_start_stop_time_with_notime(tmpdir):
234234
# run
235235
with pytest.raises(ValueError, match="Could not find time.start or time.stop"):
236236
compass.get_start_stop_time(tmpdir2)
237+
238+
239+
@pytest.mark.parametrize(
240+
"root_filename, channel, live_time, real_time",
241+
[
242+
(
243+
Path(__file__).parent
244+
/ "compass_test_data/times/Hcompass_Co60_20241107.root",
245+
1,
246+
808.305,
247+
900.108,
248+
),
249+
(
250+
Path(__file__).parent
251+
/ "compass_test_data/times/Hcompass_Co60_20241107.root",
252+
2,
253+
896.374,
254+
900.108,
255+
),
256+
(
257+
Path(__file__).parent
258+
/ "compass_test_data/times/Hcompass_Zirconium_20250319.root",
259+
4,
260+
35654.785,
261+
39722.502,
262+
),
263+
(
264+
Path(__file__).parent
265+
/ "compass_test_data/times/Hcompass_Zirconium_20250319.root",
266+
5,
267+
39678.458,
268+
39722.502,
269+
),
270+
],
271+
)
272+
def test_get_live_time_from_root(root_filename, channel, live_time, real_time):
273+
live_time_out, real_time_out = compass.get_live_time_from_root(
274+
root_filename, channel
275+
)
276+
assert live_time_out == live_time
277+
assert real_time_out == real_time

0 commit comments

Comments
 (0)