Belle II Software  release-08-01-10
ApplyBelleWeights.py
1 #!/usr/bin/env python3
2 
3 
10 
11 
19 
20 import basf2 as b2
21 import modularAnalysis as ma
22 import variables as va
23 import os
24 from b2biiConversion import convertBelleMdstToBelleIIMdst
25 
26 # Usual b2bii magic
27 os.environ['PGUSER'] = 'g0db'
28 os.environ['BELLE_POSTGRES_SERVER'] = 'can01'
29 os.environ['USE_GRAND_REPROCESS_DATA'] = '1'
30 
31 my_path = b2.create_path()
32 
33 # Adding database with weight tables
34 b2.conditions.prepend_globaltag("BellePID")
35 
36 # Read in and convert Belle mdst
37 inputfile = b2.find_file('b2bii_input_evtgen_exp_07_BptoD0pip-D0toKpipi0-0.mdst', 'examples', False)
38 convertBelleMdstToBelleIIMdst(inputfile, path=my_path)
39 
40 """
41 In this example, we add information from three types of weight tables to the track.
42 Since there are only three types of such tables, the example is quite full.
43 Each weight table contains variables listed in the example.
44 Meaning of the variables can be found in Belle documentation (see links in the body of the example).
45 """
46 
47 ma.fillParticleList(decayString='pi+:all', cut='', path=my_path)
48 
49 """
50 Lepton ID
51 
52 Several weight tables were produced for lepton ID correction at Belle.
53 Naming scheme for payloads is:
54 
55 BelleLID<e|mu>_<LID cut>
56 
57 Study was done for different cut set for electrons and muons.
58 Possible cuts for electron:
59 0.01, 0.10, 0.50, 0.60, 0.80, 0.90
60 
61 Possible cuts for muons:
62 0.10, 0.80, 0.90, 0.95, 0.97
63 
64 Sources of original Belle results are here:
65 https://belle.kek.jp/group/pid_joint/lid/final/
66 
67 Here we add PID correction information that is important for
68 electrons selected with "eIDBelle>0.9" cut.
69 """
70 lid_table = "BelleLIDe_0.90"
71 
72 va.variables.addAlias('LID_ratio', 'extraInfo('+lid_table+'_ratio)')
73 va.variables.addAlias('LID_ratio_stat_err', 'extraInfo('+lid_table+'_ratio_stat_err)')
74 va.variables.addAlias('LID_ratio_syst_err', 'extraInfo('+lid_table+'_ratio_syst_err)')
75 va.variables.addAlias('LID_ratio_syst_err_from_2photon', 'extraInfo('+lid_table+'_ratio_syst_err_from_2photon)')
76 va.variables.addAlias('LID_ratio_syst_err_from_JPsi', 'extraInfo('+lid_table+'_ratio_syst_err_from_JPsi)')
77 va.variables.addAlias('LID_run_bin', 'extraInfo('+lid_table+'_run_bin)')
78 va.variables.addAlias('LID_kinematic_bin', 'extraInfo('+lid_table+'_kinematic_bin)')
79 
80 lid_weights = ['LID_ratio',
81  'LID_ratio_stat_err',
82  'LID_ratio_syst_err',
83  'LID_ratio_syst_err_from_2photon',
84  'LID_ratio_syst_err_from_JPsi',
85  'LID_run_bin',
86  'LID_kinematic_bin']
87 
88 reweighter = b2.register_module('ParticleWeighting')
89 reweighter.param('tableName', lid_table)
90 reweighter.param('particleList', 'pi+:all')
91 my_path.add_module(reweighter)
92 
93 
94 """
95 Kaon ID
96 
97 Several weight tables were produced for kaon/pion ID corrections at Belle.
98 Naming scheme for payloads is:
99 
100 BelleKID<K|Pi><Eff|Fake><Combined|Plus|Minus>_<PID cut:[1..9]>
101 
102 Here,
103  - K or Pi refers to correction information obtained for kaons or pions, accordingly
104  - Eff or Fake refers to efficiency or fake rate corrections
105  - Combined, Plus or Minus refers to the charge of tracks used for the study
106  - PID cut is an integer number from 1 to 9 that correspond to "cut > 0.number"
107 
108 Information is taken from here:
109  https://belle.kek.jp/group/pid_joint/kid/files-2006/
110 
111 Here we add PID correction information for pion efficiency selected as kaons with
112 "kaonIDBelle>0.1" cut.
113 
114 """
115 kid_table = "BelleKIDPiFakePlus_1"
116 
117 va.variables.addAlias('KID_eff_data', 'extraInfo('+kid_table+'_eff_data)')
118 va.variables.addAlias('KID_eff_data_stat_err', 'extraInfo('+kid_table+'_eff_data_stat_err)')
119 va.variables.addAlias('KID_eff_data_syst_err', 'extraInfo('+kid_table+'_eff_data_syst_err)')
120 va.variables.addAlias('KID_eff_mc', 'extraInfo('+kid_table+'_eff_mc)')
121 va.variables.addAlias('KID_eff_mc_stat_err', 'extraInfo('+kid_table+'_eff_mc_stat_err)')
122 va.variables.addAlias('KID_fit_flag', 'extraInfo('+kid_table+'_fit_flag)')
123 va.variables.addAlias('KID_kinematic_bin', 'extraInfo('+kid_table+'_kinematic_bin)')
124 va.variables.addAlias('KID_ratio', 'extraInfo('+kid_table+'_ratio)')
125 va.variables.addAlias('KID_ratio_stat_err', 'extraInfo('+kid_table+'_ratio_stat_err)')
126 va.variables.addAlias('KID_ratio_syst_err', 'extraInfo('+kid_table+'_ratio_syst_err)')
127 va.variables.addAlias('KID_run_bin', 'extraInfo('+kid_table+'_run_bin)')
128 
129 kid_weights = ['KID_eff_data',
130  'KID_eff_data_stat_err',
131  'KID_eff_data_syst_err',
132  'KID_eff_mc',
133  'KID_eff_mc_stat_err',
134  'KID_fit_flag',
135  'KID_ratio',
136  'KID_ratio_stat_err',
137  'KID_ratio_syst_err',
138  'KID_run_bin',
139  'KID_kinematic_bin']
140 
141 reweighter2 = b2.register_module('ParticleWeighting')
142 reweighter2.param('tableName', kid_table)
143 reweighter2.param('particleList', 'pi+:all')
144 my_path.add_module(reweighter2)
145 
146 
147 """
148 Proton ID
149 
150 Several weight tables were produced for proton ID corrections at Belle.
151 Naming scheme for payloads is:
152 
153 BellePID<Plus|Minus>_<PID cut>
154 
155 Here,
156  - Plus or Minus refers to the charge of tracks used for the study
157  - PID cut can be 0.6, 0.7, 0.8 or 0.9
158 
159 Information is taken from here:
160  https://belle.kek.jp/group/pid_joint/protonid/
161 
162 Here we add PID correction information for proton efficiency selected with
163 "protonIDBelle>0.6" cut.
164 """
165 pid_table = "BellePIDPlus_0.6"
166 
167 va.variables.addAlias("PID_eff_data", 'extraInfo('+pid_table+"_eff_data)")
168 va.variables.addAlias("PID_eff_data_stat_err", 'extraInfo('+pid_table+"_eff_data_stat_err)")
169 va.variables.addAlias("PID_eff_mc", 'extraInfo('+pid_table+"_eff_mc)")
170 va.variables.addAlias("PID_eff_mc_stat_err", 'extraInfo('+pid_table+"_eff_mc_stat_err)")
171 va.variables.addAlias("PID_ratio", 'extraInfo('+pid_table+"_ratio)")
172 va.variables.addAlias("PID_ratio_stat_err", 'extraInfo('+pid_table+"_ratio_stat_err)")
173 va.variables.addAlias("PID_ratio_syst_err", 'extraInfo('+pid_table+"_ratio_syst_err)")
174 va.variables.addAlias("PID_kinematic_bin", 'extraInfo('+pid_table+"_kinematic_bin)")
175 va.variables.addAlias("PID_run_bin", 'extraInfo('+pid_table+"_run_bin)")
176 
177 pid_weights = ["PID_eff_data",
178  "PID_eff_data_stat_err",
179  "PID_eff_mc",
180  "PID_eff_mc_stat_err",
181  "PID_ratio",
182  "PID_ratio_stat_err",
183  "PID_ratio_syst_err",
184  "PID_run_bin",
185  "PID_kinematic_bin"]
186 
187 
188 reweighter3 = b2.register_module('ParticleWeighting')
189 reweighter3.param('tableName', pid_table)
190 reweighter3.param('particleList', 'pi+:all')
191 my_path.add_module(reweighter3)
192 
193 """
194 All weighting modules are configured.
195 Let's add some tracks and add the information from weighting tables to them.
196 """
197 pivars = ['p', 'pz']
198 pivars += kid_weights
199 pivars += lid_weights
200 pivars += pid_weights
201 
202 
203 # Saving variables to ntuple
204 output_file = 'ApplyBelleWeightsToTracks.root'
205 ma.variablesToNtuple(decayString='pi+:all',
206  variables=pivars,
207  treename='pion',
208  filename=output_file,
209  path=my_path)
210 
211 # Process the events
212 b2.process(my_path)
213 
214 # print out the summary
215 print(b2.statistics)