File indexing completed on 2024-04-06 12:21:08
0001 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/OMTFinputMaker.h"
0002 #include "L1Trigger/L1TMuonOverlapPhase1/interface/MuonStub.h"
0003 #include "L1Trigger/L1TMuonOverlapPhase1/interface/ProcConfigurationBase.h"
0004
0005 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigi.h"
0006 #include "DataFormats/DetId/interface/DetId.h"
0007 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhDigi.h"
0008 #include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h"
0009 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0010 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0011 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0012 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015
0016 #include <map>
0017 #include <sstream>
0018 #include <string>
0019
0020
0021 void DtDigiToStubsConverterOmtf::addDTphiDigi(MuonStubPtrs2D& muonStubsInLayers,
0022 const L1MuDTChambPhDigi& digi,
0023 const L1MuDTChambThContainer* dtThDigis,
0024 unsigned int iProcessor,
0025 l1t::tftype procTyp) {
0026 DTChamberId detid(digi.whNum(), digi.stNum(), digi.scNum() + 1);
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 if (digi.code() == 7 || digi.code() < config->getMinDtPhiQuality())
0038 return;
0039
0040 unsigned int hwNumber = config->getLayerNumber(detid.rawId());
0041 if (config->getHwToLogicLayer().find(hwNumber) == config->getHwToLogicLayer().end())
0042 return;
0043
0044 auto iter = config->getHwToLogicLayer().find(hwNumber);
0045 unsigned int iLayer = iter->second;
0046 unsigned int iInput = OMTFinputMaker::getInputNumber(config, detid.rawId(), iProcessor, procTyp);
0047
0048 MuonStub stub;
0049
0050 stub.type = MuonStub::DT_PHI_ETA;
0051 stub.qualityHw = digi.code();
0052 stub.phiHw = angleConverter->getProcessorPhi(
0053 OMTFinputMaker::getProcessorPhiZero(config, iProcessor), procTyp, digi.scNum(), digi.phi());
0054 stub.etaHw = angleConverter->getGlobalEta(detid, dtThDigis, digi.bxNum());
0055
0056
0057
0058 stub.phiBHw = digi.phiB();
0059
0060 stub.bx = digi.bxNum();
0061
0062
0063
0064 stub.logicLayer = iLayer;
0065 stub.detId = detid;
0066
0067 OMTFinputMaker::addStub(config, muonStubsInLayers, iLayer, iInput, stub);
0068 }
0069
0070 void DtDigiToStubsConverterOmtf::addDTetaStubs(MuonStubPtrs2D& muonStubsInLayers,
0071 const L1MuDTChambThDigi& thetaDigi,
0072 unsigned int iProcessor,
0073 l1t::tftype procTyp) {
0074
0075 }
0076
0077 bool DtDigiToStubsConverterOmtf::acceptDigi(const DTChamberId& dTChamberId,
0078 unsigned int iProcessor,
0079 l1t::tftype procType) {
0080 return OMTFinputMaker::acceptDtDigi(config, dTChamberId, iProcessor, procType);
0081 }
0082
0083 void CscDigiToStubsConverterOmtf::addCSCstubs(MuonStubPtrs2D& muonStubsInLayers,
0084 unsigned int rawid,
0085 const CSCCorrelatedLCTDigi& digi,
0086 unsigned int iProcessor,
0087 l1t::tftype procTyp) {
0088 unsigned int hwNumber = config->getLayerNumber(rawid);
0089 if (config->getHwToLogicLayer().find(hwNumber) == config->getHwToLogicLayer().end())
0090 return;
0091
0092 unsigned int iLayer = config->getHwToLogicLayer().at(hwNumber);
0093 unsigned int iInput = OMTFinputMaker::getInputNumber(config, rawid, iProcessor, procTyp);
0094
0095 float r = 0;
0096 MuonStub stub;
0097 stub.type = MuonStub::CSC_PHI_ETA;
0098 stub.phiHw = angleConverter->getProcessorPhi(
0099 OMTFinputMaker::getProcessorPhiZero(config, iProcessor), procTyp, CSCDetId(rawid), digi, iInput);
0100 stub.etaHw = angleConverter->getGlobalEta(rawid, digi, r);
0101 stub.r = round(r);
0102 stub.phiBHw = digi.getPattern();
0103 stub.qualityHw = digi.getQuality();
0104
0105 stub.bx = digi.getBX() - config->cscLctCentralBx();
0106
0107
0108
0109 stub.logicLayer = iLayer;
0110 stub.detId = rawid;
0111
0112
0113
0114 if (iLayer == 9) {
0115 if (stub.r >= config->minCSCStubRME12())
0116 OMTFinputMaker::addStub(config, muonStubsInLayers, iLayer, iInput, stub);
0117 } else if (stub.r >= config->minCscStubR()) {
0118 OMTFinputMaker::addStub(config, muonStubsInLayers, iLayer, iInput, stub);
0119 }
0120
0121
0122
0123
0124
0125
0126
0127
0128 }
0129
0130 bool CscDigiToStubsConverterOmtf::acceptDigi(const CSCDetId& csc, unsigned int iProcessor, l1t::tftype procType) {
0131 if (procType == l1t::tftype::omtf_pos && (csc.endcap() == 2 || csc.ring() == 1 || csc.station() == 4))
0132 return false;
0133 if (procType == l1t::tftype::omtf_neg && (csc.endcap() == 1 || csc.ring() == 1 || csc.station() == 4))
0134 return false;
0135
0136 if (procType == l1t::tftype::emtf_pos && (csc.endcap() == 2 || (csc.station() == 1 && csc.ring() == 3)))
0137 return false;
0138 if (procType == l1t::tftype::emtf_neg && (csc.endcap() == 1 || (csc.station() == 1 && csc.ring() == 3)))
0139 return false;
0140
0141 unsigned int aSector = csc.chamber();
0142 unsigned int aMin = config->getEndcap10DegMin()[iProcessor];
0143 unsigned int aMax = config->getEndcap10DegMax()[iProcessor];
0144
0145 if ((procType == l1t::tftype::emtf_pos || procType == l1t::tftype::emtf_neg) && csc.station() > 1 &&
0146 csc.ring() == 1) {
0147 aMin = config->getEndcap20DegMin()[iProcessor];
0148 aMax = config->getEndcap20DegMax()[iProcessor];
0149 }
0150
0151 if (aMax > aMin && aSector >= aMin && aSector <= aMax)
0152 return true;
0153 if (aMax < aMin && (aSector >= aMin || aSector <= aMax))
0154 return true;
0155
0156 return false;
0157 }
0158
0159 void RpcDigiToStubsConverterOmtf::addRPCstub(MuonStubPtrs2D& muonStubsInLayers,
0160 const RPCDetId& roll,
0161 const RpcCluster& cluster,
0162 unsigned int iProcessor,
0163 l1t::tftype procTyp) {
0164 unsigned int rawid = roll.rawId();
0165
0166 unsigned int hwNumber = config->getLayerNumber(rawid);
0167 unsigned int iLayer = config->getHwToLogicLayer().at(hwNumber);
0168 unsigned int iInput = OMTFinputMaker::getInputNumber(config, rawid, iProcessor, procTyp);
0169
0170
0171
0172
0173
0174 MuonStub stub;
0175 stub.type = MuonStub::RPC;
0176 stub.phiHw = angleConverter->getProcessorPhi(
0177 OMTFinputMaker::getProcessorPhiZero(config, iProcessor), procTyp, roll, cluster.firstStrip, cluster.lastStrip);
0178
0179 float r = 0;
0180 stub.etaHw = angleConverter->getGlobalEtaRpc(rawid, cluster.firstStrip, r);
0181 stub.r = round(r);
0182
0183 stub.qualityHw = cluster.size();
0184
0185 stub.bx = cluster.bx;
0186 stub.timing = cluster.timing;
0187
0188
0189 stub.logicLayer = iLayer;
0190 stub.detId = rawid;
0191
0192
0193
0194
0195
0196
0197
0198 if (config->getRpcDropAllClustersIfMoreThanMax()) {
0199
0200 if (muonStubsInLayers[iLayer][iInput + 1]) {
0201
0202 muonStubsInLayers[iLayer][iInput]->type = MuonStub::RPC_DROPPED;
0203 muonStubsInLayers[iLayer][iInput + 1]->type = MuonStub::RPC_DROPPED;
0204 } else if (cluster.size() > config->getRpcMaxClusterSize()) {
0205
0206 if (muonStubsInLayers[iLayer][iInput]) {
0207 muonStubsInLayers[iLayer][iInput]->type = MuonStub::RPC_DROPPED;
0208
0209 muonStubsInLayers[iLayer][iInput + 1] = std::make_shared<MuonStub>(stub);
0210 muonStubsInLayers[iLayer][iInput + 1]->type = MuonStub::RPC_DROPPED;
0211 } else {
0212
0213 muonStubsInLayers[iLayer].at(iInput) = std::make_shared<MuonStub>(stub);
0214 muonStubsInLayers[iLayer][iInput]->type = MuonStub::RPC_DROPPED;
0215
0216 muonStubsInLayers[iLayer][iInput + 1] = std::make_shared<MuonStub>(stub);
0217 muonStubsInLayers[iLayer][iInput + 1]->type = MuonStub::RPC_DROPPED;
0218 }
0219 } else
0220 OMTFinputMaker::addStub(config, muonStubsInLayers, iLayer, iInput, stub);
0221 } else {
0222 if (cluster.size() <= config->getRpcMaxClusterSize())
0223 OMTFinputMaker::addStub(config, muonStubsInLayers, iLayer, iInput, stub);
0224 }
0225
0226 std::ostringstream str;
0227 str << " RPC halfDigi "
0228 << " begin: " << cluster.firstStrip << " end: " << cluster.lastStrip << " iPhi: " << stub.phiHw
0229 << " iEta: " << stub.etaHw << " hwNumber: " << hwNumber << " iInput: " << iInput << " iLayer: " << iLayer
0230 << std::endl;
0231
0232 LogTrace("l1tOmtfEventPrint") << str.str();
0233 }
0234
0235 bool RpcDigiToStubsConverterOmtf::acceptDigi(const RPCDetId& rpcDetId, unsigned int iProcessor, l1t::tftype procType) {
0236 unsigned int aMin = config->getBarrelMin()[iProcessor];
0237 unsigned int aMax = config->getBarrelMax()[iProcessor];
0238
0239 unsigned int aSector = rpcDetId.sector();
0240
0241
0242 if (procType == l1t::tftype::omtf_pos &&
0243 (rpcDetId.region() < 0 || (rpcDetId.region() == 0 && rpcDetId.ring() != 2) ||
0244 (rpcDetId.region() == 0 && rpcDetId.station() == 4) ||
0245 (rpcDetId.region() == 0 && rpcDetId.station() == 2 && rpcDetId.layer() == 2 && rpcDetId.roll() == 1) ||
0246 (rpcDetId.region() == 0 && rpcDetId.station() == 3 && rpcDetId.roll() == 1) ||
0247 (rpcDetId.region() == 1 && rpcDetId.station() == 4) ||
0248
0249 (rpcDetId.region() == 1 && rpcDetId.station() > 0 && rpcDetId.ring() < 3)))
0250 return false;
0251
0252 if (procType == l1t::tftype::omtf_neg &&
0253 (rpcDetId.region() > 0 || (rpcDetId.region() == 0 && rpcDetId.ring() != -2) ||
0254 (rpcDetId.region() == 0 && rpcDetId.station() == 4) ||
0255 (rpcDetId.region() == 0 && rpcDetId.station() == 2 && rpcDetId.layer() == 2 && rpcDetId.roll() == 1) ||
0256 (rpcDetId.region() == 0 && rpcDetId.station() == 3 && rpcDetId.roll() == 1) ||
0257 (rpcDetId.region() == -1 && rpcDetId.station() == 4) ||
0258
0259 (rpcDetId.region() == -1 && rpcDetId.station() > 0 && rpcDetId.ring() < 3)))
0260 return false;
0261
0262 if (procType == l1t::tftype::omtf_pos || procType == l1t::tftype::omtf_neg) {
0263 if (rpcDetId.region() != 0 && rpcDetId.station() == 3) {
0264 unsigned int iInput = OMTFinputMaker::getInputNumber(config, rpcDetId.rawId(), iProcessor, procType);
0265 if (iInput == 0 || iInput == 1)
0266 return false;
0267 }
0268 }
0269
0270 if (procType == l1t::tftype::bmtf && rpcDetId.region() != 0)
0271 return false;
0272
0273 if (procType == l1t::tftype::emtf_pos &&
0274 (rpcDetId.region() <= 0 || (rpcDetId.station() == 1 && rpcDetId.ring() == 3)))
0275 return false;
0276 if (procType == l1t::tftype::emtf_neg &&
0277 (rpcDetId.region() >= 0 || (rpcDetId.station() == 1 && rpcDetId.ring() == 3)))
0278 return false;
0279
0280 if (rpcDetId.region() == 0)
0281 aSector = rpcDetId.sector();
0282 if (rpcDetId.region() != 0) {
0283 aSector = (rpcDetId.sector() - 1) * 6 + rpcDetId.subsector();
0284 aMin = config->getEndcap10DegMin()[iProcessor];
0285 aMax = config->getEndcap10DegMax()[iProcessor];
0286 }
0287
0288 if (aMax > aMin && aSector >= aMin && aSector <= aMax)
0289 return true;
0290 if (aMax < aMin && (aSector >= aMin || aSector <= aMax))
0291 return true;
0292
0293 return false;
0294 }
0295
0296
0297 bool OMTFinputMaker::acceptDtDigi(const OMTFConfiguration* config,
0298 const DTChamberId& dTChamberId,
0299 unsigned int iProcessor,
0300 l1t::tftype procType) {
0301 unsigned int aMin = config->getBarrelMin()[iProcessor];
0302 unsigned int aMax = config->getBarrelMax()[iProcessor];
0303
0304 if (procType == l1t::tftype::omtf_pos && dTChamberId.wheel() != 2)
0305 return false;
0306 if (procType == l1t::tftype::omtf_neg && dTChamberId.wheel() != -2)
0307 return false;
0308 if (procType == l1t::tftype::emtf_pos || procType == l1t::tftype::emtf_neg)
0309 return false;
0310
0311 unsigned int aSector = dTChamberId.sector();
0312
0313 if (aMax > aMin && aSector >= aMin && aSector <= aMax)
0314 return true;
0315 if (aMax < aMin && (aSector >= aMin || aSector <= aMax))
0316 return true;
0317
0318 return false;
0319 }
0320
0321
0322
0323 OMTFinputMaker::OMTFinputMaker(const edm::ParameterSet& edmParameterSet,
0324 MuStubsInputTokens& muStubsInputTokens,
0325 const OMTFConfiguration* config,
0326 std::unique_ptr<OmtfAngleConverter> angleConverter)
0327 : MuonStubMakerBase(config), config(config), angleConverter(std::move(angleConverter)) {
0328 if (!edmParameterSet.getParameter<bool>("dropDTPrimitives"))
0329 digiToStubsConverters.emplace_back(std::make_unique<DtDigiToStubsConverterOmtf>(
0330 config, this->angleConverter.get(), muStubsInputTokens.inputTokenDtPh, muStubsInputTokens.inputTokenDtTh));
0331
0332 if (!edmParameterSet.getParameter<bool>("dropCSCPrimitives"))
0333 digiToStubsConverters.emplace_back(std::make_unique<CscDigiToStubsConverterOmtf>(
0334 config, this->angleConverter.get(), muStubsInputTokens.inputTokenCSC));
0335
0336 if (!edmParameterSet.getParameter<bool>("dropRPCPrimitives"))
0337 digiToStubsConverters.emplace_back(std::make_unique<RpcDigiToStubsConverterOmtf>(
0338 config, this->angleConverter.get(), &rpcClusterization, muStubsInputTokens.inputTokenRPC));
0339 }
0340
0341 void OMTFinputMaker::initialize(const edm::ParameterSet& edmCfg,
0342 const edm::EventSetup& es,
0343 const MuonGeometryTokens& muonGeometryTokens) {
0344 MuonStubMakerBase::initialize(edmCfg, es, muonGeometryTokens);
0345 angleConverter->checkAndUpdateGeometry(es, config, muonGeometryTokens);
0346 }
0347
0348
0349
0350 OMTFinputMaker::~OMTFinputMaker() {}
0351
0352
0353 unsigned int OMTFinputMaker::getInputNumber(const OMTFConfiguration* config,
0354 unsigned int rawId,
0355 unsigned int iProcessor,
0356 l1t::tftype type) {
0357 unsigned int iInput = 99;
0358 unsigned int aSector = 99;
0359 int aMin = config->getBarrelMin()[iProcessor];
0360 int iRoll = 1;
0361 int nInputsPerSector = 2;
0362
0363 DetId detId(rawId);
0364 if (detId.det() != DetId::Muon)
0365 edm::LogError("Critical OMTFinputMaker") << "PROBLEM: hit in unknown Det, detID: " << detId.det() << std::endl;
0366 switch (detId.subdetId()) {
0367 case MuonSubdetId::RPC: {
0368 RPCDetId rpc(rawId);
0369 if (rpc.region() == 0) {
0370 nInputsPerSector = 4;
0371 aSector = rpc.sector();
0372
0373
0374 if (iProcessor == (config->nProcessors() - 1) && aSector < 3)
0375 aSector += 12;
0376
0377 iRoll = rpc.roll();
0378
0379
0380 if (rpc.station() == 2 && rpc.layer() == 2 && rpc.roll() == 2)
0381 iRoll = 1;
0382
0383 if (rpc.station() == 3) {
0384 iRoll = 1;
0385 nInputsPerSector = 2;
0386 }
0387
0388 if (type == l1t::tftype::bmtf)
0389 iRoll = 1;
0390 }
0391 if (rpc.region() != 0) {
0392 aSector = (rpc.sector() - 1) * 6 + rpc.subsector();
0393 aMin = config->getEndcap10DegMin()[iProcessor];
0394
0395
0396 if (iProcessor == (config->nProcessors() - 1) && aSector < 5)
0397 aSector += 36;
0398 }
0399 break;
0400 }
0401 case MuonSubdetId::DT: {
0402 DTChamberId dt(rawId);
0403 aSector = dt.sector();
0404
0405
0406 if (iProcessor == (config->nProcessors() - 1) && aSector < 3)
0407 aSector += 12;
0408 break;
0409 }
0410 case MuonSubdetId::CSC: {
0411 CSCDetId csc(rawId);
0412 aSector = csc.chamber();
0413 aMin = config->getEndcap10DegMin()[iProcessor];
0414
0415
0416 if (iProcessor == (config->nProcessors() - 1) && aSector < 5)
0417 aSector += 36;
0418
0419
0420
0421 if ((type == l1t::tftype::emtf_pos || type == l1t::tftype::emtf_neg) && csc.station() > 1 && csc.ring() == 1) {
0422 aMin = config->getEndcap20DegMin()[iProcessor];
0423 if (iProcessor == (config->nProcessors() - 1) && aSector < 3)
0424 aSector += 18;
0425 }
0426 break;
0427 }
0428 }
0429
0430
0431 iInput = (aSector - aMin) * nInputsPerSector;
0432
0433 iInput += iRoll - 1;
0434
0435 return iInput;
0436 }
0437
0438
0439
0440
0441 int OMTFinputMaker::getProcessorPhiZero(const OMTFConfiguration* config, unsigned int iProcessor) {
0442 unsigned int nPhiBins = config->nPhiBins();
0443
0444 int phiZero =
0445 nPhiBins / config->nProcessors() * (iProcessor) + nPhiBins / 24;
0446
0447
0448 return config->foldPhi(phiZero);
0449 }
0450
0451
0452
0453 void OMTFinputMaker::addStub(const OMTFConfiguration* config,
0454 MuonStubPtrs2D& muonStubsInLayers,
0455 unsigned int iLayer,
0456 unsigned int iInput,
0457 MuonStub& stub) {
0458
0459
0460
0461
0462
0463 if (muonStubsInLayers[iLayer][iInput] && muonStubsInLayers[iLayer][iInput]->phiHw == stub.phiHw &&
0464 muonStubsInLayers[iLayer][iInput]->phiBHw == stub.phiBHw &&
0465 muonStubsInLayers[iLayer][iInput]->etaHw == stub.etaHw) {
0466 LogTrace("OMTFReconstruction") << "addStub: the stub with exactly the same phi, phiB and eta was already added:\n"
0467 << "incomnig stub " << stub << "\n"
0468 << "existing stub " << *(muonStubsInLayers[iLayer][iInput]) << std::endl;
0469
0470 }
0471
0472 if (muonStubsInLayers[iLayer][iInput] && muonStubsInLayers[iLayer][iInput]->phiHw != (int)config->nPhiBins())
0473 ++iInput;
0474
0475 if (muonStubsInLayers[iLayer][iInput] && muonStubsInLayers[iLayer][iInput]->phiHw != (int)config->nPhiBins())
0476 return;
0477
0478
0479 stub.input = iInput;
0480 muonStubsInLayers.at(iLayer).at(iInput) = std::make_shared<MuonStub>(stub);
0481 }