diff --git a/CondTools/Hcal/test/pfcuts_db_io_test.sh b/CondTools/Hcal/test/pfcuts_db_io_test.sh index 61aee899ae22f..6c1271526957f 100755 --- a/CondTools/Hcal/test/pfcuts_db_io_test.sh +++ b/CondTools/Hcal/test/pfcuts_db_io_test.sh @@ -106,4 +106,8 @@ EOF cmsRun temp_pfcuts_from_db.py rm temp_pfcuts_from_db.py -diff DumpPFCuts_Run1.txt $inputfile +# Ingnore raw channel ids in the comparison +rm -f db_reference.txt db_dump.txt +awk '{print $1, $2, $3, $4, $5, $6}' $inputfile > db_reference.txt +awk '{print $1, $2, $3, $4, $5, $6}' DumpPFCuts_Run1.txt > db_dump.txt +diff db_dump.txt db_reference.txt diff --git a/DataFormats/HcalDetId/interface/HcalZDCDetId.h b/DataFormats/HcalDetId/interface/HcalZDCDetId.h index 781449333551b..fafb1af7da2cf 100644 --- a/DataFormats/HcalDetId/interface/HcalZDCDetId.h +++ b/DataFormats/HcalDetId/interface/HcalZDCDetId.h @@ -3,54 +3,163 @@ #include #include "DataFormats/DetId/interface/DetId.h" +#include "FWCore/Utilities/interface/Exception.h" /** \class HcalZDCDetId * - * Contents of the HcalZDCDetId : + * Contents of the HcalZDCDetId (Old): * [7] Set for RPD * [6] Z position (true for positive) * [5:4] Section (EM/HAD/Lumi) * [3:0] Channel + * Contents of the HcalZDCDetId (New): + * [8] Set to 1 for new format + * [7] Set for RPD + * [6] Z position (true for positive) + * [5:4] Section (EM/HAD/Lumi) + * [3:0] Chaneel for EM/HAD/Lumi + * [5:0] Channel for RPD * */ class HcalZDCDetId : public DetId { public: - static const int kZDCChannelMask = 0xF; - static const int kZDCSectionMask = 0x3; - static const int kZDCSectionOffset = 4; - static const int kZDCZsideMask = 0x40; - static const int kZDCRPDMask = 0x80; + static constexpr uint32_t kZDCChannelMask1 = 0xF; + static constexpr uint32_t kZDCChannelMask2 = 0x7F; + static constexpr uint32_t kZDCSectionMask = 0x3; + static constexpr uint32_t kZDCSectionOffset = 4; + static constexpr uint32_t kZDCZsideMask = 0x40; + static constexpr uint32_t kZDCRPDMask = 0x80; + static constexpr uint32_t kZDCnewFormat = 0x100; enum Section { Unknown = 0, EM = 1, HAD = 2, LUM = 3, RPD = 4 }; - static const int SubdetectorId = 2; + static constexpr int32_t SubdetectorId = 2; /** Create a null cellid*/ - HcalZDCDetId(); + constexpr HcalZDCDetId() : DetId() {} /** Create cellid from raw id (0=invalid tower id) */ - HcalZDCDetId(uint32_t rawid); + constexpr HcalZDCDetId(uint32_t rawid) : DetId(rawid) {} /** Constructor from section, eta sign, and channel */ - HcalZDCDetId(Section section, bool true_for_positive_eta, int channel); + constexpr HcalZDCDetId(Section section, bool true_for_positive_eta, int32_t channel) { + id_ = packHcalZDCDetId(section, true_for_positive_eta, channel); + } /** Constructor from a generic cell id */ - HcalZDCDetId(const DetId& id); + constexpr HcalZDCDetId(const DetId& gen) { + if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) { + throw cms::Exception("Invalid DetId") + << "Cannot initialize ZDCDetId from " << std::hex << gen.rawId() << std::dec; + } + id_ = newForm(gen.rawId()); + } /** Assignment from a generic cell id */ - HcalZDCDetId& operator=(const DetId& id); + constexpr HcalZDCDetId& operator=(const DetId& gen) { + if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) { + throw cms::Exception("Invalid DetId") << "Cannot assign ZDCDetId from " << std::hex << gen.rawId() << std::dec; + } + id_ = newForm(gen.rawId()); + return *this; + } + /** Comparison operator */ + constexpr bool operator==(DetId gen) const { + if (gen.rawId() == id_) { + return true; + } else { + uint32_t id1 = newForm(gen.rawId()); + uint32_t id2 = newForm(id_); + return (id1 == id2); + } + } + constexpr bool operator!=(DetId gen) const { + if (gen.rawId() != id_) { + return true; + } else { + uint32_t id1 = newForm(gen.rawId()); + uint32_t id2 = newForm(id_); + return (id1 != id2); + } + } /// get the z-side of the cell (1/-1) - int zside() const { return ((id_ & kZDCZsideMask) ? (1) : (-1)); } + constexpr int32_t zside() const { return ((id_ & kZDCZsideMask) ? (1) : (-1)); } /// get the section - Section section() const; + constexpr Section section() const { + uint32_t id = newForm(id_); + if (id & kZDCRPDMask) + return RPD; + else + return (Section)((id >> kZDCSectionOffset) & kZDCSectionMask); + } /// get the depth (1 for EM, channel + 1 for HAD, 2 for RPD, not sure yet for LUM, leave as default) - int depth() const; + constexpr int32_t depth() const { + const int se(section()); + if (se == EM) + return 1; + else if (se == HAD) + return (channel() + 2); + else if (se == RPD) + return 2; + else + return channel(); + } /// get the channel - int channel() const; + constexpr int32_t channel() const { + const int32_t se(section()); + uint32_t id = newForm(id_); + if (se == RPD) + return (1 + (id & kZDCChannelMask2)); + else + return (id & kZDCChannelMask1); + } - uint32_t denseIndex() const; + constexpr static bool newFormat(const uint32_t& di) { return (di & kZDCnewFormat); } + constexpr static uint32_t newForm(const uint32_t& di) { + uint32_t id(di); + if (!newFormat(id)) { + Section se(Unknown); + bool zside(true); + int32_t channel(0); + unpackHcalZDCDetId(id, se, zside, channel); + id = packHcalZDCDetId(se, zside, channel); + } + return id; + } - static bool validDenseIndex(uint32_t di) { return (di < kSizeForDenseIndexing); } + constexpr uint32_t denseIndex() const { + const int32_t se(section()); + uint32_t di = + (channel() - 1 + + (se == RPD ? 2 * kDepRun1 + (zside() < 0 ? 0 : kDepRPD) + : ((zside() < 0 ? 0 : kDepRun1) + (se == HAD ? kDepEM : (se == LUM ? kDepEM + kDepHAD : 0))))); + return di; + } - static HcalZDCDetId detIdFromDenseIndex(uint32_t di); + constexpr static bool validDenseIndex(const uint32_t& di) { return (di < kSizeForDenseIndexing); } - static bool validDetId(Section se, int dp); + constexpr static HcalZDCDetId detIdFromDenseIndex(uint32_t di) { + if (validDenseIndex(di)) { + bool lz(false); + uint32_t dp(0); + Section se(Unknown); + if (di >= 2 * kDepRun1) { + lz = (di >= (kDepRun1 + kDepTot)); + se = RPD; + dp = 1 + ((di - 2 * kDepRun1) % kDepRPD); + } else { + lz = (di >= kDepRun1); + uint32_t in = (di % kDepRun1); + se = (in < kDepEM ? EM : (in < kDepEM + kDepHAD ? HAD : LUM)); + dp = (se == EM ? in + 1 : (se == HAD ? in - kDepEM + 1 : in - kDepEM - kDepHAD + 1)); + } + return HcalZDCDetId(se, lz, dp); + } else { + return HcalZDCDetId(); + } + } + + constexpr static bool validDetId(Section se, int32_t dp) { + bool flag = (dp >= 1 && (((se == EM) && (dp <= kDepEM)) || ((se == HAD) && (dp <= kDepHAD)) || + ((se == LUM) && (dp <= kDepLUM)) || ((se == RPD) && (dp <= kDepRPD)))); + return flag; + } private: enum { @@ -59,11 +168,41 @@ class HcalZDCDetId : public DetId { kDepLUM = 2, kDepRPD = 16, kDepRun1 = kDepEM + kDepHAD + kDepLUM, - kDepTot = kDepRun1 + kDepRPD + kDepTot = kDepRun1 + kDepRPD, + kDepRun3 = kDepTot }; + constexpr static uint32_t packHcalZDCDetId(const Section& se, const bool& zside, const int32_t& channel) { + uint32_t id = DetId(DetId::Calo, SubdetectorId); + id |= kZDCnewFormat; + if (se == RPD) { + id |= kZDCRPDMask; + id |= ((channel - 1) & kZDCChannelMask2); + } else { + id |= (se & kZDCSectionMask) << kZDCSectionOffset; + id |= (channel & kZDCChannelMask1); + } + if (zside) + id |= kZDCZsideMask; + return id; + } + + constexpr static void unpackHcalZDCDetId(const uint32_t& id, Section& se, bool& zside, int32_t& channel) { + if (id & kZDCnewFormat) { + se = (id & kZDCRPDMask) ? RPD : (Section)((id >> kZDCSectionOffset) & kZDCSectionMask); + channel = (se == RPD) ? (1 + (id & kZDCChannelMask2)) : (id & kZDCChannelMask1); + zside = (id & kZDCZsideMask); + } else { + se = (id & kZDCRPDMask) ? RPD : (Section)((id >> kZDCSectionOffset) & kZDCSectionMask); + channel = (se == RPD) ? (1 + (id & kZDCChannelMask1)) : (id & kZDCChannelMask1); + zside = (id & kZDCZsideMask); + } + } + public: - enum { kSizeForDenseIndexing = 2 * kDepRun1 }; + constexpr static int32_t kSizeForDenseIndexingRun1 = 2 * kDepRun1; + constexpr static int32_t kSizeForDenseIndexingRun3 = 2 * kDepRun3; + enum { kSizeForDenseIndexing = kSizeForDenseIndexingRun1 }; }; std::ostream& operator<<(std::ostream&, const HcalZDCDetId& id); diff --git a/DataFormats/HcalDetId/src/HcalZDCDetId.cc b/DataFormats/HcalDetId/src/HcalZDCDetId.cc index 4b2452d1184fd..8b59fe4f1bbb8 100644 --- a/DataFormats/HcalDetId/src/HcalZDCDetId.cc +++ b/DataFormats/HcalDetId/src/HcalZDCDetId.cc @@ -1,111 +1,8 @@ #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h" -#include "FWCore/Utilities/interface/Exception.h" - -const int HcalZDCDetId::kZDCChannelMask; -const int HcalZDCDetId::kZDCSectionMask; -const int HcalZDCDetId::kZDCSectionOffset; -const int HcalZDCDetId::kZDCZsideMask; -const int HcalZDCDetId::kZDCRPDMask; -const int HcalZDCDetId::SubdetectorId; - -HcalZDCDetId::HcalZDCDetId() : DetId() {} - -HcalZDCDetId::HcalZDCDetId(uint32_t rawid) : DetId(rawid) {} - -HcalZDCDetId::HcalZDCDetId(Section section, bool true_for_positive_eta, int channel) - : DetId(DetId::Calo, SubdetectorId) { - if (section == RPD) { - id_ |= (Unknown & kZDCSectionMask) << kZDCSectionOffset; - id_ |= kZDCRPDMask; - id_ |= ((channel - 1) & kZDCChannelMask); - } else { - id_ |= (section & kZDCSectionMask) << kZDCSectionOffset; - id_ |= (channel & kZDCChannelMask); - } - if (true_for_positive_eta) - id_ |= kZDCZsideMask; -} - -HcalZDCDetId::HcalZDCDetId(const DetId& gen) { - if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) { - throw cms::Exception("Invalid DetId") << "Cannot initialize ZDCDetId from " << std::hex << gen.rawId() << std::dec; - } - id_ = gen.rawId(); -} - -HcalZDCDetId& HcalZDCDetId::operator=(const DetId& gen) { - if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) { - throw cms::Exception("Invalid DetId") << "Cannot assign ZDCDetId from " << std::hex << gen.rawId() << std::dec; - } - id_ = gen.rawId(); - return *this; -} - -HcalZDCDetId::Section HcalZDCDetId::section() const { - if (id_ & kZDCRPDMask) - return RPD; - else - return (Section)((id_ >> kZDCSectionOffset) & kZDCSectionMask); -} - -int HcalZDCDetId::depth() const { - const int se(section()); - if (se == EM) - return 1; - else if (se == HAD) - return (channel() + 2); - else if (se == RPD) - return 2; - else - return channel(); -} - -int HcalZDCDetId::channel() const { - const int se(section()); - if (se == RPD) - return (1 + (id_ & kZDCChannelMask)); - else - return (id_ & kZDCChannelMask); -} - -uint32_t HcalZDCDetId::denseIndex() const { - const int se(section()); - uint32_t di = - (channel() - 1 + - (se == RPD ? 2 * kDepRun1 + (zside() < 0 ? 0 : kDepRPD) - : ((zside() < 0 ? 0 : kDepRun1) + (se == HAD ? kDepEM : (se == LUM ? kDepEM + kDepHAD : 0))))); - return di; -} - -HcalZDCDetId HcalZDCDetId::detIdFromDenseIndex(uint32_t di) { - if (validDenseIndex(di)) { - bool lz(false); - uint32_t dp(0); - Section se(Unknown); - if (di >= 2 * kDepRun1) { - lz = (di >= (kDepRun1 + kDepTot)); - se = RPD; - dp = 1 + ((di - 2 * kDepRun1) % kDepRPD); - } else { - lz = (di >= kDepRun1); - uint32_t in = (di % kDepRun1); - se = (in < kDepEM ? EM : (in < kDepEM + kDepHAD ? HAD : LUM)); - dp = (EM == se ? in + 1 : (HAD == se ? in - kDepEM + 1 : in - kDepEM - kDepHAD + 1)); - } - return HcalZDCDetId(se, lz, dp); - } else { - return HcalZDCDetId(); - } -} - -bool HcalZDCDetId::validDetId(Section se, int dp) { - bool flag = (dp >= 1 && (((se == EM) && (dp <= kDepEM)) || ((se == HAD) && (dp <= kDepHAD)) || - ((se == LUM) && (dp <= kDepLUM)) || ((se == RPD) && (dp <= kDepRPD)))); - return flag; -} std::ostream& operator<<(std::ostream& s, const HcalZDCDetId& id) { - s << "(ZDC" << ((id.zside() == 1) ? ("+") : ("-")); + s << "(Det " << id.det() << ":" << DetId::Calo << " subdet " << id.subdetId() << ":" << HcalZDCDetId::SubdetectorId + << " ZDC" << ((id.zside() == 1) ? ("+") : ("-")); switch (id.section()) { case (HcalZDCDetId::EM): s << " EM "; diff --git a/DataFormats/HcalDetId/src/classes_def.xml b/DataFormats/HcalDetId/src/classes_def.xml index 2d3c956aa7305..943ec363bf4eb 100644 --- a/DataFormats/HcalDetId/src/classes_def.xml +++ b/DataFormats/HcalDetId/src/classes_def.xml @@ -34,9 +34,16 @@ - + + + + rawId())); + *newObj=tmp; + ]]> + diff --git a/Geometry/ForwardGeometry/interface/ZdcGeometry.h b/Geometry/ForwardGeometry/interface/ZdcGeometry.h index e0f04c51ca34c..7b55d8651742f 100644 --- a/Geometry/ForwardGeometry/interface/ZdcGeometry.h +++ b/Geometry/ForwardGeometry/interface/ZdcGeometry.h @@ -58,6 +58,8 @@ class ZdcGeometry : public CaloSubdetectorGeometry { const DetId& detId) override; protected: + unsigned int indexFor(const DetId& id) const override { return HcalZDCDetId(id).denseIndex(); } + // Modify the RawPtr class const CaloCellGeometry* getGeometryRawPtr(uint32_t index) const override; diff --git a/Geometry/ForwardGeometry/src/ZdcGeometry.cc b/Geometry/ForwardGeometry/src/ZdcGeometry.cc index 861939c443348..df7e9433b6632 100644 --- a/Geometry/ForwardGeometry/src/ZdcGeometry.cc +++ b/Geometry/ForwardGeometry/src/ZdcGeometry.cc @@ -1,3 +1,4 @@ +#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "Geometry/CaloGeometry/interface/CaloGenericDetId.h" #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" #include "Geometry/ForwardGeometry/interface/ZdcGeometry.h" @@ -48,7 +49,6 @@ DetId ZdcGeometry::getClosestCell(const GlobalPoint& r) const */ unsigned int ZdcGeometry::alignmentTransformIndexLocal(const DetId& id) { const CaloGenericDetId gid(id); - assert(gid.isZDC()); return (0 > HcalZDCDetId(id).zside() ? 0 : 1); @@ -66,7 +66,6 @@ void ZdcGeometry::newCell(const GlobalPoint& f1, const CCGFloat* parm, const DetId& detId) { const CaloGenericDetId cgid(detId); - assert(cgid.isZDC()); const unsigned int di(cgid.denseIndex()); @@ -77,6 +76,8 @@ void ZdcGeometry::newCell(const GlobalPoint& f1, const CaloCellGeometry* ZdcGeometry::getGeometryRawPtr(uint32_t index) const { // Modify the RawPtr class + if (m_cellVec.size() < index) + return nullptr; const CaloCellGeometry* cell(&m_cellVec[index]); - return (m_cellVec.size() < index || nullptr == cell->param() ? nullptr : cell); + return (((cell == nullptr) || (nullptr == cell->param())) ? nullptr : cell); } diff --git a/Geometry/ForwardGeometry/src/ZdcHardcodeGeometryLoader.cc b/Geometry/ForwardGeometry/src/ZdcHardcodeGeometryLoader.cc index 971c44456b263..47f19d5669526 100644 --- a/Geometry/ForwardGeometry/src/ZdcHardcodeGeometryLoader.cc +++ b/Geometry/ForwardGeometry/src/ZdcHardcodeGeometryLoader.cc @@ -57,7 +57,7 @@ void ZdcHardcodeGeometryLoader::fill(HcalZDCDetId::Section section, ReturnType g geom->allocatePar(ZdcGeometry::k_NumberOfParametersPerShape * ZdcGeometry::k_NumberOfShapes, ZdcGeometry::k_NumberOfParametersPerShape); - edm::LogInfo("ZdcHardcodeGeometry") << "Number of ZDC DetIds made: " << section << " " << zdcIds.size(); + edm::LogVerbatim("ZdcGeometry") << "Number of ZDC DetIds made: " << section << " " << zdcIds.size(); // for each new HcalZdcDetId, make a CaloCellGeometry @@ -73,6 +73,7 @@ void ZdcHardcodeGeometryLoader::makeCell(const HcalZDCDetId& detId, ReturnType g const int channel(detId.channel()); + edm::LogVerbatim("ZdcGeometry") << "ZDCGeometry::Cell: " << detId << " Section " << section << " channel " << channel; //********* Here are all the hardcoded numbers you need to know, in **cm** //********* Most are from the zdc.xml and zdclum.xml files ******