File indexing completed on 2024-09-22 22:37:18
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 (not m_config) {
0075 auto temp = std::make_shared<L1MuGMTConfig>(ps);
0076 std::shared_ptr<L1MuGMTConfig> empty;
0077 std::atomic_compare_exchange_strong(&m_config, &empty, temp);
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 (not m_db) {
0126 auto temp = std::make_shared<L1MuGMTDebugBlock>(m_config->getBxMin(), m_config->getBxMax());
0127 std::shared_ptr<L1MuGMTDebugBlock> empty;
0128 std::atomic_compare_exchange_strong(&m_db, &empty, temp);
0129 }
0130 usesResource("L1MuGlobalMuonTrigger");
0131
0132 m_gmtScalesToken = esConsumes<L1MuGMTScales, L1MuGMTScalesRcd>();
0133 m_trigScalesToken = esConsumes<L1MuTriggerScales, L1MuTriggerScalesRcd>();
0134 m_trigPtScaleToken = esConsumes<L1MuTriggerPtScale, L1MuTriggerPtScaleRcd>();
0135 m_gmtParamsToken = esConsumes<L1MuGMTParameters, L1MuGMTParametersRcd>();
0136 m_gmtChanMaskToken = esConsumes<L1MuGMTChannelMask, L1MuGMTChannelMaskRcd>();
0137 m_caloGeomToken = esConsumes<L1CaloGeometry, L1CaloGeometryRecord>();
0138 }
0139
0140
0141
0142
0143 L1MuGlobalMuonTrigger::~L1MuGlobalMuonTrigger() {
0144 delete m_Sorter;
0145 delete m_Merger[1];
0146 delete m_Merger[0];
0147 delete m_MipIsoAU[1];
0148 delete m_MipIsoAU[0];
0149 delete m_CancelOutUnit[3];
0150 delete m_CancelOutUnit[2];
0151 delete m_CancelOutUnit[1];
0152 delete m_CancelOutUnit[0];
0153 delete m_Matcher[1];
0154 delete m_Matcher[0];
0155 delete m_PSB;
0156
0157
0158 std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
0159 for (; irr != m_ReadoutRingbuffer.end(); irr++)
0160 delete (*irr);
0161 m_ReadoutRingbuffer.clear();
0162
0163 }
0164
0165
0166
0167
0168
0169 void L1MuGlobalMuonTrigger::beginJob() {}
0170
0171 void L1MuGlobalMuonTrigger::produce(edm::Event& e, const edm::EventSetup& es) {
0172
0173
0174 unsigned long long L1MuGMTScalesCacheID = es.get<L1MuGMTScalesRcd>().cacheIdentifier();
0175 if (L1MuGMTScalesCacheID != m_L1MuGMTScalesCacheID) {
0176 edm::ESHandle<L1MuGMTScales> gmtscales_h = es.getHandle(m_gmtScalesToken);
0177 m_config->setGMTScales(gmtscales_h.product());
0178 }
0179
0180 unsigned long long L1MuTriggerScalesCacheID = es.get<L1MuTriggerScalesRcd>().cacheIdentifier();
0181 if (L1MuTriggerScalesCacheID != m_L1MuTriggerScalesCacheID) {
0182 edm::ESHandle<L1MuTriggerScales> trigscales_h = es.getHandle(m_trigScalesToken);
0183 m_config->setTriggerScales(trigscales_h.product());
0184 }
0185
0186 unsigned long long L1MuTriggerPtScaleCacheID = es.get<L1MuTriggerPtScaleRcd>().cacheIdentifier();
0187 if (L1MuTriggerPtScaleCacheID != m_L1MuTriggerPtScaleCacheID) {
0188 edm::ESHandle<L1MuTriggerPtScale> trigptscale_h = es.getHandle(m_trigPtScaleToken);
0189 m_config->setTriggerPtScale(trigptscale_h.product());
0190 }
0191
0192 unsigned long long L1MuGMTParametersCacheID = es.get<L1MuGMTParametersRcd>().cacheIdentifier();
0193 if (L1MuGMTParametersCacheID != m_L1MuGMTParametersCacheID) {
0194 edm::ESHandle<L1MuGMTParameters> gmtparams_h = es.getHandle(m_gmtParamsToken);
0195 m_config->setGMTParams(gmtparams_h.product());
0196 m_config->setDefaults();
0197 }
0198
0199 unsigned long long L1MuGMTChannelMaskCacheID = es.get<L1MuGMTChannelMaskRcd>().cacheIdentifier();
0200 if (L1MuGMTChannelMaskCacheID != m_L1MuGMTChannelMaskCacheID) {
0201 edm::ESHandle<L1MuGMTChannelMask> gmtchanmask_h = es.getHandle(m_gmtChanMaskToken);
0202 m_config->setGMTChanMask(gmtchanmask_h.product());
0203 if (L1MuGMTConfig::Debug(1)) {
0204 std::string onoff;
0205 const L1MuGMTChannelMask* theChannelMask = L1MuGMTConfig::getGMTChanMask();
0206 unsigned mask = theChannelMask->getSubsystemMask();
0207
0208 edm::LogVerbatim("GMT_info");
0209 edm::LogVerbatim("GMT_info") << " GMT input Channel Mask:" << std::hex << mask << std::dec;
0210 onoff = mask & 1 ? "OFF" : "ON";
0211 edm::LogVerbatim("GMT_info") << " DT input " << onoff;
0212 onoff = mask & 2 ? "OFF" : "ON";
0213 edm::LogVerbatim("GMT_info") << " RPCb input " << onoff;
0214 onoff = mask & 4 ? "OFF" : "ON";
0215 edm::LogVerbatim("GMT_info") << " CSC input " << onoff;
0216 onoff = mask & 8 ? "OFF" : "ON";
0217 edm::LogVerbatim("GMT_info") << " RPCf input " << onoff;
0218 edm::LogVerbatim("GMT_info");
0219 }
0220 }
0221
0222 unsigned long long L1CaloGeometryCacheID = es.get<L1CaloGeometryRecord>().cacheIdentifier();
0223 if (L1CaloGeometryCacheID != m_L1CaloGeometryCacheID) {
0224 edm::ESHandle<L1CaloGeometry> caloGeom_h = es.getHandle(m_caloGeomToken);
0225 m_config->setCaloGeom(caloGeom_h.product());
0226 }
0227
0228 m_config->createLUTsRegs();
0229
0230
0231
0232 if (m_writeLUTsAndRegs) {
0233 std::string dir = "gmtconfig";
0234
0235 mkdir(dir.c_str(), S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR);
0236
0237 m_config->dumpLUTs(dir);
0238 m_config->dumpRegs(dir);
0239 }
0240
0241
0242 if (L1MuGMTConfig::Debug(2))
0243 edm::LogVerbatim("GMT_info");
0244 if (L1MuGMTConfig::Debug(2))
0245 edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger processing ****";
0246 if (L1MuGMTConfig::Debug(2))
0247 edm::LogVerbatim("GMT_info");
0248
0249 int bx_min = L1MuGMTConfig::getBxMin();
0250 int bx_max = L1MuGMTConfig::getBxMax();
0251
0252 m_ExtendedCands.clear();
0253
0254
0255 std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
0256 for (; irr != m_ReadoutRingbuffer.end(); irr++)
0257 delete (*irr);
0258 m_ReadoutRingbuffer.clear();
0259
0260 if (m_db)
0261 m_db->reset();
0262
0263 for (int bx = bx_min; bx <= bx_max; bx++) {
0264 m_db->SetBX(bx);
0265
0266
0267 m_ReadoutRingbuffer.push_back(new L1MuGMTReadoutRecord(bx));
0268
0269 if (L1MuGMTConfig::Debug(2))
0270 edm::LogVerbatim("GMT_info") << "L1GlobalMuonTrigger processing bunch-crossing : " << bx;
0271
0272
0273 if (L1MuGMTConfig::Debug(2))
0274 edm::LogVerbatim("GMT_info") << "running GMT PSB";
0275 if (m_PSB) {
0276 m_PSB->receiveData(e, bx);
0277 if (L1MuGMTConfig::Debug(4))
0278 m_PSB->print();
0279 }
0280
0281 if (m_PSB && !m_PSB->empty()) {
0282
0283 if (L1MuGMTConfig::Debug(2))
0284 edm::LogVerbatim("GMT_info") << "running GMT barrel Matcher";
0285 if (m_Matcher[0])
0286 m_Matcher[0]->run();
0287 if (L1MuGMTConfig::Debug(3) && m_Matcher[0])
0288 m_Matcher[0]->print();
0289 if (L1MuGMTConfig::Debug(2))
0290 edm::LogVerbatim("GMT_info") << "running GMT endcap Matcher";
0291 if (m_Matcher[1])
0292 m_Matcher[1]->run();
0293 if (L1MuGMTConfig::Debug(3) && m_Matcher[1])
0294 m_Matcher[1]->print();
0295
0296
0297 if (L1MuGMTConfig::Debug(2))
0298 edm::LogVerbatim("GMT_info") << "running GMT barrel Cancel Out Unit";
0299 if (m_CancelOutUnit[0])
0300 m_CancelOutUnit[0]->run();
0301 if (L1MuGMTConfig::Debug(3) && m_CancelOutUnit[0])
0302 m_CancelOutUnit[0]->print();
0303
0304 if (L1MuGMTConfig::Debug(2))
0305 edm::LogVerbatim("GMT_info") << "running GMT endcap Cancel Out Unit";
0306 if (m_CancelOutUnit[1])
0307 m_CancelOutUnit[1]->run();
0308 if (L1MuGMTConfig::Debug(3) && m_CancelOutUnit[1])
0309 m_CancelOutUnit[1]->print();
0310
0311 if (L1MuGMTConfig::Debug(2))
0312 edm::LogVerbatim("GMT_info") << "running GMT CSC/fRPC Cancel Out Unit";
0313 if (m_CancelOutUnit[2])
0314 m_CancelOutUnit[2]->run();
0315 if (L1MuGMTConfig::Debug(3) && m_CancelOutUnit[2])
0316 m_CancelOutUnit[2]->print();
0317
0318 if (L1MuGMTConfig::Debug(2))
0319 edm::LogVerbatim("GMT_info") << "running GMT DT/bRPC Cancel Out Unit";
0320 if (m_CancelOutUnit[3])
0321 m_CancelOutUnit[3]->run();
0322 if (L1MuGMTConfig::Debug(3) && m_CancelOutUnit[3])
0323 m_CancelOutUnit[3]->print();
0324
0325
0326 if (L1MuGMTConfig::Debug(2))
0327 edm::LogVerbatim("GMT_info") << "running GMT barrel MIP & ISO bit Assignment Unit";
0328 if (m_MipIsoAU[0])
0329 m_MipIsoAU[0]->run();
0330 if (L1MuGMTConfig::Debug(3) && m_MipIsoAU[0])
0331 m_MipIsoAU[0]->print();
0332 if (L1MuGMTConfig::Debug(2))
0333 edm::LogVerbatim("GMT_info") << "running GMT endcap MIP & ISO bit Assignment Unit";
0334 if (m_MipIsoAU[1])
0335 m_MipIsoAU[1]->run();
0336 if (L1MuGMTConfig::Debug(3) && m_MipIsoAU[1])
0337 m_MipIsoAU[1]->print();
0338
0339
0340 if (L1MuGMTConfig::Debug(2))
0341 edm::LogVerbatim("GMT_info") << "running GMT barrel Merger";
0342 if (m_Merger[0])
0343 m_Merger[0]->run();
0344 if (L1MuGMTConfig::Debug(3) && m_Merger[0])
0345 m_Merger[0]->print();
0346 if (L1MuGMTConfig::Debug(2))
0347 edm::LogVerbatim("GMT_info") << "running GMT endcap Merger";
0348 if (m_Merger[1])
0349 m_Merger[1]->run();
0350 if (L1MuGMTConfig::Debug(3) && m_Merger[1])
0351 m_Merger[1]->print();
0352
0353
0354 if (L1MuGMTConfig::Debug(2))
0355 edm::LogVerbatim("GMT_info") << "running GMT Sorter";
0356 if (m_Sorter)
0357 m_Sorter->run();
0358 if (L1MuGMTConfig::Debug(1) && m_Sorter)
0359 m_Sorter->print();
0360
0361
0362 if (m_Sorter && m_Sorter->numberOfCands() > 0) {
0363 const std::vector<const L1MuGMTExtendedCand*>& gmt_cont = m_Sorter->Cands();
0364 std::vector<const L1MuGMTExtendedCand*>::const_iterator iexc;
0365 for (iexc = gmt_cont.begin(); iexc != gmt_cont.end(); iexc++) {
0366 if (*iexc)
0367 m_ExtendedCands.push_back(**iexc);
0368 }
0369 }
0370
0371
0372 reset();
0373 }
0374 }
0375
0376
0377 std::unique_ptr<std::vector<L1MuGMTCand> > GMTCands(new std::vector<L1MuGMTCand>);
0378 std::vector<L1MuGMTExtendedCand>::const_iterator iexc;
0379 for (iexc = m_ExtendedCands.begin(); iexc != m_ExtendedCands.end(); iexc++) {
0380 GMTCands->push_back(*iexc);
0381 }
0382 e.put(std::move(GMTCands));
0383
0384 std::unique_ptr<L1MuGMTReadoutCollection> GMTRRC(getReadoutCollection());
0385 e.put(std::move(GMTRRC));
0386
0387 if (m_sendMipIso) {
0388 std::unique_ptr<std::vector<unsigned> > mipiso(new std::vector<unsigned>);
0389 for (int i = 0; i < 32; i++) {
0390 mipiso->push_back(m_db->IsMIPISO(0, i));
0391 }
0392 e.put(std::move(mipiso));
0393 }
0394
0395
0396 m_config->clearLUTsRegs();
0397 }
0398
0399
0400
0401
0402 void L1MuGlobalMuonTrigger::reset() {
0403 if (m_PSB)
0404 m_PSB->reset();
0405 if (m_Matcher[0])
0406 m_Matcher[0]->reset();
0407 if (m_Matcher[1])
0408 m_Matcher[1]->reset();
0409 if (m_CancelOutUnit[0])
0410 m_CancelOutUnit[0]->reset();
0411 if (m_CancelOutUnit[1])
0412 m_CancelOutUnit[1]->reset();
0413 if (m_CancelOutUnit[2])
0414 m_CancelOutUnit[2]->reset();
0415 if (m_CancelOutUnit[3])
0416 m_CancelOutUnit[3]->reset();
0417 if (m_MipIsoAU[0])
0418 m_MipIsoAU[0]->reset();
0419 if (m_MipIsoAU[1])
0420 m_MipIsoAU[1]->reset();
0421 if (m_Merger[0])
0422 m_Merger[0]->reset();
0423 if (m_Merger[1])
0424 m_Merger[1]->reset();
0425 if (m_Sorter)
0426 m_Sorter->reset();
0427 }
0428
0429
0430 std::unique_ptr<L1MuGMTReadoutCollection> L1MuGlobalMuonTrigger::getReadoutCollection() {
0431 int bx_min_ro = L1MuGMTConfig::getBxMinRo();
0432 int bx_max_ro = L1MuGMTConfig::getBxMaxRo();
0433 int bx_size = bx_max_ro - bx_min_ro + 1;
0434
0435 std::unique_ptr<L1MuGMTReadoutCollection> rrc(new L1MuGMTReadoutCollection(bx_size));
0436
0437 for (int bx = bx_min_ro; bx <= bx_max_ro; bx++) {
0438 std::vector<L1MuGMTReadoutRecord*>::const_iterator iter = m_ReadoutRingbuffer.begin();
0439
0440 for (; iter != m_ReadoutRingbuffer.end(); iter++) {
0441 if ((*iter)->getBxInEvent() == bx) {
0442 rrc->addRecord(**iter);
0443 break;
0444 }
0445 }
0446 }
0447
0448 return rrc;
0449 }
0450
0451
0452
0453 std::shared_ptr<L1MuGMTConfig> L1MuGlobalMuonTrigger::m_config;
0454 std::shared_ptr<L1MuGMTDebugBlock> L1MuGlobalMuonTrigger::m_db;