Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // legacyGtHelper.cc
0002 // Authors: Alex Barbieri
0003 //
0004 // This is a collection of helper methods to make sure that
0005 // the objects passed to the legacy GT are using the proper
0006 // Et scales and eta coordinates.
0007 
0008 #include "L1Trigger/L1TCalorimeter/interface/legacyGtHelper.h"
0009 
0010 namespace l1t {
0011 
0012   void calibrateAndRankJets(CaloParamsHelper const *params,
0013                             const std::vector<l1t::Jet> *input,
0014                             std::vector<l1t::Jet> *output) {
0015     for (std::vector<l1t::Jet>::const_iterator itJet = input->begin(); itJet != input->end(); ++itJet) {
0016       unsigned int pt = itJet->hwPt();
0017       if (pt > ((1 << 10) - 1))
0018         pt = ((1 << 10) - 1);
0019       unsigned int eta = itJet->hwEta();
0020       if (eta > 10) {  // LUT is symmetric in eta. For eta>10 map to corresponding eta<10 bin
0021         int offset = 2 * (eta - 10) - 1;
0022         eta = eta - offset;
0023       }
0024       unsigned int lutAddress = (eta << 10) + pt;
0025 
0026       unsigned int rank = params->jetCalibrationLUT()->data(lutAddress);
0027 
0028       ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > ldummy(0, 0, 0, 0);
0029       l1t::Jet outJet(*&ldummy, rank, itJet->hwEta(), itJet->hwPhi(), itJet->hwQual());
0030       output->push_back(outJet);
0031     }
0032   }
0033 
0034   void calibrateAndRankTaus(CaloParamsHelper const *params,
0035                             const std::vector<l1t::Tau> *input,
0036                             std::vector<l1t::Tau> *output) {
0037     for (std::vector<l1t::Tau>::const_iterator itTau = input->begin(); itTau != input->end(); ++itTau) {
0038       unsigned int pt = itTau->hwPt();
0039       if (pt > ((1 << 10) - 1))
0040         pt = ((1 << 10) - 1);
0041       unsigned int eta = itTau->hwEta();
0042       unsigned int lutAddress = (eta << 10) + pt;
0043 
0044       unsigned int rank = params->tauCalibrationLUT()->data(lutAddress);
0045 
0046       ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > ldummy(0, 0, 0, 0);
0047       l1t::Tau outTau(*&ldummy, rank, itTau->hwEta(), itTau->hwPhi(), itTau->hwQual());
0048       output->push_back(outTau);
0049     }
0050   }
0051 
0052   void JetToGtEtaScales(CaloParamsHelper const *params,
0053                         const std::vector<l1t::Jet> *input,
0054                         std::vector<l1t::Jet> *output) {
0055     for (std::vector<l1t::Jet>::const_iterator itJet = input->begin(); itJet != input->end(); ++itJet) {
0056       unsigned newPhi = itJet->hwPhi();
0057       unsigned newEta = gtEta(itJet->hwEta());
0058 
0059       // jets with hwQual & 10 ==10 are "padding" jets from a sort, set their eta and phi
0060       // to the max value
0061       if ((itJet->hwQual() & 0x10) == 0x10) {
0062         newEta = 0x0;
0063         newPhi = 0x0;
0064       }
0065 
0066       ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > ldummy(0, 0, 0, 0);
0067 
0068       l1t::Jet gtJet(*&ldummy, itJet->hwPt(), newEta, newPhi, itJet->hwQual());
0069       output->push_back(gtJet);
0070     }
0071   }
0072 
0073   void JetToGtPtScales(CaloParamsHelper const *params,
0074                        const std::vector<l1t::Jet> *input,
0075                        std::vector<l1t::Jet> *output) {
0076     for (std::vector<l1t::Jet>::const_iterator itJet = input->begin(); itJet != input->end(); ++itJet) {
0077       uint16_t linPt = (uint16_t)itJet->hwPt();
0078       if (linPt > params->jetScale().linScaleMax())
0079         linPt = params->jetScale().linScaleMax();
0080       const uint16_t rankPt = params->jetScale().rank(linPt);
0081 
0082       ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > ldummy(0, 0, 0, 0);
0083 
0084       l1t::Jet gtJet(*&ldummy, rankPt, itJet->hwEta(), itJet->hwPhi(), itJet->hwQual());
0085       output->push_back(gtJet);
0086     }
0087   }
0088 
0089   void EGammaToGtScales(CaloParamsHelper const *params,
0090                         const std::vector<l1t::EGamma> *input,
0091                         std::vector<l1t::EGamma> *output) {
0092     for (std::vector<l1t::EGamma>::const_iterator itEGamma = input->begin(); itEGamma != input->end(); ++itEGamma) {
0093       unsigned newEta = gtEta(itEGamma->hwEta());
0094       unsigned newPhi = itEGamma->hwPhi();
0095       const uint16_t rankPt = (uint16_t)itEGamma->hwPt();  //max value?
0096 
0097       //hwQual &10 == 10 means that the object came from a sort and is padding
0098       if ((itEGamma->hwQual() & 0x10) == 0x10) {
0099         newEta = 0x0;
0100         newPhi = 0x0;
0101       }
0102 
0103       ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > ldummy(0, 0, 0, 0);
0104 
0105       l1t::EGamma gtEGamma(*&ldummy, rankPt, newEta, newPhi, itEGamma->hwQual(), itEGamma->hwIso());
0106       output->push_back(gtEGamma);
0107     }
0108   }
0109 
0110   void TauToGtEtaScales(CaloParamsHelper const *params,
0111                         const std::vector<l1t::Tau> *input,
0112                         std::vector<l1t::Tau> *output) {
0113     for (std::vector<l1t::Tau>::const_iterator itTau = input->begin(); itTau != input->end(); ++itTau) {
0114       unsigned newPhi = itTau->hwPhi();
0115       unsigned newEta = gtEta(itTau->hwEta());
0116 
0117       // taus with hwQual & 10 ==10 are "padding" jets from a sort, set their eta and phi
0118       // to the max value
0119       if ((itTau->hwQual() & 0x10) == 0x10) {
0120         newEta = 0x0;
0121         newPhi = 0x0;
0122       }
0123 
0124       ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > ldummy(0, 0, 0, 0);
0125 
0126       l1t::Tau gtTau(*&ldummy, itTau->hwPt(), newEta, newPhi, itTau->hwQual(), itTau->hwIso());
0127       output->push_back(gtTau);
0128     }
0129   }
0130 
0131   void TauToGtPtScales(CaloParamsHelper const *params,
0132                        const std::vector<l1t::Tau> *input,
0133                        std::vector<l1t::Tau> *output) {
0134     for (std::vector<l1t::Tau>::const_iterator itTau = input->begin(); itTau != input->end(); ++itTau) {
0135       uint16_t linPt = (uint16_t)itTau->hwPt();
0136       if (linPt > params->jetScale().linScaleMax())
0137         linPt = params->jetScale().linScaleMax();
0138       const uint16_t rankPt = params->jetScale().rank(linPt);
0139 
0140       ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > ldummy(0, 0, 0, 0);
0141 
0142       l1t::Tau gtTau(*&ldummy, rankPt, itTau->hwEta(), itTau->hwPhi(), itTau->hwQual(), itTau->hwIso());
0143       output->push_back(gtTau);
0144     }
0145   }
0146 
0147   void EtSumToGtScales(CaloParamsHelper const *params,
0148                        const std::vector<l1t::EtSum> *input,
0149                        std::vector<l1t::EtSum> *output) {
0150     for (std::vector<l1t::EtSum>::const_iterator itEtSum = input->begin(); itEtSum != input->end(); ++itEtSum) {
0151       uint16_t rankPt;
0152       // Hack for now to make sure they come out with the right scale
0153       //rankPt = params->jetScale().rank((uint16_t)itEtSum->hwPt());
0154       rankPt = (uint16_t)itEtSum->hwPt();
0155       if (EtSum::EtSumType::kMissingHt == itEtSum->getType()) {
0156         // if(rankPt > params->HtMissScale().linScaleMax()) rankPt = params->HtMissScale().linScaleMax();
0157         // params->HtMissScale().linScaleMax() always returns zero.  Hardcode 512 for now
0158 
0159         // comment out for mht/ht (already in GT scale)
0160         //if(rankPt > 512) rankPt = 512;
0161         //rankPt = params->HtMissScale().rank(rankPt*params->emScale().linearLsb());
0162       }
0163 
0164       ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > ldummy(0, 0, 0, 0);
0165 
0166       l1t::EtSum gtEtSum(*&ldummy, itEtSum->getType(), rankPt, 0, itEtSum->hwPhi(), itEtSum->hwQual());
0167 
0168       output->push_back(gtEtSum);
0169     }
0170   }
0171 
0172   const unsigned int gtEta(const unsigned int iEta) {
0173     unsigned rctEta = (iEta < 11 ? 10 - iEta : iEta - 11);
0174     return (((rctEta % 7) & 0x7) | (iEta < 11 ? 0x8 : 0));
0175   }
0176 }  // namespace l1t