Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-28 03:10:06

0001 //-------------------------------------------------
0002 //
0003 //   Class: RPCHitCleaner
0004 //
0005 //   RPCHitCleaner
0006 //
0007 //
0008 //   Author :
0009 //   G. Flouris               U Ioannina    Mar. 2015
0010 //   modifications:   G Karathanasis     U Athens
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   //Need to shift the index so that index 0
0035   // corresponds to min_rpc_bx
0036   class BxToStrips {
0037   public:
0038     BxToStrips() : m_strips{} {}  //zero initializes
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 }  // namespace
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;  //Region = 0 Barrel
0066     for (auto digi = (*chamber).second.first; digi != (*chamber).second.second; ++digi) {
0067       if (fabs(digi->bx()) > 3)
0068         continue;
0069       ///Create cluster ids and store their size
0070       //if((digi->strip()-1!=strip_n1) || digi->bx()!=bx_n1){
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       ///hit belongs to cluster with clusterid
0080       detId_Ext tmp{detid, digi->bx(), digi->strip()};
0081       hits[tmp] = cluster_id;
0082       ///strip of i-1
0083       strip_n1 = digi->strip();
0084       bx_n1 = digi->bx();
0085     }  ///for digicout
0086   }    ///for chamber
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;  //Region = 0 Barrel
0093     BxToStrips strips;
0094     int cluster_n1 = -10;
0095     bx_hits[detid] = 10;
0096     //Keep cluster with min bx in a roll
0097     for (auto digi = (*chamber).second.first; digi != (*chamber).second.second; ++digi) {
0098       if (BxToStrips::outOfRange(digi->bx()))
0099         continue;
0100       //int cluster_id =  hits[(detid.ring()+2)][(detid.station()-1)][(detid.sector()-1)][(detid.layer()-1)][(digi->bx()+2)][detid.roll()-1][digi->strip()];
0101       detId_Ext tmp{detid, digi->bx(), digi->strip()};
0102       int cluster_id = hits[tmp];
0103       ///Remove clusters with size>=4
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       ///Remove clusters with size>=4
0116       if (vcluster_size[cluster_id] >= 4)
0117         continue;
0118       ///keep only one bx per st/sec/wheel/layer
0119       if (digi->bx() != bx_hits[detid])
0120         continue;
0121       ///Count strips in a cluster
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       ///Keep clusters with size=2. Calculate and store the mean phi in RPCtoDTTranslator
0131       RPCDigi digi_out(digi->strip(), digi->bx());
0132       m_outrpcDigis.insertDigi(detid, digi_out);
0133     }  ///for digicout
0134   }    ///for chamber
0135 }