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

Mass/dR Implementation in New MenuTools #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion rate-estimation/menu2lib/menu2lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def hasCorrelationCuts(condition):

for cut in condition.getCuts():
if cut.getCutType() in (tmEventSetup.DeltaEta, tmEventSetup.OvRmDeltaR, tmEventSetup.Mass, tmEventSetup.MassUpt,
tmEventSetup.OvRmDeltaEta, tmEventSetup.DeltaR):
tmEventSetup.OvRmDeltaEta, tmEventSetup.DeltaR, tmEventSetup.MassDeltaR):
requireDeltaEta = True

if requireDeltaEta:
Expand Down Expand Up @@ -349,6 +349,8 @@ def getLookUpTable(scaleMap, obj1, obj2):
precisionMath = getPrecision(scaleMap, obj1, obj2, 'Math')
precisionPt = getPrecision(scaleMap, obj1, obj2, 'MassPt')

precisionInvDeltaR = getPrecision(scaleMap, obj1, obj2, 'InverseDeltaRMath')

has_deta = not (isVectorSum(obj1) or isVectorSum(obj2))
convert = ((obj1.getType() != obj2.getType())
and
Expand All @@ -373,6 +375,8 @@ def getLookUpTable(scaleMap, obj1, obj2):
rc['COSH_DETA'] = "LUT_COSH_DETA_%s_%s" % (getObjectName(obj1), getObjectName(obj2))
rc['PREC_DR'] = 2*precisionDelta

rc['PREC_INVDR'] = precisionInvDeltaR

if convert:
if obj1.getType() == tmEventSetup.Muon:
rc['CONV_PHI'] = 'LUT_PHI_%s2%s' % (getObjectName(obj2), getObjectName(obj1))
Expand All @@ -386,6 +390,8 @@ def getLookUpTable(scaleMap, obj1, obj2):
rc['ETA_OFFSET'] = 2**getScale(scaleMap, obj1, tmGrammar.ETA).getNbits()
return rc

def toMassDeltaR(value):
return "%.2f" % math.sqrt(2.*value)

def toMass(value):
return math.sqrt(2.*value)
Expand Down Expand Up @@ -419,6 +425,7 @@ def render(menu, template):
j2_env.filters['warning'] = warning
j2_env.filters['toMass'] = toMass
j2_env.filters['toDeltaR'] = toDeltaR
j2_env.filters['toMassDeltaR'] = toMassDeltaR
j2_env.filters['chkChgCor'] = chkChgCor
j2_env.filters['getPrefix'] = getPrefix
j2_env.filters['isMuon'] = isMuon
Expand Down
2 changes: 1 addition & 1 deletion rate-estimation/menu2lib/templates/MenuTemplate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ PermutationFactory::cache_t PermutationFactory::cache_ = {};
{% include 'CaloCaloCorrelationTemplate.cc' %}
{% endif %}

{% elif cond.getType() in (tmEventSetup.InvariantMassUpt, ) %}
{% elif cond.getType() in (tmEventSetup.InvariantMassUpt, tmEventSetup.InvariantMassDeltaR) %}
{% set objects = cond.getObjects() %}
{% set combination = tmEventSetup.getObjectCombination(objects[0].getType(), objects[1].getType()) %}
{% if combination == tmEventSetup.MuonMuonCombination %}
Expand Down
45 changes: 45 additions & 0 deletions rate-estimation/menu2lib/templates/MuonMuonLUT.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,49 @@ const int LUT_MU_UPT[] = {
{{x}}{% if not loop.last %},{% endif %}
{%- endfor -%}
};

{# inverse deltaR #}
const int prec_mu_mu_invdeltar = {{ scaleMap | getPrecisionByName('MU', 'MU', 'InverseDeltaRMath') }};
const int prec_mu_mu_massdr = prec_mu_mu_mass + prec_mu_mu_invdeltar;

{# const int iRSq = 0; #}
{# const int jRSq = 0; #}
{# const int iRSqmax = 227; #}
{# const int jRSqmax = 145; #}
{# const double tempRsq = 0.0; #}
{# const double tempdiffeta = 0.02175; #}
{# const double tempdiffphi = 0.02181661564992912; #}
{# const double resolution = 0.5; #}
{# const unsigned int precInvRsq = 0x5; #}


{# const long long InvDeltaRSqLUT[iRSqmax][jRSqmax]; #}
{# const double temp_InvDeltaRSq[iRSqmax][jRSqmax]; #}
{# if (corrPar.corrCutType & 0x80) { //Only build the 1/dR2 LUT if necessary #}
{# for (iRSq = 0; iRSq < iRSqmax; iRSq = iRSq + 1) { #}
{# for (jRSq = 0; jRSq < jRSqmax; jRSq = jRSq + 1) { #}
{# tempRsq = (tempdiffeta * iRSq) * (tempdiffeta * iRSq) + (tempdiffphi * jRSq) * (tempdiffphi * jRSq); #}
{# if (tempRsq > 0.0) { #}
{# temp_InvDeltaRSq[iRSq][jRSq] = 1.0 / tempRsq; #}
{# InvDeltaRSqLUT[iRSq][jRSq] = (long long)round(pow(10, precInvRsq) * temp_InvDeltaRSq[iRSq][jRSq]); #}
{# } else { #}
{# temp_InvDeltaRSq[iRSq][jRSq] = 0.0; #}
{# InvDeltaRSqLUT[iRSq][jRSq] = (long long)0; #}
{# } #}
{# } #}
{# } #}
{# } #}



{# const int LUT_INVDR_MU_MU[] = { #}
{# {% for x in range -%} #}
{# { #}
{# {% for y in mu_mu_invdelta[tmGrammar.INVERSE_DR] -%} #}
{# {{tempRsq}}{% if not loop.last %},{% endif %} #}
{# {%- endfor -%} #}
{# }{% if not loop.last %},{% endif %} #}
{# {%- endfor -%} #}
{# }; #}

{# eof #}
19 changes: 18 additions & 1 deletion rate-estimation/menu2lib/templates/macros.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@
const long long mass2 = upt0 * upt1 * (coshDeltaEta - cosDeltaPhi);
{%- endmacro -%}

{#
# set mass2 over delta R2
#}
{%- macro setMass2DeltaR2(prefix0, prefix1, idx0, idx1, LUTS, iPi, useDelta=True) -%}
{{ setMass2(prefix0, prefix1, idx0, idx1, LUTS, iPi, useDelta) }}
const long long inversedR2 = {{LUTS.COS_DPHI}}[deltaIPhi];
{# dummy LUT for now #}
const long long mass2deltaR2 = mass2 * inversedR2;
{%- endmacro -%}
{# get actual LUT name #}

{#
# set mass3
#}
Expand Down Expand Up @@ -143,7 +154,7 @@
{
const long long minimum = {{(cut.getMinimum().value * 10**precision) | int}}; // {{cut.getMinimum().value}} * 10^{{precision}}
const long long maximum = {{(cut.getMaximum().value * 10**precision) | int}}; // {{cut.getMaximum().value}} * 10^{{precision}}
if (not ((minimum <= {{value}}) and ({{value}} <= maximum))) continue;
if (not ((minimum <= {{value}}) and (maximum == 0)) or ((minimum <= {{value}}) and ({{value}} <= maximum))) continue;
}
{% endmacro -%}

Expand Down Expand Up @@ -287,6 +298,12 @@
{{ setMassUpt2(prefix, prefix, idx0, idx1, LUTS, iPi, False) }}
{{ applyFunctionCut('mass2', cut, LUTS.PREC_MASS) }}

{% elif cut.getCutType() == tmEventSetup.MassDeltaR %}
// {{ cut.getMinimum().value | toMassDeltaR }} <= massdr <= {{ cut.getMaximum().value | toMassDeltaR}}
{{ setMass2DeltaR2(prefix, prefix, idx0, idx1, LUTS, iPi, False) }}
{{ applyFunctionCut('mass2deltaR2', cut, LUTS.PREC_INVDR) }}


{% elif cut.getCutType() == tmEventSetup.ChargeCorrelation %}
if (data->{{prefix}}Chg.at({{idx0}}) == 0) continue; // charge valid bit not set
if (data->{{prefix}}Chg.at({{idx1}}) == 0) continue; // charge valid bit not set
Expand Down