CMS 3D CMS Logo

L1GTEvaluationProducer.cc
Go to the documentation of this file.
4 
7 
10 
15 
18 
20 
21 #include <vector>
22 #include <array>
23 #include <string>
24 #include <unordered_map>
25 #include <fstream>
26 #include <limits>
27 
28 #include <optional>
29 #include <random>
30 
31 using namespace l1t;
32 
34 public:
35  explicit L1GTEvaluationProducer(const edm::ParameterSet &);
36  ~L1GTEvaluationProducer() override = default;
37 
39 
40 private:
41  void produce(edm::Event &, const edm::EventSetup &) override;
42  int nextValue(int mean = 1000, bool sign = false, int max = std::numeric_limits<int>::max());
43 
44  int nextPt() {
45  return std::max<int>(0,
46  nextValue(300, false, (1 << P2GTCandidate::hwPT_t::width) - 1) +
47  std::normal_distribution<double>(0, 500)(randomGenerator_));
48  }
49  int nextEta() {
50  return std::uniform_int_distribution<int>(-(1 << (P2GTCandidate::hwEta_t::width - 1)),
51  (1 << (P2GTCandidate::hwEta_t::width - 1)) - 1)(randomGenerator_);
52  }
53  int nextPhi() {
54  return std::uniform_int_distribution<int>(-(1 << (P2GTCandidate::hwPhi_t::width - 1)),
55  (1 << (P2GTCandidate::hwPhi_t::width - 1)) - 1)(randomGenerator_);
56  }
57 
58  void writeInputPatterns(
59  const std::unordered_map<std::string, std::vector<std::unique_ptr<l1t::L1TGT_BaseInterface>>> &inputObjects);
60 
61  void endJob() override;
62 
63  std::mt19937 randomGenerator_;
65 };
66 
67 template <typename T, std::size_t low, std::size_t high, std::size_t incr = 1>
68 static constexpr std::array<T, high - low> arange() {
70  T value = low;
71  for (T &el : array) {
72  el = value;
73  value += incr;
74  }
75  return array;
76 }
77 
78 template <typename T, std::size_t low, std::size_t high, std::size_t incr = 1>
79 static std::vector<T> vrange() {
80  std::array<T, high - low> arr(arange<T, low, high, incr>());
81  return std::vector(std::begin(arr), std::end(arr));
82 }
83 
85  {{"GTT", 0}, {{6, 0}, vrange<std::size_t, 0, 6>()}},
86  {{"GTT", 1}, {{6, 0}, vrange<std::size_t, 6, 12>()}},
87  {{"CL2", 0}, {{6, 0}, vrange<std::size_t, 28, 34>()}},
88  {{"CL2", 1}, {{6, 0}, vrange<std::size_t, 34, 40>()}},
89  {{"GCT", 0}, {{6, 0}, vrange<std::size_t, 54, 60>()}},
90  {{"GMT", 0}, {{18, 0}, vrange<std::size_t, 60, 78>()}},
91  {{"CL2", 2}, {{6, 0}, vrange<std::size_t, 80, 86>()}},
92  {{"GTT", 2}, {{6, 0}, vrange<std::size_t, 104, 110>()}},
93  {{"GTT", 3}, {{6, 0}, vrange<std::size_t, 110, 116>()}}};
94 
96  {{"GTT", 0}, {{6, 0}, vrange<std::size_t, 0, 6>()}},
97  {{"GTT", 1}, {{6, 0}, vrange<std::size_t, 6, 12>()}},
98  {{"GCT", 0}, {{6, 0}, vrange<std::size_t, 24, 30>()}},
99  {{"CL2", 0}, {{6, 0}, vrange<std::size_t, 32, 38>()}},
100  {{"CL2", 1}, {{6, 0}, vrange<std::size_t, 38, 44>()}},
101  {{"GMT", 0}, {{18, 0}, {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 68, 69, 70, 71, 72, 73}}},
102  {{"CL2", 2}, {{6, 0}, vrange<std::size_t, 80, 86>()}},
103  {{"GTT", 2}, {{6, 0}, vrange<std::size_t, 112, 118>()}},
104  {{"GTT", 3}, {{6, 0}, vrange<std::size_t, 118, 124>()}}};
105 
107  : randomGenerator_(config.exists("random_seed") ? config.getParameter<unsigned int>("random_seed")
108  : std::random_device()()),
109  boardDataWriter_(l1t::demo::parseFileFormat(config.getParameter<std::string>("patternFormat")),
110  config.getParameter<std::string>("outputFilename"),
111  config.getParameter<std::string>("outputFileExtension"),
112  9,
113  1,
114  config.getParameter<unsigned int>("maxLines"),
115  config.getParameter<std::string>("platform") == "VU13P" ? CHANNEL_MAP_VU13P : CHANNEL_MAP_VU9P) {
116  produces<P2GTCandidateCollection>("GCTNonIsoEg");
117  produces<P2GTCandidateCollection>("GCTIsoEg");
118  produces<P2GTCandidateCollection>("GCTJets");
119  produces<P2GTCandidateCollection>("GCTTaus");
120  produces<P2GTCandidateCollection>("GCTHtSum");
121  produces<P2GTCandidateCollection>("GCTEtSum");
122  produces<P2GTCandidateCollection>("GMTSaPromptMuons");
123  produces<P2GTCandidateCollection>("GMTSaDisplacedMuons");
124  produces<P2GTCandidateCollection>("GMTTkMuons");
125  produces<P2GTCandidateCollection>("GMTTopo");
126  produces<P2GTCandidateCollection>("GTTPromptJets");
127  produces<P2GTCandidateCollection>("GTTDisplacedJets");
128  produces<P2GTCandidateCollection>("GTTPhiCandidates");
129  produces<P2GTCandidateCollection>("GTTRhoCandidates");
130  produces<P2GTCandidateCollection>("GTTBsCandidates");
131  produces<P2GTCandidateCollection>("GTTHadronicTaus");
132  produces<P2GTCandidateCollection>("GTTPrimaryVert");
133  produces<P2GTCandidateCollection>("GTTPromptHtSum");
134  produces<P2GTCandidateCollection>("GTTDisplacedHtSum");
135  produces<P2GTCandidateCollection>("GTTEtSum");
136  produces<P2GTCandidateCollection>("CL2Jets");
137  produces<P2GTCandidateCollection>("CL2Taus");
138  produces<P2GTCandidateCollection>("CL2Electrons");
139  produces<P2GTCandidateCollection>("CL2Photons");
140  produces<P2GTCandidateCollection>("CL2HtSum");
141  produces<P2GTCandidateCollection>("CL2EtSum");
142 }
143 
146  desc.addOptional<unsigned int>("random_seed");
147  desc.add<unsigned int>("maxLines", 1024);
148  desc.add<std::string>("outputFilename");
149  desc.add<std::string>("outputFileExtension", "txt");
150  desc.add<std::string>("patternFormat", "EMPv2");
151  desc.ifValue(edm::ParameterDescription<std::string>("platform", "VU9P", true),
152  edm::allowedValues<std::string>("VU9P", "VU13P"));
153  description.addWithDefaultLabel(desc);
154 }
155 
157  bool positive = sign ? std::bernoulli_distribution(0.5)(randomGenerator_) : true;
158 
159  int result;
160  do {
161  result = std::poisson_distribution<int>(mean)(randomGenerator_);
162  } while (result > max);
163 
164  return positive ? result : -result;
165 }
166 
167 template <typename... Args>
168 static std::vector<ap_uint<64>> vpack(const Args &...vobjects) {
169  std::vector<ap_uint<64>> vpacked;
170 
171  (
172  [&vpacked](const std::vector<std::unique_ptr<l1t::L1TGT_BaseInterface>> &objects) {
173  std::optional<ap_uint<64>> next_packed;
174  for (const auto &object : objects) {
175  if (object->packed_width() == 64) {
176  const l1t::L1TGT_Interface<64> &interface_obj = dynamic_cast<const l1t::L1TGT_Interface<64> &>(*object);
177  vpacked.emplace_back(interface_obj.pack());
178  } else if (object->packed_width() == 96) {
179  const l1t::L1TGT_Interface<96> &interface_obj = dynamic_cast<const l1t::L1TGT_Interface<96> &>(*object);
180  ap_uint<96> packed = interface_obj.pack();
181  if (next_packed.has_value()) {
182  vpacked.emplace_back(packed(95, 64) << 32 | next_packed.value());
183  next_packed.reset();
184  } else {
185  next_packed = packed(95, 64);
186  }
187 
188  vpacked.emplace_back(packed(63, 0));
189 
190  } else if (object->packed_width() == 128) {
191  const l1t::L1TGT_Interface<128> &interface_obj = dynamic_cast<const l1t::L1TGT_Interface<128> &>(*object);
192  ap_uint<128> packed = interface_obj.pack();
193  vpacked.emplace_back(packed(63, 0));
194  vpacked.emplace_back(packed(127, 64));
195  }
196  }
197  }(vobjects),
198  ...);
199 
200  return vpacked;
201 }
202 
204  const std::unordered_map<std::string, std::vector<std::unique_ptr<l1t::L1TGT_BaseInterface>>> &inputObjects) {
206  {{{"GTT", 0},
207  vpack(inputObjects.at("GTTPromptJets"),
208  inputObjects.at("GTTDisplacedJets"),
209  inputObjects.at("GTTPromptHtSum"),
210  inputObjects.at("GTTDisplacedHtSum"),
211  inputObjects.at("GTTEtSum"))},
212  {{"GTT", 1}, vpack(inputObjects.at("GTTHadronicTaus"))},
213  {{"CL2", 0}, vpack(inputObjects.at("CL2Jets"), inputObjects.at("CL2HtSum"), inputObjects.at("CL2EtSum"))},
214  {{"CL2", 1}, vpack(inputObjects.at("CL2Taus"))},
215  {{"GCT", 0},
216  vpack(inputObjects.at("GCTNonIsoEg"),
217  inputObjects.at("GCTIsoEg"),
218  inputObjects.at("GCTJets"),
219  inputObjects.at("GCTTaus"),
220  inputObjects.at("GCTHtSum"),
221  inputObjects.at("GCTEtSum"))},
222  {{"GMT", 0},
223  vpack(inputObjects.at("GMTSaPromptMuons"),
224  inputObjects.at("GMTSaDisplacedMuons"),
225  inputObjects.at("GMTTkMuons"),
226  inputObjects.at("GMTTopo"))},
227  {{"CL2", 2}, vpack(inputObjects.at("CL2Electrons"), inputObjects.at("CL2Photons"))},
228  {{"GTT", 2},
229  vpack(inputObjects.at("GTTPhiCandidates"),
230  inputObjects.at("GTTRhoCandidates"),
231  inputObjects.at("GTTBsCandidates"))},
232  {{"GTT", 3}, vpack(inputObjects.at("GTTPrimaryVert"))}}});
233 }
234 
236  // Generate random input objects
237  std::unordered_map<std::string, std::vector<std::unique_ptr<l1t::L1TGT_BaseInterface>>> inputObjects;
238  for (std::size_t i = 0; i < 12; ++i) {
239  // Global Muon Trigger
240  inputObjects["GMTSaPromptMuons"].emplace_back(std::make_unique<l1t::L1TGT_GMT_PromptDisplacedMuon>(
241  true, nextPt(), nextEta(), nextPhi(), nextValue(), nextValue(), nextValue(), nextValue()));
242 
243  inputObjects["GMTSaDisplacedMuons"].emplace_back(std::make_unique<l1t::L1TGT_GMT_PromptDisplacedMuon>(
244  true, nextPt(), nextEta(), nextPhi(), nextValue(), nextValue(), nextValue(), nextValue()));
245  inputObjects["GMTTkMuons"].emplace_back(std::make_unique<l1t::L1TGT_GMT_TrackMatchedmuon>(true,
246  nextPt(),
247  nextEta(),
248  nextPhi(),
249  nextValue(),
250  nextValue(),
251  nextValue(),
252  nextValue(),
253  nextValue(),
254  nextValue()));
255  inputObjects["GMTTopo"].emplace_back(
256  std::make_unique<l1t::L1TGT_GMT_TopoObject>(true, nextPt(), nextEta(), nextPhi(), nextValue(), nextValue()));
257 
258  // Global Calorimeter Trigger
259  inputObjects["GCTNonIsoEg"].emplace_back(
260  std::make_unique<l1t::L1TGT_GCT_EgammaNonIsolated6p6>(true, nextPt(), nextEta(), nextPhi()));
261  inputObjects["GCTIsoEg"].emplace_back(
262  std::make_unique<l1t::L1TGT_GCT_EgammaIsolated6p6>(true, nextPt(), nextEta(), nextPhi()));
263  inputObjects["GCTJets"].emplace_back(std::make_unique<l1t::L1TGT_GCT_jet6p6>(true, nextPt(), nextEta(), nextPhi()));
264  inputObjects["GCTTaus"].emplace_back(
265  std::make_unique<l1t::L1TGT_GCT_tau6p6>(true, nextPt(), nextEta(), nextPhi(), nextValue()));
266 
267  // Global Track Trigger
268  inputObjects["GTTPrimaryVert"].emplace_back(
269  std::make_unique<l1t::L1TGT_GTT_PrimaryVert>(true, nextPt(), nextEta(), nextPhi(), nextValue(), nextValue()));
270  inputObjects["GTTPromptJets"].emplace_back(
271  std::make_unique<l1t::L1TGT_GTT_PromptJet>(true, nextPt(), nextEta(), nextPhi(), nextValue(), nextValue()));
272  inputObjects["GTTDisplacedJets"].emplace_back(std::make_unique<l1t::L1TGT_GTT_DisplacedJet>(
273  true, nextPt(), nextEta(), nextPhi(), nextValue(), nextValue(), nextValue()));
274  inputObjects["GTTHadronicTaus"].emplace_back(std::make_unique<l1t::L1TGT_GTT_HadronicTau>(
275  true, nextPt(), nextEta(), nextPhi(), nextValue(), nextValue(), nextValue(), nextValue()));
276  inputObjects["GTTPhiCandidates"].emplace_back(
277  std::make_unique<l1t::L1TGT_GTT_LightMeson>(true, nextPt(), nextEta(), nextPhi(), nextValue()));
278  inputObjects["GTTRhoCandidates"].emplace_back(
279  std::make_unique<l1t::L1TGT_GTT_LightMeson>(true, nextPt(), nextEta(), nextPhi(), nextValue()));
280  inputObjects["GTTBsCandidates"].emplace_back(
281  std::make_unique<l1t::L1TGT_GTT_LightMeson>(true, nextPt(), nextEta(), nextPhi(), nextValue()));
282 
283  // Correlator Layer-2
284  inputObjects["CL2Jets"].emplace_back(
285  std::make_unique<l1t::L1TGT_CL2_Jet>(true, nextPt(), nextEta(), nextPhi(), nextValue()));
286  inputObjects["CL2Electrons"].emplace_back(std::make_unique<l1t::L1TGT_CL2_Electron>(
287  true, nextPt(), nextEta(), nextPhi(), nextValue(), nextValue(), nextValue(), nextValue()));
288  inputObjects["CL2Photons"].emplace_back(
289  std::make_unique<l1t::L1TGT_CL2_Photon>(true, nextPt(), nextEta(), nextPhi(), nextValue(), nextValue()));
290  inputObjects["CL2Taus"].emplace_back(std::make_unique<l1t::L1TGT_CL2_Tau>(
291  true, nextPt(), nextEta(), nextPhi(), nextValue(), nextValue(), nextValue(), nextValue()));
292  }
293 
294  inputObjects["CL2HtSum"].emplace_back(
295  std::make_unique<l1t::L1TGT_CL2_Sum>(true, nextValue(), nextValue(), nextValue()));
296  inputObjects["CL2EtSum"].emplace_back(
297  std::make_unique<l1t::L1TGT_CL2_Sum>(true, nextValue(), nextValue(), nextValue()));
298  inputObjects["GCTHtSum"].emplace_back(
299  std::make_unique<l1t::L1TGT_GCT_Sum2>(true, nextValue(), nextValue(), nextValue()));
300  inputObjects["GCTEtSum"].emplace_back(
301  std::make_unique<l1t::L1TGT_GCT_Sum2>(true, nextValue(), nextValue(), nextValue()));
302 
303  inputObjects["GTTPromptHtSum"].emplace_back(
304  std::make_unique<l1t::L1TGT_GTT_Sum>(true, nextValue(), nextValue(), nextValue()));
305  inputObjects["GTTDisplacedHtSum"].emplace_back(
306  std::make_unique<l1t::L1TGT_GTT_Sum>(true, nextValue(), nextValue(), nextValue()));
307  inputObjects["GTTEtSum"].emplace_back(
308  std::make_unique<l1t::L1TGT_GTT_Sum>(true, nextValue(), nextValue(), nextValue()));
309 
310  // Write them to a pattern file
312 
313  for (const auto &[key, inputCollection] : inputObjects) {
314  std::unique_ptr<P2GTCandidateCollection> gtCollection = std::make_unique<P2GTCandidateCollection>();
315  for (const auto &object : inputCollection) {
316  gtCollection->emplace_back(object->to_GTObject());
317  }
318 
319  event.put(std::move(gtCollection), key);
320  }
321 }
322 
324 
l1t::demo::BoardDataWriter boardDataWriter_
L1GTEvaluationProducer(const edm::ParameterSet &)
void addEvent(const EventData &data)
FileFormat parseFileFormat(const std::string &)
Definition: utilities.cc:73
delete x;
Definition: CaloConfig.h:22
Definition: config.py:1
static std::vector< T > vrange()
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static const l1t::demo::BoardDataWriter::ChannelMap_t CHANNEL_MAP_VU13P
Definition: value.py:1
void produce(edm::Event &, const edm::EventSetup &) override
std::map< LinkId, std::pair< ChannelSpec, std::vector< size_t > > > ChannelMap_t
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void writeInputPatterns(const std::unordered_map< std::string, std::vector< std::unique_ptr< l1t::L1TGT_BaseInterface >>> &inputObjects)
static constexpr std::array< T, high - low > arange()
virtual ap_uint< N > pack() const =0
int nextValue(int mean=1000, bool sign=false, int max=std::numeric_limits< int >::max())
static const l1t::demo::BoardDataWriter::ChannelMap_t CHANNEL_MAP_VU9P
static void fillDescriptions(edm::ConfigurationDescriptions &)
static std::vector< ap_uint< 64 > > vpack(const Args &...vobjects)
long double T
Class representing information phase-2 ATCA I/O data corresponding to a single event, with logical channel IDs (essentially string-uint pairs, e.g. tracks-0 to tracks-17).
Definition: EventData.h:28
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1