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