Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:17

0001 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
0002 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 
0005 HcalCastorDetId::HcalCastorDetId() : DetId() {}
0006 
0007 HcalCastorDetId::HcalCastorDetId(uint32_t rawid) : DetId(rawid) {}
0008 
0009 void HcalCastorDetId::buildMe(Section section, bool true_for_positive_eta, int sector, int module) {
0010   sector -= 1;  // we count sector from 1-16 instead of 0-15
0011   id_ |= (true_for_positive_eta << 8) | (sector << 4) | module;
0012 }
0013 
0014 HcalCastorDetId::HcalCastorDetId(Section section, bool true_for_positive_eta, int sector, int module)
0015     : DetId(DetId::Calo, SubdetectorId) {
0016   buildMe(section, true_for_positive_eta, sector, module);
0017 }
0018 
0019 HcalCastorDetId::HcalCastorDetId(bool true_for_positive_eta, int sector, int module)
0020     : DetId(DetId::Calo, SubdetectorId) {
0021   buildMe(Section(Unknown), true_for_positive_eta, sector, module);
0022 }
0023 
0024 HcalCastorDetId::HcalCastorDetId(const DetId& gen) {
0025   if (!gen.null() && (gen.det() != DetId::Calo || gen.subdetId() != SubdetectorId)) {
0026     throw cms::Exception("Invalid DetId")
0027         << "Cannot initialize CASTORDetId from " << std::hex << gen.rawId() << std::dec;
0028   }
0029   id_ = gen.rawId();
0030 }
0031 
0032 HcalCastorDetId& HcalCastorDetId::operator=(const DetId& gen) {
0033   if (!gen.null() && (gen.det() != DetId::Calo || gen.subdetId() != SubdetectorId)) {
0034     throw cms::Exception("Invalid DetId") << "Cannot assign Castor DetId from " << std::hex << gen.rawId() << std::dec;
0035   }
0036 
0037   id_ = gen.rawId();
0038 
0039   return *this;
0040 }
0041 
0042 /*
0043 int HcalCastorDetId::channel() const {
0044   int channelid = 16*(sector-1)+module;
0045   return channelid;
0046 }
0047 */
0048 
0049 HcalCastorDetId::Section HcalCastorDetId::section() const {
0050   const int mod = module();
0051 
0052   Section sect;
0053   if (mod <= 2) {
0054     sect = HcalCastorDetId::EM;
0055   } else {
0056     if (mod > 2 && mod <= 14) {
0057       sect = HcalCastorDetId::HAD;
0058     } else {
0059       sect = HcalCastorDetId::Unknown;
0060     }
0061   }
0062   return sect;
0063 }
0064 
0065 uint32_t HcalCastorDetId::denseIndex() const {
0066   return (kNumberCellsPerEnd * (zside() + 1) / 2 + kNumberSectorsPerEnd * (module() - 1) + sector() - 1);
0067 }
0068 
0069 bool HcalCastorDetId::validDetId(Section iSection, bool posEta, int iSector, int iModule) {
0070   return (0 < iSector && kNumberSectorsPerEnd >= iSector && 0 < iModule && kNumberModulesPerEnd >= iModule);
0071 }
0072 
0073 HcalCastorDetId HcalCastorDetId::detIdFromDenseIndex(uint32_t di) {
0074   return HcalCastorDetId(
0075       kNumberCellsPerEnd <= di, di % kNumberSectorsPerEnd + 1, (di % kNumberCellsPerEnd) / kNumberSectorsPerEnd + 1);
0076 }
0077 
0078 std::ostream& operator<<(std::ostream& s, const HcalCastorDetId& id) {
0079   s << "(CASTOR" << ((id.zside() == 1) ? ("+") : ("-"));
0080 
0081   switch (id.section()) {
0082     case (HcalCastorDetId::EM):
0083       s << " EM ";
0084       break;
0085     case (HcalCastorDetId::HAD):
0086       s << " HAD ";
0087       break;
0088     default:
0089       s << " UNKNOWN ";
0090   }
0091 
0092   return s << id.sector() << ',' << id.module() << ',' << ')';
0093 }