File indexing completed on 2023-03-17 11:11:58
0001
0002
0003
0004
0005
0006
0007
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "L1Trigger/L1TCalorimeter/interface/Stage2Layer2DemuxTauAlgoFirmware.h"
0010
0011 #include "L1Trigger/L1TCalorimeter/interface/CaloParamsHelper.h"
0012
0013 #include <vector>
0014 #include <algorithm>
0015 #include "L1Trigger/L1TCalorimeter/interface/BitonicSort.h"
0016
0017 namespace l1t {
0018 inline bool operator>(l1t::Tau& a, l1t::Tau& b) {
0019 if (a.pt() == b.pt()) {
0020 if (a.hwPhi() == b.hwPhi()) {
0021 return a.hwEta() > b.hwEta();
0022 } else {
0023 return a.hwPhi() > b.hwPhi();
0024 }
0025
0026 } else {
0027 return a.pt() > b.pt();
0028 }
0029 }
0030 }
0031
0032 l1t::Stage2Layer2DemuxTauAlgoFirmwareImp1::Stage2Layer2DemuxTauAlgoFirmwareImp1(CaloParamsHelper const* params)
0033 : params_(params) {}
0034
0035 l1t::Stage2Layer2DemuxTauAlgoFirmwareImp1::~Stage2Layer2DemuxTauAlgoFirmwareImp1() {}
0036
0037 void l1t::Stage2Layer2DemuxTauAlgoFirmwareImp1::processEvent(const std::vector<l1t::Tau>& inputTaus,
0038 std::vector<l1t::Tau>& outputTaus) {
0039 vector<pair<int, double> > etaGT;
0040 etaGT.reserve(115);
0041 for (int i = 0; i < 115; i++)
0042 etaGT.push_back(make_pair(i, i * (0.087 / 2.)));
0043
0044 vector<pair<int, double> > phiGT;
0045 phiGT.reserve(145);
0046 for (int i = 0; i < 145; i++)
0047 phiGT.push_back(make_pair(i, i * (M_PI / 72.)));
0048 phiGT[144] = make_pair(0, 2 * M_PI);
0049
0050 outputTaus = inputTaus;
0051
0052 for (auto& tau : outputTaus) {
0053 double eta = tau.eta();
0054 double phi = tau.phi();
0055 if (phi < 0)
0056 phi += 2 * M_PI;
0057
0058 double minDistance = 99999.;
0059 pair<int, double> closestPoint = make_pair(0, 0.);
0060
0061 for (const auto& p : etaGT) {
0062 double distance = abs(abs(eta) - p.second);
0063 if (distance < minDistance) {
0064 closestPoint = p;
0065 minDistance = distance;
0066 }
0067 }
0068
0069 int hwEta_GT = (eta > 0) ? closestPoint.first : -closestPoint.first;
0070 double eta_GT = (eta > 0) ? closestPoint.second : -closestPoint.second;
0071
0072 minDistance = 99999.;
0073 closestPoint = make_pair(0, 0.);
0074
0075 for (const auto& p : phiGT) {
0076 double distance = abs(phi - p.second);
0077 if (distance < minDistance) {
0078 closestPoint = p;
0079 minDistance = distance;
0080 }
0081 }
0082
0083 int hwPhi_GT = closestPoint.first;
0084 double phi_GT = closestPoint.second;
0085
0086 tau.setHwEta(hwEta_GT);
0087 tau.setHwPhi(hwPhi_GT);
0088
0089
0090 if (tau.hwPt() > 511)
0091 tau.setHwPt(511);
0092
0093 math::PtEtaPhiMLorentzVector tauP4(tau.hwPt() * params_->egLsb(), eta_GT, phi_GT, 0.);
0094 tau.setP4(tauP4);
0095 }
0096
0097
0098 std::vector<l1t::Tau>::iterator start_ = outputTaus.begin();
0099 std::vector<l1t::Tau>::iterator end_ = outputTaus.end();
0100 BitonicSort<l1t::Tau>(down, start_, end_);
0101 }