Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-12 01:51:39

0001 /*
0002  * RpcClusterization.cpp
0003  *
0004  *  Created on: Jan 14, 2019
0005  *      Author: kbunkow
0006  */
0007 
0008 #include "L1Trigger/L1TMuonOverlapPhase1/interface/RpcClusterization.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 #include <cmath>
0012 #include <algorithm>
0013 
0014 RpcClusterization::~RpcClusterization() {}
0015 
0016 std::vector<RpcCluster> RpcClusterization::getClusters(const RPCDetId& roll, std::vector<RPCDigi>& digis) const {
0017   std::vector<RpcCluster> allClusters;
0018 
0019   std::sort(digis.begin(), digis.end(), [](const RPCDigi& a, const RPCDigi& b) { return a.strip() < b.strip(); });
0020 
0021   typedef std::pair<unsigned int, unsigned int> Cluster;
0022 
0023   //This implementation of clusterization emulation gives the cluster in the same order as the order of digis,
0024   //and the order of unpacked digis should be the same as the order of the LB channels on which the clustrization
0025   //in the firmware is performed.
0026   //This cluster order plays role in some rare cases for the OMTF algorithm
0027   //when two hits has the same abs(minDistPhi), and then the phi of the resulting candidate
0028   //depends on the order of these hits.
0029   for (unsigned int iDigi = 0; iDigi < digis.size(); iDigi++) {
0030     //edm::LogVerbatim("l1tOmtfEventPrint")<< __FUNCTION__ << ":" << __LINE__<<" "<<roll<<" iDigi "<<iDigi<<" digi "<<digis[iDigi];
0031 
0032     //removing duplicated digis
0033     //the digis might be duplicated, because the same data might be received by two OMTF boards (as the same link goes to two neighboring boards)
0034     //and the unpacker is not cleaning them
0035     bool duplicatedDigi = false;
0036     for (unsigned int iDigi2 = 0; iDigi2 < iDigi; iDigi2++) {
0037       if (digis[iDigi].strip() == digis[iDigi2].strip()) {
0038         duplicatedDigi = true;
0039         //edm::LogVerbatim("l1tOmtfEventPrint")<<"duplicatedDigi";
0040         break;
0041       }
0042     }
0043 
0044     if (duplicatedDigi)
0045       continue;
0046 
0047     bool addNewCluster = true;
0048 
0049     for (auto& cluster : allClusters) {
0050       if (digis[iDigi].strip() - cluster.lastStrip == 1) {
0051         cluster.lastStrip = digis[iDigi].strip();
0052         addNewCluster = false;
0053       } else if (digis[iDigi].strip() - cluster.firstStrip == -1) {
0054         cluster.firstStrip = digis[iDigi].strip();
0055         addNewCluster = false;
0056       } else if (digis[iDigi].strip() >= cluster.firstStrip && digis[iDigi].strip() <= cluster.lastStrip) {
0057         addNewCluster = false;
0058       }
0059     }
0060 
0061     if (addNewCluster) {
0062       allClusters.emplace_back(digis[iDigi].strip(), digis[iDigi].strip());
0063       allClusters.back().bx = digis[iDigi].bx();
0064       allClusters.back().timing = convertTiming(digis[iDigi].time());
0065     }
0066   }
0067 
0068   /* Debug only
0069   if(allClusters.size())
0070       edm::LogVerbatim("l1tOmtfEventPrint")<< __FUNCTION__ <<" "<<roll<<" allClusters.size() "<<allClusters.size();
0071   for (auto& cluster : allClusters)
0072       edm::LogVerbatim("l1tOmtfEventPrint")
0073         << __FUNCTION__ << " cluster: firstStrip " << cluster.firstStrip
0074         << " lastStrip " << cluster.lastStrip << " halfStrip " << cluster.halfStrip() << std::endl;*/
0075 
0076   return allClusters;
0077 }
0078 
0079 int RpcClusterization::convertTiming(double timing) const {
0080   return timing;  //TODO implement
0081 }