Skip to content

Commit 4ad86c0

Browse files
committed
Subtract sample run by empty can
1 parent d6b516c commit 4ad86c0

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

src/ess/dream/io/geant4.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from scippneutron.metadata import ESS_SOURCE
99

1010
from ess.powder.types import (
11+
BackgroundRun,
1112
Beamline,
1213
CalibratedBeamline,
1314
CalibratedDetector,
@@ -320,7 +321,7 @@ def LoadGeant4Workflow() -> sciline.Pipeline:
320321
Workflow for loading NeXus data.
321322
"""
322323
wf = GenericTofWorkflow(
323-
run_types=[SampleRun, VanadiumRun], monitor_types=[CaveMonitor]
324+
run_types=[SampleRun, VanadiumRun, BackgroundRun], monitor_types=[CaveMonitor]
324325
)
325326
wf.insert(extract_geant4_detector)
326327
wf.insert(load_geant4_csv)

src/ess/dream/workflow.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
from ess.powder.types import (
2121
AccumulatedProtonCharge,
22+
BackgroundRun,
2223
CaveMonitorPosition, # Should this be a DREAM-only parameter?
2324
MonitorType,
2425
PixelMaskFilename,
@@ -75,10 +76,13 @@ def default_parameters() -> dict:
7576
return {
7677
Position[snx.NXsample, SampleRun]: sample_position,
7778
Position[snx.NXsample, VanadiumRun]: sample_position,
79+
Position[snx.NXsample, BackgroundRun]: sample_position,
7880
Position[snx.NXsource, SampleRun]: source_position,
7981
Position[snx.NXsource, VanadiumRun]: source_position,
82+
Position[snx.NXsource, BackgroundRun]: source_position,
8083
AccumulatedProtonCharge[SampleRun]: charge,
8184
AccumulatedProtonCharge[VanadiumRun]: charge,
85+
AccumulatedProtonCharge[BackgroundRun]: charge,
8286
TofMask: None,
8387
WavelengthMask: None,
8488
TwoThetaMask: None,

src/ess/powder/correction.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
from ._util import event_or_outer_coord
1313
from .types import (
1414
AccumulatedProtonCharge,
15+
BackgroundRun,
16+
BackgroundSubtractedData,
17+
BackgroundSubtractedDataTwoTheta,
1518
CaveMonitor,
1619
DataWithScatteringCoordinates,
1720
FocussedDataDspacing,
@@ -155,7 +158,7 @@ def _normalize_by_vanadium(
155158

156159

157160
def normalize_by_vanadium_dspacing(
158-
data: FocussedDataDspacing[SampleRun],
161+
data: BackgroundSubtractedData[SampleRun],
159162
vanadium: FocussedDataDspacing[VanadiumRun],
160163
uncertainty_broadcast_mode: UncertaintyBroadcastMode,
161164
) -> IofDspacing:
@@ -185,7 +188,7 @@ def normalize_by_vanadium_dspacing(
185188

186189

187190
def normalize_by_vanadium_dspacing_and_two_theta(
188-
data: FocussedDataDspacingTwoTheta[SampleRun],
191+
data: BackgroundSubtractedDataTwoTheta[SampleRun],
189192
vanadium: FocussedDataDspacingTwoTheta[VanadiumRun],
190193
uncertainty_broadcast_mode: UncertaintyBroadcastMode,
191194
) -> IofDspacingTwoTheta:
@@ -335,6 +338,22 @@ def _shallow_copy(da: sc.DataArray) -> sc.DataArray:
335338
return out
336339

337340

341+
def subtract_background(
342+
data: FocussedDataDspacing[SampleRun],
343+
background: FocussedDataDspacing[BackgroundRun],
344+
) -> BackgroundSubtractedData[SampleRun]:
345+
return BackgroundSubtractedData[SampleRun](data.bins.concatenate(-background))
346+
347+
348+
def subtract_background_two_theta(
349+
data: FocussedDataDspacingTwoTheta[SampleRun],
350+
background: FocussedDataDspacingTwoTheta[BackgroundRun],
351+
) -> BackgroundSubtractedDataTwoTheta[SampleRun]:
352+
return BackgroundSubtractedDataTwoTheta[SampleRun](
353+
data.bins.concatenate(-background)
354+
)
355+
356+
338357
class RunNormalization(enum.Enum):
339358
"""Type of normalization applied to each run."""
340359

@@ -357,6 +376,8 @@ def insert_run_normalization(
357376

358377

359378
providers = (
379+
subtract_background,
380+
subtract_background_two_theta,
360381
normalize_by_proton_charge,
361382
normalize_by_vanadium_dspacing,
362383
normalize_by_vanadium_dspacing_and_two_theta,

src/ess/powder/types.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
TimeOfFlightLookupTableFilename = tof_t.TimeOfFlightLookupTableFilename
5959
SimulationResults = tof_t.SimulationResults
6060

61-
RunType = TypeVar("RunType", SampleRun, VanadiumRun)
61+
RunType = TypeVar("RunType", SampleRun, VanadiumRun, BackgroundRun)
6262
MonitorType = TypeVar("MonitorType", CaveMonitor, BunkerMonitor)
6363

6464

@@ -175,6 +175,16 @@ class NormalizedRunData(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
175175
"""Data that has been normalized by proton charge."""
176176

177177

178+
class BackgroundSubtractedData(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
179+
"""Data where background has been subtracted."""
180+
181+
182+
class BackgroundSubtractedDataTwoTheta(
183+
sciline.Scope[RunType, sc.DataArray], sc.DataArray
184+
):
185+
"""Data with 2theta bins where background has been subtracted."""
186+
187+
178188
PixelMaskFilename = NewType("PixelMaskFilename", str)
179189
"""Filename of a pixel mask."""
180190

0 commit comments

Comments
 (0)