File indexing completed on 2024-09-07 04:37:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <iostream>
0014 #include <iomanip>
0015 #include <iterator>
0016 #include <cmath>
0017 #include <map>
0018
0019 #include "L1Trigger/L1TTwinMux/interface/RPCHitCleaner.h"
0020 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
0021 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
0022 #include "CondFormats/DataRecord/interface/RPCEMapRcd.h"
0023 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0024 #include "L1Trigger/L1TTwinMux/interface/RPCtoDTTranslator.h"
0025
0026 using namespace std;
0027
0028 RPCHitCleaner::RPCHitCleaner(RPCDigiCollection const& inrpcDigis) : m_inrpcDigis{inrpcDigis} {}
0029
0030 namespace {
0031 constexpr int max_rpc_bx = 3;
0032 constexpr int min_rpc_bx = -3;
0033
0034
0035
0036 class BxToStrips {
0037 public:
0038 BxToStrips() : m_strips{} {}
0039
0040 static bool outOfRange(int iBX) { return (iBX > max_rpc_bx or iBX < min_rpc_bx); }
0041
0042 int& operator[](int iBX) { return m_strips[iBX - min_rpc_bx]; }
0043
0044 size_t size() const { return m_strips.size(); }
0045
0046 private:
0047 std::array<int, max_rpc_bx - min_rpc_bx + 1> m_strips;
0048 };
0049 }
0050
0051 void RPCHitCleaner::run() {
0052 std::map<detId_Ext, int> hits;
0053 vector<int> vcluster_size;
0054 std::map<RPCDetId, int> bx_hits;
0055
0056 int cluster_size = 0;
0057 int cluster_id = -1;
0058 int itr = 0;
0059
0060 for (auto chamber = m_inrpcDigis.begin(); chamber != m_inrpcDigis.end(); ++chamber) {
0061 RPCDetId detid = (*chamber).first;
0062 int strip_n1 = -10000;
0063 int bx_n1 = -10000;
0064 if (detid.region() != 0)
0065 continue;
0066 for (auto digi = (*chamber).second.first; digi != (*chamber).second.second; ++digi) {
0067 if (fabs(digi->bx()) > 3)
0068 continue;
0069
0070
0071 if (abs(digi->strip() - strip_n1) != 1 || digi->bx() != bx_n1) {
0072 if (itr != 0)
0073 vcluster_size.push_back(cluster_size);
0074 cluster_size = 0;
0075 cluster_id++;
0076 }
0077 itr++;
0078 cluster_size++;
0079
0080 detId_Ext tmp{detid, digi->bx(), digi->strip()};
0081 hits[tmp] = cluster_id;
0082
0083 strip_n1 = digi->strip();
0084 bx_n1 = digi->bx();
0085 }
0086 }
0087 vcluster_size.push_back(cluster_size);
0088
0089 for (auto chamber = m_inrpcDigis.begin(); chamber != m_inrpcDigis.end(); ++chamber) {
0090 RPCDetId detid = (*chamber).first;
0091 if (detid.region() != 0)
0092 continue;
0093 BxToStrips strips;
0094 int cluster_n1 = -10;
0095 bx_hits[detid] = 10;
0096
0097 for (auto digi = (*chamber).second.first; digi != (*chamber).second.second; ++digi) {
0098 if (BxToStrips::outOfRange(digi->bx()))
0099 continue;
0100
0101 detId_Ext tmp{detid, digi->bx(), digi->strip()};
0102 int cluster_id = hits[tmp];
0103
0104 if (vcluster_size[cluster_id] >= 4)
0105 continue;
0106 if (bx_hits[detid] > digi->bx())
0107 bx_hits[detid] = digi->bx();
0108 }
0109
0110 for (auto digi = (*chamber).second.first; digi != (*chamber).second.second; ++digi) {
0111 if (fabs(digi->bx()) > 3)
0112 continue;
0113 detId_Ext tmp{detid, digi->bx(), digi->strip()};
0114 int cluster_id = hits[tmp];
0115
0116 if (vcluster_size[cluster_id] >= 4)
0117 continue;
0118
0119 if (digi->bx() != bx_hits[detid])
0120 continue;
0121
0122 if (cluster_n1 != cluster_id) {
0123 strips[digi->bx()] = {0};
0124 }
0125 strips[digi->bx()]++;
0126 cluster_n1 = cluster_id;
0127
0128 if (vcluster_size[cluster_id] == 3 && strips[digi->bx()] != 2)
0129 continue;
0130
0131 RPCDigi digi_out(digi->strip(), digi->bx());
0132 m_outrpcDigis.insertDigi(detid, digi_out);
0133 }
0134 }
0135 }