Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-11-14 23:29:03

0001 /*
0002  * \file L1TdeStage2uGT.cc
0003  *
0004  * L. Apanasevich <Leonard.Apanasevich@cern.ch>
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   // Only using gtUtil to find prescale factors and mapping of bits to names, so only call gtUtil_ at lumi boundaries.
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   // Get standard event parameters
0068   int lumi = event.luminosityBlock();
0069   if (lumi > numLS_)
0070     lumi = numLS_;
0071 
0072   // int bx = event.bunchCrossing();
0073 
0074   // check that the requested range of BX's is consistent with the BX's in the emulated and unpacked collections
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 
0099     hsummary = "dataEmulSummary_" + bxt.str();
0100 
0101     bool foundInitalMismatchDataNoEmul{false};
0102     bool foundInitalMismatchEmulNoData{false};
0103     bool foundFinalMismatchDataNoEmul{false};
0104     bool foundFinalMismatchEmulNoData{false};
0105     // Looping over the algo blocks from each trigger board
0106     std::vector<GlobalAlgBlk>::const_iterator it_data, it_emul;
0107     for (it_data = dataCollection->begin(ibx), it_emul = emulCollection->begin(ibx);
0108          it_data != dataCollection->end(ibx) && it_emul != emulCollection->end(ibx);
0109          ++it_data, ++it_emul) {
0110       // Fills algorithm bits histograms
0111       int numAlgs = it_data->getAlgoDecisionInitial().size();
0112       for (int algoBit = 0; algoBit < numAlgs; ++algoBit) {
0113         string algoName = "xxx";
0114         bool found = gtUtil_.getAlgNameFromBit(algoBit, algoName);
0115         if (not found)
0116           continue;
0117 
0118         // skip bits which emulator does not handle (only skiped for bx !=0)
0119         bool isBlackListed(false);
0120         for (auto const& pattern : triggerBlackList_) {
0121           //std::cout << pattern << std::endl;
0122           if (edm::is_glob(pattern)) {
0123             std::regex regexp(edm::glob2reg(pattern));
0124             if (regex_match(algoName.c_str(), regexp))
0125               isBlackListed = true;
0126           } else {
0127             if (algoName == pattern)
0128               isBlackListed = true;
0129           }
0130         }
0131         if (ibx != 0 && isBlackListed)
0132           continue;
0133 
0134         // Check initial decisions
0135         if (it_data->getAlgoDecisionInitial(algoBit) != it_emul->getAlgoDecisionInitial(algoBit)) {
0136           if (it_data->getAlgoDecisionInitial(algoBit)) {
0137             hname = "DataNoEmul_" + bxt.str();
0138             foundInitalMismatchDataNoEmul = true;
0139             initDecisionMismatchesDnoE_vs_LS->Fill(float(lumi));
0140           } else {
0141             hname = "EmulatorNoData_" + bxt.str();
0142             foundInitalMismatchEmulNoData = true;
0143             initDecisionMismatchesEnoD_vs_LS->Fill(float(lumi));
0144           }
0145           fillHist(m_HistNamesInitial, hname, float(algoBit), 1.);
0146         }
0147 
0148         // Check final decisions
0149         if (it_data->getAlgoDecisionFinal(algoBit) != it_emul->getAlgoDecisionFinal(algoBit)) {
0150           bool unprescaled = true;
0151           // check the prescale factor
0152           double prescale = -999;
0153           bool dummy = gtUtil_.getPrescaleByBit(algoBit, prescale);
0154           if (not dummy)
0155             edm::LogWarning("L1TdeStage2uGT") << "Could not find prescale value for algobit: " << algoBit << std::endl;
0156 
0157           if (prescale != 1)
0158             unprescaled = false;
0159 
0160           if (unprescaled) {
0161             if (it_data->getAlgoDecisionFinal(algoBit)) {
0162               hname = "DataNoEmul_" + bxt.str();
0163               foundFinalMismatchDataNoEmul = true;
0164               finalDecisionMismatchesDnoE_vs_LS->Fill(float(lumi));
0165             } else {
0166               hname = "EmulatorNoData_" + bxt.str();
0167               foundFinalMismatchEmulNoData = true;
0168               finalDecisionMismatchesEnoD_vs_LS->Fill(float(lumi));
0169             }
0170             fillHist(m_HistNamesFinal, hname, float(algoBit), 1.);
0171           }
0172         }
0173 
0174       }  // end loop over algoBits
0175     }    // end loop over globalalgblk vector
0176     if (foundInitalMismatchDataNoEmul) {
0177       fillHist(m_SummaryHistograms, hsummary, float(NInitalMismatchDataNoEmul), 1.);
0178     }
0179     if (foundInitalMismatchEmulNoData) {
0180       fillHist(m_SummaryHistograms, hsummary, float(NInitalMismatchEmulNoData), 1.);
0181     }
0182     if (foundFinalMismatchDataNoEmul) {
0183       fillHist(m_SummaryHistograms, hsummary, float(NFinalMismatchDataNoEmul), 1.);
0184     }
0185     if (foundFinalMismatchEmulNoData) {
0186       fillHist(m_SummaryHistograms, hsummary, float(NFinalMismatchEmulNoData), 1.);
0187     }
0188   }  // endof loop over BX collections
0189 }
0190 
0191 void L1TdeStage2uGT::bookHistograms(DQMStore::IBooker& ibooker, const edm::Run& run, const edm::EventSetup& es) {
0192   gtUtil_.retrieveL1Setup(es);
0193 
0194   auto const& prescales = gtUtil_.prescales();
0195   int nbins = prescales.size();  // dummy values for now; update later when gtutils function is called
0196   double xmin = -0.5;
0197   double xmax = nbins - 0.5;
0198 
0199   string hname, htitle;
0200 
0201   int ibx = (numBx_ + 1) / 2 - numBx_;
0202   for (int i = 0; i < numBx_; i++) {
0203     ostringstream bxn, bxt;
0204 
0205     if (ibx == 0) {
0206       bxt << "CentralBX";
0207       bxn << " Central BX ";
0208     } else {
0209       bxt << "BX" << ibx;
0210       bxn << " BX " << ibx;
0211     }
0212     ibx++;
0213 
0214     ibooker.setCurrentFolder(histFolder_);
0215     hname = "dataEmulSummary_" + bxt.str();
0216     htitle = "uGT Data/Emulator Mismatches --" + bxn.str();
0217     m_SummaryHistograms[hname] = ibooker.book1D(hname, htitle, NSummaryColumns, 0., double(NSummaryColumns));
0218     m_SummaryHistograms[hname]->setAxisTitle("Events", /* axis */ 2);
0219     m_SummaryHistograms[hname]->setBinLabel(1 + NInitalMismatchDataNoEmul, "Data, NoEmul -- Initial Decisions");
0220     m_SummaryHistograms[hname]->setBinLabel(1 + NInitalMismatchEmulNoData, "Emulator, No Data -- Initial Decisions");
0221     m_SummaryHistograms[hname]->setBinLabel(1 + NFinalMismatchDataNoEmul, "Data, NoEmul -- Final Decisions");
0222     m_SummaryHistograms[hname]->setBinLabel(1 + NFinalMismatchEmulNoData, "Emulator, No Data -- Final Decisions");
0223 
0224     if (i == 0) {
0225       hname = "normalizationHisto";
0226       htitle = "Normalization histogram for uGT Data/Emulator Mismatches ratios";
0227       m_normalizationHisto = ibooker.book1D(hname, htitle, NSummaryColumns, 0., double(NSummaryColumns));
0228       m_normalizationHisto->setAxisTitle("Events", /* axis */ 2);
0229       m_normalizationHisto->setBinLabel(1 + NInitalMismatchDataNoEmul, "Data, NoEmul -- Initial Decisions");
0230       m_normalizationHisto->setBinLabel(1 + NInitalMismatchEmulNoData, "Emulator, No Data -- Initial Decisions");
0231       m_normalizationHisto->setBinLabel(1 + NFinalMismatchDataNoEmul, "Data, NoEmul -- Final Decisions");
0232       m_normalizationHisto->setBinLabel(1 + NFinalMismatchEmulNoData, "Emulator, No Data -- Final Decisions");
0233     }
0234 
0235     // book initial decisions histograms
0236     ibooker.setCurrentFolder(histFolder_ + "/InitialDecisionMismatches");
0237     initDecisionMismatchesDnoE_vs_LS =
0238         ibooker.book1D("initialDecisionMismatchesDnoE_vs_LS",
0239                        "uGT initial decision mismatches (Data, but no emu) vs Luminosity Segment",
0240                        numLS_,
0241                        0.,
0242                        double(numLS_));
0243     initDecisionMismatchesDnoE_vs_LS->setAxisTitle("Events with Initial Decision Mismatch", /* axis */ 2);
0244     initDecisionMismatchesDnoE_vs_LS->setAxisTitle("Luminosity Segment");
0245 
0246     initDecisionMismatchesEnoD_vs_LS =
0247         ibooker.book1D("initialDecisionMismatchesEnoD_vs_LS",
0248                        "uGT initial decision mismatches (Emu, but no data) vs Luminosity Segment",
0249                        numLS_,
0250                        0.,
0251                        double(numLS_));
0252     initDecisionMismatchesEnoD_vs_LS->setAxisTitle("Events with Initial Decision Mismatch", /* axis */ 2);
0253     initDecisionMismatchesEnoD_vs_LS->setAxisTitle("Luminosity Segment");
0254 
0255     hname = "DataNoEmul_" + bxt.str();
0256     htitle = "uGT data-emul mismatch -- Data fired but not Emulator --" + bxn.str();
0257     m_HistNamesInitial[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
0258 
0259     hname = "EmulatorNoData_" + bxt.str();
0260     htitle = "uGT data-emul mismatch -- Emulator fired but not Data --" + bxn.str();
0261     m_HistNamesInitial[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
0262 
0263     // book final decisions histograms
0264     ibooker.setCurrentFolder(histFolder_ + "/FinalDecisionMismatches");
0265     finalDecisionMismatchesDnoE_vs_LS =
0266         ibooker.book1D("finalDecisionMismatchesDnoE_vs_LS",
0267                        "uGT final decision mismatches (Data, but no emu) vs Luminosity Segment",
0268                        numLS_,
0269                        0.,
0270                        double(numLS_));
0271     finalDecisionMismatchesDnoE_vs_LS->setAxisTitle("Events with Final Decision Mismatch", /* axis */ 2);
0272     finalDecisionMismatchesDnoE_vs_LS->setAxisTitle("Luminosity Segment");
0273 
0274     finalDecisionMismatchesEnoD_vs_LS =
0275         ibooker.book1D("finalDecisionMismatchesEnoD_vs_LS",
0276                        "uGT final decision mismatches (Emu, but no data) vs Luminosity Segment",
0277                        numLS_,
0278                        0.,
0279                        double(numLS_));
0280     finalDecisionMismatchesEnoD_vs_LS->setAxisTitle("Events with Final Decision Mismatch", /* axis */ 2);
0281     finalDecisionMismatchesEnoD_vs_LS->setAxisTitle("Luminosity Segment");
0282 
0283     hname = "DataNoEmul_" + bxt.str();
0284     htitle = "uGT data-emul mismatch -- Data fired but not Emulator --" + bxn.str();
0285     m_HistNamesFinal[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
0286 
0287     hname = "EmulatorNoData_" + bxt.str();
0288     htitle = "uGT data-emul mismatch -- Emulator fired but not Data --" + bxn.str();
0289     m_HistNamesFinal[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
0290   }
0291 
0292   // Set some histogram attributes
0293   for (std::map<std::string, MonitorElement*>::iterator it = m_HistNamesInitial.begin(); it != m_HistNamesInitial.end();
0294        ++it) {
0295     // for (unsigned int i = 0; i < prescales.size(); i++) {
0296     //   auto const& name = prescales.at(i).first;
0297     //   if (name != "NULL")
0298     //  (*it).second->setBinLabel(1+i, name.c_str());
0299     // }
0300     (*it).second->setAxisTitle("Trigger Bit");
0301     (*it).second->setAxisTitle("Events with Initial Decision Mismatch", /* axis */ 2);
0302   }
0303 
0304   for (std::map<std::string, MonitorElement*>::iterator it = m_HistNamesFinal.begin(); it != m_HistNamesFinal.end();
0305        ++it) {
0306     // for (unsigned int i = 0; i < prescales.size(); i++) {
0307     //   auto const& name = prescales.at(i).first;
0308     //   if (name != "NULL")
0309     //  (*it).second->setBinLabel(1+i, name.c_str());
0310     // }
0311     (*it).second->setAxisTitle("Trigger Bit (Unprescaled)");
0312     (*it).second->setAxisTitle("Events with Final Decision Mismatch", /* axis */ 2);
0313   }
0314 }
0315 
0316 void L1TdeStage2uGT::fillHist(const std::map<std::string, MonitorElement*>& m_HistNames,
0317                               const std::string& histName,
0318                               const Double_t& value,
0319                               const Double_t& wt = 1.) {
0320   std::map<std::string, MonitorElement*>::const_iterator hid = m_HistNames.find(histName);
0321 
0322   if (hid == m_HistNames.end())
0323     edm::LogWarning("L1TdeStage2uGT") << "%fillHist -- Could not find histogram with name: " << histName << std::endl;
0324   else
0325     hid->second->Fill(value, wt);
0326 }