HGCalEntityList

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#ifndef _geometry_hgcalmapping_hgcalmappingtools_h_
#define _geometry_hgcalmapping_hgcalmappingtools_h_

#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
#include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
#include "DataFormats/HGCalDigi/interface/HGCalElectronicsId.h"
#include <map>
#include <algorithm>

namespace hgcal {

  namespace mappingtools {

    /**
     * @class HGCalEntityList is a helper class is used to hold the values of the different rows
     * as strings. The class builds its structure and indexing from parsing ascii files separated by spaces
     * assuming the first row is the header
    */
    class HGCalEntityList {
    public:
      typedef std::string HGCalEntityAttr;
      typedef std::vector<HGCalEntityAttr> HGCalEntityRow;

      HGCalEntityList() {}

      /**
           * @short builds the entity list from a file
          */
      void buildFrom(std::string url);

      /**
           * @short gets the attribute corresponding the column col in a row
          */
      HGCalEntityAttr getAttr(std::string col, HGCalEntityRow &row) {
        auto it = columnIndex_.find(col);
        if (it == columnIndex_.end()) {
          throw cms::Exception("ValueError") << "Request for unknown column " << col;
        }
        return row[it->second];
      }
      float getFloatAttr(std::string col, HGCalEntityRow &row) { return (float)atof(getAttr(col, row).c_str()); }
      float getIntAttr(std::string col, HGCalEntityRow &row) { return atoi(getAttr(col, row).c_str()); }
      const std::vector<HGCalEntityRow> &getEntries() { return entities_; }
      HGCalEntityRow getColumnNames() { return colNames_; }
      bool hasColumn(std::string_view col) {
        return std::find(colNames_.begin(), colNames_.end(), col) != colNames_.end();
      }

    private:
      HGCalEntityRow colNames_;
      std::map<HGCalEntityAttr, size_t> columnIndex_;
      std::vector<HGCalEntityRow> entities_;
      void setHeader(HGCalEntityRow &header) {
        for (size_t i = 0; i < header.size(); i++) {
          std::string cname = header[i];
          colNames_.push_back(cname);
          columnIndex_[cname] = i;
        }
      }
      void addRow(HGCalEntityRow &row) { entities_.push_back(row); }
    };

    uint16_t getEcondErx(uint16_t chip, uint16_t half);
    uint32_t getElectronicsId(
        bool zside, uint16_t fedid, uint16_t captureblock, uint16_t econdidx, int cellchip, int cellhalf, int cellseq);
    uint32_t getSiDetId(bool zside, int moduleplane, int moduleu, int modulev, int celltype, int celliu, int celliv);
    uint32_t getSiPMDetId(bool zside, int moduleplane, int modulev, int celltype, int celliu, int celliv);

    /**
     * @short matches the module and cell info by detId and returns their indices (-1 is used in case index was not found)
     */
    template <class T1, class T2>
    std::pair<int32_t, int32_t> getModuleCellIndicesForSiCell(const T1 &modules, const T2 &cells, uint32_t detid) {
      std::pair<int32_t, int32_t> key(-1, -1);

      //get the module and cell parts of the id
      HGCSiliconDetId siid(detid);

      // match module det id
      uint32_t modid = siid.moduleId().rawId();
      for (int i = 0; i < modules.view().metadata().size(); i++) {
        auto imod = modules.view()[i];
        if (imod.detid() != modid)
          continue;

        key.first = i;

        //match cell by type of module and by cell det id
        DetId::Detector det(DetId::Detector::HGCalEE);
        uint32_t cellid = 0x3ff & HGCSiliconDetId(det, 0, 0, 0, 0, 0, siid.cellU(), siid.cellV()).rawId();
        for (int j = 0; j < cells.view().metadata().size(); j++) {
          auto jcell = cells.view()[j];

          if (jcell.typeidx() != imod.typeidx())
            continue;
          if (jcell.detid() != cellid)
            continue;

          key.second = j;
          return key;
        }

        return key;
      }

      return key;
    }

    /**
     * @short after getting the module/cell indices it returns the sum of the corresponding electronics ids
    */
    template <class T1, class T2>
    uint32_t getElectronicsIdForSiCell(const T1 &modules, const T2 &cells, uint32_t detid) {
      std::pair<int32_t, int32_t> idx = getModuleCellIndicesForSiCell<T1, T2>(modules, cells, detid);
      if (idx.first < 0 || idx.first < 0)
        return 0;
      return modules.view()[idx.first].eleid() + cells.view()[idx.second].eleid();
    }

  }  // namespace mappingtools

}  // namespace hgcal

#endif