From 2679706dde30869c951117c56b40b8f8212146e7 Mon Sep 17 00:00:00 2001 From: sihyunjeon Date: Wed, 21 Aug 2024 10:18:03 +0200 Subject: [PATCH] lets not forget the format check --- DataFormats/Phase2TrackerDigi/interface/Hit.h | 24 +- .../Phase2TrackerDigi/interface/QCore.h | 108 +++---- .../interface/ROCBitStream.h | 43 +-- .../Phase2TrackerDigi/interface/ReadoutChip.h | 28 +- DataFormats/Phase2TrackerDigi/src/Hit.cc | 8 +- DataFormats/Phase2TrackerDigi/src/QCore.cc | 224 +++++++------- .../Phase2TrackerDigi/src/ReadoutChip.cc | 154 +++++----- .../plugins/PixelQCoreProducer.cc | 284 +++++++++--------- .../test/plugins/Phase2PixelQCoreNtuple.cc | 110 +++---- 9 files changed, 472 insertions(+), 511 deletions(-) diff --git a/DataFormats/Phase2TrackerDigi/interface/Hit.h b/DataFormats/Phase2TrackerDigi/interface/Hit.h index c5c95286aee38..1baf402f032c1 100644 --- a/DataFormats/Phase2TrackerDigi/interface/Hit.h +++ b/DataFormats/Phase2TrackerDigi/interface/Hit.h @@ -2,20 +2,20 @@ #define HIT_H class Hit { - private: - int row_; - int col_; - int adc_; +private: + int row_; + int col_; + int adc_; - public: - Hit(int row_num, int col_num, int adc_num); +public: + Hit(int row_num, int col_num, int adc_num); - void set_row(int row) { row_ = row; } - void set_col(int col) { col_ = col; } + void set_row(int row) { row_ = row; } + void set_col(int col) { col_ = col; } - int row() const { return row_; } - int col() const { return col_; } - int adc() const { return adc_; } + int row() const { return row_; } + int col() const { return col_; } + int adc() const { return adc_; } }; -#endif // HIT_H +#endif // HIT_H diff --git a/DataFormats/Phase2TrackerDigi/interface/QCore.h b/DataFormats/Phase2TrackerDigi/interface/QCore.h index 9c14cac7c764c..d1f69d64e45bb 100644 --- a/DataFormats/Phase2TrackerDigi/interface/QCore.h +++ b/DataFormats/Phase2TrackerDigi/interface/QCore.h @@ -2,59 +2,59 @@ #define QCORE_H #include -class QCore{ - - private: - std::vector adcs; - std::vector hits; - bool islast_; - bool isneighbour_; - int rocid_; - int ccol; - int qcrow; - - public: - QCore( - int rocid, - int ccol_in, - int qcrow_in, - bool isneighbour_in, - bool islast_in, - std::vector adcs_in, - std::vector hits_in - ); - - QCore() { - rocid_ = -1; - islast_ = false; - isneighbour_ = false; - ccol = -1; - qcrow = -1; - } - - void setIsLast(bool islast) { islast_ = islast; } - bool islast() const { return islast_; } - - void setIsNeighbour(bool isneighbour) { isneighbour_ = isneighbour; } - - int rocid() const { return rocid_; } - int get_col() const { return ccol; } - int get_row() const { return qcrow; } - - std::vector getHitmap(); - std::vector getADCs(); - std::vector encodeQCore(bool is_new_col); - - const bool operator<(const QCore& other) { - if (ccol==other.ccol) { return (ccol < other.ccol); } - else { return (qcrow < other.qcrow); } - } - - private: - std::vector toRocCoordinates(std::vector& hitmap); - std::vector intToBinary(int num, int length); - bool containsHit(std::vector& hitmap); - std::vector getHitmapCode(std::vector hitmap); +class QCore { +private: + std::vector adcs; + std::vector hits; + bool islast_; + bool isneighbour_; + int rocid_; + int ccol; + int qcrow; + +public: + QCore(int rocid, + int ccol_in, + int qcrow_in, + bool isneighbour_in, + bool islast_in, + std::vector adcs_in, + std::vector hits_in); + + QCore() { + rocid_ = -1; + islast_ = false; + isneighbour_ = false; + ccol = -1; + qcrow = -1; + } + + void setIsLast(bool islast) { islast_ = islast; } + bool islast() const { return islast_; } + + void setIsNeighbour(bool isneighbour) { isneighbour_ = isneighbour; } + + int rocid() const { return rocid_; } + int get_col() const { return ccol; } + int get_row() const { return qcrow; } + + std::vector getHitmap(); + std::vector getADCs(); + std::vector encodeQCore(bool is_new_col); + + const bool operator<(const QCore& other) { + if (ccol == other.ccol) { + return (ccol < other.ccol); + } else { + return (qcrow < other.qcrow); + } + } + +private: + std::vector toRocCoordinates(std::vector& hitmap); + std::vector intToBinary(int num, int length); + bool containsHit(std::vector& hitmap); + std::vector getHitmapCode(std::vector hitmap); }; -#endif // QCORE_H +#endif // QCORE_H diff --git a/DataFormats/Phase2TrackerDigi/interface/ROCBitStream.h b/DataFormats/Phase2TrackerDigi/interface/ROCBitStream.h index 392db83ec635a..e9334ae3df6cb 100644 --- a/DataFormats/Phase2TrackerDigi/interface/ROCBitStream.h +++ b/DataFormats/Phase2TrackerDigi/interface/ROCBitStream.h @@ -1,37 +1,24 @@ #ifndef ROCBITSTREAM_H #define ROCBITSTREAM_H -#include +#include -class ROCBitStream{ +class ROCBitStream { +public: + ROCBitStream(int rocid, const std::vector& bitstream) { + rocid_ = rocid; + bitstream_ = bitstream; + } - public: - ROCBitStream( - int rocid, - const std::vector& bitstream - ) { - rocid_ = rocid; - bitstream_ = bitstream; - } + ROCBitStream() { rocid_ = -1; } - ROCBitStream() { - rocid_ = -1; - } + int get_rocid() const { return rocid_; } - int get_rocid() const { - return rocid_; - } + const std::vector& get_bitstream() const { return bitstream_; } - const std::vector& get_bitstream() const { - return bitstream_; - } - - const bool operator<(const ROCBitStream& other) { - return rocid_ < other.rocid_; - } - - private: - int rocid_; - std::vector bitstream_; + const bool operator<(const ROCBitStream& other) { return rocid_ < other.rocid_; } +private: + int rocid_; + std::vector bitstream_; }; -#endif // ROCBITSTREAM_H +#endif // ROCBITSTREAM_H diff --git a/DataFormats/Phase2TrackerDigi/interface/ReadoutChip.h b/DataFormats/Phase2TrackerDigi/interface/ReadoutChip.h index 357b50d14aa5d..7937e49078129 100644 --- a/DataFormats/Phase2TrackerDigi/interface/ReadoutChip.h +++ b/DataFormats/Phase2TrackerDigi/interface/ReadoutChip.h @@ -7,24 +7,24 @@ #include "DataFormats/Phase2TrackerDigi/interface/Hit.h" class ReadoutChip { - std::vector hitList; - int rocnum_; + std::vector hitList; + int rocnum_; - public: - ReadoutChip(int rocnum, std::vector hl); +public: + ReadoutChip(int rocnum, std::vector hl); - unsigned int size(); - int rocnum() const { return rocnum_; } + unsigned int size(); + int rocnum() const { return rocnum_; } - std::vector get_organized_QCores(); - std::vector get_chip_code(); + std::vector get_organized_QCores(); + std::vector get_chip_code(); - private: - std::pair get_QCore_pos(Hit hit); +private: + std::pair get_QCore_pos(Hit hit); - QCore get_QCore_from_hit(Hit pixel); - std::vector rem_duplicates(std::vector qcores); - std::vector organize_QCores(std::vector qcores); + QCore get_QCore_from_hit(Hit pixel); + std::vector rem_duplicates(std::vector qcores); + std::vector organize_QCores(std::vector qcores); }; -#endif // READOUTCHIP_H +#endif // READOUTCHIP_H diff --git a/DataFormats/Phase2TrackerDigi/src/Hit.cc b/DataFormats/Phase2TrackerDigi/src/Hit.cc index f77993c95a1b2..5ed828332d454 100644 --- a/DataFormats/Phase2TrackerDigi/src/Hit.cc +++ b/DataFormats/Phase2TrackerDigi/src/Hit.cc @@ -2,9 +2,7 @@ // Describes the 4x4=16 bit hitmap with its row and column numbers and the ADC values Hit::Hit(int row_num, int col_num, int adc_num) { - - row_ = row_num; - col_ = col_num; - adc_ = adc_num; - + row_ = row_num; + col_ = col_num; + adc_ = adc_num; } diff --git a/DataFormats/Phase2TrackerDigi/src/QCore.cc b/DataFormats/Phase2TrackerDigi/src/QCore.cc index 9a207433101f8..586ab8c1a1f2f 100644 --- a/DataFormats/Phase2TrackerDigi/src/QCore.cc +++ b/DataFormats/Phase2TrackerDigi/src/QCore.cc @@ -4,174 +4,164 @@ #include //4x4 region of hits in sensor coordinates -QCore::QCore( - int rocid, - int ccol_in, - int qcrow_in, - bool isneighbour_in, - bool islast_in, - std::vector adcs_in, - std::vector hits_in) { - rocid_ = rocid; - ccol = ccol_in; - qcrow = qcrow_in; - isneighbour_ = isneighbour_in; - islast_ = islast_in; - adcs = adcs_in; - hits = hits_in; +QCore::QCore(int rocid, + int ccol_in, + int qcrow_in, + bool isneighbour_in, + bool islast_in, + std::vector adcs_in, + std::vector hits_in) { + rocid_ = rocid; + ccol = ccol_in; + qcrow = qcrow_in; + isneighbour_ = isneighbour_in; + islast_ = islast_in; + adcs = adcs_in; + hits = hits_in; } //Takes a hitmap in sensor coordinates in 4x4 and converts it to readout chip coordinates with 2x8 std::vector QCore::toRocCoordinates(std::vector& hitmap) { - std::vector ROC_hitmap(16, 0); - - for(size_t i = 0; i < hitmap.size(); i++) { - int row = std::floor(i / 4); - int col = i % 4; - int new_row; - int new_col; - - if(row % 2 == 0) { - new_row = row / 2; - new_col = 2 * col; - } - else { - new_row = std::floor(row / 2); - new_col = 2 * col + 1; - } - - int new_index = 8 * new_row + new_col; - ROC_hitmap[new_index] = hitmap[i]; + std::vector ROC_hitmap(16, 0); + + for (size_t i = 0; i < hitmap.size(); i++) { + int row = std::floor(i / 4); + int col = i % 4; + int new_row; + int new_col; + + if (row % 2 == 0) { + new_row = row / 2; + new_col = 2 * col; + } else { + new_row = std::floor(row / 2); + new_col = 2 * col + 1; } - return ROC_hitmap; + int new_index = 8 * new_row + new_col; + ROC_hitmap[new_index] = hitmap[i]; + } + + return ROC_hitmap; } //Returns the hitmap for the QCore in 4x4 sensor coordinates std::vector QCore::getHitmap() { - std::vector hitmap = {}; + std::vector hitmap = {}; - for (auto hit : hits) { - hitmap.push_back(hit > 0); - } + for (auto hit : hits) { + hitmap.push_back(hit > 0); + } - return (toRocCoordinates(hitmap)); + return (toRocCoordinates(hitmap)); } std::vector QCore::getADCs() { - std::vector adcmap = {}; + std::vector adcmap = {}; - for (auto adc : adcs) { - adcmap.push_back(adc); - } + for (auto adc : adcs) { + adcmap.push_back(adc); + } - return adcmap; + return adcmap; } //Converts an integer into a binary, and formats it with the given length std::vector QCore::intToBinary(int num, int length) { - int n = num; - std::vector bi_num(length, 0); - - for(int i = length; i > 0; i--) { - if(n >= pow(2, i-1)) { - bi_num[length-i] = 1; - n -= pow(2, i-1); - } - else { - bi_num[length - i] = 0; - } + int n = num; + std::vector bi_num(length, 0); + + for (int i = length; i > 0; i--) { + if (n >= pow(2, i - 1)) { + bi_num[length - i] = 1; + n -= pow(2, i - 1); + } else { + bi_num[length - i] = 0; } + } - return bi_num; + return bi_num; } //Takes a hitmap and returns true if it contains any hits bool QCore::containsHit(std::vector& hitmap) { - bool foundHit = false; - for (size_t i = 0; i < hitmap.size(); i++) { - if (hitmap[i]) { - foundHit = true; - break; - } + bool foundHit = false; + for (size_t i = 0; i < hitmap.size(); i++) { + if (hitmap[i]) { + foundHit = true; + break; } + } - return foundHit; + return foundHit; } //Returns the Huffman encoded hitmap, created iteratively within this function std::vector QCore::getHitmapCode(std::vector hitmap) { - std::vector code = {}; - // If hitmap is a single bit, there is no need to further split the bits - if (hitmap.size() == 1) { - return code; - } - - std::vector left_hitmap = std::vector(hitmap.begin(), hitmap.begin() + hitmap.size() / 2); - std::vector right_hitmap = std::vector(hitmap.begin() + hitmap.size() / 2, hitmap.end()); - - bool hit_left = containsHit(left_hitmap); - bool hit_right = containsHit(right_hitmap); - - if(hit_left && hit_right) { + std::vector code = {}; + // If hitmap is a single bit, there is no need to further split the bits + if (hitmap.size() == 1) { + return code; + } - code.push_back(1); - code.push_back(1); + std::vector left_hitmap = std::vector(hitmap.begin(), hitmap.begin() + hitmap.size() / 2); + std::vector right_hitmap = std::vector(hitmap.begin() + hitmap.size() / 2, hitmap.end()); - std::vector left_code = getHitmapCode(left_hitmap); - std::vector right_code = getHitmapCode(right_hitmap); + bool hit_left = containsHit(left_hitmap); + bool hit_right = containsHit(right_hitmap); - code.insert(code.end(),left_code.begin(),left_code.end()); - code.insert(code.end(),right_code.begin(),right_code.end()); + if (hit_left && hit_right) { + code.push_back(1); + code.push_back(1); - } - else if(hit_right) { + std::vector left_code = getHitmapCode(left_hitmap); + std::vector right_code = getHitmapCode(right_hitmap); - //Huffman encoding compresses 01 into 0 - code.push_back(0); - - std::vector right_code = getHitmapCode(right_hitmap); - code.insert(code.end(),right_code.begin(),right_code.end()); + code.insert(code.end(), left_code.begin(), left_code.end()); + code.insert(code.end(), right_code.begin(), right_code.end()); - } - else if(hit_left) { + } else if (hit_right) { + //Huffman encoding compresses 01 into 0 + code.push_back(0); - code.push_back(1); - code.push_back(0); + std::vector right_code = getHitmapCode(right_hitmap); + code.insert(code.end(), right_code.begin(), right_code.end()); - std::vector left_code = getHitmapCode(left_hitmap); - code.insert(code.end(),left_code.begin(),left_code.end()); + } else if (hit_left) { + code.push_back(1); + code.push_back(0); - } + std::vector left_code = getHitmapCode(left_hitmap); + code.insert(code.end(), left_code.begin(), left_code.end()); + } - return code; + return code; } //Returns the bit code associated with the QCore std::vector QCore::encodeQCore(bool is_new_col) { + std::vector code = {}; - std::vector code = {}; + if (is_new_col) { + std::vector col_code = intToBinary(ccol, 6); + code.insert(code.end(), col_code.begin(), col_code.end()); + } - if(is_new_col) { - std::vector col_code = intToBinary(ccol, 6); - code.insert(code.end(), col_code.begin(), col_code.end()); - } - - code.push_back(islast_); - code.push_back(isneighbour_); + code.push_back(islast_); + code.push_back(isneighbour_); - if(!isneighbour_) { - std::vector row_code = intToBinary(qcrow, 8); - code.insert(code.end(), row_code.begin(), row_code.end()); - } + if (!isneighbour_) { + std::vector row_code = intToBinary(qcrow, 8); + code.insert(code.end(), row_code.begin(), row_code.end()); + } - std::vector hitmap_code = getHitmapCode(getHitmap()); - code.insert(code.end(), hitmap_code.begin(), hitmap_code.end()); + std::vector hitmap_code = getHitmapCode(getHitmap()); + code.insert(code.end(), hitmap_code.begin(), hitmap_code.end()); - for(auto adc : adcs) { - std::vector adc_code = intToBinary(adc, 4); - code.insert(code.end(), adc_code.begin(), adc_code.end()); - } + for (auto adc : adcs) { + std::vector adc_code = intToBinary(adc, 4); + code.insert(code.end(), adc_code.begin(), adc_code.end()); + } - return code; + return code; } diff --git a/DataFormats/Phase2TrackerDigi/src/ReadoutChip.cc b/DataFormats/Phase2TrackerDigi/src/ReadoutChip.cc index 1d59ec1e0506a..4b1fb1aed319f 100644 --- a/DataFormats/Phase2TrackerDigi/src/ReadoutChip.cc +++ b/DataFormats/Phase2TrackerDigi/src/ReadoutChip.cc @@ -7,126 +7,124 @@ #include "DataFormats/Phase2TrackerDigi/interface/Hit.h" ReadoutChip::ReadoutChip(int rocnum, std::vector hl) { - hitList = hl; - rocnum_ = rocnum; + hitList = hl; + rocnum_ = rocnum; } -unsigned int ReadoutChip::size() { - return hitList.size(); -} +unsigned int ReadoutChip::size() { return hitList.size(); } //Returns the position (row,col) of the 4x4 QCores that contains a hit -std::pair ReadoutChip::get_QCore_pos(Hit hit) { - int row = hit.row() / 4; - int col = hit.col() / 4; - return {row,col}; +std::pair ReadoutChip::get_QCore_pos(Hit hit) { + int row = hit.row() / 4; + int col = hit.col() / 4; + return {row, col}; } //Takes a hit and returns the 4x4 QCore that contains it QCore ReadoutChip::get_QCore_from_hit(Hit pixel) { - std::vector adcs(16,0), hits(16,0); - std::pair pos = get_QCore_pos(pixel); - - for (const auto& hit:hitList) { - if (get_QCore_pos(hit) == pos) { - int i = (4 * (hit.row() % 4) + (hit.col() % 4) + 8) % 16; - adcs[i] = hit.adc(); - hits[i] = 1; - } + std::vector adcs(16, 0), hits(16, 0); + std::pair pos = get_QCore_pos(pixel); + + for (const auto& hit : hitList) { + if (get_QCore_pos(hit) == pos) { + int i = (4 * (hit.row() % 4) + (hit.col() % 4) + 8) % 16; + adcs[i] = hit.adc(); + hits[i] = 1; } + } - QCore qcore(0, pos.second, pos.first, false, false, adcs, hits); - return qcore; + QCore qcore(0, pos.second, pos.first, false, false, adcs, hits); + return qcore; } //Removes duplicated QCores std::vector ReadoutChip::rem_duplicates(std::vector qcores) { - std::vector list = {}; - - size_t i = 0; - while (i < qcores.size()) { - for (size_t j = i + 1; j < qcores.size();) { - if (qcores[j].get_col() == qcores[i].get_col() - && qcores[j].get_row() == qcores[i].get_row()) { - qcores.erase(qcores.begin() + j); - } - else { ++j; } - } - list.push_back(qcores[i]); - ++i; + std::vector list = {}; + + size_t i = 0; + while (i < qcores.size()) { + for (size_t j = i + 1; j < qcores.size();) { + if (qcores[j].get_col() == qcores[i].get_col() && qcores[j].get_row() == qcores[i].get_row()) { + qcores.erase(qcores.begin() + j); + } else { + ++j; + } } + list.push_back(qcores[i]); + ++i; + } - return list; + return list; } //Returns a list of the qcores with hits arranged by increasing column and then row numbers std::vector ReadoutChip::organize_QCores(std::vector qcores) { - std::vector organized_list = {}; - while (qcores.size() > 0) { - int min = 0; - - for (size_t i = 1; i < qcores.size(); i++) { - if (qcores[i].get_col() < qcores[min].get_col()) { min = i; } - else if(qcores[i].get_col() == qcores[min].get_col() - && qcores[i].get_row() < qcores[min].get_row()) { min = i; } - } - - organized_list.push_back(qcores[min]); - qcores.erase(qcores.begin() + min); + std::vector organized_list = {}; + while (qcores.size() > 0) { + int min = 0; + + for (size_t i = 1; i < qcores.size(); i++) { + if (qcores[i].get_col() < qcores[min].get_col()) { + min = i; + } else if (qcores[i].get_col() == qcores[min].get_col() && qcores[i].get_row() < qcores[min].get_row()) { + min = i; + } } - return organized_list; + organized_list.push_back(qcores[min]); + qcores.erase(qcores.begin() + min); + } + + return organized_list; } //Takes in an oranized list of QCores and sets the islast and isneighbor properties of those qcores std::vector link_QCores(std::vector qcores) { - - for (size_t i = 1; i < qcores.size(); i++) { - if (qcores[i].get_row() == qcores[i-1].get_row()) { - qcores[i].setIsNeighbour(true); - } + for (size_t i = 1; i < qcores.size(); i++) { + if (qcores[i].get_row() == qcores[i - 1].get_row()) { + qcores[i].setIsNeighbour(true); } - - //.size() is unsigned. If size is zero size()-1 is a huge number hence this needs to be protected - if (qcores.size() > 0) { - for (size_t i = 0; i < qcores.size()-1; i++) { - if (qcores[i].get_col() != qcores[i+1].get_col()) { - qcores[i].setIsLast(true); - } - } - qcores[qcores.size()-1].setIsLast(true); + } + + //.size() is unsigned. If size is zero size()-1 is a huge number hence this needs to be protected + if (qcores.size() > 0) { + for (size_t i = 0; i < qcores.size() - 1; i++) { + if (qcores[i].get_col() != qcores[i + 1].get_col()) { + qcores[i].setIsLast(true); + } } + qcores[qcores.size() - 1].setIsLast(true); + } - return qcores; + return qcores; } //Takes in a list of hits and organizes them into the 4x4 QCores that contains them std::vector ReadoutChip::get_organized_QCores() { - std::vector qcores = {}; + std::vector qcores = {}; - for (const auto& hit:hitList) { - qcores.push_back(get_QCore_from_hit(hit)); - } + for (const auto& hit : hitList) { + qcores.push_back(get_QCore_from_hit(hit)); + } - return (link_QCores(organize_QCores(rem_duplicates(qcores)))); + return (link_QCores(organize_QCores(rem_duplicates(qcores)))); } //Returns the encoding of the readout chip std::vector ReadoutChip::get_chip_code() { - std::vector code = {}; + std::vector code = {}; - if (hitList.size() > 0) { - std::vector qcores = get_organized_QCores(); - bool is_new_col = true; + if (hitList.size() > 0) { + std::vector qcores = get_organized_QCores(); + bool is_new_col = true; - for (auto& qcore:qcores) { + for (auto& qcore : qcores) { + std::vector qcore_code = qcore.encodeQCore(is_new_col); + code.insert(code.end(), qcore_code.begin(), qcore_code.end()); - std::vector qcore_code = qcore.encodeQCore(is_new_col); - code.insert(code.end(), qcore_code.begin(), qcore_code.end()); - - is_new_col = qcore.islast(); - } + is_new_col = qcore.islast(); } + } - return code; + return code; } diff --git a/EventFilter/Phase2TrackerRawToDigi/plugins/PixelQCoreProducer.cc b/EventFilter/Phase2TrackerRawToDigi/plugins/PixelQCoreProducer.cc index d1b4b543147c0..426290a991518 100644 --- a/EventFilter/Phase2TrackerRawToDigi/plugins/PixelQCoreProducer.cc +++ b/EventFilter/Phase2TrackerRawToDigi/plugins/PixelQCoreProducer.cc @@ -33,184 +33,190 @@ #include "TrackingTools/Records/interface/TransientTrackRecord.h" class PixelQCoreProducer : public edm::stream::EDProducer<> { - public: - explicit PixelQCoreProducer(const edm::ParameterSet&); - ~PixelQCoreProducer(); - - private: - virtual void beginJob(const edm::EventSetup&); - virtual void produce(edm::Event&, const edm::EventSetup&); - virtual void endJob() ; - - edm::InputTag src_; - edm::EDGetTokenT> pixelDigi_token_; - edm::ESGetToken const tTopoToken_; - typedef math::XYZPointD Point; - typedef std::vector PointCollection; +public: + explicit PixelQCoreProducer(const edm::ParameterSet&); + ~PixelQCoreProducer(); + +private: + virtual void beginJob(const edm::EventSetup&); + virtual void produce(edm::Event&, const edm::EventSetup&); + virtual void endJob(); + + edm::InputTag src_; + edm::EDGetTokenT> pixelDigi_token_; + edm::ESGetToken const tTopoToken_; + typedef math::XYZPointD Point; + typedef std::vector PointCollection; }; PixelQCoreProducer::PixelQCoreProducer(const edm::ParameterSet& iConfig) - : tTopoToken_(esConsumes()){ + : tTopoToken_(esConsumes()) { + src_ = iConfig.getParameter("src"); + pixelDigi_token_ = consumes>(iConfig.getParameter("siPixelDigi")); - src_ = iConfig.getParameter("src"); - pixelDigi_token_ = consumes>(iConfig.getParameter("siPixelDigi")); - - produces >(); - produces >(); + produces>(); + produces>(); } PixelQCoreProducer::~PixelQCoreProducer() {} -Hit updateHitCoordinatesForLargePixels(Hit &hit) { - /* +Hit updateHitCoordinatesForLargePixels(Hit& hit) { + /* In-place modification of Hit coordinates to take into account large pixels Hits corresponding to large pixels are remapped so they lie on the boundary of the chip Note that this operation can produce multiple hits with the same row/column coordinates Duplicates get removed later on */ - // Current values before remapping - int row = hit.row(); - int col = hit.col(); - - // Values after remapping - int updated_row = 0; - int updated_col = 0; - - // Dimension for 2 chips module = 672 X 434 = 672 X (216 + 1 + 216 + 1) - // Dimension for 4 chips module = 1354 X 434 = (672 + 5 + 672 + 5) X (216 + 1 + 216 + 1) - // Spacing 1 in column and 5 in row is introduced for each chip in between - // if neighboring chip exists - - // Remapping of the row coordinate - if (row < 672) { updated_row = row; } - else if(row <= 676) { updated_row = 671; } // This will be ignored for 2 chips module - else if(row <= 681) { updated_row = 672; } - else { updated_row = hit.row() - 10; } - - // Remapping of the column coordinate - if(col < 216) { updated_col = col; } - else if(col <= 216) { updated_col = 215; } - else if(col <= 217) { updated_col = 216; } - else { updated_col = hit.col() - 2; } - - hit.set_row(updated_row); - hit.set_col(updated_col); - - return hit; + // Current values before remapping + int row = hit.row(); + int col = hit.col(); + + // Values after remapping + int updated_row = 0; + int updated_col = 0; + + // Dimension for 2 chips module = 672 X 434 = 672 X (216 + 1 + 216 + 1) + // Dimension for 4 chips module = 1354 X 434 = (672 + 5 + 672 + 5) X (216 + 1 + 216 + 1) + // Spacing 1 in column and 5 in row is introduced for each chip in between + // if neighboring chip exists + + // Remapping of the row coordinate + if (row < 672) { + updated_row = row; + } else if (row <= 676) { + updated_row = 671; + } // This will be ignored for 2 chips module + else if (row <= 681) { + updated_row = 672; + } else { + updated_row = hit.row() - 10; + } + + // Remapping of the column coordinate + if (col < 216) { + updated_col = col; + } else if (col <= 216) { + updated_col = 215; + } else if (col <= 217) { + updated_col = 216; + } else { + updated_col = hit.col() - 2; + } + + hit.set_row(updated_row); + hit.set_col(updated_col); + + return hit; } std::vector adjustEdges(std::vector hitList) { - /* + /* In-place modification of Hit coordinates to take into account large pixels */ - std::for_each(hitList.begin(), hitList.end(), &updateHitCoordinatesForLargePixels); - return hitList; + std::for_each(hitList.begin(), hitList.end(), &updateHitCoordinatesForLargePixels); + return hitList; } std::vector splitByChip(std::vector hitList) { - // Split the hit list by read out chip - std::vector> hits_per_chip(4); - for (auto hit:hitList) { - int chip_index = (hit.col() < 216) ? 0 : 1; - if (hit.row() >= 672){ - chip_index += 2; - } - hits_per_chip[chip_index].push_back(hit); + // Split the hit list by read out chip + std::vector> hits_per_chip(4); + for (auto hit : hitList) { + int chip_index = (hit.col() < 216) ? 0 : 1; + if (hit.row() >= 672) { + chip_index += 2; } + hits_per_chip[chip_index].push_back(hit); + } - // Generate ReadoutChip objects from the hit lists - std::vector chips; - for (int chip_index=0; chip_index<4; chip_index++) { - chips.push_back(ReadoutChip(chip_index, hits_per_chip[chip_index])); - } + // Generate ReadoutChip objects from the hit lists + std::vector chips; + for (int chip_index = 0; chip_index < 4; chip_index++) { + chips.push_back(ReadoutChip(chip_index, hits_per_chip[chip_index])); + } - return chips; + return chips; } std::vector processHits(std::vector hitList) { + std::vector newHitList; + newHitList = adjustEdges(hitList); - std::vector newHitList; - newHitList = adjustEdges(hitList); + std::vector chips = splitByChip(newHitList); + std::vector code; - std::vector chips = splitByChip(newHitList); - std::vector code; - - for (size_t i = 0; i < chips.size(); i++) { - ReadoutChip chip = chips[i]; - code = chip.get_chip_code(); - } + for (size_t i = 0; i < chips.size(); i++) { + ReadoutChip chip = chips[i]; + code = chip.get_chip_code(); + } - return chips; + return chips; } // ------------ method called to produce the data ------------ void PixelQCoreProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - using namespace edm; - using namespace std; - - unique_ptr > aQCoreVector = make_unique >(); - unique_ptr > aBitStreamVector = make_unique >(); - - auto const &tTopo = iSetup.getData(tTopoToken_); - - edm::Handle > pixelDigiHandle; - iEvent.getByToken(pixelDigi_token_, pixelDigiHandle); - - edm::DetSetVector::const_iterator iterDet; - for ( iterDet = pixelDigiHandle->begin(); iterDet != pixelDigiHandle->end(); iterDet++ ) { - - DetId tkId = iterDet->id; - edm::DetSet theDigis = (*pixelDigiHandle)[ tkId ]; - std::vector hitlist; - std::vector id; - - if (tkId.subdetId() == PixelSubdetector::PixelBarrel) { - int layer_num = tTopo.pxbLayer(tkId.rawId()); - int ladder_num = tTopo.pxbLadder(tkId.rawId()); - int module_num = tTopo.pxbModule(tkId.rawId()); - id = {tkId.subdetId(), layer_num, ladder_num, module_num}; - } - else if (tkId.subdetId() == PixelSubdetector::PixelEndcap) { - int module_num = tTopo.pxfModule(tkId()); - int disk_num = tTopo.pxfDisk(tkId()); - int blade_num = tTopo.pxfBlade(tkId()); - int panel_num = tTopo.pxfPanel(tkId()); - int side_num = tTopo.pxfSide(tkId()); - id = {tkId.subdetId(), module_num, disk_num, blade_num, panel_num, side_num}; - } - - for ( auto iterDigi = theDigis.begin(); iterDigi != theDigis.end(); ++iterDigi ) { - hitlist.emplace_back(Hit(iterDigi->row(),iterDigi->column(),iterDigi->adc())); - } - - std::vector chips = processHits(hitlist); - - DetSet DetSetQCores(tkId); - DetSet DetSetBitStream(tkId); - - for(size_t i = 0; i < chips.size(); i++) { - ReadoutChip chip = chips[i]; - std::vector qcores = chip.get_organized_QCores(); - for (auto& qcore:qcores) { - DetSetQCores.push_back(qcore); - } - - ROCBitStream aROCBitStream(i,chip.get_chip_code()); - DetSetBitStream.push_back(aROCBitStream); - } - - aBitStreamVector->insert(DetSetBitStream); - aQCoreVector->insert(DetSetQCores); + using namespace edm; + using namespace std; + + unique_ptr> aQCoreVector = make_unique>(); + unique_ptr> aBitStreamVector = make_unique>(); + + auto const& tTopo = iSetup.getData(tTopoToken_); + + edm::Handle> pixelDigiHandle; + iEvent.getByToken(pixelDigi_token_, pixelDigiHandle); + + edm::DetSetVector::const_iterator iterDet; + for (iterDet = pixelDigiHandle->begin(); iterDet != pixelDigiHandle->end(); iterDet++) { + DetId tkId = iterDet->id; + edm::DetSet theDigis = (*pixelDigiHandle)[tkId]; + std::vector hitlist; + std::vector id; + + if (tkId.subdetId() == PixelSubdetector::PixelBarrel) { + int layer_num = tTopo.pxbLayer(tkId.rawId()); + int ladder_num = tTopo.pxbLadder(tkId.rawId()); + int module_num = tTopo.pxbModule(tkId.rawId()); + id = {tkId.subdetId(), layer_num, ladder_num, module_num}; + } else if (tkId.subdetId() == PixelSubdetector::PixelEndcap) { + int module_num = tTopo.pxfModule(tkId()); + int disk_num = tTopo.pxfDisk(tkId()); + int blade_num = tTopo.pxfBlade(tkId()); + int panel_num = tTopo.pxfPanel(tkId()); + int side_num = tTopo.pxfSide(tkId()); + id = {tkId.subdetId(), module_num, disk_num, blade_num, panel_num, side_num}; + } + + for (auto iterDigi = theDigis.begin(); iterDigi != theDigis.end(); ++iterDigi) { + hitlist.emplace_back(Hit(iterDigi->row(), iterDigi->column(), iterDigi->adc())); + } + + std::vector chips = processHits(hitlist); + + DetSet DetSetQCores(tkId); + DetSet DetSetBitStream(tkId); + + for (size_t i = 0; i < chips.size(); i++) { + ReadoutChip chip = chips[i]; + std::vector qcores = chip.get_organized_QCores(); + for (auto& qcore : qcores) { + DetSetQCores.push_back(qcore); + } + + ROCBitStream aROCBitStream(i, chip.get_chip_code()); + DetSetBitStream.push_back(aROCBitStream); } - iEvent.put( std::move(aQCoreVector) ); - iEvent.put( std::move(aBitStreamVector) ); + aBitStreamVector->insert(DetSetBitStream); + aQCoreVector->insert(DetSetQCores); + } + + iEvent.put(std::move(aQCoreVector)); + iEvent.put(std::move(aBitStreamVector)); } -void PixelQCoreProducer::beginJob(edm::EventSetup const&){} +void PixelQCoreProducer::beginJob(edm::EventSetup const&) {} -void PixelQCoreProducer::endJob(){} +void PixelQCoreProducer::endJob() {} DEFINE_FWK_MODULE(PixelQCoreProducer); - diff --git a/EventFilter/Phase2TrackerRawToDigi/test/plugins/Phase2PixelQCoreNtuple.cc b/EventFilter/Phase2TrackerRawToDigi/test/plugins/Phase2PixelQCoreNtuple.cc index 02f5da78b10f8..0237eaefa4a3d 100644 --- a/EventFilter/Phase2TrackerRawToDigi/test/plugins/Phase2PixelQCoreNtuple.cc +++ b/EventFilter/Phase2TrackerRawToDigi/test/plugins/Phase2PixelQCoreNtuple.cc @@ -120,7 +120,7 @@ class Phase2PixelQCoreNtuple : public edm::one::EDAnalyzer<> { const GeomDet* PixGeom, const TrajectoryStateOnSurface tsos); - void processHits(const std::vector >& hitList); + void processHits(const std::vector>& hitList); std::pair computeAnglesFromDetPosition(const SiPixelCluster& cl, const PixelTopology& top, @@ -129,11 +129,11 @@ class Phase2PixelQCoreNtuple : public edm::one::EDAnalyzer<> { private: edm::ParameterSet const conf_; edm::ESGetToken tTopoToken_; - edm::ESGetToken geomToken_; + edm::ESGetToken geomToken_; TrackerHitAssociator::Config trackerHitAssociatorConfig_; edm::EDGetTokenT> pixelRecHits_token_; - edm::EDGetTokenT > qcore_token_; - edm::EDGetTokenT > bitstream_token_; + edm::EDGetTokenT> qcore_token_; + edm::EDGetTokenT> bitstream_token_; edm::EDGetTokenT> pixelDigi_token_; edm::EDGetTokenT> recoTracks_token_; edm::EDGetTokenT tta_token_; @@ -208,20 +208,19 @@ class Phase2PixelQCoreNtuple : public edm::one::EDAnalyzer<> { }; Phase2PixelQCoreNtuple::Phase2PixelQCoreNtuple(edm::ParameterSet const& conf) - : tTopoToken_(esConsumes()), + : tTopoToken_(esConsumes()), geomToken_(esConsumes()), trackerHitAssociatorConfig_(conf, consumesCollector()), pixelRecHits_token_(consumes>(edm::InputTag("siPixelRecHits"))), - qcore_token_(consumes >(edm::InputTag("PixelQCore"))), - bitstream_token_(consumes >(edm::InputTag("PixelQCore"))), + qcore_token_(consumes>(edm::InputTag("PixelQCore"))), + bitstream_token_(consumes>(edm::InputTag("PixelQCore"))), pixelDigi_token_(consumes>(conf.getParameter("siPixelDigi"))), recoTracks_token_(consumes>(conf.getParameter("trackProducer"))), tta_token_(consumes(conf.getParameter("trajectoryInput"))), verbose_(conf.getUntrackedParameter("verbose", false)), picky_(conf.getUntrackedParameter("picky", false)), pixeltree_(0), - pixeltreeOnTrack_(0) -{} + pixeltreeOnTrack_(0) {} Phase2PixelQCoreNtuple::~Phase2PixelQCoreNtuple() {} @@ -348,7 +347,6 @@ void Phase2PixelQCoreNtuple::beginJob() { // Functions that gets called by framework every event void Phase2PixelQCoreNtuple::analyze(const edm::Event& e, const edm::EventSetup& es) { - //Retrieve tracker topology from geometry const TrackerTopology* const tTopo = &es.getData(tTopoToken_); @@ -361,43 +359,33 @@ void Phase2PixelQCoreNtuple::analyze(const edm::Event& e, const edm::EventSetup& edm::Handle recHitColl; e.getByToken(pixelRecHits_token_, recHitColl); - edm::Handle > aQCoreVector; + edm::Handle> aQCoreVector; e.getByToken(qcore_token_, aQCoreVector); - edm::Handle > aBitStreamVector; + edm::Handle> aBitStreamVector; e.getByToken(bitstream_token_, aBitStreamVector); edm::DetSetVector::const_iterator iterDet; - for ( iterDet = aQCoreVector->begin(); - iterDet != aQCoreVector->end(); - iterDet++ ) { - + for (iterDet = aQCoreVector->begin(); iterDet != aQCoreVector->end(); iterDet++) { DetId tkId = iterDet->id; - edm::DetSet theQCores = (*aQCoreVector)[ tkId ]; + edm::DetSet theQCores = (*aQCoreVector)[tkId]; //std::cout << "QCORE DETID NEW : " << tkId.rawId() << std::endl; - for ( auto iterQCore = theQCores.begin(); - iterQCore != theQCores.end(); - ++iterQCore ) { + for (auto iterQCore = theQCores.begin(); iterQCore != theQCores.end(); ++iterQCore) { } } edm::DetSetVector::const_iterator iterDetBitStream; - for ( iterDetBitStream = aBitStreamVector->begin(); - iterDetBitStream != aBitStreamVector->end(); - iterDetBitStream++ ) { - + for (iterDetBitStream = aBitStreamVector->begin(); iterDetBitStream != aBitStreamVector->end(); iterDetBitStream++) { DetId tkId = iterDetBitStream->id; - edm::DetSet theBitStreams = (*aBitStreamVector)[ tkId ]; + edm::DetSet theBitStreams = (*aBitStreamVector)[tkId]; //std::cout << "BITSTREAM DETID : " << tkId.rawId() << std::endl; - for ( auto iterBitStream = theBitStreams.begin(); - iterBitStream != theBitStreams.end(); - ++iterBitStream ) { + for (auto iterBitStream = theBitStreams.begin(); iterBitStream != theBitStreams.end(); ++iterBitStream) { //std::cout << "BITSTREAM : " << iterBitStream->get_rocid() << " size = " << iterBitStream->get_bitstream().size() << std::endl; } } @@ -405,7 +393,7 @@ void Phase2PixelQCoreNtuple::analyze(const edm::Event& e, const edm::EventSetup& // for finding matched simhit TrackerHitAssociator associate(e, trackerHitAssociatorConfig_); - edm::Handle > pixelDigiHandle; + edm::Handle> pixelDigiHandle; e.getByToken(pixelDigi_token_, pixelDigiHandle); /* @@ -668,18 +656,18 @@ void Phase2PixelQCoreNtuple::analyze(const edm::Event& e, const edm::EventSetup& // Function for filling in all the rechits // I know it is lazy to pass everything, but I'm doing it anyway. -EB void Phase2PixelQCoreNtuple::fillPRecHit(const int detid_db, - const int subid, - const int layer_num, - const int ladder_num, - const int module_num, - const int disk_num, - const int blade_num, - const int panel_num, - const int side_num, - SiPixelRecHitCollection::DetSet::const_iterator pixeliter, - const int num_simhit, - const PSimHit* closest_simhit, - const GeomDet* PixGeom) { + const int subid, + const int layer_num, + const int ladder_num, + const int module_num, + const int disk_num, + const int blade_num, + const int panel_num, + const int side_num, + SiPixelRecHitCollection::DetSet::const_iterator pixeliter, + const int num_simhit, + const PSimHit* closest_simhit, + const GeomDet* PixGeom) { LocalPoint lp = pixeliter->localPosition(); LocalError le = pixeliter->localPositionError(); @@ -775,26 +763,25 @@ void Phase2PixelQCoreNtuple::fillPRecHit(const int detid_db, // float cotalpha = sim_xdir/sim_zdir; // beta: angle with respect to local y axis in local (y,z) plane // float cotbeta = sim_ydir/sim_zdir; - } } // Function for filling in on track rechits void Phase2PixelQCoreNtuple::fillPRecHit(const int detid_db, - const int subid, - const int layer_num, - const int ladder_num, - const int module_num, - const int disk_num, - const int blade_num, - const int panel_num, - const int side_num, - const TrackingRecHit* recHit, - const SiPixelRecHit* pixHit, - const int num_simhit, - const PSimHit* closest_simhit, - const GeomDet* PixGeom, - const TrajectoryStateOnSurface tsos) { + const int subid, + const int layer_num, + const int ladder_num, + const int module_num, + const int disk_num, + const int blade_num, + const int panel_num, + const int side_num, + const TrackingRecHit* recHit, + const SiPixelRecHit* pixHit, + const int num_simhit, + const PSimHit* closest_simhit, + const GeomDet* PixGeom, + const TrajectoryStateOnSurface tsos) { LocalPoint lp = recHit->localPosition(); LocalError le = recHit->localPositionError(); @@ -894,7 +881,6 @@ void Phase2PixelQCoreNtuple::fillPRecHit(const int detid_db, // float cotalpha = sim_xdir/sim_zdir; // beta: angle with respect to local y axis in local (y,z) plane // float cotbeta = sim_ydir/sim_zdir; - } } @@ -955,8 +941,8 @@ void Phase2PixelQCoreNtuple::RecHit::init() { fDgN = 0; } std::pair Phase2PixelQCoreNtuple::computeAnglesFromDetPosition(const SiPixelCluster& cl, - const PixelTopology& theTopol, - const GeomDetUnit& theDet) const { + const PixelTopology& theTopol, + const GeomDetUnit& theDet) const { // get cluster center of gravity (of charge) float xcenter = cl.x(); float ycenter = cl.y(); @@ -980,11 +966,7 @@ std::pair Phase2PixelQCoreNtuple::computeAnglesFromDetPosition(con return std::make_pair(cotalpha_, cotbeta_); } -void Phase2PixelQCoreNtuple::processHits(const std::vector >& hitList) { - -} - +void Phase2PixelQCoreNtuple::processHits(const std::vector>& hitList) {} //define this as a plug-in DEFINE_FWK_MODULE(Phase2PixelQCoreNtuple); -