11# SPDX-License-Identifier: BSD-3-Clause
2- # Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
3-
4- from __future__ import annotations
2+ # Copyright (c) 2025 Scipp contributors (https://github.com/scipp)
53
64import itertools
75
1210
1311from ess .powder import providers as powder_providers
1412from ess .powder import with_pixel_mask_filenames
15- from ess .powder .correction import (
16- RunNormalization ,
17- insert_run_normalization ,
18- )
13+ from ess .powder .correction import RunNormalization , insert_run_normalization
1914from ess .powder .types import (
2015 AccumulatedProtonCharge ,
16+ BunkerMonitor ,
2117 CaveMonitor ,
2218 CaveMonitorPosition , # Should this be a DREAM-only parameter?
2319 EmptyCanRun ,
3228 VanadiumRun ,
3329 WavelengthMask ,
3430)
35- from ess .reduce import time_of_flight
36- from ess .reduce .nexus .types import NeXusName
31+ from ess .reduce .nexus .types import DetectorBankSizes , NeXusName
3732from ess .reduce .parameter import parameter_mappers
3833from ess .reduce .time_of_flight import GenericTofWorkflow
3934from ess .reduce .workflow import register_workflow
4439 prepare_reduced_empty_can_subtracted_tof_cif ,
4540 prepare_reduced_tof_cif ,
4641)
47- from .io .geant4 import LoadGeant4Workflow
42+ from .io .geant4 import providers as geant4_providers
4843from .parameters import typical_outputs
4944
45+ DETECTOR_BANK_SIZES = {
46+ "endcap_backward_detector" : {
47+ "strip" : 16 ,
48+ "wire" : 16 ,
49+ "module" : 11 ,
50+ "segment" : 28 ,
51+ "counter" : 2 ,
52+ },
53+ "endcap_forward_detector" : {
54+ "strip" : 16 ,
55+ "wire" : 16 ,
56+ "module" : 5 ,
57+ "segment" : 28 ,
58+ "counter" : 2 ,
59+ },
60+ "mantle_detector" : {
61+ "wire" : 32 ,
62+ "module" : 5 ,
63+ "segment" : 6 ,
64+ "strip" : 256 ,
65+ "counter" : 2 ,
66+ },
67+ "high_resolution_detector" : {"strip" : 32 , "other" : - 1 },
68+ "sans_detector" : {"strip" : 32 , "other" : - 1 },
69+ }
70+
5071
5172def _get_lookup_table_filename_from_configuration (
5273 configuration : InstrumentConfiguration ,
@@ -64,52 +85,58 @@ def _get_lookup_table_filename_from_configuration(
6485 return TimeOfFlightLookupTableFilename (out )
6586
6687
67- _dream_providers = (
88+ def _collect_reducer_software () -> ReducerSoftware :
89+ return ReducerSoftware (
90+ [
91+ Software .from_package_metadata ('essdiffraction' ),
92+ Software .from_package_metadata ('scippneutron' ),
93+ Software .from_package_metadata ('scipp' ),
94+ ]
95+ )
96+
97+
98+ def DreamWorkflow () -> sciline .Pipeline :
99+ """
100+ Dream generic workflow with default parameters.
101+ The workflow is based on the GenericTofWorkflow.
102+ It can load data from a NeXus file recorded on the DREAM instrument, and can
103+ compute time-of-flight for the neutron events.
104+
105+ It can be used as is, or as a base for more specific workflows, such as
106+ ``DreamPowderWorkflow``.
107+ """
108+ wf = GenericTofWorkflow (
109+ run_types = [SampleRun , VanadiumRun , EmptyCanRun ],
110+ monitor_types = [BunkerMonitor , CaveMonitor ],
111+ )
112+ wf [DetectorBankSizes ] = DETECTOR_BANK_SIZES
113+ wf [NeXusName [BunkerMonitor ]] = "monitor_bunker"
114+ wf [NeXusName [CaveMonitor ]] = "monitor_cave"
115+ wf .insert (_get_lookup_table_filename_from_configuration )
116+ wf [ReducerSoftware ] = _collect_reducer_software ()
117+ return wf
118+
119+
120+ _cif_providers = (
68121 prepare_reduced_tof_cif ,
69122 prepare_reduced_empty_can_subtracted_tof_cif ,
70- _get_lookup_table_filename_from_configuration ,
71123)
72124
73125parameter_mappers [PixelMaskFilename ] = with_pixel_mask_filenames
74126
75127
76128def default_parameters () -> dict :
77- # Quantities not available in the simulated data
78- sample_position = sc .vector ([0.0 , 0.0 , 0.0 ], unit = "mm" )
79- source_position = sc .vector ([- 3.478 , 0.0 , - 76550 ], unit = "mm" )
80- charge = sc .scalar (1.0 , unit = "µAh" )
81129 return {
82130 KeepEvents [SampleRun ]: KeepEvents [SampleRun ](True ),
83131 KeepEvents [VanadiumRun ]: KeepEvents [VanadiumRun ](False ),
84132 KeepEvents [EmptyCanRun ]: KeepEvents [EmptyCanRun ](True ),
85- Position [snx .NXsample , SampleRun ]: sample_position ,
86- Position [snx .NXsample , VanadiumRun ]: sample_position ,
87- Position [snx .NXsample , EmptyCanRun ]: sample_position ,
88- Position [snx .NXsource , SampleRun ]: source_position ,
89- Position [snx .NXsource , VanadiumRun ]: source_position ,
90- Position [snx .NXsource , EmptyCanRun ]: source_position ,
91- AccumulatedProtonCharge [SampleRun ]: charge ,
92- AccumulatedProtonCharge [VanadiumRun ]: charge ,
93- AccumulatedProtonCharge [EmptyCanRun ]: charge ,
94133 TofMask : None ,
95134 WavelengthMask : None ,
96135 TwoThetaMask : None ,
97- CaveMonitorPosition : sc .vector ([0.0 , 0.0 , - 4220.0 ], unit = 'mm' ),
98136 CIFAuthors : CIFAuthors ([]),
99- ReducerSoftware : _collect_reducer_software (),
100137 }
101138
102139
103- def _collect_reducer_software () -> ReducerSoftware :
104- return ReducerSoftware (
105- [
106- Software .from_package_metadata ('essdiffraction' ),
107- Software .from_package_metadata ('scippneutron' ),
108- Software .from_package_metadata ('scipp' ),
109- ]
110- )
111-
112-
113140def DreamPowderWorkflow (* , run_norm : RunNormalization ) -> sciline .Pipeline :
114141 """
115142 Dream powder workflow with default parameters.
@@ -124,14 +151,11 @@ def DreamPowderWorkflow(*, run_norm: RunNormalization) -> sciline.Pipeline:
124151 :
125152 A workflow object for DREAM.
126153 """
127- wf = GenericTofWorkflow ( run_types = [ SampleRun ], monitor_types = [ CaveMonitor ] )
128- for provider in itertools .chain (powder_providers , _dream_providers ):
154+ wf = DreamWorkflow ( )
155+ for provider in itertools .chain (powder_providers , _cif_providers ):
129156 wf .insert (provider )
130- wf [NeXusName [CaveMonitor ]] = "monitor_cave"
131157 insert_run_normalization (wf , run_norm )
132- for key , value in itertools .chain (
133- default_parameters ().items (), time_of_flight .default_parameters ().items ()
134- ):
158+ for key , value in default_parameters ().items ():
135159 wf [key ] = value
136160 wf .typical_outputs = typical_outputs
137161 return wf
@@ -151,14 +175,33 @@ def DreamGeant4Workflow(*, run_norm: RunNormalization) -> sciline.Pipeline:
151175 :
152176 A workflow object for DREAM.
153177 """
154- wf = LoadGeant4Workflow ()
155- for provider in itertools .chain (powder_providers , _dream_providers ):
178+ wf = DreamWorkflow ()
179+ for provider in itertools .chain (geant4_providers , powder_providers , _cif_providers ):
156180 wf .insert (provider )
157181 insert_run_normalization (wf , run_norm )
158- for key , value in itertools .chain (
159- default_parameters ().items (), time_of_flight .default_parameters ().items ()
160- ):
182+ for key , value in default_parameters ().items ():
183+ wf [key ] = value
184+
185+ # Quantities not available in the simulated data
186+ sample_position = sc .vector ([0.0 , 0.0 , 0.0 ], unit = "mm" )
187+ source_position = sc .vector ([- 3.478 , 0.0 , - 76550 ], unit = "mm" )
188+ charge = sc .scalar (1.0 , unit = "µAh" )
189+
190+ additional_parameters = {
191+ Position [snx .NXsample , SampleRun ]: sample_position ,
192+ Position [snx .NXsample , VanadiumRun ]: sample_position ,
193+ Position [snx .NXsample , EmptyCanRun ]: sample_position ,
194+ Position [snx .NXsource , SampleRun ]: source_position ,
195+ Position [snx .NXsource , VanadiumRun ]: source_position ,
196+ Position [snx .NXsource , EmptyCanRun ]: source_position ,
197+ AccumulatedProtonCharge [SampleRun ]: charge ,
198+ AccumulatedProtonCharge [VanadiumRun ]: charge ,
199+ AccumulatedProtonCharge [EmptyCanRun ]: charge ,
200+ CaveMonitorPosition : sc .vector ([0.0 , 0.0 , - 4220.0 ], unit = 'mm' ),
201+ }
202+ for key , value in additional_parameters .items ():
161203 wf [key ] = value
204+
162205 wf .typical_outputs = typical_outputs
163206 return wf
164207
@@ -195,5 +238,7 @@ def DreamGeant4ProtonChargeWorkflow() -> sciline.Pipeline:
195238 'DreamGeant4MonitorIntegratedWorkflow' ,
196239 'DreamGeant4ProtonChargeWorkflow' ,
197240 'DreamGeant4Workflow' ,
241+ 'DreamPowderWorkflow' ,
242+ 'DreamWorkflow' ,
198243 'default_parameters' ,
199244]
0 commit comments