ATLAS Offline Software
Functions | Variables
L1TopoRatesCalculator_submatrix_plotter Namespace Reference

Functions

def load_selected_matrix (root_file, matrix_name, selected_vars, with_errors=True)
 
def plot_matrix (selected_matrix, errors_matrix, selected_vars, title, output_name, colorbar_label)
 

Variables

 parser
 
 description
 
 type
 
 str
 
 help
 
 nargs
 
 args
 
 file
 
 rates
 
 rates_err
 
 selected_vars
 
 with_errors
 
 counts
 
 _
 
 topo
 
 topo_err
 

Function Documentation

◆ load_selected_matrix()

def L1TopoRatesCalculator_submatrix_plotter.load_selected_matrix (   root_file,
  matrix_name,
  selected_vars,
  with_errors = True 
)

Definition at line 10 of file L1TopoRatesCalculator_submatrix_plotter.py.

10 def load_selected_matrix(root_file, matrix_name, selected_vars, with_errors=True):
11  matrix = root_file.Get(matrix_name)
12  if not matrix:
13  raise RuntimeError(f"Matrix '{matrix_name}' not found in ROOT file.")
14 
15  n = matrix.GetNbinsX()
16  all_vars = [matrix.GetXaxis().GetBinLabel(i) for i in range(1, n+1)]
17  indices = [all_vars.index(var) for var in selected_vars]
18 
19  selected_matrix = np.zeros((len(indices), len(indices)))
20  errors_matrix = np.zeros((len(indices), len(indices))) if with_errors else None
21 
22  for i, ix in enumerate(indices):
23  for j, iy in enumerate(indices):
24  selected_matrix[i, j] = matrix.GetBinContent(ix+1, iy+1)
25  if with_errors:
26  errors_matrix[i, j] = matrix.GetBinError(ix+1, iy+1)
27 
28  return selected_matrix, errors_matrix
29 

◆ plot_matrix()

def L1TopoRatesCalculator_submatrix_plotter.plot_matrix (   selected_matrix,
  errors_matrix,
  selected_vars,
  title,
  output_name,
  colorbar_label 
)

Definition at line 30 of file L1TopoRatesCalculator_submatrix_plotter.py.

30 def plot_matrix(selected_matrix, errors_matrix, selected_vars, title, output_name, colorbar_label):
31  min_value = np.min(selected_matrix)
32  max_value = np.max(selected_matrix)
33 
34  fig, ax = plt.subplots(figsize=(46, 44))
35  cax = ax.matshow(selected_matrix, cmap='coolwarm', norm=Normalize(vmin=min_value, vmax=max_value))
36 
37  for (i, j), val in np.ndenumerate(selected_matrix):
38  if errors_matrix is not None:
39  error = errors_matrix[i, j]
40  text = f'{val:.2f}\n±{error:.2f}'
41  else:
42  text = f'{val:.2f}'
43  ax.text(j, i, text, ha='center', va='center', color='black', fontsize=25)
44 
45  ax.set_xticks(np.arange(len(selected_vars)))
46  ax.set_yticks([])
47  ax.set_xticklabels(selected_vars, rotation=90, fontsize=25)
48  ax.set_yticklabels([])
49  plt.xticks(rotation=45)
50  for tick in ax.get_xticklabels():
51  tick.set_horizontalalignment('left')
52 
53  colorbar = fig.colorbar(cax)
54  colorbar.ax.tick_params(labelsize=25)
55  colorbar.set_label(colorbar_label, fontsize=25)
56 
57  plt.title(title, fontsize=30)
58  plt.savefig(output_name, bbox_inches='tight')
59  plt.close()
60 

Variable Documentation

◆ _

L1TopoRatesCalculator_submatrix_plotter._
private

Definition at line 74 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ args

L1TopoRatesCalculator_submatrix_plotter.args

Definition at line 65 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ counts

L1TopoRatesCalculator_submatrix_plotter.counts

Definition at line 74 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ description

L1TopoRatesCalculator_submatrix_plotter.description

Definition at line 62 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ file

L1TopoRatesCalculator_submatrix_plotter.file

Definition at line 67 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ help

L1TopoRatesCalculator_submatrix_plotter.help

Definition at line 63 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ nargs

L1TopoRatesCalculator_submatrix_plotter.nargs

Definition at line 64 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ parser

L1TopoRatesCalculator_submatrix_plotter.parser

Definition at line 62 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ rates

L1TopoRatesCalculator_submatrix_plotter.rates

Definition at line 70 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ rates_err

L1TopoRatesCalculator_submatrix_plotter.rates_err

Definition at line 70 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ selected_vars

L1TopoRatesCalculator_submatrix_plotter.selected_vars

Definition at line 70 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ str

L1TopoRatesCalculator_submatrix_plotter.str

Definition at line 63 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ topo

L1TopoRatesCalculator_submatrix_plotter.topo

Definition at line 78 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ topo_err

L1TopoRatesCalculator_submatrix_plotter.topo_err

Definition at line 78 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ type

L1TopoRatesCalculator_submatrix_plotter.type

Definition at line 63 of file L1TopoRatesCalculator_submatrix_plotter.py.

◆ with_errors

L1TopoRatesCalculator_submatrix_plotter.with_errors

Definition at line 70 of file L1TopoRatesCalculator_submatrix_plotter.py.

plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
L1TopoRatesCalculator_submatrix_plotter.load_selected_matrix
def load_selected_matrix(root_file, matrix_name, selected_vars, with_errors=True)
Definition: L1TopoRatesCalculator_submatrix_plotter.py:10
L1TopoRatesCalculator_submatrix_plotter.plot_matrix
def plot_matrix(selected_matrix, errors_matrix, selected_vars, title, output_name, colorbar_label)
Definition: L1TopoRatesCalculator_submatrix_plotter.py:30