Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 
0004 const int HcalZDCDetId::kZDCChannelMask;
0005 const int HcalZDCDetId::kZDCSectionMask;
0006 const int HcalZDCDetId::kZDCSectionOffset;
0007 const int HcalZDCDetId::kZDCZsideMask;
0008 const int HcalZDCDetId::kZDCRPDMask;
0009 const int HcalZDCDetId::SubdetectorId;
0010 
0011 HcalZDCDetId::HcalZDCDetId() : DetId() {}
0012 
0013 HcalZDCDetId::HcalZDCDetId(uint32_t rawid) : DetId(rawid) {}
0014 
0015 HcalZDCDetId::HcalZDCDetId(Section section, bool true_for_positive_eta, int channel)
0016     : DetId(DetId::Calo, SubdetectorId) {
0017   if (section == RPD) {
0018     id_ |= (Unknown & kZDCSectionMask) << kZDCSectionOffset;
0019     id_ |= kZDCRPDMask;
0020     id_ |= ((channel - 1) & kZDCChannelMask);
0021   } else {
0022     id_ |= (section & kZDCSectionMask) << kZDCSectionOffset;
0023     id_ |= (channel & kZDCChannelMask);
0024   }
0025   if (true_for_positive_eta)
0026     id_ |= kZDCZsideMask;
0027 }
0028 
0029 HcalZDCDetId::HcalZDCDetId(const DetId& gen) {
0030   if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) {
0031     throw cms::Exception("Invalid DetId") << "Cannot initialize ZDCDetId from " << std::hex << gen.rawId() << std::dec;
0032   }
0033   id_ = gen.rawId();
0034 }
0035 
0036 HcalZDCDetId& HcalZDCDetId::operator=(const DetId& gen) {
0037   if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) {
0038     throw cms::Exception("Invalid DetId") << "Cannot assign ZDCDetId from " << std::hex << gen.rawId() << std::dec;
0039   }
0040   id_ = gen.rawId();
0041   return *this;
0042 }
0043 
0044 HcalZDCDetId::Section HcalZDCDetId::section() const {
0045   if (id_ & kZDCRPDMask)
0046     return RPD;
0047   else
0048     return (Section)((id_ >> kZDCSectionOffset) & kZDCSectionMask);
0049 }
0050 
0051 int HcalZDCDetId::depth() const {
0052   const int se(section());
0053   if (se == EM)
0054     return 1;
0055   else if (se == HAD)
0056     return (channel() + 2);
0057   else if (se == RPD)
0058     return 2;
0059   else
0060     return channel();
0061 }
0062 
0063 int HcalZDCDetId::channel() const {
0064   const int se(section());
0065   if (se == RPD)
0066     return (1 + (id_ & kZDCChannelMask));
0067   else
0068     return (id_ & kZDCChannelMask);
0069 }
0070 
0071 uint32_t HcalZDCDetId::denseIndex() const {
0072   const int se(section());
0073   uint32_t di =
0074       (channel() - 1 +
0075        (se == RPD ? 2 * kDepRun1 + (zside() < 0 ? 0 : kDepRPD)
0076                   : ((zside() < 0 ? 0 : kDepRun1) + (se == HAD ? kDepEM : (se == LUM ? kDepEM + kDepHAD : 0)))));
0077   return di;
0078 }
0079 
0080 HcalZDCDetId HcalZDCDetId::detIdFromDenseIndex(uint32_t di) {
0081   if (validDenseIndex(di)) {
0082     bool lz(false);
0083     uint32_t dp(0);
0084     Section se(Unknown);
0085     if (di >= 2 * kDepRun1) {
0086       lz = (di >= (kDepRun1 + kDepTot));
0087       se = RPD;
0088       dp = 1 + ((di - 2 * kDepRun1) % kDepRPD);
0089     } else {
0090       lz = (di >= kDepRun1);
0091       uint32_t in = (di % kDepRun1);
0092       se = (in < kDepEM ? EM : (in < kDepEM + kDepHAD ? HAD : LUM));
0093       dp = (EM == se ? in + 1 : (HAD == se ? in - kDepEM + 1 : in - kDepEM - kDepHAD + 1));
0094     }
0095     return HcalZDCDetId(se, lz, dp);
0096   } else {
0097     return HcalZDCDetId();
0098   }
0099 }
0100 
0101 bool HcalZDCDetId::validDetId(Section se, int dp) {
0102   bool flag = (dp >= 1 && (((se == EM) && (dp <= kDepEM)) || ((se == HAD) && (dp <= kDepHAD)) ||
0103                            ((se == LUM) && (dp <= kDepLUM)) || ((se == RPD) && (dp <= kDepRPD))));
0104   return flag;
0105 }
0106 
0107 std::ostream& operator<<(std::ostream& s, const HcalZDCDetId& id) {
0108   s << "(ZDC" << ((id.zside() == 1) ? ("+") : ("-"));
0109   switch (id.section()) {
0110     case (HcalZDCDetId::EM):
0111       s << " EM ";
0112       break;
0113     case (HcalZDCDetId::HAD):
0114       s << " HAD ";
0115       break;
0116     case (HcalZDCDetId::LUM):
0117       s << " LUM ";
0118       break;
0119     case (HcalZDCDetId::RPD):
0120       s << " RPD ";
0121       break;
0122     default:
0123       s << " UNKNOWN ";
0124   }
0125   return s << id.channel() << "," << id.depth() << ')';
0126 }