Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
#include "DQM/RPCMonitorDigi/interface/RPCTTUMonitor.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <fmt/format.h>

//
RPCTTUMonitor::RPCTTUMonitor(const edm::ParameterSet& iConfig) {
  ttuFolder = iConfig.getUntrackedParameter<std::string>("TTUFolder", "RPC/TTU");
  outputFile = iConfig.getUntrackedParameter<std::string>("OutPutFile", "");

  m_gtReadoutLabel = consumes<L1GlobalTriggerReadoutRecord>(iConfig.getParameter<edm::InputTag>("GTReadoutRcd"));
  m_gmtReadoutLabel = consumes<L1MuGMTReadoutCollection>(iConfig.getParameter<edm::InputTag>("GMTReadoutRcd"));
  m_rpcTechTrigEmu = consumes<L1GtTechnicalTriggerRecord>(iConfig.getParameter<edm::InputTag>("L1TTEmuBitsLabel"));

  m_ttBits = iConfig.getParameter<std::vector<unsigned> >("BitNumbers");
  m_maxttBits = m_ttBits.size();
}

// ------------ method called to for each event  ------------
void RPCTTUMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
  //..............................................................................................
  // Data .
  edm::Handle<L1GlobalTriggerReadoutRecord> gtRecord;
  iEvent.getByToken(m_gtReadoutLabel, gtRecord);

  if (!gtRecord.isValid()) {
    edm::LogError("RPCTTUMonitor") << "can nout find L1GlobalTriggerRecord \n";
    return;
  }

  // Emulator .
  edm::Handle<L1GtTechnicalTriggerRecord> emuTTRecord;
  iEvent.getByToken(m_rpcTechTrigEmu, emuTTRecord);

  if (!emuTTRecord.isValid()) {
    edm::LogError("RPCTTUMonitor") << "can not find L1GtTechnicalTriggerRecord (emulator) \n";
    return;
  }

  //..............................................................................................
  //
  //Timing difference between RPC-PAT and DT

  const int dGMT = discriminateGMT(iEvent, iSetup);
  if (dGMT < 0)
    return;

  std::map<int, bool> ttuDec;

  const int bxX = iEvent.bunchCrossing();  // ... 1 to 3564

  for (int k = 0; k < m_maxttBits; ++k) {
    for (int iebx = 0; iebx <= 2; iebx++) {
      const TechnicalTriggerWord gtTTWord = gtRecord->technicalTriggerWord(iebx - 1);
      ttuDec[iebx - 1] = gtTTWord[24 + k];
    }

    //. RPC
    if (m_rpcTrigger) {
      const int bx1 = (bxX - m_GMTcandidatesBx[0]);
      for (const auto& dec : ttuDec) {
        if (dec.second) {
          const int bx2 = dec.first;
          const float bxdiffPacTT = 1.0 * (bx1 - bx2);
          m_bxDistDiffPac[k]->Fill(bxdiffPacTT);
        }
      }
    }

    //.. DT
    if (m_dtTrigger) {
      const int bx1 = (bxX - m_DTcandidatesBx[0]);
      for (const auto& dec : ttuDec) {
        if (dec.second) {
          const int bx2 = dec.first;
          const float bxdiffDtTT = 1.0 * (bx1 - bx2);
          m_bxDistDiffDt[k]->Fill(bxdiffDtTT);
        }
      }
    }
    ttuDec.clear();
  }

  m_GMTcandidatesBx.clear();
  m_DTcandidatesBx.clear();

  //..............................................................................................
  //
  //... For Data Emulator comparison

  const TechnicalTriggerWord gtTTWord = gtRecord->technicalTriggerWord();

  std::vector<L1GtTechnicalTrigger> ttVec = emuTTRecord->gtTechnicalTrigger();

  int k = 0;
  //int m_BxWindow = 0;
  bool hasDataTrigger = false;
  bool hasEmulatorTrigger = false;

  if (ttVec.empty())
    return;

  for (const auto& bits : m_ttBits) {
    hasDataTrigger = gtTTWord.at(bits);
    m_ttBitsDecisionData->Fill(bits, (int)hasDataTrigger);

    hasEmulatorTrigger = ttVec[k].gtTechnicalTriggerResult();
    m_ttBitsDecisionEmulator->Fill(ttVec[k].gtTechnicalTriggerBitNumber(), (int)hasEmulatorTrigger);

    discriminateDecision(hasDataTrigger, hasEmulatorTrigger, k);

    ++k;
  }
}

