e15190.neutron_wall.shadow_bar.ShadowBar

class e15190.neutron_wall.shadow_bar.ShadowBar(AB, max_workers=8)

Functions

__init__(AB[, max_workers])

Initialize the ShadowBar class.

cache_run(run[, tree_name])

Read in data from ROOT file and save relevant branches to an SQLite database.

calculate_background(result, x, y)

fit(background_position[, path])

fit_energy_range(ene, background_position)

fit_parameters(background_position, x, y, y_err)

fit_scaled_hist(background_position, x, y, y_err)

gate_on_tof()

infer_tree_name(uproot_file)

make_space_above([topmargin])

increase figure size to make topmargin (in inches) space for titles, without changing the axes sizes

preprocessing()

read(run, bar[, from_cache, verbose])

Read in the data needed to do shadow bar analysis.

read_run_from_root_file(run[, tree_name, ...])

Read in single run from ROOT file.

remove_vetowall_coincidences()

save_to_gallery(sf, background_position, ...)

Save a diagnostic plot to the gallery as a PNG file.

save_to_gallery_scaled(sf, ...[, path, ...])

scaled_histogram(result, x, y, y_err)

Properties

database_dir

energy_bin

energy_range

light_GM_range

nbins1

pos_range

psd

root_files_dir

theta_b

theta_f

__init__(AB, max_workers=8)

Initialize the ShadowBar class.

Parameters
  • AB (str) – Either ‘A’ or ‘B’. To specify neutron wall A or B.

  • max_workers (int, default 8) – Maximum number of workers to use for parallelization. The parallelization is used to read in data from ROOT files as executors for decompression and interpretation in uproot.

_cut_for_root_file_data(AB)

A simple cut to select valid entries only.

This is not the final cut. It is only the biggest cut that defines the largest subset of data that will be used, i.e. we only throw away entries that are not useable or recoverable. Data that are not of our interest should not be thrown away here.

read_run_from_root_file(run, tree_name=None, apply_cut=True)

Read in single run from ROOT file.

The ROOT file here refers to the one generated by calibrate.cpp, not the “Daniele’s ROOT file”.

Parameters
  • run (int) – Run number.

  • tree_name (str, default None) – Name of the tree in the ROOT file. If not specified, the function will try to automatically determine the tree name. If multiple trees are found within the ROOT file, an exception will be raised as the function has no way to know which tree to use.

  • apply_cut (bool, default True) – If set to True, the function will apply the cut specified by _cut_for_root_file_data() to the data. Otherwise, the cut is not applied.

Returns

df – Dataframe containing the data for the specified run.

Return type

pd.DataFrame

cache_run(run, tree_name=None)

Read in data from ROOT file and save relevant branches to an SQLite database.

The data will be grouped according to bar number, because future retrieval by this class will most likely analyze only one bar at a time.

Parameters
  • run (int) – Run number.

  • tree_name (str, default None) – Name of the tree in the ROOT file. If not specified, the function will try to automatically determine the tree name. If multiple trees are found within the ROOT file, an exception will be raised as the function has no way to know which tree to use.

_read_single_run(run, bar, from_cache=True)

Read in single run from either cache or ROOT file.

If no cache is available or from_cache is set to False, the function first prepare a cache for the run by invoking cache_run(), then read in the data from the newly created cache into a dataframe to be returned. Otherwise, it reads directly from the cache and returns the dataframe.

Notice that the cache file is always generated for one run at a time, with multiple dataframes contained in it, each dataframe corresponding to one bar. In other words, if you have invoked _read_single_run(6666, 1), then a cache file cache/run-6666.db will be generated, and in it there are dataframes for not just bar-01, but also all the other bars (of course, excluding those that you had chosen to filter out).

Parameters
  • run (int) – Run number.

  • bar (int) – Bar number.

  • from_cache (bool, default True) – If set to True, the data will be read from the cache if exists. Otherwise, it will refresh the cache by reading again from the ROOT file, then read from the newly created cache.

Returns

df – Dataframe containing the data for the specified run and bar.

Return type

pd.DataFrame

read(run, bar, from_cache=True, verbose=False)

Read in the data needed to do shadow bar analysis.

This function reads in the data as a dataframe, and saves it to self.df. It also updates self.bar for future reference.

The data will be read from the cache files if they exists, otherwise the function will read in from the ROOT files (generated by calibrate.cpp).

Branch names that start with NW{self.AB}_ will be dropped because of redunancy. For example, NWB_psd will be reduced into psd. However, other prefixes that indicate detectors other than the neutron wall will be kept, e.g. MB_multi, FA_time_min, etc.

Parameters
  • run (int or list of ints) – The run number(s).

  • bar (int) – Bar number.

  • from_cache (bool, default True) – If set to True, the data will be read from the cache if exists. Otherwise, it will refresh the cache by reading again from the ROOT file, then read from the newly created cache.

  • verbose (bool, default False) – Whether to print out the progress of the read in.

Example

>>> from e15190.neutron_wall.shadow_bar import ShadowBar
>>> shade = ShadowBar('B') # ShadowBar object for neutron wall B
>>> shade.read([4083, 4084], 1, verbose=True) # read in run 4083 and 4084, bar-01
Reading run-4083  (1/2)
Reading run-4084  (2/2)
>>> shade.df[['run', 'theta']] # display the columns run and theta for inspection
        run      theta
0      4083  32.787231
1      4083  33.294674
2      4083  35.215828
3      4083  40.720539
4      4083  31.086285
...     ...        ...
25253  4084  38.263584
25254  4084  35.900543
25255  4084  40.574760
25256  4084  31.906084
25257  4084  49.476383

[25258 rows x 2 columns]
make_space_above(topmargin=1)

increase figure size to make topmargin (in inches) space for titles, without changing the axes sizes

Save a diagnostic plot to the gallery as a PNG file.

Parameters
pathstr or pathlib.Path, default None

The path to save the plot. If None, the plot is saved to the default database.

cutstr, default ‘light_GM > 3’

The cut to apply to the data when plotting. All panels in the figure will apply this cut, and potentially other cuts, joined by logical AND, except for the panel that draws the PPSD as a function of light GM.

show_plotbool, default False

If True, the plot will be shown in run time, i.e. the command plt.show() will be called.

savebool, default True

If True, the plot will be saved to the database. False option is useful when users are using this function to inspect the plot without saving.