Belle II Software development
B2A306-B02RhoGamma-withPi0EtaVeto.py
1#!/usr/bin/env python3
2
3
10
11
33
34import basf2 as b2
35import modularAnalysis as ma
36import variables.collections as vc
37import variables.utils as vu
38from stdCharged import stdK
39
40# create path
41my_path = b2.create_path()
42
43# writePi0EtaVeto uses a payload in analysis global tag.
44b2.conditions.prepend_globaltag(ma.getAnalysisGlobaltag())
45
46# load input ROOT file
47ma.inputMdst(filename=b2.find_file('B2rhogamma_rho2pipi.root', 'examples', False),
48 path=my_path)
49
50ma.fillParticleList(decayString='gamma:highE',
51 cut='E > 1.5',
52 path=my_path)
53ma.fillParticleList(decayString='pi+:loose',
54 cut='abs(d0) < 0.5 and abs(z0) < 0.5 and pionID > 0.002',
55 path=my_path)
56
57# reconstruct rho -> pi+ pi- decay
58# keep only candidates with 0.6 < M(pi+pi-) < 1.0 GeV
59ma.reconstructDecay(decayString='rho0 -> pi+:loose pi-:loose',
60 cut='0.6 < M < 1.0',
61 path=my_path)
62
63# reconstruct B0 -> rho0 gamma decay
64# keep only candidates with Mbc > 5.2 GeV
65# and -2 < Delta E < 2 GeV
66ma.reconstructDecay(decayString='B0 -> rho0 gamma:highE',
67 cut='5.2 < Mbc and abs(deltaE) < 2.0',
68 path=my_path)
69
70# perform MC matching (MC truth association)
71ma.matchMCTruth(list_name='B0',
72 path=my_path)
73
74# build RestOfEvent (ROE) object for each B0 candidate
75# ROE is required by the veto
76ma.buildRestOfEvent(target_list_name='B0',
77 path=my_path)
78
79# perform pi0/eta veto
80# particleList : Signal side particle's particleList
81# decayString : DecayString specifying a particle which is used to calculate the pi0/eta probability
82# mode : One can select the payload from 'standard'(default), 'tight', 'cluster', and 'both'.
83# Each payload is optimized for different soft-photon selection criteria.
84# If one wants to use one's own payload and soft-photon criteria, please use arguments,
85# pi0PayloadNameOverride, pi0SoftPhotonCutOverride, etaPayloadNameOverride, etaSoftPhotonCutOverride,
86modePi0EtaVeto = 'standardMC16rd'
87ma.writePi0EtaVeto(particleList='B0',
88 decayString='B0 -> rho0 ^gamma',
89 mode=modePi0EtaVeto,
90 path=my_path)
91
92# Perform addPi0VetoEfficiencySystematics
93# Data/MC ratio will be provided as extraInfo related with particleList for a given threshold.
94mode = 'standard'
95tableName = 'Pi0VetoEfficiencySystematics_Mar2022'
96threshold = 0.30
97suffix = '30'
98ma.addPi0VetoEfficiencySystematics(particleList='B0',
99 decayString='B0 -> rho0 ^gamma',
100 tableName=tableName,
101 threshold=threshold,
102 mode='standard',
103 suffix=suffix,
104 path=my_path)
105
106# Then one can obtain the pi0/eta probability by the variables pi0Prob(arg) and etaProb(arg).
107# The argument corresponds to the mode which you set in writePi0EtaVeto function.
108# In above case, one can call pi0Probe(standard) and etaProb(standard).
109# For the B0 candidates whose gamma daughter could not be combined with
110# any of the remaining photons to form pi0/eta because of soft photon selection
111# NaN will be written to the pi0Probe(standard) branch and etaProb(standard) branch.
112
113# For the validation purpose, one may want to calculate the pi0/eta probability using a particle other than a photon.
114# Example : B+ -> anti-D0 pi+. This is one of the modes to validate the pi0/eta veto tool.
115stdK('loose', path=my_path)
116ma.reconstructDecay("D0:Kpi -> K-:loose pi+:loose", "", path=my_path)
117ma.reconstructDecay("B+:Dpi -> anti-D0:Kpi pi+:loose", "useCMSFrame(daughter(1,E))>1.4", path=my_path)
118ma.matchMCTruth("B+:Dpi", path=my_path)
119ma.buildRestOfEvent("B+:Dpi", path=my_path)
120
121# hardParticle : If one wants to use non-gamma particle to calculate the pi0/eta probability,
122# you have to tell the particle name with an argument hardParticle. (default: gamma)
123ma.writePi0EtaVeto(particleList='B+:Dpi',
124 decayString='B+ -> [anti-D0 -> K+ pi-] ^pi+',
125 mode='standard',
126 hardParticle='pi+',
127 path=my_path)
128
129
130# The weight files are optimised by MC campaign 12.
131# If you train by yourself, you should refer to
132# B2A701-ContinuumSuppression_Input.py
133# B2A702-ContinuumSuppression_MVATrain.py
134
135
136# You can also do a simple veto using delta mass ranking as below.
137
138# VETO starts here
139# ----------------
140
141# Create a new path (called ROE path) which will be executed for
142# each ROE in an event.
143# Note that ROE exists for each B0 candidate, so when we loop
144# over each ROE, we effectively loop over signal B0 candidates
145
146roe_path = b2.create_path()
147
148# The ROE objects might in general be related to Particle from multiple
149# particle lists therefore we need to check if the current ROE object
150# is related to the Particle from our signal decay. If it is not
151# the execution of roe_path will be finished (by starting empty,
152# dead end path). Note that in this example this x-check is not
153# necessary, but is anyway added for sake of completeness
154deadEndPath = b2.create_path()
155
156# Note again: all actions (modules) included in roe_path will be
157# executed for each ROE in the event
158# First we check that the current ROE is related to B0 candidate
159ma.signalSideParticleFilter(particleList='B0',
160 selection='',
161 roe_path=roe_path,
162 deadEndPath=deadEndPath)
163
164# create and fill gamma ParticleList that will contain
165# all photons found in ROE (not used to reconstruct current B0 candidate)
166# The photons need to have energy above 50 MeV to be considered
167# (one can add any cut)
168ma.fillParticleList(decayString='gamma:roe',
169 cut='isInRestOfEvent == 1 and E > 0.050',
170 path=roe_path)
171
172# in order to be able to use modularAnalysis functions (reconstructDecay in particular)
173# we need a ParticleList containing the photon candidate used to reconstruct the
174# current B meson as well
175# The DecayString is used to specify the selected particle (^)
176ma.fillSignalSideParticleList(outputListName='gamma:sig',
177 decayString='B0 -> rho0 ^gamma',
178 path=roe_path)
179
180# make combinations of signal photon candidates with all photons from ROE
181# keep only combinations in given invariant mass range
182ma.reconstructDecay(decayString='pi0:veto -> gamma:sig gamma:roe',
183 cut='0.080 < M < 0.200',
184 path=roe_path)
185
186# at this point one could use all features provided by the analysis software
187# to make the veto as effective as possible. For example, one can perform truth
188# matching, training/applying TMVA classifier, save pi0 candidates with ntuple
189# maker for offline analysis/study.
190
191# in this example the variable, which is used to veto pi0 is very simple:
192# invariant mass of pi0 that is closest to the pi0's nominal mass
193# Therefore, we just simply rank pi0 candidates according to their distance
194# from nominal mass (dM variable) and keep only the best candidate
195ma.rankByLowest(particleList='pi0:veto',
196 variable='abs(dM)',
197 numBest=1,
198 path=roe_path)
199
200# write the invariant mass of the best pi0 candidate to the current B0
201# candidate as the 'pi0veto' extraInfo
202ma.variableToSignalSideExtraInfo(particleList='pi0:veto', varToExtraInfo={'M': 'pi0veto'}, path=roe_path)
203
204# execute roe_path for each RestOfEvent in the event
205my_path.for_each('RestOfEvent', 'RestOfEvents', roe_path)
206
207# VETO ends here
208# ----------------
209
210# we're now out of the ROE path
211# at this stage the B0 candidates should have
212# extraInfo(pi0veto) value attached. For the B0
213# candidates whose gamma daughter could not be combined with
214# any of the remaining photons to form pi0 within given mass
215# range the extraInfo(pi0veto) does not exist. In these cases
216# NaN will be written to the extraInfo(pi0veto) branch
217# Select variables that we want to store to ntuple
218
219gamma_vars = vc.cluster + \
220 vc.mc_truth + \
221 vc.kinematics
222
223rho_vars = vc.cluster + \
224 vc.mc_truth + \
225 vc.kinematics + \
226 vc.inv_mass
227
228pi_vars = vc.track
229
230b_vars = vc.kinematics + \
231 vc.deltae_mbc + \
232 vc.mc_truth + \
233 vu.create_aliases_for_selected(list_of_variables=gamma_vars,
234 decay_string='B0 -> rho0 ^gamma') + \
235 vu.create_aliases_for_selected(list_of_variables=rho_vars,
236 decay_string='B0 -> ^rho0 gamma') + \
237 vu.create_aliases_for_selected(list_of_variables=pi_vars,
238 decay_string='B0 -> [rho0 -> ^pi+ ^pi-] gamma') + \
239 [f'pi0Prob({modePi0EtaVeto})', f'etaProb({modePi0EtaVeto})', 'extraInfo(pi0veto)'] + \
240 [f'extraInfo(Pi0VetoEfficiencySystematics_{mode}{suffix}_data_MC_ratio)',
241 f'extraInfo(Pi0VetoEfficiencySystematics_{mode}{suffix}_data_MC_uncertainty_stat)',
242 f'extraInfo(Pi0VetoEfficiencySystematics_{mode}{suffix}_data_MC_uncertainty_sys)',
243 f'extraInfo(Pi0VetoEfficiencySystematics_{mode}{suffix}_data_MC_uncertainty_total)',
244 f'extraInfo(Pi0VetoEfficiencySystematics_{mode}{suffix}_threshold)']
245
246
247# Saving variables to ntuple
248rootOutputFile = "B2A306-B02RhoGamma-withPi0EtaVeto.root"
249ma.variablesToNtuple(decayString='B0',
250 variables=b_vars,
251 filename=rootOutputFile,
252 treename='b0',
253 path=my_path)
254
255# Process the events
256b2.process(my_path, calculateStatistics=True)