CMS 3D CMS Logo

L1TComparison.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // L1TComparison: produce a summary of comparison of L1T event data
4 //
5 
6 #include <iostream>
19 
20 using namespace std;
21 using namespace edm;
22 using namespace l1t;
23 
24 static bool compare_l1candidate(const L1Candidate& a, const L1Candidate& b, int verbose = 1) {
25  int status = 0;
26  if (a.pt() != b.pt())
27  status = 1;
28  if (a.eta() != b.eta())
29  status = 1;
30  if (a.phi() != b.phi())
31  status = 1;
32 
33  if (status) {
34  cout << "COMPARISON FAILURE: \n";
35  cout << "A: pt = " << a.pt() << " eta = " << a.eta() << " phi = " << a.phi() << "\n";
36  cout << "B: pt = " << b.pt() << " eta = " << b.eta() << " phi = " << b.phi() << "\n";
37  }
38 
39  if (a.hwPt() != b.hwPt())
40  status = 1;
41  if (a.hwEta() != b.hwEta())
42  status = 1;
43  if (a.hwPhi() != b.hwPhi())
44  status = 1;
45 
46  if (status) {
47  cout << "COMPARISON FAILURE: \n";
48  cout << "A: hwPt = " << a.hwPt() << " hwEta = " << a.hwEta() << " hwPhi = " << a.hwPhi() << "\n";
49  cout << "B: hwPt = " << b.hwPt() << " hwEta = " << b.hwEta() << " hwPhi = " << b.hwPhi() << "\n";
50  }
51 
52  if (a.hwQual() != b.hwQual())
53  status = 1;
54  if (a.hwIso() != b.hwIso())
55  status = 1;
56  if (status) {
57  cout << "COMPARISON FAILURE: \n";
58  cout << "A: hwQual = " << a.hwQual() << " hwIso = " << a.hwIso() << "\n";
59  cout << "B: hwQual = " << b.hwQual() << " hwIso = " << b.hwIso() << "\n";
60  }
61 
62  return status;
63 }
64 
65 class L1TComparison : public one::EDAnalyzer<> {
66 public:
67  explicit L1TComparison(const ParameterSet&);
68  ~L1TComparison() override;
69 
70  static void fillDescriptions(ConfigurationDescriptions& descriptions);
71 
72 private:
73  void beginJob() override;
74  void analyze(Event const&, EventSetup const&) override;
75  void endJob() override;
76 
77  // Tag string to mark summary with:
78  string tag_;
79 
80  // Checks to perform:
81  bool egCheck_;
82  bool tauCheck_;
83  bool jetCheck_;
84  bool sumCheck_;
85  bool muonCheck_;
86  bool algCheck_;
88 
89  // EDM tokens:
96 
103 
104  // keep a tally for summary:
105  int egCount_;
111 
112  int egFails_;
118 };
119 
121  tag_ = iConfig.getParameter<string>("tag");
122  egCheck_ = iConfig.getParameter<bool>("egCheck");
123  tauCheck_ = iConfig.getParameter<bool>("tauCheck");
124  jetCheck_ = iConfig.getParameter<bool>("jetCheck");
125  sumCheck_ = iConfig.getParameter<bool>("sumCheck");
126  muonCheck_ = iConfig.getParameter<bool>("muonCheck");
127  algCheck_ = iConfig.getParameter<bool>("algCheck");
128  bxZeroOnly_ = iConfig.getParameter<bool>("bxZeroOnly");
129 
130  cout << "L1T Summary for " << tag_ << "\n";
131  cout << "DEBUG: egCheck: " << egCheck_ << "\n";
132  cout << "DEBUG: tauCheck: " << tauCheck_ << "\n";
133  cout << "DEBUG: jetCheck: " << jetCheck_ << "\n";
134  cout << "DEBUG: sumCheck: " << sumCheck_ << "\n";
135  cout << "DEBUG: muonCheck: " << muonCheck_ << "\n";
136  cout << "DEBUG: algCheck: " << algCheck_ << "\n";
137 
138  if (egCheck_) {
139  egTokenA_ = consumes<EGammaBxCollection>(iConfig.getParameter<InputTag>("egTagA"));
140  }
141  if (tauCheck_) {
142  tauTokenA_ = consumes<TauBxCollection>(iConfig.getParameter<InputTag>("tauTagA"));
143  }
144  if (jetCheck_) {
145  jetTokenA_ = consumes<JetBxCollection>(iConfig.getParameter<InputTag>("jetTagA"));
146  }
147  if (sumCheck_) {
148  sumTokenA_ = consumes<EtSumBxCollection>(iConfig.getParameter<InputTag>("sumTagA"));
149  }
150  if (muonCheck_) {
151  muonTokenA_ = consumes<MuonBxCollection>(iConfig.getParameter<InputTag>("muonTagA"));
152  }
153  if (algCheck_) {
154  algTokenA_ = consumes<GlobalAlgBlkBxCollection>(iConfig.getParameter<InputTag>("algTagA"));
155  }
156 
157  if (egCheck_) {
158  egTokenB_ = consumes<EGammaBxCollection>(iConfig.getParameter<InputTag>("egTagB"));
159  }
160  if (tauCheck_) {
161  tauTokenB_ = consumes<TauBxCollection>(iConfig.getParameter<InputTag>("tauTagB"));
162  }
163  if (jetCheck_) {
164  jetTokenB_ = consumes<JetBxCollection>(iConfig.getParameter<InputTag>("jetTagB"));
165  }
166  if (sumCheck_) {
167  sumTokenB_ = consumes<EtSumBxCollection>(iConfig.getParameter<InputTag>("sumTagB"));
168  }
169  if (muonCheck_) {
170  muonTokenB_ = consumes<MuonBxCollection>(iConfig.getParameter<InputTag>("muonTagB"));
171  }
172  if (algCheck_) {
173  algTokenB_ = consumes<GlobalAlgBlkBxCollection>(iConfig.getParameter<InputTag>("algTagB"));
174  }
175 
176  egCount_ = 0;
177  tauCount_ = 0;
178  jetCount_ = 0;
179  sumCount_ = 0;
180  muonCount_ = 0;
181  algCount_ = 0;
182 
183  egFails_ = 0;
184  tauFails_ = 0;
185  jetFails_ = 0;
186  sumFails_ = 0;
187  muonFails_ = 0;
188  algFails_ = 0;
189 }
190 
192 
193 void L1TComparison::analyze(Event const& iEvent, EventSetup const& iSetup) {
194  cout << "L1TComparison Module output for " << tag_ << "\n";
195 
196  if (egCheck_) {
198  iEvent.getByToken(egTokenA_, XTMPA);
200  iEvent.getByToken(egTokenB_, XTMPB);
201 
202  if (!(XTMPA.isValid() && XTMPB.isValid())) {
203  LogWarning("MissingProduct") << "L1Upgrade e-gamma's not found." << std::endl;
204  } else {
205  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
206  if (bxZeroOnly_ && (ibx != 0))
207  continue;
208  if (ibx < XTMPB->getFirstBX())
209  continue;
210  if (ibx > XTMPB->getLastBX())
211  continue;
212  int sizeA = XTMPA->size(ibx);
213  int sizeB = XTMPB->size(ibx);
214  if (sizeA != sizeB) {
215  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
216  } else {
217  auto itB = XTMPB->begin(ibx);
218  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
219  bool fail = compare_l1candidate(*itA, *itB);
220  itB++;
221  if (!fail) {
222  egCount_++;
223  } else {
224  egFails_++;
225  }
226  }
227  }
228  }
229  }
230  }
231 
232  if (tauCheck_) {
234  iEvent.getByToken(tauTokenA_, XTMPA);
236  iEvent.getByToken(tauTokenB_, XTMPB);
237 
238  if (!(XTMPA.isValid() && XTMPB.isValid())) {
239  LogWarning("MissingProduct") << "L1Upgrade tau's not found." << std::endl;
240  } else {
241  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
242  if (bxZeroOnly_ && (ibx != 0))
243  continue;
244  if (ibx < XTMPB->getFirstBX())
245  continue;
246  if (ibx > XTMPB->getLastBX())
247  continue;
248  int sizeA = XTMPA->size(ibx);
249  int sizeB = XTMPB->size(ibx);
250  if (sizeA != sizeB) {
251  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
252  } else {
253  auto itB = XTMPB->begin(ibx);
254  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
255  bool fail = compare_l1candidate(*itA, *itB);
256  itB++;
257  if (!fail) {
258  tauCount_++;
259  } else {
260  tauFails_++;
261  }
262  }
263  }
264  }
265  }
266  }
267 
268  if (jetCheck_) {
270  iEvent.getByToken(jetTokenA_, XTMPA);
272  iEvent.getByToken(jetTokenB_, XTMPB);
273 
274  if (!(XTMPA.isValid() && XTMPB.isValid())) {
275  LogWarning("MissingProduct") << "L1Upgrade jet's not found." << std::endl;
276  } else {
277  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
278  if (bxZeroOnly_ && (ibx != 0))
279  continue;
280  if (ibx < XTMPB->getFirstBX())
281  continue;
282  if (ibx > XTMPB->getLastBX())
283  continue;
284  int sizeA = XTMPA->size(ibx);
285  int sizeB = XTMPB->size(ibx);
286  if (sizeA != sizeB) {
287  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
288  } else {
289  auto itB = XTMPB->begin(ibx);
290  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
291  bool fail = compare_l1candidate(*itA, *itB);
292  itB++;
293  if (!fail) {
294  jetCount_++;
295  } else {
296  jetFails_++;
297  }
298  }
299  }
300  }
301  }
302  }
303 
304  if (sumCheck_) {
306  iEvent.getByToken(sumTokenA_, XTMPA);
308  iEvent.getByToken(sumTokenB_, XTMPB);
309 
310  if (!(XTMPA.isValid() && XTMPB.isValid())) {
311  LogWarning("MissingProduct") << "L1Upgrade sum's not found." << std::endl;
312  } else {
313  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
314  if (bxZeroOnly_ && (ibx != 0))
315  continue;
316  if (ibx < XTMPB->getFirstBX())
317  continue;
318  if (ibx > XTMPB->getLastBX())
319  continue;
320  int sizeA = XTMPA->size(ibx);
321  int sizeB = XTMPB->size(ibx);
322 
323  if (sizeA != sizeB) {
324  cout << "L1T COMPARISON WARNING: sums collections have different sizes for bx = " << ibx << "\n";
325  cout << "L1T COMPARISON WARNING: sums collections A size = " << sizeA
326  << " sums collection B size = " << sizeB << "\n";
327  cout << "L1T COMPARISON WARNING: known issue because packer has not been udpated for Minbias\n";
328  }
329  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
330  cout << "L1T COMPARISON : EtSum type: A = " << itA->getType() << "\n";
331  }
332  for (auto itB = XTMPB->begin(ibx); itB != XTMPB->end(ibx); ++itB) {
333  cout << "L1T COMPARISON : EtSum type: B = " << itB->getType() << "\n";
334  }
335 
336  // temp workaround for sums not packed...
337  if (sizeA > sizeB)
338  sizeA = sizeB;
339  if (sizeB > sizeA)
340  sizeB = sizeA;
341 
342  if (sizeA != sizeB) {
343  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
344  } else {
345  auto itB = XTMPB->begin(ibx);
346  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
347  cout << "L1T COMPARISON : EtSum type: A = " << itA->getType() << " vs B = " << itB->getType() << "\n";
348  if (itA->getType() != itB->getType()) {
349  cout << "L1T COMPARISON FAILURE: Different types .... EtSum type:" << itA->getType() << " vs "
350  << itB->getType() << "\n";
351  }
352  if (itA->getType() == EtSum::kTotalEtEm)
353  cout << "L1T COMPARISON WARNING: (known issue) sum of type " << itA->getType()
354  << " when emulated has a dummy value (pending proper emulation)"
355  << "\n";
356  if (itA->getType() < EtSum::kMinBiasHFP0 || itA->getType() > EtSum::kMinBiasHFM1) {
357  bool fail = compare_l1candidate(*itA, *itB);
358  if (fail) {
359  cout << "L1T COMPARISON FAILURE: for type " << itA->getType() << "\n";
360  }
361  if (!fail) {
362  sumCount_++;
363  } else {
364  sumFails_++;
365  }
366  } else {
367  cout << "L1T COMPARISON WARNING: (known issue) not checking sum of type " << itA->getType() << "\n";
368  }
369  itB++;
370  }
371  }
372  }
373  }
374  }
375 
376  if (muonCheck_) {
378  iEvent.getByToken(muonTokenA_, XTMPA);
380  iEvent.getByToken(muonTokenB_, XTMPB);
381 
382  if (!(XTMPA.isValid() && XTMPB.isValid())) {
383  LogWarning("MissingProduct") << "L1Upgrade muon's not found." << std::endl;
384  } else {
385  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
386  if (bxZeroOnly_ && (ibx != 0))
387  continue;
388  if (ibx < XTMPB->getFirstBX())
389  continue;
390  if (ibx > XTMPB->getLastBX())
391  continue;
392  int sizeA = XTMPA->size(ibx);
393  int sizeB = XTMPB->size(ibx);
394  if (sizeA != sizeB) {
395  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
396  } else {
397  auto itB = XTMPB->begin(ibx);
398  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
399  bool fail = compare_l1candidate(*itA, *itB);
400  itB++;
401  if (!fail) {
402  muonCount_++;
403  } else {
404  muonFails_++;
405  }
406  }
407  }
408  }
409  }
410  }
411 }
412 
413 void L1TComparison::beginJob() { cout << "INFO: L1TComparison module beginJob called.\n"; }
414 
416  cout << "INFO: L1T Comparison for " << tag_ << "\n";
417  cout << "INFO: count of successful comparison for each type follows:\n";
418  if (egCheck_)
419  cout << "eg: " << egCount_ << "\n";
420  if (tauCheck_)
421  cout << "tau: " << tauCount_ << "\n";
422  if (jetCheck_)
423  cout << "jet: " << jetCount_ << "\n";
424  if (sumCheck_)
425  cout << "sum: " << sumCount_ << "\n";
426  if (muonCheck_)
427  cout << "muon: " << muonCount_ << "\n";
428  cout << "INFO: count of failed comparison for each type follows:\n";
429  if (egCheck_)
430  cout << "eg: " << egFails_ << "\n";
431  if (tauCheck_)
432  cout << "tau: " << tauFails_ << "\n";
433  if (jetCheck_)
434  cout << "jet: " << jetFails_ << "\n";
435  if (sumCheck_)
436  cout << "sum: " << sumFails_ << "\n";
437  if (muonCheck_)
438  cout << "muon: " << muonFails_ << "\n";
439 
440  int fail = 0;
441  if (egCheck_ && ((egFails_ > 0) || (egCount_ <= 0)))
442  fail = 1;
443  if (tauCheck_ && ((tauFails_ > 0) || (tauCount_ <= 0)))
444  fail = 1;
445  if (jetCheck_ && ((jetFails_ > 0) || (jetCount_ <= 0)))
446  fail = 1;
447  if (sumCheck_ && ((sumFails_ > 0) || (sumCount_ <= 0)))
448  fail = 1;
449  if (muonCheck_ && ((muonFails_ > 0) || (muonCount_ <= 0)))
450  fail = 1;
451 
452  if (fail) {
453  cout << "SUMMARY: L1T Comparison for " << tag_ << " was FAILURE\n";
454  } else {
455  cout << "SUMMARY: L1T Comparison for " << tag_ << " was SUCCESS\n";
456  }
457 }
458 
460  //The following says we do not know what parameters are allowed so do no validation
461  // Please change this to state exactly what you do use, even if it is no parameters
463  desc.setUnknown();
464  descriptions.addDefault(desc);
465 }
466 
int getLastBX() const
edm::EDGetTokenT< EGammaBxCollection > egTokenB_
int getFirstBX() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< MuonBxCollection > muonTokenA_
static bool compare_l1candidate(const L1Candidate &a, const L1Candidate &b, int verbose=1)
bool verbose
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< EGammaBxCollection > egTokenA_
void beginJob() override
L1TComparison(const ParameterSet &)
delete x;
Definition: CaloConfig.h:22
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void beginJob()
Definition: Breakpoints.cc:14
const_iterator begin(int bx) const
unsigned size(int bx) const
int iEvent
Definition: GenABIO.cc:224
~L1TComparison() override
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< MuonBxCollection > muonTokenB_
void analyze(Event const &, EventSetup const &) override
void endJob() override
edm::EDGetTokenT< JetBxCollection > jetTokenA_
edm::EDGetTokenT< EtSumBxCollection > sumTokenB_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< EtSumBxCollection > sumTokenA_
double b
Definition: hdecay.h:118
edm::EDGetTokenT< GlobalAlgBlkBxCollection > algTokenB_
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< JetBxCollection > jetTokenB_
const_iterator end(int bx) const
HLT enums.
double a
Definition: hdecay.h:119
edm::EDGetTokenT< TauBxCollection > tauTokenB_
edm::EDGetTokenT< TauBxCollection > tauTokenA_
edm::EDGetTokenT< GlobalAlgBlkBxCollection > algTokenA_
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Log< level::Warning, false > LogWarning