From 5c2c0770a90d45e1e7cf6526a47d907522508f71 Mon Sep 17 00:00:00 2001 From: menzel Date: Sun, 30 Aug 2026 12:46:12 +0200 Subject: [PATCH] fix(filters): use the measured thicknesses and keep calibration foils out of fil_trans Two ways the filter table disagreed with filter.mac rev 1.19. The Si thicknesses were nominal where spec used values measured at 18.58 keV: 400/200/3200/100/1600/800 against 345.6/234.6/3303/137.5/ 1661.5/833.8. Si100 vs Si137.5 is 37% out, and at 17 keV the pair Si200+Si1600 gives T=0.060 where the measured Si234.6+Si1661.5 gives 0.052 -- a 16% error, larger than any distinction the search was trying to make between neighbouring combinations. The Zr and Cu calibration foils were selectable. filter.mac flagged them disabled so that selection by transmission could not pick them, and at 17 keV fil_trans(0.05) duly returned 5246 -- a combination built on the Zr foil, 1 keV below its K edge, where its transmission moves with any small change in energy. They are excluded through a new _EXCLUDE_FROM_SEARCH rather than by clearing their 'enabled' flag, because those two things are not the same and the flag is load-bearing elsewhere: _fil_trans_report substitutes T=1.0 for a disabled position, so clearing the flag would have made the report silently ignore a foil parked in the beam -- precisely the state an edge scan puts it in. The foils stay enabled, stay addressable via fil_comb as they were in spec, and are skipped only by the automatic search. At 17 keV fil_trans(0.05) now returns 2146 (Si345.6 + Ti200 + Ti20, T=0.0494) and fil_trans(0.01) returns 2234 (T=0.0099), both matching an independent calculation over the same CXRO tables. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_017kLGTqTyXzTT4swt3CfTkV --- .../plugins/cSAXS/filter_transmission.py | 53 ++++++++++++++----- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/csaxs_bec/bec_ipython_client/plugins/cSAXS/filter_transmission.py b/csaxs_bec/bec_ipython_client/plugins/cSAXS/filter_transmission.py index 3ca0f475..29e10193 100644 --- a/csaxs_bec/bec_ipython_client/plugins/cSAXS/filter_transmission.py +++ b/csaxs_bec/bec_ipython_client/plugins/cSAXS/filter_transmission.py @@ -74,19 +74,30 @@ class cSAXSFilterTransmission: # ----------------------------------------- # Exposure-box filter configuration (4 x 6) # - # Current hardware (per your message): - # Unit 1 (filter_array_1_x): out, Si400, Ge300, Ti800, Zr20 - # Unit 2 (filter_array_2_x): out, Si200, Si3200, Ti400, Cu20 - # Unit 3 (filter_array_3_x): out, Si100, Si1600, Ti200, Ti3200, Fe5 - # Unit 4 (filter_array_4_x): out, Si50, Si800, Ti100, Ti1600, Ti20 + # Thicknesses are the values from filter.mac rev 1.19, i.e. effective + # thicknesses measured at 18.58 keV rather than nominal foil thicknesses. + # They are used at every energy, which assumes the tabulated attenuation + # lengths are right and only the thickness was uncertain -- the same + # assumption spec made. The odd Si values are measurements, not typos. + # + # Unit 1 (filter_array_1_x): out, Si345.6, Ge300, Ti800, Zr20 + # Unit 2 (filter_array_2_x): out, Si234.6, Si3303, Ti400, Cu20 + # Unit 3 (filter_array_3_x): out, Si137.5, Si1661.5, Ti200, Ti3200, Fe5 + # Unit 4 (filter_array_4_x): out, Si50, Si833.8, Ti100, Ti1600, Ti20 # # Positions 1..6 = [out, m1, m2, m3, m4, m5] # Each entry: ((mat1, th1_um), (mat2, th2_um), enabled_bool) + # + # 'enabled' means the position exists and its transmission can be computed. + # Keeping the Zr/Cu calibration foils enabled is deliberate: they are real + # filters, so _fil_trans_report must account for them when one is parked in + # the beam for an edge scan. Excluding them from automatic selection is a + # separate concern -- see _EXCLUDE_FROM_SEARCH. # ----------------------------------------- _FILTERS: List[Tuple[Tuple[str, float], Tuple[str, float], bool]] = [ # Unit 1 (("none", 0.0), ("none", 0.0), True), # out - (("si", 400.0), ("none", 0.0), True), # Si400 + (("si", 345.6), ("none", 0.0), True), # Si345.6 (("ge", 300.0), ("none", 0.0), True), # Ge300 (("ti", 800.0), ("none", 0.0), True), # Ti800 (("zr", 20.0), ("none", 0.0), True), # Zr20 @@ -94,16 +105,16 @@ class cSAXSFilterTransmission: # Unit 2 (("none", 0.0), ("none", 0.0), True), # out - (("si", 200.0), ("none", 0.0), True), # Si200 - (("si", 3200.0), ("none", 0.0), True), # Si3200 + (("si", 234.6), ("none", 0.0), True), # Si234.6 + (("si", 3303.0), ("none", 0.0), True), # Si3303 (("ti", 400.0), ("none", 0.0), True), # Ti400 (("cu", 20.0), ("none", 0.0), True), # Cu20 (("none", 0.0), ("none", 0.0), False), # unused # Unit 3 (("none", 0.0), ("none", 0.0), True), # out - (("si", 100.0), ("none", 0.0), True), # Si100 - (("si", 1600.0), ("none", 0.0), True), # Si1600 + (("si", 137.5), ("none", 0.0), True), # Si137.5 + (("si", 1661.5), ("none", 0.0), True), # Si1661.5 (("ti", 200.0), ("none", 0.0), True), # Ti200 (("ti", 3200.0), ("none", 0.0), True), # Ti3200 (("fe", 5.0), ("none", 0.0), False), # Fe5 (disabled unless data file provided) @@ -111,12 +122,20 @@ class cSAXSFilterTransmission: # Unit 4 (("none", 0.0), ("none", 0.0), True), # out (("si", 50.0), ("none", 0.0), True), # Si50 - (("si", 800.0), ("none", 0.0), True), # Si800 + (("si", 833.8), ("none", 0.0), True), # Si833.8 (("ti", 100.0), ("none", 0.0), True), # Ti100 (("ti", 1600.0), ("none", 0.0), True), # Ti1600 (("ti", 20.0), ("none", 0.0), True), # Ti20 ] + # Calibration foils, not attenuators. filter.mac flagged these "disabled" so + # that selection by transmission would not pick them, while leaving them + # directly addressable via fil_comb -- they are exactly what you park in the + # beam for a K-edge scan. Zr in particular has its edge at 18.0 keV, so near + # that energy its transmission moves with any small energy change. + # (unit, position), both 1-based. + _EXCLUDE_FROM_SEARCH = frozenset({(1, 5), (2, 5)}) # Zr20, Cu20 + _UNITS = 4 _PER_UNIT = 6 @@ -520,10 +539,16 @@ class cSAXSFilterTransmission: for u in range(self._UNITS) ] - # Precompute per-position transmissions + # Precompute per-position transmissions. Positions excluded from the + # search are treated exactly like disabled ones here, i.e. skipped. per_pos_T: List[List[Optional[float]]] = [ - [self._position_transmission(pos_entry, energy_kev) for pos_entry in unit] - for unit in units + [ + None + if (u + 1, i + 1) in self._EXCLUDE_FROM_SEARCH + else self._position_transmission(pos_entry, energy_kev) + for i, pos_entry in enumerate(unit) + ] + for u, unit in enumerate(units) ] combos: List[dict] = []