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