Skip to content

Commit

Permalink
Merge pull request #36499 from dpilipov/InvMassOverDR_12_3_X
Browse files Browse the repository at this point in the history
Inv mass over dr 12 3 x
  • Loading branch information
cmsbuild committed Dec 17, 2021
2 parents a62c11a + 9b54619 commit 16a5ae7
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 24 deletions.
13 changes: 12 additions & 1 deletion L1Trigger/L1TGlobal/plugins/GenToInputProducer.cc
Expand Up @@ -287,6 +287,12 @@ namespace l1t {
int rank = 0;
int hwEtaAtVtx = eta;
int hwPhiAtVtx = phi;
double etaAtVtx = 0.0;
double phiAtVtx = 0.0;
int hwPtUnconstrained =
convertPtToHW(mcParticle.pt(), MaxLepPt_, PtStep_) / 2; // word is 8 bits wide so divide 9 bit word by 2
double ptUnconstrained = 0.0;
int dXY = gRandom->Integer(4); // should be [0,3] = 2 bits

// Eta outside of acceptance
if (eta >= 9999)
Expand All @@ -311,7 +317,12 @@ namespace l1t {
dEta,
rank,
hwEtaAtVtx,
hwPhiAtVtx);
hwPhiAtVtx,
etaAtVtx,
phiAtVtx,
hwPtUnconstrained,
ptUnconstrained,
dXY); // modified to conform to latest Muon.h interface
muonVec.push_back(mu);
}

