Skip to content
Snippets Groups Projects
Commit bb8a46c6 authored by ssummers's avatar ssummers
Browse files

Add a firmware validation section

parent a187aa65
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:49e7d9d8 tags:
# Firmware validation
Using the pattern files from the CMSSW emulator and the FPGA simulation we can validate our integration.
Reference files are provided in `solutions/part3/`
- `sink.txt` from the firmware simulation
- `L1TMLDemoPatterns_out_0.txt` from the CMSSW emulator
We read from the pattern file data to numpy arrays, scaling to the physical range of the data type. Then we plot the distribution and compute the difference between the two.
%% Cell type:code id:35d206a6 tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
import os
import mplhep
```
%% Cell type:code id:5f5d4181 tags:
``` python
def read_pattern_file_to_numpy(f):
'''
A quick and dirty pattern file reader for our data format
'''
fp = open(f)
lines = fp.readlines()
X = []
for line in lines:
if 'Frame' in line:
fields = line.split()
v = '1' in fields[2]
if v:
x = int(fields[3], 16)
x = x / 2**11
X.append(x)
return np.array(X, dtype='float')
```
%% Cell type:code id:d7cb7022 tags:
``` python
y_cmssw = read_pattern_file_to_numpy(os.environ['MLATL1T_DIR'] + '/solutions/part3/L1TMLDemoPatterns_out_0.txt')
y_fpga = read_pattern_file_to_numpy(os.environ['MLATL1T_DIR'] + '/solutions/part3/sink.txt')
```
%% Cell type:code id:9c0e677b tags:
``` python
bins = np.linspace(0, 1, 100)
h_cmssw, _ = np.histogram(y_cmssw, bins=bins)
h_cmssw = h_cmssw.astype('float') / np.sum(h_cmssw)
h_fpga, _ = np.histogram(y_fpga, bins=bins)
h_fpga = h_fpga.astype('float') / np.sum(h_fpga)
mplhep.histplot(h_cmssw, bins, label='CMSSW')
mplhep.histplot(h_fpga, bins, label='FPGA')
plt.xlim((0, 1))
plt.xlabel('y')
plt.semilogy()
plt.legend(loc='upper left')
```
%% Cell type:code id:2f099a12 tags:
``` python
N = min([len(y_fpga), len(y_cmssw)])
d = y_cmssw[:N] - y_fpga[:N]
bins = np.linspace(-1,1,100)
h, _ = np.histogram(d, bins=bins)
mplhep.histplot(h, bins)
plt.xlim((-1,1))
plt.xlabel('y_cmssw - y_fpga')
```
%% Cell type:code id:62a005c2 tags:
``` python
```
This diff is collapsed.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment