CMS 3D CMS Logo

layer1_emulator.h
Go to the documentation of this file.
1 #ifndef DataFormats_L1TParticleFlow_layer1_emulator_h
2 #define DataFormats_L1TParticleFlow_layer1_emulator_h
3 
4 #include <fstream>
5 #include <vector>
11 
12 namespace l1t {
13  class PFTrack;
14  class PFCluster;
15  class PFCandidate;
16  class SAMuon;
17 } // namespace l1t
18 
19 namespace l1ct {
20 
21  struct HadCaloObjEmu : public HadCaloObj {
22  const l1t::PFCluster *src = nullptr;
23  bool read(std::fstream &from);
24  bool write(std::fstream &to) const;
25  void clear() {
27  src = nullptr;
28  }
29  };
30 
31  struct EmCaloObjEmu : public EmCaloObj {
32  const l1t::PFCluster *src = nullptr;
33  bool read(std::fstream &from);
34  bool write(std::fstream &to) const;
35  void clear() {
37  src = nullptr;
38  }
39  };
40 
41  struct TkObjEmu : public TkObj {
42  uint16_t hwChi2;
44  const l1t::PFTrack *src = nullptr;
45  bool read(std::fstream &from);
46  bool write(std::fstream &to) const;
47  void clear() {
48  TkObj::clear();
49  src = nullptr;
50  hwChi2 = 0;
51  simPt = 0;
52  simCaloEta = 0;
53  simCaloPhi = 0;
54  simVtxEta = 0;
55  simVtxPhi = 0;
56  simZ0 = 0;
57  simD0 = 0;
58  }
59  };
60 
61  struct MuObjEmu : public MuObj {
62  const l1t::SAMuon *src = nullptr;
63  bool read(std::fstream &from);
64  bool write(std::fstream &to) const;
65  void clear() {
66  MuObj::clear();
67  src = nullptr;
68  }
69  };
70 
71  struct PFChargedObjEmu : public PFChargedObj {
72  const l1t::PFCluster *srcCluster = nullptr;
73  const l1t::PFTrack *srcTrack = nullptr;
74  const l1t::SAMuon *srcMu = nullptr;
75  const l1t::PFCandidate *srcCand = nullptr;
76  bool read(std::fstream &from);
77  bool write(std::fstream &to) const;
78  void clear() {
80  srcCluster = nullptr;
81  srcTrack = nullptr;
82  srcMu = nullptr;
83  srcCand = nullptr;
84  }
85  };
86 
87  struct PFNeutralObjEmu : public PFNeutralObj {
88  const l1t::PFCluster *srcCluster = nullptr;
89  const l1t::PFCandidate *srcCand = nullptr;
90  bool read(std::fstream &from);
91  bool write(std::fstream &to) const;
92  void clear() {
94  srcCluster = nullptr;
95  srcCand = nullptr;
96  }
97  };
98 
99  struct PFRegionEmu : public PFRegion {
101  PFRegionEmu(float etaCenter, float phicenter);
102  PFRegionEmu(float etamin, float etamax, float phicenter, float phiwidth, float etaextra, float phiextra);
103 
104  // global coordinates
105  bool contains(float eta, float phi) const;
106  bool containsHw(glbeta_t glbeta, glbphi_t phi) const;
107  float localEta(float globalEta) const;
108  float localPhi(float globalPhi) const;
109 
110  bool read(std::fstream &from);
111  bool write(std::fstream &to) const;
112  };
113 
114  struct PuppiObjEmu : public PuppiObj {
115  const l1t::PFCluster *srcCluster = nullptr;
116  const l1t::PFTrack *srcTrack = nullptr;
117  const l1t::SAMuon *srcMu = nullptr;
118  const l1t::PFCandidate *srcCand = nullptr;
119  bool read(std::fstream &from);
120  bool write(std::fstream &to) const;
121  void clear() {
122  PuppiObj::clear();
123  srcCluster = nullptr;
124  srcTrack = nullptr;
125  srcMu = nullptr;
126  srcCand = nullptr;
127  }
128  inline void fill(const PFRegionEmu &region, const PFChargedObjEmu &src) {
130  srcCluster = src.srcCluster;
131  srcTrack = src.srcTrack;
132  srcMu = src.srcMu;
133  srcCand = src.srcCand;
134  }
135  inline void fill(const PFRegionEmu &region, const PFNeutralObjEmu &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
136  PuppiObj::fill(region, src, puppiPt, puppiWgt);
137  srcCluster = src.srcCluster;
138  srcTrack = nullptr;
139  srcMu = nullptr;
140  srcCand = src.srcCand;
141  }
142  inline void fill(const PFRegionEmu &region, const HadCaloObjEmu &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
143  PuppiObj::fill(region, src, puppiPt, puppiWgt);
144  srcCluster = src.src;
145  srcTrack = nullptr;
146  srcMu = nullptr;
147  srcCand = nullptr;
148  }
149  };
150 
151  struct EGObjEmu : public EGIsoObj {
152  const l1t::PFCluster *srcCluster = nullptr;
153  void clear() {
154  srcCluster = nullptr;
155  EGIsoObj::clear();
156  }
157  };
158 
159  struct EGIsoObjEmu : public EGIsoObj {
161  // we use an index to the standalone object needed to retrieve a Ref when putting
162  int sta_idx;
163  bool read(std::fstream &from);
164  bool write(std::fstream &to) const;
165  void clear() {
166  EGIsoObj::clear();
167  srcCluster = nullptr;
168  sta_idx = -1;
169  clearIsoVars();
170  }
171 
172  void clearIsoVars() {
173  hwIsoVars[0] = 0;
174  hwIsoVars[1] = 0;
175  hwIsoVars[2] = 0;
176  hwIsoVars[3] = 0;
177  hwIsoVars[4] = 0;
178  hwIsoVars[5] = 0;
179  }
180 
181  using EGIsoObj::floatIso;
182 
183  enum IsoType { TkIso = 0, PfIso = 1, TkIsoPV = 2, PfIsoPV = 3, PuppiIso = 4, PuppiIsoPV = 5 };
184 
185  float floatIso(IsoType type) const { return Scales::floatIso(hwIsoVars[type]); }
187  float hwIsoVar(IsoType type) const { return hwIsoVars[type]; }
189 
191  };
192 
193  struct EGIsoEleObjEmu : public EGIsoEleObj {
194  const l1t::PFCluster *srcCluster = nullptr;
195  const l1t::PFTrack *srcTrack = nullptr;
196  // we use an index to the standalone object needed to retrieve a Ref when putting
197  int sta_idx;
198  float idScore;
199  bool read(std::fstream &from);
200  bool write(std::fstream &to) const;
201  void clear() {
203  srcCluster = nullptr;
204  srcTrack = nullptr;
205  sta_idx = -1;
206  idScore = -999;
207  clearIsoVars();
208  }
209 
210  void clearIsoVars() {
211  hwIsoVars[0] = 0;
212  hwIsoVars[1] = 0;
213  hwIsoVars[2] = 0;
214  }
215 
216  using EGIsoEleObj::floatIso;
217 
218  enum IsoType { TkIso = 0, PfIso = 1, PuppiIso = 2 };
219 
220  float floatIso(IsoType type) const { return Scales::floatIso(hwIsoVars[type]); }
222  float hwIsoVar(IsoType type) const { return hwIsoVars[type]; }
224 
226  };
227 
228  struct PVObjEmu : public PVObj {
229  bool read(std::fstream &from);
230  bool write(std::fstream &to) const;
231  };
232 
233  template <typename T>
234  struct DetectorSector {
236  std::vector<T> obj;
238  DetectorSector(float etamin, float etamax, float phicenter, float phiwidth, float etaextra = 0, float phiextra = 0)
239  : region(etamin, etamax, phicenter, phiwidth, etaextra, phiextra) {}
240  // convenience forwarding of some methods
241  typedef typename std::vector<T>::const_iterator const_iterator;
242  typedef typename std::vector<T>::iterator iterator;
243  inline const T &operator[](unsigned int i) const { return obj[i]; }
244  inline T &operator[](unsigned int i) { return obj[i]; }
245  inline const_iterator begin() const { return obj.begin(); }
246  inline iterator begin() { return obj.begin(); }
247  inline const_iterator end() const { return obj.end(); }
248  inline iterator end() { return obj.end(); }
249  inline unsigned int size() const { return obj.size(); }
250  inline void resize(unsigned int size) { obj.resize(size); }
251  inline void clear() { obj.clear(); }
252  };
253 
254  struct RawInputs {
255  std::vector<DetectorSector<ap_uint<96>>> track;
256  DetectorSector<ap_uint<64>> muon; // muons are global
257  std::vector<DetectorSector<ap_uint<256>>> hgcalcluster;
258 
259  bool read(std::fstream &from);
260  bool write(std::fstream &to) const;
261  void clear();
262  };
263 
265  std::vector<DetectorSector<HadCaloObjEmu>> hadcalo;
266  std::vector<DetectorSector<EmCaloObjEmu>> emcalo;
267  std::vector<DetectorSector<TkObjEmu>> track;
268  DetectorSector<MuObjEmu> muon; // muons are global
269 
270  bool read(std::fstream &from);
271  bool write(std::fstream &to) const;
272  void clear();
273  };
274 
275  struct PFInputRegion {
277  std::vector<HadCaloObjEmu> hadcalo;
278  std::vector<EmCaloObjEmu> emcalo;
279  std::vector<TkObjEmu> track;
280  std::vector<MuObjEmu> muon;
281 
283  PFInputRegion(float etamin, float etamax, float phicenter, float phiwidth, float etaextra, float phiextra)
284  : region(etamin, etamax, phicenter, phiwidth, etaextra, phiextra) {}
285  bool read(std::fstream &from);
286  bool write(std::fstream &to) const;
287  void clear();
288  };
289 
290  struct OutputRegion {
291  std::vector<PFChargedObjEmu> pfcharged;
292  std::vector<PFNeutralObjEmu> pfphoton;
293  std::vector<PFNeutralObjEmu> pfneutral;
294  std::vector<PFChargedObjEmu> pfmuon;
295  std::vector<PuppiObjEmu> puppi;
296  std::vector<EGObjEmu> egsta;
297  std::vector<EGIsoObjEmu> egphoton;
298  std::vector<EGIsoEleObjEmu> egelectron;
299 
300  bool read(std::fstream &from);
301  bool write(std::fstream &to) const;
302  void clear();
303 
304  // for multiplicities
305  enum ObjType {
306  anyType = 0,
310  muonType = 4,
314  nPFTypes = 8,
318  };
319  static constexpr const char *objTypeName[nObjTypes] = {
320  "", "Charged", "Neutral", "Electron", "Muon", "ChargedHadron", "NeutralHadron", "Photon", "EGIso", "EGIsoEle"};
321  unsigned int nObj(ObjType type, bool puppi) const;
322  };
323 
324  struct OutputBoard {
325  float eta;
326  float phi;
327  // NOTE: region_index is not written to the dump file
328  std::vector<unsigned int> region_index;
329  std::vector<EGIsoObjEmu> egphoton;
330  std::vector<EGIsoEleObjEmu> egelectron;
331 
332  bool read(std::fstream &from);
333  bool write(std::fstream &to) const;
334  void clear();
335  };
336 
337  struct Event {
338  enum { VERSION = 12 };
339  uint32_t run, lumi;
343  std::vector<PFInputRegion> pfinputs;
344  std::vector<PVObjEmu> pvs;
345  std::vector<ap_uint<64>> pvs_emu;
346  std::vector<OutputRegion> out;
347  std::vector<OutputBoard> board_out;
348 
349  Event() : run(0), lumi(0), event(0) {}
350 
351  bool read(std::fstream &from);
352  bool write(std::fstream &to) const;
353  void clear();
354  void init(uint32_t run, uint32_t lumi, uint64_t event);
355  inline l1ct::PVObjEmu pv(unsigned int ipv = 0) const {
357  if (ipv < pvs.size())
358  ret = pvs[ipv];
359  else
360  ret.clear();
361  return ret;
362  }
363  inline ap_uint<64> pv_emu(unsigned int ipv = 0) const {
364  ap_uint<64> ret = 0;
365  if (ipv < pvs_emu.size())
366  ret = pvs_emu[ipv];
367  return ret;
368  }
369  };
370 
371  template <typename T1, typename T2>
372  void toFirmware(const std::vector<T1> &in, unsigned int NMAX, T2 out[/*NMAX*/]) {
373  unsigned int n = std::min<unsigned>(in.size(), NMAX);
374  for (unsigned int i = 0; i < n; ++i)
375  out[i] = in[i];
376  for (unsigned int i = n; i < NMAX; ++i)
377  out[i].clear();
378  }
379 
380 } // namespace l1ct
381 
382 #endif
void clear()
Definition: puppi.h:109
bool write(std::fstream &to) const
const l1t::PFCluster * srcCluster
bool read(std::fstream &from)
std::vector< PVObjEmu > pvs
bool write(std::fstream &to) const
const l1t::PFCluster * srcCluster
void fill(const PFRegionEmu &region, const PFNeutralObjEmu &src, pt_t puppiPt, puppiWgt_t puppiWgt)
void setHwIso(IsoType type, iso_t value)
DetectorSector< ap_uint< 64 > > muon
const_iterator begin() const
float floatIso(IsoType type) const
std::vector< T > obj
bool read(std::fstream &from)
std::vector< HadCaloObjEmu > hadcalo
bool containsHw(glbeta_t glbeta, glbphi_t phi) const
const l1t::PFTrack * srcTrack
void clear()
Definition: pf.h:64
bool write(std::fstream &to) const
bool write(std::fstream &to) const
unsigned int size() const
ret
prodAgent to be discontinued
std::vector< EGObjEmu > egsta
void toFirmware(const std::vector< T1 > &in, unsigned int NMAX, T2 out[])
bool write(std::fstream &to) const
bool write(std::fstream &to) const
uint64_t event
void clear()
Definition: egamma.h:36
std::vector< PFChargedObjEmu > pfcharged
float localEta(float globalEta) const
const l1t::SAMuon * srcMu
const T & operator[](unsigned int i) const
const l1t::PFTrack * src
std::vector< MuObjEmu > muon
float localPhi(float globalPhi) const
const l1t::PFCandidate * srcCand
std::vector< unsigned int > region_index
std::vector< TkObjEmu > track
delete x;
Definition: CaloConfig.h:22
std::vector< EGIsoEleObjEmu > egelectron
std::vector< OutputRegion > out
const l1t::PFCluster * srcCluster
void clear()
Definition: layer1_objs.h:197
DetectorSector(float etamin, float etamax, float phicenter, float phiwidth, float etaextra=0, float phiextra=0)
float hwIsoVar(IsoType type) const
float hwIsoVar(IsoType type) const
std::vector< EmCaloObjEmu > emcalo
void init(uint32_t run, uint32_t lumi, uint64_t event)
bool read(std::fstream &from)
const l1t::PFCandidate * srcCand
bool contains(float eta, float phi) const
bool write(std::fstream &to) const
void resize(unsigned int size)
std::vector< PuppiObjEmu > puppi
float floatRelIso(IsoType type) const
bool read(std::fstream &from)
std::vector< EGIsoEleObjEmu > egelectron
std::vector< T >::iterator iterator
float floatRelIso(IsoType type) const
bool write(std::fstream &to) const
bool read(std::fstream &from)
bool write(std::fstream &to) const
ap_int< 11 > glbphi_t
Definition: datatypes.h:28
float floatPt() const
Definition: egamma.h:23
std::vector< EGIsoObjEmu > egphoton
bool read(std::fstream &from)
bool write(std::fstream &to) const
std::vector< PFChargedObjEmu > pfmuon
float floatIso(IsoType type) const
ap_ufixed< 11, 9, AP_TRN, AP_SAT > iso_t
Definition: datatypes.h:47
void setHwIso(IsoType type, iso_t value)
const l1t::SAMuon * srcMu
bool read(std::fstream &from)
bool write(std::fstream &to) const
ap_uint< 9 > puppiWgt_t
Definition: datatypes.h:33
RawInputs raw
bool read(std::fstream &from)
Definition: value.py:1
std::vector< DetectorSector< HadCaloObjEmu > > hadcalo
const l1t::PFCluster * srcCluster
float floatIso() const
Definition: egamma.h:26
std::vector< DetectorSector< ap_uint< 96 > > > track
RegionizerDecodedInputs decoded
void clear()
Definition: layer1_objs.h:297
bool read(std::fstream &from)
bool write(std::fstream &to) const
std::vector< T >::const_iterator const_iterator
ap_ufixed< 14, 12, AP_TRN, AP_SAT > pt_t
Definition: datatypes.h:19
std::vector< PFNeutralObjEmu > pfneutral
bool write(std::fstream &to) const
bool read(std::fstream &from)
bool read(std::fstream &from)
const l1t::PFCluster * srcCluster
unsigned long long uint64_t
Definition: Time.h:13
unsigned int nObj(ObjType type, bool puppi) const
void fill(const PFRegionEmu &region, const HadCaloObjEmu &src, pt_t puppiPt, puppiWgt_t puppiWgt)
bool write(std::fstream &to) const
bool read(std::fstream &from)
std::vector< DetectorSector< EmCaloObjEmu > > emcalo
static constexpr const char * objTypeName[nObjTypes]
bool read(std::fstream &from)
const l1t::PFCluster * src
bool read(std::fstream &from)
void clear()
Definition: pf.h:125
std::vector< EGIsoObjEmu > egphoton
T & operator[](unsigned int i)
bool read(std::fstream &from)
bool write(std::fstream &to) const
std::vector< PFNeutralObjEmu > pfphoton
bool read(std::fstream &from)
ap_uint< 64 > pv_emu(unsigned int ipv=0) const
const l1t::PFTrack * srcTrack
void clear()
Definition: egamma.h:104
const l1t::PFCluster * srcCluster
void fill(const PFRegion &region, const PFChargedObj &src)
Definition: puppi.h:117
bool read(std::fstream &from)
bool write(std::fstream &to) const
const l1t::PFTrack * srcTrack
const_iterator end() const
void clear(EGIsoObj &c)
Definition: egamma.h:82
DetectorSector< MuObjEmu > muon
float floatIso(iso_t iso)
Definition: datatypes.h:175
l1ct::PVObjEmu pv(unsigned int ipv=0) const
long double T
std::vector< ap_uint< 64 > > pvs_emu
std::vector< DetectorSector< ap_uint< 256 > > > hgcalcluster
std::vector< DetectorSector< TkObjEmu > > track
const l1t::SAMuon * src
const l1t::PFCluster * src
bool write(std::fstream &to) const
void clear()
ap_int< 12 > glbeta_t
Definition: datatypes.h:27
void fill(const PFRegionEmu &region, const PFChargedObjEmu &src)
Definition: event.py:1
PFInputRegion(float etamin, float etamax, float phicenter, float phiwidth, float etaextra, float phiextra)
const l1t::PFCandidate * srcCand
std::vector< PFInputRegion > pfinputs
Definition: datatypes.h:17
std::vector< OutputBoard > board_out