File indexing completed on 2023-03-17 11:12:49
0001 #include <memory>
0002
0003 #include "FWCore/Framework/interface/ConsumesCollector.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/Utilities/interface/Transition.h"
0008
0009 #include "L1Trigger/L1TMuonOverlap/interface/OMTFProcessor.h"
0010 #include "L1Trigger/L1TMuonOverlap/interface/OMTFinput.h"
0011 #include "L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h"
0012 #include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h"
0013 #include "L1Trigger/L1TMuonOverlap/interface/XMLConfigWriter.h"
0014 #include "L1Trigger/L1TMuonOverlap/interface/OmtfName.h"
0015 #include "L1Trigger/L1TMuonOverlap/interface/GhostBusterPreferRefDt.h"
0016
0017 #include "L1Trigger/RPCTrigger/interface/RPCConst.h"
0018
0019
0020
0021 OMTFReconstruction::OMTFReconstruction(const edm::ParameterSet& theConfig, edm::ConsumesCollector&& iC)
0022 : m_Config(theConfig),
0023 l1TMuonOverlapParamsToken_(
0024 iC.esConsumes<L1TMuonOverlapParams, L1TMuonOverlapParamsRcd, edm::Transition::BeginRun>()),
0025 m_OMTFConfig(nullptr),
0026 m_InputMaker(iC, false),
0027 m_OMTF(nullptr),
0028 aTopElement(nullptr),
0029 m_OMTFConfigMaker(nullptr),
0030 m_Writer(nullptr) {
0031 dumpResultToXML = m_Config.getParameter<bool>("dumpResultToXML");
0032 dumpDetailedResultToXML = m_Config.getParameter<bool>("dumpDetailedResultToXML");
0033
0034 bxMin = m_Config.exists("bxMin") ? m_Config.getParameter<int>("bxMin") : 0;
0035 bxMax = m_Config.exists("bxMax") ? m_Config.getParameter<int>("bxMax") : 0;
0036 }
0037
0038
0039 OMTFReconstruction::~OMTFReconstruction() {
0040 delete m_OMTFConfig;
0041 delete m_OMTF;
0042
0043 if (m_Writer)
0044 delete m_Writer;
0045 }
0046
0047
0048
0049 void OMTFReconstruction::beginJob() {
0050 m_OMTFConfig = new OMTFConfiguration();
0051 m_OMTF = new OMTFProcessor();
0052 }
0053
0054
0055 void OMTFReconstruction::endJob() {
0056 if (dumpResultToXML) {
0057 std::string fName = m_Config.getParameter<std::string>("XMLDumpFileName");
0058 m_Writer->finaliseXMLDocument(fName);
0059 }
0060 }
0061
0062
0063 void OMTFReconstruction::beginRun(edm::Run const&, edm::EventSetup const& iSetup) {
0064 const L1TMuonOverlapParams* omtfParams = &iSetup.getData(l1TMuonOverlapParamsToken_);
0065
0066 if (!omtfParams) {
0067 edm::LogError("L1TMuonOverlapTrackProducer") << "Could not retrieve parameters from Event Setup" << std::endl;
0068 }
0069
0070 m_OMTFConfig->configure(omtfParams);
0071 m_OMTF->configure(m_OMTFConfig, omtfParams);
0072
0073
0074 if (m_OMTFConfig->fwVersion() >= 5) {
0075
0076
0077 m_GhostBuster = std::make_unique<GhostBusterPreferRefDt>(m_OMTFConfig);
0078 } else {
0079 m_GhostBuster = std::make_unique<GhostBuster>();
0080 }
0081
0082 m_Sorter.initialize(m_OMTFConfig);
0083 m_Sorter.setNphiBins(m_OMTFConfig->nPhiBins());
0084
0085 m_InputMaker.initialize(iSetup, m_OMTFConfig);
0086
0087 if (dumpResultToXML) {
0088 m_Writer = new XMLConfigWriter(m_OMTFConfig);
0089 std::string fName = "OMTF";
0090 m_Writer->initialiseXMLDocument(fName);
0091 }
0092 }
0093
0094
0095 std::unique_ptr<l1t::RegionalMuonCandBxCollection> OMTFReconstruction::reconstruct(const edm::Event& iEvent,
0096 const edm::EventSetup&) {
0097 loadAndFilterDigis(iEvent);
0098
0099 if (dumpResultToXML)
0100 aTopElement = m_Writer->writeEventHeader(iEvent.id().event());
0101
0102 std::unique_ptr<l1t::RegionalMuonCandBxCollection> candidates(new l1t::RegionalMuonCandBxCollection);
0103 candidates->setBXRange(bxMin, bxMax);
0104
0105
0106 for (int bx = bxMin; bx <= bxMax; bx++) {
0107 for (unsigned int iProcessor = 0; iProcessor < m_OMTFConfig->nProcessors(); ++iProcessor)
0108 getProcessorCandidates(iProcessor, l1t::tftype::omtf_pos, bx, *candidates);
0109
0110 for (unsigned int iProcessor = 0; iProcessor < m_OMTFConfig->nProcessors(); ++iProcessor)
0111 getProcessorCandidates(iProcessor, l1t::tftype::omtf_neg, bx, *candidates);
0112
0113 edm::LogInfo("OMTFReconstruction") << "OMTF: Number of candidates in BX=" << bx << ": " << candidates->size(bx)
0114 << std::endl;
0115 ;
0116 }
0117
0118 return candidates;
0119 }
0120
0121
0122
0123 void OMTFReconstruction::loadAndFilterDigis(const edm::Event& iEvent) {
0124
0125 if (!m_Config.getParameter<bool>("dropDTPrimitives")) {
0126 iEvent.getByLabel(m_Config.getParameter<edm::InputTag>("srcDTPh"), dtPhDigis);
0127 iEvent.getByLabel(m_Config.getParameter<edm::InputTag>("srcDTTh"), dtThDigis);
0128 }
0129 if (!m_Config.getParameter<bool>("dropRPCPrimitives"))
0130 iEvent.getByLabel(m_Config.getParameter<edm::InputTag>("srcRPC"), rpcDigis);
0131 if (!m_Config.getParameter<bool>("dropCSCPrimitives"))
0132 iEvent.getByLabel(m_Config.getParameter<edm::InputTag>("srcCSC"), cscDigis);
0133 }
0134
0135
0136
0137 void OMTFReconstruction::getProcessorCandidates(unsigned int iProcessor,
0138 l1t::tftype mtfType,
0139 int bx,
0140 l1t::RegionalMuonCandBxCollection& omtfCandidates) {
0141 m_InputMaker.setFlag(0);
0142 OMTFinput input = m_InputMaker.buildInputForProcessor(
0143 dtPhDigis.product(), dtThDigis.product(), cscDigis.product(), rpcDigis.product(), iProcessor, mtfType, bx);
0144 int flag = m_InputMaker.getFlag();
0145
0146 const std::vector<OMTFProcessor::resultsMap>& results = m_OMTF->processInput(iProcessor, input);
0147
0148 std::vector<AlgoMuon> algoCandidates;
0149
0150 m_Sorter.sortRefHitResults(results, algoCandidates);
0151
0152
0153 std::vector<AlgoMuon> gbCandidates = m_GhostBuster->select(algoCandidates);
0154
0155
0156 std::vector<l1t::RegionalMuonCand> candMuons = m_Sorter.candidates(iProcessor, mtfType, gbCandidates);
0157
0158
0159 for (auto& candMuon : candMuons) {
0160 candMuon.setHwQual(candMuon.hwQual() | flag);
0161 omtfCandidates.push_back(bx, candMuon);
0162 }
0163
0164
0165 if (bx == 0)
0166 writeResultToXML(iProcessor, mtfType, input, results, candMuons);
0167 }
0168
0169
0170 void OMTFReconstruction::writeResultToXML(unsigned int iProcessor,
0171 l1t::tftype mtfType,
0172 const OMTFinput& input,
0173 const std::vector<OMTFProcessor::resultsMap>& results,
0174 const std::vector<l1t::RegionalMuonCand>& candMuons) {
0175 int endcap = (mtfType == l1t::omtf_neg) ? -1 : ((mtfType == l1t::omtf_pos) ? +1 : 0);
0176 OmtfName board(iProcessor, endcap);
0177
0178
0179 if (dumpResultToXML) {
0180 xercesc::DOMElement* aProcElement = m_Writer->writeEventData(aTopElement, board, input);
0181 for (unsigned int iRefHit = 0; iRefHit < m_OMTFConfig->nTestRefHits(); ++iRefHit) {
0182
0183 AlgoMuon algoMuon = m_Sorter.sortRefHitResults(results[iRefHit], 0);
0184 if (algoMuon.getPt()) {
0185 m_Writer->writeAlgoMuon(aProcElement, iRefHit, algoMuon);
0186 if (dumpDetailedResultToXML) {
0187 for (auto& itKey : results[iRefHit])
0188 m_Writer->writeResultsData(aProcElement, iRefHit, itKey.first, itKey.second);
0189 }
0190 }
0191 }
0192 for (auto& candMuon : candMuons)
0193 m_Writer->writeCandMuon(aProcElement, candMuon);
0194 }
0195 }
0196
0197