Belle II Software light-2406-ragdoll
analysis-lookuptable-creation-energy-bias-correction.py
1#!/usr/bin/env python3
2
3
10
11
18
19import basf2 as b2
20import pandas as pd
21import argparse
22
23# add argument to get the input file with energy bias correction values
24parser = argparse.ArgumentParser()
25parser.add_argument(
26 '-i',
27 '--input_path',
28 default="/nfs/dust/belle2/user/kovalch/energyBiasCorrFiles/Feb2021.txt",
29 help='Path to input file with energy bias correction values .')
30args = parser.parse_args()
31
32weightsDB = args.input_path
33df_weightDB = pd.read_csv(weightsDB, delimiter=r"\s+")
34
35tableName = "Feb2021:TestEnergy"
36tableName2 = "Feb2021:TestEnergy2"
37
38# Add some bin constructors
39
40
41def make_1D_bin(name, min_val, max_val):
42 return {name: [min_val, max_val]}
43
44
45def get_weight(namew, w, namewerr, werr):
46 return {namew: w, namewerr: werr}
47
48
49def make_2D_bin(bin_x, bin_y):
50 bin_2d = bin_x.copy()
51 bin_2d.update(bin_y)
52 return bin_2d
53
54
55def make_3D_bin(bin_x, bin_y, bin_z):
56 bin_3d = bin_x.copy()
57 bin_3d.update(bin_y).update(bin_z)
58 return bin_3d
59
60
61# Bin IDs will be automatically assigned as follows:
62#
63# E|0-2|2-3|3-4|
64# theta| | | |
65# -------------
66# 0-1| 0 | 2 | 4 |
67# ---------------|
68# 1-2| 1 | 3 | 5 |
69# -------------
70
71
72bins_x = []
73bins_y = []
74weightInfo = {}
75weightInfo_x = []
76tableIDNotSpec = []
77binID = 0
78tableIDSpec = []
79for x in range(0, len(df_weightDB)):
80 weightInfo = {}
81 bins_x = make_1D_bin(df_weightDB['namebin1'].values[x], df_weightDB['minbin1'].values[x], df_weightDB['maxbin1'].values[x])
82 bins_y = make_1D_bin(df_weightDB['namebin2'].values[x], df_weightDB['minbin2'].values[x], df_weightDB['maxbin2'].values[x])
83 weightInfo = get_weight("Weight", df_weightDB['w'].values[x], "StatErr", df_weightDB['werr'].values[x])
84 tableIDNotSpec.append([weightInfo, make_2D_bin(bins_x, bins_y)])
85 binID += 1
86 tableIDSpec.append([[weightInfo, make_2D_bin(bins_x, bins_y)], binID])
87
88# And of course let's define out-of-range bin info
89outOfRangeWeightInfo = {}
90outOfRangeWeightInfo["Weight"] = -1
91outOfRangeWeightInfo["StatErr"] = -1
92
93# Now, let's configure table creator
94addtable = b2.register_module('ParticleWeightingLookUpCreator')
95addtable.param('tableIDSpec', tableIDSpec)
96addtable.param('outOfRangeWeight', outOfRangeWeightInfo)
97addtable.param('experimentHigh', -1)
98addtable.param('experimentLow', 0)
99addtable.param('runHigh', -1)
100addtable.param('runLow', 0)
101addtable.param('tableName', tableName)
102
103addtable2 = b2.register_module('ParticleWeightingLookUpCreator')
104addtable2.param('tableIDNotSpec', tableIDNotSpec)
105addtable2.param('outOfRangeWeight', outOfRangeWeightInfo)
106addtable2.param('experimentHigh', -1)
107addtable2.param('experimentLow', 0)
108addtable2.param('runHigh', -1)
109addtable2.param('runLow', 0)
110addtable2.param('tableName', tableName2)
111
112eventinfosetter = b2.register_module('EventInfoSetter')
113eventinfosetter.param('evtNumList', [10])
114eventinfosetter.param('runList', [0])
115eventinfosetter.param('expList', [0])
116
117my_path = b2.create_path()
118my_path.add_module(addtable)
119my_path.add_module(addtable2)
120my_path.add_module(eventinfosetter)
121
122b2.process(my_path)