Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 gtTowerCount:
0151       type = l1t::EtSum::EtSumType::kTowerCount;
0152       MissingEnergy = false;
0153       break;
0154     case gtMinBiasHFP0:
0155       type = l1t::EtSum::EtSumType::kMinBiasHFP0;
0156       MissingEnergy = false;
0157       break;
0158     case gtMinBiasHFM0:
0159       type = l1t::EtSum::EtSumType::kMinBiasHFM0;
0160       MissingEnergy = false;
0161       break;
0162     case gtMinBiasHFP1:
0163       type = l1t::EtSum::EtSumType::kMinBiasHFP1;
0164       MissingEnergy = false;
0165       break;
0166     case gtMinBiasHFM1:
0167       type = l1t::EtSum::EtSumType::kMinBiasHFM1;
0168       MissingEnergy = false;
0169       break;
0170     case gtAsymmetryEt:
0171       type = l1t::EtSum::EtSumType::kAsymEt;
0172       MissingEnergy = false;
0173       break;
0174     case gtAsymmetryHt:
0175       type = l1t::EtSum::EtSumType::kAsymHt;
0176       MissingEnergy = false;
0177       break;
0178     case gtAsymmetryEtHF:
0179       type = l1t::EtSum::EtSumType::kAsymEtHF;
0180       MissingEnergy = false;
0181       break;
0182     case gtAsymmetryHtHF:
0183       type = l1t::EtSum::EtSumType::kAsymHtHF;
0184       MissingEnergy = false;
0185       break;
0186     case gtCentrality0:
0187       centbit = 0;
0188       type = l1t::EtSum::EtSumType::kCentrality;
0189       MissingEnergy = false;
0190       break;
0191     case gtCentrality1:
0192       centbit = 1;
0193       type = l1t::EtSum::EtSumType::kCentrality;
0194       MissingEnergy = false;
0195       break;
0196     case gtCentrality2:
0197       centbit = 2;
0198       type = l1t::EtSum::EtSumType::kCentrality;
0199       MissingEnergy = false;
0200       break;
0201     case gtCentrality3:
0202       centbit = 3;
0203       type = l1t::EtSum::EtSumType::kCentrality;
0204       MissingEnergy = false;
0205       break;
0206     case gtCentrality4:
0207       centbit = 4;
0208       type = l1t::EtSum::EtSumType::kCentrality;
0209       MissingEnergy = false;
0210       break;
0211     case gtCentrality5:
0212       centbit = 5;
0213       type = l1t::EtSum::EtSumType::kCentrality;
0214       MissingEnergy = false;
0215       break;
0216     case gtCentrality6:
0217       centbit = 6;
0218       type = l1t::EtSum::EtSumType::kCentrality;
0219       MissingEnergy = false;
0220       break;
0221     case gtCentrality7:
0222       centbit = 7;
0223       type = l1t::EtSum::EtSumType::kCentrality;
0224       MissingEnergy = false;
0225       break;
0226     default:
0227       edm::LogError("L1TGlobal")
0228           << "\n  Error: "
0229           << "Unmatched object type from template to EtSumType, (m_gtEnergySumTemplate->objectType())[0] = "
0230           << (m_gtEnergySumTemplate->objectType())[0] << std::endl;
0231       type = l1t::EtSum::EtSumType::kTotalEt;
0232       break;
0233   }
0234 
0235   // get energy, phi (ETM and HTM) and overflow for the trigger object
0236   unsigned int candEt = 0;
0237   unsigned int candPhi = 0;
0238   bool candOverflow = false;
0239   for (int iEtSum = 0; iEtSum < numberObjects; ++iEtSum) {
0240     l1t::EtSum cand = *(candVec->at(useBx, iEtSum));
0241     if (cand.getType() != type)
0242       continue;
0243     candEt = cand.hwPt();
0244     candPhi = cand.hwPhi();
0245   }
0246 
0247   const EnergySumTemplate::ObjectParameter objPar = (*(m_gtEnergySumTemplate->objectParameter()))[iCondition];
0248 
0249   // check energy threshold and overflow
0250   // overflow evaluation:
0251   //     for condGEq >=
0252   //         candidate overflow true -> condition true
0253   //         candidate overflow false -> evaluate threshold
0254   //     for condGEq =
0255   //         candidate overflow true -> condition false
0256   //         candidate overflow false -> evaluate threshold
0257   //
0258 
0259   bool condGEqVal = m_gtEnergySumTemplate->condGEq();
0260 
0261   if (type == l1t::EtSum::EtSumType::kCentrality) {
0262     bool myres = checkBit(candEt, centbit);
0263     //std::cout << "CCLC:  Checking bit " << centbit << "\tResult is: " << myres << std::endl;
0264     if (!myres) {
0265       LogDebug("L1TGlobal") << "\t\t l1t::EtSum failed Centrality bit" << std::endl;
0266       return false;
0267     }
0268   } else {
0269     // check energy threshold
0270     if (!checkThreshold(objPar.etLowThreshold, objPar.etHighThreshold, candEt, condGEqVal)) {
0271       LogDebug("L1TGlobal") << "\t\t l1t::EtSum failed checkThreshold" << std::endl;
0272       return false;
0273     }
0274 
0275     if (!condGEqVal && candOverflow)
0276       return false;
0277 
0278     // for ETM and HTM check phi also
0279     // for overflow, the phi requirements are ignored
0280     if (MissingEnergy) {
0281       // check phi
0282       if (!checkRangePhi(
0283               candPhi, objPar.phiWindow1Lower, objPar.phiWindow1Upper, objPar.phiWindow2Lower, objPar.phiWindow2Upper)) {
0284         LogDebug("L1TGlobal") << "\t\t l1t::EtSum failed checkRange(phi)" << std::endl;
0285         return false;
0286       }
0287     }
0288   }
0289 
0290   // index is always zero, as they are global quantities (there is only one object)
0291   int indexObj = 0;
0292 
0293   objectsInComb.push_back(indexObj);
0294   (combinationsInCond()).push_back(objectsInComb);
0295 
0296   // if we get here all checks were successfull for this combination
0297   // set the general result for evaluateCondition to "true"
0298 
0299   condResult = true;
0300   return condResult;
0301 }
0302 
0303 void l1t::EnergySumCondition::print(std::ostream& myCout) const {
0304   m_gtEnergySumTemplate->print(myCout);
0305   ConditionEvaluation::print(myCout);
0306 }