Last modified: 18 December 2023

How can I group net counts?


The sherpa group commands work on the source and separately on the background (when the background is model separately). To group on net, background-subtracted counts, users need apply a custom grouping scheme using the set_grouping and set_quality routines.

First users need to load the data, including the background and subtract it.

sherpa> load_data("myspectrum.pi")
sherpa> subtract()

Now we need to retrieve the background subtracted data. The get_dep routine can be used to get the dataset's dependent axis, ie Y-axis, which in this case is the background subtracted counts.

sherpa> net_counts = get_data().get_dep()

Using the background subtracted "counts" we can now use the group module to compute the grouping and quality flags. Specifically, in this example we want to use the grpNumCounts routine and we will create groups with 5 net counts.

sherpa> from group import grpNumCounts
sherpa> grp,qual = grpNumCounts( net_counts, 5)

The grpNumCounts routine returns two arrays: the grouping flags and the quality flags. The grouping flags identify the boundaries of group and the quality flags indicate if the group has met the desired grouping criteria (ie does contain 5 net-counts).

Now to apply this grouping scheme to the data

sherpa> set_grouping( grp )
sherpa> set_quality(qual)
sherpa> get_data().group() 

The final group command is required to set the grouping flag which is then used when the data are used.

Finally, users may want to ignore any channels that contain partially complete groups. Often the final group will not have met the grouping criteria. Users may want to

sherpa> ignore_bad()

to remove any partial bins from their fit.

[NOTE]
Note

This technique can be used to apply any arbitrary grouping scheme that the user desires. The grouping flags and quality values must be valid, but how they are created is entirely up to the user.

Just remember that grouping is done in detector channels, not in energy (or wavelength).