Belle II Software development
B2A803-TransformerFlavorTagger.py
1#!/usr/bin/env python3
2
3
10
11
30
31import basf2 as b2
32import modularAnalysis as ma
33import tflat.flavorTagger as ft
34import vertex as vx
35import variables.collections as vc
36import variables.utils as vu
37import stdV0s as stdV0s
38
39
40# create path
41main = b2.Path()
42
43# Environment of the MC or data sample
44environmentType = "default"
45
46
47# load input ROOT file
48ma.inputMdst(environmentType=environmentType,
49 filename=b2.find_file('analysis/mdst11_BGx1_b2jpsiks.root', 'validation', False),
50 path=main)
51
52
53# Creates Muon particle list
54ma.fillParticleList(decayString='mu+:all', cut='', path=main)
55
56# reconstruct J/psi -> mu+ mu- decay
57# keep only candidates with dM<0.11
58ma.reconstructDecay(decayString='J/psi:mumu -> mu+:all mu-:all', cut='dM<0.11', path=main)
59
60
61# reconstruct Ks
62stdV0s.stdKshorts(path=main)
63
64# reconstruct B0 -> J/psi Ks decay
65ma.reconstructDecay(decayString='B0:sig -> J/psi:mumu K_S0:merged', cut='Mbc > 5.2 and abs(deltaE)<0.15', path=main)
66
67# Does the matching between reconstructed and MC particles
68ma.matchMCTruth(list_name='B0:sig', path=main)
69
70# build the rest of the event associated to the B0
71ma.buildRestOfEvent(target_list_name='B0:sig', fillWithMostLikely=True,
72 path=main)
73
74b2.conditions.append_globaltag(ma.getAnalysisGlobaltag())
75
76
77# TFlaT Flavor Tagging Function. Do not set uniqueIdentifier to get the official weight files for used release.
78ft.flavorTagger(
79 particleLists=['B0:sig'],
80 path=main)
81
82# You can apply cuts using the flavor Tagger: isNAN(qrTFLAT) < 1 rejects all events which do not
83# provide flavor information using the tag side
84ma.applyCuts(list_name='B0:sig',
85 cut='isNAN(qrTFLAT) < 1',
86 path=main)
87
88# You can rank by highest r- factor
89ma.rankByHighest(particleList='B0:sig',
90 variable='abs(qrTFLAT)',
91 numBest=0,
92 outputVariable='Dilution_rank',
93 path=main)
94
95# Fit vertex of the B0 on the signal side
96vx.kFit(list_name='B0:sig', conf_level=0.0, decay_string='B0:sig -> [J/psi:mumu -> ^mu+ ^mu-] K_S0',
97 constraint='', path=main)
98
99
100# Fit Vertex of the B0 on the tag side
101vx.TagV(list_name='B0:sig', MCassociation='breco', path=main)
102
103# Select variables that will be stored to ntuple
104fs_vars = vc.pid + vc.track + vc.track_hits + vc.mc_truth
105jpsiandk0s_vars = vc.mc_truth
106vertex_vars = vc.vertex + vc.mc_vertex + vc.kinematics + vc.mc_kinematics
107bvars = vc.reco_stats + \
108 vc.deltae_mbc + \
109 vc.mc_truth + \
110 vc.roe_multiplicities + \
111 vc.tag_vertex + \
112 vc.mc_tag_vertex + \
113 vertex_vars
114
115# Add FT output to variables that will be saved
116bvars += ['qrTFLAT']
117
118# Create aliases to save information for different particles
119bvars = bvars + \
120 vu.create_aliases_for_selected(list_of_variables=fs_vars,
121 decay_string='B0 -> [J/psi -> ^mu+ ^mu-] [K_S0 -> ^pi+ ^pi-]') + \
122 vu.create_aliases_for_selected(list_of_variables=jpsiandk0s_vars,
123 decay_string='B0 -> [^J/psi -> mu+ mu-] [^K_S0 -> pi+ pi-]') + \
124 vu.create_aliases_for_selected(list_of_variables=vertex_vars,
125 decay_string='B0 -> [^J/psi -> ^mu+ ^mu-] [^K_S0 -> ^pi+ ^pi-]')
126
127# Saving variables to ntuple
128output_file = 'B2A803-FlavorTagger.root'
129ma.variablesToNtuple(decayString='B0:sig',
130 variables=bvars,
131 filename=output_file,
132 treename='B0tree',
133 path=main)
134
135# Summary of created Lists
136ma.summaryOfLists(particleLists=['J/psi:mumu', 'B0:sig'],
137 path=main)
138
139# Process the events
140b2.process(main, calculateStatistics=True)
stdKshorts(prioritiseV0=True, fitter="TreeFit", path=None, updateAllDaughters=False, writeOut=False, addSuffix=False)
Definition stdV0s.py:25