Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/ForwardDetId/interface/HGCalTriggerDetId.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include <ostream>
0004 #include <iostream>
0005 
0006 const HGCalTriggerDetId HGCalTriggerDetId::Undefined(HGCalEETrigger, 0, 0, 0, 0, 0, 0, 0);
0007 
0008 HGCalTriggerDetId::HGCalTriggerDetId() : DetId() {}
0009 
0010 HGCalTriggerDetId::HGCalTriggerDetId(uint32_t rawid) : DetId(rawid) {}
0011 
0012 HGCalTriggerDetId::HGCalTriggerDetId(
0013     int subdet, int zp, int type, int layer, int waferU, int waferV, int cellU, int cellV)
0014     : DetId(HGCalTrigger, ForwardEmpty) {
0015   int waferUabs(std::abs(waferU)), waferVabs(std::abs(waferV));
0016   int waferUsign = (waferU >= 0) ? 0 : 1;
0017   int waferVsign = (waferV >= 0) ? 0 : 1;
0018   int zside = (zp < 0) ? 1 : 0;
0019   id_ |= (((cellU & kHGCalCellUMask) << kHGCalCellUOffset) | ((cellV & kHGCalCellVMask) << kHGCalCellVOffset) |
0020           ((waferUabs & kHGCalWaferUMask) << kHGCalWaferUOffset) |
0021           ((waferUsign & kHGCalWaferUSignMask) << kHGCalWaferUSignOffset) |
0022           ((waferVabs & kHGCalWaferVMask) << kHGCalWaferVOffset) |
0023           ((waferVsign & kHGCalWaferVSignMask) << kHGCalWaferVSignOffset) |
0024           ((layer & kHGCalLayerMask) << kHGCalLayerOffset) | ((zside & kHGCalZsideMask) << kHGCalZsideOffset) |
0025           ((type & kHGCalTypeMask) << kHGCalTypeOffset) | ((subdet & kHGCalSubdetMask) << kHGCalSubdetOffset));
0026 }
0027 
0028 HGCalTriggerDetId::HGCalTriggerDetId(const DetId& gen) {
0029   if (!gen.null()) {
0030     if (gen.det() != HGCalTrigger) {
0031       throw cms::Exception("Invalid DetId")
0032           << "Cannot initialize HGCalTriggerDetId from " << std::hex << gen.rawId() << std::dec;
0033     }
0034   }
0035   id_ = gen.rawId();
0036 }
0037 
0038 HGCalTriggerDetId& HGCalTriggerDetId::operator=(const DetId& gen) {
0039   if (!gen.null()) {
0040     if (gen.det() != HGCalTrigger) {
0041       throw cms::Exception("Invalid DetId")
0042           << "Cannot assign HGCalTriggerDetId from " << std::hex << gen.rawId() << std::dec;
0043     }
0044   }
0045   id_ = gen.rawId();
0046   return (*this);
0047 }
0048 
0049 int HGCalTriggerDetId::triggerCellX() const {
0050   int nT = ((type() == HGCSiliconDetId::HGCalHD120) || (type() == HGCSiliconDetId::HGCalHD200))
0051                ? HGCSiliconDetId::HGCalFineTrigger
0052                : HGCSiliconDetId::HGCalCoarseTrigger;
0053   int N = nT * HGCalTriggerCell;
0054   std::vector<int> vc = cellV();
0055   int x(0);
0056   for (auto const& v : vc) {
0057     x += (3 * (v - N) + 2);
0058   }
0059   return (x / static_cast<int>(vc.size()));
0060 }
0061 
0062 int HGCalTriggerDetId::triggerCellY() const {
0063   int nT = ((type() == HGCSiliconDetId::HGCalHD120) || (type() == HGCSiliconDetId::HGCalHD200))
0064                ? HGCSiliconDetId::HGCalFineTrigger
0065                : HGCSiliconDetId::HGCalCoarseTrigger;
0066   int N = nT * HGCalTriggerCell;
0067   std::vector<int> uc = cellU();
0068   std::vector<int> vc = cellV();
0069   int y(0);
0070   for (unsigned int k = 0; k < uc.size(); ++k) {
0071     y += (2 * uc[k] - (N + vc[k]));
0072   }
0073   return (y / static_cast<int>(vc.size()));
0074 }
0075 
0076 std::vector<int> HGCalTriggerDetId::cellU() const {
0077   std::vector<int> uc;
0078   int nT = ((type() == HGCSiliconDetId::HGCalHD120) || (type() == HGCSiliconDetId::HGCalHD200))
0079                ? HGCSiliconDetId::HGCalFineTrigger
0080                : HGCSiliconDetId::HGCalCoarseTrigger;
0081   if ((triggerCellU() >= HGCalTriggerCell) && (triggerCellV() >= HGCalTriggerCell)) {
0082     int u0 = nT * triggerCellU();
0083     for (int i = 0; i < nT; ++i) {
0084       for (int j = 0; j < nT; ++j) {
0085         uc.emplace_back(u0 + i);
0086       }
0087     }
0088   } else if ((triggerCellU() < HGCalTriggerCell) && (triggerCellU() <= triggerCellV())) {
0089     int u0 = nT * triggerCellU();
0090     for (int i = 0; i < nT; ++i) {
0091       for (int j = 0; j < nT; ++j) {
0092         uc.emplace_back(u0 + i);
0093       }
0094     }
0095   } else {
0096     int u0 = nT * (triggerCellU() - 1) + 1;
0097     for (int i = 0; i < nT; ++i) {
0098       for (int j = 0; j < nT; ++j) {
0099         uc.emplace_back(u0 + j);
0100       }
0101       ++u0;
0102     }
0103   }
0104   return uc;
0105 }
0106 
0107 std::vector<int> HGCalTriggerDetId::cellV() const {
0108   std::vector<int> vc;
0109   int nT = ((type() == HGCSiliconDetId::HGCalHD120) || (type() == HGCSiliconDetId::HGCalHD200))
0110                ? HGCSiliconDetId::HGCalFineTrigger
0111                : HGCSiliconDetId::HGCalCoarseTrigger;
0112   if ((triggerCellU() >= HGCalTriggerCell) && (triggerCellV() >= HGCalTriggerCell)) {
0113     int v0 = nT * triggerCellV();
0114     for (int i = 0; i < nT; ++i) {
0115       for (int j = 0; j < nT; ++j) {
0116         vc.emplace_back(v0 + j);
0117       }
0118     }
0119   } else if ((triggerCellU() < HGCalTriggerCell) && (triggerCellU() <= triggerCellV())) {
0120     int v0 = nT * triggerCellV();
0121     for (int i = 0; i < nT; ++i) {
0122       for (int j = 0; j < nT; ++j) {
0123         vc.emplace_back(v0 + j);
0124       }
0125       ++v0;
0126     }
0127   } else {
0128     int v0 = nT * triggerCellV();
0129     for (int i = 0; i < nT; ++i) {
0130       for (int j = 0; j < nT; ++j) {
0131         vc.emplace_back(v0 + i);
0132       }
0133     }
0134   }
0135   return vc;
0136 }
0137 
0138 std::vector<std::pair<int, int> > HGCalTriggerDetId::cellUV() const {
0139   std::vector<int> uc = cellU();
0140   std::vector<int> vc = cellV();
0141   std::vector<std::pair<int, int> > uv;
0142   for (unsigned int k = 0; k < uc.size(); ++k) {
0143     uv.emplace_back(std::pair<int, int>(uc[k], vc[k]));
0144   }
0145   return uv;
0146 }
0147 
0148 std::ostream& operator<<(std::ostream& s, const HGCalTriggerDetId& id) {
0149   return s << " EE:HSil= " << id.isEE() << ":" << id.isHSilicon() << " type= " << id.type() << " z= " << id.zside()
0150            << " layer= " << id.layer() << " wafer(u,v:x,y)= (" << id.waferU() << "," << id.waferV() << ":"
0151            << id.waferX() << "," << id.waferY() << ")"
0152            << " triggerCell(u,v:x,y)= (" << id.triggerCellU() << "," << id.triggerCellV() << ":" << id.triggerCellX()
0153            << "," << id.triggerCellY() << ")";
0154 }