CMS 3D CMS Logo

pfalgo_common_ref.h
Go to the documentation of this file.
1 #ifndef PFALGO_COMMON_REF_H
2 #define PFALGO_COMMON_REF_H
3 
5 #include "pfalgo_types.h"
6 
7 #include <algorithm>
8 #include <vector>
9 
10 namespace edm {
11  class ParameterSet;
13 } // namespace edm
14 
15 namespace l1ct {
16 
18  public:
19  PFAlgoEmulatorBase(unsigned int nTrack,
20  unsigned int nCalo,
21  unsigned int nMu,
22  unsigned int nSelCalo,
23  unsigned int dR2Max_Tk_Mu,
24  unsigned int dR2Max_Tk_Calo,
25  pt_t tk_MaxInvPt_Loose,
26  pt_t tk_MaxInvPt_Tight)
27  : nTRACK_(nTrack),
28  nCALO_(nCalo),
29  nMU_(nMu),
31  dR2MAX_TK_MU_(dR2Max_Tk_Mu),
32  dR2MAX_TK_CALO_(dR2Max_Tk_Calo),
33  tk_MAXINVPT_LOOSE_(tk_MaxInvPt_Loose),
34  tk_MAXINVPT_TIGHT_(tk_MaxInvPt_Tight),
35  debug_(false) {}
36 
37  virtual ~PFAlgoEmulatorBase();
38 
39  void loadPtErrBins(
40  unsigned int nbins, const float absetas[], const float scales[], const float offs[], bool verbose = false);
41  void loadPtErrBins(const edm::ParameterSet& iConfig);
43 
44  void setDebug(bool debug = true) { debug_ = debug; }
45 
46  virtual void run(const PFInputRegion& in, OutputRegion& out) const = 0;
47 
49  virtual void mergeNeutrals(OutputRegion& out) const = 0;
50 
51  protected:
52  // config
53  unsigned int nTRACK_, nCALO_, nMU_;
54  unsigned int nSELCALO_;
55  unsigned int dR2MAX_TK_MU_;
56  unsigned int dR2MAX_TK_CALO_;
58 
59  struct ptErrBin {
63  };
64  std::vector<ptErrBin> ptErrBins_;
65 
66  bool debug_;
67 
68  // tools
69  template <typename COV>
70  int best_match_with_pt_ref(int dR2MAX, const COV& calo, const TkObjEmu& track, const pt_t& trackCaloPtErr) const;
71 
72  template <typename TV>
73  void ptsort_ref(int nIn, int nOut, const TV& in, TV& out) const;
74 
75  pt_t ptErr_ref(const PFRegionEmu& region, const TkObjEmu& track) const;
76 
77  void pfalgo_mu_ref(const PFInputRegion& in, OutputRegion& out, std::vector<int>& iMu) const;
78 
79  void fillPFCand(const TkObjEmu& track, PFChargedObjEmu& pf, bool isMu, bool isEle) const;
80  void fillPFCand(const HadCaloObjEmu& calo, PFNeutralObjEmu& pf, bool isPhoton = false) const;
81  void fillPFCand(const EmCaloObjEmu& calo, PFNeutralObjEmu& pf, bool isPhoton = true) const;
82  };
83 
84 } // namespace l1ct
85 //=== begin implementation part
86 
87 template <typename COV>
89  const COV& calo,
90  const TkObjEmu& track,
91  const pt_t& trackCaloPtErr) const {
92  pt_t caloPtMin = track.hwPt - 2 * trackCaloPtErr;
93  if (caloPtMin < 0)
94  caloPtMin = 0;
95  float ptErr = std::max<float>(Scales::INTPT_LSB, Scales::floatPt(trackCaloPtErr));
96  ptscale_t dptscale = float(dR2MAX) / (ptErr * ptErr);
97  int dr2min = 0, ibest = -1;
98  for (int ic = 0, nCAL = calo.size(); ic < nCAL; ++ic) {
99  if (calo[ic].hwPt <= caloPtMin)
100  continue;
101  int dr2 = dr2_int(track.hwEta, track.hwPhi, calo[ic].hwEta, calo[ic].hwPhi);
102  if (dr2 >= dR2MAX)
103  continue;
104  pt_t dpt = track.hwPt - calo[ic].hwPt;
105  dr2 += int((dpt * dpt) * dptscale);
106  if (ibest == -1 || dr2 < dr2min) {
107  dr2min = dr2;
108  ibest = ic;
109  }
110  }
111  return ibest;
112 }
113 
114 template <typename TV>
115 void l1ct::PFAlgoEmulatorBase::ptsort_ref(int nIn, int nOut, const TV& in, TV& out) const {
116  out.resize(nOut);
117  for (int iout = 0; iout < nOut; ++iout) {
118  out[iout].clear();
119  }
120  for (int it = 0; it < nIn; ++it) {
121  for (int iout = 0; iout < nOut; ++iout) {
122  if (in[it].hwPt >= out[iout].hwPt) {
123  for (int i2 = nOut - 1; i2 > iout; --i2) {
124  out[i2] = out[i2 - 1];
125  }
126  out[iout] = in[it];
127  break;
128  }
129  }
130  }
131 }
132 
133 #endif
void setDebug(bool debug=true)
int dr2_int(eta_t eta1, phi_t phi1, eta_t eta2, phi_t phi2)
Definition: datatypes.h:218
bool verbose
virtual void mergeNeutrals(OutputRegion &out) const =0
moves all objects from out.pfphoton to the beginning of out.pfneutral
constexpr float INTPT_LSB
Definition: datatypes.h:143
PFAlgoEmulatorBase(unsigned int nTrack, unsigned int nCalo, unsigned int nMu, unsigned int nSelCalo, unsigned int dR2Max_Tk_Mu, unsigned int dR2Max_Tk_Calo, pt_t tk_MaxInvPt_Loose, pt_t tk_MaxInvPt_Tight)
static void addCaloResolutionParameterSetDescription(edm::ParameterSetDescription &to)
void loadPtErrBins(unsigned int nbins, const float absetas[], const float scales[], const float offs[], bool verbose=false)
void ptsort_ref(int nIn, int nOut, const TV &in, TV &out) const
ap_fixed< 10, 6 > ptErrOffs_t
Definition: pfalgo_types.h:10
ap_ufixed< 9, 1 > ptErrScale_t
Definition: pfalgo_types.h:9
float floatPt(pt_t pt)
Definition: datatypes.h:153
std::vector< ptErrBin > ptErrBins_
virtual void run(const PFInputRegion &in, OutputRegion &out) const =0
ap_ufixed< 14, 12, AP_TRN, AP_SAT > pt_t
Definition: datatypes.h:10
#define debug
Definition: HDRShower.cc:19
int best_match_with_pt_ref(int dR2MAX, const COV &calo, const TkObjEmu &track, const pt_t &trackCaloPtErr) const
HLT enums.
pt_t ptErr_ref(const PFRegionEmu &region, const TkObjEmu &track) const
void pfalgo_mu_ref(const PFInputRegion &in, OutputRegion &out, std::vector< int > &iMu) const
ap_ufixed< 17, 17 - 4, AP_TRN, AP_SAT > ptscale_t
Definition: pfalgo_types.h:8
ap_int< 12 > glbeta_t
Definition: datatypes.h:18
Definition: Common.h:9
void fillPFCand(const TkObjEmu &track, PFChargedObjEmu &pf, bool isMu, bool isEle) const
Definition: datatypes.h:8