Expand Down
43 changes: 36 additions & 7 deletions L1Trigger/L1TGlobal/plugins/GtRecordDump.cc
Expand Up @@ -851,13 +851,42 @@ namespace l1t {
// Pack Bits
packedVal |= ((cms_uint64_t)(mu->hwPhi() & 0x3ff) << 43);
packedVal |= ((cms_uint64_t)(mu->hwPhiAtVtx() & 0x3ff) << 0); // & 0x3ff) <<18);
packedVal |= ((cms_uint64_t)(mu->hwEta() & 0x1ff) << 53);
packedVal |= ((cms_uint64_t)(mu->hwEtaAtVtx() & 0x1ff) << 23); // & 0x1ff) <<9);
packedVal |= ((cms_uint64_t)(mu->hwPt() & 0x1ff) << 10); // & 0x1ff) <<0);
packedVal |= ((cms_uint64_t)(mu->hwChargeValid() & 0x1) << 35); // & 0x1) <<28);
packedVal |= ((cms_uint64_t)(mu->hwCharge() & 0x1) << 34); // & 0x1) <<29);
packedVal |= ((cms_uint64_t)(mu->hwQual() & 0xf) << 19); // & 0xf) <<30);
packedVal |= ((cms_uint64_t)(mu->hwIso() & 0x3) << 32); // & 0x3) <<34);
// packedVal |= ((cms_uint64_t)(mu->hwEta() & 0x1ff) << 53); // removed
packedVal |= ((cms_uint64_t)(mu->hwPtUnconstrained() & 0xff) << 53); // added
packedVal |= ((cms_uint64_t)(mu->hwDXY() & 0x3) << 62); // added
packedVal |= ((cms_uint64_t)(mu->hwEtaAtVtx() & 0x1ff) << 23); // & 0x1ff) <<9);
packedVal |= ((cms_uint64_t)(mu->hwPt() & 0x1ff) << 10); // & 0x1ff) <<0);
packedVal |= ((cms_uint64_t)(mu->hwChargeValid() & 0x1) << 35); // & 0x1) <<28);
packedVal |= ((cms_uint64_t)(mu->hwCharge() & 0x1) << 34); // & 0x1) <<29);
packedVal |= ((cms_uint64_t)(mu->hwQual() & 0xf) << 19); // & 0xf) <<30);
packedVal |= ((cms_uint64_t)(mu->hwIso() & 0x3) << 32); // & 0x3) <<34);

// if (false) { // for debugging purposes
// std::cout << "----------------------" << std::endl;
// std::cout << "<< 0; mu->hwPhiAtVtx() = " << std::hex << std::setw(16) << std::setfill('0')
// << ((cms_uint64_t)(mu->hwPhiAtVtx() & 0x3ff) << 0) << std::endl;
// std::cout << "<< 10; mu->hwPt() = " << std::hex << std::setw(16) << std::setfill('0')
// << ((cms_uint64_t)(mu->hwPt() & 0x1ff) << 10) << std::endl;
// std::cout << "<< 19; mu->hwQual() = " << std::hex << std::setw(16) << std::setfill('0')
// << ((cms_uint64_t)(mu->hwQual() & 0xf) << 19) << std::endl;
// std::cout << "<< 23; mu->hwEtaAtVtx() = " << std::hex << std::setw(16) << std::setfill('0')
// << ((cms_uint64_t)(mu->hwEtaAtVtx() & 0x1ff) << 23) << std::endl;
// std::cout << "<< 32; mu->hwIso() = " << std::hex << std::setw(16) << std::setfill('0')
// << ((cms_uint64_t)(mu->hwIso() & 0x3) << 32) << std::endl;
// std::cout << "<< 34; mu->hwCharge() = " << std::hex << std::setw(16) << std::setfill('0')
// << ((cms_uint64_t)(mu->hwCharge() & 0x1) << 34) << std::endl;
// std::cout << "<< 35; mu->hwChargeValid() = " << std::hex << std::setw(16) << std::setfill('0')
// << ((cms_uint64_t)(mu->hwChargeValid() & 0x1) << 35) << std::endl;
// std::cout << "<< 43; mu->hwPhi() = " << std::hex << std::setw(16) << std::setfill('0')
// << ((cms_uint64_t)(mu->hwPhi() & 0x3ff) << 43) << std::endl;
// std::cout << "<< 53; mu->hwPtUnconstrained() = " << std::hex << std::setw(16) << std::setfill('0')
// << ((cms_uint64_t)(mu->hwPtUnconstrained() & 0xff) << 53) << std::endl;
// std::cout << "<< 62; mu->hwDXY() = " << std::hex << std::setw(16) << std::setfill('0')
// << ((cms_uint64_t)(mu->hwDXY() & 0x3) << 62) << std::endl;
// std::cout << "packedWord = " << std::hex << std::setw(16) << std::setfill('0') << packedVal
// << std::endl;
// std::cout << "----------------------" << std::endl;
// }

return packedVal;
}
Expand Down
18 changes: 17 additions & 1 deletion L1Trigger/L1TGlobal/plugins/TriggerMenuParser.cc
Expand Up @@ -16,6 +16,8 @@
*
* \new features: Elisa Fontanesi
* - extended for three-body correlation conditions
* \new features: Dragana Pilipovic
* - updated for invariant mass over delta R condition
*
* $Date$
* $Revision$
Expand Down Expand Up @@ -319,6 +321,7 @@ void l1t::TriggerMenuParser::parseCondFormats(const L1TUtmTriggerMenu* utmMenu)
condition.getType() == esConditionType::CaloCaloCorrelation ||
condition.getType() == esConditionType::CaloEsumCorrelation ||
condition.getType() == esConditionType::InvariantMass ||
condition.getType() == esConditionType::InvariantMassDeltaR ||
condition.getType() == esConditionType::TransverseMass ||
condition.getType() == esConditionType::InvariantMassUpt) { // Added for displaced muons
parseCorrelation(condition, chipNr);
Expand Down Expand Up @@ -2729,7 +2732,8 @@ bool l1t::TriggerMenuParser::parseCorrelation(tmeventsetup::esCondition corrCond
<< " Max = " << maxV << " precMin = " << cut.getMinimum().index
<< " precMax = " << cut.getMaximum().index << std::endl;
cutType = cutType | 0x20;
} else if (cut.getCutType() == esCutType::Mass) {
} else if ((cut.getCutType() == esCutType::Mass) ||
(cut.getCutType() == esCutType::MassDeltaR)) { //Invariant Mass, MassOverDeltaR
LogDebug("TriggerMenuParser") << "CutType: " << cut.getCutType() << "\tMass Cut minV = " << minV
<< " Max = " << maxV << " precMin = " << cut.getMinimum().index
<< " precMax = " << cut.getMaximum().index << std::endl;
Expand All @@ -2739,6 +2743,8 @@ bool l1t::TriggerMenuParser::parseCorrelation(tmeventsetup::esCondition corrCond
// cutType = cutType | 0x8;
if (corrCond.getType() == esConditionType::TransverseMass) {
cutType = cutType | 0x10;
} else if (corrCond.getType() == esConditionType::InvariantMassDeltaR) {
cutType = cutType | 0x80;
} else {
cutType = cutType | 0x8;
}
Expand Down Expand Up @@ -2990,6 +2996,11 @@ bool l1t::TriggerMenuParser::parseCorrelationThreeBody(tmeventsetup::esCondition
corrThreeBodyParameter.maxMassCutValue = (long long)(maxV * pow(10., cut.getMaximum().index));
corrThreeBodyParameter.precMassCut = cut.getMinimum().index;
cutType = cutType | 0x8;
} else if (cut.getCutType() == esCutType::MassDeltaR) {
corrThreeBodyParameter.minMassCutValue = (long long)(minV * pow(10., cut.getMinimum().index));
corrThreeBodyParameter.maxMassCutValue = (long long)(maxV * pow(10., cut.getMaximum().index));
corrThreeBodyParameter.precMassCut = cut.getMinimum().index;
cutType = cutType | 0x80;
}
}
corrThreeBodyParameter.corrCutType = cutType;
Expand Down Expand Up @@ -3164,6 +3175,11 @@ bool l1t::TriggerMenuParser::parseCorrelationWithOverlapRemoval(const tmeventset
corrParameter.maxMassCutValue = (long long)(maxV * pow(10., cut.getMaximum().index));
corrParameter.precMassCut = cut.getMinimum().index;
cutType = cutType | 0x8;
} else if (cut.getCutType() == esCutType::MassDeltaR) {
corrParameter.minMassCutValue = (long long)(minV * pow(10., cut.getMinimum().index));
corrParameter.maxMassCutValue = (long long)(maxV * pow(10., cut.getMaximum().index));
corrParameter.precMassCut = cut.getMinimum().index;
cutType = cutType | 0x80;
}
if (cut.getCutType() == esCutType::OvRmDeltaEta) {
//std::cout << "OverlapRemovalDeltaEta Cut minV = " << minV << " Max = " << maxV << " precMin = " << cut.getMinimum().index << " precMax = " << cut.getMaximum().index << std::endl;
Expand Down
109 changes: 94 additions & 15 deletions L1Trigger/L1TGlobal/src/CorrCondition.cc
Expand Up @@ -7,7 +7,8 @@
* Implementation:
* <TODO: enter implementation details>
*
*
*\new features: Dragana Pilipovic
* - updated for invariant mass over delta R condition*
*/

// this class header
Expand Down Expand Up @@ -345,6 +346,43 @@ const bool l1t::CorrCondition::evaluateCondition(const int bxEval) const {
}
LogDebug("L1TGlobal") << "Phi Bound = " << phiBound << std::endl;

// BUILD THE 1/dR2 LUT BASED ON CONDITION
int iRSq = 0;
int jRSq = 0;
int iRSqmax = 227;
int jRSqmax = 145;
double tempRsq = 0.0;
double tempdiffeta = 0.0435;
double tempdiffphi = 0.02181661564992912;
double resolution = 1.0;
unsigned int precInvRsq = 0x5;
if (cond0Categ == CondMuon || cond1Categ == CondMuon) {
LogTrace("L1TGlobal") << " Building 1/dR2 for Muon " << std::endl;
tempdiffeta = tempdiffeta / 2.0;
resolution = 0.5;
} else {
LogTrace("L1TGlobal") << " Building 1/dR2 for Calo " << std::endl;
iRSqmax = 231;
jRSqmax = 73;
tempdiffphi = 0.04363323129985824;
}
long long InvDeltaRSqLUT[iRSqmax][jRSqmax];
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;
}
}
}
}

