MuonDataLib Tutorial 2: Viewing Histograms

In this tutorial we will load some data from the archive and then view some of the histograms. This can be used to check that the count data looks about right before creating the histogram nexus file.

The data shown in the plots, and written to the histogram nexus files, is referred to as histograms. However, strictly speaking they are bar charts as they do not include the normalisation by bin width (this is applied in the analysis software). They are still called histograms because that is the expected terminology.

To start lets load the example and plot a pair of histograms.

[1]:
from MuonDataLib.data.loader.load_events import load_events
from MuonDataLib.plot.basic import Figure
import os

file_name = 'HIFI00195790.nxs'
input_file = os.path.join('..', '..', '..', '..', 'test', 'data_files', file_name)

data = load_events(input_file, 64)

hist, bins = data.histogram()
fig = Figure(y_label='Counts')
fig.plot_from_histogram(bins, hist, [10, 21], label='Period 1, ', period=1)
fig.plot_from_histogram(bins, hist, [10, 21], label='Period 2, ', period=2)
fig.show()

WARNING: The metadata **RUN** is missing. Using fallback values
WARNING: The metadata **TITLE** is missing. Using fallback values
WARNING: The metadata **EXPERIMENT IDENTIFIER** is missing. Using fallback values

Data type cannot be displayed: application/vnd.plotly.v1+json

The plot above is interactive, you can show/hide data by clicking on it in the legend.

To get more data, the archive is needed. On IDAaaS you need to open file explorer and go to smb://ISISARVR55.isis.cclrc.ac.uk/SuperMusrTestDataBackup$/incoming/hifi. It will require your username (fed ID), domain (clrc) and password. Then you can copy your file to your local directory.

The following code changes the histogram time bounds and bin width, plots and saves the data to a histogram nexus file (with the new resolution).

[2]:
data.set_histogram_settings(min_time=0., max_time=35., num_bins=350)
hist, bins = data.histogram()
fig = Figure(y_label='Counts')
fig.plot_from_histogram(bins, hist, [10, 21], label='Period 1, ', period=1)
fig.plot_from_histogram(bins, hist, [10, 21], label='Period 2, ', period=2)
fig.show()
Resolution: 0.1 μs

Data type cannot be displayed: application/vnd.plotly.v1+json

[3]:
output_file = os.path.join('..', 'Output_files', 'HIFI00193325.nxs')
data.save_histograms(output_file)