Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-02 00:53:54

0001 /**
0002  * \class EnergySumCondition
0003  *
0004  *
0005  * Description: evaluation of a CondEnergySum condition.
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *
0010  *
0011  */
0012 
0013 // this class header
0014 #include "L1Trigger/L1TGlobal/interface/EnergySumCondition.h"
0015 
0016 // system include files
0017 #include <iostream>
0018 #include <iomanip>
0019 
0020 #include <string>
0021 #include <vector>
0022 #include <algorithm>
0023 
0024 // user include files
0025 //   base classes
0026 #include "L1Trigger/L1TGlobal/interface/EnergySumTemplate.h"
0027 #include "L1Trigger/L1TGlobal/interface/ConditionEvaluation.h"
0028 #include "DataFormats/L1Trigger/interface/L1Candidate.h"
0029 #include "L1Trigger/L1TGlobal/interface/GlobalBoard.h"
0030 
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0033 
0034 // constructors
0035 //     default
0036 l1t::EnergySumCondition::EnergySumCondition() : ConditionEvaluation() {
0037   //empty
0038 }
0039 
0040 //     from base template condition (from event setup usually)
0041 l1t::EnergySumCondition::EnergySumCondition(const GlobalCondition* eSumTemplate, const GlobalBoard* ptrGTB)
0042     : ConditionEvaluation(),
0043       m_gtEnergySumTemplate(static_cast<const EnergySumTemplate*>(eSumTemplate)),
0044       m_uGtB(ptrGTB)
0045 
0046 {
0047   // maximum number of objects received for the evaluation of the condition
0048   // energy sums are global quantities - one object per event
0049 
0050   m_condMaxNumberObjects = 1;
0051 }
0052 
0053 // copy constructor
0054 void l1t::EnergySumCondition::copy(const l1t::EnergySumCondition& cp) {
0055   m_gtEnergySumTemplate = cp.gtEnergySumTemplate();
0056   m_uGtB = cp.getuGtB();
0057 
0058   m_condMaxNumberObjects = cp.condMaxNumberObjects();
0059   m_condLastResult = cp.condLastResult();
0060   m_combinationsInCond = cp.getCombinationsInCond();
0061 
0062   m_verbosity = cp.m_verbosity;
0063 }
0064 
0065 l1t::EnergySumCondition::EnergySumCondition(const l1t::EnergySumCondition& cp) : ConditionEvaluation() { copy(cp); }
0066 
0067 // destructor
0068 l1t::EnergySumCondition::~EnergySumCondition() {
0069   // empty
0070 }
0071 
0072 // equal operator
0073 l1t::EnergySumCondition& l1t::EnergySumCondition::operator=(const l1t::EnergySumCondition& cp) {
0074   copy(cp);
0075   return *this;
0076 }
0077 
0078 // methods
0079 void l1t::EnergySumCondition::setGtEnergySumTemplate(const EnergySumTemplate* eSumTempl) {
0080   m_gtEnergySumTemplate = eSumTempl;
0081 }
0082 
0083 ///   set the pointer to uGT GlobalBoard
0084 void l1t::EnergySumCondition::setuGtB(const GlobalBoard* ptrGTB) { m_uGtB = ptrGTB; }
0085 
0086 // try all object permutations and check spatial correlations, if required
0087 const bool l1t::EnergySumCondition::evaluateCondition(const int bxEval) const {
0088   // number of trigger objects in the condition
0089   // in fact, there is only one object
0090   int iCondition = 0;
0091 
0092   // condition result condResult set to true if the energy sum
0093   // passes all requirements
0094   bool condResult = false;
0095 
0096   // store the indices of the calorimeter objects
0097   // from the combination evaluated in the condition
0098   SingleCombInCond objectsInComb;
0099 
0100   // clear the m_combinationsInCond vector
0101   (combinationsInCond()).clear();
0102 
0103   // clear the indices in the combination
0104   objectsInComb.clear();
0105 
0106   const BXVector<const l1t::EtSum*>* candVec = m_uGtB->getCandL1EtSum();
0107 
0108   // Look at objects in bx = bx + relativeBx
0109   int useBx = bxEval + m_gtEnergySumTemplate->condRelativeBx();
0110 
0111   // Fail condition if attempting to get Bx outside of range
0112   if ((useBx < candVec->getFirstBX()) || (useBx > candVec->getLastBX())) {
0113     return false;
0114   }
0115 
0116   // If no candidates, no use looking any further.
0117   int numberObjects = candVec->size(useBx);
0118   if (numberObjects < 1) {
0119     return false;
0120   }
0121 
0122   l1t::EtSum::EtSumType type;
0123   bool MissingEnergy = false;
0124   int centbit = 0;
0125   switch ((m_gtEnergySumTemplate->objectType())[0]) {
0126     case gtETM:
0127       type = l1t::EtSum::EtSumType::kMissingEt;
0128       MissingEnergy = true;
0129       break;
0130     case gtETT:
0131       type = l1t::EtSum::EtSumType::kTotalEt;
0132       MissingEnergy = false;
0133       break;
0134     case gtETTem:
0135       type = l1t::EtSum::EtSumType::kTotalEtEm;
0136       MissingEnergy = false;
0137       break;
0138     case gtHTM:
0139       type = l1t::EtSum::EtSumType::kMissingHt;
0140       MissingEnergy = true;
0141       break;
0142     case gtHTT:
0143       type = l1t::EtSum::EtSumType::kTotalHt;
0144       MissingEnergy = false;
0145       break;
0146     case gtETMHF:
0147       type = l1t::EtSum::EtSumType::kMissingEtHF;
0148       MissingEnergy = true;
0149       break;
0150     case gtHTMHF:
0151       type = l1t::EtSum::EtSumType::kMissingHtHF;
0152       MissingEnergy = true;
0153       break;
0154     case gtTowerCount:
0155       type = l1t::EtSum::EtSumType::kTowerCount;
0156       MissingEnergy = false;
0157       break;
0158     case gtMinBiasHFP0:
0159       type = l1t::EtSum::EtSumType::kMinBiasHFP0;
0160       MissingEnergy = false;
0161       break;
0162     case gtMinBiasHFM0:
0163       type = l1t::EtSum::EtSumType::kMinBiasHFM0;
0164       MissingEnergy = false;
0165       break;
0166     case gtMinBiasHFP1:
0167       type = l1t::EtSum::EtSumType::kMinBiasHFP1;
0168       MissingEnergy = false;
0169       break;
0170     case gtMinBiasHFM1:
0171       type = l1t::EtSum::EtSumType::kMinBiasHFM1;
0172       MissingEnergy = false;
0173       break;
0174     case gtAsymmetryEt:
0175       type = l1t::EtSum::EtSumType::kAsymEt;
0176       MissingEnergy = false;
0177       break;
0178     case gtAsymmetryHt:
0179       type = l1t::EtSum::EtSumType::kAsymHt;
0180       MissingEnergy = false;
0181       break;
0182     case gtAsymmetryEtHF:
0183       type = l1t::EtSum::EtSumType::kAsymEtHF;
0184       MissingEnergy = false;
0185       break;
0186     case gtAsymmetryHtHF:
0187       type = l1t::EtSum::EtSumType::kAsymHtHF;
0188       MissingEnergy = false;
0189       break;
0190     case gtCentrality0:
0191       centbit = 0;
0192       type = l1t::EtSum::EtSumType::kCentrality;
0193       MissingEnergy = false;
0194       break;
0195     case gtCentrality1:
0196       centbit = 1;
0197       type = l1t::EtSum::EtSumType::kCentrality;
0198       MissingEnergy = false;
0199       break;
0200     case gtCentrality2:
0201       centbit = 2;
0202       type = l1t::EtSum::EtSumType::kCentrality;
0203       MissingEnergy = false;
0204       break;
0205     case gtCentrality3:
0206       centbit = 3;
0207       type = l1t::EtSum::EtSumType::kCentrality;
0208       MissingEnergy = false;
0209       break;
0210     case gtCentrality4:
0211       centbit = 4;
0212       type = l1t::EtSum::EtSumType::kCentrality;
0213       MissingEnergy = false;
0214       break;
0215     case gtCentrality5:
0216       centbit = 5;
0217       type = l1t::EtSum::EtSumType::kCentrality;
0218       MissingEnergy = false;
0219       break;
0220     case gtCentrality6:
0221       centbit = 6;
0222       type = l1t::EtSum::EtSumType::kCentrality;
0223       MissingEnergy = false;
0224       break;
0225     case gtCentrality7:
0226       centbit = 7;
0227       type = l1t::EtSum::EtSumType::kCentrality;
0228       MissingEnergy = false;
0229       break;
0230     case gtZDCP:
0231       type = l1t::EtSum::EtSumType::kZDCP;
0232       MissingEnergy = false;
0233       break;
0234     case gtZDCM:
0235       type = l1t::EtSum::EtSumType::kZDCM;
0236       MissingEnergy = false;
0237       break;
0238     default:
0239       edm::LogError("L1TGlobal")
0240           << "\n  Error: "
0241           << "Unmatched object type from template to EtSumType, (m_gtEnergySumTemplate->objectType())[0] = "
0242           << (m_gtEnergySumTemplate->objectType())[0] << std::endl;
0243       type = l1t::EtSum::EtSumType::kTotalEt;
0244       break;
0245   }
0246 
0247   // get energy, phi (ETM and HTM) and overflow for the trigger object
0248   unsigned int candEt = 0;
0249   unsigned int candPhi = 0;
0250   bool candOverflow = false;
0251   for (int iEtSum = 0; iEtSum < numberObjects; ++iEtSum) {
0252     l1t::EtSum cand = *(candVec->at(useBx, iEtSum));
0253     if (cand.getType() != type)
0254       continue;
0255     candEt = cand.hwPt();
0256     candPhi = cand.hwPhi();
0257   }
0258 
0259   const EnergySumTemplate::ObjectParameter objPar = (*(m_gtEnergySumTemplate->objectParameter()))[iCondition];
0260 
0261   // check energy threshold and overflow
0262   // overflow evaluation:
0263   //     for condGEq >=
0264   //         candidate overflow true -> condition true
0265   //         candidate overflow false -> evaluate threshold
0266   //     for condGEq =
0267   //         candidate overflow true -> condition false
0268   //         candidate overflow false -> evaluate threshold
0269   //
0270 
0271   bool condGEqVal = m_gtEnergySumTemplate->condGEq();
0272 
0273   if (type == l1t::EtSum::EtSumType::kCentrality) {
0274     bool myres = checkBit(candEt, centbit);
0275     //std::cout << "CCLC:  Checking bit " << centbit << "\tResult is: " << myres << std::endl;
0276     if (!myres) {
0277       LogDebug("L1TGlobal") << "\t\t l1t::EtSum failed Centrality bit" << std::endl;
0278       return false;
0279     }
0280   } else if (type == l1t::EtSum::EtSumType::kZDCP || type == l1t::EtSum::EtSumType::kZDCM) {
0281     return false;
0282   } else {
0283     // check energy threshold
0284     if (!checkThreshold(objPar.etLowThreshold, objPar.etHighThreshold, candEt, condGEqVal)) {
0285       LogDebug("L1TGlobal") << "\t\t l1t::EtSum failed checkThreshold" << std::endl;
0286       return false;
0287     }
0288 
0289     if (!condGEqVal && candOverflow)
0290       return false;
0291 
0292     // for ETM and HTM check phi also
0293     // for overflow, the phi requirements are ignored
0294     if (MissingEnergy) {
0295       // check phi
0296       if (!checkRangePhi(
0297               candPhi, objPar.phiWindow1Lower, objPar.phiWindow1Upper, objPar.phiWindow2Lower, objPar.phiWindow2Upper)) {
0298         LogDebug("L1TGlobal") << "\t\t l1t::EtSum failed checkRange(phi)" << std::endl;
0299         return false;
0300       }
0301     }
0302   }
0303 
0304   // index is always zero, as they are global quantities (there is only one object)
0305   int indexObj = 0;
0306 
0307   objectsInComb.push_back(indexObj);
0308   (combinationsInCond()).push_back(objectsInComb);
0309 
0310   // if we get here all checks were successfull for this combination
0311   // set the general result for evaluateCondition to "true"
0312 
0313   condResult = true;
0314   return condResult;
0315 }
0316 
0317 void l1t::EnergySumCondition::print(std::ostream& myCout) const {
0318   m_gtEnergySumTemplate->print(myCout);
0319   ConditionEvaluation::print(myCout);
0320 }