23import pidDataUtils
as pdu
27standard = pdu.read_npz(
'data/slim_dstar/test.npz')
28weighted = standard.copy(deep=
True)
29print(f
'{len(standard)} events')
32weights = np.load(
'models/net_wgt.npy')
35standard = pdu.produce_analysis_df(standard)
36weighted = pdu.produce_analysis_df(weighted, weights=weights)
37print(f
'{len(standard)} events after cuts')
39print(
'\nValues of the weights')
43def 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)
49standard_acc = compute_accuracy(standard)
50weighted_acc = compute_accuracy(weighted)
51print(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}')
64my_path = b2.create_path()
66matrixName =
"PIDCalibrationWeight_Example"
67weightMatrix = weights.tolist()
69addmatrix = b2.register_module(
'PIDCalibrationWeightCreator')
70addmatrix.param(
'matrixName', matrixName)
71addmatrix.param(
'weightMatrix', weightMatrix)
72addmatrix.param(
'experimentHigh', -1)
73addmatrix.param(
'experimentLow', 0)
74addmatrix.param(
'runHigh', -1)
75addmatrix.param(
'runLow', 0)
77eventinfosetter = b2.register_module(
'EventInfoSetter')
78eventinfosetter.param(
'evtNumList', [10])
79eventinfosetter.param(
'runList', [0])
80eventinfosetter.param(
'expList', [0])
82my_path.add_module(addmatrix)
83my_path.add_module(eventinfosetter)