forked from cms-pixel-autotuning/CA-parameter-tuning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
26 lines (21 loc) · 941 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import numpy as np
# calculate the metrics from validation results
def get_metrics(uproot_file, id):
tree = uproot_file['simpleValidation' + str(id)]['output']
total_rec = tree['rt'].array()[0]
total_ass = tree['at'].array()[0]
total_ass_sim = tree['ast'].array()[0]
total_dup = tree['dt'].array()[0]
total_sim = tree['st'].array()[0]
if not total_ass or not total_rec or not total_sim or not total_ass_sim:
return [1.0] * 2
return [1 - total_ass_sim / total_sim, (total_rec - total_ass + total_dup) / total_rec]
# read a csv file, return a matrix
def read_csv(filename):
matrix = np.genfromtxt(filename, delimiter=",", dtype=float)
if matrix.ndim == 2:
return np.genfromtxt(filename, delimiter=",", dtype=float)
return np.array([matrix])
# write a matrix to a csv file
def write_csv(filename, matrix):
np.savetxt(filename, matrix, fmt='%.18f', delimiter=',')