atlas-ftag-tools 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atlas-ftag-tools
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: ATLAS Flavour Tagging Tools
5
5
  Author: Sam Van Stroud, Philipp Gadow
6
6
  License: MIT
@@ -11,8 +11,8 @@ Requires-Dist: h5py >=3.0
11
11
  Requires-Dist: numpy
12
12
  Requires-Dist: PyYAML >=5.1
13
13
  Provides-Extra: dev
14
- Requires-Dist: ruff ==0.2.2 ; extra == 'dev'
15
- Requires-Dist: mypy ==1.5.1 ; extra == 'dev'
14
+ Requires-Dist: ruff ==0.6.2 ; extra == 'dev'
15
+ Requires-Dist: mypy ==1.11.2 ; extra == 'dev'
16
16
  Requires-Dist: pre-commit ==3.1.1 ; extra == 'dev'
17
17
  Requires-Dist: pytest ==7.2.2 ; extra == 'dev'
18
18
  Requires-Dist: pytest-cov ==4.0.0 ; extra == 'dev'
@@ -1,10 +1,10 @@
1
- ftag/__init__.py,sha256=w5AN4J84WCX5o22f3aAcidCQISyQgYqeyfWQlMJCzfU,629
1
+ ftag/__init__.py,sha256=7IKOa65yKaQWsx6-s7VVQs4t1NQ9hyVAOlj-U5m-VBk,629
2
2
  ftag/cli_utils.py,sha256=w3TtQmUHSyAKChS3ewvOtcSDAUJAZGIIomaNi8f446U,298
3
3
  ftag/cuts.py,sha256=a0BJj4cVRunc-hFLPloGvNoSFvRmZg2kVLv7sA0iAaI,2817
4
4
  ftag/flavour.py,sha256=qvgp4DarOdcQgjae_NWnd81k_YqdmFY74lOKky2lpb8,3568
5
- ftag/flavours.yaml,sha256=9ifKyz1_VoHlOaWuf3JEqMLSYyLFedYJf9x1D6dCTnM,5335
5
+ ftag/flavours.yaml,sha256=lFnVwjh_DwLhOc3mr5n6bSIWyHgxQvAXas4lEmEDncU,7520
6
6
  ftag/git_check.py,sha256=Y-XqM80CVXZ5ZKrDdZcYOJt3X64uU6W3OP6Z0D7AZU0,1663
7
- ftag/mock.py,sha256=9V6sAT4_t-rhR67q9KHaj1NKAeqU7lQjWxiOxEzk8Sw,4338
7
+ ftag/mock.py,sha256=QAm0ti6FWDCRtIyay4yozbGNNATDQbq5b1uc8uVhi2s,4275
8
8
  ftag/region.py,sha256=ANv0dGI2W6NJqD9fp7EfqAUReH4FOjc1gwl_Qn8llcM,360
9
9
  ftag/sample.py,sha256=TFXMhDkbPmjkms9-b-bINJ32T3bO86JcU70C0nY7wa8,2500
10
10
  ftag/test_cli_utils.py,sha256=xa08vf6SEOow58SSFagYdAselb-dkNOVvWsWheMnW-g,1001
@@ -12,15 +12,15 @@ ftag/transform.py,sha256=uEGGJSnqoKOzLYQv650XdK_kDNw4Aw-5dc60z9Dp_y0,3963
12
12
  ftag/vds.py,sha256=nRViQZQIORB95nC7NZsW3KsSoGkLzEdOsuCViH5h8-U,3296
13
13
  ftag/hdf5/__init__.py,sha256=LFDNxVOCp58SvLHwQhdT68Q-KBMS_i6jBrbXoRpHzbM,354
14
14
  ftag/hdf5/h5move.py,sha256=oYpRu0IDCIJIQ2ML52HBAdoyDxmKkHTeM9JdbPEgKfI,947
15
- ftag/hdf5/h5reader.py,sha256=et-_LXt942xegqc14bPapUgIO7MUfC2m04uJslLkXxI,13579
15
+ ftag/hdf5/h5reader.py,sha256=H_5Aw0lOyEzK_phMRhD-jR_OSCsXnCA3qJZnRvPqaRU,13569
16
16
  ftag/hdf5/h5split.py,sha256=4Wy6Xc3J58MdD9aBaSZHf5ZcVFnJSkWsm42R5Pgo-R4,2448
