atlas-ftag-tools 0.0.7__py3-none-any.whl → 0.0.9__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.0.7
3
+ Version: 0.0.9
4
4
  Summary: ATLAS Flavour Tagging Tools
5
5
  Author: Sam Van Stroud, Philipp Gadow
6
6
  License: MIT
@@ -47,3 +47,40 @@ or from source
47
47
  ```bash
48
48
  python -m pip install -e ".[dev]"
49
49
  ```
50
+
51
+
52
+ ## Create virtual file
53
+
54
+ This package contains a script to easily merge a set of H5 files.
55
+ A virtual file is a fast and lightweight way to wrap a set of files.
56
+ See the [h5py documentation](https://docs.h5py.org/en/stable/vds.html) for more information on virtual datasets.
57
+
58
+ The script is `vds.py` and can be run after installing this package with
59
+
60
+ ```
61
+ vds <pattern> <output path>
62
+ ```
63
+
64
+ The `<pattern>` argument should be a quotes enclosed [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)), for example `"dsid/path/*.h5"`
65
+
66
+
67
+ ## Calculate WPs
68
+
69
+ This package contains a script to calculate tagger working points (WPs).
70
+ The script is `working_points.py` and can be run after installing this package with
71
+
72
+ ```
73
+ wps \
74
+ --ttbar "path/to/ttbar/*.h5" \
75
+ --tagger GN120220509 \
76
+ --fx 0.1
77
+ ```
78
+
79
+ Both the `--tagger` and `--fx` options accept a list if you want to get the WPs for multiple taggers.
80
+
81
+ If you want to use the `ttbar` WPs get the efficiencies and rejections for the `zprime` sample, you can add `--zprime "path/to/zprime/*.h5"` to the command.
82
+ Note that a default selection of $p_T > 250 ~GeV$ to jets in the `zprime` sample.
83
+
84
+ By default the working points are printed to the terminal, but you can save the results to a YAML file with the `--outfile` option.
85
+
86
+ Use `--help` for more options and information.
@@ -0,0 +1,17 @@
1
+ ftag/__init__.py,sha256=092e5JJGG0mORUgE6Si-6sMU2HxNP90t0NfWh9n3t5g,543
2
+ ftag/cuts.py,sha256=Ge4WXLPg3WNgGxg-g7oIgCbbNFcKZonvkyskU0fDuDg,2733
3
+ ftag/flavour.py,sha256=67Otbi-78vEAOagLC9mvPGwNcr_S0ljy34eoChzd_9o,2396
4
+ ftag/flavours.yaml,sha256=S4WoB_n2uqvjo8_mlvNA1wKUwz9aFLhpyXtWsR8uR80,3121
5
+ ftag/mock.py,sha256=3ux7kx22o94K4eCHvI3vLTElBTvlDWEHwfCwidkNCiU,3579
6
+ ftag/region.py,sha256=Tbw7o7cqdeZcu3x49n1iXUxR0apHaUSAsSY_vTHPuGI,371
7
+ ftag/sample.py,sha256=p7JWiBvj4tq0YcvRGi_xp_3IvBXOFvx2mUEtO05NHac,2319
8
+ ftag/vds.py,sha256=FmpP31YiSKBvh6TRIMWr-_aJHAkQs0Trhmqh2KLfT64,2402
9
+ ftag/hdf5/__init__.py,sha256=A_a_4IUlZ2mSiDcfrZKBdja_3iTrUHvADM2lWx6g66g,325
10
+ ftag/hdf5/h5reader.py,sha256=7FK1TfOb4tV34rlf6O3Xh918j3RwYMkm0-QLgO2NkHM,8446
11
+ ftag/hdf5/h5utils.py,sha256=tHspHfO0lsRFcft9WQo98_ot55837nYNiTO4_0z4qwk,2376
12
+ ftag/hdf5/h5writer.py,sha256=D4GZKWyPE-ob8anCsZ2Vw2UFwbZltl1dPn7ZlI-y1oM,3094
13
+ atlas_ftag_tools-0.0.9.dist-info/METADATA,sha256=yajFDhKPhccegFIOLG49l7cuclhJiguFgF72ELrTQJA,2966
14
+ atlas_ftag_tools-0.0.9.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
15
+ atlas_ftag_tools-0.0.9.dist-info/entry_points.txt,sha256=UKbRbwA9DxfsTPRBIVVDz3u15WdzhzgRKwXXSAXuQqc,73
16
+ atlas_ftag_tools-0.0.9.dist-info/top_level.txt,sha256=qiYQuKcAvMim-31FwkT3MTQu7WQm0s58tPAia5KKWqs,5
17
+ atlas_ftag_tools-0.0.9.dist-info/RECORD,,
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ vds = ftag.vds:main
3
+ wps = ftag.wps.working_points:main
ftag/__init__.py CHANGED
@@ -1,23 +1,25 @@
1
1
  """atlas-ftag-tools - Common tools for ATLAS flavour tagging software."""
