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;
12 }
13 
14 namespace l1ct {
15 
17  public:
18  PFAlgoEmulatorBase(unsigned int nTrack,
19  unsigned int nCalo,
20  unsigned int nMu,
21  unsigned int nSelCalo,
22  unsigned int dR2Max_Tk_Mu,
23  unsigned int dR2Max_Tk_Calo,
24  pt_t tk_MaxInvPt_Loose,
25  pt_t tk_MaxInvPt_Tight)
26  : nTRACK_(nTrack),
27  nCALO_(nCalo),
28  nMU_(nMu),
30  dR2MAX_TK_MU_(dR2Max_Tk_Mu),
31  dR2MAX_TK_CALO_(dR2Max_Tk_Calo),
32  tk_MAXINVPT_LOOSE_(tk_MaxInvPt_Loose),
33  tk_MAXINVPT_TIGHT_(tk_MaxInvPt_Tight),
34  debug_(false) {}
35 
36  virtual ~PFAlgoEmulatorBase();
37 
38  void loadPtErrBins(
39  unsigned int nbins, const float absetas[], const float scales[], const float offs[], bool verbose = false);
40  void loadPtErrBins(const edm::ParameterSet& iConfig);
41 
42  void setDebug(bool debug = true) { debug_ = debug; }
43 
44  virtual void run(const PFInputRegion& in, OutputRegion& out) const = 0;
45 
47  virtual void mergeNeutrals(OutputRegion& out) const = 0;
48 
49  protected:
50  // config
51  unsigned int nTRACK_, nCALO_, nMU_;
52  unsigned int nSELCALO_;
53  unsigned int dR2MAX_TK_MU_;
54  unsigned int dR2MAX_TK_CALO_;
56 
57  struct ptErrBin {
61  };
62  std::vector<ptErrBin> ptErrBins_;
63 
64  bool debug_;
65 
66  // tools
67  template <typename COV>
68  int best_match_with_pt_ref(int dR2MAX, const COV& calo, const TkObjEmu& track, const pt_t& trackCaloPtErr) const;
69 
70  template <typename TV>
71  void ptsort_ref(int nIn, int nOut, const TV& in, TV& out) const;
72 
73  pt_t ptErr_ref(const PFRegionEmu& region, const TkObjEmu& track) const;
74 
75  void pfalgo_mu_ref(const PFInputRegion& in, OutputRegion& out, std::vector<int>& iMu) const;
76 
77  void fillPFCand(const TkObjEmu& track, PFChargedObjEmu& pf, bool isMu, bool isEle) const;
78  void fillPFCand(const HadCaloObjEmu& calo, PFNeutralObjEmu& pf, bool isPhoton = false) const;
79  void fillPFCand(const EmCaloObjEmu& calo, PFNeutralObjEmu& pf, bool isPhoton = true) const;
80  };
81 
82 } // namespace l1ct
83 //=== begin implementation part
84 
85 template <typename COV>
87  const COV& calo,
88  const TkObjEmu& track,
89  const pt_t& trackCaloPtErr) const {
90  pt_t caloPtMin = track.hwPt - 2 * trackCaloPtErr;
91  if (caloPtMin < 0)
92  caloPtMin = 0;
93  float ptErr = std::max<float>(Scales::INTPT_LSB, Scales::floatPt(trackCaloPtErr));
94  ptscale_t dptscale = float(dR2MAX) / (ptErr * ptErr);
95  int dr2min = 0, ibest = -1;
96  for (int ic = 0, nCAL = calo.size(); ic < nCAL; ++ic) {
97  if (calo[ic].hwPt <= caloPtMin)
98  continue;
99  int dr2 = dr2_int(track.hwEta, track.hwPhi, calo[ic].hwEta, calo[ic].hwPhi);
100  if (dr2 >= dR2MAX)
101  continue;
102  pt_t dpt = track.hwPt - calo[ic].hwPt;
103  dr2 += int((dpt * dpt) * dptscale);
104  if (ibest == -1 || dr2 < dr2min) {
105  dr2min = dr2;
106  ibest = ic;
107  }
108  }
109  return ibest;
110 }
111 
112 template <typename TV>
113 void l1ct::PFAlgoEmulatorBase::ptsort_ref(int nIn, int nOut, const TV& in, TV& out) const {
114  out.resize(nOut);
115  for (int iout = 0; iout < nOut; ++iout) {
116  out[iout].clear();
117  }
118  for (int it = 0; it < nIn; ++it) {
119  for (int iout = 0; iout < nOut; ++iout) {
120  if (in[it].hwPt >= out[iout].hwPt) {
121  for (int i2 = nOut - 1; i2 > iout; --i2) {
122  out[i2] = out[i2 - 1];
123  }
124  out[iout] = in[it];
125  break;
126  }
127  }
128  }
129 }
130 
131 #endif
void setDebug(bool debug=true)
int dr2_int(eta_t eta1, phi_t phi1, eta_t eta2, phi_t phi2)
Definition: datatypes.h:204
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:147
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)
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:152
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:21
#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:29
Definition: Common.h:9
void fillPFCand(const TkObjEmu &track, PFChargedObjEmu &pf, bool isMu, bool isEle) const
Definition: datatypes.h:19