File indexing completed on 2025-01-07 03:06:28
0001 #include <vector>
0002 #include <utility>
0003 #include <string>
0004 #include <iostream>
0005 #include "DataFormats/Phase2TrackerDigi/interface/Phase2ITQCore.h"
0006 #include "DataFormats/Phase2TrackerDigi/interface/Phase2ITChip.h"
0007 #include "DataFormats/Phase2TrackerDigi/interface/Phase2ITDigiHit.h"
0008
0009 Phase2ITChip::Phase2ITChip(int rocnum, const std::vector<Phase2ITDigiHit> hl) {
0010 hitList_ = hl;
0011 rocnum_ = rocnum;
0012 }
0013
0014 unsigned int Phase2ITChip::size() { return hitList_.size(); }
0015
0016
0017 std::pair<int, int> Phase2ITChip::get_QCore_pos(Phase2ITDigiHit hit) {
0018 int row = hit.row() / 4;
0019 int col = hit.col() / 4;
0020 return {row, col};
0021 }
0022
0023
0024 Phase2ITQCore Phase2ITChip::get_QCore_from_hit(Phase2ITDigiHit pixel) {
0025 std::vector<int> adcs(16, 0), hits(16, 0);
0026 std::pair<int, int> pos = get_QCore_pos(pixel);
0027
0028 for (const auto& hit : hitList_) {
0029 if (get_QCore_pos(hit) == pos) {
0030 int i = (4 * (hit.row() % 4) + (hit.col() % 4) + 8) % 16;
0031 adcs[i] = hit.adc();
0032 hits[i] = 1;
0033 }
0034 }
0035
0036 Phase2ITQCore qcore(0, pos.second, pos.first, false, false, adcs, hits);
0037 return qcore;
0038 }
0039
0040
0041 std::vector<Phase2ITQCore> Phase2ITChip::rem_duplicates(std::vector<Phase2ITQCore> qcores) {
0042 std::vector<Phase2ITQCore> list = {};
0043
0044 size_t i = 0;
0045 while (i < qcores.size()) {
0046 for (size_t j = i + 1; j < qcores.size();) {
0047 if (qcores[j].get_col() == qcores[i].get_col() && qcores[j].get_row() == qcores[i].get_row()) {
0048 qcores.erase(qcores.begin() + j);
0049 } else {
0050 ++j;
0051 }
0052 }
0053 list.push_back(qcores[i]);
0054 ++i;
0055 }
0056
0057 return list;
0058 }
0059
0060
0061 std::vector<Phase2ITQCore> Phase2ITChip::organize_QCores(std::vector<Phase2ITQCore> qcores) {
0062 std::vector<Phase2ITQCore> organized_list = {};
0063 while (!qcores.empty()) {
0064 int min = 0;
0065
0066 for (size_t i = 1; i < qcores.size(); i++) {
0067 if (qcores[i].get_col() < qcores[min].get_col()) {
0068 min = i;
0069 } else if (qcores[i].get_col() == qcores[min].get_col() && qcores[i].get_row() < qcores[min].get_row()) {
0070 min = i;
0071 }
0072 }
0073
0074 organized_list.push_back(qcores[min]);
0075 qcores.erase(qcores.begin() + min);
0076 }
0077
0078 return organized_list;
0079 }
0080
0081
0082 std::vector<Phase2ITQCore> link_QCores(std::vector<Phase2ITQCore> qcores) {
0083 for (size_t i = 1; i < qcores.size(); i++) {
0084 if (qcores[i].get_row() == qcores[i - 1].get_row()) {
0085 qcores[i].setIsNeighbour(true);
0086 }
0087 }
0088
0089
0090 if (!qcores.empty()) {
0091 for (size_t i = 0; i < qcores.size() - 1; i++) {
0092 if (qcores[i].get_col() != qcores[i + 1].get_col()) {
0093 qcores[i].setIsLast(true);
0094 }
0095 }
0096 qcores[qcores.size() - 1].setIsLast(true);
0097 }
0098
0099 return qcores;
0100 }
0101
0102
0103 std::vector<Phase2ITQCore> Phase2ITChip::get_organized_QCores() {
0104 std::vector<Phase2ITQCore> qcores = {};
0105
0106 qcores.reserve(hitList_.size());
0107 for (const auto& hit : hitList_) {
0108 qcores.push_back(get_QCore_from_hit(hit));
0109 }
0110
0111 return (link_QCores(organize_QCores(rem_duplicates(qcores))));
0112 }
0113
0114
0115 std::vector<bool> Phase2ITChip::get_chip_code() {
0116 std::vector<bool> code = {};
0117
0118 if (!hitList_.empty()) {
0119 std::vector<Phase2ITQCore> qcores = get_organized_QCores();
0120 bool is_new_col = true;
0121
0122 for (auto& qcore : qcores) {
0123 std::vector<bool> qcore_code = qcore.encodeQCore(is_new_col);
0124 code.insert(code.end(), qcore_code.begin(), qcore_code.end());
0125
0126 is_new_col = qcore.islast();
0127 }
0128 }
0129
0130 return code;
0131 }