2
2
 
3
3
 
4
- __version__ = "v0.0.7"
4
+ __version__ = "v0.0.9"
5
5
 
6
- from pathlib import Path
7
-
8
- import yaml
9
6
 
10
7
  import ftag.hdf5 as hdf5
11
8
  from ftag.cuts import Cuts
12
- from ftag.flavour import Flavour, FlavourContainer
9
+ from ftag.flavour import Flavour, Flavours
13
10
  from ftag.mock import get_mock_file
14
11
  from ftag.sample import Sample
12
+ from ftag.wps.discriminant import get_discriminant
13
+ from ftag.wps.working_points import get_working_points
15
14
 
16
- # load flavours
17
- with open(Path(__file__).parent / "flavours.yaml") as f:
18
- flavours_yaml = yaml.safe_load(f)
19
- flavours_dict = {f["name"]: Flavour(cuts=Cuts.from_list(f.pop("cuts")), **f) for f in flavours_yaml}
20
- assert len(flavours_dict) == len(flavours_yaml), "Duplicate flavour names detected"
21
- Flavours = FlavourContainer(flavours_dict)
22
-
23
- __all__ = ["Cuts", "Flavours", "Sample", "hdf5", "get_mock_file", "__version__"]
15
+ __all__ = [
16
+ "Cuts",
17
+ "Flavour",
18
+ "Flavours",
19
+ "Sample",
20
+ "hdf5",
21
+ "get_mock_file",
22
+ "get_discriminant",
23
+ "get_working_points",
24
+ "__version__",
25
+ ]
ftag/flavour.py CHANGED
@@ -2,6 +2,9 @@ from __future__ import annotations
2
2
 
3
3
  from collections.abc import Generator
4
4
  from dataclasses import dataclass
5
+ from pathlib import Path
6
+
7
+ import yaml
5
8
 
6
9
  from ftag.cuts import Cuts
7
10
 
@@ -74,3 +77,10 @@ class FlavourContainer:
74
77
  if flavour.cuts == cuts:
75
78
  return flavour
76
79
  raise KeyError(f"Flavour with {cuts} not found")
80
+
81
+
82
+ with open(Path(__file__).parent / "flavours.yaml") as f:
83
+ flavours_yaml = yaml.safe_load(f)
84
+ flavours_dict = {f["name"]: Flavour(cuts=Cuts.from_list(f.pop("cuts")), **f) for f in flavours_yaml}
85
+ assert len(flavours_dict) == len(flavours_yaml), "Duplicate flavour names detected"
86
+ Flavours = FlavourContainer(flavours_dict)
ftag/hdf5/h5reader.py CHANGED
@@ -111,12 +111,33 @@ class H5SingleReader:
111
111
 
112
112
  @dataclass
113
113
  class H5Reader:
114
+ """Reads data from multiple HDF5 files.
115
+
116
+ Parameters
117
+ ----------
118
+ fname : Path | str | list[Path | str]
119
+ Path to the HDF5 file or list of paths
120
+ batch_size : int, optional
121
+ Number of jets to read at a time, by default 100_000
122
+ jets_name : str, optional
123
+ Name of the jets dataset, by default "jets"
124
+ precision : str | None, optional
125
+ Cast floats to given precision, by default None
126
+ shuffle : bool, optional
127
+ Read batches in a shuffled order, by default True
128
+ weights : list[float] | None, optional
129
+ Weights for different input datasets, by default None
130
+ do_remove_inf : bool, optional
131
+ Remove jets with inf values, by default False
132
+ """
133
+
114
134
  fname: Path | str | list[Path | str]
115
135
  batch_size: int = 100_000
116
136
  jets_name: str = "jets"
117
137
  precision: str | None = None
118
138
  shuffle: bool = True
