23 import pidDataUtils
as pdu
27 standard = pdu.read_npz(
'data/slim_dstar/test.npz')
28 weighted = standard.copy(deep=
True)
29 print(f
'{len(standard)} events')
32 weights = np.load(
'models/net_wgt.npy')
35 standard = pdu.produce_analysis_df(standard)
36 weighted = pdu.produce_analysis_df(weighted, weights=weights)
37 print(f
'{len(standard)} events after cuts')
39 print(
'\nValues of the weights')
43 def compute_accuracy(df, mask=None):
44 _df = df.loc[mask]
if mask
is not None else df
45 return (_df[
'pid'] == _df[
'labels']).values.sum() / len(_df)
48 print(
'\n no wgt wgt')
49 standard_acc = compute_accuracy(standard)
50 weighted_acc = compute_accuracy(weighted)
51 print(f
'Accuracy: {standard_acc:.3f} {weighted_acc:.3f}')
53 lbl =
"pion" if label == 2
else "kaon"
54 _standard_eff = compute_accuracy(standard, mask=standard[
"labels"] == label)
55 _weighted_eff = compute_accuracy(weighted, mask=weighted[
"labels"] == label)
56 print(f
'{lbl} eff: {_standard_eff:.3f} {_weighted_eff:.3f}')
64 my_path = b2.create_path()
66 matrixName =
"PIDCalibrationWeight_Example"
67 weightMatrix = weights.tolist()
69 addmatrix = b2.register_module(
'PIDCalibrationWeightCreator')
70 addmatrix.param(
'matrixName', matrixName)
71 addmatrix.param(
'weightMatrix', weightMatrix)
72 addmatrix.param(
'experimentHigh', -1)
73 addmatrix.param(
'experimentLow', 0)
74 addmatrix.param(
'runHigh', -1)
75 addmatrix.param(
'runLow', 0)
77 eventinfosetter = b2.register_module(
'EventInfoSetter')
78 eventinfosetter.param(
'evtNumList', [10])
79 eventinfosetter.param(
'runList', [0])
80 eventinfosetter.param(
'expList', [0])
82 my_path.add_module(addmatrix)
83 my_path.add_module(eventinfosetter)