Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:44

0001 ///
0002 /// \class l1t::Stage2Layer2SumsAlgorithmFirmwareImp1
0003 ///
0004 /// \author:
0005 ///
0006 /// Description:
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "L1Trigger/L1TCalorimeter/interface/Stage2Layer2DemuxSumsAlgoFirmware.h"
0010 #include "L1Trigger/L1TCalorimeter/interface/CaloTools.h"
0011 #include "L1Trigger/L1TCalorimeter/interface/CaloParamsHelper.h"
0012 
0013 #include <vector>
0014 #include <algorithm>
0015 
0016 l1t::Stage2Layer2DemuxSumsAlgoFirmwareImp1::Stage2Layer2DemuxSumsAlgoFirmwareImp1(CaloParamsHelper const* params)
0017     : params_(params),
0018       cordic_(
0019           Cordic(144 * 16, 17, 8))  // These are the settings in the hardware - should probably make this configurable
0020 {}
0021 
0022 void l1t::Stage2Layer2DemuxSumsAlgoFirmwareImp1::processEvent(const std::vector<l1t::EtSum>& inputSums,
0023                                                               std::vector<l1t::EtSum>& outputSums) {
0024   int et(0), etHF(0), etHFOnly(0), etem(0), metx(0), mety(0), metxHF(0), metyHF(0), ht(0), htHF(0), mhtx(0), mhty(0),
0025       mhtxHF(0), mhtyHF(0), metPhi(0), metPhiHF(0), mhtPhi(0), mhtPhiHF(0);
0026   double etPos(0), etNeg(0), etHFPos(0), etHFNeg(0), htPos(0), htNeg(0), htHFPos(0), htHFNeg(0);
0027   int cent(0);
0028   unsigned int asymEt(0), asymEtHF(0), asymHt(0), asymHtHF(0);
0029   bool posEt(false), posEtHF(false), posHt(false), posHtHF(false);
0030   unsigned int met(0), metHF(0), mht(0), mhtHF(0);
0031   unsigned int mbp0(0), mbm0(0), mbp1(0), mbm1(0);
0032   unsigned int ntow(0);
0033 
0034   bool etSat(false), etHFSat(false), htSat(false), htHFSat(false);
0035   bool metSat(false), metHFSat(false), mhtSat(false), mhtHFSat(false);
0036 
0037   // Add up the x, y and scalar components
0038   for (auto&& eSum : inputSums) {
0039     switch (eSum.getType()) {
0040       case l1t::EtSum::EtSumType::kTotalEt:
0041         if (eSum.hwPt() == 0xffff)
0042           etSat = true;
0043         et += eSum.hwPt();
0044         if (posEt)
0045           etPos = eSum.hwPt();
0046         else {
0047           etNeg = eSum.hwPt();
0048           posEt = true;
0049         }
0050         break;
0051 
0052       case l1t::EtSum::EtSumType::kTotalEtHF:
0053         if (eSum.hwPt() == 0xffff)
0054           etHFSat = true;
0055         etHF += eSum.hwPt();
0056         if (posEtHF)
0057           etHFPos = eSum.hwPt();
0058         else {
0059           etHFNeg = eSum.hwPt();
0060           posEtHF = true;
0061         }
0062         break;
0063 
0064       case l1t::EtSum::EtSumType::kTotalEtEm:
0065         etem += eSum.hwPt();
0066         break;
0067 
0068       case l1t::EtSum::EtSumType::kTotalEtx:
0069         if (eSum.hwPt() == 0x7fffffff)
0070           metSat = true;
0071         else
0072           metx += eSum.hwPt();
0073         break;
0074 
0075       case l1t::EtSum::EtSumType::kTotalEty:
0076         if (eSum.hwPt() == 0x7fffffff)
0077           metSat = true;
0078         else
0079           mety += eSum.hwPt();
0080         break;
0081 
0082       case l1t::EtSum::EtSumType::kTotalHt:
0083         if (eSum.hwPt() == 0xffff)
0084           htSat = true;
0085         ht += eSum.hwPt();
0086         if (posHt)
0087           htPos = eSum.hwPt();
0088         else {
0089           htNeg = eSum.hwPt();
0090           posHt = true;
0091         }
0092         break;
0093 
0094       case l1t::EtSum::EtSumType::kTotalHtHF:
0095         if (eSum.hwPt() == 0xffff)
0096           htHFSat = true;
0097         htHF += eSum.hwPt();
0098         if (posHtHF)
0099           htHFPos = eSum.hwPt();
0100         else {
0101           htHFNeg = eSum.hwPt();
0102           posHtHF = true;
0103         }
0104         break;
0105 
0106       case l1t::EtSum::EtSumType::kTotalHtx:
0107         if (eSum.hwPt() == 0x7fffffff)
0108           mhtSat = true;
0109         else
0110           mhtx += eSum.hwPt();
0111         break;
0112 
0113       case l1t::EtSum::EtSumType::kTotalHty:
0114         if (eSum.hwPt() == 0x7fffffff)
0115           mhtSat = true;
0116         else
0117           mhty += eSum.hwPt();
0118         break;
0119 
0120       case l1t::EtSum::EtSumType::kTotalEtxHF:
0121         if (eSum.hwPt() == 0x7fffffff)
0122           metHFSat = true;
0123         else
0124           metxHF += eSum.hwPt();
0125         break;
0126 
0127       case l1t::EtSum::EtSumType::kTotalEtyHF:
0128         if (eSum.hwPt() == 0x7fffffff)
0129           metHFSat = true;
0130         else
0131           metyHF += eSum.hwPt();
0132         break;
0133 
0134       case l1t::EtSum::EtSumType::kTotalHtxHF:
0135         if (eSum.hwPt() == 0x7fffffff)
0136           mhtHFSat = true;
0137         else
0138           mhtxHF += eSum.hwPt();
0139         break;
0140 
0141       case l1t::EtSum::EtSumType::kTotalHtyHF:
0142         if (eSum.hwPt() == 0x7fffffff)
0143           mhtHFSat = true;
0144         else
0145           mhtyHF += eSum.hwPt();
0146         break;
0147 
0148       case l1t::EtSum::EtSumType::kMinBiasHFP0:
0149         mbp0 = eSum.hwPt();
0150         break;
0151 
0152       case l1t::EtSum::EtSumType::kMinBiasHFM0:
0153         mbm0 = eSum.hwPt();
0154         break;
0155 
0156       case l1t::EtSum::EtSumType::kMinBiasHFP1:
0157         mbp1 = eSum.hwPt();
0158         break;
0159 
0160       case l1t::EtSum::EtSumType::kMinBiasHFM1:
0161         mbm1 = eSum.hwPt();
0162         break;
0163 
0164       case l1t::EtSum::EtSumType::kTowerCount:
0165         ntow = eSum.hwPt();
0166         break;
0167 
0168       default:
0169         continue;  // Should throw an exception or something?
0170     }
0171   }
0172 
0173   // calculate centrality
0174   etHFOnly = abs(etHF - et);
0175   for (uint i = 0; i < 8; ++i) {
0176     if (etHFOnly >= (params_->etSumCentLower(i) / params_->towerLsbSum()) &&
0177         etHFOnly <= (params_->etSumCentUpper(i) / params_->towerLsbSum())) {
0178       cent |= 1 << i;
0179     }
0180   }
0181   if (etHFSat)
0182     cent = 0x80;
0183 
0184   // calculate HI imbalance
0185   asymEt = l1t::CaloTools::gloriousDivision(abs(etPos - etNeg), et);
0186   asymEtHF = l1t::CaloTools::gloriousDivision(abs(etHFPos - etHFNeg), etHF);
0187   asymHt = l1t::CaloTools::gloriousDivision(abs(htPos - htNeg), ht);
0188   asymHtHF = l1t::CaloTools::gloriousDivision(abs(htHFPos - htHFNeg), htHF);
0189 
0190   if (etSat)
0191     asymEt = 0xFF;
0192   if (etHFSat)
0193     asymEtHF = 0xFF;
0194   if (htSat)
0195     asymHt = 0xFF;
0196   if (htHFSat)
0197     asymHtHF = 0xFF;
0198 
0199   if (et > 0xFFF)
0200     et = 0xFFF;
0201   if (etHF > 0xFFF)
0202     etHF = 0xFFF;
0203   if (etem > 0xFFF)
0204     etem = 0xFFF;
0205   if (ht > 0xFFF)
0206     ht = 0xFFF;
0207   if (htHF > 0xFFF)
0208     htHF = 0xFFF;
0209 
0210   //if (mhtx>0xFFF) mhtx = 0xFFF;
0211   //if (mhty>0xFFF) mhty = 0xFFF;
0212 
0213   //mhtPhi = (111 << 4);
0214   //mhtPhiHF = (111 << 4); // to match hw value if undefined
0215 
0216   // Final MET calculation
0217   if ((metx != 0 || mety != 0) && !metSat)
0218     cordic_(metx, mety, metPhi, met);
0219   // sets the met scale back to the original range for output into GT, this corresponds to
0220   // the previous scaling of sin/cos factors in calculation of metx and mety by 2^10 = 1024
0221   met >>= 10;
0222 
0223   // Final METHF calculation
0224   if ((metxHF != 0 || metyHF != 0) && !metHFSat)
0225     cordic_(metxHF, metyHF, metPhiHF, metHF);
0226   metHF >>= 10;
0227 
0228   // Final MHT calculation
0229   if ((mhtx != 0 || mhty != 0) && !mhtSat)
0230     cordic_(mhtx, mhty, mhtPhi, mht);
0231   // sets the mht scale back to the original range for output into GT, the other 4
0232   // bits are brought back just before the accumulation of ring sum in MP jet sum algorithm
0233   mht >>= 6;
0234 
0235   if ((mhtxHF != 0 || mhtyHF != 0) && !mhtHFSat)
0236     cordic_(mhtxHF, mhtyHF, mhtPhiHF, mhtHF);
0237   mhtHF >>= 6;
0238 
0239   if (metSat || met > 0xFFF)
0240     met = 0xFFF;
0241   if (metHFSat || metHF > 0xFFF)
0242     metHF = 0xFFF;
0243   if (mhtSat || mht > 0xFFF)
0244     mht = 0xFFF;
0245   if (mhtHFSat || mhtHF > 0xFFF)
0246     mhtHF = 0xFFF;
0247 
0248   // Make final collection
0249   math::XYZTLorentzVector p4;
0250 
0251   l1t::EtSum etSumTotalEt(p4, l1t::EtSum::EtSumType::kTotalEt, et, 0, 0, 0);
0252   l1t::EtSum etSumTotalEtHF(p4, l1t::EtSum::EtSumType::kTotalEtHF, etHF, 0, 0, 0);
0253   l1t::EtSum etSumTotalEtEm(p4, l1t::EtSum::EtSumType::kTotalEtEm, etem, 0, 0, 0);
0254   l1t::EtSum etSumMissingEt(p4, l1t::EtSum::EtSumType::kMissingEt, met, 0, metPhi >> 4, 0);
0255   l1t::EtSum etSumMissingEtHF(p4, l1t::EtSum::EtSumType::kMissingEtHF, metHF, 0, metPhiHF >> 4, 0);
0256   l1t::EtSum htSumht(p4, l1t::EtSum::EtSumType::kTotalHt, ht, 0, 0, 0);
0257   l1t::EtSum htSumhtHF(p4, l1t::EtSum::EtSumType::kTotalHtHF, htHF, 0, 0, 0);
0258   l1t::EtSum htSumMissingHt(p4, l1t::EtSum::EtSumType::kMissingHt, mht, 0, mhtPhi >> 4, 0);
0259   l1t::EtSum htSumMissingHtHF(p4, l1t::EtSum::EtSumType::kMissingHtHF, mhtHF, 0, mhtPhiHF >> 4, 0);
0260   l1t::EtSum etSumMinBiasHFP0(p4, l1t::EtSum::EtSumType::kMinBiasHFP0, mbp0, 0, 0, 0);
0261   l1t::EtSum etSumMinBiasHFM0(p4, l1t::EtSum::EtSumType::kMinBiasHFM0, mbm0, 0, 0, 0);
0262   l1t::EtSum etSumMinBiasHFP1(p4, l1t::EtSum::EtSumType::kMinBiasHFP1, mbp1, 0, 0, 0);
0263   l1t::EtSum etSumMinBiasHFM1(p4, l1t::EtSum::EtSumType::kMinBiasHFM1, mbm1, 0, 0, 0);
0264   l1t::EtSum etSumTowCount(p4, l1t::EtSum::EtSumType::kTowerCount, ntow, 0, 0, 0);
0265   l1t::EtSum etAsym(p4, l1t::EtSum::EtSumType::kAsymEt, asymEt, 0, 0, 0);
0266   l1t::EtSum etHFAsym(p4, l1t::EtSum::EtSumType::kAsymEtHF, asymEtHF, 0, 0, 0);
0267   l1t::EtSum htAsym(p4, l1t::EtSum::EtSumType::kAsymHt, asymHt, 0, 0, 0);
0268   l1t::EtSum htHFAsym(p4, l1t::EtSum::EtSumType::kAsymHtHF, asymHtHF, 0, 0, 0);
0269   l1t::EtSum centrality(p4, l1t::EtSum::EtSumType::kCentrality, cent, 0, 0, 0);
0270 
0271   outputSums.push_back(etSumTotalEt);
0272   outputSums.push_back(etSumTotalEtHF);
0273   outputSums.push_back(etSumTotalEtEm);
0274   outputSums.push_back(etSumMinBiasHFP0);
0275   outputSums.push_back(htSumht);
0276   outputSums.push_back(htSumhtHF);
0277   outputSums.push_back(etSumMinBiasHFM0);
0278   outputSums.push_back(etSumMissingEt);
0279   outputSums.push_back(etSumMinBiasHFP1);
0280   outputSums.push_back(htSumMissingHt);
0281   outputSums.push_back(etSumMinBiasHFM1);
0282   outputSums.push_back(etSumMissingEtHF);
0283   outputSums.push_back(htSumMissingHtHF);
0284   outputSums.push_back(etSumTowCount);
0285   outputSums.push_back(etAsym);
0286   outputSums.push_back(etHFAsym);
0287   outputSums.push_back(htAsym);
0288   outputSums.push_back(htHFAsym);
0289   outputSums.push_back(centrality);
0290 }