Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-08 03:06:42

0001 #include "L1Trigger/L1TGEM/plugins/ME0StubBuilder.h"
0002 #include "DataFormats/MuonDetId/interface/GEMDetId.h"
0003 #include "DataFormats/GEMDigi/interface/GEMPadDigi.h"
0004 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0005 #include "Geometry/GEMGeometry/interface/GEMEtaPartition.h"
0006 #include "L1Trigger/L1TGEM/interface/ME0StubAlgoChamber.h"
0007 
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 using namespace l1t::me0;
0012 
0013 typedef std::vector<std::vector<UInt192>> ME0ChamberData;
0014 typedef std::vector<std::vector<std::vector<int>>> ME0ChamberBXData;
0015 
0016 ME0StubBuilder::ME0StubBuilder(const edm::ParameterSet& ps) {
0017   skipCentroids_ = ps.getParameter<bool>("skipCentroids");
0018   layerThresholdPatternId_ = ps.getParameter<std::vector<int32_t>>("layerThresholdPatternId");
0019   layerThresholdEta_ = ps.getParameter<std::vector<int32_t>>("layerThresholdEta");
0020   maxSpan_ = ps.getParameter<int32_t>("maxSpan");
0021   width_ = ps.getParameter<int32_t>("width");
0022   deghostPre_ = ps.getParameter<bool>("deghostPre");
0023   deghostPost_ = ps.getParameter<bool>("deghostPost");
0024   groupWidth_ = ps.getParameter<int32_t>("groupWidth");
0025   ghostWidth_ = ps.getParameter<int32_t>("ghostWidth");
0026   xPartitionEnabled_ = ps.getParameter<bool>("xPartitionEnabled");
0027   enableNonPointing_ = ps.getParameter<bool>("enableNonPointing");
0028   crossPartitionSegmentWidth_ = ps.getParameter<int32_t>("crossPartitionSegmentWidth");
0029   numOutputs_ = ps.getParameter<int32_t>("numOutputs");
0030   checkIds_ = ps.getParameter<bool>("checkIds");
0031   edgeDistance_ = ps.getParameter<int32_t>("edgeDistance");
0032   numOr_ = ps.getParameter<int32_t>("numOr");
0033   mseThreshold_ = ps.getParameter<double>("mseThreshold");
0034 }
0035 ME0StubBuilder::~ME0StubBuilder() {}
0036 
0037 void ME0StubBuilder::fillDescription(edm::ParameterSetDescription& desc) {
0038   desc.add<bool>("skipCentroids", false);
0039   desc.add<std::vector<int32_t>>("layerThresholdPatternId", {7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 4, 4, 4, 4, 4});
0040   desc.add<std::vector<int32_t>>("layerThresholdEta", {4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4});
0041   desc.add<int32_t>("maxSpan", 37);
0042   desc.add<int32_t>("width", 192);
0043   desc.add<bool>("deghostPre", true);
0044   desc.add<bool>("deghostPost", true);
0045   desc.add<int32_t>("groupWidth", 8);
0046   desc.add<int32_t>("ghostWidth", 1);
0047   desc.add<bool>("xPartitionEnabled", true);
0048   desc.add<bool>("enableNonPointing", false);
0049   desc.add<int32_t>("crossPartitionSegmentWidth", 4);
0050   desc.add<int32_t>("numOutputs", 4);
0051   desc.add<bool>("checkIds", false);
0052   desc.add<int32_t>("edgeDistance", 2);
0053   desc.add<int32_t>("numOr", 2);
0054   desc.add<double>("mseThreshold", 0.75);
0055 }
0056 
0057 void ME0StubBuilder::build(const GEMPadDigiCollection* padDigis, ME0StubCollection& oc) {
0058   Config config;
0059   config.skipCentroids = skipCentroids_;
0060   config.layerThresholdPatternId = layerThresholdPatternId_;
0061   config.layerThresholdEta = layerThresholdEta_;
0062   config.maxSpan = maxSpan_;
0063   config.width = width_;
0064   config.deghostPre = deghostPre_;
0065   config.deghostPost = deghostPost_;
0066   config.groupWidth = groupWidth_;
0067   config.ghostWidth = ghostWidth_;
0068   config.xPartitionEnabled = xPartitionEnabled_;
0069   config.enableNonPointing = enableNonPointing_;
0070   config.crossPartitionSegmentWidth = crossPartitionSegmentWidth_;
0071   config.numOutputs = numOutputs_;
0072   config.checkIds = checkIds_;
0073   config.edgeDistance = edgeDistance_;
0074   config.numOr = numOr_;
0075 
0076   std::map<uint32_t, std::pair<ME0ChamberData, ME0ChamberBXData>> dataMap;
0077   for (auto it = padDigis->begin(); it != padDigis->end(); ++it) {
0078     GEMDetId gemId((*it).first);
0079     if (gemId.station() != 0)
0080       continue;
0081 
0082     uint32_t gemRawId = (gemId.superChamberId()).rawId();
0083 
0084     if (dataMap[gemRawId].first.empty() || dataMap[gemRawId].second.empty()) {
0085       dataMap[gemRawId].first = std::vector<std::vector<UInt192>>(8, std::vector<UInt192>(6, UInt192(0)));
0086       dataMap[gemRawId].second =
0087           std::vector<std::vector<std::vector<int>>>(8, std::vector<std::vector<int>>(6, std::vector<int>(192, -9999)));
0088     }
0089     int layer = gemId.layer();
0090     int ieta = gemId.ieta();
0091     for (auto padDigi = ((*it).second).first; padDigi != ((*it).second).second; ++padDigi) {
0092       int strip = (*padDigi).pad();
0093       (dataMap[gemRawId].first.at(ieta - 1)).at(layer - 1) |= (UInt192(1) << (strip));
0094       ((dataMap[gemRawId].second.at(ieta - 1)).at(layer - 1)).at(strip) = (*padDigi).bx();
0095     }
0096   }
0097 
0098   // Find stub per chamber using dataMap
0099   for (const auto& dataPair : dataMap) {
0100     uint32_t rawId = dataPair.first;
0101     auto data = dataPair.second.first;
0102     auto bxData = dataPair.second.second;
0103 
0104     bool isNoneZero = false;
0105     for (const auto& etaData : data) {
0106       for (const auto& ly : etaData) {
0107         if (ly.any()) {
0108           isNoneZero = true;
0109           break;
0110         }
0111       }
0112       if (isNoneZero)
0113         break;
0114     }
0115     if (!isNoneZero)
0116       continue;
0117 
0118     GEMDetId id(rawId);
0119 
0120     std::vector<ME0StubPrimitive> segList = processChamber(data, bxData, config);
0121 
0122     std::vector<ME0Stub> segListProcessed;
0123 
0124     for (ME0StubPrimitive& seg : segList) {
0125       seg.fit(config.maxSpan);
0126       if (seg.mse() >= mseThreshold_) {
0127         seg.reset();
0128       }
0129 
0130       if (seg.patternId() == 0)
0131         continue;
0132       if ((seg.etaPartition() % 2) != 0)
0133         seg.setEtaPartition(seg.etaPartition() / 2 + 1);
0134       else
0135         seg.setEtaPartition(seg.etaPartition() / 2);
0136 
0137       ME0Stub segFinal(id,
0138                        seg.etaPartition(),
0139                        seg.strip() + seg.subStrip(),
0140                        seg.bendingAngle(),
0141                        seg.layerCount(),
0142                        seg.quality(),
0143                        seg.patternId(),
0144                        seg.bx());
0145 
0146       segListProcessed.push_back(segFinal);
0147     }
0148 
0149     oc.put(id, segListProcessed.begin(), segListProcessed.end());
0150   }
0151 }