Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:22

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 =
0051       (type() == HGCSiliconDetId::HGCalFine) ? HGCSiliconDetId::HGCalFineTrigger : HGCSiliconDetId::HGCalCoarseTrigger;
0052   int N = nT * HGCalTriggerCell;
0053   std::vector<int> vc = cellV();
0054   int x(0);
0055   for (auto const& v : vc) {
0056     x += (3 * (v - N) + 2);
0057   }
0058   return (x / static_cast<int>(vc.size()));
0059 }
0060 
0061 int HGCalTriggerDetId::triggerCellY() const {
0062   int nT =
0063       (type() == HGCSiliconDetId::HGCalFine) ? HGCSiliconDetId::HGCalFineTrigger : HGCSiliconDetId::HGCalCoarseTrigger;
0064   int N = nT * HGCalTriggerCell;
0065   std::vector<int> uc = cellU();
0066   std::vector<int> vc = cellV();
0067   int y(0);
0068   for (unsigned int k = 0; k < uc.size(); ++k) {
0069     y += (2 * uc[k] - (N + vc[k]));
0070   }
0071   return (y / static_cast<int>(vc.size()));
0072 }
0073 
0074 std::vector<int> HGCalTriggerDetId::cellU() const {
0075   std::vector<int> uc;
0076   int nT =
0077       (type() == HGCSiliconDetId::HGCalFine) ? HGCSiliconDetId::HGCalFineTrigger : HGCSiliconDetId::HGCalCoarseTrigger;
0078   if ((triggerCellU() >= HGCalTriggerCell) && (triggerCellV() >= HGCalTriggerCell)) {
0079     int u0 = nT * triggerCellU();
0080     for (int i = 0; i < nT; ++i) {
0081       for (int j = 0; j < nT; ++j) {
0082         uc.emplace_back(u0 + i);
0083       }
0084     }
0085   } else if ((triggerCellU() < HGCalTriggerCell) && (triggerCellU() <= triggerCellV())) {
0086     int u0 = nT * triggerCellU();
0087     for (int i = 0; i < nT; ++i) {
0088       for (int j = 0; j < nT; ++j) {
0089         uc.emplace_back(u0 + i);
0090       }
0091     }
0092   } else {
0093     int u0 = nT * (triggerCellU() - 1) + 1;
0094     for (int i = 0; i < nT; ++i) {
0095       for (int j = 0; j < nT; ++j) {
0096         uc.emplace_back(u0 + j);
0097       }
0098       ++u0;
0099     }
0100   }
0101   return uc;
0102 }
0103 
0104 std::vector<int> HGCalTriggerDetId::cellV() const {
0105   std::vector<int> vc;
0106   int nT =
0107       (type() == HGCSiliconDetId::HGCalFine) ? HGCSiliconDetId::HGCalFineTrigger : HGCSiliconDetId::HGCalCoarseTrigger;
0108   if ((triggerCellU() >= HGCalTriggerCell) && (triggerCellV() >= HGCalTriggerCell)) {
0109     int v0 = nT * triggerCellV();
0110     for (int i = 0; i < nT; ++i) {
0111       for (int j = 0; j < nT; ++j) {
0112         vc.emplace_back(v0 + j);
0113       }
0114     }
0115   } else if ((triggerCellU() < HGCalTriggerCell) && (triggerCellU() <= triggerCellV())) {
0116     int v0 = nT * triggerCellV();
0117     for (int i = 0; i < nT; ++i) {
0118       for (int j = 0; j < nT; ++j) {
0119         vc.emplace_back(v0 + j);
0120       }
0121       ++v0;
0122     }
0123   } else {
0124     int v0 = nT * triggerCellV();
0125     for (int i = 0; i < nT; ++i) {
0126       for (int j = 0; j < nT; ++j) {
0127         vc.emplace_back(v0 + i);
0128       }
0129     }
0130   }
0131   return vc;
0132 }
0133 
0134 std::vector<std::pair<int, int> > HGCalTriggerDetId::cellUV() const {
0135   std::vector<int> uc = cellU();
0136   std::vector<int> vc = cellV();
0137   std::vector<std::pair<int, int> > uv;
0138   for (unsigned int k = 0; k < uc.size(); ++k) {
0139     uv.emplace_back(std::pair<int, int>(uc[k], vc[k]));
0140   }
0141   return uv;
0142 }
0143 
0144 std::ostream& operator<<(std::ostream& s, const HGCalTriggerDetId& id) {
0145   return s << " EE:HSil= " << id.isEE() << ":" << id.isHSilicon() << " type= " << id.type() << " z= " << id.zside()
0146            << " layer= " << id.layer() << " wafer(u,v:x,y)= (" << id.waferU() << "," << id.waferV() << ":"
0147            << id.waferX() << "," << id.waferY() << ")"
0148            << " triggerCell(u,v:x,y)= (" << id.triggerCellU() << "," << id.triggerCellV() << ":" << id.triggerCellX()
0149            << "," << id.triggerCellY() << ")";
0150 }