Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-01 01:02:11

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