CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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()) status = 1;
27  if (a.eta() != b.eta()) status = 1;
28  if (a.phi() != b.phi()) status = 1;
29 
30  if (status){
31  cout << "COMPARISON FAILURE: \n";
32  cout << "A: pt = " << a.pt() << " eta = " << a.eta() << " phi = " << a.phi() << "\n";
33  cout << "B: pt = " << b.pt() << " eta = " << b.eta() << " phi = " << b.phi() << "\n";
34  }
35 
36  if (a.hwPt() != b.hwPt()) status = 1;
37  if (a.hwEta() != b.hwEta()) status = 1;
38  if (a.hwPhi() != b.hwPhi()) status = 1;
39 
40  if (status){
41  cout << "COMPARISON FAILURE: \n";
42  cout << "A: hwPt = " << a.hwPt() << " hwEta = " << a.hwEta() << " hwPhi = " << a.hwPhi() << "\n";
43  cout << "B: hwPt = " << b.hwPt() << " hwEta = " << b.hwEta() << " hwPhi = " << b.hwPhi() << "\n";
44  }
45 
46  if (a.hwQual() != b.hwQual()) status = 1;
47  if (a.hwIso() != b.hwIso()) status = 1;
48  if (status){
49  cout << "COMPARISON FAILURE: \n";
50  cout << "A: hwQual = " << a.hwQual() << " hwIso = " << a.hwIso() << "\n";
51  cout << "B: hwQual = " << b.hwQual() << " hwIso = " << b.hwIso() << "\n";
52  }
53 
54 
55 
56  return status;
57 }
58 
59 
60 
61 class L1TComparison : public EDAnalyzer {
62 public:
63  explicit L1TComparison(const ParameterSet&);
64  ~L1TComparison();
65 
66  static void fillDescriptions(ConfigurationDescriptions& descriptions);
67 
68 private:
69  virtual void beginJob();
70  virtual void analyze(Event const&, EventSetup const&);
71  virtual void endJob();
72 
73  virtual void beginRun(Run const&, EventSetup const&);
74  virtual void endRun(Run const&, EventSetup const&);
75  virtual void beginLuminosityBlock(LuminosityBlock const&, EventSetup const&);
76  virtual void endLuminosityBlock(LuminosityBlock const&, EventSetup const&);
77 
78  // Tag string to mark summary with:
79  string tag_;
80 
81  // Checks to perform:
82  bool egCheck_;
83  bool tauCheck_;
84  bool jetCheck_;
85  bool sumCheck_;
86  bool muonCheck_;
87  bool algCheck_;
88  bool bxZeroOnly_;
89 
90  // EDM tokens:
97 
104 
105  // keep a tally for summary:
106  int egCount_;
112 
113 
114  int egFails_;
120 };
121 
123 
124 
125  tag_ = iConfig.getParameter<string>("tag");
126  egCheck_ = iConfig.getParameter<bool>("egCheck");
127  tauCheck_ = iConfig.getParameter<bool>("tauCheck");
128  jetCheck_ = iConfig.getParameter<bool>("jetCheck");
129  sumCheck_ = iConfig.getParameter<bool>("sumCheck");
130  muonCheck_ = iConfig.getParameter<bool>("muonCheck");
131  algCheck_ = iConfig.getParameter<bool>("algCheck");
132  bxZeroOnly_ = iConfig.getParameter<bool>("bxZeroOnly");
133 
134  cout << "L1T Summary for " << tag_ << "\n";
135  cout << "DEBUG: egCheck: " << egCheck_ << "\n";
136  cout << "DEBUG: tauCheck: " << tauCheck_ << "\n";
137  cout << "DEBUG: jetCheck: " << jetCheck_ << "\n";
138  cout << "DEBUG: sumCheck: " << sumCheck_ << "\n";
139  cout << "DEBUG: muonCheck: " << muonCheck_ << "\n";
140  cout << "DEBUG: algCheck: " << algCheck_ << "\n";
141 
142  if (egCheck_) {egTokenA_ = consumes<EGammaBxCollection> (iConfig.getParameter<InputTag>("egTagA"));}
143  if (tauCheck_) {tauTokenA_ = consumes<TauBxCollection> (iConfig.getParameter<InputTag>("tauTagA"));}
144  if (jetCheck_) {jetTokenA_ = consumes<JetBxCollection> (iConfig.getParameter<InputTag>("jetTagA"));}
145  if (sumCheck_) {sumTokenA_ = consumes<EtSumBxCollection> (iConfig.getParameter<InputTag>("sumTagA"));}
146  if (muonCheck_) {muonTokenA_ = consumes<MuonBxCollection> (iConfig.getParameter<InputTag>("muonTagA"));}
147  if (algCheck_) {algTokenA_ = consumes<GlobalAlgBlkBxCollection> (iConfig.getParameter<InputTag>("algTagA"));}
148 
149  if (egCheck_) {egTokenB_ = consumes<EGammaBxCollection> (iConfig.getParameter<InputTag>("egTagB"));}
150  if (tauCheck_) {tauTokenB_ = consumes<TauBxCollection> (iConfig.getParameter<InputTag>("tauTagB"));}
151  if (jetCheck_) {jetTokenB_ = consumes<JetBxCollection> (iConfig.getParameter<InputTag>("jetTagB"));}
152  if (sumCheck_) {sumTokenB_ = consumes<EtSumBxCollection> (iConfig.getParameter<InputTag>("sumTagB"));}
153  if (muonCheck_) {muonTokenB_ = consumes<MuonBxCollection> (iConfig.getParameter<InputTag>("muonTagB"));}
154  if (algCheck_) {algTokenB_ = consumes<GlobalAlgBlkBxCollection> (iConfig.getParameter<InputTag>("algTagB"));}
155 
156  egCount_ = 0;
157  tauCount_ = 0;
158  jetCount_ = 0;
159  sumCount_ = 0;
160  muonCount_ = 0;
161  algCount_ = 0;
162 
163  egFails_ = 0;
164  tauFails_ = 0;
165  jetFails_ = 0;
166  sumFails_ = 0;
167  muonFails_ = 0;
168  algFails_ = 0;
169 
170 }
171 
173 
174 
175 void
177 {
178 
179  cout << "L1TComparison Module output for " << tag_ << "\n";
180 
181  if (egCheck_){
183  iEvent.getByToken(egTokenA_, XTMPA);
185  iEvent.getByToken(egTokenB_, XTMPB);
186 
187  if (!(XTMPA.isValid() && XTMPB.isValid())){
188  LogWarning("MissingProduct") << "L1Upgrade e-gamma's not found." << std::endl;
189  } else {
190  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
191  if (bxZeroOnly_ && (ibx != 0)) continue;
192  if (ibx < XTMPB->getFirstBX()) continue;
193  if (ibx > XTMPB->getLastBX()) continue;
194  int sizeA = XTMPA->size(ibx);
195  int sizeB = XTMPB->size(ibx);
196  if (sizeA != sizeB){
197  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
198  } else {
199  auto itB=XTMPB->begin(ibx);
200  for (auto itA=XTMPA->begin(ibx); itA!=XTMPA->end(ibx); ++itA){
201  bool fail = compare_l1candidate(*itA, *itB);
202  itB++;
203  if (! fail) { egCount_++; }
204  else { egFails_++; }
205  }
206 
207  }
208  }
209  }
210  }
211 
212 
213  if (tauCheck_){
215  iEvent.getByToken(tauTokenA_, XTMPA);
217  iEvent.getByToken(tauTokenB_, XTMPB);
218 
219  if (!(XTMPA.isValid() && XTMPB.isValid())){
220  LogWarning("MissingProduct") << "L1Upgrade tau's not found." << std::endl;
221  } else {
222  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
223  if (bxZeroOnly_ && (ibx != 0)) continue;
224  if (ibx < XTMPB->getFirstBX()) continue;
225  if (ibx > XTMPB->getLastBX()) continue;
226  int sizeA = XTMPA->size(ibx);
227  int sizeB = XTMPB->size(ibx);
228  if (sizeA != sizeB){
229  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
230  } else {
231  auto itB=XTMPB->begin(ibx);
232  for (auto itA=XTMPA->begin(ibx); itA!=XTMPA->end(ibx); ++itA){
233  bool fail = compare_l1candidate(*itA, *itB);
234  itB++;
235  if (! fail) { tauCount_++; }
236  else { tauFails_++; }
237  }
238  }
239  }
240  }
241  }
242 
243  if (jetCheck_){
245  iEvent.getByToken(jetTokenA_, XTMPA);
247  iEvent.getByToken(jetTokenB_, XTMPB);
248 
249  if (!(XTMPA.isValid() && XTMPB.isValid())){
250  LogWarning("MissingProduct") << "L1Upgrade jet's not found." << std::endl;
251  } else {
252  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
253  if (bxZeroOnly_ && (ibx != 0)) continue;
254  if (ibx < XTMPB->getFirstBX()) continue;
255  if (ibx > XTMPB->getLastBX()) continue;
256  int sizeA = XTMPA->size(ibx);
257  int sizeB = XTMPB->size(ibx);
258  if (sizeA != sizeB){
259  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
260  } else {
261  auto itB=XTMPB->begin(ibx);
262  for (auto itA=XTMPA->begin(ibx); itA!=XTMPA->end(ibx); ++itA){
263  bool fail = compare_l1candidate(*itA, *itB);
264  itB++;
265  if (! fail) { jetCount_++; }
266  else { jetFails_++; }
267  }
268  }
269  }
270  }
271  }
272 
273  if (sumCheck_){
275  iEvent.getByToken(sumTokenA_, XTMPA);
277  iEvent.getByToken(sumTokenB_, XTMPB);
278 
279  if (!(XTMPA.isValid() && XTMPB.isValid())){
280  LogWarning("MissingProduct") << "L1Upgrade sum's not found." << std::endl;
281  } else {
282  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
283  if (bxZeroOnly_ && (ibx != 0)) continue;
284  if (ibx < XTMPB->getFirstBX()) continue;
285  if (ibx > XTMPB->getLastBX()) continue;
286  int sizeA = XTMPA->size(ibx);
287  int sizeB = XTMPB->size(ibx);
288 
289  if (sizeA != sizeB){
290  cout << "L1T COMPARISON WARNING: sums collections have different sizes for bx = " << ibx << "\n";
291  cout << "L1T COMPARISON WARNING: sums collections A size = " << sizeA << " sums collection B size = " << sizeB << "\n";
292  cout << "L1T COMPARISON WARNING: known issue because packer has not been udpated for Minbias\n";
293  }
294  for (auto itA=XTMPA->begin(ibx); itA!=XTMPA->end(ibx); ++itA){
295  cout << "L1T COMPARISON : EtSum type: A = " << itA->getType() << "\n";
296  }
297  for (auto itB=XTMPB->begin(ibx); itB!=XTMPB->end(ibx); ++itB){
298  cout << "L1T COMPARISON : EtSum type: B = " << itB->getType() << "\n";
299  }
300 
301  // temp workaround for sums not packed...
302  if (sizeA > sizeB) sizeA = sizeB;
303  if (sizeB > sizeA) sizeB = sizeA;
304 
305  if (sizeA != sizeB){
306  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
307  } else {
308  auto itB=XTMPB->begin(ibx);
309  for (auto itA=XTMPA->begin(ibx); itA!=XTMPA->end(ibx); ++itA){
310  cout << "L1T COMPARISON : EtSum type: A = " << itA->getType() << " vs B = " << itB->getType() << "\n";
311  if (itA->getType() != itB->getType()){
312  cout << "L1T COMPARISON FAILURE: Different types .... EtSum type:" << itA->getType() << " vs " << itB->getType() << "\n";
313  }
314  if (itA->getType() == EtSum::kTotalEtEm)
315  cout << "L1T COMPARISON WARNING: (known issue) sum of type " << itA->getType() << " when emulated has a dummy value (pending proper emulation)" << "\n";
316  if (itA->getType() < EtSum::kMinBiasHFP0 || itA->getType() > EtSum::kMinBiasHFM1) {
317  bool fail = compare_l1candidate(*itA, *itB);
318  if (fail){ cout << "L1T COMPARISON FAILURE: for type " << itA->getType() << "\n";}
319  if (! fail) { sumCount_++; }
320  else { sumFails_++; }
321  } else {
322  cout << "L1T COMPARISON WARNING: (known issue) not checking sum of type " << itA->getType() << "\n";
323  }
324  itB++;
325  }
326  }
327  }
328  }
329  }
330 
331 
332  if (muonCheck_){
334  iEvent.getByToken(muonTokenA_, XTMPA);
336  iEvent.getByToken(muonTokenB_, XTMPB);
337 
338  if (!(XTMPA.isValid() && XTMPB.isValid())){
339  LogWarning("MissingProduct") << "L1Upgrade muon's not found." << std::endl;
340  } else {
341  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
342  if (bxZeroOnly_ && (ibx != 0)) continue;
343  if (ibx < XTMPB->getFirstBX()) continue;
344  if (ibx > XTMPB->getLastBX()) continue;
345  int sizeA = XTMPA->size(ibx);
346  int sizeB = XTMPB->size(ibx);
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  bool fail = compare_l1candidate(*itA, *itB);
353  itB++;
354  if (! fail) { muonCount_++; }
355  else { muonFails_++; }
356  }
357  }
358  }
359  }
360  }
361 
362 
363 
364 
365 
366 }
367 
368 void
370 {
371  cout << "INFO: L1TComparison module beginJob called.\n";
372 }
373 
374 void
376  cout << "INFO: L1T Comparison for " << tag_ << "\n";
377  cout << "INFO: count of successful comparison for each type follows:\n";
378  if (egCheck_) cout << "eg: " << egCount_ << "\n";
379  if (tauCheck_) cout << "tau: " << tauCount_ << "\n";
380  if (jetCheck_) cout << "jet: " << jetCount_ << "\n";
381  if (sumCheck_) cout << "sum: " << sumCount_ << "\n";
382  if (muonCheck_) cout << "muon: " << muonCount_ << "\n";
383  cout << "INFO: count of failed comparison for each type follows:\n";
384  if (egCheck_) cout << "eg: " << egFails_ << "\n";
385  if (tauCheck_) cout << "tau: " << tauFails_ << "\n";
386  if (jetCheck_) cout << "jet: " << jetFails_ << "\n";
387  if (sumCheck_) cout << "sum: " << sumFails_ << "\n";
388  if (muonCheck_) cout << "muon: " << muonFails_ << "\n";
389 
390  int fail = 0;
391  if (egCheck_ && ((egFails_>0) || (egCount_<=0))) fail = 1;
392  if (tauCheck_ && ((tauFails_>0) || (tauCount_<=0))) fail = 1;
393  if (jetCheck_ && ((jetFails_>0) || (jetCount_<=0))) fail = 1;
394  if (sumCheck_ && ((sumFails_>0) || (sumCount_<=0))) fail = 1;
395  if (muonCheck_ && ((muonFails_>0) || (muonCount_<=0))) fail = 1;
396 
397  if (fail){
398  cout << "SUMMARY: L1T Comparison for " << tag_ << " was FAILURE\n";
399  } else {
400  cout << "SUMMARY: L1T Comparison for " << tag_ << " was SUCCESS\n";
401  }
402 
403 
404 
405 
406 }
407 
408 void
410 {
411 }
412 
413 void
415 {
416 }
417 
418 void
420 {
421 }
422 
423 void
425 {
426 }
427 
428 void
430  //The following says we do not know what parameters are allowed so do no validation
431  // Please change this to state exactly what you do use, even if it is no parameters
433  desc.setUnknown();
434  descriptions.addDefault(desc);
435 }
436 
437 
T getParameter(std::string const &) const
edm::EDGetTokenT< EGammaBxCollection > egTokenB_
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:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< EGammaBxCollection > egTokenA_
L1TComparison(const ParameterSet &)
virtual double phi() const final
momentum azimuthal angle
int hwPhi() const
Definition: L1Candidate.h:50
void beginJob()
Definition: Breakpoints.cc:15
int hwIso() const
Definition: L1Candidate.h:52
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< MuonBxCollection > muonTokenB_
virtual void beginRun(Run const &, EventSetup const &)
virtual void endLuminosityBlock(LuminosityBlock const &, EventSetup const &)
edm::EDGetTokenT< JetBxCollection > jetTokenA_
edm::EDGetTokenT< EtSumBxCollection > sumTokenB_
int hwEta() const
Definition: L1Candidate.h:49
bool isValid() const
Definition: HandleBase.h:75
int hwQual() const
Definition: L1Candidate.h:51
virtual void endJob()
int hwPt() const
Definition: L1Candidate.h:48
virtual void beginLuminosityBlock(LuminosityBlock const &, EventSetup const &)
edm::EDGetTokenT< EtSumBxCollection > sumTokenA_
double b
Definition: hdecay.h:120
edm::EDGetTokenT< GlobalAlgBlkBxCollection > algTokenB_
edm::EDGetTokenT< JetBxCollection > jetTokenB_
double a
Definition: hdecay.h:121
edm::EDGetTokenT< TauBxCollection > tauTokenB_
edm::EDGetTokenT< TauBxCollection > tauTokenA_
edm::EDGetTokenT< GlobalAlgBlkBxCollection > algTokenA_
tuple cout
Definition: gather_cfg.py:145
virtual double eta() const final
momentum pseudorapidity
static void fillDescriptions(ConfigurationDescriptions &descriptions)
virtual void analyze(Event const &, EventSetup const &)
virtual void beginJob()
virtual void endRun(Run const &, EventSetup const &)
Definition: Run.h:43
tuple status
Definition: mps_update.py:57
virtual double pt() const final
transverse momentum