File indexing completed on 2021-05-31 22:35:54
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 int ndec(0);
0061 const int bx1 = (bxX - m_GMTcandidatesBx[0]);
0062 for (const auto& dec : ttuDec) {
0063 if (dec.second) {
0064 const int bx2 = dec.first;
0065 const float bxdiffPacTT = 1.0 * (bx1 - bx2);
0066 m_bxDistDiffPac[k]->Fill(bxdiffPacTT);
0067 ++ndec;
0068 }
0069 }
0070 }
0071
0072
0073 if (m_dtTrigger) {
0074 int ndec(0);
0075 const int bx1 = (bxX - m_DTcandidatesBx[0]);
0076 for (const auto& dec : ttuDec) {
0077 if (dec.second) {
0078 const int bx2 = dec.first;
0079 const float bxdiffDtTT = 1.0 * (bx1 - bx2);
0080 m_bxDistDiffDt[k]->Fill(bxdiffDtTT);
0081 ++ndec;
0082 }
0083 }
0084 }
0085 ttuDec.clear();
0086 }
0087
0088 m_GMTcandidatesBx.clear();
0089 m_DTcandidatesBx.clear();
0090
0091
0092
0093
0094
0095 const TechnicalTriggerWord gtTTWord = gtRecord->technicalTriggerWord();
0096
0097 std::vector<L1GtTechnicalTrigger> ttVec = emuTTRecord->gtTechnicalTrigger();
0098
0099 int k = 0;
0100
0101 bool hasDataTrigger = false;
0102 bool hasEmulatorTrigger = false;
0103
0104 if (ttVec.empty())
0105 return;
0106
0107 for (const auto& bits : m_ttBits) {
0108 hasDataTrigger = gtTTWord.at(bits);
0109 m_ttBitsDecisionData->Fill(bits, (int)hasDataTrigger);
0110
0111 hasEmulatorTrigger = ttVec[k].gtTechnicalTriggerResult();
0112 m_ttBitsDecisionEmulator->Fill(ttVec[k].gtTechnicalTriggerBitNumber(), (int)hasEmulatorTrigger);
0113
0114 discriminateDecision(hasDataTrigger, hasEmulatorTrigger, k);
0115
0116 ++k;
0117 }
0118 }
0119
0120 int RPCTTUMonitor::discriminateGMT(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0121 edm::Handle<L1MuGMTReadoutCollection> pCollection;
0122 iEvent.getByToken(m_gmtReadoutLabel, pCollection);
0123
0124 if (!pCollection.isValid()) {
0125 edm::LogError("discriminateGMT") << "can't find L1MuGMTReadoutCollection with label \n";
0126
0127 return -1;
0128 }
0129
0130 int gmtDec(0);
0131
0132 bool rpcBar_l1a = false;
0133 bool dtBar_l1a = false;
0134
0135 m_dtTrigger = false;
0136 m_rpcTrigger = false;
0137
0138
0139 const L1MuGMTReadoutCollection* gmtRC = pCollection.product();
0140
0141
0142 std::vector<L1MuGMTReadoutRecord> gmt_records = gmtRC->getRecords();
0143
0144 edm::LogInfo("DiscriminateGMT") << "nRecords: " << gmt_records.size() << '\n';
0145
0146 for (const auto& rr : gmt_records) {
0147 const int BxInEvent = rr.getBxInEvent();
0148 const int BxInEventNew = rr.getBxNr();
0149
0150
0151 int nrpcB = 0;
0152 int ndtB = 0;
0153
0154 std::vector<L1MuRegionalCand> BrlRpcCands = rr.getBrlRPCCands();
0155 std::vector<L1MuRegionalCand> BrlDtCands = rr.getDTBXCands();
0156
0157 for (const auto& rc : BrlRpcCands) {
0158 if (!rc.empty()) {
0159 m_GMTcandidatesBx.push_back(BxInEventNew);
0160
0161 nrpcB++;
0162 }
0163 }
0164
0165 for (const auto& rc : BrlDtCands) {
0166 if (!rc.empty()) {
0167 m_DTcandidatesBx.push_back(BxInEventNew);
0168 ndtB++;
0169 }
0170 }
0171
0172 if (BxInEvent == 0 && nrpcB > 0)
0173 rpcBar_l1a = true;
0174 if (BxInEvent == 0 && ndtB > 0)
0175 dtBar_l1a = true;
0176 }
0177
0178 if (rpcBar_l1a) {
0179 gmtDec = 1;
0180 m_rpcTrigger = true;
0181 }
0182
0183 if (dtBar_l1a) {
0184 gmtDec = 2;
0185 m_dtTrigger = true;
0186 }
0187
0188 return gmtDec;
0189 }
0190
0191 void RPCTTUMonitor::discriminateDecision(bool data, bool emu, int indx) {
0192 if (data == 1 && emu == 1) {
0193 m_dataVsemulator[indx]->Fill(1);
0194 } else if (data == 1 && emu == 0) {
0195 m_dataVsemulator[indx]->Fill(3);
0196 } else if (data == 0 && emu == 1) {
0197 m_dataVsemulator[indx]->Fill(5);
0198 } else if (data == 0 && emu == 0) {
0199 m_dataVsemulator[indx]->Fill(7);
0200 }
0201 }
0202
0203 void RPCTTUMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& r, edm::EventSetup const& iSetup) {
0204 ibooker.setCurrentFolder(ttuFolder);
0205 std::string hname;
0206
0207 m_ttBitsDecisionData = ibooker.book1D("TechTrigger.Bits.Data", "Technical Trigger bits : Summary", 10, 23, 33);
0208
0209 m_ttBitsDecisionEmulator =
0210 ibooker.book1D("TechTrigger.Bits.Emulator", "Technical Trigger bits : Summary", 10, 23, 33);
0211 for (int k = 0; k < m_maxttBits; ++k) {
0212 hname = fmt::format("BX.diff.PAC-TTU.bit.{}", m_ttBits[k]);
0213 m_bxDistDiffPac[k] = ibooker.book1D(hname, "Timing difference between PAC and TTU", 7, -3, 3);
0214
0215 hname = fmt::format("BX.diff.DT-TTU.bit.{}", m_ttBits[k]);
0216 m_bxDistDiffDt[k] = ibooker.book1D(hname, "Timing difference between DT and TTU", 7, -3, 3);
0217
0218 hname = fmt::format("Emu.Ttu.Compare.bit.{}", m_ttBits[k]);
0219 m_dataVsemulator[k] = ibooker.book1D(hname, "Comparison between emulator and TT decisions", 10, 0, 10);
0220 }
0221 }