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