Belle II Software  release-08-01-10
B2A904-LookUpTableCreation.py
1 #!/usr/bin/env python3
2 
3 
10 
11 
19 
20 import basf2 as b2
21 import random
22 
23 # Add some bin constructors
24 
25 
26 def make_1D_bin(name, min_val, max_val):
27  return {name: [min_val, max_val]}
28 
29 
30 def make_2D_bin(bin_x, bin_y):
31  bin_2d = bin_x.copy()
32  bin_2d.update(bin_y)
33  return bin_2d
34 
35 
36 def make_3D_bin(bin_x, bin_y, bin_z):
37  bin_3d = bin_x.copy()
38  bin_3d.update(bin_y).update(bin_z)
39  return bin_3d
40 
41 
42 # Define bin ranges. Bins may be of different size
43 # They shouldn't event cover the whole parameter space
44 bins_x = [make_1D_bin("p", 0, 2),
45  make_1D_bin("p", 2, 3),
46  make_1D_bin("p", 3, 4)]
47 
48 bins_y = [make_1D_bin("pz", 0, 1),
49  make_1D_bin("pz", 1, 5)]
50 
51 
52 # Here would be input from the experts.
53 # We don't have real calibration tables yet
54 # So we use randomized info.
55 # Bin IDs will be automatically assigned as follows:
56 #
57 # p|0-2|2-3|3-4|
58 # pz| | | |
59 # -------------
60 # 0-1| 0 | 2 | 4 |
61 # ---------------|
62 # 1-5| 1 | 3 | 5 |
63 # -------------
64 
65 tableIDNotSpec = []
66 random.seed()
67 for xbin in bins_x:
68  for ybin in bins_y:
69  weightInfo = {}
70  weightInfo["Weight"] = float(random.randint(0, 100)) / 100
71  weightInfo["StatErr"] = float(random.randint(100, 200)) / 100
72  weightInfo["SystErr"] = float(10)
73  tableIDNotSpec.append([weightInfo, make_2D_bin(xbin, ybin)])
74 
75 # Now let's assign binIDs manually (to be able to assign identical IDs for different bins)
76 # Let's do this structure of bins (out-of-range bin -1 is assigned later):
77 #
78 # p|0-2|2-3|3-4|
79 # pz| | | |
80 # ---------------|
81 # | |
82 # ------------- |
83 # 0-1| 43| 45| | |
84 # ------------ | |
85 # 1-5| 44| 46| |
86 # ------------- |
87 # | -1|
88 # ---------------|
89 tableIDSpec = []
90 random.seed()
91 binID = 42
92 weightInfo = {}
93 for xbin in bins_x:
94  for ybin in bins_y:
95  if binID < 46:
96  binID += 1
97  weightInfo = {}
98  weightInfo["Weight"] = float(random.randint(0, 100)) / 100
99  weightInfo["StatErr"] = float(random.randint(100, 200)) / 100
100  weightInfo["SystErr"] = float(10)
101  tableIDSpec.append([[weightInfo, make_2D_bin(xbin, ybin)], binID])
102 
103 # And of course let's define out-of-range bin info
104 outOfRangeWeightInfo = {}
105 outOfRangeWeightInfo["Weight"] = -1
106 outOfRangeWeightInfo["StatErr"] = -1
107 outOfRangeWeightInfo["SystErr"] = -1
108 
109 # Now, let's configure table creator
110 addtable = b2.register_module('ParticleWeightingLookUpCreator')
111 addtable.param('tableIDSpec', tableIDSpec)
112 addtable.param('outOfRangeWeight', outOfRangeWeightInfo)
113 addtable.param('experimentHigh', 1000)
114 addtable.param('experimentLow', 0)
115 addtable.param('runHigh', 1000)
116 addtable.param('runLow', 0)
117 addtable.param('tableName', "ParticleReweighting:TestMomentum")
118 
119 addtable2 = b2.register_module('ParticleWeightingLookUpCreator')
120 addtable2.param('tableIDNotSpec', tableIDNotSpec)
121 addtable2.param('outOfRangeWeight', outOfRangeWeightInfo)
122 addtable2.param('experimentHigh', 1000)
123 addtable2.param('experimentLow', 0)
124 addtable2.param('runHigh', 1000)
125 addtable2.param('runLow', 0)
126 addtable2.param('tableName', "ParticleReweighting:TestMomentum2")
127 
128 eventinfosetter = b2.register_module('EventInfoSetter')
129 eventinfosetter.param('evtNumList', [10])
130 eventinfosetter.param('runList', [0])
131 eventinfosetter.param('expList', [0])
132 
133 my_path = b2.create_path()
134 my_path.add_module(addtable)
135 my_path.add_module(addtable2)
136 my_path.add_module(eventinfosetter)
137 
138 b2.process(my_path)