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 // 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 
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52 private:
53  void analyze(const edm::Event&, const edm::EventSetup&) override;
54  void endJob() override;
55 
56  // ----------member data ---------------------------
57 
60 
63 
64  uint32_t eventCount;
65  uint32_t badEventCount;
66  uint32_t towerCount;
67  uint32_t badTowerCount;
70  uint32_t regionCount;
71  uint32_t badRegionCount;
74 
75  uint32_t ngRegion[22];
76  uint32_t nbRegion[22];
77  uint32_t zgRegion[22];
78  uint32_t zbRegion[22];
79 
80  uint32_t ngCard[18];
81  uint32_t nbCard[18];
82  uint32_t zgCard[18];
83  uint32_t zbCard[18];
84 
85  uint32_t tLrEmulTotET;
86  uint32_t tErEmulTotET;
87  uint32_t tGrEmulTotET;
88 
89  uint32_t tLeTotET;
90  uint32_t tEeTotET;
91  uint32_t tGeTotET;
92 
95 
96  bool verbose;
97 };
98 
99 //
100 // constants, enums and typedefs
101 //
102 
103 //
104 // static data member definitions
105 //
106 
107 //
108 // constructors and destructor
109 //
111  : testTowerToken(consumes<CaloTowerBxCollection>(iConfig.getParameter<edm::InputTag>("testTowerToken"))),
112  emulTowerToken(consumes<CaloTowerBxCollection>(iConfig.getParameter<edm::InputTag>("emulTowerToken"))),
113  testRegionToken(consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("testRegionToken"))),
114  emulRegionToken(consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("emulRegionToken"))),
115  eventCount(0),
116  badEventCount(0),
117  towerCount(0),
118  badTowerCount(0),
119  nonZeroTowerCount(0),
120  badNonZeroTowerCount(0),
121  regionCount(0),
122  badRegionCount(0),
123  nonZeroRegionCount(0),
124  badNonZeroRegionCount(0),
125  tLrEmulTotET(0),
126  tErEmulTotET(0),
127  tGrEmulTotET(0),
128  tLeTotET(0),
129  tEeTotET(0),
130  tGeTotET(0),
131  validateTowers(iConfig.getParameter<bool>("validateTowers")),
132  validateRegions(iConfig.getParameter<bool>("validateRegions")),
133  verbose(iConfig.getParameter<bool>("verbose")) {
134  for (uint32_t r = 0; r < 22; r++)
135  ngRegion[r] = nbRegion[r] = zgRegion[r] = zbRegion[r] = 0;
136  for (uint32_t c = 0; c < 18; c++)
137  ngCard[c] = nbCard[c] = zgCard[c] = zbCard[c] = 0;
138 }
139 
140 //
141 // member functions
142 //
143 
144 // ------------ method called for each event ------------
146  using namespace edm;
147  bool badEvent = false;
148  int theBX = 0;
149 
150  // Emulator calo towers and regions should always be available - get them
151  // Data will always contain calo regions, but not necessarily calo towers
152 
154  iEvent.getByToken(emulTowerToken, emulTowers);
156  iEvent.getByToken(testRegionToken, testRegions);
158  iEvent.getByToken(emulRegionToken, emulRegions);
159 
160  if (validateTowers) {
161  // Test towers will be available for spy and fat events only
163  iEvent.getByToken(testTowerToken, testTowers);
164  for (std::vector<CaloTower>::const_iterator testTower = testTowers->begin(theBX);
165  testTower != testTowers->end(theBX);
166  ++testTower) {
167  int test_iEta = testTower->hwEta();
168  int test_iPhi = testTower->hwPhi();
169  int test_et = testTower->hwPt();
170  int test_er = testTower->hwEtRatio();
171  int test_fb = testTower->hwQual();
172  for (std::vector<CaloTower>::const_iterator emulTower = emulTowers->begin(theBX);
173  emulTower != emulTowers->end(theBX);
174  ++emulTower) {
175  int emul_iEta = emulTower->hwEta();
176  int emul_iPhi = emulTower->hwPhi();
177  int emul_et = emulTower->hwPt();
178  int emul_er = emulTower->hwEtRatio();
179  int emul_fb = emulTower->hwQual();
180  bool success = true;
181  if (test_iEta == emul_iEta && test_iPhi == emul_iPhi) {
182  if (test_et != emul_et) {
183  success = false;
184  }
185  if (test_er != emul_er) {
186  success = false;
187  }
188  if (test_fb != emul_fb) {
189  success = false;
190  }
191  if (!success) {
192  if (test_et != emul_et) {
193  if (verbose)
194  LOG_ERROR << "ET ";
195  }
196  if (test_er != emul_er) {
197  if (verbose)
198  LOG_ERROR << "ER ";
199  }
200  if (test_fb != emul_fb) {
201  if (verbose)
202  LOG_ERROR << "FB ";
203  }
204  if (verbose)
205  LOG_ERROR << "Checks failed for tower (" << std::dec << test_iEta << ", " << test_iPhi << ") : ("
206  << test_et << ", " << test_er << ", " << test_fb << ") != (" << emul_et << ", " << emul_er
207  << ", " << emul_fb << ")" << std::endl;
208  badEvent = true;
209  badTowerCount++;
210  if (test_et > 0)
212  }
213  towerCount++;
214  if (test_et > 0)
216  }
217  if (!success && test_et == emul_et && test_iPhi == emul_iPhi) {
218  if (verbose)
219  LOG_ERROR << "Incidental match for tower (" << std::dec << test_iEta << ", " << test_iPhi << ") : ("
220  << test_et << ", " << test_er << ", " << test_fb << ") != (" << emul_iEta << "," << emul_iPhi
221  << ") :(" << emul_et << ", " << emul_er << ", " << emul_fb << ")" << std::endl;
222  }
223  }
224  }
225  }
226 
227  // Region Validation
228 
229  if (validateRegions) {
230  UCTGeometry g;
231  uint32_t testRegionTotET = 0;
232  uint32_t emulRegionTotET = 0;
233  for (std::vector<L1CaloRegion>::const_iterator testRegion = testRegions->begin(); testRegion != testRegions->end();
234  ++testRegion) {
235  // uint16_t test_raw = testRegion->raw();
236  uint32_t test_et = testRegion->et();
237  testRegionTotET += test_et;
238  uint32_t test_rEta = testRegion->id().ieta();
239  uint32_t test_rPhi = testRegion->id().iphi();
240  // uint32_t test_iEta = (test_raw >> 12) & 0x3;
241  // uint32_t test_iPhi = (test_raw >> 14) & 0x3;
242  bool test_negativeEta = false;
243  int test_cEta = (test_rEta - 11) * 4 + 1; //test_iEta + 1;
244  if (test_rEta < 11) {
245  test_negativeEta = true;
246  test_cEta = -((10 - test_rEta) * 4 + 1); //test_iEta + 1);
247  }
248  int test_cPhi = test_rPhi * 4 + 1; //test_iPhi + 1;
249  uint32_t test_crate = g.getCrate(test_cEta, test_cPhi);
250  uint32_t test_card = g.getCard(test_cEta, test_cPhi);
251  uint32_t test_region = g.getRegion(test_cEta, test_cPhi);
252  for (std::vector<L1CaloRegion>::const_iterator emulRegion = emulRegions->begin();
253  emulRegion != emulRegions->end();
254  ++emulRegion) {
255  // uint16_t emul_raw = emulRegion->raw();
256  uint32_t emul_et = emulRegion->et();
257  if (testRegion == testRegions->begin())
258  emulRegionTotET += emul_et; // increment only once!
259  uint32_t emul_rEta = emulRegion->id().ieta();
260  uint32_t emul_rPhi = emulRegion->id().iphi();
261  // uint32_t emul_iEta = (emul_raw >> 12) & 0x3;
262  // uint32_t emul_iPhi = (emul_raw >> 14) & 0x3;
263  bool emul_negativeEta = false;
264  int emul_cEta = (emul_rEta - 11) * 4 + 1; //emul_iEta + 1;
265  if (emul_rEta < 11) {
266  emul_negativeEta = true;
267  emul_cEta = -((10 - emul_rEta) * 4 + 1); //emul_iEta + 1);
268  }
269  int emul_cPhi = emul_rPhi * 4 + 1; //emul_iPhi + 1;
270  uint32_t emul_crate = g.getCrate(emul_cEta, emul_cPhi);
271  uint32_t emul_card = g.getCard(emul_cEta, emul_cPhi);
272  uint32_t emul_region = g.getRegion(emul_cEta, emul_cPhi);
273  bool success = true;
274  if (test_rEta == emul_rEta && test_rPhi == emul_rPhi) {
275  if (test_et != emul_et)
276  success = false;
277  //if(test_iEta != emul_iEta) success = false;
278  //if(test_iPhi != emul_iPhi) success = false;
279  if (!success) {
280  if (verbose)
281  LOG_ERROR << "Checks failed for region (" << std::dec << test_rEta << ", " << test_rPhi << ") ("
282  << test_negativeEta << ", " << test_crate << ", " << test_card << ", " << test_region
283  << ", "
284  // << test_iEta << ", "
285  // << test_iPhi << ", "
286  << test_et << ") != (" << emul_negativeEta << ", " << emul_crate << ", " << emul_card << ", "
287  << emul_region
288  << ", "
289  // << emul_iEta << ", "
290  // << emul_iPhi << ", "
291  << emul_et << ")" << std::endl;
292  badEvent = true;
293  badRegionCount++;
294  if (test_et > 0) {
296  nbRegion[test_rEta]++;
297  nbCard[test_rPhi]++;
298  } else {
299  zbRegion[test_rEta]++;
300  zbCard[test_rPhi]++;
301  }
302  } else {
303  if (test_et > 0) {
304  ngRegion[test_rEta]++;
305  ngCard[test_rPhi]++;
306  if (verbose)
307  LOG_ERROR << "Checks passed for region (" << std::dec << test_rEta << ", " << test_rPhi << ") ("
308  << test_negativeEta << ", " << test_crate << ", " << test_card << ", " << test_region
309  << ", "
310  // << test_iEta << ", "
311  // << test_iPhi << ", "
312  << test_et << ") == (" << emul_negativeEta << ", " << emul_crate << ", " << emul_card << ", "
313  << emul_region
314  << ", "
315  // << emul_iEta << ", "
316  // << emul_iPhi << ", "
317  << emul_et << ")" << std::endl;
318  } else {
319  zgRegion[test_rEta]++;
320  zgCard[test_rPhi]++;
321  }
322  }
323  regionCount++;
324  if (test_et > 0)
326  }
327  if (!success && test_et == emul_et) { // && test_iPhi == emul_iPhi) {
328  if (verbose)
329  LOG_ERROR << "Incidental match for region (" << std::dec << test_rEta << ", " << test_rPhi
330  << ", "
331  // << test_iEta << ", "
332  // << test_iPhi << ", "
333  << test_et << ") != (" << emul_rEta << ", " << emul_rPhi
334  << ", "
335  // << emul_iEta << ", "
336  // << emul_iPhi << ", "
337  << emul_et << ")" << std::endl;
338  }
339  }
340  }
341  uint32_t emulTowerTotET = 0;
342  for (std::vector<CaloTower>::const_iterator emulTower = emulTowers->begin(theBX);
343  emulTower != emulTowers->end(theBX);
344  ++emulTower) {
345  int twr_et = emulTower->hwPt();
346  int twr_cEta = emulTower->hwEta();
347  int twr_cPhi = emulTower->hwPhi();
348  uint32_t twr_region = g.getRegion(twr_cEta, twr_cPhi);
349  uint32_t twr_gEta = 10 - twr_region;
350  if (twr_cEta > 0)
351  twr_gEta = twr_region + 11;
352  uint32_t twr_gPhi = g.getUCTRegionPhiIndex(twr_cPhi);
353  if (badEvent && twr_et > 0) {
354  if (verbose)
355  LOG_ERROR << "Non-zero tower in region (" << twr_gEta << ", " << twr_gPhi << ") "
356  << "(cEta, cPhi, et) = (" << twr_cEta << ", " << twr_cPhi << ", " << twr_et << ")" << std::endl;
357  }
358  if (std::abs(twr_cEta) <= 28)
359  emulTowerTotET += twr_et; // Exclude HF towers for now
360  }
361  // Increment counters for emulated total tower ET comparison with total region ET
362  if (emulTowerTotET < emulRegionTotET)
363  tLrEmulTotET++;
364  else if (emulTowerTotET > emulRegionTotET)
365  tGrEmulTotET++;
366  else
367  tErEmulTotET++;
368  // Increment counters for emulated total region ET comparison with region test ET
369  if (testRegionTotET < emulRegionTotET)
370  tLeTotET++;
371  else if (testRegionTotET > emulRegionTotET)
372  tGeTotET++;
373  else
374  tEeTotET++;
375  }
376 
377  // Event counters
378 
379  if (badEvent)
380  badEventCount++;
381  eventCount++;
382 }
383 
384 // ------------ method called once each job just after ending the event loop ------------
386  if (validateTowers)
387  LOG_ERROR << "L1TCaloLayer1Validator: Summary is Non-Zero Bad Tower / Bad Tower / Event Count = ("
388  << badNonZeroTowerCount << " of " << nonZeroTowerCount << ") / (" << badTowerCount << " of " << towerCount
389  << ") / (" << badEventCount << " of " << eventCount << ")" << std::endl;
390  if (validateRegions) {
391  LOG_ERROR << "L1TCaloLayer1Validator: Summary is Non-Zero Bad Region / Bad Region / Event Count = ("
392  << badNonZeroRegionCount << " of " << nonZeroRegionCount << ") / (" << badRegionCount << " of "
393  << regionCount << ") / (" << badEventCount << " of " << eventCount << ")" << std::endl;
394  LOG_ERROR << "L1TCaloLayer1Validator reTa, non-zero-good / non-zero-bad / zero-good / zero-bad region[rEta] = "
395  << std::endl;
396  for (uint32_t r = 0; r < 22; r++)
397  LOG_ERROR << r << ", " << ngRegion[r] << " / " << nbRegion[r] << " / " << zgRegion[r] << " / " << zbRegion[r]
398  << std::endl;
399  LOG_ERROR << "L1TCaloLayer1Validator rPhi, non-zero-good / non-zero-bad / zero-good / zero-bad region[rPhi] = "
400  << std::endl;
401  for (uint32_t r = 0; r < 18; r++)
402  LOG_ERROR << r << ", " << ngCard[r] << " / " << nbCard[r] << " / " << zgCard[r] << " / " << zbCard[r]
403  << std::endl;
404  LOG_ERROR << "L1TCaloLayer1Validator : Total ET emulator tower vs region; less / equal / greater counts: "
405  << tLrEmulTotET << " / " << tErEmulTotET << " / " << tGrEmulTotET << std::endl;
406  LOG_ERROR << "L1TCaloLayer1Validator : Total ET region test vs emulator; less / equal / greater counts: "
407  << tLeTotET << " / " << tEeTotET << " / " << tGeTotET << std::endl;
408  }
409 }
410 
411 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
413  //The following says we do not know what parameters are allowed so do no validation
414  // Please change this to state exactly what you do use, even if it is no parameters
416  desc.setUnknown();
417  descriptions.addDefault(desc);
418 }
419 
420 //define this as a plug-in
edm::EDGetTokenT< CaloTowerBxCollection > emulTowerToken
bool verbose
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
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void analyze(const edm::Event &, const edm::EventSetup &) override
const_iterator begin(int bx) const
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< L1CaloRegionCollection > testRegionToken
L1TCaloLayer1Validator(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const_iterator end(int bx) const
HLT enums.
std::vector< L1CaloRegion > L1CaloRegionCollection
#define LOG_ERROR
Definition: CSCDQM_Logger.h:40