CMS 3D CMS Logo

L1TDEMON.cc
Go to the documentation of this file.
3 #include <bitset>
4 
5 using namespace dedefs;
6 
8 
9  verbose_ = iConfig.getUntrackedParameter<int> ("VerboseFlag", 0);
10 
11  if (verbose())
12  std::cout << "L1TDEMON::L1TDEMON()...\n" << std::flush;
13 
14  DEsource_ = iConfig.getParameter<edm::InputTag> ("DataEmulCompareSource");
15  histFolder_ = iConfig.getUntrackedParameter<std::string> ("HistFolder",
16  "L1TEMU");
17  histFile_ = iConfig.getUntrackedParameter<std::string> ("HistFile", "");
18 
19  runInFF_ = iConfig.getUntrackedParameter<bool> ("RunInFilterFarm", false);
20  if (verbose())
21  std::cout << "Filter farm run setting? " << runInFF_ << "\n"
22  << std::flush;
23 
24  if (iConfig.getUntrackedParameter<bool> ("disableROOToutput", true))
25  histFile_ = "";
26 
27  if (!histFile_.empty()) {
28  edm::LogInfo("OutputRootFile")
29  << "L1TEmulator Monitoring histograms will be saved to "
30  << histFile_.c_str() << std::endl;
31  }
32 
33  // copied from HardwareValidation/L1Comparator
34  // check on size are done there
35  std::vector<unsigned int> dosys(0, DEnsys);
36  dosys = iConfig.getUntrackedParameter<std::vector<unsigned int> > (
37  "COMPARE_COLLS", dosys);
38 
39  for (int i = 0; i < DEnsys; i++) {
40  m_doSys[i] = dosys[i];
41  }
42 
43  //
44 
45  nEvt_ = 0;
46  for (int i = 0; i < DEnsys; i++) {
47  deSysCount[i] = 0;
48  nEvtWithSys[i] = 0;
49  }
50 
51  hasRecord_ = true;
52 
53  if (verbose())
54  std::cout << "L1TDEMON::L1TDEMON constructor...done.\n" << std::flush;
55 
56  //set Tokens(-s)
57  DEsourceToken_ = consumes<L1DataEmulRecord>(iConfig.getParameter<edm::InputTag> ("DataEmulCompareSource"));
58 }
59 
61 }
62 
64 
65  if (verbose())
66  std::cout << "L1TDEMON::beginJob() start\n" << std::flush;
67 
68  ibooker.setCurrentFolder(histFolder_);
69 
70  //physical values disabled now, waiting for scale procedure
71  //const double tpi = 6.2832;
72  //const double amin= -0.5;
73  //const double amax=tpi+0.5;
74 
75  // ETP, HTP, RCT, GCT, DTP, DTF, CTP, CTF, RPC,LTC, GMT,GLT
76  int phiNBins[DEnsys] = { 71 , 71 , 18 ,18 , 12, 255, 160, 255, 144, 0, 255,0};
77  double phiMinim[DEnsys] = { 0.5, 0.5, -0.5,-0.5,-0.5, 0, -0.5, 0, -0.5, 0, 0,0};
78  double phiMaxim[DEnsys] = { 71.5, 71.5, 17.5,17.5,11.5, 255,159.5, 255, 143.5, 0, 255,0};
79 
80  int etaNBins[DEnsys] = { 35 , 35 , 22 ,22 , 5, 20, 120, 20, 64, 0, 20,0};
81  double etaMinim[DEnsys] = {-17.5,-17.5, -0.5,-0.5,-2.5, 0, -0.5, 0, -0.5, 0, 0,0};
82  double etaMaxim[DEnsys] = { 17.5, 17.5, 21.5,21.5, 2.5, 63,119.5, 63, 63.5, 0, 63,0};
83 
84  int x3NBins [DEnsys] = { 0, 0, 7, 0, 4, 0, 0, 0, 0, 0, 0,0};
85  double x3Minim [DEnsys] = { 0, 0, -0.5, 0, 0.5, 0, 0, 0, 0, 0, 0,0};
86  double x3Maxim [DEnsys] = { 0, 0, 6.5, 0, 4.5, 0, 0, 0, 0, 0, 0,0};
87 
88  int rnkNBins[DEnsys] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0};
89  double rnkMinim[DEnsys] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0};
90  double rnkMaxim[DEnsys] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0};
91  //assume for
92  for (int i = 0; i < DEnsys; i++) {
93  rnkNBins[i] = 63;
94  rnkMinim[i] = 0.5;
95  rnkMaxim[i] = 63.5;
96  }//rank 0x3f->63
97  rnkNBins[DTP] = 7;
98  rnkMinim[DTP] = -0.5;
99  rnkMaxim[DTP] = 6.5; //rank 0-6
100  rnkNBins[CTP] = 16;
101  rnkMinim[CTP] = -0.5;
102  rnkMaxim[CTP] = 15.5; //quality 0-15
103 
104  /*--notes
105  RCT: global index ieta (0-21)=[22,-0.5,21.5] , iphi (0-17)=[18,-0.5,17.5]; card (0-6)
106  GCT: phi index (0-17); eta = -6 to -0, +0 to +6. Sign is bit 3, 1 means -ve Z, 0 means +ve Z -> 0.17
107  DTP: usc 0..11; uwh -2..2; ust 1..4;
108  CTP: rank is quality 0..15
109  */
110 
111  if (!runInFF_)
112  ibooker.setCurrentFolder(std::string(histFolder_ + "/common"));
113 
114  for (int j = 0; j < 2; j++) {
115  std::string lbl("sysncand");
116  lbl += (j == 0 ? "Data" : "Emul");
117  sysncand[j] = ibooker.book1D(lbl.data(), lbl.data(), DEnsys, 0, DEnsys);
118  }
119 
120  sysrates = ibooker.book1D("sysrates", "sysrates", DEnsys, 0, DEnsys);
121  const int nerr = 5;
122  errordist = ibooker.book1D("errorflag", "errorflag", nerr, 0, nerr);
123 
124  for (int j = 0; j < DEnsys; j++) {
125 
126  // skip if system disabled
127  if (!m_doSys[j]) {
128  continue;
129  }
130 
131  if (!runInFF_) {
132  ibooker.setCurrentFolder(
133  std::string(histFolder_ + "/" + SystLabelExt[j]));
134  }
135 
136  std::string lbl("");
137  lbl.clear();
138  lbl += SystLabel[j];
139  lbl += "ErrorFlag";
140  errortype[j] = ibooker.book1D(lbl.data(), lbl.data(), nerr, 0, nerr);
141 
142  // skip next histos if running in filter farm
143  if (runInFF_) {
144  continue;
145  }
146 
147  //
148  lbl.clear();
149  lbl += SystLabel[j];
150  lbl += "eta";
151  eta[j] = ibooker.book1D(lbl.data(), lbl.data(), etaNBins[j],
152  etaMinim[j], etaMaxim[j]);
153  lbl.clear();
154  lbl += SystLabel[j];
155  lbl += "phi";
156  phi[j] = ibooker.book1D(lbl.data(), lbl.data(), phiNBins[j],
157  phiMinim[j], phiMaxim[j]);
158  lbl.clear();
159  lbl += SystLabel[j];
160  lbl += "x3";
161  x3[j] = ibooker.book1D(lbl.data(), lbl.data(), x3NBins[j], x3Minim[j],
162  x3Maxim[j]);
163  lbl.clear();
164  lbl += SystLabel[j];
165  lbl += "etaphi";
166  etaphi[j] = ibooker.book2D(lbl.data(), lbl.data(), etaNBins[j],
167  etaMinim[j], etaMaxim[j], phiNBins[j], phiMinim[j],
168  phiMaxim[j]);
169  //
170  lbl.clear();
171  lbl += SystLabel[j];
172  lbl += "eta";
173  lbl += "Data";
174  etaData[j] = ibooker.book1D(lbl.data(), lbl.data(), etaNBins[j],
175  etaMinim[j], etaMaxim[j]);
176  lbl.clear();
177  lbl += SystLabel[j];
178  lbl += "phi";
179  lbl += "Data";
180  phiData[j] = ibooker.book1D(lbl.data(), lbl.data(), phiNBins[j],
181  phiMinim[j], phiMaxim[j]);
182  lbl.clear();
183  lbl += SystLabel[j];
184  lbl += "x3";
185  lbl += "Data";
186  x3Data[j] = ibooker.book1D(lbl.data(), lbl.data(), x3NBins[j],
187  x3Minim[j], x3Maxim[j]);
188  lbl.clear();
189  lbl += SystLabel[j];
190  lbl += "rank";
191  lbl += "Data";
192  rnkData[j] = ibooker.book1D(lbl.data(), lbl.data(), rnkNBins[j],
193  rnkMinim[j], rnkMaxim[j]);
194 
195  const int nbit = (j == GLT) ? 128 : 32;
196  lbl.clear();
197  lbl += SystLabel[j];
198  lbl += "dword";
199  dword[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
200  lbl.clear();
201  lbl += SystLabel[j];
202  lbl += "eword";
203  eword[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
204  lbl.clear();
205  lbl += SystLabel[j];
206  lbl += "deword";
207  deword[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
208  //lbl.clear();
209  //lbl+=SystLabel[j];lbl+="masked";
210  //masked[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
211  }
212 
213 
215  for (int i = 0; i < DEnsys; i++) {
216  sysrates ->setBinLabel(i + 1, SystLabel[i]);
217  sysncand[0]->setBinLabel(i + 1, SystLabel[i]);
218  sysncand[1]->setBinLabel(i + 1, SystLabel[i]);
219  }
220  //const int nerr = 5;
221  std::string errLabel[nerr] = { "Agree", "Loc. Agree", "L.Disagree",
222  "Data only", "Emul only" };
223  for (int j = 0; j < nerr; j++) {
224  errordist->setBinLabel(j + 1, errLabel[j]);
225  }
226  for (int i = 0; i < DEnsys; i++) {
227 
228  // skip if system disabled
229  if (!m_doSys[i]) {
230  continue;
231  }
232 
233  for (int j = 0; j < nerr; j++) {
234 
235  errortype[i]->setBinLabel(j + 1, errLabel[j]);
236  }
237  }
238 
239  // done if running in filter farm
240  if (runInFF_)
241  return;
242 
243  for (int i = 0; i < DEnsys; i++) {
244 
245  // skip if system disabled
246  if (!m_doSys[i]) {
247  continue;
248  }
249 
250  etaphi[i]->setAxisTitle("eta", 1);
251  etaphi[i]->setAxisTitle("phi", 2);
252  eta[i]->setAxisTitle("eta");
253  phi[i]->setAxisTitle("phi");
254  x3[i]->setAxisTitle("x3");
255  etaData[i]->setAxisTitle("eta");
256  phiData[i]->setAxisTitle("phi");
257  x3Data[i]->setAxisTitle("x3");
258  rnkData[i]->setAxisTitle("rank");
259  dword[i]->setAxisTitle("trigger data word bit");
260  eword[i]->setAxisTitle("trigger data word bit");
261  deword[i]->setAxisTitle("trigger data word bit");
262  //masked [i]->setAxisTitle("trigger data word bit");
263  }
264 
265 
266  // assertions/temporary
267  assert(ETP == 0);
268  assert(HTP == 1);
269  assert(RCT == 2);
270  assert(GCT == 3);
271  assert(DTP == 4);
272  assert(DTF == 5);
273  assert(CTP == 6);
274  assert(CTF == 7);
275  assert(RPC == 8);
276  assert(LTC == 9);
277  assert(GMT == 10);
278  assert(GLT == 11);
279 
280  if (verbose())
281  std::cout << "L1TDEMON::bookHistograms() end.\n" << std::flush;
282 }
283 
284 
286 }
287 
288 
289 
290 
291 // ------------ method called to for each event ------------
292 void L1TDEMON::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
293 
294  if (!hasRecord_)
295  return;
296 
297  if (verbose())
298  std::cout << "L1TDEMON::analyze() start\n" << std::flush;
299 
300  nEvt_++;
301 
304  iEvent.getByToken(DEsourceToken_, deRecord);
305 
306  if (!deRecord.isValid()) {
307  edm::LogInfo("DataNotFound")
308  << "Cannot find L1DataEmulRecord with label "
309  << DEsource_.label()
310  << " Please verify that comparator was successfully executed."
311  << " Emulator DQM will be skipped!" << std::endl;
312  hasRecord_ = false;
313  return;
314  }
315 
316  bool deMatch[DEnsys];
317  deRecord->get_status(deMatch);
318  if (verbose()) {
319  std::cout << "[L1TDEMON] verbose sys match?: ";
320  for (int i = 0; i < DEnsys; i++)
321  std::cout << deMatch[i] << " ";
322  std::cout << std::endl;
323  }
324 
325  bool isComp[DEnsys];
326  for (int i = 0; i < DEnsys; i++)
327  isComp[i] = deRecord->get_isComp(i);
328  if (verbose()) {
329  std::cout << "[L1TDEMON] verbose dosys?: ";
330  for (int i = 0; i < DEnsys; i++)
331  std::cout << isComp[i];
332  std::cout << std::endl;
333  }
334 
335  int DEncand[DEnsys][2];
336  for (int i = 0; i < DEnsys; i++)
337  for (int j = 0; j < 2; j++)
338  DEncand[i][j] = deRecord->getNCand(i, j);
339 
340  if (verbose()) {
341  std::cout << "[L1TDEMON] ncands d: ";
342  for (int i = 0; i < DEnsys; i++)
343  std::cout << DEncand[i][0] << " ";
344  std::cout << "\n[L1TDEMON] ncands e: ";
345  for (int i = 0; i < DEnsys; i++)
346  std::cout << DEncand[i][1] << " ";
347  std::cout << std::endl;
348  }
349 
350  const int nullVal = L1DataEmulDigi().reset();
351 
353  L1DEDigiCollection deColl;
354  deColl = deRecord->getColl();
355 
356  // global counters
357  int hasSys[DEnsys] = { 0 };
358  for (L1DEDigiCollection::const_iterator it = deColl.begin(); it
359  != deColl.end(); it++)
360  if (!it->empty())
361  hasSys[it->sid()]++;
362  for (int i = 0; i < DEnsys; i++) {
363  if (!hasSys[i])
364  continue;
365  nEvtWithSys[i]++;
366  if (deMatch[i])
367  deSysCount[i]++;
368  }
369 
370  if (verbose()) {
371  std::cout << "[L1TDEMON] digis: \n";
372  for (L1DEDigiCollection::const_iterator it = deColl.begin(); it
373  != deColl.end(); it++)
374  std::cout << "\t" << *it << std::endl;
375  }
376 
378 
379  // global, sub-systems d|e match, ncands
380  for (int i = 0; i < DEnsys; i++) {
381 
382  // skip if system disabled
383  if (!m_doSys[i]) {
384  continue;
385  }
386 
387  if (!isComp[i])
388  continue;
389 
390  for (int j = 0; j < 2; j++)
391  sysncand[j]->Fill(i, DEncand[i][j]);
392 
393  //sysrates->Fill(i,(int)!deMatch[i]);
394  int ibin = i + 1;
395  double rate = nEvtWithSys[i] ? (nEvtWithSys[i] - 1. * deSysCount[i])
396  / nEvtWithSys[i] : 0.;
397  sysrates->setBinContent(ibin, rate);
398 
399  if (verbose()) {
400  std::cout << "[L1TDEMON] analyze "
401  << " sysid:" << i
402  << " nEvt:" << nEvt_
403  << " match?" << deMatch[i]
404  << " ncands:" << hasSys[i]
405  << " nevtwsys:" << nEvtWithSys[i]
406  << " nevtgood:" << deSysCount[i]
407  << " rate:" << sysrates->getBinContent(ibin)
408  << "\n";
409 
410  if (rate > 1)
411  std::cout << "problem, error rate for " << SystLabel[i]
412  << " is " << sysrates->getBinContent(ibin) << std::endl;
413  }
414  }
415 
416  // container for subsystem's leading candidate
417  const int ncorr = 3;
418  float LeadCandVal[DEnsys][ncorr] = { { (float) nullVal } };
419  for (int i = 0; i < DEnsys; i++)
420  for (int j = 0; j < ncorr; j++)
421  LeadCandVal[i][j] = nullVal;
422 
423  // d|e candidate loop
424  for (L1DEDigiCollection::const_iterator it = deColl.begin(); it
425  != deColl.end(); it++) {
426 
427  int sid = it->sid();
428  int cid = it->cid();
429 
430  if (it->empty())
431  continue;
432  assert(isComp[sid]);
433 
434  int type = it->type();
435  double phiv = it->x1();
436  double etav = it->x2();
437  double x3v = it->x3();
438 
439  float rankarr[2];
440  it->rank(rankarr);
441  float rnkv = rankarr[0];
442 
443  double wei = 1.;
444 
445  unsigned int mask = (~0x0);
446 
447  if (sid == RCT) {
448  //if(cid!=RCTem) continue;
449  //if(cid!=RCTrgn) continue;
450  }
451  // if(sid==GCT) {
452  // // For the moment just include EM and jet objects, energy sums being debugged in the expert DQM first.
453  // if(cid!=GCTisolaem &&
454  // cid!=GCTnoisoem &&
455  // cid!=GCTcenjets &&
456  // cid!=GCTforjets &&
457  // cid!=GCTtaujets) continue;
458  // }
459  if (sid == DTP) {
460  //tbd cols:th,ph; plots per wheel
461  //if(it->x3()!=0) continue;
462  }
463  if (sid == GMT) {
464  //select gmt cands only for GMT sys
465  if (cid != GMTcnd)
466  continue;
467  //masking: gres -- I.Mikulec: mask bits 0,5,16,21,22,23
468  //mask = (~(0x0e10021));
469  }
470  if (sid == DTF) {
471  if (cid != DTtftrk)
472  continue;
473  }
474  if (sid == RPC || sid == CTF || sid == RPC) {
475  //select mu regional cands only for dtf,ctf,rpc
476  //if(cid!=MUrtf) continue;
477  //masking: gres dttf only -- I.Mikulec: lowest 16 bits only
478  //if(sid==DTF) mask = 0xffff;
479  }
480 
481  errordist ->Fill(type);
482  errortype[sid]->Fill(type);
483 
484  // skip next if running in filter farm
485  if (runInFF_)
486  continue;
487 
488  //exclude agreeing cands
489  wei = 1.;
490  if (!type)
491  wei = 0.;
492  if (etav != nullVal && phiv != nullVal)
493  etaphi[sid]->Fill(etav, phiv, wei);
494  if (etav != nullVal)
495  eta[sid]->Fill(etav, wei);
496  if (phiv != nullVal)
497  phi[sid]->Fill(phiv, wei);
498  if (sid == DTP)
499  if (x3v != nullVal)
500  x3[sid]->Fill(x3v, wei);
501 
502  unsigned int word[2];
503  it->data(word);
504  std::bitset < 32 > dbits(word[0]);
505  std::bitset < 32 > ebits(word[1]);
506  unsigned int dexor = ((word[0]) ^ (word[1]));
507  //disagreeing bits
508  std::bitset < 32 > debits(dexor);
509  //disagreeing bits after masking
510  std::bitset < 32 > dembits(((dexor) & (mask)));
511 
512  if (verbose())
513  std::cout << "l1demon" << " sid:" << sid << " cid:" << cid << "\n"
514  << " data:0x" << std::hex << word[0] << std::dec
515  << " bitset:" << dbits << "\n" << " emul:0x" << std::hex
516  << word[1] << std::dec << " bitset:" << ebits << "\n"
517  << " xor:0x" << std::hex << dexor << std::dec
518  << " bitset:" << debits << " bitset:"
519  << ((dbits) ^ (ebits)) << "\n" << std::flush;
520 
522  for (int ibit = 0; ibit < 32; ibit++) {
523  wei = 1.;
524  //comparison gives no info if there's only 1 candidate
525  if (type == 3 || type == 4)
526  wei = 0.;
527  if (dbits[ibit])
528  dword[sid]->Fill(ibit, wei);
529  if (ebits[ibit])
530  eword[sid]->Fill(ibit, wei);
531  if (debits[ibit])
532  deword[sid]->Fill(ibit, wei);
533  //if(dembits[ibit])masked[sid]->Fill(ibit,wei);
534  }
535 
536  //exclude e-only cands (only data)
537  wei = 1.;
538  if (type == 4)
539  wei = 0.;
540  if (etav != nullVal)
541  etaData[sid]->Fill(etav, wei);
542  if (phiv != nullVal)
543  phiData[sid]->Fill(phiv, wei);
544  if (sid == DTP)
545  if (x3v != nullVal)
546  x3Data[sid]->Fill(x3v, wei);
547  rnkData[sid]->Fill(rnkv, wei);
548 
549  //correlations: store leading candidate
550  if (type == 4)
551  continue; //exclude e-only cands
552  bool islead = false;
553  if (rnkv > LeadCandVal[sid][2])
554  islead = true;
555  else if (rnkv == LeadCandVal[sid][2]) {
556  if (phiv > LeadCandVal[sid][0])
557  islead = true;
558  else if (phiv == LeadCandVal[sid][0])
559  if (etav > LeadCandVal[sid][1])
560  islead = true;
561  }
562 
563  if (islead) {
564  LeadCandVal[sid][0] = phiv;
565  LeadCandVal[sid][1] = etav;
566  LeadCandVal[sid][2] = rnkv;
567  }
568 
569  }//close loop over dedigi-cands
570 
571 }
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::string SystLabelExt[DEnsys]
Definition: DEtrait.h:50
const int DEnsys
Definition: DEtrait.h:38
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: L1TDEMON.cc:292
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
~L1TDEMON() override
Definition: L1TDEMON.cc:60
L1TDEMON(const edm::ParameterSet &)
Definition: L1TDEMON.cc:7
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const &) override
Definition: L1TDEMON.cc:63
std::vector< L1DataEmulDigi > L1DEDigiCollection
Definition: DEtrait.h:80
int iEvent
Definition: GenABIO.cc:230
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
static int verbose
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
std::pair< T, T > etaphi(T x, T y, T z)
Definition: FastMath.h:128
bool get_status() const
int getNCand(int i, int j) const
bool isValid() const
Definition: HandleBase.h:74
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
L1DEDigiCollection getColl() const
const std::string SystLabel[DEnsys]
Definition: DEtrait.h:45
double rate(double x)
Definition: Constants.cc:3
Definition: DEtrait.h:36
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
Definition: L1TDEMON.cc:285
bool get_isComp(int i) const
Definition: Run.h:44