Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run3-hcx354X Modify the DetId fo ZDC to accommodate the changes that happened during Run3 and some provision for the future (backport of #43200) #43206

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CondTools/Hcal/test/pfcuts_db_io_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
183 changes: 161 additions & 22 deletions DataFormats/HcalDetId/interface/HcalZDCDetId.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,163 @@

#include <ostream>
#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 {
Expand All @@ -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);
Expand Down
107 changes: 2 additions & 105 deletions DataFormats/HcalDetId/src/HcalZDCDetId.cc
Original file line number Diff line number Diff line change
@@ -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 ";
Expand Down
9 changes: 8 additions & 1 deletion DataFormats/HcalDetId/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@
<version ClassVersion="11" checksum="3710487366"/>
<version ClassVersion="10" checksum="4165221916"/>
</class>
<class name="HcalZDCDetId" ClassVersion="11">
<class name="HcalZDCDetId" ClassVersion="12">
<version ClassVersion="12" checksum="3806242743"/>
<version ClassVersion="11" checksum="3806242743"/>
<version ClassVersion="10" checksum="927247167"/>
<ioread sourceClass = "HcalZDCDetId" version="[-11]" targetClass="HcalZDCDetId" source="" target="">
<![CDATA[
HcalZDCDetId tmp(HcalZDCDetId::newForm(newObj->rawId()));
*newObj=tmp;
]]>
</ioread>
</class>
<class name="HcalCastorDetId" ClassVersion="11">
<version ClassVersion="11" checksum="2854161010"/>
Expand Down
2 changes: 2 additions & 0 deletions Geometry/ForwardGeometry/interface/ZdcGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading