CMS 3D CMS Logo

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