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 
7 
8 namespace edm {
9  class ParameterSet;
10 }
11 
12 namespace l1ct {
13 
15  unsigned int nTRACK;
16  unsigned int nTRACK_EGIN;
17  unsigned int nEMCALO_EGIN;
18  unsigned int nEM_EGOUT;
19 
25  float emClusterPtMin; // GeV
26  float dEtaMaxBrem;
27  float dPhiMaxBrem;
28 
29  std::vector<double> absEtaBoundaries;
30  std::vector<double> dEtaValues;
31  std::vector<double> dPhiValues;
32  float trkQualityPtMin; // GeV
33  bool writeEgSta;
34 
35  struct IsoParameters {
37  IsoParameters(float tkQualityPtMin, float dZ, float dRMin, float dRMax)
39  dZ(Scales::makeZ0(dZ)),
41  dRMax2(Scales::makeDR2FromFloatDR(dRMax)) {}
43  ap_int<z0_t::width + 1> dZ;
44  int dRMin2;
45  int dRMax2;
46  };
47 
52  bool doTkIso;
53  bool doPfIso;
56  int debug = 0;
57 
58  PFTkEGAlgoEmuConfig(const edm::ParameterSet &iConfig);
60  unsigned int nTrack_in,
61  unsigned int nEmCalo_in,
62  unsigned int nEmOut,
63  bool filterHwQuality,
64  bool doBremRecovery,
65  bool writeBeforeBremRecovery = false,
66  int caloHwQual = 4,
67  bool doEndcapHwQual = false,
68  float emClusterPtMin = 2.,
69  float dEtaMaxBrem = 0.02,
70  float dPhiMaxBrem = 0.1,
71  const std::vector<double> &absEtaBoundaries = {0.0, 1.5},
72  const std::vector<double> &dEtaValues = {0.015, 0.01},
73  const std::vector<double> &dPhiValues = {0.07, 0.07},
74  float trkQualityPtMin = 10.,
75  bool writeEgSta = false,
76  const IsoParameters &tkIsoParams_tkEle = {2., 0.6, 0.03, 0.2},
77  const IsoParameters &tkIsoParams_tkEm = {2., 0.6, 0.07, 0.3},
78  const IsoParameters &pfIsoParams_tkEle = {1., 0.6, 0.03, 0.2},
79  const IsoParameters &pfIsoParams_tkEm = {1., 0.6, 0.07, 0.3},
80  bool doTkIso = true,
81  bool doPfIso = false,
82  EGIsoEleObjEmu::IsoType hwIsoTypeTkEle = EGIsoEleObjEmu::IsoType::TkIso,
83  EGIsoObjEmu::IsoType hwIsoTypeTkEm = EGIsoObjEmu::IsoType::TkIsoPV,
84  int debug = 0)
85 
86  : nTRACK(nTrack),
87  nTRACK_EGIN(nTrack_in),
88  nEMCALO_EGIN(nEmCalo_in),
89  nEM_EGOUT(nEmOut),
107  doTkIso(doTkIso),
108  doPfIso(doPfIso),
111  debug(debug) {}
112  };
113 
115  public:
117 
118  virtual ~PFTkEGAlgoEmulator() {}
119 
120  void toFirmware(const PFInputRegion &in, PFRegion &region, EmCaloObj calo[/*nCALO*/], TkObj track[/*nTRACK*/]) const;
121  void toFirmware(const OutputRegion &out, EGIsoObj out_egphs[], EGIsoEleObj out_egeles[]) const;
122  void toFirmware(const PFInputRegion &in,
123  const l1ct::PVObjEmu &pvin,
124  PFRegion &region,
125  TkObj track[/*nTRACK*/],
126  PVObj &pv) const;
127 
128  void run(const PFInputRegion &in, OutputRegion &out) const;
129  void runIso(const PFInputRegion &in, const std::vector<l1ct::PVObjEmu> &pvs, OutputRegion &out) const;
130 
131  void setDebug(int verbose) { debug_ = verbose; }
132 
133  bool writeEgSta() const { return cfg.writeEgSta; }
134 
135  private:
136  void link_emCalo2emCalo(const std::vector<EmCaloObjEmu> &emcalo, std::vector<int> &emCalo2emCalo) const;
137 
138  void link_emCalo2tk(const PFRegionEmu &r,
139  const std::vector<EmCaloObjEmu> &emcalo,
140  const std::vector<TkObjEmu> &track,
141  std::vector<int> &emCalo2tk) const;
142 
143  //FIXME: still needed
144  float deltaPhi(float phi1, float phi2) const;
145 
146  void sel_emCalo(unsigned int nmax_sel,
147  const std::vector<EmCaloObjEmu> &emcalo,
148  std::vector<EmCaloObjEmu> &emcalo_sel) const;
149 
150  void eg_algo(const PFRegionEmu &region,
151  const std::vector<EmCaloObjEmu> &emcalo,
152  const std::vector<TkObjEmu> &track,
153  const std::vector<int> &emCalo2emCalo,
154  const std::vector<int> &emCalo2tk,
155  std::vector<EGObjEmu> &egstas,
156  std::vector<EGIsoObjEmu> &egobjs,
157  std::vector<EGIsoEleObjEmu> &egeleobjs) const;
158 
159  void addEgObjsToPF(std::vector<EGObjEmu> &egstas,
160  std::vector<EGIsoObjEmu> &egobjs,
161  std::vector<EGIsoEleObjEmu> &egeleobjs,
162  const std::vector<EmCaloObjEmu> &emcalo,
163  const std::vector<TkObjEmu> &track,
164  const int calo_idx,
165  const unsigned int hwQual,
166  const pt_t ptCorr,
167  const int tk_idx,
168  const std::vector<unsigned int> &components = {}) const;
169 
170  EGObjEmu &addEGStaToPF(std::vector<EGObjEmu> &egobjs,
171  const EmCaloObjEmu &calo,
172  const unsigned int hwQual,
173  const pt_t ptCorr,
174  const std::vector<unsigned int> &components) const;
175 
176  EGIsoObjEmu &addEGIsoToPF(std::vector<EGIsoObjEmu> &egobjs,
177  const EmCaloObjEmu &calo,
178  const unsigned int hwQual,
179  const pt_t ptCorr) const;
180 
181  EGIsoEleObjEmu &addEGIsoEleToPF(std::vector<EGIsoEleObjEmu> &egobjs,
182  const EmCaloObjEmu &calo,
183  const TkObjEmu &track,
184  const unsigned int hwQual,
185  const pt_t ptCorr) const;
186 
187  // FIXME: reimplemented from PFAlgoEmulatorBase
188  template <typename T>
189  void ptsort_ref(int nIn, int nOut, const std::vector<T> &in, std::vector<T> &out) const {
190  out.resize(nOut);
191  for (int iout = 0; iout < nOut; ++iout) {
192  out[iout].clear();
193  }
194  for (int it = 0; it < nIn; ++it) {
195  for (int iout = 0; iout < nOut; ++iout) {
196  if (in[it].hwPt >= out[iout].hwPt) {
197  for (int i2 = nOut - 1; i2 > iout; --i2) {
198  out[i2] = out[i2 - 1];
199  }
200  out[iout] = in[it];
201  break;
202  }
203  }
204  }
205  }
206 
207  template <typename T>
208  int deltaR2(const T &charged, const EGIsoObjEmu &egphoton) const {
209  // NOTE: we compare Tk at vertex against the calo variable...
210  return dr2_int(charged.hwVtxEta(), charged.hwVtxPhi(), egphoton.hwEta, egphoton.hwPhi);
211  }
212 
213  template <typename T>
214  int deltaR2(const T &charged, const EGIsoEleObjEmu &egele) const {
215  return dr2_int(charged.hwVtxEta(), charged.hwVtxPhi(), egele.hwVtxEta(), egele.hwVtxPhi());
216  }
217 
218  int deltaR2(const PFNeutralObjEmu &neutral, const EGIsoObjEmu &egphoton) const {
219  return dr2_int(neutral.hwEta, neutral.hwPhi, egphoton.hwEta, egphoton.hwPhi);
220  }
221 
222  int deltaR2(const PFNeutralObjEmu &neutral, const EGIsoEleObjEmu &egele) const {
223  // NOTE: we compare Tk at vertex against the calo variable...
224  return dr2_int(neutral.hwEta, neutral.hwPhi, egele.hwVtxEta(), egele.hwVtxPhi());
225  }
226 
227  template <typename T>
228  ap_int<z0_t::width + 1> deltaZ0(const T &charged, const EGIsoObjEmu &egphoton, z0_t z0) const {
229  ap_int<z0_t::width + 1> delta = charged.hwZ0 - z0;
230  if (delta < 0)
231  delta = -delta;
232  return delta;
233  }
234 
235  template <typename T>
236  ap_int<z0_t::width + 1> deltaZ0(const T &charged, const EGIsoEleObjEmu &egele, z0_t z0) const {
237  ap_int<z0_t::width + 1> delta = charged.hwZ0 - egele.hwZ0;
238  if (delta < 0)
239  delta = -delta;
240  return delta;
241  }
242 
243  template <typename TCH, typename TEG>
245  iso_t &sumPtPV,
246  const std::vector<TCH> &objects,
247  unsigned int nMaxObj,
248  const TEG &egobj,
250  z0_t z0) const {
251  for (unsigned int itk = 0; itk < std::min<unsigned>(objects.size(), nMaxObj); ++itk) {
252  const auto &obj = objects[itk];
253 
254  if (obj.hwPt < params.tkQualityPtMin)
255  continue;
256 
257  int dR2 = deltaR2(obj, egobj);
258 
259  if (dR2 > params.dRMin2 && dR2 < params.dRMax2) {
260  sumPt += obj.hwPt;
261  if (deltaZ0(obj, egobj, z0) < params.dZ) {
262  sumPtPV += obj.hwPt;
263  }
264  }
265  }
266  }
267 
268  template <typename TEG>
270  iso_t &sumPtPV,
271  const std::vector<PFNeutralObjEmu> &objects,
272  unsigned int nMaxObj,
273  const TEG &egobj,
275  z0_t z0) const {
276  for (unsigned int itk = 0; itk < std::min<unsigned>(objects.size(), nMaxObj); ++itk) {
277  const auto &obj = objects[itk];
278 
279  if (obj.hwPt < params.tkQualityPtMin)
280  continue;
281 
282  int dR2 = deltaR2(obj, egobj);
283 
284  if (dR2 > params.dRMin2 && dR2 < params.dRMax2) {
285  sumPt += obj.hwPt;
286  // PF neutrals are not constrained by PV (since their Z0 is 0 by design)
287  sumPtPV += obj.hwPt;
288  }
289  }
290  }
291 
292  void compute_isolation(std::vector<EGIsoObjEmu> &egobjs,
293  const std::vector<TkObjEmu> &objects,
295  z0_t z0) const;
296  void compute_isolation(std::vector<EGIsoEleObjEmu> &egobjs,
297  const std::vector<TkObjEmu> &objects,
299  z0_t z0) const;
300  void compute_isolation(std::vector<EGIsoObjEmu> &egobjs,
301  const std::vector<PFChargedObjEmu> &charged,
302  const std::vector<PFNeutralObjEmu> &neutrals,
304  z0_t z0) const;
305  void compute_isolation(std::vector<EGIsoEleObjEmu> &egobjs,
306  const std::vector<PFChargedObjEmu> &charged,
307  const std::vector<PFNeutralObjEmu> &neutrals,
309  z0_t z0) const;
310 
312  int debug_;
313  };
314 } // namespace l1ct
315 
316 #endif
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:172
void link_emCalo2tk(const PFRegionEmu &r, const std::vector< EmCaloObjEmu > &emcalo, const std::vector< TkObjEmu > &track, std::vector< int > &emCalo2tk) const
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:204
float deltaPhi(float phi1, float phi2) const
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
eta_t hwEta
Definition: pf.h:11
Definition: config.py:1
pt_t makePtFromFloat(float pt)
Definition: datatypes.h:170
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:196
ap_ufixed< 11, 9, AP_TRN, AP_SAT > iso_t
Definition: datatypes.h:43
void toFirmware(const PFInputRegion &in, PFRegion &region, EmCaloObj calo[], TkObj track[]) const
PFTkEGAlgoEmulator(const PFTkEGAlgoEmuConfig &config)
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, std::vector< EGObjEmu > &egstas, std::vector< EGIsoObjEmu > &egobjs, std::vector< EGIsoEleObjEmu > &egeleobjs) const
ap_int< z0_t::width+1 > deltaZ0(const T &charged, const EGIsoEleObjEmu &egele, z0_t z0) const
glbeta_t hwEta
Definition: egamma.h:12
EGIsoEleObjEmu & addEGIsoEleToPF(std::vector< EGIsoEleObjEmu > &egobjs, const EmCaloObjEmu &calo, const TkObjEmu &track, const unsigned int hwQual, const pt_t ptCorr) const
phi_t hwVtxPhi() const
Definition: egamma.h:92
IsoParameters pfIsoParams_tkEm
void run(const PFInputRegion &in, OutputRegion &out) const
std::vector< double > dEtaValues
int deltaR2(const PFNeutralObjEmu &neutral, const EGIsoObjEmu &egphoton) const
ap_int< 10 > z0_t
Definition: datatypes.h:32
void compute_isolation(std::vector< EGIsoObjEmu > &egobjs, const std::vector< TkObjEmu > &objects, const PFTkEGAlgoEmuConfig::IsoParameters &params, z0_t z0) 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:21
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 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, int debug=0)
#define debug
Definition: HDRShower.cc:19
int deltaR2(const T &charged, const EGIsoObjEmu &egphoton) 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 std::vector< unsigned int > &components={}) const
EGIsoEleObjEmu::IsoType hwIsoTypeTkEle
IsoParameters pfIsoParams_tkEle
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
ap_ufixed< 16, 14 > pt_t
Definition: TauNNIdHW.h:27
void ptsort_ref(int nIn, int nOut, const std::vector< T > &in, std::vector< T > &out) const
Definition: Common.h:9
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:19