Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-02 00:53:33

0001 #ifndef DataFormats_ForwardDetId_HGCSiliconDetId_H
0002 #define DataFormats_ForwardDetId_HGCSiliconDetId_H 1
0003 
0004 #include <iosfwd>
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 #include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 
0009 /* \brief description of the bit assigment
0010    [0:4]   u-coordinate of the cell (measured from the lower left
0011    [5:9]   v-coordinate of the cell  corner of the wafer)
0012    [10:13] abs(u) of the wafer (u-axis points along -x axis)
0013    [14:14] sign of u (0:+u; 1:-u) (u=0 is at the center of beam line)
0014    [15:18] abs(v) of the wafer (v-axis points 60-degree wrt x-axis)
0015    [19:19] sign of v (0:+v; 1:-v) (v=0 is at the center of beam line)
0016    [20:24] layer number 
0017    [25:25] z-side (0 for +z; 1 for -z)
0018    [26:27] Type (0 high density wafer with depltetion thickness of 120 mum
0019                  1 low density wafer with depletion thickness of 200 mum
0020                  2 low density wafer with depletion thickness of 300 mum
0021                  3 high density wafer with depletion thickness of 200 mum)
0022    [28:31] Detector type (HGCalEE or HGCalHSi)
0023 */
0024 class HGCSiliconDetId : public DetId {
0025 public:
0026   enum waferType { HGCalHD120 = 0, HGCalLD200 = 1, HGCalLD300 = 2, HGCalHD200 = 3 };
0027   static constexpr int32_t HGCalHighDensityN = 12;
0028   static constexpr int32_t HGCalLowDensityN = 8;
0029   static constexpr int32_t HGCalFineTrigger = 3;
0030   static constexpr int32_t HGCalCoarseTrigger = 2;
0031   static constexpr int32_t HGCal0Depletion = 120;
0032   static constexpr int32_t HGCal1Depletion = 200;
0033   static constexpr int32_t HGCal2Depletion = 300;
0034 
0035   /** Create a null cellid*/
0036   constexpr HGCSiliconDetId() : DetId() {}
0037   /** Create cellid from raw id (0=invalid tower id) */
0038   constexpr HGCSiliconDetId(uint32_t rawid) : DetId(rawid) {}
0039   /** Constructor from subdetector, zplus, layer, module, cell numbers */
0040   constexpr HGCSiliconDetId(DetId::Detector det,
0041                             int32_t zp,
0042                             int32_t type,
0043                             int32_t layer,
0044                             int32_t waferU,
0045                             int32_t waferV,
0046                             int32_t cellU,
0047                             int32_t cellV)
0048       : DetId(det, ForwardEmpty) {
0049     int32_t waferUabs(std::abs(waferU)), waferVabs(std::abs(waferV));
0050     int32_t waferUsign = (waferU >= 0) ? 0 : 1;
0051     int32_t waferVsign = (waferV >= 0) ? 0 : 1;
0052     int32_t zside = (zp < 0) ? 1 : 0;
0053     id_ |= (((cellU & kHGCalCellUMask) << kHGCalCellUOffset) | ((cellV & kHGCalCellVMask) << kHGCalCellVOffset) |
0054             ((waferUabs & kHGCalWaferUMask) << kHGCalWaferUOffset) |
0055             ((waferUsign & kHGCalWaferUSignMask) << kHGCalWaferUSignOffset) |
0056             ((waferVabs & kHGCalWaferVMask) << kHGCalWaferVOffset) |
0057             ((waferVsign & kHGCalWaferVSignMask) << kHGCalWaferVSignOffset) |
0058             ((layer & kHGCalLayerMask) << kHGCalLayerOffset) | ((zside & kHGCalZsideMask) << kHGCalZsideOffset) |
0059             ((type & kHGCalTypeMask) << kHGCalTypeOffset));
0060   }
0061 
0062   /** Constructor from a generic cell id */
0063   constexpr HGCSiliconDetId(const DetId& gen) {
0064     if (!gen.null()) {
0065       if ((gen.det() != HGCalEE) && (gen.det() != HGCalHSi)) {
0066         throw cms::Exception("Invalid DetId")
0067             << "Cannot initialize HGCSiliconDetId from " << std::hex << gen.rawId() << std::dec;
0068       }
0069     }
0070     id_ = gen.rawId();
0071   }
0072 
0073   /** Assignment from a generic cell id */
0074   constexpr HGCSiliconDetId& operator=(const DetId& gen) {
0075     if (!gen.null()) {
0076       if ((gen.det() != HGCalEE) && (gen.det() != HGCalHSi)) {
0077         throw cms::Exception("Invalid DetId")
0078             << "Cannot assign HGCSiliconDetId from " << std::hex << gen.rawId() << std::dec;
0079       }
0080     }
0081     id_ = gen.rawId();
0082     return (*this);
0083   }
0084 
0085   /** Converter for a geometry cell id */
0086   constexpr HGCSiliconDetId geometryCell() const {
0087     return HGCSiliconDetId(det(), zside(), 0, layer(), waferU(), waferV(), 0, 0);
0088   }
0089   constexpr HGCSiliconDetId moduleId() const {
0090     return HGCSiliconDetId(det(), zside(), type(), layer(), waferU(), waferV(), 0, 0);
0091   }
0092 
0093   /// get the subdetector
0094   constexpr DetId::Detector subdet() const { return det(); }
0095 
0096   /// get the type
0097   constexpr int32_t type() const { return (id_ >> kHGCalTypeOffset) & kHGCalTypeMask; }
0098   constexpr bool lowDensity() const { return ((type() == HGCalLD200) || (type() == HGCalLD300)); }
0099   constexpr bool highDensity() const { return ((type() == HGCalHD120) || (type() == HGCalHD200)); }
0100   constexpr int32_t depletion() const {
0101     return ((type() == HGCalHD120) ? HGCal0Depletion : ((type() == HGCalLD300) ? HGCal2Depletion : HGCal1Depletion));
0102   }
0103 
0104   /// get the z-side of the cell (1/-1)
0105   constexpr int32_t zside() const { return (((id_ >> kHGCalZsideOffset) & kHGCalZsideMask) ? -1 : 1); }
0106 
0107   /// get the layer #
0108   constexpr int32_t layer() const { return (id_ >> kHGCalLayerOffset) & kHGCalLayerMask; }
0109 
0110   /// get the cell #'s in u,v or in x,y
0111   constexpr int32_t cellU() const { return (id_ >> kHGCalCellUOffset) & kHGCalCellUMask; }
0112   constexpr int32_t cellV() const { return (id_ >> kHGCalCellVOffset) & kHGCalCellVMask; }
0113   constexpr std::pair<int32_t, int32_t> cellUV() const { return std::pair<int32_t, int32_t>(cellU(), cellV()); }
0114   constexpr int32_t cellX() const {
0115     int32_t N = ((type() == HGCalHD120) || (type() == HGCalHD200)) ? HGCalHighDensityN : HGCalLowDensityN;
0116     return (3 * (cellV() - N) + 2);
0117   }
0118   constexpr int32_t cellY() const {
0119     int32_t N = ((type() == HGCalHD120) || (type() == HGCalHD200)) ? HGCalHighDensityN : HGCalLowDensityN;
0120     return (2 * cellU() - (N + cellV()));
0121   }
0122   constexpr std::pair<int32_t, int32_t> cellXY() const { return std::pair<int32_t, int32_t>(cellX(), cellY()); }
0123 
0124   /// get the wafer #'s in u,v or in x,y
0125   constexpr int32_t waferUAbs() const { return (id_ >> kHGCalWaferUOffset) & kHGCalWaferUMask; }
0126   constexpr int32_t waferVAbs() const { return (id_ >> kHGCalWaferVOffset) & kHGCalWaferVMask; }
0127   constexpr int32_t waferU() const {
0128     return (((id_ >> kHGCalWaferUSignOffset) & kHGCalWaferUSignMask) ? -waferUAbs() : waferUAbs());
0129   }
0130   constexpr int32_t waferV() const {
0131     return (((id_ >> kHGCalWaferVSignOffset) & kHGCalWaferVSignMask) ? -waferVAbs() : waferVAbs());
0132   }
0133   constexpr std::pair<int32_t, int32_t> waferUV() const { return std::pair<int32_t, int32_t>(waferU(), waferV()); }
0134   constexpr int32_t waferX() const { return (-2 * waferU() + waferV()); }
0135   constexpr int32_t waferY() const { return (2 * waferV()); }
0136   constexpr std::pair<int32_t, int32_t> waferXY() const { return std::pair<int32_t, int32_t>(waferX(), waferY()); }
0137   constexpr void unpack(
0138       int32_t& ty, int32_t& zs, int32_t& ly, int32_t& wU, int32_t& wV, int32_t& cU, int32_t& cV) const {
0139     ty = type();
0140     zs = zside();
0141     ly = layer();
0142     wU = waferU();
0143     wV = waferV();
0144     cU = cellU();
0145     cV = cellV();
0146   }
0147 
0148   // get trigger cell u,v
0149   constexpr int32_t triggerCellU() const {
0150     int32_t N = ((type() == HGCalHD120) || (type() == HGCalHD200)) ? HGCalHighDensityN : HGCalLowDensityN;
0151     int32_t NT = ((type() == HGCalHD120) || (type() == HGCalHD200)) ? HGCalFineTrigger : HGCalCoarseTrigger;
0152     return (cellU() >= N && cellV() >= N)
0153                ? cellU() / NT
0154                : ((cellU() < N && cellU() <= cellV()) ? cellU() / NT : (1 + (cellU() - (cellV() % NT + 1)) / NT));
0155   }
0156   constexpr int32_t triggerCellV() const {
0157     int32_t N = ((type() == HGCalHD120) || (type() == HGCalHD200)) ? HGCalHighDensityN : HGCalLowDensityN;
0158     int32_t NT = ((type() == HGCalHD120) || (type() == HGCalHD200)) ? HGCalFineTrigger : HGCalCoarseTrigger;
0159     return (cellU() >= N && cellV() >= N)
0160                ? cellV() / NT
0161                : ((cellU() < N && cellU() <= cellV()) ? ((cellV() - cellU()) / NT + cellU() / NT) : cellV() / NT);
0162   }
0163   constexpr std::pair<int32_t, int32_t> triggerCellUV() const {
0164     return std::pair<int32_t, int32_t>(triggerCellU(), triggerCellV());
0165   }
0166 
0167   /// consistency check : no bits left => no overhead
0168   constexpr bool isEE() const { return (det() == HGCalEE); }
0169   constexpr bool isHE() const { return (det() == HGCalHSi); }
0170   constexpr bool isForward() const { return true; }
0171 
0172   static const HGCSiliconDetId Undefined;
0173 
0174 public:
0175   static constexpr uint32_t kHGCalCellUOffset = 0;
0176   static constexpr uint32_t kHGCalCellUMask = 0x1F;
0177   static constexpr uint32_t kHGCalCellVOffset = 5;
0178   static constexpr uint32_t kHGCalCellVMask = 0x1F;
0179   static constexpr uint32_t kHGCalWaferUOffset = 10;
0180   static constexpr uint32_t kHGCalWaferUMask = 0xF;
0181   static constexpr uint32_t kHGCalWaferUSignOffset = 14;
0182   static constexpr uint32_t kHGCalWaferUSignMask = 0x1;
0183   static constexpr uint32_t kHGCalWaferVOffset = 15;
0184   static constexpr uint32_t kHGCalWaferVMask = 0xF;
0185   static constexpr uint32_t kHGCalWaferVSignOffset = 19;
0186   static constexpr uint32_t kHGCalWaferVSignMask = 0x1;
0187   static constexpr uint32_t kHGCalLayerOffset = 20;
0188   static constexpr uint32_t kHGCalLayerMask = 0x1F;
0189   static constexpr uint32_t kHGCalZsideOffset = 25;
0190   static constexpr uint32_t kHGCalZsideMask = 0x1;
0191   static constexpr uint32_t kHGCalTypeOffset = 26;
0192   static constexpr uint32_t kHGCalTypeMask = 0x3;
0193 };
0194 
0195 std::ostream& operator<<(std::ostream&, const HGCSiliconDetId& id);
0196 
0197 #endif