CMS 3D CMS Logo

pftkegalgo_ref.h
Go to the documentation of this file.
1 #ifndef PFTKEGALGO_REF_H
2 #define PFTKEGALGO_REF_H
3 
8 
9 #include "conifer.h"
10 
11 namespace edm {
12  class ParameterSet;
14 } // namespace edm
15 
16 namespace l1ct {
17 
19  unsigned int nTRACK;
20  unsigned int nTRACK_EGIN;
21  unsigned int nEMCALO_EGIN;
22  unsigned int nEM_EGOUT;
23 
29  float emClusterPtMin; // GeV
30  float dEtaMaxBrem;
31  float dPhiMaxBrem;
32 
33  std::vector<double> absEtaBoundaries;
34  std::vector<double> dEtaValues;
35  std::vector<double> dPhiValues;
36  float trkQualityPtMin; // GeV
38  unsigned int nCompCandPerCluster;
39  bool writeEgSta;
40 
41  struct IsoParameters {
43  IsoParameters(float tkQualityPtMin, float dZ, float dRMin, float dRMax)
45  dZ(Scales::makeZ0(dZ)),
47  dRMax2(Scales::makeDR2FromFloatDR(dRMax)) {}
49  ap_int<z0_t::width + 1> dZ;
50  int dRMin2;
51  int dRMax2;
53  };
54 
59  bool doTkIso;
60  bool doPfIso;
63 
68  const id_score_t bdtScore_loose_wp; // Conifer score/4
69  const id_score_t bdtScore_tight_wp; // Conifer score/4
72  };
73 
75 
76  int debug = 0;
77 
78  PFTkEGAlgoEmuConfig(const edm::ParameterSet &iConfig);
80  unsigned int nTrack_in,
81  unsigned int nEmCalo_in,
82  unsigned int nEmOut,
83  bool filterHwQuality,
84  bool doBremRecovery,
85  bool writeBeforeBremRecovery = false,
86  int caloHwQual = 4,
87  bool doEndcapHwQual = false,
88  float emClusterPtMin = 2.,
89  float dEtaMaxBrem = 0.02,
90  float dPhiMaxBrem = 0.1,
91  const std::vector<double> &absEtaBoundaries = {0.0, 1.5},
92  const std::vector<double> &dEtaValues = {0.015, 0.01},
93  const std::vector<double> &dPhiValues = {0.07, 0.07},
94  float trkQualityPtMin = 10.,
95  bool doCompositeTkEle = false,
96  unsigned int nCompCandPerCluster = 4,
97  bool writeEgSta = false,
98  const IsoParameters &tkIsoParams_tkEle = {2., 0.6, 0.03, 0.2},
99  const IsoParameters &tkIsoParams_tkEm = {2., 0.6, 0.07, 0.3},
100  const IsoParameters &pfIsoParams_tkEle = {1., 0.6, 0.03, 0.2},
101  const IsoParameters &pfIsoParams_tkEm = {1., 0.6, 0.07, 0.3},
102  bool doTkIso = true,
103  bool doPfIso = false,
104  EGIsoEleObjEmu::IsoType hwIsoTypeTkEle = EGIsoEleObjEmu::IsoType::TkIso,
105  EGIsoObjEmu::IsoType hwIsoTypeTkEm = EGIsoObjEmu::IsoType::TkIsoPV,
106  const CompIDParameters &compIDparams = {-4, 0.214844, "compositeID.json"},
107  int debug = 0)
108 
109  : nTRACK(nTrack),
110  nTRACK_EGIN(nTrack_in),
111  nEMCALO_EGIN(nEmCalo_in),
112  nEM_EGOUT(nEmOut),
132  doTkIso(doTkIso),
133  doPfIso(doPfIso),
137  debug(debug) {}
138 
140  };
141 
143  public:
145 
146  virtual ~PFTkEGAlgoEmulator() {}
147 
148  void toFirmware(const PFInputRegion &in, PFRegion &region, EmCaloObj calo[/*nCALO*/], TkObj track[/*nTRACK*/]) const;
149  void toFirmware(const OutputRegion &out, EGIsoObj out_egphs[], EGIsoEleObj out_egeles[]) const;
150  void toFirmware(const PFInputRegion &in,
151  const l1ct::PVObjEmu &pvin,
152  PFRegion &region,
153  TkObj track[/*nTRACK*/],
154  PVObj &pv) const;
155 
156  void run(const PFInputRegion &in, OutputRegion &out) const;
157  void runIso(const PFInputRegion &in, const std::vector<l1ct::PVObjEmu> &pvs, OutputRegion &out) const;
158 
159  void setDebug(int verbose) { debug_ = verbose; }
160 
161  bool writeEgSta() const { return cfg.writeEgSta; }
162 
163  typedef ap_fixed<21, 12, AP_RND_CONV, AP_SAT> bdt_feature_t;
164  typedef ap_fixed<12, 3, AP_RND_CONV, AP_SAT> bdt_score_t;
165 
166  private:
167  void link_emCalo2emCalo(const std::vector<EmCaloObjEmu> &emcalo, std::vector<int> &emCalo2emCalo) const;
168 
169  void link_emCalo2tk_elliptic(const PFRegionEmu &r,
170  const std::vector<EmCaloObjEmu> &emcalo,
171  const std::vector<TkObjEmu> &track,
172  std::vector<int> &emCalo2tk) const;
173 
175  const std::vector<EmCaloObjEmu> &emcalo,
176  const std::vector<TkObjEmu> &track,
177  std::vector<int> &emCalo2tk,
178  std::vector<id_score_t> &emCaloTkBdtScore) const;
179 
181  unsigned int cluster_idx;
182  unsigned int track_idx;
183  double dpt; // For sorting
184  };
185 
187  const std::vector<EmCaloObjEmu> &emcalo,
188  const std::vector<TkObjEmu> &track,
190 
191  //FIXME: still needed
192  float deltaPhi(float phi1, float phi2) const;
193 
194  void sel_emCalo(unsigned int nmax_sel,
195  const std::vector<EmCaloObjEmu> &emcalo,
196  std::vector<EmCaloObjEmu> &emcalo_sel) const;
197 
198  void eg_algo(const PFRegionEmu &region,
199  const std::vector<EmCaloObjEmu> &emcalo,
200  const std::vector<TkObjEmu> &track,
201  const std::vector<int> &emCalo2emCalo,
202  const std::vector<int> &emCalo2tk,
203  const std::vector<id_score_t> &emCaloTkBdtScore,
204  std::vector<EGObjEmu> &egstas,
205  std::vector<EGIsoObjEmu> &egobjs,
206  std::vector<EGIsoEleObjEmu> &egeleobjs) const;
207 
208  void addEgObjsToPF(std::vector<EGObjEmu> &egstas,
209  std::vector<EGIsoObjEmu> &egobjs,
210  std::vector<EGIsoEleObjEmu> &egeleobjs,
211  const std::vector<EmCaloObjEmu> &emcalo,
212  const std::vector<TkObjEmu> &track,
213  const int calo_idx,
214  const unsigned int hwQual,
215  const pt_t ptCorr,
216  const int tk_idx,
217  const id_score_t bdtScore,
218  const std::vector<unsigned int> &components = {}) const;
219 
220  EGObjEmu &addEGStaToPF(std::vector<EGObjEmu> &egobjs,
221  const EmCaloObjEmu &calo,
222  const unsigned int hwQual,
223  const pt_t ptCorr,
224  const std::vector<unsigned int> &components) const;
225 
226  EGIsoObjEmu &addEGIsoToPF(std::vector<EGIsoObjEmu> &egobjs,
227  const EmCaloObjEmu &calo,
228  const unsigned int hwQual,
229  const pt_t ptCorr) const;
230 
231  EGIsoEleObjEmu &addEGIsoEleToPF(std::vector<EGIsoEleObjEmu> &egobjs,
232  const EmCaloObjEmu &calo,
233  const TkObjEmu &track,
234  const unsigned int hwQual,
235  const pt_t ptCorr,
236  const id_score_t bdtScore) const;
237 
238  // FIXME: reimplemented from PFAlgoEmulatorBase
239  template <typename T>
240  void ptsort_ref(int nIn, int nOut, const std::vector<T> &in, std::vector<T> &out) const {
241  out.resize(nOut);
242  for (int iout = 0; iout < nOut; ++iout) {
243  out[iout].clear();
244  }
245  for (int it = 0; it < nIn; ++it) {
246  for (int iout = 0; iout < nOut; ++iout) {
247  if (in[it].hwPt >= out[iout].hwPt) {
248  for (int i2 = nOut - 1; i2 > iout; --i2) {
249  out[i2] = out[i2 - 1];
250  }
251  out[iout] = in[it];
252  break;
253  }
254  }
255  }
256  }
257 
258  template <typename T>
259  int deltaR2(const T &charged, const EGIsoObjEmu &egphoton) const {
260  // NOTE: we compare Tk at vertex against the calo variable...
261  return dr2_int(charged.hwVtxEta(), charged.hwVtxPhi(), egphoton.hwEta, egphoton.hwPhi);
262  }
263 
264  template <typename T>
265  int deltaR2(const T &charged, const EGIsoEleObjEmu &egele) const {
266  return dr2_int(charged.hwVtxEta(), charged.hwVtxPhi(), egele.hwVtxEta(), egele.hwVtxPhi());
267  }
268 
269  int deltaR2(const PFNeutralObjEmu &neutral, const EGIsoObjEmu &egphoton) const {
270  return dr2_int(neutral.hwEta, neutral.hwPhi, egphoton.hwEta, egphoton.hwPhi);
271  }
272 
273  int deltaR2(const PFNeutralObjEmu &neutral, const EGIsoEleObjEmu &egele) const {
274  // NOTE: we compare Tk at vertex against the calo variable...
275  return dr2_int(neutral.hwEta, neutral.hwPhi, egele.hwVtxEta(), egele.hwVtxPhi());
276  }
277 
278  template <typename T>
279  ap_int<z0_t::width + 1> deltaZ0(const T &charged, const EGIsoObjEmu &egphoton, z0_t z0) const {
280  ap_int<z0_t::width + 1> delta = charged.hwZ0 - z0;
281  if (delta < 0)
282  delta = -delta;
283  return delta;
284  }
285 
286  template <typename T>
287  ap_int<z0_t::width + 1> deltaZ0(const T &charged, const EGIsoEleObjEmu &egele, z0_t z0) const {
288  ap_int<z0_t::width + 1> delta = charged.hwZ0 - egele.hwZ0;
289  if (delta < 0)
290  delta = -delta;
291  return delta;
292  }
293 
294  template <typename TCH, typename TEG>
296  iso_t &sumPtPV,
297  const std::vector<TCH> &objects,
298  unsigned int nMaxObj,
299  const TEG &egobj,
301  z0_t z0) const {
302  for (unsigned int itk = 0; itk < std::min<unsigned>(objects.size(), nMaxObj); ++itk) {
303  const auto &obj = objects[itk];
304 
305  if (obj.hwPt < params.tkQualityPtMin)
306  continue;
307 
308  int dR2 = deltaR2(obj, egobj);
309 
310  if (dR2 > params.dRMin2 && dR2 < params.dRMax2) {
311  sumPt += obj.hwPt;
312  if (deltaZ0(obj, egobj, z0) < params.dZ) {
313  sumPtPV += obj.hwPt;
314  }
315  }
316  }
317  }
318 
319  template <typename TEG>
321  iso_t &sumPtPV,
322  const std::vector<PFNeutralObjEmu> &objects,
323  unsigned int nMaxObj,
324  const TEG &egobj,
326  z0_t z0) const {
327  for (unsigned int itk = 0; itk < std::min<unsigned>(objects.size(), nMaxObj); ++itk) {
328  const auto &obj = objects[itk];
329 
330  if (obj.hwPt < params.tkQualityPtMin)
331  continue;
332 
333  int dR2 = deltaR2(obj, egobj);
334 
335  if (dR2 > params.dRMin2 && dR2 < params.dRMax2) {
336  sumPt += obj.hwPt;
337  // PF neutrals are not constrained by PV (since their Z0 is 0 by design)
338  sumPtPV += obj.hwPt;
339  }
340  }
341  }
342 
343  void compute_isolation(std::vector<EGIsoObjEmu> &egobjs,
344  const std::vector<TkObjEmu> &objects,
346  z0_t z0) const;
347  void compute_isolation(std::vector<EGIsoEleObjEmu> &egobjs,
348  const std::vector<TkObjEmu> &objects,
350  z0_t z0) const;
351  void compute_isolation(std::vector<EGIsoObjEmu> &egobjs,
352  const std::vector<PFChargedObjEmu> &charged,
353  const std::vector<PFNeutralObjEmu> &neutrals,
355  z0_t z0) const;
356  void compute_isolation(std::vector<EGIsoEleObjEmu> &egobjs,
357  const std::vector<PFChargedObjEmu> &charged,
358  const std::vector<PFNeutralObjEmu> &neutrals,
360  z0_t z0) const;
361 
363  conifer::BDT<bdt_feature_t, ap_fixed<12, 3, AP_RND_CONV, AP_SAT>, false> *composite_bdt_;
364  int debug_;
365  };
366 } // namespace l1ct
367 
368 #endif
void sel_emCalo(unsigned int nmax_sel, const std::vector< EmCaloObjEmu > &emcalo, std::vector< EmCaloObjEmu > &emcalo_sel) const
glbphi_t hwVtxPhi() const
Definition: egamma.h:93
z0_t makeZ0(float z0)
Definition: datatypes.h:186
static edm::ParameterSetDescription getParameterSetDescription()
PFTkEGAlgoEmuConfig(const edm::ParameterSet &iConfig)
void setDebug(int verbose)
int deltaR2(const T &charged, const EGIsoEleObjEmu &egele) const
int dr2_int(eta_t eta1, phi_t phi1, eta_t eta2, phi_t phi2)
Definition: datatypes.h:221
float deltaPhi(float phi1, float phi2) const
CompIDParameters(const edm::ParameterSet &)
bool verbose
IsoParameters tkIsoParams_tkEle
void compute_sumPt(iso_t &sumPt, iso_t &sumPtPV, const std::vector< PFNeutralObjEmu > &objects, unsigned int nMaxObj, const TEG &egobj, const PFTkEGAlgoEmuConfig::IsoParameters &params, z0_t z0) const
id_score_t compute_composite_score(CompositeCandidate &cand, const std::vector< EmCaloObjEmu > &emcalo, const std::vector< TkObjEmu > &track, const PFTkEGAlgoEmuConfig::CompIDParameters &params) const
ap_int< z0_t::width+1 > deltaZ0(const T &charged, const EGIsoObjEmu &egphoton, z0_t z0) const
PFTkEGAlgoEmuConfig cfg
IsoParameters(float tkQualityPtMin, float dZ, float dRMin, float dRMax)
EGIsoEleObjEmu & addEGIsoEleToPF(std::vector< EGIsoEleObjEmu > &egobjs, const EmCaloObjEmu &calo, const TkObjEmu &track, const unsigned int hwQual, const pt_t ptCorr, const id_score_t bdtScore) const
ap_fixed< 12, 3, AP_RND_CONV, AP_SAT > bdt_score_t
eta_t hwEta
Definition: pf.h:11
Definition: config.py:1
pt_t makePtFromFloat(float pt)
Definition: datatypes.h:184
static edm::ParameterSetDescription getParameterSetDescription()
IsoParameters tkIsoParams_tkEm
IsoParameters(const edm::ParameterSet &)
EGObjEmu & addEGStaToPF(std::vector< EGObjEmu > &egobjs, const EmCaloObjEmu &calo, const unsigned int hwQual, const pt_t ptCorr, const std::vector< unsigned int > &components) const
phi_t hwPhi
Definition: pf.h:12
void runIso(const PFInputRegion &in, const std::vector< l1ct::PVObjEmu > &pvs, OutputRegion &out) const
int makeDR2FromFloatDR(float dr)
Definition: datatypes.h:210
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float dR2(Position4 pos1, Position4 pos2)
static edm::ParameterSetDescription getParameterSetDescription()
ap_ufixed< 11, 9, AP_TRN, AP_SAT > iso_t
Definition: datatypes.h:48
void toFirmware(const PFInputRegion &in, PFRegion &region, EmCaloObj calo[], TkObj track[]) const
ap_fixed< 10, 1, AP_RND_CONV, AP_SAT > id_score_t
Definition: datatypes.h:45
PFTkEGAlgoEmulator(const PFTkEGAlgoEmuConfig &config)
void link_emCalo2tk_elliptic(const PFRegionEmu &r, const std::vector< EmCaloObjEmu > &emcalo, const std::vector< TkObjEmu > &track, std::vector< int > &emCalo2tk) const
conifer::BDT< bdt_feature_t, ap_fixed< 12, 3, AP_RND_CONV, AP_SAT >, false > * composite_bdt_
ap_int< z0_t::width+1 > deltaZ0(const T &charged, const EGIsoEleObjEmu &egele, z0_t z0) const
glbeta_t hwVtxEta() const
Definition: egamma.h:94
glbeta_t hwEta
Definition: egamma.h:12
IsoParameters pfIsoParams_tkEm
void run(const PFInputRegion &in, OutputRegion &out) const
std::vector< double > dEtaValues
ap_fixed< 21, 12, AP_RND_CONV, AP_SAT > bdt_feature_t
int deltaR2(const PFNeutralObjEmu &neutral, const EGIsoObjEmu &egphoton) const
ap_int< 10 > z0_t
Definition: datatypes.h:30
void compute_isolation(std::vector< EGIsoObjEmu > &egobjs, const std::vector< TkObjEmu > &objects, const PFTkEGAlgoEmuConfig::IsoParameters &params, z0_t z0) const
void link_emCalo2tk_composite(const PFRegionEmu &r, const std::vector< EmCaloObjEmu > &emcalo, const std::vector< TkObjEmu > &track, std::vector< int > &emCalo2tk, std::vector< id_score_t > &emCaloTkBdtScore) const
EGIsoObjEmu & addEGIsoToPF(std::vector< EGIsoObjEmu > &egobjs, const EmCaloObjEmu &calo, const unsigned int hwQual, const pt_t ptCorr) const
int deltaR2(const PFNeutralObjEmu &neutral, const EGIsoEleObjEmu &egele) const
ap_ufixed< 14, 12, AP_TRN, AP_SAT > pt_t
Definition: datatypes.h:19
int deltaR2(const T &charged, const EGIsoObjEmu &egphoton) const
EGIsoEleObjEmu::IsoType hwIsoTypeTkEle
void eg_algo(const PFRegionEmu &region, const std::vector< EmCaloObjEmu > &emcalo, const std::vector< TkObjEmu > &track, const std::vector< int > &emCalo2emCalo, const std::vector< int > &emCalo2tk, const std::vector< id_score_t > &emCaloTkBdtScore, std::vector< EGObjEmu > &egstas, std::vector< EGIsoObjEmu > &egobjs, std::vector< EGIsoEleObjEmu > &egeleobjs) const
CompIDParameters compIDparams
unsigned int nCompCandPerCluster
IsoParameters pfIsoParams_tkEle
PFTkEGAlgoEmuConfig(unsigned int nTrack, unsigned int nTrack_in, unsigned int nEmCalo_in, unsigned int nEmOut, bool filterHwQuality, bool doBremRecovery, bool writeBeforeBremRecovery=false, int caloHwQual=4, bool doEndcapHwQual=false, float emClusterPtMin=2., float dEtaMaxBrem=0.02, float dPhiMaxBrem=0.1, const std::vector< double > &absEtaBoundaries={0.0, 1.5}, const std::vector< double > &dEtaValues={0.015, 0.01}, const std::vector< double > &dPhiValues={0.07, 0.07}, float trkQualityPtMin=10., bool doCompositeTkEle=false, unsigned int nCompCandPerCluster=4, bool writeEgSta=false, const IsoParameters &tkIsoParams_tkEle={2., 0.6, 0.03, 0.2}, const IsoParameters &tkIsoParams_tkEm={2., 0.6, 0.07, 0.3}, const IsoParameters &pfIsoParams_tkEle={1., 0.6, 0.03, 0.2}, const IsoParameters &pfIsoParams_tkEm={1., 0.6, 0.07, 0.3}, bool doTkIso=true, bool doPfIso=false, EGIsoEleObjEmu::IsoType hwIsoTypeTkEle=EGIsoEleObjEmu::IsoType::TkIso, EGIsoObjEmu::IsoType hwIsoTypeTkEm=EGIsoObjEmu::IsoType::TkIsoPV, const CompIDParameters &compIDparams={-4, 0.214844, "compositeID.json"}, int debug=0)
HLT enums.
std::vector< double > dPhiValues
void link_emCalo2emCalo(const std::vector< EmCaloObjEmu > &emcalo, std::vector< int > &emCalo2emCalo) const
std::vector< double > absEtaBoundaries
glbphi_t hwPhi
Definition: egamma.h:13
long double T
void ptsort_ref(int nIn, int nOut, const std::vector< T > &in, std::vector< T > &out) const
void addEgObjsToPF(std::vector< EGObjEmu > &egstas, std::vector< EGIsoObjEmu > &egobjs, std::vector< EGIsoEleObjEmu > &egeleobjs, const std::vector< EmCaloObjEmu > &emcalo, const std::vector< TkObjEmu > &track, const int calo_idx, const unsigned int hwQual, const pt_t ptCorr, const int tk_idx, const id_score_t bdtScore, const std::vector< unsigned int > &components={}) const
Definition: Common.h:9
CompIDParameters(double bdtScore_loose_wp, double bdtScore_tight_wp, const std::string &model)
EGIsoObjEmu::IsoType hwIsoTypeTkEm
void compute_sumPt(iso_t &sumPt, iso_t &sumPtPV, const std::vector< TCH > &objects, unsigned int nMaxObj, const TEG &egobj, const PFTkEGAlgoEmuConfig::IsoParameters &params, z0_t z0) const
Definition: datatypes.h:17