File indexing completed on 2024-04-06 12:04:08
0001 #include "DataFormats/ForwardDetId/interface/HGCHEDetId.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include <ostream>
0004
0005 const HGCHEDetId HGCHEDetId::Undefined(ForwardEmpty, 0, 0, 0, 0, 0);
0006
0007 HGCHEDetId::HGCHEDetId() : DetId() {}
0008
0009 HGCHEDetId::HGCHEDetId(uint32_t rawid) : DetId(rawid) {}
0010
0011 HGCHEDetId::HGCHEDetId(ForwardSubdetector subdet, int zp, int lay, int sec, int subsec, int cell)
0012 : DetId(Forward, subdet) {
0013 id_ |= ((cell & kHGCHECellMask) << kHGCHECellOffset);
0014 id_ |= ((sec & kHGCHESectorMask) << kHGCHESectorOffset);
0015 if (subsec < 0)
0016 subsec = 0;
0017 id_ |= ((subsec & kHGCHESubSectorMask) << kHGCHESubSectorOffset);
0018 id_ |= ((lay & kHGCHELayerMask) << kHGCHELayerOffset);
0019 if (zp > 0)
0020 id_ |= ((zp & kHGCHEZsideMask) << kHGCHEZsideOffset);
0021 }
0022
0023 HGCHEDetId::HGCHEDetId(const DetId& gen) {
0024 if (!gen.null()) {
0025 ForwardSubdetector subdet = (ForwardSubdetector(gen.subdetId()));
0026 if ((gen.det() != Forward) || (subdet != HGCHEF && subdet != HGCHEB)) {
0027 throw cms::Exception("Invalid DetId") << "Cannot initialize HGCHEDetId from " << std::hex << gen.rawId()
0028 << std::dec << " Det|SubDet " << gen.det() << "|" << subdet;
0029 }
0030 }
0031 id_ = gen.rawId();
0032 }
0033
0034 HGCHEDetId& HGCHEDetId::operator=(const DetId& gen) {
0035 if (!gen.null()) {
0036 ForwardSubdetector subdet = (ForwardSubdetector(gen.subdetId()));
0037 if ((gen.det() != Forward) || (subdet != HGCHEF && subdet != HGCHEB)) {
0038 throw cms::Exception("Invalid DetId") << "Cannot assign HGCHEDetId from " << std::hex << gen.rawId() << std::dec
0039 << " Det|SubDet " << gen.det() << "|" << subdet;
0040 }
0041 }
0042 id_ = gen.rawId();
0043 return (*this);
0044 }
0045
0046 HGCHEDetId HGCHEDetId::geometryCell() const {
0047 int sub = ((subdet() == HGCHEF) ? 0 : ((id_ >> kHGCHESubSectorOffset) & kHGCHESubSectorMask));
0048 return HGCHEDetId(subdet(), zside(), layer(), sector(), sub, 0);
0049 }
0050
0051 std::ostream& operator<<(std::ostream& s, const HGCHEDetId& id) {
0052 if (id.subdet() == HGCHEF || id.subdet() == HGCHEB) {
0053 return s << "isHE=" << id.isHE() << " zpos=" << id.zside() << " layer=" << id.layer()
0054 << " phi subSector=" << id.subsector() << " sector=" << id.sector() << " cell=" << id.cell();
0055 } else {
0056 return s << std::hex << id.rawId() << std::dec;
0057 }
0058 }