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 
162  // NOTE: we use an index to the persistable RefPtr when we reshuffle collections
163  // this way we avoid complex object in the object interface which needs to be used in standalone programs
164  int src_idx;
165  bool read(std::fstream &from);
166  bool write(std::fstream &to) const;
167  void clear() {
168  EGIsoObj::clear();
169  srcCluster = nullptr;
170  src_idx = -1;
171  clearIsoVars();
172  }
173 
174  void clearIsoVars() {
175  hwIsoVars[0] = 0;
176  hwIsoVars[1] = 0;
177  hwIsoVars[2] = 0;
178  hwIsoVars[3] = 0;
179  hwIsoVars[4] = 0;
180  hwIsoVars[5] = 0;
181  }
182 
183  using EGIsoObj::floatIso;
184 
185  enum IsoType { TkIso = 0, PfIso = 1, TkIsoPV = 2, PfIsoPV = 3, PuppiIso = 4, PuppiIsoPV = 5 };
186 
187  float floatIso(IsoType type) const { return Scales::floatIso(hwIsoVars[type]); }
189  float hwIsoVar(IsoType type) const { return hwIsoVars[type]; }
191 
193  };
194 
195  struct EGIsoEleObjEmu : public EGIsoEleObj {
196  const l1t::PFCluster *srcCluster = nullptr;
197  const l1t::PFTrack *srcTrack = nullptr;
198 
199  // NOTE: we use an index to the persistable RefPtr when we reshuffle collections
200  // this way we avoid complex object in the object interface which needs to be used in standalone programs
201  int src_idx;
202  bool read(std::fstream &from);
203  bool write(std::fstream &to) const;
204  void clear() {
206  srcCluster = nullptr;
207  srcTrack = nullptr;
208  src_idx = -1;
209  clearIsoVars();
210  }
211 
212  void clearIsoVars() {
213  hwIsoVars[0] = 0;
214  hwIsoVars[1] = 0;
215  hwIsoVars[2] = 0;
216  }
217 
218  using EGIsoEleObj::floatIso;
219 
220  enum IsoType { TkIso = 0, PfIso = 1, PuppiIso = 2 };
221 
222  float floatIso(IsoType type) const { return Scales::floatIso(hwIsoVars[type]); }
224  float hwIsoVar(IsoType type) const { return hwIsoVars[type]; }
226 
228  };
229 
230  struct PVObjEmu : public PVObj {
231  bool read(std::fstream &from);
232  bool write(std::fstream &to) const;
233  };
234 
235  template <typename T>
236  struct DetectorSector {
238  std::vector<T> obj;
240  DetectorSector(float etamin, float etamax, float phicenter, float phiwidth, float etaextra = 0, float phiextra = 0)
241  : region(etamin, etamax, phicenter, phiwidth, etaextra, phiextra) {}
242  // convenience forwarding of some methods
243  typedef typename std::vector<T>::const_iterator const_iterator;
244  typedef typename std::vector<T>::iterator iterator;
245  inline const T &operator[](unsigned int i) const { return obj[i]; }
246  inline T &operator[](unsigned int i) { return obj[i]; }
247  inline const_iterator begin() const { return obj.begin(); }
248  inline iterator begin() { return obj.begin(); }
249  inline const_iterator end() const { return obj.end(); }
250  inline iterator end() { return obj.end(); }
251  inline unsigned int size() const { return obj.size(); }
252  inline void resize(unsigned int size) { obj.resize(size); }
253  inline void clear() { obj.clear(); }
254  };
255 
256  struct RawInputs {
257  std::vector<DetectorSector<ap_uint<96>>> track;
258  DetectorSector<ap_uint<64>> muon; // muons are global
259  std::vector<DetectorSector<ap_uint<256>>> hgcalcluster;
260 
261  bool read(std::fstream &from);
262  bool write(std::fstream &to) const;
263  void clear();
264  };
265 
267  std::vector<DetectorSector<HadCaloObjEmu>> hadcalo;
268  std::vector<DetectorSector<EmCaloObjEmu>> emcalo;
269  std::vector<DetectorSector<TkObjEmu>> track;
270  DetectorSector<MuObjEmu> muon; // muons are global
271 
272  bool read(std::fstream &from);
273  bool write(std::fstream &to) const;
274  void clear();
275  };
276 
277  struct PFInputRegion {
279  std::vector<HadCaloObjEmu> hadcalo;
280  std::vector<EmCaloObjEmu> emcalo;
281  std::vector<TkObjEmu> track;
282  std::vector<MuObjEmu> muon;
283 
285  PFInputRegion(float etamin, float etamax, float phicenter, float phiwidth, float etaextra, float phiextra)
286  : region(etamin, etamax, phicenter, phiwidth, etaextra, phiextra) {}
287  bool read(std::fstream &from);
288  bool write(std::fstream &to) const;
289  void clear();
290  };
291 
292  struct OutputRegion {
293  std::vector<PFChargedObjEmu> pfcharged;
294  std::vector<PFNeutralObjEmu> pfphoton;
295  std::vector<PFNeutralObjEmu> pfneutral;
296  std::vector<PFChargedObjEmu> pfmuon;
297  std::vector<PuppiObjEmu> puppi;
298  std::vector<EGObjEmu> egsta;
299  std::vector<EGIsoObjEmu> egphoton;
300  std::vector<EGIsoEleObjEmu> egelectron;
301 
302  bool read(std::fstream &from);
303  bool write(std::fstream &to) const;
304  void clear();
305 
306  // for multiplicities
307  enum ObjType {
308  anyType = 0,
312  muonType = 4,
316  nPFTypes = 8,
320  };
321  static constexpr const char *objTypeName[nObjTypes] = {
322  "", "Charged", "Neutral", "Electron", "Muon", "ChargedHadron", "NeutralHadron", "Photon", "EGIso", "EGIsoEle"};
323  unsigned int nObj(ObjType type, bool puppi) const;
324  };
325 
326  struct OutputBoard {
327  float eta;
328  float phi;
329  // NOTE: region_index is not written to the dump file
330  std::vector<unsigned int> region_index;
331  std::vector<EGIsoObjEmu> egphoton;
332  std::vector<EGIsoEleObjEmu> egelectron;
333 
334  bool read(std::fstream &from);
335  bool write(std::fstream &to) const;
336  void clear();
337  };
338 
339  struct Event {
340  enum { VERSION = 13 };
341  uint32_t run, lumi;
345  std::vector<PFInputRegion> pfinputs;
346  std::vector<PVObjEmu> pvs;
347  std::vector<ap_uint<64>> pvs_emu;
348  std::vector<OutputRegion> out;
349  std::vector<OutputBoard> board_out;
350 
351  Event() : run(0), lumi(0), event(0) {}
352 
353  bool read(std::fstream &from);
354  bool write(std::fstream &to) const;
355  void clear();
356  void init(uint32_t run, uint32_t lumi, uint64_t event);
357  inline l1ct::PVObjEmu pv(unsigned int ipv = 0) const {
359  if (ipv < pvs.size())
360  ret = pvs[ipv];
361  else
362  ret.clear();
363  return ret;
364  }
365  inline ap_uint<64> pv_emu(unsigned int ipv = 0) const {
366  ap_uint<64> ret = 0;
367  if (ipv < pvs_emu.size())
368  ret = pvs_emu[ipv];
369  return ret;
370  }
371  };
372 
373  template <typename T1, typename T2>
374  void toFirmware(const std::vector<T1> &in, unsigned int NMAX, T2 out[/*NMAX*/]) {
375  unsigned int n = std::min<unsigned>(in.size(), NMAX);
376  for (unsigned int i = 0; i < n; ++i)
377  out[i] = in[i];
378  for (unsigned int i = n; i < NMAX; ++i)
379  out[i].clear();
380  }
381 
382 } // namespace l1ct
383 
384 #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:19
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:39
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:24
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:10
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:105
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:173
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:18
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:8
std::vector< OutputBoard > board_out