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