Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Functions | Variables
L1TopoRatesCalculator_submatrix_plotter Namespace Reference

Functions

def plot_correlation_matrix (file_name, matrix_name, selected_vars, output_name)
 

Variables

 parser
 
 description
 
 type
 
 str
 
 help
 
 nargs
 
 args
 

Function Documentation

◆ plot_correlation_matrix()

def L1TopoRatesCalculator_submatrix_plotter.plot_correlation_matrix (   file_name,
  matrix_name,
  selected_vars,
  output_name 
)

Definition at line 9 of file L1TopoRatesCalculator_submatrix_plotter.py.

9 def plot_correlation_matrix(file_name, matrix_name, selected_vars, output_name):
10  # Open the ROOT file
11  root_file = ROOT.TFile.Open(file_name)
12 
13  # Retrieve the correlation matrix
14  rates_matrix = root_file.Get(matrix_name)
15 
16  # Extract the list of variables
17  n = rates_matrix.GetNbinsX() # Assuming the number of bins is the same in both X and Y axes
18  variables = [rates_matrix.GetXaxis().GetBinLabel(i) for i in range(1, n+1)]
19 
20  # Filter the selected variables
21  indices = [variables.index(var) for var in selected_vars]
22 
23  # Create a numpy array to store the selected values
24  selected_matrix = np.zeros((len(indices), len(indices)))
25  errors_matrix = np.zeros((len(indices), len(indices)))
26 
27  for i, ix in enumerate(indices):
28  for j, iy in enumerate(indices):
29  selected_matrix[i, j] = rates_matrix.GetBinContent(ix+1, iy+1)
30  errors_matrix[i, j] = rates_matrix.GetBinError(ix+1, iy+1)
31  # Find the minimum and maximum values in the selected matrix
32  min_value = np.min(selected_matrix)
33  max_value = np.max(selected_matrix)
34 
35  # Create the plot
36  fig, ax = plt.subplots(figsize=(24, 22))
37  cax = ax.matshow(selected_matrix, cmap='coolwarm', norm=Normalize(vmin=min_value, vmax=max_value))
38 
39  # Add text inside the cells
40  for (i, j), val in np.ndenumerate(selected_matrix):
41  error = errors_matrix[i, j]
42  ax.text(j, i, f'{val:.2f}\n±{error:.2f}', ha='center', va='center', color='black', fontsize=25)
43 
44  # Set the axis labels
45  ax.set_xticks(np.arange(len(indices)))
46  ax.set_yticks([])
47  ax.set_xticklabels([selected_vars[i] for i in range(len(indices))], rotation=90, fontsize=25)
48  ax.set_yticklabels([])
49  plt.xticks(rotation=45)
50 
51  # Adjust labels to align at the start of each bin
52  for tick in ax.get_xticklabels():
53  tick.set_horizontalalignment('left') # Align left
54  # Add a color bar
55  colorbar = fig.colorbar(cax)
56  colorbar.ax.tick_params(labelsize=25)
57  colorbar.set_label('Hz', fontsize=25)
58 
59  # Save the image as a PNG file
60  plt.savefig(output_name, bbox_inches='tight')
61  plt.close()
62 

Variable Documentation

◆ args

L1TopoRatesCalculator_submatrix_plotter.args

Definition at line 72 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ description

L1TopoRatesCalculator_submatrix_plotter.description

Definition at line 65 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ help

L1TopoRatesCalculator_submatrix_plotter.help

Definition at line 66 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ nargs

L1TopoRatesCalculator_submatrix_plotter.nargs

Definition at line 68 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ parser

L1TopoRatesCalculator_submatrix_plotter.parser

Definition at line 65 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ str

L1TopoRatesCalculator_submatrix_plotter.str

Definition at line 66 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ type

L1TopoRatesCalculator_submatrix_plotter.type

Definition at line 66 of file L1TopoRatesCalculator_submatrix_plotter.py.

L1TopoRatesCalculator_submatrix_plotter.plot_correlation_matrix
def plot_correlation_matrix(file_name, matrix_name, selected_vars, output_name)
Definition: L1TopoRatesCalculator_submatrix_plotter.py:9
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195