119
139
  weights: list[float] | None = None
140
+ do_remove_inf: bool = False
120
141
 
121
142
  def __post_init__(self) -> None:
122
143
  if isinstance(self.fname, (str, Path)):
@@ -129,8 +150,8 @@ class H5Reader:
129
150
 
130
151
  # create readers
131
152
  self.readers = [
132
- H5SingleReader(fname, batch_size, self.jets_name, self.precision, self.shuffle)
133
- for fname, batch_size in zip(self.fname, self.batch_sizes)
153
+ H5SingleReader(f, b, self.jets_name, self.precision, self.shuffle, self.do_remove_inf)
154
+ for f, b in zip(self.fname, self.batch_sizes)
134
155
  ]
135
156
 
136
157
  @property
ftag/vds.py CHANGED
@@ -60,3 +60,26 @@ def create_virtual_file(
60
60
  f.create_virtual_dataset(group, layout)
61
61
 
62
62
  return out_fname
63
+
64
+
65
+ def main():
66
+ import argparse
67
+
68
+ parser = argparse.ArgumentParser(
69
+ description="Create a lightweight wrapper around a set of h5 files"
70
+ )
71
+ parser.add_argument("pattern", type=Path, help="quotes-enclosed glob pattern of files to merge")
72
+ parser.add_argument("output", type=Path, help="path to output virtual file")
73
+ args = parser.parse_args()
74
+
75
+ print(f"Globbing {args.pattern}...")
76
+ create_virtual_file(args.pattern, args.output, overwrite=True)
77
+ with h5py.File(args.output) as f:
78
+ key = list(f.keys())[0]
79
+ num = len(f[key])
80
+ print(f"Virtual dataset '{key}' has {num:,} entries")
81
+ print(f"Saved virtual file to {args.output.resolve()}")
82
+
83
+
84
+ if __name__ == "__main__":
85
+ main()
@@ -1,16 +0,0 @@
1
- ftag/__init__.py,sha256=ALaSSRinlhI2xrwYaSAAI4-Q_tFPQITMgqVclM99HgY,731
2
- ftag/cuts.py,sha256=Ge4WXLPg3WNgGxg-g7oIgCbbNFcKZonvkyskU0fDuDg,2733
3
- ftag/flavour.py,sha256=ciNtvPjcLhmf0tq2x5sOQXk2xwtLgMFS1wVlRk16VqI,2033
4
- ftag/flavours.yaml,sha256=S4WoB_n2uqvjo8_mlvNA1wKUwz9aFLhpyXtWsR8uR80,3121
5
- ftag/mock.py,sha256=3ux7kx22o94K4eCHvI3vLTElBTvlDWEHwfCwidkNCiU,3579
6
- ftag/region.py,sha256=Tbw7o7cqdeZcu3x49n1iXUxR0apHaUSAsSY_vTHPuGI,371
7
- ftag/sample.py,sha256=p7JWiBvj4tq0YcvRGi_xp_3IvBXOFvx2mUEtO05NHac,2319
8
- ftag/vds.py,sha256=OT6cW_jN4mbJzp7ZWEJU-GY7svLSUezrzapngBa6THg,1671
9
- ftag/hdf5/__init__.py,sha256=A_a_4IUlZ2mSiDcfrZKBdja_3iTrUHvADM2lWx6g66g,325
10
- ftag/hdf5/h5reader.py,sha256=LGAgJiNafMSWVa1uWHqLKYY29jrJ2WyAX-7OtzGJvNU,7699
11
- ftag/hdf5/h5utils.py,sha256=tHspHfO0lsRFcft9WQo98_ot55837nYNiTO4_0z4qwk,2376
12
- ftag/hdf5/h5writer.py,sha256=D4GZKWyPE-ob8anCsZ2Vw2UFwbZltl1dPn7ZlI-y1oM,3094
13
- atlas_ftag_tools-0.0.7.dist-info/METADATA,sha256=Jgx-Xp5gHCJp35perl_stD1b_e3SbfagD4SynLzvcAk,1639
14
- atlas_ftag_tools-0.0.7.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
15
- atlas_ftag_tools-0.0.7.dist-info/top_level.txt,sha256=qiYQuKcAvMim-31FwkT3MTQu7WQm0s58tPAia5KKWqs,5
16
- atlas_ftag_tools-0.0.7.dist-info/RECORD,,