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