Alignment Plotting¶
systematic generation of alignment-related plots
- hps_align.plot.generate_legend_names(input_files)¶
Generate legend names from input file names
- hps_align.plot.plot(plots: ~typing.List[~hps_align.plot.PlotOpt] = <typer.models.ArgumentInfo object>, plot_list: str = <typer.models.OptionInfo object>, input_files: ~typing.List[str] = <typer.models.OptionInfo object>, legend: ~typing.List[str] = <typer.models.OptionInfo object>, out_dir: str = <typer.models.OptionInfo object>, html: bool = <typer.models.OptionInfo object>, is2016: bool = <typer.models.OptionInfo object>, ext: str = <typer.models.OptionInfo object>, config: str = <typer.models.OptionInfo object>)¶
create comparison plots across different detector iterations of alignment-related variables
Plotters¶
The hps_align.plot submodule is broken up into various “plotters” so that users can choose which plots to generate from the input files.
- hps_align.plot.vertex.multi_vtx(p)¶
plot multi-vertex distributions
input ROOT files have to contain the ‘/MultiEventVtx/’ directory
- hps_align.plot.derivatives.single_derivative(p: Plotter, name: str)¶
Make a single derivative plot
This is here instead of in the Plotter class since it is so specialized. We assume that the ‘gbl_derivatives’ directory exists in all the input ROOT files.
- Parameters:
p (Plotter) – plotter instance with package of input files to compare
name (str) – name of derivative to plot
- hps_align.plot.kinks.Lambda(p: Plotter)¶
Create lambda-kink summary plots
Unfortunately, we have to break name convention since ‘lambda’ is a reserved word in Python.
- hps_align.plot.residual.one_dim(p: Plotter)¶
Plot the 1D residuals for the sensors in the plot listing
- hps_align.plot.residual.single_residual_plot(p: Plotter, histo_name, title='')¶
Plot a single 1D residual plot for the input sensor
Advanced Usage¶
The main way we achieve this auto-registration of the different plotters is by using a “decorator”. This decorator is a class member of the object that is passed to each plotting function and is used to uniformly interact with the input files.
Plotter object which is passed into plotting functions
- class hps_align.plot._plotter.Plotter(legend_names=[], infile_names=[], outdir='', do_HTML=False, oFext='.png', is2016=False, plot_list_file=None)¶
Bases:
object
class for plotting alignment results
This class contains the basic functionality and setup for plotting alignment results. It is intended to be inherited by other classes that implement specific plotting.
The class is initialized with the following arguments: - input_file_list: list of file names containing the alignment results - outdir: directory where the plots will be saved - legend_names: list of names for the legend entries - do_html: if True, an index page with links to the plots will be created - oFext: extension of the output files
This class holds the open TFiles and is then passed to future plotting functions in order to provide access to the histograms within the files being held.
- Parameters:
legend_names (List[str]) – list of legend names aligned with the input files
infile_names (List[str]) – list of ROOT files to open
outdir (str) – path to output directory to dump plots
do_HTML (bool) – whether to write html file or not
oFext (str) – extension to use for writing plots (‘.png’ or ‘.pdf’)
indir (str) – directory inside ROOT files to access plots from
- __registry__¶
Dictionary of registered plotters
- Type:
dict
- colors¶
list of ROOT colors to iterate through as we plot
- Type:
List[int]
- markers¶
list of ROOT markers to iterate through as we plot in parallel with colors
- Type:
List[int]
- binLabels¶
list of bin labels for kink and ures summary plots
- Type:
List[str]
- input_files¶
list of ROOT files we are going to pull histograms from
- Type:
List[TFile]
- do_legend(histos, legend_names, location=1, plot_properties=[], leg_location=[])¶
Create legend
- Parameters:
histos (List[TH1]) – of histograms to do legend for
legend_names (List[str]) – names for the histograms in the legend
location (int) – location short ID
plot_properties (List[str]) – list of properties to include along with legend entries
leg_location (List[float]) – more precise legend location, overwriting predefined one
- Returns:
created TLegend ready to Draw at your convenience
- Return type:
TLegend
- get(hist_name, indir='')¶
Get a histogram from each ROOT file
- Parameters:
hist_name (str) – name of histogram to get
indir (str, optional) – optional ROOT directory histogram is contained in
- Returns:
list of histograms, one from each file
- Return type:
List[TH1]
- Raises:
KeyError – if hist_name is not found in any of the files
- make_1D_plots(histolist, out_name='output', xtitle='', ytitle='', yrange=[], logy=False, RebinFactor=0)¶
! Make 1D plots
@param histolist List of histograms to plot @param out_name Name of the plot @param xtitle X-axis title @param ytitle Y-axis title @param yrange Y-axis range @param logy Set the Y-axis to log scale @param RebinFactor Rebin factor
- make_1D_plots_with_fit(histopath, xtitle='', ytitle='', fit=True, scale_histos=False)¶
Plot the histograms with an iterative gaussian fit
- Parameters:
histopath (str) – path to the histogram in the ROOT files
fit (bool or dict, optional) – do the iterative gaussing fit and plot the result if dictionary, use those settings as keyword arguments to make_fit
xtitle (str) – title of x-axis
ytitle (str) – title of y-axis
scale_histos (bool) – scale the histograms to unity
See also
alignment_utils.make_fit
for how fitting of histograms is done
- make_2D_plots(histolist, out_name='output', xtitle='', ytitle='', ztitle='', zrange=[])¶
! Make combined 2D scatter plots from histograms in histolist
@param histolist list of histograms to plot @param out_name name of output file @param xtitle x axis title @param ytitle y axis title @param ztitle z axis title @param zrange z axis range
- plot_2D_colormesh(name, indir='res/', xtitle=None, ytitle=None, ztitle=None, logz=True)¶
plot a 2D colormesh for _each_ histogram in the list _separately_
- Parameters:
name (str) – name of histogram to plot for each loaded file
indir (str, optional) – directory in which histogram resides in ROOT file
out_name (str, optional) – out name prefix, it is a prefix since we will be printing multiplt plots
xtitle (str, optional) – title of x axis
ytitle (str, optional) – title of y axis
ztitle (str, optional) – title of z axis
logz (bool, optional) – whether to have color scale be logarithmic or not (default yes)
- plot_list(name=None)¶
Get the plot listing
If a name is not provided, the full plot listing is returned. If a name is provided, only that category of plots is returned and if that category of plots is separated by year, we only return the group of plots from that category for the configured year.
Parameter¶
- namestr, optional
optional name of plot category to pull
- returns:
plot listing
- rtype:
dict
- plot_profileY(name, indir='res/', xtitle='hit position [mm]', ytitle='<ures> [mm]', rangeX=[], rangeY=[], do_fit=False, fitrange=[-200000.0, 200000.0], fit='[0]*x + [1]', num_bins=1, rebin=1, do_sigma_profile=False)¶
! Plot y profile of distribution
@param name name of the histogram @param xtitle x axis title @param ytitle y axis title @param rangeX x axis range @param rangeY y axis range @param do_fit if true, fit is performed @param fitrange range for fit @param fit fit function @param num_bins number of bins for profile @param rebin rebinning factor @param do_sigma_profile if true, sigma profile plots are added
- set_histo_style(histo, ihisto, marker_size=4, line_width=5, label_size=0.05)¶
Set histo properties.
- Parameters:
histo (r.TH1) – histogram to style
ihisto (int) – index of histogram in list of histograms, sets the style
marker_size (int) – size of marker in ROOT units
line_width (int) – with of line in ROOT units
label_size (float) – size of label in ROOT units
- user()¶
decorator for registering plotters
This is the wackiest python thing in this package and is used to allow the CLI to have a list of all plotters in submodules. In order for this to function, a plotting function needs…
to be in a module imported in __init__.py. This is required so that the function is imported when the parent module is imported
to be decorated by the ‘plotter’ decorator below.
Examples
Register a plotter:
@Plotter.user def my_hist_plotter(d) : # d will be a Plotter object