test
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 << "pt = " << a.pt() << " eta = " << a.eta() << " phi = " << a.phi() << "\n";
33  cout << "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 << "hwPt = " << a.hwPt() << " hwEta = " << a.hwEta() << " hwPhi = " << a.hwPhi() << "\n";
43  cout << "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 << "hwQual = " << a.hwQual() << " hwIso = " << a.hwIso() << "\n";
51  cout << "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: known issue because packer has not been udpated for Minbias\n";
292  }
293 
294  // temp workaround for sums not packed...
295  if (sizeA > sizeB) sizeA = sizeB;
296  if (sizeB > sizeA) sizeB = sizeA;
297 
298  if (sizeA != sizeB){
299  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
300  } else {
301  auto itB=XTMPB->begin(ibx);
302  for (auto itA=XTMPA->begin(ibx); itA!=XTMPA->end(ibx); ++itA){
303  if (itA->getType() != itB->getType()){
304  cout << "L1T COMPARISON FAILURE: EtSum type:" << itA->getType() << " vs " << itB->getType() << "\n";
305  }
306  if (itA->getType() < EtSum::kMissingEt2) {
307  bool fail = compare_l1candidate(*itA, *itB);
308  if (fail){ cout << "L1T COMPARISON FAILURE: for type " << itA->getType() << "\n";}
309  if (! fail) { sumCount_++; }
310  else { sumFails_++; }
311  } else {
312  cout << "L1T COMPARISON WARNING: (known issue) not checking sum of type " << itA->getType() << "\n";
313  }
314  itB++;
315  }
316  }
317  }
318  }
319  }
320 
321 
322  if (muonCheck_){
324  iEvent.getByToken(muonTokenA_, XTMPA);
326  iEvent.getByToken(muonTokenB_, XTMPB);
327 
328  if (!(XTMPA.isValid() && XTMPB.isValid())){
329  LogWarning("MissingProduct") << "L1Upgrade muon's not found." << std::endl;
330  } else {
331  for (int ibx = XTMPA->getFirstBX(); ibx <= XTMPA->getLastBX(); ++ibx) {
332  if (bxZeroOnly_ && (ibx != 0)) continue;
333  if (ibx < XTMPB->getFirstBX()) continue;
334  if (ibx > XTMPB->getLastBX()) continue;
335  int sizeA = XTMPA->size(ibx);
336  int sizeB = XTMPB->size(ibx);
337  if (sizeA != sizeB){
338  cout << "L1T COMPARISON FAILURE: collections have different sizes for bx = " << ibx << "\n";
339  } else {
340  auto itB=XTMPB->begin(ibx);
341  for (auto itA=XTMPA->begin(ibx); itA!=XTMPA->end(ibx); ++itA){
342  bool fail = compare_l1candidate(*itA, *itB);
343  itB++;
344  if (! fail) { muonCount_++; }
345  else { muonFails_++; }
346  }
347  }
348  }
349  }
350  }
351 
352 
353 
354 
355 
356 }
357 
358 void
360 {
361  cout << "INFO: L1TComparison module beginJob called.\n";
362 }
363 
364 void
366  cout << "INFO: L1T Comparison for " << tag_ << "\n";
367  cout << "INFO: count of successful comparison for each type follows:\n";
368  if (egCheck_) cout << "eg: " << egCount_ << "\n";
369  if (tauCheck_) cout << "tau: " << tauCount_ << "\n";
370  if (jetCheck_) cout << "jet: " << jetCount_ << "\n";
371  if (sumCheck_) cout << "sum: " << sumCount_ << "\n";
372  if (muonCheck_) cout << "muon: " << muonCount_ << "\n";
373  cout << "INFO: count of failed comparison for each type follows:\n";
374  if (egCheck_) cout << "eg: " << egFails_ << "\n";
375  if (tauCheck_) cout << "tau: " << tauFails_ << "\n";
376  if (jetCheck_) cout << "jet: " << jetFails_ << "\n";
377  if (sumCheck_) cout << "sum: " << sumFails_ << "\n";
378  if (muonCheck_) cout << "muon: " << muonFails_ << "\n";
379 
380  int fail = 0;
381  if (egCheck_ && ((egFails_>0) || (egCount_<=0))) fail = 1;
382  if (tauCheck_ && ((tauFails_>0) || (tauCount_<=0))) fail = 1;
383  if (jetCheck_ && ((jetFails_>0) || (jetCount_<=0))) fail = 1;
384  if (sumCheck_ && ((sumFails_>0) || (sumCount_<=0))) fail = 1;
385  if (muonCheck_ && ((muonFails_>0) || (muonCount_<=0))) fail = 1;
386 
387  if (fail){
388  cout << "SUMMARY: L1T Comparison for " << tag_ << " was FAILURE\n";
389  } else {
390  cout << "SUMMARY: L1T Comparison for " << tag_ << " was SUCCESS\n";
391  }
392 
393 
394 
395 
396 }
397 
398 void
400 {
401 }
402 
403 void
405 {
406 }
407 
408 void
410 {
411 }
412 
413 void
415 {
416 }
417 
418 void
420  //The following says we do not know what parameters are allowed so do no validation
421  // Please change this to state exactly what you do use, even if it is no parameters
423  desc.setUnknown();
424  descriptions.addDefault(desc);
425 }
426 
427 
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.cc:79
void beginJob()
Definition: Breakpoints.cc:15
int hwIso() const
Definition: L1Candidate.cc:84
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.cc:74
bool isValid() const
Definition: HandleBase.h:75
int hwQual() const
Definition: L1Candidate.cc:89
virtual void endJob()
int hwPt() const
Definition: L1Candidate.cc:69
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