26 #include <TDirectoryFile.h>
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 = {1, 3, 5, 7, 9, 11, 13, 15};
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());
282 const GEMChamber *ch = GEMGeometry_->chamber(gid);
290 hName =
"vfatStatus_QualityFlag_" + strIdxName;
291 hTitle =
"VFAT quality " + strIdxTitle;
293 listVFATQualityFlag_[gid] = ibooker.
book2D(hName, hTitle, nVFAT, 0, nVFAT, 9, 0, 9);
295 hName =
"vfatStatus_BC_" + strIdxName;
296 hTitle =
"VFAT bunch crossing " + strIdxTitle;
297 hTitle +=
";Bunch crossing;VFAT";
298 listVFATBC_[gid] = ibooker.
book2D(hName, hTitle, nNBxBin_, -nNBxRange_, nNBxRange_, nVFAT, 0, nVFAT);
300 hName =
"vfatStatus_EC_" + strIdxName;
301 hTitle =
"VFAT event counter " + strIdxTitle;
302 hTitle +=
";Event counter;VFAT";
303 listVFATEC_[gid] = ibooker.
book2D(hName, hTitle, 256, 0, 256, nVFAT, 0, nVFAT);
306 listVFATQualityFlag_[gid]->
setBinLabel(unBinPos++,
"Good", 2);
307 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"CRC fail", 2);
308 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"b1010 fail", 2);
309 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"b1100 fail", 2);
310 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"b1110 fail", 2);
311 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"Hamming error", 2);
312 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"AFULL", 2);
313 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"SEUlogic", 2);
314 listVFATQualityFlag_[gid]->setBinLabel(unBinPos++,
"SUEI2C", 2);
316 m_mapStatusFill[gid] =
false;
317 m_mapStatusErr[gid] =
false;
325 UInt_t la = lid.
layer();
338 strName = strName +
"_" + suffixLayer(lid);
339 strTitle = strTitle +
", station: " + (re >= 0 ?
"+" :
"-") + std::to_string(nStation);
341 if (bPerSuperchamber_) {
342 strTitle +=
", layer: " + std::to_string(nLayer);
345 strTitle +=
";Chamber;" + strAxis;
347 auto hNew = ibooker.
book2D(strName, strTitle, this->nNCh_, 0, this->nNCh_,
nBin, fMin, fMax);
349 for (Int_t
i = 0;
i < this->nNCh_;
i++) {
350 auto &gid = this->m_listChambers[
i];
351 Int_t nCh = gid.chamber() + (this->bPerSuperchamber_ ? 0 : gid.layer() - 1);
358 listGEBInputStatus_[lid] =
359 newbookGEB(ibooker,
"geb_input_status",
"inputStatus",
"", lid, la, st, re, eBit_, 0, eBit_);
360 listGEBInputID_[lid] = newbookGEB(ibooker,
"geb_input_ID",
"inputID",
"Input ID", lid, la, st, re, 32, 0, 32);
361 listGEBVFATWordCnt_[lid] =
362 newbookGEB(ibooker,
"geb_no_vfats",
"nvfats in header",
"Number of VFATs in header", lid, la, st, re, 25, 0, 25);
363 listGEBVFATWordCntT_[lid] = newbookGEB(
364 ibooker,
"geb_no_vfatsT",
"nvfats in trailer",
"Number of VFATs in trailer", lid, la, st, re, 25, 0, 25);
365 listGEBZeroSupWordsCnt_[lid] = newbookGEB(
366 ibooker,
"geb_zeroSupWordsCnt",
"zeroSupWordsCnt",
"Zero sup. words count", lid, la, st, re, 10, 0, 10);
370 newbookGEB(ibooker,
"geb_bcOH",
"OH bunch crossing",
"OH bunch crossing", lid, la, st, re, 3600, 0, 3600);
372 newbookGEB(ibooker,
"geb_ecOH",
"OH event coounter",
"OH event counter", lid, la, st, re, 256, 0, 256);
374 newbookGEB(ibooker,
"geb_OHCRC",
"CRC of OH data",
"CRC of OH data", lid, la, st, re, 65536, 0, 65536);
378 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Good", 2);
379 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"BX mismatch GLIB OH", 2);
380 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"BX mismatch GLIB VFAT", 2);
381 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"OOS GLIB OH", 2);
382 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"OOS GLIB VFAT", 2);
383 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"No VFAT marker", 2);
384 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Event size warn", 2);
385 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"L1AFIFO near full", 2);
386 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"InFIFO near full", 2);
387 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"EvtFIFO near full", 2);
388 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Event size overflow", 2);
389 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"L1AFIFO full", 2);
390 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"InFIFO full", 2);
391 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"EvtFIFO full", 2);
392 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Input FIFO underflow", 2);
393 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Stuck data", 2);
394 listGEBInputStatus_[lid]->setBinLabel(unBinPos++,
"Event FIFO underflow", 2);
398 h2AMCStatus_ = ibooker.
book2D(
"amc_statusflag",
399 "Status of AMC slots;AMC slot;",
400 listAMCSlots_.size(),
402 listAMCSlots_.size(),
407 uint32_t unBinPos = 1;
409 h2AMCStatus_->setBinLabel(unBinPos++,
"BC0 not locked", 2);
410 h2AMCStatus_->setBinLabel(unBinPos++,
"DAQ not ready", 2);
411 h2AMCStatus_->setBinLabel(unBinPos++,
"DAQ clock not locked", 2);
412 h2AMCStatus_->setBinLabel(unBinPos++,
"MMCM not locked", 2);
413 h2AMCStatus_->setBinLabel(unBinPos++,
"Back pressure", 2);
414 h2AMCStatus_->setBinLabel(unBinPos++,
"GLIB out-of-sync", 2);
421 size_t unPos, unPosEnd;
423 for (unPos = strRes.find(
'%'); unPos != std::string::npos; unPos = strRes.find(
'%', unPos + 1)) {
424 unPosEnd = strRes.find(
')', unPos);
425 if (strRes[unPos + 1] !=
'(' || unPosEnd == std::string::npos)
429 std::string strKey = strRes.substr(unPos + 2, unPosEnd - (unPos + 2));
436 for (;; unPosEnd++) {
437 if (!(
'0' <= strRes[unPosEnd] && strRes[unPosEnd] <=
'9') && strRes[unPosEnd] !=
'+')
439 strOptNum += strRes[unPosEnd];
442 if (strRes[unPosEnd] !=
'i' && strRes[unPosEnd] !=
'd')
444 strOptNum += strRes[unPosEnd];
447 sprintf(szOutFmt, strOptNum.c_str(), mapArg[strKey]);
448 strRes = strRes.substr(0, unPos) + szOutFmt + strRes.substr(unPosEnd);
451 if (unPos != std::string::npos) {
452 std::cerr <<
"ERROR: Syntax error on printfWithMap(); " << std::endl;
462 GEMGeometry_ = initGeometry(iSetup);
463 if (GEMGeometry_ ==
nullptr)
475 for (
const auto &ch : gemChambers_) {
477 bookHistogramsChamberPart(ibooker, gid);
480 for (
auto lid : m_listLayers) {
481 bookHistogramsStationPart(ibooker, lid);
484 bookHistogramsAMCPart(ibooker);
486 h1_vfat_qualityflag_ = ibooker.
book1D(
"vfat_quality_flag",
"quality and flag", 9, 0, 9);
487 h2_vfat_qualityflag_ = ibooker.
book2D(
"vfat_quality_flag_per_geb",
"quality and flag", nNCh_, 0, nNCh_, 9, 0, 9);
489 h1_amc_ttsState_ = ibooker.
book1D(
"amc_ttsState",
"ttsState", 10, 0, 10);
490 h1_amc_davCnt_ = ibooker.
book1D(
"amc_davCnt",
"davCnt", 10, 0, 10);
491 h1_amc_buffState_ = ibooker.
book1D(
"amc_buffState",
"buffState", 10, 0, 10);
492 h1_amc_oosGlib_ = ibooker.
book1D(
"amc_oosGlib",
"oosGlib", 10, 0, 10);
493 h1_amc_chTimeOut_ = ibooker.
book1D(
"amc_chTimeOut",
"chTimeOut", 10, 0, 10);
498 h3SummaryStatusPre_ = ibooker.
book3D(
499 "reportSummaryMapPreliminary",
";Chamber;", nNCh_, 0, nNCh_, m_listLayers.size(), 0, m_listLayers.size(), 2, 0, 1);
501 for (Int_t
i = 0;
i < nNCh_;
i++) {
502 auto &gid = this->m_listChambers[
i];
503 Int_t nCh = gid.chamber() + (bPerSuperchamber_ ? 0 : gid.layer() - 1);
504 h3SummaryStatusPre_->
setBinLabel(
i + 1, std::to_string(nCh), 1);
508 std::unordered_map<std::string, Int_t> mapArg;
512 for (
auto lid : m_listLayers) {
513 mapArg[
"station_signed"] = lid.region() * lid.station();
514 mapArg[
"region"] = lid.region();
515 mapArg[
"station"] = lid.station();
516 mapArg[
"layer"] = lid.layer();
517 mapArg[
"chamber"] = lid.chamber();
519 h3SummaryStatusPre_->setBinLabel(nIdxLayer + 1,
printfWithMap(strFmtSummaryLabel_, mapArg), 2);
531 for (;
i < nNumBits;
i++, unFlag <<= 1) {
532 if ((unVal & unFlag) != 0) {
547 for (;
i < nNumBits;
i++, unFlag <<= 1) {
548 if ((unVal & unFlag) != 0) {
561 for (Int_t nIdx = 0; nIdx < (Int_t)listLayers.size(); nIdx++)
562 if (
id == listLayers[nIdx])
568 Int_t nLayer = (bPerSuperchamber_ ? gid.
layer() : 0);
572 nIdxLayer = seekIdx(m_listLayers, layerId) + 1;
573 nIdxChamber = seekIdx(m_listChambers, chamberId) + 1;
577 Bool_t bIsNotEmpty =
true;
584 event.getByToken(tagVFAT_, gemVFAT);
585 event.getByToken(tagGEB_, gemGEB);
586 event.getByToken(tagAMC_, gemAMC);
587 event.getByToken(tagDigi_, gemDigis);
593 const GEMChamber *ch = GEMGeometry_->chamber(gemchId);
596 int nIdx = seekIdx(m_listChambers, gemOnlychId);
597 int nRoll = gemid.
roll();
600 for (
auto vfatStat =
range.first; vfatStat !=
range.second; ++vfatStat) {
603 uint64_t unQFVFAT = vfatStat->quality() ;
604 if ((unQFVFAT & ~0
x1) == 0) {
607 Int_t nIdxLayer, nIdxChamber;
608 seekIdxSummary(gemchId, nIdxLayer, nIdxChamber);
609 h3SummaryStatusPre_->setBinContent(nIdxChamber, nIdxLayer, m_nIdxSummaryErr, 1.0);
612 FillBits(h1_vfat_qualityflag_, unQFVFAT, qVFATBit_ + fVFATBit_);
613 FillBits(h2_vfat_qualityflag_, unQFVFAT, qVFATBit_ + fVFATBit_, nIdx);
615 int nVFAT = (maxEtaPs - nRoll) + maxEtaPs * vfatStat->phi();
616 bIsNotEmpty = FillBits(listVFATQualityFlag_[gemchId], unQFVFAT, qVFATBit_ + fVFATBit_, nVFAT);
619 edm::LogError(
"BadGeometry") <<
"Wrong detId which is not in the current geometry (VFAT status): " << gemchId
624 listVFATEC_[gemchId]->Fill(vfatStat->ec(), nVFAT);
633 Int_t nCh = seekIdx(m_listChambers, chid);
636 for (
auto GEBStatus =
range.first; GEBStatus !=
range.second; ++GEBStatus) {
642 unStatus |= (GEBStatus->bxmVvV() << unBit++);
643 unStatus |= (GEBStatus->bxmAvV() << unBit++);
644 unStatus |= (GEBStatus->oOScVvV() << unBit++);
645 unStatus |= (GEBStatus->oOScAvV() << unBit++);
646 unStatus |= (GEBStatus->noVFAT() << unBit++);
647 unStatus |= (GEBStatus->evtSzW() << unBit++);
648 unStatus |= (GEBStatus->l1aNF() << unBit++);
649 unStatus |= (GEBStatus->inNF() << unBit++);
650 unStatus |= (GEBStatus->evtNF() << unBit++);
651 unStatus |= (GEBStatus->evtSzOFW() << unBit++);
652 unStatus |= (GEBStatus->l1aF() << unBit++);
653 unStatus |= (GEBStatus->inF() << unBit++);
654 unStatus |= (GEBStatus->evtF() << unBit++);
655 unStatus |= (GEBStatus->inUfw() << unBit++);
656 unStatus |= (GEBStatus->stuckData() << unBit++);
657 unStatus |= (GEBStatus->evUfw() << unBit++);
660 Int_t nIdxLayer, nIdxChamber;
661 seekIdxSummary(gemid, nIdxLayer, nIdxChamber);
662 h3SummaryStatusPre_->setBinContent(nIdxChamber, nIdxLayer, m_nIdxSummaryErr, 1.0);
667 bIsNotEmpty = FillBits(listGEBInputStatus_[lid], unStatus, eBit_, nCh);
670 edm::LogError(
"BadGeometry") <<
"Wrong detId which is not in the current geometry (GEB status): " << lid
675 listGEBInputID_[lid]->Fill(nCh, GEBStatus->inputID());
676 listGEBVFATWordCnt_[lid]->Fill(nCh, GEBStatus->vfatWordCnt() / 3);
677 listGEBVFATWordCntT_[lid]->Fill(nCh, GEBStatus->vfatWordCntT() / 3);
678 listGEBZeroSupWordsCnt_[lid]->Fill(nCh, GEBStatus->zeroSupWordsCnt());
681 listGEBbcOH_[lid]->Fill(nCh, GEBStatus->bcOH());
682 listGEBecOH_[lid]->Fill(nCh, GEBStatus->ecOH());
683 listGEBOHCRC_[lid]->Fill(nCh, GEBStatus->crc());
688 auto findAMCIdx = [
this](Int_t nAMCnum) -> Int_t {
689 for (Int_t
i = 0;
i < (Int_t)listAMCSlots_.size();
i++)
690 if (listAMCSlots_[
i] == nAMCnum)
698 Int_t nIdAMC = findAMCIdx(
amc->amcNum());
702 unStatus |= (!
amc->bc0locked() << unBit++);
703 unStatus |= (!
amc->daqReady() << unBit++);
704 unStatus |= (!
amc->daqClockLocked() << unBit++);
705 unStatus |= (!
amc->mmcmLocked() << unBit++);
706 unStatus |= (
amc->backPressure() << unBit++);
707 unStatus |= (
amc->oosGlib() << unBit++);
713 FillBits(h2AMCStatus_, unStatus, amcStatusBit_, nIdAMC);
715 h1_amc_ttsState_->Fill(
amc->ttsState());
716 h1_amc_davCnt_->Fill(
amc->davCnt());
717 h1_amc_buffState_->Fill(
amc->buffState());
718 h1_amc_oosGlib_->Fill(
amc->oosGlib());
719 h1_amc_chTimeOut_->Fill(
amc->linkTo());
724 for (
const auto &ch : gemChambers_) {
726 Bool_t bIsHit =
false;
729 std::unordered_map<Int_t, Int_t> mapBXVFAT;
734 Int_t maxEtaPs = ch.nEtaPartitions();
739 for (
auto roll : ch.etaPartitions()) {
741 const auto &digis_in_det = gemDigis->get(rId);
743 for (
auto d = digis_in_det.first;
d != digis_in_det.second; ++
d) {
744 Int_t nIdxStrip =
d->strip() - nIdxFirstStrip_;
745 Int_t nVFAT = maxEtaPs * ((Int_t)(nIdxStrip / (roll->nstrips() / nNumVFAT)) + 1) - rId.
roll();
748 mapBXVFAT[nVFAT] =
d->bx();
752 for (
auto bx : mapBXVFAT)
753 listVFATBC_[cId]->Fill(
bx.second,
bx.first);
756 Int_t nIdxLayer, nIdxChamber;
757 seekIdxSummary(cId, nIdxLayer, nIdxChamber);
758 h3SummaryStatusPre_->setBinContent(nIdxChamber, nIdxLayer, m_nIdxSummaryFill, 1.0);