Belle II Software  light-2212-foldex
stdPhotons.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import modularAnalysis as ma
12 
13 
14 def stdPhotons(
15  listtype='loose',
16  path=None,
17  loadPhotonBeamBackgroundMVA=False,
18  loadPhotonHadronicSplitOffMVA=False,
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  loadPhotonBeamBackgroundMVA (bool): If true, photon candidates will be assigned a beam background probability.
42  loadPhotonHadronicSplitOffMVA (bool): If true, photon candidates will be assigned a hadronic split-off probability.
43  biasCorrectionTable (str): correction table for the photon energy bias correction (should only be applied to data)
44 
45  .. tip::
46  Please refer to the
47  `Neutrals Performance Confluence page <https://confluence.desy.de/display/BI/Neutrals+Performance>`_
48  for information on the names of available correction tables..
49  """
50 
51  # all photons (all neutral ECLClusters that have the c_nPhotons hypothesis)
52  if listtype == 'all':
53  ma.fillParticleList('gamma:all', '', writeOut=True, path=path,
54  loadPhotonBeamBackgroundMVA=loadPhotonBeamBackgroundMVA,
55  loadPhotonHadronicSplitOffMVA=loadPhotonHadronicSplitOffMVA)
56  # all photons within the cdc tracking acceptance: remove un track-matched
57  # electrons from outside the tracking acceptance
58  elif listtype == 'cdc':
59  ma.fillParticleList(
60  'gamma:cdc',
61  'inCDCAcceptance',
62  writeOut=True,
63  path=path,
64  loadPhotonBeamBackgroundMVA=loadPhotonBeamBackgroundMVA,
65  loadPhotonHadronicSplitOffMVA=loadPhotonHadronicSplitOffMVA
66  )
67  # clusterErrorTiming < 1e6 removes failed waveform fits, this is not an actual timing cut. A 99% efficiency cut
68  # is already applied on mdst level for photons with E < 50 MeV.
69  elif listtype == 'loose':
70  stdPhotons('cdc', path,
71  loadPhotonBeamBackgroundMVA=loadPhotonBeamBackgroundMVA,
72  loadPhotonHadronicSplitOffMVA=loadPhotonHadronicSplitOffMVA,
73  biasCorrectionTable=biasCorrectionTable)
74  ma.cutAndCopyList(
75  'gamma:loose',
76  'gamma:cdc',
77  'clusterErrorTiming < 1e6 and [clusterE1E9 > 0.4 or E > 0.075]',
78  True,
79  path)
80  # additional region dependent energy cuts
81  elif listtype == 'tight':
82  stdPhotons('loose', path,
83  loadPhotonBeamBackgroundMVA=loadPhotonBeamBackgroundMVA,
84  loadPhotonHadronicSplitOffMVA=loadPhotonHadronicSplitOffMVA,
85  biasCorrectionTable=biasCorrectionTable)
86  ma.cutAndCopyList(
87  'gamma:tight',
88  'gamma:loose',
89  '[clusterReg == 1 and E > 0.05] or [clusterReg == 2 and E > 0.05] or [clusterReg == 3 and E > 0.075]',
90  True,
91  path)
92  elif listtype == 'pi0eff10_May2020':
93  ma.fillParticleList(
94  'gamma:pi0eff10_May2020',
95  '[clusterNHits>1.5] and [0.2967< clusterTheta<2.6180] and \
96  [[clusterReg==1 and E>0.200] or [clusterReg==2 and E>0.100] or [clusterReg==3 and E>0.180]] and [clusterE1E9>0.5]',
97  writeOut=True,
98  path=path,
99  loadPhotonBeamBackgroundMVA=loadPhotonBeamBackgroundMVA,
100  loadPhotonHadronicSplitOffMVA=loadPhotonHadronicSplitOffMVA
101  )
102  elif listtype == 'pi0eff20_May2020':
103  ma.fillParticleList(
104  'gamma:pi0eff20_May2020',
105  '[clusterNHits>1.5] and [0.2967< clusterTheta<2.6180] and \
106  [[clusterReg==1 and E>0.120] or [clusterReg==2 and E>0.030] or [clusterReg==3 and E>0.080]] and [clusterE1E9>0.4]',
107  writeOut=True,
108  path=path,
109  loadPhotonBeamBackgroundMVA=loadPhotonBeamBackgroundMVA,
110  loadPhotonHadronicSplitOffMVA=loadPhotonHadronicSplitOffMVA
111  )
112  elif listtype == 'pi0eff30_May2020' or listtype == 'pi0eff40_May2020':
113  ma.fillParticleList(
114  f'gamma:{listtype}',
115  '[clusterNHits>1.5] and [0.2967< clusterTheta<2.6180] and \
116  [[clusterReg==1 and E>0.080] or [clusterReg==2 and E>0.030] or [clusterReg==3 and E>0.060 ]]',
117  writeOut=True,
118  path=path,
119  loadPhotonBeamBackgroundMVA=loadPhotonBeamBackgroundMVA,
120  loadPhotonHadronicSplitOffMVA=loadPhotonHadronicSplitOffMVA
121  )
122  elif listtype == 'pi0eff50_May2020':
123  ma.fillParticleList(
124  'gamma:pi0eff50_May2020',
125  '[clusterNHits>1.5] and [0.2967< clusterTheta<2.6180] and \
126  [[clusterReg==1 and E>0.025] or [clusterReg==2 and E>0.025] or [clusterReg==3 and E>0.040]]',
127  writeOut=True,
128  path=path,
129  loadPhotonBeamBackgroundMVA=loadPhotonBeamBackgroundMVA,
130  loadPhotonHadronicSplitOffMVA=loadPhotonHadronicSplitOffMVA
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  loadPhotonBeamBackgroundMVA=loadPhotonBeamBackgroundMVA,
140  loadPhotonHadronicSplitOffMVA=loadPhotonHadronicSplitOffMVA
141  )
142  else:
143  raise ValueError(f"\"{listtype}\" is none of the allowed standardized types of photon lists!")
144 
145  if biasCorrectionTable and listtype not in ['loose', 'tight']:
146  ma.correctEnergyBias(inputListNames=[f'gamma:{listtype}'], tableName=biasCorrectionTable, path=path)
147 
148 # Used in skimming code
149 
150 
151 def loadStdSkimPhoton(path):
152  """
153  Function to prepare the skim photon lists.
154 
155  Warning:
156  Should only be used by skims.
157 
158  Parameters:
159  path (basf2.Path): modules are added to this path
160 
161  """
162  stdPhotons('loose', path)
163  ma.cutAndCopyList(
164  'gamma:skim',
165  'gamma:loose',
166  '',
167  True,
168  path)
169 
170 
171 # Only used for Belle via b2bii
172 def loadStdGoodBellePhoton(path):
173  """
174  Load the Belle goodBelle list. Creates a ParticleList named
175  'gamma:goodBelle' with '0.5 < :b2:var:`goodBelleGamma` < 1.5'
176 
177  Warning:
178  Should only be used for Belle analyses using `b2bii`.
179 
180  Parameters:
181  path (basf2.Path): the path to load the modules
182  """
183  ma.fillParticleList('gamma:goodBelle', '0.5 < goodBelleGamma < 1.5', True, path)