Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include <ostream>
0004 #include <iostream>
0005 
0006 const HGCScintillatorDetId HGCScintillatorDetId::Undefined(0, 0, 0, 0, false);
0007 
0008 HGCScintillatorDetId::HGCScintillatorDetId() : DetId() {}
0009 
0010 HGCScintillatorDetId::HGCScintillatorDetId(uint32_t rawid) : DetId(rawid) {}
0011 
0012 HGCScintillatorDetId::HGCScintillatorDetId(int type, int layer, int ring, int phi, bool trigger, int sipm)
0013     : DetId(HGCalHSc, ForwardEmpty) {
0014   int zside = (ring < 0) ? 1 : 0;
0015   int itrig = trigger ? 1 : 0;
0016   int ringAbs = std::abs(ring);
0017   id_ |= (((type & kHGCalTypeMask) << kHGCalTypeOffset) | ((zside & kHGCalZsideMask) << kHGCalZsideOffset) |
0018           ((sipm & kHGCalSiPMMask) << kHGCalSiPMOffset) | ((itrig & kHGCalTriggerMask) << kHGCalTriggerOffset) |
0019           ((layer & kHGCalLayerMask) << kHGCalLayerOffset) | ((ringAbs & kHGCalRadiusMask) << kHGCalRadiusOffset) |
0020           ((phi & kHGCalPhiMask) << kHGCalPhiOffset));
0021 }
0022 
0023 HGCScintillatorDetId::HGCScintillatorDetId(const DetId& gen) {
0024   if (!gen.null()) {
0025     if (gen.det() != HGCalHSc) {
0026       throw cms::Exception("Invalid DetId")
0027           << "Cannot initialize HGCScintillatorDetId from " << std::hex << gen.rawId() << std::dec;
0028     }
0029   }
0030   id_ = gen.rawId();
0031 }
0032 
0033 HGCScintillatorDetId& HGCScintillatorDetId::operator=(const DetId& gen) {
0034   if (!gen.null()) {
0035     if (gen.det() != HGCalHSc) {
0036       throw cms::Exception("Invalid DetId")
0037           << "Cannot assign HGCScintillatorDetId from " << std::hex << gen.rawId() << std::dec;
0038     }
0039   }
0040   id_ = gen.rawId();
0041   return (*this);
0042 }
0043 
0044 int HGCScintillatorDetId::ring() const {
0045   if (trigger())
0046     return (2 * ((id_ >> kHGCalRadiusOffset) & kHGCalRadiusMask));
0047   else
0048     return ((id_ >> kHGCalRadiusOffset) & kHGCalRadiusMask);
0049 }
0050 
0051 int HGCScintillatorDetId::iradiusTriggerAbs() const {
0052   if (trigger())
0053     return ((ring() + 1) / 2);
0054   else
0055     return ring();
0056 }
0057 
0058 int HGCScintillatorDetId::iphi() const {
0059   if (trigger())
0060     return (2 * ((id_ >> kHGCalPhiOffset) & kHGCalPhiMask));
0061   else
0062     return ((id_ >> kHGCalPhiOffset) & kHGCalPhiMask);
0063 }
0064 
0065 int HGCScintillatorDetId::iphiTrigger() const {
0066   if (trigger())
0067     return ((iphi() + 1) / 2);
0068   else
0069     return iphi();
0070 }
0071 
0072 void HGCScintillatorDetId::setType(int type) {
0073   id_ &= kHGCalTypeMask0;
0074   id_ |= ((type & kHGCalTypeMask) << kHGCalTypeOffset);
0075 }
0076 
0077 void HGCScintillatorDetId::setSiPM(int sipm) {
0078   id_ &= kHGCalSiPMMask0;
0079   id_ |= ((sipm & kHGCalSiPMMask) << kHGCalSiPMOffset);
0080 }
0081 
0082 std::vector<HGCScintillatorDetId> HGCScintillatorDetId::detectorCells() const {
0083   std::vector<HGCScintillatorDetId> cells;
0084   int irad = ring();
0085   int ifi = iphi();
0086   int iz = zside();
0087   if (trigger()) {
0088     cells.emplace_back(HGCScintillatorDetId(type(), layer(), (2 * irad - 1) * iz, 2 * ifi - 1, false));
0089     cells.emplace_back(HGCScintillatorDetId(type(), layer(), 2 * irad * iz, 2 * ifi - 1, false));
0090     cells.emplace_back(HGCScintillatorDetId(type(), layer(), (2 * irad - 1) * iz, 2 * ifi, false));
0091     cells.emplace_back(HGCScintillatorDetId(type(), layer(), 2 * irad * iz, 2 * ifi, false));
0092   } else {
0093     cells.emplace_back(HGCScintillatorDetId(type(), layer(), irad * iz, ifi, false));
0094   }
0095   return cells;
0096 }
0097 
0098 HGCScintillatorDetId HGCScintillatorDetId::geometryCell() const {
0099   if (trigger()) {
0100     return HGCScintillatorDetId(type(), layer(), iradiusTrigger(), iphiTrigger(), false);
0101   } else {
0102     return HGCScintillatorDetId(type(), layer(), iradius(), iphi(), false);
0103   }
0104 }
0105 
0106 HGCScintillatorDetId HGCScintillatorDetId::triggerCell() const {
0107   if (trigger())
0108     return HGCScintillatorDetId(type(), layer(), iradius(), iphi(), true);
0109   else
0110     return HGCScintillatorDetId(type(), layer(), iradiusTrigger(), iphiTrigger(), true);
0111 }
0112 
0113 std::ostream& operator<<(std::ostream& s, const HGCScintillatorDetId& id) {
0114   return s << " HGCScintillatorDetId::EE:HE= " << id.isEE() << ":" << id.isHE() << " trigger= " << id.trigger()
0115            << " type= " << id.type() << " SiPM= " << id.sipm() << " layer= " << id.layer() << " ring= " << id.iradius()
0116            << ":" << id.iradiusTrigger() << " phi= " << id.iphi() << ":" << id.iphiTrigger();
0117 }