CMS 3D CMS Logo

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