Belle II Software development
B2A802-GNNFlavorTagger.py
1#!/usr/bin/env python3
2
3
10
11
30
31import basf2 as b2
32import modularAnalysis as ma
33import flavorTagger as ft
34import vertex as vx
35import variables.collections as vc
36import variables.utils as vu
37
38
39# create path
40main = b2.Path()
41
42# Environment of the MC or data sample
43environmentType = "default"
44
45# For Belle data/MC use
46# from b2biiConversion import convertBelleMdstToBelleIIMdst
47# import os
48
49# os.environ['PGUSER'] = 'g0db'
50# os.environ['USE_GRAND_REPROCESS_DATA'] = '1'
51
52# environmentType = "Belle"
53
54# # You can use Belle MC/data as input calling this script as basf2 -i 'YourConvertedBelleData*.root' B2A802-FlavorTagger.py
55# ma.inputMdstList(environmentType=environmentType, filelist=[], path=main)
56
57# load input ROOT file
58ma.inputMdst(environmentType=environmentType,
59 filename=b2.find_file('analysis/mdst11_BGx1_b2jpsiks.root', 'validation', False),
60 path=main)
61
62
63# Creates Muon particle list
64ma.fillParticleList(decayString='mu+:all', cut='', path=main)
65
66# reconstruct J/psi -> mu+ mu- decay
67# keep only candidates with dM<0.11
68ma.reconstructDecay(decayString='J/psi:mumu -> mu+:all mu-:all', cut='dM<0.11', path=main)
69
70
71# For Belle data/MC use
72# # use the existent K_S0:mdst list to reconstruct B0 -> J/psi Ks decay
73# ma.reconstructDecay(decayString='B0:sig -> J/psi:mumu K_S0:mdst', cut='Mbc > 5.2 and abs(deltaE)<0.15', path=main)
74
75
76# reconstruct Ks from standard pi+ particle list
77ma.fillParticleList(decayString='pi+:all', cut='', path=main)
78ma.reconstructDecay(decayString='K_S0:pipi -> pi+:all pi-:all', cut='dM<0.25', path=main)
79
80# reconstruct B0 -> J/psi Ks decay
81ma.reconstructDecay(decayString='B0:sig -> J/psi:mumu K_S0:pipi', cut='Mbc > 5.2 and abs(deltaE)<0.15', path=main)
82
83# Does the matching between reconstructed and MC particles
84ma.matchMCTruth(list_name='B0:sig', path=main)
85
86# build the rest of the event associated to the B0
87ma.buildRestOfEvent(target_list_name='B0:sig', fillWithMostLikely=True,
88 path=main)
89
90b2.conditions.append_globaltag(ma.getAnalysisGlobaltag())
91
92
93# GNN Flavor Tagging Function. Default Expert mode to use the official weight files.
94ft.flavorTagger(
95 particleLists=['B0:sig'],
96 useGNN=True,
97 path=main)
98
99# You can apply cuts using the flavor Tagger: isNAN(qrGNN) < 1 rejects all events which do not
100# provide flavor information using the tag side
101ma.applyCuts(list_name='B0:sig',
102 cut='isNAN(qrGNN) < 1',
103 path=main)
104
105# If you applied the cut on qrGNN > -2 before then you can rank by highest r- factor
106ma.rankByHighest(particleList='B0:sig',
107 variable='abs(qrGNN)',
108 numBest=0,
109 outputVariable='Dilution_rank',
110 path=main)
111
112# Fit vertex of the B0 on the signal side
113vx.kFit(list_name='B0:sig', conf_level=0.0, decay_string='B0:sig -> [J/psi:mumu -> ^mu+ ^mu-] K_S0',
114 constraint='', path=main)
115
116
117# Fit Vertex of the B0 on the tag side
118vx.TagV(list_name='B0:sig', MCassociation='breco', path=main)
119
120# Select variables that will be stored to ntuple
121fs_vars = vc.pid + vc.track + vc.track_hits + vc.mc_truth
122jpsiandk0s_vars = vc.mc_truth
123vertex_vars = vc.vertex + vc.mc_vertex + vc.kinematics + vc.mc_kinematics
124bvars = vc.reco_stats + \
125 vc.deltae_mbc + \
126 vc.mc_truth + \
127 vc.roe_multiplicities + \
128 vc.tag_vertex + \
129 vc.mc_tag_vertex + \
130 vertex_vars
131
132# Attention: the collection of flavor tagging variables is defined in the flavorTagger
133bvars += ft.flavor_tagging
134
135# Create aliases to save information for different particles
136bvars = bvars + \
137 vu.create_aliases_for_selected(list_of_variables=fs_vars,
138 decay_string='B0 -> [J/psi -> ^mu+ ^mu-] [K_S0 -> ^pi+ ^pi-]') + \
139 vu.create_aliases_for_selected(list_of_variables=jpsiandk0s_vars,
140 decay_string='B0 -> [^J/psi -> mu+ mu-] [^K_S0 -> pi+ pi-]') + \
141 vu.create_aliases_for_selected(list_of_variables=vertex_vars,
142 decay_string='B0 -> [^J/psi -> ^mu+ ^mu-] [^K_S0 -> ^pi+ ^pi-]')
143
144# Saving variables to ntuple
145output_file = 'B2A802-FlavorTagger.root'
146ma.variablesToNtuple(decayString='B0:sig',
147 variables=bvars,
148 filename=output_file,
149 treename='B0tree',
150 path=main)
151
152# Summary of created Lists
153ma.summaryOfLists(particleLists=['J/psi:mumu', 'B0:sig'],
154 path=main)
155
156# Process the events
157b2.process(main)
158
159# print out the summary
160print(b2.statistics)