Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /**
0002  * \class L1GtCorrelationCondition
0003  *
0004  *
0005  * Description: evaluation of a CondCorrelation condition.
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *
0010  * \author: Vasile Mihai Ghete   - HEPHY Vienna
0011  *
0012  *
0013  */
0014 
0015 // this class header
0016 #include "L1Trigger/GlobalTrigger/interface/L1GtCorrelationCondition.h"
0017 
0018 // system include files
0019 #include <iomanip>
0020 #include <iostream>
0021 
0022 #include <algorithm>
0023 #include <string>
0024 #include <vector>
0025 
0026 // user include files
0027 //   base classes
0028 #include "CondFormats/L1TObjects/interface/L1GtCorrelationTemplate.h"
0029 
0030 #include "CondFormats/L1TObjects/interface/L1GtCaloTemplate.h"
0031 #include "CondFormats/L1TObjects/interface/L1GtEnergySumTemplate.h"
0032 #include "CondFormats/L1TObjects/interface/L1GtMuonTemplate.h"
0033 
0034 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTCand.h"
0035 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
0036 
0037 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctCand.h"
0038 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctEmCand.h"
0039 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctEtSums.h"
0040 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCand.h"
0041 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTCand.h"
0042 
0043 #include "L1Trigger/GlobalTrigger/interface/L1GtCaloCondition.h"
0044 #include "L1Trigger/GlobalTrigger/interface/L1GtEnergySumCondition.h"
0045 #include "L1Trigger/GlobalTrigger/interface/L1GtMuonCondition.h"
0046 
0047 #include "L1Trigger/GlobalTrigger/interface/L1GtEtaPhiConversions.h"
0048 
0049 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerFunctions.h"
0050 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerGTL.h"
0051 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerPSB.h"
0052 
0053 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0054 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0055 
0056 // constructors
0057 //     default
0058 L1GtCorrelationCondition::L1GtCorrelationCondition()
0059     : L1GtConditionEvaluation(), m_isDebugEnabled(edm::isDebugEnabled()) {
0060   // empty
0061 }
0062 
0063 //     from base template condition (from event setup usually)
0064 L1GtCorrelationCondition::L1GtCorrelationCondition(const L1GtCondition *corrTemplate,
0065                                                    const L1GtCondition *cond0Condition,
0066                                                    const L1GtCondition *cond1Condition,
0067                                                    const int cond0NrL1Objects,
0068                                                    const int cond1NrL1Objects,
0069                                                    const int cond0EtaBits,
0070                                                    const int cond1EtaBits,
0071                                                    const L1GlobalTriggerGTL *ptrGTL,
0072                                                    const L1GlobalTriggerPSB *ptrPSB,
0073                                                    const L1GtEtaPhiConversions *etaPhiConversions)
0074     : L1GtConditionEvaluation(),
0075       m_gtCorrelationTemplate(static_cast<const L1GtCorrelationTemplate *>(corrTemplate)),
0076       m_gtCond0(cond0Condition),
0077       m_gtCond1(cond1Condition),
0078       m_cond0NrL1Objects(cond0NrL1Objects),
0079       m_cond1NrL1Objects(cond1NrL1Objects),
0080       m_cond0EtaBits(cond0EtaBits),
0081       m_cond1EtaBits(cond1EtaBits),
0082       m_gtGTL(ptrGTL),
0083       m_gtPSB(ptrPSB),
0084       m_gtEtaPhiConversions(etaPhiConversions),
0085       m_isDebugEnabled(edm::isDebugEnabled()) {
0086   m_condMaxNumberObjects = 2;  // irrelevant for correlation conditions
0087   m_nrBinsPhi = 0;
0088 }
0089 
0090 // copy constructor
0091 void L1GtCorrelationCondition::copy(const L1GtCorrelationCondition &cp) {
0092   m_gtCorrelationTemplate = cp.m_gtCorrelationTemplate;
0093 
0094   m_gtCond0 = cp.m_gtCond0;
0095   m_gtCond1 = cp.m_gtCond1;
0096 
0097   m_cond0NrL1Objects = cp.m_cond0NrL1Objects;
0098   m_cond1NrL1Objects = cp.m_cond1NrL1Objects;
0099   m_cond0EtaBits = cp.m_cond0EtaBits;
0100   m_cond1EtaBits = cp.m_cond1EtaBits;
0101 
0102   m_nrBinsPhi = cp.m_nrBinsPhi;
0103 
0104   m_gtCorrelationTemplate = cp.m_gtCorrelationTemplate;
0105   m_gtGTL = cp.m_gtGTL;
0106   m_gtPSB = cp.m_gtPSB;
0107 
0108   m_gtEtaPhiConversions = cp.m_gtEtaPhiConversions;
0109 
0110   m_condMaxNumberObjects = cp.m_condMaxNumberObjects;
0111   m_condLastResult = cp.m_condLastResult;
0112   m_combinationsInCond = cp.m_combinationsInCond;
0113 
0114   m_verbosity = cp.m_verbosity;
0115   m_isDebugEnabled = cp.m_isDebugEnabled;
0116 }
0117 
0118 L1GtCorrelationCondition::L1GtCorrelationCondition(const L1GtCorrelationCondition &cp) : L1GtConditionEvaluation() {
0119   copy(cp);
0120 }
0121 
0122 // destructor
0123 L1GtCorrelationCondition::~L1GtCorrelationCondition() {
0124   // empty
0125 }
0126 
0127 // equal operator
0128 L1GtCorrelationCondition &L1GtCorrelationCondition::operator=(const L1GtCorrelationCondition &cp) {
0129   copy(cp);
0130   return *this;
0131 }
0132 
0133 // methods
0134 
0135 void L1GtCorrelationCondition::setGtNrBinsPhi(const unsigned int nrBins) { m_nrBinsPhi = nrBins; }
0136 
0137 //
0138 void L1GtCorrelationCondition::setGtCorrelationTemplate(const L1GtCorrelationTemplate *corrTempl) {
0139   m_gtCorrelationTemplate = corrTempl;
0140 }
0141 
0142 //   set the pointer to GTL
0143 void L1GtCorrelationCondition::setGtGTL(const L1GlobalTriggerGTL *ptrGTL) { m_gtGTL = ptrGTL; }
0144 
0145 //   set the pointer to PSB
0146 void L1GtCorrelationCondition::setGtPSB(const L1GlobalTriggerPSB *ptrPSB) { m_gtPSB = ptrPSB; }
0147 
0148 // try all object permutations and check spatial correlations, if required
0149 const bool L1GtCorrelationCondition::evaluateCondition() const {
0150   // std::cout << "m_isDebugEnabled = " << m_isDebugEnabled << std::endl;
0151   // std::cout << "m_verbosity = " << m_verbosity << std::endl;
0152 
0153   bool condResult = false;
0154   bool reqObjResult = false;
0155 
0156   // number of objects in condition (it is 2, no need to retrieve from
0157   // condition template) and their type
0158   int nObjInCond = 2;
0159   std::vector<L1GtObject> cndObjTypeVec(nObjInCond);
0160 
0161   // evaluate first the two sub-conditions (Type1s)
0162 
0163   const L1GtConditionCategory cond0Categ = m_gtCorrelationTemplate->cond0Category();
0164   const L1GtConditionCategory cond1Categ = m_gtCorrelationTemplate->cond1Category();
0165 
0166   const L1GtMuonTemplate *corrMuon = nullptr;
0167   const L1GtCaloTemplate *corrCalo = nullptr;
0168   const L1GtEnergySumTemplate *corrEnergySum = nullptr;
0169 
0170   // FIXME copying is slow...
0171   CombinationsInCond cond0Comb;
0172   CombinationsInCond cond1Comb;
0173 
0174   switch (cond0Categ) {
0175     case CondMuon: {
0176       corrMuon = static_cast<const L1GtMuonTemplate *>(m_gtCond0);
0177       L1GtMuonCondition muCondition(corrMuon, m_gtGTL, m_cond0NrL1Objects, m_cond0EtaBits);
0178 
0179       muCondition.evaluateConditionStoreResult();
0180       reqObjResult = muCondition.condLastResult();
0181 
0182       cond0Comb = (muCondition.getCombinationsInCond());
0183       cndObjTypeVec[0] = (corrMuon->objectType())[0];
0184 
0185       if (m_verbosity && m_isDebugEnabled) {
0186         std::ostringstream myCout;
0187         muCondition.print(myCout);
0188 
0189         LogTrace("L1GlobalTrigger") << myCout.str() << std::endl;
0190       }
0191     } break;
0192     case CondCalo: {
0193       corrCalo = static_cast<const L1GtCaloTemplate *>(m_gtCond0);
0194 
0195       L1GtCaloCondition caloCondition(corrCalo,
0196                                       m_gtPSB,
0197                                       m_cond0NrL1Objects,
0198                                       m_cond0NrL1Objects,
0199                                       m_cond0NrL1Objects,
0200                                       m_cond0NrL1Objects,
0201                                       m_cond0NrL1Objects,
0202                                       m_cond0EtaBits);
0203 
0204       caloCondition.evaluateConditionStoreResult();
0205       reqObjResult = caloCondition.condLastResult();
0206 
0207       cond0Comb = (caloCondition.getCombinationsInCond());
0208       cndObjTypeVec[0] = (corrCalo->objectType())[0];
0209 
0210       if (m_verbosity && m_isDebugEnabled) {
0211         std::ostringstream myCout;
0212         caloCondition.print(myCout);
0213 
0214         LogTrace("L1GlobalTrigger") << myCout.str() << std::endl;
0215       }
0216     } break;
0217     case CondEnergySum: {
0218       corrEnergySum = static_cast<const L1GtEnergySumTemplate *>(m_gtCond0);
0219       L1GtEnergySumCondition eSumCondition(corrEnergySum, m_gtPSB);
0220 
0221       eSumCondition.evaluateConditionStoreResult();
0222       reqObjResult = eSumCondition.condLastResult();
0223 
0224       cond0Comb = (eSumCondition.getCombinationsInCond());
0225       cndObjTypeVec[0] = (corrEnergySum->objectType())[0];
0226 
0227       if (m_verbosity && m_isDebugEnabled) {
0228         std::ostringstream myCout;
0229         eSumCondition.print(myCout);
0230 
0231         LogTrace("L1GlobalTrigger") << myCout.str() << std::endl;
0232       }
0233     } break;
0234     default: {
0235       // should not arrive here, there are no correlation conditions defined for
0236       // this object
0237       return false;
0238     } break;
0239   }
0240 
0241   // return if first subcondition is false
0242   if (!reqObjResult) {
0243     if (m_verbosity && m_isDebugEnabled) {
0244       LogTrace("L1GlobalTrigger") << "\n  First sub-condition false, second sub-condition not "
0245                                      "evaluated and not printed."
0246                                   << std::endl;
0247     }
0248     return false;
0249   }
0250 
0251   // second object
0252   reqObjResult = false;
0253 
0254   switch (cond1Categ) {
0255     case CondMuon: {
0256       corrMuon = static_cast<const L1GtMuonTemplate *>(m_gtCond1);
0257       L1GtMuonCondition muCondition(corrMuon, m_gtGTL, m_cond1NrL1Objects, m_cond1EtaBits);
0258 
0259       muCondition.evaluateConditionStoreResult();
0260       reqObjResult = muCondition.condLastResult();
0261 
0262       cond1Comb = (muCondition.getCombinationsInCond());
0263       cndObjTypeVec[1] = (corrMuon->objectType())[0];
0264 
0265       if (m_verbosity && m_isDebugEnabled) {
0266         std::ostringstream myCout;
0267         muCondition.print(myCout);
0268 
0269         LogTrace("L1GlobalTrigger") << myCout.str() << std::endl;
0270       }
0271     } break;
0272     case CondCalo: {
0273       corrCalo = static_cast<const L1GtCaloTemplate *>(m_gtCond1);
0274       L1GtCaloCondition caloCondition(corrCalo,
0275                                       m_gtPSB,
0276                                       m_cond1NrL1Objects,
0277                                       m_cond1NrL1Objects,
0278                                       m_cond1NrL1Objects,
0279                                       m_cond1NrL1Objects,
0280                                       m_cond1NrL1Objects,
0281                                       m_cond1EtaBits);
0282 
0283       caloCondition.evaluateConditionStoreResult();
0284       reqObjResult = caloCondition.condLastResult();
0285 
0286       cond1Comb = (caloCondition.getCombinationsInCond());
0287       cndObjTypeVec[1] = (corrCalo->objectType())[0];
0288 
0289       if (m_verbosity && m_isDebugEnabled) {
0290         std::ostringstream myCout;
0291         caloCondition.print(myCout);
0292 
0293         LogTrace("L1GlobalTrigger") << myCout.str() << std::endl;
0294       }
0295 
0296     } break;
0297     case CondEnergySum: {
0298       corrEnergySum = static_cast<const L1GtEnergySumTemplate *>(m_gtCond1);
0299       L1GtEnergySumCondition eSumCondition(corrEnergySum, m_gtPSB);
0300       eSumCondition.evaluateConditionStoreResult();
0301       reqObjResult = eSumCondition.condLastResult();
0302 
0303       cond1Comb = (eSumCondition.getCombinationsInCond());
0304       cndObjTypeVec[1] = (corrEnergySum->objectType())[0];
0305 
0306       if (m_verbosity && m_isDebugEnabled) {
0307         std::ostringstream myCout;
0308         eSumCondition.print(myCout);
0309 
0310         LogTrace("L1GlobalTrigger") << myCout.str() << std::endl;
0311       }
0312     } break;
0313     default: {
0314       // should not arrive here, there are no correlation conditions defined for
0315       // this object
0316       return false;
0317     } break;
0318   }
0319 
0320   // return if second sub-condition is false
0321   if (!reqObjResult) {
0322     return false;
0323   } else {
0324     LogTrace("L1GlobalTrigger") << "\n"
0325                                 << "    Both sub-conditions true for object requirements."
0326                                 << "    Evaluate correlation requirements.\n"
0327                                 << std::endl;
0328   }
0329 
0330   //
0331   // evaluate the delta_eta and delta_phi correlations
0332   // if here, the object requirements are satisfied for both sub-conditions
0333   //
0334 
0335   // get the correlation parameters
0336 
0337   L1GtCorrelationTemplate::CorrelationParameter corrPar = *(m_gtCorrelationTemplate->correlationParameter());
0338 
0339   // convert the eta template requirements from string to 64-bit integers
0340   // number of 64-bit integers: string length / 16
0341   size_t deltaEtaRangeConvSize = (corrPar.deltaEtaRange).size() / 16 + 1;
0342   std::vector<unsigned long long> deltaEtaRangeConv(deltaEtaRangeConvSize);
0343 
0344   if (!(hexStringToInt64(corrPar.deltaEtaRange, deltaEtaRangeConv))) {
0345     return false;
0346   }
0347 
0348   // convert the phi template requirements from string to 64-bit integers
0349   // number of 64-bit integers: string length / 16
0350   size_t deltaPhiRangeConvSize = (corrPar.deltaPhiRange).size() / 16 + 1;
0351   std::vector<unsigned long long> deltaPhiRangeConv(deltaPhiRangeConvSize);
0352 
0353   if (!(hexStringToInt64(corrPar.deltaPhiRange, deltaPhiRangeConv))) {
0354     return false;
0355   }
0356 
0357   // get the index of L1 GT object pair
0358   unsigned int objPairIndex = (m_gtEtaPhiConversions->gtObjectPairIndex(cndObjTypeVec[0], cndObjTypeVec[1]));
0359 
0360   // get the maximum number of bins for the delta phi scales
0361   unsigned int corrParDeltaPhiNrBins = (m_gtEtaPhiConversions->gtObjectNrBinsPhi(objPairIndex)) / 2 + 1;
0362 
0363   // vector to store the indices of the calorimeter objects
0364   // from the combination evaluated in the condition
0365   SingleCombInCond objectsInComb;
0366   objectsInComb.reserve(nObjInCond);
0367 
0368   // clear the m_combinationsInCond vector
0369   (combinationsInCond()).clear();
0370 
0371   // pointers to objects
0372   const std::vector<const L1MuGMTCand *> *candMuVec = nullptr;
0373   const std::vector<const L1GctCand *> *candCaloVec = nullptr;
0374   //    only ETM and HTM  can appear in correlation conditions
0375   const L1GctEtMiss *candETM = nullptr;
0376   const L1GctHtMiss *candHTM = nullptr;
0377 
0378   // make the conversions of the indices, depending on the combination of
0379   // objects involved (via pair index)
0380 
0381   unsigned int phiIndex0 = 0;
0382   unsigned int phiIndex1 = 0;
0383 
0384   unsigned int phiIndex0Converted = 0;
0385   unsigned int phiIndex1Converted = 0;
0386 
0387   unsigned int etaIndex0 = 0;
0388   unsigned int etaIndex1 = 0;
0389 
0390   unsigned int etaIndex0Converted = 0;
0391   unsigned int etaIndex1Converted = 0;
0392 
0393   LogTrace("L1GlobalTrigger") << "  Sub-condition 0: std::vector<SingleCombInCond> size: " << (cond0Comb.size())
0394                               << std::endl;
0395   LogTrace("L1GlobalTrigger") << "  Sub-condition 1: std::vector<SingleCombInCond> size: " << (cond1Comb.size())
0396                               << std::endl;
0397 
0398   // loop over all combinations which produced individually "true" as Type1s
0399   for (std::vector<SingleCombInCond>::const_iterator it0Comb = cond0Comb.begin(); it0Comb != cond0Comb.end();
0400        it0Comb++) {
0401     // Type1s: there is 1 object only, no need for a loop, index 0 should be OK
0402     // in (*it0Comb)[0]
0403     // ... but add protection to not crash
0404     int obj0Index = -1;
0405 
0406     if (!(*it0Comb).empty()) {
0407       obj0Index = (*it0Comb)[0];
0408     } else {
0409       LogTrace("L1GlobalTrigger") << "\n  SingleCombInCond (*it0Comb).size() " << ((*it0Comb).size()) << std::endl;
0410       return false;
0411     }
0412 
0413     bool convStatus = false;
0414 
0415     switch (cond0Categ) {
0416       case CondMuon: {
0417         candMuVec = m_gtGTL->getCandL1Mu();
0418         phiIndex0 = (*candMuVec)[obj0Index]->phiIndex();
0419         etaIndex0 = (*candMuVec)[obj0Index]->etaIndex();
0420 
0421         convStatus = m_gtEtaPhiConversions->convertPhiIndex(objPairIndex, 0, phiIndex0, phiIndex0Converted);
0422 
0423         if (!convStatus) {
0424           // conversion failed, message written in L1GtEtaPhiConversions
0425           return false;
0426         }
0427 
0428         convStatus = m_gtEtaPhiConversions->convertEtaIndex(Mu, etaIndex0, etaIndex0Converted);
0429 
0430         if (!convStatus) {
0431           // conversion failed, message written in L1GtEtaPhiConversions
0432           return false;
0433         }
0434 
0435       } break;
0436       case CondCalo: {
0437         switch (cndObjTypeVec[0]) {
0438           case NoIsoEG: {
0439             candCaloVec = m_gtPSB->getCandL1NoIsoEG();
0440           } break;
0441           case IsoEG: {
0442             candCaloVec = m_gtPSB->getCandL1IsoEG();
0443           } break;
0444           case CenJet: {
0445             candCaloVec = m_gtPSB->getCandL1CenJet();
0446           } break;
0447           case ForJet: {
0448             candCaloVec = m_gtPSB->getCandL1ForJet();
0449           } break;
0450           case TauJet: {
0451             candCaloVec = m_gtPSB->getCandL1TauJet();
0452           } break;
0453           default: {
0454             // do nothing
0455           } break;
0456         }
0457 
0458         phiIndex0 = (*candCaloVec)[obj0Index]->phiIndex();
0459         etaIndex0 = (*candCaloVec)[obj0Index]->etaIndex();
0460 
0461         convStatus = m_gtEtaPhiConversions->convertPhiIndex(objPairIndex, 0, phiIndex0, phiIndex0Converted);
0462 
0463         if (!convStatus) {
0464           // conversion failed, message written in L1GtEtaPhiConversions
0465           return false;
0466         }
0467 
0468         convStatus = m_gtEtaPhiConversions->convertEtaIndex(cndObjTypeVec[0], etaIndex0, etaIndex0Converted);
0469 
0470         if (!convStatus) {
0471           // conversion failed, message written in L1GtEtaPhiConversions
0472           return false;
0473         }
0474       } break;
0475       case CondEnergySum: {
0476         switch (cndObjTypeVec[0]) {
0477           case ETM: {
0478             candETM = m_gtPSB->getCandL1ETM();
0479             phiIndex0 = candETM->phi();
0480 
0481             convStatus = m_gtEtaPhiConversions->convertPhiIndex(objPairIndex, 0, phiIndex0, phiIndex0Converted);
0482 
0483             if (!convStatus) {
0484               // conversion failed, message written in L1GtEtaPhiConversions
0485               return false;
0486             }
0487 
0488           } break;
0489           case HTM: {
0490             candHTM = m_gtPSB->getCandL1HTM();
0491             phiIndex0 = candHTM->phi();
0492 
0493             convStatus = m_gtEtaPhiConversions->convertPhiIndex(objPairIndex, 0, phiIndex0, phiIndex0Converted);
0494 
0495             if (!convStatus) {
0496               // conversion failed, message written in L1GtEtaPhiConversions
0497               return false;
0498             }
0499 
0500           } break;
0501           default:
0502             // do nothing
0503             break;
0504         }
0505       } break;
0506       default: {
0507         // should not arrive here, there are no correlation conditions defined for
0508         // this object
0509         return false;
0510       } break;
0511     }
0512 
0513     for (std::vector<SingleCombInCond>::const_iterator it1Comb = cond1Comb.begin(); it1Comb != cond1Comb.end();
0514          it1Comb++) {
0515       // Type1s: there is 1 object only, no need for a loop (*it1Comb)[0]
0516       // ... but add protection to not crash
0517       int obj1Index = -1;
0518 
0519       if (!(*it1Comb).empty()) {
0520         obj1Index = (*it1Comb)[0];
0521       } else {
0522         LogTrace("L1GlobalTrigger") << "\n  SingleCombInCond (*it1Comb).size() " << ((*it1Comb).size()) << std::endl;
0523         return false;
0524       }
0525 
0526       switch (cond1Categ) {
0527         case CondMuon: {
0528           candMuVec = m_gtGTL->getCandL1Mu();
0529           phiIndex1 = (*candMuVec)[obj1Index]->phiIndex();
0530           etaIndex1 = (*candMuVec)[obj1Index]->etaIndex();
0531 
0532           convStatus = m_gtEtaPhiConversions->convertPhiIndex(objPairIndex, 1, phiIndex1, phiIndex1Converted);
0533 
0534           if (!convStatus) {
0535             // conversion failed, message written in L1GtEtaPhiConversions
0536             return false;
0537           }
0538 
0539           convStatus = m_gtEtaPhiConversions->convertEtaIndex(cndObjTypeVec[1], etaIndex1, etaIndex1Converted);
0540 
0541           if (!convStatus) {
0542             // conversion failed, message written in L1GtEtaPhiConversions
0543             return false;
0544           }
0545         } break;
0546         case CondCalo: {
0547           switch (cndObjTypeVec[1]) {
0548             case NoIsoEG:
0549               candCaloVec = m_gtPSB->getCandL1NoIsoEG();
0550               break;
0551             case IsoEG:
0552               candCaloVec = m_gtPSB->getCandL1IsoEG();
0553               break;
0554             case CenJet:
0555               candCaloVec = m_gtPSB->getCandL1CenJet();
0556               break;
0557             case ForJet:
0558               candCaloVec = m_gtPSB->getCandL1ForJet();
0559               break;
0560             case TauJet:
0561               candCaloVec = m_gtPSB->getCandL1TauJet();
0562               break;
0563             default:
0564               // do nothing
0565               break;
0566           }
0567 
0568           phiIndex1 = (*candCaloVec)[obj1Index]->phiIndex();
0569           etaIndex1 = (*candCaloVec)[obj1Index]->etaIndex();
0570 
0571           convStatus = m_gtEtaPhiConversions->convertPhiIndex(objPairIndex, 1, phiIndex1, phiIndex1Converted);
0572 
0573           if (!convStatus) {
0574             // conversion failed, message written in L1GtEtaPhiConversions
0575             return false;
0576           }
0577 
0578           convStatus = m_gtEtaPhiConversions->convertEtaIndex(cndObjTypeVec[1], etaIndex1, etaIndex1Converted);
0579 
0580           if (!convStatus) {
0581             // conversion failed, message written in L1GtEtaPhiConversions
0582             return false;
0583           }
0584 
0585         } break;
0586         case CondEnergySum: {
0587           switch (cndObjTypeVec[1]) {
0588             case ETM: {
0589               candETM = m_gtPSB->getCandL1ETM();
0590               phiIndex1 = candETM->phi();
0591 
0592               convStatus = m_gtEtaPhiConversions->convertPhiIndex(objPairIndex, 1, phiIndex1, phiIndex1Converted);
0593 
0594               if (!convStatus) {
0595                 // conversion failed, message written in L1GtEtaPhiConversions
0596                 return false;
0597               }
0598             } break;
0599             case HTM: {
0600               candHTM = m_gtPSB->getCandL1HTM();
0601               phiIndex1 = candHTM->phi();
0602 
0603               convStatus = m_gtEtaPhiConversions->convertPhiIndex(objPairIndex, 1, phiIndex1, phiIndex1Converted);
0604 
0605               if (!convStatus) {
0606                 // conversion failed, message written in L1GtEtaPhiConversions
0607                 return false;
0608               }
0609             } break;
0610             default:
0611               // do nothing
0612               break;
0613           }
0614         } break;
0615         default: {
0616           // should not arrive here, there are no correlation conditions defined
0617           // for this object
0618           return false;
0619         } break;
0620       }
0621 
0622       if (m_verbosity && m_isDebugEnabled) {
0623         LogTrace("L1GlobalTrigger") << "    Correlation pair [" << l1GtObjectEnumToString(cndObjTypeVec[0]) << ", "
0624                                     << l1GtObjectEnumToString(cndObjTypeVec[1]) << "] with collection indices ["
0625                                     << obj0Index << ", " << obj1Index << "] "
0626                                     << " has: \n      phi indices = [" << phiIndex0 << ", " << phiIndex1
0627                                     << "] converted to [" << phiIndex0Converted << ", " << phiIndex1Converted
0628                                     << "] \n      eta indices [" << etaIndex0 << ", " << etaIndex1 << "] converted to ["
0629                                     << etaIndex0Converted << ", " << etaIndex1Converted << "] \n"
0630                                     << std::endl;
0631       }
0632 
0633       // the conversions were successful, need to evaluate requirements now
0634 
0635       bool reqEtaPhiResult = false;
0636 
0637       // evaluate candDeltaPhi requirements
0638 
0639       unsigned int candDeltaPhi;
0640 
0641       // calculate absolute value of candDeltaPhi
0642       if (phiIndex0Converted > phiIndex1Converted) {
0643         candDeltaPhi = phiIndex0Converted - phiIndex1Converted;
0644       } else {
0645         candDeltaPhi = phiIndex1Converted - phiIndex0Converted;
0646       }
0647 
0648       // check if candDeltaPhi > 180 (via delta_phi_maxbits)
0649       // delta_phi contains bits for 0..180 (0 and 180 included)
0650       // protect also against infinite loop...
0651 
0652       int nMaxLoop = 10;
0653       int iLoop = 0;
0654 
0655       while (candDeltaPhi >= corrParDeltaPhiNrBins) {
0656         unsigned int candDeltaPhiInitial = candDeltaPhi;
0657 
0658         // candDeltaPhi > 180 ==> take 360 - candDeltaPhi
0659         candDeltaPhi = (corrParDeltaPhiNrBins - 1) * 2 - candDeltaPhi;
0660         if (m_verbosity) {
0661           LogTrace("L1GlobalTrigger") << "    Initial candDeltaPhi = " << candDeltaPhiInitial
0662                                       << " > corrParDeltaPhiNrBins = " << corrParDeltaPhiNrBins
0663                                       << "  ==> candDeltaPhi rescaled to: " << candDeltaPhi << " [ loop index " << iLoop
0664                                       << "; breaks after " << nMaxLoop << " loops ]\n"
0665                                       << std::endl;
0666         }
0667 
0668         iLoop++;
0669         if (iLoop > nMaxLoop) {
0670           return false;
0671         }
0672       }
0673 
0674       // template requirements already converted from string to 64-bit integers
0675       // ...now check for each 64-bit integer against template requirements
0676       bool indResult = true;
0677 
0678       for (size_t iDeltaPhi = 0; iDeltaPhi < deltaPhiRangeConv.size(); ++iDeltaPhi) {
0679         if (!checkBit(deltaPhiRangeConv[iDeltaPhi], candDeltaPhi)) {
0680           indResult = false;
0681         }
0682       }
0683 
0684       if (!indResult) {
0685         if (m_verbosity && m_isDebugEnabled) {
0686           LogTrace("L1GlobalTrigger") << "      object delta phi = " << candDeltaPhi << " fails delta phi requirements."
0687                                       << "\n      Pair fails correlation condition.\n"
0688                                       << std::endl;
0689         }
0690 
0691         reqEtaPhiResult = false;
0692         continue;
0693 
0694       } else {
0695         if (m_verbosity && m_isDebugEnabled) {
0696           LogTrace("L1GlobalTrigger") << "      object delta phi = " << candDeltaPhi
0697                                       << " passes delta phi requirements." << std::endl;
0698         }
0699       }
0700 
0701       // evaluate candDeltaEta requirements
0702 
0703       unsigned int candDeltaEta;
0704 
0705       // calculate absolute value of candDeltaEta
0706       if (etaIndex0Converted > etaIndex1Converted) {
0707         candDeltaEta = etaIndex0Converted - etaIndex1Converted;
0708       } else {
0709         candDeltaEta = etaIndex1Converted - etaIndex0Converted;
0710       }
0711 
0712       // template requirements already converted from string to 64-bit integers
0713       // ...now check for each 64-bit integer against template requirements
0714       indResult = true;
0715 
0716       for (size_t iDeltaEta = 0; iDeltaEta < deltaEtaRangeConv.size(); ++iDeltaEta) {
0717         if (!checkBit(deltaEtaRangeConv[iDeltaEta], candDeltaEta)) {
0718           indResult = false;
0719         }
0720       }
0721 
0722       if (!indResult) {
0723         if (m_verbosity && m_isDebugEnabled) {
0724           LogTrace("L1GlobalTrigger") << "      object delta eta = " << candDeltaEta << " fails delta eta requirements."
0725                                       << "\n      Pair fails correlation condition.\n"
0726                                       << std::endl;
0727         }
0728 
0729         reqEtaPhiResult = false;
0730         continue;
0731 
0732       } else {
0733         if (m_verbosity && m_isDebugEnabled) {
0734           LogTrace("L1GlobalTrigger") << "      object delta eta = " << candDeltaEta
0735                                       << " passes delta eta requirements."
0736                                       << "\n      Pair passes correlation condition.\n"
0737                                       << std::endl;
0738         }
0739 
0740         reqEtaPhiResult = true;
0741       }
0742 
0743       // clear the indices in the combination
0744       objectsInComb.clear();
0745 
0746       objectsInComb.push_back(obj0Index);
0747       objectsInComb.push_back(obj1Index);
0748 
0749       // if we get here all checks were successful for this combination
0750       // set the general result for evaluateCondition to "true"
0751 
0752       if (reqEtaPhiResult) {
0753         condResult = true;
0754         (combinationsInCond()).push_back(objectsInComb);
0755       }
0756     }
0757   }
0758 
0759   if (m_verbosity && m_isDebugEnabled && condResult) {
0760     LogTrace("L1GlobalTrigger") << (combinationsInCond()).size() << " correlation pair(s) ["
0761                                 << l1GtObjectEnumToString(cndObjTypeVec[0]) << ", "
0762                                 << l1GtObjectEnumToString(cndObjTypeVec[1]) << "] pass(es) the correlation condition.\n"
0763                                 << std::endl;
0764   }
0765 
0766   return condResult;
0767 }
0768 
0769 void L1GtCorrelationCondition::print(std::ostream &myCout) const {
0770   m_gtCorrelationTemplate->print(myCout);
0771   L1GtConditionEvaluation::print(myCout);
0772 }