26 #include <TDirectoryFile.h>
40 void bookHistogramsChamberPart(DQMStore::IBooker &,
GEMDetId &);
41 void bookHistogramsStationPart(DQMStore::IBooker &,
GEMDetId &);
42 void bookHistogramsAMCPart(DQMStore::IBooker &);
44 int SetInfoChambers();
46 Int_t seekIdx(std::vector<GEMDetId> &listLayers, UInt_t unId);
47 void seekIdxSummary(
GEMDetId gid, Int_t &nIdxLayer, Int_t &nIdxChamber);
74 int amcStatusBit_ = 7;
115 const Int_t m_nIdxSummaryFill = 1, m_nIdxSummaryErr = 2;
132 GEMGeometry_ = &*hGeom;
134 edm::LogError(
"MuonGEMBaseValidation") <<
"+++ Error : GEM geometry is unavailable on event loop. +++\n";
144 tagVFAT_ = consumes<GEMVfatStatusDigiCollection>(
cfg.getParameter<
edm::InputTag>(
"VFATInputLabel"));
145 tagGEB_ = consumes<GEMGEBdataCollection>(
cfg.getParameter<
edm::InputTag>(
"GEBInputLabel"));
146 tagAMC_ = consumes<GEMAMCdataCollection>(
cfg.getParameter<
edm::InputTag>(
"AMCInputLabel"));
147 tagDigi_ = consumes<GEMDigiCollection>(
cfg.getParameter<
edm::InputTag>(
"digisInputLabel"));
149 listAMCSlots_ =
cfg.getParameter<std::vector<int>>(
"AMCSlots");
151 strFmtSummaryLabel_ =
cfg.getParameter<
std::string>(
"summaryLabelFmt");
152 bFlipSummary_ =
cfg.getParameter<
bool>(
"flipSummary");
153 bPerSuperchamber_ =
cfg.getParameter<
bool>(
"perSuperchamber");
155 nIdxFirstStrip_ =
cfg.getParameter<
int>(
"idxFirstStrip");
157 nNBxRange_ =
cfg.getParameter<
int>(
"bxRange");
158 nNBxBin_ =
cfg.getParameter<
int>(
"bxBin");
160 bDebugMode_ =
cfg.getParameter<
bool>(
"debugMode");
170 std::vector<int> listAMCSlotsDef = {0, 1, 2, 3, 4, 5, 6, 7};
171 desc.
add<std::vector<int>>(
"AMCSlots", listAMCSlotsDef);
173 desc.
add<
std::string>(
"summaryLabelFmt",
"GE%(station_signed)+i/%(layer)i");
174 desc.
add<
bool>(
"flipSummary",
false);
175 desc.
add<
bool>(
"perSuperchamber",
true);
177 desc.
add<
int>(
"idxFirstStrip", 0);
179 desc.
add<
int>(
"bxRange", 10);
180 desc.
add<
int>(
"bxBin", 20);
182 desc.
add<
bool>(
"debugMode",
false);
184 descriptions.
add(
"GEMDQMStatusDigi", desc);
188 return "Gemini_" + to_string(
id.
chamber()) +
"_GE" + (
id.region() > 0 ?
"p" :
"m") + to_string(
id.
station()) +
"_" +
189 to_string(
id.layer());
193 return std::string(
"st_") + (
id.region() >= 0 ?
"p" :
"m") + std::to_string(
id.
station()) +
194 (bPerSuperchamber_ ?
"_la_" + std::to_string(
id.layer()) :
"");
198 const std::vector<const GEMSuperChamber *> &superChambers_ = GEMGeometry_->superChambers();
199 for (
auto sch : superChambers_) {
200 int nLayer = sch->nChambers();
201 for (
int l = 0;
l < nLayer;
l++) {
202 Bool_t bExist =
false;
203 for (
const auto &ch : gemChambers_)
204 if (ch.id() == sch->chamber(
l + 1)->id())
209 gemChambers_.push_back(*sch->chamber(
l + 1));
217 m_listLayers.clear();
220 for (
const auto &ch : gemChambers_) {
226 for (
auto lid : m_listLayers) {
227 if (lid == layerID) {
234 m_listLayers.push_back(layerID);
239 for (
auto cid : m_listChambers) {
252 Int_t nFlipSign = (this->bFlipSummary_ ? -1 : 1);
253 Int_t nA = nFlipSign *
a.region() * (20 *
a.station() +
a.layer());
254 Int_t nB = nFlipSign *
b.region() * (20 *
b.station() +
b.layer());
259 Int_t nA = 20 *
a.chamber() +
a.layer();
260 Int_t nB = 20 *
b.chamber() +
b.layer();
265 std::sort(m_listLayers.begin(), m_listLayers.end(), lambdaLayer);
266 std::sort(m_listChambers.begin(), m_listChambers.end(), lambdaChamber);
268 nNCh_ = (
int)m_listChambers.size();
280 to_string(gid.
station()) +
"/" + to_string(gid.
layer());
288 hName =
"vfatStatus_QualityFlag_" + strIdxName;
289 hTitle =
"VFAT quality " + strIdxTitle;
291 listVFATQualityFlag_[gid] = ibooker.book2D(hName, hTitle, nVFAT, 0, nVFAT, 9, 0, 9);
293 hName =
"vfatStatus_BC_" + strIdxName;
294 hTitle =
"VFAT bunch crossing " + strIdxTitle;
295 hTitle +=
";Bunch crossing;VFAT";
296 listVFATBC_[gid] = ibooker.book2D(hName, hTitle, nNBxBin_, -nNBxRange_, nNBxRange_, nVFAT, 0, nVFAT);
298 hName =
"vfatStatus_EC_" + strIdxName;
299 hTitle =
"VFAT event counter " + strIdxTitle;
300 hTitle +=
";Event counter;VFAT";
301 listVFATEC_[gid] = ibooker.book2D(hName, hTitle, 256, 0, 256, nVFAT, 0, nVFAT);
304 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"Good", 2);
305 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"CRC fail", 2);
306 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"b1010 fail", 2);
307 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"b1100 fail", 2);
308 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"b1110 fail", 2);
309 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"Hamming error", 2);
310 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"AFULL", 2);
311 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"SEUlogic", 2);
312 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"SUEI2C", 2);
314 m_mapStatusFill[gid] =
false;
315 m_mapStatusErr[gid] =
false;
323 UInt_t la = lid.
layer();
325 auto newbookGEB = [
this](DQMStore::IBooker &ibooker,
336 strName = strName +
"_" + suffixLayer(lid);
337 strTitle = strTitle +
", station: " + (re >= 0 ?
"+" :
"-") + std::to_string(nStation);
339 if (bPerSuperchamber_) {
340 strTitle +=
", layer: " + std::to_string(nLayer);
343 strTitle +=
";Chamber;" + strAxis;
345 auto hNew = ibooker.book2D(strName, strTitle, this->nNCh_, 0, this->nNCh_,
nBin, fMin, fMax);
347 for (Int_t
i = 0;
i < this->nNCh_;
i++) {
348 auto &gid = this->m_listChambers[
i];
349 Int_t nCh = gid.chamber() + (this->bPerSuperchamber_ ? 0 : gid.layer() - 1);
350 hNew->setBinLabel(
i + 1, std::to_string(nCh), 1);
356 listGEBInputStatus_[lid] =
357 newbookGEB(ibooker,
"geb_input_status",
"inputStatus",
"", lid, la, st, re, eBit_, 0, eBit_);
358 listGEBInputID_[lid] = newbookGEB(ibooker,
"geb_input_ID",
"inputID",
"Input ID", lid, la, st, re, 32, 0, 32);
359 listGEBVFATWordCnt_[lid] =
360 newbookGEB(ibooker,
"geb_no_vfats",
"nvfats in header",
"Number of VFATs in header", lid, la, st, re, 25, 0, 25);
361 listGEBVFATWordCntT_[lid] = newbookGEB(
362 ibooker,
"geb_no_vfatsT",
"nvfats in trailer",
"Number of VFATs in trailer", lid, la, st, re, 25, 0, 25);
363 listGEBZeroSupWordsCnt_[lid] = newbookGEB(
364 ibooker,
"geb_zeroSupWordsCnt",
"zeroSupWordsCnt",
"Zero sup. words count", lid, la, st, re, 10, 0, 10);
368 newbookGEB(ibooker,
"geb_bcOH",
"OH bunch crossing",
"OH bunch crossing", lid, la, st, re, 3600, 0, 3600);
370 newbookGEB(ibooker,
"geb_ecOH",
"OH event coounter",
"OH event counter", lid, la, st, re, 256, 0, 256);
372 newbookGEB(ibooker,
"geb_OHCRC",
"CRC of OH data",
"CRC of OH data", lid, la, st, re, 65536, 0, 65536);
376 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Good", 2);
377 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"BX mismatch GLIB OH", 2);
378 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"BX mismatch GLIB VFAT", 2);
379 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"OOS GLIB OH", 2);
380 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"OOS GLIB VFAT", 2);
381 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"No VFAT marker", 2);
382 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Event size warn", 2);
383 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"L1AFIFO near full", 2);
384 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"InFIFO near full", 2);
385 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"EvtFIFO near full", 2);
386 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Event size overflow", 2);
387 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"L1AFIFO full", 2);
388 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"InFIFO full", 2);
389 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"EvtFIFO full", 2);
390 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Input FIFO underflow", 2);
391 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Stuck data", 2);
392 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Event FIFO underflow", 2);
396 h2AMCStatus_ = ibooker.book2D(
"amc_statusflag",
397 "Status of AMC slots;AMC slot;",
398 listAMCSlots_.size(),
400 listAMCSlots_.size(),
405 uint32_t unBinPos = 1;
406 h2AMCStatus_->setBinLabel(unBinPos++,
"Good", 2);
407 h2AMCStatus_->setBinLabel(unBinPos++,
"BC0 not locked", 2);
408 h2AMCStatus_->setBinLabel(unBinPos++,
"DAQ not ready", 2);
409 h2AMCStatus_->setBinLabel(unBinPos++,
"DAQ clock not locked", 2);
410 h2AMCStatus_->setBinLabel(unBinPos++,
"MMCM not locked", 2);
411 h2AMCStatus_->setBinLabel(unBinPos++,
"Back pressure", 2);
412 h2AMCStatus_->setBinLabel(unBinPos++,
"GLIB out-of-sync", 2);
419 size_t unPos, unPosEnd;
421 for (unPos = strRes.find(
'%'); unPos != std::string::npos; unPos = strRes.find(
'%', unPos + 1)) {
422 unPosEnd = strRes.find(
')', unPos);
423 if (strRes[unPos + 1] !=
'(' || unPosEnd == std::string::npos)
427 std::string strKey = strRes.substr(unPos + 2, unPosEnd - (unPos + 2));
434 for (;; unPosEnd++) {
435 if (!(
'0' <= strRes[unPosEnd] && strRes[unPosEnd] <=
'9') && strRes[unPosEnd] !=
'+')
437 strOptNum += strRes[unPosEnd];
440 if (strRes[unPosEnd] !=
'i' && strRes[unPosEnd] !=
'd')
442 strOptNum += strRes[unPosEnd];
445 sprintf(szOutFmt, strOptNum.c_str(), mapArg[strKey]);
446 strRes = strRes.substr(0, unPos) + szOutFmt + strRes.substr(unPosEnd);
449 if (unPos != std::string::npos) {
450 std::cerr <<
"ERROR: Syntax error on printfWithMap(); " << std::endl;
460 GEMGeometry_ = initGeometry(iSetup);
461 if (GEMGeometry_ ==
nullptr)
471 ibooker.setCurrentFolder(
"GEM/StatusDigi");
473 for (
const auto &ch : gemChambers_) {
475 bookHistogramsChamberPart(ibooker, gid);
478 for (
auto lid : m_listLayers) {
479 bookHistogramsStationPart(ibooker, lid);
482 bookHistogramsAMCPart(ibooker);
484 h1_vfat_qualityflag_ = ibooker.book1D(
"vfat_quality_flag",
"quality and flag", 9, 0, 9);
485 h2_vfat_qualityflag_ = ibooker.book2D(
"vfat_quality_flag_per_geb",
"quality and flag", nNCh_, 0, nNCh_, 9, 0, 9);
487 h1_amc_ttsState_ = ibooker.book1D(
"amc_ttsState",
"ttsState", 10, 0, 10);
488 h1_amc_davCnt_ = ibooker.book1D(
"amc_davCnt",
"davCnt", 10, 0, 10);
489 h1_amc_buffState_ = ibooker.book1D(
"amc_buffState",
"buffState", 10, 0, 10);
490 h1_amc_oosGlib_ = ibooker.book1D(
"amc_oosGlib",
"oosGlib", 10, 0, 10);
491 h1_amc_chTimeOut_ = ibooker.book1D(
"amc_chTimeOut",
"chTimeOut", 10, 0, 10);
494 ibooker.setCurrentFolder(
"GEM/EventInfo");
496 h3SummaryStatusPre_ = ibooker.book3D(
497 "reportSummaryMapPreliminary",
";Chamber;", nNCh_, 0, nNCh_, m_listLayers.size(), 0, m_listLayers.size(), 2, 0, 1);
499 for (Int_t
i = 0;
i < nNCh_;
i++) {
500 auto &gid = this->m_listChambers[
i];
501 Int_t nCh = gid.chamber() + (bPerSuperchamber_ ? 0 : gid.layer() - 1);
502 h3SummaryStatusPre_->setBinLabel(
i + 1, std::to_string(nCh), 1);
506 std::unordered_map<std::string, Int_t> mapArg;
510 for (
auto lid : m_listLayers) {
511 mapArg[
"station_signed"] = lid.region() * lid.station();
512 mapArg[
"region"] = lid.region();
513 mapArg[
"station"] = lid.station();
514 mapArg[
"layer"] = lid.layer();
515 mapArg[
"chamber"] = lid.chamber();
517 h3SummaryStatusPre_->setBinLabel(nIdxLayer + 1,
printfWithMap(strFmtSummaryLabel_, mapArg), 2);
529 for (;
i < nNumBits;
i++, unFlag <<= 1) {
530 if ((unVal & unFlag) != 0) {
545 for (;
i < nNumBits;
i++, unFlag <<= 1) {
546 if ((unVal & unFlag) != 0) {
559 for (Int_t nIdx = 0; nIdx < (Int_t)listLayers.size(); nIdx++)
560 if (
id == listLayers[nIdx])
566 Int_t nLayer = (bPerSuperchamber_ ? gid.
layer() : 0);
570 nIdxLayer = seekIdx(m_listLayers, layerId) + 1;
571 nIdxChamber = seekIdx(m_listChambers, chamberId) + 1;
575 Bool_t bIsNotEmpty =
true;
582 event.getByToken(tagVFAT_, gemVFAT);
583 event.getByToken(tagGEB_, gemGEB);
584 event.getByToken(tagAMC_, gemAMC);
585 event.getByToken(tagDigi_, gemDigis);
592 int nIdx = seekIdx(m_listChambers, gemOnlychId);
593 int nRoll = gemid.
roll();
596 for (
auto vfatStat =
range.first; vfatStat !=
range.second; ++vfatStat) {
599 uint64_t unQFVFAT = vfatStat->quality() ;
600 if ((unQFVFAT & ~0
x1) == 0) {
603 Int_t nIdxLayer, nIdxChamber;
604 seekIdxSummary(gemchId, nIdxLayer, nIdxChamber);
605 h3SummaryStatusPre_->setBinContent(nIdxChamber, nIdxLayer, m_nIdxSummaryErr, 1.0);
608 FillBits(h1_vfat_qualityflag_, unQFVFAT, qVFATBit_ + fVFATBit_);
609 FillBits(h2_vfat_qualityflag_, unQFVFAT, qVFATBit_ + fVFATBit_, nIdx);
612 bIsNotEmpty = FillBits(listVFATQualityFlag_[gemchId], unQFVFAT, qVFATBit_ + fVFATBit_, nVFAT);
615 edm::LogError(
"BadGeometry") <<
"Wrong detId which is not in the current geometry (VFAT status): " << gemchId
620 listVFATEC_[gemchId]->Fill(vfatStat->ec(), nVFAT);
629 Int_t nCh = seekIdx(m_listChambers, chid);
632 for (
auto GEBStatus =
range.first; GEBStatus !=
range.second; ++GEBStatus) {
638 unStatus |= (GEBStatus->bxmVvV() << unBit++);
639 unStatus |= (GEBStatus->bxmAvV() << unBit++);
640 unStatus |= (GEBStatus->oOScVvV() << unBit++);
641 unStatus |= (GEBStatus->oOScAvV() << unBit++);
642 unStatus |= (GEBStatus->noVFAT() << unBit++);
643 unStatus |= (GEBStatus->evtSzW() << unBit++);
644 unStatus |= (GEBStatus->l1aNF() << unBit++);
645 unStatus |= (GEBStatus->inNF() << unBit++);
646 unStatus |= (GEBStatus->evtNF() << unBit++);
647 unStatus |= (GEBStatus->evtSzOFW() << unBit++);
648 unStatus |= (GEBStatus->l1aF() << unBit++);
649 unStatus |= (GEBStatus->inF() << unBit++);
650 unStatus |= (GEBStatus->evtF() << unBit++);
651 unStatus |= (GEBStatus->inUfw() << unBit++);
652 unStatus |= (GEBStatus->stuckData() << unBit++);
653 unStatus |= (GEBStatus->evUfw() << unBit++);
656 Int_t nIdxLayer, nIdxChamber;
657 seekIdxSummary(gemid, nIdxLayer, nIdxChamber);
658 h3SummaryStatusPre_->setBinContent(nIdxChamber, nIdxLayer, m_nIdxSummaryErr, 1.0);
663 bIsNotEmpty = FillBits(listGEBInputStatus_[lid], unStatus, eBit_, nCh);
666 edm::LogError(
"BadGeometry") <<
"Wrong detId which is not in the current geometry (GEB status): " << lid
671 listGEBInputID_[lid]->Fill(nCh, GEBStatus->inputID());
672 listGEBVFATWordCnt_[lid]->Fill(nCh, GEBStatus->vfatWordCnt() / 3);
673 listGEBVFATWordCntT_[lid]->Fill(nCh, GEBStatus->vfatWordCntT() / 3);
674 listGEBZeroSupWordsCnt_[lid]->Fill(nCh, GEBStatus->zeroSupWordsCnt());
677 listGEBbcOH_[lid]->Fill(nCh, GEBStatus->bcOH());
678 listGEBecOH_[lid]->Fill(nCh, GEBStatus->ecOH());
679 listGEBOHCRC_[lid]->Fill(nCh, GEBStatus->crc());
684 auto findAMCIdx = [
this](Int_t nAMCnum) -> Int_t {
685 for (Int_t
i = 0;
i < (Int_t)listAMCSlots_.size();
i++)
686 if (listAMCSlots_[
i] == nAMCnum)
694 Int_t nIdAMC = findAMCIdx(
amc->amcNum());
698 unStatus |= (!
amc->bc0locked() << unBit++);
699 unStatus |= (!
amc->daqReady() << unBit++);
700 unStatus |= (!
amc->daqClockLocked() << unBit++);
701 unStatus |= (!
amc->mmcmLocked() << unBit++);
702 unStatus |= (
amc->backPressure() << unBit++);
703 unStatus |= (
amc->oosGlib() << unBit++);
709 FillBits(h2AMCStatus_, unStatus, amcStatusBit_, nIdAMC);
711 h1_amc_ttsState_->Fill(
amc->ttsState());
712 h1_amc_davCnt_->Fill(
amc->davCnt());
713 h1_amc_buffState_->Fill(
amc->buffState());
714 h1_amc_oosGlib_->Fill(
amc->oosGlib());
715 h1_amc_chTimeOut_->Fill(
amc->linkTo());
719 auto findVFATByStrip = [](
GEMDetId gid, Int_t nIdxStrip, Int_t nNumStrips) -> Int_t {
725 return nNumEtaPart * ((Int_t)(nIdxStrip / (nNumStrips / nNumVFAT)) + 1) - gid.
roll();
726 }
else if (gid.
station() == 2) {
728 return nNumEtaPart * ((Int_t)(nIdxStrip / (nNumStrips / nNumVFAT)) + 1) - gid.
roll();
735 for (
const auto &ch : gemChambers_) {
737 Bool_t bIsHit =
false;
740 std::unordered_map<Int_t, Int_t> mapBXVFAT;
745 for (
auto roll : ch.etaPartitions()) {
747 const auto &digis_in_det = gemDigis->get(rId);
749 for (
auto d = digis_in_det.first;
d != digis_in_det.second; ++
d) {
750 Int_t nIdxStrip =
d->strip() - nIdxFirstStrip_;
751 Int_t nVFAT = findVFATByStrip(rId, nIdxStrip, roll->nstrips());
754 mapBXVFAT[nVFAT] =
d->bx();
758 for (
auto bx : mapBXVFAT)
759 listVFATBC_[cId]->Fill(
bx.second,
bx.first);
762 Int_t nIdxLayer, nIdxChamber;
763 seekIdxSummary(cId, nIdxLayer, nIdxChamber);
764 h3SummaryStatusPre_->setBinContent(nIdxChamber, nIdxLayer, m_nIdxSummaryFill, 1.0);