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