File indexing completed on 2025-06-11 03:00:11
0001 #ifndef LINPUPPI_REF_H
0002 #define LINPUPPI_REF_H
0003
0004 #include "DataFormats/L1TParticleFlow/interface/layer1_emulator.h"
0005 #include "linpuppi_bits.h"
0006
0007 #include <vector>
0008 #include "L1Trigger/Phase2L1ParticleFlow/interface/NNVtxAssoc.h"
0009 #include <memory>
0010
0011 namespace edm {
0012 class ParameterSet;
0013 class ParameterSetDescription;
0014 }
0015
0016 namespace l1ct {
0017 #ifdef CMSSW_GIT_HASH
0018 const bool withinCMSSW_ = true;
0019 #else
0020 const bool withinCMSSW_ = false;
0021 #endif
0022
0023 class LinPuppiEmulator {
0024 public:
0025 enum class SortAlgo { Insertion, BitonicRUFL, BitonicHLS, Hybrid, FoldedHybrid };
0026
0027 LinPuppiEmulator(unsigned int nTrack,
0028 unsigned int nIn,
0029 unsigned int nOut,
0030 unsigned int nVtx,
0031 unsigned int dR2Min,
0032 unsigned int dR2Max,
0033 unsigned int iptMax,
0034 unsigned int dzCut,
0035 double ptSlopeNe,
0036 double ptSlopePh,
0037 double ptZeroNe,
0038 double ptZeroPh,
0039 double alphaSlope,
0040 double alphaZero,
0041 double alphaCrop,
0042 double priorNe,
0043 double priorPh,
0044 pt_t ptCut,
0045 bool useMLAssociation = false,
0046 const double associationThreshold = 0.0,
0047 std::string associationGraphPath = "",
0048 std::vector<double> associationNetworkZ0binning = {},
0049 std::vector<double> associationNetworkEtaBounds = {},
0050 std::vector<double> associationNetworkZ0ResBins = {},
0051 unsigned int nFinalSort = 0,
0052 SortAlgo finalSortAlgo = SortAlgo::Insertion)
0053 : nTrack_(nTrack),
0054 nIn_(nIn),
0055 nOut_(nOut),
0056 nVtx_(nVtx),
0057 dR2Min_(dR2Min),
0058 dR2Max_(dR2Max),
0059 iptMax_(iptMax),
0060 dzCut_(dzCut),
0061 absEtaBins_(),
0062 ptSlopeNe_(1, ptSlopeNe),
0063 ptSlopePh_(1, ptSlopePh),
0064 ptZeroNe_(1, ptZeroNe),
0065 ptZeroPh_(1, ptZeroPh),
0066 alphaSlope_(1, alphaSlope),
0067 alphaZero_(1, alphaZero),
0068 alphaCrop_(1, alphaCrop),
0069 priorNe_(1, priorNe),
0070 priorPh_(1, priorPh),
0071 ptCut_(1, ptCut),
0072 useMLAssociation_(useMLAssociation),
0073 nFinalSort_(nFinalSort ? nFinalSort : nOut),
0074 finalSortAlgo_(finalSortAlgo),
0075 debug_(false),
0076 fakePuppi_(false) {
0077 if (useMLAssociation_ and withinCMSSW_) {
0078 nnVtxAssoc_ = std::make_unique<NNVtxAssoc>(NNVtxAssoc(associationGraphPath,
0079 associationThreshold,
0080 associationNetworkZ0binning,
0081 associationNetworkEtaBounds,
0082 associationNetworkZ0ResBins));
0083 }
0084 }
0085
0086 LinPuppiEmulator(unsigned int nTrack,
0087 unsigned int nIn,
0088 unsigned int nOut,
0089 unsigned int nVtx,
0090 unsigned int dR2Min,
0091 unsigned int dR2Max,
0092 unsigned int iptMax,
0093 unsigned int dzCut,
0094 glbeta_t etaCut,
0095 double ptSlopeNe_0,
0096 double ptSlopeNe_1,
0097 double ptSlopePh_0,
0098 double ptSlopePh_1,
0099 double ptZeroNe_0,
0100 double ptZeroNe_1,
0101 double ptZeroPh_0,
0102 double ptZeroPh_1,
0103 double alphaSlope_0,
0104 double alphaSlope_1,
0105 double alphaZero_0,
0106 double alphaZero_1,
0107 double alphaCrop_0,
0108 double alphaCrop_1,
0109 double priorNe_0,
0110 double priorNe_1,
0111 double priorPh_0,
0112 double priorPh_1,
0113 pt_t ptCut_0,
0114 pt_t ptCut_1,
0115 bool useMLAssociation = false,
0116 const double associationThreshold = 0.0,
0117 std::string associationGraphPath = "",
0118 std::vector<double> associationNetworkZ0binning = {},
0119 std::vector<double> associationNetworkEtaBounds = {},
0120 std::vector<double> associationNetworkZ0ResBins = {},
0121 unsigned int nFinalSort = 0,
0122 SortAlgo finalSortAlgo = SortAlgo::Insertion);
0123
0124 LinPuppiEmulator(unsigned int nTrack,
0125 unsigned int nIn,
0126 unsigned int nOut,
0127 unsigned int nVtx,
0128 unsigned int dR2Min,
0129 unsigned int dR2Max,
0130 unsigned int iptMax,
0131 unsigned int dzCut,
0132 const std::vector<glbeta_t> &absEtaBins,
0133 const std::vector<double> &ptSlopeNe,
0134 const std::vector<double> &ptSlopePh,
0135 const std::vector<double> &ptZeroNe,
0136 const std::vector<double> &ptZeroPh,
0137 const std::vector<double> &alphaSlope,
0138 const std::vector<double> &alphaZero,
0139 const std::vector<double> &alphaCrop,
0140 const std::vector<double> &priorNe,
0141 const std::vector<double> &priorPh,
0142 const std::vector<pt_t> &ptCut,
0143 bool useMLAssociation,
0144 const double associationThreshold,
0145 std::string associationGraphPath,
0146 std::vector<double> associationNetworkZ0binning,
0147 std::vector<double> associationNetworkEtaBounds,
0148 std::vector<double> associationNetworkZ0ResBins,
0149 unsigned int nFinalSort,
0150 SortAlgo finalSortAlgo)
0151 : nTrack_(nTrack),
0152 nIn_(nIn),
0153 nOut_(nOut),
0154 nVtx_(nVtx),
0155 dR2Min_(dR2Min),
0156 dR2Max_(dR2Max),
0157 iptMax_(iptMax),
0158 dzCut_(dzCut),
0159 absEtaBins_(absEtaBins),
0160 ptSlopeNe_(ptSlopeNe),
0161 ptSlopePh_(ptSlopePh),
0162 ptZeroNe_(ptZeroNe),
0163 ptZeroPh_(ptZeroPh),
0164 alphaSlope_(alphaSlope),
0165 alphaZero_(alphaZero),
0166 alphaCrop_(alphaCrop),
0167 priorNe_(priorNe),
0168 priorPh_(priorPh),
0169 ptCut_(ptCut),
0170 useMLAssociation_(useMLAssociation),
0171 nFinalSort_(nFinalSort),
0172 finalSortAlgo_(finalSortAlgo),
0173 debug_(false),
0174 fakePuppi_(false) {}
0175
0176 LinPuppiEmulator(const edm::ParameterSet &iConfig);
0177
0178 static edm::ParameterSetDescription getParameterSetDescription();
0179
0180
0181 void linpuppi_chs_ref(const PFRegionEmu ®ion,
0182 const PVObjEmu &pv,
0183 const std::vector<PFChargedObjEmu> &pfch ,
0184 std::vector<PuppiObjEmu> &outallch ) const;
0185
0186 void linpuppi_chs_ref(const PFRegionEmu ®ion,
0187 const std::vector<PVObjEmu> &pv ,
0188 const std::vector<PFChargedObjEmu> &pfch ,
0189 std::vector<PuppiObjEmu> &outallch ) const;
0190
0191
0192 void linpuppi_flt(const PFRegionEmu ®ion,
0193 const std::vector<TkObjEmu> &track ,
0194 const std::vector<PVObjEmu> &pv ,
0195 const std::vector<PFNeutralObjEmu> &pfallne ,
0196 std::vector<PuppiObjEmu> &outallne_nocut ,
0197 std::vector<PuppiObjEmu> &outallne ,
0198 std::vector<PuppiObjEmu> &outselne ) const;
0199 void linpuppi_ref(const PFRegionEmu ®ion,
0200 const std::vector<TkObjEmu> &track ,
0201 const std::vector<PVObjEmu> &pv ,
0202 const std::vector<PFNeutralObjEmu> &pfallne ,
0203 std::vector<PuppiObjEmu> &outallne_nocut ,
0204 std::vector<PuppiObjEmu> &outallne ,
0205 std::vector<PuppiObjEmu> &outselne ) const;
0206 void linpuppi_ref(const PFRegionEmu ®ion,
0207 const std::vector<TkObjEmu> &track ,
0208 const std::vector<PVObjEmu> &pv ,
0209 const std::vector<PFNeutralObjEmu> &pfallne ,
0210 std::vector<PuppiObjEmu> &outselne ) const {
0211 std::vector<PuppiObjEmu> outallne_nocut, outallne;
0212 linpuppi_ref(region, track, pv, pfallne, outallne_nocut, outallne, outselne);
0213 }
0214
0215
0216 void fwdlinpuppi_ref(const PFRegionEmu ®ion,
0217 const std::vector<HadCaloObjEmu> &caloin ,
0218 std::vector<PuppiObjEmu> &outallne_nocut ,
0219 std::vector<PuppiObjEmu> &outallne ,
0220 std::vector<PuppiObjEmu> &outselne ) const;
0221 void fwdlinpuppi_flt(const PFRegionEmu ®ion,
0222 const std::vector<HadCaloObjEmu> &caloin ,
0223 std::vector<PuppiObjEmu> &outallne_nocut ,
0224 std::vector<PuppiObjEmu> &outallne ,
0225 std::vector<PuppiObjEmu> &outselne ) const;
0226
0227 static void puppisort_and_crop_ref(unsigned int nOutMax,
0228 const std::vector<PuppiObjEmu> &in,
0229 std::vector<PuppiObjEmu> &out,
0230 SortAlgo algo = SortAlgo::Insertion);
0231
0232
0233 void run(const PFInputRegion &in, const std::vector<l1ct::PVObjEmu> &pvs, OutputRegion &out) const;
0234
0235 void setDebug(bool debug = true) { debug_ = debug; }
0236
0237
0238 void setFakePuppi(bool fakePuppi = true) { fakePuppi_ = fakePuppi; }
0239
0240 protected:
0241 unsigned int nTrack_, nIn_, nOut_,
0242 nVtx_;
0243 unsigned int dR2Min_, dR2Max_, iptMax_, dzCut_;
0244 std::vector<glbeta_t> absEtaBins_;
0245 std::vector<double> ptSlopeNe_, ptSlopePh_, ptZeroNe_, ptZeroPh_;
0246 std::vector<double> alphaSlope_, alphaZero_, alphaCrop_;
0247 std::vector<double> priorNe_, priorPh_;
0248 std::vector<pt_t> ptCut_;
0249
0250
0251 bool useMLAssociation_;
0252 std::unique_ptr<NNVtxAssoc> nnVtxAssoc_;
0253
0254 unsigned int nFinalSort_;
0255 SortAlgo finalSortAlgo_;
0256
0257 bool debug_;
0258 bool fakePuppi_;
0259
0260 unsigned int find_ieta(const PFRegionEmu ®ion, eta_t eta) const;
0261 std::pair<pt_t, puppiWgt_t> sum2puppiPt_ref(
0262 linpuppi::sumTerm_t sum, pt_t pt, unsigned int ieta, bool isEM, int icand) const;
0263 std::pair<float, float> sum2puppiPt_flt(float sum, float pt, unsigned int ieta, bool isEM, int icand) const;
0264 };
0265
0266 }
0267
0268 #endif