FilterEvents-v1.rst 6.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
.. algorithm::

.. summary::

.. alias::

.. properties::

Description
-----------

12
13
14
15
This algorithm filters events from an :ref:`EventWorkspace` to one or
multiple :ref:`EventWorkspaces <EventWorkspace>` according to an input
:ref:`SplittersWorkspace` containing a series of splitters (i.e.,
:ref:`splitting intervals <SplittingInterval>`).
16

17
Inputs
18
######
19

20
21
22
23
24
FilterEvents takes 2 mandatory input Workspaces and 1 optional
Workspace.  One of mandatory workspace is the :ref:`EventWorkspace`
where the events are filtered from.  The other mandatory workspace is
workspace containing splitters.  It can be either a MatrixWorkspace or
a :ref:`SplittersWorkspace <SplittersWorkspace>`.
25

26
27
28
29
30
31
The optional workspace is a :ref:`TableWorkspace <Table Workspaces>`
for information of splitters.

Algorithm :ref:`GenerateEventsFilter <algm-GenerateEventsFilter>`
creates both the :ref:`SplittersWorkspace <SplittersWorkspace>` and
splitter information workspace.
32
33
34
35
36


Splitters in relative time
==========================

37
38
39
As the SplittersWorkspace is in format of :ref:`MatrixWorkspace
<MatrixWorkspace>`, its time, i.e., the value in X vector, can be
relative time.
40
41
42
43
44
45
46
47

Property *RelativeTime* flags that the splitters' time is relative.
Property *FilterStartTime* specifies the starting time of the filter.
Or the shift of time of the splitters.
If it is not specified, then the algorithm will search for sample log *run_start*.

Outputs
#######
48
49
50
51
52
53

The output will be one or multiple workspaces according to the number of
index in splitters. The output workspace name is the combination of
parameter OutputWorkspaceBaseName and the index in splitter.

Calibration File
54
################
55
56
57
58
59
60
61
62
63
64
65
66
67

The calibration, or say correction, from the detector to sample must be
consider in fast log. Thus a calibration file is required. The math is

``TOF_calibrated = TOF_raw * correction(detector ID).``

The calibration is in column data format.

A reasonable approximation of the correction is

``correction(detector_ID) = L1/(L1+L2(detector_ID))``

Unfiltered Events
68
#################
69
70
71
72
73
74
75
76

Some events are not inside any splitters. They are put to a workspace
name ended with '\_unfiltered'.

If input property 'OutputWorkspaceIndexedFrom1' is set to True, then
this workspace shall not be outputed.

Difference from FilterByLogValue
77
################################
78
79
80
81
82
83
84
85
86
87
88
89
90
91

In FilterByLogValue(), EventList.splitByTime() is used.

In FilterEvents(), if FilterByPulse is selected true,
EventList.SplitByTime is called; otherwise, EventList.SplitByFullTime()
is called instead.

The difference between splitByTime and splitByFullTime is that
splitByTime filters events by pulse time, and splitByFullTime considers
both pulse time and TOF.

Therefore, FilterByLogValue is not suitable for fast log filtering.

Comparing with other event filtering algorithms
92
###############################################
93

94
95
Wiki page :ref:`EventFiltering` has a detailed introduction on event
filtering in MantidPlot.
96

Zhou, Wenduo's avatar
Zhou, Wenduo committed
97
98
99
Usage
-----

100
**Example - Filtering event without correction on TOF**
Zhou, Wenduo's avatar
Zhou, Wenduo committed
101
102
103
104

.. testcode:: FilterEventNoCorrection

    ws = Load(Filename='CNCS_7860_event.nxs')
105
    splitws, infows = GenerateEventsFilter(InputWorkspace=ws, UnitOfTime='Nanoseconds', LogName='SampleTemp',
Zhou, Wenduo's avatar
Zhou, Wenduo committed
106
            MinimumLogValue=279.9,  MaximumLogValue=279.98, LogValueInterval=0.01)
107

Zhou, Wenduo's avatar
Zhou, Wenduo committed
108
    FilterEvents(InputWorkspace=ws, SplitterWorkspace=splitws, InformationWorkspace=infows,
109
            OutputWorkspaceBaseName='tempsplitws',  GroupWorkspaces=True,
Zhou, Wenduo's avatar
Zhou, Wenduo committed
110
111
112
            FilterByPulseTime = False, OutputWorkspaceIndexedFrom1 = False,
            CorrectionToSample = "None", SpectrumWithoutDetector = "Skip", SplitSampleLogs = False,
            OutputTOFCorrectionWorkspace='mock')
113

Zhou, Wenduo's avatar
Zhou, Wenduo committed
114
115
116
    # Print result
    wsgroup = mtd["tempsplitws"]
    wsnames = wsgroup.getNames()
117
    for name in sorted(wsnames):
Zhou, Wenduo's avatar
Zhou, Wenduo committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
        tmpws = mtd[name]
        print "workspace %s has %d events" % (name, tmpws.getNumberEvents())


Output:

