File indexing completed on 2025-05-15 02:28:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include "L1Trigger/GlobalMuonTrigger/interface/L1MuGlobalMuonTrigger.h"
0021
0022
0023
0024
0025
0026 #include <iostream>
0027 #include <sys/stat.h>
0028 #include <sys/types.h>
0029
0030
0031
0032
0033
0034 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTCand.h"
0035 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTExtendedCand.h"
0036 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutRecord.h"
0037 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
0038 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTConfig.h"
0039 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTPSB.h"
0040 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMatcher.h"
0041 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTCancelOutUnit.h"
0042 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMipIsoAU.h"
0043 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMerger.h"
0044 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTSorter.h"
0045
0046 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTDebugBlock.h"
0047
0048 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0049
0050 #include "FWCore/Framework/interface/EventSetup.h"
0051 #include "FWCore/Framework/interface/ESHandle.h"
0052
0053
0054
0055
0056 L1MuGlobalMuonTrigger::L1MuGlobalMuonTrigger(const edm::ParameterSet& ps) {
0057 produces<std::vector<L1MuGMTCand>>();
0058 produces<L1MuGMTReadoutCollection>();
0059 m_sendMipIso = ps.getUntrackedParameter<bool>("SendMipIso", false);
0060 if (m_sendMipIso) {
0061 produces<std::vector<unsigned>>();
0062 }
0063
0064 m_L1MuGMTScalesCacheID = 0ULL;
0065 m_L1MuTriggerScalesCacheID = 0ULL;
0066 m_L1MuTriggerPtScaleCacheID = 0ULL;
0067 m_L1MuGMTParametersCacheID = 0ULL;
0068 m_L1MuGMTChannelMaskCacheID = 0ULL;
0069 m_L1CaloGeometryCacheID = 0ULL;
0070
0071 m_ExtendedCands.reserve(20);
0072
0073
0074 if (!m_config.load()) {
0075 auto temp = std::make_shared<L1MuGMTConfig>(ps);
0076 std::shared_ptr<L1MuGMTConfig> expected = nullptr;
0077 m_config.compare_exchange_strong(expected, temp, std::memory_order_acq_rel, std::memory_order_acquire);
0078 }
0079 m_writeLUTsAndRegs = ps.getUntrackedParameter<bool>("WriteLUTsAndRegs", false);
0080
0081
0082 if (L1MuGMTConfig::Debug(1))
0083 edm::LogVerbatim("GMT_info");
0084 if (L1MuGMTConfig::Debug(1))
0085 edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger building ****";
0086 if (L1MuGMTConfig::Debug(1))
0087 edm::LogVerbatim("GMT_info");
0088
0089
0090 if (L1MuGMTConfig::Debug(2))
0091 edm::LogVerbatim("GMT_info") << "creating GMT PSB";
0092 m_PSB = new L1MuGMTPSB(*this, consumesCollector());
0093
0094
0095 if (L1MuGMTConfig::Debug(2))
0096 edm::LogVerbatim("GMT_info") << "creating GMT Matcher (0,1)";
0097 m_Matcher[0] = new L1MuGMTMatcher(*this, 0);
0098 m_Matcher[1] = new L1MuGMTMatcher(*this, 1);
0099
0100
0101 if (L1MuGMTConfig::Debug(2))
0102 edm::LogVerbatim("GMT_info") << "creating GMT Cancel Out Unit (0,1,2,3)";
0103 m_CancelOutUnit[0] = new L1MuGMTCancelOutUnit(*this, 0);
0104 m_CancelOutUnit[1] = new L1MuGMTCancelOutUnit(*this, 1);
0105 m_CancelOutUnit[2] = new L1MuGMTCancelOutUnit(*this, 2);
0106 m_CancelOutUnit[3] = new L1MuGMTCancelOutUnit(*this, 3);
0107
0108
0109 if (L1MuGMTConfig::Debug(2))
0110 edm::LogVerbatim("GMT_info") << "creating GMT MIP & ISO bit Assigment Unit (0,1)";
0111 m_MipIsoAU[0] = new L1MuGMTMipIsoAU(*this, 0);
0112 m_MipIsoAU[1] = new L1MuGMTMipIsoAU(*this, 1);
0113
0114
0115 if (L1MuGMTConfig::Debug(2))
0116 edm::LogVerbatim("GMT_info") << "creating GMT Merger (0,1)";
0117 m_Merger[0] = new L1MuGMTMerger(*this, 0);
0118 m_Merger[1] = new L1MuGMTMerger(*this, 1);
0119
0120
0121 if (L1MuGMTConfig::Debug(2))
0122 edm::LogVerbatim("GMT_info") << "creating GMT Sorter";
0123 m_Sorter = new L1MuGMTSorter(*this);
0124
0125 if (!m_db.load()) {
0126 auto config = m_config.load();
0127 auto temp = std::make_shared<L1MuGMTDebugBlock>(config->getBxMin(), config->getBxMax());
0128 std::shared_ptr<L1MuGMTDebugBlock> expected = nullptr;
0129 m_db.compare_exchange_strong(expected, temp, std::memory_order_acq_rel, std::memory_order_acquire);
0130 }
0131 usesResource("L1MuGlobalMuonTrigger");
0132
0133 m_gmtScalesToken = esConsumes<L1MuGMTScales, L1MuGMTScalesRcd>();
0134 m_trigScalesToken = esConsumes<L1MuTriggerScales, L1MuTriggerScalesRcd>();
0135 m_trigPtScaleToken = esConsumes<L1MuTriggerPtScale, L1MuTriggerPtScaleRcd>();
0136 m_gmtParamsToken = esConsumes<L1MuGMTParameters, L1MuGMTParametersRcd>();
0137 m_gmtChanMaskToken = esConsumes<L1MuGMTChannelMask, L1MuGMTChannelMaskRcd>();
0138 m_caloGeomToken = esConsumes<L1CaloGeometry, L1CaloGeometryRecord>();
0139 }
0140
0141
0142
0143
0144 L1MuGlobalMuonTrigger::~L1MuGlobalMuonTrigger() {
0145 delete m_Sorter;
0146 delete m_Merger[1];
0147 delete m_Merger[0];
0148 delete m_MipIsoAU[1];
0149 delete m_MipIsoAU[0];
0150 delete m_CancelOutUnit[3];
0151 delete m_CancelOutUnit[2];
0152 delete m_CancelOutUnit[1];
0153 delete m_CancelOutUnit[0];
0154 delete m_Matcher[1];
0155 delete m_Matcher[0];
0156 delete m_PSB;
0157
0158
0159 std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
0160 for (; irr != m_ReadoutRingbuffer.end(); irr++)
0161 delete (*irr);
0162 m_ReadoutRingbuffer.clear();
0163
0164 }
0165
0166
0167
0168
0169
0170 void L1MuGlobalMuonTrigger::beginJob() {}
0171
0172 void L1MuGlobalMuonTrigger::produce(edm::Event& e, const edm::EventSetup& es) {
0173
0174
0175 unsigned long long L1MuGMTScalesCacheID = es.get<L1MuGMTScalesRcd>().cacheIdentifier();
0176 auto config = m_config.load();
0177 if (L1MuGMTScalesCacheID != m_L1MuGMTScalesCacheID) {
0178 edm::ESHandle<L1MuGMTScales> gmtscales_h = es.getHandle(m_gmtScalesToken);
0179 config->setGMTScales(gmtscales_h.product());
0180 }
0181
0182 unsigned long long L1MuTriggerScalesCacheID = es.get<L1MuTriggerScalesRcd>().cacheIdentifier();
0183 if (L1MuTriggerScalesCacheID != m_L1MuTriggerScalesCacheID) {
0184 edm::ESHandle<L1MuTriggerScales> trigscales_h = es.getHandle(m_trigScalesToken);
0185 config->setTriggerScales(trigscales_h.product());
0186 }
0187
0188 unsigned long long L1MuTriggerPtScaleCacheID = es.get<L1MuTriggerPtScaleRcd>().cacheIdentifier();
0189 if (L1MuTriggerPtScaleCacheID != m_L1MuTriggerPtScaleCacheID) {
0190 edm::ESHandle<L1MuTriggerPtScale> trigptscale_h = es.getHandle(m_trigPtScaleToken);
0191 config->setTriggerPtScale(trigptscale_h.product());
0192 }
0193
0194 unsigned long long L1MuGMTParametersCacheID = es.get<L1MuGMTParametersRcd>().cacheIdentifier();
0195 if (L1MuGMTParametersCacheID != m_L1MuGMTParametersCacheID) {
0196 edm::ESHandle<L1MuGMTParameters> gmtparams_h = es.getHandle(m_gmtParamsToken);
0197 config->setGMTParams(gmtparams_h.product());
0198 config->setDefaults();
0199 }
0200
0201 unsigned long long L1MuGMTChannelMaskCacheID = es.get<L1MuGMTChannelMaskRcd>().cacheIdentifier();
0202 if (L1MuGMTChannelMaskCacheID != m_L1MuGMTChannelMaskCacheID) {
0203 edm::ESHandle<L1MuGMTChannelMask> gmtchanmask_h = es.getHandle(m_gmtChanMaskToken);
0204 config->setGMTChanMask(gmtchanmask_h.product());
0205 if (L1MuGMTConfig::Debug(1)) {
0206 std::string onoff;
0207 const L1MuGMTChannelMask* theChannelMask = L1MuGMTConfig::getGMTChanMask();
0208 unsigned mask = theChannelMask->getSubsystemMask();
0209
0210 edm::LogVerbatim("GMT_info");
0211 edm::LogVerbatim("GMT_info") << " GMT input Channel Mask:" << std::hex << mask << std::dec;
0212 onoff = mask & 1 ? "OFF" : "ON";
0213 edm::LogVerbatim("GMT_info") << " DT input " << onoff;
0214 onoff = mask & 2 ? "OFF" : "ON";
0215 edm::LogVerbatim("GMT_info") << " RPCb input " << onoff;
0216 onoff = mask & 4 ? "OFF" : "ON";
0217 edm::LogVerbatim("GMT_info") << " CSC input " << onoff;
0218 onoff = mask & 8 ? "OFF" : "ON";
0219 edm::LogVerbatim("GMT_info") << " RPCf input " << onoff;
0220 edm::LogVerbatim("GMT_info");
0221 }
0222 }
0223
0224 unsigned long long L1CaloGeometryCacheID = es.get<L1CaloGeometryRecord>().cacheIdentifier();
0225 if (L1CaloGeometryCacheID != m_L1CaloGeometryCacheID) {
0226 edm::ESHandle<L1CaloGeometry> caloGeom_h = es.getHandle(m_caloGeomToken);
0227 config->setCaloGeom(caloGeom_h.product());
0228 }
0229
0230 config->createLUTsRegs();
0231
0232
0233
0234 if (m_writeLUTsAndRegs) {
0235 std::string dir = "gmtconfig";
0236
0237 mkdir(dir.c_str(), S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR);
0238
0239 config->dumpLUTs(dir);
0240 config->dumpRegs(dir);
0241 }
0242
0243
0244 if (L1MuGMTConfig::Debug(2))
0245 edm::LogVerbatim("GMT_info");
0246 if (L1MuGMTConfig::Debug(2))
0247 edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger processing ****";
0248 if (L1MuGMTConfig::Debug(2))
0249 edm::LogVerbatim("GMT_info");
0250
0251 int bx_min = L1MuGMTConfig::getBxMin();
0252 int bx_max = L1MuGMTConfig::getBxMax();
0253
0254 m_ExtendedCands.clear();
0255
0256
0257 std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
0258 for (; irr != m_ReadoutRingbuffer.end(); irr++)
0259 delete (*irr);
0260 m_ReadoutRingbuffer.clear();
0261
0262 auto x_db = m_db.load();
0263 if (x_db)
0264 x_db->reset();
0265
0266 for (int bx = bx_min; bx <= bx_max; bx++) {
0267 x_db->SetBX(bx);
0268
0269
0270 m_ReadoutRingbuffer.push_back(new L1MuGMTReadoutRecord(bx));
0271
0272 if (L1MuGMTConfig::Debug(2))
0273 edm::LogVerbatim("GMT_info") << "L1GlobalMuonTrigger processing bunch-crossing : " << bx;
0274
0275
0276 if (L1MuGMTConfig::Debug(2))
0277 edm::LogVerbatim("GMT_info") << "running GMT PSB";
0278 if (m_PSB) {
0279 m_PSB->receiveData(e, bx);
0280 if (L1MuGMTConfig::Debug(4))
0281 m_PSB->print();
0282 }
0283
0284 if (m_PSB && !m_PSB->empty()) {
0285
0286 if (L1MuGMTConfig::Debug(2))
0287 edm::LogVerbatim("GMT_info") << "running GMT barrel Matcher";
0288 if (m_Matcher[0])
0289 m_Matcher[0]->run();
0290 if (L1MuGMTConfig::Debug(3) && m_Matcher[0])
0291 m_Matcher[0]->print();
0292 if (L1MuGMTConfig::Debug(2))
0293 edm::LogVerbatim("GMT_info") << "running GMT endcap Matcher";
0294 if (m_Matcher[1])
0295 m_Matcher[1]->run();
0296 if (L1MuGMTConfig::Debug(3) && m_Matcher[1])
0297 m_Matcher[1]->print();
0298
0299
0300 if (L1MuGMTConfig::Debug(2))
0301 edm::LogVerbatim("GMT_info") << "running GMT barrel Cancel Out Unit";
0302 if (m_CancelOutUnit[0])
0303 m_CancelOutUnit[0]->run();
0304 if (L1MuGMTConfig::Debug(3) && m_CancelOutUnit[0])
0305 m_CancelOutUnit[0]->print();
0306
0307 if (L1MuGMTConfig::Debug(2))
0308 edm::LogVerbatim("GMT_info") << "running GMT endcap Cancel Out Unit";
0309 if (m_CancelOutUnit[1])
0310 m_CancelOutUnit[1]->run();
0311 if (L1MuGMTConfig::Debug(3) && m_CancelOutUnit[1])
0312 m_CancelOutUnit[1]->print();
0313
0314 if (L1MuGMTConfig::Debug(2))
0315 edm::LogVerbatim("GMT_info") << "running GMT CSC/fRPC Cancel Out Unit";
0316 if (m_CancelOutUnit[2])
0317 m_CancelOutUnit[2]->run();
0318 if (L1MuGMTConfig::Debug(3) && m_CancelOutUnit[2])
0319 m_CancelOutUnit[2]->print();
0320
0321 if (L1MuGMTConfig::Debug(2))
0322 edm::LogVerbatim("GMT_info") << "running GMT DT/bRPC Cancel Out Unit";
0323 if (m_CancelOutUnit[3])
0324 m_CancelOutUnit[3]->run();
0325 if (L1MuGMTConfig::Debug(3) && m_CancelOutUnit[3])
0326 m_CancelOutUnit[3]->print();
0327
0328
0329 if (L1MuGMTConfig::Debug(2))
0330 edm::LogVerbatim("GMT_info") << "running GMT barrel MIP & ISO bit Assignment Unit";
0331 if (m_MipIsoAU[0])
0332 m_MipIsoAU[0]->run();
0333 if (L1MuGMTConfig::Debug(3) && m_MipIsoAU[0])
0334 m_MipIsoAU[0]->print();
0335 if (L1MuGMTConfig::Debug(2))
0336 edm::LogVerbatim("GMT_info") << "running GMT endcap MIP & ISO bit Assignment Unit";
0337 if (m_MipIsoAU[1])
0338 m_MipIsoAU[1]->run();
0339 if (L1MuGMTConfig::Debug(3) && m_MipIsoAU[1])
0340 m_MipIsoAU[1]->print();
0341
0342
0343 if (L1MuGMTConfig::Debug(2))
0344 edm::LogVerbatim("GMT_info") << "running GMT barrel Merger";
0345 if (m_Merger[0])
0346 m_Merger[0]->run();
0347 if (L1MuGMTConfig::Debug(3) && m_Merger[0])
0348 m_Merger[0]->print();
0349 if (L1MuGMTConfig::Debug(2))
0350 edm::LogVerbatim("GMT_info") << "running GMT endcap Merger";
0351 if (m_Merger[1])
0352 m_Merger[1]->run();
0353 if (L1MuGMTConfig::Debug(3) && m_Merger[1])
0354 m_Merger[1]->print();
0355
0356
0357 if (L1MuGMTConfig::Debug(2))
0358 edm::LogVerbatim("GMT_info") << "running GMT Sorter";
0359 if (m_Sorter)
0360 m_Sorter->run();
0361 if (L1MuGMTConfig::Debug(1) && m_Sorter)
0362 m_Sorter->print();
0363
0364
0365 if (m_Sorter && m_Sorter->numberOfCands() > 0) {
0366 const std::vector<const L1MuGMTExtendedCand*>& gmt_cont = m_Sorter->Cands();
0367 std::vector<const L1MuGMTExtendedCand*>::const_iterator iexc;
0368 for (iexc = gmt_cont.begin(); iexc != gmt_cont.end(); iexc++) {
0369 if (*iexc)
0370 m_ExtendedCands.push_back(**iexc);
0371 }
0372 }
0373
0374
0375 reset();
0376 }
0377 }
0378
0379
0380 std::unique_ptr<std::vector<L1MuGMTCand>> GMTCands(new std::vector<L1MuGMTCand>);
0381 std::vector<L1MuGMTExtendedCand>::const_iterator iexc;
0382 for (iexc = m_ExtendedCands.begin(); iexc != m_ExtendedCands.end(); iexc++) {
0383 GMTCands->push_back(*iexc);
0384 }
0385 e.put(std::move(GMTCands));
0386
0387 std::unique_ptr<L1MuGMTReadoutCollection> GMTRRC(getReadoutCollection());
0388 e.put(std::move(GMTRRC));
0389
0390 if (m_sendMipIso) {
0391 std::unique_ptr<std::vector<unsigned>> mipiso(new std::vector<unsigned>);
0392 for (int i = 0; i < 32; i++) {
0393 mipiso->push_back(x_db->IsMIPISO(0, i));
0394 }
0395 e.put(std::move(mipiso));
0396 }
0397
0398
0399 config->clearLUTsRegs();
0400 }
0401
0402
0403
0404
0405 void L1MuGlobalMuonTrigger::reset() {
0406 if (m_PSB)
0407 m_PSB->reset();
0408 if (m_Matcher[0])
0409 m_Matcher[0]->reset();
0410 if (m_Matcher[1])
0411 m_Matcher[1]->reset();
0412 if (m_CancelOutUnit[0])
0413 m_CancelOutUnit[0]->reset();
0414 if (m_CancelOutUnit[1])
0415 m_CancelOutUnit[1]->reset();
0416 if (m_CancelOutUnit[2])
0417 m_CancelOutUnit[2]->reset();
0418 if (m_CancelOutUnit[3])
0419 m_CancelOutUnit[3]->reset();
0420 if (m_MipIsoAU[0])
0421 m_MipIsoAU[0]->reset();
0422 if (m_MipIsoAU[1])
0423 m_MipIsoAU[1]->reset();
0424 if (m_Merger[0])
0425 m_Merger[0]->reset();
0426 if (m_Merger[1])
0427 m_Merger[1]->reset();
0428 if (m_Sorter)
0429 m_Sorter->reset();
0430 }
0431
0432
0433 std::unique_ptr<L1MuGMTReadoutCollection> L1MuGlobalMuonTrigger::getReadoutCollection() {
0434 int bx_min_ro = L1MuGMTConfig::getBxMinRo();
0435 int bx_max_ro = L1MuGMTConfig::getBxMaxRo();
0436 int bx_size = bx_max_ro - bx_min_ro + 1;
0437
0438 std::unique_ptr<L1MuGMTReadoutCollection> rrc(new L1MuGMTReadoutCollection(bx_size));
0439
0440 for (int bx = bx_min_ro; bx <= bx_max_ro; bx++) {
0441 std::vector<L1MuGMTReadoutRecord*>::const_iterator iter = m_ReadoutRingbuffer.begin();
0442
0443 for (; iter != m_ReadoutRingbuffer.end(); iter++) {
0444 if ((*iter)->getBxInEvent() == bx) {
0445 rrc->addRecord(**iter);
0446 break;
0447 }
0448 }
0449 }
0450
0451 return rrc;
0452 }
0453
0454
0455
0456 std::atomic<std::shared_ptr<L1MuGMTConfig>> L1MuGlobalMuonTrigger::m_config;
0457 std::atomic<std::shared_ptr<L1MuGMTDebugBlock>> L1MuGlobalMuonTrigger::m_db;