CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RpcClusterization.cc
Go to the documentation of this file.
1 /*
2  * RpcClusterization.cpp
3  *
4  * Created on: Jan 14, 2019
5  * Author: kbunkow
6  */
7 
10 
11 #include <cmath>
12 #include <algorithm>
13 
15 
16 std::vector<RpcCluster> RpcClusterization::getClusters(const RPCDetId& roll, std::vector<RPCDigi>& digis) const {
17  std::vector<RpcCluster> allClusters;
18 
20  //with the 2018 firmware the agreement is better with this sort
21  std::sort(digis.begin(), digis.end(), [](const RPCDigi& a, const RPCDigi& b) { return a.strip() < b.strip(); });
22  } else {
23  //with the fixed RPC clusterization (Nov 2021 firmware) the data to emulator agreement is better if this reverse is used here,
24  //with the 2018 firmware the agreement is worse with this reverse,
25  std::reverse(digis.begin(), digis.end());
26  }
27 
28  typedef std::pair<unsigned int, unsigned int> Cluster;
29 
30  //This implementation of clusterization emulation gives the cluster in the same order as the order of digis,
31  //and the order of unpacked digis should be the same as the order of the LB channels on which the clustrization
32  //in the firmware is performed.
33  //This cluster order plays role in some rare cases for the OMTF algorithm
34  //when two hits has the same abs(minDistPhi), and then the phi of the resulting candidate
35  //depends on the order of these hits.
36  for (unsigned int iDigi = 0; iDigi < digis.size(); iDigi++) {
37  //edm::LogVerbatim("l1tOmtfEventPrint")<< __FUNCTION__ << ":" << __LINE__<<" "<<roll<<" iDigi "<<iDigi<<" digi "<<digis[iDigi];
38 
39  //removing duplicated digis
40  //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)
41  //and the unpacker is not cleaning them
42  bool duplicatedDigi = false;
43  for (unsigned int iDigi2 = 0; iDigi2 < iDigi; iDigi2++) {
44  if (digis[iDigi].strip() == digis[iDigi2].strip()) {
45  duplicatedDigi = true;
46  //edm::LogVerbatim("l1tOmtfEventPrint")<<"duplicatedDigi";
47  break;
48  }
49  }
50 
51  if (duplicatedDigi)
52  continue;
53 
54  bool addNewCluster = true;
55 
56  for (auto& cluster : allClusters) {
57  if (digis[iDigi].strip() - cluster.lastStrip == 1) {
58  cluster.lastStrip = digis[iDigi].strip();
59  addNewCluster = false;
60  } else if (digis[iDigi].strip() - cluster.firstStrip == -1) {
61  cluster.firstStrip = digis[iDigi].strip();
62  addNewCluster = false;
63  } else if (digis[iDigi].strip() >= cluster.firstStrip && digis[iDigi].strip() <= cluster.lastStrip) {
64  addNewCluster = false;
65  }
66  }
67 
68  if (addNewCluster) {
69  allClusters.emplace_back(digis[iDigi].strip(), digis[iDigi].strip());
70  allClusters.back().bx = digis[iDigi].bx();
71  allClusters.back().timing = convertTiming(digis[iDigi].time());
72  }
73  }
74 
75  /* Debug only
76  if(allClusters.size())
77  edm::LogVerbatim("l1tOmtfEventPrint")<< __FUNCTION__ <<" "<<roll<<" allClusters.size() "<<allClusters.size();
78  for (auto& cluster : allClusters)
79  edm::LogVerbatim("l1tOmtfEventPrint")
80  << __FUNCTION__ << " cluster: firstStrip " << cluster.firstStrip
81  << " lastStrip " << cluster.lastStrip << " halfStrip " << cluster.halfStrip() << std::endl;*/
82 
83  return allClusters;
84 }
85 
86 int RpcClusterization::convertTiming(double timing) const {
87  return timing; //TODO implement
88 }
virtual int convertTiming(double timing) const
int strip() const
Definition: RPCDigi.h:27
virtual ~RpcClusterization()
virtual std::vector< RpcCluster > getClusters(const RPCDetId &roll, std::vector< RPCDigi > &digis) const
N.B. digis are sorted inside the function.
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119