Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 const HcalTrigTowerDetId HcalTrigTowerDetId::Undefined(0x4a000000u);
0006 
0007 HcalTrigTowerDetId::HcalTrigTowerDetId() {}
0008 
0009 HcalTrigTowerDetId::HcalTrigTowerDetId(uint32_t rawid) : DetId(rawid) {}
0010 
0011 HcalTrigTowerDetId::HcalTrigTowerDetId(int ieta, int iphi) : DetId(Hcal, HcalTriggerTower) {
0012   id_ |=
0013       ((ieta > 0) ? (kHcalZsideMask | (ieta << kHcalEtaOffset)) : ((-ieta) << kHcalEtaOffset)) | (iphi & kHcalPhiMask);
0014   // Default to depth = 0 & version = 0
0015 }
0016 
0017 HcalTrigTowerDetId::HcalTrigTowerDetId(int ieta, int iphi, int depth) : DetId(Hcal, HcalTriggerTower) {
0018   const int ones = depth % 10;
0019   const int tens = (depth - ones) / 10;
0020   // version convension   0 : default for 3x2 TP; 1, 2, 3 : for future & currently version = 1 is for 1x1 TP
0021   // Note that in this conversion, depth can take values from 0 to 9 for different purpose
0022   // -> so depth should be = ones!
0023   id_ |= ((ones & kHcalDepthMask) << kHcalDepthOffset) |
0024          ((ieta > 0) ? (kHcalZsideMask | (ieta << kHcalEtaOffset)) : ((-ieta) << kHcalEtaOffset)) |
0025          (iphi & kHcalPhiMask);
0026 
0027   const int version = tens;
0028   if (version > 9) {  // do NOT envision to have versions over 9...
0029     edm::LogError("HcalTrigTowerDetId") << "in its ctor using depth, version larger than 9 (too many of it!)?"
0030                                         << std::endl;
0031   }
0032 
0033   id_ |= ((version & kHcalVersMask) << kHcalVersOffset);
0034 }
0035 
0036 HcalTrigTowerDetId::HcalTrigTowerDetId(int ieta, int iphi, int depth, int version) : DetId(Hcal, HcalTriggerTower) {
0037   id_ |= ((depth & kHcalDepthMask) << kHcalDepthOffset) |
0038          ((ieta > 0) ? (kHcalZsideMask | (ieta << kHcalEtaOffset)) : ((-ieta) << kHcalEtaOffset)) |
0039          (iphi & kHcalPhiMask);
0040   id_ |= ((version & kHcalVersMask) << kHcalVersOffset);
0041 }
0042 
0043 HcalTrigTowerDetId::HcalTrigTowerDetId(const DetId& gen) {
0044   if (!gen.null() && (gen.det() != Hcal || gen.subdetId() != HcalTriggerTower)) {
0045     throw cms::Exception("Invalid DetId")
0046         << "Cannot initialize HcalTrigTowerDetId from " << std::hex << gen.rawId() << std::dec;
0047   }
0048   id_ = gen.rawId();
0049 }
0050 
0051 void HcalTrigTowerDetId::setVersion(int version) { id_ |= ((version & kHcalVersMask) << kHcalVersOffset); }
0052 
0053 HcalTrigTowerDetId& HcalTrigTowerDetId::operator=(const DetId& gen) {
0054   if (!gen.null() && (gen.det() != Hcal || gen.subdetId() != HcalTriggerTower)) {
0055     throw cms::Exception("Invalid DetId")
0056         << "Cannot assign HcalTrigTowerDetId from " << std::hex << gen.rawId() << std::dec;
0057   }
0058   id_ = gen.rawId();
0059   return *this;
0060 }
0061 
0062 std::ostream& operator<<(std::ostream& s, const HcalTrigTowerDetId& id) {
0063   s << "(HcalTrigTower v" << id.version() << ": " << id.ieta() << ',' << id.iphi();
0064   if (id.depth() > 0)
0065     s << ',' << id.depth();
0066   return s << ')';
0067 }