File indexing completed on 2024-04-06 12:21:32
0001 #include "L1Trigger/Phase2L1ParticleFlow/interface/pf/pfalgo_common_ref.h"
0002 #include "L1Trigger/Phase2L1ParticleFlow/interface/dbgPrintf.h"
0003
0004 #include <cmath>
0005 #include <cstdio>
0006
0007 #ifdef CMSSW_GIT_HASH
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #endif
0011
0012 l1ct::PFAlgoEmulatorBase::~PFAlgoEmulatorBase() {}
0013
0014 void l1ct::PFAlgoEmulatorBase::loadPtErrBins(
0015 unsigned int nbins, const float absetas[], const float scales[], const float offs[], bool verbose) {
0016 ptErrBins_.resize(nbins);
0017 for (unsigned int i = 0; i < nbins; ++i) {
0018 ptErrBins_[i].abseta = Scales::makeGlbEta(absetas[i]);
0019 ptErrBins_[i].scale = scales[i];
0020 ptErrBins_[i].offs = offs[i];
0021
0022 if (verbose || debug_)
0023 dbgPrintf("loadPtErrBins: #%d: abseta %5.3f -> %8d, scale %7.4f -> %7.4f, offs %7.3f -> %7.4f\n",
0024 i,
0025 absetas[i],
0026 ptErrBins_[i].abseta.to_int(),
0027 scales[i],
0028 ptErrBins_[i].scale.to_float(),
0029 offs[i],
0030 ptErrBins_[i].offs.to_float());
0031 }
0032 }
0033
0034 #ifdef CMSSW_GIT_HASH
0035 void l1ct::PFAlgoEmulatorBase::loadPtErrBins(const edm::ParameterSet &iConfig) {
0036 const edm::ParameterSet &resol = iConfig.getParameter<edm::ParameterSet>("caloResolution");
0037 std::vector<float> absetas, scales, offs;
0038 for (auto &v : resol.getParameter<std::vector<double>>("etaBins"))
0039 absetas.push_back(v);
0040 for (auto &v : resol.getParameter<std::vector<double>>("scale"))
0041 scales.push_back(v);
0042 for (auto &v : resol.getParameter<std::vector<double>>("offset"))
0043 offs.push_back(v);
0044 loadPtErrBins(absetas.size(), &absetas[0], &scales[0], &offs[0]);
0045 }
0046
0047 void l1ct::PFAlgoEmulatorBase::addCaloResolutionParameterSetDescription(edm::ParameterSetDescription &to) {
0048 edm::ParameterSetDescription description;
0049 description.add<std::vector<double>>("etaBins");
0050 description.add<std::vector<double>>("offset");
0051 description.add<std::vector<double>>("scale");
0052 to.add<edm::ParameterSetDescription>("caloResolution", description);
0053 }
0054
0055 #endif
0056
0057 l1ct::pt_t l1ct::PFAlgoEmulatorBase::ptErr_ref(const l1ct::PFRegionEmu ®ion, const l1ct::TkObjEmu &track) const {
0058 glbeta_t abseta = region.hwGlbEta(track.hwEta);
0059 if (abseta < 0)
0060 abseta = -abseta;
0061
0062 ptErrScale_t scale = 0.3125;
0063 ptErrOffs_t offs = 7.0;
0064 for (const auto &bin : ptErrBins_) {
0065 if (abseta < bin.abseta) {
0066 scale = bin.scale;
0067 offs = bin.offs;
0068 break;
0069 }
0070 }
0071
0072 pt_t ptErr = track.hwPt * scale + offs;
0073 if (ptErr > track.hwPt)
0074 ptErr = track.hwPt;
0075 return ptErr;
0076 }
0077
0078 void l1ct::PFAlgoEmulatorBase::pfalgo_mu_ref(const PFInputRegion &in, OutputRegion &out, std::vector<int> &iMu) const {
0079
0080 unsigned int nTRACK = std::min<unsigned>(nTRACK_, in.track.size());
0081 unsigned int nMU = std::min<unsigned>(nMU_, in.muon.size());
0082 out.pfmuon.resize(nMU);
0083 iMu.resize(nTRACK);
0084 for (unsigned int ipf = 0; ipf < nMU; ++ipf)
0085 out.pfmuon[ipf].clear();
0086 for (unsigned int it = 0; it < nTRACK; ++it)
0087 iMu[it] = -1;
0088
0089
0090 for (unsigned int im = 0; im < nMU; ++im) {
0091 if (in.muon[im].hwPt > 0) {
0092 int ibest = -1;
0093 pt_t dptmin = (in.muon[im].hwPt << 1) + in.muon[im].hwPt;
0094 for (unsigned int it = 0; it < nTRACK; ++it) {
0095 if (!in.track[it].isPFLoose())
0096 continue;
0097 unsigned int dr = dr2_int(in.muon[im].hwEta, in.muon[im].hwPhi, in.track[it].hwEta, in.track[it].hwPhi);
0098
0099 if (dr < dR2MAX_TK_MU_) {
0100 dpt_t dpt = (dpt_t(in.track[it].hwPt) - dpt_t(in.muon[im].hwPt));
0101 pt_t absdpt = dpt >= 0 ? pt_t(dpt) : pt_t(-dpt);
0102 if (absdpt < dptmin) {
0103 dptmin = absdpt;
0104 ibest = it;
0105 }
0106 }
0107 }
0108 if (ibest != -1) {
0109 iMu[ibest] = im;
0110 fillPFCand(in.track[ibest], out.pfmuon[im], true, false);
0111
0112 out.pfmuon[im].srcMu = in.muon[im].src;
0113 if (debug_)
0114 dbgPrintf("FW \t muon %3d linked to track %3d \n", im, ibest);
0115 } else {
0116 if (debug_)
0117 dbgPrintf("FW \t muon %3d not linked to any track\n", im);
0118 }
0119 }
0120 }
0121 }
0122
0123 void l1ct::PFAlgoEmulatorBase::fillPFCand(const TkObjEmu &track, PFChargedObjEmu &pf, bool isMu, bool isEle) const {
0124 assert(!(isEle && isMu));
0125 pf.hwPt = track.hwPt;
0126 pf.hwEta = track.hwEta;
0127 pf.hwPhi = track.hwPhi;
0128 pf.hwDEta = track.hwDEta;
0129 pf.hwDPhi = track.hwDPhi;
0130 pf.hwZ0 = track.hwZ0;
0131 pf.hwDxy = track.hwDxy;
0132 pf.hwTkQuality = track.hwQuality;
0133 if (isMu) {
0134 pf.hwId = ParticleID::mkMuon(track.hwCharge);
0135 } else if (isEle) {
0136 pf.hwId = ParticleID::mkElectron(track.hwCharge);
0137 } else {
0138 pf.hwId = ParticleID::mkChHad(track.hwCharge);
0139 }
0140
0141 pf.srcTrack = track.src;
0142 }
0143
0144 void l1ct::PFAlgoEmulatorBase::fillPFCand(const HadCaloObjEmu &calo, PFNeutralObjEmu &pf, bool isPhoton) const {
0145 pf.hwPt = calo.hwPt;
0146 pf.hwEta = calo.hwEta;
0147 pf.hwPhi = calo.hwPhi;
0148 pf.hwId = isPhoton ? ParticleID::PHOTON : ParticleID::HADZERO;
0149 pf.hwEmPt = calo.hwEmPt;
0150 pf.hwEmID = calo.hwEmID;
0151 pf.hwPUID = 0;
0152
0153 pf.srcCluster = calo.src;
0154 }
0155
0156 void l1ct::PFAlgoEmulatorBase::fillPFCand(const EmCaloObjEmu &calo, PFNeutralObjEmu &pf, bool isPhoton) const {
0157 pf.hwPt = calo.hwPt;
0158 pf.hwEta = calo.hwEta;
0159 pf.hwPhi = calo.hwPhi;
0160 pf.hwId = isPhoton ? ParticleID::PHOTON : ParticleID::HADZERO;
0161 pf.hwEmPt = calo.hwPt;
0162 pf.hwEmID = calo.hwEmID;
0163 pf.hwPUID = 0;
0164
0165 pf.srcCluster = calo.src;
0166 }