Skip to content

Commit a5c2d46

Browse files
authored
Merge pull request #45759 from sihyunjeon/merge/CMSSW_14_1_X_qcore_producer
quarter core processor for HL-LHC inner tracker developments
2 parents 803864d + 6118c11 commit a5c2d46

File tree

13 files changed

+774
-0
lines changed

13 files changed

+774
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef DataFormats_Phase2TrackerDigi_Phase2ITChip_H
2+
#define DataFormats_Phase2TrackerDigi_Phase2ITChip_H
3+
#include <vector>
4+
#include <utility>
5+
#include <string>
6+
#include "DataFormats/Phase2TrackerDigi/interface/Phase2ITQCore.h"
7+
#include "DataFormats/Phase2TrackerDigi/interface/Phase2ITDigiHit.h"
8+
9+
class Phase2ITChip {
10+
// Quarter cores collected into a chip (only active quarter cores with hits gets collected)
11+
12+
public:
13+
Phase2ITChip(int rocnum, const std::vector<Phase2ITDigiHit> hl);
14+
15+
unsigned int size();
16+
int rocnum() const { return rocnum_; }
17+
18+
std::vector<Phase2ITQCore> get_organized_QCores();
19+
std::vector<bool> get_chip_code();
20+
21+
private:
22+
std::vector<Phase2ITDigiHit> hitList_;
23+
int rocnum_;
24+
25+
std::pair<int, int> get_QCore_pos(Phase2ITDigiHit hit);
26+
27+
Phase2ITQCore get_QCore_from_hit(Phase2ITDigiHit pixel);
28+
std::vector<Phase2ITQCore> rem_duplicates(std::vector<Phase2ITQCore> qcores);
29+
std::vector<Phase2ITQCore> organize_QCores(std::vector<Phase2ITQCore> qcores);
30+
};
31+
32+
#endif // DataFormats_Phase2TrackerDigi_Phase2ITChip_H
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef DataFormats_Phase2TrackerDigi_Phase2ITChipBitStream_H
2+
#define DataFormats_Phase2TrackerDigi_Phase2ITChipBitStream_H
3+
#include <vector>
4+
5+
class Phase2ITChipBitStream {
6+
// Encoded bit stream output from chips
7+
public:
8+
Phase2ITChipBitStream(int rocid, const std::vector<bool>& bitstream) {
9+
rocid_ = rocid;
10+
bitstream_ = bitstream;
11+
}
12+
13+
Phase2ITChipBitStream() { rocid_ = -1; }
14+
15+
int get_rocid() const { return rocid_; }
16+
17+
const std::vector<bool>& get_bitstream() const { return bitstream_; }
18+
19+
const bool operator<(const Phase2ITChipBitStream& other) { return rocid_ < other.rocid_; }
20+
21+
private:
22+
int rocid_; // Chip index
23+
std::vector<bool> bitstream_; // Chip bit stream output
24+
};
25+
#endif // DataFormats_Phase2TrackerDigi_Phase2ITChipBitStream_H
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef DataFormats_Phase2TrackerDigi_Phase2ITDigiHit_H
2+
#define DataFormats_Phase2TrackerDigi_Phase2ITDigiHit_H
3+
4+
class Phase2ITDigiHit {
5+
private:
6+
int row_; // Hit position row
7+
int col_; // Hit position column
8+
int adc_; // Hit position adc
9+
10+
public:
11+
Phase2ITDigiHit(int row_num, int col_num, int adc_num);
12+
13+
void set_row(int row) { row_ = row; }
14+
void set_col(int col) { col_ = col; }
15+
16+
int row() const { return row_; }
17+
int col() const { return col_; }
18+
int adc() const { return adc_; }
19+
};
20+
21+
#endif // DataFormats_Phase2TrackerDigi_Phase2ITDigiHit_H
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#ifndef DataFormats_Phase2TrackerDigi_Phase2ITQCore_H
2+
#define DataFormats_Phase2TrackerDigi_Phase2ITQCore_H
3+
#include <vector>
4+
5+
class Phase2ITQCore {
6+
// Collects hits and creates a quarter core (16 pixel positions)
7+
8+
public:
9+
Phase2ITQCore(int rocid,
10+
int ccol_in,
11+
int qcrow_in,
12+
bool isneighbour_in,
13+
bool islast_in,
14+
const std::vector<int>& adcs_in,
15+
const std::vector<int>& hits_in);
16+
17+
Phase2ITQCore() {
18+
rocid_ = -1;
19+
islast_ = false;
20+
isneighbour_ = false;
21+
ccol_ = -1;
22+
qcrow_ = -1;
23+
}
24+
25+
void setIsLast(bool islast) { islast_ = islast; }
26+
bool islast() const { return islast_; }
27+
28+
void setIsNeighbour(bool isneighbour) { isneighbour_ = isneighbour; }
29+
30+
int rocid() const { return rocid_; }
31+
int get_col() const { return ccol_; }
32+
int get_row() const { return qcrow_; }
33+
34+
std::vector<bool> getHitmap();
35+
std::vector<int> getADCs();
36+
std::vector<bool> encodeQCore(bool is_new_col);
37+
38+
const bool operator<(const Phase2ITQCore& other) {
39+
if (ccol_ == other.ccol_) {
40+
return (ccol_ < other.ccol_);
41+
} else {
42+
return (qcrow_ < other.qcrow_);
43+
}
44+
}
45+
46+
private:
47+
std::vector<int> adcs_; // Full array of adc values in a quarter core
48+
std::vector<int> hits_; // Full array of hit occurrences
49+
bool islast_; // RD53 chip encoding bits
50+
bool isneighbour_; // RD53 chip encoding bits
51+
int rocid_; // Chip index number
52+
int ccol_; // QCore position column
53+
int qcrow_; // QCore position row
54+
55+
std::vector<bool> toRocCoordinates(std::vector<bool>& hitmap);
56+
std::vector<bool> intToBinary(int num, int length);
57+
bool containsHit(std::vector<bool>& hitmap);
58+
std::vector<bool> getHitmapCode(std::vector<bool> hitmap);
59+
};
60+
61+
#endif // DataFormats_Phase2TrackerDigi_Phase2ITQCore_H
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#include <vector>
2+
#include <utility>
3+
#include <string>
4+
#include <iostream>
5+
#include "DataFormats/Phase2TrackerDigi/interface/Phase2ITQCore.h"
6+
#include "DataFormats/Phase2TrackerDigi/interface/Phase2ITChip.h"
7+
#include "DataFormats/Phase2TrackerDigi/interface/Phase2ITDigiHit.h"
8+
9+
Phase2ITChip::Phase2ITChip(int rocnum, const std::vector<Phase2ITDigiHit> hl) {
10+
hitList_ = hl;
11+
rocnum_ = rocnum;
12+
}
13+
14+
unsigned int Phase2ITChip::size() { return hitList_.size(); }
15+
16+
//Returns the position (row,col) of the 4x4 QCores that contains a hit
17+
std::pair<int, int> Phase2ITChip::get_QCore_pos(Phase2ITDigiHit hit) {
18+
int row = hit.row() / 4;
19+
int col = hit.col() / 4;
20+
return {row, col};
21+
}
22+
23+
//Takes a hit and returns the 4x4 QCore that contains it
24+
Phase2ITQCore Phase2ITChip::get_QCore_from_hit(Phase2ITDigiHit pixel) {
25+
std::vector<int> adcs(16, 0), hits(16, 0);
26+
std::pair<int, int> pos = get_QCore_pos(pixel);
27+
28+
for (const auto& hit : hitList_) {
29+
if (get_QCore_pos(hit) == pos) {
30+
int i = (4 * (hit.row() % 4) + (hit.col() % 4) + 8) % 16;
31+
adcs[i] = hit.adc();
32+
hits[i] = 1;
33+
}
34+
}
35+
36+
Phase2ITQCore qcore(0, pos.second, pos.first, false, false, adcs, hits);
37+
return qcore;
38+
}
39+
40+
//Removes duplicated Phase2ITQCores
41+
std::vector<Phase2ITQCore> Phase2ITChip::rem_duplicates(std::vector<Phase2ITQCore> qcores) {
42+
std::vector<Phase2ITQCore> list = {};
43+
44+
size_t i = 0;
45+
while (i < qcores.size()) {
46+
for (size_t j = i + 1; j < qcores.size();) {
47+
if (qcores[j].get_col() == qcores[i].get_col() && qcores[j].get_row() == qcores[i].get_row()) {
48+
qcores.erase(qcores.begin() + j);
49+
} else {
50+
++j;
51+
}
52+
}
53+
list.push_back(qcores[i]);
54+
++i;
55+
}
56+
57+
return list;
58+
}
59+
60+
//Returns a list of the qcores with hits arranged by increasing column and then row numbers
61+
std::vector<Phase2ITQCore> Phase2ITChip::organize_QCores(std::vector<Phase2ITQCore> qcores) {
62+
std::vector<Phase2ITQCore> organized_list = {};
63+
while (!qcores.empty()) {
64+
int min = 0;
65+
66+
for (size_t i = 1; i < qcores.size(); i++) {
67+
if (qcores[i].get_col() < qcores[min].get_col()) {
68+
min = i;
69+
} else if (qcores[i].get_col() == qcores[min].get_col() && qcores[i].get_row() < qcores[min].get_row()) {
70+
min = i;
71+
}
72+
}
73+
74+
organized_list.push_back(qcores[min]);
75+
qcores.erase(qcores.begin() + min);
76+
}
77+
78+
return organized_list;
79+
}
80+
81+
//Takes in an oranized list of Phase2ITQCores and sets the islast and isneighbor properties of those qcores
82+
std::vector<Phase2ITQCore> link_QCores(std::vector<Phase2ITQCore> qcores) {
83+
for (size_t i = 1; i < qcores.size(); i++) {
84+
if (qcores[i].get_row() == qcores[i - 1].get_row()) {
85+
qcores[i].setIsNeighbour(true);
86+
}
87+
}
88+
89+
//.size() is unsigned. If size is zero size()-1 is a huge number hence this needs to be protected
90+
if (!qcores.empty()) {
91+
for (size_t i = 0; i < qcores.size() - 1; i++) {
92+
if (qcores[i].get_col() != qcores[i + 1].get_col()) {
93+
qcores[i].setIsLast(true);
94+
}
95+
}
96+
qcores[qcores.size() - 1].setIsLast(true);
97+
}
98+
99+
return qcores;
100+
}
101+
102+
//Takes in a list of hits and organizes them into the 4x4 QCores that contains them
103+
std::vector<Phase2ITQCore> Phase2ITChip::get_organized_QCores() {
104+
std::vector<Phase2ITQCore> qcores = {};
105+
106+
qcores.reserve(hitList_.size());
107+
for (const auto& hit : hitList_) {
108+
qcores.push_back(get_QCore_from_hit(hit));
109+
}
110+
111+
return (link_QCores(organize_QCores(rem_duplicates(qcores))));
112+
}
113+
114+
//Returns the encoding of the readout chip
115+
std::vector<bool> Phase2ITChip::get_chip_code() {
116+
std::vector<bool> code = {};
117+
118+
if (!hitList_.empty()) {
119+
std::vector<Phase2ITQCore> qcores = get_organized_QCores();
120+
bool is_new_col = true;
121+
122+
for (auto& qcore : qcores) {
123+
std::vector<bool> qcore_code = qcore.encodeQCore(is_new_col);
124+
code.insert(code.end(), qcore_code.begin(), qcore_code.end());
125+
126+
is_new_col = qcore.islast();
127+
}
128+
}
129+
130+
return code;
131+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "DataFormats/Phase2TrackerDigi/interface/Phase2ITDigiHit.h"
2+
3+
// Describes the 4x4=16 bit hitmap with its row and column numbers and the ADC values
4+
Phase2ITDigiHit::Phase2ITDigiHit(int row_num, int col_num, int adc_num) {
5+
row_ = row_num;
6+
col_ = col_num;
7+
adc_ = adc_num;
8+
}

0 commit comments

Comments
 (0)