Belle II Software development
stdPhotons.py
1#!/usr/bin/env python3
2
3
10
11import b2bii
12import modularAnalysis as ma
13from basf2 import B2WARNING
14
15
16def stdPhotons(
17 listtype='loose',
18 path=None,
19 beamBackgroundMVAWeight="",
20 fakePhotonMVAWeight="",
21 biasCorrectionTable=""):
22 """
23 Function to prepare one of several standardized types of photon lists:
24
25 - 'gamma:all' with no cuts this will be polluted by tracks from outside the acceptance
26 - 'gamma:base' clusters in CDC acceptance with a loose timing cut
27 (``inCDCAcceptance and abs(clusterTiming) < 200``), replaces all deprecated lists
28
29 The following lists are **deprecated** and will be removed at the end of 2026:
30
31 - 'gamma:cdc' all clusters inside the CDC tracking acceptance
32 - 'gamma:loose' with some loose quality selections
33 - 'gamma:tight' like loose but with higher energy cuts depending on detector regions
34 - 'gamma:pi0eff60_May2020' gamma list for 60% pi0 efficiency list, optimized in May 2020
35 - 'gamma:pi0eff50_May2020' gamma list for 50% pi0 efficiency list, optimized in May 2020
36 - 'gamma:pi0eff40_May2020' gamma list for 40% pi0 efficiency list, optimized in May 2020
37 - 'gamma:pi0eff30_May2020' gamma list for 30% pi0 efficiency list, optimized in May 2020
38 - 'gamma:pi0eff20_May2020' gamma list for 20% pi0 efficiency list, optimized in May 2020
39 - 'gamma:pi0eff10_May2020' gamma list for 10% pi0 efficiency list, optimized in May 2020
40
41 - For latest pi0 recommendations see https://belle2.pages.desy.de/performance/recommendations/
42
43 Parameters:
44 listtype (str): name of standard list
45 path (basf2.Path): modules are added to this path
46 beamBackgroundMVAWeight (str): type of weight file for beam background MVA; if empty, beam background MVA will not be used
47
48 .. tip::
49 Please refer to the
50 `Performance Recommendations <https://belle2.pages.desy.de/performance/recommendations/>`_
51 for information on the beam background MVA.
52
53 fakePhotonMVAWeight (str): type of weight file for fake photon MVA; if empty, fake photon MVA will not be used
54
55 .. tip::
56 Please refer to the
57 `Performance Recommendations <https://belle2.pages.desy.de/performance/recommendations/>`_
58 for information on the fake photon MVA.
59
60 biasCorrectionTable (str): correction table for the photon energy bias correction (should only be applied to data)
61
62 .. tip::
63 Please refer to the
64 `Performance Recommendations <https://belle2.pages.desy.de/performance/recommendations/>`_
65 for information on the names of available correction tables..
66 """
67
68 _deprecated_photon_lists = {
69 'cdc', 'loose', 'tight',
70 'pi0eff10_May2020', 'pi0eff20_May2020', 'pi0eff30_May2020',
71 'pi0eff40_May2020', 'pi0eff50_May2020', 'pi0eff60_May2020',
72 }
73 if listtype in _deprecated_photon_lists:
74 B2WARNING(
75 f"The standard photon list 'gamma:{listtype}' is deprecated "
76 "and will be removed at the end of 2026. "
77 "Only the 'all' and 'base' lists will be kept. "
78 "Please update your analysis accordingly."
79 )
80
81 # all photons (all neutral ECLClusters that have the c_nPhotons hypothesis)
82 if listtype == 'all':
83 ma.fillParticleList('gamma:all', '', writeOut=True, path=path)
84 # all photons within the cdc tracking acceptance: remove un track-matched
85 # electrons from outside the tracking acceptance
86 elif listtype == 'cdc':
87 ma.fillParticleList(
88 'gamma:cdc',
89 'inCDCAcceptance',
90 writeOut=True,
91 path=path
92 )
93 # clusterErrorTiming < 1e6 removes failed waveform fits, this is not an actual timing cut. A 99% efficiency cut
94 # is already applied on mdst level for photons with E < 50 MeV.
95 elif listtype == 'loose':
96 stdPhotons('cdc', path,
97 beamBackgroundMVAWeight=beamBackgroundMVAWeight,
98 fakePhotonMVAWeight=fakePhotonMVAWeight,
99 biasCorrectionTable=biasCorrectionTable)
100 ma.cutAndCopyList(
101 'gamma:loose',
102 'gamma:cdc',
103 'clusterErrorTiming < 1e6 and [clusterE1E9 > 0.4 or E > 0.075]',
104 True,
105 path)
106 # additional region dependent energy cuts
107 elif listtype == 'tight':
108 stdPhotons('loose', path,
109 beamBackgroundMVAWeight=beamBackgroundMVAWeight,
110 fakePhotonMVAWeight=fakePhotonMVAWeight,
111 biasCorrectionTable=biasCorrectionTable)
112 ma.cutAndCopyList(
113 'gamma:tight',
114 'gamma:loose',
115 '[clusterReg == 1 and E > 0.05] or [clusterReg == 2 and E > 0.05] or [clusterReg == 3 and E > 0.075]',
116 True,
117 path)
118 elif listtype == 'pi0eff10_May2020':
119 ma.fillParticleList(
120 'gamma:pi0eff10_May2020',
121 '[clusterNHits>1.5] and thetaInCDCAcceptance and \
122 [[clusterReg==1 and E>0.200] or [clusterReg==2 and E>0.100] or [clusterReg==3 and E>0.180]] and [clusterE1E9>0.5]',
123 writeOut=True,
124 path=path
125 )
126 elif listtype == 'pi0eff20_May2020':
127 ma.fillParticleList(
128 'gamma:pi0eff20_May2020',
129 '[clusterNHits>1.5] and thetaInCDCAcceptance and \
130 [[clusterReg==1 and E>0.120] or [clusterReg==2 and E>0.030] or [clusterReg==3 and E>0.080]] and [clusterE1E9>0.4]',
131 writeOut=True,
132 path=path
133 )
134 elif listtype == 'pi0eff30_May2020' or listtype == 'pi0eff40_May2020':
135 ma.fillParticleList(
136 f'gamma:{listtype}',
137 '[clusterNHits>1.5] and thetaInCDCAcceptance and \
138 [[clusterReg==1 and E>0.080] or [clusterReg==2 and E>0.030] or [clusterReg==3 and E>0.060 ]]',
139 writeOut=True,
140 path=path
141 )
142 elif listtype == 'pi0eff50_May2020':
143 ma.fillParticleList(
144 'gamma:pi0eff50_May2020',
145 '[clusterNHits>1.5] and thetaInCDCAcceptance and \
146 [[clusterReg==1 and E>0.025] or [clusterReg==2 and E>0.025] or [clusterReg==3 and E>0.040]]',
147 writeOut=True,
148 path=path
149 )
150 elif listtype == 'pi0eff60_May2020':
151 ma.fillParticleList(
152 'gamma:pi0eff60_May2020',
153 '[clusterNHits>1.5] and thetaInCDCAcceptance and \
154 [[clusterReg==1 and E>0.0225] or [clusterReg==2 and E>0.020] or [clusterReg==3 and E>0.020]]',
155 writeOut=True,
156 path=path
157 )
158 elif listtype == 'base':
159 ma.fillParticleList(
160 'gamma:base',
161 'inCDCAcceptance and [abs(clusterTiming) < 200]',
162 writeOut=True,
163 path=path
164 )
165 else:
166 raise ValueError(f"\"{listtype}\" is none of the allowed standardized types of photon lists!")
167
168 if listtype not in ['loose', 'tight']:
169 if beamBackgroundMVAWeight:
170 ma.getBeamBackgroundProbability(particleList=f'gamma:{listtype}', weight=beamBackgroundMVAWeight, path=path)
171 if fakePhotonMVAWeight:
172 ma.getFakePhotonProbability(particleList=f'gamma:{listtype}', weight=fakePhotonMVAWeight, path=path)
173 if biasCorrectionTable:
174 ma.correctEnergyBias(inputListNames=[f'gamma:{listtype}'], tableName=biasCorrectionTable, path=path)
175
176# Used in skimming code
177
178
179def loadStdSkimPhoton(path):
180 """
181 Function to prepare the skim photon lists.
182
183 Warning:
184 Should only be used by skims.
185
186 Parameters:
187 path (basf2.Path): modules are added to this path
188
189 """
190 stdPhotons('loose', path)
191 ma.cutAndCopyList(
192 'gamma:skim',
193 'gamma:loose',
194 '',
195 True,
196 path)
197
198
199def loadStdGoodBellePhoton(path):
200 """
201 Load the Belle goodBelle list. Creates a ParticleList named
202 'gamma:goodBelle' with '0.5 < :b2:var:`goodBelleGamma` < 1.5'
203
204 Parameters:
205 path (basf2.Path): the path to load the modules
206 """
207 if b2bii.isB2BII():
208 ma.cutAndCopyList(
209 'gamma:goodBelle',
210 'gamma:mdst',
211 '0.5 < goodBelleGamma < 1.5',
212 writeOut=True,
213 path=path
214 )
215 else:
216 ma.fillParticleList(
217 'gamma:goodBelle',
218 '0.5 < goodBelleGamma < 1.5',
219 writeOut=True,
220 path=path
221 )
isB2BII()
Definition b2bii.py:14