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

Draft of muon showers implementation #62

Merged
merged 8 commits into from
Nov 2, 2021
Merged
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
51 changes: 40 additions & 11 deletions rate-estimation/menu2lib/menu2lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
assert tmGrammar.__version__ == UTM_VERSION, f"invalid utm version {tmGrammar.__version__}, should be {UTM_VERSION}"
assert tmEventSetup.__version__ == UTM_VERSION, f"invalid utm version {tmEventSetup.__version__}, should be {UTM_VERSION}"

#
# constants
#

#############
# Constants #
#############
# Muon showers: PREFIX extended according to `L1AnalysisL1UpgradeDataFormat` vectors
PREFIX = {
tmEventSetup.Muon: 'muon',
tmEventSetup.Egamma: 'eg',
Expand All @@ -35,12 +37,24 @@
tmEventSetup.MBT1HFM: 'sum',
tmEventSetup.MBT1HFP: 'sum',
tmEventSetup.TOWERCOUNT: 'sum',
tmEventSetup.MUS0: 'muonShower',
tmEventSetup.MUS1: 'muonShower',
tmEventSetup.MUSOOT0: 'muonShower',
tmEventSetup.MUSOOT1: 'muonShower'
}

# Muon showers: Add mapping for event setup types to L1Analysis types;
# it can be done for Centrality signals, as well
ANALYSIS_TYPES = {
tmEventSetup.MUS0: 'kOneNominal', # how to map these types?
tmEventSetup.MUS1: 'kOneTight',
tmEventSetup.MUSOOT0: 'kInvalid',
tmEventSetup.MUSOOT1: 'kInvalid'
}

#
# helpers
#
###########
# Helpers #
###########
def getObjectName(key):
return {
tmEventSetup.Muon: tmGrammar.MU,
Expand All @@ -50,6 +64,14 @@ def getObjectName(key):
tmEventSetup.ETM: tmGrammar.ETM,
tmEventSetup.HTM: tmGrammar.HTM,
tmEventSetup.ETMHF: tmGrammar.ETMHF,
tmEventSetup.MUS0: tmGrammar.MUS0,
tmEventSetup.MUS1: tmGrammar.MUS1,
tmEventSetup.MUSOOT0: tmGrammar.MUSOOT0,
tmEventSetup.MUSOOT1: tmGrammar.MUSOOT1
#tmEventSetup.MuonShower0: tmGrammar.MUS0,
#tmEventSetup.MuonShower1: tmGrammar.MUS1,
#tmEventSetup.MuonShowerOutOfTime0: tmGrammar.MUSOOT0,
#tmEventSetup.MuonShowerOutOfTime1: tmGrammar.MUSOOT1
}[key.getType()]


Expand All @@ -72,9 +94,9 @@ def getScaleByName(scaleMap, obj, cut):
return scaleMap[key]


#
# filters
#
###########
# Filters #
###########
def toDecimal(value, bits):
signed = 1 << (bits - 1);
return (~signed & value) - signed if (signed & value) else value
Expand Down Expand Up @@ -173,6 +195,11 @@ def sortObjects(obj1, obj2):
elif obj1.getType() in (tmEventSetup.ETM, tmEventSetup.HTM, tmEventSetup.ETMHF):
return obj2, obj1

# Muon showers
elif obj1.getType() in (tmEventSetup.MUS0, tmEventSetup.MUS1, tmEventSetup.MUSOOT0, tmEventSetup.MUSOOT1):
if obj2.getType() not in (tmEventSetup.Tau, tmEventSetup.ETM, tmEventSetup.HTM,
tmEventSetup.ETMHF, tmEventSetup.Muon, tmEventSetup.Jet):
return obj2, obj1
return obj1, obj2


Expand Down Expand Up @@ -305,7 +332,6 @@ def isTau(prefix):
def isMuon(prefix):
return prefix == PREFIX[tmEventSetup.Muon]


def hasIndexCut(cuts):
for cut in cuts:
if cut.getCutType() == tmEventSetup.Slice:
Expand Down Expand Up @@ -382,6 +408,9 @@ def warning(message):
print(message)
return ''

# Muon showers: add filter function to get analysis type for use in templates
def getAnalysisType(key):
return ANALYSIS_TYPES[key.getType()]

def render(menu, template):
module_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -411,7 +440,7 @@ def render(menu, template):
j2_env.filters['getIndexCut'] = getIndexCut
j2_env.filters['getScale'] = getScale
j2_env.filters['getLookUpTable'] = getLookUpTable

