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
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
pfalgo_config::~pfalgo_config
virtual ~pfalgo_config()
Definition: pfalgo_common_ref.h:43
L1TowerCalibrationProducer_cfi.calo
calo
Definition: L1TowerCalibrationProducer_cfi.py:59
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
sqr
int sqr(const T &t)
Definition: pfalgo_common_ref.h:9
pfalgo_config::dR2MAX_TK_MU
unsigned int dR2MAX_TK_MU
Definition: pfalgo_common_ref.h:22
pfalgo_config
Definition: pfalgo_common_ref.h:19
pfalgo_mu_ref
void pfalgo_mu_ref(const pfalgo_config &cfg, const TkObj track[], const MuObj mu[], bool isMu[], PFChargedObj outmu[], bool debug)
ptsort_ref
void ptsort_ref(int nIn, int nOut, const T in[], T out[])
pfalgo_config::pfalgo_config
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)
Definition: pfalgo_common_ref.h:26
debug
#define debug
Definition: HDRShower.cc:19
pfalgo_config::nCALO
unsigned int nCALO
Definition: pfalgo_common_ref.h:20
OrderedSet.t
t
Definition: OrderedSet.py:90
PFChargedObj
Definition: data.h:169
pfalgo_config::dR2MAX_TK_CALO
unsigned int dR2MAX_TK_CALO
Definition: pfalgo_common_ref.h:23
TkObj
Definition: data.h:143
pt_t
ap_int< 16 > pt_t
Definition: data.h:6
pfalgo_config::nSELCALO
unsigned int nSELCALO
Definition: pfalgo_common_ref.h:21
recoMuon::in
Definition: RecoMuonEnumerators.h:6
MuObj
Definition: data.h:158
looper.cfg
cfg
Definition: looper.py:297
dr2_int
int dr2_int(etaphi_t eta1, etaphi_t phi1, etaphi_t eta2, etaphi_t phi2)
Definition: pfalgo_common.h:6
pfalgo_config::nTRACK
unsigned int nTRACK
Definition: pfalgo_common_ref.h:20
T
long double T
Definition: Basic3DVectorLD.h:48
flavorHistoryFilter_cfi.dr
dr
Definition: flavorHistoryFilter_cfi.py:37
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
pfalgo_config::tk_MAXINVPT_LOOSE
unsigned int tk_MAXINVPT_LOOSE
Definition: pfalgo_common_ref.h:24
jets_cff.isMu
isMu
Definition: jets_cff.py:288
pfalgo_config::nMU
unsigned int nMU
Definition: pfalgo_common_ref.h:20
best_match_with_pt_ref
int best_match_with_pt_ref(int nCAL, int dR2MAX, const CO_t calo[], const TkObj &track)
Definition: pfalgo_common_ref.h:56
pfalgo_config::tk_MAXINVPT_TIGHT
unsigned int tk_MAXINVPT_TIGHT
Definition: pfalgo_common_ref.h:24