Skip to content

Commit

Permalink
Merge pull request cms-sw#43194 from bsunanda/Phase2-hgx348B
Browse files Browse the repository at this point in the history
Phase2-hgx348B Take care of handling both HGCal and HFNose access to Geometry and Topology classes
  • Loading branch information
cmsbuild authored Nov 6, 2023
2 parents dd8547a + 22b5a7b commit 7d99d30
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
32 changes: 19 additions & 13 deletions Geometry/CaloTopology/src/HGCalTopology.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
#include "DataFormats/ForwardDetId/interface/HFNoseDetId.h"
#include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
Expand Down Expand Up @@ -25,7 +26,7 @@ HGCalTopology::HGCalTopology(const HGCalDDDConstants& hdcons, int det) : hdcons_
subdet_ = (ForwardSubdetector)(det);
kHGeomHalf_ = sectors_ * layers_;
types_ = 2;
} else if (det == (int)(DetId::Forward)) {
} else if (det == static_cast<int>(DetId::Forward)) {
det_ = DetId::Forward;
subdet_ = HFNose;
kHGeomHalf_ = sectors_ * layers_;
Expand Down Expand Up @@ -389,8 +390,8 @@ uint32_t HGCalTopology::detId2denseId(const DetId& idin) const {
DetId HGCalTopology::denseId2detId(uint32_t hi) const {
HGCalTopology::DecodedDetId id;
if (validHashIndex(hi)) {
id.zSide = ((int)(hi) < kHGhalfType_ ? -1 : 1);
int di = ((int)(hi) % kHGhalfType_);
id.zSide = (static_cast<int>(hi) < kHGhalfType_ ? -1 : 1);
int di = (static_cast<int>(hi) % kHGhalfType_);
if (waferHexagon6()) {
int type = (di % types_);
id.iType = (type == 0 ? -1 : 1);
Expand Down Expand Up @@ -466,8 +467,8 @@ bool HGCalTopology::valid(const DetId& idin) const {
HGCalTopology::DecodedDetId id = decode(idin);
bool flag;
if (waferHexagon6()) {
flag = (idin.det() == det_ && idin.subdetId() == (int)(subdet_) && id.iCell1 >= 0 && id.iCell1 < cells_ &&
id.iLay > 0 && id.iLay <= layers_ && id.iSec1 >= 0 && id.iSec1 <= sectors_);
flag = (idin.det() == det_ && idin.subdetId() == static_cast<int>(subdet_) && id.iCell1 >= 0 &&
id.iCell1 < cells_ && id.iLay > 0 && id.iLay <= layers_ && id.iSec1 >= 0 && id.iSec1 <= sectors_);
if (flag)
flag = hdcons_.isValidHex(id.iLay, id.iSec1, id.iCell1, true);
} else if (tileTrapezoid()) {
Expand Down Expand Up @@ -503,7 +504,7 @@ bool HGCalTopology::validModule(const DetId& idin, int cornerMin) const {
}

DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX, int nrStepsY) const {
if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)) {
if (startId.det() == DetId::Forward && startId.subdetId() == static_cast<int>(subdet_)) {
DetId id = changeXY(startId, nrStepsX, nrStepsY);
if (valid(id))
return id;
Expand All @@ -524,8 +525,8 @@ DetId HGCalTopology::switchZSide(const DetId startId) const {
HGCalTopology::DecodedDetId HGCalTopology::geomDenseId2decId(const uint32_t& hi) const {
HGCalTopology::DecodedDetId id;
if (hi < totalGeomModules()) {
id.zSide = ((int)(hi) < kHGeomHalf_ ? -1 : 1);
int di = ((int)(hi) % kHGeomHalf_);
id.zSide = (static_cast<int>(hi) < kHGeomHalf_ ? -1 : 1);
int di = (static_cast<int>(hi) % kHGeomHalf_);
if (waferHexagon6()) {
id.iSec1 = (di % sectors_);
di = (di - id.iSec1) / sectors_;
Expand Down Expand Up @@ -582,8 +583,13 @@ void HGCalTopology::addHGCSiliconId(
<< hdcons_.isValidHex8(lay, waferU, waferV, cellU, cellV, false);
#endif
if (hdcons_.isValidHex8(lay, waferU, waferV, cellU, cellV, false)) {
HGCSiliconDetId id((DetId::Detector)(det), zside, type, lay, waferU, waferV, cellU, cellV);
ids.emplace_back(DetId(id));
if (det == static_cast<int>(ForwardSubdetector::HFNose)) {
HFNoseDetId id(DetId::Forward, zside, type, lay, waferU, waferV, cellU, cellV);
ids.emplace_back(DetId(id));
} else {
HGCSiliconDetId id((DetId::Detector)(det), zside, type, lay, waferU, waferV, cellU, cellV);
ids.emplace_back(DetId(id));
}
}
}

Expand All @@ -608,7 +614,7 @@ HGCalTopology::DecodedDetId HGCalTopology::decode(const DetId& startId) const {
idx.iSec2 = 0;
idx.iType = id.type();
idx.zSide = id.zside();
idx.det = (int)(id.subdet());
idx.det = static_cast<int>(id.subdet());
} else if (det_ == DetId::Forward && subdet_ == ForwardSubdetector::HFNose) {
HFNoseDetId id(startId);
idx.iCell1 = id.cellU();
Expand All @@ -618,7 +624,7 @@ HGCalTopology::DecodedDetId HGCalTopology::decode(const DetId& startId) const {
idx.iSec2 = id.waferV();
idx.iType = id.type();
idx.zSide = id.zside();
idx.det = (int)(id.subdet());
idx.det = static_cast<int>(id.subdet());
} else {
HGCSiliconDetId id(startId);
idx.iCell1 = id.cellU();
Expand All @@ -628,7 +634,7 @@ HGCalTopology::DecodedDetId HGCalTopology::decode(const DetId& startId) const {
idx.iSec2 = id.waferV();
idx.iType = id.type();
idx.zSide = id.zside();
idx.det = (int)(id.subdet());
idx.det = static_cast<int>(id.subdet());
}
return idx;
}
Expand Down
13 changes: 11 additions & 2 deletions Geometry/CaloTopology/test/HGCalTopologyTester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
#include "Geometry/CaloTopology/interface/HGCalTopology.h"
#include "DataFormats/ForwardDetId/interface/HFNoseDetId.h"
#include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"

Expand Down Expand Up @@ -73,7 +74,9 @@ void HGCalTopologyTester::doTest(const HGCalTopology& topology) {
if (topology.waferHexagon8() || topology.tileTrapezoid()) {
for (unsigned int i = 0; i < type_.size(); ++i) {
DetId id;
if (detectorName_ == "HGCalEESensitive") {
if (topology.isHFNose()) {
id = HFNoseDetId(1, type_[i], layer_[i], sec1_[i], sec2_[i], cell1_[i], cell2_[i]);
} else if (detectorName_ == "HGCalEESensitive") {
id = HGCSiliconDetId(DetId::HGCalEE, 1, type_[i], layer_[i], sec1_[i], sec2_[i], cell1_[i], cell2_[i]);
} else if (detectorName_ == "HGCalHESiliconSensitive") {
id = HGCSiliconDetId(DetId::HGCalHSi, 1, type_[i], layer_[i], sec1_[i], sec2_[i], cell1_[i], cell2_[i]);
Expand All @@ -84,7 +87,13 @@ void HGCalTopologyTester::doTest(const HGCalTopology& topology) {
}
std::vector<DetId> ids = topology.neighbors(id);
unsigned int k(0);
if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
if (topology.isHFNose()) {
edm::LogVerbatim("HGCalGeom") << (HFNoseDetId)(id) << " has " << ids.size() << " neighbours:";
for (const auto& idn : ids) {
edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << (HFNoseDetId)(idn);
++k;
}
} else if (id.det() == DetId::HGCalEE || id.det() == DetId::HGCalHSi) {
edm::LogVerbatim("HGCalGeom") << (HGCSiliconDetId)(id) << " has " << ids.size() << " neighbours:";
for (const auto& idn : ids) {
edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << (HGCSiliconDetId)(idn);
Expand Down
23 changes: 17 additions & 6 deletions Geometry/HGCalGeometry/src/HGCalGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ void HGCalGeometry::newCell(
} else {
cells = m_topology.dddConstants().numberCellsHexagon(id.iLay, id.iSec1, id.iSec2, false);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "NewCell " << HGCSiliconDetId(detId) << " GEOM " << HGCSiliconDetId(geomId);
if (detId.det() == DetId::Forward)
edm::LogVerbatim("HGCalGeom") << "NewCell " << HFNoseDetId(detId) << " GEOM " << HFNoseDetId(geomId);
else
edm::LogVerbatim("HGCalGeom") << "NewCell " << HGCSiliconDetId(detId) << " GEOM " << HGCSiliconDetId(geomId);
#endif
}
const uint32_t cellIndex(m_topology.detId2denseGeomId(geomId));
Expand Down Expand Up @@ -136,7 +139,10 @@ void HGCalGeometry::newCell(
m_validIds.emplace_back(idc);
#ifdef EDM_ML_DEBUG
++cellSelect;
edm::LogVerbatim("HGCalGeom") << "Valid Id [" << u << ", " << v << "] " << HGCSiliconDetId(idc);
if (idc.det() == DetId::Forward)
edm::LogVerbatim("HGCalGeom") << "Valid Id [" << u << ", " << v << "] " << HFNoseDetId(idc);
else
edm::LogVerbatim("HGCalGeom") << "Valid Id [" << u << ", " << v << "] " << HGCSiliconDetId(idc);
#endif
}
}
Expand Down Expand Up @@ -217,10 +223,15 @@ GlobalPoint HGCalGeometry::getPosition(const DetId& detid, bool debug) const {
<< lcoord.y() << " ID " << id.iLay << ":" << id.iSec1 << ":" << id.iCell1
<< " Global " << glob;
} else {
if (debug)
edm::LogVerbatim("HGCalGeom") << "getPosition for " << HGCSiliconDetId(detid) << " Layer " << id.iLay
<< " Wafer " << id.iSec1 << ":" << id.iSec2 << " Cell " << id.iCell1 << ":"
<< id.iCell2;
if (debug) {
if (detid.det() == DetId::Forward)
edm::LogVerbatim("HGCalGeom") << "getPosition for " << HFNoseDetId(detid) << " Layer " << id.iLay << " Wafer "
<< id.iSec1 << ":" << id.iSec2 << " Cell " << id.iCell1 << ":" << id.iCell2;
else
edm::LogVerbatim("HGCalGeom") << "getPosition for " << HGCSiliconDetId(detid) << " Layer " << id.iLay
<< " Wafer " << id.iSec1 << ":" << id.iSec2 << " Cell " << id.iCell1 << ":"
<< id.iCell2;
}
xy = m_topology.dddConstants().locateCell(
id.zSide, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, true, false, debug);
double xx = id.zSide * xy.first;
Expand Down

0 comments on commit 7d99d30

Please sign in to comment.