.. testoutput:: FilterEventNoCorrection

    workspace tempsplitws_0 has 124 events
    workspace tempsplitws_1 has 16915 events
    workspace tempsplitws_2 has 10009 events
    workspace tempsplitws_3 has 6962 events
    workspace tempsplitws_4 has 22520 events
    workspace tempsplitws_5 has 5133 events
    workspace tempsplitws_unfiltered has 50603 events


135
**Example - Filtering event by pulse time**
Zhou, Wenduo's avatar
Zhou, Wenduo committed
136
137
138
139

.. testcode:: FilterEventByPulseTime

    ws = Load(Filename='CNCS_7860_event.nxs')
140
    splitws, infows = GenerateEventsFilter(InputWorkspace=ws, UnitOfTime='Nanoseconds', LogName='SampleTemp',
Zhou, Wenduo's avatar
Zhou, Wenduo committed
141
            MinimumLogValue=279.9,  MaximumLogValue=279.98, LogValueInterval=0.01)
142
143
144

    FilterEvents(InputWorkspace=ws,
        SplitterWorkspace=splitws,
Zhou, Wenduo's avatar
Zhou, Wenduo committed
145
        InformationWorkspace=infows,
146
147
148
        OutputWorkspaceBaseName='tempsplitws',
        GroupWorkspaces=True,
        FilterByPulseTime = True,
Zhou, Wenduo's avatar
Zhou, Wenduo committed
149
        OutputWorkspaceIndexedFrom1 = True,
150
151
        CorrectionToSample = "None",
        SpectrumWithoutDetector = "Skip",
Zhou, Wenduo's avatar
Zhou, Wenduo committed
152
        SplitSampleLogs = False,
153
        OutputTOFCorrectionWorkspace='mock')
Zhou, Wenduo's avatar
Zhou, Wenduo committed
154
155
156
157

    # Print result
    wsgroup = mtd["tempsplitws"]
    wsnames = wsgroup.getNames()
158
    for name in sorted(wsnames):
Zhou, Wenduo's avatar
Zhou, Wenduo committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
        tmpws = mtd[name]
        print "workspace %s has %d events" % (name, tmpws.getNumberEvents())


Output:

.. testoutput:: FilterEventByPulseTime

    workspace tempsplitws_1 has 123 events
    workspace tempsplitws_2 has 16951 events
    workspace tempsplitws_3 has 9972 events
    workspace tempsplitws_4 has 7019 events
    workspace tempsplitws_5 has 22529 events
    workspace tempsplitws_6 has 5067 events


175
**Example - Filtering event with correction on TOF**
Zhou, Wenduo's avatar
Zhou, Wenduo committed
176
177
178
179

.. testcode:: FilterEventTOFCorrection

    ws = Load(Filename='CNCS_7860_event.nxs')
180
    splitws, infows = GenerateEventsFilter(InputWorkspace=ws, UnitOfTime='Nanoseconds', LogName='SampleTemp',
Zhou, Wenduo's avatar
Zhou, Wenduo committed
181
182
183
            MinimumLogValue=279.9,  MaximumLogValue=279.98, LogValueInterval=0.01)

    FilterEvents(InputWorkspace=ws, SplitterWorkspace=splitws, InformationWorkspace=infows,
184
185
186
        OutputWorkspaceBaseName='tempsplitws',
        GroupWorkspaces=True,
        FilterByPulseTime = False,
Zhou, Wenduo's avatar
Zhou, Wenduo committed
187
        OutputWorkspaceIndexedFrom1 = False,
188
        CorrectionToSample = "Direct",
Zhou, Wenduo's avatar
Zhou, Wenduo committed
189
        IncidentEnergy=3,
190
        SpectrumWithoutDetector = "Skip",
Zhou, Wenduo's avatar
Zhou, Wenduo committed
191
192
        SplitSampleLogs = False,
        OutputTOFCorrectionWorkspace='mock')
193

Zhou, Wenduo's avatar
Zhou, Wenduo committed
194
195
196
    # Print result
    wsgroup = mtd["tempsplitws"]
    wsnames = wsgroup.getNames()
197
    for name in sorted(wsnames):
Zhou, Wenduo's avatar
Zhou, Wenduo committed
198
199
200
201
202
203
204
205
        tmpws = mtd[name]
        print "workspace %s has %d events" % (name, tmpws.getNumberEvents())


Output:

.. testoutput:: FilterEventTOFCorrection

Zhou, Wenduo's avatar
Zhou, Wenduo committed
206
207
208
209
210
211
212
    workspace tempsplitws_0 has 123 events
    workspace tempsplitws_1 has 16951 events
    workspace tempsplitws_2 has 9972 events
    workspace tempsplitws_3 has 7019 events
    workspace tempsplitws_4 has 22514 events
    workspace tempsplitws_5 has 5082 events
    workspace tempsplitws_unfiltered has 50605 events
Zhou, Wenduo's avatar
Zhou, Wenduo committed
213

214
.. categories::
215
216

.. sourcelink::