File indexing completed on 2024-04-06 12:08:14
0001 #include "DQM/RPCMonitorDigi/interface/RPCTTUMonitor.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003
0004 #include <fmt/format.h>
0005
0006
0007 RPCTTUMonitor::RPCTTUMonitor(const edm::ParameterSet& iConfig) {
0008 ttuFolder = iConfig.getUntrackedParameter<std::string>("TTUFolder", "RPC/TTU");
0009 outputFile = iConfig.getUntrackedParameter<std::string>("OutPutFile", "");
0010
0011 m_gtReadoutLabel = consumes<L1GlobalTriggerReadoutRecord>(iConfig.getParameter<edm::InputTag>("GTReadoutRcd"));
0012 m_gmtReadoutLabel = consumes<L1MuGMTReadoutCollection>(iConfig.getParameter<edm::InputTag>("GMTReadoutRcd"));
0013 m_rpcTechTrigEmu = consumes<L1GtTechnicalTriggerRecord>(iConfig.getParameter<edm::InputTag>("L1TTEmuBitsLabel"));
0014
0015 m_ttBits = iConfig.getParameter<std::vector<unsigned> >("BitNumbers");
0016 m_maxttBits = m_ttBits.size();
0017 }
0018
0019
0020 void RPCTTUMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0021
0022
0023 edm::Handle<L1GlobalTriggerReadoutRecord> gtRecord;
0024 iEvent.getByToken(m_gtReadoutLabel, gtRecord);
0025
0026 if (!gtRecord.isValid()) {
0027 edm::LogError("RPCTTUMonitor") << "can nout find L1GlobalTriggerRecord \n";
0028 return;
0029 }
0030
0031
0032 edm::Handle<L1GtTechnicalTriggerRecord> emuTTRecord;
0033 iEvent.getByToken(m_rpcTechTrigEmu, emuTTRecord);
0034
0035 if (!emuTTRecord.isValid()) {
0036 edm::LogError("RPCTTUMonitor") << "can not find L1GtTechnicalTriggerRecord (emulator) \n";
0037 return;
0038 }
0039
0040
0041
0042
0043
0044 const int dGMT = discriminateGMT(iEvent, iSetup);
0045 if (dGMT < 0)
0046 return;
0047
0048 std::map<int, bool> ttuDec;
0049
0050 const int bxX = iEvent.bunchCrossing();
0051
0052 for (int k = 0; k < m_maxttBits; ++k) {
0053 for (int iebx = 0; iebx <= 2; iebx++) {
0054 const TechnicalTriggerWord gtTTWord = gtRecord->technicalTriggerWord(iebx - 1);
0055 ttuDec[iebx - 1] = gtTTWord[24 + k];
0056 }
0057
0058
0059 if (m_rpcTrigger) {
0060 const int bx1 = (bxX - m_GMTcandidatesBx[0]);
0061 for (const auto& dec : ttuDec) {
0062 if (dec.second) {
0063 const int bx2 = dec.first;
0064 const float bxdiffPacTT = 1.0 * (bx1 - bx2);
0065 m_bxDistDiffPac[k]->Fill(bxdiffPacTT);
0066 }
0067 }
0068 }
0069
0070
0071 if (m_dtTrigger) {
0072 const int bx1 = (bxX - m_DTcandidatesBx[0]);
0073 for (const auto& dec : ttuDec) {
0074 if (dec.second) {
0075 const int bx2 = dec.first;
0076 const float bxdiffDtTT = 1.0 * (bx1 - bx2);
0077 m_bxDistDiffDt[k]->Fill(bxdiffDtTT);
0078 }
0079 }
0080 }
0081 ttuDec.clear();
0082 }
0083
0084 m_GMTcandidatesBx.clear();
0085 m_DTcandidatesBx.clear();
0086
0087
0088
0089
0090
0091 const TechnicalTriggerWord gtTTWord = gtRecord->technicalTriggerWord();
0092
0093 std::vector<L1GtTechnicalTrigger> ttVec = emuTTRecord->gtTechnicalTrigger();
0094
0095 int k = 0;
0096
0097 bool hasDataTrigger = false;
0098 bool hasEmulatorTrigger = false;
0099
0100 if (ttVec.empty())
0101 return;
0102
0103 for (const auto& bits : m_ttBits) {
0104 hasDataTrigger = gtTTWord.at(bits);
0105 m_ttBitsDecisionData->Fill(bits, (int)hasDataTrigger);
0106
0107 hasEmulatorTrigger = ttVec[k].gtTechnicalTriggerResult();
0108 m_ttBitsDecisionEmulator->Fill(ttVec[k].gtTechnicalTriggerBitNumber(), (int)hasEmulatorTrigger);
0109
0110 discriminateDecision(hasDataTrigger, hasEmulatorTrigger, k);
0111
0112 ++k;
0113 }
0114 }
0115
0116 int RPCTTUMonitor::discriminateGMT(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0117 edm::Handle<L1MuGMTReadoutCollection> pCollection;
0118 iEvent.getByToken(m_gmtReadoutLabel, pCollection);
0119
0120 if (!pCollection.isValid()) {
0121 edm::LogError("discriminateGMT") << "can't find L1MuGMTReadoutCollection with label \n";
0122
0123 return -1;
0124 }
0125
0126 int gmtDec(0);
0127
0128 bool rpcBar_l1a = false;
0129 bool dtBar_l1a = false;
0130
0131 m_dtTrigger = false;
0132 m_rpcTrigger = false;
0133
0134
0135 const L1MuGMTReadoutCollection* gmtRC = pCollection.product();
0136
0137
0138 std::vector<L1MuGMTReadoutRecord> gmt_records = gmtRC->getRecords();
0139
0140 edm::LogInfo("DiscriminateGMT") << "nRecords: " << gmt_records.size() << '\n';
0141
0142 for (const auto& rr : gmt_records) {
0143 const int BxInEvent = rr.getBxInEvent();
0144 const int BxInEventNew = rr.getBxNr();
0145
0146
0147 int nrpcB = 0;
0148 int ndtB = 0;
0149
0150 std::vector<L1MuRegionalCand> BrlRpcCands = rr.getBrlRPCCands();
0151 std::vector<L1MuRegionalCand> BrlDtCands = rr.getDTBXCands();
0152
0153 for (const auto& rc : BrlRpcCands) {
0154 if (!rc.empty()) {
0155 m_GMTcandidatesBx.push_back(BxInEventNew);
0156
0157 nrpcB++;
0158 }
0159 }
0160
0161 for (const auto& rc : BrlDtCands) {
0162 if (!rc.empty()) {
0163 m_DTcandidatesBx.push_back(BxInEventNew);
0164 ndtB++;
0165 }
0166 }
0167
0168 if (BxInEvent == 0 && nrpcB > 0)
0169 rpcBar_l1a = true;
0170 if (BxInEvent == 0 && ndtB > 0)
0171 dtBar_l1a = true;
0172 }
0173
0174 if (rpcBar_l1a) {
0175 gmtDec = 1;
0176 m_rpcTrigger = true;
0177 }
0178
0179 if (dtBar_l1a) {
0180 gmtDec = 2;
0181 m_dtTrigger = true;
0182 }
0183
0184 return gmtDec;
0185 }
0186
0187 void RPCTTUMonitor::discriminateDecision(bool data, bool emu, int indx) {
0188 if (data == 1 && emu == 1) {
0189 m_dataVsemulator[indx]->Fill(1);
0190 } else if (data == 1 && emu == 0) {
0191 m_dataVsemulator[indx]->Fill(3);
0192 } else if (data == 0 && emu == 1) {
0193 m_dataVsemulator[indx]->Fill(5);
0194 } else if (data == 0 && emu == 0) {
0195 m_dataVsemulator[indx]->Fill(7);
0196 }
0197 }
0198
0199 void RPCTTUMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& r, edm::EventSetup const& iSetup) {
0200 ibooker.setCurrentFolder(ttuFolder);
0201 std::string hname;
0202
0203 m_ttBitsDecisionData = ibooker.book1D("TechTrigger.Bits.Data", "Technical Trigger bits : Summary", 10, 23, 33);
0204
0205 m_ttBitsDecisionEmulator =
0206 ibooker.book1D("TechTrigger.Bits.Emulator", "Technical Trigger bits : Summary", 10, 23, 33);
0207 for (int k = 0; k < m_maxttBits; ++k) {
0208 hname = fmt::format("BX.diff.PAC-TTU.bit.{}", m_ttBits[k]);
0209 m_bxDistDiffPac[k] = ibooker.book1D(hname, "Timing difference between PAC and TTU", 7, -3, 3);
0210
0211 hname = fmt::format("BX.diff.DT-TTU.bit.{}", m_ttBits[k]);
0212 m_bxDistDiffDt[k] = ibooker.book1D(hname, "Timing difference between DT and TTU", 7, -3, 3);
0213
0214 hname = fmt::format("Emu.Ttu.Compare.bit.{}", m_ttBits[k]);
0215 m_dataVsemulator[k] = ibooker.book1D(hname, "Comparison between emulator and TT decisions", 10, 0, 10);
0216 }
0217 }