17
17
  ftag/hdf5/h5utils.py,sha256=-4zKTMtNCrDZr_9Ww7uzfsB7M7muBKpmm_1IkKJnHOI,3222
18
- ftag/hdf5/h5writer.py,sha256=wVyurIgfSBtvZTX-v0v3R5-8JOwWK_yF1rUX-RewXzY,4826
18
+ ftag/hdf5/h5writer.py,sha256=j3Fy8snkiVVfimiUz3rrZOhSV8OF27978Y9pk0QcTGM,5277
19
19
  ftag/wps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
- ftag/wps/discriminant.py,sha256=J2Cst9slZCLoHZYTeltQSmN1Uoa8GUX529rwNlHmyfI,3519
20
+ ftag/wps/discriminant.py,sha256=kJFekUTPNIvCabJCon6OqOAQEzz5hj3XrWFFRLOgGOs,3836
21
21
  ftag/wps/working_points.py,sha256=VTU6OD40ULAJQD0MlD1EZd33q8ociUvFX1YrhgJFvXc,9722
22
- atlas_ftag_tools-0.2.0.dist-info/METADATA,sha256=MRi8CwbXm8vSXlwSFUM99Ec5ZibMtVXdJVqdb0gAv94,5168
23
- atlas_ftag_tools-0.2.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
24
- atlas_ftag_tools-0.2.0.dist-info/entry_points.txt,sha256=LfVLsZHQolqbPnwPgtmc5IQTh527BKkN2v-IpXWTNHw,137
25
- atlas_ftag_tools-0.2.0.dist-info/top_level.txt,sha256=qiYQuKcAvMim-31FwkT3MTQu7WQm0s58tPAia5KKWqs,5
26
- atlas_ftag_tools-0.2.0.dist-info/RECORD,,
22
+ atlas_ftag_tools-0.2.2.dist-info/METADATA,sha256=y2fq23cqtkaoUQxEiCrdoTVuBcG154yjo4k4cwf8P-A,5169
23
+ atlas_ftag_tools-0.2.2.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
24
+ atlas_ftag_tools-0.2.2.dist-info/entry_points.txt,sha256=LfVLsZHQolqbPnwPgtmc5IQTh527BKkN2v-IpXWTNHw,137
25
+ atlas_ftag_tools-0.2.2.dist-info/top_level.txt,sha256=qiYQuKcAvMim-31FwkT3MTQu7WQm0s58tPAia5KKWqs,5
26
+ atlas_ftag_tools-0.2.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (74.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
ftag/__init__.py CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- __version__ = "v0.2.0"
5
+ __version__ = "v0.2.2"
6
6
 
7
7
 
8
8
  from ftag import hdf5
ftag/flavours.yaml CHANGED
@@ -47,6 +47,28 @@
47
47
  colour: gold
48
48
  category: single-btag-extended
49
49
 
50
+ # single b-tagging (ghost association)
51
+ - name: ghostbjets
52
+ label: $b$-jets
53
+ cuts: ["HadronGhostTruthLabelID == 5"]
54
+ colour: tab:blue
55
+ category: single-btag-ghost
56
+ - name: ghostcjets
57
+ label: $c$-jets
58
+ cuts: ["HadronGhostTruthLabelID == 4"]
59
+ colour: tab:orange
60
+ category: single-btag-ghost
61
+ - name: ghostujets
62
+ label: Light-jets
63
+ cuts: ["HadronGhostTruthLabelID == 0"]
64
+ colour: tab:green
65
+ category: single-btag-ghost
66
+ - name: ghosttaujets
67
+ label: $\tau$-jets
68
+ cuts: ["HadronGhostTruthLabelID == 15"]
69
+ colour: tab:purple
70
+ category: single-btag-ghost
71
+
50
72
  # Xbb tagging
51
73
  - name: hbb
52
74
  label: $H \rightarrow b\bar{b}$
@@ -140,37 +162,84 @@
140
162
  colour: "#e76f51"
141
163
  category: lepton-decay
142
164
 
165
+ # PDGID labelling: taken from https://pdg.lbl.gov/2023/reviews/rpp2023-rev-monte-carlo-numbering.pdf
166
+ - name: D0meson
167
+ label: $D^0$ in $c$-jet
168
+ cuts: ["HadronConeExclTruthLabelID == 4", "HadronConeExclTruthLabelPdgId in (421,-421)"]
169
+ colour: "#FFA500"
170
+ category: PDGID
171
+ - name: nonD0meson
172
+ label: $D^+$, $Ds^+$ or baryon in $c$-jet
173
+ cuts: ["HadronConeExclTruthLabelID == 4", "HadronConeExclTruthLabelPdgId notin (421,-421)"]
174
+ colour: "#800080"
175
+ category: PDGID
176
+ - name: Dplusmeson
177
+ label: $D^+$ in $c$-jet
178
+ cuts: ["HadronConeExclTruthLabelID == 4", "HadronConeExclTruthLabelPdgId in (411,-411)"]
179
+ colour: "#00FFFF"
180
+ category: PDGID
181
+ - name: Dsplusmeson
182
+ label: $Ds^+$ in $c$-jet
183
+ cuts: ["HadronConeExclTruthLabelID == 4", "HadronConeExclTruthLabelPdgId in (431,-431)"]
184
+ colour: "#781DC8"
185
+ category: PDGID
186
+ - name: B0meson
187
+ label: $B^0$ in $b$-jet
188
+ cuts: ["HadronConeExclTruthLabelID == 5", "HadronConeExclTruthLabelPdgId in (511,-511)"]
189
+ colour: "#702B1C"
190
+ category: PDGID
191
+ - name: Bplusmeson
192
+ label: $B^0$ in $b$-jet
193
+ cuts: ["HadronConeExclTruthLabelID == 5", "HadronConeExclTruthLabelPdgId in (521,-521)"]
194
+ colour: "#C81D4A"
195
+ category: PDGID
196
+ - name: Bs0meson
197
+ label: $Bs^0$ in $b$-jet
198
+ cuts: ["HadronConeExclTruthLabelID == 5", "HadronConeExclTruthLabelPdgId in (531,-531)"]
199
+ colour: "#1D62C8"
200
+ category: PDGID
201
+
143
202
  # lepton isolation
144
203
  ## taken from https://gitlab.cern.ch/atlas/athena/-/blob/main/PhysicsAnalysis/AnalysisCommon/TruthClassification/README.md#4-details-about-the-lepton-categories
145
204
  - name: elxprompt
146
205
  label: prompt electrons
147
- cuts: ["iffClass == 2"]
206
+ cuts: ["iffClass in (2,3)"]
148
207
  colour: tab:red
149
208
  category: isolation
209
+ - name: elxnoflip
210
+ label: prompt electrons with no charge-flip
211
+ cuts: ["iffClass == 2"]
212
+ colour: darkorange
213
+ category: isolation
150
214
  - name: elxflip
151
215
  label: prompt electrons with charge-flip
152
216
  cuts: ["iffClass == 3"]
153
217
  colour: tab:orange
154
218
  category: isolation
219
+ - name: elxphconv
220
+ label: electrons from prompt photon-conversions
221
+ cuts: ["iffClass == 5"]
222
+ colour: tab:purple
223
+ category: isolation
224
+ - name: elxnonprompt
225
+ label: non-prompt electrons
226
+ cuts: ["iffClass notin (2,3,5)"]
227
+ colour: "#264653"
228
+ category: isolation
155
229
  - name: muxprompt
156
230
  label: prompt muons
157
- cuts: ["iffClass == 4"]
231
+ cuts: ["iffClass in (4,11)"]
158
232
  colour: tab:blue
159
233
  category: isolation
234
+ - name: muxnoflip
235
+ label: prompt muons with no charge-flip
236
+ cuts: ["iffClass == 4"]
237
+ colour: aqua
238
+ category: isolation
160
239
  - name: muxflip
161
240
  label: prompt muons with charge-flip
162
241
  cuts: ["iffClass == 11"]
163
- colour: aqua
164
- category: isolation
165
- - name: elxphconv
166
- label: electrons from prompt photon-conversions
167
- cuts: ["iffClass == 5"]
168
- colour: tab:purple
169
- category: isolation
170
- - name: elxfrommu
171
- label: electrons from muons
172
- cuts: ["iffClass == 6"]
173
- colour: salmon
242
+ colour: midnightblue
174
243
  category: isolation
175
244
  - name: npxall
176
245
  label: non-prompt lepton
ftag/hdf5/h5reader.py CHANGED
@@ -60,7 +60,7 @@ class H5SingleReader:
60
60
  for var in array.dtype.names:
61
61
  isinf = np.isinf(array[var])
62
62
  isinf = isinf if name == self.jets_name else isinf.any(axis=-1)
63
- keep_idx = keep_idx & ~isinf
63
+ keep_idx &= ~isinf
64
64
  if num_inf := isinf.sum():
65
65
  log.warning(
66
66
  f"{num_inf} inf values detected for variable {var} in"
ftag/hdf5/h5writer.py CHANGED
@@ -41,7 +41,7 @@ class H5Writer:
41
41
  jets_name: str = "jets"
42
42
  add_flavour_label: bool = False
43
43
  compression: str = "lzf"
44
- precision: str | None = None
44
+ precision: str = "full"
45
45
  shuffle: bool = True
46
46
 
47
47
  def __post_init__(self):
@@ -51,6 +51,13 @@ class H5Writer:
51
51
  assert len(set(self.num_jets)) == 1, "Must have same number of jets per group"
52
52
  self.num_jets = self.num_jets[0]
53
53
 
54
+ if self.precision == "full":
55
+ self.fp_dtype = np.float32
56
+ elif self.precision == "half":
57
+ self.fp_dtype = np.float16
58
+ else:
59
+ raise ValueError(f"Invalid precision: {self.precision}")
60
+
54
61
  self.dst = Path(self.dst)
55
62
  self.dst.parent.mkdir(parents=True, exist_ok=True)
56
63
  self.file = h5py.File(self.dst, "w")
@@ -77,11 +84,17 @@ class H5Writer:
77
84
  if name == self.jets_name and self.add_flavour_label:
78
85
  dtype = np.dtype([*dtype.descr, ("flavour_label", "i4")])
79
86
 
87
+ # adjust dtype based on specified precision
88
+ dtype = np.dtype([
89
+ (field, self.fp_dtype if np.issubdtype(dt, np.floating) else dt)
90
+ for field, dt in dtype.descr
91
+ ])
92
+
80
93
  # optimal chunking is around 100 jets, only aply for track groups
81
94
  shape = self.shapes[name]
82
95
  chunks = (100,) + shape[1:] if shape[1:] else None
83
96
 
84
- # note: enabling the hd5 shuffle filter doesn't improve anything
97
+ # note: enabling the hd5 shuffle filter doesn't improve write performance
85
98
  self.file.create_dataset(
86
99
  name, dtype=dtype, shape=shape, compression=self.compression, chunks=chunks
87
100
  )
ftag/mock.py CHANGED
@@ -52,7 +52,6 @@ TRACK_VARS = [
52
52
 
53
53
 
54
54
  def softmax(x, axis=None):
55
- """Compute softmax values for each sets of scores in x."""
56
55
  e_x = np.exp(x - np.max(x, axis=axis, keepdims=True))
57
56
  return e_x / e_x.sum(axis=axis, keepdims=True)
58
57
 
ftag/wps/discriminant.py CHANGED
@@ -53,6 +53,11 @@ def discriminant(
53
53
  return np.log((jets[f"{tagger}_{signal.px}"] + epsilon) / (denominator + epsilon))
54
54
 
55
55
 
56
+ def tautag_dicriminant(jets, tagger, fb, fc, epsilon=1e-10):
57
+ fxs = {"pb": fb, "pc": fc, "pu": 1 - fb - fc}
58
+ return discriminant(jets, tagger, Flavours.taujets, fxs, epsilon=epsilon)
59
+
60
+
56
61
  def btag_discriminant(jets, tagger, fc, ftau=0, epsilon=1e-10):
57
62
  fxs = {"pc": fc, "ptau": ftau, "pu": 1 - fc - ftau}
58
63
  return discriminant(jets, tagger, Flavours.bjets, fxs, epsilon=epsilon)
@@ -95,10 +100,16 @@ def get_discriminant(
95
100
  -------
96
101
  np.ndarray
97
102
  Array of discriminant values.
103
+
104
+ Raises
105
+ ------
106
+ ValueError
107
+ If the signal flavour is not recognised.
98
108
  """
99
109
  tagger_funcs: dict[str, Callable] = {
100
110
  "bjets": btag_discriminant,
101
111
  "cjets": ctag_discriminant,
112
+ "taujets": tautag_dicriminant,
102
113
  "hbb": hbb_discriminant,
103
114
  "hcc": hcc_discriminant,
104
115
  }