Belle II Software development
B2A307-BasicEventWiseNtupleSelection.py
1#!/usr/bin/env python3
2
3
10
11
35
36import basf2 as b2
37import modularAnalysis as ma
38import variables.collections as vc
39import variables.utils as vu
40import stdCharged as stdc
41from stdPi0s import stdPi0s
42
43# create path
44my_path = b2.create_path()
45
46# load input ROOT file
47ma.inputMdstList(filelist=[b2.find_file('B2pi0D_D2hh_D2hhh_B2munu.root', 'examples', False)],
48 path=my_path)
49
50# We want to apply cut on event shape. For this, we are creating events shape object
51# First, create a list of good tracks (using the pion mass hypothesis)
52# and good gammas with very minimal cuts
53ma.fillParticleList(decayString='pi+:goodtracks',
54 cut='pt> 0.1',
55 path=my_path)
56ma.fillParticleList(decayString='gamma:goodclusters',
57 cut='E > 0.1',
58 path=my_path)
59
60# Second, create event shape
61ma.buildEventShape(inputListNames=['pi+:goodtracks', 'gamma:goodclusters'],
62 allMoments=True,
63 foxWolfram=True,
64 harmonicMoments=True,
65 cleoCones=True,
66 thrust=True,
67 collisionAxis=True,
68 jets=True,
69 sphericity=True,
70 checkForDuplicates=False,
71 path=my_path)
72
73# Apply a selection at the event level, to avoid
74# processing useless events
75ma.applyEventCuts(cut='foxWolframR2 < 0.3', path=my_path)
76
77
78# The following lines cut&pasted from A304
79
80# create and fill final state ParticleLists
81# use standard lists
82# creates "pi+:loose" ParticleList (and c.c.)
83stdc.stdPi(listtype='loose', path=my_path)
84# creates "K+:loose" ParticleList (and c.c.)
85stdc.stdK(listtype='loose', path=my_path)
86# creates "mu+:loose" ParticleList (and c.c.)
87stdc.stdMu(listtype='loose', path=my_path)
88
89
90# creates "pi0:eff40_May2020Fit" ParticleList
91stdPi0s(listtype='eff40_May2020Fit', path=my_path)
92
93
94# 1. reconstruct D0 in multiple decay modes
95ma.reconstructDecay(decayString='D0:ch1 -> K-:loose pi+:loose',
96 cut='1.8 < M < 1.9',
97 dmID=1,
98 path=my_path)
99
100ma.reconstructDecay(decayString='D0:ch2 -> K-:loose pi+:loose pi0:eff40_May2020Fit',
101 cut='1.8 < M < 1.9',
102 dmID=2,
103 path=my_path)
104
105ma.reconstructDecay(decayString='D0:ch3 -> K-:loose pi+:loose pi+:loose pi-:loose',
106 cut='1.8 < M < 1.9',
107 dmID=3,
108 path=my_path)
109
110ma.reconstructDecay(decayString='D0:ch4 -> K-:loose K+:loose',
111 cut='1.8 < M < 1.9',
112 dmID=4,
113 path=my_path)
114
115ma.reconstructDecay(decayString='D0:ch5 -> pi-:loose pi+:loose',
116 cut='1.8 < M < 1.9',
117 dmID=5,
118 path=my_path)
119
120# 2. merge the D0 lists together into one single list
121ma.copyLists(outputListName='D0:all',
122 inputListNames=['D0:ch1', 'D0:ch2', 'D0:ch3', 'D0:ch4', 'D0:ch5'],
123 path=my_path)
124
125
126# 3. reconstruct B+ -> anti-D0 pi+ decay
127ma.reconstructDecay(decayString='B+:tag -> anti-D0:all pi+:loose',
128 cut='5.24 < Mbc < 5.29 and abs(deltaE) < 1.0',
129 dmID=1,
130 path=my_path)
131
132# perform MC matching (MC truth association)
133ma.matchMCTruth(list_name='B+:tag',
134 path=my_path)
135
136
137# 3. reconstruct Upsilon(4S) -> Btag+ Bsig- -> Btag+ mu-
138ma.reconstructDecay(decayString='Upsilon(4S) -> B-:tag mu+:loose',
139 cut="",
140 path=my_path)
141
142# perform MC matching (MC truth association)
143ma.matchMCTruth(list_name='Upsilon(4S)', path=my_path)
144
145# 5. build rest of the event
146ma.buildRestOfEvent(target_list_name='Upsilon(4S)', path=my_path)
147
148d_vars = vc.mc_truth + vc.kinematics + vc.inv_mass + ['foxWolframR2']
149mu_vars = vc.mc_truth
150
151b_vars = vc.mc_truth + \
152 vc.deltae_mbc + \
153 vu.create_aliases_for_selected(list_of_variables=d_vars,
154 decay_string='B- -> ^D0 pi-') + \
155 vu.create_aliases(list_of_variables=['decayModeID'],
156 wrapper='daughter(0,extraInfo({variable}))',
157 prefix="D0") + \
158 ['foxWolframR2']
159
160u4s_vars = vc.mc_truth + \
161 vc.roe_multiplicities + \
162 vc.recoil_kinematics + \
163 vc.extra_energy + \
164 vc.kinematics + \
165 vu.create_aliases_for_selected(list_of_variables=b_vars,
166 decay_string='Upsilon(4S) -> ^B- mu+') + \
167 vu.create_aliases_for_selected(list_of_variables=mu_vars,
168 decay_string='Upsilon(4S) -> B- ^mu+')
169
170
171# 7. Saving variables to ntuple
172rootOutputFile = 'B2A307-BasicEventWiseNtupleSelection.root'
173ma.variablesToNtuple(decayString='B-:tag',
174 variables=b_vars,
175 filename=rootOutputFile,
176 treename='btag',
177 path=my_path)
178ma.variablesToNtuple(decayString='Upsilon(4S)',
179 variables=u4s_vars,
180 filename=rootOutputFile,
181 treename='btagbsig',
182 path=my_path)
183
184# Process the events
185b2.process(my_path)
186
187# print out the summary
188print(b2.statistics)