Skip to content

Commit

Permalink
2.12.0 (#31)
Browse files Browse the repository at this point in the history
* fixes #14
* added boolean cut helper
  • Loading branch information
arnobaer authored Dec 9, 2021
1 parent 9e9934a commit 76a0b30
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 8 deletions.
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.11.1
pip install git+https://github.com/cms-l1-globaltrigger/tm-vhdlproducer.git@2.12.0
```

## Build from source
Expand Down
7 changes: 7 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.12.0] - 2021-12-06
### Added
- support for displaced jets
### Changed
- depending on tm-python 0.10.0
- depending on tm-reporter 2.10.1

## [2.11.1] - 2021-10-12
### Changed
- refactored resource calculation
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Jinja2==2.11.*
tm-python @ git+https://github.com/cms-l1-globaltrigger/tm-python@0.9.1
tm-reporter @ git+https://github.com/cms-l1-globaltrigger/tm-reporter@2.9.0
tm-python @ git+https://github.com/cms-l1-globaltrigger/tm-python@0.10.0
tm-reporter @ git+https://github.com/cms-l1-globaltrigger/tm-reporter@2.10.1
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="tm-vhdlproducer",
version='2.11.1',
version='2.12.0',
url="https://github.com/cms-l1-globaltrigger/tm-vhdlproducer",
author="Bernhard Arnold",
author_email="bernhard.arnold@cern.ch",
Expand All @@ -23,8 +23,8 @@
},
install_requires=[
'Jinja2==2.11.*',
'tm-python @ git+https://github.com/cms-l1-globaltrigger/tm-python@0.9.1',
'tm-reporter @ git+https://github.com/cms-l1-globaltrigger/tm-reporter@2.9.0'
'tm-python @ git+https://github.com/cms-l1-globaltrigger/tm-python@0.10.0',
'tm-reporter @ git+https://github.com/cms-l1-globaltrigger/tm-reporter@2.10.1'
],
entry_points={
'console_scripts': [
Expand Down
20 changes: 20 additions & 0 deletions tests/test_vhdlhelper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import unittest
from collections import namedtuple

from tmVhdlProducer import vhdlhelper


CutHandle = namedtuple('CutHandle', 'data')


class VhdlHelperTest(unittest.TestCase):

def test_snakecase(self):
Expand Down Expand Up @@ -96,5 +101,20 @@ def test_bx_encode_4_array(self):
r = vhdlhelper.bx_encode_4_array(key)
self.assertEqual(r, value)

def test_cut_helper(self):
cut = vhdlhelper.CutHelper()
self.assertEqual(cut.enabled, False)

def test_boolean_cut_helper(self):
cut = vhdlhelper.BooleanCutHelper()
self.assertEqual(cut.enabled, False)
self.assertEqual(cut.state, False)
cut.update(CutHandle(data="1"))
self.assertEqual(cut.enabled, True)
self.assertEqual(cut.state, True)
cut.update(CutHandle(data="0"))
self.assertEqual(cut.enabled, True)
self.assertEqual(cut.state, False)

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion tmVhdlProducer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.11.1'
__version__ = '2.12.0'
2 changes: 2 additions & 0 deletions tmVhdlProducer/algodist.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
kCharge = 'Charge'
kQuality = 'Quality'
kIsolation = 'Isolation'
kDisplaced = 'Displaced'
kDeltaEta = 'DeltaEta'
kDeltaPhi = 'DeltaPhi'
kDeltaR = 'DeltaR'
Expand Down Expand Up @@ -215,6 +216,7 @@
tmEventSetup.Charge: kCharge,
tmEventSetup.Quality: kQuality,
tmEventSetup.Isolation: kIsolation,
tmEventSetup.Displaced: kDisplaced,
tmEventSetup.DeltaEta: kDeltaEta,
tmEventSetup.DeltaPhi: kDeltaPhi,
tmEventSetup.DeltaR: kDeltaR,
Expand Down
5 changes: 5 additions & 0 deletions tmVhdlProducer/config/resource_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@
"brams": 0,
"sliceLUTs": 1
},
"Displaced": {
"processors": 0,
"brams": 0,
"sliceLUTs": 1
},
"Slice": {
"processors": 0,
"brams": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
{%- if (o1.isolation) or (o2.isolation) or (o3.isolation) or (o4.isolation) %}
iso_luts_obj1 => (X"{{ o1.isolation.value | X01 }}", X"{{ o2.isolation.value | X01 }}", X"{{ o3.isolation.value | X01 }}", X"{{ o4.isolation.value | X01 }}"),
{%- endif %}
{%- if (o1.displaced) or (o2.displaced) or (o3.displaced) or (o4.displaced) %}
disp_cuts_obj1 => ({{ o1.displaced | vhdl_bool }}, {{ o2.displaced | vhdl_bool }}, {{ o3.displaced | vhdl_bool }}, {{ o4.displaced | vhdl_bool }}),
disp_requs_obj1 => ({{ o1.displaced.state | vhdl_bool }}, {{ o2.displaced.state | vhdl_bool}}, {{ o3.displaced.state | vhdl_bool}}, {{ o4.displaced.state | vhdl_bool}}),
{% endif %}
{%- if (o1.charge) or (o2.charge) or (o3.charge) or (o4.charge) %}
requested_charges_obj1 => ("{{ o1.charge.value }}", "{{ o2.charge.value }}", "{{ o3.charge.value }}", "{{ o4.charge.value }}"),
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
{%- if o.isolation %}
iso_lut_obj{{i+1}} => X"{{ o.isolation.value | X01 }}",
{%- endif %}
{%- if o.displaced %}
disp_cut_obj{{i+1}} => {{ o.displaced | vhdl_bool }},
disp_requ_obj{{i+1}} => {{ o.displaced.state | vhdl_bool }},
{% endif %}
{%- if o.upt %}
upt_cut_obj{{i+1}} => {{ o.upt | vhdl_bool }},
upt_upper_limit_obj{{i+1}} => X"{{ o.upt.upper | X04 }}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ calc_cut_mass_over_dr_{{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }}
)
port map(
lhc_clk,
{%- if o1.is_calo_type and o2.is_calo_type %}
deta_integer => {{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_deta_integer,
dphi_integer => {{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_dphi_integer,
{%- elif o1.is_muon_type or o2.is_muon_type %}
deta_integer => {{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_deta_integer_half_res,
dphi_integer => {{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_dphi_integer_half_res,
{%- endif %}
inv_mass_pt_in => {{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_mass_inv_pt,
mass_over_dr => {{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_mass_over_dr
);
Expand Down
11 changes: 11 additions & 0 deletions tmVhdlProducer/templates/vhdl/instances/deta_dphi_calculations.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ calc_deta_dphi_integer_{{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }
generic map(
{%- if o1.is_muon_type or o2.is_muon_type %}
phi_half_range => MUON_PHI_HALF_RANGE_BINS,
phi_h_r_half_range => MUON_PHI_HALF_RES_HALF_RANGE_BINS,
{%- endif %}
nr_obj1 => NR_{{ o1.type | upper }}_OBJECTS,
type_obj1 => {{ o1.type | upper }}_TYPE,
Expand Down Expand Up @@ -30,6 +31,16 @@ calc_deta_dphi_integer_{{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }
phi_integer_obj1 => {{ o1.type | lower }}_bx_{{ o1.bx }}_phi_integer,
phi_integer_obj2 => {{ o2.type | lower }}_bx_{{ o2.bx }}_phi_conv_2_muon_phi_integer,
{%- endif %}
{%- if (o1.is_muon_type and o2.is_muon_type) %}
eta_integer_h_r_obj1 => {{ o1.type | lower }}_bx_{{ o1.bx }}_eta_integer_half_res,
phi_integer_h_r_obj1 => {{ o1.type | lower }}_bx_{{ o1.bx }}_phi_integer_half_res,
eta_integer_h_r_obj2 => {{ o2.type | lower }}_bx_{{ o2.bx }}_eta_integer_half_res,
phi_integer_h_r_obj2 => {{ o2.type | lower }}_bx_{{ o2.bx }}_phi_integer_half_res,
{%- endif %}
{%- if (o1.is_muon_type and o2.is_muon_type) %}
deta_integer_half_res => {{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_deta_integer_half_res,
dphi_integer_half_res => {{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_dphi_integer_half_res,
{%- endif %}
{%- if not o2.is_esums_type %}
deta_integer => {{ o1.type | lower }}_{{ o2.type | lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_deta_integer,
{%- endif %}
Expand Down
4 changes: 4 additions & 0 deletions tmVhdlProducer/templates/vhdl/instances/obj_parameter.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ calc_obj_parameter_{{ o.type | lower }}_bx_{{ o.bx }}_i: entity work.obj_paramet
eta_integer => {{ o.type | lower }}_bx_{{ o.bx }}_eta_integer,
{%- endif %}
phi_integer => {{ o.type | lower }}_bx_{{ o.bx }}_phi_integer,
{%- if o.is_muon_type %}
eta_integer_h_r => {{ o.type | lower }}_bx_{{ o.bx }}_eta_integer_half_res,
phi_integer_h_r => {{ o.type | lower }}_bx_{{ o.bx }}_phi_integer_half_res,
{%- endif %}
cos_phi => {{ o.type | lower }}_bx_{{ o.bx }}_cos_phi,
{%- if not o.is_muon_type %}
sin_phi => {{ o.type | lower }}_bx_{{ o.bx }}_sin_phi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
signal {{ o.type|lower }}_bx_{{ o.bx }}_upt_vector: diff_inputs_array(0 to NR_{{ o.type|upper }}_OBJECTS-1) := (others => (others => '0'));
signal {{ o.type|lower }}_bx_{{ o.bx }}_eta_integer: integer_array(0 to NR_{{ o.type|upper }}_OBJECTS-1) := (others => 0);
signal {{ o.type|lower }}_bx_{{ o.bx }}_phi_integer: integer_array(0 to NR_{{ o.type|upper }}_OBJECTS-1) := (others => 0);
signal {{ o.type|lower }}_bx_{{ o.bx }}_eta_integer_half_res: integer_array(0 to NR_{{ o.type|upper }}_OBJECTS-1) := (others => 0);
signal {{ o.type|lower }}_bx_{{ o.bx }}_phi_integer_half_res: integer_array(0 to NR_{{ o.type|upper }}_OBJECTS-1) := (others => 0);
signal {{ o.type|lower }}_bx_{{ o.bx }}_cos_phi: integer_array(0 to NR_{{ o.type|upper }}_OBJECTS-1) := (others => 0);
signal {{ o.type|lower }}_bx_{{ o.bx }}_sin_phi: integer_array(0 to NR_{{ o.type|upper }}_OBJECTS-1) := (others => 0);
{%- elif o.is_esums_type %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
signal {{ o1.type|lower }}_{{ o2.type|lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_dphi_integer: dim2_max_phi_range_array(0 to NR_{{ o1.type|upper }}_OBJECTS-1, 0 to NR_{{ o2.type|upper }}_OBJECTS-1) := (others => (others => 0));
signal {{ o1.type|lower }}_{{ o2.type|lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_dphi: deta_dphi_vector_array(0 to NR_{{ o1.type|upper }}_OBJECTS-1, 0 to NR_{{ o2.type|upper }}_OBJECTS-1) := (others => (others => (others => '0')));
{%- endif %}
{%- if o2.is_muon_type %}
signal {{ o1.type|lower }}_{{ o2.type|lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_deta_integer_half_res: dim2_max_eta_range_array(0 to NR_{{ o1.type|upper }}_OBJECTS-1, 0 to NR_{{ o2.type|upper }}_OBJECTS-1) := (others => (others => 0));
signal {{ o1.type|lower }}_{{ o2.type|lower }}_bx_{{ o1.bx }}_bx_{{ o2.bx }}_dphi_integer_half_res: dim2_max_phi_range_array(0 to NR_{{ o1.type|upper }}_OBJECTS-1, 0 to NR_{{ o2.type|upper }}_OBJECTS-1) := (others => (others => 0));
{%- endif %}
{%- endfor %}

{%- for o1, o2 in module.correlationCombinationsDeltaR %}
Expand Down
20 changes: 19 additions & 1 deletion tmVhdlProducer/vhdlhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ class ObjectHelper(VhdlHelper):
count [CountCutHelper]
upt [UptCutHelper]
impactParameter [ImpactParameterCutHelper]
displaced [DisplacedCutHelper]
etaNrCuts [int]
etaLowerLimit [list]
etaLowerLimit [list]
Expand Down Expand Up @@ -1236,6 +1237,7 @@ def __init__(self):
self.count = CountCutHelper()
self.upt = UptCutHelper()
self.impactParameter = ImpactParameterCutHelper(0xf)
self.displaced = DisplacedCutHelper()
# spatial cuts
self.etaNrCuts = 0
self.etaLowerLimit = [0, 0, 0, 0, 0]
Expand Down Expand Up @@ -1281,6 +1283,8 @@ def update(self, object_handle):
self.upt.update(cut_handle)
elif cut_handle.cut_type == tmEventSetup.ImpactParameter:
self.impactParameter.update(cut_handle)
elif cut_handle.cut_type == tmEventSetup.Displaced:
self.displaced.update(cut_handle)
if cut_handle.cut_type == tmEventSetup.Slice:
self.slice.update(cut_handle)
# setup eta windows
Expand Down Expand Up @@ -1348,7 +1352,7 @@ def __init__(self):

def __bool__(self):
return self.enabled

class ThresholdCutHelper(CutHelper):

def __init__(self, threshold=0):
Expand Down Expand Up @@ -1401,6 +1405,20 @@ def update(self, cut_handle):
self.value = int(cut_handle.data)
self.enabled = True

class BooleanCutHelper(CutHelper):

def __init__(self, state=False):
super().__init__()
self.state = state

def update(self, cut_handle):
self.state = bool(int(cut_handle.data))
self.enabled = True

class DisplacedCutHelper(BooleanCutHelper):

pass

class ChargeCutHelper(CutHelper):

def __init__(self, value):
Expand Down

0 comments on commit 76a0b30

Please sign in to comment.