44import numpy as np
55import sciline
66import scipp as sc
7+ import scippnexus as snx
78
89from ess .powder .types import (
910 CalibratedDetector ,
1011 CalibrationData ,
1112 CalibrationFilename ,
1213 DetectorData ,
1314 Filename ,
14- NeXusDetector ,
15+ NeXusComponent ,
1516 NeXusDetectorName ,
16- NeXusSample ,
17- NeXusSource ,
17+ Position ,
1818 RunType ,
1919)
20+ from ess .reduce .nexus .types import CalibratedBeamline
2021from ess .reduce .nexus .workflow import GenericNeXusWorkflow
2122
2223MANTLE_DETECTOR_ID = sc .index (7 )
@@ -60,9 +61,23 @@ def load_geant4_csv(file_path: Filename[RunType]) -> AllRawDetectors[RunType]:
6061
6162def extract_geant4_detector (
6263 detectors : AllRawDetectors [RunType ], detector_name : NeXusDetectorName
63- ) -> NeXusDetector [ RunType ]:
64+ ) -> NeXusComponent [ snx . NXdetector , RunType ]:
6465 """Extract a single detector from a loaded GEANT4 simulation."""
65- return NeXusDetector [RunType ](detectors ["instrument" ][detector_name ])
66+ return NeXusComponent [snx .NXdetector , RunType ](
67+ detectors ["instrument" ][detector_name ]
68+ )
69+
70+
71+ def get_calibrated_geant4_detector (
72+ detector : NeXusComponent [snx .NXdetector , RunType ],
73+ ) -> CalibratedDetector [RunType ]:
74+ """
75+ Replacement for :py:func:`ess.reduce.nexus.workflow.get_calibrated_detector`.
76+
77+ Since the Geant4 detectors already have computed positions as well as logical shape,
78+ this just extracts the relevant event data.
79+ """
80+ return detector ['events' ].copy (deep = False )
6681
6782
6883def _load_raw_events (file_path : str ) -> sc .DataArray :
@@ -171,21 +186,21 @@ def geant4_load_calibration(filename: CalibrationFilename) -> CalibrationData:
171186
172187
173188def dummy_assemble_detector_data (
174- detector : CalibratedDetector [RunType ],
189+ detector : CalibratedBeamline [RunType ],
175190) -> DetectorData [RunType ]:
176191 """Dummy assembly of detector data, detector already contains neutron data."""
177192 return DetectorData [RunType ](detector )
178193
179194
180- def dummy_source () -> NeXusSource [ RunType ]:
181- return NeXusSource [ RunType ](
182- sc .DataGroup ( position = sc . vector ([np .nan , np .nan , np .nan ], unit = "mm" ) )
195+ def dummy_source_position () -> Position [ snx . NXsource , RunType ]:
196+ return Position [ snx . NXsource , RunType ](
197+ sc .vector ([np .nan , np .nan , np .nan ], unit = "mm" )
183198 )
184199
185200
186- def dummy_sample () -> NeXusSample [ RunType ]:
187- return NeXusSample [ RunType ](
188- sc .DataGroup ( position = sc . vector ([np .nan , np .nan , np .nan ], unit = "mm" ) )
201+ def dummy_sample_position () -> Position [ snx . NXsample , RunType ]:
202+ return Position [ snx . NXsample , RunType ](
203+ sc .vector ([np .nan , np .nan , np .nan ], unit = "mm" )
189204 )
190205
191206
@@ -197,7 +212,8 @@ def LoadGeant4Workflow() -> sciline.Pipeline:
197212 wf .insert (extract_geant4_detector )
198213 wf .insert (load_geant4_csv )
199214 wf .insert (geant4_load_calibration )
215+ wf .insert (get_calibrated_geant4_detector )
200216 wf .insert (dummy_assemble_detector_data )
201- wf .insert (dummy_source )
202- wf .insert (dummy_sample )
217+ wf .insert (dummy_source_position )
218+ wf .insert (dummy_sample_position )
203219 return wf
0 commit comments