Skip to content

Commit

Permalink
Feature/371 z2beta2 sh12a (#372)
Browse files Browse the repository at this point in the history
* add new detectors

* Fix missing units in plots from new .bdo file.
  • Loading branch information
nbassler authored Jan 2, 2021
1 parent 9211cee commit 6cdcad7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
24 changes: 22 additions & 2 deletions pymchelper/readers/shieldhit/reader_bdo2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def read_data(self, estimator):
token_id, token_type, payload_len, raw_payload = token

payload = [None] * payload_len
_has_geo_units_in_ascii = False

# decode all strings (currently there will never be more than one per token)
if 'S' in token_type.decode('ASCII'):
Expand Down Expand Up @@ -73,11 +74,21 @@ def read_data(self, estimator):
estimator.y = estimator.y._replace(max_val=payload[1])
estimator.z = estimator.z._replace(max_val=payload[2])

if token_id == SHBDOTagID.SHBDO_GEO_UNITIDS:
if token_id == SHBDOTagID.SHBDO_GEO_UNITIDS and not _has_geo_units_in_ascii:
estimator.x = estimator.x._replace(unit=unit_name_from_unit_id.get(payload[0], ""))
estimator.y = estimator.y._replace(unit=unit_name_from_unit_id.get(payload[1], ""))
estimator.z = estimator.z._replace(unit=unit_name_from_unit_id.get(payload[2], ""))

# Units may also be given as pure ASCII directly from SHIELD-HIT12A new .bdo format.
# If this is available, then use those embedded in the .bdo file, instead of pymchelper setting them.
if token_id == SHBDOTagID.SHBDO_GEO_UNITS:
_units = payload.split(";")
if len(_units) == 3:
estimator.x = estimator.x._replace(unit=_units[0])
estimator.y = estimator.y._replace(unit=_units[1])
estimator.z = estimator.z._replace(unit=_units[2])
_has_geo_units_in_ascii = True

# detector type
if token_id == SHBDOTagID.SHBDO_PAG_TYPE:
# check if detector type attribute present, if yes, then create new page
Expand Down Expand Up @@ -112,15 +123,24 @@ def read_data(self, estimator):
logger.debug("Setting page.{} = {}".format(page_name_from_bdotag[token_id], payload))
setattr(estimator.pages[-1], page_name_from_bdotag[token_id], payload)

# Check if we have differential scoring, i.e. data dimension is larger than 1:
for page in estimator.pages:
diff_level_1_size = getattr(page, 'dif_size', [0, 0])[0]
if diff_level_1_size > 1 and hasattr(page, 'dif_start') and hasattr(page, 'dif_stop'):
page.diff_axis1 = MeshAxis(n=diff_level_1_size,
min_val=page.dif_start[0],
max_val=page.dif_stop[0],
name="",
unit="",
unit=page.diff_units.split(";")[0],
binning=MeshAxis.BinningType.linear)

# Copy the SH12A specific units into the general placeholders:
for page in estimator.pages:
page.unit = page.data_unit
# in future, a user may optionially give a more specific name in SH12A detect.dat, which then
# may be written to the .bdo file. If the name is not set, use the official detector name instead:
if not page.name:
page.name = str(page.dettyp)

logger.debug("Done reading bdo file.")
return True
8 changes: 7 additions & 1 deletion pymchelper/shieldhit/detector/detector_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SHDetType(IntEnum):

dose_eqv = 40
eqv_dose = 41
user1 = 41
user1 = 42
user2 = 43
n_eqv_dose = 44 # Neutron equivalent dose, ICRP 103 protection quantity.

Expand All @@ -69,6 +69,12 @@ class SHDetType(IntEnum):
dose_av_q = 48
track_av_q = 49

z = 50
zeff = 51
zeff2beta2 = 52
tzeff2beta2 = 53
dzeff2beta2 = 54

let_bdo2016 = 120 # for differential scoring
angle_bdo2016 = 121 # for differential scoring
dose_gy_bdo2016 = 205
Expand Down

0 comments on commit 6cdcad7

Please sign in to comment.