CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1TCaloLayer1Validator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1TCaloLayer1
4 // Class: L1TCaloLayer1Validator
5 //
14 //
15 // Original Author: Sridhara Dasu
16 // Created: Sun, 11 Oct 2015 08:14:01 GMT
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
35 
36 #include "L1Trigger/L1TCaloLayer1/src/UCTGeometry.hh"
37 
38 #include "L1Trigger/L1TCaloLayer1/src/UCTLogging.hh"
39 
40 using namespace l1t;
41 
42 //
43 // class declaration
44 //
45 
47 public:
49  ~L1TCaloLayer1Validator() override;
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53 private:
54  void beginJob() override;
55  void analyze(const edm::Event&, const edm::EventSetup&) override;
56  void endJob() override;
57 
58  //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
59  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
60  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
61  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
62 
63  // ----------member data ---------------------------
64 
67 
70 
71  uint32_t eventCount;
72  uint32_t badEventCount;
73  uint32_t towerCount;
74  uint32_t badTowerCount;
77  uint32_t regionCount;
78  uint32_t badRegionCount;
81 
82  uint32_t ngRegion[22];
83  uint32_t nbRegion[22];
84  uint32_t zgRegion[22];
85  uint32_t zbRegion[22];
86 
87  uint32_t ngCard[18];
88  uint32_t nbCard[18];
89  uint32_t zgCard[18];
90  uint32_t zbCard[18];
91 
92  uint32_t tLrEmulTotET;
93  uint32_t tErEmulTotET;
94  uint32_t tGrEmulTotET;
95 
96  uint32_t tLeTotET;
97  uint32_t tEeTotET;
98  uint32_t tGeTotET;
99 
102 
103  bool verbose;
104 };
105 
106 //
107 // constants, enums and typedefs
108 //
109 
110 //
111 // static data member definitions
112 //
113 
114 //
115 // constructors and destructor
116 //
118  : testTowerToken(consumes<CaloTowerBxCollection>(iConfig.getParameter<edm::InputTag>("testTowerToken"))),
119  emulTowerToken(consumes<CaloTowerBxCollection>(iConfig.getParameter<edm::InputTag>("emulTowerToken"))),
120  testRegionToken(consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("testRegionToken"))),
121  emulRegionToken(consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("emulRegionToken"))),
122  eventCount(0),
123  badEventCount(0),
124  towerCount(0),
125  badTowerCount(0),
126  nonZeroTowerCount(0),
127  badNonZeroTowerCount(0),
128  regionCount(0),
129  badRegionCount(0),
130  nonZeroRegionCount(0),
131  badNonZeroRegionCount(0),
132  tLrEmulTotET(0),
133  tErEmulTotET(0),
134  tGrEmulTotET(0),
135  tLeTotET(0),
136  tEeTotET(0),
137  tGeTotET(0),
138  validateTowers(iConfig.getParameter<bool>("validateTowers")),
139  validateRegions(iConfig.getParameter<bool>("validateRegions")),
140  verbose(iConfig.getParameter<bool>("verbose")) {
141  for (uint32_t r = 0; r < 22; r++)
142  ngRegion[r] = nbRegion[r] = zgRegion[r] = zbRegion[r] = 0;
143  for (uint32_t c = 0; c < 18; c++)
144  ngCard[c] = nbCard[c] = zgCard[c] = zbCard[c] = 0;
145 }
146 
148 
149 //
150 // member functions
151 //
152 
153 // ------------ method called for each event ------------
155  using namespace edm;
156  bool badEvent = false;
157  int theBX = 0;
158 
159  // Emulator calo towers and regions should always be available - get them
160  // Data will always contain calo regions, but not necessarily calo towers
161 
163  iEvent.getByToken(emulTowerToken, emulTowers);
165  iEvent.getByToken(testRegionToken, testRegions);
167  iEvent.getByToken(emulRegionToken, emulRegions);
168 
169  if (validateTowers) {
170  // Test towers will be available for spy and fat events only
172  iEvent.getByToken(testTowerToken, testTowers);
173  for (std::vector<CaloTower>::const_iterator testTower = testTowers->begin(theBX);
174  testTower != testTowers->end(theBX);
175  ++testTower) {
176  int test_iEta = testTower->hwEta();
177  int test_iPhi = testTower->hwPhi();
178  int test_et = testTower->hwPt();
179  int test_er = testTower->hwEtRatio();
180  int test_fb = testTower->hwQual();
181  for (std::vector<CaloTower>::const_iterator emulTower = emulTowers->begin(theBX);
182  emulTower != emulTowers->end(theBX);
183  ++emulTower) {
184  int emul_iEta = emulTower->hwEta();
185  int emul_iPhi = emulTower->hwPhi();
186  int emul_et = emulTower->hwPt();
187  int emul_er = emulTower->hwEtRatio();
188  int emul_fb = emulTower->hwQual();
189  bool success = true;
190  if (test_iEta == emul_iEta && test_iPhi == emul_iPhi) {
191  if (test_et != emul_et) {
192  success = false;
193  }
194  if (test_er != emul_er) {
195  success = false;
196  }
197  if (test_fb != emul_fb) {
198  success = false;
199  }
200  if (!success) {
201  if (test_et != emul_et) {
202  if (verbose)
203  LOG_ERROR << "ET ";
204  }
205  if (test_er != emul_er) {
206  if (verbose)
207  LOG_ERROR << "ER ";
208  }
209  if (test_fb != emul_fb) {
210  if (verbose)
211  LOG_ERROR << "FB ";
212  }
213  if (verbose)
214  LOG_ERROR << "Checks failed for tower (" << std::dec << test_iEta << ", " << test_iPhi << ") : ("
215  << test_et << ", " << test_er << ", " << test_fb << ") != (" << emul_et << ", " << emul_er
216  << ", " << emul_fb << ")" << std::endl;
217  badEvent = true;
218  badTowerCount++;
219  if (test_et > 0)
221  }
222  towerCount++;
223  if (test_et > 0)
225  }
226  if (!success && test_et == emul_et && test_iPhi == emul_iPhi) {
227  if (verbose)
228  LOG_ERROR << "Incidental match for tower (" << std::dec << test_iEta << ", " << test_iPhi << ") : ("
229  << test_et << ", " << test_er << ", " << test_fb << ") != (" << emul_iEta << "," << emul_iPhi
230  << ") :(" << emul_et << ", " << emul_er << ", " << emul_fb << ")" << std::endl;
231  }
232  }
233  }
234  }
235 
236  // Region Validation
237 
238  if (validateRegions) {
239  UCTGeometry g;
240  uint32_t testRegionTotET = 0;
241  uint32_t emulRegionTotET = 0;
242  for (std::vector<L1CaloRegion>::const_iterator testRegion = testRegions->begin(); testRegion != testRegions->end();
243  ++testRegion) {
244  // uint16_t test_raw = testRegion->raw();
245  uint32_t test_et = testRegion->et();
246  testRegionTotET += test_et;
247  uint32_t test_rEta = testRegion->id().ieta();
248  uint32_t test_rPhi = testRegion->id().iphi();
249  // uint32_t test_iEta = (test_raw >> 12) & 0x3;
250  // uint32_t test_iPhi = (test_raw >> 14) & 0x3;
251  bool test_negativeEta = false;
252  int test_cEta = (test_rEta - 11) * 4 + 1; //test_iEta + 1;
253  if (test_rEta < 11) {
254  test_negativeEta = true;
255  test_cEta = -((10 - test_rEta) * 4 + 1); //test_iEta + 1);
256  }
257  int test_cPhi = test_rPhi * 4 + 1; //test_iPhi + 1;
258  uint32_t test_crate = g.getCrate(test_cEta, test_cPhi);
259  uint32_t test_card = g.getCard(test_cEta, test_cPhi);
260  uint32_t test_region = g.getRegion(test_cEta, test_cPhi);
261  for (std::vector<L1CaloRegion>::const_iterator emulRegion = emulRegions->begin();
262  emulRegion != emulRegions->end();
263  ++emulRegion) {
264  // uint16_t emul_raw = emulRegion->raw();
265  uint32_t emul_et = emulRegion->et();
266  if (testRegion == testRegions->begin())
267  emulRegionTotET += emul_et; // increment only once!
268  uint32_t emul_rEta = emulRegion->id().ieta();
269  uint32_t emul_rPhi = emulRegion->id().iphi();
270  // uint32_t emul_iEta = (emul_raw >> 12) & 0x3;
271  // uint32_t emul_iPhi = (emul_raw >> 14) & 0x3;
272  bool emul_negativeEta = false;
273  int emul_cEta = (emul_rEta - 11) * 4 + 1; //emul_iEta + 1;
274  if (emul_rEta < 11) {
275  emul_negativeEta = true;
276  emul_cEta = -((10 - emul_rEta) * 4 + 1); //emul_iEta + 1);
277  }
278  int emul_cPhi = emul_rPhi * 4 + 1; //emul_iPhi + 1;
279  uint32_t emul_crate = g.getCrate(emul_cEta, emul_cPhi);
280  uint32_t emul_card = g.getCard(emul_cEta, emul_cPhi);
281  uint32_t emul_region = g.getRegion(emul_cEta, emul_cPhi);
282  bool success = true;
283  if (test_rEta == emul_rEta && test_rPhi == emul_rPhi) {
284  if (test_et != emul_et)
285  success = false;
286  //if(test_iEta != emul_iEta) success = false;
287  //if(test_iPhi != emul_iPhi) success = false;
288  if (!success) {
289  if (verbose)
290  LOG_ERROR << "Checks failed for region (" << std::dec << test_rEta << ", " << test_rPhi << ") ("
291  << test_negativeEta << ", " << test_crate << ", " << test_card << ", " << test_region
292  << ", "
293  // << test_iEta << ", "
294  // << test_iPhi << ", "
295  << test_et << ") != (" << emul_negativeEta << ", " << emul_crate << ", " << emul_card << ", "
296  << emul_region
297  << ", "
298  // << emul_iEta << ", "
299  // << emul_iPhi << ", "
300  << emul_et << ")" << std::endl;
301  badEvent = true;
302  badRegionCount++;
303  if (test_et > 0) {
305  nbRegion[test_rEta]++;
306  nbCard[test_rPhi]++;
307  } else {
308  zbRegion[test_rEta]++;
309  zbCard[test_rPhi]++;
310  }
311  } else {
312  if (test_et > 0) {
313  ngRegion[test_rEta]++;
314  ngCard[test_rPhi]++;
315  if (verbose)
316  LOG_ERROR << "Checks passed for region (" << std::dec << test_rEta << ", " << test_rPhi << ") ("
317  << test_negativeEta << ", " << test_crate << ", " << test_card << ", " << test_region
318  << ", "
319  // << test_iEta << ", "
320  // << test_iPhi << ", "
321  << test_et << ") == (" << emul_negativeEta << ", " << emul_crate << ", " << emul_card << ", "
322  << emul_region
323  << ", "
324  // << emul_iEta << ", "
325  // << emul_iPhi << ", "
326  << emul_et << ")" << std::endl;
327  } else {
328  zgRegion[test_rEta]++;
329  zgCard[test_rPhi]++;
330  }
331  }
332  regionCount++;
333  if (test_et > 0)
335  }
336  if (!success && test_et == emul_et) { // && test_iPhi == emul_iPhi) {
337  if (verbose)
338  LOG_ERROR << "Incidental match for region (" << std::dec << test_rEta << ", " << test_rPhi
339  << ", "
340  // << test_iEta << ", "
341  // << test_iPhi << ", "
342  << test_et << ") != (" << emul_rEta << ", " << emul_rPhi
343  << ", "
344  // << emul_iEta << ", "
345  // << emul_iPhi << ", "
346  << emul_et << ")" << std::endl;
347  }
348  }
349  }
350  uint32_t emulTowerTotET = 0;
351  for (std::vector<CaloTower>::const_iterator emulTower = emulTowers->begin(theBX);
352  emulTower != emulTowers->end(theBX);
353  ++emulTower) {
354  int twr_et = emulTower->hwPt();
355  int twr_cEta = emulTower->hwEta();
356  int twr_cPhi = emulTower->hwPhi();
357  uint32_t twr_region = g.getRegion(twr_cEta, twr_cPhi);
358  uint32_t twr_gEta = 10 - twr_region;
359  if (twr_cEta > 0)
360  twr_gEta = twr_region + 11;
361  uint32_t twr_gPhi = g.getUCTRegionPhiIndex(twr_cPhi);
362  if (badEvent && twr_et > 0) {
363  if (verbose)
364  LOG_ERROR << "Non-zero tower in region (" << twr_gEta << ", " << twr_gPhi << ") "
365  << "(cEta, cPhi, et) = (" << twr_cEta << ", " << twr_cPhi << ", " << twr_et << ")" << std::endl;
366  }
367  if (std::abs(twr_cEta) <= 28)
368  emulTowerTotET += twr_et; // Exclude HF towers for now
369  }
370  // Increment counters for emulated total tower ET comparison with total region ET
371  if (emulTowerTotET < emulRegionTotET)
372  tLrEmulTotET++;
373  else if (emulTowerTotET > emulRegionTotET)
374  tGrEmulTotET++;
375  else
376  tErEmulTotET++;
377  // Increment counters for emulated total region ET comparison with region test ET
378  if (testRegionTotET < emulRegionTotET)
379  tLeTotET++;
380  else if (testRegionTotET > emulRegionTotET)
381  tGeTotET++;
382  else
383  tEeTotET++;
384  }
385 
386  // Event counters
387 
388  if (badEvent)
389  badEventCount++;
390  eventCount++;
391 }
392 
393 // ------------ method called once each job just before starting event loop ------------
395 
396 // ------------ method called once each job just after ending the event loop ------------
398  if (validateTowers)
399  LOG_ERROR << "L1TCaloLayer1Validator: Summary is Non-Zero Bad Tower / Bad Tower / Event Count = ("
400  << badNonZeroTowerCount << " of " << nonZeroTowerCount << ") / (" << badTowerCount << " of " << towerCount
401  << ") / (" << badEventCount << " of " << eventCount << ")" << std::endl;
402  if (validateRegions) {
403  LOG_ERROR << "L1TCaloLayer1Validator: Summary is Non-Zero Bad Region / Bad Region / Event Count = ("
404  << badNonZeroRegionCount << " of " << nonZeroRegionCount << ") / (" << badRegionCount << " of "
405  << regionCount << ") / (" << badEventCount << " of " << eventCount << ")" << std::endl;
406  LOG_ERROR << "L1TCaloLayer1Validator reTa, non-zero-good / non-zero-bad / zero-good / zero-bad region[rEta] = "
407  << std::endl;
408  for (uint32_t r = 0; r < 22; r++)
409  LOG_ERROR << r << ", " << ngRegion[r] << " / " << nbRegion[r] << " / " << zgRegion[r] << " / " << zbRegion[r]
410  << std::endl;
411  LOG_ERROR << "L1TCaloLayer1Validator rPhi, non-zero-good / non-zero-bad / zero-good / zero-bad region[rPhi] = "
412  << std::endl;
413  for (uint32_t r = 0; r < 18; r++)
414  LOG_ERROR << r << ", " << ngCard[r] << " / " << nbCard[r] << " / " << zgCard[r] << " / " << zbCard[r]
415  << std::endl;
416  LOG_ERROR << "L1TCaloLayer1Validator : Total ET emulator tower vs region; less / equal / greater counts: "
417  << tLrEmulTotET << " / " << tErEmulTotET << " / " << tGrEmulTotET << std::endl;
418  LOG_ERROR << "L1TCaloLayer1Validator : Total ET region test vs emulator; less / equal / greater counts: "
419  << tLeTotET << " / " << tEeTotET << " / " << tGeTotET << std::endl;
420  }
421 }
422 
423 // ------------ method called when starting to processes a run ------------
424 /*
425 void
426 L1TCaloLayer1Validator::beginRun(edm::Run const&, edm::EventSetup const&)
427 {
428 }
429 */
430 
431 // ------------ method called when ending the processing of a run ------------
432 /*
433 void
434 L1TCaloLayer1Validator::endRun(edm::Run const&, edm::EventSetup const&)
435 {
436 }
437 */
438 
439 // ------------ method called when starting to processes a luminosity block ------------
440 /*
441 void
442 L1TCaloLayer1Validator::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
443 {
444 }
445 */
446 
447 // ------------ method called when ending the processing of a luminosity block ------------
448 /*
449 void
450 L1TCaloLayer1Validator::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
451 {
452 }
453 */
454 
455 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
457  //The following says we do not know what parameters are allowed so do no validation
458  // Please change this to state exactly what you do use, even if it is no parameters
460  desc.setUnknown();
461  descriptions.addDefault(desc);
462 }
463 
464 //define this as a plug-in
const edm::EventSetup & c
edm::EDGetTokenT< CaloTowerBxCollection > emulTowerToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< L1CaloRegionCollection > emulRegionToken
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< CaloTowerBxCollection > testTowerToken
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void analyze(const edm::Event &, const edm::EventSetup &) override
void beginJob()
Definition: Breakpoints.cc:14
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
static constexpr int verbose
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< L1CaloRegionCollection > testRegionToken
L1TCaloLayer1Validator(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< L1CaloRegion > L1CaloRegionCollection
#define LOG_ERROR
Definition: CSCDQM_Logger.h:40