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 
261 // ------------ method called to for each event ------------
262 void L1TDEMON::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
263  if (!hasRecord_)
264  return;
265 
266  if (verbose())
267  std::cout << "L1TDEMON::analyze() start\n" << std::flush;
268 
269  nEvt_++;
270 
273  iEvent.getByToken(DEsourceToken_, deRecord);
274 
275  if (!deRecord.isValid()) {
276  edm::LogInfo("DataNotFound") << "Cannot find L1DataEmulRecord with label " << DEsource_.label()
277  << " Please verify that comparator was successfully executed."
278  << " Emulator DQM will be skipped!" << std::endl;
279  hasRecord_ = false;
280  return;
281  }
282 
283  bool deMatch[DEnsys];
284  deRecord->get_status(deMatch);
285  if (verbose()) {
286  std::cout << "[L1TDEMON] verbose sys match?: ";
287  for (int i = 0; i < DEnsys; i++)
288  std::cout << deMatch[i] << " ";
289  std::cout << std::endl;
290  }
291 
292  bool isComp[DEnsys];
293  for (int i = 0; i < DEnsys; i++)
294  isComp[i] = deRecord->get_isComp(i);
295  if (verbose()) {
296  std::cout << "[L1TDEMON] verbose dosys?: ";
297  for (int i = 0; i < DEnsys; i++)
298  std::cout << isComp[i];
299  std::cout << std::endl;
300  }
301 
302  int DEncand[DEnsys][2];
303  for (int i = 0; i < DEnsys; i++)
304  for (int j = 0; j < 2; j++)
305  DEncand[i][j] = deRecord->getNCand(i, j);
306 
307  if (verbose()) {
308  std::cout << "[L1TDEMON] ncands d: ";
309  for (int i = 0; i < DEnsys; i++)
310  std::cout << DEncand[i][0] << " ";
311  std::cout << "\n[L1TDEMON] ncands e: ";
312  for (int i = 0; i < DEnsys; i++)
313  std::cout << DEncand[i][1] << " ";
314  std::cout << std::endl;
315  }
316 
317  const int nullVal = L1DataEmulDigi().reset();
318 
320  L1DEDigiCollection deColl;
321  deColl = deRecord->getColl();
322 
323  // global counters
324  int hasSys[DEnsys] = {0};
325  for (L1DEDigiCollection::const_iterator it = deColl.begin(); it != deColl.end(); it++)
326  if (!it->empty())
327  hasSys[it->sid()]++;
328  for (int i = 0; i < DEnsys; i++) {
329  if (!hasSys[i])
330  continue;
331  nEvtWithSys[i]++;
332  if (deMatch[i])
333  deSysCount[i]++;
334  }
335 
336  if (verbose()) {
337  std::cout << "[L1TDEMON] digis: \n";
338  for (L1DEDigiCollection::const_iterator it = deColl.begin(); it != deColl.end(); it++)
339  std::cout << "\t" << *it << std::endl;
340  }
341 
343 
344  // global, sub-systems d|e match, ncands
345  for (int i = 0; i < DEnsys; i++) {
346  // skip if system disabled
347  if (!m_doSys[i]) {
348  continue;
349  }
350 
351  if (!isComp[i])
352  continue;
353 
354  for (int j = 0; j < 2; j++)
355  sysncand[j]->Fill(i, DEncand[i][j]);
356 
357  //sysrates->Fill(i,(int)!deMatch[i]);
358  int ibin = i + 1;
359  double rate = nEvtWithSys[i] ? (nEvtWithSys[i] - 1. * deSysCount[i]) / nEvtWithSys[i] : 0.;
360  sysrates->setBinContent(ibin, rate);
361 
362  if (verbose()) {
363  std::cout << "[L1TDEMON] analyze "
364  << " sysid:" << i << " nEvt:" << nEvt_ << " match?" << deMatch[i] << " ncands:" << hasSys[i]
365  << " nevtwsys:" << nEvtWithSys[i] << " nevtgood:" << deSysCount[i]
366  << " rate:" << sysrates->getBinContent(ibin) << "\n";
367 
368  if (rate > 1)
369  std::cout << "problem, error rate for " << SystLabel[i] << " is " << sysrates->getBinContent(ibin) << std::endl;
370  }
371  }
372 
373  // container for subsystem's leading candidate
374  const int ncorr = 3;
375  float LeadCandVal[DEnsys][ncorr] = {{(float)nullVal}};
376  for (int i = 0; i < DEnsys; i++)
377  for (int j = 0; j < ncorr; j++)
378  LeadCandVal[i][j] = nullVal;
379 
380  // d|e candidate loop
381  for (L1DEDigiCollection::const_iterator it = deColl.begin(); it != deColl.end(); it++) {
382  int sid = it->sid();
383  int cid = it->cid();
384 
385  if (it->empty())
386  continue;
387  assert(isComp[sid]);
388 
389  int type = it->type();
390  double phiv = it->x1();
391  double etav = it->x2();
392  double x3v = it->x3();
393 
394  float rankarr[2];
395  it->rank(rankarr);
396  float rnkv = rankarr[0];
397 
398  double wei = 1.;
399 
400  unsigned int mask = (~0x0);
401 
402  if (sid == RCT) {
403  //if(cid!=RCTem) continue;
404  //if(cid!=RCTrgn) continue;
405  }
406  // if(sid==GCT) {
407  // // For the moment just include EM and jet objects, energy sums being debugged in the expert DQM first.
408  // if(cid!=GCTisolaem &&
409  // cid!=GCTnoisoem &&
410  // cid!=GCTcenjets &&
411  // cid!=GCTforjets &&
412  // cid!=GCTtaujets) continue;
413  // }
414  if (sid == DTP) {
415  //tbd cols:th,ph; plots per wheel
416  //if(it->x3()!=0) continue;
417  }
418  if (sid == GMT) {
419  //select gmt cands only for GMT sys
420  if (cid != GMTcnd)
421  continue;
422  //masking: gres -- I.Mikulec: mask bits 0,5,16,21,22,23
423  //mask = (~(0x0e10021));
424  }
425  if (sid == DTF) {
426  if (cid != DTtftrk)
427  continue;
428  }
429  if (sid == RPC || sid == CTF || sid == RPC) {
430  //select mu regional cands only for dtf,ctf,rpc
431  //if(cid!=MUrtf) continue;
432  //masking: gres dttf only -- I.Mikulec: lowest 16 bits only
433  //if(sid==DTF) mask = 0xffff;
434  }
435 
436  errordist->Fill(type);
437  errortype[sid]->Fill(type);
438 
439  // skip next if running in filter farm
440  if (runInFF_)
441  continue;
442 
443  //exclude agreeing cands
444  wei = 1.;
445  if (!type)
446  wei = 0.;
447  if (etav != nullVal && phiv != nullVal)
448  etaphi[sid]->Fill(etav, phiv, wei);
449  if (etav != nullVal)
450  eta[sid]->Fill(etav, wei);
451  if (phiv != nullVal)
452  phi[sid]->Fill(phiv, wei);
453  if (sid == DTP)
454  if (x3v != nullVal)
455  x3[sid]->Fill(x3v, wei);
456 
457  unsigned int word[2];
458  it->data(word);
459  std::bitset<32> dbits(word[0]);
460  std::bitset<32> ebits(word[1]);
461  unsigned int dexor = ((word[0]) ^ (word[1]));
462  //disagreeing bits
463  std::bitset<32> debits(dexor);
464  //disagreeing bits after masking
465  std::bitset<32> dembits(((dexor) & (mask)));
466 
467  if (verbose())
468  std::cout << "l1demon"
469  << " sid:" << sid << " cid:" << cid << "\n"
470  << " data:0x" << std::hex << word[0] << std::dec << " bitset:" << dbits << "\n"
471  << " emul:0x" << std::hex << word[1] << std::dec << " bitset:" << ebits << "\n"
472  << " xor:0x" << std::hex << dexor << std::dec << " bitset:" << debits
473  << " bitset:" << ((dbits) ^ (ebits)) << "\n"
474  << std::flush;
475 
477  for (int ibit = 0; ibit < 32; ibit++) {
478  wei = 1.;
479  //comparison gives no info if there's only 1 candidate
480  if (type == 3 || type == 4)
481  wei = 0.;
482  if (dbits[ibit])
483  dword[sid]->Fill(ibit, wei);
484  if (ebits[ibit])
485  eword[sid]->Fill(ibit, wei);
486  if (debits[ibit])
487  deword[sid]->Fill(ibit, wei);
488  //if(dembits[ibit])masked[sid]->Fill(ibit,wei);
489  }
490 
491  //exclude e-only cands (only data)
492  wei = 1.;
493  if (type == 4)
494  wei = 0.;
495  if (etav != nullVal)
496  etaData[sid]->Fill(etav, wei);
497  if (phiv != nullVal)
498  phiData[sid]->Fill(phiv, wei);
499  if (sid == DTP)
500  if (x3v != nullVal)
501  x3Data[sid]->Fill(x3v, wei);
502  rnkData[sid]->Fill(rnkv, wei);
503 
504  //correlations: store leading candidate
505  if (type == 4)
506  continue; //exclude e-only cands
507  bool islead = false;
508  if (rnkv > LeadCandVal[sid][2])
509  islead = true;
510  else if (rnkv == LeadCandVal[sid][2]) {
511  if (phiv > LeadCandVal[sid][0])
512  islead = true;
513  else if (phiv == LeadCandVal[sid][0])
514  if (etav > LeadCandVal[sid][1])
515  islead = true;
516  }
517 
518  if (islead) {
519  LeadCandVal[sid][0] = phiv;
520  LeadCandVal[sid][1] = etav;
521  LeadCandVal[sid][2] = rnkv;
522  }
523 
524  } //close loop over dedigi-cands
525 }
std::pair< T, T > etaphi(T x, T y, T z)
Definition: FastMath.h:162
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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:262
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
bool verbose
~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
assert(be >=bs)
bool get_status() const
constexpr uint32_t mask
Definition: gpuClustering.h:26
T getUntrackedParameter(std::string const &, T const &) const
uint64_t word
int iEvent
Definition: GenABIO.cc:224
L1DEDigiCollection getColl() const
bool get_isComp(int i) const
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
int getNCand(int i, int j) const
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)
Log< level::Info, false > LogInfo
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
bool isValid() const
Definition: HandleBase.h:70
const std::string SystLabel[DEnsys]
Definition: DEtrait.h:42
double rate(double x)
Definition: Constants.cc:3
Definition: DEtrait.h:36
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Definition: Run.h:45