// Keep track of objects for LUTS
std::string lutObj0 = "NULL";
std::string lutObj1 = "NULL";
Expand Down Expand Up @@ -1168,8 +1206,8 @@ const bool l1t::CorrCondition::evaluateCondition(const int bxEval) const {
}
}

if (corrPar.corrCutType & 0x8 || corrPar.corrCutType & 0x10 ||
corrPar.corrCutType & 0x40) { // added 0x40 for massUpt
if (corrPar.corrCutType & 0x8 || corrPar.corrCutType & 0x10 || corrPar.corrCutType & 0x40 ||
corrPar.corrCutType & 0x80) { // added 0x40 for massUpt; added 0x80 for mass/dR
//invariant mass calculation based on
// M = sqrt(2*p1*p2(cosh(eta1-eta2) - cos(phi1 - phi2)))
// but we calculate (1/2)M^2
Expand Down Expand Up @@ -1244,18 +1282,59 @@ const bool l1t::CorrCondition::evaluateCondition(const int bxEval) const {
<< " sqrt(|massSq|) = " << sqrt(fabs(2. * massSqPhy)) << std::endl;

//if(preShift>0) massSq /= pow(10,preShift);
if (massSq >= 0 && massSq >= (long long)(corrPar.minMassCutValue * pow(10, preShift)) &&
massSq <= (long long)(corrPar.maxMassCutValue * pow(10, preShift))) {
LogDebug("L1TGlobal") << " Passed Invariant Mass Cut ["
<< (long long)(corrPar.minMassCutValue * pow(10, preShift)) << ","
<< (long long)(corrPar.maxMassCutValue * pow(10, preShift)) << "]" << std::endl;
} else {
LogDebug("L1TGlobal") << " Failed Invariant Mass Cut ["
<< (long long)(corrPar.minMassCutValue * pow(10, preShift)) << ","
<< (long long)(corrPar.maxMassCutValue * pow(10, preShift)) << "]" << std::endl;
reqResult = false;
}
}
if (corrPar.corrCutType & 0x80) { //deal with the Invariant Mass Over Delta R cut
// The following is the most precise indexing for 1/dr2 LUT iEta and jPhi - it is based on the physical VALUES for deta and dphi:
// unsigned int inverseDeltaRIndexEta = int(round(abs(deltaEtaPhy / tempdiffeta)));
// unsigned int inverseDeltaRIndexPhi = int(round(abs(deltaPhiPhy/ tempdiffphi)));
// To match the FW we instead must use these INDIVIDUAL indecies for eta and phi:
// (NOTE: The following treatment of delta eta and delta phi indecies matches the most precise case above):
int iEta0 = int(trunc(etaIndex0 * resolution));
int iEta1 = int(trunc(etaIndex1 * resolution));
unsigned int inverseDeltaRIndexEta = abs(iEta0 - iEta1);
int jPhi0 = int(trunc(phiIndex0 * resolution));
int jPhi1 = int(trunc(phiIndex1 * resolution));
unsigned int inverseDeltaRIndexPhi = abs(jPhi0 - jPhi1);
if (abs(phiIndex0 - phiIndex1) >= phiBound)
inverseDeltaRIndexPhi = int(trunc(2 * phiBound * resolution)) - inverseDeltaRIndexPhi;
unsigned int precInvDRSqLUT = 0x5;
long long LInverseDeltaRSqLUT = 0x0;
if (inverseDeltaRIndexEta + inverseDeltaRIndexPhi > 0)
LInverseDeltaRSqLUT = InvDeltaRSqLUT[inverseDeltaRIndexEta][inverseDeltaRIndexPhi];
long long massSqOverDeltaRSq =
(long long)massSq * LInverseDeltaRSqLUT; // keep full precision, do not '/pow(10,precInvDRSqLUT);'
if ((inverseDeltaRIndexEta + inverseDeltaRIndexPhi == 0) ||
((massSqOverDeltaRSq >= 0) &&
(massSqOverDeltaRSq >=
(long long)(corrPar.minMassCutValue * pow(10, preShift) *
pow(10, precInvDRSqLUT))))) { // only check for the minimum threshold in case of invMass/dR
LogDebug("L1TGlobal") << " Passed Invariant Mass Over Delta R Cut ["
<< (long long)(corrPar.minMassCutValue * pow(10, preShift) * pow(10, precInvDRSqLUT))
<< ","
<< (long long)(corrPar.maxMassCutValue * pow(10, preShift) * pow(10, precInvDRSqLUT))
<< "] massSqOverDeltaRSq " << massSqOverDeltaRSq << std::endl;
} else {
LogDebug("L1TGlobal") << " Failed Invariant Mass OverDeltaR Cut ["
<< (long long)(corrPar.minMassCutValue * pow(10, preShift) * pow(10, precInvDRSqLUT))
<< ","
<< (long long)(corrPar.maxMassCutValue * pow(10, preShift) * pow(10, precInvDRSqLUT))
<< "] massSqOverDeltaRSq " << massSqOverDeltaRSq << std::endl;
reqResult = false;
}
//Done with Invariant Mass Over Delta R vs Mass Cut choice
} else { //do the InvMassCut choice
if (massSq >= 0 && massSq >= (long long)(corrPar.minMassCutValue * pow(10, preShift)) &&
massSq <= (long long)(corrPar.maxMassCutValue * pow(10, preShift))) {
LogDebug("L1TGlobal") << " Passed Invariant Mass Cut ["
<< (long long)(corrPar.minMassCutValue * pow(10, preShift)) << ","
<< (long long)(corrPar.maxMassCutValue * pow(10, preShift)) << "]" << std::endl;
} else {
LogDebug("L1TGlobal") << " Failed Invariant Mass Cut ["
<< (long long)(corrPar.minMassCutValue * pow(10, preShift)) << ","
<< (long long)(corrPar.maxMassCutValue * pow(10, preShift)) << "]" << std::endl;
reqResult = false;
} //Done with Invariant Mass Cut
} //Done with choice of Invariant Mass Cut vs InvMass/dR
} //Done with any type of Mass Cut

// For Muon-Muon Correlation Check the Charge Correlation if requested
bool chrgCorrel = true;
Expand Down

0 comments on commit 16a5ae7

Please sign in to comment.