test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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_.size() != 0) {
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 
289 }
290 
291 
292 
293 // ------------ method called to for each event ------------
294 void L1TDEMON::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
295 
296  if (!hasRecord_)
297  return;
298 
299  if (verbose())
300  std::cout << "L1TDEMON::analyze() start\n" << std::flush;
301 
302  nEvt_++;
303 
306  iEvent.getByToken(DEsourceToken_, deRecord);
307 
308  if (!deRecord.isValid()) {
309  edm::LogInfo("DataNotFound")
310  << "Cannot find L1DataEmulRecord with label "
311  << DEsource_.label()
312  << " Please verify that comparator was successfully executed."
313  << " Emulator DQM will be skipped!" << std::endl;
314  hasRecord_ = false;
315  return;
316  }
317 
318  bool deMatch[DEnsys];
319  deRecord->get_status(deMatch);
320  if (verbose()) {
321  std::cout << "[L1TDEMON] verbose sys match?: ";
322  for (int i = 0; i < DEnsys; i++)
323  std::cout << deMatch[i] << " ";
324  std::cout << std::endl;
325  }
326 
327  bool isComp[DEnsys];
328  for (int i = 0; i < DEnsys; i++)
329  isComp[i] = deRecord->get_isComp(i);
330  if (verbose()) {
331  std::cout << "[L1TDEMON] verbose dosys?: ";
332  for (int i = 0; i < DEnsys; i++)
333  std::cout << isComp[i];
334  std::cout << std::endl;
335  }
336 
337  int DEncand[DEnsys][2];
338  for (int i = 0; i < DEnsys; i++)
339  for (int j = 0; j < 2; j++)
340  DEncand[i][j] = deRecord->getNCand(i, j);
341 
342  if (verbose()) {
343  std::cout << "[L1TDEMON] ncands d: ";
344  for (int i = 0; i < DEnsys; i++)
345  std::cout << DEncand[i][0] << " ";
346  std::cout << "\n[L1TDEMON] ncands e: ";
347  for (int i = 0; i < DEnsys; i++)
348  std::cout << DEncand[i][1] << " ";
349  std::cout << std::endl;
350  }
351 
352  const int nullVal = L1DataEmulDigi().reset();
353 
355  L1DEDigiCollection deColl;
356  deColl = deRecord->getColl();
357 
358  // global counters
359  int hasSys[DEnsys] = { 0 };
360  for (L1DEDigiCollection::const_iterator it = deColl.begin(); it
361  != deColl.end(); it++)
362  if (!it->empty())
363  hasSys[it->sid()]++;
364  for (int i = 0; i < DEnsys; i++) {
365  if (!hasSys[i])
366  continue;
367  nEvtWithSys[i]++;
368  if (deMatch[i])
369  deSysCount[i]++;
370  }
371 
372  if (verbose()) {
373  std::cout << "[L1TDEMON] digis: \n";
374  for (L1DEDigiCollection::const_iterator it = deColl.begin(); it
375  != deColl.end(); it++)
376  std::cout << "\t" << *it << std::endl;
377  }
378 
380 
381  // global, sub-systems d|e match, ncands
382  for (int i = 0; i < DEnsys; i++) {
383 
384  // skip if system disabled
385  if (!m_doSys[i]) {
386  continue;
387  }
388 
389  if (!isComp[i])
390  continue;
391 
392  for (int j = 0; j < 2; j++)
393  sysncand[j]->Fill(i, DEncand[i][j]);
394 
395  //sysrates->Fill(i,(int)!deMatch[i]);
396  int ibin = i + 1;
397  double rate = nEvtWithSys[i] ? (nEvtWithSys[i] - 1. * deSysCount[i])
398  / nEvtWithSys[i] : 0.;
399  sysrates->setBinContent(ibin, rate);
400 
401  if (verbose()) {
402  std::cout << "[L1TDEMON] analyze "
403  << " sysid:" << i
404  << " nEvt:" << nEvt_
405  << " match?" << deMatch[i]
406  << " ncands:" << hasSys[i]
407  << " nevtwsys:" << nEvtWithSys[i]
408  << " nevtgood:" << deSysCount[i]
409  << " rate:" << sysrates->getBinContent(ibin)
410  << "\n";
411 
412  if (rate > 1)
413  std::cout << "problem, error rate for " << SystLabel[i]
414  << " is " << sysrates->getBinContent(ibin) << std::endl;
415  }
416  }
417 
418  // container for subsystem's leading candidate
419  const int ncorr = 3;
420  float LeadCandVal[DEnsys][ncorr] = { { (float) nullVal } };
421  for (int i = 0; i < DEnsys; i++)
422  for (int j = 0; j < ncorr; j++)
423  LeadCandVal[i][j] = nullVal;
424 
425  // d|e candidate loop
426  for (L1DEDigiCollection::const_iterator it = deColl.begin(); it
427  != deColl.end(); it++) {
428 
429  int sid = it->sid();
430  int cid = it->cid();
431 
432  if (it->empty())
433  continue;
434  assert(isComp[sid]);
435 
436  int type = it->type();
437  double phiv = it->x1();
438  double etav = it->x2();
439  double x3v = it->x3();
440 
441  float rankarr[2];
442  it->rank(rankarr);
443  float rnkv = rankarr[0];
444 
445  double wei = 1.;
446 
447  unsigned int mask = (~0x0);
448 
449  if (sid == RCT) {
450  //if(cid!=RCTem) continue;
451  //if(cid!=RCTrgn) continue;
452  }
453  // if(sid==GCT) {
454  // // For the moment just include EM and jet objects, energy sums being debugged in the expert DQM first.
455  // if(cid!=GCTisolaem &&
456  // cid!=GCTnoisoem &&
457  // cid!=GCTcenjets &&
458  // cid!=GCTforjets &&
459  // cid!=GCTtaujets) continue;
460  // }
461  if (sid == DTP) {
462  //tbd cols:th,ph; plots per wheel
463  //if(it->x3()!=0) continue;
464  }
465  if (sid == GMT) {
466  //select gmt cands only for GMT sys
467  if (cid != GMTcnd)
468  continue;
469  //masking: gres -- I.Mikulec: mask bits 0,5,16,21,22,23
470  //mask = (~(0x0e10021));
471  }
472  if (sid == DTF) {
473  if (cid != DTtftrk)
474  continue;
475  }
476  if (sid == RPC || sid == CTF || sid == RPC) {
477  //select mu regional cands only for dtf,ctf,rpc
478  //if(cid!=MUrtf) continue;
479  //masking: gres dttf only -- I.Mikulec: lowest 16 bits only
480  //if(sid==DTF) mask = 0xffff;
481  }
482 
483  errordist ->Fill(type);
484  errortype[sid]->Fill(type);
485 
486  // skip next if running in filter farm
487  if (runInFF_)
488  continue;
489 
490  //exclude agreeing cands
491  wei = 1.;
492  if (!type)
493  wei = 0.;
494  if (etav != nullVal && phiv != nullVal)
495  etaphi[sid]->Fill(etav, phiv, wei);
496  if (etav != nullVal)
497  eta[sid]->Fill(etav, wei);
498  if (phiv != nullVal)
499  phi[sid]->Fill(phiv, wei);
500  if (sid == DTP)
501  if (x3v != nullVal)
502  x3[sid]->Fill(x3v, wei);
503 
504  unsigned int word[2];
505  it->data(word);
506  std::bitset < 32 > dbits(word[0]);
507  std::bitset < 32 > ebits(word[1]);
508  unsigned int dexor = ((word[0]) ^ (word[1]));
509  //disagreeing bits
510  std::bitset < 32 > debits(dexor);
511  //disagreeing bits after masking
512  std::bitset < 32 > dembits(((dexor) & (mask)));
513 
514  if (verbose())
515  std::cout << "l1demon" << " sid:" << sid << " cid:" << cid << "\n"
516  << " data:0x" << std::hex << word[0] << std::dec
517  << " bitset:" << dbits << "\n" << " emul:0x" << std::hex
518  << word[1] << std::dec << " bitset:" << ebits << "\n"
519  << " xor:0x" << std::hex << dexor << std::dec
520  << " bitset:" << debits << " bitset:"
521  << ((dbits) ^ (ebits)) << "\n" << std::flush;
522 
524  for (int ibit = 0; ibit < 32; ibit++) {
525  wei = 1.;
526  //comparison gives no info if there's only 1 candidate
527  if (type == 3 || type == 4)
528  wei = 0.;
529  if (dbits[ibit])
530  dword[sid]->Fill(ibit, wei);
531  if (ebits[ibit])
532  eword[sid]->Fill(ibit, wei);
533  if (debits[ibit])
534  deword[sid]->Fill(ibit, wei);
535  //if(dembits[ibit])masked[sid]->Fill(ibit,wei);
536  }
537 
538  //exclude e-only cands (only data)
539  wei = 1.;
540  if (type == 4)
541  wei = 0.;
542  if (etav != nullVal)
543  etaData[sid]->Fill(etav, wei);
544  if (phiv != nullVal)
545  phiData[sid]->Fill(phiv, wei);
546  if (sid == DTP)
547  if (x3v != nullVal)
548  x3Data[sid]->Fill(x3v, wei);
549  rnkData[sid]->Fill(rnkv, wei);
550 
551  //correlations: store leading candidate
552  if (type == 4)
553  continue; //exclude e-only cands
554  bool islead = false;
555  if (rnkv > LeadCandVal[sid][2])
556  islead = true;
557  else if (rnkv == LeadCandVal[sid][2]) {
558  if (phiv > LeadCandVal[sid][0])
559  islead = true;
560  else if (phiv == LeadCandVal[sid][0])
561  if (etav > LeadCandVal[sid][1])
562  islead = true;
563  }
564 
565  if (islead) {
566  LeadCandVal[sid][0] = phiv;
567  LeadCandVal[sid][1] = etav;
568  LeadCandVal[sid][2] = rnkv;
569  }
570 
571  }//close loop over dedigi-cands
572 
573 }
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
const std::string SystLabelExt[DEnsys]
Definition: DEtrait.h:50
const int DEnsys
Definition: DEtrait.h:38
bool verbose
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
L1TDEMON(const edm::ParameterSet &)
Definition: L1TDEMON.cc:7
assert(m_qm.get())
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)
virtual void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const &) override
Definition: L1TDEMON.cc:63
std::vector< L1DataEmulDigi > L1DEDigiCollection
Definition: DEtrait.h:80
virtual void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
Definition: L1TDEMON.cc:285
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
Definition: L1TDEMON.cc:288
int iEvent
Definition: GenABIO.cc:230
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
std::pair< T, T > etaphi(T x, T y, T z)
Definition: FastMath.h:128
int j
Definition: DBlmapReader.cc:9
bool isValid() const
Definition: HandleBase.h:75
~L1TDEMON()
Definition: L1TDEMON.cc:60
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
Geom::Phi< T > phi() const
const std::string SystLabel[DEnsys]
Definition: DEtrait.h:45
double rate(double x)
Definition: Constants.cc:3
tuple cout
Definition: gather_cfg.py:121
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: L1TDEMON.cc:294
Definition: Run.h:43