CMS 3D CMS Logo

pfalgo_common_ref.h
Go to the documentation of this file.
1 #ifndef L1Trigger_Phase2L1ParticleFlow_PFALGO_COMMON_REF_H
2 #define L1Trigger_Phase2L1ParticleFlow_PFALGO_COMMON_REF_H
3 
4 #include "../firmware/data.h"
5 #include "../firmware/pfalgo_common.h"
6 #include <algorithm>
7 
8 template <typename T>
9 inline int sqr(const T &t) {
10  return t * t;
11 }
12 
13 template <typename CO_t>
14 int best_match_with_pt_ref(int nCAL, int dR2MAX, const CO_t calo[/*nCAL*/], const TkObj &track);
15 
16 template <typename T>
17 void ptsort_ref(int nIn, int nOut, const T in[/*nIn*/], T out[/*nOut*/]);
18 
19 struct pfalgo_config {
20  unsigned int nTRACK, nCALO, nMU;
21  unsigned int nSELCALO;
22  unsigned int dR2MAX_TK_MU;
23  unsigned int dR2MAX_TK_CALO;
25 
26  pfalgo_config(unsigned int nTrack,
27  unsigned int nCalo,
28  unsigned int nMu,
29  unsigned int nSelCalo,
30  unsigned int dR2Max_Tk_Mu,
31  unsigned int dR2Max_Tk_Calo,
32  unsigned int tk_MaxInvPt_Loose,
33  unsigned int tk_MaxInvPt_Tight)
34  : nTRACK(nTrack),
35  nCALO(nCalo),
36  nMU(nMu),
37  nSELCALO(nSelCalo),
38  dR2MAX_TK_MU(dR2Max_Tk_Mu),
39  dR2MAX_TK_CALO(dR2Max_Tk_Calo),
40  tk_MAXINVPT_LOOSE(tk_MaxInvPt_Loose),
41  tk_MAXINVPT_TIGHT(tk_MaxInvPt_Tight) {}
42 
43  virtual ~pfalgo_config() {}
44 };
45 
46 void pfalgo_mu_ref(const pfalgo_config &cfg,
47  const TkObj track[/*cfg.nTRACK*/],
48  const MuObj mu[/*cfg.nMU*/],
49  bool isMu[/*cfg.nTRACK*/],
50  PFChargedObj outmu[/*cfg.nMU*/],
51  bool debug);
52 
53 //=== begin implementation part
54 
55 template <typename CO_t>
56 int best_match_with_pt_ref(int nCAL, int dR2MAX, const CO_t calo[/*nCAL*/], const TkObj &track) {
57  pt_t caloPtMin = track.hwPt - 2 * (track.hwPtErr);
58  if (caloPtMin < 0)
59  caloPtMin = 0;
60  int dptscale = (dR2MAX << 8) / std::max<int>(1, sqr(track.hwPtErr));
61  int drmin = 0, ibest = -1;
62  for (int ic = 0; ic < nCAL; ++ic) {
63  if (calo[ic].hwPt <= caloPtMin)
64  continue;
65  int dr = dr2_int(track.hwEta, track.hwPhi, calo[ic].hwEta, calo[ic].hwPhi);
66  if (dr >= dR2MAX)
67  continue;
68  dr += ((sqr(std::max<int>(track.hwPt - calo[ic].hwPt, 0)) * dptscale) >> 8);
69  if (ibest == -1 || dr < drmin) {
70  drmin = dr;
71  ibest = ic;
72  }
73  }
74  return ibest;
75 }
76 
77 template <typename T, typename TV>
78 void ptsort_ref(int nIn, int nOut, const TV &in /*[nIn]*/, T out[/*nOut*/]) {
79  for (int iout = 0; iout < nOut; ++iout) {
80  out[iout].hwPt = 0;
81  }
82  for (int it = 0; it < nIn; ++it) {
83  for (int iout = 0; iout < nOut; ++iout) {
84  if (in[it].hwPt >= out[iout].hwPt) {
85  for (int i2 = nOut - 1; i2 > iout; --i2) {
86  out[i2] = out[i2 - 1];
87  }
88  out[iout] = in[it];
89  break;
90  }
91  }
92  }
93 }
94 
95 #endif
Definition: data.h:158
int dr2_int(etaphi_t eta1, etaphi_t phi1, etaphi_t eta2, etaphi_t phi2)
Definition: pfalgo_common.h:6
unsigned int nCALO
pfalgo_config(unsigned int nTrack, unsigned int nCalo, unsigned int nMu, unsigned int nSelCalo, unsigned int dR2Max_Tk_Mu, unsigned int dR2Max_Tk_Calo, unsigned int tk_MaxInvPt_Loose, unsigned int tk_MaxInvPt_Tight)
unsigned int dR2MAX_TK_CALO
int sqr(const T &t)
void ptsort_ref(int nIn, int nOut, const T in[], T out[])
unsigned int tk_MAXINVPT_LOOSE
unsigned int nMU
void pfalgo_mu_ref(const pfalgo_config &cfg, const TkObj track[], const MuObj mu[], bool isMu[], PFChargedObj outmu[], bool debug)
unsigned int nTRACK
#define debug
Definition: HDRShower.cc:19
ap_int< 16 > pt_t
Definition: data.h:6
unsigned int tk_MAXINVPT_TIGHT
int best_match_with_pt_ref(int nCAL, int dR2MAX, const CO_t calo[], const TkObj &track)
virtual ~pfalgo_config()
unsigned int nSELCALO
long double T
unsigned int dR2MAX_TK_MU
Definition: Common.h:9
Definition: data.h:143