Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:51

0001 ///step03
0002 /// \class l1t::Stage1Layer2EGammaAlgorithm
0003 ///
0004 /// Description: interface for MP firmware
0005 ///
0006 /// Implementation:
0007 ///
0008 /// \author: Kalanand Mishra - Fermilab
0009 ///
0010 
0011 #include "L1Trigger/L1TCalorimeter/interface/Stage1Layer2EGammaAlgorithmImp.h"
0012 #include "DataFormats/L1TCalorimeter/interface/CaloRegion.h"
0013 #include "DataFormats/L1CaloTrigger/interface/L1CaloRegionDetId.h"
0014 #include "L1Trigger/L1TCalorimeter/interface/PUSubtractionMethods.h"
0015 #include "L1Trigger/L1TCalorimeter/interface/HardwareSortingMethods.h"
0016 #include "L1Trigger/L1TCalorimeter/interface/JetFinderMethods.h"
0017 #include "L1Trigger/L1TCalorimeter/interface/legacyGtHelper.h"
0018 
0019 #include <bitset>
0020 
0021 using namespace std;
0022 using namespace l1t;
0023 
0024 Stage1Layer2EGammaAlgorithmImpHW::Stage1Layer2EGammaAlgorithmImpHW(CaloParamsHelper const* params) : params_(params) {}
0025 
0026 void l1t::Stage1Layer2EGammaAlgorithmImpHW::processEvent(const std::vector<l1t::CaloEmCand>& EMCands,
0027                                                          const std::vector<l1t::CaloRegion>& regions,
0028                                                          const std::vector<l1t::Jet>* jets,
0029                                                          std::vector<l1t::EGamma>* egammas) {
0030   std::vector<l1t::CaloRegion> subRegions;
0031   std::vector<l1t::EGamma> preSortEGammas;
0032   std::vector<l1t::EGamma> preGtEGammas;
0033 
0034   //Region Correction will return uncorrected subregions if
0035   //regionPUSType is set to None in the config
0036   RegionCorrection(regions, &subRegions, params_);
0037 
0038   // ----- need to cluster jets in order to compute jet isolation ----
0039   std::vector<l1t::Jet>* unCorrJets = new std::vector<l1t::Jet>();
0040   TwelveByTwelveFinder(0, &subRegions, unCorrJets);
0041 
0042   for (CaloEmCandBxCollection::const_iterator egCand = EMCands.begin(); egCand != EMCands.end(); egCand++) {
0043     int eg_et = egCand->hwPt();
0044     int eg_eta = egCand->hwEta();
0045     int eg_phi = egCand->hwPhi();
0046     int index = (egCand->hwIso() * 4 + egCand->hwQual());
0047 
0048     ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > egLorentz(0, 0, 0, 0);
0049 
0050     int isoFlag = 0;
0051     int ijet_pt = AssociatedJetPt(eg_eta, eg_phi, unCorrJets);
0052     bool isinBarrel = (eg_eta >= 7 && eg_eta <= 14);
0053     unsigned int lutAddress = isoLutIndex(eg_et, ijet_pt);
0054 
0055     // Combined Barrel/Endcap LUT uses upper bit to indicate Barrel / Endcap:
0056     enum { MAX_LUT_ADDRESS = 0x7fff };
0057     enum { LUT_BARREL_OFFSET = 0x0, LUT_ENDCAP_OFFSET = 0x8000 };
0058     enum { LUT_RCT_OFFSET = 0x10000 };
0059 
0060     unsigned int rct_offset = 0;
0061     if (egCand->hwIso())
0062       rct_offset = LUT_RCT_OFFSET;
0063 
0064     if (eg_et > 0) {
0065       if (lutAddress > MAX_LUT_ADDRESS)
0066         lutAddress = MAX_LUT_ADDRESS;
0067 
0068       if (isinBarrel) {
0069         isoFlag = params_->egIsolationLUT()->data(LUT_BARREL_OFFSET + rct_offset + lutAddress);
0070       } else {
0071         isoFlag = params_->egIsolationLUT()->data(LUT_ENDCAP_OFFSET + rct_offset + lutAddress);
0072       }
0073     }
0074 
0075     l1t::EGamma theEG(*&egLorentz, eg_et, eg_eta, eg_phi, index, isoFlag);
0076     preSortEGammas.push_back(theEG);
0077   }
0078 
0079   SortEGammas(&preSortEGammas, &preGtEGammas);
0080 
0081   EGammaToGtScales(params_, &preGtEGammas, egammas);
0082 }
0083 
0084 //ieta =-28, nrTowers 0 is 0, increases to ieta28, nrTowers=kNrTowersInSum
0085 unsigned l1t::Stage1Layer2EGammaAlgorithmImpHW::isoLutIndex(unsigned int egPt, unsigned int jetPt) const {
0086   const unsigned int nbitsEG = 6;  // number of bits used for EG bins in LUT file (needed for left shift operation)
0087   //  const unsigned int nbitsJet=9; // not used but here for info  number of bits used for Jet bins in LUT file
0088 
0089   //jetPt &= 511; // Take only the LSB 9 bits to match firmware.
0090   if (jetPt > 511)
0091     jetPt = 511;
0092   unsigned int address = (jetPt << nbitsEG) + egPt;
0093   return address;
0094 }
0095 
0096 int l1t::Stage1Layer2EGammaAlgorithmImpHW::AssociatedJetPt(int ieta,
0097                                                            int iphi,
0098                                                            const std::vector<l1t::Jet>* jets) const {
0099   int pt = 0;
0100 
0101   for (JetBxCollection::const_iterator itJet = jets->begin(); itJet != jets->end(); ++itJet) {
0102     int jetEta = itJet->hwEta();
0103     int jetPhi = itJet->hwPhi();
0104     if ((jetEta == ieta) && (jetPhi == iphi)) {
0105       pt = itJet->hwPt();
0106       break;
0107     }
0108   }
0109 
0110   // set output
0111   return pt;
0112 }