Belle II Software development
sampler.py
1#!/usr/bin/env python
2
3
10import argparse
11import basf2 as b2
12import modularAnalysis as ma
13from tflat.flavorTagger import flavorTagger
14from b2biiConversion import convertBelleMdstToBelleIIMdst
15import os
16
17
18def reconstructMCB2nunubar(path):
19 """
20 Defines the procedure to create a B0 list for the benchmark channel 'B0 -> nu_tau anti-nu_tau'
21 """
22 ma.fillParticleListFromMC('nu_tau:MC', '', path=path)
23 ma.reconstructMCDecay('B0:sig -> nu_tau:MC anti-nu_tau:MC', '', writeOut=True, path=path)
24
25 # perform MC matching (MC truth association).
26 ma.matchMCTruth(list_name='B0:sig', path=path)
27
28
29def reconstructB2jpsiks(path, is_belle=False):
30 """
31 Defines the procedure to create a B0 list for the benchmark channel 'B0 -> Jpsi KS'
32 """
33 ma.fillParticleList('mu+:all', cut='', path=path)
34 ma.reconstructDecay('J/psi:mumu -> mu+:all mu-:all', cut='abs(dM) < 0.11', path=path)
35 ma.matchMCTruth('J/psi:mumu', path=path)
36
37 if is_belle:
38 ma.matchMCTruth('K_S0:mdst', path=path)
39 ma.reconstructDecay('B0:sig -> J/psi:mumu K_S0:mdst', cut='Mbc > 5.25 and abs(deltaE) < 0.15', path=path)
40 else:
41 ma.fillParticleList('pi+:all', cut='', path=path)
42 ma.reconstructDecay('K_S0:pipi -> pi+:all pi-:all', cut='abs(dM) < 0.25', path=path)
43 ma.matchMCTruth('K_S0:pipi', path=path)
44 ma.reconstructDecay('B0:sig -> J/psi:mumu K_S0:pipi', cut='Mbc > 5.25 and abs(deltaE) < 0.15', path=path)
45
46 # perform MC matching (MC truth association).
47 ma.matchMCTruth(list_name='B0:sig', path=path)
48
49 # keep only signal
50 ma.applyCuts(list_name='B0:sig', cut='[isSignal == 1]', path=path)
51
52
53def main(uniqueIdentifier, inputfile='', working_dir='', is_belle=False, sampler_id=0, channel='nunu'):
54 '''
55 Samples a chunk of training data for TFlat
56 '''
57
58 b2.set_log_level(b2.LogLevel.ERROR)
59 path = b2.Path()
60
61 if not is_belle:
62 b2.conditions.prepend_globaltag(ma.getAnalysisGlobaltag())
63 ma.inputMdstList(environmentType="default", filelist='', path=path)
64 else:
65 # Set Belle enviroment
66 os.environ['USE_GRAND_REPROCESS_DATA'] = '1'
67 os.environ['PGUSER'] = 'g0db'
68
69 # Load and convert input files
70 convertBelleMdstToBelleIIMdst(
71 inputBelleMDSTFile=inputfile,
72 applySkim=False,
73 enableLocalDB=False,
74 generatorLevelMCMatching=False,
75 path=path)
76
77 ma.setAnalysisConfigParams({'mcMatchingVersion': 'Belle'}, path=path)
78 b2.conditions.prepend_globaltag(ma.getAnalysisGlobaltagB2BII())
79
80 if channel == 'nunu':
81 reconstructMCB2nunubar(path)
82 elif channel == 'jpsiks':
83 reconstructB2jpsiks(path, is_belle)
84 else:
85 raise ValueError("Unknown sampler channel!")
86
87 # build the rest of the event associated to the B0
88 ma.buildRestOfEvent(target_list_name='B0:sig', path=path)
89
91 'B0:sig',
92 mode='Sampler',
93 working_dir=working_dir,
94 uniqueIdentifier=uniqueIdentifier,
95 sampler_id=sampler_id,
96 path=path)
97 ma.summaryOfLists(particleLists=['B0:sig'], path=path)
98 b2.process(path)
99 print(b2.statistics)
100
101
102if __name__ == '__main__':
103 '''
104 Samples a chunk of training data for TFlat
105 '''
106 parser = argparse.ArgumentParser(description='Sample TFlat')
107 parser.add_argument(
108 '--uniqueIdentifier',
109 metavar='uniqueIdentifier',
110 dest='uniqueIdentifier',
111 type=str,
112 default="TFlaT_MC16rd_light_2601_hyperion",
113 help='Name of both the config .yaml to be used and the produced weightfile'
114 )
115 parser.add_argument(
116 '--inputfile',
117 metavar='inputfile',
118 dest='inputfile',
119 type=str,
120 default='',
121 help='Inputfile to sample'
122 )
123 parser.add_argument(
124 '--working_dir',
125 metavar='working_dir',
126 dest='working_dir',
127 type=str,
128 default='',
129 help='working_dir'
130 )
131 parser.add_argument(
132 '--BELLE',
133 metavar='BELLE',
134 dest='BELLE',
135 type=bool,
136 default=False,
137 help='Indicate if Belle or Belle II files are to be processed'
138 )
139 parser.add_argument(
140 '--sampler_id',
141 metavar='sampler_id',
142 dest='sampler_id',
143 type=int,
144 default=0,
145 help='sampler_id'
146 )
147 parser.add_argument(
148 '--channel',
149 metavar='channel',
150 dest='channel',
151 type=str,
152 default='nunu',
153 help='Sampler channel: nunu or jpsiks'
154 )
155
156 args = parser.parse_args()
157 uniqueIdentifier = args.uniqueIdentifier
158 inputfile = args.inputfile
159 working_dir = args.working_dir
160 is_belle = args.BELLE
161 sampler_id = args.sampler_id
162 channel = args.channel
163
164 main(uniqueIdentifier, inputfile, working_dir, is_belle, sampler_id, channel)
Definition main.py:1