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