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 {
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 {
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, hwStubs;
44  const l1t::PFTrack *src;
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  hwStubs = 0;
52  simPt = 0;
53  simCaloEta = 0;
54  simCaloPhi = 0;
55  simVtxEta = 0;
56  simVtxPhi = 0;
57  simZ0 = 0;
58  simD0 = 0;
59  }
60  };
61 
62  struct MuObjEmu : public MuObj {
63  const l1t::SAMuon *src;
64  bool read(std::fstream &from);
65  bool write(std::fstream &to) const;
66  void clear() {
67  MuObj::clear();
68  src = nullptr;
69  }
70  };
71 
72  struct PFChargedObjEmu : public PFChargedObj {
77  bool read(std::fstream &from);
78  bool write(std::fstream &to) const;
79  void clear() {
81  srcCluster = nullptr;
82  srcTrack = nullptr;
83  srcMu = nullptr;
84  srcCand = nullptr;
85  }
86  };
87 
88  struct PFNeutralObjEmu : public PFNeutralObj {
91  bool read(std::fstream &from);
92  bool write(std::fstream &to) const;
93  void clear() {
95  srcCluster = nullptr;
96  srcCand = nullptr;
97  }
98  };
99 
100  struct PFRegionEmu : public PFRegion {
102  PFRegionEmu(float etaCenter, float phicenter);
103  PFRegionEmu(float etamin, float etamax, float phicenter, float phiwidth, float etaextra, float phiextra);
104 
105  // global coordinates
106  bool contains(float eta, float phi) const;
107  bool containsHw(glbeta_t glbeta, glbphi_t phi) const;
108  float localEta(float globalEta) const;
109  float localPhi(float globalPhi) const;
110 
111  bool read(std::fstream &from);
112  bool write(std::fstream &to) const;
113  };
114 
115  struct PuppiObjEmu : public PuppiObj {
120  bool read(std::fstream &from);
121  bool write(std::fstream &to) const;
122  void clear() {
123  PuppiObj::clear();
124  srcCluster = nullptr;
125  srcTrack = nullptr;
126  srcMu = nullptr;
127  srcCand = nullptr;
128  }
129  inline void fill(const PFRegionEmu &region, const PFChargedObjEmu &src) {
131  srcCluster = src.srcCluster;
132  srcTrack = src.srcTrack;
133  srcMu = src.srcMu;
134  srcCand = src.srcCand;
135  }
136  inline void fill(const PFRegionEmu &region, const PFNeutralObjEmu &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
137  PuppiObj::fill(region, src, puppiPt, puppiWgt);
138  srcCluster = src.srcCluster;
139  srcTrack = nullptr;
140  srcMu = nullptr;
141  srcCand = src.srcCand;
142  }
143  inline void fill(const PFRegionEmu &region, const HadCaloObjEmu &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
144  PuppiObj::fill(region, src, puppiPt, puppiWgt);
145  srcCluster = src.src;
146  srcTrack = nullptr;
147  srcMu = nullptr;
148  srcCand = nullptr;
149  }
150  };
151 
152  struct EGObjEmu : public EGIsoObj {
154  void clear() {
155  srcCluster = nullptr;
156  EGIsoObj::clear();
157  }
158  };
159 
160  struct EGIsoObjEmu : public EGIsoObj {
162  // we use an index to the standalone object needed to retrieve a Ref when putting
163  int sta_idx;
164  bool read(std::fstream &from);
165  bool write(std::fstream &to) const;
166  void clear() {
167  EGIsoObj::clear();
168  srcCluster = nullptr;
169  sta_idx = -1;
170  clearIsoVars();
171  }
172 
173  void clearIsoVars() {
174  hwIsoVars[0] = 0;
175  hwIsoVars[1] = 0;
176  hwIsoVars[2] = 0;
177  hwIsoVars[3] = 0;
178  }
179 
180  using EGIsoObj::floatIso;
181 
182  enum IsoType { TkIso = 0, PfIso = 1, TkIsoPV = 2, PfIsoPV = 3 };
183 
184  float floatIso(IsoType type) const { return Scales::floatIso(hwIsoVars[type]); }
186  float hwIsoVar(IsoType type) const { return hwIsoVars[type]; }
188 
190  };
191 
192  struct EGIsoEleObjEmu : public EGIsoEleObj {
195  // we use an index to the standalone object needed to retrieve a Ref when putting
196  int sta_idx;
197  bool read(std::fstream &from);
198  bool write(std::fstream &to) const;
199  void clear() {
201  srcCluster = nullptr;
202  srcTrack = nullptr;
203  sta_idx = -1;
204  clearIsoVars();
205  }
206 
207  void clearIsoVars() {
208  hwIsoVars[0] = 0;
209  hwIsoVars[1] = 0;
210  }
211 
212  using EGIsoEleObj::floatIso;
213 
214  enum IsoType { TkIso = 0, PfIso = 1 };
215 
216  float floatIso(IsoType type) const { return Scales::floatIso(hwIsoVars[type]); }
218  float hwIsoVar(IsoType type) const { return hwIsoVars[type]; }
220 
222  };
223 
224  struct PVObjEmu : public PVObj {
225  bool read(std::fstream &from);
226  bool write(std::fstream &to) const;
227  };
228 
229  template <typename T>
230  struct DetectorSector {
232  std::vector<T> obj;
234  DetectorSector(float etamin, float etamax, float phicenter, float phiwidth, float etaextra = 0, float phiextra = 0)
235  : region(etamin, etamax, phicenter, phiwidth, etaextra, phiextra) {}
236  // convenience forwarding of some methods
237  typedef typename std::vector<T>::const_iterator const_iterator;
238  typedef typename std::vector<T>::iterator iterator;
239  inline const T &operator[](unsigned int i) const { return obj[i]; }
240  inline T &operator[](unsigned int i) { return obj[i]; }
241  inline const_iterator begin() const { return obj.begin(); }
242  inline iterator begin() { return obj.begin(); }
243  inline const_iterator end() const { return obj.end(); }
244  inline iterator end() { return obj.end(); }
245  inline unsigned int size() const { return obj.size(); }
246  inline void resize(unsigned int size) { obj.resize(size); }
247  inline void clear() { obj.clear(); }
248  };
249 
250  struct RawInputs {
251  std::vector<DetectorSector<ap_uint<96>>> track;
252  DetectorSector<ap_uint<64>> muon; // muons are global
253  std::vector<DetectorSector<ap_uint<256>>> hgcalcluster;
254 
255  bool read(std::fstream &from);
256  bool write(std::fstream &to) const;
257  void clear();
258  };
259 
261  std::vector<DetectorSector<HadCaloObjEmu>> hadcalo;
262  std::vector<DetectorSector<EmCaloObjEmu>> emcalo;
263  std::vector<DetectorSector<TkObjEmu>> track;
264  DetectorSector<MuObjEmu> muon; // muons are global
265 
266  bool read(std::fstream &from);
267  bool write(std::fstream &to) const;
268  void clear();
269  };
270 
271  struct PFInputRegion {
273  std::vector<HadCaloObjEmu> hadcalo;
274  std::vector<EmCaloObjEmu> emcalo;
275  std::vector<TkObjEmu> track;
276  std::vector<MuObjEmu> muon;
277 
279  PFInputRegion(float etamin, float etamax, float phicenter, float phiwidth, float etaextra, float phiextra)
280  : region(etamin, etamax, phicenter, phiwidth, etaextra, phiextra) {}
281  bool read(std::fstream &from);
282  bool write(std::fstream &to) const;
283  void clear();
284  };
285 
286  struct OutputRegion {
287  std::vector<PFChargedObjEmu> pfcharged;
288  std::vector<PFNeutralObjEmu> pfphoton;
289  std::vector<PFNeutralObjEmu> pfneutral;
290  std::vector<PFChargedObjEmu> pfmuon;
291  std::vector<PuppiObjEmu> puppi;
292  std::vector<EGObjEmu> egsta;
293  std::vector<EGIsoObjEmu> egphoton;
294  std::vector<EGIsoEleObjEmu> egelectron;
295 
296  bool read(std::fstream &from);
297  bool write(std::fstream &to) const;
298  void clear();
299 
300  // for multiplicities
301  enum ObjType {
302  anyType = 0,
306  muonType = 4,
310  nPFTypes = 8,
314  };
315  static constexpr const char *objTypeName[nObjTypes] = {
316  "", "Charged", "Neutral", "Electron", "Muon", "ChargedHadron", "NeutralHadron", "Photon", "EGIso", "EGIsoEle"};
317  unsigned int nObj(ObjType type, bool puppi) const;
318  };
319 
320  struct OutputBoard {
321  float eta;
322  float phi;
323  // NOTE: region_index is not written to the dump file
324  std::vector<unsigned int> region_index;
325  std::vector<EGIsoObjEmu> egphoton;
326  std::vector<EGIsoEleObjEmu> egelectron;
327 
328  bool read(std::fstream &from);
329  bool write(std::fstream &to) const;
330  void clear();
331  };
332 
333  struct Event {
334  enum { VERSION = 11 };
335  uint32_t run, lumi;
339  std::vector<PFInputRegion> pfinputs;
340  std::vector<PVObjEmu> pvs;
341  std::vector<ap_uint<64>> pvs_emu;
342  std::vector<OutputRegion> out;
343  std::vector<OutputBoard> board_out;
344 
345  Event() : run(0), lumi(0), event(0) {}
346 
347  bool read(std::fstream &from);
348  bool write(std::fstream &to) const;
349  void clear();
350  void init(uint32_t run, uint32_t lumi, uint64_t event);
351  inline l1ct::PVObjEmu pv(unsigned int ipv = 0) const {
353  if (ipv < pvs.size())
354  ret = pvs[ipv];
355  else
356  ret.clear();
357  return ret;
358  }
359  inline ap_uint<64> pv_emu(unsigned int ipv = 0) const {
360  ap_uint<64> ret = 0;
361  if (ipv < pvs_emu.size())
362  ret = pvs_emu[ipv];
363  return ret;
364  }
365  };
366 
367  template <typename T1, typename T2>
368  void toFirmware(const std::vector<T1> &in, unsigned int NMAX, T2 out[/*NMAX*/]) {
369  unsigned int n = std::min<unsigned>(in.size(), NMAX);
370  for (unsigned int i = 0; i < n; ++i)
371  out[i] = in[i];
372  for (unsigned int i = n; i < NMAX; ++i)
373  out[i].clear();
374  }
375 
376 } // namespace l1ct
377 
378 #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:149
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:30
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:43
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:35
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:232
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:21
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:166
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:29
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:19
std::vector< OutputBoard > board_out