int RPCTTUMonitor::discriminateGMT(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
  edm::Handle<L1MuGMTReadoutCollection> pCollection;
  iEvent.getByToken(m_gmtReadoutLabel, pCollection);

  if (!pCollection.isValid()) {
    edm::LogError("discriminateGMT") << "can't find L1MuGMTReadoutCollection with label \n";

    return -1;
  }

  int gmtDec(0);

  bool rpcBar_l1a = false;
  bool dtBar_l1a = false;

  m_dtTrigger = false;
  m_rpcTrigger = false;

  // get GMT readout collection
  const L1MuGMTReadoutCollection* gmtRC = pCollection.product();

  // get record vector
  std::vector<L1MuGMTReadoutRecord> gmt_records = gmtRC->getRecords();

  edm::LogInfo("DiscriminateGMT") << "nRecords: " << gmt_records.size() << '\n';

  for (const auto& rr : gmt_records) {
    const int BxInEvent = rr.getBxInEvent();
    const int BxInEventNew = rr.getBxNr();

    // RPC barrel muon candidates
    int nrpcB = 0;
    int ndtB = 0;

    std::vector<L1MuRegionalCand> BrlRpcCands = rr.getBrlRPCCands();
    std::vector<L1MuRegionalCand> BrlDtCands = rr.getDTBXCands();

    for (const auto& rc : BrlRpcCands) {
      if (!rc.empty()) {
        m_GMTcandidatesBx.push_back(BxInEventNew);

        nrpcB++;
      }
    }

    for (const auto& rc : BrlDtCands) {
      if (!rc.empty()) {
        m_DTcandidatesBx.push_back(BxInEventNew);
        ndtB++;
      }
    }

    if (BxInEvent == 0 && nrpcB > 0)
      rpcBar_l1a = true;
    if (BxInEvent == 0 && ndtB > 0)
      dtBar_l1a = true;
  }

  if (rpcBar_l1a) {
    gmtDec = 1;
    m_rpcTrigger = true;
  }

  if (dtBar_l1a) {
    gmtDec = 2;
    m_dtTrigger = true;
  }

  return gmtDec;
}

void RPCTTUMonitor::discriminateDecision(bool data, bool emu, int indx) {
  if (data == 1 && emu == 1) {
    m_dataVsemulator[indx]->Fill(1);
  } else if (data == 1 && emu == 0) {
    m_dataVsemulator[indx]->Fill(3);
  } else if (data == 0 && emu == 1) {
    m_dataVsemulator[indx]->Fill(5);
  } else if (data == 0 && emu == 0) {
    m_dataVsemulator[indx]->Fill(7);
  }
}

void RPCTTUMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& r, edm::EventSetup const& iSetup) {
  ibooker.setCurrentFolder(ttuFolder);
  std::string hname;

  m_ttBitsDecisionData = ibooker.book1D("TechTrigger.Bits.Data", "Technical Trigger bits : Summary", 10, 23, 33);

  m_ttBitsDecisionEmulator =
      ibooker.book1D("TechTrigger.Bits.Emulator", "Technical Trigger bits : Summary", 10, 23, 33);
  for (int k = 0; k < m_maxttBits; ++k) {
    hname = fmt::format("BX.diff.PAC-TTU.bit.{}", m_ttBits[k]);
    m_bxDistDiffPac[k] = ibooker.book1D(hname, "Timing difference between PAC and TTU", 7, -3, 3);

    hname = fmt::format("BX.diff.DT-TTU.bit.{}", m_ttBits[k]);
    m_bxDistDiffDt[k] = ibooker.book1D(hname, "Timing difference between DT and TTU", 7, -3, 3);

    hname = fmt::format("Emu.Ttu.Compare.bit.{}", m_ttBits[k]);
    m_dataVsemulator[k] = ibooker.book1D(hname, "Comparison between emulator and TT decisions", 10, 0, 10);
  }
}