File indexing completed on 2025-01-18 03:42:04
0001 #ifndef _geometry_hgcalmapping_hgcalmappingtools_h_
0002 #define _geometry_hgcalmapping_hgcalmappingtools_h_
0003
0004 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0005 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0006 #include "DataFormats/HGCalDigi/interface/HGCalElectronicsId.h"
0007 #include <map>
0008 #include <algorithm>
0009
0010 namespace hgcal {
0011
0012 namespace mappingtools {
0013
0014
0015
0016
0017
0018
0019 class HGCalEntityList {
0020 public:
0021 typedef std::string HGCalEntityAttr;
0022 typedef std::vector<HGCalEntityAttr> HGCalEntityRow;
0023
0024 HGCalEntityList() {}
0025
0026
0027
0028
0029 void buildFrom(std::string url);
0030
0031
0032
0033
0034 HGCalEntityAttr getAttr(std::string col, HGCalEntityRow &row) {
0035 auto it = columnIndex_.find(col);
0036 if (it == columnIndex_.end()) {
0037 throw cms::Exception("ValueError") << "Request for unknown column " << col;
0038 }
0039 return row[it->second];
0040 }
0041 float getFloatAttr(std::string col, HGCalEntityRow &row) { return (float)atof(getAttr(col, row).c_str()); }
0042 float getIntAttr(std::string col, HGCalEntityRow &row) { return atoi(getAttr(col, row).c_str()); }
0043 const std::vector<HGCalEntityRow> &getEntries() { return entities_; }
0044 HGCalEntityRow getColumnNames() { return colNames_; }
0045 bool hasColumn(std::string_view col) {
0046 return std::find(colNames_.begin(), colNames_.end(), col) != colNames_.end();
0047 }
0048
0049 private:
0050 HGCalEntityRow colNames_;
0051 std::map<HGCalEntityAttr, size_t> columnIndex_;
0052 std::vector<HGCalEntityRow> entities_;
0053 void setHeader(HGCalEntityRow &header) {
0054 for (size_t i = 0; i < header.size(); i++) {
0055 std::string cname = header[i];
0056 colNames_.push_back(cname);
0057 columnIndex_[cname] = i;
0058 }
0059 }
0060 void addRow(HGCalEntityRow &row) { entities_.push_back(row); }
0061 };
0062
0063 uint16_t getEcondErx(uint16_t chip, uint16_t half);
0064 uint32_t getElectronicsId(
0065 bool zside, uint16_t fedid, uint16_t captureblock, uint16_t econdidx, int cellchip, int cellhalf, int cellseq);
0066 uint32_t getSiDetId(bool zside, int moduleplane, int moduleu, int modulev, int celltype, int celliu, int celliv);
0067 uint32_t getSiPMDetId(bool zside, int moduleplane, int modulev, int celltype, int celliu, int celliv);
0068
0069
0070
0071
0072 template <class T1, class T2>
0073 std::pair<int32_t, int32_t> getModuleCellIndicesForSiCell(const T1 &modules, const T2 &cells, uint32_t detid) {
0074 std::pair<int32_t, int32_t> key(-1, -1);
0075
0076
0077 HGCSiliconDetId siid(detid);
0078
0079
0080 uint32_t modid = siid.moduleId().rawId();
0081 for (int i = 0; i < modules.view().metadata().size(); i++) {
0082 auto imod = modules.view()[i];
0083 if (imod.detid() != modid)
0084 continue;
0085
0086 key.first = i;
0087
0088
0089 DetId::Detector det(DetId::Detector::HGCalEE);
0090 uint32_t cellid = 0x3ff & HGCSiliconDetId(det, 0, 0, 0, 0, 0, siid.cellU(), siid.cellV()).rawId();
0091 for (int j = 0; j < cells.view().metadata().size(); j++) {
0092 auto jcell = cells.view()[j];
0093
0094 if (jcell.typeidx() != imod.typeidx())
0095 continue;
0096 if (jcell.detid() != cellid)
0097 continue;
0098
0099 key.second = j;
0100 return key;
0101 }
0102
0103 return key;
0104 }
0105
0106 return key;
0107 }
0108
0109
0110
0111
0112 template <class T1, class T2>
0113 uint32_t getElectronicsIdForSiCell(const T1 &modules, const T2 &cells, uint32_t detid) {
0114 std::pair<int32_t, int32_t> idx = getModuleCellIndicesForSiCell<T1, T2>(modules, cells, detid);
0115 if (idx.first < 0 || idx.first < 0)
0116 return 0;
0117 return modules.view()[idx.first].eleid() + cells.view()[idx.second].eleid();
0118 }
0119
0120 }
0121
0122 }
0123
0124 #endif