File indexing completed on 2024-04-06 12:21:26
0001 #ifndef PFALGO_COMMON_REF_H
0002 #define PFALGO_COMMON_REF_H
0003
0004 #include "DataFormats/L1TParticleFlow/interface/layer1_emulator.h"
0005 #include "pfalgo_types.h"
0006
0007 #include <algorithm>
0008 #include <vector>
0009
0010 namespace edm {
0011 class ParameterSet;
0012 class ParameterSetDescription;
0013 }
0014
0015 namespace l1ct {
0016
0017 class PFAlgoEmulatorBase {
0018 public:
0019 PFAlgoEmulatorBase(unsigned int nTrack,
0020 unsigned int nCalo,
0021 unsigned int nMu,
0022 unsigned int nSelCalo,
0023 unsigned int dR2Max_Tk_Mu,
0024 unsigned int dR2Max_Tk_Calo,
0025 pt_t tk_MaxInvPt_Loose,
0026 pt_t tk_MaxInvPt_Tight)
0027 : nTRACK_(nTrack),
0028 nCALO_(nCalo),
0029 nMU_(nMu),
0030 nSELCALO_(nSelCalo),
0031 dR2MAX_TK_MU_(dR2Max_Tk_Mu),
0032 dR2MAX_TK_CALO_(dR2Max_Tk_Calo),
0033 tk_MAXINVPT_LOOSE_(tk_MaxInvPt_Loose),
0034 tk_MAXINVPT_TIGHT_(tk_MaxInvPt_Tight),
0035 debug_(false) {}
0036
0037 virtual ~PFAlgoEmulatorBase();
0038
0039 void loadPtErrBins(
0040 unsigned int nbins, const float absetas[], const float scales[], const float offs[], bool verbose = false);
0041 void loadPtErrBins(const edm::ParameterSet& iConfig);
0042 static void addCaloResolutionParameterSetDescription(edm::ParameterSetDescription& to);
0043
0044 void setDebug(bool debug = true) { debug_ = debug; }
0045
0046 virtual void run(const PFInputRegion& in, OutputRegion& out) const = 0;
0047
0048
0049 virtual void mergeNeutrals(OutputRegion& out) const = 0;
0050
0051 protected:
0052
0053 unsigned int nTRACK_, nCALO_, nMU_;
0054 unsigned int nSELCALO_;
0055 unsigned int dR2MAX_TK_MU_;
0056 unsigned int dR2MAX_TK_CALO_;
0057 pt_t tk_MAXINVPT_LOOSE_, tk_MAXINVPT_TIGHT_;
0058
0059 struct ptErrBin {
0060 glbeta_t abseta;
0061 ptErrScale_t scale;
0062 ptErrOffs_t offs;
0063 };
0064 std::vector<ptErrBin> ptErrBins_;
0065
0066 bool debug_;
0067
0068
0069 template <typename COV>
0070 int best_match_with_pt_ref(int dR2MAX, const COV& calo, const TkObjEmu& track, const pt_t& trackCaloPtErr) const;
0071
0072 template <typename TV>
0073 void ptsort_ref(int nIn, int nOut, const TV& in, TV& out) const;
0074
0075 pt_t ptErr_ref(const PFRegionEmu& region, const TkObjEmu& track) const;
0076
0077 void pfalgo_mu_ref(const PFInputRegion& in, OutputRegion& out, std::vector<int>& iMu) const;
0078
0079 void fillPFCand(const TkObjEmu& track, PFChargedObjEmu& pf, bool isMu, bool isEle) const;
0080 void fillPFCand(const HadCaloObjEmu& calo, PFNeutralObjEmu& pf, bool isPhoton = false) const;
0081 void fillPFCand(const EmCaloObjEmu& calo, PFNeutralObjEmu& pf, bool isPhoton = true) const;
0082 };
0083
0084 }
0085
0086
0087 template <typename COV>
0088 int l1ct::PFAlgoEmulatorBase::best_match_with_pt_ref(int dR2MAX,
0089 const COV& calo,
0090 const TkObjEmu& track,
0091 const pt_t& trackCaloPtErr) const {
0092 pt_t caloPtMin = track.hwPt - 2 * trackCaloPtErr;
0093 if (caloPtMin < 0)
0094 caloPtMin = 0;
0095 float ptErr = std::max<float>(Scales::INTPT_LSB, Scales::floatPt(trackCaloPtErr));
0096 ptscale_t dptscale = float(dR2MAX) / (ptErr * ptErr);
0097 int dr2min = 0, ibest = -1;
0098 for (int ic = 0, nCAL = calo.size(); ic < nCAL; ++ic) {
0099 if (calo[ic].hwPt <= caloPtMin)
0100 continue;
0101 int dr2 = dr2_int(track.hwEta, track.hwPhi, calo[ic].hwEta, calo[ic].hwPhi);
0102 if (dr2 >= dR2MAX)
0103 continue;
0104 pt_t dpt = track.hwPt - calo[ic].hwPt;
0105 dr2 += int((dpt * dpt) * dptscale);
0106 if (ibest == -1 || dr2 < dr2min) {
0107 dr2min = dr2;
0108 ibest = ic;
0109 }
0110 }
0111 return ibest;
0112 }
0113
0114 template <typename TV>
0115 void l1ct::PFAlgoEmulatorBase::ptsort_ref(int nIn, int nOut, const TV& in, TV& out) const {
0116 out.resize(nOut);
0117 for (int iout = 0; iout < nOut; ++iout) {
0118 out[iout].clear();
0119 }
0120 for (int it = 0; it < nIn; ++it) {
0121 for (int iout = 0; iout < nOut; ++iout) {
0122 if (in[it].hwPt >= out[iout].hwPt) {
0123 for (int i2 = nOut - 1; i2 > iout; --i2) {
0124 out[i2] = out[i2 - 1];
0125 }
0126 out[iout] = in[it];
0127 break;
0128 }
0129 }
0130 }
0131 }
0132
0133 #endif