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