Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-08 05:11:48

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