j2_env.filters['getAnalysisType'] = getAnalysisType # Muon showers
data = {
"tmGrammar": tmGrammar,
"tmEventSetup": tmEventSetup,
Expand Down
28 changes: 24 additions & 4 deletions rate-estimation/menu2lib/templates/MenuTemplate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,20 @@ PermutationFactory::cache_t PermutationFactory::cache_ = {};
//
// NB: tmEventSetup.XxxWithOverlapRemoval was removed between utm-overlapRemoval-xsd330 and utm_0.6.5
//
// generate conditions
/////////////////////////
// Generate conditions //
/////////////////////////
{#
// Muon showers: definition of ShowerSignal types;
// it can be done for Centrality signals, as well
#}
{% set ShowerSignalTypes = (
tmEventSetup.MuonShower0,
tmEventSetup.MuonShower1,
tmEventSetup.MuonShowerOutOfTime0,
tmEventSetup.MuonShowerOutOfTime1
) %}

{% for name, cond in menu.getConditionMapPtr().items() %}
{%- set overlap_removal = 0 -%}
{%- if cond.getType() in (tmEventSetup.CaloCaloCorrelationOvRm, tmEventSetup.DoubleJetOvRm, tmEventSetup.DoubleTauOvRm,
Expand All @@ -239,9 +252,9 @@ PermutationFactory::cache_t PermutationFactory::cache_ = {};
{% endif -%}

{%- if cond.getType() in (tmEventSetup.SingleMuon, tmEventSetup.DoubleMuon, tmEventSetup.TripleMuon, tmEventSetup.QuadMuon,
tmEventSetup.SingleEgamma, tmEventSetup.DoubleEgamma, tmEventSetup.TripleEgamma, tmEventSetup.QuadEgamma,
tmEventSetup.SingleTau, tmEventSetup.DoubleTau, tmEventSetup.TripleTau, tmEventSetup.QuadTau,
tmEventSetup.SingleJet, tmEventSetup.DoubleJet, tmEventSetup.TripleJet, tmEventSetup.QuadJet) %}
tmEventSetup.SingleEgamma, tmEventSetup.DoubleEgamma, tmEventSetup.TripleEgamma, tmEventSetup.QuadEgamma,
tmEventSetup.SingleTau, tmEventSetup.DoubleTau, tmEventSetup.TripleTau, tmEventSetup.QuadTau,
tmEventSetup.SingleJet, tmEventSetup.DoubleJet, tmEventSetup.TripleJet, tmEventSetup.QuadJet) %}
{% include 'ObjectTemplate.cc' %}

{% elif cond.getType() in (tmEventSetup.TotalEt, tmEventSetup.TotalHt, tmEventSetup.MissingEt, tmEventSetup.MissingHt,
Expand Down Expand Up @@ -300,6 +313,13 @@ PermutationFactory::cache_t PermutationFactory::cache_ = {};
{% if combination01 == tmEventSetup.MuonMuonCombination and combination02 == tmEventSetup.MuonMuonCombination %}
{% include 'Muon3CorrelationTemplate.cc' %}
{% endif %}
{#
// Muon showers: associate the condition type and a given template;
// it can be done for Centrality signals, as well
#}
{# {% elif cond.getType() == tmEventSetup.MuonShower0, tmEventSetup.MuonShower1, tmEventSetup.MuonShowerOutOfTime0, tmEventSetup.MuonShowerOutOfTime1 %} #}
{% elif cond.getType() in ShowerSignalTypes %}
{% include 'SignalsTemplate.cc' %}

{% endif -%}
{% endfor %}
Expand Down
27 changes: 27 additions & 0 deletions rate-estimation/menu2lib/templates/SignalsTemplate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{# Template for signal type conditions like centrality or muon showers #}
{# MuonShowerType from L1TNtuples: kInvalid, kOneNominal,kOneTight, kTwoLoose #}
{# See in: L1Trigger/L1TNtuples/interface/L1AnalysisL1UpgradeDataFormat.h #}

{% block SignalsTemplate scoped %}
{% import 'macros.jinja2' as macros %}
{% set object = cond.getObjects()[0] %}
{% set prefix = object | getPrefix %}
{% set analysis_type = object | getAnalysisType %}

bool
{{ cond.getName() }}
(L1Analysis::L1AnalysisL1UpgradeDataFormat* data)
{
bool pass = false;
{# Is signals in same bx? #}
if (data->{{ prefix }}Bx.at(0) == {{ object.getBxOffset() }})
{
{# Is signal set? #}
if (data->{{ prefix }}Type.at(0) == L1Analysis::{{ analysis_type }})
{
pass = true;
}
}
return pass;
}
{% endblock SignalsTemplate %}