-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_config_PUweights.py
67 lines (46 loc) · 2.21 KB
/
prepare_config_PUweights.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pandas as pd
import numpy as np
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--wEE", type=str, help="Weights file EE", required=True)
parser.add_argument("--wEB", type=str, help="Weights file EB", required=True)
parser.add_argument("--PU", type=int, help="PU weights" , required=True)
parser.add_argument("--S", type=str, help="S weights", required=True )
parser.add_argument("-o", "--output", type=str, help="Output name", required=True)
args = parser.parse_args()
weightsEE = pd.read_csv(args.wEE, sep=',', float_precision='round_trip')
weightsEB = pd.read_csv(args.wEB, sep=',', float_precision='round_trip')
# The original contains the ID map of the strip and 1 or 0 for EE or EB
group_orig = pd.read_csv("EcalTPGWeightGroup_original.txt", sep=" ", header=None)
stripids_map = {}
# Defaults weights groups for EB and EE
wgroups = [[92,93,16,159,24], [86,95,16,161,26]]
Sbin = args.S
PU = args.PU
def add_8th_bit(num):
return int(num) | 0x80
for _, row in weightsEE[(weightsEE.PU==PU) & (weightsEE.Sbin ==Sbin)].iterrows():
group = list(map(int,[row.enc_w_1_1, row.enc_w_1_2, row.enc_w_1_3, add_8th_bit(row.enc_w_1_4), row.enc_w_1_5]))
try:
index = wgroups.index(group)
stripids_map[row.stripid] = index
except ValueError:
stripids_map[row.stripid] = len(wgroups)
wgroups.append(group)
for _, row in weightsEB[(weightsEB.PU==PU) & (weightsEB.Sbin ==Sbin)].iterrows():
group = list(map(int,[row.enc_w_1_1, row.enc_w_1_2, row.enc_w_1_3, add_8th_bit(row.enc_w_1_4), row.enc_w_1_5]))
try:
index = wgroups.index(group)
stripids_map[row.stripid] = index
except ValueError:
stripids_map[row.stripid] = len(wgroups)
wgroups.append(group)
for j in group_orig.index:
strip = group_orig.loc[j,0]
det = group_orig.loc[j,1]
if strip in stripids_map:
group_orig.loc[j,1] = stripids_map[strip]
# If not present leave the default two groups
idmap = pd.DataFrame(wgroups)
group_orig.to_csv("EcalTPGWeightGroup_{}.txt".format(args.output), sep=' ', index=False, header=None)
idmap.to_csv("EcalTPGWeightIdMap_{}.txt".format(args.output), sep=' ', index=False, header=None)