Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:12:14

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 [" << l1TGtObjectEnumToString(cndObjTypeVec[0]) << ", "
1088                               << l1TGtObjectEnumToString(cndObjTypeVec[1]) << "] with collection indices [" << obj0Index
1089                               << ", " << 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                               << std::endl;
1096       }
1097 
1098       // Now perform the desired correlation on these two objects. Assume true until we find a contradition
1099       bool reqResult = true;
1100 
1101       // if we get here all checks were successful for this combination
1102       // set the general result for evaluateCondition to "true"
1103 
1104       // These all require some delta eta and phi calculations.  Do them first...for now real calculation but need to
1105       // revise this to line up with firmware calculations.
1106       double deltaPhiPhy = fabs(phi1Phy - phi0Phy);
1107       if (deltaPhiPhy > M_PI)
1108         deltaPhiPhy = 2. * M_PI - deltaPhiPhy;
1109       double deltaEtaPhy = fabs(eta1Phy - eta0Phy);
1110 
1111       // Determine the integer based delta eta and delta phi
1112       int deltaPhiFW = abs(phiIndex0 - phiIndex1);
1113       if (deltaPhiFW >= phiBound)
1114         deltaPhiFW = 2 * phiBound - deltaPhiFW;
1115       std::string lutName = lutObj0;
1116       lutName += "-";
1117       lutName += lutObj1;
1118       long long deltaPhiLUT = m_gtScales->getLUT_DeltaPhi(lutName, deltaPhiFW);
1119       unsigned int precDeltaPhiLUT = m_gtScales->getPrec_DeltaPhi(lutName);
1120 
1121       int deltaEtaFW = abs(etaIndex0 - etaIndex1);
1122       long long deltaEtaLUT = 0;
1123       unsigned int precDeltaEtaLUT = 0;
1124       if (!etSumCond) {
1125         deltaEtaLUT = m_gtScales->getLUT_DeltaEta(lutName, deltaEtaFW);
1126         precDeltaEtaLUT = m_gtScales->getPrec_DeltaEta(lutName);
1127       }
1128 
1129       //
1130       LogDebug("L1TGlobal") << "Obj0 phiFW = " << phiIndex0 << " Obj1 phiFW = " << phiIndex1 << "\n"
1131                             << "    DeltaPhiFW = " << deltaPhiFW << "\n"
1132                             << "    LUT Name = " << lutName << " Prec = " << precDeltaPhiLUT
1133                             << "  DeltaPhiLUT = " << deltaPhiLUT << "\n"
1134                             << "Obj0 etaFW = " << etaIndex0 << " Obj1 etaFW = " << etaIndex1 << "\n"
1135                             << "    DeltaEtaFW = " << deltaEtaFW << "\n"
1136                             << "    LUT Name = " << lutName << " Prec = " << precDeltaEtaLUT
1137                             << "  DeltaEtaLUT = " << deltaEtaLUT << std::endl;
1138 
1139       // If there is a delta eta, check it.
1140       if (corrPar.corrCutType & 0x1) {
1141         unsigned int preShift = precDeltaEtaLUT - corrPar.precEtaCut;
1142         LogDebug("L1TGlobal") << "    Testing Delta Eta Cut (" << lutObj0 << "," << lutObj1 << ") ["
1143                               << (long long)(corrPar.minEtaCutValue * pow(10, preShift)) << ","
1144                               << (long long)(corrPar.maxEtaCutValue * pow(10, preShift))
1145                               << "] with precision = " << corrPar.precEtaCut << "\n"
1146                               << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1147                               << "    Precision Shift = " << preShift << "\n"
1148                               << "    deltaEta (shift)= " << (deltaEtaLUT / pow(10, preShift + corrPar.precEtaCut))
1149                               << "\n"
1150                               << "    deltaEtaPhy = " << deltaEtaPhy << std::endl;
1151 
1152         //if(preShift>0) deltaEtaLUT /= pow(10,preShift);
1153         if (deltaEtaLUT >= (long long)(corrPar.minEtaCutValue * pow(10, preShift)) &&
1154             deltaEtaLUT <= (long long)(corrPar.maxEtaCutValue * pow(10, preShift))) {
1155           LogDebug("L1TGlobal") << "    Passed Delta Eta Cut ["
1156                                 << (long long)(corrPar.minEtaCutValue * pow(10, preShift)) << ","
1157                                 << (long long)(corrPar.maxEtaCutValue * pow(10, preShift)) << "]" << std::endl;
1158 
1159         } else {
1160           LogDebug("L1TGlobal") << "    Failed Delta Eta Cut ["
1161                                 << (long long)(corrPar.minEtaCutValue * pow(10, preShift)) << ","
1162                                 << (long long)(corrPar.maxEtaCutValue * pow(10, preShift)) << "]" << std::endl;
1163           reqResult = false;
1164         }
1165       }
1166 
1167       //if there is a delta phi check it.
1168       if (corrPar.corrCutType & 0x2) {
1169         unsigned int preShift = precDeltaPhiLUT - corrPar.precPhiCut;
1170         LogDebug("L1TGlobal") << "    Testing Delta Phi Cut (" << lutObj0 << "," << lutObj1 << ") ["
1171                               << (long long)(corrPar.minPhiCutValue * pow(10, preShift)) << ","
1172                               << (long long)(corrPar.maxPhiCutValue * pow(10, preShift))
1173                               << "] with precision = " << corrPar.precPhiCut << "\n"
1174                               << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1175                               << "    Precision Shift = " << preShift << "\n"
1176                               << "    deltaPhi (shift)= " << (deltaPhiLUT / pow(10, preShift + corrPar.precPhiCut))
1177                               << "\n"
1178                               << "    deltaPhiPhy = " << deltaPhiPhy << std::endl;
1179 
1180         //if(preShift>0) deltaPhiLUT /= pow(10,preShift);
1181         if (deltaPhiLUT >= (long long)(corrPar.minPhiCutValue * pow(10, preShift)) &&
1182             deltaPhiLUT <= (long long)(corrPar.maxPhiCutValue * pow(10, preShift))) {
1183           LogDebug("L1TGlobal") << "    Passed Delta Phi Cut ["
1184                                 << (long long)(corrPar.minPhiCutValue * pow(10, preShift)) << ","
1185                                 << (long long)(corrPar.maxPhiCutValue * pow(10, preShift)) << "]" << std::endl;
1186 
1187         } else {
1188           LogDebug("L1TGlobal") << "    Failed Delta Phi Cut ["
1189                                 << (long long)(corrPar.minPhiCutValue * pow(10, preShift)) << ","
1190                                 << (long long)(corrPar.maxPhiCutValue * pow(10, preShift)) << "]" << std::endl;
1191           reqResult = false;
1192         }
1193       }
1194 
1195       if (corrPar.corrCutType & 0x4) {
1196         //Assumes Delta Eta and Delta Phi LUTs have the same precision
1197         unsigned int preShift = 2 * precDeltaPhiLUT - corrPar.precDRCut;
1198         double deltaRSqPhy = deltaPhiPhy * deltaPhiPhy + deltaEtaPhy * deltaEtaPhy;
1199         long long deltaRSq = deltaEtaLUT * deltaEtaLUT + deltaPhiLUT * deltaPhiLUT;
1200 
1201         LogDebug("L1TGlobal") << "    Testing Delta R Cut (" << lutObj0 << "," << lutObj1 << ") ["
1202                               << (long long)(corrPar.minDRCutValue * pow(10, preShift)) << ","
1203                               << (long long)(corrPar.maxDRCutValue * pow(10, preShift))
1204                               << "] with precision = " << corrPar.precDRCut << "\n"
1205                               << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1206                               << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1207                               << "    deltaRSqLUT = " << deltaRSq << "\n"
1208                               << "    Precision Shift = " << preShift << "\n"
1209                               << "    deltaRSqLUT (shift)= " << (deltaRSq / pow(10, preShift + corrPar.precDRCut))
1210                               << "\n"
1211                               << "    deltaRSqPhy = " << deltaRSqPhy << std::endl;
1212 
1213         //if(preShift>0) deltaRSq /= pow(10,preShift);
1214         if (deltaRSq >= (long long)(corrPar.minDRCutValue * pow(10, preShift)) &&
1215             deltaRSq <= (long long)(corrPar.maxDRCutValue * pow(10, preShift))) {
1216           LogDebug("L1TGlobal") << "    Passed Delta R Cut [" << (long long)(corrPar.minDRCutValue * pow(10, preShift))
1217                                 << "," << (long long)(corrPar.maxDRCutValue * pow(10, preShift)) << "]" << std::endl;
1218 
1219         } else {
1220           LogDebug("L1TGlobal") << "    Failed Delta R Cut [" << (int)(corrPar.minDRCutValue * pow(10, preShift)) << ","
1221                                 << (long long)(corrPar.maxDRCutValue * pow(10, preShift)) << "]" << std::endl;
1222           reqResult = false;
1223         }
1224       }
1225 
1226       if (corrPar.corrCutType & 0x20) {
1227         // Two body pt: pt^2 = pt1^2+pt2^2+2*pt1*pt2*(cos(phi1)*cos(phi2)+sin(phi1)*sin(phi2)).
1228 
1229         LogDebug("L1TGlobal") << " corrPar.corrCutType: " << corrPar.corrCutType << "\n";
1230 
1231         //calculate math sins and cosines for debugging
1232         double cosPhi1Phy = cos(phi0Phy);
1233         double sinPhi1Phy = sin(phi0Phy);
1234         double cosPhi2Phy = cos(phi1Phy);
1235         double sinPhi2Phy = sin(phi1Phy);
1236 
1237         double tbptSqPhy = et0Phy * et0Phy + et1Phy * et1Phy +
1238                            2 * et0Phy * et1Phy * (cosPhi1Phy * cosPhi2Phy + sinPhi1Phy * sinPhi2Phy);
1239         // get values from LUT's
1240 
1241         const std::string& lutName0 = lutObj0;
1242         unsigned int precCosLUT0 = m_gtScales->getPrec_Cos(lutName0);
1243         unsigned int precSinLUT0 = m_gtScales->getPrec_Sin(lutName0);
1244 
1245         const std::string& lutName1 = lutObj1;
1246         unsigned int precCosLUT1 = m_gtScales->getPrec_Cos(lutName1);
1247         unsigned int precSinLUT1 = m_gtScales->getPrec_Sin(lutName1);
1248 
1249         if (precCosLUT0 - precCosLUT1 != 0)
1250           LogDebug("L1TGlobal") << "Warning: Cos LUTs for TwoBodyPt on different Precision" << std::endl;
1251         if (precSinLUT0 - precSinLUT1 != 0)
1252           LogDebug("L1TGlobal") << "Warning: Sin LUTs for TwoBodyPt on different Precision" << std::endl;
1253         if (precSinLUT0 - precCosLUT1 != 0)
1254           LogDebug("L1TGlobal") << "Warning: Sin and Cos LUTs for TwoBodyPt on different Precision" << std::endl;
1255         if (precSinLUT1 - precCosLUT0 != 0)
1256           LogDebug("L1TGlobal") << "Warning: Sin and Cos LUTs for TwoBodyPt on different Precision" << std::endl;
1257 
1258         long long cosPhi1LUT = m_gtScales->getLUT_Cos(lutName0, phiIndex0);
1259         long long sinPhi1LUT = m_gtScales->getLUT_Sin(lutName0, phiIndex0);
1260 
1261         long long cosPhi2LUT = m_gtScales->getLUT_Cos(lutName1, phiIndex1);
1262         long long sinPhi2LUT = m_gtScales->getLUT_Sin(lutName1, phiIndex1);
1263 
1264         // now get pt LUTs
1265         std::string lutName = lutObj0;
1266         lutName += "-ET";
1267         long long ptObj0 = m_gtScales->getLUT_Pt("TwoBody_" + lutName, etIndex0);
1268         unsigned int precPtLUTObj0 = m_gtScales->getPrec_Pt("TwoBody_" + lutName);
1269 
1270         lutName = lutObj1;
1271         lutName += "-ET";
1272         long long ptObj1 = m_gtScales->getLUT_Pt("TwoBody_" + lutName, etIndex1);
1273         unsigned int precPtLUTObj1 = m_gtScales->getPrec_Pt("TwoBody_" + lutName);
1274 
1275         LogTrace("L1TGlobal") << " TBPT Trig precisions:\t " << precCosLUT0 << "\t" << precCosLUT1 << "\t"
1276                               << precSinLUT0 << "\t" << precSinLUT1;
1277         LogTrace("L1TGlobal") << " TBPT Pt precisions:\t " << precPtLUTObj0 << "\t" << precPtLUTObj1;
1278         LogTrace("L1TGlobal") << " TBPT Pt cut:\t " << corrPar.minTBPTCutValue << "\tPrecTBPTCut\t"
1279                               << corrPar.precTBPTCut;
1280         LogTrace("L1TGlobal") << " TBPT Pt1*Pt1 -- Phys:\t " << et0Phy * et0Phy << "\tHW:\t"
1281                               << ptObj0 * ptObj0 * (pow(10, 6));
1282         LogTrace("L1TGlobal") << " TBPT Pt2*Pt2 -- Phys:\t " << et1Phy * et1Phy << "\tHW:\t"
1283                               << ptObj1 * ptObj1 * (pow(10, 6));
1284         LogTrace("L1TGlobal") << " TBPT 2Pt1*Pt2 -- Phys:\t " << 2 * et0Phy * et1Phy << "\tHW:\t"
1285                               << 2 * (ptObj0 * pow(10, 0)) * (ptObj1 * pow(10, 0));
1286         LogTrace("L1TGlobal") << " TBPT Trig -- Phys:\t " << cosPhi1Phy * cosPhi2Phy + sinPhi1Phy * sinPhi2Phy
1287                               << "\tHW:\t" << cosPhi1LUT * cosPhi2LUT + sinPhi1LUT * sinPhi2LUT;
1288 
1289         //double tbptSqPhy =   et0Phy*et0Phy             + et1Phy*et1Phy + 2*et0Phy*et1Phy*(cosPhi1Phy*cosPhi2Phy + sinPhi1Phy*sinPhi2Phy);
1290         long long tbptSqHW = ptObj0 * ptObj0 * (pow(10, 2 * precCosLUT0)) +
1291                              ptObj1 * ptObj1 * (pow(10, 2 * precCosLUT0)) +
1292                              2 * ptObj0 * ptObj1 * (cosPhi1LUT * cosPhi2LUT + sinPhi1LUT * sinPhi2LUT);
1293 
1294         unsigned int preShift = precPtLUTObj0 + precPtLUTObj1 + 2 * precCosLUT0;
1295 
1296         LogTrace("L1TGlobal") << "TBPT Result -- Phys: " << tbptSqPhy << "\tHW: " << tbptSqHW << "\tShifted\t"
1297                               << tbptSqHW / pow(10, preShift) << std::endl;
1298 
1299         preShift = preShift - corrPar.precTBPTCut;
1300 
1301         LogDebug("L1TGlobal")
1302             << "    Testing Two Body Pt Cut (" << lutObj0 << "," << lutObj1 << ") ["
1303             << (long long)(corrPar.minTBPTCutValue * pow(10, preShift)) << ","
1304             << (long long)(corrPar.maxTBPTCutValue * pow(10, preShift)) << "] with precision = " << corrPar.precTBPTCut
1305             << "\n"
1306             << "    etIndex0     = " << etIndex0 << "    pt0LUT      = " << ptObj0 << " PhyEt0 = " << et0Phy << "\n"
1307             << "    etIndex1     = " << etIndex1 << "    pt1LUT      = " << ptObj1 << " PhyEt1 = " << et1Phy << "\n"
1308             << "    Precision Shift = " << preShift << "\n"
1309             << "    Sin(phi1): LUT/Phys\t " << sinPhi1LUT << " / " << sinPhi1Phy << "\n"
1310             << "    Sin(phi2): LUT/Phys\t " << sinPhi2LUT << " / " << sinPhi2Phy << "\n"
1311             << "    Cos(phi1): LUT/Phys\t " << cosPhi1LUT << " / " << cosPhi1Phy << "\n"
1312             << "    Cos(phi2): LUT/Phys\t " << cosPhi2LUT << " / " << cosPhi2Phy
1313             << "\n"
1314 
1315             //    << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1316             //    << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1317             //    << "    deltaRSqLUT = " << deltaRSq <<  "\n"
1318             //    << "    Precision Shift = " << preShift << "\n"
1319             //    << "    deltaRSqLUT (shift)= " << (deltaRSq/pow(10,preShift+corrPar.precDRCut)) << "\n"
1320             //    << "    deltaRSqPhy = " << deltaRSqPhy
1321             << std::endl;
1322 
1323         if (tbptSqHW > 0. && tbptSqHW >= (long long)(corrPar.minTBPTCutValue * pow(10, preShift))) {
1324           LogDebug("L1TGlobal") << "    Passed Two Body pT Cut ["
1325                                 << (long long)(corrPar.minTBPTCutValue * pow(10, preShift)) << "]"
1326                                 << "\twith value: " << tbptSqHW << "\n"
1327                                 << "\tPhysics Cut[" << corrPar.minTBPTCutValue / pow(10, corrPar.precTBPTCut)
1328                                 << "]\tPhysics Value: " << tbptSqPhy << std::endl;
1329 
1330         } else {
1331           LogDebug("L1TGlobal") << "    Failed Two Body pT Cut ["
1332                                 << (long long)(corrPar.minTBPTCutValue * pow(10, preShift)) << "]"
1333                                 << "\t with value: " << tbptSqHW << "\n"
1334                                 << "\tPhysics Cut[" << corrPar.minTBPTCutValue / pow(10, corrPar.precTBPTCut)
1335                                 << "]\tPhysics Value: " << tbptSqPhy << std::endl;
1336           reqResult = false;
1337         }
1338       }
1339 
1340       if (corrPar.corrCutType & 0x8 || corrPar.corrCutType & 0x10) {
1341         //invariant mass calculation based on
1342         // M = sqrt(2*p1*p2(cosh(eta1-eta2) - cos(phi1 - phi2)))
1343         // but we calculate (1/2)M^2
1344         //
1345         double cosDeltaPhiPhy = cos(deltaPhiPhy);
1346         double coshDeltaEtaPhy = cosh(deltaEtaPhy);
1347         if (corrPar.corrCutType & 0x10)
1348           coshDeltaEtaPhy = 1.;
1349         double massSqPhy = et0Phy * et1Phy * (coshDeltaEtaPhy - cosDeltaPhiPhy);
1350 
1351         long long cosDeltaPhiLUT = m_gtScales->getLUT_DeltaPhi_Cos(lutName, deltaPhiFW);
1352         unsigned int precCosLUT = m_gtScales->getPrec_DeltaPhi_Cos(lutName);
1353 
1354         long long coshDeltaEtaLUT;
1355         if (corrPar.corrCutType & 0x10) {
1356           coshDeltaEtaLUT = 1 * pow(10, precCosLUT);
1357         } else {
1358           coshDeltaEtaLUT = m_gtScales->getLUT_DeltaEta_Cosh(lutName, deltaEtaFW);
1359           unsigned int precCoshLUT = m_gtScales->getPrec_DeltaEta_Cosh(lutName);
1360           if (precCoshLUT - precCosLUT != 0)
1361             LogDebug("L1TGlobal") << "Warning: Cos and Cosh LUTs on different Precision" << std::endl;
1362         }
1363 
1364         std::string lutName = lutObj0;
1365         lutName += "-ET";
1366         long long ptObj0 = m_gtScales->getLUT_Pt("Mass_" + lutName, etIndex0);
1367         unsigned int precPtLUTObj0 = m_gtScales->getPrec_Pt("Mass_" + lutName);
1368 
1369         lutName = lutObj1;
1370         lutName += "-ET";
1371         long long ptObj1 = m_gtScales->getLUT_Pt("Mass_" + lutName, etIndex1);
1372         unsigned int precPtLUTObj1 = m_gtScales->getPrec_Pt("Mass_" + lutName);
1373 
1374         // Pt and Angles are at different precission.
1375         long long massSq = ptObj0 * ptObj1 * (coshDeltaEtaLUT - cosDeltaPhiLUT);
1376 
1377         //Note: There is an assumption here that Cos and Cosh have the same precission
1378         unsigned int preShift = precPtLUTObj0 + precPtLUTObj1 + precCosLUT - corrPar.precMassCut;
1379 
1380         LogDebug("L1TGlobal") << "    Testing Invariant Mass (" << lutObj0 << "," << lutObj1 << ") ["
1381                               << (long long)(corrPar.minMassCutValue * pow(10, preShift)) << ","
1382                               << (long long)(corrPar.maxMassCutValue * pow(10, preShift))
1383                               << "] with precision = " << corrPar.precMassCut << "\n"
1384                               << "    deltaPhiLUT  = " << deltaPhiLUT << "  cosLUT  = " << cosDeltaPhiLUT << "\n"
1385                               << "    deltaEtaLUT  = " << deltaEtaLUT << "  coshLUT = " << coshDeltaEtaLUT << "\n"
1386                               << "    etIndex0     = " << etIndex0 << "    pt0LUT      = " << ptObj0
1387                               << " PhyEt0 = " << et0Phy << "\n"
1388                               << "    etIndex1     = " << etIndex1 << "    pt1LUT      = " << ptObj1
1389                               << " PhyEt1 = " << et1Phy << "\n"
1390                               << "    massSq/2     = " << massSq << "\n"
1391                               << "    Precision Shift = " << preShift << "\n"
1392                               << "    massSq   (shift)= " << (massSq / pow(10, preShift + corrPar.precMassCut)) << "\n"
1393                               << "    deltaPhiPhy  = " << deltaPhiPhy << "  cos() = " << cosDeltaPhiPhy << "\n"
1394                               << "    deltaEtaPhy  = " << deltaEtaPhy << "  cosh()= " << coshDeltaEtaPhy << "\n"
1395                               << "    massSqPhy/2  = " << massSqPhy
1396                               << "  sqrt(|massSq|) = " << sqrt(fabs(2. * massSqPhy)) << std::endl;
1397 
1398         //if(preShift>0) massSq /= pow(10,preShift);
1399         if (massSq >= 0 && massSq >= (long long)(corrPar.minMassCutValue * pow(10, preShift)) &&
1400             massSq <= (long long)(corrPar.maxMassCutValue * pow(10, preShift))) {
1401           LogDebug("L1TGlobal") << "    Passed Invariant Mass Cut ["
1402                                 << (long long)(corrPar.minMassCutValue * pow(10, preShift)) << ","
1403                                 << (long long)(corrPar.maxMassCutValue * pow(10, preShift)) << "]" << std::endl;
1404 
1405         } else {
1406           LogDebug("L1TGlobal") << "    Failed Invariant Mass Cut ["
1407                                 << (long long)(corrPar.minMassCutValue * pow(10, preShift)) << ","
1408                                 << (long long)(corrPar.maxMassCutValue * pow(10, preShift)) << "]" << std::endl;
1409           reqResult = false;
1410         }
1411       }
1412 
1413       // For Muon-Muon Correlation Check the Charge Correlation if requested
1414       bool chrgCorrel = true;
1415       if (cond0Categ == CondMuon && cond1Categ == CondMuon) {
1416         // Check for like-sign
1417         if (corrPar.chargeCorrelation == 2 && chrg0 != chrg1)
1418           chrgCorrel = false;
1419         // Check for opp-sign
1420         if (corrPar.chargeCorrelation == 4 && chrg0 == chrg1)
1421           chrgCorrel = false;
1422       }
1423 
1424       if (!reqResult || !chrgCorrel)
1425         continue;
1426 
1427       // ///////////////////////////////////////////////////////////////////////////////////////////
1428       // loop over overlap-removal leg combination which produced individually "true" as Type1s
1429       // ///////////////////////////////////////////////////////////////////////////////////////////
1430       for (std::vector<SingleCombInCond>::const_iterator it2Comb = cond2Comb.begin(); it2Comb != cond2Comb.end();
1431            it2Comb++) {
1432         // Type1s: there is 1 object only, no need for a loop, index 0 should be OK in (*it2Comb)[0]
1433         // ... but add protection to not crash
1434         int obj2Index = -1;
1435 
1436         if (!(*it2Comb).empty()) {
1437           obj2Index = (*it2Comb)[0];
1438         } else {
1439           LogTrace("L1TGlobal") << "\n  SingleCombInCond (*it2Comb).size() " << ((*it2Comb).size()) << std::endl;
1440           return false;
1441         }
1442 
1443         // Collect the information on the overlap-removal leg
1444         switch (cond2Categ) {
1445           case CondMuon: {
1446             lutObj2 = "MU";
1447             candMuVec = m_uGtB->getCandL1Mu();
1448             phiIndex2 = (candMuVec->at(cond2bx, obj2Index))->hwPhi();  //(*candMuVec)[obj2Index]->phiIndex();
1449             etaIndex2 = (candMuVec->at(cond2bx, obj2Index))->hwEta();
1450             int etaBin2 = etaIndex2;
1451             if (etaBin2 < 0)
1452               etaBin2 = m_gtScales->getMUScales().etaBins.size() + etaBin2;  //twos complement
1453             //LogDebug("L1TGlobal") << "Muon phi" << phiIndex2 << " eta " << etaIndex2 << " etaBin2 = " << etaBin2  << " et " << etIndex2 << std::endl;
1454 
1455             // Determine Floating Pt numbers for floating point caluclation
1456             std::pair<double, double> binEdges = m_gtScales->getMUScales().phiBins.at(phiIndex2);
1457             phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1458             binEdges = m_gtScales->getMUScales().etaBins.at(etaBin2);
1459             eta2Phy = 0.5 * (binEdges.second + binEdges.first);
1460 
1461             LogDebug("L1TGlobal") << "Found all quantities for the muon 0" << std::endl;
1462           } break;
1463 
1464           // Calorimeter Objects (EG, Jet, Tau)
1465           case CondCalo: {
1466             switch (cndObjTypeVec[2]) {
1467               case gtEG: {
1468                 lutObj2 = "EG";
1469                 candCaloVec = m_uGtB->getCandL1EG();
1470                 phiIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwPhi();
1471                 etaIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwEta();
1472                 if (etaBin2 < 0)
1473                   etaBin2 = m_gtScales->getEGScales().etaBins.size() + etaBin2;
1474                 //LogDebug("L1TGlobal") << "EG0 phi" << phiIndex2 << " eta " << etaIndex2 << " etaBin2 = " << etaBin2 << " et " << etIndex2 << std::endl;
1475 
1476                 // Determine Floating Pt numbers for floating point caluclation
1477                 std::pair<double, double> binEdges = m_gtScales->getEGScales().phiBins.at(phiIndex2);
1478                 phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1479                 binEdges = m_gtScales->getEGScales().etaBins.at(etaBin2);
1480                 eta2Phy = 0.5 * (binEdges.second + binEdges.first);
1481               } break;
1482 
1483               case gtJet: {
1484                 lutObj2 = "JET";
1485                 candCaloVec = m_uGtB->getCandL1Jet();
1486                 phiIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwPhi();
1487                 etaIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwEta();
1488                 etaBin2 = etaIndex2;
1489                 if (etaBin2 < 0)
1490                   etaBin2 = m_gtScales->getJETScales().etaBins.size() + etaBin2;
1491                 // Determine Floating Pt numbers for floating point caluclation
1492                 std::pair<double, double> binEdges = m_gtScales->getJETScales().phiBins.at(phiIndex2);
1493                 phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1494                 binEdges = m_gtScales->getJETScales().etaBins.at(etaBin2);
1495                 eta2Phy = 0.5 * (binEdges.second + binEdges.first);
1496               } break;
1497               case gtTau: {
1498                 candCaloVec = m_uGtB->getCandL1Tau();
1499                 phiIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwPhi();
1500                 etaIndex2 = (candCaloVec->at(cond2bx, obj2Index))->hwEta();
1501                 if (etaBin2 < 0)
1502                   etaBin2 = m_gtScales->getTAUScales().etaBins.size() + etaBin2;
1503 
1504                 // Determine Floating Pt numbers for floating point caluclation
1505                 std::pair<double, double> binEdges = m_gtScales->getTAUScales().phiBins.at(phiIndex2);
1506                 phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1507                 binEdges = m_gtScales->getTAUScales().etaBins.at(etaBin2);
1508                 eta2Phy = 0.5 * (binEdges.second + binEdges.first);
1509                 lutObj2 = "TAU";
1510               } break;
1511               default: {
1512               } break;
1513             }  //end switch on calo type.
1514 
1515             //If needed convert calo scales to muon scales for comparison
1516             if (convertCaloScales) {
1517               std::string lutName = lutObj2;
1518               lutName += "-MU";
1519               long long tst = m_gtScales->getLUT_CalMuEta(lutName, etaBin2);
1520               LogDebug("L1TGlobal") << lutName << "  EtaCal = " << etaIndex2 << " etaBin2 = " << etaBin2
1521                                     << " EtaMu = " << tst << std::endl;
1522               etaIndex2 = tst;
1523 
1524               tst = m_gtScales->getLUT_CalMuPhi(lutName, phiIndex2);
1525               LogDebug("L1TGlobal") << lutName << "  PhiCal = " << phiIndex2 << " PhiMu = " << tst << std::endl;
1526               phiIndex2 = tst;
1527             }
1528 
1529           } break;
1530 
1531           // Energy Sums
1532           case CondEnergySum: {
1533             etSumCond = true;
1534             //Stupid mapping between enum types for energy sums.
1535             l1t::EtSum::EtSumType type;
1536             switch (cndObjTypeVec[2]) {
1537               case gtETM:
1538                 type = l1t::EtSum::EtSumType::kMissingEt;
1539                 lutObj2 = "ETM";
1540                 break;
1541               case gtETT:
1542                 type = l1t::EtSum::EtSumType::kTotalEt;
1543                 lutObj2 = "ETT";
1544                 break;
1545               case gtETTem:
1546                 type = l1t::EtSum::EtSumType::kTotalEtEm;
1547                 lutObj2 =
1548                     "ETTem";  //should this be just ETT (share LUTs?) Can't be used for CorrCond anyway since now directional information
1549                 break;
1550               case gtHTM:
1551                 type = l1t::EtSum::EtSumType::kMissingHt;
1552                 lutObj2 = "HTM";
1553                 break;
1554               case gtHTT:
1555                 type = l1t::EtSum::EtSumType::kTotalHt;
1556                 lutObj2 = "HTT";
1557                 break;
1558               case gtETMHF:
1559                 type = l1t::EtSum::EtSumType::kMissingEtHF;
1560                 lutObj2 = "ETMHF";
1561                 break;
1562               case gtMinBiasHFP0:
1563               case gtMinBiasHFM0:
1564               case gtMinBiasHFP1:
1565               case gtMinBiasHFM1:
1566                 type = l1t::EtSum::EtSumType::kMinBiasHFP0;
1567                 lutObj2 =
1568                     "MinBias";  //??Fix?? Not a valid LUT type Can't be used for CorrCond anyway since now directional information
1569                 break;
1570               default:
1571                 edm::LogError("L1TGlobal")
1572                     << "\n  Error: "
1573                     << "Unmatched object type from template to EtSumType, cndObjTypeVec[2] = " << cndObjTypeVec[2]
1574                     << std::endl;
1575                 type = l1t::EtSum::EtSumType::kTotalEt;
1576                 break;
1577             }
1578 
1579             candEtSumVec = m_uGtB->getCandL1EtSum();
1580 
1581             for (int iEtSum = 0; iEtSum < (int)candEtSumVec->size(cond2bx); iEtSum++) {
1582               if ((candEtSumVec->at(cond2bx, iEtSum))->getType() == type) {
1583                 phiIndex2 = (candEtSumVec->at(cond2bx, iEtSum))->hwPhi();
1584                 etaIndex2 = (candEtSumVec->at(cond2bx, iEtSum))->hwEta();
1585 
1586                 //  Get the floating point numbers
1587                 if (cndObjTypeVec[2] == gtETM) {
1588                   std::pair<double, double> binEdges = m_gtScales->getETMScales().phiBins.at(phiIndex2);
1589                   phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1590                   eta2Phy = 0.;  //No Eta for Energy Sums
1591 
1592                 } else if (cndObjTypeVec[2] == gtHTM) {
1593                   std::pair<double, double> binEdges = m_gtScales->getHTMScales().phiBins.at(phiIndex2);
1594                   phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1595                   eta2Phy = 0.;  //No Eta for Energy Sums
1596 
1597                 } else if (cndObjTypeVec[2] == gtETMHF) {
1598                   std::pair<double, double> binEdges = m_gtScales->getETMHFScales().phiBins.at(phiIndex2);
1599                   phi2Phy = 0.5 * (binEdges.second + binEdges.first);
1600                   eta2Phy = 0.;  //No Eta for Energy Sums
1601                 }
1602 
1603                 //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
1604                 if (convertCaloScales) {
1605                   std::string lutName = lutObj2;
1606                   lutName += "-MU";
1607                   long long tst = m_gtScales->getLUT_CalMuPhi(lutName, phiIndex2);
1608                   LogDebug("L1TGlobal") << lutName << "  PhiCal = " << phiIndex2 << " PhiMu = " << tst << std::endl;
1609                   phiIndex2 = tst;
1610                 }
1611 
1612               }  //check it is the EtSum we want
1613             }    // loop over Etsums
1614 
1615           }  // end case CondEnerySum
1616           break;
1617           default: {
1618             // should not arrive here, there are no correlation conditions defined for this object
1619             LogDebug("L1TGlobal") << "Error could not find the Cond Category for Leg 3" << std::endl;
1620             return false;
1621           } break;
1622         }  //end switch on overlap-removal leg type
1623 
1624         // /////////////////////////////////////////////////////////////////////////////////////////
1625         //
1626         // here check if there is a match of 1st leg with overlap removal object, and store result
1627         //
1628         // /////////////////////////////////////////////////////////////////////////////////////////
1629         // These all require some delta eta and phi calculations.  Do them first...for now real calculation but need to
1630         // revise this to line up with firmware calculations.
1631         deltaPhiPhy = fabs(phi2Phy - phi0Phy);
1632         if (deltaPhiPhy > M_PI)
1633           deltaPhiPhy = 2. * M_PI - deltaPhiPhy;
1634         deltaEtaPhy = fabs(eta2Phy - eta0Phy);
1635 
1636         // Deter the integer based delta eta and delta phi
1637         deltaPhiFW = abs(phiORIndex0 - phiIndex2);
1638         if (deltaPhiFW >= phiBound)
1639           deltaPhiFW = 2 * phiBound - deltaPhiFW;
1640         lutName = lutObj0;
1641         lutName += "-";
1642         lutName += lutObj2;
1643         deltaPhiLUT = m_gtScales->getLUT_DeltaPhi(lutName, deltaPhiFW);
1644         precDeltaPhiLUT = m_gtScales->getPrec_DeltaPhi(lutName);
1645 
1646         deltaEtaFW = abs(etaORIndex0 - etaIndex2);
1647         deltaEtaLUT = 0;
1648         precDeltaEtaLUT = 0;
1649         if (!etSumCond) {
1650           deltaEtaLUT = m_gtScales->getLUT_DeltaEta(lutName, deltaEtaFW);
1651           precDeltaEtaLUT = m_gtScales->getPrec_DeltaEta(lutName);
1652         }
1653 
1654         LogDebug("L1TGlobal") << "Obj0 phiFW = " << phiORIndex0 << " Obj2 phiFW = " << phiIndex2 << "\n"
1655                               << "    DeltaPhiFW = " << deltaPhiFW << "\n"
1656                               << "    LUT Name = " << lutName << " Prec = " << precDeltaPhiLUT
1657                               << "  DeltaPhiLUT = " << deltaPhiLUT << "\n"
1658                               << "Obj0 etaFW = " << etaIndex0 << " Obj2 etaFW = " << etaIndex2 << "\n"
1659                               << "    DeltaEtaFW = " << deltaEtaFW << "\n"
1660                               << "    LUT Name = " << lutName << " Prec = " << precDeltaEtaLUT
1661                               << "  DeltaEtaLUT = " << deltaEtaLUT << std::endl;
1662 
1663         // If there is a OverlapRemovalDeltaEta cut, check it.
1664         if (corrPar.corrCutType & 0x10) {
1665           unsigned int preShift = precDeltaEtaLUT - corrPar.precOverlapRemovalEtaCut;
1666           LogDebug("L1TGlobal") << "    Testing Leg1 Overlap Removal Delta Eta Cut (" << lutObj0 << "," << lutObj2
1667                                 << ") [" << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1668                                 << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift))
1669                                 << "] with precision = " << corrPar.precOverlapRemovalEtaCut << "\n"
1670                                 << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1671                                 << "    Precision Shift = " << preShift << "\n"
1672                                 << "    deltaEta (shift)= "
1673                                 << (deltaEtaLUT / pow(10, preShift + corrPar.precOverlapRemovalEtaCut)) << "\n"
1674                                 << "    deltaEtaPhy = " << deltaEtaPhy << std::endl;
1675 
1676           //if(preShift>0) deltaEtaLUT /= pow(10,preShift);
1677           if (deltaEtaLUT >= (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) &&
1678               deltaEtaLUT <= (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift))) {
1679             LogDebug("L1TGlobal") << "    Satified Leg1 Overlap Removal Delta Eta Cut ["
1680                                   << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1681                                   << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift)) << "]"
1682                                   << std::endl;
1683             // next leg3 object
1684             continue;
1685 
1686           } else {
1687             LogDebug("L1TGlobal") << "    Failed Leg1 Overlap Removal Delta Eta Cut ["
1688                                   << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1689                                   << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift)) << "]"
1690                                   << std::endl;
1691           }
1692         }
1693 
1694         //if there is a OverlapRemovalDeltaPhi cut, check it.
1695         if (corrPar.corrCutType & 0x20) {
1696           unsigned int preShift = precDeltaPhiLUT - corrPar.precOverlapRemovalPhiCut;
1697           LogDebug("L1TGlobal") << "    Testing Leg1 Overlap Removal Delta Phi Cut (" << lutObj0 << "," << lutObj2
1698                                 << ") [" << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1699                                 << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift))
1700                                 << "] with precision = " << corrPar.precOverlapRemovalPhiCut << "\n"
1701                                 << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1702                                 << "    Precision Shift = " << preShift << "\n"
1703                                 << "    deltaPhi (shift)= "
1704                                 << (deltaPhiLUT / pow(10, preShift + corrPar.precOverlapRemovalPhiCut)) << "\n"
1705                                 << "    deltaPhiPhy = " << deltaPhiPhy << std::endl;
1706 
1707           //if(preShift>0) deltaPhiLUT /= pow(10,preShift);
1708           if (deltaPhiLUT >= (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) &&
1709               deltaPhiLUT <= (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift))) {
1710             LogDebug("L1TGlobal") << "    Satisfied Leg1 Overlap Removal Delta Phi Cut ["
1711                                   << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1712                                   << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift)) << "]"
1713                                   << std::endl;
1714             // next leg3 object
1715             continue;
1716 
1717           } else {
1718             LogDebug("L1TGlobal") << "    Failed Leg1 Overlap Removal Delta Phi Cut ["
1719                                   << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1720                                   << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift)) << "]"
1721                                   << std::endl;
1722           }
1723         }
1724 
1725         //if there is a OverlapRemovalDeltaR cut, check it.
1726         if (corrPar.corrCutType & 0x40) {
1727           //Assumes Delta Eta and Delta Phi LUTs have the same precision
1728           unsigned int preShift = 2 * precDeltaPhiLUT - corrPar.precOverlapRemovalDRCut;
1729           double deltaRSqPhy = deltaPhiPhy * deltaPhiPhy + deltaEtaPhy * deltaEtaPhy;
1730           long long deltaRSq = deltaEtaLUT * deltaEtaLUT + deltaPhiLUT * deltaPhiLUT;
1731 
1732           LogDebug("L1TGlobal") << "    Testing Leg1 Overlap Removal Delta R Cut (" << lutObj0 << "," << lutObj2
1733                                 << ") [" << (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1734                                 << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift))
1735                                 << "] with precision = " << corrPar.precOverlapRemovalDRCut << "\n"
1736                                 << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1737                                 << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1738                                 << "    deltaRSqLUT = " << deltaRSq << "\n"
1739                                 << "    Precision Shift = " << preShift << "\n"
1740                                 << "    deltaRSqLUT (shift)= " << (deltaRSq / pow(10, preShift + corrPar.precDRCut))
1741                                 << "\n"
1742                                 << "    deltaRSqPhy = " << deltaRSqPhy << std::endl;
1743 
1744           //if(preShift>0) deltaRSq /= pow(10,preShift);
1745           if (deltaRSq >= (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) &&
1746               deltaRSq <= (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift))) {
1747             LogDebug("L1TGlobal") << "    Satified Leg1 Overlap Removal Delta R Cut ["
1748                                   << (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1749                                   << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift)) << "]"
1750                                   << std::endl;
1751             // next leg3 object
1752             continue;
1753 
1754           } else {
1755             LogDebug("L1TGlobal") << "    Failed Leg1 Overlap Removal Delta R Cut ["
1756                                   << (int)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1757                                   << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift)) << "]"
1758                                   << std::endl;
1759           }
1760         }
1761 
1762         // /////////////////////////////////////////////////////////////////////////////////////////
1763         //
1764         // here check if there is a match of 2st leg with overlap removal object ...if yes, continue
1765         //
1766         // /////////////////////////////////////////////////////////////////////////////////////////
1767         // These all require some delta eta and phi calculations.  Do them first...for now real calculation but need to
1768         // revise this to line up with firmware calculations.
1769         deltaPhiPhy = fabs(phi2Phy - phi1Phy);
1770         if (deltaPhiPhy > M_PI)
1771           deltaPhiPhy = 2. * M_PI - deltaPhiPhy;
1772         deltaEtaPhy = fabs(eta2Phy - eta1Phy);
1773 
1774         // Deter the integer based delta eta and delta phi
1775         deltaPhiFW = abs(phiORIndex1 - phiIndex2);
1776         if (deltaPhiFW >= phiBound)
1777           deltaPhiFW = 2 * phiBound - deltaPhiFW;
1778         lutName = lutObj1;
1779         lutName += "-";
1780         lutName += lutObj2;
1781         deltaPhiLUT = m_gtScales->getLUT_DeltaPhi(lutName, deltaPhiFW);
1782         precDeltaPhiLUT = m_gtScales->getPrec_DeltaPhi(lutName);
1783 
1784         deltaEtaFW = abs(etaORIndex1 - etaIndex2);
1785         deltaEtaLUT = 0;
1786         precDeltaEtaLUT = 0;
1787         if (!etSumCond) {
1788           deltaEtaLUT = m_gtScales->getLUT_DeltaEta(lutName, deltaEtaFW);
1789           precDeltaEtaLUT = m_gtScales->getPrec_DeltaEta(lutName);
1790         }
1791 
1792         LogDebug("L1TGlobal") << "Obj1 phiFW = " << phiORIndex1 << " Obj2 phiFW = " << phiIndex2 << "\n"
1793                               << "    DeltaPhiFW = " << deltaPhiFW << "\n"
1794                               << "    LUT Name = " << lutName << " Prec = " << precDeltaPhiLUT
1795                               << "  DeltaPhiLUT = " << deltaPhiLUT << "\n"
1796                               << "Obj1 etaFW = " << etaIndex1 << " Obj1 etaFW = " << etaIndex1 << "\n"
1797                               << "    DeltaEtaFW = " << deltaEtaFW << "\n"
1798                               << "    LUT Name = " << lutName << " Prec = " << precDeltaEtaLUT
1799                               << "  DeltaEtaLUT = " << deltaEtaLUT << std::endl;
1800 
1801         // If there is a OverlapRemovalDeltaEta cut, check it.
1802         // /////////////////////////////////////////////////
1803         if (corrPar.corrCutType & 0x10) {
1804           unsigned int preShift = precDeltaEtaLUT - corrPar.precOverlapRemovalEtaCut;
1805           LogDebug("L1TGlobal") << "    Testing Leg2 Overlap Removal Delta Eta Cut (" << lutObj1 << "," << lutObj2
1806                                 << ") [" << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1807                                 << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift))
1808                                 << "] with precision = " << corrPar.precOverlapRemovalEtaCut << "\n"
1809                                 << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1810                                 << "    Precision Shift = " << preShift << "\n"
1811                                 << "    deltaEta (shift)= "
1812                                 << (deltaEtaLUT / pow(10, preShift + corrPar.precOverlapRemovalEtaCut)) << "\n"
1813                                 << "    deltaEtaPhy = " << deltaEtaPhy << std::endl;
1814 
1815           //if(preShift>0) deltaEtaLUT /= pow(10,preShift);
1816           if (deltaEtaLUT >= (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) &&
1817               deltaEtaLUT <= (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift))) {
1818             LogDebug("L1TGlobal") << "    Satisfied Leg2 Overlap Removal Delta Eta Cut ["
1819                                   << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1820                                   << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift)) << "]"
1821                                   << std::endl;
1822             // next leg3 object
1823             continue;
1824 
1825           } else {
1826             LogDebug("L1TGlobal") << "    Failed Leg2 Overlap Removal Delta Eta Cut ["
1827                                   << (long long)(corrPar.minOverlapRemovalEtaCutValue * pow(10, preShift)) << ","
1828                                   << (long long)(corrPar.maxOverlapRemovalEtaCutValue * pow(10, preShift)) << "]"
1829                                   << std::endl;
1830           }
1831         }
1832         // If there is a OverlapRemovalDeltaPhi cut, check it.
1833         // /////////////////////////////////////////////////
1834         if (corrPar.corrCutType & 0x20) {
1835           unsigned int preShift = precDeltaPhiLUT - corrPar.precOverlapRemovalPhiCut;
1836           LogDebug("L1TGlobal") << "    Testing Delta Phi Cut (" << lutObj1 << "," << lutObj2 << ") ["
1837                                 << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1838                                 << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift))
1839                                 << "] with precision = " << corrPar.precOverlapRemovalPhiCut << "\n"
1840                                 << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1841                                 << "    Precision Shift = " << preShift << "\n"
1842                                 << "    deltaPhi (shift)= "
1843                                 << (deltaPhiLUT / pow(10, preShift + corrPar.precOverlapRemovalPhiCut)) << "\n"
1844                                 << "    deltaPhiPhy = " << deltaPhiPhy << std::endl;
1845 
1846           //if(preShift>0) deltaPhiLUT /= pow(10,preShift);
1847           if (deltaPhiLUT >= (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) &&
1848               deltaPhiLUT <= (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift))) {
1849             LogDebug("L1TGlobal") << "    Satisfied Leg2 Overlap Removal Delta Phi Cut ["
1850                                   << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1851                                   << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift)) << "]"
1852                                   << std::endl;
1853             // next leg3 object
1854             continue;
1855 
1856           } else {
1857             LogDebug("L1TGlobal") << "    Failed Leg2 Overlap Removal Delta Phi Cut ["
1858                                   << (long long)(corrPar.minOverlapRemovalPhiCutValue * pow(10, preShift)) << ","
1859                                   << (long long)(corrPar.maxOverlapRemovalPhiCutValue * pow(10, preShift)) << "]"
1860                                   << std::endl;
1861           }
1862         }
1863 
1864         //if there is a OverlapRemovalDeltaR cut, check it.
1865         // /////////////////////////////////////////////////
1866         if (corrPar.corrCutType & 0x40) {
1867           //Assumes Delta Eta and Delta Phi LUTs have the same precision
1868           unsigned int preShift = 2 * precDeltaPhiLUT - corrPar.precOverlapRemovalDRCut;
1869           double deltaRSqPhy = deltaPhiPhy * deltaPhiPhy + deltaEtaPhy * deltaEtaPhy;
1870           long long deltaRSq = deltaEtaLUT * deltaEtaLUT + deltaPhiLUT * deltaPhiLUT;
1871 
1872           LogDebug("L1TGlobal") << "    Testing Leg2 Overlap Removal Delta R Cut (" << lutObj1 << "," << lutObj2
1873                                 << ") [" << (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1874                                 << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift))
1875                                 << "] with precision = " << corrPar.precOverlapRemovalDRCut << "\n"
1876                                 << "    deltaPhiLUT = " << deltaPhiLUT << "\n"
1877                                 << "    deltaEtaLUT = " << deltaEtaLUT << "\n"
1878                                 << "    deltaRSqLUT = " << deltaRSq << "\n"
1879                                 << "    Precision Shift = " << preShift << "\n"
1880                                 << "    deltaRSqLUT (shift)= " << (deltaRSq / pow(10, preShift + corrPar.precDRCut))
1881                                 << "\n"
1882                                 << "    deltaRSqPhy = " << deltaRSqPhy << std::endl;
1883 
1884           //if(preShift>0) deltaRSq /= pow(10,preShift);
1885           if (deltaRSq >= (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) &&
1886               deltaRSq <= (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift))) {
1887             LogDebug("L1TGlobal") << "    Satisfied Leg2 Overlap Removal Delta R Cut ["
1888                                   << (long long)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1889                                   << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift)) << "]"
1890                                   << std::endl;
1891             // next leg3 object
1892             continue;
1893 
1894           } else {
1895             LogDebug("L1TGlobal") << "    Failed Leg2 Overlap Removal Delta R Cut ["
1896                                   << (int)(corrPar.minOverlapRemovalDRCutValue * pow(10, preShift)) << ","
1897                                   << (long long)(corrPar.maxOverlapRemovalDRCutValue * pow(10, preShift)) << "]"
1898                                   << std::endl;
1899           }
1900         }
1901 
1902         condResult = true;
1903 
1904         // clear the indices in the combination
1905         objectsInComb.clear();
1906 
1907         objectsInComb.push_back(obj0Index);
1908         objectsInComb.push_back(obj1Index);
1909         objectsInComb.push_back(obj2Index);
1910 
1911         (combinationsInCond()).push_back(objectsInComb);
1912 
1913       }  // end loop over combinations in overlap-removal leg.
1914 
1915     }  //end loop over second leg
1916 
1917   }  //end loop over first leg
1918 
1919   if (m_verbosity && condResult) {
1920     LogDebug("L1TGlobal") << " pass(es) the correlation condition.\n" << std::endl;
1921   }
1922 
1923   return condResult;
1924 }
1925 
1926 // load calo candidates
1927 const l1t::L1Candidate* l1t::CorrWithOverlapRemovalCondition::getCandidate(const int bx, const int indexCand) const {
1928   // objectType() gives the type for nrObjects() only,
1929   // but in a CondCalo all objects have the same type
1930   // take type from the type of the first object
1931   switch ((m_gtCorrelationWithOverlapRemovalTemplate->objectType())[0]) {
1932     case gtEG:
1933       return (m_uGtB->getCandL1EG())->at(bx, indexCand);
1934       break;
1935 
1936     case gtJet:
1937       return (m_uGtB->getCandL1Jet())->at(bx, indexCand);
1938       break;
1939 
1940     case gtTau:
1941       return (m_uGtB->getCandL1Tau())->at(bx, indexCand);
1942       break;
1943     default:
1944       return nullptr;
1945       break;
1946   }
1947 
1948   return nullptr;
1949 }
1950 
1951 /**
1952  * checkObjectParameter - Compare a single particle with a numbered condition.
1953  *
1954  * @param iCondition The number of the condition.
1955  * @param cand The candidate to compare.
1956  *
1957  * @return The result of the comparison (false if a condition does not exist).
1958  */
1959 
1960 const bool l1t::CorrWithOverlapRemovalCondition::checkObjectParameter(const int iCondition,
1961                                                                       const l1t::L1Candidate& cand) const {
1962   return true;
1963 }
1964 
1965 void l1t::CorrWithOverlapRemovalCondition::print(std::ostream& myCout) const {
1966   myCout << "Dummy Print for CorrWithOverlapRemovalCondition" << std::endl;
1967   m_gtCorrelationWithOverlapRemovalTemplate->print(myCout);
1968 
1969   ConditionEvaluation::print(myCout);
1970 }