Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:35

0001 /**
0002  * \class CorrWithOverlapRemovalCondition
0003  *
0004  *
0005  * Description: evaluation of a correlation-with-overlap-removal condition.
0006  *
0007  *
0008  * Implementation:
0009  *
0010  *  The central method of the class is evaluateCondition().
0011  *  Correlation cuts inherited from the original CorrCondition class.
0012  *
0013  *  v1 Logic:
0014  *  - Define 3 GtConditionCategories: (1st & 2nd correlation legs, and overlap-removal leg)
0015  *
0016  *  - Loop leg1: over all objects of 1st correlation leg
0017  *
0018  *    - Retrive its coordinates, and do conversions depending on the types
0019  *
0020  *    - Loop over all objects of leg3 (overlap-removal leg)
0021  *      - Retrive its coodrinates, and do conversions depending on the types
0022  *      - Check for matching with overlap-removal object.
0023  *    - If metched with any overlap object, next leg1 object.
0024  *
0025  *    - Loop leg2: over all object of 2nd correlation leg
0026  *      - Retrive its coordinates, and do conversion depending on the types
0027  *      - Loop over all objects of leg3 (overlap-removal leg)
0028  *        - Retrive its coodrinates, and do conversions depending on the types
0029  *        - Check for matching with any overlap-removal object.
0030  *      - If metched with any overlap object, next leg2 object.
0031  *      - Check for dEta, dPhi, dR, and mass (and charge) correlation with 1st leg object.
0032  *        If any correlation cut pass, save leg1-leg2 object combination.
0033  *    - End loop leg2
0034  *
0035  *  - End loop leg1
0036  *
0037  *  - Return true, if saved at least one leg1-leg2 combintation
0038  *
0039  *
0040  * \author: Vladimir Rekovic
0041  *
0042  */
0043 
0044 // this class header
0045 #include "L1Trigger/L1TGlobal/interface/CorrWithOverlapRemovalCondition.h"
0046 
0047 // system include files
0048 #include <iostream>
0049 #include <iomanip>
0050 
0051 #include <string>
0052 #include <vector>
0053 #include <algorithm>
0054 
0055 // user include files
0056 //   base classes
0057 #include "L1Trigger/L1TGlobal/interface/CorrelationWithOverlapRemovalTemplate.h"
0058 #include "L1Trigger/L1TGlobal/interface/ConditionEvaluation.h"
0059 
0060 #include "L1Trigger/L1TGlobal/interface/MuCondition.h"
0061 #include "L1Trigger/L1TGlobal/interface/CaloCondition.h"
0062 #include "L1Trigger/L1TGlobal/interface/EnergySumCondition.h"
0063 #include "L1Trigger/L1TGlobal/interface/MuonTemplate.h"
0064 #include "L1Trigger/L1TGlobal/interface/CaloTemplate.h"
0065 #include "L1Trigger/L1TGlobal/interface/EnergySumTemplate.h"
0066 #include "L1Trigger/L1TGlobal/interface/GlobalScales.h"
0067 
0068 #include "DataFormats/L1Trigger/interface/L1Candidate.h"
0069 
0070 #include "L1Trigger/L1TGlobal/interface/GlobalBoard.h"
0071 
0072 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0073 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0074 
0075 // constructors
0076 //     default
0077 l1t::CorrWithOverlapRemovalCondition::CorrWithOverlapRemovalCondition() : ConditionEvaluation() {}
0078 
0079 //     from base template condition (from event setup usually)
0080 l1t::CorrWithOverlapRemovalCondition::CorrWithOverlapRemovalCondition(const GlobalCondition* corrTemplate,
0081                                                                       const GlobalCondition* cond0Condition,
0082                                                                       const GlobalCondition* cond1Condition,
0083                                                                       const GlobalCondition* cond2Condition,
0084                                                                       const GlobalBoard* ptrGTB)
0085     : ConditionEvaluation(),
0086       m_gtCorrelationWithOverlapRemovalTemplate(
0087           static_cast<const CorrelationWithOverlapRemovalTemplate*>(corrTemplate)),
0088       m_gtCond0(cond0Condition),
0089       m_gtCond1(cond1Condition),
0090       m_gtCond2(cond2Condition),
0091       m_uGtB(ptrGTB) {}
0092 
0093 // copy constructor
0094 void l1t::CorrWithOverlapRemovalCondition::copy(const l1t::CorrWithOverlapRemovalCondition& cp) {
0095   m_gtCorrelationWithOverlapRemovalTemplate = cp.gtCorrelationWithOverlapRemovalTemplate();
0096   m_uGtB = cp.getuGtB();
0097 
0098   m_condMaxNumberObjects = cp.condMaxNumberObjects();
0099   m_condLastResult = cp.condLastResult();
0100   m_combinationsInCond = cp.getCombinationsInCond();
0101 
0102   m_verbosity = cp.m_verbosity;
0103 }
0104 
0105 l1t::CorrWithOverlapRemovalCondition::CorrWithOverlapRemovalCondition(const l1t::CorrWithOverlapRemovalCondition& cp)
0106     : ConditionEvaluation() {
0107   copy(cp);
0108 }
0109 
0110 // destructor
0111 l1t::CorrWithOverlapRemovalCondition::~CorrWithOverlapRemovalCondition() {
0112   // empty
0113 }
0114 
0115 // equal operator
0116 l1t::CorrWithOverlapRemovalCondition& l1t::CorrWithOverlapRemovalCondition::operator=(
0117     const l1t::CorrWithOverlapRemovalCondition& cp) {
0118   copy(cp);
0119   return *this;
0120 }
0121 
0122 // methods
0123 void l1t::CorrWithOverlapRemovalCondition::setGtCorrelationWithOverlapRemovalTemplate(
0124     const CorrelationWithOverlapRemovalTemplate* caloTempl) {
0125   m_gtCorrelationWithOverlapRemovalTemplate = caloTempl;
0126 }
0127 
0128 ///   set the pointer to uGT GlobalBoard
0129 void l1t::CorrWithOverlapRemovalCondition::setuGtB(const GlobalBoard* ptrGTB) { m_uGtB = ptrGTB; }
0130 
0131 void l1t::CorrWithOverlapRemovalCondition::setScales(const GlobalScales* sc) { m_gtScales = sc; }
0132 
0133 // try all object permutations and check spatial correlations, if required
0134 const bool l1t::CorrWithOverlapRemovalCondition::evaluateCondition(const int bxEval) const {
0135   // std::cout << "m_isDebugEnabled = " << m_isDebugEnabled << std::endl;
0136   // std::cout << "m_verbosity = " << m_verbosity << std::endl;
0137 
0138   //std::ostringstream myCout;
0139   //m_gtCorrelationWithOverlapRemovalTemplate->print(myCout);
0140   //LogDebug("L1TGlobal")
0141   //   << "CorrelationWithOverlapRemoval Condition Evaluation \n" << myCout.str() << std::endl;
0142 
0143   bool condResult = false;
0144   bool reqObjResult = false;
0145 
0146   // number of objects in condition (it is 3, no need to retrieve from
0147   // condition template) and their type
0148   int nObjInCond = 3;
0149   std::vector<GlobalObject> cndObjTypeVec(nObjInCond);
0150 
0151   // evaluate first the two sub-conditions (Type1s)
0152 
0153   const GtConditionCategory cond0Categ = m_gtCorrelationWithOverlapRemovalTemplate->cond0Category();
0154   const GtConditionCategory cond1Categ = m_gtCorrelationWithOverlapRemovalTemplate->cond1Category();
0155   const GtConditionCategory cond2Categ = m_gtCorrelationWithOverlapRemovalTemplate->cond2Category();
0156 
0157   //Decide if we have a mixed (muon + cal) condition
0158   bool convertCaloScales = false;
0159   if ((cond0Categ == CondMuon && (cond1Categ == CondCalo || cond1Categ == CondEnergySum)) ||
0160       (cond1Categ == CondMuon && (cond0Categ == CondCalo || cond0Categ == CondEnergySum)))
0161     convertCaloScales = true;
0162 
0163   bool convertCaloScalesForOverlapRemovalFromLeg0 = false;
0164   if ((cond0Categ == CondMuon && (cond2Categ == CondCalo || cond2Categ == CondEnergySum)) ||
0165       (cond2Categ == CondMuon && (cond0Categ == CondCalo || cond0Categ == CondEnergySum)))
0166     convertCaloScalesForOverlapRemovalFromLeg0 = true;
0167 
0168   bool convertCaloScalesForOverlapRemovalFromLeg1 = false;
0169   if ((cond1Categ == CondMuon && (cond2Categ == CondCalo || cond2Categ == CondEnergySum)) ||
0170       (cond2Categ == CondMuon && (cond1Categ == CondCalo || cond1Categ == CondEnergySum)))
0171     convertCaloScalesForOverlapRemovalFromLeg1 = true;
0172 
0173   const MuonTemplate* corrMuon = nullptr;
0174   const CaloTemplate* corrCalo = nullptr;
0175   const EnergySumTemplate* corrEnergySum = nullptr;
0176 
0177   // FIXME copying is slow...
0178   CombinationsInCond cond0Comb;
0179   CombinationsInCond cond1Comb;
0180   CombinationsInCond cond2Comb;
0181 
0182   int cond0bx(0);
0183   int cond1bx(0);
0184   int cond2bx(0);
0185 
0186   switch (cond0Categ) {
0187     case CondMuon: {
0188       corrMuon = static_cast<const MuonTemplate*>(m_gtCond0);
0189       MuCondition muCondition(
0190           corrMuon, m_uGtB, 0, 0);  //BLW these are counts that don't seem to be used...perhaps remove
0191 
0192       muCondition.evaluateConditionStoreResult(bxEval);
0193       reqObjResult = muCondition.condLastResult();
0194 
0195       cond0Comb = (muCondition.getCombinationsInCond());
0196       cond0bx = bxEval + (corrMuon->condRelativeBx());
0197 
0198       cndObjTypeVec[0] = (corrMuon->objectType())[0];
0199 
0200       if (m_verbosity) {
0201         std::ostringstream myCout;
0202         muCondition.print(myCout);
0203 
0204         LogDebug("L1TGlobal") << myCout.str() << std::endl;
0205       }
0206     } break;
0207     case CondCalo: {
0208       corrCalo = static_cast<const CaloTemplate*>(m_gtCond0);
0209 
0210       CaloCondition caloCondition(
0211           corrCalo, m_uGtB, 0, 0, 0, 0);  //BLW these are counters that don't seem to be used...perhaps remove.
0212 
0213       caloCondition.evaluateConditionStoreResult(bxEval);
0214       reqObjResult = caloCondition.condLastResult();
0215 
0216       cond0Comb = (caloCondition.getCombinationsInCond());
0217       cond0bx = bxEval + (corrCalo->condRelativeBx());
0218 
0219       cndObjTypeVec[0] = (corrCalo->objectType())[0];
0220 
0221       if (m_verbosity) {
0222         std::ostringstream myCout;
0223         caloCondition.print(myCout);
0224 
0225         LogDebug("L1TGlobal") << myCout.str() << std::endl;
0226       }
0227     } break;
0228     case CondEnergySum: {
0229       corrEnergySum = static_cast<const EnergySumTemplate*>(m_gtCond0);
0230       EnergySumCondition eSumCondition(corrEnergySum, m_uGtB);
0231 
0232       eSumCondition.evaluateConditionStoreResult(bxEval);
0233       reqObjResult = eSumCondition.condLastResult();
0234 
0235       cond0Comb = (eSumCondition.getCombinationsInCond());
0236       cond0bx = bxEval + (corrEnergySum->condRelativeBx());
0237 
0238       cndObjTypeVec[0] = (corrEnergySum->objectType())[0];
0239 
0240       if (m_verbosity) {
0241         std::ostringstream myCout;
0242         eSumCondition.print(myCout);
0243 
0244         LogDebug("L1TGlobal") << myCout.str() << std::endl;
0245       }
0246     } break;
0247     default: {
0248       // should not arrive here, there are no correlation conditions defined for this object
0249       return false;
0250     } break;
0251   }
0252 
0253   // return if first subcondition is false
0254   if (!reqObjResult) {
0255     LogDebug("L1TGlobal") << "\n  First sub-condition false, second sub-condition not evaluated and not printed."
0256                           << std::endl;
0257     return false;
0258   }
0259 
0260   // second object
0261   reqObjResult = false;
0262 
0263   switch (cond1Categ) {
0264     case CondMuon: {
0265       corrMuon = static_cast<const MuonTemplate*>(m_gtCond1);
0266       MuCondition muCondition(
0267           corrMuon, m_uGtB, 0, 0);  //BLW these are counts that don't seem to be used...perhaps remove
0268 
0269       muCondition.evaluateConditionStoreResult(bxEval);
0270       reqObjResult = muCondition.condLastResult();
0271 
0272       cond1Comb = (muCondition.getCombinationsInCond());
0273       cond1bx = bxEval + (corrMuon->condRelativeBx());
0274       cndObjTypeVec[1] = (corrMuon->objectType())[0];
0275 
0276       if (m_verbosity) {
0277         std::ostringstream myCout;
0278         muCondition.print(myCout);
0279 
0280         LogDebug("L1TGlobal") << myCout.str() << std::endl;
0281       }
0282     } break;
0283     case CondCalo: {
0284       corrCalo = static_cast<const CaloTemplate*>(m_gtCond1);
0285       CaloCondition caloCondition(
0286           corrCalo, m_uGtB, 0, 0, 0, 0);  //BLW these are counters that don't seem to be used...perhaps remove.
0287 
0288       caloCondition.evaluateConditionStoreResult(bxEval);
0289       reqObjResult = caloCondition.condLastResult();
0290 
0291       cond1Comb = (caloCondition.getCombinationsInCond());
0292       cond1bx = bxEval + (corrCalo->condRelativeBx());
0293 
0294       cndObjTypeVec[1] = (corrCalo->objectType())[0];
0295 
0296       if (m_verbosity) {
0297         std::ostringstream myCout;
0298         caloCondition.print(myCout);
0299 
0300         LogDebug("L1TGlobal") << myCout.str() << std::endl;
0301       }
0302 
0303     } break;
0304     case CondEnergySum: {
0305       corrEnergySum = static_cast<const EnergySumTemplate*>(m_gtCond1);
0306 
0307       EnergySumCondition eSumCondition(corrEnergySum, m_uGtB);
0308 
0309       eSumCondition.evaluateConditionStoreResult(bxEval);
0310       reqObjResult = eSumCondition.condLastResult();
0311 
0312       cond1Comb = (eSumCondition.getCombinationsInCond());
0313       cond1bx = bxEval + (corrEnergySum->condRelativeBx());
0314       cndObjTypeVec[1] = (corrEnergySum->objectType())[0];
0315 
0316       if (m_verbosity) {
0317         std::ostringstream myCout;
0318         eSumCondition.print(myCout);
0319 
0320         LogDebug("L1TGlobal") << myCout.str() << std::endl;
0321       }
0322     } break;
0323     default: {
0324       // should not arrive here, there are no correlation conditions defined for this object
0325       return false;
0326     } break;
0327   }
0328 
0329   // return if second sub-condition is false
0330   if (!reqObjResult) {
0331     return false;
0332   } else {
0333     LogDebug("L1TGlobal") << "\n"
0334                           << "    Both sub-conditions true for object requirements."
0335                           << "    Evaluate correlation requirements.\n"
0336                           << std::endl;
0337   }
0338 
0339   // third object (used for overlap removal)
0340   reqObjResult = false;
0341 
0342   switch (cond2Categ) {
0343     case CondMuon: {
0344       corrMuon = static_cast<const MuonTemplate*>(m_gtCond2);
0345       MuCondition muCondition(
0346           corrMuon, m_uGtB, 0, 0);  //BLW these are counts that don't seem to be used...perhaps remove
0347 
0348       muCondition.evaluateConditionStoreResult(bxEval);
0349       reqObjResult = muCondition.condLastResult();
0350 
0351       cond2Comb = (muCondition.getCombinationsInCond());
0352       cond2bx = bxEval + (corrMuon->condRelativeBx());
0353       cndObjTypeVec[2] = (corrMuon->objectType())[0];
0354 
0355       if (m_verbosity) {
0356         std::ostringstream myCout;
0357         muCondition.print(myCout);
0358 
0359         LogDebug("L1TGlobal") << myCout.str() << std::endl;
0360       }
0361     } break;
0362     case CondCalo: {
0363       corrCalo = static_cast<const CaloTemplate*>(m_gtCond2);
0364       CaloCondition caloCondition(
0365           corrCalo, m_uGtB, 0, 0, 0, 0);  //BLW these are counters that don't seem to be used...perhaps remove.
0366 
0367       caloCondition.evaluateConditionStoreResult(bxEval);
0368       reqObjResult = caloCondition.condLastResult();
0369 
0370       cond2Comb = (caloCondition.getCombinationsInCond());
0371       cond2bx = bxEval + (corrCalo->condRelativeBx());
0372       cndObjTypeVec[2] = (corrCalo->objectType())[0];
0373 
0374       if (m_verbosity) {
0375         std::ostringstream myCout;
0376         caloCondition.print(myCout);
0377 
0378         LogDebug("L1TGlobal") << myCout.str() << std::endl;
0379       }
0380 
0381     } break;
0382     case CondEnergySum: {
0383       corrEnergySum = static_cast<const EnergySumTemplate*>(m_gtCond2);
0384 
0385       EnergySumCondition eSumCondition(corrEnergySum, m_uGtB);
0386 
0387       eSumCondition.evaluateConditionStoreResult(bxEval);
0388       reqObjResult = eSumCondition.condLastResult();
0389 
0390       cond2Comb = (eSumCondition.getCombinationsInCond());
0391       cond2bx = bxEval + (corrEnergySum->condRelativeBx());
0392       cndObjTypeVec[2] = (corrEnergySum->objectType())[0];
0393 
0394       if (m_verbosity) {
0395         std::ostringstream myCout;
0396         eSumCondition.print(myCout);
0397 
0398         LogDebug("L1TGlobal") << myCout.str() << std::endl;
0399       }
0400     } break;
0401     default: {
0402       // should not arrive here, there are no correlation conditions defined for this object
0403       return false;
0404     } break;
0405   }
0406 
0407   // if third sub-condition is false, effectively there will no overlap removal
0408   if (!reqObjResult) {
0409     LogDebug("L1TGlobal") << "\n"
0410                           << "    Third sub-condtion false for object requirements."
0411                           << "    Algorithm returning false.\n"
0412                           << std::endl;
0413     return false;
0414   } else {
0415     LogDebug("L1TGlobal") << "\n"
0416                           << "    All three sub-conditions true for object requirements."
0417                           << "    Evaluate correlation requirements and overlap removal.\n"
0418                           << std::endl;
0419   }
0420 
0421   // since we have two good legs and overlap-removal let, get the correlation parameters
0422   CorrelationWithOverlapRemovalTemplate::CorrelationWithOverlapRemovalParameter corrPar =
0423       *(m_gtCorrelationWithOverlapRemovalTemplate->correlationParameter());
0424 
0425   // vector to store the indices of the calorimeter objects
0426   // from the combination evaluated in the condition
0427   SingleCombInCond objectsInComb;
0428   objectsInComb.reserve(nObjInCond);
0429 
0430   // clear the m_combinationsInCond vector
0431   (combinationsInCond()).clear();
0432 
0433   // pointers to objects
0434   const BXVector<const l1t::Muon*>* candMuVec = nullptr;
0435   const BXVector<const l1t::L1Candidate*>* candCaloVec = nullptr;
0436   const BXVector<const l1t::EtSum*>* candEtSumVec = nullptr;
0437 
0438   bool etSumCond = false;
0439 
0440   // make the conversions of the indices, depending on the combination of objects involved
0441   // (via pair index)
0442 
0443   int phiIndex0 = 0;
0444   int phiIndex1 = 0;
0445   int phiORIndex0 = 0;  // hold phi index transformed in case of need with overlap-removal
0446   int phiORIndex1 = 0;  // hold phi index transformed in case of need with overlap-removal
0447   double phi0Phy = 0.;
0448   double phi1Phy = 0.;
0449 
0450   int etaIndex0 = 0;
0451   int etaIndex1 = 0;
0452   int etaORIndex0 = 0;
0453   int etaORIndex1 = 0;
0454   double eta0Phy = 0.;
0455   double eta1Phy = 0.;
0456   int etaBin0 = 0;
0457   int etaBin1 = 0;
0458 
0459   int etIndex0 = 0;
0460   int etIndex1 = 0;
0461   int etBin0 = 0;
0462   int etBin1 = 0;
0463   double et0Phy = 0.;
0464   double et1Phy = 0.;
0465 
0466   int chrg0 = -1;
0467   int chrg1 = -1;
0468 
0469   // make the conversions of the indices, depending on the combination of objects involved in overlap-removal
0470   int phiIndex2 = 0;
0471   int etaIndex2 = 0;
0472   double phi2Phy = 0.;
0473   double eta2Phy = 0.;
0474   int etaBin2 = 0;
0475   //int etIndex2  = 0;
0476   //int etBin2    = 0;
0477 
0478   // Determine the number of phi bins to get cutoff at pi
0479   int phiBound = 0;
0480   if (cond0Categ == CondMuon || cond1Categ == CondMuon || cond2Categ == CondMuon) {
0481     GlobalScales::ScaleParameters par = m_gtScales->getMUScales();
0482     //phiBound = par.phiBins.size()/2;
0483     phiBound = (int)((par.phiMax - par.phiMin) / par.phiStep) / 2;
0484   } else {
0485     //Assumes all calorimeter objects are on same phi scale
0486     GlobalScales::ScaleParameters par = m_gtScales->getEGScales();
0487     //phiBound = par.phiBins.size()/2;
0488     phiBound = (int)((par.phiMax - par.phiMin) / par.phiStep) / 2;
0489   }
0490   LogDebug("L1TGlobal") << "Phi Bound = " << phiBound << std::endl;
0491 
0492   // Keep track of objects for LUTS
0493   std::string lutObj0 = "NULL";
0494   std::string lutObj1 = "NULL";
0495   std::string lutObj2 = "NULL";
0496 
0497   LogTrace("L1TGlobal") << "  Sub-condition 0: std::vector<SingleCombInCond> size: " << (cond0Comb.size()) << std::endl;
0498   LogTrace("L1TGlobal") << "  Sub-condition 1: std::vector<SingleCombInCond> size: " << (cond1Comb.size()) << std::endl;
0499   LogTrace("L1TGlobal") << "  Sub-condition 2: std::vector<SingleCombInCond> size: " << (cond2Comb.size()) << std::endl;
0500 
0501   // ///////////////////////////////////////////////////////////////////////////////////////////
0502   // loop over all combinations which produced individually "true" as Type1s
0503   // ///////////////////////////////////////////////////////////////////////////////////////////
0504   // BLW: Optimization issue: potentially making the same comparison twice
0505   //                          if both legs are the same object type.
0506   // ///////////////////////////////////////////////////////////////////////////////////////////
0507   for (std::vector<SingleCombInCond>::const_iterator it0Comb = cond0Comb.begin(); it0Comb != cond0Comb.end();
0508        it0Comb++) {
0509     // Type1s: there is 1 object only, no need for a loop, index 0 should be OK in (*it0Comb)[0]
0510     // ... but add protection to not crash
0511     int obj0Index = -1;
0512 
0513     if (!(*it0Comb).empty()) {
0514       obj0Index = (*it0Comb)[0];
0515     } else {
0516       LogTrace("L1TGlobal") << "\n  SingleCombInCond (*it0Comb).size() " << ((*it0Comb).size()) << std::endl;
0517       return false;
0518     }
0519 
0520     // Collect the information on the first leg of the correlation
0521     switch (cond0Categ) {
0522       case CondMuon: {
0523         lutObj0 = "MU";
0524         candMuVec = m_uGtB->getCandL1Mu();
0525         phiIndex0 = (candMuVec->at(cond0bx, obj0Index))->hwPhi();  //(*candMuVec)[obj0Index]->phiIndex();
0526         etaIndex0 = (candMuVec->at(cond0bx, obj0Index))->hwEta();
0527         etIndex0 = (candMuVec->at(cond0bx, obj0Index))->hwPt();
0528         chrg0 = (candMuVec->at(cond0bx, obj0Index))->hwCharge();
0529         int etaBin0 = etaIndex0;
0530         if (etaBin0 < 0)
0531           etaBin0 = m_gtScales->getMUScales().etaBins.size() + etaBin0;  //twos complement
0532         //      LogDebug("L1TGlobal") << "Muon phi" << phiIndex0 << " eta " << etaIndex0 << " etaBin0 = " << etaBin0  << " et " << etIndex0 << std::endl;
0533         //
0534 
0535         etBin0 = etIndex0;
0536         int ssize = m_gtScales->getMUScales().etBins.size();
0537         if (etBin0 >= ssize) {
0538           etBin0 = ssize - 1;
0539           LogTrace("L1TGlobal") << "muon0 hw et" << etBin0 << " out of scale range.  Setting to maximum.";
0540         }
0541 
0542         // Determine Floating Pt numbers for floating point caluclation
0543         std::pair<double, double> binEdges = m_gtScales->getMUScales().phiBins.at(phiIndex0);
0544         phi0Phy = 0.5 * (binEdges.second + binEdges.first);
0545         binEdges = m_gtScales->getMUScales().etaBins.at(etaBin0);
0546         eta0Phy = 0.5 * (binEdges.second + binEdges.first);
0547         binEdges = m_gtScales->getMUScales().etBins.at(etBin0);
0548         et0Phy = 0.5 * (binEdges.second + binEdges.first);
0549 
0550         LogDebug("L1TGlobal") << "Found all quantities for the muon 0" << std::endl;
0551       } break;
0552 
0553         // Calorimeter Objects (EG, Jet, Tau)
0554       case CondCalo: {
0555         switch (cndObjTypeVec[0]) {
0556           case gtEG: {
0557             lutObj0 = "EG";
0558             candCaloVec = m_uGtB->getCandL1EG();
0559             phiIndex0 = (candCaloVec->at(cond0bx, obj0Index))->hwPhi();
0560             etaIndex0 = (candCaloVec->at(cond0bx, obj0Index))->hwEta();
0561             etIndex0 = (candCaloVec->at(cond0bx, obj0Index))->hwPt();
0562             etaBin0 = etaIndex0;
0563             if (etaBin0 < 0)
0564               etaBin0 = m_gtScales->getEGScales().etaBins.size() + etaBin0;
0565             //          LogDebug("L1TGlobal") << "EG0 phi" << phiIndex0 << " eta " << etaIndex0 << " etaBin0 = " << etaBin0 << " et " << etIndex0 << std::endl;
0566 
0567             etBin0 = etIndex0;
0568             int ssize = m_gtScales->getEGScales().etBins.size();
0569             if (etBin0 >= ssize) {
0570               etBin0 = ssize - 1;
0571               LogTrace("L1TGlobal") << "EG0 hw et" << etBin0 << " out of scale range.  Setting to maximum.";
0572             }
0573 
0574             // Determine Floating Pt numbers for floating point caluclation
0575             std::pair<double, double> binEdges = m_gtScales->getEGScales().phiBins.at(phiIndex0);
0576             phi0Phy = 0.5 * (binEdges.second + binEdges.first);
0577             binEdges = m_gtScales->getEGScales().etaBins.at(etaBin0);
0578             eta0Phy = 0.5 * (binEdges.second + binEdges.first);
0579             binEdges = m_gtScales->getEGScales().etBins[etBin0];
0580             et0Phy = 0.5 * (binEdges.second + binEdges.first);
0581 
0582           } break;
0583           case gtJet: {
0584             lutObj0 = "JET";
0585             candCaloVec = m_uGtB->getCandL1Jet();
0586             phiIndex0 = (candCaloVec->at(cond0bx, obj0Index))->hwPhi();
0587             etaIndex0 = (candCaloVec->at(cond0bx, obj0Index))->hwEta();
0588             etIndex0 = (candCaloVec->at(cond0bx, obj0Index))->hwPt();
0589             etaBin0 = etaIndex0;
0590             if (etaBin0 < 0)
0591               etaBin0 = m_gtScales->getJETScales().etaBins.size() + etaBin0;
0592 
0593             etBin0 = etIndex0;
0594             int ssize = m_gtScales->getJETScales().etBins.size();
0595             if (etBin0 >= ssize) {
0596               //edm::LogWarning("L1TGlobal")
0597               //<< "jet0 hw et" << etBin0 << " out of scale range.  Setting to maximum.";
0598               etBin0 = ssize - 1;
0599             }
0600 
0601             // Determine Floating Pt numbers for floating point caluclation
0602             std::pair<double, double> binEdges = m_gtScales->getJETScales().phiBins.at(phiIndex0);
0603             phi0Phy = 0.5 * (binEdges.second + binEdges.first);
0604             binEdges = m_gtScales->getJETScales().etaBins.at(etaBin0);
0605             eta0Phy = 0.5 * (binEdges.second + binEdges.first);
0606             binEdges = m_gtScales->getJETScales().etBins.at(etBin0);
0607             et0Phy = 0.5 * (binEdges.second + binEdges.first);
0608 
0609           } break;
0610           case gtTau: {
0611             candCaloVec = m_uGtB->getCandL1Tau();
0612             phiIndex0 = (candCaloVec->at(cond0bx, obj0Index))->hwPhi();
0613             etaIndex0 = (candCaloVec->at(cond0bx, obj0Index))->hwEta();
0614             etIndex0 = (candCaloVec->at(cond0bx, obj0Index))->hwPt();
0615             etaBin0 = etaIndex0;
0616             if (etaBin0 < 0)
0617               etaBin0 = m_gtScales->getTAUScales().etaBins.size() + etaBin0;
0618 
0619             etBin0 = etIndex0;
0620             int ssize = m_gtScales->getTAUScales().etBins.size();
0621             if (etBin0 >= ssize) {
0622               etBin0 = ssize - 1;
0623               LogTrace("L1TGlobal") << "tau0 hw et" << etBin0 << " out of scale range.  Setting to maximum.";
0624             }
0625 
0626             // Determine Floating Pt numbers for floating point caluclation
0627             std::pair<double, double> binEdges = m_gtScales->getTAUScales().phiBins.at(phiIndex0);
0628             phi0Phy = 0.5 * (binEdges.second + binEdges.first);
0629             binEdges = m_gtScales->getTAUScales().etaBins.at(etaBin0);
0630             eta0Phy = 0.5 * (binEdges.second + binEdges.first);
0631             binEdges = m_gtScales->getTAUScales().etBins.at(etBin0);
0632             et0Phy = 0.5 * (binEdges.second + binEdges.first);
0633             lutObj0 = "TAU";
0634           } break;
0635           default: {
0636           } break;
0637         }  //end switch on calo type.
0638 
0639         phiORIndex0 = phiIndex0;
0640         etaORIndex0 = etaIndex0;
0641 
0642         //If needed convert calo scales to muon scales for comparison
0643         if (convertCaloScales) {
0644           std::string lutName = lutObj0;
0645           lutName += "-MU";
0646           long long tst = m_gtScales->getLUT_CalMuEta(lutName, etaBin0);
0647           LogDebug("L1TGlobal") << lutName << "  EtaCal = " << etaIndex0 << " etaBin0 = " << etaBin0
0648                                 << " EtaMu = " << tst << std::endl;
0649           etaIndex0 = tst;
0650           tst = m_gtScales->getLUT_CalMuPhi(lutName, phiIndex0);
0651           LogDebug("L1TGlobal") << lutName << "  PhiCal = " << phiIndex0 << " PhiMu = " << tst << std::endl;
0652           phiIndex0 = tst;
0653         }
0654 
0655         //If needed convert calo scales to muon scales for comparison
0656         if (convertCaloScalesForOverlapRemovalFromLeg0) {
0657           phiORIndex0 = phiIndex0;
0658           etaORIndex0 = etaIndex0;
0659         }
0660 
0661       } break;
0662 
0663       // Energy Sums
0664       case CondEnergySum: {
0665         etSumCond = true;
0666         //Stupid mapping between enum types for energy sums.
0667         l1t::EtSum::EtSumType type;
0668 
0669         switch (cndObjTypeVec[0]) {
0670           case gtETM:
0671             type = l1t::EtSum::EtSumType::kMissingEt;
0672             lutObj0 = "ETM";
0673             break;
0674           case gtETT:
0675             type = l1t::EtSum::EtSumType::kTotalEt;
0676             lutObj0 = "ETT";
0677             break;
0678           case gtETTem:
0679             type = l1t::EtSum::EtSumType::kTotalEtEm;
0680             lutObj0 =
0681                 "ETTem";  //should this be just ETT (share LUTs?) Can't be used for CorrCond anyway since now directional information
0682             break;
0683           case gtHTM:
0684             type = l1t::EtSum::EtSumType::kMissingHt;
0685             lutObj0 = "HTM";
0686             break;
0687           case gtHTT:
0688             type = l1t::EtSum::EtSumType::kTotalHt;
0689             lutObj0 = "HTT";
0690             break;
0691           case gtETMHF:
0692             type = l1t::EtSum::EtSumType::kMissingEtHF;
0693             lutObj0 = "ETMHF";
0694             break;
0695           case gtMinBiasHFP0:
0696           case gtMinBiasHFM0:
0697           case gtMinBiasHFP1:
0698           case gtMinBiasHFM1:
0699             type = l1t::EtSum::EtSumType::kMinBiasHFP0;
0700             lutObj0 =
0701                 "MinBias";  //??Fix?? Not a valid LUT type Can't be used for CorrCond anyway since now directional information
0702             break;
0703           default:
0704             edm::LogError("L1TGlobal") << "\n  Error: "
0705                                        << "Unmatched object type from template to EtSumType, cndObjTypeVec[0] = "
0706                                        << cndObjTypeVec[0] << std::endl;
0707             type = l1t::EtSum::EtSumType::kTotalEt;
0708             break;
0709         }
0710 
0711         candEtSumVec = m_uGtB->getCandL1EtSum();
0712 
0713         for (int iEtSum = 0; iEtSum < (int)candEtSumVec->size(cond0bx); iEtSum++) {
0714           if ((candEtSumVec->at(cond0bx, iEtSum))->getType() == type) {
0715             phiIndex0 = (candEtSumVec->at(cond0bx, iEtSum))->hwPhi();
0716             etaIndex0 = (candEtSumVec->at(cond0bx, iEtSum))->hwEta();
0717             etIndex0 = (candEtSumVec->at(cond0bx, iEtSum))->hwPt();
0718 
0719             //  Get the floating point numbers
0720             if (cndObjTypeVec[0] == gtETM) {
0721               std::pair<double, double> binEdges = m_gtScales->getETMScales().phiBins.at(phiIndex0);
0722               phi0Phy = 0.5 * (binEdges.second + binEdges.first);
0723               eta0Phy = 0.;  //No Eta for Energy Sums
0724 
0725               etBin0 = etIndex0;
0726               int ssize = m_gtScales->getETMScales().etBins.size();
0727               assert(ssize > 0);
0728               if (etBin0 >= ssize) {
0729                 etBin0 = ssize - 1;
0730               }
0731 
0732               binEdges = m_gtScales->getETMScales().etBins.at(etBin0);
0733               et0Phy = 0.5 * (binEdges.second + binEdges.first);
0734             } else if (cndObjTypeVec[0] == gtHTM) {
0735               std::pair<double, double> binEdges = m_gtScales->getHTMScales().phiBins.at(phiIndex0);
0736               phi0Phy = 0.5 * (binEdges.second + binEdges.first);
0737               eta0Phy = 0.;  //No Eta for Energy Sums
0738 
0739               etBin0 = etIndex0;
0740               int ssize = m_gtScales->getHTMScales().etBins.size();
0741               assert(ssize > 0);
0742               if (etBin0 >= ssize) {
0743                 etBin0 = ssize - 1;
0744               }
0745 
0746               binEdges = m_gtScales->getHTMScales().etBins.at(etBin0);
0747               et0Phy = 0.5 * (binEdges.second + binEdges.first);
0748             } else if (cndObjTypeVec[0] == gtETMHF) {
0749               std::pair<double, double> binEdges = m_gtScales->getETMHFScales().phiBins.at(phiIndex0);
0750               phi0Phy = 0.5 * (binEdges.second + binEdges.first);
0751               eta0Phy = 0.;  //No Eta for Energy Sums
0752 
0753               etBin0 = etIndex0;
0754               int ssize = m_gtScales->getETMHFScales().etBins.size();
0755               assert(ssize > 0);
0756               if (etBin0 >= ssize) {
0757                 etBin0 = ssize - 1;
0758               }
0759 
0760               binEdges = m_gtScales->getETMHFScales().etBins.at(etBin0);
0761               et0Phy = 0.5 * (binEdges.second + binEdges.first);
0762             }
0763 
0764             phiORIndex0 = phiIndex0;
0765             etaORIndex0 = etaIndex0;
0766 
0767             //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
0768             if (convertCaloScales) {
0769               std::string lutName = lutObj0;
0770               lutName += "-MU";
0771               long long tst = m_gtScales->getLUT_CalMuPhi(lutName, phiIndex0);
0772               LogDebug("L1TGlobal") << lutName << "  PhiCal = " << phiIndex0 << " PhiMu = " << tst << std::endl;
0773               phiIndex0 = tst;
0774             }
0775 
0776             //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
0777             if (convertCaloScalesForOverlapRemovalFromLeg0) {
0778               phiORIndex0 = phiIndex0;
0779             }
0780 
0781           }  //check it is the EtSum we want
0782         }    // loop over Etsums
0783 
0784       }  // end case CondEnergySum
0785       break;
0786 
0787       default: {
0788         // should not arrive here, there are no correlation conditions defined for this object
0789         LogDebug("L1TGlobal") << "Error could not find the Cond Category for Leg 0" << std::endl;
0790         return false;
0791       } break;
0792     }  //end switch on first leg type
0793 
0794     LogDebug("L1TGlobal") << "lutObj0 = " << lutObj0 << std::endl;
0795 
0796     // ///////////////////////////////////////////////////////////////////////////////////////////
0797     // Now loop over the second leg to get its information
0798     // ///////////////////////////////////////////////////////////////////////////////////////////
0799     for (std::vector<SingleCombInCond>::const_iterator it1Comb = cond1Comb.begin(); it1Comb != cond1Comb.end();
0800          it1Comb++) {
0801       LogDebug("L1TGlobal") << "Looking at second Condition" << std::endl;
0802       // Type1s: there is 1 object only, no need for a loop (*it1Comb)[0]
0803       // ... but add protection to not crash
0804       int obj1Index = -1;
0805 
0806       if (!(*it1Comb).empty()) {
0807         obj1Index = (*it1Comb)[0];
0808       } else {
0809         LogTrace("L1TGlobal") << "\n  SingleCombInCond (*it1Comb).size() " << ((*it1Comb).size()) << std::endl;
0810         return false;
0811       }
0812 
0813       //If we are dealing with the same object type avoid the two legs
0814       // either being the same object
0815       if (cndObjTypeVec[0] == cndObjTypeVec[1] && obj0Index == obj1Index && cond0bx == cond1bx) {
0816         LogDebug("L1TGlobal") << "Corr Condition looking at same leg...skip" << std::endl;
0817         continue;
0818       }
0819 
0820       switch (cond1Categ) {
0821         case CondMuon: {
0822           lutObj1 = "MU";
0823           candMuVec = m_uGtB->getCandL1Mu();
0824           phiIndex1 = (candMuVec->at(cond1bx, obj1Index))->hwPhi();  //(*candMuVec)[obj0Index]->phiIndex();
0825           etaIndex1 = (candMuVec->at(cond1bx, obj1Index))->hwEta();
0826           etIndex1 = (candMuVec->at(cond1bx, obj1Index))->hwPt();
0827           chrg1 = (candMuVec->at(cond1bx, obj1Index))->hwCharge();
0828           etaBin1 = etaIndex1;
0829           if (etaBin1 < 0)
0830             etaBin1 = m_gtScales->getMUScales().etaBins.size() + etaBin1;
0831           //           LogDebug("L1TGlobal") << "Muon phi" << phiIndex1 << " eta " << etaIndex1 << " etaBin1 = " << etaBin1  << " et " << etIndex1 << std::endl;
0832           etBin1 = etIndex1;
0833           int ssize = m_gtScales->getMUScales().etBins.size();
0834 
0835           if (etBin1 >= ssize) {
0836             LogTrace("L1TGlobal") << "muon2 hw et" << etBin1 << " out of scale range.  Setting to maximum.";
0837             etBin1 = ssize - 1;
0838           }
0839 
0840           // Determine Floating Pt numbers for floating point caluclation
0841           std::pair<double, double> binEdges = m_gtScales->getMUScales().phiBins.at(phiIndex1);
0842           phi1Phy = 0.5 * (binEdges.second + binEdges.first);
0843           binEdges = m_gtScales->getMUScales().etaBins.at(etaBin1);
0844           eta1Phy = 0.5 * (binEdges.second + binEdges.first);
0845           binEdges = m_gtScales->getMUScales().etBins.at(etBin1);
0846           et1Phy = 0.5 * (binEdges.second + binEdges.first);
0847 
0848         } break;
0849 
0850         case CondCalo: {
0851           switch (cndObjTypeVec[1]) {
0852             case gtEG: {
0853               candCaloVec = m_uGtB->getCandL1EG();
0854               phiIndex1 = (candCaloVec->at(cond1bx, obj1Index))->hwPhi();
0855               etaIndex1 = (candCaloVec->at(cond1bx, obj1Index))->hwEta();
0856               etIndex1 = (candCaloVec->at(cond1bx, obj1Index))->hwPt();
0857               etaBin1 = etaIndex1;
0858               if (etaBin1 < 0)
0859                 etaBin1 = m_gtScales->getEGScales().etaBins.size() + etaBin1;
0860 
0861               etBin1 = etIndex1;
0862               int ssize = m_gtScales->getEGScales().etBins.size();
0863               if (etBin1 >= ssize) {
0864                 LogTrace("L1TGlobal") << "EG1 hw et" << etBin1 << " out of scale range.  Setting to maximum.";
0865                 etBin1 = ssize - 1;
0866               }
0867 
0868               // Determine Floating Pt numbers for floating point caluclation
0869               std::pair<double, double> binEdges = m_gtScales->getEGScales().phiBins.at(phiIndex1);
0870               phi1Phy = 0.5 * (binEdges.second + binEdges.first);
0871               binEdges = m_gtScales->getEGScales().etaBins.at(etaBin1);
0872               eta1Phy = 0.5 * (binEdges.second + binEdges.first);
0873               binEdges = m_gtScales->getEGScales().etBins.at(etBin1);
0874               et1Phy = 0.5 * (binEdges.second + binEdges.first);
0875               lutObj1 = "EG";
0876             } break;
0877 
0878             case gtJet: {
0879               candCaloVec = m_uGtB->getCandL1Jet();
0880               phiIndex1 = (candCaloVec->at(cond1bx, obj1Index))->hwPhi();
0881               etaIndex1 = (candCaloVec->at(cond1bx, obj1Index))->hwEta();
0882               etIndex1 = (candCaloVec->at(cond1bx, obj1Index))->hwPt();
0883               etaBin1 = etaIndex1;
0884               if (etaBin1 < 0)
0885                 etaBin1 = m_gtScales->getJETScales().etaBins.size() + etaBin1;
0886               etBin1 = etIndex1;
0887               int ssize = m_gtScales->getJETScales().etBins.size();
0888               assert(ssize);
0889               if (etBin1 >= ssize) {
0890                 //edm::LogWarning("L1TGlobal")
0891                 //<< "jet2 hw et" << etBin1 << " out of scale range.  Setting to maximum.";
0892                 etBin1 = ssize - 1;
0893               }
0894 
0895               // Determine Floating Pt numbers for floating point caluclation
0896               std::pair<double, double> binEdges = m_gtScales->getJETScales().phiBins.at(phiIndex1);
0897               phi1Phy = 0.5 * (binEdges.second + binEdges.first);
0898               binEdges = m_gtScales->getJETScales().etaBins.at(etaBin1);
0899               eta1Phy = 0.5 * (binEdges.second + binEdges.first);
0900 
0901               binEdges = m_gtScales->getJETScales().etBins.at(etBin1);
0902               et1Phy = 0.5 * (binEdges.second + binEdges.first);
0903               lutObj1 = "JET";
0904             } break;
0905 
0906             case gtTau: {
0907               candCaloVec = m_uGtB->getCandL1Tau();
0908               phiIndex1 = (candCaloVec->at(cond1bx, obj1Index))->hwPhi();
0909               etaIndex1 = (candCaloVec->at(cond1bx, obj1Index))->hwEta();
0910               etIndex1 = (candCaloVec->at(cond1bx, obj1Index))->hwPt();
0911               etaBin1 = etaIndex1;
0912               if (etaBin1 < 0)
0913                 etaBin1 = m_gtScales->getTAUScales().etaBins.size() + etaBin1;
0914               etBin1 = etIndex1;
0915               int ssize = m_gtScales->getTAUScales().etBins.size();
0916               if (etBin1 >= ssize) {
0917                 LogTrace("L1TGlobal") << "tau2 hw et" << etBin1 << " out of scale range.  Setting to maximum.";
0918                 etBin1 = ssize - 1;
0919               }
0920 
0921               // Determine Floating Pt numbers for floating point caluclation
0922               std::pair<double, double> binEdges = m_gtScales->getTAUScales().phiBins.at(phiIndex1);
0923               phi1Phy = 0.5 * (binEdges.second + binEdges.first);
0924               binEdges = m_gtScales->getTAUScales().etaBins.at(etaBin1);
0925               eta1Phy = 0.5 * (binEdges.second + binEdges.first);
0926               binEdges = m_gtScales->getTAUScales().etBins.at(etBin1);
0927               et1Phy = 0.5 * (binEdges.second + binEdges.first);
0928               lutObj1 = "TAU";
0929             } break;
0930             default: {
0931             } break;
0932           }  //end switch on calo type.
0933 
0934           phiORIndex1 = phiIndex1;
0935           etaORIndex1 = etaIndex1;
0936 
0937           //If needed convert calo scales to muon scales for comparison
0938           if (convertCaloScales) {
0939             std::string lutName = lutObj1;
0940             lutName += "-MU";
0941             long long tst = m_gtScales->getLUT_CalMuEta(lutName, etaBin1);
0942             LogDebug("L1TGlobal") << lutName << "  EtaCal = " << etaIndex1 << " EtaMu = " << tst << std::endl;
0943             etaIndex1 = tst;
0944             tst = m_gtScales->getLUT_CalMuPhi(lutName, phiIndex1);
0945             LogDebug("L1TGlobal") << lutName << "  PhiCal = " << phiIndex1 << " PhiMu = " << tst << std::endl;
0946             phiIndex1 = tst;
0947           }
0948 
0949           //If needed convert calo scales to muon scales for comparison
0950           if (convertCaloScalesForOverlapRemovalFromLeg1) {
0951             phiORIndex1 = phiIndex1;
0952             etaORIndex1 = etaIndex1;
0953           }
0954 
0955         }  // end case CondCalo
0956         break;
0957         case CondEnergySum: {
0958           LogDebug("L1TGlobal") << "Looking at second Condition as Energy Sum: " << cndObjTypeVec[1] << std::endl;
0959           etSumCond = true;
0960 
0961           //Stupid mapping between enum types for energy sums.
0962           l1t::EtSum::EtSumType type;
0963 
0964           switch (cndObjTypeVec[1]) {
0965             case gtETM:
0966               type = l1t::EtSum::EtSumType::kMissingEt;
0967               lutObj1 = "ETM";
0968               break;
0969             case gtETT:
0970               type = l1t::EtSum::EtSumType::kTotalEt;
0971               lutObj1 = "ETT";
0972               break;
0973             case gtETTem:
0974               type = l1t::EtSum::EtSumType::kTotalEtEm;
0975               lutObj1 = "ETTem";
0976               break;
0977             case gtHTM:
0978               type = l1t::EtSum::EtSumType::kMissingHt;
0979               lutObj1 = "HTM";
0980               break;
0981             case gtHTT:
0982               type = l1t::EtSum::EtSumType::kTotalHt;
0983               lutObj1 = "HTT";
0984               break;
0985             case gtETMHF:
0986               type = l1t::EtSum::EtSumType::kMissingEtHF;
0987               lutObj1 = "ETMHF";
0988               break;
0989             case gtMinBiasHFP0:
0990             case gtMinBiasHFM0:
0991             case gtMinBiasHFP1:
0992             case gtMinBiasHFM1:
0993               type = l1t::EtSum::EtSumType::kMinBiasHFP0;
0994               lutObj1 = "MinBias";
0995               break;
0996             default:
0997               edm::LogError("L1TGlobal") << "\n  Error: "
0998                                          << "Unmatched object type from template to EtSumType, cndObjTypeVec[1] = "
0999                                          << cndObjTypeVec[1] << std::endl;
1000               type = l1t::EtSum::EtSumType::kTotalEt;
1001               break;
1002           }
1003 
1004           candEtSumVec = m_uGtB->getCandL1EtSum();
1005 
1006           LogDebug("L1TGlobal") << "obj " << lutObj1 << " Vector Size " << candEtSumVec->size(cond1bx) << std::endl;
1007           for (int iEtSum = 0; iEtSum < (int)candEtSumVec->size(cond1bx); iEtSum++) {
1008             if ((candEtSumVec->at(cond1bx, iEtSum))->getType() == type) {
1009               phiIndex1 = (candEtSumVec->at(cond1bx, iEtSum))->hwPhi();
1010               etaIndex1 = (candEtSumVec->at(cond1bx, iEtSum))->hwEta();
1011               etIndex1 = (candEtSumVec->at(cond1bx, iEtSum))->hwPt();
1012 
1013               // Determine Floating Pt numbers for floating point caluclation
1014 
1015               if (cndObjTypeVec[1] == gtETM) {
1016                 std::pair<double, double> binEdges = m_gtScales->getETMScales().phiBins.at(phiIndex1);
1017                 phi1Phy = 0.5 * (binEdges.second + binEdges.first);
1018                 eta1Phy = 0.;  //No Eta for Energy Sums
1019 
1020                 etBin1 = etIndex1;
1021                 int ssize = m_gtScales->getETMScales().etBins.size();
1022                 assert(ssize > 0);
1023                 if (etBin1 >= ssize) {
1024                   etBin1 = ssize - 1;
1025                 }
1026 
1027                 binEdges = m_gtScales->getETMScales().etBins.at(etBin1);
1028                 et1Phy = 0.5 * (binEdges.second + binEdges.first);
1029               } else if (cndObjTypeVec[1] == gtHTM) {
1030                 std::pair<double, double> binEdges = m_gtScales->getHTMScales().phiBins.at(phiIndex1);
1031                 phi1Phy = 0.5 * (binEdges.second + binEdges.first);
1032                 eta1Phy = 0.;  //No Eta for Energy Sums
1033 
1034                 etBin1 = etIndex1;
1035                 int ssize = m_gtScales->getHTMScales().etBins.size();
1036                 assert(ssize > 0);
1037                 if (etBin1 >= ssize) {
1038                   etBin1 = ssize - 1;
1039                 }
1040 
1041                 binEdges = m_gtScales->getHTMScales().etBins.at(etBin1);
1042                 et1Phy = 0.5 * (binEdges.second + binEdges.first);
1043               } else if (cndObjTypeVec[1] == gtETMHF) {
1044                 std::pair<double, double> binEdges = m_gtScales->getETMHFScales().phiBins.at(phiIndex1);
1045                 phi1Phy = 0.5 * (binEdges.second + binEdges.first);
1046                 eta1Phy = 0.;  //No Eta for Energy Sums
1047                 etBin1 = etIndex1;
1048                 int ssize = m_gtScales->getETMHFScales().etBins.size();
1049                 assert(ssize > 0);
1050                 if (etBin1 >= ssize) {
1051                   etBin1 = ssize - 1;
1052                 }
1053                 binEdges = m_gtScales->getETMHFScales().etBins.at(etBin1);
1054                 et1Phy = 0.5 * (binEdges.second + binEdges.first);
1055               }
1056 
1057               phiORIndex1 = phiIndex1;
1058               etaORIndex1 = etaIndex1;
1059 
1060               //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
1061               if (convertCaloScales) {
1062                 std::string lutName = lutObj1;
1063                 lutName += "-MU";
1064                 long long tst = m_gtScales->getLUT_CalMuPhi(lutName, phiIndex1);
1065                 LogDebug("L1TGlobal") << lutName << "  PhiCal = " << phiIndex1 << " PhiMu = " << tst << std::endl;
1066                 phiIndex1 = tst;
1067               }
1068 
1069               //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
1070               if (convertCaloScalesForOverlapRemovalFromLeg1) {
1071                 phiORIndex1 = phiIndex1;
1072               }
1073 
1074             }  //check it is the EtSum we want
1075           }    // loop over Etsums
1076 
1077         }  // end case EnergySum
1078         break;
1079         default: {
1080           // should not arrive here, there are no correlation conditions defined for this object
1081           LogDebug("L1TGlobal") << "Error could not find the Cond Category for Leg 0" << std::endl;
1082           return false;
1083         } break;
1084       }  //end switch on second leg
1085 
1086       if (m_verbosity) {
1087         LogDebug("L1TGlobal") << "    Correlation pair [" << l1t::GlobalObjectEnumToString(cndObjTypeVec[0]) << ", "
1088                               << l1t::GlobalObjectEnumToString(cndObjTypeVec[1]) << "] with collection indices ["
1089                               << obj0Index << ", " << obj1Index << "] "
1090                               << " has: \n"
1091                               << "     Et  value   = [" << etIndex0 << ", " << etIndex1 << "]\n"
1092                               << "     phi indices = [" << phiIndex0 << ", " << phiIndex1 << "]\n"
1093                               << "     eta indices = [" << etaIndex0 << ", " << etaIndex1 << "]\n"
1094                               << "     chrg        = [" << chrg0 << ", " << chrg1 << "]\n";
1095       }
1096 
1097       // Now perform the desired correlation on these two objects. Assume true until we find a contradition
1098       bool reqResult = true;
1099 
1100       // if we get here all checks were successful for this combination
1101       // set the general result for evaluateCondition to "true"
1102 
1103       // These all require some delta eta and phi calculations.  Do them first...for now real calculation but need to
1104       // revise this to line up with firmware calculations.
1105       double deltaPhiPhy = fabs(phi1Phy - phi0Phy);
1106       if (deltaPhiPhy > M_PI)
1107         deltaPhiPhy = 2. * M_PI - deltaPhiPhy;
1108       double deltaEtaPhy = fabs(eta1Phy - eta0Phy);
1109 
1110       // Determine the integer based delta eta and delta phi
1111       int deltaPhiFW = abs(phiIndex0 - phiIndex1);
1112       if (deltaPhiFW >= phiBound)
1113         deltaPhiFW = 2 * phiBound - deltaPhiFW;
1114       std::string lutName = lutObj0;
1115       lutName += "-";
1116       lutName += lutObj1;
1117       long long deltaPhiLUT = m_gtScales->getLUT_DeltaPhi(lutName, deltaPhiFW);
1118       unsigned int precDeltaPhiLUT = m_gtScales->getPrec_DeltaPhi(lutName);
1119 
1120       int deltaEtaFW = abs(etaIndex0 - etaIndex1);
1121       long long deltaEtaLUT = 0;
1122       unsigned int precDeltaEtaLUT = 0;
1123       if (!etSumCond) {
1124         deltaEtaLUT = m_gtScales->getLUT_DeltaEta(lutName, deltaEtaFW);
1125         precDeltaEtaLUT = m_gtScales->getPrec_DeltaEta(lutName);
1126       }
1127 
1128       //
1129       LogDebug("L1TGlobal") << "Obj0 phiFW = " << phiIndex0 << " Obj1 phiFW = " << phiIndex1 << "\n"
1130                             << "    DeltaPhiFW = " << deltaPhiFW << "\n"
1131                             << "    LUT Name = " << lutName << " Prec = " << precDeltaPhiLUT
1132                             << "  DeltaPhiLUT = " << deltaPhiLUT << "\n"
1133                             << "Obj0 etaFW = " << etaIndex0 << " Obj1 etaFW = " << etaIndex1 << "\n"
1134                             << "    DeltaEtaFW = " << deltaEtaFW << "\n"
1135                             << "    LUT Name = " << lutName << " Prec = " << precDeltaEtaLUT
1136                             << "  DeltaEtaLUT = " << deltaEtaLUT << std::endl;
1137 
1138       // If there is a delta eta, check it.
1139       if (corrPar.corrCutType & 0x1) {
1140         unsigned int preShift = precDeltaEtaLUT - corrPar.precEtaCut;
1141         LogDebug("L1TGlobal") << "    Testing Delta Eta Cut (" << lutObj0 << "," << lutObj1 << ") ["
1142                               << (long long)(corrPar.minEtaCutValue * pow(10, preShift)) << ","
1143                               << (long long)(corrPar.maxEtaCutValue * pow(10, preShift))
1144                               << "] with precision = " << corrPar.precEtaCut << "\n"
1145                               << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1146                               << "    Precision Shift = " << preShift << "\n"
1147                               << "    deltaEta (shift)= " << (deltaEtaLUT / pow(10, preShift + corrPar.precEtaCut))
1148                               << "\n"
1149                               << "    deltaEtaPhy = " << deltaEtaPhy << std::endl;
1150 
1151         //if(preShift>0) deltaEtaLUT /= pow(10,preShift);
1152         if (deltaEtaLUT >= (long long)(corrPar.minEtaCutValue * pow(10, preShift)) &&
1153             deltaEtaLUT <= (long long)(corrPar.maxEtaCutValue * pow(10, preShift))) {
1154           LogDebug("L1TGlobal") << "    Passed Delta Eta Cut ["
1155                                 << (long long)(corrPar.minEtaCutValue * pow(10, preShift)) << ","
1156                                 << (long long)(corrPar.maxEtaCutValue * pow(10, preShift)) << "]" << std::endl;
1157 
1158         } else {
1159           LogDebug("L1TGlobal") << "    Failed Delta Eta Cut ["
1160                                 << (long long)(corrPar.minEtaCutValue * pow(10, preShift)) << ","
1161                                 << (long long)(corrPar.maxEtaCutValue * pow(10, preShift)) << "]" << std::endl;
1162           reqResult = false;
1163         }
1164       }
1165 
1166       //if there is a delta phi check it.
1167       if (corrPar.corrCutType & 0x2) {
1168         unsigned int preShift = precDeltaPhiLUT - corrPar.precPhiCut;
1169         LogDebug("L1TGlobal") << "    Testing Delta Phi Cut (" << lutObj0 << "," << lutObj1 << ") ["
1170                               << (long long)(corrPar.minPhiCutValue * pow(10, preShift)) << ","
1171                               << (long long)(corrPar.maxPhiCutValue * pow(10, preShift))
1172                               << "] with precision = " << corrPar.precPhiCut << "\n"
1173                               << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1174                               << "    Precision Shift = " << preShift << "\n"
1175                               << "    deltaPhi (shift)= " << (deltaPhiLUT / pow(10, preShift + corrPar.precPhiCut))
1176                               << "\n"
1177                               << "    deltaPhiPhy = " << deltaPhiPhy << std::endl;
1178 
1179         //if(preShift>0) deltaPhiLUT /= pow(10,preShift);
1180         if (deltaPhiLUT >= (long long)(corrPar.minPhiCutValue * pow(10, preShift)) &&
1181             deltaPhiLUT <= (long long)(corrPar.maxPhiCutValue * pow(10, preShift))) {
1182           LogDebug("L1TGlobal") << "    Passed Delta Phi Cut ["
1183                                 << (long long)(corrPar.minPhiCutValue * pow(10, preShift)) << ","
1184                                 << (long long)(corrPar.maxPhiCutValue * pow(10, preShift)) << "]" << std::endl;
1185 
1186         } else {
1187           LogDebug("L1TGlobal") << "    Failed Delta Phi Cut ["
1188                                 << (long long)(corrPar.minPhiCutValue * pow(10, preShift)) << ","
1189                                 << (long long)(corrPar.maxPhiCutValue * pow(10, preShift)) << "]" << std::endl;
1190           reqResult = false;
1191         }
1192       }
1193 
1194       if (corrPar.corrCutType & 0x4) {
1195         //Assumes Delta Eta and Delta Phi LUTs have the same precision
1196         unsigned int preShift = 2 * precDeltaPhiLUT - corrPar.precDRCut;
1197         double deltaRSqPhy = deltaPhiPhy * deltaPhiPhy + deltaEtaPhy * deltaEtaPhy;
1198         long long deltaRSq = deltaEtaLUT * deltaEtaLUT + deltaPhiLUT * deltaPhiLUT;
1199 
1200         LogDebug("L1TGlobal") << "    Testing Delta R Cut (" << lutObj0 << "," << lutObj1 << ") ["
1201                               << (long long)(corrPar.minDRCutValue * pow(10, preShift)) << ","
1202                               << (long long)(corrPar.maxDRCutValue * pow(10, preShift))
1203                               << "] with precision = " << corrPar.precDRCut << "\n"
1204                               << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1205                               << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1206                               << "    deltaRSqLUT = " << deltaRSq << "\n"
1207                               << "    Precision Shift = " << preShift << "\n"
1208                               << "    deltaRSqLUT (shift)= " << (deltaRSq / pow(10, preShift + corrPar.precDRCut))
1209                               << "\n"
1210                               << "    deltaRSqPhy = " << deltaRSqPhy << std::endl;
1211 
1212         //if(preShift>0) deltaRSq /= pow(10,preShift);
1213         if (deltaRSq >= (long long)(corrPar.minDRCutValue * pow(10, preShift)) &&
1214             deltaRSq <= (long long)(corrPar.maxDRCutValue * pow(10, preShift))) {
1215           LogDebug("L1TGlobal") << "    Passed Delta R Cut [" << (long long)(corrPar.minDRCutValue * pow(10, preShift))
1216                                 << "," << (long long)(corrPar.maxDRCutValue * pow(10, preShift)) << "]" << std::endl;
1217 
1218         } else {
1219           LogDebug("L1TGlobal") << "    Failed Delta R Cut [" << (int)(corrPar.minDRCutValue * pow(10, preShift)) << ","
1220                                 << (long long)(corrPar.maxDRCutValue * pow(10, preShift)) << "]" << std::endl;
1221           reqResult = false;
1222         }
1223       }
1224 
1225       if (corrPar.corrCutType & 0x20) {
1226         // Two body pt: pt^2 = pt1^2+pt2^2+2*pt1*pt2*(cos(phi1)*cos(phi2)+sin(phi1)*sin(phi2)).
1227 
1228         LogDebug("L1TGlobal") << " corrPar.corrCutType: " << corrPar.corrCutType << "\n";
1229 
1230         //calculate math sins and cosines for debugging
1231         double cosPhi1Phy = cos(phi0Phy);
1232         double sinPhi1Phy = sin(phi0Phy);
1233         double cosPhi2Phy = cos(phi1Phy);
1234         double sinPhi2Phy = sin(phi1Phy);
1235 
1236         double tbptSqPhy = et0Phy * et0Phy + et1Phy * et1Phy +
1237                            2 * et0Phy * et1Phy * (cosPhi1Phy * cosPhi2Phy + sinPhi1Phy * sinPhi2Phy);
1238         // get values from LUT's
1239 
1240         const std::string& lutName0 = lutObj0;
1241         unsigned int precCosLUT0 = m_gtScales->getPrec_Cos(lutName0);
1242         unsigned int precSinLUT0 = m_gtScales->getPrec_Sin(lutName0);
1243 
1244         const std::string& lutName1 = lutObj1;
1245         unsigned int precCosLUT1 = m_gtScales->getPrec_Cos(lutName1);
1246         unsigned int precSinLUT1 = m_gtScales->getPrec_Sin(lutName1);
1247 
1248         if (precCosLUT0 - precCosLUT1 != 0)
1249           LogDebug("L1TGlobal") << "Warning: Cos LUTs for TwoBodyPt on different Precision" << std::endl;
1250         if (precSinLUT0 - precSinLUT1 != 0)
1251           LogDebug("L1TGlobal") << "Warning: Sin LUTs for TwoBodyPt on different Precision" << std::endl;
1252         if (precSinLUT0 - precCosLUT1 != 0)
1253           LogDebug("L1TGlobal") << "Warning: Sin and Cos LUTs for TwoBodyPt on different Precision" << std::endl;
1254         if (precSinLUT1 - precCosLUT0 != 0)
1255           LogDebug("L1TGlobal") << "Warning: Sin and Cos LUTs for TwoBodyPt on different Precision" << std::endl;
1256 
1257         long long cosPhi1LUT = m_gtScales->getLUT_Cos(lutName0, phiIndex0);
1258         long long sinPhi1LUT = m_gtScales->getLUT_Sin(lutName0, phiIndex0);
1259 
1260         long long cosPhi2LUT = m_gtScales->getLUT_Cos(lutName1, phiIndex1);
1261         long long sinPhi2LUT = m_gtScales->getLUT_Sin(lutName1, phiIndex1);
1262 
1263         // now get pt LUTs
1264         std::string lutName = lutObj0;
1265         lutName += "-ET";
1266         long long ptObj0 = m_gtScales->getLUT_Pt("TwoBody_" + lutName, etIndex0);
1267         unsigned int precPtLUTObj0 = m_gtScales->getPrec_Pt("TwoBody_" + lutName);
1268 
1269         lutName = lutObj1;
1270         lutName += "-ET";
1271         long long ptObj1 = m_gtScales->getLUT_Pt("TwoBody_" + lutName, etIndex1);
1272         unsigned int precPtLUTObj1 = m_gtScales->getPrec_Pt("TwoBody_" + lutName);
1273 
1274         LogTrace("L1TGlobal") << " TBPT Trig precisions:\t " << precCosLUT0 << "\t" << precCosLUT1 << "\t"
1275                               << precSinLUT0 << "\t" << precSinLUT1;
1276         LogTrace("L1TGlobal") << " TBPT Pt precisions:\t " << precPtLUTObj0 << "\t" << precPtLUTObj1;
1277         LogTrace("L1TGlobal") << " TBPT Pt cut:\t " << corrPar.minTBPTCutValue << "\tPrecTBPTCut\t"
1278                               << corrPar.precTBPTCut;
1279         LogTrace("L1TGlobal") << " TBPT Pt1*Pt1 -- Phys:\t " << et0Phy * et0Phy << "\tHW:\t"
1280                               << ptObj0 * ptObj0 * (pow(10, 6));
1281         LogTrace("L1TGlobal") << " TBPT Pt2*Pt2 -- Phys:\t " << et1Phy * et1Phy << "\tHW:\t"
1282                               << ptObj1 * ptObj1 * (pow(10, 6));
1283         LogTrace("L1TGlobal") << " TBPT 2Pt1*Pt2 -- Phys:\t " << 2 * et0Phy * et1Phy << "\tHW:\t"
1284                               << 2 * (ptObj0 * pow(10, 0)) * (ptObj1 * pow(10, 0));
1285         LogTrace("L1TGlobal") << " TBPT Trig -- Phys:\t " << cosPhi1Phy * cosPhi2Phy + sinPhi1Phy * sinPhi2Phy
1286                               << "\tHW:\t" << cosPhi1LUT * cosPhi2LUT + sinPhi1LUT * sinPhi2LUT;
1287 
1288         //double tbptSqPhy =   et0Phy*et0Phy             + et1Phy*et1Phy + 2*et0Phy*et1Phy*(cosPhi1Phy*cosPhi2Phy + sinPhi1Phy*sinPhi2Phy);
1289         long long tbptSqHW = ptObj0 * ptObj0 * (pow(10, 2 * precCosLUT0)) +
1290                              ptObj1 * ptObj1 * (pow(10, 2 * precCosLUT0)) +
1291                              2 * ptObj0 * ptObj1 * (cosPhi1LUT * cosPhi2LUT + sinPhi1LUT * sinPhi2LUT);
1292 
1293         unsigned int preShift = precPtLUTObj0 + precPtLUTObj1 + 2 * precCosLUT0;
1294 
1295         LogTrace("L1TGlobal") << "TBPT Result -- Phys: " << tbptSqPhy << "\tHW: " << tbptSqHW << "\tShifted\t"
1296                               << tbptSqHW / pow(10, preShift) << std::endl;
1297 
1298         preShift = preShift - corrPar.precTBPTCut;
1299 
1300         LogDebug("L1TGlobal")
1301             << "    Testing Two Body Pt Cut (" << lutObj0 << "," << lutObj1 << ") ["
1302             << (long long)(corrPar.minTBPTCutValue * pow(10, preShift)) << ","
1303             << (long long)(corrPar.maxTBPTCutValue * pow(10, preShift)) << "] with precision = " << corrPar.precTBPTCut
1304             << "\n"
1305             << "    etIndex0     = " << etIndex0 << "    pt0LUT      = " << ptObj0 << " PhyEt0 = " << et0Phy << "\n"
1306             << "    etIndex1     = " << etIndex1 << "    pt1LUT      = " << ptObj1 << " PhyEt1 = " << et1Phy << "\n"
1307             << "    Precision Shift = " << preShift << "\n"
1308             << "    Sin(phi1): LUT/Phys\t " << sinPhi1LUT << " / " << sinPhi1Phy << "\n"
1309             << "    Sin(phi2): LUT/Phys\t " << sinPhi2LUT << " / " << sinPhi2Phy << "\n"
1310             << "    Cos(phi1): LUT/Phys\t " << cosPhi1LUT << " / " << cosPhi1Phy << "\n"
1311             << "    Cos(phi2): LUT/Phys\t " << cosPhi2LUT << " / " << cosPhi2Phy
1312             << "\n"
1313 
1314             //    << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1315             //    << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1316             //    << "    deltaRSqLUT = " << deltaRSq <<  "\n"
1317             //    << "    Precision Shift = " << preShift << "\n"
1318             //    << "    deltaRSqLUT (shift)= " << (deltaRSq/pow(10,preShift+corrPar.precDRCut)) << "\n"
1319             //    << "    deltaRSqPhy = " << deltaRSqPhy
1320             << std::endl;
1321 
1322         if (tbptSqHW > 0. && tbptSqHW >= (long long)(corrPar.minTBPTCutValue * pow(10, preShift))) {
1323           LogDebug("L1TGlobal") << "    Passed Two Body pT Cut ["
1324                                 << (long long)(corrPar.minTBPTCutValue * pow(10, preShift)) << "]"
1325                                 << "\twith value: " << tbptSqHW << "\n"
1326                                 << "\tPhysics Cut[" << corrPar.minTBPTCutValue / pow(10, corrPar.precTBPTCut)
1327                                 << "]\tPhysics Value: " << tbptSqPhy << std::endl;
1328 
1329         } else {
1330           LogDebug("L1TGlobal") << "    Failed Two Body pT Cut ["
1331                                 << (long long)(corrPar.minTBPTCutValue * pow(10, preShift)) << "]"
1332                                 << "\t with value: " << tbptSqHW << "\n"
1333                                 << "\tPhysics Cut[" << corrPar.minTBPTCutValue / pow(10, corrPar.precTBPTCut)
1334                                 << "]\tPhysics Value: " << tbptSqPhy << std::endl;
1335           reqResult = false;
1336         }
1337       }
1338 
1339       if (corrPar.corrCutType & 0x8 || corrPar.corrCutType & 0x10) {
1340         //invariant mass calculation based on
1341         // M = sqrt(2*p1*p2(cosh(eta1-eta2) - cos(phi1 - phi2)))
1342         // but we calculate (1/2)M^2
1343         //
1344         double cosDeltaPhiPhy = cos(deltaPhiPhy);
1345         double coshDeltaEtaPhy = cosh(deltaEtaPhy);
1346         if (corrPar.corrCutType & 0x10)
1347           coshDeltaEtaPhy = 1.;
1348         double massSqPhy = et0Phy * et1Phy * (coshDeltaEtaPhy - cosDeltaPhiPhy);
1349 
1350         long long cosDeltaPhiLUT = m_gtScales->getLUT_DeltaPhi_Cos(lutName, deltaPhiFW);
1351         unsigned int precCosLUT = m_gtScales->getPrec_DeltaPhi_Cos(lutName);
1352 
1353         long long coshDeltaEtaLUT;
1354         if (corrPar.corrCutType & 0x10) {
1355           coshDeltaEtaLUT = 1 * pow(10, precCosLUT);
1356         } else {
1357           coshDeltaEtaLUT = m_gtScales->getLUT_DeltaEta_Cosh(lutName, deltaEtaFW);
1358           unsigned int precCoshLUT = m_gtScales->getPrec_DeltaEta_Cosh(lutName);
1359           if (precCoshLUT - precCosLUT != 0)
1360             LogDebug("L1TGlobal") << "Warning: Cos and Cosh LUTs on different Precision" << std::endl;
1361         }
1362 
1363         std::string lutName = lutObj0;
1364         lutName += "-ET";
1365         long long ptObj0 = m_gtScales->getLUT_Pt("Mass_" + lutName, etIndex0);
1366         unsigned int precPtLUTObj0 = m_gtScales->getPrec_Pt("Mass_" + lutName);
1367 
1368         lutName = lutObj1;
1369         lutName += "-ET";
1370         long long ptObj1 = m_gtScales->getLUT_Pt("Mass_" + lutName, etIndex1);
1371         unsigned int precPtLUTObj1 = m_gtScales->getPrec_Pt("Mass_" + lutName);
1372 
1373         // Pt and Angles are at different precission.
1374         long long massSq = ptObj0 * ptObj1 * (coshDeltaEtaLUT - cosDeltaPhiLUT);
1375 
1376         //Note: There is an assumption here that Cos and Cosh have the same precission
1377         unsigned int preShift = precPtLUTObj0 + precPtLUTObj1 + precCosLUT - corrPar.precMassCut;
1378 
1379         LogDebug("L1TGlobal") << "    Testing Invariant Mass (" << lutObj0 << "," << lutObj1 << ") ["
1380                               << (long long)(corrPar.minMassCutValue * pow(10, preShift)) << ","
1381                               << (long long)(corrPar.maxMassCutValue * pow(10, preShift))
1382                               << "] with precision = " << corrPar.precMassCut << "\n"
1383                               << "    deltaPhiLUT  = " << deltaPhiLUT << "  cosLUT  = " << cosDeltaPhiLUT << "\n"
1384                               << "    deltaEtaLUT  = " << deltaEtaLUT << "  coshLUT = " << coshDeltaEtaLUT << "\n"
1385                               << "    etIndex0     = " << etIndex0 << "    pt0LUT      = " << ptObj0
1386                               << " PhyEt0 = " << et0Phy << "\n"
1387                               << "    etIndex1     = " << etIndex1 << "    pt1LUT      = " << ptObj1
1388                               << " PhyEt1 = " << et1Phy << "\n"
1389                               << "    massSq/2     = " << massSq << "\n"
1390                               << "    Precision Shift = " << preShift << "\n"
1391                               << "    massSq   (shift)= " << (massSq / pow(10, preShift + corrPar.precMassCut)) << "\n"
1392                               << "    deltaPhiPhy  = " << deltaPhiPhy << "  cos() = " << cosDeltaPhiPhy << "\n"
1393                               << "    deltaEtaPhy  = " << deltaEtaPhy << "  cosh()= " << coshDeltaEtaPhy << "\n"
1394                               << "    massSqPhy/2  = " << massSqPhy
1395                               << "  sqrt(|massSq|) = " << sqrt(fabs(2. * massSqPhy)) << std::endl;
1396 
1397         //if(preShift>0) massSq /= pow(10,preShift);
1398         if (massSq >= 0 && massSq >= (long long)(corrPar.minMassCutValue * pow(10, preShift)) &&
1399             massSq <= (long long)(corrPar.maxMassCutValue * pow(10, preShift))) {
1400           LogDebug("L1TGlobal") << "    Passed Invariant Mass Cut ["
1401                                 << (long long)(corrPar.minMassCutValue * pow(10, preShift)) << ","
1402                                 << (long long)(corrPar.maxMassCutValue * pow(10, preShift)) << "]" << std::endl;
1403 
1404         } else {
1405           LogDebug("L1TGlobal") << "    Failed Invariant Mass Cut ["
1406                                 << (long long)(corrPar.minMassCutValue * pow(10, preShift)) << ","
1407                                 << (long long)(corrPar.maxMassCutValue * pow(10, preShift)) << "]" << std::endl;
1408           reqResult = false;
1409         }
1410       }
1411 
1412       // For Muon-Muon Correlation Check the Charge Correlation if requested
1413       bool chrgCorrel = true;
1414       if (cond0Categ == CondMuon && cond1Categ == CondMuon) {
1415         // Check for like-sign
1416         if (corrPar.chargeCorrelation == 2 && chrg0 != chrg1)
1417           chrgCorrel = false;
1418         // Check for opp-sign
1419         if (corrPar.chargeCorrelation == 4 && chrg0 == chrg1)
1420           chrgCorrel = false;
1421       }
1422 
1423       if (!reqResult || !chrgCorrel)
1424         continue;
1425 
1426       // ///////////////////////////////////////////////////////////////////////////////////////////
1427       // loop over overlap-removal leg combination which produced individually "true" as Type1s
1428       // ///////////////////////////////////////////////////////////////////////////////////////////
1429       for (std::vector<SingleCombInCond>::const_iterator it2Comb = cond2Comb.begin(); it2Comb != cond2Comb.end();
1430            it2Comb++) {
1431         // Type1s: there is 1 object only, no need for a loop, index 0 should be OK in (*it2Comb)[0]
1432         // ... but add protection to not crash
1433         int obj2Index = -1;
1434 
1435         if (!(*it2Comb).empty()) {
1436           obj2Index = (*it2Comb)[0];
1437         } else {
1438           LogTrace("L1TGlobal") << "\n  SingleCombInCond (*it2Comb).size() " << ((*it2Comb).size()) << std::endl;
1439           return false;
1440         }
1441 
1442         // Collect the information on the overlap-removal leg
1443         switch (cond2Categ) {
1444           case CondMuon: {
1445             lutObj2 = "MU";
1446             candMuVec = m_uGtB->getCandL1Mu();
1447             phiIndex2 = (candMuVec->at(cond2bx, obj2Index))->hwPhi();  //(*candMuVec)[obj2Index]->phiIndex();
1448             etaIndex2 = (candMuVec->at(cond2bx, obj2Index))->hwEta();
1449             int etaBin2 = etaIndex2;
1450             if (etaBin2 < 0)
1451               etaBin2 = m_gtScales->getMUScales().etaBins.size() + etaBin2;  //twos complement
1452             //LogDebug("L1TGlobal") << "Muon phi" << phiIndex2 << " eta " << etaIndex2 << " etaBin2 = " << etaBin2  << " et " << etIndex2 << std::endl;
1453 
1454             // Determine Floating Pt numbers for floating point caluclation
1455             std::pair<double, double> binEdges = m_gtScales->getMUScales().phiBins.at(phiIndex2);
1456             phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1457             binEdges = m_gtScales->getMUScales().etaBins.at(etaBin2);
1458             eta2Phy = 0.5 * (binEdges.second + binEdges.first);
1459 
1460             LogDebug("L1TGlobal") << "Found all quantities for the muon 0" << std::endl;
1461           } break;
1462 
1463           // Calorimeter Objects (EG, Jet, Tau)
1464           case CondCalo: {
1465             switch (cndObjTypeVec[2]) {
1466               case gtEG: {
1467                 lutObj2 = "EG";
1468                 candCaloVec = m_uGtB->getCandL1EG();
1469                 phiIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwPhi();
1470                 etaIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwEta();
1471                 if (etaBin2 < 0)
1472                   etaBin2 = m_gtScales->getEGScales().etaBins.size() + etaBin2;
1473                 //LogDebug("L1TGlobal") << "EG0 phi" << phiIndex2 << " eta " << etaIndex2 << " etaBin2 = " << etaBin2 << " et " << etIndex2 << std::endl;
1474 
1475                 // Determine Floating Pt numbers for floating point caluclation
1476                 std::pair<double, double> binEdges = m_gtScales->getEGScales().phiBins.at(phiIndex2);
1477                 phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1478                 binEdges = m_gtScales->getEGScales().etaBins.at(etaBin2);
1479                 eta2Phy = 0.5 * (binEdges.second + binEdges.first);
1480               } break;
1481 
1482               case gtJet: {
1483                 lutObj2 = "JET";
1484                 candCaloVec = m_uGtB->getCandL1Jet();
1485                 phiIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwPhi();
1486                 etaIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwEta();
1487                 etaBin2 = etaIndex2;
1488                 if (etaBin2 < 0)
1489                   etaBin2 = m_gtScales->getJETScales().etaBins.size() + etaBin2;
1490                 // Determine Floating Pt numbers for floating point caluclation
1491                 std::pair<double, double> binEdges = m_gtScales->getJETScales().phiBins.at(phiIndex2);
1492                 phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1493                 binEdges = m_gtScales->getJETScales().etaBins.at(etaBin2);
1494                 eta2Phy = 0.5 * (binEdges.second + binEdges.first);
1495               } break;
1496               case gtTau: {
1497                 candCaloVec = m_uGtB->getCandL1Tau();
1498                 phiIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwPhi();
1499                 etaIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwEta();
1500                 if (etaBin2 < 0)
1501                   etaBin2 = m_gtScales->getTAUScales().etaBins.size() + etaBin2;
1502 
1503                 // Determine Floating Pt numbers for floating point caluclation
1504                 std::pair<double, double> binEdges = m_gtScales->getTAUScales().phiBins.at(phiIndex2);
1505                 phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1506                 binEdges = m_gtScales->getTAUScales().etaBins.at(etaBin2);
1507                 eta2Phy = 0.5 * (binEdges.second + binEdges.first);
1508                 lutObj2 = "TAU";
1509               } break;
1510               default: {
1511               } break;
1512             }  //end switch on calo type.
1513 
1514             //If needed convert calo scales to muon scales for comparison
1515             if (convertCaloScales) {
1516               std::string lutName = lutObj2;
1517               lutName += "-MU";
1518               long long tst = m_gtScales->getLUT_CalMuEta(lutName, etaBin2);
1519               LogDebug("L1TGlobal") << lutName << "  EtaCal = " << etaIndex2 << " etaBin2 = " << etaBin2
1520                                     << " EtaMu = " << tst << std::endl;
1521               etaIndex2 = tst;
1522 
1523               tst = m_gtScales->getLUT_CalMuPhi(lutName, phiIndex2);
1524               LogDebug("L1TGlobal") << lutName << "  PhiCal = " << phiIndex2 << " PhiMu = " << tst << std::endl;
1525               phiIndex2 = tst;
1526             }
1527 
1528           } break;
1529 
1530           // Energy Sums
1531           case CondEnergySum: {
1532             etSumCond = true;
1533             //Stupid mapping between enum types for energy sums.
1534             l1t::EtSum::EtSumType type;
1535             switch (cndObjTypeVec[2]) {
1536               case gtETM:
1537                 type = l1t::EtSum::EtSumType::kMissingEt;
1538                 lutObj2 = "ETM";
1539                 break;
1540               case gtETT:
1541                 type = l1t::EtSum::EtSumType::kTotalEt;
1542                 lutObj2 = "ETT";
1543                 break;
1544               case gtETTem:
1545                 type = l1t::EtSum::EtSumType::kTotalEtEm;
1546                 lutObj2 =
1547                     "ETTem";  //should this be just ETT (share LUTs?) Can't be used for CorrCond anyway since now directional information
1548                 break;
1549               case gtHTM:
1550                 type = l1t::EtSum::EtSumType::kMissingHt;
1551                 lutObj2 = "HTM";
1552                 break;
1553               case gtHTT:
1554                 type = l1t::EtSum::EtSumType::kTotalHt;
1555                 lutObj2 = "HTT";
1556                 break;
1557               case gtETMHF:
1558                 type = l1t::EtSum::EtSumType::kMissingEtHF;
1559                 lutObj2 = "ETMHF";
1560                 break;
1561               case gtMinBiasHFP0:
1562               case gtMinBiasHFM0:
1563               case gtMinBiasHFP1:
1564               case gtMinBiasHFM1:
1565                 type = l1t::EtSum::EtSumType::kMinBiasHFP0;
1566                 lutObj2 =
1567                     "MinBias";  //??Fix?? Not a valid LUT type Can't be used for CorrCond anyway since now directional information
1568                 break;
1569               default:
1570                 edm::LogError("L1TGlobal")
1571                     << "\n  Error: "
1572                     << "Unmatched object type from template to EtSumType, cndObjTypeVec[2] = " << cndObjTypeVec[2]
1573                     << std::endl;
1574                 type = l1t::EtSum::EtSumType::kTotalEt;
1575                 break;
1576             }
1577 
1578             candEtSumVec = m_uGtB->getCandL1EtSum();
1579 
1580             for (int iEtSum = 0; iEtSum < (int)candEtSumVec->size(cond2bx); iEtSum++) {
1581               if ((candEtSumVec->at(cond2bx, iEtSum))->getType() == type) {
1582                 phiIndex2 = (candEtSumVec->at(cond2bx, iEtSum))->hwPhi();
1583                 etaIndex2 = (candEtSumVec->at(cond2bx, iEtSum))->hwEta();
1584 
1585                 //  Get the floating point numbers
1586                 if (cndObjTypeVec[2] == gtETM) {
1587                   std::pair<double, double> binEdges = m_gtScales->getETMScales().phiBins.at(phiIndex2);
1588                   phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1589                   eta2Phy = 0.;  //No Eta for Energy Sums
1590 
1591                 } else if (cndObjTypeVec[2] == gtHTM) {
1592                   std::pair<double, double> binEdges = m_gtScales->getHTMScales().phiBins.at(phiIndex2);
1593                   phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1594                   eta2Phy = 0.;  //No Eta for Energy Sums
1595 
1596                 } else if (cndObjTypeVec[2] == gtETMHF) {
1597                   std::pair<double, double> binEdges = m_gtScales->getETMHFScales().phiBins.at(phiIndex2);
1598                   phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1599                   eta2Phy = 0.;  //No Eta for Energy Sums
1600                 }
1601 
1602                 //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
1603                 if (convertCaloScales) {
1604                   std::string lutName = lutObj2;
1605                   lutName += "-MU";
1606                   long long tst = m_gtScales->getLUT_CalMuPhi(lutName, phiIndex2);
1607                   LogDebug("L1TGlobal") << lutName << "  PhiCal = " << phiIndex2 << " PhiMu = " << tst << std::endl;
1608                   phiIndex2 = tst;
1609                 }
1610 
1611               }  //check it is the EtSum we want
1612             }    // loop over Etsums
1613 
1614           }  // end case CondEnerySum
1615           break;
1616           default: {
1617             // should not arrive here, there are no correlation conditions defined for this object
1618             LogDebug("L1TGlobal") << "Error could not find the Cond Category for Leg 3" << std::endl;
1619             return false;
1620           } break;
1621         }  //end switch on overlap-removal leg type
1622 
1623         // /////////////////////////////////////////////////////////////////////////////////////////
1624         //
1625         // here check if there is a match of 1st leg with overlap removal object, and store result
1626         //
1627         // /////////////////////////////////////////////////////////////////////////////////////////
1628         // These all require some delta eta and phi calculations.  Do them first...for now real calculation but need to
1629         // revise this to line up with firmware calculations.
1630         deltaPhiPhy = fabs(phi2Phy - phi0Phy);
1631         if (deltaPhiPhy > M_PI)
1632           deltaPhiPhy = 2. * M_PI - deltaPhiPhy;
1633         deltaEtaPhy = fabs(eta2Phy - eta0Phy);
1634 
1635         // Deter the integer based delta eta and delta phi
1636         deltaPhiFW = abs(phiORIndex0 - phiIndex2);
1637         if (deltaPhiFW >= phiBound)
1638           deltaPhiFW = 2 * phiBound - deltaPhiFW;
1639         lutName = lutObj0;
1640         lutName += "-";
1641         lutName += lutObj2;
1642         deltaPhiLUT = m_gtScales->getLUT_DeltaPhi(lutName, deltaPhiFW);
1643         precDeltaPhiLUT = m_gtScales->getPrec_DeltaPhi(lutName);
1644 
1645         deltaEtaFW = abs(etaORIndex0 - etaIndex2);
1646         deltaEtaLUT = 0;
1647         precDeltaEtaLUT = 0;
1648         if (!etSumCond) {
1649           deltaEtaLUT = m_gtScales->getLUT_DeltaEta(lutName, deltaEtaFW);
1650           precDeltaEtaLUT = m_gtScales->getPrec_DeltaEta(lutName);
1651         }
1652 
1653         LogDebug("L1TGlobal") << "Obj0 phiFW = " << phiORIndex0 << " Obj2 phiFW = " << phiIndex2 << "\n"
1654                               << "    DeltaPhiFW = " << deltaPhiFW << "\n"
1655                               << "    LUT Name = " << lutName << " Prec = " << precDeltaPhiLUT
1656                               << "  DeltaPhiLUT = " << deltaPhiLUT << "\n"
1657                               << "Obj0 etaFW = " << etaIndex0 << " Obj2 etaFW = " << etaIndex2 << "\n"
1658                               << "    DeltaEtaFW = " << deltaEtaFW << "\n"
1659                               << "    LUT Name = " << lutName << " Prec = " << precDeltaEtaLUT
1660                               << "  DeltaEtaLUT = " << deltaEtaLUT << std::endl;
1661 
1662         // If there is a OverlapRemovalDeltaEta cut, check it.
1663         if (corrPar.corrCutType & 0x10) {
1664           unsigned int preShift = precDeltaEtaLUT - corrPar.precOverlapRemovalEtaCut;
1665           LogDebug("L1TGlobal") << "    Testing Leg1 Overlap Removal Delta Eta Cut (" << lutObj0 << "," << lutObj2
1666                                 << ") [" << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1667                                 << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift))
1668                                 << "] with precision = " << corrPar.precOverlapRemovalEtaCut << "\n"
1669                                 << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1670                                 << "    Precision Shift = " << preShift << "\n"
1671                                 << "    deltaEta (shift)= "
1672                                 << (deltaEtaLUT / pow(10, preShift + corrPar.precOverlapRemovalEtaCut)) << "\n"
1673                                 << "    deltaEtaPhy = " << deltaEtaPhy << std::endl;
1674 
1675           //if(preShift>0) deltaEtaLUT /= pow(10,preShift);
1676           if (deltaEtaLUT >= (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) &&
1677               deltaEtaLUT <= (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift))) {
1678             LogDebug("L1TGlobal") << "    Satified Leg1 Overlap Removal Delta Eta Cut ["
1679                                   << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1680                                   << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift)) << "]"
1681                                   << std::endl;
1682             // next leg3 object
1683             continue;
1684 
1685           } else {
1686             LogDebug("L1TGlobal") << "    Failed Leg1 Overlap Removal Delta Eta Cut ["
1687                                   << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1688                                   << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift)) << "]"
1689                                   << std::endl;
1690           }
1691         }
1692 
1693         //if there is a OverlapRemovalDeltaPhi cut, check it.
1694         if (corrPar.corrCutType & 0x20) {
1695           unsigned int preShift = precDeltaPhiLUT - corrPar.precOverlapRemovalPhiCut;
1696           LogDebug("L1TGlobal") << "    Testing Leg1 Overlap Removal Delta Phi Cut (" << lutObj0 << "," << lutObj2
1697                                 << ") [" << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1698                                 << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift))
1699                                 << "] with precision = " << corrPar.precOverlapRemovalPhiCut << "\n"
1700                                 << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1701                                 << "    Precision Shift = " << preShift << "\n"
1702                                 << "    deltaPhi (shift)= "
1703                                 << (deltaPhiLUT / pow(10, preShift + corrPar.precOverlapRemovalPhiCut)) << "\n"
1704                                 << "    deltaPhiPhy = " << deltaPhiPhy << std::endl;
1705 
1706           //if(preShift>0) deltaPhiLUT /= pow(10,preShift);
1707           if (deltaPhiLUT >= (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) &&
1708               deltaPhiLUT <= (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift))) {
1709             LogDebug("L1TGlobal") << "    Satisfied Leg1 Overlap Removal Delta Phi Cut ["
1710                                   << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1711                                   << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift)) << "]"
1712                                   << std::endl;
1713             // next leg3 object
1714             continue;
1715 
1716           } else {
1717             LogDebug("L1TGlobal") << "    Failed Leg1 Overlap Removal Delta Phi Cut ["
1718                                   << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1719                                   << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift)) << "]"
1720                                   << std::endl;
1721           }
1722         }
1723 
1724         //if there is a OverlapRemovalDeltaR cut, check it.
1725         if (corrPar.corrCutType & 0x40) {
1726           //Assumes Delta Eta and Delta Phi LUTs have the same precision
1727           unsigned int preShift = 2 * precDeltaPhiLUT - corrPar.precOverlapRemovalDRCut;
1728           double deltaRSqPhy = deltaPhiPhy * deltaPhiPhy + deltaEtaPhy * deltaEtaPhy;
1729           long long deltaRSq = deltaEtaLUT * deltaEtaLUT + deltaPhiLUT * deltaPhiLUT;
1730 
1731           LogDebug("L1TGlobal") << "    Testing Leg1 Overlap Removal Delta R Cut (" << lutObj0 << "," << lutObj2
1732                                 << ") [" << (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1733                                 << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift))
1734                                 << "] with precision = " << corrPar.precOverlapRemovalDRCut << "\n"
1735                                 << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1736                                 << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1737                                 << "    deltaRSqLUT = " << deltaRSq << "\n"
1738                                 << "    Precision Shift = " << preShift << "\n"
1739                                 << "    deltaRSqLUT (shift)= " << (deltaRSq / pow(10, preShift + corrPar.precDRCut))
1740                                 << "\n"
1741                                 << "    deltaRSqPhy = " << deltaRSqPhy << std::endl;
1742 
1743           //if(preShift>0) deltaRSq /= pow(10,preShift);
1744           if (deltaRSq >= (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) &&
1745               deltaRSq <= (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift))) {
1746             LogDebug("L1TGlobal") << "    Satified Leg1 Overlap Removal Delta R Cut ["
1747                                   << (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1748                                   << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift)) << "]"
1749                                   << std::endl;
1750             // next leg3 object
1751             continue;
1752 
1753           } else {
1754             LogDebug("L1TGlobal") << "    Failed Leg1 Overlap Removal Delta R Cut ["
1755                                   << (int)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1756                                   << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift)) << "]"
1757                                   << std::endl;
1758           }
1759         }
1760 
1761         // /////////////////////////////////////////////////////////////////////////////////////////
1762         //
1763         // here check if there is a match of 2st leg with overlap removal object ...if yes, continue
1764         //
1765         // /////////////////////////////////////////////////////////////////////////////////////////
1766         // These all require some delta eta and phi calculations.  Do them first...for now real calculation but need to
1767         // revise this to line up with firmware calculations.
1768         deltaPhiPhy = fabs(phi2Phy - phi1Phy);
1769         if (deltaPhiPhy > M_PI)
1770           deltaPhiPhy = 2. * M_PI - deltaPhiPhy;
1771         deltaEtaPhy = fabs(eta2Phy - eta1Phy);
1772 
1773         // Deter the integer based delta eta and delta phi
1774         deltaPhiFW = abs(phiORIndex1 - phiIndex2);
1775         if (deltaPhiFW >= phiBound)
1776           deltaPhiFW = 2 * phiBound - deltaPhiFW;
1777         lutName = lutObj1;
1778         lutName += "-";
1779         lutName += lutObj2;
1780         deltaPhiLUT = m_gtScales->getLUT_DeltaPhi(lutName, deltaPhiFW);
1781         precDeltaPhiLUT = m_gtScales->getPrec_DeltaPhi(lutName);
1782 
1783         deltaEtaFW = abs(etaORIndex1 - etaIndex2);
1784         deltaEtaLUT = 0;
1785         precDeltaEtaLUT = 0;
1786         if (!etSumCond) {
1787           deltaEtaLUT = m_gtScales->getLUT_DeltaEta(lutName, deltaEtaFW);
1788           precDeltaEtaLUT = m_gtScales->getPrec_DeltaEta(lutName);
1789         }
1790 
1791         LogDebug("L1TGlobal") << "Obj1 phiFW = " << phiORIndex1 << " Obj2 phiFW = " << phiIndex2 << "\n"
1792                               << "    DeltaPhiFW = " << deltaPhiFW << "\n"
1793                               << "    LUT Name = " << lutName << " Prec = " << precDeltaPhiLUT
1794                               << "  DeltaPhiLUT = " << deltaPhiLUT << "\n"
1795                               << "Obj1 etaFW = " << etaIndex1 << " Obj1 etaFW = " << etaIndex1 << "\n"
1796                               << "    DeltaEtaFW = " << deltaEtaFW << "\n"
1797                               << "    LUT Name = " << lutName << " Prec = " << precDeltaEtaLUT
1798                               << "  DeltaEtaLUT = " << deltaEtaLUT << std::endl;
1799 
1800         // If there is a OverlapRemovalDeltaEta cut, check it.
1801         // /////////////////////////////////////////////////
1802         if (corrPar.corrCutType & 0x10) {
1803           unsigned int preShift = precDeltaEtaLUT - corrPar.precOverlapRemovalEtaCut;
1804           LogDebug("L1TGlobal") << "    Testing Leg2 Overlap Removal Delta Eta Cut (" << lutObj1 << "," << lutObj2
1805                                 << ") [" << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1806                                 << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift))
1807                                 << "] with precision = " << corrPar.precOverlapRemovalEtaCut << "\n"
1808                                 << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1809                                 << "    Precision Shift = " << preShift << "\n"
1810                                 << "    deltaEta (shift)= "
1811                                 << (deltaEtaLUT / pow(10, preShift + corrPar.precOverlapRemovalEtaCut)) << "\n"
1812                                 << "    deltaEtaPhy = " << deltaEtaPhy << std::endl;
1813 
1814           //if(preShift>0) deltaEtaLUT /= pow(10,preShift);
1815           if (deltaEtaLUT >= (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) &&
1816               deltaEtaLUT <= (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift))) {
1817             LogDebug("L1TGlobal") << "    Satisfied Leg2 Overlap Removal Delta Eta Cut ["
1818                                   << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1819                                   << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift)) << "]"
1820                                   << std::endl;
1821             // next leg3 object
1822             continue;
1823 
1824           } else {
1825             LogDebug("L1TGlobal") << "    Failed Leg2 Overlap Removal Delta Eta Cut ["
1826                                   << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1827                                   << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift)) << "]"
1828                                   << std::endl;
1829           }
1830         }
1831         // If there is a OverlapRemovalDeltaPhi cut, check it.
1832         // /////////////////////////////////////////////////
1833         if (corrPar.corrCutType & 0x20) {
1834           unsigned int preShift = precDeltaPhiLUT - corrPar.precOverlapRemovalPhiCut;
1835           LogDebug("L1TGlobal") << "    Testing Delta Phi Cut (" << lutObj1 << "," << lutObj2 << ") ["
1836                                 << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1837                                 << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift))
1838                                 << "] with precision = " << corrPar.precOverlapRemovalPhiCut << "\n"
1839                                 << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1840                                 << "    Precision Shift = " << preShift << "\n"
1841                                 << "    deltaPhi (shift)= "
1842                                 << (deltaPhiLUT / pow(10, preShift + corrPar.precOverlapRemovalPhiCut)) << "\n"
1843                                 << "    deltaPhiPhy = " << deltaPhiPhy << std::endl;
1844 
1845           //if(preShift>0) deltaPhiLUT /= pow(10,preShift);
1846           if (deltaPhiLUT >= (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) &&
1847               deltaPhiLUT <= (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift))) {
1848             LogDebug("L1TGlobal") << "    Satisfied Leg2 Overlap Removal Delta Phi Cut ["
1849                                   << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1850                                   << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift)) << "]"
1851                                   << std::endl;
1852             // next leg3 object
1853             continue;
1854 
1855           } else {
1856             LogDebug("L1TGlobal") << "    Failed Leg2 Overlap Removal Delta Phi Cut ["
1857                                   << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1858                                   << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift)) << "]"
1859                                   << std::endl;
1860           }
1861         }
1862 
1863         //if there is a OverlapRemovalDeltaR cut, check it.
1864         // /////////////////////////////////////////////////
1865         if (corrPar.corrCutType & 0x40) {
1866           //Assumes Delta Eta and Delta Phi LUTs have the same precision
1867           unsigned int preShift = 2 * precDeltaPhiLUT - corrPar.precOverlapRemovalDRCut;
1868           double deltaRSqPhy = deltaPhiPhy * deltaPhiPhy + deltaEtaPhy * deltaEtaPhy;
1869           long long deltaRSq = deltaEtaLUT * deltaEtaLUT + deltaPhiLUT * deltaPhiLUT;
1870 
1871           LogDebug("L1TGlobal") << "    Testing Leg2 Overlap Removal Delta R Cut (" << lutObj1 << "," << lutObj2
1872                                 << ") [" << (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1873                                 << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift))
1874                                 << "] with precision = " << corrPar.precOverlapRemovalDRCut << "\n"
1875                                 << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1876                                 << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1877                                 << "    deltaRSqLUT = " << deltaRSq << "\n"
1878                                 << "    Precision Shift = " << preShift << "\n"
1879                                 << "    deltaRSqLUT (shift)= " << (deltaRSq / pow(10, preShift + corrPar.precDRCut))
1880                                 << "\n"
1881                                 << "    deltaRSqPhy = " << deltaRSqPhy << std::endl;
1882 
1883           //if(preShift>0) deltaRSq /= pow(10,preShift);
1884           if (deltaRSq >= (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) &&
1885               deltaRSq <= (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift))) {
1886             LogDebug("L1TGlobal") << "    Satisfied Leg2 Overlap Removal Delta R Cut ["
1887                                   << (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1888                                   << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift)) << "]"
1889                                   << std::endl;
1890             // next leg3 object
1891             continue;
1892 
1893           } else {
1894             LogDebug("L1TGlobal") << "    Failed Leg2 Overlap Removal Delta R Cut ["
1895                                   << (int)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1896                                   << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift)) << "]"
1897                                   << std::endl;
1898           }
1899         }
1900 
1901         condResult = true;
1902 
1903         // clear the indices in the combination
1904         objectsInComb.clear();
1905 
1906         objectsInComb.push_back(obj0Index);
1907         objectsInComb.push_back(obj1Index);
1908         objectsInComb.push_back(obj2Index);
1909 
1910         (combinationsInCond()).push_back(objectsInComb);
1911 
1912       }  // end loop over combinations in overlap-removal leg.
1913 
1914     }  //end loop over second leg
1915 
1916   }  //end loop over first leg
1917 
1918   if (m_verbosity && condResult) {
1919     LogDebug("L1TGlobal") << " pass(es) the correlation condition.\n" << std::endl;
1920   }
1921 
1922   return condResult;
1923 }
1924 
1925 // load calo candidates
1926 const l1t::L1Candidate* l1t::CorrWithOverlapRemovalCondition::getCandidate(const int bx, const int indexCand) const {
1927   // objectType() gives the type for nrObjects() only,
1928   // but in a CondCalo all objects have the same type
1929   // take type from the type of the first object
1930   switch ((m_gtCorrelationWithOverlapRemovalTemplate->objectType())[0]) {
1931     case gtEG:
1932       return (m_uGtB->getCandL1EG())->at(bx, indexCand);
1933       break;
1934 
1935     case gtJet:
1936       return (m_uGtB->getCandL1Jet())->at(bx, indexCand);
1937       break;
1938 
1939     case gtTau:
1940       return (m_uGtB->getCandL1Tau())->at(bx, indexCand);
1941       break;
1942     default:
1943       return nullptr;
1944       break;
1945   }
1946 
1947   return nullptr;
1948 }
1949 
1950 /**
1951  * checkObjectParameter - Compare a single particle with a numbered condition.
1952  *
1953  * @param iCondition The number of the condition.
1954  * @param cand The candidate to compare.
1955  *
1956  * @return The result of the comparison (false if a condition does not exist).
1957  */
1958 
1959 const bool l1t::CorrWithOverlapRemovalCondition::checkObjectParameter(const int iCondition,
1960                                                                       const l1t::L1Candidate& cand) const {
1961   return true;
1962 }
1963 
1964 void l1t::CorrWithOverlapRemovalCondition::print(std::ostream& myCout) const {
1965   myCout << "Dummy Print for CorrWithOverlapRemovalCondition" << std::endl;
1966   m_gtCorrelationWithOverlapRemovalTemplate->print(myCout);
1967 
1968   ConditionEvaluation::print(myCout);
1969 }