CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 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  void beginRun(Run const&, EventSetup const&) override;
78  void endRun(Run const&, EventSetup const&) override;
79  void beginLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
80  void endLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
81 
82  // Tag string to mark summary with:
83  string tag_;
84 
85  // Checks to perform:
86  bool egCheck_;
87  bool tauCheck_;
88  bool jetCheck_;
89  bool sumCheck_;
90  bool muonCheck_;
91  bool algCheck_;
93 
94  // EDM tokens:
101 
108 
109  // keep a tally for summary:
110  int egCount_;
116 
117  int egFails_;
123 };
124 
126  tag_ = iConfig.getParameter<string>("tag");
127  egCheck_ = iConfig.getParameter<bool>("egCheck");
128  tauCheck_ = iConfig.getParameter<bool>("tauCheck");
129  jetCheck_ = iConfig.getParameter<bool>("jetCheck");
130  sumCheck_ = iConfig.getParameter<bool>("sumCheck");
131  muonCheck_ = iConfig.getParameter<bool>("muonCheck");
132  algCheck_ = iConfig.getParameter<bool>("algCheck");
133  bxZeroOnly_ = iConfig.getParameter<bool>("bxZeroOnly");
134 
135  cout << "L1T Summary for " << tag_ << "\n";
136  cout << "DEBUG: egCheck: " << egCheck_ << "\n";
137  cout << "DEBUG: tauCheck: " << tauCheck_ << "\n";
138  cout << "DEBUG: jetCheck: " << jetCheck_ << "\n";
139  cout << "DEBUG: sumCheck: " << sumCheck_ << "\n";
140  cout << "DEBUG: muonCheck: " << muonCheck_ << "\n";
141  cout << "DEBUG: algCheck: " << algCheck_ << "\n";
142 
143  if (egCheck_) {
144  egTokenA_ = consumes<EGammaBxCollection>(iConfig.getParameter<InputTag>("egTagA"));
145  }
146  if (tauCheck_) {
147  tauTokenA_ = consumes<TauBxCollection>(iConfig.getParameter<InputTag>("tauTagA"));
148  }
149  if (jetCheck_) {
150  jetTokenA_ = consumes<JetBxCollection>(iConfig.getParameter<InputTag>("jetTagA"));
151  }
152  if (sumCheck_) {
153  sumTokenA_ = consumes<EtSumBxCollection>(iConfig.getParameter<InputTag>("sumTagA"));
154  }
155  if (muonCheck_) {
156  muonTokenA_ = consumes<MuonBxCollection>(iConfig.getParameter<InputTag>("muonTagA"));
157  }
158  if (algCheck_) {
159  algTokenA_ = consumes<GlobalAlgBlkBxCollection>(iConfig.getParameter<InputTag>("algTagA"));
160  }
161 
162  if (egCheck_) {
163  egTokenB_ = consumes<EGammaBxCollection>(iConfig.getParameter<InputTag>("egTagB"));
164  }
165  if (tauCheck_) {
166  tauTokenB_ = consumes<TauBxCollection>(iConfig.getParameter<InputTag>("tauTagB"));
167  }
168  if (jetCheck_) {
169  jetTokenB_ = consumes<JetBxCollection>(iConfig.getParameter<InputTag>("jetTagB"));
170  }
171  if (sumCheck_) {
172  sumTokenB_ = consumes<EtSumBxCollection>(iConfig.getParameter<InputTag>("sumTagB"));
173  }
174  if (muonCheck_) {
175  muonTokenB_ = consumes<MuonBxCollection>(iConfig.getParameter<InputTag>("muonTagB"));
176  }
177  if (algCheck_) {
178  algTokenB_ = consumes<GlobalAlgBlkBxCollection>(iConfig.getParameter<InputTag>("algTagB"));
179  }
180 
181  egCount_ = 0;
182  tauCount_ = 0;
183  jetCount_ = 0;
184  sumCount_ = 0;
185  muonCount_ = 0;
186  algCount_ = 0;
187 
188  egFails_ = 0;
189  tauFails_ = 0;
190  jetFails_ = 0;
191  sumFails_ = 0;
192  muonFails_ = 0;
193  algFails_ = 0;
194 }
195 
197 
198 void L1TComparison::analyze(Event const& iEvent, EventSetup const& iSetup) {
199  cout << "L1TComparison Module output for " << tag_ << "\n";
200 
201  if (egCheck_) {
203  iEvent.getByToken(egTokenA_, XTMPA);
205  iEvent.getByToken(egTokenB_, XTMPB);
206 
207  if (!(XTMPA.isValid() && XTMPB.isValid())) {
208  LogWarning("MissingProduct") << "L1Upgrade e-gamma's not found." << std::endl;
209  } else {
210  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
211  if (bxZeroOnly_ && (ibx != 0))
212  continue;
213  if (ibx < XTMPB->getFirstBX())
214  continue;
215  if (ibx > XTMPB->getLastBX())
216  continue;
217  int sizeA = XTMPA->size(ibx);
218  int sizeB = XTMPB->size(ibx);
219  if (sizeA != sizeB) {
220  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
221  } else {
222  auto itB = XTMPB->begin(ibx);
223  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
224  bool fail = compare_l1candidate(*itA, *itB);
225  itB++;
226  if (!fail) {
227  egCount_++;
228  } else {
229  egFails_++;
230  }
231  }
232  }
233  }
234  }
235  }
236 
237  if (tauCheck_) {
239  iEvent.getByToken(tauTokenA_, XTMPA);
241  iEvent.getByToken(tauTokenB_, XTMPB);
242 
243  if (!(XTMPA.isValid() && XTMPB.isValid())) {
244  LogWarning("MissingProduct") << "L1Upgrade tau's not found." << std::endl;
245  } else {
246  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
247  if (bxZeroOnly_ && (ibx != 0))
248  continue;
249  if (ibx < XTMPB->getFirstBX())
250  continue;
251  if (ibx > XTMPB->getLastBX())
252  continue;
253  int sizeA = XTMPA->size(ibx);
254  int sizeB = XTMPB->size(ibx);
255  if (sizeA != sizeB) {
256  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
257  } else {
258  auto itB = XTMPB->begin(ibx);
259  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
260  bool fail = compare_l1candidate(*itA, *itB);
261  itB++;
262  if (!fail) {
263  tauCount_++;
264  } else {
265  tauFails_++;
266  }
267  }
268  }
269  }
270  }
271  }
272 
273  if (jetCheck_) {
275  iEvent.getByToken(jetTokenA_, XTMPA);
277  iEvent.getByToken(jetTokenB_, XTMPB);
278 
279  if (!(XTMPA.isValid() && XTMPB.isValid())) {
280  LogWarning("MissingProduct") << "L1Upgrade jet's not found." << std::endl;
281  } else {
282  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
283  if (bxZeroOnly_ && (ibx != 0))
284  continue;
285  if (ibx < XTMPB->getFirstBX())
286  continue;
287  if (ibx > XTMPB->getLastBX())
288  continue;
289  int sizeA = XTMPA->size(ibx);
290  int sizeB = XTMPB->size(ibx);
291  if (sizeA != sizeB) {
292  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
293  } else {
294  auto itB = XTMPB->begin(ibx);
295  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
296  bool fail = compare_l1candidate(*itA, *itB);
297  itB++;
298  if (!fail) {
299  jetCount_++;
300  } else {
301  jetFails_++;
302  }
303  }
304  }
305  }
306  }
307  }
308 
309  if (sumCheck_) {
311  iEvent.getByToken(sumTokenA_, XTMPA);
313  iEvent.getByToken(sumTokenB_, XTMPB);
314 
315  if (!(XTMPA.isValid() && XTMPB.isValid())) {
316  LogWarning("MissingProduct") << "L1Upgrade sum's not found." << std::endl;
317  } else {
318  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
319  if (bxZeroOnly_ && (ibx != 0))
320  continue;
321  if (ibx < XTMPB->getFirstBX())
322  continue;
323  if (ibx > XTMPB->getLastBX())
324  continue;
325  int sizeA = XTMPA->size(ibx);
326  int sizeB = XTMPB->size(ibx);
327 
328  if (sizeA != sizeB) {
329  cout << "L1T COMPARISON WARNING: sums collections have different sizes for bx = " << ibx << "\n";
330  cout << "L1T COMPARISON WARNING: sums collections A size = " << sizeA
331  << " sums collection B size = " << sizeB << "\n";
332  cout << "L1T COMPARISON WARNING: known issue because packer has not been udpated for Minbias\n";
333  }
334  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
335  cout << "L1T COMPARISON : EtSum type: A = " << itA->getType() << "\n";
336  }
337  for (auto itB = XTMPB->begin(ibx); itB != XTMPB->end(ibx); ++itB) {
338  cout << "L1T COMPARISON : EtSum type: B = " << itB->getType() << "\n";
339  }
340 
341  // temp workaround for sums not packed...
342  if (sizeA > sizeB)
343  sizeA = sizeB;
344  if (sizeB > sizeA)
345  sizeB = sizeA;
346 
347  if (sizeA != sizeB) {
348  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
349  } else {
350  auto itB = XTMPB->begin(ibx);
351  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
352  cout << "L1T COMPARISON : EtSum type: A = " << itA->getType() << " vs B = " << itB->getType() << "\n";
353  if (itA->getType() != itB->getType()) {
354  cout << "L1T COMPARISON FAILURE: Different types .... EtSum type:" << itA->getType() << " vs "
355  << itB->getType() << "\n";
356  }
357  if (itA->getType() == EtSum::kTotalEtEm)
358  cout << "L1T COMPARISON WARNING: (known issue) sum of type " << itA->getType()
359  << " when emulated has a dummy value (pending proper emulation)"
360  << "\n";
361  if (itA->getType() < EtSum::kMinBiasHFP0 || itA->getType() > EtSum::kMinBiasHFM1) {
362  bool fail = compare_l1candidate(*itA, *itB);
363  if (fail) {
364  cout << "L1T COMPARISON FAILURE: for type " << itA->getType() << "\n";
365  }
366  if (!fail) {
367  sumCount_++;
368  } else {
369  sumFails_++;
370  }
371  } else {
372  cout << "L1T COMPARISON WARNING: (known issue) not checking sum of type " << itA->getType() << "\n";
373  }
374  itB++;
375  }
376  }
377  }
378  }
379  }
380 
381  if (muonCheck_) {
383  iEvent.getByToken(muonTokenA_, XTMPA);
385  iEvent.getByToken(muonTokenB_, XTMPB);
386 
387  if (!(XTMPA.isValid() && XTMPB.isValid())) {
388  LogWarning("MissingProduct") << "L1Upgrade muon's not found." << std::endl;
389  } else {
390  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
391  if (bxZeroOnly_ && (ibx != 0))
392  continue;
393  if (ibx < XTMPB->getFirstBX())
394  continue;
395  if (ibx > XTMPB->getLastBX())
396  continue;
397  int sizeA = XTMPA->size(ibx);
398  int sizeB = XTMPB->size(ibx);
399  if (sizeA != sizeB) {
400  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
401  } else {
402  auto itB = XTMPB->begin(ibx);
403  for (auto itA = XTMPA->begin(ibx); itA != XTMPA->end(ibx); ++itA) {
404  bool fail = compare_l1candidate(*itA, *itB);
405  itB++;
406  if (!fail) {
407  muonCount_++;
408  } else {
409  muonFails_++;
410  }
411  }
412  }
413  }
414  }
415  }
416 }
417 
418 void L1TComparison::beginJob() { cout << "INFO: L1TComparison module beginJob called.\n"; }
419 
421  cout << "INFO: L1T Comparison for " << tag_ << "\n";
422  cout << "INFO: count of successful comparison for each type follows:\n";
423  if (egCheck_)
424  cout << "eg: " << egCount_ << "\n";
425  if (tauCheck_)
426  cout << "tau: " << tauCount_ << "\n";
427  if (jetCheck_)
428  cout << "jet: " << jetCount_ << "\n";
429  if (sumCheck_)
430  cout << "sum: " << sumCount_ << "\n";
431  if (muonCheck_)
432  cout << "muon: " << muonCount_ << "\n";
433  cout << "INFO: count of failed comparison for each type follows:\n";
434  if (egCheck_)
435  cout << "eg: " << egFails_ << "\n";
436  if (tauCheck_)
437  cout << "tau: " << tauFails_ << "\n";
438  if (jetCheck_)
439  cout << "jet: " << jetFails_ << "\n";
440  if (sumCheck_)
441  cout << "sum: " << sumFails_ << "\n";
442  if (muonCheck_)
443  cout << "muon: " << muonFails_ << "\n";
444 
445  int fail = 0;
446  if (egCheck_ && ((egFails_ > 0) || (egCount_ <= 0)))
447  fail = 1;
448  if (tauCheck_ && ((tauFails_ > 0) || (tauCount_ <= 0)))
449  fail = 1;
450  if (jetCheck_ && ((jetFails_ > 0) || (jetCount_ <= 0)))
451  fail = 1;
452  if (sumCheck_ && ((sumFails_ > 0) || (sumCount_ <= 0)))
453  fail = 1;
454  if (muonCheck_ && ((muonFails_ > 0) || (muonCount_ <= 0)))
455  fail = 1;
456 
457  if (fail) {
458  cout << "SUMMARY: L1T Comparison for " << tag_ << " was FAILURE\n";
459  } else {
460  cout << "SUMMARY: L1T Comparison for " << tag_ << " was SUCCESS\n";
461  }
462 }
463 
464 void L1TComparison::beginRun(Run const& run, EventSetup const& iSetup) {}
465 
466 void L1TComparison::endRun(Run const&, EventSetup const&) {}
467 
469 
471 
473  //The following says we do not know what parameters are allowed so do no validation
474  // Please change this to state exactly what you do use, even if it is no parameters
476  desc.setUnknown();
477  descriptions.addDefault(desc);
478 }
479 
edm::EDGetTokenT< EGammaBxCollection > egTokenB_
double pt() const final
transverse momentum
void beginRun(Run const &, EventSetup const &) override
edm::EDGetTokenT< MuonBxCollection > muonTokenA_
static bool compare_l1candidate(const L1Candidate &a, const L1Candidate &b, int verbose=1)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< EGammaBxCollection > egTokenA_
list status
Definition: mps_update.py:107
void beginJob() override
L1TComparison(const ParameterSet &)
int hwPhi() const
Definition: L1Candidate.h:37
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void beginJob()
Definition: Breakpoints.cc:14
int hwIso() const
Definition: L1Candidate.h:39
int iEvent
Definition: GenABIO.cc:224
~L1TComparison() override
void addDefault(ParameterSetDescription const &psetDescription)
static constexpr int verbose
edm::EDGetTokenT< MuonBxCollection > muonTokenB_
void analyze(Event const &, EventSetup const &) override
void endRun(Run const &, EventSetup const &) override
void endJob() override
edm::EDGetTokenT< JetBxCollection > jetTokenA_
void endLuminosityBlock(LuminosityBlock const &, EventSetup const &) override
edm::EDGetTokenT< EtSumBxCollection > sumTokenB_
int hwEta() const
Definition: L1Candidate.h:36
bool isValid() const
Definition: HandleBase.h:70
int hwQual() const
Definition: L1Candidate.h:38
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int hwPt() const
Definition: L1Candidate.h:35
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< EtSumBxCollection > sumTokenA_
double b
Definition: hdecay.h:118
edm::EDGetTokenT< GlobalAlgBlkBxCollection > algTokenB_
edm::EDGetTokenT< JetBxCollection > jetTokenB_
double a
Definition: hdecay.h:119
edm::EDGetTokenT< TauBxCollection > tauTokenB_
edm::EDGetTokenT< TauBxCollection > tauTokenA_
edm::EDGetTokenT< GlobalAlgBlkBxCollection > algTokenA_
tuple cout
Definition: gather_cfg.py:144
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Log< level::Warning, false > LogWarning
double phi() const final
momentum azimuthal angle
Definition: Run.h:45
void beginLuminosityBlock(LuminosityBlock const &, EventSetup const &) override
double eta() const final
momentum pseudorapidity