Belle II Software  release-05-02-19
stdCharged.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 from basf2 import B2ERROR
5 from modularAnalysis import fillParticleList
6 
7 
8 # define arrays to interpret cut matrix
9 _chargednames = ['pi', 'K', 'p', 'e', 'mu']
10 _pidnames = ['pionID', 'kaonID', 'protonID', 'electronID', 'muonID']
11 _effnames = ['95eff', '90eff', '85eff']
12 # default particle list for stdPi() and similar functions
13 _defaultlist = 'good'
14 _mostLikelyList = 'mostlikely'
15 
16 
17 def _stdChargedEffCuts(particletype, listtype):
18  """
19  Provides the PID cut corresponding to a given efficiency percentile
20 
21  @param particletype type of charged particle (pi, K, p, e, mu)
22  @param listtype efficiency percentile for the list (95eff, 90eff, 85eff)
23  """
24 
25  particleindex = _chargednames.index(particletype)
26  effindex = _effnames.index(listtype)
27 
28  # efficiency cuts = [.95,.90,.85] efficiency; values outside (0,1) mean the cut does not exist and an error will be thrown
29  effcuts = [[0.001, 0.019, 0.098],
30  [5e-6, 0.027, 0.167],
31  [0.000, 0.043, 0.251],
32  [0.093, 0.301, 0.709],
33  [0.187, 0.418, 0.909]]
34  #
35  return effcuts[particleindex][effindex]
36 
37 
38 def stdCharged(particletype, listtype, path):
39  """
40  Function to prepare one of several standardized types of charged particle lists:
41  - 'all' with no cuts on track
42  - 'good' high purity lists for data studies
43  - 'loosepid' loose selections for skimming, PID cut only
44  - 'loose' loose selections for skimming
45  - 'higheff' high efficiency list with loose global ID cut for data studies
46  - 'mostlikely' list with the highest PID likelihood
47  Also the following lists, which may or may not be available depending on the release
48  - '99eff' with 99% selection efficiency (calculated for 1<p<4 GeV) and good track (MC only)
49  - '95eff' with 95% selection efficiency (calculated for 1<p<4 GeV) and good track (MC only)
50  - '90eff' with 90% selection efficiency (calculated for 1<p<4 GeV) and good track (MC only)
51  - '85eff' with 85% selection efficiency (calculated for 1<p<4 GeV) and good track (MC only)
52 
53  @param particletype type of charged particle to make a list of
54  @param listtype name of standard list
55  @param path modules are added to this path
56  """
57 
58  # basic quality cut strings
59  trackQuality = 'thetaInCDCAcceptance and nCDCHits>20'
60  ipCut = 'dr < 0.5 and abs(dz) < 2'
61  goodTrack = trackQuality + ' and ' + ipCut
62 
63  if particletype not in _chargednames:
64  B2ERROR("The requested list is not a standard charged particle. Use one of pi, K, e, mu, p.")
65 
66  if listtype == 'all':
67  fillParticleList(particletype + '+:all', '', True, path=path)
68  elif listtype == 'good':
69  fillParticleList(
70  particletype + '+:good',
71  _pidnames[_chargednames.index(particletype)] + ' > 0.5 and ' + goodTrack,
72  True,
73  path=path)
74  elif listtype == 'loose':
75  fillParticleList(
76  particletype + '+:loose',
77  _pidnames[_chargednames.index(particletype)] + ' > 0.1 and ' + goodTrack,
78  True,
79  path=path)
80  elif listtype == 'loosepid':
81  fillParticleList(
82  particletype + '+:loosepid',
83  _pidnames[_chargednames.index(particletype)] + ' > 0.1',
84  True,
85  path=path)
86  elif listtype == 'higheff':
87  fillParticleList(
88  particletype + '+:higheff',
89  _pidnames[_chargednames.index(particletype)] + ' > 0.002 and ' + goodTrack,
90  True,
91  path=path)
92  elif listtype not in _effnames:
93  B2ERROR("The requested list is not defined. Please refer to the stdCharged documentation.")
94  else:
95  pidcut = _stdChargedEffCuts(particletype, listtype)
96  if 0.0 < pidcut < 1.0:
97  fillParticleList(
98  particletype +
99  '+:' +
100  listtype,
101  _pidnames[_chargednames.index(particletype)] +
102  ' > ' +
103  str(pidcut) +
104  ' and ' +
105  goodTrack,
106  True,
107  path=path)
108  else:
109  B2ERROR('The requested standard particle list ' + particletype +
110  '+:' + listtype + ' is not available in this release.')
111 
112 
113 
114 
115 def stdPi(listtype=_defaultlist, path=None):
116  """
117  Function to prepare standard pion lists, refer to stdCharged for details
118 
119  @param listtype name of standard list
120  @param path modules are added to this path
121  """
122  stdCharged('pi', listtype, path)
123 
124 
125 def stdK(listtype=_defaultlist, path=None):
126  """
127  Function to prepare standard kaon lists, refer to stdCharged for details
128 
129  @param listtype name of standard list
130  @param path modules are added to this path
131  """
132  stdCharged('K', listtype, path)
133 
134 
135 def stdPr(listtype=_defaultlist, path=None):
136  """
137  Function to prepare standard proton lists, refer to stdCharged for details
138 
139  @param listtype name of standard list
140  @param path modules are added to this path
141  """
142  stdCharged('p', listtype, path)
143 
144 
145 def stdE(listtype=_defaultlist, path=None):
146  """
147  Function to prepare standard electron lists, refer to stdCharged for details
148 
149  @param listtype name of standard list
150  @param path modules are added to this path
151  """
152  stdCharged('e', listtype, path)
153 
154 
155 def stdMu(listtype=_defaultlist, path=None):
156  """
157  Function to prepare standard muon lists, refer to stdCharged for details
158 
159  @param listtype name of standard list
160  @param path modules are added to this path
161  """
162  stdCharged('mu', listtype, path)
163 
164 
165 def stdMostLikely(pidPriors=None, suffix='', path=None):
166  """
167  Function to prepare most likely particle lists according to PID likelihood, refer to stdCharged for details
168 
169  @param pidPriors list of 5 float numbers used to reweight PID likelihoods
170  @param suffix string added to the end of particle list names
171  @param path modules are added to this path
172  """
173  # Here we need basic track quality cuts to be applied,
174  # otherwise, we get a lot of badly reconstructed particles,
175  # which will end up filled as a random type
176  args = ''
177  if pidPriors is not None:
178  args = str(pidPriors)[1:-1] # remove brackets
179  trackQuality = 'thetaInCDCAcceptance and nCDCHits>20'
180  for name in _chargednames:
181  fillParticleList('%s+:%s' % (name, _mostLikelyList+suffix),
182  'pidIsMostLikely(%s) > 0 and %s' % (args, trackQuality), True, path=path)
stdCharged
Definition: stdCharged.py:1