File indexing completed on 2021-02-14 13:10:39
0001
0002
0003
0004
0005
0006
0007 #include "DQM/L1TMonitor/interface/L1TdeStage2uGT.h"
0008
0009 L1TdeStage2uGT::L1TdeStage2uGT(const edm::ParameterSet& ps)
0010 : dataLabel_(ps.getParameter<edm::InputTag>("dataSource")),
0011 dataSource_(consumes<GlobalAlgBlkBxCollection>(dataLabel_)),
0012 emulLabel_(ps.getParameter<edm::InputTag>("emulSource")),
0013 emulSource_(consumes<GlobalAlgBlkBxCollection>(emulLabel_)),
0014 triggerBlackList_(ps.getParameter<std::vector<std::string> >("triggerBlackList")),
0015 numBx_(ps.getParameter<int>("numBxToMonitor")),
0016 histFolder_(ps.getParameter<std::string>("histFolder")),
0017 gtUtil_(ps,
0018 consumesCollector(),
0019 *this,
0020 ps.getParameter<edm::InputTag>("dataSource"),
0021 ps.getParameter<edm::InputTag>("dataSource"),
0022 l1t::UseEventSetupIn::RunAndEvent),
0023 numLS_(2000),
0024 m_currentLumi(0),
0025 m_currentRun(0) {
0026 if (numBx_ > 5)
0027 numBx_ = 5;
0028 if ((numBx_ > 0) && ((numBx_ % 2) == 0)) {
0029 numBx_ = numBx_ - 1;
0030
0031 edm::LogWarning("L1TdeStage2uGT") << "\nWARNING: Number of bunch crossing to be emulated rounded to: " << numBx_
0032 << "\n The number must be an odd number!\n"
0033 << std::endl;
0034 }
0035 firstBx = (numBx_ + 1) / 2 - numBx_;
0036 lastBx = (numBx_ + 1) / 2 - 1;
0037
0038 edm::LogInfo("L1TdeStage2uGT") << "Number of bunches crossings monitored: " << numBx_ << "\t"
0039 << "Min BX= " << firstBx << "\t"
0040 << "Max BX= " << lastBx << std::endl;
0041 }
0042
0043 L1TdeStage2uGT::~L1TdeStage2uGT() {}
0044
0045 void L1TdeStage2uGT::analyze(const edm::Event& event, const edm::EventSetup& es) {
0046 edm::Handle<GlobalAlgBlkBxCollection> dataCollection;
0047 event.getByToken(dataSource_, dataCollection);
0048 edm::Handle<GlobalAlgBlkBxCollection> emulCollection;
0049 event.getByToken(emulSource_, emulCollection);
0050
0051 if (!dataCollection.isValid()) {
0052 edm::LogError("L1TdeStage2uGT") << "Cannot find unpacked uGT readout record.";
0053 return;
0054 }
0055 if (!emulCollection.isValid()) {
0056 edm::LogError("L1TdeStage2uGT") << "Cannot find emulated uGT readout record.";
0057 return;
0058 }
0059
0060
0061 if (m_currentLumi != event.luminosityBlock() || m_currentRun != event.run()) {
0062 m_currentLumi = event.luminosityBlock();
0063 m_currentRun = event.run();
0064 gtUtil_.retrieveL1(event, es, dataSource_);
0065 }
0066
0067
0068 int lumi = event.luminosityBlock();
0069 if (lumi > numLS_)
0070 lumi = numLS_;
0071
0072
0073
0074
0075 if (emulCollection->getFirstBX() > firstBx)
0076 firstBx = emulCollection->getFirstBX();
0077 if (emulCollection->getLastBX() < lastBx)
0078 lastBx = emulCollection->getLastBX();
0079
0080 if (dataCollection->getFirstBX() > firstBx)
0081 firstBx = dataCollection->getFirstBX();
0082 if (dataCollection->getLastBX() < lastBx)
0083 lastBx = dataCollection->getLastBX();
0084
0085 m_normalizationHisto->Fill(float(NInitalMismatchDataNoEmul));
0086 m_normalizationHisto->Fill(float(NInitalMismatchEmulNoData));
0087 m_normalizationHisto->Fill(float(NFinalMismatchDataNoEmul));
0088 m_normalizationHisto->Fill(float(NFinalMismatchEmulNoData));
0089
0090 for (int ibx = firstBx; ibx <= lastBx; ++ibx) {
0091 ostringstream bxt;
0092 if (ibx == 0) {
0093 bxt << "CentralBX";
0094 } else {
0095 bxt << "BX" << ibx;
0096 }
0097 std::string hname, hsummary;
0098 float wt;
0099
0100 hsummary = "dataEmulSummary_" + bxt.str();
0101
0102 std::vector<GlobalAlgBlk>::const_iterator it_data, it_emul;
0103 for (it_data = dataCollection->begin(ibx), it_emul = emulCollection->begin(ibx);
0104 it_data != dataCollection->end(ibx) && it_emul != emulCollection->end(ibx);
0105 ++it_data, ++it_emul) {
0106
0107 int numAlgs = it_data->getAlgoDecisionInitial().size();
0108 for (int algoBit = 0; algoBit < numAlgs; ++algoBit) {
0109 string algoName = "xxx";
0110 bool found = gtUtil_.getAlgNameFromBit(algoBit, algoName);
0111 if (not found)
0112 continue;
0113
0114
0115 bool isBlackListed(false);
0116 for (auto const& pattern : triggerBlackList_) {
0117
0118 if (edm::is_glob(pattern)) {
0119 std::regex regexp(edm::glob2reg(pattern));
0120 if (regex_match(algoName.c_str(), regexp))
0121 isBlackListed = true;
0122 } else {
0123 if (algoName == pattern)
0124 isBlackListed = true;
0125 }
0126 }
0127 if (ibx != 0 && isBlackListed)
0128 continue;
0129
0130
0131 if (it_data->getAlgoDecisionInitial(algoBit) != it_emul->getAlgoDecisionInitial(algoBit)) {
0132 if (it_data->getAlgoDecisionInitial(algoBit)) {
0133 hname = "DataNoEmul_" + bxt.str();
0134 fillHist(m_SummaryHistograms, hsummary, float(NInitalMismatchDataNoEmul), 1.);
0135 wt = 1;
0136 } else {
0137 hname = "EmulatorNoData_" + bxt.str();
0138 fillHist(m_SummaryHistograms, hsummary, float(NInitalMismatchEmulNoData), 1.);
0139 wt = -1;
0140 }
0141 fillHist(m_HistNamesInitial, hname, float(algoBit), 1.);
0142 initDecisionMismatches_vs_LS->Fill(float(lumi), wt);
0143 }
0144
0145
0146 if (it_data->getAlgoDecisionFinal(algoBit) != it_emul->getAlgoDecisionFinal(algoBit)) {
0147 bool unprescaled = true;
0148
0149 double prescale = -999;
0150 bool dummy = gtUtil_.getPrescaleByBit(algoBit, prescale);
0151 if (not dummy)
0152 edm::LogWarning("L1TdeStage2uGT") << "Could not find prescale value for algobit: " << algoBit << std::endl;
0153
0154 if (prescale != 1)
0155 unprescaled = false;
0156
0157 if (unprescaled) {
0158 if (it_data->getAlgoDecisionFinal(algoBit)) {
0159 hname = "DataNoEmul_" + bxt.str();
0160 fillHist(m_SummaryHistograms, hsummary, float(NFinalMismatchDataNoEmul), 1.);
0161 wt = 1;
0162 } else {
0163 hname = "EmulatorNoData_" + bxt.str();
0164 fillHist(m_SummaryHistograms, hsummary, float(NFinalMismatchEmulNoData), 1.);
0165 wt = -1;
0166 }
0167 fillHist(m_HistNamesFinal, hname, float(algoBit), 1.);
0168 finalDecisionMismatches_vs_LS->Fill(float(lumi), wt);
0169 }
0170 }
0171
0172 }
0173 }
0174 }
0175 }
0176
0177 void L1TdeStage2uGT::bookHistograms(DQMStore::IBooker& ibooker, const edm::Run& run, const edm::EventSetup& es) {
0178 gtUtil_.retrieveL1Setup(es);
0179
0180 auto const& prescales = gtUtil_.prescales();
0181 int nbins = prescales.size();
0182 double xmin = -0.5;
0183 double xmax = nbins - 0.5;
0184
0185 string hname, htitle;
0186
0187 int ibx = (numBx_ + 1) / 2 - numBx_;
0188 for (int i = 0; i < numBx_; i++) {
0189 ostringstream bxn, bxt;
0190
0191 if (ibx == 0) {
0192 bxt << "CentralBX";
0193 bxn << " Central BX ";
0194 } else {
0195 bxt << "BX" << ibx;
0196 bxn << " BX " << ibx;
0197 }
0198 ibx++;
0199
0200 ibooker.setCurrentFolder(histFolder_);
0201 hname = "dataEmulSummary_" + bxt.str();
0202 htitle = "uGT Data/Emulator Mismatches --" + bxn.str();
0203 m_SummaryHistograms[hname] = ibooker.book1D(hname, htitle, NSummaryColumns, 0., double(NSummaryColumns));
0204 m_SummaryHistograms[hname]->setAxisTitle("Events", 2);
0205 m_SummaryHistograms[hname]->setBinLabel(1 + NInitalMismatchDataNoEmul, "Data, NoEmul -- Initial Decisions");
0206 m_SummaryHistograms[hname]->setBinLabel(1 + NInitalMismatchEmulNoData, "Emulator, No Data -- Initial Decisions");
0207 m_SummaryHistograms[hname]->setBinLabel(1 + NFinalMismatchDataNoEmul, "Data, NoEmul -- Final Decisions");
0208 m_SummaryHistograms[hname]->setBinLabel(1 + NFinalMismatchEmulNoData, "Emulator, No Data -- Final Decisions");
0209
0210 if (i == 0) {
0211 hname = "normalizationHisto";
0212 htitle = "Normalization histogram for uGT Data/Emulator Mismatches ratios";
0213 m_normalizationHisto = ibooker.book1D(hname, htitle, NSummaryColumns, 0., double(NSummaryColumns));
0214 m_normalizationHisto->setAxisTitle("Events", 2);
0215 m_normalizationHisto->setBinLabel(1 + NInitalMismatchDataNoEmul, "Data, NoEmul -- Initial Decisions");
0216 m_normalizationHisto->setBinLabel(1 + NInitalMismatchEmulNoData, "Emulator, No Data -- Initial Decisions");
0217 m_normalizationHisto->setBinLabel(1 + NFinalMismatchDataNoEmul, "Data, NoEmul -- Final Decisions");
0218 m_normalizationHisto->setBinLabel(1 + NFinalMismatchEmulNoData, "Emulator, No Data -- Final Decisions");
0219 }
0220
0221
0222 ibooker.setCurrentFolder(histFolder_ + "/InitialDecisionMismatches");
0223 initDecisionMismatches_vs_LS = ibooker.book1D("initialDecisionMismatches_vs_LS",
0224 "uGT initial decision mismatches vs Luminosity Segment",
0225 numLS_,
0226 0.,
0227 double(numLS_));
0228 initDecisionMismatches_vs_LS->setAxisTitle("Events with Initial Decision Mismatch", 2);
0229 initDecisionMismatches_vs_LS->setAxisTitle("Luminosity Segment");
0230
0231 hname = "DataNoEmul_" + bxt.str();
0232 htitle = "uGT data-emul mismatch -- Data fired but not Emulator --" + bxn.str();
0233 m_HistNamesInitial[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
0234
0235 hname = "EmulatorNoData_" + bxt.str();
0236 htitle = "uGT data-emul mismatch -- Emulator fired but not Data --" + bxn.str();
0237 m_HistNamesInitial[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
0238
0239
0240 ibooker.setCurrentFolder(histFolder_ + "/FinalDecisionMismatches");
0241 finalDecisionMismatches_vs_LS = ibooker.book1D("finalDecisionMismatches_vs_LS",
0242 "uGT final decision mismatches vs Luminosity Segment",
0243 numLS_,
0244 0.,
0245 double(numLS_));
0246 finalDecisionMismatches_vs_LS->setAxisTitle("Events with Final Decision Mismatch", 2);
0247 finalDecisionMismatches_vs_LS->setAxisTitle("Luminosity Segment");
0248
0249 hname = "DataNoEmul_" + bxt.str();
0250 htitle = "uGT data-emul mismatch -- Data fired but not Emulator --" + bxn.str();
0251 m_HistNamesFinal[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
0252
0253 hname = "EmulatorNoData_" + bxt.str();
0254 htitle = "uGT data-emul mismatch -- Emulator fired but not Data --" + bxn.str();
0255 m_HistNamesFinal[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
0256 }
0257
0258
0259 for (std::map<std::string, MonitorElement*>::iterator it = m_HistNamesInitial.begin(); it != m_HistNamesInitial.end();
0260 ++it) {
0261
0262
0263
0264
0265
0266 (*it).second->setAxisTitle("Trigger Bit");
0267 (*it).second->setAxisTitle("Events with Initial Decision Mismatch", 2);
0268 }
0269
0270 for (std::map<std::string, MonitorElement*>::iterator it = m_HistNamesFinal.begin(); it != m_HistNamesFinal.end();
0271 ++it) {
0272
0273
0274
0275
0276
0277 (*it).second->setAxisTitle("Trigger Bit (Unprescaled)");
0278 (*it).second->setAxisTitle("Events with Final Decision Mismatch", 2);
0279 }
0280 }
0281
0282 void L1TdeStage2uGT::fillHist(const std::map<std::string, MonitorElement*>& m_HistNames,
0283 const std::string& histName,
0284 const Double_t& value,
0285 const Double_t& wt = 1.) {
0286 std::map<std::string, MonitorElement*>::const_iterator hid = m_HistNames.find(histName);
0287
0288 if (hid == m_HistNames.end())
0289 edm::LogWarning("L1TdeStage2uGT") << "%fillHist -- Could not find histogram with name: " << histName << std::endl;
0290 else
0291 hid->second->Fill(value, wt);
0292 }