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