Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev_2.18.1_validate_window_limits #52

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9']
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Install using pip (>= 19.0)

```bash
pip install --upgrade pip
pip install git+https://github.com/cms-l1-globaltrigger/tm-vhdlproducer.git@2.18.0
pip install git+https://github.com/cms-l1-globaltrigger/tm-vhdlproducer.git@2.18.1
```

## Build from source
Expand Down
8 changes: 7 additions & 1 deletion changelog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.18.1] - 2024-06-05

### Added
- validation for eta and index windows limits (function "validate_window_limits" in vhdlhelper.py).

## [2.18.0] - 2024-03-22

### Added
Expand Down Expand Up @@ -318,7 +323,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- adjusted `--dryrun` and `--ratio` options.

[unreleased]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.18.0...HEAD
[unreleased]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.18.1...HEAD
[2.18.1]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.18.0...2.18.1
[2.18.0]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.17.1...2.18.0
[2.17.1]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.17.0...2.17.1
[2.17.0]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.16.0...2.17.0
Expand Down
3 changes: 3 additions & 0 deletions tmVhdlProducer/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
PROCESSORS_TOTAL: int = 3600
NR_CALOS: int = 12
NR_MUONS: int = 8
CALOS_ETA_BITS: int = 8
MUON_ETA_BITS: int = 9
MUON_INDEX_BITS: int = 7
40 changes: 40 additions & 0 deletions tmVhdlProducer/vhdlhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
from . import __version__
from . import algodist

from .constants import CALOS_ETA_BITS, MUON_ETA_BITS, MUON_INDEX_BITS

# -----------------------------------------------------------------------------
# Precompiled regular expressions
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -162,6 +164,32 @@
# Filters
# -----------------------------------------------------------------------------

def validate_window_limits(cut_type: str, type: str, lower: int, upper: int, cut_name: str, obj_h):
"""Validation of eta and index windows limits"""
if cut_type == tmEventSetup.Eta:
if obj_h.isMuonObject():
mask = 1 << MUON_ETA_BITS-1
elif obj_h.isCaloObject():
mask = 1 << CALOS_ETA_BITS-1
else:
assert f"\033[1;31m ERROR: wrong object type for eta cut ! - {type}\033[0;31m"
# case 1: positive values for lower and upper limits
if (lower & mask != mask and upper & mask != mask):
assert lower < upper, f"\033[1;31m ERROR in eta window: positive lower limit > positive upper limit ! => cut name: {cut_name} lower: {lower} ({hex(lower)}), upper: {upper} ({hex(upper)})\033[0;31m"
# case 2: positive value for lower and and negative value for upper limit
elif (lower & mask != mask and upper & mask == mask):
assert lower > upper, f"\033[1;31m ERROR in eta window: lower limit is positive, but upper limit is negative ! => cut name: {cut_name}, lower: {lower} ({hex(lower)}), upper: {upper} ({hex(upper)})\033[0;31m"
# case 3: negative values for lower and upper limits
elif (lower & mask == mask and upper & mask == mask):
assert lower < upper, f"\033[1;31m ERROR in eta window: negative lower limit > negative upper limit ! => cut name: {cut_name}, lower: {lower} ({hex(lower)}), upper: {upper} ({hex(upper)})\033[0;31m"
elif cut_type == tmEventSetup.Index:
if not obj_h.isMuonObject():
assert f"\033[1;31m ERROR: wrong object type for index cut ! - {type}\033[0;31m"
else:
assert lower < upper, f"\033[1;31m ERROR in index window: lower limit > upper limit ! => cut name: {cut_name}, lower: {lower} ({hex(lower)}), upper: {upper} ({hex(upper)})\033[0;31m"
else:
assert f"\033[1;31m ERROR: wrong cut type (only ETA and INDEX cuts have lower and upper limits) ! - {cut_type}\033[0;31m"

def snakecase(label: str, separator: str = '_') -> str:
"""Transformes camel case label to spaced lower case (snaked) label.

Expand Down Expand Up @@ -1291,7 +1319,9 @@ def update(self, object_handle):
# set the default slice range to maxNum - 1 (e.g. 0-11)
self.slice.upper = ObjectCount[object_handle.type] - 1
etaCuts = []
etaCutsName = []
indexCuts = []
indexCutsName = []
phiCuts = []
# setup cuts
for cut_handle in object_handle.cuts:
Expand All @@ -1301,8 +1331,10 @@ def update(self, object_handle):
self.isolation.update(cut_handle)
elif cut_handle.cut_type == tmEventSetup.Eta:
etaCuts.append((cut_handle.minimum.index, cut_handle.maximum.index))
etaCutsName.append(cut_handle.name)
elif cut_handle.cut_type == tmEventSetup.Index:
indexCuts.append((cut_handle.minimum.index, cut_handle.maximum.index))
indexCutsName.append(cut_handle.name)
elif cut_handle.cut_type == tmEventSetup.Phi:
phiCuts.append((cut_handle.minimum.index, cut_handle.maximum.index))
elif cut_handle.cut_type == tmEventSetup.Quality:
Expand All @@ -1327,6 +1359,14 @@ def update(self, object_handle):
self.displaced.update(cut_handle)
if cut_handle.cut_type == tmEventSetup.Slice:
self.slice.update(cut_handle)

# validate eta windows
for i in range(len(etaCuts)):
validate_window_limits(tmEventSetup.Eta, self.type, etaCuts[i][0], etaCuts[i][1], etaCutsName[i], object_handle)
# validate index windows
for i in range(len(indexCuts)):
validate_window_limits(tmEventSetup.Index, self.type, indexCuts[i][0], indexCuts[i][1], indexCutsName[i], object_handle)

# setup eta windows
if len(etaCuts) > 0:
self.etaNrCuts = 1
Expand Down
Loading