Skip to content

Commit 8cf584f

Browse files
author
Andreas Pettersson
committed
made a 2D heatmap for inv_vref and noinv_vref parameters
1 parent b2e7f4f commit 8cf584f

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

ana/inv_vref/heatmap.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"""heatmap of pedestal data separated by link_channel"""
2+
3+
import pandas as pd
4+
import numpy as np
5+
import hist
6+
import matplotlib.pyplot as plt
7+
from pathlib import Path
8+
import argparse
9+
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument('pedestals', type=Path, help='decoded pedestal CSV file to summarize')
12+
parser.add_argument('-o','--output', type=Path, help='file to which to print, default is pedestal file with "-heatmap" suffix and extension changed to ".png"')
13+
parser.add_argument('--full-range', action='store_true', help='use full 10-bit range rather than dynamically change the binning to fit between the min/max of the data')
14+
args = parser.parse_args()
15+
16+
if args.output is None:
17+
args.output = args.pedestals.parent / (args.pedestals.stem + '-heatmap.png')
18+
19+
samples = pd.read_csv(args.pedestals)
20+
21+
fig, axes = plt.subplots(1, 2)
22+
23+
# pedestal per link vs noinv
24+
25+
link0_df = samples[(samples['ch'] < 32) & (samples['inv_vref'] == 600)]
26+
link1_df = samples[(samples['ch'] >= 32) & (samples['inv_vref'] == 600)]
27+
28+
median_adc_0 = link0_df.groupby('noinv_vref')['adc'].median().sort_index()
29+
median_adc_1 = link1_df.groupby('noinv_vref')['adc'].median().sort_index()
30+
31+
axes[0].plot(median_adc_0.index, median_adc_0.values)
32+
axes[1].plot(median_adc_1.index, median_adc_1.values)
33+
axes[0].set_ylabel('median pedestal [ADC]')
34+
axes[0].set_xlabel('noinv_vref')
35+
axes[1].set_xlabel('noinv_vref')
36+
axes[0].set_title('link 0')
37+
axes[1].set_title('link 1')
38+
39+
plt.savefig('noinv_scan.png', dpi=400, bbox_inches='tight')
40+
plt.close()
41+
42+
# pedestal per link vs inv
43+
44+
fig, axes = plt.subplots(1, 2)
45+
46+
link0_df = samples[(samples['ch'] < 32) & (samples['noinv_vref'] == 600)]
47+
link1_df = samples[(samples['ch'] >= 32) & (samples['noinv_vref'] == 600)]
48+
49+
median_adc_0 = link0_df.groupby('inv_vref')['adc'].median().sort_index()
50+
median_adc_1 = link1_df.groupby('inv_vref')['adc'].median().sort_index()
51+
52+
axes[0].plot(median_adc_0.index, median_adc_0.values)
53+
axes[1].plot(median_adc_1.index, median_adc_1.values)
54+
axes[0].set_ylabel('median pedestal [ADC]')
55+
axes[0].set_xlabel('inv_vref')
56+
axes[1].set_xlabel('inv_vref')
57+
axes[0].set_title('link 0')
58+
axes[1].set_title('link 1')
59+
60+
plt.savefig('inv_scan.png', dpi=400, bbox_inches='tight')
61+
plt.close()
62+
63+
# Heatmap
64+
65+
channels = samples.groupby('ch')
66+
67+
for ch_id, ch_df in channels:
68+
print("channel ", ch_id)
69+
fig = plt.figure()
70+
71+
heat = (
72+
ch_df
73+
.groupby(['noinv_vref', 'inv_vref'])['adc']
74+
.median()
75+
.unstack('inv_vref')
76+
.sort_index()
77+
.sort_index(axis=1)
78+
)
79+
80+
plt.imshow(
81+
heat.values,
82+
extent=[
83+
heat.columns.min(), heat.columns.max(),
84+
heat.index.min(), heat.index.max()
85+
],
86+
origin="lower",
87+
aspect="auto",
88+
#cmap="tab20"
89+
)
90+
plt.colorbar(label="median pedestal [ADC]")
91+
plt.xlabel("inv_vref")
92+
plt.ylabel("noinv_vref")
93+
plt.savefig(f'heatmap_ch_{ch_id}.png', dpi=400, bbox_inches='tight')
94+
plt.close()

0 commit comments

Comments
 (0)